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',
|
||||
]
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\HRM\Database\Seeders;
|
||||
|
||||
use Illuminate\Database\Seeder;
|
||||
use Modules\HRM\Models\Department;
|
||||
|
||||
class DepartmentsTableSeeder extends Seeder
|
||||
{
|
||||
/**
|
||||
* Run the database seeds.
|
||||
*/
|
||||
public function run(): void
|
||||
{
|
||||
$departments = [
|
||||
['restaurant_id' => 1, 'name' => 'Human Resources', 'description' => 'Manage users and HR processes'],
|
||||
['restaurant_id' => 1, 'name' => 'Finance', 'description' => 'Handle accounting and payroll'],
|
||||
['restaurant_id' => 1, 'name' => 'Operations', 'description' => 'Manage daily restaurant operations'],
|
||||
['restaurant_id' => 1, 'name' => 'Kitchen', 'description' => 'Manage cooking and kitchen staff'],
|
||||
['restaurant_id' => 1, 'name' => 'Service', 'description' => 'Waiters and customer service'],
|
||||
];
|
||||
|
||||
foreach ($departments as $dept) {
|
||||
Department::updateOrCreate(['name' => $dept['name']], $dept);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\HRM\Database\Seeders;
|
||||
|
||||
use Illuminate\Database\Seeder;
|
||||
use Modules\HRM\Models\Designation;
|
||||
|
||||
class DesignationsTableSeeder extends Seeder
|
||||
{
|
||||
/**
|
||||
* Run the database seeds.
|
||||
*/
|
||||
public function run(): void
|
||||
{
|
||||
$designations = [
|
||||
['restaurant_id' => 1, 'title' => 'Manager'],
|
||||
['restaurant_id' => 1, 'title' => 'Chef'],
|
||||
['restaurant_id' => 1, 'title' => 'Waiter'],
|
||||
['restaurant_id' => 1, 'title' => 'Accountant'],
|
||||
['restaurant_id' => 1, 'title' => 'HR Executive'],
|
||||
];
|
||||
|
||||
foreach ($designations as $designation) {
|
||||
Designation::updateOrCreate(['title' => $designation['title']], $designation);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\HRM\Database\Seeders;
|
||||
|
||||
use Illuminate\Database\Seeder;
|
||||
use Modules\HRM\Models\Employee;
|
||||
use Modules\HRM\Models\EmployeeSalary;
|
||||
|
||||
class EmployeeSalariesTableSeeder extends Seeder
|
||||
{
|
||||
/**
|
||||
* Run the database seeds.
|
||||
*/
|
||||
public function run(): void
|
||||
{
|
||||
$users = Employee::all();
|
||||
foreach ($users as $employee) {
|
||||
$basic = rand(20000, 50000);
|
||||
$allowances = rand(1000, 5000);
|
||||
$deductions = rand(500, 2000);
|
||||
$overtimeHours = rand(0, 20);
|
||||
$overtimeRate = rand(200, 500);
|
||||
$bonus = rand(0, 5000);
|
||||
$netSalary = $basic + $allowances + ($overtimeHours * $overtimeRate) + $bonus - $deductions;
|
||||
|
||||
EmployeeSalary::create([
|
||||
'restaurant_id' => $employee->restaurant_id,
|
||||
'employee_id' => $employee->id,
|
||||
'salary_month' => now()->format('Y-m'),
|
||||
'basic_salary' => $basic,
|
||||
'allowances' => $allowances,
|
||||
'deductions' => $deductions,
|
||||
'overtime_hours' => $overtimeHours,
|
||||
'overtime_rate' => $overtimeRate,
|
||||
'bonus' => $bonus,
|
||||
'net_salary' => $netSalary,
|
||||
'payment_date' => now(),
|
||||
'remarks' => 'Auto-generated seeder',
|
||||
'status' => 'paid',
|
||||
]);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\HRM\Database\Seeders;
|
||||
|
||||
use Illuminate\Database\Seeder;
|
||||
use Modules\Authentication\Models\User;
|
||||
use Modules\HRM\Models\EmployeeShiftAssignment;
|
||||
use Modules\HRM\Models\Shift;
|
||||
|
||||
class EmployeeShiftAssignmentSeeder extends Seeder
|
||||
{
|
||||
/**
|
||||
* Run the database seeds.
|
||||
*/
|
||||
public function run(): void
|
||||
{
|
||||
$employees = User::all();
|
||||
$shifts = Shift::all();
|
||||
|
||||
foreach ($employees as $employee) {
|
||||
EmployeeShiftAssignment::updateOrCreate(
|
||||
[
|
||||
'restaurant_id' => 1,
|
||||
'employee_id' => $employee->id,
|
||||
],
|
||||
[
|
||||
'shift_id' => $shifts->random()->id,
|
||||
'status' => 1,
|
||||
]
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\HRM\Database\Seeders;
|
||||
|
||||
use Illuminate\Database\Seeder;
|
||||
use Modules\HRM\Models\Department;
|
||||
use Modules\HRM\Models\Designation;
|
||||
use Modules\HRM\Models\Employee;
|
||||
use Modules\HRM\Models\SalaryType;
|
||||
|
||||
class EmployeesTableSeeder extends Seeder
|
||||
{
|
||||
/**
|
||||
* Run the database seeds.
|
||||
*/
|
||||
public function run(): void
|
||||
{
|
||||
$departments = Department::pluck('id')->toArray();
|
||||
$designations = Designation::pluck('id')->toArray();
|
||||
$salaryTypes = SalaryType::pluck('id')->toArray();
|
||||
|
||||
if (empty($departments) || empty($designations) || empty($salaryTypes)) {
|
||||
$this->command->info('Please seed Departments, Designations, and SalaryTypes first.');
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
Employee::factory(10)->create()->each(function ($employee) use ($departments, $designations, $salaryTypes) {
|
||||
$employee->department_id = $departments[array_rand($departments)];
|
||||
$employee->designation_id = $designations[array_rand($designations)];
|
||||
$employee->salary_type_id = $salaryTypes[array_rand($salaryTypes)];
|
||||
$employee->save();
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\HRM\Database\Seeders;
|
||||
|
||||
use Illuminate\Database\Seeder;
|
||||
|
||||
class HRMDatabaseSeeder extends Seeder
|
||||
{
|
||||
/**
|
||||
* Run the database seeds.
|
||||
*/
|
||||
public function run(): void
|
||||
{
|
||||
$this->call([
|
||||
DepartmentsTableSeeder::class,
|
||||
DesignationsTableSeeder::class,
|
||||
EmployeesTableSeeder::class,
|
||||
ShiftsTableSeeder::class,
|
||||
EmployeeShiftAssignmentSeeder::class,
|
||||
LeaveTypesTableSeeder::class,
|
||||
WeeklyHolidaysTableSeeder::class,
|
||||
SalaryTypesTableSeeder::class,
|
||||
SalarySetupsTableSeeder::class,
|
||||
EmployeeSalariesTableSeeder::class,
|
||||
AttendancesTableSeeder::class,
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\HRM\Database\Seeders;
|
||||
|
||||
use Illuminate\Database\Seeder;
|
||||
use Modules\HRM\Models\LeaveType;
|
||||
|
||||
class LeaveTypesTableSeeder extends Seeder
|
||||
{
|
||||
/**
|
||||
* Run the database seeds.
|
||||
*/
|
||||
public function run(): void
|
||||
{
|
||||
$types = ['Casual Leave', 'Sick Leave', 'Maternity Leave', 'Paternity Leave', 'Earned Leave'];
|
||||
|
||||
foreach ($types as $type) {
|
||||
LeaveType::updateOrCreate(['name' => $type, 'restaurant_id' => 1]);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\HRM\Database\Seeders;
|
||||
|
||||
use Illuminate\Database\Seeder;
|
||||
use Modules\HRM\Models\Employee;
|
||||
use Modules\HRM\Models\SalarySetup;
|
||||
use Modules\HRM\Models\SalaryType;
|
||||
|
||||
class SalarySetupsTableSeeder extends Seeder
|
||||
{
|
||||
/**
|
||||
* Run the database seeds.
|
||||
*/
|
||||
public function run(): void
|
||||
{
|
||||
$restaurantId = 1;
|
||||
|
||||
$users = Employee::where('restaurant_id', $restaurantId)->pluck('id')->toArray();
|
||||
$salaryTypes = SalaryType::where('restaurant_id', $restaurantId)->pluck('id')->toArray();
|
||||
if (empty($users) || empty($salaryTypes)) {
|
||||
$this->command->info('Please seed Employees and SalaryTypes first.');
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
foreach ($users as $employeeId) {
|
||||
foreach ($salaryTypes as $typeId) {
|
||||
SalarySetup::updateOrCreate(
|
||||
[
|
||||
'employee_id' => $employeeId,
|
||||
'salary_type_id' => $typeId,
|
||||
'restaurant_id' => $restaurantId,
|
||||
],
|
||||
[
|
||||
'amount' => rand(1000, 5000),
|
||||
'calculation_type' => 'fixed',
|
||||
'status' => 1,
|
||||
]
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
$this->command->info('Salary setups seeded successfully.');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\HRM\Database\Seeders;
|
||||
|
||||
use Illuminate\Database\Seeder;
|
||||
use Modules\HRM\Models\SalaryType;
|
||||
|
||||
class SalaryTypesTableSeeder extends Seeder
|
||||
{
|
||||
/**
|
||||
* Run the database seeds.
|
||||
*/
|
||||
public function run(): void
|
||||
{
|
||||
$types = ['Monthly', 'Weekly', 'Daily'];
|
||||
|
||||
foreach ($types as $type) {
|
||||
SalaryType::updateOrCreate(['name' => $type, 'restaurant_id' => 1]);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\HRM\Database\Seeders;
|
||||
|
||||
use Illuminate\Database\Seeder;
|
||||
use Modules\HRM\Models\Shift;
|
||||
|
||||
class ShiftsTableSeeder extends Seeder
|
||||
{
|
||||
/**
|
||||
* Run the database seeds.
|
||||
*/
|
||||
public function run(): void
|
||||
{
|
||||
$shifts = [
|
||||
[
|
||||
'restaurant_id' => 1,
|
||||
'name' => 'Morning',
|
||||
'start_time' => '08:00:00',
|
||||
'end_time' => '16:00:00',
|
||||
'description' => 'Morning shift from 8 AM to 4 PM',
|
||||
],
|
||||
[
|
||||
'restaurant_id' => 1,
|
||||
'name' => 'Evening',
|
||||
'start_time' => '16:00:00',
|
||||
'end_time' => '00:00:00',
|
||||
'description' => 'Evening shift from 4 PM to 12 AM',
|
||||
],
|
||||
[
|
||||
'restaurant_id' => 1,
|
||||
'name' => 'Night',
|
||||
'start_time' => '00:00:00',
|
||||
'end_time' => '08:00:00',
|
||||
'description' => 'Night shift from 12 AM to 8 AM',
|
||||
],
|
||||
];
|
||||
|
||||
foreach ($shifts as $shift) {
|
||||
Shift::create($shift);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\HRM\Database\Seeders;
|
||||
|
||||
use Illuminate\Database\Seeder;
|
||||
use Modules\HRM\Models\WeeklyHoliday;
|
||||
|
||||
class WeeklyHolidaysTableSeeder extends Seeder
|
||||
{
|
||||
/**
|
||||
* Run the database seeds.
|
||||
*/
|
||||
public function run(): void
|
||||
{
|
||||
$days = ['Friday'];
|
||||
|
||||
foreach ($days as $day) {
|
||||
WeeklyHoliday::updateOrCreate(['day' => $day, 'restaurant_id' => 1]);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user