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.

TaxFactory.php 1.3KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. <?php
  2. namespace Database\Factories;
  3. use App\Models\Setting\Tax;
  4. use Illuminate\Database\Eloquent\Factories\Factory;
  5. /**
  6. * @extends Factory<Tax>
  7. */
  8. class TaxFactory extends Factory
  9. {
  10. /**
  11. * The name of the factory's corresponding model.
  12. *
  13. * @var string
  14. */
  15. protected $model = Tax::class;
  16. /**
  17. * Define the model's default state.
  18. *
  19. * @return array<string, mixed>
  20. */
  21. public function definition(): array
  22. {
  23. // Common fields
  24. return [
  25. 'description' => $this->faker->sentence,
  26. 'rate' => $this->faker->randomFloat(4, 0, 20),
  27. 'computation' => $this->faker->randomElement(Tax::getComputationTypes()),
  28. 'scope' => $this->faker->randomElement(Tax::getTaxScopes()),
  29. 'enabled' => true,
  30. ];
  31. }
  32. public function salesTax(): self
  33. {
  34. return $this->state(function (array $attributes) {
  35. return [
  36. 'name' => 'State Sales Tax',
  37. 'type' => 'sales',
  38. ];
  39. });
  40. }
  41. public function purchaseTax(): self
  42. {
  43. return $this->state(function (array $attributes) {
  44. return [
  45. 'name' => 'State Purchase Tax',
  46. 'type' => 'purchase',
  47. ];
  48. });
  49. }
  50. }