<?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_requests_inquiry_db.inc");
include_once($path_to_root . "/projects/includes/db/projects_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 Request"), true, false, "", $js);

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

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

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

        $myrow = view_asset_quantity_adjustment_request($asset_qty_ajt_req_id);

        start_row();
            label_cells("Reference", $myrow['reference'], "class='tableheader2'");
        end_row();
        start_row();
            $project_name = get_project_formatted_name(45);
            label_cells(_("Project"), $project_name, "class='tableheader2'");
        end_row();
        start_row();
            label_cells(_("Location"), $myrow['location_name'], "class='tableheader2'");
        end_row();
        start_row();
        $is_deduction = ($myrow['is_deduction'] == 1) ? "Yes" : "No";
        label_cells(_("Deduction"), $is_deduction, "class='tableheader2'");
        end_row();
        start_row();
            label_cells(_("Date"), sql2date($myrow['tran_date']), "class='tableheader2'");
        end_row();
        start_row();
            label_cells(_("Comment"), $myrow['comment'], "class='tableheader2'");
        end_row();
        start_row();
            label_cells(_("Total"), number_format($myrow['total'], 2), "class='tableheader2'");
        end_row();
//        start_row();
//            $created_by = get_user($myrow['created_by']);
//            label_cells(_("Created BY"), $created_by['real_name'], "class='tableheader2'");
//        end_row();
//        start_row();
//            label_cells(_("Created On"), sql2date($myrow['created_on']), "class='tableheader2'");
//        end_row();
//        start_row();
//            $updated_by = get_user($myrow['updated_by']);
//            label_cells(_("Updated BY"), $updated_by['real_name'], "class='tableheader2'");
//        end_row();
//        start_row();
//            label_cells(_("Updated On"), sql2date($myrow['updated_on']), "class='tableheader2'");
//        end_row();
//        start_row();
//            $approved_by = get_user($myrow['approved_by']);
//            label_cells(_("Approved BY"), $approved_by['real_name'], "class='tableheader2'");
//        end_row();
//        start_row();
//            label_cells(_("Approved On"), sql2date($myrow['approved_on']), "class='tableheader2'");
//        end_row();

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

    end_table(2);

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

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

        display_heading("Asset Quantity Adjustment Request Details");
        br();
        $result = view_asset_quantity_adjustment_request_details($asset_qty_ajt_req_id);

        $th = array(_("ID"),_("Asset"), _('Site'), _("Budget"), _("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["asset_code"]."-".$row["asset_description"]."-"."(".$row["asset_id"].")");  
            label_cell($row['site_description']);
//            label_cell(($row['is_deduction'] == 1) ? "Yes" : "No", "align=center");
            label_cell($row["task_description"]."(".($row["task_code"]).")");  
            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");

            if(strlen($row['line_comment']) > 0){
                start_row();
                    $k +=1;
                    label_cell('');
                    label_cell('<b>Comment :</b> '.$row['line_comment'], 'colspan=8');
                end_row();
            }
            $line_total += $line_cost;
            $k++;
        }
        
        start_row();
            label_cell("Total", "colspan=7 align=right");
            amount_cell($line_total, true);    
        end_row();

    end_table(2);

end_page(true, false, false, ST_ASSET_QUANTITY_ADJUSTMENT_REQUEST, $asset_qty_ajt_req_id);

?>