<?php
if(!empty($$class->pm_resource_transaction_id)){
 $mode = 2; $readonly = 1;
}
$class_second = 'pm_batch_line';
$$class_second = &$pm_batch_line;

$$class->document_type = 'Batch';
$$class->reference_type = 'table';


if (!empty($_GET['pm_batch_header_id'])) {
 $pm_batch_header_id = ($_GET["pm_batch_header_id"]);
 $pm_batch = pm_batch_header::find_by_id($pm_batch_header_id);
} else if (!empty($_GET["batch_name"])) {
 $batch_name = $_GET["batch_name"];
 $pm_batch = pm_batch_header::find_by_batchName($batch_name);
 $pm_batch_header_id = $pm_batch->pm_batch_header_id;
}else if (!empty($$class->pm_batch_header_id)) {
 $pm_batch_header_id = $$class->pm_batch_header_id;
 $pm_batch = pm_batch_header::find_by_id($pm_batch_header_id);
}

if (!empty($pm_batch_header_id) && empty($$class->pm_resource_transaction_id)) {
 $$class->org_id = $pm_batch->org_id;
 $$class->pm_batch_header_id = $pm_batch_header_id;
 $$class->batch_name = $pm_batch->batch_name;
 $pm_batch_bom_object = pm_batch_operation_line::find_operationDetails_by_batchHeaderId($pm_batch_header_id);
 if (count($pm_batch_bom_object) == 0) {
  $pm_batch_bom_object = [new pm_batch_line()];
 }
}else if (!empty($pm_batch_header_id) && !empty($$class->pm_resource_transaction_id)) {
 $$class->batch_name = $pm_batch->batch_name;
 $pm_batch_bom_object = [$$class];
 if (count($pm_batch_bom_object) == 0) {
  $pm_batch_bom_object = [new pm_batch_line()];
 }
}
?>

<?php

if ((!empty($pm_batch_header_id)) && !empty($pm_batch_bom_object)) {
 $bom_sequence_stament = '<select class=" select bom_sequence large" name="bom_sequence[]">';
 $bom_sequence_stament .= '<option></option>';
 foreach ($pm_batch_bom_object as $array) {
  $bom_sequence_stament .='<option ';
  $bom_sequence_stament .=' data-pm_batch_operation_detail_id ="' . $array->pm_batch_operation_detail_id . '"';
  $bom_sequence_stament .=' data-resource_sequence ="' . $array->resource_sequence . '"';
  $bom_sequence_stament .=' data-resource_usage ="' . $array->resource_usage . '"';
  $bom_sequence_stament .=' data-step_no ="' . $array->step_no . '"';
  $bom_sequence_stament .=' data-batch_quantity ="' . $array->batch_quantity . '"';
  $bom_sequence_stament .=' data-pm_batch_operation_line_id ="' . $array->pm_batch_operation_line_id . '"';
  $bom_sequence_stament .=' data-pm_process_routing_header_id ="' . $array->pm_process_routing_header_id . '"';
  $bom_sequence_stament .=' data-activity_code ="' . $array->activity_code . '"';
  $bom_sequence_stament .=' data-activity_factror ="' . $array->activity_factror . '"';
  $bom_sequence_stament .=' value="' . $array->pm_batch_operation_detail_id . '" >';
  $bom_sequence_stament .=  'Step-'. $array->step_no . ' | ' . $array->resource_sequence . ' | ' . $array->activity_code;
  $bom_sequence_stament .= '</option>';
 }
 $bom_sequence_stament .= '</select>';
}

 if (empty($$class->transaction_date)) {
  $$class->transaction_date = current_time(true);
 }
 $$class->transaction_type = 'WIP_RESOURCE_TRANSACTION';
?>