<?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_SALES_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/sales_top_customers_graph.inc");
include_once($path_to_root . "/dashboard/includes/graphs/sales_top_items_graph.inc");
include_once($path_to_root . "/dashboard/includes/graphs/departments_wise_sales_for_the_period_graph.inc");
include_once($path_to_root . "/dashboard/includes/graphs/sales_monthly_graph.inc");

include_once($path_to_root . "/dashboard/includes/tables/sales_least_markup_items_table.inc");
include_once($path_to_root . "/dashboard/includes/db/summary_projects_db.inc");

include_once($path_to_root . "/dashboard/includes/db/summary_payrolls_db.inc");
include_once($path_to_root . "/dashboard/includes/db/summary_sales_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 . "/includes/ui/ui_lists.inc");

include_once($path_to_root . "/dashboard/includes/db/dashboard_db.inc");



global $Ajax;

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

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

$Ajax->activate('level0');

$pg0 = new graph();
$pg1 = new graph();
$pg2 = new graph();
$pg3 = 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=60%");

months_list_row("From Month:", 'from_month_id', null, false, true);   
months_list_row("To Month:", 'to_month_id', 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']);

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

div_start('uda_ddg');



start_table();
$today = Today();

$company_code = 'SAWHO';

monthly_sales_graph_display($pg3, $company_code, $from_month['display_order'], $to_month['display_order']);
br(2);
department_wise_period_sales_graph_display($pg2, $company_code, $from_month['display_order'], $to_month['display_order']);
br(2);
sales_least_markup_items_table_display($company_code, $from_month['month_begin_date'], $to_month['month_end_date']);
br(2);
sales_top_customers_graph_display($pg0, $from_month['month_begin_date'], $to_month['month_end_date']);
br(2);
sales_top_items_graph_display($pg1, $from_month['month_begin_date'], $to_month['month_end_date']);
br(2);


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

end_page();

