From abad89a873d6c0335a474c917d13f6349dbb5785 Mon Sep 17 00:00:00 2001 From: denisdulici Date: Mon, 29 Oct 2018 15:13:18 +0300 Subject: [PATCH] fixed #572 --- app/Console/Commands/RecurringCheck.php | 58 ++++++++++++------------- 1 file changed, 28 insertions(+), 30 deletions(-) diff --git a/app/Console/Commands/RecurringCheck.php b/app/Console/Commands/RecurringCheck.php index 8b41c499a..7c2f10167 100644 --- a/app/Console/Commands/RecurringCheck.php +++ b/app/Console/Commands/RecurringCheck.php @@ -63,43 +63,41 @@ class RecurringCheck extends Command $company->setSettings(); - foreach ($company->recurring as $recur) { - if (!$current = $recur->current()) { - continue; - } + foreach ($company->recurring as $recurring) { + foreach ($recurring->schedule() as $recur) { + $recur_date = Date::parse($recur->getStart()->format('Y-m-d')); - $current_date = Date::parse($current->format('Y-m-d')); + // Check if should recur today + if ($this->today->ne($recur_date)) { + continue; + } - // Check if should recur today - if ($this->today->ne($current_date)) { - continue; - } + $model = $recurring->recurable; - $model = $recur->recurable; + if (!$model) { + continue; + } - if (!$model) { - continue; - } + switch ($recurring->recurable_type) { + case 'App\Models\Expense\Bill': + $this->recurBill($company, $model); + break; + case 'App\Models\Income\Invoice': + $this->recurInvoice($company, $model); + break; + case 'App\Models\Expense\Payment': + case 'App\Models\Income\Revenue': + $model->cloneable_relations = []; - switch ($recur->recurable_type) { - case 'App\Models\Expense\Bill': - $this->recurBill($company, $model); - break; - case 'App\Models\Income\Invoice': - $this->recurInvoice($company, $model); - break; - case 'App\Models\Expense\Payment': - case 'App\Models\Income\Revenue': - $model->cloneable_relations = []; + // Create new record + $clone = $model->duplicate(); - // Create new record - $clone = $model->duplicate(); + $clone->parent_id = $model->id; + $clone->paid_at = $this->today->format('Y-m-d'); + $clone->save(); - $clone->parent_id = $model->id; - $clone->paid_at = $this->today->format('Y-m-d'); - $clone->save(); - - break; + break; + } } } }