amount update
This commit is contained in:
@@ -92,5 +92,20 @@ class Invoice extends Model
|
||||
return $this->hasMany(InvoiceInstallment::class);
|
||||
}
|
||||
|
||||
// App\Models\Invoice.php
|
||||
|
||||
public function totalPaid()
|
||||
{
|
||||
return $this->installments()->sum('amount');
|
||||
}
|
||||
|
||||
public function remainingAmount()
|
||||
{
|
||||
return max(
|
||||
($this->final_amount_with_gst ?? 0) - $this->totalPaid(),
|
||||
0
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -94,6 +94,19 @@ public function invoices()
|
||||
return $this->hasMany(\App\Models\Invoice::class, 'customer_id', 'id');
|
||||
}
|
||||
|
||||
// App\Models\User.php
|
||||
|
||||
|
||||
public function invoiceInstallments()
|
||||
{
|
||||
return $this->hasManyThrough(
|
||||
InvoiceInstallment::class,
|
||||
Invoice::class,
|
||||
'customer_id', // FK on invoices
|
||||
'invoice_id' // FK on installments
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user