update/ledger #1
@@ -25,6 +25,20 @@ class Expense extends Model
|
|||||||
return $this->morphMany(Transaction::class, 'transactionable');
|
return $this->morphMany(Transaction::class, 'transactionable');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected static function booted()
|
||||||
|
{
|
||||||
|
static::deleting(function ($expense) {
|
||||||
|
$expense->transactions->each(function ($transaction) {
|
||||||
|
// Delete associated ledgers first to trigger any ledger deletion logic if exists
|
||||||
|
$transaction->ledgers->each(function ($ledger) {
|
||||||
|
$ledger->balances()->delete(); // Delete balances associated with ledger
|
||||||
|
$ledger->delete();
|
||||||
|
});
|
||||||
|
$transaction->delete();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
public function branch(): BelongsTo
|
public function branch(): BelongsTo
|
||||||
{
|
{
|
||||||
return $this->belongsTo(Branch::class);
|
return $this->belongsTo(Branch::class);
|
||||||
|
|||||||
@@ -25,6 +25,20 @@ class Sale extends Model
|
|||||||
return $this->morphMany(Transaction::class, 'transactionable');
|
return $this->morphMany(Transaction::class, 'transactionable');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected static function booted()
|
||||||
|
{
|
||||||
|
static::deleting(function ($sale) {
|
||||||
|
$sale->transactions->each(function ($transaction) {
|
||||||
|
// Delete associated ledgers first to trigger any ledger deletion logic if exists
|
||||||
|
$transaction->ledgers->each(function ($ledger) {
|
||||||
|
$ledger->balances()->delete(); // Delete balances associated with ledger
|
||||||
|
$ledger->delete();
|
||||||
|
});
|
||||||
|
$transaction->delete();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
public function branch(): BelongsTo
|
public function branch(): BelongsTo
|
||||||
{
|
{
|
||||||
return $this->belongsTo(Branch::class);
|
return $this->belongsTo(Branch::class);
|
||||||
|
|||||||
Reference in New Issue
Block a user