<?php
/**********************************************************************
***********************************************************************/
$page_security = 'SA_PETTYCASH_TRANSVIEW';
$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.inc");
include_once($path_to_root . "/petty_cash/includes/db/petty_cash_float_reimbursement_db.inc");
include_once($path_to_root . "/petty_cash/includes/db/i_owe_you_advances_inquiry_db.inc");
include_once($path_to_root . "/petty_cash/includes/ui/petty_cash_ui.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 . "/includes/ui/ui_input.inc");                


$js = "";
if ($SysPrefs->use_popup_windows)
	$js .= get_js_open_window(800, 500);
page(_($help_context = "I Owe You Advances"), true, false, "", $js);

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

global $approval_statuses;


function display_i_owe_you_advances_details($iou_no)
{
    div_start('price_table');
    
    start_table(TABLESTYLE2, "width=50%");

    $th = array("Batch #", _("Float"), _("Amount"), "Reimbursement");
    table_header($th);
    
    $q = view_i_owe_you_advances($iou_no);

    $total = 0;
    while ($iou = db_fetch($q))
    {     

        start_row();    
        $batch_link = get_petty_cash_trans_view_str(ST_I_OWE_YOU_ADVANCES_BATCH, $iou['batch_no']);
        display_pety_cash_detail_row($batch_link,"align=center");          
        display_pety_cash_detail_row($iou["float_name"],null);
        amount_decimal_cell($iou["amount"]);
        
        $link = get_petty_cash_trans_view_str(ST_PETTY_CASH_FLOAT_REIMBUR, $iou['float_reimbursement_id'], $iou['reimbursed_amount']);
        label_cell($link, 'align=right');

        $total += $iou["amount"];

        end_row();

    }


    start_row();    
        label_cell("Total advances:", "colspan=2 align=right");
        amount_cell($total, true); 
        label_cell("");
    end_row();



    end_table(1);  
    
    div_end();   
}

display_heading("Advances for I Owe You No: " . $id);
br();


display_i_owe_you_advances_details($id);

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

?>
