From 56d64b35a18b199153f47034134bd6925f15ffd9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Batuhan=20Ba=C5=9F?= Date: Wed, 10 Oct 2018 18:04:10 +0300 Subject: [PATCH 1/2] Show outstanding in customer/vendor list #89 --- app/Models/Expense/Vendor.php | 12 +++++++++--- app/Models/Income/Customer.php | 12 +++++++++--- resources/lang/en-GB/general.php | 1 + resources/views/expenses/vendors/index.blade.php | 6 +++--- resources/views/incomes/customers/index.blade.php | 6 +++--- 5 files changed, 25 insertions(+), 12 deletions(-) diff --git a/app/Models/Expense/Vendor.php b/app/Models/Expense/Vendor.php index 5af0b8eca..6a425914e 100644 --- a/app/Models/Expense/Vendor.php +++ b/app/Models/Expense/Vendor.php @@ -71,10 +71,16 @@ class Vendor extends Model return $this->getMedia('logo')->last(); } - public function getAmountAttribute() + public function getUnpaidAttribute() { - $invoice_total = $this->bills()->notPaid()->sum('amount'); + $amount = 0; + $bills = $this->bills()->accrued()->notPaid()->get(); - return $invoice_total; + foreach ($bills as $bill) { + + $bill_amount = $bill->amount - $bill->paid; + $amount += $this->dynamicConvert(setting('general.default_currency'), $bill_amount, $bill->currency_code, $bill->currency_rate, false); + } + return $amount; } } diff --git a/app/Models/Income/Customer.php b/app/Models/Income/Customer.php index 175f08c4b..cfd988796 100644 --- a/app/Models/Income/Customer.php +++ b/app/Models/Income/Customer.php @@ -65,10 +65,16 @@ class Customer extends Model $this->user_id = null; } - public function getAmountAttribute() + public function getUnpaidAttribute() { - $invoice_total = $this->invoices()->notPaid()->sum('amount'); + $amount = 0; + $invoices = $this->invoices()->accrued()->notPaid()->get(); - return $invoice_total; + foreach ($invoices as $invoice) { + + $invoice_amount = $invoice->amount - $invoice->paid; + $amount += $this->dynamicConvert(setting('general.default_currency'), $invoice_amount, $invoice->currency_code, $invoice->currency_rate, false); + } + return $amount; } } diff --git a/resources/lang/en-GB/general.php b/resources/lang/en-GB/general.php index daee66c9d..713ace6cc 100644 --- a/resources/lang/en-GB/general.php +++ b/resources/lang/en-GB/general.php @@ -106,6 +106,7 @@ return [ 'disable' => 'Disable', 'select_all' => 'Select All', 'unselect_all' => 'Unselect All', + 'outstanding' => 'Outstanding', 'title' => [ 'new' => 'New :type', 'edit' => 'Edit :type', diff --git a/resources/views/expenses/vendors/index.blade.php b/resources/views/expenses/vendors/index.blade.php index 48d0f5e7e..05f4e7c40 100644 --- a/resources/views/expenses/vendors/index.blade.php +++ b/resources/views/expenses/vendors/index.blade.php @@ -33,10 +33,10 @@ - + - + @@ -47,7 +47,7 @@ - +
@sortablelink('name', trans('general.name'))@sortablelink('name', trans('general.name')) @sortablelink('phone', trans('general.phone')) {{ trans('general.actions') }}
{{ $item->name }} {{ $item->phone }}@money($item->amount, setting('general.default_currency'), true)@money($item->unpaid, setting('general.default_currency'), true)