<?php
/**********************************************************************
***********************************************************************/


function process_jobq_payroll($jqr){
    global $path_to_root;
    
    $parameters_json = $jqr['parameters'];
    $parameters_json = str_replace("&quot;", '"', $parameters_json);
    $payroll_parameters = json_decode($parameters_json,true);
    
    $payroll_run_id = $payroll_parameters[0]['payroll_run_id'];
    $payroll_processing_type = $payroll_parameters[0]['payroll_processing_type'];

    start_processing_jobq_request($jqr['id']);
    
    if($payroll_processing_type == "CALCULATE"){
            
            include_once($path_to_root."/payroll/includes/payroll_calculation.inc");
            include_once($path_to_root."/payroll/includes/db/payroll_run_db.inc");
            include_once($path_to_root."/payroll/includes/db/payroll_calculation_db.inc");

            $msg = calculate_payroll($payroll_run_id);
    }
    elseif($payroll_processing_type == "CALCULATE_SUMMARY"){
            
            include_once($path_to_root."/payroll/includes/payroll_summary_calculation.inc");
            include_once($path_to_root."/payroll/includes/payroll_calculation.inc");
            include_once($path_to_root."/payroll/includes/db/payroll_run_db.inc");
            include_once($path_to_root."/payroll/includes/db/payroll_calculation_db.inc");
            include_once($path_to_root."/payroll/includes/db/payroll_summary_calculation_db.inc");


            $msg = calculate_payroll_summries($payroll_run_id);
    }
    elseif($payroll_processing_type == "PROCESS"){
        
    }
    else{
            $msg = array("passed" => false, "message" => _("Unknown payroll_processing_type [".$payroll_processing_type."]"));
    }

    $msg_s["success"] = $msg["passed"]; 
    $msg_s["message"] = $msg["message"]; 
    
    complete_jobq_request($jqr, $msg_s, "Payroll calculation completed.");
    
}


?>
