first commit
This commit is contained in:
67
Modules/Attendance/app/Http/Controllers/ReportController.php
Normal file
67
Modules/Attendance/app/Http/Controllers/ReportController.php
Normal file
@ -0,0 +1,67 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\Attendance\Http\Controllers;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use Carbon\Carbon;
|
||||
use Modules\Attendance\Models\Attendance;
|
||||
use Modules\Attendance\Repositories\AttendanceInterface;
|
||||
use Modules\Attendance\Repositories\AttendanceRepository;
|
||||
use Modules\Employee\Repositories\EmployeeInterface;
|
||||
use Modules\Leave\Models\Leave;
|
||||
|
||||
class ReportController extends Controller
|
||||
{
|
||||
private $attendanceRepository;
|
||||
private $employeeRepository;
|
||||
|
||||
public function __construct(
|
||||
AttendanceInterface $attendanceRepository,
|
||||
EmployeeInterface $employeeRepository) {
|
||||
$this->attendanceRepository = $attendanceRepository;
|
||||
$this->employeeRepository = $employeeRepository;
|
||||
|
||||
}
|
||||
|
||||
public function monthly()
|
||||
{
|
||||
$data['title'] = 'Employee Attendance Lists';
|
||||
$firstDayOfMonth = Carbon::createFromDate(date('Y'), date('m'), 1)->startOfMonth();
|
||||
$lastDayOfMonth = Carbon::createFromDate(date('Y'), date('m'), 1)->endOfMonth();
|
||||
|
||||
for ($day = $firstDayOfMonth; $day <= $lastDayOfMonth; $day->addDay()) {
|
||||
$data['dayLists'][] = $day->format('Y-m-d');
|
||||
}
|
||||
$data['employees'] = $this->employeeRepository->findAll()
|
||||
->transform(function ($employee) use ($data) {
|
||||
$attendances = Attendance::
|
||||
where('employee_id', $employee->id)
|
||||
->whereIn('date', $data['dayLists'])
|
||||
->select('clock_in_time', 'clock_out_time', 'date')
|
||||
->get()
|
||||
// ->groupBy('date')
|
||||
->mapWithKeys(function ($atd) {
|
||||
return [$atd['date'] => 'P'];
|
||||
});
|
||||
|
||||
$leave = Leave::
|
||||
where('employee_id', $employee->id)
|
||||
->whereIn('start_date', $data['dayLists'])
|
||||
->whereStatus(2)
|
||||
->get()
|
||||
->mapWithKeys(function ($atd) {
|
||||
return [$atd['start_date'] => 'L'];
|
||||
});
|
||||
|
||||
$final = $attendances->push($leave);
|
||||
$attendanceArray = [];
|
||||
foreach ($data['dayLists'] as $date) {
|
||||
$attendanceArray[$date] = array_key_exists($date, $final->toArray()) ? $final[$date] : '';
|
||||
}
|
||||
$employee->dates = $attendanceArray;
|
||||
return $employee;
|
||||
});
|
||||
return view('attendance::report.monthly', $data);
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user