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

include_once($path_to_root . "/includes/session.inc");
include_once($path_to_root . "/includes/ui/ui_input.inc");



include_once($path_to_root . "/includes/date_functions.inc");
include_once($path_to_root . "/includes/ui.inc");
include_once($path_to_root . "/includes/common_functions.inc");


include_once($path_to_root . "/projects/includes/db/project_transaction_type_transactions_db.inc");
include_once($path_to_root . "/projects/includes/db/tasks_db.inc");
include_once($path_to_root . "/projects/includes/db/projects_db.inc");


include_once($path_to_root . "/admin/db/list_values_db.inc");
include_once($path_to_root . "/includes/db/group_companies_db.inc");

$js = '';

if ($SysPrefs->use_popup_windows) {
	$js .= get_js_open_window(900, 500);
}

if (user_use_date_picker()) {
	$js .= get_js_date_picker();
}


simple_page_mode(true);

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

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

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

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



page(_($help_context = "Project Transactions"), true, false, false, $js);

function display_subheading($project_id, $subheading)
{
    $project = get_project_record($project_id);
    $text = $subheading.' for project "'.$project['description'].'"';
    display_heading($text);
    
    br(1);
    
    start_table(TABLESTYLE, "width=70%");

    $th = array(_("Date"), _("No"), _("Reference"), "Supplier / Employee / Package", "Amount");
     

    table_header($th);

}

function display_subtotals($total_amount, $subheading)
{
    label_cell("Total for ".$subheading." :","align=right colspan=4");
    label_cell(text_bold(number_format($total_amount,2)),"align=right");

    
    end_table();
}

function print_material_issues($project_id, $type, $from_date, $to_date)
{
        $total_amount = $total_settlement = 0;

        $subheading = "Material Issues";

        $invoices_result= get_material_issues($type, $project_id, $from_date, $to_date);
        
        if(!(db_num_rows($invoices_result) > 0)){
            $msg = "No Material Issues found";
            display_note($msg);
            return;
        }
                  
        display_subheading($project_id, $subheading);
        
        while( $inv = db_fetch($invoices_result))
        {
            start_row();
            label_cell(sql2date($inv['im_date']),"align=center");
            $link = get_trans_view_str($type, $inv['im_no']);
            label_cell($link, "align=center");
            label_cell($inv['reference']);
            
            $emp_name = '';
            if(strlen($inv['employee_code']) > 0){
                $emp_name = get_group_company_employee_formatted_long_name($inv['company_code'], $inv['employee_code']);
            }
            label_cell($emp_name);
            $amount = $inv["total_cost"];
            label_cell(number_format($amount,2), "align=right");
            //$rep->TextCol(5, 6, number_format($amount));
            
            end_row();
                  
            $total_amount += $amount;
            $total_settlement += $amount;
            
//            print_material_purchase_credit_notes($inv['trans_no'], ST_SUPPCREDIT, $inv['supp_name'], $total_amount, $total_settlement);
        
        }

        display_subtotals($total_amount, $subheading);
}

function print_material_returns($project_id, $type, $from_date, $to_date)
{
        $total_amount = $total_settlement = 0;

        $subheading = "Material Returns";

        
        $invoices_result= get_material_returns($type, $project_id, $from_date, $to_date);
        
        if(!(db_num_rows($invoices_result) > 0)){
            $msg = "No Material Returns found";
            display_note($msg);
            return;
        }
        
        display_subheading($project_id, $subheading);
                  
        
        while( $inv = db_fetch($invoices_result))
        {
            start_row();
            label_cell(sql2date($inv['rm_date']),"align=center");
            $link = get_trans_view_str($type, $inv['rm_no']);
            label_cell($link, "align=center");
            label_cell($inv['reference']);
            
            $emp_name = '';
            if(strlen($inv['employee_code']) > 0){
                $emp_name = get_group_company_employee_formatted_long_name($inv['company_code'], $inv['employee_code']);
            }

            label_cell($emp_name);
            $amount = $inv["total_cost"];
            label_cell(number_format($amount,2), "align=right");

                  
            $total_amount += $amount;
            $total_settlement += $amount;
            
            end_row();
            

        }
        
        display_subtotals($total_amount, $subheading);
}

function print_daily_item_issues($project_id, $type, $from_date, $to_date)
{
        $total_amount = $total_settlement = 0;

        $subheading = "";
        if($type == ST_DAILY_ITEM_ISSUE){
            $subheading = "Daily Item Issues";
        }elseif($type == ST_DAILY_ITEM_RETURN){
            $subheading = "Daily Item Returns";
        }

        $invoices_result= get_daily_item_issues($type, $project_id, $from_date, $to_date);
        
        if(!(db_num_rows($invoices_result) > 0)){
            $msg = "";
            if($type == ST_DAILY_ITEM_ISSUE){
                $msg = "No Daily Item Issues found";
            }elseif($type == ST_DAILY_ITEM_RETURN){
                $msg = "No Daily Item Returns found";
            }
            
            display_note($msg);
            return;
        }
                  
        display_subheading($project_id, $subheading);
        
        while( $inv = db_fetch($invoices_result))
        {
            start_row();
            label_cell(sql2date($inv['tran_date']),"align=center");
            $link = get_inventory_trans_view_str($type, $inv['trans_no']);
            label_cell($link, "align=center");
            label_cell($inv['reference']);
            
            $movement_type_name = $inv['movement_type_name'];
            label_cell($movement_type_name);
            
            if($type == ST_DAILY_ITEM_ISSUE){
                $amount = $inv["total_cost"];
            }elseif($type == ST_DAILY_ITEM_RETURN){
                $amount = -$inv["total_cost"];
            }
            label_cell(number_format($amount,2), "align=right");
            //$rep->TextCol(5, 6, number_format($amount));
            
            end_row();
                  
            $total_amount += $amount;
            $total_settlement += $amount;
            
//            print_material_purchase_credit_notes($inv['trans_no'], ST_SUPPCREDIT, $inv['supp_name'], $total_amount, $total_settlement);
        
        }

        display_subtotals($total_amount, $subheading);
}


function print_material_purchased_invoices($project_id, $type, $from_date, $to_date)
{
        $total_amount = $total_settlement = 0;

        $subheading = "Material Purchased Invoices";

        $invoices_result= get_material_purchased_invoices($type, $project_id, $from_date, $to_date);
        
        if(!(db_num_rows($invoices_result) > 0)){
            $msg = "No Material Purchase invoices found";
            display_note($msg);
            return;
        }
        
        display_subheading($project_id, $subheading);
                  
        
        while( $inv = db_fetch($invoices_result))
        {
            start_row();
            label_cell(sql2date($inv['tran_date']),"align=center");
            $link = get_trans_view_str($type, $inv['trans_no']);
            label_cell($link, "align=center");
            label_cell($inv['reference']);
            
            label_cell($inv['supp_name']);
//            $amount = $inv["ov_amount"] - $inv["ov_discount"] + $inv["ov_gst"];
            $amount = $inv["amount"];
            amount_cell($amount);
                  
            $total_amount += $amount;
            $total_settlement += $inv["alloc"];
            
            end_row();
        }
        
        display_subtotals($total_amount, $subheading);
}


function print_material_purchase_credit_notes($project_id, $type, $from_date, $to_date)
{
        $total_amount = $total_settlement = 0;

        $subheading = "Material Purchased Credit Notes";

        $invoices_result= get_material_purchased_credit_notes($type, $project_id, $from_date, $to_date);
        
        if(!(db_num_rows($invoices_result) > 0)){
            $msg = "No Material Purchased Credit Notes";
            display_note($msg);
            return;
        }
        
        display_subheading($project_id, $subheading);
        
        while( $inv = db_fetch($invoices_result))
        {
            start_row();
            label_cell(sql2date($inv['tran_date']),"align=center");
            $link = get_trans_view_str($type, $inv['trans_no']);
            label_cell($link, "align=center");
            label_cell($inv['reference']);
            
            label_cell($inv['supp_name']);
//            $amount = $inv["ov_amount"] - $inv["ov_discount"] + $inv["ov_gst"];
            $amount = $inv["amount"];
            
            amount_cell($amount);
                  
            $total_amount += $amount;
            $total_settlement += -$inv["alloc"];
            end_row();
        }
        
        display_subtotals($total_amount, $subheading);
}


function print_subcontractor_invoices($project_id, $type, $from_date, $to_date)
{
        $total_amount = $total_settlement = 0;

        $subheading = "Subcontractor Invoices";

        $invoices_result= get_subcontractor_invoices($type, $project_id, $from_date, $to_date);
        
        if(!(db_num_rows($invoices_result) > 0)){
            $msg = "No Subcontractor invoices found";
            display_note($msg);
            return;
        }
        
        display_subheading($project_id, $subheading);
        
        while( $inv = db_fetch($invoices_result))
        {
            start_row();
            label_cell(sql2date($inv['tran_date']),"align=center");
            $link = get_trans_view_str($type, $inv['trans_no']);
            label_cell($link, "align=center");
            label_cell($inv['reference']);
            
            label_cell($inv['supp_name']);
            $amount = $inv["ov_amount"] - $inv["ov_discount"];// + $inv["ov_gst"];
            amount_decimal_cell($amount); 

            $total_amount += $amount;
            $total_settlement += $inv["alloc"];
        
            end_row();
        }
        
        display_subtotals($total_amount, $subheading);
}

function print_subcontractor_credit_notes($project_id, $type, $from_date, $to_date)
{
        $total_amount = $total_settlement = 0;

        $subheading = "Subcontractor Credit Notes";

        $invoices_result= get_subcontractor_credit_notes($type, $project_id, $from_date, $to_date);
        
        if(!(db_num_rows($invoices_result) > 0)){
            $msg = "No Subcontractor Credit Notes found";
            display_note($msg);
            return;
        }
        
        display_subheading($project_id, $subheading);
        
        while( $inv = db_fetch($invoices_result))
        {
            start_row();
            label_cell(sql2date($inv['tran_date']),"align=center");
            $link = get_trans_view_str($type, $inv['trans_no']);
            label_cell($link, "align=center");
            label_cell($inv['reference']);
            
            label_cell($inv['supp_name']);
            $amount = $inv["ov_amount"] - $inv["ov_discount"];// + $inv["ov_gst"];
            amount_decimal_cell($amount); 
            $allocation = -$inv["alloc"];
                  
            $total_amount += $amount;
            $total_settlement += $allocation;
        
            end_row();
        }
        
        display_subtotals($total_amount, $subheading);
}

function print_transport_expenses($project_id, $from_date, $to_date)
{
        $total_amount = $total_settlement = 0;
        $subheading = "Transport Expenses (Package Based Costs)";
         
        $iou_result= get_vehicle_running_chart_entries($project_id, $from_date, $to_date);
        
        if(!(db_num_rows($iou_result) > 0)){
            $msg = "No Transport Expenses found";
            display_note($msg);
            return;
        }
        
        display_subheading($project_id, $subheading);
        
        while( $row = db_fetch($iou_result))
        {
            start_row();
            label_cell(sql2date($row['end_date_time']),"align=center");
            $link = get_trans_view_str(ST_VEHICLE_RUNNING_CHART, $row['id']);
            label_cell($link, "align=center");
            label_cell($row['route']);
            
            label_cell($row['package_name']);

            amount_decimal_cell($row["cost"]); 
            
            if($row["inv_no"] > 0 || $row["payment_source_no"] > 0){
                $paid_amount = $row["cost"];
            }
            else{
                $paid_amount = 0;
            }

            $total_amount += $row["cost"];
            $total_settlement += $paid_amount;
            end_row();
        }
        
        display_subtotals($total_amount, $subheading);
}



function print_project_cost_adjustments($project_id, $from_date, $to_date)
{
        $total_amount = $total_settlement = 0;
        $subheading = "Project Cost Adjustments";
         
        $iou_result= get_project_cost_adjustments($project_id, $from_date, $to_date);
        
        if(!(db_num_rows($iou_result) > 0)){
            $msg = "No ".$subheading." found";
            display_note($msg);
            return;
        }
        
        display_subheading($project_id, $subheading);
        
        while( $row = db_fetch($iou_result))
        {
            start_row();
            label_cell(sql2date($row['tran_date']),"align=center");
            $link = get_trans_view_str(ST_PROJECT_COST_ADJUST, $row['id']);
            label_cell($link, "align=center");
            label_cell('');
            
//            label_cell($row['route']);
            

            label_cell($row['comment']);

            amount_decimal_cell($row["amount"]); 
            

            $paid_amount = 0;
            

            $total_amount += $row["amount"];
            $total_settlement += $paid_amount;
            end_row();
        }
        
        display_subtotals($total_amount, $subheading);
}


function print_petty_cash_payments($project_id, $from_date, $to_date)
{
    global $systypes_array;
    
        $total_amount = $total_settlement = 0;
        $subheading = "Petty Cash Payments";
        
        $iou_result= get_petty_cash_payments($project_id, $from_date, $to_date);
        
        if(!(db_num_rows($iou_result) > 0)){
            $msg = "No Petty Cash Payments found";
            display_note($msg);
            return;
        }
        
        display_subheading($project_id, $subheading);
        
        while( $row = db_fetch($iou_result))
        {            
            $type_name = $systypes_array[$row['expense_source']];
            
            switch ($row['expense_source']) {
                case ST_SUPPLIER_TRANSPORT_INVOICES:
                    $tran_no = $row['expense_id'];
                    $amount = $row['expense_amount'];                    
                    break;
                case ST_VEHICLE_ALLOCATION:
                    $tran_no = $row['expense_id'];
                    $amount = $row['expense_amount'];  
                    break;
                case ST_VEHICLE_RUNNING_CHART:
                    $tran_no = $row['expense_id'];
                    $amount = $row['expense_amount'];
                    break;
                case ST_PETTY_CASH:
                    $tran_no = $row['expense_id'];
                    $amount = $row['expense_amount'];  
                    break;
                case ST_I_OWE_YOU:
                    $tran_no = $row['expense_id'];
                    $amount = $row['expense_amount'];  
                    break;

                default:
                    $tran_no = 0;
                    break;
            }
            
            start_row();
            label_cell(sql2date($row['tran_date']),"align=center");
            $link = get_trans_view_str(ST_I_OWE_YOU_PAYMENT, $row['id']);
            label_cell($link, "align=center");
            label_cell('');
            
            label_cell($type_name." (#".$tran_no." - Rs. ".$amount.")");

            amount_decimal_cell($row["payment_amount"]); 
            
            $total_amount += $row["payment_amount"];
            $total_settlement += $row["payment_amount"];
        
            end_row();
        }
        
        display_subtotals($total_amount, $subheading);
}

function print_iou_bank_payments($project_id, $tran_type, $from_date, $to_date)
{
    global $systypes_array;
    
        $total_amount = $total_settlement = 0;
        
        if($tran_type == ST_IOU_BANKPAYMENT){
            $subheading = $systypes_array[$tran_type]."s";
        }
        elseif($tran_type == ST_IOU_BANKPAYMENT_RETURN){
            $subheading = $systypes_array[$tran_type]."s";
        }
        else{
            $subheading = "Unknown transaction type";
        }
        
//        $iou_result= get_petty_cash_payments($project_id, $from_date, $to_date);
        $result = get_iou_bank_payments($project_id, $from_date, $to_date, $tran_type);
        
        if(!(db_num_rows($result) > 0)){
            $msg = "No Petty Cash Payments found";
            display_note($msg);
            return;
        }
        
        display_subheading($project_id, $subheading);
        
        while( $row = db_fetch($result))
        {            
            $type_name = $systypes_array[$tran_type];
            $tran_no = $row['trans_no'];
            $amount = abs($row['amount']);         
            
            start_row();
            label_cell(sql2date($row['trans_date']),"align=center");
            $link = get_trans_view_str($tran_type, $tran_no);
            label_cell($link, "align=center");
            label_cell($row['ref']);
            
//            label_cell($type_name." (#".$tran_no." - Rs. ".$amount.")");
            label_cell('');

            amount_decimal_cell($amount); 
            
            $total_amount += $amount;
            $total_settlement += $amount;
        
            end_row();
        }
        
        display_subtotals($total_amount, $subheading);
}


function print_iou_advances($project_id, $from_date, $to_date)
{
        $total_amount = $total_settlement = 0;
        
        $subheading = "I Owe You Adavnces";

        $iou_result= get_iou_advances_details($project_id, $from_date, $to_date);
        
        if(!(db_num_rows($iou_result) > 0)){
            $msg = "No I Owe You Adavnces found";
            display_note($msg);
            return;
        }
        
        display_subheading($project_id, $subheading);
        
        while( $row = db_fetch($iou_result))
        {              
            start_row();
            label_cell(sql2date($row['tran_date']),"align=center");
            
//            get_i_owe_you_advances_paid_total($iou_id);
            $link = get_trans_view_str(ST_I_OWE_YOU_ADVANCES_BATCH, $row['batch_no'], $row['id']);
            label_cell($link, "align=center");
            label_cell($row['reference']);
            
            $emp_name = '';
            if(strlen($row['employee_code']) > 0){
                $emp_name = get_group_company_employee_formatted_long_name($row['company_code'], $row['employee_code']);
            }

            label_cell($emp_name);
            $amount = $row["advance_amount"];
            label_cell(number_format($amount,2), "align=right");

            $total_amount += $amount;
            $total_settlement += $amount;
            
            end_row();
        }
        
        display_subtotals($total_amount, $subheading);
}

function print_miscellaneous_project_costs($project_id, $from_date, $to_date)
{
        $total_amount = $total_settlement = 0;
        $type = ST_MISCELLANEOUS_PROJECT_COST;
        
        $subheading = "Miscellaneous Project Costs";
        
        $iou_result= get_miscellaneous_project_costs($project_id, $from_date, $to_date);
        
        if(!(db_num_rows($iou_result) > 0)){
            $msg = "No Miscellaneous Project Cost entries found";
            display_note($msg);
            return;
        }
        
        display_subheading($project_id, $subheading);                  
        
        while( $row = db_fetch($iou_result))
        {            
            start_row();
            label_cell(sql2date($row['date']),"align=center");
            $link = get_trans_view_str($type, $row['id']);
            label_cell($link, "align=center");
            label_cell($row['reference']);
            label_cell($row['comment']);
                  
            $amount = $row["total"];
            label_cell(number_format($amount,2), "align=right");
            
            $paid_amount = 0;
            $total_amount += $amount;
            $total_settlement += $paid_amount;
            end_row();
        }
        
        display_subtotals($total_amount, $subheading);
}


function print_monthly_project_costs($project_id, $from_date, $to_date)
{
        $total_amount = $total_settlement = 0;
        $type = ST_MONTHLY_PROJECT_COSTS;
        
        $subheading = "Monthly Project Costs";
        
        $iou_result= get_monthly_project_costs($project_id, $from_date, $to_date);
        
        if(!(db_num_rows($iou_result) > 0)){
            $msg = "No Monthly Project Cost entries found";
            display_note($msg);
            return;
        }
        
        display_subheading($project_id, $subheading);                  
        
        while( $row = db_fetch($iou_result))
        {            
            start_row();
            label_cell(sql2date($row['date']),"align=center");
            $link = get_trans_view_str($type, $row['mpc_id']);
            label_cell($link, "align=center");
            label_cell($row['reference']);
            label_cell($row['comment']);
                  
            $amount = $row["value"];
            label_cell(number_format($amount,2), "align=right");
            
            $paid_amount = 0;
            $total_amount += $amount;
            $total_settlement += $paid_amount;
            end_row();
        }
        
        display_subtotals($total_amount, $subheading);
}

function print_utility_bills($project_id, $type, $from_date, $to_date)
{
        $total_amount = $total_settlement = 0;

        $subheading = "Utility Bills";

        $invoices_result= get_utility_bills($type, $project_id, $from_date, $to_date);
        
        if(!(db_num_rows($invoices_result) > 0)){
            $msg = "No $subheading found";
            display_note($msg);
            return;
        }
        
        display_subheading($project_id, $subheading);
        
        while( $inv = db_fetch($invoices_result))
        {
            start_row();
            label_cell(sql2date($inv['tran_date']),"align=center");
            $link = get_trans_view_str($type, $inv['trans_no']);
            label_cell($link, "align=center");
            label_cell($inv['reference']);
            
            label_cell($inv['supp_name']);
            $amount = $inv["ov_amount"] - $inv["ov_discount"];// + $inv["ov_gst"];
            amount_decimal_cell($amount); 

            $total_amount += $amount;
            $total_settlement += $inv["alloc"];
        
            end_row();
        }
        
        display_subtotals($total_amount, $subheading);
}

function print_utility_bill_credit_notes($project_id, $type, $from_date, $to_date)
{
        $total_amount = $total_settlement = 0;

        $subheading = "Utility Bill Credit Notes";

        $invoices_result= get_utility_bill_credit_notes($type, $project_id, $from_date, $to_date);
        
        if(!(db_num_rows($invoices_result) > 0)){
            $msg = "No $subheading found";
            display_note($msg);
            return;
        }
        
        display_subheading($project_id, $subheading);
        
        while( $inv = db_fetch($invoices_result))
        {
            start_row();
            label_cell(sql2date($inv['tran_date']),"align=center");
            $link = get_trans_view_str($type, $inv['trans_no']);
            label_cell($link, "align=center");
            label_cell($inv['reference']);
            
            label_cell($inv['supp_name']);
            $amount = $inv["ov_amount"] - $inv["ov_discount"];// + $inv["ov_gst"];
            amount_decimal_cell($amount); 
            $allocation = -$inv["alloc"];
                  
            $total_amount += $amount;
            $total_settlement += $allocation;
        
            end_row();
        }
        
        display_subtotals($total_amount, $subheading);
}

function print_tool_usage_charges($project_id, $type, $from_date, $to_date)
{
        $total_amount = $total_settlement = 0;

        $subheading = "Tool Usage Charges";

        $invoices_result= get_tool_usage_charges($type, $project_id, $from_date, $to_date);
        
        if(!(db_num_rows($invoices_result) > 0)){
            $msg = "No $subheading found";
            display_note($msg);
            return;
        }
        
        display_subheading($project_id, $subheading);
        
        while( $inv = db_fetch($invoices_result))
        {
            start_row();
            label_cell(sql2date($inv['tran_date']),"align=center");
            $link = get_trans_view_str(ST_TOOL_ISSUE, $inv['trans_no']);
            label_cell($link, "align=center");
            label_cell($inv['reference']);
            
            $emp_name = get_group_company_employee_formatted_long_name($inv['company_code'], $inv['employee_code']);
            label_cell($emp_name);
            $amount = $inv["total"];
            amount_decimal_cell($amount); 
            
                  
            $total_amount += $amount;
            $total_settlement += $amount;
        
            end_row();
        }
        
        display_subtotals($total_amount, $subheading);
}


   
function print_project_credit_notes_pending($project_id, $type, $from_date, $to_date)
{
        $total_amount = $total_settlement = 0;

        $subheading = "Project Credit Notes - Pending (IPAs)";

        $invoices_result= get_project_credit_notes_pending($project_id, $from_date, $to_date);
        
        if(!(db_num_rows($invoices_result) > 0)){
            $msg = "No Project Credit Notes found";
            display_note($msg);
            return;
        }
        
        display_subheading($project_id, $subheading);  
        
        while( $inv = db_fetch($invoices_result))
        {
            start_row();
            label_cell(sql2date($inv['ord_date']),"align=center");
            $link = get_trans_view_str($type, $inv['order_no']);
            label_cell($link, "align=center");
            label_cell($inv['reference']);
            
            label_cell($inv['cust_name']);
            $amount = $inv["total"];
            amount_decimal_cell($amount);
                  
            $total_amount += $amount;
            $total_settlement += 0;        
        
            end_row();
        }
        
        display_subtotals($total_amount, $subheading);
}

function print_project_invoices_pending($project_id, $type, $from_date, $to_date)
{
        $total_amount = $total_settlement = 0;

        $subheading = "Project Invoices - Pending (IPAs)";

        $invoices_result= get_project_invoices_pending($project_id, $from_date, $to_date);
        
        if(!(db_num_rows($invoices_result) > 0)){
            $msg = "No pending Project Invoices found";
            display_note($msg);
            return;
        }
        
        display_subheading($project_id, $subheading);   
        
        while( $inv = db_fetch($invoices_result))
        {
            start_row();
            label_cell(sql2date($inv['ord_date']),"align=center");
            $link = get_trans_view_str($type, $inv['order_no']);
            label_cell($link, "align=center");
            label_cell($inv['reference']);
            
            label_cell($inv['cust_name']);
            $amount = $inv["total"];
            amount_decimal_cell($amount);
                  
            $total_amount += $amount;
            $total_settlement += 0;        
            end_row();
        }
        
        display_subtotals($total_amount, $subheading);
                  
}


function print_project_credit_notes_certified($project_id, $type, $from_date, $to_date)
{
        $total_amount = $total_settlement = 0;

        $subheading = "Project Credit Notes - Certified (IPCs)";

        $invoices_result= get_project_credit_notes_certified($type, $project_id, $from_date, $to_date);
        
        if(!(db_num_rows($invoices_result) > 0)){
            $msg = "No Project Credit Notes found";
            display_note($msg);
            return;
        }
        
        display_subheading($project_id, $subheading);   
        
        while( $inv = db_fetch($invoices_result))
        {
            start_row();
            label_cell(sql2date($inv['tran_date']),"align=center");
            $link = get_trans_view_str($type, $inv['trans_no']);
            label_cell($link, "align=center");
            label_cell($inv['reference']);
            
            label_cell($inv['cust_name']);
            $amount = $inv["ov_amount"] - $inv["ov_discount"];
            amount_decimal_cell($amount);
            
            $allocation = -$inv["alloc"];
                  
            $total_amount += $amount;
            $total_settlement += $allocation;
        
            end_row();
        }
        
        display_subtotals($total_amount, $subheading);
}



function print_project_invoices_certified($project_id, $type, $from_date, $to_date)
{
        $total_amount = $total_settlement = 0;

        $subheading = "Project Invoices - Certified (IPCs)";
        
        $invoices_result= get_project_invoices_certified($type, $project_id, $from_date, $to_date);
        
        if(!(db_num_rows($invoices_result) > 0)){
            $msg = "No Project Invoices found";
            display_note($msg);
            return;
        }
        
        display_subheading($project_id, $subheading);   
        
        while( $inv = db_fetch($invoices_result))
        {            
            start_row();
            label_cell(sql2date($inv['tran_date']),"align=center");
            $link = get_trans_view_str($type, $inv['trans_no']);
            label_cell($link, "align=center");
            label_cell($inv['reference']);
            
            label_cell($inv['cust_name']);
            $amount = $inv["ov_amount"] - $inv["ov_discount"];
            amount_decimal_cell($amount);
                  
            $total_amount += $amount;
            $total_settlement += $inv["alloc"];
        
            end_row();
        }
        
        display_subtotals($total_amount, $subheading);
}

function print_project_collections($project_id, $from_date, $to_date)
{
    global $systypes_array;
    
    $project = get_project_record($project_id);
    $subheading = "Project Collections";
    $text = $subheading.' for project "'.$project['description'].'"';
    display_heading($text);
    
    br(1);
    
    start_table(TABLESTYLE, "width=70%");

    $th = array(_("Date"), _("Type"), _("No"), _("Reference"), "Supplier / Employee / Package", "Amount", "Paid");
     

    table_header($th);
    
        $total_amount = $total_settlement = 0;

        
        
        $invoices_result= get_project_invoices_and_credit_notes($project_id, $from_date, $to_date);
        
        if(!(db_num_rows($invoices_result) > 0)){
            $msg = "No transactions found";
            display_note($msg);
            return;
        }
        
//        display_subheading($project_id, $subheading);   
        
        while( $inv = db_fetch($invoices_result))
        {            
            start_row();
            label_cell(sql2date($inv['tran_date']),"align=center");
            label_cell($systypes_array[$inv['type']]);
//            label_cell($inv['trans_no']);
//            label_cell($inv['reference']);
            
            $link = get_trans_view_str($inv['type'], $inv['trans_no']);
            label_cell($link, "align=center");
            label_cell($inv['reference']);
            
            label_cell($inv['cust_name']);
            if($inv['type'] == ST_PROJECT_INVOICE){
                $amount = $inv["ov_amount"] + $inv["ov_gst"] + $inv["ov_freight"] + $inv["ov_freight_tax"] - $inv["ov_discount"];
                $allocation = $inv["alloc"];
            }
            else{
                $amount = -($inv["ov_amount"] + $inv["ov_gst"] + $inv["ov_freight"] + $inv["ov_freight_tax"]  - $inv["ov_discount"]);
                $allocation = -$inv["alloc"];
            }
            
            amount_decimal_cell($amount);

            $allocation = $inv['type'] == ST_PROJECT_INVOICE ? $inv["alloc"] : -$inv["alloc"];
            amount_decimal_cell($allocation);
                  
            $total_amount += $amount;
            $total_settlement += $allocation;
        
            end_row();
        }
        
        label_cell("Total for ".$subheading." :","align=right colspan=5");
        label_cell(text_bold(number_format($total_amount,2)),"align=right");
        label_cell(text_bold(number_format($total_settlement,2)),"align=right");
        
        end_table();
}


function print_material_requisitions($project_id, $type, $from_date, $to_date)
{
        $total_amount = $total_settlement = 0;

        $subheading = "Material Requistion Allocations";

        $invoices_result= get_material_requisitions($type, $project_id, $from_date, $to_date);
        
        if(!(db_num_rows($invoices_result) > 0)){
            $msg = "No $subheading found";
            display_note($msg);
            return;
        }
                  
        display_subheading($project_id, $subheading);
        
        while( $inv = db_fetch($invoices_result))
        {
            start_row();
            label_cell(sql2date($inv['tran_date']),"align=center");
            $link = get_trans_view_str($type, $inv['trans_no']);
            label_cell($link, "align=center");
            label_cell($inv['reference']);
            
            $emp_name = '';
            if(strlen($inv['employee_code']) > 0){
                $emp_name = get_group_company_employee_formatted_long_name($inv['company_code'], $inv['employee_code']);
            }
            label_cell($emp_name);
            $amount = $inv["total_cost"];
            label_cell(number_format($amount,2), "align=right");
            //$rep->TextCol(5, 6, number_format($amount));
            
            end_row();
                  
            $total_amount += $amount;
            $total_settlement += $amount;
            
//            print_material_purchase_credit_notes($inv['trans_no'], ST_SUPPCREDIT, $inv['supp_name'], $total_amount, $total_settlement);
        
        }

        display_subtotals($total_amount, $subheading);
}


function print_purchase_requisitions($project_id, $type, $from_date, $to_date)
{
        $total_amount = $total_settlement = 0;

        $subheading = "Purchase Requistion Allocations";

        $invoices_result= get_purchase_requisitions($type, $project_id, $from_date, $to_date);
        
        if(!(db_num_rows($invoices_result) > 0)){
            $msg = "No $subheading found";
            display_note($msg);
            return;
        }
                  
        display_subheading($project_id, $subheading);
        
        while( $inv = db_fetch($invoices_result))
        {
            start_row();
            label_cell(sql2date($inv['tran_date']),"align=center");
            $link = get_trans_view_str($type, $inv['trans_no']);
            label_cell($link, "align=center");
            label_cell($inv['reference']);
            
            $emp_name = '';
            if(strlen($inv['employee_code']) > 0){
                $emp_name = get_group_company_employee_formatted_long_name($inv['company_code'], $inv['employee_code']);
            }
            label_cell($emp_name);
            $amount = $inv["total_cost"];
            label_cell(number_format($amount,2), "align=right");
            //$rep->TextCol(5, 6, number_format($amount));
            
            end_row();
                  
            $total_amount += $amount;
            $total_settlement += $amount;
            
//            print_material_purchase_credit_notes($inv['trans_no'], ST_SUPPCREDIT, $inv['supp_name'], $total_amount, $total_settlement);
        
        }

        display_subtotals($total_amount, $subheading);
}


function print_subcontractor_purchase_orders($project_id, $type, $from_date, $to_date)
{
        $total_amount = $total_settlement = 0;

        $subheading = "Subcontractor Purchase Order Allocations";

        $invoices_result= get_subcontractor_purchase_orders($type, $project_id, $from_date, $to_date);
        
        if(!(db_num_rows($invoices_result) > 0)){
            $msg = "No ".$subheading." found.";
            display_note($msg);
            return;
        }
                  
        display_subheading($project_id, $subheading);
        
        while( $inv = db_fetch($invoices_result))
        {
            start_row();
            label_cell(sql2date($inv['tran_date']),"align=center");
            $link = get_trans_view_str($type, $inv['trans_no']);
            label_cell($link, "align=center");
            label_cell($inv['reference']);
            
            label_cell($inv["supp_name"]);
            $amount = $inv["total_cost"];
            label_cell(number_format($amount,2), "align=right");
            //$rep->TextCol(5, 6, number_format($amount));
            
            end_row();
                  
            $total_amount += $amount;
            $total_settlement += $amount;
            
//            print_material_purchase_credit_notes($inv['trans_no'], ST_SUPPCREDIT, $inv['supp_name'], $total_amount, $total_settlement);
        
        }

        display_subtotals($total_amount, $subheading);
}


function print_i_owe_yous($project_id, $type, $from_date, $to_date)
{
        $total_amount = $total_settlement = 0;

        $subheading = "I Owe You Allocations";

        $invoices_result= get_i_owe_yous($type, $project_id, $from_date, $to_date);
        
        if(!(db_num_rows($invoices_result) > 0)){
            $msg = "No ".$subheading." found.";
            display_note($msg);
            return;
        }
                  
        display_subheading($project_id, $subheading);
        
        while( $inv = db_fetch($invoices_result))
        {
            start_row();
            label_cell(sql2date($inv['tran_date']),"align=center");
            $link = get_trans_view_str($type, $inv['trans_no']);
            label_cell($link, "align=center");
            label_cell($inv['reference']);
            
            $emp_name = '';
            if(strlen($inv['employee_code']) > 0){
                $emp_name = get_group_company_employee_formatted_long_name($inv['company_code'], $inv['employee_code']);
            }
            label_cell($emp_name);
            
            $amount = $inv["total_cost"];
            label_cell(number_format($amount,2), "align=right");
            //$rep->TextCol(5, 6, number_format($amount));
            
            end_row();
                  
            $total_amount += $amount;
            $total_settlement += $amount;
            
//            print_material_purchase_credit_notes($inv['trans_no'], ST_SUPPCREDIT, $inv['supp_name'], $total_amount, $total_settlement);
        
        }

        display_subtotals($total_amount, $subheading);
}


function print_vehicle_requests($project_id, $type, $from_date, $to_date)
{
        $total_amount = $total_settlement = 0;

        $subheading = "Vehicle Requests Allocations";

        $invoices_result= get_vehicle_requests($type, $project_id, $from_date, $to_date);
        
        if(!(db_num_rows($invoices_result) > 0)){
            $msg = "No ".$subheading." found.";
            display_note($msg);
            return;
        }
                  
        display_subheading($project_id, $subheading);
        
        while( $inv = db_fetch($invoices_result))
        {
            start_row();
            label_cell(sql2date($inv['tran_date']),"align=center");
            $link = get_trans_view_str($type, $inv['trans_no']);
            label_cell($link, "align=center");
            label_cell($inv['reference']);
            
            label_cell($inv['route']);
            
            $amount = $inv["total_cost"];
            label_cell(number_format($amount,2), "align=right");
            //$rep->TextCol(5, 6, number_format($amount));
            
            end_row();
                  
            $total_amount += $amount;
            $total_settlement += $amount;
            
//            print_material_purchase_credit_notes($inv['trans_no'], ST_SUPPCREDIT, $inv['supp_name'], $total_amount, $total_settlement);
        
        }

        display_subtotals($total_amount, $subheading);
}


function print_site_material_returns($project_id, $type, $from_date, $to_date){
    $total_amount = $total_settlement = 0;
    $subheading = "Site Material Returns";
    $invoices_result = get_site_material_returns($project_id, $from_date, $to_date);
    if(!(db_num_rows($invoices_result) > 0)){
        $msg = "No ".$subheading." found.";
        display_note($msg);
        return;
    }
                  
    display_subheading($project_id, $subheading);
        
        while($inv = db_fetch($invoices_result)){
            start_row();
                label_cell(sql2date($inv['tran_date']),"align=center");
                $link = get_trans_view_str($type, $inv['id']);
                label_cell($link, "align=center");
                label_cell($inv['reference']);
                $employee_name = get_group_company_employee($inv['company_code'], $inv['employee_code']);
                label_cell( $employee_name['employee_code'].' - '.$employee_name['initials'].' '.$employee_name['last_name']);
                $amount = $inv["total"];
                label_cell(number_format($amount,2), "align=right");            
            end_row();
                  
            $total_amount += $amount;
            $total_settlement += $amount;        
        }
        display_subtotals($total_amount, $subheading);
}

function print_purchase_requisition_issues($project_id, $type, $from_date, $to_date){
    $total_amount = $total_settlement = 0;
    $subheading = "Purchase Requisition Issues";
    $invoices_result = get_pr_issues($project_id, $from_date, $to_date);
    if(!(db_num_rows($invoices_result) > 0)){
        $msg = "No ".$subheading." found.";
        display_note($msg);
        return;
    }
                  
    display_subheading($project_id, $subheading);
        
        while($inv = db_fetch($invoices_result)){
            start_row();
                label_cell(sql2date($inv['created_on']),"align=center");
                $link = get_trans_view_str($type, $inv['pri_no']);
                label_cell($link, "align=center");
                label_cell($inv['reference']);
                label_cell($inv['supp_name']);
                $amount = $inv["total"];
                label_cell(number_format($amount,2), "align=right");            
            end_row();
                  
            $total_amount += $amount;
            $total_settlement += $amount;        
        }
        display_subtotals($total_amount, $subheading);
}

function print_purchase_requisition_returns($project_id, $type, $from_date, $to_date){
    $total_amount = $total_settlement = 0;
    $subheading = "Purchase Requisition Returns";
    $invoices_result = get_pr_returns($project_id, $from_date, $to_date);
    if(!(db_num_rows($invoices_result) > 0)){
        $msg = "No ".$subheading." found.";
        display_note($msg);
        return;
    }
                  
    display_subheading($project_id, $subheading);
        
        while($inv = db_fetch($invoices_result)){
            start_row();
                label_cell(sql2date($inv['prr_date']),"align=center");
                $link = get_trans_view_str($type, $inv['prr_no']);
                label_cell($link, "align=center");
                label_cell($inv['reference']);
                label_cell($inv['supp_name']);
                $amount = $inv["total"];
                label_cell(number_format($amount,2), "align=right");            
            end_row();
                  
            $total_amount += $amount;
            $total_settlement += $amount;        
        }
        display_subtotals($total_amount, $subheading);
}


function print_subcontractor_advances_paid_invoices($project_id, $type, $display_type, $from_date, $to_date)
{
    global $systypes_array;
    
        $total_amount = 0;

        switch ($display_type) {
            case "SUB_AP":
                $subheading = "Subcontractor Advance Payments";
                $line_category_code = "'ADVANCE'";
                break;
            
            case "SUB_AR":
                $subheading = "Subcontractor Advance Recovered";
                $line_category_code = "'ADVANCE_RECOVERED'";
                break;
            
            case "SUB_RH":
                $subheading = "Subcontractor Retentions Held";
                $line_category_code = "'RETENTION'";
                break;
            
            case "SUB_RS":
                $subheading = "Subcontractor Retentions Settled";
                $line_category_code = "'RETENTION_RECOVERED'";
                break;            

            default:
                $subheading = "Unknown subcontractor invoice type";
                $line_category_code = "'XXXXXXXXXXX'";
                break;
        }
        
        
        $invoices_details_array= get_subcontractor_advances_paid_invoices_details($project_id, $line_category_code, $from_date, $to_date);
        $credit_note_details_array= get_subcontractor_credit_notes_returned_details($project_id, $line_category_code, $from_date, $to_date);
        
        if(!(count($invoices_details_array) > 0 || count($credit_note_details_array) > 0)){
            $msg = "No ".$systypes_array[ST_SUBCONTRACTOR_INVOICE]."s or ".$systypes_array[ST_SUBCONTRACTOR_CREDIT_NOTE]."s found";
            display_note($msg);
            return;
        }
        
        display_subheading($project_id, $subheading);
        
        if(count($invoices_details_array) > 0){
            start_row();
                label_cell(text_bold($systypes_array[ST_SUBCONTRACTOR_INVOICE]."s"),"colspan=5");
            end_row();

            foreach ($invoices_details_array as $inv) 
            {
                start_row();
                label_cell(sql2date($inv['ord_date']),"align=center");
                $link = get_trans_view_str($type, $inv['order_no']);
                label_cell($link, "align=center");
                label_cell($inv['reference']);

                label_cell($inv['supp_name']);
                $amount = abs($inv["amount"]);// + $inv["ov_gst"];
                amount_decimal_cell($amount); 

                $total_amount += $amount;

                end_row();
            }
        }
        
//        display_subtotals($total_amount, $subheading);
        
        
        
        if(count($credit_note_details_array) > 0){
            start_row();
                label_cell(text_bold($systypes_array[ST_SUBCONTRACTOR_CREDIT_NOTE]."s"),"colspan=5");
            end_row();
        
            foreach ($invoices_details_array as $inv) 
            {
                start_row();
                label_cell(sql2date($inv['ord_date']),"align=center");
                $link = get_trans_view_str($type, $inv['order_no']);
                label_cell($link, "align=center");
                label_cell($inv['reference']);

                label_cell($inv['supp_name']);
                $amount = abs($inv["amount"]);// + $inv["ov_gst"];
                amount_decimal_cell(-$amount); 

                $total_amount -= $amount;

                end_row();
            }
        
        }
        display_subtotals($total_amount, $subheading);
}

function get_subcontractor_advances_paid_invoices_details($project_id, $line_category_in, $from_date, $to_date)
{
    $a = array();
    
    $subcontractors_res = get_project_invoice_subcontractors($project_id, $line_category_in);
    while ($subcontractor = db_fetch($subcontractors_res)) {
        $subcontractor_id = $subcontractor["supplier_id"];
        $invoice_res = get_subcontractor_invoice_advance_paid_details($project_id, $subcontractor_id, $line_category_in, $from_date, $to_date);
        while ($invoice = db_fetch($invoice_res)) {
            $a[$invoice['order_no']] = $invoice;
        }
    }
    
    asort($a);
    
    return $a;
 
}

function get_subcontractor_credit_notes_returned_details($project_id, $line_category_in, $from_date, $to_date)
{
    $a = array();
    
    $subcontractors_res = get_project_credit_note_subcontractors($project_id, $line_category_in);
    while ($subcontractor = db_fetch($subcontractors_res)) {
        $subcontractor_id = $subcontractor["supplier_id"];
        $invoice_res = get_subcontractor_credit_note_advance_returned_details($project_id, $subcontractor_id, $line_category_in, $from_date, $to_date);
        while ($invoice = db_fetch($invoice_res)) {
            $a[$invoice['order_no']] = $invoice;
        }
    }
    
    asort($a);
    
    return $a;
 
}



function print_project_petty_cash_expenses($project_id, $from_date, $to_date, $approved) {
    global $approval_statuses;
    
    if ($approved === true) {
        $aps_name = "Approved";
        $tbl_cl = "Complete";
        $aps_array = array(AS_APPROVED);
    } else {
        $aps_name = "Unapproved";
        $tbl_cl = "Approval Status";
        $aps_array = array(AS_NEW, AS_WITH_THE_APPROVER, AS_AWAITING_APPROVAL, AS_BACK_TO_ORIGINATOR);
    }
    
    $project = get_project_record($project_id);
    $subheading = "$aps_name Petty Cash Expenses";
    $text = $subheading.' for Project "'.$project['description'].'"';
    display_heading($text);
    
    br(1);
    
    start_table(TABLESTYLE, "width=60%");

        $th = array(_("Tran. Date"), _("Batch #"), _("Flotat"), _("$tbl_cl"), _("Amount"));
        table_header($th);

            $total_amount = 0;

            $result = get_project_petty_cash_expenses($project_id, $from_date, $to_date, $aps_array);

            if (! (db_num_rows($result) > 0)) {
                display_note("No transactions found");
                return;
            }

            while ($row = db_fetch($result)) {      
                
                start_row();
                    label_cell(sql2date($row['tran_date']),"align=center");
                    label_cell(get_petty_cash_trans_view_str(ST_I_OWE_YOU_BATCH, $row['batch_no']), "align=center");
                    label_cell($row['float_name']);
                    if ($approved !== true) {
                        label_cell($approval_statuses[$row['approval_status']], "align=center");
                    } else {
                        label_cell(($row['complete'] == 1) ? 'Yes' : '', "align=center");
                    }

                    amount_decimal_cell($row['amount'], '', null, 2);
                end_row();
                
                $total_amount += $row['amount'];
            }

            label_cell(text_bold("Total:"), "align=right colspan=4");
            label_cell(text_bold(number_format($total_amount, 2)),"align=right");

    end_table(2);
}




function display_project_transaction_type_transactions($project_id, $type, $from_date, $to_date){

    switch ($type) {
        case ST_MATERIAL_ISSUE:
            print_material_issues($project_id, ST_MATERIAL_ISSUE, $from_date, $to_date); 
            break;
        case ST_MATERIAL_RETURN:
            print_material_returns($project_id, ST_MATERIAL_RETURN, $from_date, $to_date);  
            break;
        case ST_DAILY_ITEM_ISSUE:
            print_daily_item_issues($project_id, ST_DAILY_ITEM_ISSUE, $from_date, $to_date); 
            break;
        case ST_DAILY_ITEM_RETURN:
            print_daily_item_issues($project_id, ST_DAILY_ITEM_RETURN, $from_date, $to_date);  
            break;
        case ST_SUPPINVOICE:
            print_material_purchased_invoices($project_id, ST_SUPPINVOICE, $from_date, $to_date);  
            break;
        case ST_SUPPCREDIT:
            print_material_purchase_credit_notes($project_id, ST_SUPPCREDIT, $from_date, $to_date);
            break;
        case ST_SUBCONTRACTOR_INVOICE:
            print_subcontractor_invoices($project_id, ST_SUBCONTRACTOR_INVOICE, $from_date, $to_date);  
            break;
        case ST_SUBCONTRACTOR_CREDIT_NOTE:
            print_subcontractor_credit_notes($project_id, ST_SUBCONTRACTOR_CREDIT_NOTE, $from_date, $to_date);  
            break;
        case ST_VEHICLE_RUNNING_CHART:
            print_transport_expenses($project_id, $from_date, $to_date);  
            break;
        case ST_IOU_BANKPAYMENT:
            print_iou_bank_payments($project_id, ST_IOU_BANKPAYMENT, $from_date, $to_date); 
            break;
        case ST_IOU_BANKPAYMENT_RETURN:
            print_iou_bank_payments($project_id, ST_IOU_BANKPAYMENT_RETURN, $from_date, $to_date); 
            break;
        case ST_I_OWE_YOU_PAYMENT:
            print_petty_cash_payments($project_id, $from_date, $to_date); 
            break;
        case ST_I_OWE_YOU_ADVANCES:
            print_iou_advances($project_id, $from_date, $to_date); 
            break;
        case ST_MONTHLY_PROJECT_COSTS:
            print_monthly_project_costs($project_id, $from_date, $to_date);  
            break;
        case ST_MISCELLANEOUS_PROJECT_COST:
            print_miscellaneous_project_costs($project_id, $from_date, $to_date);  
            break;
        case ST_PROJECT_COST_ADJUST:
            print_project_cost_adjustments($project_id, $from_date, $to_date);  
            break;
        
        
        case "108P":
            print_project_invoices_pending($project_id, ST_PROJECT_INVOICE, $from_date, $to_date);   
            break; 
        case "128P":
            print_project_credit_notes_pending($project_id, ST_PROJECT_CREDIT_NOTE, $from_date, $to_date);  
            break;
        case ST_PROJECT_INVOICE:
            print_project_invoices_certified($project_id, ST_PROJECT_INVOICE, $from_date, $to_date);
            break;
        case ST_PROJECT_CREDIT_NOTE:
            print_project_credit_notes_certified($project_id, ST_PROJECT_CREDIT_NOTE, $from_date, $to_date);  
            break;
        case ST_UTILITY_BILLS:
            print_utility_bills($project_id, ST_UTILITY_BILLS, $from_date, $to_date);
            break;
        case ST_UTILITY_BILL_CREDIT_NOTE:
            print_utility_bill_credit_notes($project_id, ST_UTILITY_BILL_CREDIT_NOTE, $from_date, $to_date);  
            break;
        case ST_TOOL_USAGE_CHARGE:
            print_tool_usage_charges($project_id, ST_TOOL_USAGE_CHARGE, $from_date, $to_date);  
            break;
        
        
        
        case ST_MATERIAL_REQ:
            print_material_requisitions($project_id, ST_MATERIAL_REQ, $from_date, $to_date);
            break;
        case ST_PURCH_REQ:
            print_purchase_requisitions($project_id, ST_PURCH_REQ, $from_date, $to_date);  
            break;
        case ST_SUBCONTRACTOR_PURCH_ORDER:
            print_subcontractor_purchase_orders($project_id, ST_SUBCONTRACTOR_PURCH_ORDER, $from_date, $to_date);
            break;
        case ST_I_OWE_YOU:
            print_i_owe_yous($project_id, ST_I_OWE_YOU, $from_date, $to_date);  
            break;
        case ST_VEHICLE_REQUEST:
            print_vehicle_requests($project_id, ST_VEHICLE_REQUEST, $from_date, $to_date);  
            break;
        case ST_SITE_MATERIAL_RETURN:
            print_site_material_returns($project_id, ST_SITE_MATERIAL_RETURN, $from_date, $to_date);  
            break;
        case ST_PR_ISSUE:
            print_purchase_requisition_issues($project_id, ST_PR_ISSUE, $from_date, $to_date);  
            break;
        case ST_PR_RETURN:
            print_purchase_requisition_returns($project_id, ST_PR_RETURN, $from_date, $to_date);  
            break;
        
        case "SUB_AP":
        case "SUB_AR":
        case "SUB_RH":
        case "SUB_RS":
            print_subcontractor_advances_paid_invoices($project_id, ST_SUBCONTRACTOR_INVOICE, $type, $from_date, $to_date);  
            break;
        
        case 'COLLECTIONS':
            print_project_collections($project_id, $from_date, $to_date);  
            break;
        case 'PCE_AP':
            print_project_petty_cash_expenses($project_id, $from_date, $to_date, true);  
            break;
        case 'PCE_UAP':
            print_project_petty_cash_expenses($project_id, $from_date, $to_date, false);  
            break;
        default:
            break;
        
    }    
}
   


start_form();

br(1);

$user_id = $_SESSION['wa_current_user']->user;
$r = can_access_project($project_id, $user_id);
if($r["success"] !== true){
    display_error($r["message"]);
    display_footer_exit();
    exit;
}

hidden('trans_no', $project_id);



//$from_date = INFINITE_START_DATE;
//$to_date = INFINITE_END_DATE;
$from_date = date2sql($from_date);
$to_date = date2sql($to_date);

display_project_transaction_type_transactions($project_id, $trans_type, $from_date, $to_date);

//submit_center_first('Recalculate_Poject_PA', _("Recalculate Payment Application Summaries"), '', 'default');


br(2);
            
end_form();


end_page();
