From a36f7123e89e6e72b94f75fa4f74ed09142b887c Mon Sep 17 00:00:00 2001 From: edmondlang Date: Tue, 21 Mar 2023 12:56:53 +0800 Subject: [PATCH 1/3] audit billplz invoice --- app/Console/Commands/AuditBillplzInvoice.php | 73 +++++++++++++++++++ ...ditBillplz.php => AuditBillplzPayment.php} | 8 +- 2 files changed, 77 insertions(+), 4 deletions(-) create mode 100644 app/Console/Commands/AuditBillplzInvoice.php rename app/Console/Commands/{AuditBillplz.php => AuditBillplzPayment.php} (88%) diff --git a/app/Console/Commands/AuditBillplzInvoice.php b/app/Console/Commands/AuditBillplzInvoice.php new file mode 100644 index 00000000..919c0f71 --- /dev/null +++ b/app/Console/Commands/AuditBillplzInvoice.php @@ -0,0 +1,73 @@ +info(Carbon::now() . ' : Audit Billplz Invoice cron started.'); + $start = new Carbon(); + + $transactions = Transaction::where('type', TransactionType::SHIPPING_INVOICE)->where('status', ApprovalStatus::COMPLETED)->whereHas('transactions', function($query){ + return $query->where('type', TransactionType::PAYMENT)->where('payment_method', PaymentMethodType::PAYMENT_GATEWAY)->where('status', ApprovalStatus::REJECTED); + })->get(); + + $totalTransactions = count($transactions); + $counter = 1; + $totalAmount = 0; + foreach ($transactions as $transaction){ + $payment_transaction = $transaction->transactions->sortByDesc('created_at')->first(); + + $this->info($counter . ' of ' . $totalTransactions . '. Transaction Id: '. $payment_transaction->id . '. Invoice Id: '. $transaction->id . ' - Date: '.$payment_transaction->created_at->format('d-m-Y').' - Amount: '. $payment_transaction->amount); + + $totalAmount += $transaction->amount; + + $counter++; + } + + $end = new Carbon(); + $elapsedTime = $start->diff($end)->format('%H:%I:%S'); + + $this->info(Carbon::now() . ' : Done Audit Billplz. ElapsedTime: ' . $elapsedTime . '. Total: ' . $totalAmount); + } +} diff --git a/app/Console/Commands/AuditBillplz.php b/app/Console/Commands/AuditBillplzPayment.php similarity index 88% rename from app/Console/Commands/AuditBillplz.php rename to app/Console/Commands/AuditBillplzPayment.php index 77540087..871431ad 100644 --- a/app/Console/Commands/AuditBillplz.php +++ b/app/Console/Commands/AuditBillplzPayment.php @@ -10,21 +10,21 @@ use Carbon\Carbon; use Illuminate\Console\Command; use Illuminate\Support\Facades\Http; -class AuditBillplz extends Command +class AuditBillplzPayment extends Command { /** * The name and signature of the console command. * * @var string */ - protected $signature = 'billplz:audit'; + protected $signature = 'billplz-payment:audit'; /** * The console command description. * * @var string */ - protected $description = 'Audit Billplz'; + protected $description = 'Check all failed payment in billplz, but marked at success at our system'; /** * Create a new command instance. @@ -45,7 +45,7 @@ class AuditBillplz extends Command { ini_set('memory_limit', '-1'); - $this->info(Carbon::now() . ' : Audit Billplz cron started.'); + $this->info(Carbon::now() . ' : Audit Billplz Payment cron started.'); $start = new Carbon(); $transactions = Transaction::where('type', TransactionType::PAYMENT)->where('payment_method', PaymentMethodType::PAYMENT_GATEWAY)->whereIn('status', [ApprovalStatus::COMPLETED, ApprovalStatus::APPROVED])->get(); From 75babc9f382f1486e2fd05dd9df5681b5a63932a Mon Sep 17 00:00:00 2001 From: edmondlang Date: Tue, 21 Mar 2023 13:03:27 +0800 Subject: [PATCH 2/3] audit billplz invoice --- app/Console/Commands/AuditBillplzInvoice.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/Console/Commands/AuditBillplzInvoice.php b/app/Console/Commands/AuditBillplzInvoice.php index 919c0f71..b519b696 100644 --- a/app/Console/Commands/AuditBillplzInvoice.php +++ b/app/Console/Commands/AuditBillplzInvoice.php @@ -58,7 +58,7 @@ class AuditBillplzInvoice extends Command foreach ($transactions as $transaction){ $payment_transaction = $transaction->transactions->sortByDesc('created_at')->first(); - $this->info($counter . ' of ' . $totalTransactions . '. Transaction Id: '. $payment_transaction->id . '. Invoice Id: '. $transaction->id . ' - Date: '.$payment_transaction->created_at->format('d-m-Y').' - Amount: '. $payment_transaction->amount); + $this->info($counter . ' of ' . $totalTransactions . '. Order Marking: '. $payment_transaction->owner->owner->owner->reference . '. Transaction Id: '. $payment_transaction->id . '. Invoice Id: '. $transaction->id . ' - Date: '.$payment_transaction->created_at->format('d-m-Y').' - Amount: '. $payment_transaction->amount); $totalAmount += $transaction->amount; From fea03de5bd1fcc6995dc687b5be39289c42a21b5 Mon Sep 17 00:00:00 2001 From: edmondlang Date: Tue, 21 Mar 2023 13:08:05 +0800 Subject: [PATCH 3/3] audit billplz invoice --- app/Console/Commands/AuditBillplzInvoice.php | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/app/Console/Commands/AuditBillplzInvoice.php b/app/Console/Commands/AuditBillplzInvoice.php index b519b696..19c974d9 100644 --- a/app/Console/Commands/AuditBillplzInvoice.php +++ b/app/Console/Commands/AuditBillplzInvoice.php @@ -58,11 +58,13 @@ class AuditBillplzInvoice extends Command foreach ($transactions as $transaction){ $payment_transaction = $transaction->transactions->sortByDesc('created_at')->first(); - $this->info($counter . ' of ' . $totalTransactions . '. Order Marking: '. $payment_transaction->owner->owner->owner->reference . '. Transaction Id: '. $payment_transaction->id . '. Invoice Id: '. $transaction->id . ' - Date: '.$payment_transaction->created_at->format('d-m-Y').' - Amount: '. $payment_transaction->amount); + if ($payment_transaction->status === ApprovalStatus::REJECTED) { + $this->info($counter . ' of ' . $totalTransactions . '. Order Marking: '. $payment_transaction->owner->owner->owner->reference . '. Transaction Id: '. $payment_transaction->id . '. Invoice Id: '. $transaction->id . ' - Date: '.$payment_transaction->created_at->format('d-m-Y').' - Amount: '. $payment_transaction->amount); - $totalAmount += $transaction->amount; - - $counter++; + $totalAmount += $transaction->amount; + + $counter++; + } } $end = new Carbon();