replaced revenues/payments with transactions

This commit is contained in:
denisdulici
2019-11-27 12:08:36 +03:00
parent e4d0de0677
commit 3a15c1d615
28 changed files with 139 additions and 141 deletions

View File

@ -34,16 +34,16 @@ class Account extends Model
return $this->belongsTo('App\Models\Setting\Currency', 'currency_code', 'code');
}
public function revenues()
{
return $this->transactions()->where('type', 'income');
}
public function payments()
public function expense_transactions()
{
return $this->transactions()->where('type', 'expense');
}
public function income_transacions()
{
return $this->transactions()->where('type', 'income');
}
public function transactions()
{
return $this->hasMany('App\Models\Banking\Transaction');
@ -71,10 +71,10 @@ class Account extends Model
$total = $this->opening_balance;
// Sum Incomes
$total += $this->revenues->sum('amount');
$total += $this->income_transacions->sum('amount');
// Subtract Expenses
$total -= $this->payments->sum('amount');
$total -= $this->expense_transactions->sum('amount');
return $total;
}

View File

@ -88,6 +88,16 @@ class Company extends Eloquent
return $this->hasMany('App\Models\Common\Dashboard');
}
public function expense_transactions()
{
return $this->transactions()->where('type', 'expense');
}
public function income_transactions()
{
return $this->transactions()->where('type', 'income');
}
public function invoice_histories()
{
return $this->hasMany('App\Models\Income\InvoiceHistory');
@ -113,21 +123,11 @@ class Company extends Eloquent
return $this->hasMany('App\Models\Common\Item');
}
public function payments()
{
return $this->transactions()->where('type', 'expense');
}
public function recurring()
{
return $this->hasMany('App\Models\Common\Recurring');
}
public function revenues()
{
return $this->transactions()->where('type', 'income');
}
public function settings()
{
return $this->hasMany('App\Models\Setting\Setting');

View File

@ -38,21 +38,21 @@ class Contact extends Model
return $this->belongsTo('App\Models\Setting\Currency', 'currency_code', 'code');
}
public function invoices()
{
return $this->hasMany('App\Models\Income\Invoice');
}
public function payments()
public function expense_transactions()
{
return $this->transactions()->where('type', 'expense');
}
public function revenues()
public function income_transactions()
{
return $this->transactions()->where('type', 'income');
}
public function invoices()
{
return $this->hasMany('App\Models\Income\Invoice');
}
public function transactions()
{
return $this->hasMany('App\Models\Banking\Transaction');

View File

@ -225,10 +225,10 @@ class Invoice extends Model
$paid = 0;
$reconciled = $reconciled_amount = 0;
if ($this->payments->count()) {
if ($this->transactions->count()) {
$currencies = Currency::enabled()->pluck('rate', 'code')->toArray();
foreach ($this->payments as $item) {
foreach ($this->transactions as $item) {
if ($this->currency_code == $item->currency_code) {
$amount = (double) $item->amount;
} else {

View File

@ -27,6 +27,16 @@ class Category extends Model
return $this->hasMany('App\Models\Expense\Bill');
}
public function expense_transactions()
{
return $this->transactions()->where('type', 'expense');
}
public function income_transacions()
{
return $this->transactions()->where('type', 'income');
}
public function invoices()
{
return $this->hasMany('App\Models\Income\Invoice');
@ -37,16 +47,6 @@ class Category extends Model
return $this->hasMany('App\Models\Common\Item');
}
public function payments()
{
return $this->transactions()->where('type', 'expense');
}
public function revenues()
{
return $this->transactions()->where('type', 'income');
}
public function transactions()
{
return $this->hasMany('App\Models\Banking\Transaction');

View File

@ -43,21 +43,21 @@ class Currency extends Model
return $this->contacts()->where('type', 'customer');
}
public function invoices()
{
return $this->hasMany('App\Models\Income\Invoice', 'currency_code', 'code');
}
public function payments()
public function expense_transactions()
{
return $this->transactions()->where('type', 'expense');
}
public function revenues()
public function income_transactions()
{
return $this->transactions()->where('type', 'income');
}
public function invoices()
{
return $this->hasMany('App\Models\Income\Invoice', 'currency_code', 'code');
}
public function transactions()
{
return $this->hasMany('App\Models\Banking\Transaction', 'currency_code', 'code');