<?php

/* * ********************************************************************
  Copyright (C) FrontAccounting, LLC.
  Released under the terms of the GNU General Public License, GPL,
  as published by the Free Software Foundation, either version 3
  of the License, or (at your option) any later version.
  This program is distributed in the hope that it will be useful,
  but WITHOUT ANY WARRANTY; without even the implied warranty of
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  See the License here <http://www.gnu.org/licenses/gpl-3.0.html>.
 * ********************************************************************* */

$page_security = 'SA_DASHBOARD_COMPANY_VIEW'; // A very low access level. The real access level is inside the routines.
$path_to_root = "..";

include_once($path_to_root . "/includes/session.inc");
include_once($path_to_root . "/includes/ui.inc");
include_once($path_to_root . "/reporting/includes/class.graphic.inc");
include_once($path_to_root . "/includes/dashboard.inc"); // here are all the dashboard routines.
include_once($path_to_root . "/admin/db/list_values_db.inc");
include_once($path_to_root . "/admin/db/months_db.inc");
include_once($path_to_root . "/admin/db/list_values_db.inc");

include_once($path_to_root . "/dashboard/includes/graphs/all_departments_average_salary_graph.inc");
include_once($path_to_root . "/dashboard/includes/graphs/all_departments_salary_expenses_graph.inc");
include_once($path_to_root . "/dashboard/includes/graphs/all_departments_new_and_resigned_employees_graph.inc");
include_once($path_to_root . "/dashboard/includes/graphs/all_departments_bids_and_new_projects_graph.inc");
include_once($path_to_root . "/dashboard/includes/graphs/all_departments_project_expenses_invoices_and_collections_graph.inc");
include_once($path_to_root . "/dashboard/includes/db/summary_projects_db.inc");
include_once($path_to_root . "/dashboard/includes/db/summary_company_loans_db.inc");
include_once($path_to_root . "/dashboard/includes/db/summary_company_db.inc");
include_once($path_to_root . "/dashboard/includes/db/summary_sales_db.inc");


include_once($path_to_root . "/dashboard/includes/db/summary_payrolls_db.inc");
include_once($path_to_root . "/dashboard/includes/ui/dashboard_ui.inc");


include_once($path_to_root . "/includes/ui/ui_lists_group_companies.inc");
include_once($path_to_root . "/includes/db/group_companies_db.inc");

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

include_once($path_to_root . "/dashboard/includes/tables/bill_approval_report_division_wise_table.inc");
include_once($path_to_root . "/dashboard/includes/tables/ipa_submission_division_wise_table.inc");
include_once($path_to_root . "/dashboard/includes/tables/profit_loss_table_month_range_department_wise.inc");
include_once($path_to_root . "/dashboard/includes/tables/cashflow_table_month_range_department_wise.inc");
include_once($path_to_root . "/dashboard/includes/tables/company_cashflow_table_month_wise.inc");
include_once($path_to_root . "/dashboard/includes/tables/company_profit_loss_table_month_wise.inc");

include_once($path_to_root . "/dashboard/includes/graphs/company_company_profit_loss_graph.inc");
include_once($path_to_root . "/dashboard/includes/graphs/company_company_cash_flow_graph.inc"); 



global $Ajax;

$js = "";
//if ($SysPrefs->use_popup_windows)
$js .= get_js_open_window(800, 500);

page(_($help_context = "Dashboard Company View"), false, false, "", $js);

$Ajax->activate('level0');

$pg0 = new graph();
$pg1 = new graph();
$pg2 = new graph();
$pg3 = new graph();
$pg4 = new graph();
$pg5 = new graph();
$pg6 = new graph();

if(!(isset($_POST['from_month_id']) && $_POST['from_month_id'] > 0)){
    $_POST['from_month_id'] = get_global_dashboard_from_month();
}
if(!(isset($_POST['to_month_id']) && $_POST['to_month_id'] > 0)){
    $_POST['to_month_id'] = get_global_dashboard_to_month();
}

start_form('level0');
div_start();
start_table(TABLESTYLE_NOBORDER, "width=40%");
    months_list_row("From Month:", 'from_month_id', null, false, true);   
    months_list_row("To Month:", 'to_month_id', null, false, true);  
//    group_companies_list_row("Company", 'company_code', null, false, true);  
    $values_array['SAW'] = get_group_company_name('SAW');
    $values_array['VEE'] = get_group_company_name('VEE');
    custom_values_list_row("Company:", 'group_company_code', $values_array, null, false, true);
    
    $groups_array['PAYROLL'] = "Salary Expenses";
    $groups_array['INVOICES'] = "Invoices Submission and Approval";
    $groups_array['PROFIT_LOSS'] = "Profit and Loss";
    $groups_array['CASHFLOW'] = "Cashflow";
    $groups_array['INVOICES_COLLECTIONS'] = "Invoices and Collections";
    $groups_array['BIDS_NEW_PROJECTS'] = "Bids and New Projects";
    $groups_array['DEPARTMENT_SUMMARIES'] = "Department Summaries";
    custom_values_list_row("Group:", 'group_code', $groups_array, null, false, true);
    
table_end();

div_end();

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

//if($_POST['from_month_id'] == $_POST['to_month_id']){
    $Ajax->activate('uda_uda');
//    display_footer_exit();
//}

    
$from_month = get_month($_POST['from_month_id']);
$to_month = get_month($_POST['to_month_id']);


div_start('uda_ddg');

start_table();
$today = Today();

switch ($_POST['group_code']) {
    case 'PAYROLL':
        all_departments_salary_expenses_graph_display($pg1, $_POST['group_company_code'], $from_month['display_order'], $to_month['display_order']);
        br(2);
        all_departments_average_salary_graph_display($pg6, $_POST['group_company_code'], $from_month['display_order'], $to_month['display_order']);
        br(2);
        all_departments_new_and_resigned_employees_graph_display($pg2, $_POST['group_company_code'], $from_month['display_order'], $to_month['display_order']);
        br(2);
        break;
    case 'INVOICES':
        bill_approval_report_division_wise_table_display($_POST['group_company_code'], $from_month['month_begin_date'], $to_month['month_end_date']);
        br(2);
        ipa_submission_division_wise_table_display($_POST['group_company_code'], $from_month['month_begin_date'], $to_month['month_end_date']);
        br(2);
        break;
    case 'PROFIT_LOSS':        
        company_company_profit_loss_graph_display($pg4, $_POST['group_company_code'], $from_month['display_order'], $to_month['display_order']);
        br(2);
        company_profit_loss_table_month_wise_display($_POST['group_company_code'], $from_month['display_order'], $to_month['display_order']);
        br(2);
        break;
    case 'CASHFLOW':        
        company_company_cash_flow_graph_display($pg5, $_POST['group_company_code'], $from_month['display_order'], $to_month['display_order']);
        br(2);
        company_cashflow_table_month_wise_display($_POST['group_company_code'], $from_month['display_order'], $to_month['display_order']);
        br(2);
        break;
    case 'INVOICES_COLLECTIONS':
        all_departments_project_expenses_invoices_and_collections_graph_display($pg3, $_POST['group_company_code'], $from_month['display_order'], $to_month['display_order']);
        br(2);
        break;
    case 'BIDS_NEW_PROJECTS':
        all_departments_bids_and_new_projects_graph_display($pg0, $_POST['group_company_code'], $from_month['display_order'], $to_month['display_order']);
        br(2);
        break;
    case 'DEPARTMENT_SUMMARIES':
        department_pl_table_month_range_department_wise_display($_POST['group_company_code'], $from_month['display_order'], $to_month['display_order']);
        br(2);
        department_cf_table_month_range_department_wise_display($_POST['group_company_code'], $from_month['display_order'], $to_month['display_order']);
        br(2);
        break;
    default:
        
        break;
}








		




table_end();
div_end();
end_form();

end_page();
























