<?php
/**********************************************************************
***********************************************************************/
$page_security = 'SA_ITEMSTRANSVIEW';
$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 . "/inventory/includes/db/stock_items_adjustment_inquiry_db.inc");
include_once($path_to_root . "/inventory/includes/db/petty_cash_item_issue_inquiry_db.inc");
include_once($path_to_root . "/petty_cash/includes/ui/petty_cash_ui.inc");
include_once($path_to_root . "/petty_cash/includes/db/i_owe_you_expenses_db.inc");
include_once($path_to_root . "/inventory/includes/db/petty_cash_item_receive_db.inc");

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


global $systypes_array;

$trans_type = ST_PETTY_CASH_ITEM_ISSUE;

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

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





function display_petty_cash_item_issue_header($trans_type, $trans_no)
{
        $batch = view_petty_cash_item_issue_header($trans_type, $trans_no);

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

        start_row();
            label_cells(_("Reference"), $batch['reference'], "class='tableheader2'");
            
            label_cells(_("Project"), $batch['project_description'], "class='tableheader2'");
            
        end_row();
        start_row();
            
            label_cells(_("Date"), sql2date($batch['tran_date']), "class='tableheader2'");            
            label_cells(_("company_code"), $batch['company_code'], "class='tableheader2'");
        end_row();
        start_row();
            label_cells(_("Location"), $batch['location_name'], "class='tableheader2'");
            label_cells(_("employee_code"), $batch['employee_code'], "class='tableheader2'");
//            label_cells(_("Batch No."), get_petty_cash_trans_view_str(ST_I_OWE_YOU_BATCH, $batch['iou_batch_no']), "class='tableheader2'");
        end_row();
        start_row();
            label_cells(_("Comment"), $batch['comment'], "class='tableheader2'", 'colspan=3 ');
            
        end_row();     
        start_row();
            
            
        end_row();
        
        end_table();
        
        return $batch["source_detail_id"];
}


function display_petty_cash_item_issue_details($trans_type, $trans_no)
{

    
    start_table(TABLESTYLE, "width=90%");
    $th = array( _("Receipt #"),   _("Itemcode"),_("Description") ,_("Tran. Unit"), _("Tran. Unit<br>Ave. Cost"), 
                    _("Quantity"),"Line Total", "Comment");
    table_header($th);
        
//    $expense_category_res = get_petty_cash_expense_category_invoices(EC_STOCK_ITEM_RECEIPT, $trans_no);
//    while ($invoice = db_fetch($expense_category_res))
//	{
    
        $result = view_petty_cash_item_issue_items($trans_type, $trans_no);
        

	$k = 0;
        $j = "";
        $total_cost = 0;                  
       
                
	while ($myrow = db_fetch($result))
	{                       
            alt_table_row_color($k);            
            $link = get_inventory_trans_view_str(ST_PETTY_CASH_ITEM_RECEIPT, $myrow["source_line_id"]);
            label_cell($link, "align=center");
            label_cell($myrow["stock_id"]);
            label_cell($myrow["display_item_description"]);
            label_cell($myrow["tran_unit"]);
            
            $tran_unit_cost = $myrow["unit_cost"] * $myrow["conversion_factor"];
            label_cell(number_format($tran_unit_cost, 2), "align=right");
            label_cell(number_format($myrow["tran_qty"], 2), "align=right");   
            $line_total = $tran_unit_cost * $myrow["tran_qty"];
            label_cell(number_format($line_total, 2), "align=right");  

            end_row();          

            $j++;

            $total_cost += $line_total ;                
	} 
        
        start_row();
            label_cell(text_bold("Total :"), "colspan=6 align=right");
            amount_cell($total_cost, true);
            label_cell("", "colspan=2");
        end_row();
                                                 
        
        end_table(2);
    
}

    
br();

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

br();

$source_detail_id = display_petty_cash_item_issue_header($trans_type, $trans_no);

//br(2);
//
//display_i_owe_you_batch_header($trans_no);

br(2);

display_petty_cash_item_issue_details($trans_type, $trans_no);



end_page(true, false, false, $trans_type, $trans_no);
?>







