diff --git a/app/Http/Requests/RecurringInvoice/StoreRecurringInvoiceRequest.php b/app/Http/Requests/RecurringInvoice/StoreRecurringInvoiceRequest.php index d478ebcd79..e04a672c46 100644 --- a/app/Http/Requests/RecurringInvoice/StoreRecurringInvoiceRequest.php +++ b/app/Http/Requests/RecurringInvoice/StoreRecurringInvoiceRequest.php @@ -95,9 +95,24 @@ class StoreRecurringInvoiceRequest extends Request } $input['line_items'] = isset($input['line_items']) ? $this->cleanItems($input['line_items']) : []; - //$input['line_items'] = json_encode($input['line_items']); - $this->replace($input); - } + + if(isset($input['auto_bill'])) + $input['auto_bill_enabled'] = $this->setAutoBillFlag($input['auto_bill']); + + $this->replace($input); +} + +private function setAutoBillFlag($auto_bill) +{ + if($auto_bill == 'always') + return true; + + if($auto_bill == 'off') + return false; + + //todo do we need to handle optin / optout here? + +} public function messages() { diff --git a/app/Http/Requests/RecurringInvoice/UpdateRecurringInvoiceRequest.php b/app/Http/Requests/RecurringInvoice/UpdateRecurringInvoiceRequest.php index 48cdae76c6..5b1e9111f3 100644 --- a/app/Http/Requests/RecurringInvoice/UpdateRecurringInvoiceRequest.php +++ b/app/Http/Requests/RecurringInvoice/UpdateRecurringInvoiceRequest.php @@ -85,6 +85,22 @@ class UpdateRecurringInvoiceRequest extends Request $input['line_items'] = isset($input['line_items']) ? $this->cleanItems($input['line_items']) : []; + if(isset($input['auto_bill'])) + $input['auto_bill_enabled'] = $this->setAutoBillFlag($input['auto_bill']); + $this->replace($input); } + + private function setAutoBillFlag($auto_bill) + { + if($auto_bill == 'always') + return true; + + if($auto_bill == 'off') + return false; + + //todo do we need to handle optin / optout here? + + } + } diff --git a/app/Models/RecurringInvoice.php b/app/Models/RecurringInvoice.php index 91079cc67b..e2508f14bd 100644 --- a/app/Models/RecurringInvoice.php +++ b/app/Models/RecurringInvoice.php @@ -104,6 +104,7 @@ class RecurringInvoice extends BaseModel 'next_send_date', 'remaining_cycles', 'auto_bill', + 'auto_bill_enabled', ]; protected $casts = [ diff --git a/app/Utils/Traits/Recurring/HasRecurrence.php b/app/Utils/Traits/Recurring/HasRecurrence.php index 2b94ef18bd..e56bdcb00a 100644 --- a/app/Utils/Traits/Recurring/HasRecurrence.php +++ b/app/Utils/Traits/Recurring/HasRecurrence.php @@ -53,13 +53,13 @@ trait HasRecurrence */ public function setDayOfMonth($date, $day_of_month) { - $data = Carbon::parse($date); + $carbon_date = Carbon::parse($date); - $set_date = $date->copy()->setUnitNoOverflow('day', $day_of_month, 'month'); + $set_date = $carbon_date->copy()->setUnitNoOverflow('day', $day_of_month, 'month'); //If the set date is less than the original date we need to add a month. //If we are overflowing dates, then we need to diff the dates and ensure it doesn't equal 0 - if($set_date->lte($date) || $set_date->diffInDays($date) == 0) + if($set_date->lte($date) || $set_date->diffInDays($carbon_date) == 0) $set_date->addMonthNoOverflow(); if($day_of_month == '31')