<?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_adjustments_db.inc");


$js = "";
if ($SysPrefs->use_popup_windows)
	$js .= get_js_open_window(800, 500);
page(_($help_context = "View Petty Cash Float Entry"), true, false, "", $js);

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

global $systypes_array, $approval_statuses;

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



function display_transaction_currency_denomination_details($type_id, $type_no)
{ 
    $result = view_petty_cash_transaction_currency_denominations($type_id, $type_no);    
    if(db_num_rows($result) == 0){
        $m = "No currency denomination details found.";
        display_note($m);
        br(2);
        return;
    }
    
    start_table(TABLESTYLE2, 'width=20%');    
    
    $th = array(_("Denomination"),_("Quantity"), "Amount");
    table_header($th);
    
    $total = 0;
    while ($row = db_fetch($result)) {

        start_row();
            $quantity = $row['quantity'];
            if(!($quantity > 0)){
                continue;
            }
            label_cell($row['value_name'].spaces(5), 'align=right');
            label_cell($quantity, 'align=right'); 
            $denomination_value = (int)$row['value_code'];
            $line_total =  $denomination_value * $quantity;
            label_cell(number_format($line_total, 2), 'align=right');
        end_row();
        
        $total += $line_total;
    }
    
    start_row();
        label_cell(text_bold("Total"), 'align=right colspan=2'); 
        label_cell(text_bold(number_format($total, 2)), 'align=right');
    end_row();    
    
    end_table(2);
    
}




$myrow = view_petty_cash_float_adjustment_by_type_id_and_trans_no($type_id, $trans_no);

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

start_row();

label_cells(_("Reference"), $myrow['reference'], "class='tableheader2'");
end_row();
if ($myrow['type'] == ST_FLOAT_TRANSFER) {
    label_row(_("From Float"), $myrow['float_name'], "class='tableheader2'");
    label_row(_("To Float"), $myrow['to_float_name'], "class='tableheader2'");
} else {
    label_cells(_("Float"), $myrow['float_name'], "class='tableheader2'");
    end_row();
}
label_cells(_("Date"), sql2date($myrow['tran_date']), "class='tableheader2'");
end_row();
label_cells(_("Type"), ($myrow['is_return'] == 1?"Deduct from float": "Add to float"), "class='tableheader2'");
end_row();
label_cells(_("Amount"), number_format(abs($myrow['amount']),2), "class='tableheader2'");
end_row();
label_cells(_("Comment"), $myrow['comment'], "class='tableheader2'");
end_row();

label_cells(_("Created By"), $myrow['user_name'], "class='tableheader2'");
end_row();

//$link = get_petty_cash_trans_view_str(ST_PETTY_CASH_FLOAT_REIMBUR, $myrow['float_reimbursement_id']);
//label_cells(_("Reimbursement"), $link, "class='tableheader2'");

$link = get_petty_cash_float_reimbursement_details_view_str($type_id, $trans_no, number_format($myrow['reimbursed_amount'],2));
//$link = get_petty_cash_trans_view_str(ST_PETTY_CASH_FLOAT_REIMBUR, $myrow['reimbursed_amount']);
label_cells(_("Reimbursed Amount"), $link, "class='tableheader2'");

end_row();

label_row(_("Source Type"), $myrow['source_type'] > 0 ? $systypes_array[$myrow['source_type']] : '', "class='tableheader2'");
label_row(_("Source Trans #"), $myrow['source_trans_no'] > 0 ? get_payroll_trans_view_str($myrow['source_type'], $myrow['source_trans_no']) : '', "class='tableheader2'");

end_table(2);


display_transaction_currency_denomination_details($type_id, $trans_no);

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

?>
