<?php
/**********************************************************************
***********************************************************************/

$page_security = 'SA_PROJECT_SALES_ORDER_INQ';
$path_to_root = "../..";

include($path_to_root . "/includes/session.inc");

page(_($help_context = "View Inventory Transfer"), true);

include_once($path_to_root . "/includes/date_functions.inc");
include_once($path_to_root . "/includes/ui.inc");
include_once($path_to_root . "/gl/includes/gl_db.inc");
include_once($path_to_root . "/projects/includes/db/project_sales_orders_db.inc");
include_once($path_to_root . "/projects/includes/db/project_sales_orders_inquiry_db.inc");


if (isset($_GET["trans_no"]))
{
    $trans_no = $_GET["trans_no"];
}

$pso_header = view_project_sales_orders_header($trans_no);

display_heading('Project (Customer) Purchase Order' . " #$trans_no");

echo "<br>";
start_table(TABLESTYLE2, "width=40%");

start_row();

label_cells(_("Project"), $pso_header['project_description'], "class='tableheader2'");
end_row();
label_cells(_("Customer"), $pso_header['customer_name'], "class='tableheader2'");
end_row();
label_cells(_("Branch"), $pso_header['branch_name'], "class='tableheader2'");
end_row();
label_cells(_("Reference"), $pso_header['reference'], "class='tableheader2'");
end_row();
label_cells(_("Order Date"), sql2date($pso_header['ord_date']), "class='tableheader2'");
end_row();
label_cells(_("Payment Terms"), $pso_header['payment_terms'], "class='tableheader2'");
end_row();
label_cells(_("Sales Person"), $pso_header['salesman_name'], "class='tableheader2'");
end_row();
label_cells(_("PO Reference"), $pso_header['po_reference'], "class='tableheader2'");
end_row();
label_cells(_("Rate Include Taxes"), number_format($pso_header['rate_include_taxes'], 2), "class='tableheader2'");
end_row();
label_cells(_("Tax Group"), $pso_header['tax_group_name'], "class='tableheader2'");
end_row();

end_table(2);

//--------------------------------------------------------------------------------------------

start_table(TABLESTYLE, "width=80%");

$th = array(_("Type"), _("Details"), _("Unit"),_("Rate"), _("Quantity"), "Total", _("Comment"));                   

display_heading('Order Details');
table_header($th);

$pso_lines = view_project_sales_orders_details($trans_no);
$k = 0;
$lines_total = 0;
while ($item = db_fetch($pso_lines))
{
    alt_table_row_color($k);
    
    if($item['type'] == 0){
        $type = "Comment";
    }else{
        $type = "BOQ Item";
    }
    label_cell($type);
    if($item['type'] == 0){
        $item_description = $item['description'];
    }else{
        $item_description = $item['boq_iem_description'];
    }
    label_cell($item_description);
    
    $unit_name = isset($item['unit']) ? $item['unit'] : '';
    label_cell($unit_name);
    
    label_cell(number_format($item['order_unit_rate'], 2), "align=right");
    label_cell(number_format($item['quantity'], 2), "align=right");  
    label_cell(number_format($item['quantity'] * $item['order_unit_rate'], 2), "align=right");  
    label_cell($item['line_comment']);
    end_row();
    
    $lines_total += $item['quantity'] * $item['order_unit_rate'];
	
}

start_row();
label_cell(number_format($lines_total, 2), "align=right colspan=6");  
end_row();

$tax_included = $pso_header['rate_include_taxes'];
$taxes = get_project_sales_order_taxes($trans_no, 0);
display_edit_tax_items($taxes, 5, $tax_included, 2, false);
        
$sub_total = $lines_total;
if(!$tax_included){
    foreach ($taxes as $tax) {
        $sub_total += $tax['Value'];
    }
}

start_row();
label_cell("Amount Total", "colspan=5 align=right");
amount_decimal_cell($sub_total);
label_cell("");
//label_cell("");
end_row();
            
end_table(1);
//
//is_voided_display(ST_LOCTRANSFER, $trans_no, _("This transfer has been voided."));

end_page(true, false, false, ST_MATERIAL_REQ, $trans_no);




?>