<?php

$prl = new sys_profile_line();

if ($$class->po_type == 'BLANKET_RELEASE') {
 $$class = new po_header();
 $po_line_object = array(new po_line());
 $po_detail_object = array(new po_detail());
 $access_denied_msg = "<br>You cant open releases in this form. Use PO release form";
}

if (!empty($$class->po_header_id)) {
 foreach ($po_line_object as &$po_lines) {
  if (!empty($po_lines->item_id_m)) {
   $item = item::find_by_id($po_lines->item_id_m);
   $po_lines->item_number = $item->item_number;
  }
  if (!empty($po_lines->tax_code_id)) {
   $tax = mdm_tax_code::find_by_id($po_lines->tax_code_id);
   $po_lines->tax_code_value = (!empty($tax->percentage)) ? 'p_' . $tax->percentage : 'a_' . $tax->tax_amount;
  } else {
   $po_lines->tax_code_value = null;
  }
 }
} else {
 $buyer = ino_user::find_by_user_name($session->username);
 if ($buyer) {
  $$class->buyer = $buyer->first_name . ' ' . $buyer->last_name;
 }
 if (empty($$class->po_status)) {
  $$class->po_status = 'ENTERED';
 }
}

//asign values of fields on form but not in databse only if $$class->$primary_cloumn is not nul
if (!empty($$class->po_header_id)) {
 $supplier_details = supplier::find_by_id($$class->supplier_id);
 $$class->supplier_name = $supplier_details->supplier_name;
 $$class->supplier_number = !empty($supplier_details->supplier_number) ? $supplier_details->supplier_number : null;
}

$action_readonly = false;
//Action values
if(in_array($$class->po_status, array('CLOSED', 'INPROCESS', 'CANCELLED' , ''))){
 $action_readonly = 1;
 $mode = 2;
 $readony = 1;
 return;
}

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



$$class->exchange_rate = !empty($$class->exchange_rate) ? $$class->exchange_rate : 1;
if (empty($$class->po_header_id)) {
 $$class->action_a = array(null);
}

if($$class->po_status != 'ENTERED'){
 $readonly = 1;
}

if (empty($$class->po_type)) {
 $$class->po_type = 'STANDARD';
}
?>