diff --git a/app/Models/Expense/Vendor.php b/app/Models/Expense/Vendor.php
index 5af0b8eca..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';
@@ -71,10 +72,18 @@ class Vendor extends Model
return $this->getMedia('logo')->last();
}
- public function getAmountAttribute()
+ public function getUnpaidAttribute()
{
- $invoice_total = $this->bills()->notPaid()->sum('amount');
+ $amount = 0;
- return $invoice_total;
+ $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 175f08c4b..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';
@@ -65,10 +66,18 @@ class Customer extends Model
$this->user_id = null;
}
- public function getAmountAttribute()
+ public function getUnpaidAttribute()
{
- $invoice_total = $this->invoices()->notPaid()->sum('amount');
+ $amount = 0;
- return $invoice_total;
+ $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/views/expenses/vendors/index.blade.php b/resources/views/expenses/vendors/index.blade.php
index 48d0f5e7e..42dd09b56 100644
--- a/resources/views/expenses/vendors/index.blade.php
+++ b/resources/views/expenses/vendors/index.blade.php
@@ -33,10 +33,10 @@
- | @sortablelink('name', trans('general.name')) |
+ @sortablelink('name', trans('general.name')) |
@sortablelink('email', trans('general.email')) |
@sortablelink('phone', trans('general.phone')) |
- @sortablelink('amount', trans('general.amount')) |
+ @sortablelink('unpaid', trans('general.unpaid')) |
@sortablelink('enabled', trans_choice('general.statuses', 1)) |
{{ trans('general.actions') }} |
@@ -47,7 +47,7 @@
{{ $item->name }} |
{{ !empty($item->email) ? $item->email : trans('general.na') }} |
{{ $item->phone }} |
- @money($item->amount, setting('general.default_currency'), true) |
+ @money($item->unpaid, setting('general.default_currency'), true) |
@if ($item->enabled)
{{ trans('general.enabled') }}
diff --git a/resources/views/incomes/customers/index.blade.php b/resources/views/incomes/customers/index.blade.php
index 692e632f9..ec6d809c1 100644
--- a/resources/views/incomes/customers/index.blade.php
+++ b/resources/views/incomes/customers/index.blade.php
@@ -33,10 +33,10 @@
- | @sortablelink('name', trans('general.name')) |
+ @sortablelink('name', trans('general.name')) |
@sortablelink('email', trans('general.email')) |
@sortablelink('phone', trans('general.phone')) |
- @sortablelink('amounts', trans('general.amount')) |
+ @sortablelink('unpaid', trans('general.unpaid')) |
@sortablelink('enabled', trans_choice('general.statuses', 1)) |
{{ trans('general.actions') }} |
@@ -47,7 +47,7 @@
{{ $item->name }} |
{{ !empty($item->email) ? $item->email : trans('general.na') }} |
{{ $item->phone }} |
- @money($item->amount, setting('general.default_currency'), true) |
+ @money($item->unpaid, setting('general.default_currency'), true) |
@if ($item->enabled)
{{ trans('general.enabled') }}
| |