<?php
/**********************************************************************
***********************************************************************/
$page_security = 'SA_CALCULATE_DEPARTMENT_SUMMARY';
$path_to_root = "..";
include_once($path_to_root . "/includes/session.inc");
include_once($path_to_root . "/includes/date_functions.inc");
include_once($path_to_root . "/includes/ui.inc");
include_once($path_to_root . "/includes/inventory.inc");
include_once($path_to_root . "/includes/data_checks.inc");
include_once($path_to_root . "/payroll/includes/process_payroll_calculation.inc");
include_once($path_to_root . "/payroll/includes/ui/calculate_payroll_departments_summary_ui.inc");
include_once($path_to_root . "/payroll/includes/db/calculate_payroll_departments_summary_db.inc");
include_once($path_to_root . "/payroll/includes/db/process_payroll_calculation_db.inc");
include_once($path_to_root . "/payroll/includes/db/payroll_calculation_db.inc");

$js = "";
if ($SysPrefs->use_popup_windows) {
    $js .= get_js_open_window(900, 500);
}
    
page(_($help_context = "Calculate Payroll Departments Summary"), false, false, "", $js);
simple_page_mode(true);

if (isset($_POST['CPCS'])/* && can_process($_POST['payroll_run_id'])*/) {
    if (! ($_POST['payroll_run_id'] > 0)) {
        display_error('Please select a payroll run.');
        return;
    }
    calculate_payroll_components_summary($_POST['payroll_run_id']);
}

if ($Mode == 'RESET') {
    $selected_id = -1;
    unset($_POST);
}

if (list_updated('payroll_run_id')) 
    $Ajax->activate('code_table');

start_form();

    start_table();
        payroll_run_list_row("Payroll Run:", 'payroll_run_id', false, "", true, "all");
    end_table(2);

    div_start('code_table');
        display_calculate_payroll_components_summary($_POST['payroll_run_id']);   
        
        display_get_all_departments_components_summary($_POST['payroll_run_id']);
    div_end();
    
    submit_center_first('CPCS', 'Calculate Payroll Departments Summary', 'Calculate Payroll Departments Summary', false, ICON_SUBMIT);
    br(3);
    
end_form();

end_page();

?>