From a17812be3b74f137a061e4bbce29de4bacebe5e6 Mon Sep 17 00:00:00 2001 From: edmondlang Date: Wed, 22 May 2024 23:22:44 +0800 Subject: [PATCH] check duplicate refunds --- .../Constants/TransactionType.php | 21 ++++- app/Http/Resources/BookingResource.php | 3 +- routes/web.php | 79 +++++++++++++++++++ 3 files changed, 101 insertions(+), 2 deletions(-) diff --git a/app/Classes/ValueObjects/Constants/TransactionType.php b/app/Classes/ValueObjects/Constants/TransactionType.php index e14930b0..09479729 100644 --- a/app/Classes/ValueObjects/Constants/TransactionType.php +++ b/app/Classes/ValueObjects/Constants/TransactionType.php @@ -38,4 +38,23 @@ final class TransactionType { public const BILL_REFUND = 16; -} + public const ID_TO_NAME = [ + self::PAYMENT_ATTEMPT => "PAYMENT_ATTEMPT", + self::PAYMENT => "PAYMENT", + self::INVOICE => "INVOICE", + self::BILL => "BILL", + self::PROFORMA => "PROFORMA", + self::TOP_UP => "TOP_UP", + self::REFUND => "REFUND", + self::PURCHASE_ORDER => "PURCHASE_ORDER", + self::SUPPLIER_DELIVER => "SUPPLIER_DELIVER", + self::CREDIT_NOTE => "CREDIT_NOTE", + self::DEBIT_NOTE => "DEBIT_NOTE", + self::WITHDRAW => "WITHDRAW", + self::TRANSFER_FEE => "TRANSFER_FEE", + self::CASH_BACK => "CASH_BACK", + self::SUPPLIER_PAYMENT => "SUPPLIER_PAYMENT", + self::SUPPLIER_REFUND => "SUPPLIER_REFUND", + ]; + + } diff --git a/app/Http/Resources/BookingResource.php b/app/Http/Resources/BookingResource.php index 6803eec9..2612c5b4 100644 --- a/app/Http/Resources/BookingResource.php +++ b/app/Http/Resources/BookingResource.php @@ -56,7 +56,8 @@ class BookingResource extends JsonResource ->whereDate('expires_on', '>=', Carbon::now()) ->get() ), - 'expired_payment_attempts' => TransactionResource::collection($this->transactions()->payments()->where('status', ApprovalStatus::PENDING_SUBMISSION)->whereDate('expires_on', '>=', Carbon::now())->where('expires_on', '>', Carbon::now()->toTimeString())->get()), + // 'expired_payment_attempts' => TransactionResource::collection($this->transactions()->payments()->where('status', ApprovalStatus::PENDING_SUBMISSION)->whereDate('expires_on', '>=', Carbon::now())->where('expires_on', '>', Carbon::now()->toTimeString())->get()), + 'expired_payment_attempts' => TransactionResource::collection($this->transactions()->payments()->where('status', ApprovalStatus::EXPIRED)->get()), 'payment_history' => TransactionResource::collection($this->transactions()->where(function($query){ $query->where(function($query){ $query->payments()->whereIn('status', [ApprovalStatus::APPROVED, ApprovalStatus::PENDING_VERIFICATION, ApprovalStatus::COMPLETED, ApprovalStatus::REJECTED, ApprovalStatus::REFUNDED]); diff --git a/routes/web.php b/routes/web.php index 6d92fce9..f0234e70 100644 --- a/routes/web.php +++ b/routes/web.php @@ -33,6 +33,7 @@ use App\Classes\Modules\Bookings\Services\CalculatesBookingRefundAmount; use App\Classes\Modules\Documents\Services\DeletesDocument; use App\Classes\Modules\Transactions\Processors\CreateInvoiceTransactionWithInvoiceNoProcessor; use App\Classes\Modules\Transactions\Services\DeletesTransaction; +use Illuminate\Support\Facades\DB; use Illuminate\Support\Facades\Log; @@ -1099,3 +1100,81 @@ Route::get('/show-white-form-transactions-in-date-range/{from_date}/{to_date}', echo ''; echo ''; }); + +Route::get('check-duplicate-refunds', function () { + $results = Transaction::select('payment_reference', 'owner_id', 'owner_type', 'type', 'status', 'amount', DB::raw('COUNT(*) as count')) + ->whereNotNull('payment_reference') + ->where('payment_reference', '<>', '') + ->where('payment_reference', '<>', 'Withdraw') + ->where('payment_reference', '<>', 'Refund for Ref. 77315') + ->whereNull('deleted_at') + ->groupBy('payment_reference', 'owner_id', 'owner_type', 'type', 'status', 'amount') + ->having(DB::raw('COUNT(*)'), '>', 1) + ->get(); + + $transactionType = TransactionType::ID_TO_NAME; + $approvalStatus = ApprovalStatus::APPROVAL_STATUS_ID; + + echo ''; + echo ''; + echo ''; + echo ''; + echo ''; + echo ''; + echo ''; + echo ''; + echo ''; + echo ''; + echo ''; + echo ''; + echo ''; + echo ''; + echo ''; + echo ''; + echo ''; + echo ''; + + foreach ($results as $result) { + $booking_ref_arr = explode(' ', $result->payment_reference); + $booking_ref = end($booking_ref_arr); + + echo ''; + echo ""; + echo ""; + echo ""; + $status = $transactionType[$result->type]; + echo ""; + $approvalsName = $approvalStatus[$result->status]; + echo ""; + echo ""; + echo ""; + + $click = null; + if ($result->owner_type == 'App\Models\Wallet') { + $click = ''.$result->owner->owner->reference.''; + } + echo ""; + + $booking_ref_click = null; + $payment = null; + $refund = null; + if ($booking_ref) { + $booking_ref_click = ''.$booking_ref.''; + + $booking = Booking::where('marking', $booking_ref)->first(); + $payment = $booking->transactions()->where('type', TransactionType::PAYMENT)->first(); + $refund = $payment->transactions()->where('type', TransactionType::REFUND)->get()->pluck('id')->toArray(); + $refund = implode(',', $refund); + } + echo ""; + echo ""; + echo ""; + echo ""; + echo ''; + + + } + echo ''; + echo '
Owner TypeOwner IDPayment ReferenceTypeStatusCountAmountWallet DetailsBooking RefPayment IDPayment StatusRefund ID
$result->owner_type$result->owner_id$result->payment_reference$status$approvalsName$result->count$result->amount". $click ."$booking_ref_click" . ($payment ? $payment->id : '') . "" . ($payment ? $approvalStatus[$payment->status] : '') . "" . ($refund ? $refund : '') . "
'; +}); +