Quellcode durchsuchen

Merge pull request #171 from andrewdwallo/development-3.x

Development 3.x
3.x
Andrew Wallo vor 4 Monaten
Ursprung
Commit
b6f305d558
Es ist kein Account mit der E-Mail-Adresse des Committers verbunden

+ 38
- 0
database/migrations/2025_05_19_220944_update_transaction_payeeables.php Datei anzeigen

@@ -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…
Abbrechen
Speichern