<?php

//if (!empty($$class->prj_project_header_id) && !empty($prj_project_line_object)) {
// foreach ($prj_project_line_object as &$prj_project_lines) {
//  if (!empty($prj_project_lines->item_id_m)) {
//   $item = item::find_by_id($prj_project_lines->item_id_m);
//   $prj_project_lines->item_number = $item->item_number;
//   $prj_project_lines->item_description = $item->item_description;
////   $prj_project_lines->uom_id = $item->uom_id;
//  }
//
//  if (empty($prj_project_lines->sd_so_line_id)) {
//   $prj_project_lines->so_number = null;
//   $prj_project_lines->so_line_number = null;
//  }
// }
//}
//asign values of fields on form but not in databse only if $$class->$primary_cloumn is not null
if (!empty($$class->ar_customer_id)) {
 $ac = new ar_customer();
 $ac->findBy_id($$class->ar_customer_id);
 $$class->customer_name = $ac->customer_name;
 $$class->customer_number = $ac->customer_number;
}

$customer_site_obj = [];
if (!empty($$class->ar_customer_site_id)) {
 $arc = new ar_customer_site();
 $arc_i = $arc->findBy_id($$class->ar_customer_site_id);
 array_push($customer_site_obj, $arc_i);
}

if (empty($$class->order_status)) {
 $$class->so_status = 'ENTERED';
}

if (empty($$class->order_source_type)) {
 $$class->order_source_type = 'MANUAL';
}

if (!empty($$class->service_person_employee_id)) {
 $emp_details = hr_employee::find_by_id($$class->service_person_employee_id);
 $$class->service_person = $emp_details->first_name . ' ' . $emp_details->last_name;
}

if (empty($prj_project_member_object) && !empty($$class->prj_project_header_id)) {
 $prj_project_member_object = prj_project_member::find_by_parent_id($$class->prj_project_header_id);
}
if (empty($prj_project_member_object)) {
 $prj_project_member_object = array(new prj_project_member());
}

if (empty($prj_project_control_object) && !empty($$class->prj_project_header_id)) {
 $prj_project_control_object = prj_project_control::find_by_parent_id($$class->prj_project_header_id);
}
if (empty($prj_project_control_object)) {
 $prj_project_control_object = array(new prj_project_control());
}


if ((!empty($$class->arproval_status)) && ($$class->arproval_status == 'CANCELLED')) {
 $mode = 2;
 $readonly = 1;
}

$add_to_order_a = [];

// foreach ($prj_project_line_object as $prj_project_line) {
//  if(!in_array($prj_project_line->sd_so_header_id, $add_to_order_a)){
//   $add_to_order_a[$prj_project_line->sd_so_header_id] = $prj_project_line->sd_so_header_id;
//  }
// }

$pageno = !empty($_GET['pageno']) ? $_GET['pageno'] : 1;
$per_page = !empty($_GET['per_page']) ? $_GET['per_page'] : 10;
$total_count = count($prj_project_line_object);
$pagination = new pagination($pageno, $per_page, $total_count);
$pagination->setProperty('_path', 'form');
$position = ($pageno - 1) * $per_page;
?>

