<?php
/**********************************************************************
***********************************************************************/
$page_security = 'SA_ASSETTRANSVIEW';
$path_to_root = "../..";

include_once($path_to_root . "/includes/session.inc");
include_once($path_to_root . "/includes/date_functions.inc");
include_once($path_to_root . "/includes/data_checks.inc");
include_once($path_to_root . "/includes/ui.inc");
include_once($path_to_root . "/assets/includes/db/asset_quantity_adjustment_inquiry_db.inc");
include_once($path_to_root . "/includes/common_functions.inc");     
include_once($path_to_root . "/includes/db/group_companies_db.inc");   
include_once($path_to_root . "/admin/db/users_db.inc"); 

$js = "";
if ($SysPrefs->use_popup_windows)
	$js .= get_js_open_window(800, 500);
page(_($help_context = "View Asset Quantity Adjustment"), true, false, "", $js);

//-------------------------------------------------------------------------------------------------
$woid = 0;
if($_GET['trans_no'] != ""){
    $asset_transfer_id = $_GET['trans_no'];
}

display_heading("Asset Quantity Adjustment No: " . $asset_transfer_id);
    br();

    start_table(TABLESTYLE2, "width=60%");

        $row = view_asset_quantity_adjustment_header($asset_transfer_id);
        start_row();
            label_cells("Reference", $row['reference'], "class='tableheader2'");
        end_row();
        start_row();
            label_cells("Asset Quantity Adjustment Request Id", $row['aqar_id'], "class='tableheader2'");
        end_row();
        start_row();
            label_cells(_("Company"), get_group_company_name($row['company_code']), "class='tableheader2'");
        end_row();
        start_row();
            $employee_name = get_group_company_employee($row['company_code'], $row['employee_code']);
            label_cells(_("Employee"), $employee_name['employee_code'].' - '.$employee_name['initials'].' '.$employee_name['last_name'], "class='tableheader2'");
        end_row();
        start_row();
            label_cells(_("Date"), sql2date($row['tran_date']), "class='tableheader2'");
        end_row();
        start_row();
            label_cells(_("Comment"), $row['comment'], "class='tableheader2'");
        end_row();
        start_row();
            label_cells(_("Total"), number_format($row['total'], 2), "class='tableheader2'");
        end_row();
//        start_row();
//            $created_by = get_user($row['created_by']);
//            label_cells(_("Created BY"), $created_by['real_name'], "class='tableheader2'");
//        end_row();
//        start_row();
//            label_cells(_("Created On"), sql2date($row['created_on']), "class='tableheader2'");
//        end_row();

    end_table(2);

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

    start_table(TABLESTYLE2, "width=98%");

        display_heading("Asset Quantity Adjustment Details");
        br();
        $result = view_asset_quantity_adjustment_details($asset_transfer_id);

        $th = array(_("Line ID"), _("Req. Line ID"), _('Asset'), _("Quantity"), _("Asset Value"), _('Line Total'));  

        table_header($th);
        $k = 0; //row colour counter

        $line_total =0;
        while($row = db_fetch($result)){

            alt_table_row_color($k);

            label_cell($row['id'], "align=center");
            label_cell($row['aqar_line_id'], "align=center");
            label_cell($row['asset_code']."-".$row['asset_description']."-"."(".$row['asset_id'].")");
            label_cell(number_format($row['quantity'], 2), "align=right");
            label_cell(number_format($row['asset_value'], 2), "align=right");
            $line_cost = $row["asset_value"] * $row["quantity"];
            label_cell(number_format($line_cost, 2), "align=right");
            
            $line_total += $line_cost;
            $k++;
        }
        
        start_row();
            label_cell("Total", "colspan=5 align=right");
            amount_cell($line_total, true);    
        end_row();

    end_table(1);

end_page(true, false, false, ST_ASSET_QUANTITY_ADJUSTMENT, $asset_transfer_id);

?>