mirror of
https://gitlab.com/uldvstar/exchange-2.0.git
synced 2026-08-19 12:34:24 +00:00
37 lines
1.1 KiB
PHP
37 lines
1.1 KiB
PHP
<?php
|
|
|
|
use App\Models\Transaction;
|
|
use App\Classes\ValueObjects\Constants\TransactionType;
|
|
|
|
use Illuminate\Database\Seeder;
|
|
use Illuminate\Support\Facades\DB;
|
|
|
|
class UpdateTransactionBillOwnerSeeder extends Seeder
|
|
{
|
|
/**
|
|
* Run the database seeds.
|
|
*
|
|
* @return void
|
|
*/
|
|
public function run()
|
|
{
|
|
DB::beginTransaction();
|
|
|
|
$transaction = Transaction::where('type', TransactionType::BILL)->get();
|
|
|
|
foreach ($transaction as $key => $row) {
|
|
$key = 0;
|
|
$bills = $row->booking->transactions()->bills()->where('original_amount', '=', $row->original_amount)->get();
|
|
if(count($bills) > 1){ $key = $bills->search(function($bill)use($row){ return $bill->id === $row->id; }); }
|
|
$paymentTransaction = $row->booking->transactions()->payments()->complete()->where('original_amount', '=', $row->original_amount)->skip($key)->first();
|
|
|
|
$row->owner_type = Transaction::class;
|
|
$row->owner_id = $paymentTransaction->id;
|
|
$row->updated_at = $row->updated_at;
|
|
$row->update();
|
|
}
|
|
|
|
DB::commit();
|
|
}
|
|
}
|