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