Gst Updates
This commit is contained in:
@@ -31,6 +31,13 @@ class Invoice extends Model
|
||||
'pincode',
|
||||
'pdf_path',
|
||||
'notes',
|
||||
// totals from charge groups
|
||||
'charge_groups_total',
|
||||
'grand_total_with_charges',
|
||||
'tax_type',
|
||||
'cgst_percent',
|
||||
'sgst_percent',
|
||||
'igst_percent',
|
||||
];
|
||||
|
||||
/****************************
|
||||
@@ -57,16 +64,16 @@ class Invoice extends Model
|
||||
return $this->hasMany(InvoiceInstallment::class);
|
||||
}
|
||||
|
||||
// ✅ SINGLE, correct relation
|
||||
public function chargeGroups()
|
||||
{
|
||||
return $this->hasMany(\App\Models\InvoiceChargeGroup::class, 'invoice_id');
|
||||
return $this->hasMany(InvoiceChargeGroup::class, 'invoice_id');
|
||||
}
|
||||
|
||||
/****************************
|
||||
* Helper Functions
|
||||
****************************/
|
||||
|
||||
// (Items based calculateTotals वापरणार नाहीस तरी ठेवू शकतोस)
|
||||
public function calculateTotals()
|
||||
{
|
||||
$gst = ($this->final_amount * $this->gst_percent) / 100;
|
||||
@@ -84,29 +91,32 @@ class Invoice extends Model
|
||||
return null;
|
||||
}
|
||||
|
||||
// ✅ Charge groups total accessor
|
||||
// ✅ Charge groups base total (WITHOUT GST)
|
||||
public function getChargeGroupsTotalAttribute()
|
||||
{
|
||||
// relation already loaded असेल तर collection वरून sum होईल
|
||||
// base = total_charge sum
|
||||
return (float) $this->chargeGroups->sum('total_charge');
|
||||
}
|
||||
|
||||
// ✅ Grand total accessor (items + GST + charge groups)
|
||||
// ✅ Grand total: Charge groups base + GST (items ignore)
|
||||
public function getGrandTotalWithChargesAttribute()
|
||||
{
|
||||
return (float) ($this->final_amount_with_gst ?? 0) + $this->charge_groups_total;
|
||||
$base = (float) ($this->charge_groups_total ?? 0);
|
||||
$gst = (float) ($this->gst_amount ?? 0);
|
||||
|
||||
return $base + $gst;
|
||||
}
|
||||
|
||||
public function totalPaid()
|
||||
{
|
||||
return $this->installments->sum('amount');
|
||||
}
|
||||
|
||||
|
||||
public function remainingAmount()
|
||||
{
|
||||
return $this->grand_total_with_charges - $this->totalPaid();
|
||||
}
|
||||
|
||||
|
||||
public function totalPaid(): float
|
||||
{
|
||||
return (float) $this->installments()->sum('amount');
|
||||
}
|
||||
|
||||
public function remainingAmount(): float
|
||||
{
|
||||
$grand = (float) $this->grand_total_with_charges;
|
||||
$paid = (float) $this->totalPaid();
|
||||
|
||||
return max(0, $grand - $paid);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,6 +13,10 @@ class InvoiceChargeGroup extends Model
|
||||
'basis_value',
|
||||
'rate',
|
||||
'total_charge',
|
||||
|
||||
'tax_type',
|
||||
'gst_percent',
|
||||
'total_with_gst',
|
||||
];
|
||||
|
||||
public function invoice()
|
||||
|
||||
Reference in New Issue
Block a user