<?php
/**********************************************************************
***********************************************************************/
$page_security = 'SA_PAYROLLTRANSVIEW';
$path_to_root = "../..";

include($path_to_root . "/includes/session.inc");

page(_($help_context = "View Payroll Summary"), true);

include_once($path_to_root . "/includes/date_functions.inc");
include_once($path_to_root . "/includes/ui.inc");
include_once($path_to_root . "/payroll/includes/db/payroll_inquiry_db.inc");
include_once($path_to_root . "/payroll/includes/db/loans_db.inc");
include_once($path_to_root . "/payroll/includes/db/employees_db.inc");
include_once($path_to_root . "/payroll/includes/db/loan_installments_db.inc");

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


br();

display_heading("Loan Id #$trans_no");

br(1);

$loan = get_loan_details($trans_no);
if($loan){
    $employee = get_employee($loan['employee_code']);
    if($employee){
        display_heading2("Loan Details");
        br(1);
        start_table(TABLESTYLE, "width=50%");
            label_cells("Employee", $employee['employee_code']." - ".$employee['last_name'], "class='tableheader2'", "width=200px");
            end_row();
            start_row();  
            label_cells("Description", $loan['loan_description'], "class='tableheader2'", "width=200px");
            end_row();
            start_row();
            label_cells("Loan Amount", $loan['loan_amount'], "class='tableheader2'", "width=200px");
            end_row();
            start_row();
            label_cells("Installment Amount", $loan['installment_amount'], "class='tableheader2'", "width=200px");
            end_row();
            start_row();
            label_cells("Start Date", sql2date($loan['start_date']), "class='tableheader2'", "width=200px");
            end_row();
//            start_row();
//            label_cells("Total Paid", $loan['total_paid'], "class='tableheader2'", "width=200px");
//            end_row();
            
            $on_hold = "No";
            if($loan['inactive'] == 1){
                $on_hold = "Yes";
            }
            start_row();
            label_cells("On Hold", $on_hold, "class='tableheader2'", "width=200px");
            end_row();
            
            $completed = "No";
            if($loan['completed'] == 1){
                $completed = "Yes";
            }
            start_row();
            label_cells("Completed", $completed, "class='tableheader2'", "width=200px");
            end_row();
        end_table();  
    }
}
else{
    display_heading2("Loan id sent is invalid");
}

     
br(1);        

display_heading2("Installment Details");
br(1);  

$result = get_loan_installments($trans_no);
$k = 0;
$header_shown = false;

        
        $th = array( _("Date"), _("Installment"),_("Payroll Run"));
            
        start_table(TABLESTYLE, "width=50%");
        table_header($th);

while ($myrow = db_fetch($result))
{	
    //start_row();
    alt_table_row_color($k);
    label_cell(substr($myrow["created_on"],0,10),"align=center"); 
    label_cell($myrow["installment_amount"],"align=right");   
    label_cell($myrow["payroll_run_id"],"align=center");

    end_row();
}

end_table(1);


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