migrate to gtea from bistbucket

This commit is contained in:
2026-03-15 17:08:23 +07:00
commit 129ca2260c
3716 changed files with 566316 additions and 0 deletions

View File

@@ -0,0 +1,28 @@
<?php
namespace Modules\HRM\Database\Factories;
use Illuminate\Database\Eloquent\Factories\Factory;
use Modules\HRM\Models\Employee;
class EmployeeFactory extends Factory
{
protected $model = Employee::class;
public function definition(): array
{
$roles = ['chef', 'waiter', 'manager', 'staff', 'admin'];
return [
'restaurant_id' => rand(1, 5),
'first_name' => $this->faker->firstName(),
'last_name' => $this->faker->lastName(),
'email' => $this->faker->unique()->safeEmail(),
'phone' => $this->faker->unique()->phoneNumber(),
'avatar' => null,
'joining_date' => $this->faker->date(),
'role' => $roles[array_rand($roles)],
'status' => 1,
];
}
}

View File

@@ -0,0 +1,43 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
public function up(): void
{
Schema::create('departments', function (Blueprint $table) {
$table->id();
// Multi-restaurant support
$table->unsignedBigInteger('restaurant_id')->nullable()->index();
// Optional hierarchical structure (parent department)
$table->unsignedBigInteger('parent_id')->nullable()->index()->comment('For department hierarchy');
// Department info
$table->string('name', 100);
$table->text('description')->nullable();
// Status: active/inactive
$table->smallInteger('status')->default(1)->comment('1=Active, 2=Inactive');
// Optional metadata for future
$table->json('meta')->nullable()->comment('Optional JSON for additional info');
// Timestamps & soft deletes
$table->timestamps();
$table->softDeletes();
// Indexes for faster search
$table->unique(['restaurant_id', 'name']); // prevent duplicate names within the same restaurant
});
}
public function down(): void
{
Schema::dropIfExists('departments');
}
};

View File

@@ -0,0 +1,43 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
public function up(): void
{
Schema::create('designations', function (Blueprint $table) {
$table->id();
// Multi-restaurant support
$table->unsignedBigInteger('restaurant_id')->nullable()->index();
// Department reference (nullable for flexibility)
$table->foreignId('department_id')->nullable()->constrained('departments')->onDelete('set null');
// Designation info
$table->string('title', 100);
$table->text('description')->nullable();
// Status: active/inactive
$table->smallInteger('status')->default(1)->comment('1=Active, 2=Inactive');
// Optional metadata for future features
$table->json('meta')->nullable()->comment('Optional JSON for additional info like level, grade, or code');
// Timestamps & soft deletes
$table->timestamps();
$table->softDeletes();
// Unique constraint to prevent duplicate designations within same department & restaurant
$table->unique(['restaurant_id', 'department_id', 'title']);
});
}
public function down(): void
{
Schema::dropIfExists('designations');
}
};

View File

@@ -0,0 +1,45 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
public function up(): void
{
Schema::create('salary_types', function (Blueprint $table) {
$table->id();
// Multi-restaurant support
$table->unsignedBigInteger('restaurant_id')->nullable()->index();
// Salary type details
$table->string('name', 100)->comment('Name of the salary component, e.g., Basic, Bonus, Tax');
$table->enum('type', ['earning', 'deduction'])->default('earning');
$table->decimal('default_amount', 15, 2)->default(0)->comment('Default amount for this salary type');
// Optional: calculation rules
$table->enum('calculation_method', ['fixed', 'percentage'])->default('fixed')
->comment('Fixed amount or percentage of basic salary');
$table->boolean('is_taxable')->default(false)->comment('Whether this earning is taxable');
$table->boolean('is_visible_in_payslip')->default(true)->comment('Show in employee payslip');
// Status
$table->smallInteger('status')->default(1)->comment('1=Active, 2=Inactive');
// Timestamps & soft deletes
$table->timestamps();
$table->softDeletes();
// Indexes
$table->index(['restaurant_id', 'type', 'status']);
});
}
public function down(): void
{
Schema::dropIfExists('salary_types');
}
};

View File

@@ -0,0 +1,55 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
public function up(): void
{
Schema::create('employee_salaries', function (Blueprint $table) {
$table->id();
// Multi-restaurant support
$table->unsignedBigInteger('restaurant_id')->nullable()->index();
// Employee reference
$table->foreignId('employee_id')->constrained('users')->onDelete('cascade');
// Salary period
$table->string('salary_month', 7)->comment('Format: YYYY-MM')->index();
// Salary components
$table->decimal('basic_salary', 12, 2)->default(0);
$table->decimal('allowances', 12, 2)->default(0);
$table->decimal('deductions', 12, 2)->default(0);
$table->decimal('overtime_hours', 8, 2)->default(0);
$table->decimal('overtime_rate', 12, 2)->default(0);
$table->decimal('bonus', 12, 2)->default(0);
$table->decimal('net_salary', 12, 2)->default(0);
// Payment tracking
$table->date('payment_date')->nullable();
$table->text('remarks')->nullable();
// Status and audit
$table->enum('status', ['pending', 'approved', 'paid'])->default('pending');
// Optional: store JSON breakdown of salary components for flexibility
$table->json('salary_breakdown')->nullable()->comment('Detailed breakdown of earnings/deductions');
// Timestamps & soft delete
$table->timestamps();
$table->softDeletes();
// Indexes
$table->index(['employee_id', 'salary_month', 'status']);
});
}
public function down(): void
{
Schema::dropIfExists('employee_salaries');
}
};

View File

@@ -0,0 +1,47 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
public function up(): void
{
Schema::create('salary_setups', function (Blueprint $table) {
$table->id();
// Multi-restaurant support
$table->unsignedBigInteger('restaurant_id')->nullable()->index();
// Employee reference
$table->foreignId('employee_id')->constrained('users')->onDelete('cascade');
// Salary component reference
$table->foreignId('salary_type_id')->constrained('salary_types')->onDelete('cascade');
// Amount & calculation
$table->decimal('amount', 15, 2)->default(0)->comment('Amount for this salary component');
$table->enum('calculation_type', ['fixed', 'percentage'])->default('fixed')
->comment('Fixed amount or percentage of basic salary');
// Optional: custom notes
$table->string('notes')->nullable()->comment('Optional notes or description');
// Status & audit
$table->smallInteger('status')->default(1)->comment('1=Active, 2=Inactive');
// Timestamps & soft delete
$table->timestamps();
$table->softDeletes();
// Indexes for reporting
$table->index(['employee_id', 'salary_type_id', 'status']);
});
}
public function down(): void
{
Schema::dropIfExists('salary_setups');
}
};

View File

@@ -0,0 +1,54 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
public function up(): void
{
Schema::create('salary_generates', function (Blueprint $table) {
$table->id();
// Multi-restaurant support
$table->unsignedBigInteger('restaurant_id')->nullable()->index();
// Employee reference
$table->foreignId('employee_id')->constrained('users')->onDelete('cascade');
// Salary month
$table->string('month', 7)->comment('Format: YYYY-MM')->index();
// Salary components
$table->decimal('basic_salary', 15, 2)->default(0);
$table->decimal('total_earnings', 15, 2)->default(0);
$table->decimal('total_deductions', 15, 2)->default(0);
$table->decimal('overtime_hours', 8, 2)->default(0);
$table->decimal('overtime_amount', 15, 2)->default(0);
$table->decimal('net_salary', 15, 2)->default(0);
// Payroll metadata
$table->date('generated_date')->nullable();
$table->unsignedBigInteger('generated_by')->nullable()->index();
// Optional: store salary breakdown for auditing
$table->json('salary_breakdown')->nullable()->comment('Detailed JSON of salary components');
// Status
$table->enum('status', ['pending', 'approved', 'paid'])->default('pending');
// Timestamps & soft deletes
$table->timestamps();
$table->softDeletes();
// Indexes for performance
$table->index(['employee_id', 'month', 'status']);
});
}
public function down(): void
{
Schema::dropIfExists('salary_generates');
}
};

View File

@@ -0,0 +1,48 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
public function up(): void
{
Schema::create('attendances', function (Blueprint $table) {
$table->id();
// Multi-restaurant support
$table->unsignedBigInteger('restaurant_id')->nullable()->index();
// Employee reference
$table->foreignId('employee_id')->constrained('users')->onDelete('cascade');
// Attendance date
$table->date('date')->index();
// Attendance times
$table->time('first_clock_in')->nullable();
$table->time('last_clock_out')->nullable();
$table->decimal('hours_worked', 5, 2)->nullable()->comment('Total hours worked');
// Status & type
$table->enum('status', ['present', 'absent', 'leave', 'holiday'])->default('present');
// Optional metadata
$table->json('breaks')->nullable()->comment('Optional JSON array to store break periods');
$table->json('notes')->nullable()->comment('Any admin notes or special remarks');
// Timestamps & soft deletes
$table->timestamps();
$table->softDeletes();
// Ensure only one record per employee per day
$table->unique(['employee_id', 'date']);
});
}
public function down(): void
{
Schema::dropIfExists('attendances');
}
};

View File

@@ -0,0 +1,41 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
public function up(): void
{
Schema::create('attendance_logs', function (Blueprint $table) {
$table->id();
// Multi-restaurant support
$table->unsignedBigInteger('restaurant_id')->nullable()->index();
// Employee reference
$table->foreignId('employee_id')->constrained('users')->onDelete('cascade');
// Link to daily attendance
$table->foreignId('attendance_id')->constrained('attendances')->onDelete('cascade');
// Clock-in / Clock-out
$table->enum('type', ['in', 'out']);
$table->timestamp('punch_time')->index();
$table->string('device_id')->nullable()->comment('Optional device ID');
// Optional: capture location
$table->decimal('latitude', 10, 7)->nullable();
$table->decimal('longitude', 10, 7)->nullable();
$table->string('ip_address', 45)->nullable()->comment('IP from which punch was made');
$table->timestamps();
});
}
public function down(): void
{
Schema::dropIfExists('attendance_logs');
}
};

View File

@@ -0,0 +1,37 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
public function up(): void
{
Schema::create('leave_types', function (Blueprint $table) {
$table->id();
// 🔗 Multi-restaurant support
$table->unsignedBigInteger('restaurant_id')->nullable()->index();
// 🏷️ Leave Type Information
$table->string('name', 100);
$table->integer('max_days')->default(0)->comment('Maximum days allowed per year');
$table->boolean('carry_forward')->default(false)->comment('Whether unused days can carry over to next year');
$table->boolean('is_paid')->default(true)->comment('Determines if the leave is paid');
// ⚙️ Control & Status
$table->smallInteger('status')->default(1)->comment('1=Active, 2=Inactive');
$table->text('description')->nullable()->comment('Optional leave policy or notes');
// 🕓 Standard timestamps
$table->timestamps();
$table->softDeletes();
});
}
public function down(): void
{
Schema::dropIfExists('leave_types');
}
};

View File

@@ -0,0 +1,49 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
public function up(): void
{
Schema::create('leave_applications', function (Blueprint $table) {
$table->id();
// 🔗 Multi-restaurant support
$table->unsignedBigInteger('restaurant_id')->nullable()->index();
// 🔗 Foreign keys
$table->foreignId('employee_id')->constrained('users')->onDelete('cascade');
$table->foreignId('leave_type_id')->constrained('leave_types')->onDelete('cascade');
// 🗓️ Leave duration
$table->date('start_date');
$table->date('end_date');
// 📝 Reason and notes
$table->text('reason')->nullable();
$table->text('admin_note')->nullable()->comment('Optional note by admin/manager');
// ⚙️ Status and approval tracking
$table->enum('status', ['pending', 'approved', 'rejected'])->default('pending');
$table->foreignId('approved_by')->nullable()->constrained('users')->onDelete('set null');
// Optional: flag for half-day, full-day, or custom leave
$table->enum('leave_duration_type', ['full_day', 'half_day', 'custom'])->default('full_day');
// ⚙️ Metadata
$table->timestamps();
$table->softDeletes();
// Indexes for faster filtering
$table->index(['employee_id', 'leave_type_id', 'status']);
});
}
public function down(): void
{
Schema::dropIfExists('leave_applications');
}
};

View File

@@ -0,0 +1,29 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
public function up(): void
{
Schema::create('weekly_holidays', function (Blueprint $table) {
$table->id();
$table->unsignedBigInteger('restaurant_id')->nullable()->index();
$table->string('day', 20);
$table->string('description', 255)->nullable();
$table->smallInteger('status')->default(1)->comment('1=Active, 2=Inactive');
$table->timestamps();
$table->softDeletes();
// Unique per restaurant
$table->unique(['restaurant_id', 'day']);
});
}
public function down(): void
{
Schema::dropIfExists('weekly_holidays');
}
};

View File

@@ -0,0 +1,51 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
public function up(): void
{
Schema::create('loans', function (Blueprint $table) {
$table->id();
// 🔗 Multi-restaurant / branch support
$table->unsignedBigInteger('restaurant_id')->nullable()->index();
// 🔗 Employee
$table->foreignId('employee_id')->constrained('users')->onDelete('cascade');
// 💰 Loan details
$table->decimal('amount', 15, 2)->comment('Total loan amount');
$table->decimal('paid_amount', 15, 2)->default(0);
$table->decimal('remaining_amount', 15, 2)->default(0)->comment('Remaining amount');
$table->enum('schedule_type', ['daily', 'weekly', 'monthly', 'yearly'])->default('monthly');
$table->integer('installments')->default(1)->comment('Total number of installments');
$table->decimal('fine_rate', 8, 4)->default(0)->comment('per day percentage e.g. 0.01 = 1%');
// ⚙️ Status and type
$table->enum('status', ['active', 'closed'])->default('active')->comment('Loan status');
$table->enum('loan_type', ['personal', 'business', 'emergency', 'other'])->default('personal')
->comment('Type of loan');
// 📝 Optional metadata
$table->text('remarks')->nullable()->comment('Notes about the loan');
$table->date('start_date')->nullable();
$table->date('end_date')->nullable(); // calculated from installments
// ⏱ Timestamps & soft delete
$table->timestamps();
$table->softDeletes();
// Indexes for reports
$table->index(['employee_id', 'status', 'loan_type']);
});
}
public function down(): void
{
Schema::dropIfExists('loans');
}
};

View File

@@ -0,0 +1,49 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
public function up(): void
{
Schema::create('loan_installments', function (Blueprint $table) {
$table->id();
// 🔗 Multi-restaurant support
$table->unsignedBigInteger('restaurant_id')->nullable()->index();
// 🔗 Link to parent loan
$table->foreignId('loan_id')->constrained('loans')->onDelete('cascade');
// Installment details
$table->decimal('amount', 15, 2)->comment('Installment amount');
$table->date('due_date')->comment('Scheduled due date');
$table->date('paid_date')->nullable()->comment('Actual paid date');
$table->boolean('is_paid')->default(false)->comment('Payment status');
// Overdue handling
$table->boolean('is_overdue')->default(false)->comment('Marks overdue installment');
$table->decimal('fine_amount', 15, 2)->default(0)->comment('Fine for overdue payment');
$table->decimal('total_due', 15, 2)->virtualAs('amount + fine_amount')->nullable()
->comment('Total due including fine');
// Status and remarks
$table->enum('status', ['active', 'inactive'])->default('active');
$table->text('remarks')->nullable()->comment('Optional notes');
// Timestamps & soft delete
$table->timestamps();
$table->softDeletes();
// Indexes for fast reporting and filtering
$table->index(['loan_id', 'is_paid', 'due_date', 'is_overdue']);
});
}
public function down(): void
{
Schema::dropIfExists('loan_installments');
}
};

View File

@@ -0,0 +1,45 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
public function up(): void
{
Schema::create('awards', function (Blueprint $table) {
$table->id();
// Multi-restaurant support
$table->unsignedBigInteger('restaurant_id')->nullable()->index();
// Employee reference
$table->foreignId('employee_id')->constrained('users')->onDelete('cascade');
// Award details
$table->string('title', 100);
$table->text('description')->nullable();
$table->date('date_awarded');
$table->decimal('amount', 15, 2)->default(0)->comment('Cash award amount');
// Optional: type of award (cash, recognition, certificate)
$table->enum('award_type', ['cash', 'recognition', 'certificate', 'other'])->default('cash');
// Status
$table->smallInteger('status')->default(1)->comment('1=Active, 2=Inactive');
// Metadata
$table->timestamps();
$table->softDeletes();
// Indexes
$table->index(['employee_id', 'date_awarded']);
});
}
public function down(): void
{
Schema::dropIfExists('awards');
}
};

View File

@@ -0,0 +1,51 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
public function up(): void
{
Schema::create('recruitments', function (Blueprint $table) {
$table->id();
// Multi-restaurant support
$table->unsignedBigInteger('restaurant_id')->nullable()->index();
// Job details
$table->string('title', 150);
$table->text('description')->nullable();
$table->text('requirements')->nullable();
$table->integer('vacancy_count')->default(1);
// Department & Designation (optional)
$table->foreignId('department_id')->nullable()->constrained('departments')->onDelete('set null');
$table->foreignId('designation_id')->nullable()->constrained('designations')->onDelete('set null');
// Dates
$table->date('start_date');
$table->date('end_date')->nullable();
// Job type & recruiter tracking
$table->enum('job_type', ['full_time', 'part_time', 'internship', 'contract'])->default('full_time');
$table->foreignId('recruiter_id')->nullable()->constrained('users')->onDelete('set null');
// Status
$table->enum('status', ['open', 'closed'])->default('open');
// Timestamps & soft delete
$table->timestamps();
$table->softDeletes();
// Indexes for faster queries
$table->index(['restaurant_id', 'status', 'start_date']);
});
}
public function down(): void
{
Schema::dropIfExists('recruitments');
}
};

View File

@@ -0,0 +1,47 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
public function up(): void
{
Schema::create('candidates', function (Blueprint $table) {
$table->id();
// Multi-restaurant support
$table->unsignedBigInteger('restaurant_id')->nullable()->index();
// Link to recruitment/job post
$table->foreignId('recruitment_id')->constrained('recruitments')->onDelete('cascade');
// Candidate details
$table->string('first_name', 50);
$table->string('last_name', 50)->nullable();
$table->string('email', 100)->nullable()->index();
$table->string('phone', 20)->nullable()->index();
$table->string('resume')->nullable()->comment('File path for uploaded resume');
$table->string('cover_letter')->nullable()->comment('Optional cover letter file path');
// Candidate status
$table->enum('status', ['applied', 'shortlisted', 'interviewed', 'selected', 'rejected'])->default('applied');
// Optional notes from recruiter or admin
$table->text('notes')->nullable();
// Timestamps & soft delete
$table->timestamps();
$table->softDeletes();
// Indexes for queries and reporting
$table->index(['recruitment_id', 'status']);
});
}
public function down(): void
{
Schema::dropIfExists('candidates');
}
};

View File

@@ -0,0 +1,47 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
public function up(): void
{
Schema::create('interviews', function (Blueprint $table) {
$table->id();
// Multi-restaurant support
$table->unsignedBigInteger('restaurant_id')->nullable()->index();
// Candidate reference
$table->foreignId('candidate_id')->constrained('candidates')->onDelete('cascade');
// Optional department reference
$table->foreignId('department_id')->nullable()->constrained('departments')->onDelete('set null');
// Interview details
$table->dateTime('interview_date')->nullable();
$table->string('interviewer_name', 100)->nullable();
$table->text('feedback')->nullable();
// Status tracking
$table->enum('status', ['pending', 'shortlisted', 'rejected', 'hired'])->default('pending');
// Optional notes or rating
$table->tinyInteger('rating')->nullable()->comment('Rating out of 5');
// Timestamps & soft delete
$table->timestamps();
$table->softDeletes();
// Indexes for performance
$table->index(['candidate_id', 'status', 'interview_date']);
});
}
public function down(): void
{
Schema::dropIfExists('interviews');
}
};

View File

@@ -0,0 +1,28 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
public function up(): void
{
Schema::create('shifts', function (Blueprint $table) {
$table->id();
$table->unsignedBigInteger('restaurant_id')->nullable();
$table->string('name'); // e.g., Morning, Evening, Night
$table->time('start_time');
$table->time('end_time');
$table->string('description')->nullable();
$table->smallInteger('status')->default(1)->comment('1=Active, 2=InActive');
$table->timestamps();
$table->softDeletes();
});
}
public function down(): void
{
Schema::dropIfExists('shifts');
}
};

View File

@@ -0,0 +1,30 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
public function up(): void
{
Schema::create('employee_shift_assignments', function (Blueprint $table) {
$table->id();
$table->unsignedBigInteger('restaurant_id')->nullable();
$table->unsignedBigInteger('employee_id');
$table->unsignedBigInteger('shift_id');
$table->smallInteger('status')->default(1)->comment('1=Active, 2=InActive');
$table->timestamps();
$table->softDeletes();
$table->foreign('employee_id')->references('id')->on('users')->onDelete('cascade');
$table->foreign('shift_id')->references('id')->on('shifts')->onDelete('cascade');
$table->unique(['employee_id']); // One shift per employee
});
}
public function down(): void
{
Schema::dropIfExists('employee_shift_assignments');
}
};

View File

@@ -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',
]
);
}
}
}

View File

@@ -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);
}
}
}

View File

@@ -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);
}
}
}

View File

@@ -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',
]);
}
}
}

View File

@@ -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,
]
);
}
}
}

View File

@@ -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();
});
}
}

View File

@@ -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,
]);
}
}

View File

@@ -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]);
}
}
}

View File

@@ -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.');
}
}

View File

@@ -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]);
}
}
}

View File

@@ -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);
}
}
}

View File

@@ -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]);
}
}
}