0xV3NOMx
Linux ip-172-26-7-228 5.4.0-1103-aws #111~18.04.1-Ubuntu SMP Tue May 23 20:04:10 UTC 2023 x86_64



Your IP : 18.226.34.148


Current Path : /var/www/misc/public_html/oums_old/phpscript/
Upload File :
Current File : /var/www/misc/public_html/oums_old/phpscript/status_report_03022018.php

<?php
	include("sys_session.php");	
	include("sys_mainphp.php");	
	include("sys_connect.php");		
	
	$resp_mesg="";
	$resp_stat="";
	$resp_file="";
	$dept_code="";	
	$attn_date=date('Y-m-d');

	//IMPORT LOGISYS ATTENDANCE
	$mysql = "";
	$mysql.= "select * from masempl where fdeptcode='LOGS' and femplstat='T' and fdeleted<>'T' and faltrcode<>'' order by faltrcode";
	$myres = mysqli_query($mycon,$mysql);
	$mycnt = mysqli_num_rows($myres);
	if($mycnt!=0)
	{
		while($row = mysqli_fetch_assoc($myres))	
		{			
			$empl_code=$row['femplcode'];
			$altr_code=$row['faltrcode'];
						
			$mysql1 = "select faltrcode, min(ftime) as llogitime, max(ftime) as llogotime from  attendancedet ";
			$mysql1.= "where fattndate='$attn_date' and faltrcode='$altr_code' order by faltrcode,ftime ";
			$myres1 = mysqli_query($mycon,$mysql1);
			while($row1 = mysqli_fetch_assoc($myres1))	
			{											
				if($row1['faltrcode']=="")
				{
					$attn_stat="AB";
					$logi_time="";
					$logo_time="";				
				}
				else
				{
					$attn_stat="PR";
					$logi_time=date("i:s", strtotime($row1['llogitime']));
					$logo_time=date("i:s", strtotime($row1['llogotime']));
					
					if($logi_time==$logo_time){$logo_time="";}
				}
			}

			$mysql2 = "";
			$mysql2.= "select * from attendance where fattndate='$attn_date' and femplcode='$empl_code'";
			$myres2 = mysqli_query($mycon,$mysql2);
			$mycnt2 = mysqli_num_rows($myres2);
			if($mycnt2==0)
			{
				$mysqlx = "";
				$mysqlx.= "insert into attendance (fdeptcode,femplcode,fattndate,fattnstat,flogitime,flogotime,fupdtuser,fupdttime) ";
				$mysqlx.= "values('LOGS','$empl_code','$attn_date','$attn_stat','$logi_time','$logo_time','$user_id',now())";
				$myresx = mysqli_query($mycon,$mysqlx);		
			}
			else
			{
				$mysqlx = "";
				$mysqlx.= "update attendance set fattnstat='$attn_stat',flogitime='$logi_time',flogotime='$logo_time',fupdtuser='$user_id',fupdttime=now() ";
				$mysqlx.= "where fattndate='$attn_date' and femplcode='$empl_code'";
				$myresx = mysqli_query($mycon,$mysqlx);
			}
		}	
	}
	
	require_once("fpdf/fpdf.php");						
	$pdf = new FPDF('P','mm','A4');
	$pdf->SetMargins(15,15);		
	$pdf->SetFont('Arial','',9);		
	
	//DAY SUMMARY
	$mysql = "";
	$mysql.= "select * from masdept where ifnull(fdeptstat,'F')='T' order by fdeptname";
	$myres = mysqli_query($mycon,$mysql);
	$mycnt = mysqli_num_rows($myres);
	if($mycnt==0)
	{
	
	}
	else
	{
		$i=1;
		$line_no=0;
		while($row = mysqli_fetch_assoc($myres))	
		{			
			$dept_code=$row['fdeptcode'];
			if($line_no==0||$line_no%36==0)			
			{
				$rept_date=date('d-m-Y',strtotime($attn_date));
				$header_dept_code=$dept_code;						
				$header_dept_name=get_dept_name($dept_code);

				$pdf->AddPage();

				$pdf->SetFont('Arial','B',11);				
				$pdf->Cell(0,7,"LOGISYS",0,1,"C");	$line_no++;				
				
				$pdf->SetFont('Arial','B',10);								
				$pdf->Cell(0,7,"ATTENDANCE SUMMARY",0,1,"C");	$line_no++;					
				$pdf->Cell(0,7,"DATE: {$rept_date}",0,1,"C");	$line_no++;												
								
				$pdf->SetFont('Arial','B',9);									

				$x = $pdf->GetX();	$y = $pdf->GetY();		
				$pdf->MultiCell(10,7,"Sl. No.",1,"C");			

				$pdf->SetXY($x + 10, $y);	
				$pdf->MultiCell(15,7,"Dept. Code",1,"C");			

				$pdf->SetXY($x + 25, $y);	
				$pdf->MultiCell(100,14,"Department Name",1,"C");			

				$pdf->SetXY($x + 125, $y);	
				$pdf->MultiCell(40,7,"Total",1,"C");			

				$pdf->SetXY($x + 125, $y + 7);	
				$pdf->MultiCell(10,7,"Empl.",1,"C");			

				$pdf->SetXY($x + 135, $y + 7);	
				$pdf->MultiCell(10,7,"Pr.",1,"C");			

				$pdf->SetXY($x + 145, $y + 7);	
				$pdf->MultiCell(10,7,"Ab.",1,"C");			
				
				$pdf->SetXY($x + 155, $y + 7);	
				$pdf->MultiCell(10,7,"C.L.",1,"C");			
				
				$pdf->SetXY($x + 165, $y);					
				$pdf->MultiCell(20,14,"Remarks",1,"C");			
				$line_no++;				
			}
			$pdf->SetFont('Arial','',9);				
			$pdf->Cell(10,7,"{$i}",1,0,"C");					
			$pdf->Cell(15,7,"{$row['fdeptcode']}",1,0,"C");											
			$pdf->Cell(100,7,"{$row['fdeptname']}",1,0,"L");														
			
			$mysql1 = "";
			$mysql1.= "select count(*) as ltotempl, sum(case when fattnstat in ('PR','P1','P2','PO','CD','D1','D2') then 1 end) as ltotalpr, ";
			$mysql1.= "sum(case when fattnstat ='AB' then 1 else 0 end) as ltotalab,";
			$mysql1.= "sum(case when fattnstat ='CL' then 1 else 0 end) as ltotalcl ";			
			$mysql1.= "from attendance where fdeptcode='$dept_code' and fattndate='$attn_date' ";			
			$mysql1.= "group by fdeptcode";
			$myres1 = mysqli_query($mycon,$mysql1);
			$mycnt1 = mysqli_num_rows($myres1);
			if($mycnt1==0)
			{
					$pdf->Cell(10,7,"-",1,0,"C");																				
					$pdf->Cell(10,7,"-",1,0,"C");																				
					$pdf->Cell(10,7,"-",1,0,"C");																									
					$pdf->Cell(10,7,"-",1,0,"C");																									
					$pdf->Cell(20,7,"Pending",1,0,"C");																							
			}
			else
			{
				while($row1 = mysqli_fetch_assoc($myres1))	
				{
					$pdf->Cell(10,7,"{$row1['ltotempl']}",1,0,"C");																				
					$pdf->Cell(10,7,"{$row1['ltotalpr']}",1,0,"C");																									
					$pdf->Cell(10,7,"{$row1['ltotalab']}",1,0,"C");																				
					$pdf->Cell(10,7,"{$row1['ltotalcl']}",1,0,"C");																									
					$pdf->Cell(20,7,"",1,0,"C");																				
				}					
			}
			$pdf->ln();$line_no++;				
			$i++;			
		}
	}


	//LOGISYS EMPLOYEES
	$mysql ="";
	$mysql.="select (case when fpermempl='T' then 'LOGS' else attendance.fdeptcode end) as fdeptcode,attendance.femplcode,femplname,";
	$mysql.="fattndate,attendance.fattnstat,fstatdesc,attendance.flogitime,attendance.flogotime,";
	$mysql.="masattnstat.flogitime as llogitime,masattnstat.flogotime as llogotime ";
	$mysql.="from attendance,masempl,masattnstat where fattndate='$attn_date' and attendance.femplcode=masempl.femplcode ";
	$mysql.="and attendance.fattnstat=masattnstat.fattnstat and attendance.fdeptcode=masattnstat.fdeptcode and fpermempl='T' ";
	$mysql.="order by femplname";	

	$myres=mysqli_query($mycon,$mysql);
	$mycnt=mysqli_num_rows($myres);
	if($mycnt!=0)
	{
		$line_no=0;
		while($row = mysqli_fetch_assoc($myres))	
		{
			if($dept_code<>$row['fdeptcode'])
			{
				$line_no=0;
				$i=1;			
			}
			
			if($line_no==0||$line_no%36==0)			
			{
				$dept_code=$row['fdeptcode'];
				$rept_date=date('d-m-Y',strtotime($attn_date));
				$header_dept_code=$dept_code;						
				$header_dept_name=get_dept_name($dept_code);

				$pdf->AddPage();
				$pdf->SetFont('Arial','B',11);				
				$pdf->Cell(0,7,"LOGISYS",0,1,"C");	$line_no++;				
				
				$pdf->SetFont('Arial','B',10);				
				$pdf->Cell(0,7,"ATTENDANCE STATUS: {$rept_date}",0,1,"C");	$line_no++;					
				$pdf->Cell(0,7,"[{$header_dept_name}]",0,1,"C");	$line_no++;											
				
				$pdf->SetFont('Arial','B',9);									
				
				$x = $pdf->GetX();	$y = $pdf->GetY();		
				$pdf->MultiCell(10,7,"Sl. No.",1,"C");			

				$pdf->SetXY($x + 10, $y);	
				$pdf->MultiCell(15,7,"Empl. Code",1,"C");			

				$pdf->SetXY($x + 25, $y);	
				$pdf->MultiCell(50,14,"Employee Name",1,"C");			

				$pdf->SetXY($x + 75, $y);	
				$pdf->MultiCell(25,14,"Status",1,"C");			
								
				$pdf->SetXY($x + 100, $y);	
				$pdf->MultiCell(35,7,"Log In",1,"C");			

				$pdf->SetXY($x + 100, $y + 7);	
				$pdf->MultiCell(15,7,"Time",1,"C");			

				$pdf->SetXY($x + 115, $y + 7);	
				$pdf->MultiCell(20,7,"Remarks",1,"C");			

				$pdf->SetXY($x + 135, $y);	
				$pdf->MultiCell(35,7,"Log Out",1,"C");			

				$pdf->SetXY($x + 135, $y + 7);	
				$pdf->MultiCell(15,7,"Time",1,"C");			

				$pdf->SetXY($x + 150, $y + 7);	
				$pdf->MultiCell(20,7,"Remarks",1,"C");			

				$pdf->SetXY($x + 170, $y);	
				$pdf->MultiCell(15,7,"Work Hours",1,"C");			
				
				$line_no++;				
			}
			$empl_code=$row['femplcode'];
			$pdf->SetFont('Arial','',9);				
			$pdf->Cell(10,7,"{$i}",1,0,"C");					
			$pdf->Cell(15,7,"{$row['femplcode']}",1,0,"C");											
			$pdf->Cell(50,7,"{$row['femplname']}",1,0,"L");														
			$pdf->Cell(25,7,"{$row['fstatdesc']}",1,0,"C");																										
			$attn_stat=strtolower($row['fattnstat']);
			if($attn_stat=="ab"||$attn_stat=="cl"||$attn_stat=="hd")
			{
				$pdf->Cell(15,7,"-",1,0,"C");														
				$pdf->Cell(20,7,"-",1,0,"C");																										
				$pdf->Cell(15,7,"-",1,0,"C");														
				$pdf->Cell(20,7,"-",1,0,"C");																										
				$pdf->Cell(15,7,"-",1,0,"C");																														
			}
			else
			{
				$logi_tim1 = $row['flogitime'];
				$logi_tim2 = $row['llogitime'];
				$pdf->Cell(15,7,"{$logi_tim1}",1,0,"C");														
				if($logi_tim1>$logi_tim2) 
				{
					$logi_diff = get_time_diff($logi_tim2, $logi_tim1);
					$pdf->Cell(20,7,"{$logi_diff} delay",1,0,"C");
				}
				elseif($logi_tim1<$logi_tim2) 
				{	
					$logi_diff = get_time_diff($logi_tim1, $logi_tim2);
					$pdf->Cell(20,7,"{$logi_diff} early",1,0,"C");
				}				
				else
				{	
					$pdf->Cell(20,7,"-",1,0,"C");
				}								

				$logo_tim1 = $row['flogotime'];
				$logo_tim2 = $row['llogotime'];
				$logo_diff = get_time_diff($logo_tim1, $logo_tim2);
				if($logo_tim1>$logo_tim2) 
				{
					$pdf->Cell(15,7,"{$logo_tim1}",1,0,"C");														
					$pdf->Cell(20,7,"{$logo_diff} delay",1,0,"C");
				}
				elseif($logo_tim1=="00:00:00") 
				{	
					$pdf->Cell(15,7,"-",1,0,"C");														
					$pdf->Cell(20,7,"Pending",1,0,"C");
				}				
				elseif($logo_tim1<$logo_tim2) 
				{	
					$pdf->Cell(15,7,"{$logo_tim1}",1,0,"C");														
					$pdf->Cell(20,7,"{$logo_diff} early",1,0,"C");
				}				
				else
				{	
					$pdf->Cell(15,7,"-",1,0,"C");
					$pdf->Cell(20,7,"-",1,0,"C");
				}								

			
				$work_time = get_time_diff($logi_tim1, $logo_tim1);				
				if($logo_tim1=="00:00:00") 
				{
					$pdf->Cell(15,7,"-",1,0,"C");																											
				}
				else
				{
					$pdf->Cell(15,7,"{$work_time}",1,0,"C");																															
				}
			}
			$i++;
			$pdf->ln();$line_no++;				
		}
	}
	
	//OTHER EMPLOYEES
	$mysql ="";
	$mysql.="select (case when fpermempl='T' then 'LOGS' else attendance.fdeptcode end) as fdeptcode,attendance.femplcode,femplname,";
	$mysql.="fattndate,attendance.fattnstat,fstatdesc,attendance.flogitime,attendance.flogotime,";
	$mysql.="masattnstat.flogitime as llogitime,masattnstat.flogotime as llogotime ";
	$mysql.="from attendance,masempl,masattnstat where fattndate='$attn_date' and attendance.femplcode=masempl.femplcode ";
	$mysql.="and attendance.fattnstat=masattnstat.fattnstat and attendance.fdeptcode=masattnstat.fdeptcode and fpermempl<>'T' ";
	$mysql.="order by attendance.fdeptcode,femplname";	

	$myres=mysqli_query($mycon,$mysql);
	$mycnt=mysqli_num_rows($myres);
	if($mycnt!=0)
	{
		$line_no=0;

		while($row = mysqli_fetch_assoc($myres))	
		{
			if($dept_code<>$row['fdeptcode'])
			{
				$line_no=0;
				$i=1;			
			}
			
			if($line_no==0||$line_no%36==0)			
			{
				$dept_code=$row['fdeptcode'];
				$rept_date=date('d-m-Y',strtotime($attn_date));
				$header_dept_code=$dept_code;						
				$header_dept_name=get_dept_name($dept_code);

				$pdf->AddPage();
				$pdf->SetFont('Arial','B',11);				
				$pdf->Cell(0,7,"LOGISYS",0,1,"C");	$line_no++;				
				
				$pdf->SetFont('Arial','B',10);				
				$pdf->Cell(0,7,"ATTENDANCE STATUS: {$rept_date}",0,1,"C");	$line_no++;					
				$pdf->Cell(0,7,"[{$header_dept_name}]",0,1,"C");	$line_no++;											
				
				$pdf->SetFont('Arial','B',9);									
				
				$x = $pdf->GetX();	$y = $pdf->GetY();		
				$pdf->MultiCell(10,7,"Sl. No.",1,"C");			

				$pdf->SetXY($x + 10, $y);	
				$pdf->MultiCell(15,7,"Empl. Code",1,"C");			

				$pdf->SetXY($x + 25, $y);	
				$pdf->MultiCell(50,14,"Employee Name",1,"C");			

				$pdf->SetXY($x + 75, $y);	
				$pdf->MultiCell(25,14,"Status",1,"C");			
								
				$pdf->SetXY($x + 100, $y);	
				$pdf->MultiCell(35,7,"Log In",1,"C");			

				$pdf->SetXY($x + 100, $y + 7);	
				$pdf->MultiCell(15,7,"Time",1,"C");			

				$pdf->SetXY($x + 115, $y + 7);	
				$pdf->MultiCell(20,7,"Remarks",1,"C");			

				$pdf->SetXY($x + 135, $y);	
				$pdf->MultiCell(35,7,"Log Out",1,"C");			

				$pdf->SetXY($x + 135, $y + 7);	
				$pdf->MultiCell(15,7,"Time",1,"C");			

				$pdf->SetXY($x + 150, $y + 7);	
				$pdf->MultiCell(20,7,"Remarks",1,"C");			

				$pdf->SetXY($x + 170, $y);	
				$pdf->MultiCell(15,7,"Work Hours",1,"C");			
				
				$line_no++;				
			}
			$empl_code=$row['femplcode'];
			$pdf->SetFont('Arial','',9);				
			$pdf->Cell(10,7,"{$i}",1,0,"C");					
			$pdf->Cell(15,7,"{$row['femplcode']}",1,0,"C");											
			$pdf->Cell(50,7,"{$row['femplname']}",1,0,"L");														
			$pdf->Cell(25,7,"{$row['fstatdesc']}",1,0,"C");																										
			$attn_stat=strtolower($row['fattnstat']);
			if($attn_stat=="ab"||$attn_stat=="cl"||$attn_stat=="hd")
			{
				$pdf->Cell(15,7,"-",1,0,"C");														
				$pdf->Cell(20,7,"-",1,0,"C");																										
				$pdf->Cell(15,7,"-",1,0,"C");														
				$pdf->Cell(20,7,"-",1,0,"C");																										
				$pdf->Cell(15,7,"-",1,0,"C");																														
			}
			else
			{
				$logi_tim1 = $row['flogitime'];
				$logi_tim2 = $row['llogitime'];
				$pdf->Cell(15,7,"{$logi_tim1}",1,0,"C");														
				if($logi_tim1>$logi_tim2) 
				{
					$logi_diff = get_time_diff($logi_tim2, $logi_tim1);
					$pdf->Cell(20,7,"{$logi_diff} delay",1,0,"C");
				}
				elseif($logi_tim1<$logi_tim2) 
				{	
					$logi_diff = get_time_diff($logi_tim1, $logi_tim2);
					$pdf->Cell(20,7,"{$logi_diff} early",1,0,"C");
				}				
				else
				{	
					$pdf->Cell(20,7,"-",1,0,"C");
				}								

				$logo_tim1 = $row['flogotime'];
				$logo_tim2 = $row['llogotime'];
				$logo_diff = get_time_diff($logo_tim1, $logo_tim2);
				if($logo_tim1>$logo_tim2) 
				{
					$pdf->Cell(15,7,"{$logo_tim1}",1,0,"C");														
					$pdf->Cell(20,7,"{$logo_diff} delay",1,0,"C");
				}
				elseif($logo_tim1=="00:00:00") 
				{	
					$pdf->Cell(15,7,"-",1,0,"C");														
					$pdf->Cell(20,7,"Pending",1,0,"C");
				}				
				elseif($logo_tim1<$logo_tim2) 
				{	
					$pdf->Cell(15,7,"{$logo_tim1}",1,0,"C");														
					$pdf->Cell(20,7,"{$logo_diff} early",1,0,"C");
				}				
				else
				{	
					$pdf->Cell(15,7,"-",1,0,"C");
					$pdf->Cell(20,7,"-",1,0,"C");					
				}								
			
				$work_time = get_time_diff($logi_tim1, $logo_tim1);				
				if($logo_tim1=="00:00:00") 
				{
					$pdf->Cell(15,7,"-",1,0,"C");																											
				}
				else
				{
					$pdf->Cell(15,7,"{$work_time}",1,0,"C");																															
				}
			}
			$i++;
			$pdf->ln();$line_no++;				
		}		
	}

	$resp_file="reports/status_report.pdf";
	$pdf->output($resp_file,'F');	

	$mail_main="raghu.s@logisys.org";
	$mail_copy="mahesh.r@logisys.org";
	$mail_subj="Attendance Report: ".date('d-m-Y');
	$mail_text="Attendance Report".date('d-m-Y');
	$mail_file=$resp_file;

	include("api_sendmail.php");
 	$resp_stat=send_mail($mail_main,$mail_copy,$mail_subj,$mail_text,$mail_file);	
	echo json_encode(array("mesg"=>$resp_mesg, "stat"=>$resp_stat, "file"=>$resp_file));		
?>