<?php 

$PageSecurity = 15;
set_time_limit (900) ;
$title = _('Monthly Attendance') ;
include ("CSVImporterClass.php");
include('includes/fun-php.php'); 
include('Class-EmpMaster.php');   
include('func_emp_leave.php'); 
$target="index.php?route=HRModule/Entry-Monthly-Attendance".$rurl;
$currentyear=date('Y');?>

<h2 align="center"><strong>Importing Monthly Attendance</strong></h2>
<h4 align="center"><font color="#CC0033"><strong>*Please select a month to view attendance</strong></font></h4>
<?php
if($_REQUEST['proceed']!='')
{
 	 $s->pageLocation($target."&month=".$_REQUEST['month']."&years=".$_REQUEST['years']."&site=".$_REQUEST['site']."&empcode=".$_REQUEST['employee_code']);
}
?>




<form method="post" action="" enctype="multipart/form-data">
<table width="50%" border="0" align="center" cellpadding="3" cellspacing="0">


<tr>
	<td><strong>Import CSV File</strong></td>
	<td><input type="file" name="imprt" id="imprt" />
	  <input type="submit" name="impsave" value="Save" /></td>
</tr>
<tr>
	<td colspan="2">&nbsp;</td>
</tr>
</table>
</form>



<?php
if(isset($_REQUEST['impsave']))
{

if($_FILES['imprt']['type']!='')
{		
 $data2=$_FILES['imprt']['tmp_name'];

//$cnx = conexion ();
 $upload = new CSVImporter ("daily_attendance_2", $data2, "yes", $cnx);

$upload->Upload ();
	if($upload)
	{
	echo "Upload Sucessfully";

		$qryinp = "SELECT e_code,site,shift_start,shiftstart_AMPM,shift_end,shiftend_AMPM,time_in,timein_AMPM,time_out
				  ,timeout_AMPM,ot_hrs,attendance_date,pres_abs FROM daily_attendance_2";
				$qryinpq = DB_query($qryinp,$db);
		while($qryrow = DB_fetch_array($qryinpq))
		{
		###### get employee id #######
		 $entry_empid = $s->GetFieldValue('empmaster', 'emp_code="'.$qryrow['e_code'].'" 
		AND emp_site="'.ucwords($qryrow['site']).'"', 'id');
		
		 $entry_shiftcat = $s->GetFieldValue('empmaster', 'emp_code="'.$qryrow['e_code'].'" 
		 AND emp_site="'.ucwords($qryrow['site']).'"', 'employee_type');
		 
		 $sqlatt = "INSERT INTO daily_attendance (id, site, e_code, employee, shift_category, shift_start,
		  shiftstart_AMPM, shift_end, shiftend_AMPM, time_in,
		   timein_AMPM, time_out, timeout_AMPM, ot_hrs,attendance_date,
		     pres_abs,created_date,  created_by)
			  VALUES ('', '".ucwords($qryrow['site'])."'
			  , '".$qryrow['e_code']."', '".$entry_empid."',
			   '".$entry_shiftcat."', '".$qryrow['shift_start']."', 
			   '".$qryrow['start_AMPM']."', '".$qryrow['shift_end']."',
			    '".$qryrow['shiftend_AMPM']."', '".$qryrow['time_in']."',
				 '".$qryrow['timein_AMPM']."', '".$qryrow['time_out']."',
				  '".$qryrow['timeout_AMPM']."',  '".$qryrow['ot_hrs']."',
				    '".$qryrow['attendance_date']."','".$qryrow['pres_abs']."'
					, NOW(), '".$_SESSION['UserID']."')";
				  DB_query($sqlatt,$db); 


         } 
    }
 }
} 
 ?>







</div>
