Show unpaid column in customer/vendor list
This commit is contained in:
@@ -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;
|
||||
}
|
||||
}
|
||||
|
@@ -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;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user