v2 first commit
This commit is contained in:
@@ -2,13 +2,10 @@
|
||||
|
||||
namespace App\Models\Banking;
|
||||
|
||||
use App\Models\Model;
|
||||
use Sofa\Eloquence\Eloquence;
|
||||
use App\Abstracts\Model;
|
||||
|
||||
class Account extends Model
|
||||
{
|
||||
use Eloquence;
|
||||
|
||||
protected $table = 'accounts';
|
||||
|
||||
/**
|
||||
@@ -32,42 +29,24 @@ class Account extends Model
|
||||
*/
|
||||
public $sortable = ['name', 'number', 'opening_balance', 'enabled'];
|
||||
|
||||
/**
|
||||
* Searchable rules.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $searchableColumns = [
|
||||
'name' => 10,
|
||||
'number' => 10,
|
||||
'bank_name' => 10,
|
||||
'bank_phone' => 5,
|
||||
'bank_address' => 2,
|
||||
];
|
||||
|
||||
public function currency()
|
||||
{
|
||||
return $this->belongsTo('App\Models\Setting\Currency', 'currency_code', 'code');
|
||||
}
|
||||
|
||||
public function invoice_payments()
|
||||
{
|
||||
return $this->hasMany('App\Models\Income\InvoicePayment');
|
||||
}
|
||||
|
||||
public function revenues()
|
||||
{
|
||||
return $this->hasMany('App\Models\Income\Revenue');
|
||||
}
|
||||
|
||||
public function bill_payments()
|
||||
{
|
||||
return $this->hasMany('App\Models\Expense\BillPayment');
|
||||
return $this->transactions()->where('type', 'income');
|
||||
}
|
||||
|
||||
public function payments()
|
||||
{
|
||||
return $this->hasMany('App\Models\Expense\Payment');
|
||||
return $this->transactions()->where('type', 'expense');
|
||||
}
|
||||
|
||||
public function transactions()
|
||||
{
|
||||
return $this->hasMany('App\Models\Banking\Transaction');
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -92,10 +71,10 @@ class Account extends Model
|
||||
$total = $this->opening_balance;
|
||||
|
||||
// Sum Incomes
|
||||
$total += $this->invoice_payments()->sum('amount') + $this->revenues()->sum('amount');
|
||||
$total += $this->revenues->sum('amount');
|
||||
|
||||
// Subtract Expenses
|
||||
$total -= $this->bill_payments()->sum('amount') + $this->payments()->sum('amount');
|
||||
$total -= $this->payments->sum('amount');
|
||||
|
||||
return $total;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user