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ů.

TaxFactory.php 1.6KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. <?php
  2. namespace Database\Factories\Setting;
  3. use App\Enums\Setting\TaxComputation;
  4. use App\Enums\Setting\TaxScope;
  5. use App\Enums\Setting\TaxType;
  6. use App\Models\Setting\Tax;
  7. use Illuminate\Database\Eloquent\Factories\Factory;
  8. /**
  9. * @extends Factory<Tax>
  10. */
  11. class TaxFactory extends Factory
  12. {
  13. /**
  14. * The name of the factory's corresponding model.
  15. */
  16. protected $model = Tax::class;
  17. /**
  18. * Define the model's default state.
  19. *
  20. * @return array<string, mixed>
  21. */
  22. public function definition(): array
  23. {
  24. $computation = $this->faker->randomElement(TaxComputation::class);
  25. if ($computation === TaxComputation::Fixed) {
  26. $rate = $this->faker->biasedNumberBetween(1, 10) * 100; // $1 - $10
  27. } else {
  28. $rate = $this->faker->biasedNumberBetween(3, 25) * 10000; // 3% - 25%
  29. }
  30. return [
  31. 'name' => $this->faker->unique()->word,
  32. 'description' => $this->faker->sentence,
  33. 'rate' => $rate,
  34. 'computation' => $computation,
  35. 'type' => $this->faker->randomElement(TaxType::class),
  36. 'scope' => $this->faker->randomElement(TaxScope::class),
  37. 'enabled' => false,
  38. ];
  39. }
  40. public function salesTax(): self
  41. {
  42. return $this->state([
  43. 'name' => 'State Sales Tax',
  44. 'type' => TaxType::Sales,
  45. ]);
  46. }
  47. public function purchaseTax(): self
  48. {
  49. return $this->state([
  50. 'name' => 'State Purchase Tax',
  51. 'type' => TaxType::Purchase,
  52. ]);
  53. }
  54. }