diff --git a/app/Console/Commands/AuditBillplzInvoice.php b/app/Console/Commands/AuditBillplzInvoice.php index 19c974d9..753905be 100644 --- a/app/Console/Commands/AuditBillplzInvoice.php +++ b/app/Console/Commands/AuditBillplzInvoice.php @@ -24,7 +24,7 @@ class AuditBillplzInvoice extends Command * * @var string */ - protected $description = 'Check all unpaid invoice but marked at paid at out system'; + protected $description = 'Check all unpaid invoice but marked paid at our system'; /** * Create a new command instance. diff --git a/app/Console/Commands/CheckDeletedInvoiceButPaid.php b/app/Console/Commands/CheckDeletedInvoiceButPaid.php new file mode 100644 index 00000000..e16edab1 --- /dev/null +++ b/app/Console/Commands/CheckDeletedInvoiceButPaid.php @@ -0,0 +1,83 @@ +info(Carbon::now() . ' : Start Check all deleted invoice but has completed payment.'); + $start = new Carbon(); + + $totalAmount = 0; + + $softDeletedTransactions = Transaction::onlyTrashed()->where('type', TransactionType::SHIPPING_INVOICE)->whereHas('transactions', function (Builder $query) { + $query->where('type', TransactionType::PAYMENT)->where('payment_method', PaymentMethodType::PAYMENT_GATEWAY); + })->get(); + + foreach ($softDeletedTransactions as $invoice) { + $invoice_payments = $invoice->transactions()->payments()->get(); + + foreach($invoice_payments as $invoice_payment) { + + $response = Http::withBasicAuth(config('billplz.api_key').':', '')->get(config('billplz.base_url').'/api/v3/bills/'.$invoice_payment->payment_reference); + + if($response->successful()){ + $data = $response->json(); + if($data['paid']){ + $this->info('Invoice id: ' . $invoice->id. '. Payment id: ' . $invoice_payment->id); + } else { + + } + }else{ + $this->info("billplz error"); + } + } + } + + $end = new Carbon(); + $elapsedTime = $start->diff($end)->format('%H:%I:%S'); + + $this->info(Carbon::now() . ' : Done Check all deleted invoice but has completed payment. ElapsedTime: ' . $elapsedTime . '. Total: ' . $totalAmount); + } +} diff --git a/routes/web.php b/routes/web.php index 71ab5f30..252f63cf 100644 --- a/routes/web.php +++ b/routes/web.php @@ -955,3 +955,45 @@ Route::get('/packing-lists/delete-duplicated', function(Request $request){ } } }); + +Route::get('/final-duplicated-invoice-debug', function(){ + $duplicatedTransactions = DB::table('transactions') + ->select(DB::raw('owner_type, owner_id, receiver, type, GROUP_CONCAT(id) as transaction_ids, COUNT(*) as count')) + ->groupBy('owner_type', 'owner_id', 'receiver', 'type') + ->having('count', '>', 1) + ->get(); + + $approvalStatusArray = ApprovalStatus::APPROVAL_STATUS_ID; + + + echo '
| Owner Type | +Owner Id | +Reveiver | +Transaction type | +Count | +Invoice Ids | +
|---|---|---|---|---|---|
| ' . $transaction->owner_type . ' | '; + echo '' . $transaction->owner_id . ' | '; + echo '' . $transaction->receiver . ' | '; + echo '' . $transaction->type . ' | '; + echo '' . count($transactionIds) . ' | '; + echo '';
+ foreach ($duplicatedInvoice as $invoice) {
+ echo ' ID: ' . $invoice->id . '. Status: ' . $approvalStatusArray[$invoice->status] . '. Amount: ' . $invoice->amount . '. Is_Deleted: ' . ($invoice->deleted_at ? 'true' : 'false') . ' '; + } + echo' | ';
+ echo '