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

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

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


include_once($path_to_root . "/includes/date_functions.inc");
include_once($path_to_root . "/includes/ui.inc");
include_once($path_to_root . "/projects/includes/db/miscellaneous_project_cost_inquiry_db.inc");

$js = "";
if ($SysPrefs->use_popup_windows)
	$js .= get_js_open_window(800, 500);
page(_($help_context = "View Miscellaneous Project Cost"), true, false, "", $js);

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

$mpc_header = view_miscellaneous_pc_header($trans_no);

display_heading('Miscellaneous Project Cost' . " #$trans_no");

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

start_row();

label_cells(_("Reference"), $mpc_header['reference'], "class='tableheader2'");
end_row();
label_cells(_("Project"), $mpc_header['project_description'], "class='tableheader2'");
end_row();
label_cells(_("Date"), sql2date($mpc_header['date']), "class='tableheader2'");
end_row();
label_cells(_("Comments"), $mpc_header['comment'], "class='tableheader2'");
end_row();


$s = get_project_trans_view_str(ST_APPROVAL_LOG, $mpc_header['id']."&source_type_id=".ST_MISCELLANEOUS_PROJECT_COST, "Approval Status");
        label_cells($s,$approval_statuses[$mpc_header['approval_status']], "class='tableheader2'");  

end_table(2);

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

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

$th = array(_("Description."), _("Units"),
            _("Quantity"), _("Rate"), _("Amount"), _("BOQ Group"), 
            _("Budget "), _("Type"));                   

display_heading('Miscellaneous Project Cost Details');
table_header($th);

$mpc_lines = view_miscellaneous_pc_details($trans_no);
$k = 0;
$total_amount=0;

while ($item = db_fetch($mpc_lines))
{
    alt_table_row_color($k);
     
    label_cell($item['description']);
    label_cell($item['unit_name']);
    label_cell($item['quantity'], "align=right");
    label_cell($item['rate'], "align=right");
    
    $amount = $item['quantity'] * $item['rate'];
    label_cell(number_format($amount, 2), "align=right");
    label_cell($item['boq_item_group_description']);
    label_cell($item['budget_name']);
    label_cell($item['miscellaneous_type']); 
//    label_cell($item['comment']);
        
    $total_amount += $amount; 
    end_row();
    
            if(strlen($item["debit_account"]) > 0){
                $debit_account_name = "<b>Debit A/C:</b> ".$item["debit_account"]." - ".$item["debit_account_name"];
            }
            else{
                $debit_account_name = "<b>Debit A/C:</b> No account selected";
            }
            
            if(strlen($item["credit_account"]) > 0){
                $credit_account_name = "<b>Credit A/C:</b> ".$item["credit_account"]." - ".$item["credit_account_name"];
            }
            else{
                $credit_account_name = "<b>Debit A/C:</b> No account selected";
            }
            
            
            $details = $debit_account_name.spaces(5).$credit_account_name;
        
        
            if(strlen($details) > 0){
                alt_table_row_color($k);
                label_cell('');
                label_cell($details, "colspan=8 align=right");
                end_row();
            }

            if(strlen($item["comment"]) > 0){
                alt_table_row_color($k);                
                label_cell("<b>Comment:</b> ".$item["comment"], "colspan= 8 align=right");
                end_row(); 
            }
    
}
    
start_row();
label_cell("");
label_cell("");

label_cell("Total", "colspan=2") ;
label_cell(number_format($total_amount, 2), "align=right");

label_cell("");
label_cell("");
label_cell("");
end_row();

end_table(1);

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



?>