From 4980b299408a5a332dd8143f8867eb12cf9da047 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Batuhan=20Ba=C5=9F?= Date: Wed, 10 Oct 2018 18:18:15 +0300 Subject: [PATCH] Show unpaid column in customer/vendor list --- app/Models/Expense/Vendor.php | 7 +++++-- app/Models/Income/Customer.php | 7 +++++-- resources/lang/en-GB/general.php | 1 - resources/views/expenses/vendors/index.blade.php | 2 +- resources/views/incomes/customers/index.blade.php | 2 +- 5 files changed, 12 insertions(+), 7 deletions(-) diff --git a/app/Models/Expense/Vendor.php b/app/Models/Expense/Vendor.php index 6a425914e..541a4b307 100644 --- a/app/Models/Expense/Vendor.php +++ b/app/Models/Expense/Vendor.php @@ -4,12 +4,13 @@ namespace App\Models\Expense; use App\Models\Model; use Bkwld\Cloner\Cloneable; +use App\Traits\Currencies; use Sofa\Eloquence\Eloquence; use App\Traits\Media; class Vendor extends Model { - use Cloneable, Eloquence, Media; + use Cloneable, Currencies, Eloquence, Media; protected $table = 'vendors'; @@ -74,13 +75,15 @@ class Vendor extends Model public function getUnpaidAttribute() { $amount = 0; + $bills = $this->bills()->accrued()->notPaid()->get(); 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 cfd988796..9c7299445 100644 --- a/app/Models/Income/Customer.php +++ b/app/Models/Income/Customer.php @@ -4,12 +4,13 @@ namespace App\Models\Income; use App\Models\Model; use Bkwld\Cloner\Cloneable; +use App\Traits\Currencies; use Illuminate\Notifications\Notifiable; use Sofa\Eloquence\Eloquence; class Customer extends Model { - use Cloneable, Eloquence, Notifiable; + use Cloneable, Currencies, Eloquence, Notifiable; protected $table = 'customers'; @@ -68,13 +69,15 @@ class Customer extends Model public function getUnpaidAttribute() { $amount = 0; + $invoices = $this->invoices()->accrued()->notPaid()->get(); 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 713ace6cc..daee66c9d 100644 --- a/resources/lang/en-GB/general.php +++ b/resources/lang/en-GB/general.php @@ -106,7 +106,6 @@ 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 05f4e7c40..42dd09b56 100644 --- a/resources/views/expenses/vendors/index.blade.php +++ b/resources/views/expenses/vendors/index.blade.php @@ -36,7 +36,7 @@ @sortablelink('name', trans('general.name')) @sortablelink('email', trans('general.email')) @sortablelink('phone', trans('general.phone')) - @sortablelink('outstanding', trans('general.outstanding')) + @sortablelink('unpaid', trans('general.unpaid')) @sortablelink('enabled', trans_choice('general.statuses', 1)) {{ trans('general.actions') }} diff --git a/resources/views/incomes/customers/index.blade.php b/resources/views/incomes/customers/index.blade.php index 5636f8320..ec6d809c1 100644 --- a/resources/views/incomes/customers/index.blade.php +++ b/resources/views/incomes/customers/index.blade.php @@ -36,7 +36,7 @@ @sortablelink('name', trans('general.name')) @sortablelink('email', trans('general.email')) @sortablelink('phone', trans('general.phone')) - @sortablelink('outstanding', trans('general.outstanding')) + @sortablelink('unpaid', trans('general.unpaid')) @sortablelink('enabled', trans_choice('general.statuses', 1)) {{ trans('general.actions') }}