Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

RecurringInvoiceFactory.php 3.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. <?php
  2. namespace Database\Factories\Accounting;
  3. use App\Enums\Accounting\DayOfMonth;
  4. use App\Enums\Accounting\DayOfWeek;
  5. use App\Enums\Accounting\EndType;
  6. use App\Enums\Accounting\Frequency;
  7. use App\Enums\Accounting\IntervalType;
  8. use App\Enums\Accounting\Month;
  9. use App\Enums\Accounting\RecurringInvoiceStatus;
  10. use App\Enums\Setting\PaymentTerms;
  11. use App\Models\Accounting\RecurringInvoice;
  12. use App\Models\Common\Client;
  13. use Illuminate\Database\Eloquent\Factories\Factory;
  14. use Illuminate\Support\Carbon;
  15. /**
  16. * @extends Factory<RecurringInvoice>
  17. */
  18. class RecurringInvoiceFactory extends Factory
  19. {
  20. /**
  21. * The name of the factory's corresponding model.
  22. */
  23. protected $model = RecurringInvoice::class;
  24. /**
  25. * Define the model's default state.
  26. *
  27. * @return array<string, mixed>
  28. */
  29. public function definition(): array
  30. {
  31. return [
  32. 'company_id' => 1,
  33. 'client_id' => Client::inRandomOrder()->value('id'),
  34. 'status' => RecurringInvoiceStatus::Draft,
  35. // Schedule configuration
  36. 'frequency' => Frequency::Monthly,
  37. 'day_of_month' => DayOfMonth::First,
  38. // Date configuration
  39. 'start_date' => now()->addMonth()->startOfMonth(),
  40. 'end_type' => EndType::Never,
  41. // Invoice configuration
  42. 'payment_terms' => PaymentTerms::DueUponReceipt,
  43. 'currency_code' => 'USD',
  44. // Timestamps and user tracking
  45. 'terms' => $this->faker->sentence,
  46. 'footer' => $this->faker->sentence,
  47. 'created_by' => 1,
  48. 'updated_by' => 1,
  49. ];
  50. }
  51. public function weekly(DayOfWeek $dayOfWeek = DayOfWeek::Monday): self
  52. {
  53. return $this->state([
  54. 'frequency' => Frequency::Weekly,
  55. 'day_of_week' => $dayOfWeek,
  56. ]);
  57. }
  58. public function monthly(DayOfMonth $dayOfMonth = DayOfMonth::First): self
  59. {
  60. return $this->state([
  61. 'frequency' => Frequency::Monthly,
  62. 'day_of_month' => $dayOfMonth,
  63. ]);
  64. }
  65. public function yearly(Month $month = Month::January, DayOfMonth $dayOfMonth = DayOfMonth::First): self
  66. {
  67. return $this->state([
  68. 'frequency' => Frequency::Yearly,
  69. 'month' => $month,
  70. 'day_of_month' => $dayOfMonth,
  71. ]);
  72. }
  73. public function custom(IntervalType $intervalType, int $intervalValue = 1): self
  74. {
  75. return $this->state([
  76. 'frequency' => Frequency::Custom,
  77. 'interval_type' => $intervalType,
  78. 'interval_value' => $intervalValue,
  79. ]);
  80. }
  81. public function withEndDate(Carbon $endDate): self
  82. {
  83. return $this->state([
  84. 'end_type' => EndType::On,
  85. 'end_date' => $endDate,
  86. ]);
  87. }
  88. public function withMaxOccurrences(int $maxOccurrences): self
  89. {
  90. return $this->state([
  91. 'end_type' => EndType::After,
  92. 'max_occurrences' => $maxOccurrences,
  93. ]);
  94. }
  95. public function autoSend(string $time = '09:00'): self
  96. {
  97. return $this->state([
  98. 'auto_send' => true,
  99. 'send_time' => $time,
  100. ]);
  101. }
  102. }