feat: updates

This commit is contained in:
JP
2024-08-15 20:11:21 +08:00
parent 52431a2c61
commit 3af7207ec3
61 changed files with 1674 additions and 480 deletions

View File

@@ -6,6 +6,8 @@ use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Relations\HasMany;
use Illuminate\Database\Eloquent\Relations\HasOne;
use Illuminate\Database\Eloquent\Relations\MorphTo;
class Transaction extends Model
{
@@ -13,43 +15,36 @@ class Transaction extends Model
protected $guarded = [];
/**
* Get the expense that owns the Transaction
*
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
*/
public function expense(): BelongsTo
public function transactionable(): MorphTo
{
return $this->belongsTo(Expense::class);
}
/**
* Get the sale that owns the Transaction
*
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
*/
public function sale(): BelongsTo
{
return $this->belongsTo(Sale::class);
return $this->morphTo();
}
/**
* Get the account that owns the Transaction
*
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
*/
public function account(): BelongsTo
{
return $this->belongsTo(Account::class);
}
public function getAccountTypeAttribute(): string
{
return $this->account->type;
}
/**
* Get the ledgers associated with the Transaction
*
* @return \Illuminate\Database\Eloquent\Relations\HasOne
* @return HasOne
*/
public function ledgers(): HasMany
{
return $this->hasMany(Ledger::class);
}
public function branch(): BelongsTo
{
return $this->belongsTo(Branch::class);
}
}