mirror of
https://gitlab.com/CIEFWorldwideSdnBhd/exchange-2.0.git
synced 2026-08-19 04:23:55 +00:00
-fix expired booking command to ignore 1688 as 1688 may not have PO initally
-create command to revert those fully refunded payment transaction from status EXPIRED to REFUNDED
This commit is contained in:
@@ -51,11 +51,12 @@ class ExpiredBookingCommand extends Command
|
||||
// 1. Cancel booking without payment & purchase order (1 month)
|
||||
$bookings = Booking::where('status', ApprovalStatus::APPROVED)
|
||||
->where('created_at', '<', now()->subDays(30)->endOfDay())
|
||||
->where('service_id', '!=', 4)
|
||||
->where(function ($query) {
|
||||
$query->whereDoesntHave('transactions')
|
||||
->orWhereDoesntHave('transactions', function($transaction) {
|
||||
return $transaction->where('type', TransactionType::PURCHASE_ORDER)->orWhere(function ($q) {
|
||||
$q->where('type', TransactionType::PAYMENT)->whereIn('status', [ApprovalStatus::APPROVED, ApprovalStatus::COMPLETED]);
|
||||
$q->where('type', TransactionType::PAYMENT)->whereIn('status', [ApprovalStatus::APPROVED, ApprovalStatus::COMPLETED, ApprovalStatus::REFUNDED]);
|
||||
});
|
||||
});
|
||||
})->get();
|
||||
@@ -78,7 +79,7 @@ class ExpiredBookingCommand extends Command
|
||||
->where('created_at', '<', now()->subDays(60)->endOfDay())
|
||||
->where(function ($query) {
|
||||
$query->whereDoesntHave('transactions', function($transaction) {
|
||||
return $transaction->where('type', TransactionType::PAYMENT)->whereIn('status', [ApprovalStatus::APPROVED, ApprovalStatus::COMPLETED]);
|
||||
return $transaction->where('type', TransactionType::PAYMENT)->whereIn('status', [ApprovalStatus::APPROVED, ApprovalStatus::COMPLETED, ApprovalStatus::REFUNDED]);
|
||||
})->whereHas('transactions', function($transaction) {
|
||||
return $transaction->where('type', TransactionType::PURCHASE_ORDER);
|
||||
});
|
||||
|
||||
@@ -0,0 +1,67 @@
|
||||
<?php
|
||||
|
||||
namespace App\Console\Commands;
|
||||
|
||||
use App\Classes\ValueObjects\Constants\ApprovalStatus;
|
||||
use App\Classes\ValueObjects\Constants\TransactionType;
|
||||
use App\Models\Booking;
|
||||
use Illuminate\Console\Command;
|
||||
|
||||
class FixExpiredBookingWithRefundedPaymentTransactionCommand extends Command
|
||||
{
|
||||
/**
|
||||
* The name and signature of the console command.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $signature = 'expired_booking:fixExpiredPaymentTransaction';
|
||||
|
||||
/**
|
||||
* The console command description.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $description = 'Change the EXPIRED payment transaction of EXPIRED booking to REFUNDED if the payment transaction is fully refunded';
|
||||
|
||||
/**
|
||||
* Create a new command instance.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute the console command.
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
$bookings = Booking::where('status', ApprovalStatus::EXPIRED)->whereHas('transactions', function ($q) {
|
||||
$q->where('type', TransactionType::PAYMENT)->where('status', ApprovalStatus::EXPIRED)->whereHas('transactions', function ($q2) {
|
||||
$q2->where('type', TransactionType::REFUND)->whereIn('status', [ApprovalStatus::APPROVED, ApprovalStatus::COMPLETED]);
|
||||
});
|
||||
})->get();
|
||||
|
||||
foreach ($bookings as $booking) {
|
||||
$payment_transactions = $booking->transactions()->where('type', TransactionType::PAYMENT)->whereHas('transactions', function ($q2) {
|
||||
$q2->where('type', TransactionType::REFUND)->whereIn('status', [ApprovalStatus::APPROVED, ApprovalStatus::COMPLETED]);
|
||||
})->get();
|
||||
|
||||
foreach ($payment_transactions as $payment) {
|
||||
$payment_original_amount = $payment->original_amount;
|
||||
$refund_original_amount = $payment->transactions()->where('type', TransactionType::REFUND)->whereIn('status', [ApprovalStatus::APPROVED, ApprovalStatus::COMPLETED])->sum('original_amount');
|
||||
|
||||
if ($payment_original_amount - $refund_original_amount < 0.01) {
|
||||
$this->info("Updated booking id: $booking->id, payment transaction id: $payment->id, from EXPIRED to REFUNDED");
|
||||
|
||||
$payment->status = ApprovalStatus::REFUNDED;
|
||||
$payment->save();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -44,10 +44,10 @@ class Kernel extends ConsoleKernel
|
||||
->appendOutputTo(storage_path().'/logs/delete-bulk-download-files.log')
|
||||
->withoutOverlapping();
|
||||
|
||||
// $schedule->command('booking:expired')
|
||||
// ->dailyAt('02:00')
|
||||
// ->appendOutputTo(storage_path().'/logs/expire-booking.log')
|
||||
// ->withoutOverlapping();
|
||||
$schedule->command('booking:expired')
|
||||
->dailyAt('02:00')
|
||||
->appendOutputTo(storage_path().'/logs/expire-booking.log')
|
||||
->withoutOverlapping();
|
||||
|
||||
// $schedule->command('purchaseOrder:autoFill')
|
||||
// ->dailyAt('03:00')
|
||||
|
||||
Reference in New Issue
Block a user