Initial commit
This commit is contained in:
152
database/factories/CashierLedgerEntryFactory.php
Normal file
152
database/factories/CashierLedgerEntryFactory.php
Normal file
@@ -0,0 +1,152 @@
|
||||
<?php
|
||||
|
||||
namespace Database\Factories;
|
||||
|
||||
use App\Models\CashierLedgerEntry;
|
||||
use App\Models\FinanceDocument;
|
||||
use App\Models\User;
|
||||
use Illuminate\Database\Eloquent\Factories\Factory;
|
||||
|
||||
/**
|
||||
* @extends \Illuminate\Database\Eloquent\Factories\Factory<\App\Models\CashierLedgerEntry>
|
||||
*/
|
||||
class CashierLedgerEntryFactory extends Factory
|
||||
{
|
||||
protected $model = CashierLedgerEntry::class;
|
||||
|
||||
/**
|
||||
* Define the model's default state.
|
||||
*
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
public function definition(): array
|
||||
{
|
||||
$entryTypes = ['receipt', 'payment'];
|
||||
$paymentMethods = ['cash', 'bank_transfer', 'check'];
|
||||
$entryType = $this->faker->randomElement($entryTypes);
|
||||
$amount = $this->faker->randomFloat(2, 100, 50000);
|
||||
$balanceBefore = $this->faker->randomFloat(2, 0, 100000);
|
||||
|
||||
// Calculate balance after based on entry type
|
||||
$balanceAfter = $entryType === 'receipt'
|
||||
? $balanceBefore + $amount
|
||||
: $balanceBefore - $amount;
|
||||
|
||||
return [
|
||||
'entry_type' => $entryType,
|
||||
'entry_date' => $this->faker->dateTimeBetween('-30 days', 'now'),
|
||||
'amount' => $amount,
|
||||
'payment_method' => $this->faker->randomElement($paymentMethods),
|
||||
'bank_account' => $this->faker->company() . ' Bank - ' . $this->faker->numerify('##########'),
|
||||
'balance_before' => $balanceBefore,
|
||||
'balance_after' => $balanceAfter,
|
||||
'recorded_by_cashier_id' => User::factory(),
|
||||
'recorded_at' => now(),
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Indicate that the entry is a receipt (incoming money).
|
||||
*/
|
||||
public function receipt(): static
|
||||
{
|
||||
return $this->state(function (array $attributes) {
|
||||
$balanceBefore = $attributes['balance_before'] ?? 0;
|
||||
$amount = $attributes['amount'];
|
||||
|
||||
return [
|
||||
'entry_type' => 'receipt',
|
||||
'balance_after' => $balanceBefore + $amount,
|
||||
];
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Indicate that the entry is a payment (outgoing money).
|
||||
*/
|
||||
public function payment(): static
|
||||
{
|
||||
return $this->state(function (array $attributes) {
|
||||
$balanceBefore = $attributes['balance_before'] ?? 0;
|
||||
$amount = $attributes['amount'];
|
||||
|
||||
return [
|
||||
'entry_type' => 'payment',
|
||||
'balance_after' => $balanceBefore - $amount,
|
||||
];
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Indicate that the entry is linked to a finance document.
|
||||
*/
|
||||
public function withFinanceDocument(): static
|
||||
{
|
||||
return $this->state(fn (array $attributes) => [
|
||||
'finance_document_id' => FinanceDocument::factory(),
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Indicate that the payment method is cash.
|
||||
*/
|
||||
public function cash(): static
|
||||
{
|
||||
return $this->state(fn (array $attributes) => [
|
||||
'payment_method' => 'cash',
|
||||
'bank_account' => null,
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Indicate that the payment method is bank transfer.
|
||||
*/
|
||||
public function bankTransfer(): static
|
||||
{
|
||||
return $this->state(fn (array $attributes) => [
|
||||
'payment_method' => 'bank_transfer',
|
||||
'bank_account' => $this->faker->company() . ' Bank - ' . $this->faker->numerify('##########'),
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Indicate that the payment method is check.
|
||||
*/
|
||||
public function check(): static
|
||||
{
|
||||
return $this->state(fn (array $attributes) => [
|
||||
'payment_method' => 'check',
|
||||
'transaction_reference' => 'CHK' . $this->faker->numerify('######'),
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a sequence of entries with running balance for a specific account.
|
||||
*/
|
||||
public function sequence(string $bankAccount, float $initialBalance = 0): static
|
||||
{
|
||||
static $currentBalance;
|
||||
|
||||
if ($currentBalance === null) {
|
||||
$currentBalance = $initialBalance;
|
||||
}
|
||||
|
||||
return $this->state(function (array $attributes) use ($bankAccount, &$currentBalance) {
|
||||
$amount = $attributes['amount'];
|
||||
$entryType = $attributes['entry_type'];
|
||||
$balanceBefore = $currentBalance;
|
||||
|
||||
$balanceAfter = $entryType === 'receipt'
|
||||
? $balanceBefore + $amount
|
||||
: $balanceBefore - $amount;
|
||||
|
||||
$currentBalance = $balanceAfter;
|
||||
|
||||
return [
|
||||
'bank_account' => $bankAccount,
|
||||
'balance_before' => $balanceBefore,
|
||||
'balance_after' => $balanceAfter,
|
||||
];
|
||||
});
|
||||
}
|
||||
}
|
||||
216
database/factories/FinanceDocumentFactory.php
Normal file
216
database/factories/FinanceDocumentFactory.php
Normal file
@@ -0,0 +1,216 @@
|
||||
<?php
|
||||
|
||||
namespace Database\Factories;
|
||||
|
||||
use App\Models\FinanceDocument;
|
||||
use App\Models\User;
|
||||
use Illuminate\Database\Eloquent\Factories\Factory;
|
||||
|
||||
/**
|
||||
* @extends \Illuminate\Database\Eloquent\Factories\Factory<\App\Models\FinanceDocument>
|
||||
*/
|
||||
class FinanceDocumentFactory extends Factory
|
||||
{
|
||||
protected $model = FinanceDocument::class;
|
||||
|
||||
/**
|
||||
* Define the model's default state.
|
||||
*
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
public function definition(): array
|
||||
{
|
||||
$amount = $this->faker->randomFloat(2, 100, 100000);
|
||||
$requestTypes = ['expense_reimbursement', 'advance_payment', 'purchase_request', 'petty_cash'];
|
||||
$statuses = ['pending', 'approved_cashier', 'approved_accountant', 'approved_chair', 'rejected'];
|
||||
|
||||
return [
|
||||
'title' => $this->faker->sentence(6),
|
||||
'description' => $this->faker->paragraph(3),
|
||||
'amount' => $amount,
|
||||
'request_type' => $this->faker->randomElement($requestTypes),
|
||||
'status' => $this->faker->randomElement($statuses),
|
||||
'submitted_by_id' => User::factory(),
|
||||
'submitted_at' => now(),
|
||||
'amount_tier' => $this->determineAmountTier($amount),
|
||||
'requires_board_meeting' => $amount > 50000,
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Indicate that the document is pending approval.
|
||||
*/
|
||||
public function pending(): static
|
||||
{
|
||||
return $this->state(fn (array $attributes) => [
|
||||
'status' => 'pending',
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Indicate that the document is approved by cashier.
|
||||
*/
|
||||
public function approvedByCashier(): static
|
||||
{
|
||||
return $this->state(fn (array $attributes) => [
|
||||
'status' => FinanceDocument::STATUS_APPROVED_CASHIER,
|
||||
'cashier_approved_by_id' => User::factory(),
|
||||
'cashier_approved_at' => now(),
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Indicate that the document is approved by accountant.
|
||||
*/
|
||||
public function approvedByAccountant(): static
|
||||
{
|
||||
return $this->state(fn (array $attributes) => [
|
||||
'status' => FinanceDocument::STATUS_APPROVED_ACCOUNTANT,
|
||||
'cashier_approved_by_id' => User::factory(),
|
||||
'cashier_approved_at' => now(),
|
||||
'accountant_approved_by_id' => User::factory(),
|
||||
'accountant_approved_at' => now(),
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Indicate that the document is approved by chair.
|
||||
*/
|
||||
public function approvedByChair(): static
|
||||
{
|
||||
return $this->state(fn (array $attributes) => [
|
||||
'status' => FinanceDocument::STATUS_APPROVED_CHAIR,
|
||||
'cashier_approved_by_id' => User::factory(),
|
||||
'cashier_approved_at' => now(),
|
||||
'accountant_approved_by_id' => User::factory(),
|
||||
'accountant_approved_at' => now(),
|
||||
'chair_approved_by_id' => User::factory(),
|
||||
'chair_approved_at' => now(),
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Indicate that the document is rejected.
|
||||
*/
|
||||
public function rejected(): static
|
||||
{
|
||||
return $this->state(fn (array $attributes) => [
|
||||
'status' => FinanceDocument::STATUS_REJECTED,
|
||||
'rejection_reason' => $this->faker->sentence(10),
|
||||
'rejected_at' => now(),
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Indicate that the document is a small amount (< 5000).
|
||||
*/
|
||||
public function smallAmount(): static
|
||||
{
|
||||
return $this->state(fn (array $attributes) => [
|
||||
'amount' => $this->faker->randomFloat(2, 100, 4999),
|
||||
'amount_tier' => 'small',
|
||||
'requires_board_meeting' => false,
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Indicate that the document is a medium amount (5000-50000).
|
||||
*/
|
||||
public function mediumAmount(): static
|
||||
{
|
||||
return $this->state(fn (array $attributes) => [
|
||||
'amount' => $this->faker->randomFloat(2, 5000, 50000),
|
||||
'amount_tier' => 'medium',
|
||||
'requires_board_meeting' => false,
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Indicate that the document is a large amount (> 50000).
|
||||
*/
|
||||
public function largeAmount(): static
|
||||
{
|
||||
return $this->state(fn (array $attributes) => [
|
||||
'amount' => $this->faker->randomFloat(2, 50001, 200000),
|
||||
'amount_tier' => 'large',
|
||||
'requires_board_meeting' => true,
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Indicate that the document is an expense reimbursement.
|
||||
*/
|
||||
public function expenseReimbursement(): static
|
||||
{
|
||||
return $this->state(fn (array $attributes) => [
|
||||
'request_type' => 'expense_reimbursement',
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Indicate that the document is an advance payment.
|
||||
*/
|
||||
public function advancePayment(): static
|
||||
{
|
||||
return $this->state(fn (array $attributes) => [
|
||||
'request_type' => 'advance_payment',
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Indicate that the document is a purchase request.
|
||||
*/
|
||||
public function purchaseRequest(): static
|
||||
{
|
||||
return $this->state(fn (array $attributes) => [
|
||||
'request_type' => 'purchase_request',
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Indicate that the document is petty cash.
|
||||
*/
|
||||
public function pettyCash(): static
|
||||
{
|
||||
return $this->state(fn (array $attributes) => [
|
||||
'request_type' => 'petty_cash',
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Indicate that payment order has been created.
|
||||
*/
|
||||
public function withPaymentOrder(): static
|
||||
{
|
||||
return $this->state(fn (array $attributes) => [
|
||||
'payment_order_created_at' => now(),
|
||||
'payment_order_created_by_id' => User::factory(),
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Indicate that payment has been executed.
|
||||
*/
|
||||
public function paymentExecuted(): static
|
||||
{
|
||||
return $this->state(fn (array $attributes) => [
|
||||
'payment_order_created_at' => now(),
|
||||
'payment_verified_at' => now(),
|
||||
'payment_executed_at' => now(),
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine amount tier based on amount.
|
||||
*/
|
||||
protected function determineAmountTier(float $amount): string
|
||||
{
|
||||
if ($amount < 5000) {
|
||||
return 'small';
|
||||
} elseif ($amount <= 50000) {
|
||||
return 'medium';
|
||||
} else {
|
||||
return 'large';
|
||||
}
|
||||
}
|
||||
}
|
||||
152
database/factories/PaymentOrderFactory.php
Normal file
152
database/factories/PaymentOrderFactory.php
Normal file
@@ -0,0 +1,152 @@
|
||||
<?php
|
||||
|
||||
namespace Database\Factories;
|
||||
|
||||
use App\Models\FinanceDocument;
|
||||
use App\Models\PaymentOrder;
|
||||
use App\Models\User;
|
||||
use Illuminate\Database\Eloquent\Factories\Factory;
|
||||
|
||||
/**
|
||||
* @extends \Illuminate\Database\Eloquent\Factories\Factory<\App\Models\PaymentOrder>
|
||||
*/
|
||||
class PaymentOrderFactory extends Factory
|
||||
{
|
||||
protected $model = PaymentOrder::class;
|
||||
|
||||
/**
|
||||
* Define the model's default state.
|
||||
*
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
public function definition(): array
|
||||
{
|
||||
$paymentMethods = ['cash', 'check', 'bank_transfer'];
|
||||
$paymentMethod = $this->faker->randomElement($paymentMethods);
|
||||
|
||||
$attributes = [
|
||||
'finance_document_id' => FinanceDocument::factory(),
|
||||
'payment_order_number' => PaymentOrder::generatePaymentOrderNumber(),
|
||||
'payee_name' => $this->faker->name(),
|
||||
'payment_amount' => $this->faker->randomFloat(2, 100, 50000),
|
||||
'payment_method' => $paymentMethod,
|
||||
'status' => 'pending_verification',
|
||||
'verification_status' => 'pending',
|
||||
'execution_status' => 'pending',
|
||||
'created_by_accountant_id' => User::factory(),
|
||||
];
|
||||
|
||||
// Add bank details for bank transfers
|
||||
if ($paymentMethod === 'bank_transfer') {
|
||||
$attributes['payee_bank_name'] = $this->faker->company() . ' Bank';
|
||||
$attributes['payee_bank_code'] = $this->faker->numerify('###');
|
||||
$attributes['payee_account_number'] = $this->faker->numerify('##########');
|
||||
}
|
||||
|
||||
return $attributes;
|
||||
}
|
||||
|
||||
/**
|
||||
* Indicate that the payment order is pending verification.
|
||||
*/
|
||||
public function pendingVerification(): static
|
||||
{
|
||||
return $this->state(fn (array $attributes) => [
|
||||
'status' => 'pending_verification',
|
||||
'verification_status' => 'pending',
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Indicate that the payment order is verified.
|
||||
*/
|
||||
public function verified(): static
|
||||
{
|
||||
return $this->state(fn (array $attributes) => [
|
||||
'status' => 'verified',
|
||||
'verification_status' => 'approved',
|
||||
'verified_by_cashier_id' => User::factory(),
|
||||
'verified_at' => now(),
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Indicate that the payment order is rejected during verification.
|
||||
*/
|
||||
public function rejectedDuringVerification(): static
|
||||
{
|
||||
return $this->state(fn (array $attributes) => [
|
||||
'status' => 'pending_verification',
|
||||
'verification_status' => 'rejected',
|
||||
'verified_by_cashier_id' => User::factory(),
|
||||
'verified_at' => now(),
|
||||
'verification_notes' => $this->faker->sentence(10),
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Indicate that the payment order is executed.
|
||||
*/
|
||||
public function executed(): static
|
||||
{
|
||||
return $this->state(fn (array $attributes) => [
|
||||
'status' => 'executed',
|
||||
'verification_status' => 'approved',
|
||||
'execution_status' => 'completed',
|
||||
'verified_by_cashier_id' => User::factory(),
|
||||
'verified_at' => now()->subHours(2),
|
||||
'executed_by_cashier_id' => User::factory(),
|
||||
'executed_at' => now(),
|
||||
'transaction_reference' => 'TXN' . $this->faker->numerify('##########'),
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Indicate that the payment order is cancelled.
|
||||
*/
|
||||
public function cancelled(): static
|
||||
{
|
||||
return $this->state(fn (array $attributes) => [
|
||||
'status' => 'cancelled',
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Indicate that the payment method is cash.
|
||||
*/
|
||||
public function cash(): static
|
||||
{
|
||||
return $this->state(fn (array $attributes) => [
|
||||
'payment_method' => 'cash',
|
||||
'payee_bank_name' => null,
|
||||
'payee_bank_code' => null,
|
||||
'payee_account_number' => null,
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Indicate that the payment method is check.
|
||||
*/
|
||||
public function check(): static
|
||||
{
|
||||
return $this->state(fn (array $attributes) => [
|
||||
'payment_method' => 'check',
|
||||
'payee_bank_name' => null,
|
||||
'payee_bank_code' => null,
|
||||
'payee_account_number' => null,
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Indicate that the payment method is bank transfer.
|
||||
*/
|
||||
public function bankTransfer(): static
|
||||
{
|
||||
return $this->state(fn (array $attributes) => [
|
||||
'payment_method' => 'bank_transfer',
|
||||
'payee_bank_name' => $this->faker->company() . ' Bank',
|
||||
'payee_bank_code' => $this->faker->numerify('###'),
|
||||
'payee_account_number' => $this->faker->numerify('##########'),
|
||||
]);
|
||||
}
|
||||
}
|
||||
44
database/factories/UserFactory.php
Normal file
44
database/factories/UserFactory.php
Normal file
@@ -0,0 +1,44 @@
|
||||
<?php
|
||||
|
||||
namespace Database\Factories;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\Factory;
|
||||
use Illuminate\Support\Facades\Hash;
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
/**
|
||||
* @extends \Illuminate\Database\Eloquent\Factories\Factory<\App\Models\User>
|
||||
*/
|
||||
class UserFactory extends Factory
|
||||
{
|
||||
/**
|
||||
* The current password being used by the factory.
|
||||
*/
|
||||
protected static ?string $password;
|
||||
|
||||
/**
|
||||
* Define the model's default state.
|
||||
*
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
public function definition(): array
|
||||
{
|
||||
return [
|
||||
'name' => fake()->name(),
|
||||
'email' => fake()->unique()->safeEmail(),
|
||||
'email_verified_at' => now(),
|
||||
'password' => static::$password ??= Hash::make('password'),
|
||||
'remember_token' => Str::random(10),
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Indicate that the model's email address should be unverified.
|
||||
*/
|
||||
public function unverified(): static
|
||||
{
|
||||
return $this->state(fn (array $attributes) => [
|
||||
'email_verified_at' => null,
|
||||
]);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user