<?php
/****************************************
/*  Author 	: Kvvaradha
/*  Module 	: Extended HRM
/*  E-mail 	: admin@kvcodes.com
/*  Version : 1.0
/*  Http 	: www.kvcodes.com
/* Attendance PDF
*****************************************/
$page_security = 'SA_OPEN';

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

global $path_to_root, $systypes_array, $kv_empl_gender;

    $year = $_POST['PARAM_0'];
    $month = (int)$_POST['PARAM_1'];
    $dept_id = $_POST['PARAM_2'];
    $comments = $_POST['PARAM_3'];
    // $destination = $_POST['PARAM_4'];

	// if ($destination)
		include_once($path_to_root . "/reporting/includes/excel_report.inc");
	// else
	// 		include_once($path_to_root . "/modules/ExtendedHRM/reports/pdf_report.inc");

	$orientation = 'L';
 	$dec = user_price_dec();
	$selected_fiscal_year = get_fiscalyear($year);

    $start = date("Y", strtotime($selected_fiscal_year['begin']));
    $end = 	date("Y", strtotime($selected_fiscal_year['end']));
    $get_year_frm_fiscalyear = date("Y-m-d", strtotime($start.'-'.$month.'-01'));

    if(is_date_in_fiscalyear(sql2date($get_year_frm_fiscalyear))){ 
    	$total_days =  date("t", strtotime($start.'-'.$month.'-01'));
    	$rep_year = $start;
    } else {
    	$total_days =  date("t", strtotime($start.'-'.$month.'-01'));
    	$rep_year = $end;
    }

    $months_with_years_list = kv_get_months_with_years_in_fiscal_year($year);
 	$ext_year = date("Y", strtotime($months_with_years_list[(int)$month]));

	$cols = array(0, 20, 55,130, 175, 220, 230);

	$headers = array(_('S.No'), _('Emp. Code'), _('Name'), _('Location'), _('Department'), _('Grade'));
	$aligns = array('left',	'left' ,'left', 'left', 'left', 'left', 'left');
	$payroll_monthly_choice =get_hrm_option('monthly_choice');
	$hrmsetup = get_hrm_option();

	if($payroll_monthly_choice == 1){
			$vj= 1;	
			$kv_end_days = date("t", strtotime($year."-".$month."-01"));		
			for($js=1;$js<=$kv_end_days;$js++){			
				$col_span = 240+($vj*16); 	
				$cols[$vj+5] =  $col_span;
				$headers[$vj+5] =  _($js);
				$aligns[$vj+5] =  'left';
				$vj++;
			}
	}elseif($payroll_monthly_choice == 2){
		$vj= 1;
		if($hrmsetup['BeginDay'] >= 1 && $hrmsetup['BeginDay'] < 31){
			$kv = $hrmsetup['BeginDay'];
			// $pre_mnth =  (($month > 1)? ($month-1) : 12);
			$total_days =  date("t", strtotime($year."-".$month."-01"));
			for($kv; $kv<=$total_days; $kv++){		
				$col_span = 240+($vj*16); 	
				$cols[$vj+5] =  $col_span;
				$headers[$vj+5] =  _($kv);
				$aligns[$vj+5] =  'left';
				$vj++;
			}	
		}
	
		if($hrmsetup['EndDay'] < 31){ 
			$kv_end_days = $hrmsetup['EndDay'];
			$nxt_mnth =  (($month < 12)? ($month+1) : '1');

			for($js=1;$js<=$hrmsetup['EndDay'];$js++){			
				$col_span = 240+($vj*16); 	
				$cols[$vj+5] =  $col_span;
				$headers[$vj+5] =  _($js);
				$aligns[$vj+5] =  'left';
				$vj++;
			}
		}

	}elseif($payroll_monthly_choice == 3){

		$vj= 1;
		if($hrmsetup['BeginDay'] >= 1 && $hrmsetup['BeginDay'] < 31){
			$kv = $hrmsetup['BeginDay'];
			$pre_mnth =  (($month > 1)? ($month-1) : 12);
			$total_days =  date("t", strtotime($year."-".$pre_mnth."-01"));
			for($kv; $kv<=$total_days; $kv++){		
					$col_span = 240+($vj*16); 	
					$cols[$vj+5] =  $col_span;
					$headers[$vj+5] =  _($kv);
					$aligns[$vj+5] =  'left';
					$vj++;
			}	
		}
					
		if($hrmsetup['EndDay'] < 31){ 
			$kv_end_days = $hrmsetup['EndDay'];
						//$nxt_mnth =  (($month < 12)? ($month+1) : '1');
			for($js=1;$js<=$hrmsetup['EndDay'];$js++){			
				$col_span = 240+($vj*16); 	
				$cols[$vj+5] =  $col_span;
				$headers[$vj+5] =  _($js);
				$aligns[$vj+5] =  'left';
				$vj++;
			}
		}
	}

	$headers[] = _("Working Days");
	$headers[] = _("LOP Days");
	$headers[] = _("Payble Days");

	$aligns[] =  'right';
	$aligns[] =  'right';
	$aligns[] =  'right';
	// $cols[] = 150+$col_span+60;
	// $cols[] = 200+$col_span+80;
	// $cols[] = 150+$col_span-30;
	$cols[] = 100+$col_span-50;
	$cols[] = 120+$col_span-10;
	$cols[] = 110+$col_span+50;
	$Allowance = get_all_allowances();
		foreach($Allowance as $single) {	
			if($single['type'] == 'Earnings')
				$headers[] = $single['description'] ; //substr($single['description'], 0, 5);
		}
		$headers[] = _("OT");
		$headers[] = _("Ot.Allo.");
		$headers[] = _("Gross");
		foreach($Allowance as $single) {
			if($single['type'] == 'Deductions')	
				$headers[] = $single['description']; //substr($single['description'], 0, 7);
		}

	   	$headers1 = array(_("Abs Days"),_("Abs Amt"),_("Misc."),_("Total Ded."),_("Net Sal"));
	   	$headers = array_merge($headers, $headers1);
	   	$count_header = count($headers)+2;

	$Col_count = 3000/$count_header;
		for($vj=1; $vj<=$count_header; $vj++){
			$aligns[] ='left';
			$cols[] = $vj*$Col_count;
		}
		array_pop($cols);
	
	$weekly_off = $hrmsetup['weekly_off'];
	
   $rep = new FrontReport(_('Month of Attendance').":".kv_month_name_by_id($month).' - Dept: '.GetSingleValue('kv_empl_departments', 'description', array('id' => $dept_id)), "Attendance", 'A3', 9, $orientation);
    if ($orientation == 'L')
    	recalculate_cols($cols);
	$params =   array( 	0 => $comments);
    $rep->Font();
    $rep->Info($params, $cols, $headers, $aligns);
    $rep->NewPage();

$serial_no = 1;
if($payroll_monthly_choice == 1){

 	$selected_empl = kv_get_employees_list_based_on_dept($dept_id);
	$total_days_count = date("t", strtotime($ext_year."-".$month."-01"));
	$sql_query = "SELECT date FROM ".TB_PREF."kv_empl_gazetted_holidays WHERE (date BETWEEN '".date("Y-m-d", strtotime($ext_year."-".$month."-1"))."' AND '".date("Y-m-d", strtotime($ext_year."-".$month."-".$total_days_count))."' ) ";

		$first_gazetted_leaves = array();
		$result = db_query($sql_query, _("Can't get results"));
		if(db_num_rows($result)){
			while($cont = db_fetch($result))
				$first_gazetted_leaves[] = $cont[0];
		}
		$beginDay = date("Y-m-d", strtotime($ext_year."-".$month."-01"));
		while ($row = db_fetch_assoc($selected_empl)) {	
			$weekly_off1 = GetSingleValue('kv_empl_job', 'weekly_off', array('empl_id'=>$row['empl_id'])); 		
			$sql = "SELECT * FROM ".TB_PREF."kv_empl_attendance WHERE empl_id=".db_escape($row['empl_id'])." AND a_date >= '".$beginDay."' AND a_date <= '".date("Y-m-t", strtotime($ext_year."-".$month."-01"))."' GROUP BY a_date, dimension ORDER BY a_date ASC";
			$res = db_query($sql, _("Can't get attendance"));
			$final = array();
			while($row2 = db_fetch_assoc($res)){
				$final[$row2['a_date']][$row2['dimension']] = $row2;
			}

			$data_for_empl = GetRow('kv_empl_salary', array('empl_id' => $row['empl_id'], 'month' => $month, 'year' => $year));							
			$empl['department']= GetSingleValue('kv_empl_departments', 'description', array('id' => $row['department']));
			$empl['grade'] = GetSingleValue('kv_empl_grade', 'description', array('id' => $row['grade']));

			$rep->NewLine(1, 2);
			$rep->TextCol(0, 1, $serial_no);
			$rep->TextCol(1, 2, $row['empl_id']);
			$rep->TextCol(2, 3, $row['empl_firstname']);
			$rep->TextCol(3, 4, $row['empl_city']);
			$rep->TextCol(4, 5, $empl['department']);
			$rep->TextCol(5, 6, $empl['grade']);
			$leave_Day = $workingDays = 0 ;
			$j = 6;
			$v = 7; 
			$serial_no++;	
			for($vj=1; $vj <= $total_days_count; $vj++){		

				if(date("D", strtotime($ext_year."-".$month."-".$vj)) != $weekly_off )	{	
					$workingDays++;

					if(isset($final[date("Y-m-d", strtotime($ext_year."-".$month."-".$vj))]))	{						
						$val = $final[date("Y-m-d", strtotime($ext_year."-".$month."-".$vj))][0];	

						$rep->TextCol($j, $v, ($val['code']? $val['code']: '-'));

						if($val['code'] == 'A')
							$leave_Day += 1;
						if($val['code'] == 'HD')
							$leave_Day += 0.5;
					}else
						$rep->TextCol($j, $v, '-');

				}else {

						if($val[$vj] == 'P' || $val[$vj] == 'OD')
							$workingDays++;
						if($val[$vj] == 'A' || ($val[$vj] == '' && (strtotime($ext_year."-".$month."-".$vj)<= strtotime(date('Y-m-d'))) ))
							$leave_Day += 1;
						if($val[$vj] == 'GL' || $val[$vj] == 'CL' || $val[$vj] == 'ML')
							$leave_Day += 1;
						if($val[$vj] == 'HD'){
							$leave_Day += 0.5;
							$workingDays += 0.5;
						}
						$rep->TextCol($j, $v, ($val[$vj]? $val[$vj]: (strtotime($ext_year."-".$month."-".$vj)<= strtotime(date('Y-m-d'))? 'A' : '-')));
					}
					$j++; $v++;
				}
			
				$Payable_days=$total_days-$leave_Day;

				$rep->TextCol($j, $v, $workingDays);
				$j++;
				$v++;
				$rep->TextCol($j, $v, $leave_Day);

				$j++;
				$v++;
				$rep->TextCol($j, $v, $Payable_days);

				if($data_for_empl) {
					$vj = $j++; $jv = $v++;	
						foreach($Allowance as $single) {
							if($single['type'] == 'Earnings'){
								$vj++; $jv++;
								$rep->TextCol($vj, $jv, number_format2($data_for_empl[$single['id']]*$data_for_empl['rate'],$dec));
							}							
						}
						$vj++; $jv++;
						$rep->TextCol($vj, $jv, number_format2($data_for_empl['ot_earnings']*$data_for_empl['rate'],$dec));

						$vj++; $jv++;
						$rep->TextCol($vj, $jv, number_format2($data_for_empl['ot_other_allowance']*$data_for_empl['rate'],$dec));

						$vj++; $jv++;
						$rep->TextCol($vj, $jv, number_format2($data_for_empl['gross']*$data_for_empl['rate'],$dec));

						$total_ded = 0; 
						foreach($Allowance as $single) {
							if($single['type'] == 'Deductions'){
								$vj++; $jv++;
								$rep->TextCol($vj, $jv, number_format2($data_for_empl[$single['id']]*$data_for_empl['rate'],$dec));
								$total_ded += $data_for_empl[$single['id']]; 
							}
						}
						//$vj++; $jv++;
						//$rep->TextCol($vj, $jv, number_format2($data_for_empl['loan']*$data_for_empl['rate'],$dec));
						//$total_ded += $data_for_empl['loan']; 

						$vj++; $jv++;
						$rep->TextCol($vj, $jv, get_empl_attendance_for_month($data_for_empl['empl_id'], $month, $year));

						$vj++; $jv++;
						$rep->TextCol($vj, $jv, number_format2($data_for_empl['lop_amount']*$data_for_empl['rate'],$dec));
						$total_ded += $data_for_empl['lop_amount']; 

						$vj++; $jv++;
						$rep->TextCol($vj, $jv, number_format2($data_for_empl['misc']*$data_for_empl['rate'],$dec));
						$total_ded += $data_for_empl['misc']; 						

						$vj++; $jv++;
						$rep->TextCol($vj, $jv, number_format2($total_ded*$data_for_empl['rate'],$dec));

						$vj++; $jv++;
						$rep->TextCol($vj, $jv, number_format2($data_for_empl['net_pay']*$data_for_empl['rate'],$dec));

				$rep->NewLine();  
			}
		}				

}elseif($payroll_monthly_choice == 2){

	$selected_empl = kv_get_employees_list_based_on_dept($dept_id);
	$pre_mnth =  (($month > 1)? ($month-1) : '12');

	$beginDay = date("Y-m-d", strtotime($ext_year."-".$pre_mnth."-01"));
	while ($row = db_fetch_assoc($selected_empl)) {
		$weekly_off1 = GetSingleValue('kv_empl_job', 'weekly_off', array('empl_id'=>$row['empl_id']));

		$sql = "SELECT * FROM ".TB_PREF."kv_empl_attendance WHERE empl_id=".db_escape($row['empl_id'])." AND a_date >= '".$beginDay."' AND a_date <= '".date("Y-m-t", strtotime($ext_year."-".$nxt_mnth."-01"))."' GROUP BY a_date, dimension ORDER BY a_date ASC";
			$res = db_query($sql, _("Can't get attendance"));
			$final = array();
			while($row2 = db_fetch_assoc($res)){
				$final[$row2['a_date']][$row2['dimension']] = $row2;
			}	

			$data_for_empl = GetRow('kv_empl_salary', array('empl_id' => $row['empl_id'], 'month' => $month, 'year' => $year));							
			$empl['department']= GetSingleValue('kv_empl_departments', 'description', array('id' => $row['department']));
			$empl['grade'] = GetSingleValue('kv_empl_grade', 'description', array('id' => $row['grade']));

			$rep->NewLine(1, 2);
			$rep->TextCol(0, 1, $serial_no);
			$rep->TextCol(1, 2, $row['empl_id']);
			$rep->TextCol(2, 3, $row['empl_firstname']);
			$rep->TextCol(3, 4, $row['empl_city']);
			$rep->TextCol(4, 5, $empl['department']);
			$rep->TextCol(5, 6, $empl['grade']);
			$leave_Day = $workingDays = 0 ;
			$j = 6;
			$v = 7; 
			$serial_no++;	
			
			if($hrmsetup['BeginDay'] >= 1 && $hrmsetup['BeginDay'] < 31){
				$vj = $hrmsetup['BeginDay'];
				
				$total_days =  date("t", strtotime($ext_year."-".$month."-01"));
				for($vj; $vj<=$total_days; $vj++){

					if(date("D", strtotime($ext_year."-".$month."-".$vj))  != $weekly_off )	{
						$workingDays++;

						if(isset($final[date("Y-m-d", strtotime($ext_year."-".$month."-".$vj))]))	{						
							$val = $final[date("Y-m-d", strtotime($ext_year."-".$month."-".$vj))][0];
											
							$rep->TextCol($j, $v, ($val['code']? $val['code']: '-'));

							if($val['code'] == 'A')
								$leave_Day += 1;
							if($val['code'] == 'HD')
								$leave_Day += 0.5;
						} else

						$rep->TextCol($j, $v, '-');
						
						$j++; $v++;
					}
				}
			}
			if($hrmsetup['EndDay'] < 31){ 
				$kv_end_days = $hrmsetup['EndDay'];			

				for($js=1;$js<=$kv_end_days;$js++){	

				if(date("D", strtotime($ext_year."-".$nxt_mnth."-".$js)) != $weekly_off )	{	
						$workingDays++;

				if(isset($final[date("Y-m-d", strtotime($ext_year."-".$nxt_mnth."-".$js))]))	{						
						$val = $final[date("Y-m-d", strtotime($ext_year."-".$nxt_mnth."-".$js))][0];		
					$rep->TextCol($j, $v, ($val['code']? $val['code']: '-'));

					if($val['code'] == 'A')
						$leave_Day += 1;
					if($val['code'] == 'HD')
						$leave_Day += 0.5;
				}else
					$rep-> TextCol($j, $v, '-');
					
					$j++; $v++;
				}
			}
			}
			$Payable_days=$total_days-$leave_Day;

			$rep->TextCol($j, $v, $workingDays);
			$j++;
			$v++;
			$rep->TextCol($j, $v, $leave_Day);

			$j++;
			$v++;
			$rep->TextCol($j, $v, $Payable_days);

			if($data_for_empl) {
				$vj = $j++; $jv = $v++;
						foreach($Allowance as $single) {
							if($single['type'] == 'Earnings'){
								$vj++; $jv++;
								$rep->TextCol($vj, $jv, number_format2($data_for_empl[$single['id']]*$data_for_empl['rate'],$dec));
							}							
						}

						$vj++; $jv++;
						$rep->TextCol($vj, $jv, number_format2($data_for_empl['ot_earnings']*$data_for_empl['rate'],$dec));

						$vj++; $jv++;
						$rep->TextCol($vj, $jv, number_format2($data_for_empl['ot_other_allowance']*$data_for_empl['rate'],$dec));

						$vj++; $jv++;
						$rep->TextCol($vj, $jv, number_format2($data_for_empl['gross']*$data_for_empl['rate'],$dec));

						$total_ded = 0; 
						foreach($Allowance as $single) {
							if($single['type'] == 'Deductions'){
								$vj++; $jv++;
								$rep->TextCol($vj, $jv, number_format2($data_for_empl[$single['id']]*$data_for_empl['rate'],$dec));
								$total_ded += $data_for_empl[$single['id']]; 
							}
						}
						//$vj++; $jv++;
						//$rep->TextCol($vj, $jv, number_format2($data_for_empl['loan']*$data_for_empl['rate'],$dec));
						//$total_ded += $data_for_empl['loan']; 

						$vj++; $jv++;
						$rep->TextCol($vj, $jv, get_empl_attendance_for_month($data_for_empl['empl_id'], $month, $year));

						$vj++; $jv++;
						$rep->TextCol($vj, $jv, number_format2($data_for_empl['lop_amount']*$data_for_empl['rate'],$dec));
						$total_ded += $data_for_empl['lop_amount']; 

						$vj++; $jv++;
						$rep->TextCol($vj, $jv, number_format2($data_for_empl['misc']*$data_for_empl['rate'],$dec));
						$total_ded += $data_for_empl['misc']; 						

						$vj++; $jv++;
						$rep->TextCol($vj, $jv, number_format2($total_ded*$data_for_empl['rate'],$dec));

						$vj++; $jv++;
						$rep->TextCol($vj, $jv, number_format2($data_for_empl['net_pay']*$data_for_empl['rate'],$dec));

				$rep->NewLine();  

			}
		}								
}elseif($payroll_monthly_choice == 3){

    $selected_empl = kv_get_employees_list_based_on_dept($dept_id);
	$pre_mnth =  (($month > 1)? ($month-1) : '12');

	$beginDay = date("Y-m-d", strtotime($ext_year."-".$pre_mnth."-01"));
	while ($row = db_fetch_assoc($selected_empl)) {
		$weekly_off1 = GetSingleValue('kv_empl_job', 'weekly_off', array('empl_id'=>$row['empl_id']));

		$sql = "SELECT * FROM ".TB_PREF."kv_empl_attendance WHERE empl_id=".db_escape($row['empl_id'])." AND a_date >= '".$beginDay."' AND a_date <= '".date("Y-m-t", strtotime($ext_year."-".$month."-01"))."' GROUP BY a_date, dimension ORDER BY a_date ASC";
		$res = db_query($sql, _("Can't get attendance"));
		$final = array();
		while($row2 = db_fetch_assoc($res)){
			$final[$row2['a_date']][$row2['dimension']] = $row2;
		}	
		//foreach ($res as $details_single_empl) {	}
		// if($details_single_empl || $details_single_empl_nxt_mnth){

		$data_for_empl = GetRow('kv_empl_salary', array('empl_id' => $row['empl_id'], 'month' => $month, 'year' => $year));							
		$empl['department']= GetSingleValue('kv_empl_departments', 'description', array('id' => $row['department']));
		$empl['grade'] = GetSingleValue('kv_empl_grade', 'description', array('id' => $row['grade']));

		$rep->NewLine(1, 2);
		$rep->TextCol(0, 1, $serial_no);
		$rep->TextCol(1, 2, $row['empl_id']);
		$rep->TextCol(2, 3, $row['empl_firstname']);
		$rep->TextCol(3, 4, $row['empl_city']);
		$rep->TextCol(4, 5, $empl['department']);
		$rep->TextCol(5, 6, $empl['grade']);
		$leave_Day = $workingDays = $workingDayss = 0 ;
		$j = 6;
		$v = 7; 
			$serial_no++;	
			
		if($hrmsetup['BeginDay'] >= 1 && $hrmsetup['BeginDay'] < 31){
			$vj = $hrmsetup['BeginDay'];
				
			$total_days =  date("t", strtotime($ext_year."-".$pre_mnth."-01"));
			for($vj; $vj<=$total_days; $vj++){

				$day_letters = date("D", strtotime($ext_year."-".$pre_mnth."-".$vj)) ;
				if(in_array($day_letters, $weekly_off )){
					$val['code'] = 'OFF';	
				}

				if(date("D", strtotime($ext_year."-".$pre_mnth."-".$vj))  != $weekly_off )	{
					$workingDays++;

					if(isset($final[date("Y-m-d", strtotime($ext_year."-".$pre_mnth."-".$vj))]))	{						
						$val = $final[date("Y-m-d", strtotime($ext_year."-".$pre_mnth."-".$vj))][0];
						$day_letters = date("D", strtotime($ext_year."-".$pre_mnth."-".$vj)) ;

						if(in_array($day_letters, $weekly_off )){
							$val['code'] = 'off';
						}
						if(isset($val['code']) && $val['code'] == 'P')
								$workingDayss++;
						$rep->TextCol($j, $v, ($val['code'] ? $val['code']: '-'));

						if($val['code'] == 'A')
							$leave_Day += 1;
						if($val['code'] == 'HD')
							$leave_Day += 0.5;
					} else {
						$rep->TextCol($j, $v, (isset($val['code']) ? $val['code']: '-'));
					}
					if(isset($val))
					unset($val['code']);
					$j++; $v++;						
				}
			}
		}
		if($hrmsetup['EndDay'] < 31){ 
			$kv_end_days = $hrmsetup['EndDay'];		

			for($js=1;$js<=$kv_end_days;$js++){	
				$day_letters = date("D", strtotime($ext_year."-".$month."-".$js)) ;
				if(in_array($day_letters, $weekly_off )){
						$val['code'] = 'OFF';	
				}

				if(date("D", strtotime($ext_year."-".$month."-".$js)) != $weekly_off )	{	
					$workingDays++;

					if(isset($final[date("Y-m-d", strtotime($ext_year."-".$month."-".$js))]))	{						
							$val = $final[date("Y-m-d", strtotime($ext_year."-".$month."-".$js))][0];
							$day_letters = date("D", strtotime($ext_year."-".$month."-".$js)) ;
							if(in_array($day_letters, $weekly_off )){
								$val['code'] = 'off';
							}
							if(isset($val['code']) && $val['code'] == 'P')
									$workingDayss++;
							$rep->TextCol($j, $v, ($val['code']? $val['code']: '-'));
							if($val['code'] == 'A')
								$leave_Day += 1;
							if($val['code'] == 'HD')
								$leave_Day += 0.5;
					}else {
							$rep->TextCol($j, $v, (isset($val['code']) ? $val['code']: '-'));
					}

					unset($val['code']);
					$j++; $v++;
				}
			}
		}
		$Payable_days=$workingDayss;

		$rep->TextCol($j, $v, $workingDays);
			$j++;
			$v++;
		$rep->TextCol($j, $v, $leave_Day);
			$j++;
			$v++;
		$rep->TextCol($j, $v, $Payable_days);

		if($data_for_empl) {
			$vj = $j++; $jv = $v++;					

			foreach($Allowance as $single) {
				if($single['type'] == 'Earnings'){
					$vj++; $jv++;
					$rep->TextCol($vj, $jv, number_format2($data_for_empl[$single['id']]*$data_for_empl['rate'],$dec));
				}							
			}

			$vj++; $jv++;
			$rep->TextCol($vj, $jv, number_format2($data_for_empl['ot_earnings']*$data_for_empl['rate'],$dec));

			$vj++; $jv++;
			$rep->TextCol($vj, $jv, number_format2($data_for_empl['ot_other_allowance']*$data_for_empl['rate'],$dec));

			$vj++; $jv++;
			$rep->TextCol($vj, $jv, number_format2($data_for_empl['gross']*$data_for_empl['rate'],$dec));

			$total_ded = 0; 
			foreach($Allowance as $single) {
				if($single['type'] == 'Deductions'){
					$vj++; $jv++;
					$rep->TextCol($vj, $jv, number_format2($data_for_empl[$single['id']]*$data_for_empl['rate'],$dec));
					$total_ded += $data_for_empl[$single['id']]; 
				}
			}
			//$vj++; $jv++;
			//$rep->TextCol($vj, $jv, number_format2($data_for_empl['loan']*$data_for_empl['rate'],$dec));
			//$total_ded += $data_for_empl['loan']; 

			$vj++; $jv++;
			$rep->TextCol($vj, $jv, get_empl_attendance_for_month($data_for_empl['empl_id'], $month, $year));

			$vj++; $jv++;
			$rep->TextCol($vj, $jv, number_format2($data_for_empl['lop_amount']*$data_for_empl['rate'],$dec));
			$total_ded += $data_for_empl['lop_amount']; 

			$vj++; $jv++;
			$rep->TextCol($vj, $jv, number_format2($data_for_empl['misc']*$data_for_empl['rate'],$dec));
			$total_ded += $data_for_empl['misc']; 						

			$vj++; $jv++;
			$rep->TextCol($vj, $jv, number_format2($total_ded*$data_for_empl['rate'],$dec));

			$vj++; $jv++;
			$rep->TextCol($vj, $jv, number_format2($data_for_empl['net_pay']*$data_for_empl['rate'],$dec));

			$rep->NewLine();  
		}					
	}	
}

if ($rep->row < $rep->bottomMargin + (15 * $rep->lineHeight))
	$rep->NewPage();	
$rep->End();

?>