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

2025_05_19_220944_update_transaction_payeeables.php 1.1KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. <?php
  2. use App\Models\Accounting\Bill;
  3. use App\Models\Accounting\Invoice;
  4. use App\Models\Accounting\Transaction;
  5. use App\Models\Common\Client;
  6. use App\Models\Common\Vendor;
  7. use Illuminate\Database\Migrations\Migration;
  8. return new class extends Migration
  9. {
  10. /**
  11. * Run the migrations.
  12. */
  13. public function up(): void
  14. {
  15. $transactions = Transaction::query()
  16. ->withoutGlobalScopes()
  17. ->whereNotNull('transactionable_id')
  18. ->whereNull('payeeable_id')
  19. ->with('transactionable')
  20. ->get();
  21. foreach ($transactions as $transaction) {
  22. $document = $transaction->transactionable;
  23. if ($document instanceof Invoice) {
  24. $transaction->payeeable_id = $document->client_id;
  25. $transaction->payeeable_type = Client::class;
  26. $transaction->saveQuietly();
  27. } elseif ($document instanceof Bill) {
  28. $transaction->payeeable_id = $document->vendor_id;
  29. $transaction->payeeable_type = Vendor::class;
  30. $transaction->saveQuietly();
  31. }
  32. }
  33. }
  34. };