<?php
if (!empty($_GET['bu_org_id']) && (!is_array($_GET['bu_org_id']))) {
 $$class->bu_org_id = $_GET['bu_org_id'];
}

if (!empty($_GET['sd_so_header_id']) && (!is_array($_GET['sd_so_header_id']))) {
 $$class->sd_so_header_id = $_GET['sd_so_header_id'];
 $$class->get_details_from_sd_so_header();
}

if (!empty($$class->bu_org_id) ) {
  $legal_org_id = org::find_by_id($$class->bu_org_id)->legal_org_id;
 $ledger_id = legal::find_by_orgId($legal_org_id)->ledger_id;
 $$class->ledger_id = $ledger_id;
}

if (!empty($$class->om_so_header_id)) {
 $po = new om_so_header();
 $om_so_i = $po->findBy_id($$class->om_so_header_id);
 $$class->om_so_number = $om_so_i->om_so_number;
}

if (!empty($$class->ledger_id)) {
 $ledger = new gl_ledger();
 $ledger_i = $ledger->findBy_id($$class->ledger_id);
 if($ledger_i){
 $$class->currency = $ledger_i->currency_code;
 }
 $gp = new gl_period();
 $all_open_periods = $gp->find_all_periods($$class->ledger_id, 'OPEN');
 if (empty($$class->period_id)) {
	$$class->period_id = $gp->current_open_period($$class->ledger_id, 'OPEN')->gl_period_id;
 }
 $period_name_stmt = form::select_field_from_object('period_id', $all_open_periods, 'gl_period_id', 'period_name', $$class->period_id, 'gl_period_id', '', '', '', 1);
}

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(isset($ar_transaction_header)){
$customer_name_stmt = $f->text_field('customer_name', $ar_transaction_header->customer_name, '20', 'customer_name', 'select_customer_name', 1, $readonly1);
$customer_number_stmt = $f->text_field('customer_number', $ar_transaction_header->customer_number, '8', 'customer_number', 'select_customer_number', 1, $readonly1);
}

if (!empty($ar_transaction_line_object)) {
 foreach ($ar_transaction_line_object as &$ar_transaction_lines) {
	if (!empty($ar_transaction_lines->item_id_m)) {
	 $item = item::find_by_id($ar_transaction_lines->item_id_m);
	 $ar_transaction_lines->item_number = $item->item_number;
	} else {
	 $ar_transaction_lines->item_number = null;
	 }
 }
}

if((empty($$class->transaction_status))){
$$class->transaction_status = 'INCOMPLETE';
}

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