|
@@ -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
|
+};
|