<?php

function dashboard_view_project_cash_flow($project_id, $type, $from_date_, $to_date_) {
    
    $from_date = date2sql($from_date_);
    $to_date = date2sql($to_date_);
    
    br();
    $project_name = get_project_formatted_name($project_id);    
    display_heading("Project : ".$project_name);
    
    br();
    
    switch ($type) {
        case DASH_VW_PROJECT_CF_PROJECT_INVOICE_RECEIPTS:
            $name = "Project Invoice Receipts";
            display_heading($name);    
            br();
            dashboard_view_PROJECT_CF_PROJECT_INVOICE_RECEIPTS($project_id, $from_date, $to_date);
            break;
        case DASH_VW_PROJECT_CF_SUBCONTRACTOR_CREDIT_NOTE_RECEIPTS:
            $name = "Subcontractor Credit Note Receipts";
            display_heading($name);    
            br();
            dashboard_view_PROJECT_CF_SUBCONTRACTOR_CREDIT_NOTE_RECEIPTS($project_id, $from_date, $to_date);
            break;
        case DASH_VW_PROJECT_CF_UTILITY_BILL_CREDIT_NOTE_RECEIPTS:
            $name = "Utility Bill Credit Note Receipts";
            display_heading($name);    
            br();
            dashboard_view_PROJECT_CF_UTILITY_BILL_CREDIT_NOTE_RECEIPTS($project_id, $from_date, $to_date);
            break;
        case DASH_VW_PROJECT_CF_PROJECT_CREDIT_NOTE_PAYMENTS:
            $name = "Project Credit Note Payments";
            display_heading($name);    
            br();
            dashboard_view_PROJECT_CF_PROJECT_CREDIT_NOTE_PAYMENTS($project_id, $from_date, $to_date);
            break;
        case DASH_VW_PROJECT_CF_SUBCONTRACTOR_INVOICE_PAYMENTS:
            $name = "Subcontractor Invoice Payments";
            display_heading($name);    
            br();
            dashboard_view_PROJECT_CF_SUBCONTRACTOR_INVOICE_PAYMENTS($project_id, $from_date, $to_date);
            break;
        case DASH_VW_PROJECT_CF_UTILITY_BILL_PAYMENTS:
            $name = "Utility Bill Payments";
            display_heading($name);    
            br();
            dashboard_view_PROJECT_CF_UTILITY_BILL_PAYMENTS($project_id, $from_date, $to_date);
            break;


        default:
            break;
    }
    
}


function dashboard_view_PROJECT_CF_UTILITY_BILL_PAYMENTS($project_id, $from_date, $to_date) {
    
    global $systypes_array;


    br(2);
    
    start_table(TABLESTYLE, "width=70%");

            $th = array(" Date","Type", "No", "Reference", "Supplier", "Amount", "Allocated Amount", "UB. CN No.");
                table_header($th);
                
                    $k = $total_amount = $count = 0;
                    $result = dashboard_view_cf_utility_bill_payments_details(ST_UTILITY_BILLS, $project_id, $from_date, $to_date);
                        while($row = db_fetch($result)) {
                            alt_table_row_color($k);
                                label_cell(sql2date($row['tran_date']),"align=center");
                                label_cell($systypes_array[$row['type']]);
                                $grn_link = get_trans_view_str($row['type'], $row['trans_no']);
                                label_cell($grn_link, "align=center");
                                
                                label_cell($row['reference']);
                                
                                $customer_name = get_supplier_formatted_name($row['supplier_id']);
                                label_cell($customer_name);

                                amount_cell($row['ov_amount']);
                                $alllocated_amount = $row['alllocated_amount'];
                                amount_cell($alllocated_amount);
                                
                                $link = get_journal_trans_view_str(ST_UTILITY_BILLS, $row['ub_no']);
                                label_cell($link, "align=center");
\
                            end_row();

                            $total_amount += $alllocated_amount;
                            $count++;
                        }
                        
                        start_row();
                            label_cell(text_bold("Total "),"align=right colspan=6");
                            label_cell(text_bold(number_format($total_amount, 2)),"align=right");
                            label_cell("", "colspan=2");
                        end_row();
                
        end_table(2);
}


function dashboard_view_PROJECT_CF_SUBCONTRACTOR_INVOICE_PAYMENTS($project_id, $from_date, $to_date) {
    
    global $systypes_array;


    br(2);
    
    start_table(TABLESTYLE, "width=70%");

            $th = array(" Date","Type", "No", "Reference", "Supplier", "Amount", "Allocated Amount", "Sub. Inv. No.");
                table_header($th);
                
                    $k = $total_amount = $count = 0;
                    $result = dashboard_view_cf_subcontractor_invoice_payments(ST_SUBCONTRACTOR_INVOICE, $project_id, $from_date, $to_date);
                        while($row = db_fetch($result)) {
                            alt_table_row_color($k);
                                label_cell(sql2date($row['tran_date']),"align=center");
                                label_cell($systypes_array[$row['type']]);
                                $grn_link = get_trans_view_str($row['type'], $row['trans_no']);
                                label_cell($grn_link, "align=center");
                                
                                label_cell($row['reference']);
                                
                                $customer_name = get_supplier_formatted_name($row['supplier_id']);
                                label_cell($customer_name);

                                amount_cell($row['ov_amount']);
                                $alllocated_amount = $row['alllocated_amount'];
                                amount_cell($alllocated_amount);
                                
                                $link = get_project_trans_view_str(ST_SUBCONTRACTOR_INVOICE, $row['order_no']);
                                label_cell($link, "align=center");
\
                            end_row();

                            $total_amount += $alllocated_amount;
                            $count++;
                        }
                        
                        start_row();
                            label_cell(text_bold("Total "),"align=right colspan=6");
                            label_cell(text_bold(number_format($total_amount, 2)),"align=right");
                            label_cell("", "colspan=2");
                        end_row();
                
        end_table(2);
}

function dashboard_view_PROJECT_CF_PROJECT_CREDIT_NOTE_PAYMENTS($project_id, $from_date, $to_date) {
    
    global $systypes_array;


    br(2);
    
    start_table(TABLESTYLE, "width=70%");

            $th = array(" Date","Type", "No", "Reference", "Customer", "Amount", "Allocated Amount", "Proj. CN No.");
                table_header($th);
                
                    $k = $total_amount = $count = 0;
                    $result = dashboard_view_cf_project_credit_note_paymets_details(ST_PROJECT_CREDIT_NOTE, $project_id, $from_date, $to_date);
                        while($row = db_fetch($result)) {
                            alt_table_row_color($k);
                                label_cell(sql2date($row['tran_date']),"align=center");
                                label_cell($systypes_array[$row['type']]);
                                $grn_link = get_trans_view_str($row['type'], $row['trans_no']);
                                label_cell($grn_link, "align=center");
                                
                                label_cell($row['reference']);
                                
                                $customer_name = get_customer_formatted_name($row['debtor_no']);
                                label_cell($customer_name);

                                amount_cell($row['ov_amount']);
                                $alllocated_amount = $row['alllocated_amount'];
                                amount_cell($alllocated_amount);
                                
                                $link = get_project_trans_view_str(ST_PROJECT_CREDIT_NOTE, $row['order_no']);
                                label_cell($link, "align=center");
\
                            end_row();

                            $total_amount += $alllocated_amount;
                            $count++;
                        }
                        
                        start_row();
                            label_cell(text_bold("Total "),"align=right colspan=6");
                            label_cell(text_bold(number_format($total_amount, 2)),"align=right");
                            label_cell("", "colspan=2");
                        end_row();
                
        end_table(2);
}

function dashboard_view_PROJECT_CF_UTILITY_BILL_CREDIT_NOTE_RECEIPTS($project_id, $from_date, $to_date) {
    
    global $systypes_array;


    br(2);
    
    start_table(TABLESTYLE, "width=70%");

            $th = array(" Date","Type", "No", "Reference", "Supplier", "Amount", "Allocated Amount", "UB. CN No.");
                table_header($th);
                
                    $k = $total_amount = $count = 0;
                    $result = dashboard_view_cf_utility_bill_credit_note_receipts_details(ST_UTILITY_BILL_CREDIT_NOTE, $project_id, $from_date, $to_date);
                        while($row = db_fetch($result)) {
                            alt_table_row_color($k);
                                label_cell(sql2date($row['tran_date']),"align=center");
                                label_cell($systypes_array[$row['type']]);
                                $grn_link = get_trans_view_str($row['type'], $row['trans_no']);
                                label_cell($grn_link, "align=center");
                                
                                label_cell($row['reference']);
                                
                                $customer_name = get_supplier_formatted_name($row['supplier_id']);
                                label_cell($customer_name);

                                amount_cell($row['ov_amount']);
                                $alllocated_amount = $row['alllocated_amount'];
                                amount_cell($alllocated_amount);
                                
                                $link = get_project_trans_view_str(ST_UTILITY_BILL_CREDIT_NOTE, $row['ub_cn_no']);
                                label_cell($link, "align=center");
\
                            end_row();

                            $total_amount += $alllocated_amount;
                            $count++;
                        }
                        
                        start_row();
                            label_cell(text_bold("Total "),"align=right colspan=6");
                            label_cell(text_bold(number_format($total_amount, 2)),"align=right");
                            label_cell("", "colspan=2");
                        end_row();
                
        end_table(2);
}

function dashboard_view_PROJECT_CF_SUBCONTRACTOR_CREDIT_NOTE_RECEIPTS($project_id, $from_date, $to_date) {
    
    global $systypes_array;


    br(2);
    
    start_table(TABLESTYLE, "width=70%");

            $th = array(" Date","Type", "No", "Reference", "Supplier", "Amount", "Allocated Amount", "Sub. CN No.");
                table_header($th);
                
                    $k = $total_amount = $count = 0;
                    $result = dashboard_view_cf_subcontractor_credit_note_receipts_details(ST_SUBCONTRACTOR_CREDIT_NOTE, $project_id, $from_date, $to_date);
                        while($row = db_fetch($result)) {
                            alt_table_row_color($k);
                                label_cell(sql2date($row['tran_date']),"align=center");
                                label_cell($systypes_array[$row['type']]);
                                $grn_link = get_trans_view_str($row['type'], $row['trans_no']);
                                label_cell($grn_link, "align=center");
                                
                                label_cell($row['reference']);
                                
                                $customer_name = get_supplier_formatted_name($row['supplier_id']);
                                label_cell($customer_name);

                                amount_cell($row['ov_amount']);
                                $alllocated_amount = $row['alllocated_amount'];
                                amount_cell($alllocated_amount);
                                
                                $link = get_project_trans_view_str(ST_SUBCONTRACTOR_CREDIT_NOTE, $row['invoice_no']);
                                label_cell($link, "align=center");
\
                            end_row();

                            $total_amount += $alllocated_amount;
                            $count++;
                        }
                        
                        start_row();
                            label_cell(text_bold("Total "),"align=right colspan=6");
                            label_cell(text_bold(number_format($total_amount, 2)),"align=right");
                            label_cell("", "colspan=2");
                        end_row();
                
        end_table(2);
}


function dashboard_view_PROJECT_CF_PROJECT_INVOICE_RECEIPTS($project_id, $from_date, $to_date) {
    
    global $systypes_array;


    start_table(TABLESTYLE, "width=70%");

            $th = array(" Date","Type", "No", "Reference", "Customer", "Amount", "Allocated Amount", "Proj. Inv. No.");
                table_header($th);
                
                    $k = $total_amount = $count = 0;
                    $result = dashboard_view_cf_project_invoice_receipts_details(ST_PROJECT_INVOICE, $project_id, $from_date, $to_date);
                        while($row = db_fetch($result)) {
                            alt_table_row_color($k);
                                label_cell(sql2date($row['tran_date']),"align=center");
                                label_cell($systypes_array[$row['type']]);
                                $grn_link = get_trans_view_str($row['type'], $row['trans_no']);
                                label_cell($grn_link, "align=center");
                                
                                label_cell($row['reference']);
                                
                                $customer_name = get_customer_formatted_name($row['debtor_no']);
                                label_cell($customer_name);

                                amount_cell($row['ov_amount']);
                                $alllocated_amount = $row['alllocated_amount'];
                                amount_cell($alllocated_amount);
                                
                                $link = get_project_trans_view_str(ST_PROJECT_INVOICE, $row['invoice_no']);
                                label_cell($link, "align=center");
\
                            end_row();

                            $total_amount += $alllocated_amount;
                            $count++;
                        }
                        
                        start_row();
                            label_cell(text_bold("Total "),"align=right colspan=6");
                            label_cell(text_bold(number_format($total_amount, 2)),"align=right");
                            label_cell("", "colspan=2");
                        end_row();
                
        end_table(2);
}


?>