一切都成功完成,但只是坚持出勤报告工作。请帮助我
如何获取数据每月出勤报告在Laravel 5.5中
这是我的mysql查询
< - language:lang-sql - >
$data = DB::table("attendance_management")->select('attendance_management.*',
DB::raw('group_concat(attendance ORDER BY date) as atten'),
DB::raw('group_concat(date ORDER BY date) as date_att')
)->whereYear('date', '=', $year)
->whereMonth('date', '=', $month)
->groupBy('employee_name')
->orderBy('attendance_management.date', 'ASC')
->get();
这是我的Mysql表
Date client_id Name Attendance
01-05-18 34 Hitesh Leave
02-05-18 34 Hitesh Leave
03-05-18 34 Hitesh Leave
02-05-18 21 udip Full-Day
01-05-18 21 udip Full-Day
03-05-18 21 udip Leave
这是View.blade.php
@foreach($data as $data)
<tr class="odd gradeX">
<td>{{$data->shift}}</td>
<td> {{$data->employee_name}} </td>
<?php
$dateaa = explode(',', $data->date_att);
$attendance = explode(',', $data->atten);
$daysInMonth = cal_days_in_month(CAL_GREGORIAN,$month, $year);
for($i=1; $i<=$daysInMonth; $i++)
{
$db_date = $data->date;
$resultDate = sprintf('%02d', $i);
$date1 = $year.'-'.$month.'-'.$resultDate;
if($i==$db_date[2])
{
$x = 0;
foreach($attendance as $key=>$value)
{
$x++;
if($x==$key+1)
{
if($value=="Full-Day")
{
$status = "P";
?><td><?php echo $status; ?></td><?php
}
else
{
$status = "A";
?><td><?php echo $status; ?></td><?php
}
}
else
{
//echo $x;
}
}
}
else
{
//echo $i;
}
}
?>
<td> 25 </td>
</tr>
@endforeach
答案 0 :(得分:0)
通过从github https://github.com/briannesbitt/Carbon安装软件包,在laravel中使用此库。并使用此代码获取当前月份记录
func addPointsToTeam(_ teamNumber: inout Int) {
teamNumber += 1
}