我有两张表,分别称为 work_details 和 Holy_days。
Holy_days 表包含每年每个假期的一行。work_details 包含每个员工每天的工作报告的行。
我想获得所有员工的休假报告(每年和每月)。
我想显示他们每年和每月请假多少天(带日期)
计算除周六、周日和 Holy_days 表中的日期以外的休假天数。我正在使用以下代码,但这不能正常工作..任何人请帮忙。
if ($request->isPost()) {
$sdate1 = $request->get('txt_date1','post');
$d1=explode('/', $sdate1);
$sdate= $d1['2'].'-'.$d1['0'].'-'.$d1['1'];
$edate1 = $request->get('txt_date2','post');
$d2=explode('/', $edate1);
$edate= $d2['2'].'-'.$d2['0'].'-'.$d2['1'];
$count=dates_between($emp_id,$sdate,$edate);
echo $count;
}
function dates_between($emp_id,$start_date, $end_date = false)
{
if ( !$end_date )
{
$end_date = date("Y-m-d");
}
$test_date = $start_date;
$day_incrementer = 1;
$count_leaves=0;
$flag=0;
echo "SELECT DISTINCT date FROM `work_details` WHERE employee_id='".$emp_id."' and date between '".$start_date."' and '".$end_date."'";
$work_res = mysql_query("SELECT DISTINCT date FROM `work_details` WHERE employee_id='".$emp_id."' and date between '".$start_date."' and '".$end_date."'");
do
{
while($row=mysql_fetch_array($work_res))
{
while((date("Y-m-d",$test_date)<$row['date'])&&($flag=0))
{
if(!(date('N', strtotime(date("Y-m-d", $test_date))) >= 6))
{
echo "<tr><td align=center class=fontclass style=color:FF0000>".date("Y-m-d", $test_date)."</td></tr>";
$count_leaves++;
}
$test_date = $test_date + ($day_incrementer * 60 * 60 * 24);
}
$flag=1;
while((date("Y-m-d",$test_date)!=$row['date']))
{
if(!(date('N', strtotime(date("Y-m-d", $test_date))) >= 6))
{
echo "<tr><td align=center class=fontclass style=color:FF0000>".date("Y-m-d", $test_date)."</td></tr>";
$count_leaves++;
}
$test_date = $test_date + ($day_incrementer * 60 * 60 * 24);
}
$test_date = $test_date + ($day_incrementer * 60 * 60 * 24);
}
if(!(date('N', strtotime(date("Y-m-d", $test_date))) >= 6)&&($test_date <= $end_date))
{
echo "<tr><td align=center class=fontclass style=color:FF0000>".date("Y-m-d", $test_date)."</td></tr>";
$count_leaves++;
$test_date = $test_date + ($day_incrementer * 60 * 60 * 24);
}
}
while ( $test_date <= $end_date);
return($count_leaves);
}