<?php

 if ((!empty($_GET['view_type'])) && ($_GET['view_type'] != 'list')&&empty($$class->po_quote_header_id) && empty($_GET['po_rfq_header_id'])) {
  $access_denied_msg =  "<br>Wrong selection of Quote or RFQ";
 }

 if (!empty($$class->po_quote_header_id)) {
  if ((!empty($$class->po_rfq_header_id))) {
   $rfq_i = po_rfq_header::find_by_id($$class->po_rfq_header_id);
   foreach ($rfq_i as $k => $v) {
    if (empty($$class->$k) && !empty($v)) {
     $$class->$k = $v;
    }
   }
  }
  if (!empty($po_quote_line_object)) {
   foreach ($po_quote_line_object as &$po_quote_line1) {
    $rfq_line_a = po_rfq_line::find_by_id($po_quote_line1->po_rfq_line_id);
    if ($rfq_line_a) {
     foreach ($rfq_line_a as $k => $v) {
      if (empty($po_quote_line1->$k) && !empty($v)) {
       $po_quote_line1->$k = $v;
      }
     }
    } else {
     $rfq_line = new po_rfq_line();
     foreach ($rfq_line as $k => $v) {
      if (empty($po_quote_line1->$k)) {
       $po_quote_line1->$k = $v;
      }
     }
    }
   }
  }
 } else if (!empty($_GET['po_rfq_header_id'])) {
  $rfq_i = po_rfq_header::find_by_id($_GET['po_rfq_header_id']);
  foreach ($rfq_i as $k => $v) {
   if (!empty($v)) {
    $$class->$k = $v;
   }
  }
  $po_quote_line_object = [];
  $rfq_line_a = po_rfq_line::find_by_parent_id($_GET['po_rfq_header_id']);
  foreach ($rfq_line_a as $rfq_line) {
   $po_quote_line_value = new po_quote_line();
   foreach ($rfq_line as $k => $v) {
    if (!empty($v)) {
     $po_quote_line_value->$k = $v;
    }
   }
   array_push($po_quote_line_object, $po_quote_line_value);
  }
 }

 if (!empty($po_quote_line_object)) {
  foreach ($po_quote_line_object as &$po_quote_lines) {
   if (!empty($po_quote_lines->item_id_m)) {
    $item = item::find_by_id($po_quote_lines->item_id_m);
    $po_quote_lines->item_number = $item->item_number;
   }
  }
 }

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

 //Action values
 $action_readonly = in_array($$class->quote_status, array('CLOSED', 'INPROCESS', '')) ? 1 : '';
 if (empty($$class->po_quote_header_id)) {
  $$class->action_a = array(null);
 }

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

 if (!empty($$class->supplier_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;
 }
?>