<?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_payments_db.inc");
include_once($path_to_root . "/transport/includes/db/supplier_transport_invoices_db.inc");
include_once($path_to_root . "/transport/includes/db/vehicle_allocation_db.inc");
include_once($path_to_root . "/transport/includes/db/vehicle_running_chart_entry_db.inc");


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

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

global $approval_statuses, $direct_petty_cash_payment_expence_sources;

display_heading("Petty Cash Payment No: " . $id);
br();
$myrow = view_petty_cash_direct_payment($id);

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

start_row();

$iou_link = get_petty_cash_trans_view_str(ST_I_OWE_YOU, $myrow['iou_id']);

label_cells(_("Float"), $myrow['float_name'], "class='tableheader2'");
end_row();
label_cells(_("Date"), sql2date($myrow['payment_date']), "class='tableheader2'");
end_row();
label_cells(_("Amount"), number_format($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();





switch ($myrow['expense_source']){
    case ST_SUPPLIER_TRANSPORT_INVOICES:
        $sti = get_supplier_transport_invoice_record_by_payment_source(ST_PETTY_CASH_DIRECT_PAYMENTS, $myrow['id']);
        $expense_no_link = get_transport_trans_view_str(ST_SUPPLIER_TRANSPORT_INVOICES, $sti["id"]);
//        label_cells("Supp. Transport Inv.", $sti_link,"align=center class='tableheader2'"); 
        break;

    case ST_VEHICLE_ALLOCATION:
        $va = get_vehicle_allocation_record_by_payment_source(ST_PETTY_CASH_DIRECT_PAYMENTS, $myrow['id']);
        $expense_no_link = get_transport_trans_view_str(ST_VEHICLE_ALLOCATION, $va["id"]);
//        label_cells("Vehicle Allocation", $vr_link,"align=center class='tableheader2'");  
//        label_cells(_("Expense"), $expense_id, "class='tableheader2'");
        break;
    
    case ST_VEHICLE_RUNNING_CHART:
        $vrc = get_vehicle_running_chart_entry_by_payment_source(ST_PETTY_CASH_DIRECT_PAYMENTS, $myrow['id']);
        $expense_no_link = get_transport_trans_view_str(ST_VEHICLE_RUNNING_CHART, $vrc["id"]);
//        label_cells("Vehicle Running Chart Entry", $vrc_link,"align=center class='tableheader2'"); 
        break;
    
    default:
        $expense_id = 0;
        break;
}

label_cells(_("Paid To"), $direct_petty_cash_payment_expense_sources[$myrow['expense_source']]." (".$expense_no_link.")", "class='tableheader2'");
end_row();
//$link = get_petty_cash_trans_view_str(ST_PETTY_CASH_FLOAT_ADJ, $myrow['float_reimbursement_id']);
//label_cells(_("Expense"), $expense_id, "class='tableheader2'");
//end_row();

$link = get_petty_cash_float_reimbursement_details_view_str(ST_PETTY_CASH_DIRECT_PAYMENTS, $id, number_format($myrow['reimbursed_amount'],2));
label_cells(_("Reimbursed Amount"), $link, "class='tableheader2'");

end_row();

end_table();

br(1);

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

?>
