【发布时间】:2019-04-19 11:14:30
【问题描述】:
在选择月份和年份后,我有一个月份和年份的列,它将计算员工当前的总天数,减去员工在该月的休假。
这是我的控制器文件代码
public function employeeAttendance(Request $request)
{
$employeeName = User::all();
$employeeLeave = LeaveManagement::all();
$countMonth = $request->get('month');
$countYear = $request->get('year');
function countDays($year, $month, $ignore)
{
$count = 0;
$counter = mktime(0, 0, 0, $month, 1, $year);
while (date("n", $counter) == $month) {
if (in_array(date("w", $counter), $ignore) == false)
{
$count++;
}
$counter = strtotime("+1 day", $counter);
}
return $count;
}
$totalWorkingDays = countDays($countYear, $countMonth, array(0, 6));
return view('pages.attendance', compact('employeeName', 'totalWorkingDays', 'employeeLeave', 'countMonth', 'countYear'));
}
这是我的查看文件代码
<div class="col-md-5 align-self-center">
<h4 class="text-themecolor">{{__('Employee Attendance')}}</h4>
</div>
</div>
<div class="card">
<div class="card-body">
<form action="{{ route('employee_attendance') }}" method="GET">
<select class="custom-select col-md-2" name="month">
<option value="">Select Month</option>
<option value="01">January</option>
<option value="02">February</option>
<option value="03">March</option>
<option value="04">April</option>
<option value="05">May</option>
<option value="06">June</option>
<option value="07">July</option>
<option value="08">August</option>
<option value="09">September</option>
<option value="10">October</option>
<option value="11">November</option>
<option value="12">December</option>
</select>
<select class="custom-select col-md-2" name="year">
<option value="">Select Year</option>
<?php
for ($year = 2000; $year <= 2050; $year++)
{
$selected = (isset($getYear) && $getYear == $year) ? 'selected' : '';
echo "<option value=$year $selected>$year</option>";
}
?>
</select>
<button class="btn btn-info" type="submit"><i class="fa fa-search "></i></button>
<span style="float:right" class = "btn btn-info" disabled>Total Working Days : {{ $totalWorkingDays }} </span>
</form>
<div class="table-responsive m-t-40">
<table class="table table-bordered table-striped ">
<thead>
<tr>
<th>Employee Name</th>
<th>Present Day</th>
<th>Casual Leave</th>
<th>Medical Leave</th>
</tr>
</thead>
<tbody>
@foreach ($employeeName as $empName)
@php
$casualCount = $medicalCount = 0;
@endphp
@foreach($employeeLeave as $empleave)
@if($empName['personal_detail']['first_name'] == $empleave->name)
@if($empleave->type == 'casual')
@php $casualCount++; @endphp
@endif
@if($empleave->type == 'medical')
@php $medicalCount++; @endphp
@endif
@endif
@endforeach
@if($empName['username'] != 'admin')
<tr>
<td>
{{$empName['personal_detail']['first_name']}}
</td>
<td>
@if($totalWorkingDays == 0)
{{ $totalWorkingDays }}
@else
@php
$totalLeave = $casualCount + $medicalCount;
$presentDay = $totalWorkingDays - $totalLeave;
@endphp
{{ $presentDay }}
@endif
</td>
<td>
@if( $totalWorkingDays == 0 )
{{ $totalWorkingDays }}
@elseif( $countMonth == date('m', strtotime($empleave->start)) && $countYear == date('Y', strtotime($empleave->start)))
{{ $casualCount }}
@endif
</td>
<td>
@if( $totalWorkingDays == 0 )
{{ $totalWorkingDays }}
@elseif( $countMonth == date('m', strtotime($empleave->start)) && $countYear == date('Y', strtotime($empleave->start)))
{{ $medicalCount }}
@endif
</td>
</tr>
@endif
@endforeach
</tbody>
</table>
</div>
</div>
</div>
</div>
</div>
我希望如果我选择 2019 年 3 月,它将为我提供所有员工在该月的当前日期,如果他们在该月休了任何病假或临时休假,那么它将在当前列中减去
p>【问题讨论】: