solve recurring invoice starts_at condition

This commit is contained in:
harshjagad20
2021-12-06 16:13:20 +05:30
parent b543f6d389
commit 8026c205cc

View File

@ -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();
}
}