<?php

if (!empty($$class->mdm_bank_account_id)) {
 $ba = new mdm_bank_account_v();
 $ba->findBy_id($$class->mdm_bank_account_id);
 $$class->bank_name = $ba->bank_name;
 $$class->account_number = $ba->account_number;
 $$class->bank_number = $ba->bank_number;
 $$class->bank_name_short = $ba->bank_name_short;
 $$class->bank_name_alt = $ba->bank_name_alt;
 $$class->branch_name = $ba->branch_name;
 $$class->branch_number = $ba->branch_number;
 $$class->ifsc_code = $ba->ifsc_code;
 $$class->swift_code = $ba->swift_code;
 $$class->routing_number = $ba->routing_number;
 $$class->iban_code = $ba->iban_code;
}

//if (!empty($$class->sd_so_header_id)) {
// foreach ($sd_so_line_object as &$sd_so_lines) {
//  if (!empty($sd_so_lines->item_id_m)) {
//   $item = item::find_by_id($sd_so_lines->item_id_m);
//   $sd_so_lines->item_number = $item->item_number;
//  }
// }
//}
//
//if (!empty($$class->bu_org_id)) {
// $sales_control = sd_sales_control::find_by_org_id($$class->bu_org_id);
//} else {
// $sales_control = new sd_sales_control();
//}


//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($sd_so_line_object)) {
// foreach ($sd_so_line_object as &$sd_so_lines) {
//  if (empty($sd_so_lines->schedule_ship_date) && ($sales_control->default_schedule_ship_date_cb == 1)) {
//   $sd_so_lines->schedule_ship_date = current_time(true);
//  }
//
//  if (empty($sd_so_lines->promise_date) && ($sales_control->default_promise_date_cb == 1)) {
//   $sd_so_lines->promise_date = current_time(true);
//  }
//
//  if (empty($sd_so_lines->requested_date) && ($sales_control->default_requested_date_cb == 1)) {
//   $sd_so_lines->requested_date = current_time(true);
//  }
//
//  if (!empty($sd_so_lines->item_id_m)) {
//   $item = item::find_by_id($sd_so_lines->item_id_m);
//   $sd_so_lines->item_number = $item->item_number;
//   $sd_so_lines->uom_id = $item->uom_id;
//  } else {
//   $sd_so_lines->item_number = null;
//   $sd_so_lines->uom_id = null;
//  }
//  if (!empty($sd_so_lines->tax_code_id)) {
//   $tax = mdm_tax_code::find_by_id($sd_so_lines->tax_code_id);
//   $sd_so_lines->tax_code_value = (!empty($tax->percentage)) ? 'p_' . $tax->percentage : 'a_' . $tax->tax_amount;
//  } else {
//   $sd_so_lines->tax_code_value = null;
//  }
// }
//}

//if (!empty($$class->hr_employee_id)) {
// $emp_details = hr_employee::find_by_id($$class->hr_employee_id);
// $$class->sales_person = $emp_details->first_name . ' ' . $emp_details->last_name;
//} else {
// $$class->sales_person = null;
//}
//
//if (!empty($$class->document_type)) {
// $document_type_i = sd_document_type::find_by_id($$class->document_type);
//}
//
//if (empty($$class->so_status)) {
// $$class->so_status = 'ENTERED';
//}

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

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

