*/ class PaymentOrderFactory extends Factory { protected $model = PaymentOrder::class; /** * Define the model's default state. * * @return array */ 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('##########'), ]); } }