mirror of
https://github.com/crater-invoice/crater.git
synced 2025-10-27 11:41:09 -04:00
add overdue
This commit is contained in:
@ -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();
|
||||
}
|
||||
|
||||
@ -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);
|
||||
}),
|
||||
|
||||
@ -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);
|
||||
}),
|
||||
|
||||
@ -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;
|
||||
|
||||
Reference in New Issue
Block a user