From f6f06d7a40d71c36ce7896e2bd8c0bcb45446277 Mon Sep 17 00:00:00 2001 From: Prashant Singh Date: Fri, 28 Jun 2019 17:22:17 +0530 Subject: [PATCH] Updated credit max module --- .../Webkul/CustomerCreditMax/src/Listeners/Cart.php | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/packages/Webkul/CustomerCreditMax/src/Listeners/Cart.php b/packages/Webkul/CustomerCreditMax/src/Listeners/Cart.php index 25a6d7f55..1046067b5 100644 --- a/packages/Webkul/CustomerCreditMax/src/Listeners/Cart.php +++ b/packages/Webkul/CustomerCreditMax/src/Listeners/Cart.php @@ -55,14 +55,18 @@ class Cart return; $baseGrandTotal = $this->orderRepository->scopeQuery(function ($query) { - return $query->where('orders.customer_id', $this->getCurrentCustomerGuard()->user()->id); + return $query + ->where('orders.customer_id', '=', $this->getCurrentCustomerGuard()->user()->id) + ->where('orders.status', '<>', 'canceled'); })->sum('base_grand_total'); $baseGrandTotalInvoiced = $this->orderRepository->scopeQuery(function ($query) { - return $query->where('orders.customer_id', $this->getCurrentCustomerGuard()->user()->id); + return $query + ->where('orders.customer_id', $this->getCurrentCustomerGuard()->user()->id) + ->where('orders.status', '<>', 'canceled'); })->sum('base_grand_total_invoiced'); - if ( ($baseGrandTotal - $baseGrandTotalInvoiced) >= core()->getConfigData('customer.settings.credit_max.amount')) + if ( ($baseGrandTotal - $baseGrandTotalInvoiced) >= (core()->getConfigData('customer.settings.credit_max.amount') - ($baseGrandTotal - $baseGrandTotalInvoiced))) throw new \Exception('You available credit limit has been exceeded. Please you pay your pending invoice.'); } } \ No newline at end of file