mirror of
https://github.com/crater-invoice/crater.git
synced 2025-10-28 04:01:10 -04:00
solve recurring invoice starts_at condition
This commit is contained in:
@ -20,6 +20,10 @@ class RecurringInvoice extends Model
|
||||
'id',
|
||||
];
|
||||
|
||||
protected $dates = [
|
||||
'starts_at'
|
||||
];
|
||||
|
||||
public const NONE = 'NONE';
|
||||
public const COUNT = 'COUNT';
|
||||
public const DATE = 'DATE';
|
||||
@ -259,34 +263,36 @@ class RecurringInvoice extends Model
|
||||
|
||||
public function generateInvoice()
|
||||
{
|
||||
if (Carbon::now()->format('Y-m-d H:i:s') < $this->starts_at) {
|
||||
if ($this->limit_by == 'DATE') {
|
||||
$startDate = Carbon::today()->format('Y-m-d');
|
||||
if (Carbon::now()->lessThan($this->starts_at)) {
|
||||
return;
|
||||
}
|
||||
|
||||
$endDate = $this->limit_date;
|
||||
if ($this->limit_by == 'DATE') {
|
||||
$startDate = Carbon::today()->format('Y-m-d');
|
||||
|
||||
if ($endDate >= $startDate) {
|
||||
$this->createInvoice();
|
||||
$endDate = $this->limit_date;
|
||||
|
||||
$this->updateNextInvoiceDate();
|
||||
} else {
|
||||
$this->markStatusAsCompleted();
|
||||
}
|
||||
} elseif ($this->limit_by == 'COUNT') {
|
||||
$invoiceCount = Invoice::where('recurring_invoice_id', $this->id)->count();
|
||||
|
||||
if ($invoiceCount < $this->limit_count) {
|
||||
$this->createInvoice();
|
||||
|
||||
$this->updateNextInvoiceDate();
|
||||
} else {
|
||||
$this->markStatusAsCompleted();
|
||||
}
|
||||
} else {
|
||||
if ($endDate >= $startDate) {
|
||||
$this->createInvoice();
|
||||
|
||||
$this->updateNextInvoiceDate();
|
||||
} else {
|
||||
$this->markStatusAsCompleted();
|
||||
}
|
||||
} elseif ($this->limit_by == 'COUNT') {
|
||||
$invoiceCount = Invoice::where('recurring_invoice_id', $this->id)->count();
|
||||
|
||||
if ($invoiceCount < $this->limit_count) {
|
||||
$this->createInvoice();
|
||||
|
||||
$this->updateNextInvoiceDate();
|
||||
} else {
|
||||
$this->markStatusAsCompleted();
|
||||
}
|
||||
} else {
|
||||
$this->createInvoice();
|
||||
|
||||
$this->updateNextInvoiceDate();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user