diff --git a/app/Enums/IconEnum.php b/app/Enums/IconEnum.php index b8c3207..857112d 100644 --- a/app/Enums/IconEnum.php +++ b/app/Enums/IconEnum.php @@ -31,9 +31,10 @@ enum IconEnum: string case COPY = 'lucide-copy'; // Invoice Status - case UNPAID = 'lucide-circle-x'; - case PAID = 'lucide-circle-check'; - case VOID = 'lucide-circle-slash'; + case UNPAID = 'lucide-circle-x'; + case PARTIALLY_PAID = 'lucide-circle-minus'; + case PAID = 'lucide-circle-check'; + case VOID = 'lucide-circle-slash'; // Order Attributes case NEW_ART = 'lucide-brush'; diff --git a/app/Enums/InvoiceStatus.php b/app/Enums/InvoiceStatus.php index e3aaf0f..c6a99af 100644 --- a/app/Enums/InvoiceStatus.php +++ b/app/Enums/InvoiceStatus.php @@ -8,9 +8,10 @@ enum InvoiceStatus: string implements HasColor, HasIcon, HasLabel { - case UNPAID = 'Not paid'; - case PAID = 'Paid'; - case VOID = 'Void'; + case UNPAID = 'Not paid'; + case PARTIALLY_PAID = 'Partially paid'; + case PAID = 'Paid'; + case VOID = 'Void'; public function getLabel(): ?string { @@ -20,18 +21,20 @@ public function getLabel(): ?string public function getColor(): string|array|null { return match ($this) { - self::UNPAID => 'warning', - self::PAID => 'success', - self::VOID => 'gray' + self::UNPAID => 'danger', + self::PARTIALLY_PAID => 'warning', + self::PAID => 'success', + self::VOID => 'gray' }; } public function getIcon(): ?string { return match ($this) { - self::UNPAID => IconEnum::UNPAID->value, - self::PAID => IconEnum::PAID->value, - self::VOID => IconEnum::VOID->value, + self::UNPAID => IconEnum::UNPAID->value, + self::PARTIALLY_PAID => IconEnum::PARTIALLY_PAID->value, + self::PAID => IconEnum::PAID->value, + self::VOID => IconEnum::VOID->value, }; } } diff --git a/app/Models/InvoiceReport.php b/app/Models/InvoiceReport.php index 3570faf..d9e6aa7 100644 --- a/app/Models/InvoiceReport.php +++ b/app/Models/InvoiceReport.php @@ -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(); }); } diff --git a/app/Models/Payment.php b/app/Models/Payment.php index 0445509..33ec6b3 100644 --- a/app/Models/Payment.php +++ b/app/Models/Payment.php @@ -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); } }