query($sql); while($rowg = $resultg->fetch_assoc()) { $cmp=$rowg['comp_id']; $sql="select a.*,spell1 from ( select employeeid ,tdate,mntime,mxtime,eb_no,dept_id,desg_id,worker_name,last_name from ( SELECT employeeid,SUBSTR(transaction_time,1,10) tdate,MIN(transaction_time) mntime,MAX(transaction_time) mxtime from tbl_alm_attendance_log taal WHERE SUBSTR(transaction_time,1,10)>'2023-01-26' and SUBSTR(transaction_time,1,10)<='2023-02-26' and reader_id in (1,2) and pending=1 group by employeeid,SUBSTR(transaction_time,1,10) order by employeeid ) a,worker_master b where a.employeeid=b.eb_id and b.company_id=".$cmp." order by employeeid ,tdate ) a, ( select a.eb_id,spell1 from ( select eb_id,max(emp_shift_map_id) mxid from employee_shift_mapping where active_status=1 group by eb_id ) a,employee_shift_mapping b where mxid=emp_shift_map_id order by a.eb_id ) b where employeeid =eb_id order by employeeid ,tdate"; echo $sql; $resulta = $connect->query($sql); while($rowa = $resulta->fetch_assoc()) { echo $rowa['eb_no'].$rowa['tdate'] ; $entime=$rowa['mntime']; $extime=$rowa['mxtime']; $extm=""; $fnd="N"; if ($entime<>$extime) { $extm=$rowa['mxtime']; $fnd="Y"; } if ($fnd<>'N') { $sql1=" insert into daily_attendance (attendance_date,attendance_mark,attendance_source,attendance_type,company_id,device_id,eb_code, eb_id,eb_no,entry_time,exit_time,is_active,remarks,spell,spell_hours,status_id,worked_department_id,worked_designation_id,working_hours) values ('".$rowa['tdate']."','HD','B','R',".$cmp.",4,'".$rowa['eb_no']."',".$rowa['employeeid'].",'".$rowa['eb_no']."','".$entime."','".$extm."',1, 'Biometeric','".$rowa['spell1']."',8,1,".$rowa['dept_id'].",".$rowa['desg_id'].",8)"; } else{ $sql1=" insert into daily_attendance (attendance_date,attendance_mark,attendance_source,attendance_type,company_id,device_id,eb_code, eb_id,eb_no,entry_time,exit_time,is_active,remarks,spell,spell_hours,status_id,worked_department_id,worked_designation_id,working_hours) values ('".$rowa['tdate']."','HD','B','R',".$cmp.",4,'".$rowa['eb_no']."',".$rowa['employeeid'].",'".$rowa['eb_no']."','".$entime."',NULL,1, 'Biometeric','".$rowa['spell1']."',8,1,".$rowa['dept_id'].",".$rowa['desg_id'].",8)"; } echo $sql1; if (mysqli_query($connect, $sql1)) { echo "New record created successfully"; //} else { // echo "Error: " . $sql . "
" . mysqli_error($conn); } } } ?>