<?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");

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

print_payslips();

function get_payroll_employees($payroll_run_id, $filtering_employee_from,$filtering_employee_to,$fromdate)
{
	$sql = " SELECT DISTINCT prd.employee_code,em.*,
                        IFNULL(dn.value_name,'No Department Entered') department_name,
                        edl.designation
                 FROM ".TB_PREF."payroll_run_details prd, 
                        ".TB_PREF."payroll_runs pr,
                        ".TB_PREF."employee_departments ed,
                        ".TB_PREF."list_values dn,
                        ".TB_PREF."employee_master em,
                        ".TB_PREF."employment_details edl
                 WHERE prd.payroll_run_id = pr.id AND em.employee_code=prd.employee_code AND
                        prd.employee_code = ed.employee_code AND ed.start_date <= '$fromdate' AND ed.end_date >= '$fromdate' 
                        AND ed.department_id=dn.id AND prd.employee_code = edl.employee_code AND 
                        edl.contract_start_date <= '$fromdate' AND edl.contract_end_date >= '$fromdate'AND
                        prd.employee_code <> '' AND 
                        pr.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_salary_sheet_header($payroll_run_id)
{
        $sql = "SELECT lv.value_name, lv.value_code   
                FROM ".TB_PREF."payroll_runs pr, 
                      ".TB_PREF."list_values lv,  
                     ".TB_PREF."payroll_calculation_seq pcs 
                WHERE   pcs.active='1' AND    
                        pr.payroll_id = pcs.payroll_id AND 
                        pcs.process_code = lv.value_code AND 
                        lv.list_code IN(".PAYROLL_LISTS.") AND 
                        pr.id = ".db_escape($payroll_run_id)."
                ORDER BY pcs.seq_no ";
    
   	$result = db_query($sql, "Payslip details could not be retrieved");

        return $result;
}




function get_employeee_details($employee)
{
        $sql = "SELECT em.* 
                FROM ".TB_PREF."employee_master em 
                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 get_salary_hold_details($payroll_run_id, $employee)
{
    $sql = "SELECT hs.* 
                FROM ".TB_PREF."hold_salary hs
                WHERE hs.employee_code = ".db_escape($employee)." AND
                        hs.payroll_run_id = ".db_escape($payroll_run_id);
        
   	$result = db_query($sql, "hold salary  details could not be retrieved");

        return db_fetch($result);
}


function calculate_sum_column_ot(&$value,$comp_total)
{
    //999:15
    $vh = substr($value,0, -3);
    $vm = substr($value, -2);
    $vs = $vh*3600 + $vm*60;
    
    $th = substr($comp_total,0, -3);
    $tm = substr($comp_total, -2);
    $ts = $th*3600 + $tm*60;
    
    $s = $vs + $ts;
    
    $hhmm= calculatetime($s);
    
    return $hhmm;
    
//        $secondspayOt = time_diff_seconds(sql2date(Today()), $value, sql2date(Today()), "00:00:00") ;
//        $secondspayOt =abs($secondspayOt);
//        $value += $secondspayOt; 
//    
//        $value= calculatetime($value);
    
}

//function print_payslip_value($rep, $payslip_value_name, $component_value, &$total,$h)
//{
//    $rep->NewLine();
//    $rep->TextCol(0+$h, 1+$h, $payslip_value_name);
//    $rep->TextCol(1+$h, 2+$h, number_format($component_value,2));
//    $total += $component_value;
//}


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

    $a = array_merge(array("left"),array("left"), array("left"), array("left"), array("left"));
    $s = array_merge(array("Employee No"),array("Name"), array("Gender"), array("Department"),array("Designation"));
    
   
    $column_positions= array_merge(array(0,75,175,200,300,600));
    $total= array_merge(array(0,0,0,0,0));
    //$current_position = 0;
    $width = 600;
    //$column_positions = "0,";
    
    $i = 1;
    $head_data=get_salary_sheet_header($payroll_run_id);
    while ($component = db_fetch($head_data))
    {
        $s = array_merge($s, array($component['value_name']));
        
        $i++;
        $width += 75;
       
        $a = array_merge($a, array('right'));
        
        
        $column_positions = array_merge($column_positions, array($width));
        //$column_positions .= $current_position.",";
        
    }
    
    //Normal OT
    $a = array_merge( $a,array("right"),array("right"), array("right"), array("right"), array("right"),array("right"));
    $s = array_merge($s,array("Normal OT Hrs"),array("Normal OT Rate"), array("Normal OT Amount"), array("Double OT Hrs"),array("Double OT Rate"), array("Double OT Amount"));
    
    for ($g = 0; $g < 6; $g++) {
        $width += 75;
        $column_positions = array_merge($column_positions, array($width));
    }
    
    $a = array_merge( $a,array("right"),array("right"), array("right"), array("right"), array("right"),array("right"));
    $s = array_merge($s,array("Basic Nopay days"),array("No Pay 1 Rate"), array("No Pay 1 Amount"), array("Incentive Nopay days"),array("No Pay 2 Rate"), array("No Pay 2 Amount"));
    
    for ($g = 0; $g < 6; $g++) {
        $width += 75;
        $column_positions = array_merge($column_positions, array($width));
    }

//    $last_col_align = array("right");
//    $last_cols = array(4575,4650);
//    $last_col_names = array("Normal OT Hrs");
//    $column_positions = array_merge($column_positions, $last_cols);
//    $s= array_merge($s, $last_col_names);
//    $a= array_merge($a, $last_col_align);
    
    //$s = substr($s, 0, -1);
    //$a = substr($a, 0, -1);
    //$column_positions = substr($column_positions, 0, -1);

    
}

function get_employee_salary_component_amount1($payroll_run_id, $employee, $component)
{
        $sql = "SELECT value 
                FROM ".TB_PREF."payroll_run_details 
                WHERE payroll_run_id = ".db_escape($payroll_run_id)." AND 
                         employee_code = ".  db_escape($employee)." AND 
                         component = ".db_escape($component); 
                         
   	$result = db_query($sql, "Salary component amount could not be retrieved");

        return db_fetch($result);
}

function get_employee_ot_rate($payroll_run_id, $employee_code, $ot_type)
{

    $sql="SELECT t.calculation_value  
          FROM ".TB_PREF."attendance a,
               ".TB_PREF."list_values lv,
               ".TB_PREF."payroll_runs p,
               ".TB_PREF."value_tables t 
          WHERE lv.value_description=".db_escape($ot_type)." 
                AND p.id= ".db_escape($payroll_run_id)." 
                AND a.employee_code=".db_escape($employee_code)." 
                AND a.calculated_payroll_run_id=p.id AND a.rate_table_id=lv.id 
                AND t.table_id = a.rate_table_id 
                AND t.calculation_value > 0 
                AND t.calculation_type = 'P' 
                LIMIT 1";
    
        $result = db_query($sql, "OT information could not be retrieved");
       
        return db_fetch($result);
       

}

//----------------------------------------------------------------------------------------------------
function cal_comp_total(&$comp_total ,$component_code, $value, $type = 'NUMERIC')
{
    //$comp_total= array_merge(array(0,0,0,0));
//    if($component_code=='NORMAL_OT_AMOUNT')
//    {
//        $n=5;
//    }
    
    
    if($type == 'NUMERIC'){
        $value = str_replace(',','', $value);
        if(isset($comp_total[$component_code])){
           $comp_total[$component_code] += $value;
        }
        else{
           $comp_total[$component_code] = $value;
        }
        
    }
    elseif($type == 'HOURS'){
        
        if(isset($comp_total[$component_code])){
           $comp_total[$component_code] = calculate_sum_column_ot($value,$comp_total[$component_code]);
        }
        else{
            if($value == null || $value == 0 || $value == ''){
                $value = '00:00';
            }
           $comp_total[$component_code] = $value;
        }

    }
    elseif($type == 'TEXT'){
        $comp_total[$component_code] = $value;
    }
   
    
}

//----------------------------------------------------------------------------------------------------
function get_empployee_rate($payroll_run_id,$employee_code, $ot_type)
{
    
    $sql="SELECT a.*,lv.value_description 
          FROM ".TB_PREF."attendance a,
               ".TB_PREF."list_values lv,
               ".TB_PREF."payroll_runs p
          WHERE lv.value_description=".db_escape($ot_type);
     
    if($payroll_run_id)
         {
          $sql .= " AND p.id= ".db_escape($payroll_run_id);            
         }
     if($employee_code)
         {
          $sql .= " AND a.employee_code=".db_escape($employee_code);            
         }    
        
                   
       $sql .=" AND a.calculated_payroll_run_id=p.id AND a.rate_table_id=lv.id";
    
       return $result = db_query($sql, "OT information could not be retrieved");

       
    
}

function get_employee_ot($payroll_run_id,$employee_code, $ot_type)
{
    
    $sql="SELECT a.*,lv.value_description 
          FROM ".TB_PREF."attendance a,
               ".TB_PREF."list_values lv,
               ".TB_PREF."payroll_runs p
          WHERE lv.value_description=".db_escape($ot_type);
     
    if($payroll_run_id)
         {
          $sql .= " AND p.id= ".db_escape($payroll_run_id);            
         }
     if($employee_code)
         {
          $sql .= " AND a.employee_code=".db_escape($employee_code);            
         }    
        
                   
       $sql .=" AND a.calculated_payroll_run_id=p.id AND a.rate_table_id=lv.id";
    
       return $result = db_query($sql, "OT information could not be retrieved");

       
    
}

function get_employee_nopay($payroll_run_id,$employee_code)
{
    $sql="SELECT l.*
          FROM ".TB_PREF."leaves l,
                ".TB_PREF."payroll_runs p
          WHERE p.id=".db_escape($payroll_run_id);
         
     if($employee_code)
         {
          $sql .= " AND l.employee_code=".db_escape($employee_code);            
         }    
        
                   
       $sql .=" AND l.payroll_run_id=p.id ";
    
       return $result = db_query($sql, "Nopay information could not be retrieved");
    
    
}

function calculatetime($time)
        {
            $h = floor($time /3600);
            $m = floor(($time - $h *3600) / 60);
            
            if(strlen($h) == 1){
                $h = '0'.$h;
            }
            if(strlen($m) == 1){
                $m = '0'.$m;
            }
            
            return $h.":".$m;        
            
        }
        
function calculate_ot(&$normal_ot_total_hrs, &$normal_ot_rate, &$normal_ot_total_amount,$payroll_run_id,$employee_code,$ot_type)
{
      $ot_total_column=0;
      $sum_cal_payot=0;
      $normal_ot_total_hrs =$normal_ot_rate = $normal_ot_total_amount = 0;
      $result_ot = get_employee_ot($payroll_run_id, $employee_code,$ot_type);
      
      
      $sum_ot_amount = 0;
  
       while($employee_ot = db_fetch($result_ot) )
       {
                    
                     $secondspayOt = time_diff_seconds(sql2date(Today()), $employee_ot['payroll_ot_time'], sql2date(Today()), "00:00:00") ;
                     $secondspayOt =abs($secondspayOt);
                     $sum_cal_payot += $secondspayOt;                      
                     $sum_ot_amount += $employee_ot['ot_amount'];
                    
       }
       
    $ot_total_column += $sum_cal_payot;
    $sum_cal_payot = calculatetime($sum_cal_payot);
    $ot_total_column = calculatetime($ot_total_column);
    
    $ot_rate=get_employee_ot_rate($payroll_run_id, $employee_code, $ot_type);
    if($ot_rate){
        $rate=$ot_rate['calculation_value'];   
    }
    else{
        $rate = 0;
    }
       
    //$ot_salary = 0;
    $salary_for_ot = get_calculated_payroll_db_value("SALARY_FOR_OT", $employee_code, $payroll_run_id);
    if($salary_for_ot){
    $ot_salary = $salary_for_ot;
    }

    
    $normal_ot_total_hrs = $sum_cal_payot;
    $normal_ot_rate = $ot_salary * $rate / 100;
    $normal_ot_total_amount =$sum_ot_amount;
}

function calculate_nopay(&$basic_nopay_days, &$basic_nopay_rate, &$basic_nopay_amount,$payroll_run_id,$employee_code)
{

      $sum_cal_nopay=0;
      $basic_nopay_days =$basic_nopay_rate = $basic_nopay_amount = 0;
      $result_nopay = get_employee_nopay($payroll_run_id, $employee_code);
    
       while($employee_nopay = db_fetch($result_nopay) )
       {
                    
       $sum_cal_nopay += $employee_nopay['nopay_days']; 
                     

       }
   
        
    $no_pay_dedct_amount=0; 
    $no_pay_deductions = get_calculated_payroll_db_value("NO_PAY_DEDUCTIONS", $employee_code, $payroll_run_id);
    if($no_pay_deductions){
    $no_pay_dedct_amount = $no_pay_deductions;
    }
    
    $salary_for_ot = get_calculated_payroll_db_value("SALARY_FOR_OT", $employee_code, $payroll_run_id);
    if($salary_for_ot){
    $ot_salary = $salary_for_ot;
    }                       
    
    $incentive = get_calculated_payroll_db_value("INCENTIVE", $employee_code, $payroll_run_id);
    if($incentive){
        $insentive_amount = $incentive;
    }
    else{
        $insentive_amount = 0;
    }
    $nopay_basic=abs($no_pay_dedct_amount)/($ot_salary+$insentive_amount)*$ot_salary;
    
    $basic_nopay_days = number_format($sum_cal_nopay, 1);
    if($basic_nopay_days ==0)
    {
        
      $basic_nopay_rate=number_format($nopay_basic,2);  
    }
    else
    {
    $basic_nopay_rate =number_format($nopay_basic/$basic_nopay_days,2);
    }
    //$basic_nopay_rate = number_format($nopay_basic/$sum_cal_nopay,2);
    $basic_nopay_amount = number_format($nopay_basic,2);
}


function calculate_nopay2(&$incentive_nopay_days, &$incentive_nopay_rate, &$incentive_nopay_amount,$payroll_run_id,$employee_code)
{
     
      $sum_cal_nopay=0;
      $incentive_nopay_days =$incentive_nopay_rate = $incentive_nopay_amount = 0;
      $incentive_nopay = get_employee_nopay($payroll_run_id, $employee_code);
      
      
      $sum_cal_ins_nopay = 0;
  
       while($employee_insen_nopay = db_fetch($incentive_nopay) )
       {
                    
       $sum_cal_ins_nopay += $employee_insen_nopay['nopay_days']; 
                     

       }
   
        
    $no_pay_dedct_amount=0;   
    $no_pay_deductions = get_calculated_payroll_db_value("NO_PAY_DEDUCTIONS", $employee_code, $payroll_run_id);
    if($no_pay_deductions){
    $no_pay_dedct_amount = $no_pay_deductions;
    }
    
    $salary_for_ot = get_calculated_payroll_db_value("SALARY_FOR_OT", $employee_code, $payroll_run_id);
    if($salary_for_ot){
    $ot_salary = $salary_for_ot;
    }                       
    
    $incentive = get_calculated_payroll_db_value("INCENTIVE", $employee_code, $payroll_run_id);
    if($incentive){
    $insentive_amount = $incentive;
    }
    else{
        $insentive_amount = 0;
    }
    $nopay_basic=abs($no_pay_dedct_amount)/($ot_salary+$insentive_amount)*$incentive;
    
    $incentive_nopay_days = number_format($sum_cal_ins_nopay,1);
    if($incentive_nopay_days)
    {
       $incentive_nopay_rate = number_format($nopay_basic,2); 
        
    }
 else {
        $incentive_nopay_rate = number_format($nopay_basic/$sum_cal_ins_nopay,2);
    }
    
    $incentive_nopay_amount =number_format($nopay_basic,2);
}

function get_employee_salary_component_amount($payroll_run_id, $employee_code, $process_code, $all_components)
{
//    $my_row = select_calculated_payroll_value($process_code, $employee_code, $payroll_run_id);
//    if($my_row == null)
//        return 0;
    
    $calculated_payroll_value = get_calculated_salary_component_values($process_code, $all_components);
    
    return $calculated_payroll_value;
    
}

function get_calculated_salary_component_values($process_code, $all_components)
{
    
    
    foreach ($all_components as $element) {
        if($element['component'] == $process_code){

            return $element['value'];
            
        }        
    }
    
    return 0;
}


function get_employeee_salary_details($payroll_run_id, $employee)
{
        $sql = "SELECT component, value   
                FROM ".TB_PREF."payroll_run_details  
                WHERE payroll_run_id =".db_escape($payroll_run_id)." AND employee_code =".db_escape($employee);
                

        
   	return db_query($sql, "Employee details could not be retrieved");

}

function get_employee_all_salary_components($payroll_run_id, $employee, &$all_components)
{
        $result= get_employeee_salary_details($payroll_run_id, $employee);
        while ($row = db_fetch($result)){
            $temp = array("component" => $row['component'], "value" => $row['value']);
            $all_components[] = $temp;

        }
}

function print_payslips()
{
    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'];

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

	$orientation = 'L';
        $count_colums='';
      
   	$rep = new FrontReport(_('Salary Sheet'), "SalarySheet", 'A4', 9, $orientation);

        $head_data=get_salary_sheet_header($payroll_run_id);
        $count_colums= mysql_num_rows($head_data);
      
        $headers = array();
        $aligns = array();
        $cols = array();
        
        build_header_names($payroll_run_id, $headers, $aligns, $cols);
          
        $rep->Info(null, $cols, $headers, $aligns);
        $rep->NewPage();
                
        $ot_total_column=0;                
        $payroll_run_details = get_payroll_run_details($payroll_run_id);
        $period = date('F Y', strtotime($payroll_run_details['period_start_date']));
        $fromdate = $payroll_run_details['period_start_date'];
        $h=0;
   
        $comp_total=array();
        $salary_total_column=array();
        $first_employee=true;
        
	$res = get_payroll_employees($payroll_run_id, $filtering_employee_from,$filtering_employee_to,$fromdate);  
        //get_salary_sheet_header
	while ($payroll_employee = db_fetch($res))
	{
                    $all_components='';
                    get_employee_all_salary_components($payroll_run_id,$payroll_employee['employee_code'] , $all_components);
                    
                    $rep->NewLine();
                    $name=$payroll_employee['initials']." ".$payroll_employee['first_name']." ".$payroll_employee['last_name']; 
                    $rep->textcol(0, 1, $payroll_employee['employee_code']);
                    $rep->textcol(1, 2, $name);
                    $rep->textcol(2, 3, $payroll_employee['gender']);
                    $rep->textcol(3, 4, $payroll_employee['department_name']);
                    $rep->textcol(4, 5, $payroll_employee['designation']);
                
                    $k = 5;
                    $head_data=get_salary_sheet_header($payroll_run_id);
                    while ($component = db_fetch($head_data)){
                            if($first_employee==true)
                            {
                                cal_comp_total($comp_total,$component['value_code'], $amount=0);

                            }
//                        if($first_employee==true)
//                        {
//                            get_calculated_salary_component_values($component['value_code'],$all_components, $amount);
//
//                        }

                        $val = get_employee_salary_component_amount($payroll_run_id, $payroll_employee['employee_code'], $component['value_code'],$all_components);

                        if($val){
                            $amount=$val;
                            $rep->textcol($k, $k+1, number_format($amount,2));
                            cal_comp_total($comp_total,$component['value_code'], $amount);

                        }

                        $k++;
                    }
                
                
                //$n=57;
                
                calculate_ot($normal_ot_total_hrs, $normal_ot_rate, $normal_ot_total_amount,$payroll_run_id,$payroll_employee['employee_code'],'TYPE1');
                $rep->textcol($k, $k+1, $normal_ot_total_hrs); $k++; //hh:mm
                cal_comp_total($comp_total,'NORMAL_OT_HRS', $normal_ot_total_hrs, 'HOURS');
                $rep->textcol($k, $k+1, number_format($normal_ot_rate,2));$k++;
                cal_comp_total($comp_total,'NORMAL_RATE', 'HIDE', 'TEXT');
                $rep->textcol($k, $k+1,number_format($normal_ot_total_amount,2));$k++;
                cal_comp_total($comp_total,'NORMAL_OT_AMOUNT', $normal_ot_total_amount);
                
                calculate_ot($double_ot_total_hrs, $double_ot_rate, $double_ot_total_amount,$payroll_run_id,$payroll_employee['employee_code'],'TYPE2');
                $rep->textcol($k, $k+1, $double_ot_total_hrs); $k++;
                cal_comp_total($comp_total,'DOUBLE_OT_HRS', $double_ot_total_hrs, 'HOURS');
                $rep->textcol($k, $k+1, $double_ot_rate);$k++;
                cal_comp_total($comp_total,'DOUBLE_RATE', 'HIDE', 'TEXT');
                $rep->textcol($k, $k+1,$double_ot_total_amount);$k++;
                cal_comp_total($comp_total,'DOUBLE_OT_AMOUNT', number_format($double_ot_total_amount,2));
                
                calculate_nopay($basic_nopay_days, $basic_nopay_rate, $basic_nopay_amount,$payroll_run_id,$payroll_employee['employee_code']);
                $rep->textcol($k, $k+1, $basic_nopay_days); $k++;
                cal_comp_total($comp_total,'NORMAL_NOPAY_DAYS', $basic_nopay_days);
                $rep->textcol($k, $k+1, $basic_nopay_rate);$k++;
                cal_comp_total($comp_total,'NORMAL_NOPAY_RATE', 'HIDE', 'TEXT');
                $rep->textcol($k, $k+1, $basic_nopay_amount);$k++;
                cal_comp_total($comp_total,'NORMAL_NOPAY_AMOUNT', $basic_nopay_amount);
//                
                calculate_nopay2($incentive_nopay_days, $incentive_nopay_rate, $incentive_nopay_amount,$payroll_run_id,$payroll_employee['employee_code']);
                $rep->textcol($k, $k+1, $incentive_nopay_days); $k++;
                cal_comp_total($comp_total,'INCENTIVE_NOPAY_DAYS', $incentive_nopay_days);
                $rep->textcol($k, $k+1, $incentive_nopay_rate);$k++;
                cal_comp_total($comp_total,'INCENTIVE_RATE', 'HIDE', 'TEXT');
                $rep->textcol($k, $k+1, $incentive_nopay_amount);$k++;
                cal_comp_total($comp_total,'INCENTIVE_NOPAY_AMOUNT', $incentive_nopay_amount);
                

                $first_employee=false; 
             

	}
                
                    $rep->NewLine(2);               
                    $rep->textcol(3, 4,"Total");
                    $m= 5;
                    foreach($comp_total as $key=>$total)
                    {  
                     if($total != 'HIDE'){  
                         switch ($key) {
                             case 'NORMAL_OT_HRS':
                             case 'DOUBLE_OT_HRS':
                                 $rep->textcol($m, $m+1,$total);
                                 break;
                             case 'NORMAL_NOPAY_DAYS':
                             case 'INCENTIVE_NOPAY_DAYS':
                                 $rep->textcol($m, $m+1, number_format($total,1));
                                 break;
                             case 'NORMAL_OT_AMOUNT':
                             case 'DOUBLE_OT_AMOUNT':
                                 $rep->textcol($m, $m+1, number_format($total,2));
                                 break;
                             case 'INCENTIVE_NOPAY_AMOUNT':
                             case 'NORMAL_NOPAY_AMOUNT':
                                 $rep->textcol($m, $m+1, number_format($total,2));
                                 break;
                             default:
                                 $rep->textcol($m, $m+1,number_format($total,2));
                         }
                        
                     }
                     $m++;
                    }

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


?>
