<?php

$revision_name_val = !empty($_GET['revision_name']) ? $_GET['revision_name'] : null;

if ((!empty($_GET["bom_header_id"])) && (!(is_array($_GET["bom_header_id"])))) {
 $bom_header_id = htmlentities($_GET["bom_header_id"]);
}

if ((empty($_GET["bom_header_id"])) && (!empty($_GET["item_id_m"])) && (!empty($_GET["org_id"]))) {
 $bom_header_byItem = bom_header::find_by_itemId_orgId($_GET["item_id_m"], $_GET["org_id"]);
 if ($bom_header_byItem) {
  foreach ($bom_header_byItem as $k => $v) {
   $$class->$k = $v;
  }
  $bom_header_id = $$class->bom_header_id;
//   $bom_line_object = bom_line::find_by_parent_id($bom_header_id );
  $bom_line_object = bom_line::find_by_bomHeaderId_revNumber($bom_header_id, $revision_name_val);
 } else {
  $$class->item_id_m = $_GET["item_id_m"];
  $item_m = item::find_by_item_id_m($_GET["item_id_m"]);
  $$class->item_number = $item_m->item_number;
  $$class->uom = $item_m->uom_id;
 }
}

if (!empty($bom_header_id)) {
 if (!empty($bom_header->item_id_m)) {
  $item = item::find_by_id($bom_header->item_id_m);
  $bom_header->item_number = $item->item_number;
  $bom_header->item_description = $item->item_description;
  $bom_header->uom = $item->uom_id;

  $routing_line_details = bom_routing_line_v::find_by_itemIdM_OrgId($$class->item_id_m, $$class->org_id);
//   echo "<br><br><br><br>BOM Routing line";
//   pa($routing_line_details);
 }


 if (!empty($$class->common_bom_item_id_m) && !empty($$class->common_bom_org_id)) {
  $bom_header_byItem = bom_header::find_by_itemId_orgId($$class->common_bom_item_id_m, $$class->common_bom_org_id);
  $bom_lines = new bom_line();
  $bom_line_object = $bom_lines->findBy_parentId($bom_header_byItem->bom_header_id);
  $common_bom_details = bom_commonbom_line::find_by_parent_id($bom_header_id);
 }

 if (empty($bom_line_object)) {
  $bom_lines = new bom_line();
  $bom_line_object = array();
  array_push($bom_line_object, $bom_lines);
 } else {
  foreach ($bom_line_object as &$bom_lines) {
   $item = item::find_by_id($bom_lines->component_item_id_m);
   if ($item) {
    $bom_lines->component_item_number = $item->item_number;
    $bom_lines->component_description = $item->item_description;
    $bom_lines->component_uom = $item->uom_id;
   }
   if (empty($bom_lines->bom_commonbom_line_id)) {
    $bom_lines->bom_commonbom_line_id = null;
   }
   if (!empty($common_bom_details)) {
    foreach ($common_bom_details as $lines) {
     if (!empty($value)) {
      $bom_lines->routing_sequence = $lines->routing_sequence;
      $bom_lines->planning_percentage = $lines->planning_percentage;
      $bom_lines->yield = $lines->yield;
      $bom_lines->wip_supply_type = $lines->wip_supply_type;
      $bom_lines->supply_sub_inventory = $lines->supply_sub_inventory;
      $bom_lines->supply_locator = $lines->supply_locator;
      $bom_lines->bom_commonbom_line_id = $lines->bom_commonbom_line_id;
     }
    }
   }
  }
 }
}

if (!empty($$class->common_bom_item_id_m)) {
 $item_c = item::find_by_id($bom_header->common_bom_item_id_m);
 $$class->commonBom_item_number = $item_c->item_number;
 $$class->commonBom_item_description = $item_c->item_description;
 $readonly1 = true;
}

if (!empty($$class->item_id_m) && !empty($$class->org_id)) {
//  $item_rev_d = inv_item_revision::find_by_itemIdM_orgId($$class->item_id_m, $$class->org_id);
 $revision_name_a = inv_item_revision::find_by_itemIdM_orgId($$class->item_id_m, $$class->org_id);
} else {
 $revision_name_a = array();
}

if (!empty($_GET['am_asset_type'])) {
 $hidden_field =  $f->hidden_field_withCLass('am_asset_type', $_GET['am_asset_type'], 'popup_value');
 $form_name_header = ucwords(str_replace('_', ' ', $_GET['am_asset_type']));
}
?>