<?php

function display_dashboard_project_filtering_parameters() {
    
    dashboard_set_from_to_months('from_month_id', 'to_month_id');
    
    
    start_table(TABLESTYLE);
    
        project_list_row("Project", 'project_id', null, 'Select a project', true);
        $dash_purchs_array = get_dashboard_project_view_types_array();
        custom_values_list_row("Type:", 'group_code', $dash_purchs_array, null, false, true);
        
        months_list_row("From Month:", 'from_month_id', null, false, true);   
        months_list_row("To Month:", 'to_month_id', null, false, true);  

        set_global_dashboard_from_month($_POST['from_month_id']);
        set_global_dashboard_to_month($_POST['to_month_id']);
    end_table(1);

    start_table(TABLESTYLE);
        start_row();
            submit_center_first('DashboardPurch', "Display", '', 'process', ICON_OK);
        end_row();
    end_table(2);
}

function get_dashboard_project_view_types_array() {
    $dash_purchs_array = array();
    
        $dash_purchs_array['EXPENSES'] = "Petty Cash Expenses"; 
        $dash_purchs_array['CONSUMPTION_VALUE'] = "Item Consumption (Value)"; 
        $dash_purchs_array['CONSUMPTION_QTY'] = "Item Consumption (Quantity)"; 
        $dash_purchs_array['PROFIT_AND_LOSS'] = "Profit and Loss"; 
        $dash_purchs_array['CASH_FLOW'] = "Cash Flow"; 
        $dash_purchs_array['APPROVALS'] = "Approvals"; 
        
        return $dash_purchs_array;
}

function display_dashboard_project_view() {
    global $path_to_root, $Ajax;

    $from_month = get_month(get_global_dashboard_from_month());
    $to_month = get_month(get_global_dashboard_to_month());

    $Ajax->activate('uda_ddg');
        div_start('uda_ddg');

            start_table();

                switch ($_POST['group_code']) {
                    case 'EXPENSES':
                        include_once("$path_to_root/dashboard/includes/ui/dashboard_project_expenses_ui.inc");
                        include_once($path_to_root . "/dashboard/includes/db/dashboard_project_expenses_db.inc"); 
                        dashboard_project_expenses($from_month['display_order'], $to_month['display_order'], $_POST['project_id']);
                        break;
                    case 'CONSUMPTION_VALUE':
                        include_once("$path_to_root/dashboard/includes/ui/dashboard_project_item_consumption_ui.inc");
                        include_once($path_to_root . "/dashboard/includes/db/dashboard_project_item_consumption_db.inc"); 
                        include_once($path_to_root . "/dashboard/includes/db/dashboard_inventory_item_consumption_db.inc"); 
                        dashboard_project_item_consuption($from_month['display_order'], $to_month['display_order'], $_POST['project_id'], 1);
                        break;
                    case 'CONSUMPTION_QTY':
                        include_once("$path_to_root/dashboard/includes/ui/dashboard_project_item_consumption_ui.inc");
                        include_once($path_to_root . "/dashboard/includes/db/dashboard_project_item_consumption_db.inc"); 
                        include_once($path_to_root . "/dashboard/includes/db/dashboard_inventory_item_consumption_db.inc"); 
                        dashboard_project_item_consuption($from_month['display_order'], $to_month['display_order'], $_POST['project_id'], 2);
                        break;
                    case 'PROFIT_AND_LOSS':
                        include_once("$path_to_root/dashboard/includes/ui/dashboard_project_profit_loss_ui.inc");
                        include_once($path_to_root . "/projects/includes/db/project_status_view_db.inc"); 
                        include_once($path_to_root . "/projects/includes/db/projects_db.inc"); 
                        include_once($path_to_root . "/projects/includes/ui/project_status_view_ui.inc"); 
                        dashboard_project_profit_and_loss($from_month['display_order'], $to_month['display_order'], $_POST['project_id']);
                        break;
                    case 'CASH_FLOW':
                        include_once("$path_to_root/dashboard/includes/ui/dashboard_project_cash_flow_ui.inc");
                        include_once("$path_to_root/dashboard/includes/ui/dashboard_project_profit_loss_ui.inc");
                        include_once("$path_to_root/dashboard/includes/db/dashboard_project_cash_flow_db.inc"); 
                        include_once($path_to_root . "/projects/includes/db/project_status_view_db.inc"); 
                        include_once($path_to_root . "/projects/includes/db/projects_db.inc"); 
                        include_once($path_to_root . "/projects/includes/ui/project_status_view_ui.inc"); 
                        dashboard_project_cash_flow($from_month['display_order'], $to_month['display_order'], $_POST['project_id']);
                        break;                    
                    case 'APPROVALS':
                        include_once("$path_to_root/dashboard/includes/ui/dashboard_approvals_ui.inc");
                        include_once("$path_to_root/dashboard/includes/db/dashboard_approvals_db.inc"); 
                        include_once("$path_to_root/dashboard/includes/ui/dashboard_project_approvals_ui.inc");
                        include_once("$path_to_root/dashboard/includes/db/dashboard_project_approvals_db.inc"); 
                        dashboard_project_approvals($from_month['display_order'], $to_month['display_order']);
                        break;
                    
                    
                        
                    default:        
                        break;
                }

            end_table(2);
        div_end();
}

?>