vernova/database/seeders/ExpenseSeeder.php
2026-07-26 19:58:27 +03:30

377 lines
18 KiB
PHP
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?php
namespace Database\Seeders;
use App\Models\Currency;
use App\Models\Employee;
use App\Models\Expense;
use App\Models\Tenant;
use App\Models\User;
use Illuminate\Database\Seeder;
class ExpenseSeeder extends Seeder
{
/**
* Run the database seeds.
*
* Creates 20 sample expense records distributed across projects
* for both tenants, with varied categories and statuses to
* reflect realistic construction expense tracking.
*
* Distribution:
* - 13 expenses for tenant 1 (Sepideh) — IRR amounts
* - 7 expenses for tenant 2 (Global) — USD amounts
*/
public function run(): void
{
$tenant1 = Tenant::where('slug', 'sepideh')->firstOrFail();
$tenant2 = Tenant::where('slug', 'global')->firstOrFail();
$irr = Currency::where('code', 'IRR')->firstOrFail();
$usd = Currency::where('code', 'USD')->firstOrFail();
$tenant1Projects = $tenant1->projects()->orderBy('id')->get();
$tenant2Projects = $tenant2->projects()->orderBy('id')->get();
$tenant1Employees = $tenant1->employees()->orderBy('id')->get();
$tenant2Employees = $tenant2->employees()->orderBy('id')->get();
$admin1 = User::where('email', 'admin@sepideh.ir')->firstOrFail();
$manager = User::where('email', 'manager@sepideh.ir')->firstOrFail();
$admin2 = User::where('email', 'admin@global.com')->firstOrFail();
// ─────────────────────────────────────────────
// Tenant 1 — Sepideh Expenses (IRR)
// ─────────────────────────────────────────────
$tenant1Expenses = [
// Project: ساختمان مسکونی گلستان
[
'tenant_id' => $tenant1->id,
'project_id' => $tenant1Projects[0]->id,
'petty_cash_id' => null,
'employee_id' => $tenant1Employees[0]->id ?? null,
'amount' => 2500000000, // 2.5B IRR — میلگرد
'currency_id' => $irr->id,
'original_amount' => null,
'description' => 'خرید میلگرد آج از ذوب آهن اصفهان — ۵۰ تن',
'expense_date' => '2024-05-10',
'category' => 'materials',
'receipt_path' => null,
'status' => 'approved',
'approved_by' => $admin1->id,
],
[
'tenant_id' => $tenant1->id,
'project_id' => $tenant1Projects[0]->id,
'petty_cash_id' => null,
'employee_id' => $tenant1Employees[1]->id ?? null,
'amount' => 850000000, // 850M IRR — سیمان
'currency_id' => $irr->id,
'original_amount' => null,
'description' => 'خرید سیمان تهران — ۲۰۰ تن تیپ ۲ و ۵',
'expense_date' => '2024-05-25',
'category' => 'materials',
'receipt_path' => null,
'status' => 'approved',
'approved_by' => $admin1->id,
],
[
'tenant_id' => $tenant1->id,
'project_id' => $tenant1Projects[0]->id,
'petty_cash_id' => null,
'employee_id' => null,
'amount' => 320000000, // 320M IRR — اجاره جرثقیل
'currency_id' => $irr->id,
'original_amount' => null,
'description' => 'اجاره جرثقیل ۵۰ تنی برای مدت ۲۰ روز',
'expense_date' => '2024-06-15',
'category' => 'equipment',
'receipt_path' => null,
'status' => 'pending',
'approved_by' => null,
],
[
'tenant_id' => $tenant1->id,
'project_id' => $tenant1Projects[0]->id,
'petty_cash_id' => null,
'employee_id' => null,
'amount' => 45000000, // 45M IRR — حمل و نقل
'currency_id' => $irr->id,
'original_amount' => null,
'description' => 'هزینه حمل مصالح از کارخانه تا محل پروژه — ۳ سفر کامیون',
'expense_date' => '2024-06-20',
'category' => 'transport',
'receipt_path' => null,
'status' => 'approved',
'approved_by' => $manager->id,
],
// Project: مجتمع تجاری مروارید
[
'tenant_id' => $tenant1->id,
'project_id' => $tenant1Projects[2]->id,
'petty_cash_id' => null,
'employee_id' => $tenant1Employees[4]->id ?? null,
'amount' => 1800000000, // 1.8B IRR — چیلر
'currency_id' => $irr->id,
'original_amount' => null,
'description' => 'خرید چیلر ۵۰۰ تنی و نصب سیستم تهویه',
'expense_date' => '2024-07-05',
'category' => 'equipment',
'receipt_path' => null,
'status' => 'approved',
'approved_by' => $admin1->id,
],
[
'tenant_id' => $tenant1->id,
'project_id' => $tenant1Projects[2]->id,
'petty_cash_id' => null,
'employee_id' => $tenant1Employees[3]->id ?? null,
'amount' => 120000000, // 120M IRR — خوراک
'currency_id' => $irr->id,
'original_amount' => null,
'description' => 'وعده غذایی کارگران — ۳ ماهه دوم ۱۴۰۳',
'expense_date' => '2024-07-15',
'category' => 'food',
'receipt_path' => null,
'status' => 'approved',
'approved_by' => $manager->id,
],
[
'tenant_id' => $tenant1->id,
'project_id' => $tenant1Projects[2]->id,
'petty_cash_id' => null,
'employee_id' => null,
'amount' => 600000000, // 600M IRR — نیروی کار
'currency_id' => $irr->id,
'original_amount' => null,
'description' => 'حقوق کارگران ساختمانی پروژه مروارید — تیرماه ۱۴۰۳',
'expense_date' => '2024-07-22',
'category' => 'labor',
'receipt_path' => null,
'status' => 'pending',
'approved_by' => null,
],
// Project: بازسازی بیمارستان شفا
[
'tenant_id' => $tenant1->id,
'project_id' => $tenant1Projects[4]->id,
'petty_cash_id' => null,
'employee_id' => null,
'amount' => 950000000, // 950M IRR — مصالح
'currency_id' => $irr->id,
'original_amount' => null,
'description' => 'خرید مصالح بهداشتی بیمارستانی — کفپوش، رنگ ضدعفونی‌کننده و درب‌های اتوماتیک',
'expense_date' => '2024-06-10',
'category' => 'materials',
'receipt_path' => null,
'status' => 'approved',
'approved_by' => $admin1->id,
],
[
'tenant_id' => $tenant1->id,
'project_id' => $tenant1Projects[4]->id,
'petty_cash_id' => null,
'employee_id' => null,
'amount' => 200000000, // 200M IRR — تجهیزات
'currency_id' => $irr->id,
'original_amount' => null,
'description' => 'تأمین و نصب ژنراتور اضطراری ۵۰۰ کیلووات',
'expense_date' => '2024-07-01',
'category' => 'equipment',
'receipt_path' => null,
'status' => 'rejected',
'approved_by' => $admin1->id,
],
// Project: استخر و سونا سلامت
[
'tenant_id' => $tenant1->id,
'project_id' => $tenant1Projects[3]->id,
'petty_cash_id' => null,
'employee_id' => null,
'amount' => 350000000, // 350M IRR — مصالح
'currency_id' => $irr->id,
'original_amount' => null,
'description' => 'خرید سرامیک و موزاییک استخر — مارک آلفا',
'expense_date' => '2024-02-15',
'category' => 'materials',
'receipt_path' => null,
'status' => 'approved',
'approved_by' => $admin1->id,
],
[
'tenant_id' => $tenant1->id,
'project_id' => $tenant1Projects[3]->id,
'petty_cash_id' => null,
'employee_id' => null,
'amount' => 75000000, // 75M IRR — حمل و نقل
'currency_id' => $irr->id,
'original_amount' => null,
'description' => 'هزینه حمل و نصب سیستم فیلتراسیون آب استخر',
'expense_date' => '2024-03-20',
'category' => 'transport',
'receipt_path' => null,
'status' => 'approved',
'approved_by' => $manager->id,
],
// Project: پل عابر سپید
[
'tenant_id' => $tenant1->id,
'project_id' => $tenant1Projects[1]->id,
'petty_cash_id' => null,
'employee_id' => $tenant1Employees[2]->id ?? null,
'amount' => 150000000, // 150M IRR — گمانه‌بوری
'currency_id' => $irr->id,
'original_amount' => null,
'description' => 'هزینه گمانه‌بوری و مطالعات ژئوتکنیک پل عابر',
'expense_date' => '2024-07-10',
'category' => 'other',
'receipt_path' => null,
'status' => 'pending',
'approved_by' => null,
],
[
'tenant_id' => $tenant1->id,
'project_id' => $tenant1Projects[1]->id,
'petty_cash_id' => null,
'employee_id' => null,
'amount' => 280000000, // 280M IRR — تجهیزات
'currency_id' => $irr->id,
'original_amount' => null,
'description' => 'خرید و نصب داربست و قالب فلزی برای ساخت پایه‌های پل',
'expense_date' => '2024-07-18',
'category' => 'equipment',
'receipt_path' => null,
'status' => 'approved',
'approved_by' => $admin1->id,
],
];
foreach ($tenant1Expenses as $expenseData) {
Expense::create($expenseData);
}
// ─────────────────────────────────────────────
// Tenant 2 — Global Expenses (USD)
// ─────────────────────────────────────────────
$tenant2Expenses = [
// Project: Riverside Tower
[
'tenant_id' => $tenant2->id,
'project_id' => $tenant2Projects[0]->id,
'petty_cash_id' => null,
'employee_id' => $tenant2Employees[0]->id ?? null,
'amount' => 1250000, // $1.25M — concrete
'currency_id' => $usd->id,
'original_amount' => null,
'description' => 'Ready-mix concrete supply for foundation pouring — 3,000 cubic yards',
'expense_date' => '2024-04-15',
'category' => 'materials',
'receipt_path' => null,
'status' => 'approved',
'approved_by' => $admin2->id,
],
[
'tenant_id' => $tenant2->id,
'project_id' => $tenant2Projects[0]->id,
'petty_cash_id' => null,
'employee_id' => null,
'amount' => 340000, // $340K — steel
'currency_id' => $usd->id,
'original_amount' => null,
'description' => 'Structural steel reinforcement bars — Grade 60, 500 tons',
'expense_date' => '2024-05-20',
'category' => 'materials',
'receipt_path' => null,
'status' => 'approved',
'approved_by' => $admin2->id,
],
[
'tenant_id' => $tenant2->id,
'project_id' => $tenant2Projects[0]->id,
'petty_cash_id' => null,
'employee_id' => $tenant2Employees[2]->id ?? null,
'amount' => 85000, // $85K — equipment rental
'currency_id' => $usd->id,
'original_amount' => null,
'description' => 'Tower crane rental — 3 months',
'expense_date' => '2024-06-01',
'category' => 'equipment',
'receipt_path' => null,
'status' => 'pending',
'approved_by' => null,
],
[
'tenant_id' => $tenant2->id,
'project_id' => $tenant2Projects[0]->id,
'petty_cash_id' => null,
'employee_id' => null,
'amount' => 22500, // $22.5K — labor
'currency_id' => $usd->id,
'original_amount' => null,
'description' => 'Labor wages for concrete finishing crew — June 2024',
'expense_date' => '2024-06-30',
'category' => 'labor',
'receipt_path' => null,
'status' => 'approved',
'approved_by' => $admin2->id,
],
// Project: Industrial Warehouse Complex
[
'tenant_id' => $tenant2->id,
'project_id' => $tenant2Projects[1]->id,
'petty_cash_id' => null,
'employee_id' => null,
'amount' => 45000, // $45K — site survey
'currency_id' => $usd->id,
'original_amount' => null,
'description' => 'Geotechnical survey and soil testing across the warehouse site',
'expense_date' => '2024-07-10',
'category' => 'other',
'receipt_path' => null,
'status' => 'pending',
'approved_by' => null,
],
[
'tenant_id' => $tenant2->id,
'project_id' => $tenant2Projects[1]->id,
'petty_cash_id' => null,
'employee_id' => null,
'amount' => 15000, // $15K — transport
'currency_id' => $usd->id,
'original_amount' => null,
'description' => 'Transportation of heavy equipment to warehouse site',
'expense_date' => '2024-07-15',
'category' => 'transport',
'receipt_path' => null,
'status' => 'approved',
'approved_by' => $admin2->id,
],
// Project: Greenfield School Campus
[
'tenant_id' => $tenant2->id,
'project_id' => $tenant2Projects[2]->id,
'petty_cash_id' => null,
'employee_id' => $tenant2Employees[4]->id ?? null,
'amount' => 62000, // $62K — electrical
'currency_id' => $usd->id,
'original_amount' => null,
'description' => 'Electrical wiring, panels and fire alarm system for Building A',
'expense_date' => '2024-04-10',
'category' => 'equipment',
'receipt_path' => null,
'status' => 'approved',
'approved_by' => $admin2->id,
],
];
foreach ($tenant2Expenses as $expenseData) {
Expense::create($expenseData);
}
$total = count($tenant1Expenses) + count($tenant2Expenses);
$this->command->info("Expenses seeded: {$total} records created.");
}
}