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

	Released under the terms of the GNU General Public License, GPL,
***********************************************************************/
$page_security = 'SA_ITEMSVALREP';
// ----------------------------------------------------------------
// $ Revision:	2.0 $
// Creator:	Joe Hunt
// date_:	2005-05-19
// Title:	Stock Check Sheet
// ----------------------------------------------------------------
$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/data_checks.inc");
include_once($path_to_root . "/gl/includes/gl_db.inc");
include_once($path_to_root . "/inventory/includes/inventory_db.inc");
include_once($path_to_root . "/payroll/includes/payroll_calculation/pc_functions.inc");
include_once($path_to_root . "/payroll/includes/db/payroll_calculation_db.inc");
include_once($path_to_root . "/admin/db/list_values_db.inc");
include_once($path_to_root . "/payroll/includes/db/salary_totals_db.inc");
include_once($path_to_root . "/payroll/includes/db/employees_db.inc");
include_once($path_to_root . "/payroll/includes/db/employee_departments_db.inc");
include_once($path_to_root . "/payroll/includes/db/job_details_db.inc");


//----------------------------------------------------------------------------------------------------

print_dep_salary_expences();

function get_payroll_employees($payroll_run_id, $from_employee, $to_employee)
{
	$sql = " SELECT DISTINCT prd.employee_code 
                 FROM ".TB_PREF."payroll_run_details prd, 
                        ".TB_PREF."payroll_runs pr   
                 WHERE prd.payroll_run_id = pr.id AND 
                        prd.employee_code <> '' AND 
                        pr.id = ".db_escape($payroll_run_id)  ;
        
        if(strlen($from_employee) > 0){
            $sql .= " AND prd.employee_code >= ".db_escape($from_employee);
        }
        
        if(strlen($to_employee) > 0){
            $sql .= " AND prd.employee_code <= ".db_escape($to_employee);
        }
        
	$sql .= " ORDER BY prd.employee_code";
	return db_query($sql, "Could not retreive payroll employess");
}

function get_componant_names($payroll_run_id)
{
        $sql = "SELECT lv.list_code, lv.value_code, lv.value_name  
                FROM ".TB_PREF."list_values lv 
                WHERE lv.list_code IN(".PAYROLL_LISTS.")";
              
    
   	$result = db_query($sql, "Payslip details could not be retrieved");

        while($myrow=db_fetch($result)){
            $componanet_names[$myrow['value_code']] = $myrow['value_name'];
        }
         
        $componanet_names["LOAN_DEDUCTIONS"] = "Loan Deductions";
        return $componanet_names;
}


function get_employer_contribution($payroll_run_id, $employee)
{
        $sql = "SELECT prd.*, lv.list_code, lv.value_name  
                FROM ".TB_PREF."payroll_run_details prd, 
                        ".TB_PREF."payroll_runs pr, 
                        ".TB_PREF."list_values lv,  
                        ".TB_PREF."payroll_calculation_seq pcs 
                WHERE prd.payroll_run_id = pr.id AND 
                        pr.payroll_id = pcs.payroll_id AND 
                        pcs.process_code = prd.component AND  
                        pcs.process_code = lv.value_code AND 
                        lv.list_code IN('COMMON_SALARY_COMP','STATUTORY_DEDUCTIONS') AND 
                        prd.payroll_run_id = ".db_escape($payroll_run_id)." AND 
                        prd.employee_code = ".  db_escape($employee)." 
                ORDER BY pcs.seq_no";
    
   	$result = db_query($sql, "Payslip details could not be retrieved");

        return $result;
}


function get_employeee_details($employee,$end_date)
{
        $sql = "SELECT em.* , IFNULL(dn.value_name,' --') department_name
                FROM ".TB_PREF."employee_master em
                LEFT JOIN ".TB_PREF."employee_departments ed ON 
                em.employee_code = ed.employee_code AND 
                ed.start_date <= '$end_date' AND ed.end_date >= '$end_date'
                LEFT JOIN ".TB_PREF."list_values dn ON
                ed.department_id=dn.id 
                WHERE em.employee_code = ".db_escape($employee);
        
   	$result = db_query($sql, "Employee details could not be retrieved");

        return db_fetch($result);
}


function get_payroll_run_details($payroll_run_id)
{
        $sql = "SELECT * 
                FROM ".TB_PREF."payroll_runs  
                WHERE id = ".  db_escape($payroll_run_id);
        
   	$result = db_query($sql, "Payroll run details could not be retrieved");

        return db_fetch($result);
}


function print_dep_sal_details($rep, $comp_name, $component_value)
{
    $rep->NewLine();
    $rep->TextCol(0, 1, $comp_name);
    $value = number_format($component_value,2);
    $rep->TextCol(1, 2, $value);
}

function display_department_sub_heading($rep, $dep_salary_row)
{
    $rep->NewPage(); 
    $rep->NewLine(); 
    $rep->Font('bold'); 
    $rep->TextCol(0, 1, $dep_salary_row['department_code']." - ".$dep_salary_row['department_name'] );
    $rep->Font(''); 
    $rep->NewLine(); 
}

function get_employees_for_salary_report($payroll_run_id, $filtering_employee_from,$filtering_employee_to)
{
	$sql = " SELECT DISTINCT prd.employee_code
                 FROM ".TB_PREF."payroll_run_details prd
                 WHERE prd.payroll_run_id =".db_escape($payroll_run_id);
        
        if(strlen($filtering_employee_from) > 0){
            $sql .= " AND prd.employee_code >= ".db_escape($filtering_employee_from);
        }
         if(strlen($filtering_employee_to) > 0){
            $sql .= " AND prd.employee_code <= ".db_escape($filtering_employee_to);
        }
	$sql .= " ORDER BY prd.employee_code";
	return db_query($sql, "Could not retreive payroll employess");
}

//
//function get_employees_for_salary_report($start_date,$to_date, $payroll_run_id,$from_employee,$to_employee)
//{
//
//
//        $sql = "SELECT em.*, 
//                        IFNULL((SELECT ed1.department_id FROM ".TB_PREF."employee_departments ed1   
//                                   WHERE vpe.employee_code = ed1.employee_code AND ed1.start_date <= ".db_escape($to_date)." 
//                                   ORDER BY ed1.start_date DESC LIMIT 1), 0) department_id,
//                        IFNULL((SELECT value_code FROM ".TB_PREF."list_values dn WHERE dn.id = department_id), 'NO_DEPARTMENT') department_code, 
//                        IFNULL((SELECT value_name FROM ".TB_PREF."list_values dn WHERE dn.id = department_id), 'No Department Entered') department_name                         
//                FROM ".TB_PREF."vw_payroll_employees vpe 
//                        INNER JOIN ".TB_PREF."employee_master em ON 
//                            vpe.employee_code = em.employee_code                                                                 
//                WHERE  1=1 
//                            AND vpe.payroll_run_id = ".db_escape($payroll_run_id);
//     
//     
//        if($from_employee != "-1")
//        {
//          $sql .= " em.employee_code >= ".db_escape($from_employee);
//        }
//        if($to_employee != "-1")
//        {
//          $sql .= " em.employee_code <= ".db_escape($from_employee);
//        }  
//                       
//       
//        $sql .= " ORDER BY em.employee_code ";
//        
//       
//        
//        return  $result= db_query($sql,"Employee details could not be retreived");
//}

function get_employee_salary_component_result($payroll_run_id,$employee, $components_in)
{
        $sql = "SELECT SUM(value) component_sum   
                FROM ".TB_PREF."payroll_run_details 
                WHERE payroll_run_id = ".$payroll_run_id." AND component IN (".$components_in.") 
                AND employee_code=".db_escape($employee);
            
        
   	$result = db_query($sql, "ETF salary components could not be retrieved");

        $value = db_fetch($result);
        if($value){
            return $value['component_sum'];
        }
        else{
            return 0;
        }
}


function get_departments($department)  
 {
            $sql = "SELECT  
                ls.value_name department_name
                FROM 
                " .TB_PREF."list_values ls WHERE ls.id=".db_escape($department);
            
       $result = db_query($sql, "Status could not be retrieved");
       return db_fetch($result);
 }
 
 function initialize_additions_array(&$arr)
 {
     $arr['BASIC_SALARY'] = 0;
     $arr['BRA_1'] = 0;
     $arr['BRA_2'] = 0;
     $arr['SALARY_FOR_OT'] = 0;
//     $arr['SALARY_TOTAL_2'] = 0;
     $arr['APPLICABLE_INSENTIVE'] =0;
     $arr['INCENTIVE_ARREARS']=0;
     $arr['INCENTIVE']=0;
     $arr['BANKING_INCENTIVE_II']=0;
     $arr['BANKING_INCENTIVE']=0;
     $arr['BANKING_INCENTIVE_I']=0;
     $arr['SALARY_TOTAL_1']=0;
     $arr['NO_PAY_DEDUCTIONS']=0;
     $arr['SALARY_FOR_EPF']=0;
     $arr['COMP_EPF_8']=0;
     $arr['PAYE']=0;
     $arr['COMP_PAYE']=0;
     $arr['ADDONS_TO_EPF_SALARY']=0;
     $arr['OVER_TIME']=0;
     $arr['SINGLE_OT_HOURS']=0;
     $arr['SINGLE_OT_RATE']=0;
     $arr['SINGLE_OT_AMOUNT']=0;
     $arr['DOUBLE_OT_HOURS']=0;
     $arr['DOUBLE_OT_RATE']=0;
     $arr['DOUBLE_OT_AMOUNT']=0;
     $arr['OT_TOTAL']=0;
     $arr['VEHICLE_REIMBURSEMEN']=0;
//     $arr['SALARY_TOTAL_1']=0;
     $arr['ACCOMMODATION_1']=0;
     $arr['FUEL_ALLOWANCES']=0;
     $arr['FUEL_REIMBURSEMENT_T']=0;
     
     $arr['MEAL_REIMBURSEMENT']=0;
     $arr['MEAL_REIMBURSEMENT_T']=0;
     $arr['SITE_EXPENSES']=0;
     $arr['TRAVELLING_ALLOWANCE']=0;
     $arr['COMMISSION']=0;
     $arr['SAVINGS_COMMISSION']=0;
     $arr['DRIVING_ALLOWANCE']=0;
     
     $arr['SPECIAL_ATTENDANCE']=0;
//     $arr['SALES_COMMISSION']=0;
     $arr['SPECIAL_PAYMENT']=0;
     $arr['SPECIAL_PAYMENT1']=0;
     $arr['ATTENDANCE_INCENTIVE']=0;
      $arr['POWDER_COATING_ALL']=0;
     $arr['NO_PAY_REFUND']=0;
     $arr['LOAN_INSTALLMENTS']=0;
     
//     $arr['LOAN_INSTALLMENTS']=0;
     $arr['DATA_OVER_LIMIT']=0;
     $arr['MOBILE_DEDUCTION_1']=0;
     $arr['WATER_ELECTRICITY']=0;
     $arr['Water_Electricity']=0;
     $arr['INSURANCE']=0;
     $arr['WELFARE_REGISTRATION']=0;
     $arr['WELFARE']=0;
     
//     $arr['SALARY_ADVANCE']=0;
      $arr['PANELTY']=0;
     $arr['SALARY_ADVANCES']=0;
    
     $arr['EPF_DEDUCTION']=0;
     $arr['OTHER_DEDUCTIOIN']=0;
     $arr['OTHER_DEDUCTIOIN_2']=0;
     $arr['EPF_12%']=0;
     $arr['ETF_3%']=0;
     
     $arr['BANKING_INCENT_TOTAL']=0;
//     $arr['BASIC_NOPAY_DAYS']=0;
//     $arr['NOPAY_1_RATE']=0;
//     $arr['NOPAY_1_AMOUNT']=0;
//     $arr['INSENTIVE_NOPAY_DAYS']=0;
//     $arr['NOPAY_2_RATE']=0;
//     $arr['NOPAY_2_AMOUNT']=0;
     
     $arr['ADDONS_FROM_BASIC']=0;
     $arr['ADDONS_TO_INSENTIVE']=0;
     $arr['TOTAL_ADDONS']=0;
     $arr['BASIC_SALARY_NET']=0;
     
     $arr['NET_INSENTIVE']=0;
     $arr['NET_PAY_TO_BANK']=0;
     $arr['ROUNDING_OFF']=0;
     $arr['BF']=0;
    
     
 }

 
 
 
 function get_employee_loan_amount($payroll_run_id,$employee_code)
 {
    $sql="SELECT  SUM(li.installment_amount) loan_amount
          FROM " .TB_PREF."loan_installments li
          LEFT JOIN ".TB_PREF."loans lo ON
                  lo.id=li.loan_id
          WHERE li.status_code='Y' AND li.payroll_run_id=".db_escape($payroll_run_id)." AND lo.employee_code=".db_escape($employee_code);
              

       $result = db_query($sql, "Loan deduction amount can not be retrieved");            
       
       $value = db_fetch($result);
        if($value){
            return $value['loan_amount'];
        }
        else{
            return 0;
        }
     
 }
 
 function add_to_report_totals(&$rpt_totals, &$emp)
 {

    foreach ($rpt_totals as $key => $value) {
        $rpt_totals[$key] += abs($emp[$key]);
        $emp[$key] = 0;        
    }
    
 }
 
 function get_employee_loan_deduc_result($payroll_run_id,$employee_code)
 {
     $loan_amount=get_employee_loan_amount($payroll_run_id,$employee_code);
     return $loan_amount;
 }
 
 function display_component_values(&$rep, $dept, $component_names, $grand_totals = false) // type (STD, OTHR, STAT, GRND)
 {
//     $i=6;
//     foreach ($dept as $key => $value) {
//         
//          $rep->TextCol($i, $i+1, $key);
//         
//          $i++;
//     }
//     $rep->NewLine();
    $dept_additions_total = 0;
    foreach ($dept as $key => $value) {
        
        if($key == 'BASIC_SALARY'){
           $rep->TextCol(6, 7, number_format($dept[$key],2));

        }
        elseif($key == 'BRA_1'){
//           $rep->TextCol($i, $i+1, "Fuel Reimbursement");
           $rep->TextCol(7, 8, number_format($dept[$key],2));

        }
        elseif($key == 'BRA_2'){
           $rep->TextCol(8, 9, number_format($dept[$key],2));

        }
        elseif($key == 'SALARY_FOR_OT'){
           $rep->TextCol(9, 10, number_format($dept[$key],2));

        }
       
         elseif($key == 'APPLICABLE_INSENTIVE'){
           $rep->TextCol(10, 11, number_format($dept[$key],2));

        }
        elseif($key == 'INCENTIVE_ARREARS'){
           $rep->TextCol(11, 12, number_format($dept[$key],2));

        }
        elseif($key == 'INCENTIVE'){
           $rep->TextCol(12, 13, number_format($dept[$key],2));

        }
         elseif($key == 'BANKING_INCENTIVE_II'){
           $rep->TextCol(13, 14, number_format($dept[$key],2));

        }
          elseif($key == 'BANKING_INCENTIVE'){
           $rep->TextCol(14, 15, number_format($dept[$key],2));

        }
        elseif($key == 'BANKING_INCENTIVE_I'){
           $rep->TextCol(15, 16, number_format($dept[$key],2));

        }
        elseif($key == 'SALARY_TOTAL_1'){
           $rep->TextCol(16, 17, number_format($dept[$key],2));

        }
         elseif($key == 'NO_PAY_DEDUCTIONS'){
           $rep->TextCol(17, 18, number_format($dept[$key],2));

        }
         elseif($key == 'SALARY_FOR_EPF'){
           $rep->TextCol(18, 19, number_format($dept[$key],2));

        }
        elseif($key == 'COMP_EPF_8'){
           $rep->TextCol(19, 20, number_format($dept[$key],2));

        }
         elseif($key == 'PAYE' || $key == 'COMP_PAYE'){
           $rep->TextCol(20, 21, number_format($dept[$key],2));

        }
        elseif($key == 'ADDONS_TO_EPF_SALARY'){
           $rep->TextCol(21, 22, number_format($dept[$key],2));

        }
         elseif($key == 'OVER_TIME'){
           $rep->TextCol(22, 23, number_format($dept[$key],2));

        }
        elseif($key == 'SINGLE_OT_HOURS'){
           $rep->TextCol(23, 24, $dept[$key]);

        }
         elseif($key == 'SINGLE_OT_RATE'){
           $rep->TextCol(24, 25, number_format($dept[$key],2));

        }
         elseif($key == 'SINGLE_OT_AMOUNT'){
           $rep->TextCol(25, 26, number_format($dept[$key],2));

        }
         elseif($key == 'DOUBLE_OT_HOURS'){
           $rep->TextCol(26, 27, $dept[$key]);

        }
        elseif($key == 'DOUBLE_OT_RATE'){
           $rep->TextCol(27, 28, number_format($dept[$key],2));

        }
         elseif($key == 'DOUBLE_OT_AMOUNT'){
           $rep->TextCol(28, 29, number_format($dept[$key],2));

        }
           elseif($key == 'OT_TOTAL'){
           $rep->TextCol(29, 30, number_format($dept[$key],2));

        }
         elseif($key == 'VEHICLE_REIMBURSEMEN'){
           $rep->TextCol(30, 31, number_format($dept[$key],2));

        }
         elseif($key == 'ACCOMMODATION_1'){
           $rep->TextCol(31, 32, number_format($dept[$key],2));

        }
        
        elseif($key == 'FUEL_ALLOWANCES'){
          $rep->TextCol(32, 33, number_format($dept[$key],2));
        }
         elseif($key == 'FUEL_REIMBURSEMENT_T'){
          $rep->TextCol(33, 34, number_format($dept[$key],2));
        }
         elseif($key == 'MEAL_REIMBURSEMENT'){
           $rep->TextCol(34, 35, number_format($dept[$key],2));

        }
           elseif($key == 'MEAL_REIMBURSEMENT_T'){
           $rep->TextCol(35, 36, number_format($dept[$key],2));

        }
        elseif($key == 'SITE_EXPENSES'){
           $rep->TextCol(36, 37, number_format($dept[$key],2));

        }
         elseif($key == 'TRAVELLING_ALLOWANCE'){
           $rep->TextCol(37, 38, number_format($dept[$key],2));

        }
        elseif($key == 'COMMISSION'){
          $rep->TextCol(38, 39, number_format($dept[$key],2));
        }
         elseif($key == 'SAVINGS_COMMISSION'){
           $rep->TextCol(39, 40, number_format($dept[$key],2));

        }
        elseif($key == 'DRIVING_ALLOWANCE'){
          $rep->TextCol(40, 41, number_format($dept[$key],2));
        }
        elseif($key == 'SPECIAL_ATTENDANCE'){
           $rep->TextCol(41, 42, number_format($dept[$key],2));

        }
//         elseif($key == 'SALES_COMMISSION'){
//           $rep->TextCol(42, 43, number_format($dept[$key],2));
//
//        }
        elseif($key == 'SPECIAL_PAYMENT'){
          $rep->TextCol(42, 43, number_format($dept[$key],2));
        }
        elseif($key == 'SPECIAL_PAYMENT1'){
          $rep->TextCol(43, 44, number_format($dept[$key],2));
        }
          elseif($key == 'ATTENDANCE_INCENTIVE'){
           $rep->TextCol(44, 45, number_format($dept[$key],2));

        }
        elseif($key == 'POWDER_COATING_ALL'){
           $rep->TextCol(45, 46, number_format($dept[$key],2));

        }
        elseif($key == 'NO_PAY_REFUND'){
          $rep->TextCol(46, 47, number_format($dept[$key],2));
        }
        
        elseif($key == 'LOAN_INSTALLMENTS'){
          $rep->TextCol(47, 48, number_format($dept[$key],2));
        }
          elseif($key == 'DATA_OVER_LIMIT'){
           $rep->TextCol(48, 49, number_format($dept[$key],2));

        }
        elseif($key == 'MOBILE_DEDUCTION_1'){
          $rep->TextCol(49, 50, number_format($dept[$key],2));
        }
         elseif($key == 'Water_Electricity' || $key == 'WATER_ELECTRICITY'){
          $rep->TextCol(50, 51, number_format($dept[$key],2));
        }
        elseif($key == 'INSURANCE'){
          $rep->TextCol(51, 52, number_format($dept[$key],2));
        }
         elseif($key == 'WELFARE_REGISTRATION'){
          $rep->TextCol(52, 53, number_format($dept[$key],2));
        }
          elseif($key == 'WELFARE'){
           $rep->TextCol(53, 54, number_format($dept[$key],2));

        }
//        elseif($key == 'SALARY_ADVANCE'){
//          $rep->TextCol(54, 55, number_format($dept[$key],2));
//        }
        elseif($key == 'PANELTY'){
           $rep->TextCol(54, 55, number_format($dept[$key],2));

        }
       
         elseif($key == 'SALARY_ADVANCES'){
           $rep->TextCol(55, 56, number_format($dept[$key],2));

        }
         
        elseif($key == 'EPF_DEDUCTION'){
           $rep->TextCol(56, 57, number_format($dept[$key],2));

        }
        elseif($key == 'OTHER_DEDUCTIOIN'){
          $rep->TextCol(57, 58, number_format($dept[$key],2));
        }
        
        elseif($key == 'OTHER_DEDUCTIOIN_2'){
          $rep->TextCol(58, 59, number_format($dept[$key],2));
        }
          elseif($key == 'EPF_12%'){
           $rep->TextCol(59, 60, number_format($dept[$key],2));

        }
        elseif($key == 'ETF_3%'){
          $rep->TextCol(60, 61, number_format($dept[$key],2));
        }
        
           elseif($key == 'BANKING_INCENT_TOTAL'){
           $rep->TextCol(61, 62, number_format($dept[$key],2));

        }
        elseif($key == 'ADDONS_FROM_BASIC'){
          $rep->TextCol(62, 63, number_format($dept[$key],2));
        }
        
          elseif($key == 'ADDONS_TO_INSENTIVE'){
          $rep->TextCol(63, 64, number_format($dept[$key],2));
        }
          elseif($key == 'TOTAL_ADDONS'){
           $rep->TextCol(64, 65, number_format($dept[$key],2));

        }
        elseif($key == 'BASIC_SALARY_NET'){
          $rep->TextCol(65, 66, number_format($dept[$key],2));
        }
      
       
          elseif($key == 'NET_INSENTIVE'){
           $rep->TextCol(66, 67, number_format($dept[$key],2));

        }
          elseif($key == 'NET_PAY_TO_BANK'){
          $rep->TextCol(67, 68, number_format($dept[$key],2));
        }
        elseif($key == 'ROUNDING_OFF'){
           $rep->TextCol(68, 69, number_format($dept[$key],2));

        }
        elseif($key == 'BF'){
           $rep->TextCol(69, 70, number_format($dept[$key],2));

        }
         
        

        
        
    }

 }
 

 
 
//function display_salary_deduction_heading(&$rep)
//{
//            $rep->NewLine();
//            $rep->fontSize += 1;           
//
//            $rep->font('b');
//            $rep->TextCol(0, 1, "Salary Deductions" );
//            $rep->fontSize -=1;
//            $rep->font('');
//            $rep->NewLine();
//    
//}
 
 
 
// function display_department_deduc_sub_totals(&$rep, $dept, $component_names,$grand_totals = false)
// {
//      
//    switch ($grand_totals) {
//        case "STD":
//            $total_text_heading = "Other Deductions";
//            break;
//        case "OTHR":
//            $total_text_heading = "Deductions from Salary Cost";
//            break;
//
//        default:
//           $total_text_heading = "";
//           break;
//    }
//       if($total_text_heading=="")
//       {
//
//       }
//       else
//       {     
//            $rep->font('BI');
//            $rep->TextCol(0, 1, $total_text_heading);
//            $rep->font('');
//            $rep->NewLine();
//       }
//
//    $i=0;
//    $dept_deductions_total = 0;
//    $dept_additions_total=0;
////    $dept[$key]=0;
//    foreach ($dept as $key => $value) {
//        if($key == 'OTHER_DEDUCTIOIN_OTHER_DEDUCTIOIN_2'){
//           $rep->TextCol($i, $i+1, "Other Deductions");
//           $rep->TextCol($i+2, $i+3, number_format($dept[$key],2));
//           $dept_deductions_total += $dept[$key];
//           $rep->NewLine();
//        }
//        elseif($key == 'EPF 12%'){
//           $rep->TextCol($i, $i+1, "EPF Employer (12%)");
//           $rep->TextCol($i+2, $i+3, number_format($dept[$key],2));
//           $dept_deductions_total += $dept[$key];
//           $rep->NewLine();
//        }
//        elseif($key == 'ETF 3%'){
//           $rep->TextCol($i, $i+1, "ETF Employer (3%)");
//           $rep->TextCol($i+2, $i+3, number_format($dept[$key],2));
//           $dept_deductions_total += $dept[$key];
//           $rep->NewLine();
//        }
//        elseif($key == 'Water_Electricity'){
//           $rep->TextCol($i, $i+1, "Water / Electricity");
//           $rep->TextCol($i+2, $i+3, number_format($dept[$key],2));
//           $dept_deductions_total += $dept[$key];
//           $rep->NewLine();
//        }
//        else
//        {
//            $name = '';
//            $amount = 0.00;
//            if(isset($component_names[$key])){
//                $name = $component_names[$key];
//                $amount = $dept[$key];
//                $rep->TextCol($i, $i+1, $name);
//                $rep->TextCol($i+2, $i+3, number_format($amount,2));
//                $rep->NewLine();
//            }
//           
//            if(isset($dept[$key])){
//                $dept_deductions_total += $dept[$key];
//            }
//            
//        }
//    }
//    
//
//    
//    switch ($grand_totals) {
//        case "STD":
//            $sub_total_text = "Other Deductions Total";
//            break;
//        case "OTHR":
//            $sub_total_text = "Deductions From Salary Cost Total";
//            break;
//        
//
//
//        default:
//           $sub_total_text = "";
//           break;
//    }
//       if($sub_total_text=="")
//       {
//
//       }
//       else
//       {
//        
//            $rep->TextCol(1, 2, $sub_total_text);
//            $rep->font('b');
//            $rep->TextCol(2 ,3, number_format($dept_deductions_total,2));   
//            $rep->font('');
//            $rep->NewLine();
//       }
//   
//   return $dept_deductions_total;
//   
// }
 
 
function populate_employee_salary_array($payroll_run_id, $employee_code,&$dep_head_count)
{
    $salary = array();
    $result = get_employee_salary_components($payroll_run_id, $employee_code);
    if(db_num_rows($result)>0)
    {
        $dep_head_count +=1;
    }
    while($myrow=db_fetch($result)){
        $salary[$myrow['component']] = $myrow['value'];
    }

    return $salary;
}


function get_employee_salary_component_value($salary, $component)
{
    if(!is_array($salary)){
        return 0;
    }
    
     if($component == 'SINGLE_OT_HRS'){
        $value_m = substr($salary['amount_achieved'] ,strpos($salary['amount_achieved'],'.'));
        $value_h = explode(".", $salary['amount_achieved'], 2);
        $first = $value_h[0];
        if($value_m >0)
        {
            $minutes = $value_m *60;
        }
        else
        {
            $minutes = '00';
        }
        $hrs = $first.":".$minutes;
        return $hrs;
     }
    if($component == 'DOUBLE_OT_HOURS'){
        $value_m = substr($salary['amount_achieved'] ,strpos($salary['amount_achieved'],'.'));
        $value_h = explode(".", $salary['amount_achieved'], 2);
        $first = $value_h[0];
        if($value_m >0)
        {
            $minutes = $value_m *60;
        }
        else
        {
            $minutes = '00';
        }
        $hrs = $first.":".$minutes;
        return $hrs;
     }
    foreach ($salary as $key => $value) {
        if($key == $component){
            $x = $salary[$key];
            return $x;
        }
        
    }

        return 0;
    
    
}

function display_dept_head_count(&$rep,$head_count)
{
    $rep->NewLine();
    $rep->font('b');
    $rep->TextCol(1, 2, "Head Count  :  ".$head_count);   
    $rep->font('');
    $rep->NewLine();
    
    
}

function get_employee_ot_hrs($employee_code,$ot_type,$payroll_id)
{
    $sql = "SELECT * FROM ".TB_PREF."performance_incentives_details
            WHERE employee_code = ".db_escape($employee_code)." AND component = ".db_escape($ot_type)." 
            AND payroll_run_id=". db_escape($payroll_id); 
    
    $result = db_query($sql, "OT Details could not be retrieved");
    return db_fetch($result);    
    
}

function get_employee_ot_rate($employee_code,$ot_type,$period_end_date)
{
     $sql = "SELECT sc.amount 
             FROM ".TB_PREF."salary_components sc
             LEFT JOIN ".TB_PREF."list_values lv ON
                 lv.id=sc.salary_component_id
             WHERE sc.employee_code = ".db_escape($employee_code)." AND lv.value_code = ".db_escape($ot_type)." 
             AND sc.end_date >=". db_escape($period_end_date)." AND sc.effective_date <= ". db_escape($period_end_date)."
             ORDER BY sc.effective_date DESC LIMIT 1"; 
    
    $result = db_query($sql, "OT Rate could not be retrieved");
    return db_fetch($result);  
}

function build_header_names(&$s, &$a, &$column_positions)
{

    $a = array_merge(array("left"),
                    array("left"),
                    array("left"),
                    array("left"),
                    array("left"), 
                    array("left"), 
                    array("right"),
                    array("right"),
                    array("right"), 
                    array("right"), 
                    array("right"), 
                    array("right"),
                    array("right"),
                    array("right"),
                    array("right"),
                    array("right"),
                    array("right"), 
                    array("right"),
                    array("right"),
                    array("right"),
                    array("right"), 
                    array("right"),
                    array("right"),
                    array("right"),
                    array("right"),
                    array("right"),
                    array("right"), 
                    array("right"), 
                    array("right"), 
                    array("right"),
                    array("right"),
                    array("right"),
                    array("right"), 
                    array("right"), 
                    array("right"),
                    array("right"),
                    array("right"),
                    array("right"),
                    array("right"),
                    array("right"), 
                    array("right"),
                    array("right"),
                    array("right"),
                    array("right"),
                    array("right"),
                    array("right"),
                    array("right"),
                    array("right"),
                    array("right"),
//                    array("right"),
                    array("right"),
                    array("right"),
                    array("right"),
                    array("right"),
                    array("right"),
                    array("right"),
                    array("right"),
                    array("right"),
                    array("right"),
                    array("right"),
                    array("right"),
                    array("right"),
                    array("right"),
                    array("right"),
                    array("right"),
//                    array("right"),
                    array("right"),
                    array("right"),
                    array("right"),
                    array("right"),
                    array("right"),
                    array("right"),
                    array("right"),
                    array("right"),
                    array("right"),
                    array("right"),
                    array("right"));
    $s = array_merge(array("Employee No"),
                    array("Name"), 
                    array("Gender"), 
                    array("Department"),
                    array("Designation"),
                    array("Job Category"),
                    array("Basic Salary"),
                    array("BRA 1"), 
                    array("BRA 2"),
                    array("Basic Total(Salary for OT)"),
                    array("Applicable Incentive"),
                    array("Salary Arrears"),
                    array("Incentive"),
                    array("Incentive - Bank"),
                    array("Vehicle Reimbursement(Banking Incentive)"),
                    array("Meal Reimbursement II(Banking Incentive I)"),
                    array("Total Salary (Basic + Incentive)"),
                    array("No-Pay Deductions"),
                    array("Salary for EPF"),
                    array("EPF Employee"),
                    array("Paye"),
                    array("Addons To EPF Salary"),
                    array("Over Time 1"),
                    array("Single OT Hrs"),
                    array("Single OT Rate"),
                    array("Single OT Amount"),
                    array("Double OT Hrs"),
                    array("Double OT Rate"),
                    array("Double OT Amount"),
                    array("Over Time"),
                    array("Travelling Reimbursement II"),
                    array("Accommodation Reimbursement"),
                    array("Fuel Reimbursement"),
                    array("Fuel Reimbursement T"),
                    array("Meal Reimbursement"),
                    array("Meal Reimbursement T"),
                    array("Site Expenses Reimbursement"),
                    array("Travelling Reimbursement "),
                    array("Commission"),
                    array("Savings Commission"),
                    array("Driving Incentive"),
                    array("Special Attendance Incentive"),
//                    array("Sales Commission"),
                    array("Special Payment"),
                    array("Special Payment 1"),
                    array("Attendance Incentive"),
                    array("Powder Coating All"),
                    array("No Pay Refund"),
                    array("Loan Installment"),
                    array("Data Over Limit"),
                    array("Mobile Deduction"),
                    array("Water Electricity"),
                    array("Insurance"),
                    array("Welfare Registration Fee"),
                    array("Welfare"),
//                    array("Salary Advance"),
                    array("Penalty"),
                    array("Salary Advances"),
                    array("EPF Deduction"),
                    array("Other Deduction"),
                    array("Other Deduction2"),
                    array("EPF Employer"),
                    array("ETF Employer"),
                    array("Total Banking Incentive"),
            
                    array("Addons from Basic"),
                    array("Addons To Incentive"),
                    array("Total Addons"),
                    array("Basic Salary - Net"),                    
                    array("Net Incentive"),
                    array("Net Pay to Bank"),
                    array("Rounded"),
                    array("BF")
                    
            );
    
   
    $column_positions= array_merge(array(0,100,300,350,450,600,700,800,900,1000,1100,1200,1400,1500,1600,1700,1800,1900,2000,2100,2200,
                    2300,2400,2500,2600,2700,2800,2900,3000,3100,3200,3300,3400,3500,3600,3700,3800,3900,4000,4100,4200,4300,4400,4500,
                    4600,4700,4800,4900,5000,5100,5200,5300,5400,5500,5600,5700,5800,5900,6000,6100,6200,6300,6400,6500,6600,6700,6800,6900,7000,
                    7100,7200,7300,7400,7500,7600,7700));

}

function get_employee_net_pay_to_bank($emp,$bank_basic_salary,$bank_incentive_salary)
{
    if($bank_basic_salary == 1 && $bank_incentive_salary == 0 )
    {
        $net_pay_value = $emp['BASIC_SALARY_NET'];
        return $net_pay_value;
    }
    if($bank_basic_salary == 0 && $bank_incentive_salary == 1 )
    {
        $net_pay_value = $emp['TAKEHOME_INCENTIVE'];
        return $net_pay_value;
    }
    if($bank_basic_salary == 1 && $bank_incentive_salary == 1 )
    {
        $net_pay_value = $emp['TAKEHOME_INCENTIVE'] + $emp['BASIC_SALARY_NET'];
        return $net_pay_value;
    }
    else{
        
        return $net_pay_value = 0;
    }
    
//     return $net_pay_value;
    
}

function get_employee_net_pay_to_hand($emp,$bank_basic_salary,$bank_incentive_salary)
{
    if($bank_basic_salary == 1 && $bank_incentive_salary == 0 )
    {
        $net_pay_hand = $emp['TAKEHOME_INCENTIVE'];
        return $net_pay_hand;
    }
    if($bank_basic_salary == 0 && $bank_incentive_salary == 1 )
    {
        $net_pay_hand = $emp['BASIC_SALARY_NET'];
        return $net_pay_hand;
    }
    if($bank_basic_salary == 0 && $bank_incentive_salary == 0 )
    {
        $net_pay_hand = $emp['TAKEHOME_INCENTIVE'] + $emp['BASIC_SALARY_NET'];
        return $net_pay_hand;
    }
    else{
        
        return $net_pay_hand = 0;
    }
    
//     return $net_pay_hand;
    
}
//----------------------------------------------------------------------------------------------------
function get_employee_job_category($employee,$to_date)
{
    
        $sql = "SELECT IFNULL(lv.value_name,'No Job Category Entered') job_category
            FROM ".TB_PREF."employment_details edl,
                 ".TB_PREF."employee_master em,  
                 ".TB_PREF."list_values lv   
            WHERE em.employee_code = edl.employee_code AND 
                    edl.contract_start_date <= ".db_escape($to_date)." AND 
                    edl.contract_end_date >= ".db_escape($to_date)." AND 
                    em.employee_code =". db_escape($employee)." AND lv.id = edl.job_category_id 
                    ORDER BY edl.contract_start_date DESC LIMIT 1";
                
        
        $result=db_query($sql,"an job category could not be retreived");
        return db_fetch($result);
    
}

function print_dep_salary_expences()
{
    global $path_to_root, $pic_height;
    $payroll_run_id = $_POST['PARAM_0'];
    $filtering_employee_from = $_POST['PARAM_1'];
    $filtering_employee_to = $_POST['PARAM_2'];
    $valid_salaries = $_POST['PARAM_3'];
    $released_salaries = $_POST['PARAM_4'];
    $hold_salaries = $_POST['PARAM_5'];

    
//    $payroll_run_id = $_POST['PARAM_0'];
//    $department = $_POST['PARAM_1'];
//    $destination = $_POST['PARAM_2'];

	include_once($path_to_root . "/reporting/includes/excel_report.inc");
       

	$orientation = 'L';
        
        $headers = array();
        $aligns = array();
        $cols = array();
        
        build_header_names($headers, $aligns, $cols);

//        $cols = array(0, 270,420,500);
//        $headers = array('Component','','Amount');
//        $aligns = array('left','left','right');
   	$rep = new FrontReport(_('Salary Sheet'), "SalarySheet", 'A3', 9, $orientation);
        
       
        
         if($payroll_run_id != "-1")
        {
                  
            $payroll_rows= get_payroll_run_details($payroll_run_id);           
            $payrol_run_name=sql2date($payroll_rows['period_start_date'])." - ".sql2date($payroll_rows['period_end_date'])." - ".$payroll_rows['description'];
        
        }
        else
        {
           $payrol_run_name ="None";
        } 
        $from_emp = '';
        $to_emp = '';
        if($filtering_employee_from != '')
        {
            $emp_name = get_employee($filtering_employee_from);
            $from_emp = $emp_name['initials']." ".$emp_name['last_name']." (".$emp_name['last_name'].") "; 
        }
        else
        {
            $from_emp = 'All';
        }
        if($filtering_employee_to != '')
        {
            $emp_name = get_employee($filtering_employee_to);
            $to_emp = $emp_name['initials']." ".$emp_name['last_name']." (".$emp_name['last_name'].") "; 
        }
        else
        {
            $to_emp = 'All';
        }
        if($valid_salaries != '1' )
        {
            $valid_sal = 'No';
        }
        else
        {
            $valid_sal = 'Yes';
        }
        if($released_salaries != '1' )
        {
            $released_sal = 'No';
        }
        else
        {
            $released_sal = 'Yes';
        }
        if($hold_salaries != '1' )
        {
            $hold_sal = 'No';
        }
        else
        {
            $hold_sal = 'Yes';
        }
        $params =   array( 	0 => $payrol_run_name,
                                1 => $from_emp,
                                2 => $to_emp,
                                3 => $valid_sal,
                                4 => $released_sal,
                                5 => $hold_sal
                         );
       
        $rep->SetHeaderType('form_968');
        $rep->Font();
        $rep->Info($params, $cols, $headers, $aligns);

        $rep->NewPage();
//        $current_department = "";
        $payroll_data =get_payroll_run_details($payroll_run_id);

        
        
        $rpt_totals= array();
        $emp = array();
        
      
        
       

        initialize_additions_array($rpt_totals);
        initialize_additions_array($emp);
        

        $dep_head_count=0;
        
        $com_names = get_componant_names($payroll_run_id);
                
//        $NO_DEPARTMENT_new_page = true;
        $result_dep_salary= get_employees_for_salary_report($payroll_run_id,$filtering_employee_from,$filtering_employee_to);
        $grand_head_count=0; 
        $amount_single_ot = 0;
        $amount_double_ot = 0;
            while ($dep_salary_row = db_fetch($result_dep_salary))
            {
                 if($dep_salary_row['employee_code'] =='')
                {
                    continue;
                }
                    $emp_name = get_employee($dep_salary_row['employee_code']);
                    $name = $emp_name['initials']." ".$emp_name['last_name']." (".$emp_name['first_name'].") "; 
                    $depatment_details = get_employee_curent_departments($dep_salary_row['employee_code'], $payroll_rows['period_end_date']);
                    $emp_designation_details= get_employee_current_designation($dep_salary_row['employee_code'], $payroll_rows['period_end_date']);
                     $job_cat_data=get_employee_job_category($dep_salary_row['employee_code'],$payroll_rows['period_end_date']);
                    $rep->textcol(0, 1, $dep_salary_row['employee_code']);
                    $rep->textcol(1, 2, $name);
                    $rep->textcol(2, 3, $emp_name['gender']);
                    $rep->textcol(3, 4, isset($depatment_details['department_name']) ? $depatment_details['department_name'] : '');
                    $rep->textcol(4, 5, isset($emp_designation_details['designation']) ? $emp_designation_details['designation'] : '');
                    $rep->textcol(5, 6, isset($job_cat_data['job_category']) ? $job_cat_data['job_category'] : '');

                   

                    
                    //initialize_additions_array($rpt_totals);          
                    

                    initialize_additions_array($emp);
               
                $salary = "";
                $salary = populate_employee_salary_array($payroll_run_id, $dep_salary_row['employee_code'],$dep_head_count);
                
                $component = "BASIC_SALARY";
                $emp['BASIC_SALARY'] = get_employee_salary_component_value($salary, $component);

                $component = "BRA_1";
                $emp['BRA_1'] = get_employee_salary_component_value($salary, $component);
                
                $component = "BRA_2";
                $emp['BRA_2'] = get_employee_salary_component_value($salary, $component);
                
                $component = "SALARY_FOR_OT";
                $emp['SALARY_FOR_OT'] = get_employee_salary_component_value($salary, $component);
                
                $component = "SALARY_TOTAL_2";
                $emp['APPLICABLE_INSENTIVE'] = get_employee_salary_component_value($salary, $component);
                
                 $component = "INCENTIVE_ARREARS";
                $emp['INCENTIVE_ARREARS'] = get_employee_salary_component_value($salary, $component);
                
                $component = "INCENTIVE";
                $emp['INCENTIVE'] = get_employee_salary_component_value($salary, $component);
                
                $component = "BANKING_INCENTIVE_II";
                $emp['BANKING_INCENTIVE_II'] = get_employee_salary_component_value($salary, "BANKING_INCENTIVE_II");
                
                $component = "BANKING_INCENTIVE";
                $emp['BANKING_INCENTIVE'] = get_employee_salary_component_value($salary, "BANKING_INCENTIVE");
                
                $component = "BANKING_INCENTIVE_I";
                $emp['BANKING_INCENTIVE_I'] = get_employee_salary_component_value($salary, "BANKING_INCENTIVE_I");

                $component = "SALARY_TOTAL_1";
                $emp['SALARY_TOTAL_1'] = get_employee_salary_component_value($salary, "SALARY_TOTAL_1");
                
                $component = "NO_PAY_DEDUCTIONS";
                $emp['NO_PAY_DEDUCTIONS'] = get_employee_salary_component_value($salary, "NO_PAY_DEDUCTIONS");

                $component = "SALARY_FOR_EPF";
                $emp['SALARY_FOR_EPF'] = get_employee_salary_component_value($salary, "SALARY_FOR_EPF");
                
                $component = "COMP_EPF_8";
                $emp['COMP_EPF_8'] = get_employee_salary_component_value($salary, "COMP_EPF_8");
                
				$emp['PAYE'] = get_employee_salary_component_value($salary, "PAYE");
                $emp['PAYE'] += get_employee_salary_component_value($salary, "COMP_PAYE");
                
                
                //$component = "COMP_PAYE";
                //$emp['COMP_PAYE'] = get_employee_salary_component_value($salary, "COMP_PAYE");
                
                
                $component = "ADDONS_TO_EPF_SALARY";
                $emp['ADDONS_TO_EPF_SALARY'] = get_employee_salary_component_value($salary, "ADDONS_TO_EPF_SALARY") ;
                
                $component = "OVER_TIME";
                $emp['OVER_TIME'] = get_employee_salary_component_value($salary, "OVER_TIME");
                
//---------------------------------------------------------------------------------------------------------------------------------------
                $single_ot_hrs= get_employee_ot_hrs($dep_salary_row['employee_code'],'SINGLE_OT',$payroll_run_id);
                $component = "SINGLE_OT_HRS";
                $emp['SINGLE_OT_HOURS'] = get_employee_salary_component_value($single_ot_hrs, $component);                
                
                $single_ot_rate = get_employee_ot_rate($dep_salary_row['employee_code'],'SINGLE_OT',$payroll_data['period_end_date']);
                $component = "SINGLE_OT_RATE";
                $emp['SINGLE_OT_RATE'] = get_employee_salary_component_value($single_ot_rate, $component);  
                
                
                $component = "SINGLE_OT";
                $emp['SINGLE_OT_AMOUNT'] = get_employee_salary_component_value($salary, $component);
                
  //---------------------------------------------------------------------------------------------------------------------------------------
                
                $double_ot_hrs= get_employee_ot_hrs($dep_salary_row['employee_code'],'DOUBLE_OT',$payroll_run_id);
                $component = "DOUBLE_OT_HOURS";
                $emp['DOUBLE_OT_HOURS'] = get_employee_salary_component_value($double_ot_hrs, $component);                
                
                $double_ot_rate = get_employee_ot_rate($dep_salary_row['employee_code'],'DOUBLE_OT',$payroll_data['period_end_date']);
                $component = "DOUBLE_OT_RATE";
                $emp['DOUBLE_OT_RATE'] = get_employee_salary_component_value($double_ot_rate, $component);  
                
                
                $component = "DOUBLE_OT";
                $emp['DOUBLE_OT_AMOUNT'] = get_employee_salary_component_value($salary, $component);
                
  //---------------------------------------------------------------------------------------------------------------------------------------
      
                $component = "OT_TOTAL";
                $emp['OT_TOTAL'] = get_employee_salary_component_value($salary, "OT_TOTAL");
                
                $component = "VEHICLE_REIMBURSEMEN";
                $emp['VEHICLE_REIMBURSEMEN'] = get_employee_salary_component_value($salary, "VEHICLE_REIMBURSEMEN");
                
//                $component = "INCENTIVE_ARREARS";
//                $emp['INCENTIVE_ARREARS'] = get_employee_salary_component_value($salary, "INCENTIVE_ARREARS");
                
                $component = "ACCOMMODATION_1";
                $emp['ACCOMMODATION_1'] = get_employee_salary_component_value($salary, $component);
                
                $component = "FUEL_ALLOWANCES";
                $emp['FUEL_ALLOWANCES'] = get_employee_salary_component_value($salary, "FUEL_ALLOWANCES");
                
                $component = "FUEL_REIMBURSEMENT_T";
                $emp['FUEL_REIMBURSEMENT_T'] = get_employee_salary_component_value($salary, "FUEL_REIMBURSEMENT_T");
                
                $component = "MEAL_REIMBURSEMENT_T";
                $emp['MEAL_REIMBURSEMENT_T'] = get_employee_salary_component_value($salary, "MEAL_REIMBURSEMENT_T");
                
                 $component = "MEAL_REIMBURSEMENT";
                $emp['MEAL_REIMBURSEMENT'] = get_employee_salary_component_value($salary, $component);
                
                $component = "SITE_EXPENSES";
                $emp['SITE_EXPENSES'] = get_employee_salary_component_value($salary, "SITE_EXPENSES");
                
                $component = "TRAVELLING_ALLOWANCE";
                $emp['TRAVELLING_ALLOWANCE'] = get_employee_salary_component_value($salary, "TRAVELLING_ALLOWANCE");
                
                $component = "COMMISSION";
                $emp['COMMISSION'] = get_employee_salary_component_value($salary, "COMMISSION");
                
                
                $component = "SAVINGS_COMMISSION";
                $emp['SAVINGS_COMMISSION'] = get_employee_salary_component_value($salary, "SAVINGS_COMMISSION");
                
                $component = "DRIVING_ALLOWANCE";
                $emp['DRIVING_ALLOWANCE'] = get_employee_salary_component_value($salary, "DRIVING_ALLOWANCE");
                
                $component = "SPECIAL_ATTENDANCE";
                $emp['SPECIAL_ATTENDANCE'] = get_employee_salary_component_value($salary, "SPECIAL_ATTENDANCE");
                
                $component = "SPECIAL_PAYMENT";
                $emp['SPECIAL_PAYMENT'] = get_employee_salary_component_value($salary, "SPECIAL_PAYMENT");
                
                $component = "SPECIAL_PAYMENT1";
                $emp['SPECIAL_PAYMENT1'] = get_employee_salary_component_value($salary, "SPECIAL_PAYMENT1");
                
                $component = "ATTENDANCE_INCENTIVE";
                $emp['ATTENDANCE_INCENTIVE'] = get_employee_salary_component_value($salary, "ATTENDANCE_INCENTIVE");
                
                $component = "NO_PAY_REFUND";
                $emp['NO_PAY_REFUND'] = get_employee_salary_component_value($salary, $component);
                
                $component = "LOAN_INSTALLMENTS";
                $emp['LOAN_INSTALLMENTS'] = get_employee_salary_component_value($salary, $component);
                
                $component = "DATA_OVER_LIMIT";
                $emp['DATA_OVER_LIMIT'] = get_employee_salary_component_value($salary, $component);
                
                 
                $component = "MOBILE_DEDUCTION_1";
                $emp['MOBILE_DEDUCTION_1'] = get_employee_salary_component_value($salary, $component);
                
                
//                $component = "Water_Electricity";
                $emp['WATER_ELECTRICITY'] = get_employee_salary_component_value($salary, 'Water_Electricity');
                
                $emp['WATER_ELECTRICITY'] += get_employee_salary_component_value($salary, 'WATER_ELECTRICITY');
                
                $component = "WELFARE_REGISTRATION";
                $emp['WELFARE_REGISTRATION'] = get_employee_salary_component_value($salary, $component);
                
                $component = "INSURANCE";
                $emp['INSURANCE'] = get_employee_salary_component_value($salary, $component);
                
                $component = "WELFARE_REGISTRATION";
                $emp['WELFARE_REGISTRATION'] = get_employee_salary_component_value($salary, $component);
                
                $component = "WELFARE";
                $emp['WELFARE'] = get_employee_salary_component_value($salary, $component);
                
                $component = "SALARY_ADVANCE";
                $emp['SALARY_ADVANCE'] = get_employee_salary_component_value($salary, $component);
                
                $component = "PANELTY";
                $emp['PANELTY'] = get_employee_salary_component_value($salary, $component);
                
                 $component = "SALARY_ADVANCES";
                $emp['SALARY_ADVANCES'] = get_employee_salary_component_value($salary, $component);
                
                $component = "EPF_DEDUCTION";
                $emp['EPF_DEDUCTION'] = get_employee_salary_component_value($salary, $component);
                
                $component = "OTHER_DEDUCTIOIN";
                $emp['OTHER_DEDUCTIOIN'] = get_employee_salary_component_value($salary, $component);
                
                $component = "OTHER_DEDUCTIOIN_2";
                $emp['OTHER_DEDUCTIOIN_2'] = get_employee_salary_component_value($salary, $component);
                
                $component = "EPF_12%";
                $emp['EPF_12%'] = get_employee_salary_component_value($salary, $component);
                
                $component = "ETF_3%";
                $emp['ETF_3%'] = get_employee_salary_component_value($salary, $component);
                
                $component = "BANKING_INCENT_TOTAL";
                $emp['BANKING_INCENT_TOTAL'] = get_employee_salary_component_value($salary, $component);
                
                $component = "ADDONS_TO_EPF_SALARY";
                $emp['ADDONS_FROM_BASIC'] = get_employee_salary_component_value($salary, $component);
                
                $component = "ADDONS_TO_INCENTIVE";
                $emp['ADDONS_TO_INSENTIVE'] = get_employee_salary_component_value($salary, $component);                
                
                $emp['TOTAL_ADDONS'] = get_employee_salary_component_value($salary, "ADDONS_TO_BASIC")+ 
                                       get_employee_salary_component_value($salary, "ADDONS_TO_INCENTIVE");
                
                $component = "TAKEHOME_BASIC";
                $emp['BASIC_SALARY_NET'] = get_employee_salary_component_value($salary, $component); 
                
                $component = "TAKEHOME_INCENTIVE";
                $emp['TAKEHOME_INCENTIVE'] = get_employee_salary_component_value($salary, $component); 
                
                $emp['NET_PAY_TO_BANK'] = get_employee_salary_component_value($salary, "TAKEHOME_BASIC")+ 
                                       get_employee_salary_component_value($salary, "TAKEHOME_INCENTIVE");
                
//                $emp['NET_PAY_TO_BANK'] = get_employee_net_pay_to_bank($emp,$emp_name['bank_basic_salary'],$emp_name['bank_incentive_salary']);
                
//                $emp['NET_INSENTIVE'] = get_employee_net_pay_to_hand($emp,$emp_name['bank_basic_salary'],$emp_name['bank_incentive_salary']);
                
                $emp['NET_INSENTIVE'] = get_employee_salary_component_value($salary, "TAKEHOME_INCENTIVE");
                
                $component = "ROUNDING_OFF";
                $emp['ROUNDING_OFF'] = get_employee_salary_component_value($salary, $component); 
                
                $component = "BROUGHT_FORWARD";
                $emp['BF'] = get_employee_salary_component_value($salary, $component); 
                
                $component = "POWDER_COATING_ALL";
                $emp['POWDER_COATING_ALL'] = get_employee_salary_component_value($salary, $component); 
                
                $dept_additions_total = display_component_values($rep, $emp, $com_names,false);
                add_to_report_totals($rpt_totals, $emp);
                $rep->NewLine();
               
            }
            
            $dept_additions_total = display_component_values($rep, $rpt_totals, $com_names,false);
            $rep->NewLine();
            $rep->SetTextColor(255, 0, 0);
            $rep->TextCol(0, 6, "If a new salary component is added this report should be amended." );
            $rep->SetTextColor(0, 0, 0);

	$rep->NewLine();
    $rep->End();
}


?>
