Files
usher-manage-stack/database/factories/FinanceDocumentFactory.php
gbanyan 42099759e8 Add phone login support and member import functionality
Features:
- Support login via phone number or email (LoginRequest)
- Add members:import-roster command for Excel roster import
- Merge survey emails with roster data

Code Quality (Phase 1-4):
- Add database locking for balance calculation
- Add self-approval checks for finance workflow
- Create service layer (FinanceDocumentApprovalService, PaymentVerificationService)
- Add HasAccountingEntries and HasApprovalWorkflow traits
- Create FormRequest classes for validation
- Add status-badge component
- Define authorization gates in AuthServiceProvider
- Add accounting config file

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-25 03:08:06 +08:00

206 lines
6.3 KiB
PHP

<?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
{
return [
'title' => $this->faker->sentence(6),
'description' => $this->faker->paragraph(3),
'amount' => $this->faker->randomFloat(2, 100, 100000),
'status' => FinanceDocument::STATUS_PENDING,
'submitted_by_user_id' => User::factory(),
'submitted_at' => now(),
'amount_tier' => null,
'requires_board_meeting' => false,
];
}
public function configure()
{
return $this->afterMaking(function (FinanceDocument $document) {
$document->amount_tier = $document->determineAmountTier();
$document->requires_board_meeting = $document->needsBoardMeetingApproval();
})->afterCreating(function (FinanceDocument $document) {
$document->amount_tier = $document->determineAmountTier();
$document->requires_board_meeting = $document->needsBoardMeetingApproval();
$document->save();
});
}
/**
* Indicate that the document is pending approval.
*/
public function pending(): static
{
return $this->state(fn (array $attributes) => [
'status' => FinanceDocument::STATUS_PENDING,
]);
}
/**
* Indicate that the document is approved by secretary (first stage).
*/
public function approvedBySecretary(): static
{
return $this->state(fn (array $attributes) => [
'status' => FinanceDocument::STATUS_APPROVED_SECRETARY,
'approved_by_secretary_id' => User::factory(),
'secretary_approved_at' => now(),
]);
}
/**
* Indicate that the document is approved by chair (second stage).
*/
public function approvedByChair(): static
{
return $this->state(fn (array $attributes) => [
'status' => FinanceDocument::STATUS_APPROVED_CHAIR,
'approved_by_secretary_id' => User::factory(),
'secretary_approved_at' => now(),
'approved_by_chair_id' => User::factory(),
'chair_approved_at' => now(),
]);
}
/**
* Indicate that the document is approved by board (third stage - large amounts).
*/
public function approvedByBoard(): static
{
return $this->state(fn (array $attributes) => [
'status' => FinanceDocument::STATUS_APPROVED_BOARD,
'approved_by_secretary_id' => User::factory(),
'secretary_approved_at' => now(),
'approved_by_chair_id' => User::factory(),
'chair_approved_at' => now(),
'board_meeting_approved_by_id' => User::factory(),
'board_meeting_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' => FinanceDocument::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' => FinanceDocument::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' => FinanceDocument::AMOUNT_TIER_LARGE,
'requires_board_meeting' => true,
]);
}
/**
* 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_accountant_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(),
]);
}
/**
* Indicate that disbursement is complete (both confirmations).
*/
public function disbursementComplete(): static
{
return $this->state(fn (array $attributes) => [
'requester_confirmed_at' => now(),
'requester_confirmed_by_id' => User::factory(),
'cashier_confirmed_at' => now(),
'cashier_confirmed_by_id' => User::factory(),
'disbursement_status' => FinanceDocument::DISBURSEMENT_COMPLETED,
]);
}
/**
* Indicate that recording is complete.
*/
public function recordingComplete(): static
{
return $this->state(fn (array $attributes) => [
'accountant_recorded_at' => now(),
'accountant_recorded_by_id' => User::factory(),
'recording_status' => FinanceDocument::RECORDING_COMPLETED,
]);
}
/**
* Create a fully processed document (all stages complete).
*/
public function fullyProcessed(): static
{
return $this->approvedBySecretary()
->disbursementComplete()
->recordingComplete();
}
}