<?php
if (!empty($$class->sd_quote_header_id)) {
 foreach ($sd_quote_line_object as &$sd_quote_lines) {
	if (!empty($sd_quote_lines->item_id_m)) {
	 $item = item::find_by_id($sd_quote_lines->item_id_m);
	 $sd_quote_lines->item_number = $item->item_number;
	}
 }
}

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;
}

//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_quote_line_object)) {
 foreach ($sd_quote_line_object as &$sd_quote_lines) {
	if (!empty($sd_quote_lines->item_id_m)) {
	 $item = item::find_by_id($sd_quote_lines->item_id_m);
	 $sd_quote_lines->item_number = $item->item_number;
	 $sd_quote_lines->uom_id = $item->uom_id;
	} else {
	 $sd_quote_lines->item_number = null;
	 $sd_quote_lines->uom_id = null;
	}
	if (!empty($sd_quote_lines->tax_code_id)) {
	 $tax = mdm_tax_code::find_by_id($sd_quote_lines->tax_code_id);
	 $sd_quote_lines->tax_code_value = (!empty($tax->percentage)) ? 'p_' . $tax->percentage : 'a_' . $tax->tax_amount;
	} else {
	 $sd_quote_lines->tax_code_value = null;
	}
 }
}

if(!empty($$class->document_type)){
 $document_type_i = sd_document_type::find_by_id($$class->document_type);
}

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

if ((!empty($$class->status)) && (in_array($$class->status, array('CANCELLED','CLOSED')))) {
 $mode = 2;
 $readonly = 1;
}

?>

