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

@@ -16,6 +16,11 @@ class Account extends Model
protected $guarded = [];
public function getTypeAttribute(): string
{
return $this->accountType->type;
}
public function accountType(): BelongsTo
{
return $this->belongsTo(AccountType::class);

View File

@@ -18,14 +18,6 @@ class Branch extends Model
protected $guarded = [];
/**
* Get the client that owns the Branch
*/
public function client(): BelongsTo
{
return $this->belongsTo(Client::class);
}
public function getCurrentSeriesAttribute()
{
if ($this->series()->count() > 0) {
@@ -43,8 +35,21 @@ class Branch extends Model
return $this->hasMany(Series::class);
}
public function getIsClientVatableAttribute(): bool
{
return $this->client->vatable;
}
/**
* Get all of the sales for the Branch
* Get the client that owns the Branch
*/
public function client(): BelongsTo
{
return $this->belongsTo(Client::class);
}
/**
* Get all the sales for the Branch
*/
public function sales(): HasMany
{
@@ -52,7 +57,7 @@ class Branch extends Model
}
/**
* Get all of the expenses for the Branch
* Get all the expenses for the Branch
*/
public function expenses(): HasMany
{
@@ -68,4 +73,9 @@ class Branch extends Model
{
return $this->belongsToThrough(Account::class, Balance::class);
}
public function transactions(): HasMany
{
return $this->hasMany(Transaction::class);
}
}

View File

@@ -24,13 +24,13 @@ class Client extends Model
return $this->lname.', '.$this->fname.' '.$this->mname;
}
public function getVatableAttribute()
public function getVatableAttribute(): bool
{
return $this->type->type == 'Vatable' ? true : false;
}
/**
* Get all of the branches for the Client
* Get all the branches for the Client
*/
public function branches(): HasMany
{

View File

@@ -4,8 +4,29 @@ namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Relations\MorphToMany;
class Expense extends Model
{
use HasFactory;
protected $guarded = [];
protected $casts = [
'happened_on' => 'date:Y-m-d',
];
/**
* Get all the transactions for the Sale
*/
public function transactions(): MorphToMany
{
return $this->morphToMany(Transaction::class, 'transactionable');
}
public function branch(): BelongsTo
{
return $this->belongsTo(Branch::class);
}
}

View File

@@ -4,8 +4,14 @@ namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\MorphToMany;
class Sale extends Model
{
use HasFactory;
public function transactions(): MorphToMany
{
return $this->morphToMany(Transaction::class, 'transactionable');
}
}

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);
}
}