<?php
/**********************************************************************
***********************************************************************/
$page_security = 'SA_MANUFTRANSVIEW';
$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/inventory.inc");
include_once($path_to_root . "/includes/data_checks.inc");
include_once($path_to_root . "/includes/ui/ui_input.inc");
include_once($path_to_root . "/manufacturing/includes/db/job_cost_adjustments_inquiry_db.inc");



$js = "";
if ($SysPrefs->use_popup_windows)
	$js .= get_js_open_window(800, 500);


if ($_GET['trans_no'] != "")
{
	$trans_no = $_GET['trans_no'];
}
if ($_GET['trans_type'] != "")
{
	$type = $_GET['trans_type'];
}

global $systypes_array, $approval_statuses;

page(_($help_context = "View ".$systypes_array[$type]), true, false, "", $js);

//-------------------------------------------------------------------------------------------------
$woid = 0;




function display_row($name, $value)
{
    start_row();        
    label_cells($name, $value, "width=70px class='tableheader2'", "width=60px");
    end_row();
    
}



function display_job_cost_adjustment_header($type, $trans_no) 
{ 
    global $approval_statuses, $systypes_array;
    
    start_table(TABLESTYLE, "width=50%");

    display_heading($systypes_array[$type]." #".$trans_no);

    br(2);
//table_header($th);

    $myrow = view_job_cost_adjustment_header($type, $trans_no);
    display_row("Reference",$myrow["reference"]);
    //display_row("Order No:",get_trans_view_str(ST_MANUF_REQUEST,$myrow["id"]));
    display_row("Project",$myrow["project_description"]);
    display_row("Job",$myrow["site_description"]);
    display_row("Date",sql2date($myrow["tran_date"]));    
    display_row("Approval Status",$approval_statuses[$myrow["approval_status"]]); 
    display_row("Comment",nl2br($myrow["comments"])); 
    


    end_table(3);

}

function display_job_cost_adjustment_details($type, $trans_no) 
{ 
    global $Ajax;
    
    $header = view_job_cost_adjustment_header($type, $trans_no);
    
    display_heading("Details");
    

    $Ajax->activate('nsit_details');
    div_start('nsit_details');
    
        start_table(TABLESTYLE, "width=60%");

            $th = array(_("ID"), _("Description"), _("Amount"), _('Line Comment'));  
            table_header($th);

            $k = 0; //row colour counter
            $result = view_job_cost_adjustment_details($trans_no, $type);      
            while ($row = db_fetch($result)) {
                alt_table_row_color($k);

                    label_cell($row['trans_id'], 'align=center');
                    label_cell($row["item_description"]); 

                    label_cell(number_format($row["cost"], 2), 'align=right');

                    label_cell(nl2br($row["line_comment"]));          


                end_row();        
            }
            
            start_row();
                label_cell(text_bold("Total"), 'align=right colspan=2');
                amount_cell($header['total'], true);
            end_row();

        end_table(3);
    
    div_end();
}




br(2);

display_job_cost_adjustment_header($type, $trans_no);


display_job_cost_adjustment_details($type, $trans_no);

end_page(true, false, false, ST_WORKORDER, $woid);

?>
