diff --git a/app/Console/Commands/CheckInvoiceStatus.php b/app/Console/Commands/CheckInvoiceStatus.php
index d96d590e..0eeb2723 100644
--- a/app/Console/Commands/CheckInvoiceStatus.php
+++ b/app/Console/Commands/CheckInvoiceStatus.php
@@ -41,11 +41,12 @@ class CheckInvoiceStatus extends Command
{
$date = Carbon::now();
$invoices = Invoice::whereNotIn('status', [Invoice::STATUS_COMPLETED, Invoice::STATUS_DRAFT])
+ ->where('overdue', false)
->whereDate('due_date', '<', $date)
->get();
foreach ($invoices as $invoice) {
- $invoice->status = Invoice::STATUS_OVERDUE;
+ $invoice->overdue = true;
printf("Invoice %s is OVERDUE \n", $invoice->invoice_number);
$invoice->save();
}
diff --git a/app/Http/Resources/Customer/InvoiceResource.php b/app/Http/Resources/Customer/InvoiceResource.php
index 8cdfd83d..d190c0ba 100644
--- a/app/Http/Resources/Customer/InvoiceResource.php
+++ b/app/Http/Resources/Customer/InvoiceResource.php
@@ -51,6 +51,7 @@ class InvoiceResource extends JsonResource
'formatted_invoice_date' => $this->formattedInvoiceDate,
'formatted_due_date' => $this->formattedDueDate,
'payment_module_enabled' => $this->payment_module_enabled,
+ 'overdue' => $this->overdue,
'items' => $this->when($this->items()->exists(), function () {
return InvoiceItemResource::collection($this->items);
}),
diff --git a/app/Http/Resources/InvoiceResource.php b/app/Http/Resources/InvoiceResource.php
index 3025f69b..c70d2a8c 100644
--- a/app/Http/Resources/InvoiceResource.php
+++ b/app/Http/Resources/InvoiceResource.php
@@ -55,6 +55,7 @@ class InvoiceResource extends JsonResource
'payment_module_enabled' => $this->payment_module_enabled,
'sales_tax_type' => $this->sales_tax_type,
'sales_tax_address_type' => $this->sales_tax_address_type,
+ 'overdue' => $this->overdue,
'items' => $this->when($this->items()->exists(), function () {
return InvoiceItemResource::collection($this->items);
}),
diff --git a/app/Models/Invoice.php b/app/Models/Invoice.php
index 7b890f75..396fc116 100644
--- a/app/Models/Invoice.php
+++ b/app/Models/Invoice.php
@@ -28,10 +28,8 @@ class Invoice extends Model implements HasMedia
public const STATUS_DRAFT = 'DRAFT';
public const STATUS_SENT = 'SENT';
public const STATUS_VIEWED = 'VIEWED';
- public const STATUS_OVERDUE = 'OVERDUE';
public const STATUS_COMPLETED = 'COMPLETED';
- public const STATUS_DUE = 'DUE';
public const STATUS_UNPAID = 'UNPAID';
public const STATUS_PARTIALLY_PAID = 'PARTIALLY_PAID';
public const STATUS_PAID = 'PAID';
@@ -138,7 +136,6 @@ class Invoice extends Model implements HasMedia
self::STATUS_DRAFT,
self::STATUS_SENT,
self::STATUS_VIEWED,
- self::STATUS_OVERDUE,
self::STATUS_COMPLETED,
];
@@ -155,9 +152,7 @@ class Invoice extends Model implements HasMedia
public function getPreviousStatus()
{
- if ($this->due_date < Carbon::now()) {
- return self::STATUS_OVERDUE;
- } elseif ($this->viewed) {
+ if ($this->viewed) {
return self::STATUS_VIEWED;
} elseif ($this->sent) {
return self::STATUS_SENT;
@@ -254,7 +249,7 @@ class Invoice extends Model implements HasMedia
$filters->get('status') == self::STATUS_PAID
) {
$query->wherePaidStatus($filters->get('status'));
- } elseif ($filters->get('status') == self::STATUS_DUE) {
+ } elseif ($filters->get('status') == 'DUE') {
$query->whereDueStatus($filters->get('status'));
} else {
$query->whereStatus($filters->get('status'));
@@ -692,6 +687,7 @@ class Invoice extends Model implements HasMedia
if ($amount == 0) {
$this->status = Invoice::STATUS_COMPLETED;
$this->paid_status = Invoice::STATUS_PAID;
+ $this->overdue = false;
} elseif ($amount == $this->total) {
$this->status = $this->getPreviousStatus();
$this->paid_status = Invoice::STATUS_UNPAID;
diff --git a/database/factories/InvoiceFactory.php b/database/factories/InvoiceFactory.php
index 2adf71b6..04c4af11 100644
--- a/database/factories/InvoiceFactory.php
+++ b/database/factories/InvoiceFactory.php
@@ -37,15 +37,6 @@ class InvoiceFactory extends Factory
});
}
- public function overdue()
- {
- return $this->state(function (array $attributes) {
- return [
- 'status' => Invoice::STATUS_OVERDUE,
- ];
- });
- }
-
public function completed()
{
return $this->state(function (array $attributes) {
@@ -55,15 +46,6 @@ class InvoiceFactory extends Factory
});
}
- public function due()
- {
- return $this->state(function (array $attributes) {
- return [
- 'status' => Invoice::STATUS_DUE,
- ];
- });
- }
-
public function unpaid()
{
return $this->state(function (array $attributes) {
diff --git a/database/migrations/2022_03_02_120210_add_overdue_to_invoices_table.php b/database/migrations/2022_03_02_120210_add_overdue_to_invoices_table.php
new file mode 100644
index 00000000..26ee791f
--- /dev/null
+++ b/database/migrations/2022_03_02_120210_add_overdue_to_invoices_table.php
@@ -0,0 +1,32 @@
+boolean('overdue')->default(false);
+ });
+ }
+
+ /**
+ * Reverse the migrations.
+ *
+ * @return void
+ */
+ public function down()
+ {
+ Schema::table('invoices', function (Blueprint $table) {
+ $table->dropForeign(['overdue']);
+ });
+ }
+}
diff --git a/resources/scripts/admin/views/invoices/Index.vue b/resources/scripts/admin/views/invoices/Index.vue
index 394eaec3..c1b21874 100644
--- a/resources/scripts/admin/views/invoices/Index.vue
+++ b/resources/scripts/admin/views/invoices/Index.vue
@@ -237,6 +237,14 @@
:currency="row.data.currency"
/>
+
+ {{ $t('invoices.overdue') }}
+
+
diff --git a/resources/scripts/components/base/BasePaidStatusBadge.vue b/resources/scripts/components/base/BasePaidStatusBadge.vue
index 51ee9d75..2a99872e 100644
--- a/resources/scripts/components/base/BasePaidStatusBadge.vue
+++ b/resources/scripts/components/base/BasePaidStatusBadge.vue
@@ -29,6 +29,8 @@ export default {
return ' bg-yellow-500 bg-opacity-25 text-yellow-900 uppercase font-normal text-center '
case 'PARTIALLY_PAID':
return 'bg-blue-400 bg-opacity-25 text-blue-900 uppercase font-normal text-center'
+ case 'OVERDUE':
+ return 'bg-red-300 bg-opacity-50 px-2 py-1 text-sm text-red-900 uppercase font-normal text-center'
default:
return 'bg-gray-500 bg-opacity-25 text-gray-900 uppercase font-normal text-center'
}
diff --git a/resources/scripts/customer/views/invoices/Index.vue b/resources/scripts/customer/views/invoices/Index.vue
index d06c07d3..b40fabc5 100644
--- a/resources/scripts/customer/views/invoices/Index.vue
+++ b/resources/scripts/customer/views/invoices/Index.vue
@@ -160,7 +160,7 @@ const route = useRoute()
const table = ref(null)
let isFetchingInitialData = ref(true)
let showFilters = ref(false)
-const status = ref(['DRAFT', 'DUE', 'SENT', 'VIEWED', 'OVERDUE', 'COMPLETED'])
+const status = ref(['DRAFT', 'DUE', 'SENT', 'VIEWED', 'COMPLETED'])
const filters = reactive({
status: '',
from_date: '',
diff --git a/resources/scripts/helpers/utilities.js b/resources/scripts/helpers/utilities.js
index 82857c24..fe273915 100644
--- a/resources/scripts/helpers/utilities.js
+++ b/resources/scripts/helpers/utilities.js
@@ -209,11 +209,6 @@ export default {
bgColor: '#C9E3EC',
color: '#2c5282',
}
- case 'OVERDUE':
- return {
- bgColor: '#FED7D7',
- color: '#c53030',
- }
case 'COMPLETED':
return {
bgColor: '#D5EED0',
@@ -256,8 +251,6 @@ export default {
return global.t('estimates.expired')
case 'PARTIALLY PAID':
return global.t('estimates.partially_paid')
- case 'OVERDUE':
- return global.t('invoices.overdue')
case 'COMPLETED':
return global.t('invoices.completed')
case 'DUE':