Added recurring field validation.. ( #33kfqf6 )
This commit is contained in:
parent
93e277c654
commit
37b7144b28
@ -17,7 +17,8 @@ class DateFormat
|
||||
public function handle($request, Closure $next)
|
||||
{
|
||||
if (($request->method() == 'POST') || ($request->method() == 'PATCH')) {
|
||||
$fields = ['paid_at', 'due_at', 'issued_at', 'started_at', 'ended_at', 'expire_at'];
|
||||
// todo fire event
|
||||
$fields = ['paid_at', 'due_at', 'issued_at', 'started_at', 'ended_at', 'expire_at', 'recurring_started_at', 'recurring_limit_date'];
|
||||
|
||||
foreach ($fields as $field) {
|
||||
$date = $request->get($field);
|
||||
|
@ -37,7 +37,7 @@ class Transaction extends FormRequest
|
||||
$attachment = 'mimes:' . config('filesystems.mimes') . '|between:0,' . config('filesystems.max_size') * 1024;
|
||||
}
|
||||
|
||||
return [
|
||||
$rules = [
|
||||
'type' => 'required|string',
|
||||
'number' => 'required|string|unique:transactions,NULL,' . $id . ',id,company_id,' . $company_id . ',deleted_at,NULL',
|
||||
'account_id' => 'required|integer',
|
||||
@ -53,6 +53,29 @@ class Transaction extends FormRequest
|
||||
'recurring_count' => 'gte:0',
|
||||
'recurring_interval' => 'exclude_unless:recurring_frequency,custom|gt:0',
|
||||
];
|
||||
|
||||
// Is Recurring
|
||||
if ($this->request->has('recurring_frequency')) {
|
||||
// first line of the recurring rule
|
||||
if ($this->request->get('recurring_frequency') == 'custom') {
|
||||
$rules['recurring_interval'] = 'required|gte:1';
|
||||
$rules['recurring_custom_frequency'] = 'required|string|in:daily,weekly,monthly,yearly';
|
||||
}
|
||||
|
||||
// second line of the recurring rule
|
||||
$rules['recurring_started_at'] = 'required|date_format:Y-m-d H:i:s';
|
||||
|
||||
switch($this->request->get('recurring_limit')) {
|
||||
case 'date':
|
||||
$rules['recurring_limit_date'] = 'required|date_format:Y-m-d H:i:s|after_or_equal:recurring_started_at';
|
||||
break;
|
||||
case 'count':
|
||||
$rules['recurring_limit_count'] = 'required|gte:0';
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return $rules;
|
||||
}
|
||||
|
||||
public function withValidator($validator)
|
||||
@ -61,6 +84,18 @@ class Transaction extends FormRequest
|
||||
$paid_at = Date::parse($this->request->get('paid_at'))->format('Y-m-d');
|
||||
|
||||
$this->request->set('paid_at', $paid_at);
|
||||
|
||||
if ($this->request->get('recurring_started_at')) {
|
||||
$recurring_started_at = Date::parse($this->request->get('recurring_started_at'))->format('Y-m-d');
|
||||
|
||||
$this->request->set('recurring_started_at', $recurring_started_at);
|
||||
}
|
||||
|
||||
if ($this->request->get('recurring_limit_date')) {
|
||||
$recurring_limit_date = Date::parse($this->request->get('recurring_limit_date'))->format('Y-m-d');
|
||||
|
||||
$this->request->set('recurring_limit_date', $recurring_limit_date);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -65,6 +65,27 @@ class Document extends FormRequest
|
||||
'recurring_interval' => 'exclude_unless:recurring_frequency,custom|gt:0',
|
||||
];
|
||||
|
||||
// Is Recurring
|
||||
if ($this->request->has('recurring_frequency')) {
|
||||
// first line of the recurring rule
|
||||
if ($this->request->get('recurring_frequency') == 'custom') {
|
||||
$rules['recurring_interval'] = 'required|gte:1';
|
||||
$rules['recurring_custom_frequency'] = 'required|string|in:daily,weekly,monthly,yearly';
|
||||
}
|
||||
|
||||
// second line of the recurring rule
|
||||
$rules['recurring_started_at'] = 'required|date_format:Y-m-d H:i:s';
|
||||
|
||||
switch($this->request->get('recurring_limit')) {
|
||||
case 'date':
|
||||
$rules['recurring_limit_date'] = 'required|date_format:Y-m-d H:i:s|after_or_equal:recurring_started_at';
|
||||
break;
|
||||
case 'count':
|
||||
$rules['recurring_limit_count'] = 'required|gte:0';
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
$items = $this->request->all('items');
|
||||
|
||||
if ($items) {
|
||||
@ -93,6 +114,18 @@ class Document extends FormRequest
|
||||
|
||||
$this->request->set('issued_at', $issued_at);
|
||||
$this->request->set('due_at', $due_at);
|
||||
|
||||
if ($this->request->get('recurring_started_at')) {
|
||||
$recurring_started_at = Date::parse($this->request->get('recurring_started_at'))->format('Y-m-d');
|
||||
|
||||
$this->request->set('recurring_started_at', $recurring_started_at);
|
||||
}
|
||||
|
||||
if ($this->request->get('recurring_limit_date')) {
|
||||
$recurring_limit_date = Date::parse($this->request->get('recurring_limit_date'))->format('Y-m-d');
|
||||
|
||||
$this->request->set('recurring_limit_date', $recurring_limit_date);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -118,6 +151,8 @@ class Document extends FormRequest
|
||||
'height' => config('filesystems.max_height'),
|
||||
]);
|
||||
|
||||
$messages['recurring_limit_date.after_or_equal'] = trans('');
|
||||
|
||||
return $messages;
|
||||
}
|
||||
}
|
||||
|
@ -20,6 +20,8 @@
|
||||
|
||||
<input type="text" class="w-20 text-sm px-3 py-2.5 mt-1 rounded-lg border border-light-gray text-black placeholder-light-gray bg-white disabled:bg-gray-200 focus:outline-none focus:ring-transparent focus:border-purple" v-model="interval" @input="change" v-if="frequency == 'custom'">
|
||||
|
||||
<div class="text-red text-sm mt-1 block" v-if="invertalError" v-html="invertalError"></div>
|
||||
|
||||
<el-select class="w-36 ml-2" v-model="customFrequency" @input="change" v-if="frequency == 'custom'">
|
||||
<el-option
|
||||
v-for="(label, value) in customFrequencies"
|
||||
@ -28,6 +30,8 @@
|
||||
:value="value">
|
||||
</el-option>
|
||||
</el-select>
|
||||
|
||||
<div class="text-red text-sm mt-1 block" v-if="customFrequencyError" v-html="customFrequencyError"></div>
|
||||
</div>
|
||||
|
||||
<div class="flex flex-wrap lg:flex-nowrap items-center space-y-3 lg:space-y-0" :class="{ 'justify-start': limit !== 'never' }">
|
||||
@ -76,6 +80,8 @@
|
||||
}">
|
||||
</el-date-picker>
|
||||
|
||||
<div class="text-red text-sm mt-1 block" v-if="startedError" v-html="startedError"></div>
|
||||
|
||||
<div class="w-24 px-2 text-sm text-center">
|
||||
{{ middleText }}
|
||||
</div>
|
||||
@ -91,6 +97,8 @@
|
||||
|
||||
<input type="text" class="w-20 text-sm px-3 py-2.5 mt-1 ml-2 rounded-lg border border-light-gray text-black placeholder-light-gray bg-white disabled:bg-gray-200 focus:outline-none focus:ring-transparent focus:border-purple" v-model="limitCount" v-if="limit == 'after'" @input="change">
|
||||
|
||||
<div class="text-red text-sm mt-1 block" v-if="limitCountError" v-html="limitCountError"></div>
|
||||
|
||||
<div class="pl-2 text-sm" v-if="limit == 'after'">
|
||||
{{ endText }}
|
||||
</div>
|
||||
@ -106,6 +114,8 @@
|
||||
@input="change"
|
||||
>
|
||||
</el-date-picker>
|
||||
|
||||
<div class="text-red text-sm mt-1 block" v-if="limitDateError" v-html="limitDateError"></div>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
@ -163,6 +173,11 @@ export default {
|
||||
default: 'monthly',
|
||||
description: "Default reccuring type"
|
||||
},
|
||||
invertalError: {
|
||||
type: String,
|
||||
default: null,
|
||||
description: "Selectbox input error message"
|
||||
},
|
||||
|
||||
customFrequencies: null,
|
||||
customFrequencyValue: {
|
||||
@ -170,12 +185,22 @@ export default {
|
||||
default: 'monthly',
|
||||
description: "Default reccuring type"
|
||||
},
|
||||
customFrequencyError: {
|
||||
type: String,
|
||||
default: null,
|
||||
description: "Selectbox input error message"
|
||||
},
|
||||
|
||||
startedValue: {
|
||||
type: String,
|
||||
default: 'never',
|
||||
description: "Default reccuring limit"
|
||||
},
|
||||
startedError: {
|
||||
type: String,
|
||||
default: null,
|
||||
description: "Selectbox input error message"
|
||||
},
|
||||
|
||||
limits: null,
|
||||
|
||||
@ -190,12 +215,22 @@ export default {
|
||||
default: 0,
|
||||
description: "Default reccuring limit"
|
||||
},
|
||||
limitCountError: {
|
||||
type: String,
|
||||
default: null,
|
||||
description: "Selectbox input error message"
|
||||
},
|
||||
|
||||
limitDateValue: {
|
||||
type: String,
|
||||
default: '',
|
||||
description: "Default reccuring limit"
|
||||
},
|
||||
limitDateError: {
|
||||
type: String,
|
||||
default: null,
|
||||
description: "Selectbox input error message"
|
||||
},
|
||||
|
||||
dateFormat: {
|
||||
type: String,
|
||||
|
@ -23,12 +23,14 @@
|
||||
@else
|
||||
@interval="form.recurring_interval = $event"
|
||||
@endif
|
||||
:invertal-error="form.errors.get('recurring_interval')"
|
||||
|
||||
@if ($attributes->has('@custom_frequency'))
|
||||
@custom_frequency="form.recurring_custom_frequency = $event;{{ $attributes['@custom_frequency'] }}"
|
||||
@else
|
||||
@custom_frequency="form.recurring_custom_frequency = $event"
|
||||
@endif
|
||||
:custom-frequency-error="form.errors.get('recurring_custom_frequency')"
|
||||
|
||||
started-value="{{ $startedValue }}"
|
||||
@if ($attributes->has('@started'))
|
||||
@ -36,6 +38,7 @@
|
||||
@else
|
||||
@started="form.recurring_started_at = $event"
|
||||
@endif
|
||||
:started-error="form.errors.get('recurring_started_at')"
|
||||
|
||||
:limits="{{ json_encode($limits) }}"
|
||||
limit-value="{{ $limit }}"
|
||||
@ -52,6 +55,7 @@
|
||||
@else
|
||||
@limit_count="form.recurring_limit_count = $event"
|
||||
@endif
|
||||
:limit-count-error="form.errors.get('recurring_limit_count')"
|
||||
|
||||
limit-date-value="{{ $limitDateValue }}"
|
||||
@if ($attributes->has('@limit_date'))
|
||||
@ -59,6 +63,7 @@
|
||||
@else
|
||||
@limit_date="form.recurring_limit_date = $event"
|
||||
@endif
|
||||
:limit-date-error="form.errors.get('recurring_limit_date')"
|
||||
|
||||
date-format="{{ company_date_format() }}"
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user