我的计时系统有问题。好吧,在我的系统中,您可以看到员工的时间日志(例如日期、签到、休息、闯入、签出)。从生物指标机器上传 csv 文件后,我使用日期作为获取个人记录的主要来源。现在困扰我的是,当我刚刚意识到一些员工在一(1)个工作日内进行双班轮班时为时已晚。例如:
在 2013 年 4 月 5 日(月/日/年)日期,员工于上午 1:00 签入并于上午 10:00 签出。在同一日期晚上 9:00,该员工重新登录了他的双班制,因此该员工的退房日期和时间将是 2013 年 4 月 6 日上午 6:00。
现在在我的系统记录中的输出只是基于日期。所以在 2013 年 4 月 6 日的日期,不会有签到,因为它记录在 04/05/13 的日期,我在系统中所做的是,如果没有签到,它也不会显示其余的的记录。所以它会是这样的:
| ACNo | Date | CheckIn | Breakout | Breakin | Checkout
| | | | | |
| 1220 | 4/05/2013 | 01:00:18 AM | 5:46:58 AM | 6:22:41 AM | 9:42:19 AM
| 1220 | 4/05/2013 | 09:00:00 PM | | |
| 1220 | 4/06/2013 | | 1:00:00 AM | 2:00:00 AM | 6:00:00 AM
this 3rd row will not appear in the system because of the condition that if there will be no
check-in it will not show the rest of the record.
上表的接续是员工迟到、加班、加班、不足时间的计算(按行计算)。所以如果总是有一个员工要双班工作,我看不到它当天的总记录。我现在要做的是基于 Check-In 和 Check-out 的状态。顺便说一下,我的数据库表是 CheckIn、CheckOut 和 Breaks。
入住:
| CIn_ACNo | CIn_Date | CIn_Time |
| | | |
| 1220 | 4/05/2013 | 01:00:18 AM |
| 1220 | 4/05/2013 | 09:00:00 PM |
查看:
| COut_ACNo | COut_Date | COut_Time |
| | | |
| 1220 | 4/05/2013 | 09:42:19 AM |
| 1220 | 4/06/2013 | 06:00:00 AM |
这是我用来获取结果的代码:
$sql1 = mysql_query("Select * from checkin where CIn_ACNo = '$id' order by CIn_Date asc");
$stop1 = mysql_num_rows($sql1);
if(!$stop1){
$checkin = null;
}
while($row1 = mysql_fetch_array($sql1)) {
$date1 = $row1['CIn_Date'];
$checkin = $row1['CIn_Time'];
//temporary change schedule
$tempsched = mysql_query("SELECT * FROM tempschedchange where TempACNo = '$ID' AND TempDate = '$date1'");
$stop9 = mysql_num_rows($tempsched);
if(!$stop9){
$tempin = null; $tempout = null; $tempdate = null;
}
while($row9 = mysql_fetch_array($tempsched)){
$tempname = $row9['TempName'];
$tempacno = $row9['TempACNo'];
$tempdate = $row9['TempDate'];
$tempin = $row9['TempSchedIn'];
$tempout = $row9['TempSchedOut'];
}
//break out count
$sql2 = mysql_query("Select * from breaks where break_date = '$date1' AND break_ex = 'Out' AND break_acno = '$id' order by break_date asc");
$stop2 = mysql_num_rows($sql2);
if(!$stop2){
$breakoutt = "-";
}
while($row2 = mysql_fetch_array($sql2)) {
$breakoutt = $stop2;
$breakout = $row2['break_time'];
}
//break in count
$sql3 = mysql_query("Select * from breaks where break_date = '$date1' AND break_ex = 'Out Back' AND break_acno = '$id' order by break_date asc");
$stop3 = mysql_num_rows($sql3);
if(!$stop3){
$breakinn = "-";
$OBB="-";
}
while($row3 = mysql_fetch_array($sql3)) {
$breakinn = $stop3 + $stop2;
$breakin = $row3['break_time'];
if($breakinn > 2) {
if($breakinn % 2){
$breakinnn = $breakinn - 1;
$breakinn = $breakinnn / 2;
}else{
$breakinn = $breakinn / 2;
}
}
elseif($breakinn <= 2) {
$breakinn = 1;
}
}
//checkout
$sql4 = mysql_query("Select * from checkout where COut_Date = '$date1' AND COut_ACNo = '$id'");
$stop4 = mysql_num_rows($sql4);
if(!$stop4){
$checkout = "-";
}
while($row4 = mysql_fetch_array($sql4)) {
$date4 = $row4['COut_Date'];
$checkout = $row4['COut_Time'];
}
//BREAKS!!!!!!!!!!!!!!!!!!!important
//break out 1
$sql5 = mysql_query("Select * from breaks where break_date = '$date1' AND break_acno = '$id' AND break_ex = 'Out' order by break_date desc limit 1");
$stop5 = mysql_num_rows($sql5);
if(!$stop5) {
$breakout1 = 0;
}
while($row5 = mysql_fetch_array($sql5)) {
$breakout1 = $row5['break_time'];
if($breakout == $breakout1){
$breakout1 = 0;
}
}
//break in 1
$sql6 = mysql_query("Select * from breaks where break_date = '$date1' AND break_acno = '$id' AND break_ex = 'Out Back' order by break_date desc limit 1");
$stop6 = mysql_num_rows($sql6);
if(!$stop6) {
$breakin1 = 0;
}
while($row6 = mysql_fetch_array($sql6)) {
$date6 = $row6['break_date'];
$breakin1 = $row6['break_time'];
if($breakin == $breakin1){
$breakin1 = 0;
}
}
//break out 2
$sql7 = mysql_query("Select * from breaks where break_date = '$date1' AND break_acno = '$id' AND break_ex = 'Out' order by break_date desc limit 2");
$stop7 = mysql_num_rows($sql7);
if(!$stop7) {
$breakout2 = 0;
}
while($row7 = mysql_fetch_array($sql7)) {
$breakout2 = $row7['break_time'];
if($breakout1 == $breakout2){
$breakout2 = 0;
}
}
//break in 2
$sql8 = mysql_query("Select * from breaks where break_date = '$date1' AND break_acno = '$id' AND break_ex = 'Out Back' order by break_date desc limit 2");
$stop8 = mysql_num_rows($sql8);
if(!$stop8) {
$breakin2 = 0;
}
while($row8 = mysql_fetch_array($sql8)) {
$date6 = $row8['break_date'];
$breakin2 = $row8['break_time'];
if($breakin1 == $breakin2){
$breakin2 = 0;
}
}
我需要一些帮助来了解如何创建一个条件来获取签入和结帐的值,而无需仅参考日期。相反,它将基于员工的签入和签出。就像,当有一个签入记录时,它将自动与结帐配对。我不擅长在 MySQL 中创建条件,例如使用 JOINS 以及您在我的代码中可以注意到的简单查询。所以拜托,知道怎么做吗?请帮帮我!非常感谢您阅读这篇很长的解释。任何帮助深表感谢!