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.

DocumentDefaultFactory.php 2.1KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. <?php
  2. namespace Database\Factories\Setting;
  3. use App\Enums\Accounting\DocumentType;
  4. use App\Enums\Setting\Font;
  5. use App\Enums\Setting\Template;
  6. use App\Models\Setting\DocumentDefault;
  7. use Illuminate\Database\Eloquent\Factories\Factory;
  8. /**
  9. * @extends Factory<DocumentDefault>
  10. */
  11. class DocumentDefaultFactory extends Factory
  12. {
  13. /**
  14. * The name of the factory's corresponding model.
  15. *
  16. * @var string
  17. */
  18. protected $model = DocumentDefault::class;
  19. /**
  20. * Define the model's default state.
  21. *
  22. * @return array<string, mixed>
  23. */
  24. public function definition(): array
  25. {
  26. return [
  27. 'company_id' => 1,
  28. 'payment_terms' => 'due_upon_receipt',
  29. ];
  30. }
  31. /**
  32. * The model's common default state.
  33. */
  34. private function baseState(DocumentType $type): array
  35. {
  36. $state = [
  37. 'type' => $type,
  38. 'number_prefix' => $type->getDefaultPrefix(),
  39. 'item_name' => ['option' => 'items', 'custom' => null],
  40. 'unit_name' => ['option' => 'quantity', 'custom' => null],
  41. 'price_name' => ['option' => 'price', 'custom' => null],
  42. 'amount_name' => ['option' => 'amount', 'custom' => null],
  43. ];
  44. if ($type !== DocumentType::Bill) {
  45. $state = [...$state,
  46. 'header' => $type->getLabel(),
  47. 'show_logo' => false,
  48. 'accent_color' => '#4F46E5',
  49. 'font' => Font::Inter,
  50. 'template' => Template::Default,
  51. ];
  52. }
  53. return $state;
  54. }
  55. /**
  56. * Indicate that the model's type is invoice.
  57. */
  58. public function invoice(): self
  59. {
  60. return $this->state($this->baseState(DocumentType::Invoice));
  61. }
  62. /**
  63. * Indicate that the model's type is bill.
  64. */
  65. public function bill(): self
  66. {
  67. return $this->state($this->baseState(DocumentType::Bill));
  68. }
  69. /**
  70. * Indicate that the model's type is estimate.
  71. */
  72. public function estimate(): self
  73. {
  74. return $this->state($this->baseState(DocumentType::Estimate));
  75. }
  76. }