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(); 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++; } } $end = new Carbon(); $elapsedTime = $start->diff($end)->format('%H:%I:%S'); $this->info(Carbon::now() . ' : Done Audit Billplz. ElapsedTime: ' . $elapsedTime . '. Total: ' . $totalAmount); } }