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.

TaxSeeder.php 1.8KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. <?php
  2. namespace Database\Seeders;
  3. use App\Models\Setting\Tax;
  4. use Illuminate\Database\Seeder;
  5. use Illuminate\Support\Facades\DB;
  6. class TaxSeeder extends Seeder
  7. {
  8. /**
  9. * Run the database seeds.
  10. */
  11. public function run(): void
  12. {
  13. $companyId = DB::table('companies')->first()->id;
  14. $userId = DB::table('users')->first()->id;
  15. $salesTaxes = [
  16. 'Goods and Services Tax (GST)',
  17. 'Value Added Tax (VAT)',
  18. 'State Sales Tax',
  19. 'Local Sales Tax',
  20. 'Excise Tax',
  21. ];
  22. $purchaseTaxes = [
  23. 'Import Duty',
  24. 'Customs Duty',
  25. 'Value Added Tax (VAT)',
  26. 'Luxury Tax',
  27. 'Environmental Tax',
  28. ];
  29. // Merge and shuffle the sales and purchase taxes
  30. $shuffledTaxes = [
  31. ...array_map(static fn($name) => ['name' => $name, 'type' => 'sales'], $salesTaxes),
  32. ...array_map(static fn($name) => ['name' => $name, 'type' => 'purchase'], $purchaseTaxes)
  33. ];
  34. shuffle($shuffledTaxes);
  35. $allTaxes = $shuffledTaxes;
  36. foreach ($allTaxes as $tax) {
  37. Tax::factory()->create([
  38. 'company_id' => $companyId,
  39. 'name' => $tax['name'],
  40. 'type' => $tax['type'],
  41. 'enabled' => false,
  42. 'created_by' => $userId,
  43. 'updated_by' => $userId,
  44. ]);
  45. }
  46. // Set the first sales tax as enabled
  47. Tax::where('type', 'sales')
  48. ->where('company_id', $companyId)
  49. ->first()
  50. ->update(['enabled' => true]);
  51. // Set the first purchase tax as enabled
  52. Tax::where('type', 'purchase')
  53. ->where('company_id', $companyId)
  54. ->first()
  55. ->update(['enabled' => true]);
  56. }
  57. }