Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

AccountFactory.php 2.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. <?php
  2. namespace Database\Factories\Accounting;
  3. use App\Models\Accounting\Account;
  4. use App\Models\Accounting\AccountSubtype;
  5. use App\Models\Banking\BankAccount;
  6. use App\Models\Setting\Currency;
  7. use App\Utilities\Currency\CurrencyAccessor;
  8. use Illuminate\Database\Eloquent\Factories\Factory;
  9. /**
  10. * @extends Factory<Account>
  11. */
  12. class AccountFactory extends Factory
  13. {
  14. /**
  15. * The name of the factory's corresponding model.
  16. */
  17. protected $model = Account::class;
  18. /**
  19. * Define the model's default state.
  20. *
  21. * @return array<string, mixed>
  22. */
  23. public function definition(): array
  24. {
  25. return [
  26. 'company_id' => 1,
  27. 'subtype_id' => 1,
  28. 'name' => $this->faker->unique()->word,
  29. 'currency_code' => CurrencyAccessor::getDefaultCurrency() ?? 'USD',
  30. 'description' => $this->faker->sentence,
  31. 'archived' => false,
  32. 'default' => false,
  33. ];
  34. }
  35. public function withBankAccount(string $name): static
  36. {
  37. return $this->state(function (array $attributes) use ($name) {
  38. $bankAccount = BankAccount::factory()->create();
  39. $accountSubtype = AccountSubtype::where('name', 'Cash and Cash Equivalents')->first();
  40. return [
  41. 'bank_account_id' => $bankAccount->id,
  42. 'subtype_id' => $accountSubtype->id,
  43. 'name' => $name,
  44. ];
  45. });
  46. }
  47. public function withForeignBankAccount(string $name, string $currencyCode, float $rate): static
  48. {
  49. return $this->state(function (array $attributes) use ($currencyCode, $rate, $name) {
  50. $currency = Currency::factory()->forCurrency($currencyCode, $rate)->create();
  51. $bankAccount = BankAccount::factory()->create();
  52. $accountSubtype = AccountSubtype::where('name', 'Cash and Cash Equivalents')->first();
  53. return [
  54. 'bank_account_id' => $bankAccount->id,
  55. 'subtype_id' => $accountSubtype->id,
  56. 'name' => $name,
  57. 'currency_code' => $currency->code,
  58. ];
  59. });
  60. }
  61. }