migrate to gtea from bistbucket
This commit is contained in:
@@ -0,0 +1,63 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\HRM\Database\Seeders;
|
||||
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Database\Seeder;
|
||||
use Modules\HRM\Models\Attendance;
|
||||
use Modules\HRM\Models\AttendanceLog;
|
||||
use Modules\HRM\Models\Employee;
|
||||
|
||||
class AttendancesTableSeeder extends Seeder
|
||||
{
|
||||
public function run(): void
|
||||
{
|
||||
$restaurantId = 1; // default restaurant ID
|
||||
$today = Carbon::today()->toDateString();
|
||||
// Get all users
|
||||
$users = Employee::where('restaurant_id', $restaurantId)->get();
|
||||
foreach ($users as $employee) {
|
||||
// Check if attendance already exists
|
||||
$attendance = Attendance::updateOrCreate(
|
||||
[
|
||||
'employee_id' => $employee->id,
|
||||
'date' => $today,
|
||||
],
|
||||
[
|
||||
'restaurant_id' => $restaurantId,
|
||||
'first_clock_in' => '09:00:00', // first punch
|
||||
'last_clock_out' => '18:00:00', // last punch
|
||||
'hours_worked' => 9,
|
||||
'status' => 'present',
|
||||
]
|
||||
);
|
||||
|
||||
// Create attendance logs
|
||||
AttendanceLog::updateOrCreate(
|
||||
[
|
||||
'attendance_id' => $attendance->id,
|
||||
'employee_id' => $employee->id,
|
||||
'type' => 'in',
|
||||
'punch_time' => $today.' 09:00:00',
|
||||
],
|
||||
[
|
||||
'restaurant_id' => $restaurantId,
|
||||
'device_id' => 'DEVICE-1',
|
||||
]
|
||||
);
|
||||
|
||||
AttendanceLog::updateOrCreate(
|
||||
[
|
||||
'attendance_id' => $attendance->id,
|
||||
'employee_id' => $employee->id,
|
||||
'type' => 'out',
|
||||
'punch_time' => $today.' 18:00:00',
|
||||
],
|
||||
[
|
||||
'restaurant_id' => $restaurantId,
|
||||
'device_id' => 'DEVICE-1',
|
||||
]
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user