transaction bill

This commit is contained in:
glovetleong
2022-01-13 22:49:02 +08:00
parent 70adbae1d4
commit f56369d707
6 changed files with 63 additions and 9 deletions
@@ -0,0 +1,42 @@
<?php
use App\Models\Transaction;
use App\Classes\ValueObjects\Constants\TransactionType;
use Illuminate\Database\Seeder;
use Illuminate\Support\Facades\DB;
class UpdateTransactionBillOwnerSeeder extends Seeder
{
/**
* StatesTableSeeder constructor.
* @param FetchesCountry $fetchesCountry
*/
public function __construct()
{
}
/**
* Run the database seeds.
*
* @return void
*/
public function run()
{
DB::beginTransaction();
$transaction = Transaction::where('type', TransactionType::BILL)->get();
foreach ($transaction as $key => $row) {
$booking = $row->booking()->first();
$payment_trsanction = $row->booking()->first()->transactions()->payments()->complete()->where('original_amount', '=', $row->original_amount)->where('id', '<', $row->id)->orderByDesc('id')->first();
$row->owner_type = 'App\Models\Transaction';
$row->owner_id = $payment_trsanction->id;
$row->update();
}
DB::commit();
}
}