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)
|
public function handle($request, Closure $next)
|
||||||
{
|
{
|
||||||
if (($request->method() == 'POST') || ($request->method() == 'PATCH')) {
|
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) {
|
foreach ($fields as $field) {
|
||||||
$date = $request->get($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;
|
$attachment = 'mimes:' . config('filesystems.mimes') . '|between:0,' . config('filesystems.max_size') * 1024;
|
||||||
}
|
}
|
||||||
|
|
||||||
return [
|
$rules = [
|
||||||
'type' => 'required|string',
|
'type' => 'required|string',
|
||||||
'number' => 'required|string|unique:transactions,NULL,' . $id . ',id,company_id,' . $company_id . ',deleted_at,NULL',
|
'number' => 'required|string|unique:transactions,NULL,' . $id . ',id,company_id,' . $company_id . ',deleted_at,NULL',
|
||||||
'account_id' => 'required|integer',
|
'account_id' => 'required|integer',
|
||||||
@ -53,6 +53,29 @@ class Transaction extends FormRequest
|
|||||||
'recurring_count' => 'gte:0',
|
'recurring_count' => 'gte:0',
|
||||||
'recurring_interval' => 'exclude_unless:recurring_frequency,custom|gt: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)
|
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');
|
$paid_at = Date::parse($this->request->get('paid_at'))->format('Y-m-d');
|
||||||
|
|
||||||
$this->request->set('paid_at', $paid_at);
|
$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',
|
'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');
|
$items = $this->request->all('items');
|
||||||
|
|
||||||
if ($items) {
|
if ($items) {
|
||||||
@ -93,6 +114,18 @@ class Document extends FormRequest
|
|||||||
|
|
||||||
$this->request->set('issued_at', $issued_at);
|
$this->request->set('issued_at', $issued_at);
|
||||||
$this->request->set('due_at', $due_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'),
|
'height' => config('filesystems.max_height'),
|
||||||
]);
|
]);
|
||||||
|
|
||||||
|
$messages['recurring_limit_date.after_or_equal'] = trans('');
|
||||||
|
|
||||||
return $messages;
|
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'">
|
<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-select class="w-36 ml-2" v-model="customFrequency" @input="change" v-if="frequency == 'custom'">
|
||||||
<el-option
|
<el-option
|
||||||
v-for="(label, value) in customFrequencies"
|
v-for="(label, value) in customFrequencies"
|
||||||
@ -28,6 +30,8 @@
|
|||||||
:value="value">
|
:value="value">
|
||||||
</el-option>
|
</el-option>
|
||||||
</el-select>
|
</el-select>
|
||||||
|
|
||||||
|
<div class="text-red text-sm mt-1 block" v-if="customFrequencyError" v-html="customFrequencyError"></div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="flex flex-wrap lg:flex-nowrap items-center space-y-3 lg:space-y-0" :class="{ 'justify-start': limit !== 'never' }">
|
<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>
|
</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">
|
<div class="w-24 px-2 text-sm text-center">
|
||||||
{{ middleText }}
|
{{ middleText }}
|
||||||
</div>
|
</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">
|
<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'">
|
<div class="pl-2 text-sm" v-if="limit == 'after'">
|
||||||
{{ endText }}
|
{{ endText }}
|
||||||
</div>
|
</div>
|
||||||
@ -106,6 +114,8 @@
|
|||||||
@input="change"
|
@input="change"
|
||||||
>
|
>
|
||||||
</el-date-picker>
|
</el-date-picker>
|
||||||
|
|
||||||
|
<div class="text-red text-sm mt-1 block" v-if="limitDateError" v-html="limitDateError"></div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
@ -163,6 +173,11 @@ export default {
|
|||||||
default: 'monthly',
|
default: 'monthly',
|
||||||
description: "Default reccuring type"
|
description: "Default reccuring type"
|
||||||
},
|
},
|
||||||
|
invertalError: {
|
||||||
|
type: String,
|
||||||
|
default: null,
|
||||||
|
description: "Selectbox input error message"
|
||||||
|
},
|
||||||
|
|
||||||
customFrequencies: null,
|
customFrequencies: null,
|
||||||
customFrequencyValue: {
|
customFrequencyValue: {
|
||||||
@ -170,12 +185,22 @@ export default {
|
|||||||
default: 'monthly',
|
default: 'monthly',
|
||||||
description: "Default reccuring type"
|
description: "Default reccuring type"
|
||||||
},
|
},
|
||||||
|
customFrequencyError: {
|
||||||
|
type: String,
|
||||||
|
default: null,
|
||||||
|
description: "Selectbox input error message"
|
||||||
|
},
|
||||||
|
|
||||||
startedValue: {
|
startedValue: {
|
||||||
type: String,
|
type: String,
|
||||||
default: 'never',
|
default: 'never',
|
||||||
description: "Default reccuring limit"
|
description: "Default reccuring limit"
|
||||||
},
|
},
|
||||||
|
startedError: {
|
||||||
|
type: String,
|
||||||
|
default: null,
|
||||||
|
description: "Selectbox input error message"
|
||||||
|
},
|
||||||
|
|
||||||
limits: null,
|
limits: null,
|
||||||
|
|
||||||
@ -190,12 +215,22 @@ export default {
|
|||||||
default: 0,
|
default: 0,
|
||||||
description: "Default reccuring limit"
|
description: "Default reccuring limit"
|
||||||
},
|
},
|
||||||
|
limitCountError: {
|
||||||
|
type: String,
|
||||||
|
default: null,
|
||||||
|
description: "Selectbox input error message"
|
||||||
|
},
|
||||||
|
|
||||||
limitDateValue: {
|
limitDateValue: {
|
||||||
type: String,
|
type: String,
|
||||||
default: '',
|
default: '',
|
||||||
description: "Default reccuring limit"
|
description: "Default reccuring limit"
|
||||||
},
|
},
|
||||||
|
limitDateError: {
|
||||||
|
type: String,
|
||||||
|
default: null,
|
||||||
|
description: "Selectbox input error message"
|
||||||
|
},
|
||||||
|
|
||||||
dateFormat: {
|
dateFormat: {
|
||||||
type: String,
|
type: String,
|
||||||
|
@ -23,12 +23,14 @@
|
|||||||
@else
|
@else
|
||||||
@interval="form.recurring_interval = $event"
|
@interval="form.recurring_interval = $event"
|
||||||
@endif
|
@endif
|
||||||
|
:invertal-error="form.errors.get('recurring_interval')"
|
||||||
|
|
||||||
@if ($attributes->has('@custom_frequency'))
|
@if ($attributes->has('@custom_frequency'))
|
||||||
@custom_frequency="form.recurring_custom_frequency = $event;{{ $attributes['@custom_frequency'] }}"
|
@custom_frequency="form.recurring_custom_frequency = $event;{{ $attributes['@custom_frequency'] }}"
|
||||||
@else
|
@else
|
||||||
@custom_frequency="form.recurring_custom_frequency = $event"
|
@custom_frequency="form.recurring_custom_frequency = $event"
|
||||||
@endif
|
@endif
|
||||||
|
:custom-frequency-error="form.errors.get('recurring_custom_frequency')"
|
||||||
|
|
||||||
started-value="{{ $startedValue }}"
|
started-value="{{ $startedValue }}"
|
||||||
@if ($attributes->has('@started'))
|
@if ($attributes->has('@started'))
|
||||||
@ -36,6 +38,7 @@
|
|||||||
@else
|
@else
|
||||||
@started="form.recurring_started_at = $event"
|
@started="form.recurring_started_at = $event"
|
||||||
@endif
|
@endif
|
||||||
|
:started-error="form.errors.get('recurring_started_at')"
|
||||||
|
|
||||||
:limits="{{ json_encode($limits) }}"
|
:limits="{{ json_encode($limits) }}"
|
||||||
limit-value="{{ $limit }}"
|
limit-value="{{ $limit }}"
|
||||||
@ -52,6 +55,7 @@
|
|||||||
@else
|
@else
|
||||||
@limit_count="form.recurring_limit_count = $event"
|
@limit_count="form.recurring_limit_count = $event"
|
||||||
@endif
|
@endif
|
||||||
|
:limit-count-error="form.errors.get('recurring_limit_count')"
|
||||||
|
|
||||||
limit-date-value="{{ $limitDateValue }}"
|
limit-date-value="{{ $limitDateValue }}"
|
||||||
@if ($attributes->has('@limit_date'))
|
@if ($attributes->has('@limit_date'))
|
||||||
@ -59,9 +63,10 @@
|
|||||||
@else
|
@else
|
||||||
@limit_date="form.recurring_limit_date = $event"
|
@limit_date="form.recurring_limit_date = $event"
|
||||||
@endif
|
@endif
|
||||||
|
:limit-date-error="form.errors.get('recurring_limit_date')"
|
||||||
|
|
||||||
date-format="{{ company_date_format() }}"
|
date-format="{{ company_date_format() }}"
|
||||||
|
|
||||||
{{ $attributes }}
|
{{ $attributes }}
|
||||||
>
|
>
|
||||||
</akaunting-recurring>
|
</akaunting-recurring>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user