<?php
echo <<<EOF
<html><title>月度考勤明细表</title>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<style type="text/css">
<!--
Body {
Border-Top-Width: 0px;
Padding-Right: 0px;
Padding-Left: 0px;
Border-Left-Width: 0px;
Border-Bottom-Width: 0px;
Padding-Bottom: 0px;
Margin: 0px;
Color: buttontext;
Padding-TOP: 0px;
Border-Right-Width: 0px;
Line-Height: 12px;
Font-Family: "Arial", "宋体"
}
Table{
Word-Break:break-all;
Border-Collapse: collapse;
}
Td {
Font-Size: 10px;
}
A {
Color: #0066CC;
Text-Decoration: none;
}
A:Hover {
Color: #0000FF;
Text-Decoration: none;
}
.Hidden
{
Display: none;
}
-->
</style>
</head>
<center><p><br>
<h2><font color=red>
月考勤明细表</font></h2>
EOF;
$serverName = "192.168.0.246";
$connectionInfo = array( "Database"=>"kaoqin_ok", "UID"=>"kaoqincq", "PWD"=>"NF6752KlybY1o4xN");
$conn = sqlsrv_connect( $serverName, $connectionInfo );
if( $conn === false ) {
die( print_r( sqlsrv_errors(), true));
}
$i=date('j',strtotime(date('Y-m-01', strtotime('-1 month'))." +1 month -1 day"));
$m=date('n', strtotime('-1 month'));
echo '<table width="4130" border="1">';
echo '<tr>';
echo '<td width="50">工号</td>';
echo '<td width="40">姓名</td>';
for($a=1;$a<=$i;$a++){
echo '<td width="120">'.date("Y-$m-$a")."<br />";
$week=date('D', strtotime(date("Y-$m-$a")));
switch ($week)
{
case "Mon":
echo "星期一";
break;
case "Tue":
echo "星期二";
break;
case "Wed":
echo "星期三";
break;
case "Thu":
echo "星期四";
break;
case "Fri":
echo "星期五";
break;
case "Sat":
echo "星期六";
break;
default:
echo "星期日";
}
echo "</td>";
}
echo "</tr>";
$sql="SELECT USERID,BADGENUMBER,NAME,DEFAULTDEPTID FROM USERINFO where BADGENUMBER like ? order by USERID asc";
$params = array($_POST["fid"]);
$stmt = sqlsrv_query( $conn, $sql,$params);
while( $row = sqlsrv_fetch_array( $stmt, SQLSRV_FETCH_ASSOC) ) {
echo "<tr>";
echo "<td width='50'>".$row['BADGENUMBER']."</td>";
echo "<td width='40'>".$row['NAME']."</td>";
for($a=1;$a<=$i;$a++){
echo "<td width='120'>";
$time_a=date("Y-$m-$a")." 07:00:00";
$time_b=date("Y-$m-$a")." 08:05:00";
$sql1 = "SELECT USERID,CONVERT(varchar(19),CHECKTIME,120)as CHECKTIME FROM CHECKINOUT where USERID=? and CHECKTIME BETWEEN ? AND ? order by CHECKTIME asc";
$params1 = array($row['USERID'],$time_a,$time_b);
$stmt1 = sqlsrv_query( $conn, $sql1,$params1);
if( $stmt1 === false) {
die( print_r( sqlsrv_errors(), true) );
}
if (is_null($row1 = sqlsrv_fetch_array( $stmt1, SQLSRV_FETCH_ASSOC)))
{
echo "上午:<font color=red>null</font>"."-";
}
else {
echo "上午:".substr($row1['CHECKTIME'],-8)."-";
}
sqlsrv_free_stmt( $stmt1);
$time_a=date("Y-$m-$a")." 11:55:00";
$time_b=date("Y-$m-$a")." 12:35:00";
$sql1 = "SELECT USERID,CONVERT(varchar(19),CHECKTIME,120)as CHECKTIME FROM CHECKINOUT where USERID=? and CHECKTIME BETWEEN ? AND ? order by CHECKTIME asc";
$params1 = array($row['USERID'],$time_a,$time_b);
$stmt1 = sqlsrv_query( $conn, $sql1,$params1);
if( $stmt1 === false) {
die( print_r( sqlsrv_errors(), true) );
}
if (is_null($row1 = sqlsrv_fetch_array( $stmt1, SQLSRV_FETCH_ASSOC)))
{
echo "<font color=red>null</font>"."<br />";
}
else {
echo substr($row1['CHECKTIME'],-8)."<br />";
}
sqlsrv_free_stmt( $stmt1);
$time_a=date("Y-$m-$a")." 12:55:00";
$time_b=date("Y-$m-$a")." 13:35:00";
$sql1 = "SELECT USERID,CONVERT(varchar(19),CHECKTIME,120)as CHECKTIME FROM CHECKINOUT where USERID=? and CHECKTIME BETWEEN ? AND ? order by CHECKTIME asc";
$params1 = array($row['USERID'],$time_a,$time_b);
$stmt1 = sqlsrv_query( $conn, $sql1,$params1);
if( $stmt1 === false) {
die( print_r( sqlsrv_errors(), true) );
}
if (is_null($row1 = sqlsrv_fetch_array( $stmt1, SQLSRV_FETCH_ASSOC)))
{
echo "下午:<font color=red>null</font>"."-";
}
else {
echo "下午:".substr($row1['CHECKTIME'],-8)."-";
}
sqlsrv_free_stmt( $stmt1);
$time_a=date("Y-$m-$a")." 17:30:00";
$time_b=date("Y-$m-$a")." 17:44:59";
$sql1 = "SELECT USERID,CONVERT(varchar(19),CHECKTIME,120)as CHECKTIME FROM CHECKINOUT where USERID=? and CHECKTIME BETWEEN ? AND ? order by CHECKTIME asc";
$params1 = array($row['USERID'],$time_a,$time_b);
$stmt1 = sqlsrv_query( $conn, $sql1,$params1);
if( $stmt1 === false) {
die( print_r( sqlsrv_errors(), true) );
}
if (is_null($row1 = sqlsrv_fetch_array( $stmt1, SQLSRV_FETCH_ASSOC)))
{
echo "<font color=red>null</font>"."<br />";
}
else {
echo substr($row1['CHECKTIME'],-8)."<br />";
}
sqlsrv_free_stmt( $stmt1);
$time_a=date("Y-$m-$a")." 17:45:00";
$time_b=date("Y-$m-$a")." 18:10:00";
$sql1 = "SELECT USERID,CONVERT(varchar(19),CHECKTIME,120)as CHECKTIME FROM CHECKINOUT where USERID=? and CHECKTIME BETWEEN ? AND ? order by CHECKTIME asc";
$params1 = array($row['USERID'],$time_a,$time_b);
$stmt1 = sqlsrv_query( $conn, $sql1,$params1);
if( $stmt1 === false) {
die( print_r( sqlsrv_errors(), true) );
}
if (is_null($row1 = sqlsrv_fetch_array( $stmt1, SQLSRV_FETCH_ASSOC)))
{
echo "晚班:<font color=blue>null</font>"."-";
}
else {
echo "晚班:".substr($row1['CHECKTIME'],-8)."-";
}
sqlsrv_free_stmt( $stmt1);
$time_a=date("Y-$m-$a")." 19:00:00";
$time_b=date("Y-$m-$a")." 22:40:59";
$sql1 = "SELECT USERID,CONVERT(varchar(19),CHECKTIME,120)as CHECKTIME FROM CHECKINOUT where USERID=? and CHECKTIME BETWEEN ? AND ? order by CHECKTIME asc";
$params1 = array($row['USERID'],$time_a,$time_b);
$stmt1 = sqlsrv_query( $conn, $sql1,$params1);
if( $stmt1 === false) {
die( print_r( sqlsrv_errors(), true) );
}
if (is_null($row1 = sqlsrv_fetch_array( $stmt1, SQLSRV_FETCH_ASSOC)))
{
echo "<font color=blue>null</font>"."<br />";
}
else {
echo substr($row1['CHECKTIME'],-8)."<br />";
}
sqlsrv_free_stmt( $stmt1);
echo "</td>";
}
}
echo "</tr>";
echo "</table>";
sqlsrv_free_stmt( $stmt);
sqlsrv_close( $conn);
?>