Recurring model relation issue and new transaction relation,
This commit is contained in:
parent
8387830ecd
commit
50eba765d2
@ -61,7 +61,13 @@ class Recurring extends Model
|
||||
|
||||
public function documents()
|
||||
{
|
||||
return $this->morphedByMany('App\Models\Document\Document', 'recurable');
|
||||
return $this->morphedByMany(
|
||||
'App\Models\Document\Document',
|
||||
'recurable',
|
||||
'recurring',
|
||||
'recurable_id',
|
||||
'id'
|
||||
);
|
||||
}
|
||||
|
||||
public function invoices()
|
||||
@ -74,6 +80,27 @@ class Recurring extends Model
|
||||
return $this->documents()->where('type', self::BILL_RECURRING_TYPE);
|
||||
}
|
||||
|
||||
public function transactions()
|
||||
{
|
||||
return $this->morphedByMany(
|
||||
'App\Models\Banking\Transaction',
|
||||
'recurable',
|
||||
'recurring',
|
||||
'recurable_id',
|
||||
'id'
|
||||
);
|
||||
}
|
||||
|
||||
public function incomes()
|
||||
{
|
||||
return $this->transactions()->where('type', self::INCOME_RECURRING_TYPE);
|
||||
}
|
||||
|
||||
public function expenses()
|
||||
{
|
||||
return $this->transactions()->where('type', self::EXPENSE_RECURRING_TYPE);
|
||||
}
|
||||
|
||||
public function scopeActive(Builder $query): Builder
|
||||
{
|
||||
return $query->where($this->qualifyColumn('status'), '=', static::ACTIVE_STATUS);
|
||||
@ -133,4 +160,24 @@ class Recurring extends Model
|
||||
$query->where('type', self::INCOME_RECURRING_TYPE);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine if recurring is a document.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function isDocument()
|
||||
{
|
||||
return (bool) ($this->recurable_type == 'App\\Models\\Document\\Document');
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine if recurring is a transaction.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function isTransaction()
|
||||
{
|
||||
return (bool) ($this->recurable_type == 'App\\Models\\Banking\\Transaction');
|
||||
}
|
||||
}
|
||||
|
@ -102,8 +102,16 @@
|
||||
<x-date date="{{ $item->recurring->started_at }}" />
|
||||
</x-slot>
|
||||
<x-slot name="second">
|
||||
@if ($last = $item->recurring->getLastRecurring())
|
||||
{{ $last->format(company_date_format()) }}
|
||||
@if ($item->recurring->status == 'ended')
|
||||
@if ($last = $item->recurring->transactions->last()?->paid_at)
|
||||
{{ $last->format(company_date_format()) }}
|
||||
@else
|
||||
<x-empty-data />
|
||||
@endif
|
||||
@else
|
||||
@if ($last = $item->recurring->getLastRecurring())
|
||||
{{ $last->format(company_date_format()) }}
|
||||
@endif
|
||||
@endif
|
||||
</x-slot>
|
||||
</x-table.td>
|
||||
|
@ -58,8 +58,16 @@
|
||||
<x-date date="{{ $item->recurring->started_at }}" />
|
||||
</x-slot>
|
||||
<x-slot name="second">
|
||||
@if ($last = $item->recurring->getLastRecurring())
|
||||
{{ $last->format(company_date_format()) }}
|
||||
@if ($item->recurring->status == 'ended')
|
||||
@if ($last = $item->recurring->documents->last()?->issued_at)
|
||||
{{ $last->format(company_date_format()) }}
|
||||
@else
|
||||
<x-empty-data />
|
||||
@endif
|
||||
@else
|
||||
@if ($last = $item->recurring->getLastRecurring())
|
||||
{{ $last->format(company_date_format()) }}
|
||||
@endif
|
||||
@endif
|
||||
</x-slot>
|
||||
</x-table.td>
|
||||
|
Loading…
x
Reference in New Issue
Block a user