<?php

function dashboard_display_petty_cash_i_owe_yous($from_month_display_requisition, $to_month_display_requisition) {
    
   $month_ranges_array = dashboard_get_month_ranges_array($from_month_display_requisition, $to_month_display_requisition);
   $table_width = dashboard_calculate_table_width($month_ranges_array);
   
   start_table(TABLESTYLE, "width$table_width%");
        
        $th = array("Transaction Type");
            foreach ($month_ranges_array as $month) {
                $th[] = $month['month_name'];
            }

            table_header($th);
        
                dashboard_petty_cash_i_owe_yous_details($month_ranges_array, DASH_VW_PETTY_CASH_I_OWE_YOUS_CREATED, 0);

                dashboard_petty_cash_i_owe_yous_details($month_ranges_array, DASH_VW_PETTY_CASH_I_OWE_YOUS_UNAPPROVED, 1);

                dashboard_petty_cash_i_owe_yous_details($month_ranges_array, DASH_VW_PETTY_CASH_I_OWE_YOUS_APPROVED, 0, AS_APPROVED);

                dashboard_petty_cash_i_owe_yous_types_details($month_ranges_array, DASH_VW_PETTY_CASH_I_OWE_YOUS_EXPENSES_ENTERED, 1);

                dashboard_petty_cash_i_owe_yous_types_details($month_ranges_array, DASH_VW_PETTY_CASH_I_OWE_YOUS_COMPLETED, 0);

                dashboard_petty_cash_i_owe_yous_types_details($month_ranges_array, DASH_VW_PETTY_CASH_EXPENSES_CREATED, 1);

                dashboard_petty_cash_i_owe_yous_types_details($month_ranges_array, DASH_VW_PETTY_CASH_EXPENSES_UNAPPROVED, 0);

                dashboard_petty_cash_i_owe_yous_types_details($month_ranges_array, DASH_VW_PETTY_CASH_EXPENSES_APPROVED, 1);
                
                dashboard_petty_cash_i_owe_yous_types_details($month_ranges_array, DASH_VW_PETTY_CASH_EXPENSES_COMPLETED, 0);
                
                dashboard_petty_cash_i_owe_yous_types_details($month_ranges_array, DASH_VW_PETTY_CASH_EXPENSE_BATCHES_CREATED, 1);
            
                dashboard_petty_cash_i_owe_yous_types_details($month_ranges_array, DASH_VW_PETTY_CASH_EXPENSE_BATCHES_DOCUMENTS_CHECKED, 0);

                dashboard_petty_cash_i_owe_yous_types_details($month_ranges_array, DASH_VW_PETTY_CASH_EXPENSE_BATCHES_UNAPPROVED, 1);
                
                dashboard_petty_cash_i_owe_yous_types_details($month_ranges_array, DASH_VW_PETTY_CASH_EXPENSE_BATCHES_APPROVED, 0);
                
                dashboard_petty_cash_i_owe_yous_types_details($month_ranges_array, DASH_VW_PETTY_CASH_EXPENSE_BATCHES_COMPLETED, 1);
            
    end_table(2);
}

function dashboard_petty_cash_i_owe_yous_details($month_ranges_array, $type, $k=0, $approval_status=null) {
    global $dashboard_view_types_array;
    $ap_st_array = $not_ap_st_array = null;
    
        alt_table_row_color($k);

            label_cell($dashboard_view_types_array[$type]);
            if ($approval_status === null) {
                if ($type === 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);
                } else {
                    $not_ap_st_array = array(AS_REJECTED);
                }
            } else {
                $ap_st_array = array($approval_status);
            }

            foreach ($month_ranges_array as $month) {
                $from_date = $month['month_begin'];
                $to_date = $month['month_end'];
                $parameters = "type=$type&from_date=$from_date&to_date=$to_date";
                $count = dashboard_get_petty_cash_i_owe_yous_details($from_date, $to_date, $ap_st_array, $not_ap_st_array, true);
                
                if ($count > 0) {
                    $str_details = get_dashboard_view_str(DASH_SC_PETTY_CASH_I_OWE_YOUS, $parameters, $count);
                } else {
                    $str_details = "";
                }

                label_cell($str_details, 'align=center');
            }

        end_row();
}

function dashboard_petty_cash_i_owe_yous_types_details($month_ranges_array, $type, $k=0) {
    global $dashboard_view_types_array;
    $ap_st_array = $not_ap_st_array = null;
    
    alt_table_row_color($k);

        label_cell($dashboard_view_types_array[$type]);
        
        switch ($type) {
            case DASH_VW_PETTY_CASH_I_OWE_YOUS_EXPENSES_ENTERED :
                foreach ($month_ranges_array as $month) {
                    $from_date = $month['month_begin'];
                    $to_date = $month['month_end'];
                    $parameters = "type=$type&from_date=$from_date&to_date=$to_date";
                    $count = dashboard_get_petty_cash_i_owe_yous_expenses_entered_details($from_date, $to_date, true);
                    
                    if ($count > 0) {
                        $str_details = get_dashboard_view_str(DASH_SC_PETTY_CASH_I_OWE_YOUS, $parameters, $count);
                    } else {
                        $str_details = "";
                    }
                        
                    label_cell($str_details, 'align=center');
                }
                break;

            case DASH_VW_PETTY_CASH_I_OWE_YOUS_COMPLETED :
                foreach ($month_ranges_array as $month) {
                    $from_date = $month['month_begin'];
                    $to_date = $month['month_end'];
                    $parameters = "type=$type&from_date=$from_date&to_date=$to_date";
                    $count = dashboard_get_petty_cash_i_owe_yous_completed_details($from_date, $to_date, true);
                    
                    if ($count > 0) {
                        $str_details = get_dashboard_view_str(DASH_SC_PETTY_CASH_I_OWE_YOUS, $parameters, $count);
                    } else {
                        $str_details = "";
                    }
                        
                    label_cell($str_details, 'align=center');
                }
                break;

            case DASH_VW_PETTY_CASH_EXPENSES_CREATED :
                $not_ap_st_array = array(AS_REJECTED);
                
                foreach ($month_ranges_array as $month) {
                    $from_date = $month['month_begin'];
                    $to_date = $month['month_end'];
                    $parameters = "type=$type&from_date=$from_date&to_date=$to_date";
                    $count = dashboard_get_petty_cash_expenses_details($from_date, $to_date, $ap_st_array, $not_ap_st_array, true);
                    
                    if ($count > 0) {
                        $str_details = get_dashboard_view_str(DASH_SC_PETTY_CASH_I_OWE_YOUS, $parameters, $count);
                    } else {
                        $str_details = "";
                    }
                        
                    label_cell($str_details, 'align=center');
                }
                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);
                
                foreach ($month_ranges_array as $month) {
                    $from_date = $month['month_begin'];
                    $to_date = $month['month_end'];
                    $parameters = "type=$type&from_date=$from_date&to_date=$to_date";
                    $count = dashboard_get_petty_cash_expenses_details($from_date, $to_date, $ap_st_array, $not_ap_st_array, true);
                    
                    if ($count > 0) {
                        $str_details = get_dashboard_view_str(DASH_SC_PETTY_CASH_I_OWE_YOUS, $parameters, $count);
                    } else {
                        $str_details = "";
                    }
                        
                    label_cell($str_details, 'align=center');
                }
                break;

            case DASH_VW_PETTY_CASH_EXPENSES_APPROVED :
                $ap_st_array = array(AS_APPROVED);
                
                foreach ($month_ranges_array as $month) {
                    $from_date = $month['month_begin'];
                    $to_date = $month['month_end'];
                    $parameters = "type=$type&from_date=$from_date&to_date=$to_date";
                    $count = dashboard_get_petty_cash_expenses_details($from_date, $to_date, $ap_st_array, $not_ap_st_array, true);
                    
                    if ($count > 0) {
                        $str_details = get_dashboard_view_str(DASH_SC_PETTY_CASH_I_OWE_YOUS, $parameters, $count);
                    } else {
                        $str_details = "";
                    }
                        
                    label_cell($str_details, 'align=center');
                }
                break;

            case DASH_VW_PETTY_CASH_EXPENSES_COMPLETED :
                foreach ($month_ranges_array as $month) {
                    $from_date = $month['month_begin'];
                    $to_date = $month['month_end'];
                    $parameters = "type=$type&from_date=$from_date&to_date=$to_date";
                    $count = dashboard_get_petty_cash_expenses_completed_details($from_date, $to_date, true);
                    
                    if ($count > 0) {
                        $str_details = get_dashboard_view_str(DASH_SC_PETTY_CASH_I_OWE_YOUS, $parameters, $count);
                    } else {
                        $str_details = "";
                    }
                        
                    label_cell($str_details, 'align=center');
                }
                break;

            case DASH_VW_PETTY_CASH_EXPENSE_BATCHES_CREATED :
                $not_ap_st_array = array(AS_REJECTED);
                
                foreach ($month_ranges_array as $month) {
                    $from_date = $month['month_begin'];
                    $to_date = $month['month_end'];
                    $parameters = "type=$type&from_date=$from_date&to_date=$to_date";
                    $count = dashboard_get_petty_cash_expense_batches_details($from_date, $to_date, $ap_st_array, $not_ap_st_array, true);
                    
                    if ($count > 0) {
                        $str_details = get_dashboard_view_str(DASH_SC_PETTY_CASH_I_OWE_YOUS, $parameters, $count);
                    } else {
                        $str_details = "";
                    }
                        
                    label_cell($str_details, 'align=center');
                }
                break;

            case DASH_VW_PETTY_CASH_EXPENSE_BATCHES_DOCUMENTS_CHECKED :
                $ap_st_array = array(AS_NEW, AS_BACK_TO_ORIGINATOR, AS_AWAITING_APPROVAL, AS_WITH_THE_APPROVER);
                
                foreach ($month_ranges_array as $month) {
                    $from_date = $month['month_begin'];
                    $to_date = $month['month_end'];
                    $parameters = "type=$type&from_date=$from_date&to_date=$to_date";
                    $count = dashboard_get_petty_cash_expense_batches_checked_details($from_date, $to_date, true);
                    
                    if ($count > 0) {
                        $str_details = get_dashboard_view_str(DASH_SC_PETTY_CASH_I_OWE_YOUS, $parameters, $count);
                    } else {
                        $str_details = "";
                    }
                        
                    label_cell($str_details, 'align=center');
                }
                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);
                
                foreach ($month_ranges_array as $month) {
                    $from_date = $month['month_begin'];
                    $to_date = $month['month_end'];
                    $parameters = "type=$type&from_date=$from_date&to_date=$to_date";
                    $count = dashboard_get_petty_cash_expense_batches_details($from_date, $to_date, $ap_st_array, $not_ap_st_array, true);
                    
                    if ($count > 0) {
                        $str_details = get_dashboard_view_str(DASH_SC_PETTY_CASH_I_OWE_YOUS, $parameters, $count);
                    } else {
                        $str_details = "";
                    }
                        
                    label_cell($str_details, 'align=center');
                }
                break;

            case DASH_VW_PETTY_CASH_EXPENSE_BATCHES_APPROVED :
                $ap_st_array = array(AS_APPROVED);
                
                foreach ($month_ranges_array as $month) {
                    $from_date = $month['month_begin'];
                    $to_date = $month['month_end'];
                    $parameters = "type=$type&from_date=$from_date&to_date=$to_date";
                    $count = dashboard_get_petty_cash_expense_batches_details($from_date, $to_date, $ap_st_array, $not_ap_st_array, true);
                    
                    if ($count > 0) {
                        $str_details = get_dashboard_view_str(DASH_SC_PETTY_CASH_I_OWE_YOUS, $parameters, $count);
                    } else {
                        $str_details = "";
                    }
                        
                    label_cell($str_details, 'align=center');
                }
                break;

            case DASH_VW_PETTY_CASH_EXPENSE_BATCHES_COMPLETED :
                foreach ($month_ranges_array as $month) {
                    $from_date = $month['month_begin'];
                    $to_date = $month['month_end'];
                    $parameters = "type=$type&from_date=$from_date&to_date=$to_date";
                    $count = dashboard_get_petty_cash_expense_batches_completed_details($from_date, $to_date, true);
                    
                    if ($count > 0) {
                        $str_details = get_dashboard_view_str(DASH_SC_PETTY_CASH_I_OWE_YOUS, $parameters, $count);
                    } else {
                        $str_details = "";
                    }
                        
                    label_cell($str_details, 'align=center');
                }
                break;

            default:
                break;
        }

    end_row();
}

?>