1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-09-21 00:41:34 +02:00

Fixes for hasrecurrence trait

This commit is contained in:
David Bomba 2020-09-24 13:40:13 +10:00
parent 4db72d11e1
commit b906e1e92f
4 changed files with 38 additions and 6 deletions

View File

@ -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()
{

View File

@ -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?
}
}

View File

@ -104,6 +104,7 @@ class RecurringInvoice extends BaseModel
'next_send_date',
'remaining_cycles',
'auto_bill',
'auto_bill_enabled',
];
protected $casts = [

View File

@ -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')