<?php

//asign values of fields on form but not in databse only if $$class->$primary_cloumn is not null

if (!empty($$class->address_id)) {
 $ad_i = address::find_by_id($$class->address_id);
 foreach ($ad_i as $k => $v) {
  if (!in_array($k, array('description','status'))) {
   $$class->$k = $v;
  }
 }
}

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->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 ((is_object($$class)) && empty($$class->status)) {
 $$class->status = 'ENTERED';
}

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