<?php
 $class_second = 'am_wo_routing_line';
 $$class_second = &$am_wo_routing_line;
$class_third = 'am_wo_bom';
$$class_third = &$am_wo_bom;
 $$class->transaction_type = 'AM_MOVE';
?>

<?php

 if (!empty($_GET["am_wo_header_id"]) && !is_array($_GET["am_wo_header_id"])) {
  $am_wo_header_id = htmlentities($_GET["am_wo_header_id"]);
  $am_wo_header = am_wo_header::find_by_id($am_wo_header_id);
  $wmt = new am_move_transaction();

  foreach ($wmt->field_a as $key => $value) {
   if (!empty($am_wo_header->$value)) {
    $$class->$value = $am_wo_header->$value;
   }
  }
  $$class->am_wo_heared_id = $am_wo_header_id;
  $$class->total_quantity = $am_wo_header->quantity;
  $item = item::find_by_id($$class->item_id_m);
  $$class->item_number = $item->item_number;
  $$class->item_description = $item->item_description;
  $$class->uom = $item->uom_id;
  $$class->transaction_type = 'am_MOVE';

  $am_wo_bom_object = am_wo_bom::find_by_am_wo_headerId($am_wo_header_id);
  if (count($am_wo_bom_object) == 0) {
   $am_wo_bom_object = array(new am_wo_bom());
  } else {
   $routing_line_details = am_wo_routing_line::find_by_am_wo_headerId($am_wo_header_id);
   foreach ($am_wo_bom_object as & $am_wobom) {
    if (!empty($am_wobom->component_item_id_m)) {
     $item = item::find_by_orgId_item_id_m($am_wobom->component_item_id_m, $$class->org_id);
     $am_wobom->component_item_number = $item->item_number;
     $am_wobom->component_description = $item->item_description;
     $am_wobom->component_uom = $item->uom_id;
     $am_wobom->serial_generation = $item->serial_generation;
     $am_wobom->lot_generation = $item->lot_generation;
    }
   }
  }

//  pa($am_wo_bom_object);

  $am_wo_routing_line_object = am_wo_routing_line::find_by_am_wo_headerId($am_wo_header_id);
  if (count($am_wo_routing_line_object) == 0) {
   $am_wo_routing_line_object = array(new am_wo_routing_line);
  }
 } else {
  $$class->total_quantity = '';
  $am_wo_bom = new am_wo_bom();
  $am_wo_bom_object = array();
  array_push($am_wo_bom_object, $am_wo_bom);

  $am_wo_routing_line = new am_wo_routing_line();
  $am_wo_routing_line_object = array();
  array_push($am_wo_routing_line_object, $am_wo_routing_line);
 }

//for move transaction view 
 if (!empty($_GET["am_move_transaction_id"]) && !is_array($_GET["am_move_transaction_id"])) {
  $am_wo_header_id = $$class->am_wo_header_id;
  $am_wo_header = am_wo_header::find_by_id($am_wo_header_id);
  $$class->total_quantity = $am_wo_header->quantity;

  $item = item::find_by_id($$class->item_id_m);
  $$class->item_number = $item->item_number;
  $$class->item_description = $item->item_description;
  $$class->uom = $item->uom_id;
  $$class->transaction_type = 'am_MOVE';
  $readonly = 1;
  $mode = 2;
 }

 if (empty($$class->transaction_date)) {
  $$class->transaction_date = current_time();
 }
 ?>