#93 Add 'Partially paid' status to invoices
This commit is contained in:
parent
6b5a758dbe
commit
4fbb62353a
@ -32,6 +32,7 @@ enum IconEnum: string
|
||||
|
||||
// Invoice Status
|
||||
case UNPAID = 'lucide-circle-x';
|
||||
case PARTIALLY_PAID = 'lucide-circle-minus';
|
||||
case PAID = 'lucide-circle-check';
|
||||
case VOID = 'lucide-circle-slash';
|
||||
|
||||
|
@ -9,6 +9,7 @@
|
||||
enum InvoiceStatus: string implements HasColor, HasIcon, HasLabel
|
||||
{
|
||||
case UNPAID = 'Not paid';
|
||||
case PARTIALLY_PAID = 'Partially paid';
|
||||
case PAID = 'Paid';
|
||||
case VOID = 'Void';
|
||||
|
||||
@ -20,7 +21,8 @@ public function getLabel(): ?string
|
||||
public function getColor(): string|array|null
|
||||
{
|
||||
return match ($this) {
|
||||
self::UNPAID => 'warning',
|
||||
self::UNPAID => 'danger',
|
||||
self::PARTIALLY_PAID => 'warning',
|
||||
self::PAID => 'success',
|
||||
self::VOID => 'gray'
|
||||
};
|
||||
@ -30,6 +32,7 @@ public function getIcon(): ?string
|
||||
{
|
||||
return match ($this) {
|
||||
self::UNPAID => IconEnum::UNPAID->value,
|
||||
self::PARTIALLY_PAID => IconEnum::PARTIALLY_PAID->value,
|
||||
self::PAID => IconEnum::PAID->value,
|
||||
self::VOID => IconEnum::VOID->value,
|
||||
};
|
||||
|
@ -38,21 +38,17 @@ public static function boot(): void
|
||||
parent::boot();
|
||||
|
||||
static::created(function (InvoiceReport $model) {
|
||||
|
||||
// Set ID after creation
|
||||
$model->attributes['internal_id'] = 'TNR'.str_pad($model->id, 4, '0', STR_PAD_LEFT);
|
||||
|
||||
// Associate all relevant invoices
|
||||
$invoices = Invoice::whereBetween('date', [$model->date_start, $model->date_end])
|
||||
->where('customer_id', $model->customer_id)
|
||||
->when($model->filter_paid, function ($query) {
|
||||
$query->where('status', InvoiceStatus::UNPAID);
|
||||
$query->where('status', InvoiceStatus::UNPAID)
|
||||
->orWhere('status', InvoiceStatus::PARTIALLY_PAID);
|
||||
});
|
||||
|
||||
$model->invoices()->sync($invoices->pluck('id')->toArray());
|
||||
|
||||
// $model->total = $model->invoices()->where('status', 'UNPAID')->sum('total');
|
||||
|
||||
// Finally, save
|
||||
$model->save();
|
||||
});
|
||||
}
|
||||
|
@ -47,7 +47,7 @@ public function applyToInvoices(): void
|
||||
if ($invoice->remainingBalance() == 0) {
|
||||
$invoice->setStatus(InvoiceStatus::PAID);
|
||||
} elseif ($applied > 0) {
|
||||
$invoice->setStatus(InvoiceStatus::UNPAID);
|
||||
$invoice->setStatus(InvoiceStatus::PARTIALLY_PAID);
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user