<?php

function dashboard_petty_cash_i_owe_yous_views($view_type, $from_date, $to_date) {
    $ap_st_array = $not_ap_st_array = null;
     
    switch ($view_type) {
        case DASH_VW_PETTY_CASH_I_OWE_YOUS_CREATED:
            $not_ap_st_array = array(AS_REJECTED);
            
            $result = view_dashboard_get_petty_cash_i_owe_yous_details($from_date, $to_date, $ap_st_array, $not_ap_st_array); 
                dashboard_print_petty_cash_i_owe_yous_type_details($view_type, $result, ST_I_OWE_YOU);
            break;
        
        case DASH_VW_PETTY_CASH_I_OWE_YOUS_UNAPPROVED:
            $ap_st_array = array(AS_NEW, AS_BACK_TO_ORIGINATOR, AS_AWAITING_APPROVAL, AS_WITH_THE_APPROVER);
            
            $result = view_dashboard_get_petty_cash_i_owe_yous_details($from_date, $to_date, $ap_st_array); 
                dashboard_print_petty_cash_i_owe_yous_type_details($view_type, $result, ST_I_OWE_YOU);
            break;
        
        case DASH_VW_PETTY_CASH_I_OWE_YOUS_APPROVED:
            $ap_st_array = array(AS_APPROVED);
            
            $result = view_dashboard_get_petty_cash_i_owe_yous_details($from_date, $to_date, $ap_st_array); 
                dashboard_print_petty_cash_i_owe_yous_type_details($view_type, $result, ST_I_OWE_YOU);
            break;
        
        case DASH_VW_PETTY_CASH_I_OWE_YOUS_EXPENSES_ENTERED:
            $result = view_dashboard_get_petty_cash_i_owe_yous_expenses_entered_details($from_date, $to_date); 
                dashboard_print_petty_cash_i_owe_yous_type_details($view_type, $result, ST_I_OWE_YOU);
            break;
        
        case DASH_VW_PETTY_CASH_I_OWE_YOUS_COMPLETED:
            $result = view_dashboard_get_petty_cash_i_owe_yous_completed_details($from_date, $to_date); 
                dashboard_print_petty_cash_i_owe_yous_type_details($view_type, $result, ST_I_OWE_YOU);
            break;
        
        case DASH_VW_PETTY_CASH_EXPENSES_CREATED:
            $not_ap_st_array = array(AS_REJECTED);
            
            $result = view_dashboard_get_petty_cash_expenses_details($from_date, $to_date, $ap_st_array, $not_ap_st_array); 
                dashboard_print_petty_cash_i_owe_yous_type_details($view_type, $result, ST_PETTY_CASH);
            break;
        
        case DASH_VW_PETTY_CASH_EXPENSES_UNAPPROVED:
            $ap_st_array = array(AS_NEW, AS_BACK_TO_ORIGINATOR, AS_AWAITING_APPROVAL, AS_WITH_THE_APPROVER);
            
            $result = view_dashboard_get_petty_cash_expenses_details($from_date, $to_date, $ap_st_array); 
                dashboard_print_petty_cash_i_owe_yous_type_details($view_type, $result, ST_PETTY_CASH);
            break;
        
        case DASH_VW_PETTY_CASH_EXPENSES_APPROVED:
            $ap_st_array = array(AS_APPROVED);
            
            $result = view_dashboard_get_petty_cash_expenses_details($from_date, $to_date, $ap_st_array); 
                dashboard_print_petty_cash_i_owe_yous_type_details($view_type, $result, ST_PETTY_CASH);
            break;
        
        case DASH_VW_PETTY_CASH_EXPENSES_COMPLETED:
            $result = view_dashboard_get_petty_cash_expenses_completed_details($from_date, $to_date); 
                dashboard_print_petty_cash_i_owe_yous_type_details($view_type, $result, ST_PETTY_CASH);
            break;
        
        case DASH_VW_PETTY_CASH_EXPENSE_BATCHES_CREATED:
            $not_ap_st_array = array(AS_REJECTED);
            
            $result = view_dashboard_get_petty_cash_expense_batches_details($from_date, $to_date, $ap_st_array, $not_ap_st_array); 
                dashboard_print_petty_cash_i_owe_yous_type_details($view_type, $result, ST_I_OWE_YOU_BATCH, true);
            break;
        
        case DASH_VW_PETTY_CASH_EXPENSE_BATCHES_DOCUMENTS_CHECKED:
            $result = view_dashboard_get_petty_cash_expense_batches_checked_details($from_date, $to_date); 
                dashboard_print_petty_cash_i_owe_yous_type_details($view_type, $result, ST_I_OWE_YOU_BATCH, true);
            break;
        
        case DASH_VW_PETTY_CASH_EXPENSE_BATCHES_UNAPPROVED:
            $ap_st_array = array(AS_NEW, AS_BACK_TO_ORIGINATOR, AS_AWAITING_APPROVAL, AS_WITH_THE_APPROVER);
            
            $result = view_dashboard_get_petty_cash_expense_batches_details($from_date, $to_date, $ap_st_array); 
                dashboard_print_petty_cash_i_owe_yous_type_details($view_type, $result, ST_I_OWE_YOU_BATCH, true);
            break;
        
        case DASH_VW_PETTY_CASH_EXPENSE_BATCHES_APPROVED:
            $ap_st_array = array(AS_APPROVED);
            
            $result = view_dashboard_get_petty_cash_expense_batches_details($from_date, $to_date, $ap_st_array); 
                dashboard_print_petty_cash_i_owe_yous_type_details($view_type, $result, ST_I_OWE_YOU_BATCH, true);
            break;
        
        case DASH_VW_PETTY_CASH_EXPENSE_BATCHES_COMPLETED:
            $result = view_dashboard_get_petty_cash_expense_batches_completed_details($from_date, $to_date); 
                dashboard_print_petty_cash_i_owe_yous_type_details($view_type, $result, ST_I_OWE_YOU_BATCH, true);
            break;
    }
}

function dashboard_print_petty_cash_i_owe_yous_type_details($view_type, $result, $type, $no_ref_n_emp=false) {
    global $systypes_array, $dashboard_view_types_array, $document_approval_statuses;
    
        display_heading($systypes_array[$type].' - '.$dashboard_view_types_array[$view_type]);    br();

            if ($no_ref_n_emp === true) {
                $th = array("Tran Date", "#", "Project", "Approval Status", "Total");
                $width = "65";
                $colspan = 2;
            } else {
                $th = array("Tran Date", "#", "Reference", "Employee", "Project", "Approval Status", "Total");
                $width = "80";
                $colspan = 4;
            }
            
            start_table(TABLESTYLE, "width=$width%");
                table_header($th);
                
                    $k = $total_amount = $count = 0;
                        while($row = db_fetch($result)) {
                            alt_table_row_color($k);
                                label_cell(sql2date($row['tran_date']),"align=center");
                                $link = get_petty_cash_trans_view_str($type, $row['id']);
                                label_cell($link, "align=center");
                                
                                if ($no_ref_n_emp === false) {
                                    label_cell($row['reference']);
                                    label_cell(get_group_company_employee_formatted_long_name($row['company_code'], $row['employee_code']));
                                }
                                
                                label_cell($row['project_name']);
                                label_cell($document_approval_statuses[$row['approval_status']], "align=center");
                                $total = $row["amount"];
                                label_cell(number_format($total, 2),"align=right");
                            end_row();

                            $total_amount += $total;
                            $count++;
                        }
                        
                        start_row();
                            label_cell(text_bold('Count'), "align=right");
                            label_cell(text_bold($count),"align=center");
                            label_cell(text_bold('Total'), "align=right colspan=$colspan");
                            label_cell(text_bold(number_format($total_amount, 2)),"align=right");
                        end_row();
                
            end_table(2);
}

?>