update dates of new records #315
This commit is contained in:
parent
4f340cba26
commit
17758a24cc
@ -53,7 +53,7 @@ class RecurringCheck extends Command
|
|||||||
*/
|
*/
|
||||||
public function handle()
|
public function handle()
|
||||||
{
|
{
|
||||||
$today = Date::today();
|
$this->today = Date::today();
|
||||||
|
|
||||||
// Get all companies
|
// Get all companies
|
||||||
$companies = Company::all();
|
$companies = Company::all();
|
||||||
@ -76,7 +76,7 @@ class RecurringCheck extends Command
|
|||||||
$current = Date::parse($schedule->current()->getStart());
|
$current = Date::parse($schedule->current()->getStart());
|
||||||
|
|
||||||
// Check if should recur today
|
// Check if should recur today
|
||||||
if ($today->ne($current)) {
|
if ($this->today->ne($current)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -97,7 +97,12 @@ class RecurringCheck extends Command
|
|||||||
break;
|
break;
|
||||||
case 'Payment':
|
case 'Payment':
|
||||||
case 'Revenue':
|
case 'Revenue':
|
||||||
$model->duplicate();
|
// Create new record
|
||||||
|
$clone = $model->duplicate();
|
||||||
|
|
||||||
|
// Update date
|
||||||
|
$clone->paid_at = $this->today->format('Y-m-d');
|
||||||
|
$clone->save();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -109,8 +114,17 @@ class RecurringCheck extends Command
|
|||||||
|
|
||||||
protected function recurInvoice($company, $model)
|
protected function recurInvoice($company, $model)
|
||||||
{
|
{
|
||||||
|
// Create new record
|
||||||
$clone = $model->duplicate();
|
$clone = $model->duplicate();
|
||||||
|
|
||||||
|
// Days between invoiced and due date
|
||||||
|
$diff_days = Date::parse($clone->due_at)->diffInDays(Date::parse($clone->invoiced_at));
|
||||||
|
|
||||||
|
// Update dates
|
||||||
|
$clone->invoiced_at = $this->today->format('Y-m-d');
|
||||||
|
$clone->due_at = $this->today->addDays($diff_days)->format('Y-m-d');
|
||||||
|
$clone->save();
|
||||||
|
|
||||||
// Add invoice history
|
// Add invoice history
|
||||||
InvoiceHistory::create([
|
InvoiceHistory::create([
|
||||||
'company_id' => session('company_id'),
|
'company_id' => session('company_id'),
|
||||||
@ -140,8 +154,17 @@ class RecurringCheck extends Command
|
|||||||
|
|
||||||
protected function recurBill($company, $model)
|
protected function recurBill($company, $model)
|
||||||
{
|
{
|
||||||
|
// Create new record
|
||||||
$clone = $model->duplicate();
|
$clone = $model->duplicate();
|
||||||
|
|
||||||
|
// Days between invoiced and due date
|
||||||
|
$diff_days = Date::parse($clone->due_at)->diffInDays(Date::parse($clone->invoiced_at));
|
||||||
|
|
||||||
|
// Update dates
|
||||||
|
$clone->billed_at = $this->today->format('Y-m-d');
|
||||||
|
$clone->due_at = $this->today->addDays($diff_days)->format('Y-m-d');
|
||||||
|
$clone->save();
|
||||||
|
|
||||||
// Add bill history
|
// Add bill history
|
||||||
BillHistory::create([
|
BillHistory::create([
|
||||||
'company_id' => session('company_id'),
|
'company_id' => session('company_id'),
|
||||||
|
Loading…
x
Reference in New Issue
Block a user