You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

TransactionFactory.php 2.2KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. <?php
  2. namespace Database\Factories\Accounting;
  3. use App\Models\Accounting\Transaction;
  4. use Illuminate\Database\Eloquent\Factories\Factory;
  5. /**
  6. * @extends Factory<Transaction>
  7. */
  8. class TransactionFactory extends Factory
  9. {
  10. /**
  11. * Define the model's default state.
  12. *
  13. * @return array<string, mixed>
  14. */
  15. public function definition(): array
  16. {
  17. return [
  18. 'company_id' => 1,
  19. 'account_id' => $this->faker->numberBetween(1, 30),
  20. 'bank_account_id' => 1,
  21. 'type' => $this->faker->randomElement(['deposit', 'withdrawal', 'journal']),
  22. 'payment_channel' => $this->faker->randomElement(['online', 'in store', 'other']),
  23. 'description' => $this->faker->sentence,
  24. 'notes' => $this->faker->paragraph,
  25. 'reference' => $this->faker->word,
  26. 'amount' => $this->faker->numberBetween(100, 5000),
  27. 'pending' => $this->faker->boolean,
  28. 'reviewed' => $this->faker->boolean,
  29. 'posted_at' => $this->faker->dateTimeBetween('-2 years'),
  30. 'created_by' => 1,
  31. 'updated_by' => 1,
  32. ];
  33. }
  34. public function configure(): static
  35. {
  36. return $this->afterCreating(function (Transaction $transaction) {
  37. $transaction->journalEntries()->create([
  38. 'company_id' => $transaction->company_id,
  39. 'account_id' => $transaction->account_id,
  40. 'transaction_id' => $transaction->id,
  41. 'type' => 'debit',
  42. 'amount' => $transaction->amount,
  43. 'description' => $transaction->description,
  44. 'created_by' => $transaction->created_by,
  45. 'updated_by' => $transaction->updated_by,
  46. ]);
  47. $transaction->journalEntries()->create([
  48. 'company_id' => $transaction->company_id,
  49. 'account_id' => $transaction->account_id,
  50. 'transaction_id' => $transaction->id,
  51. 'type' => 'credit',
  52. 'amount' => $transaction->amount,
  53. 'description' => $transaction->description,
  54. 'created_by' => $transaction->created_by,
  55. 'updated_by' => $transaction->updated_by,
  56. ]);
  57. });
  58. }
  59. }