Bladeren bron

fix migration

3.x
Andrew Wallo 4 maanden geleden
bovenliggende
commit
50f20b1cd4
1 gewijzigde bestanden met toevoegingen van 38 en 0 verwijderingen
  1. 38
    0
      database/migrations/2025_05_19_220944_update_transaction_payeeables.php

+ 38
- 0
database/migrations/2025_05_19_220944_update_transaction_payeeables.php Bestand weergeven

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

Laden…
Annuleren
Opslaan