update addon HRM
Some checks failed
Some checks failed
This commit is contained in:
@@ -0,0 +1,66 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\HrmAddon\App\Http\Controllers\Api;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Carbon;
|
||||
use Modules\HrmAddon\App\Models\Attendance;
|
||||
|
||||
class AttendanceReportController extends Controller
|
||||
{
|
||||
public function index(Request $request)
|
||||
{
|
||||
$data = Attendance::with(['employee:id,name', 'shift:id,name'])
|
||||
->where('business_id', auth()->user()->business_id)
|
||||
->when($request->employee_id, function ($query) use ($request) {
|
||||
$query->where('employee_id', $request->employee_id);
|
||||
})
|
||||
->when($request->duration, function ($query) use ($request) {
|
||||
$today = Carbon::today();
|
||||
|
||||
if ($request->duration === 'today') {
|
||||
$query->whereDate('date', $today);
|
||||
} elseif ($request->duration === 'yesterday') {
|
||||
$query->whereDate('date', Carbon::yesterday());
|
||||
} elseif ($request->duration === 'last_seven_days') {
|
||||
$startDate = Carbon::now()->subDays(7)->format('Y-m-d');
|
||||
$endDate = Carbon::now()->format('Y-m-d');
|
||||
$query->whereDate('date', '>=', $startDate)
|
||||
->whereDate('date', '<=', $endDate);
|
||||
} elseif ($request->duration === 'last_thirty_days') {
|
||||
$startDate = Carbon::now()->subDays(30)->format('Y-m-d');
|
||||
$endDate = Carbon::now()->format('Y-m-d');
|
||||
$query->whereDate('date', '>=', $startDate)
|
||||
->whereDate('date', '<=', $endDate);
|
||||
} elseif ($request->duration === 'current_month') {
|
||||
$startDate = Carbon::now()->startOfMonth()->format('Y-m-d');
|
||||
$endDate = Carbon::now()->endOfMonth()->format('Y-m-d');
|
||||
$query->whereDate('date', '>=', $startDate)
|
||||
->whereDate('date', '<=', $endDate);
|
||||
} elseif ($request->duration === 'last_month') {
|
||||
$startDate = Carbon::now()->subMonth()->startOfMonth()->format('Y-m-d');
|
||||
$endDate = Carbon::now()->subMonth()->endOfMonth()->format('Y-m-d');
|
||||
$query->whereDate('date', '>=', $startDate)
|
||||
->whereDate('date', '<=', $endDate);
|
||||
} elseif ($request->duration === 'current_year') {
|
||||
$startDate = Carbon::now()->startOfYear()->format('Y-m-d');
|
||||
$endDate = Carbon::now()->endOfYear()->format('Y-m-d');
|
||||
$query->whereDate('date', '>=', $startDate)
|
||||
->whereDate('date', '<=', $endDate);
|
||||
} elseif ($request->duration === 'custom_date' && $request->from_date && $request->to_date) {
|
||||
$startDate = Carbon::parse($request->from_date)->format('Y-m-d');
|
||||
$endDate = Carbon::parse($request->to_date)->format('Y-m-d');
|
||||
$query->whereDate('date', '>=', $startDate)
|
||||
->whereDate('date', '<=', $endDate);
|
||||
}
|
||||
})
|
||||
->latest()
|
||||
->get();
|
||||
|
||||
return response()->json([
|
||||
'message' => __('Data fetched successfully.'),
|
||||
'data' => $data,
|
||||
]);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user