fixed report search invalid date format issue
This commit is contained in:
parent
543d180060
commit
776e8c8599
|
|
@ -4,6 +4,7 @@ namespace App\Http\Controllers\Common;
|
|||
|
||||
use App\Abstracts\Http\Controller;
|
||||
use App\Http\Requests\Common\Report as Request;
|
||||
use App\Http\Requests\Common\ReportShow as ShowRequest;
|
||||
use App\Jobs\Common\CreateReport;
|
||||
use App\Jobs\Common\DeleteReport;
|
||||
use App\Jobs\Common\UpdateReport;
|
||||
|
|
@ -66,9 +67,10 @@ class Reports extends Controller
|
|||
* Show the form for viewing the specified resource.
|
||||
*
|
||||
* @param Report $report
|
||||
* @param ShowRequest $request
|
||||
* @return Response
|
||||
*/
|
||||
public function show(Report $report)
|
||||
public function show(Report $report, ShowRequest $request)
|
||||
{
|
||||
if (Utility::cannotShow($report->class)) {
|
||||
abort(403);
|
||||
|
|
|
|||
|
|
@ -0,0 +1,51 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http\Requests\Common;
|
||||
|
||||
use App\Abstracts\Http\FormRequest;
|
||||
use Illuminate\Contracts\Validation\Validator;
|
||||
|
||||
class ReportShow extends FormRequest
|
||||
{
|
||||
/**
|
||||
* Get the validation rules that apply to the request.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function rules()
|
||||
{
|
||||
return [
|
||||
'start_date' => 'nullable|date',
|
||||
'end_date' => 'nullable|date',
|
||||
];
|
||||
}
|
||||
|
||||
public function failedValidation(Validator $validator)
|
||||
{
|
||||
// "If start_date and end_date is invalid, clear the values
|
||||
if ($validator->errors()->has('start_date') && $validator->errors()->has('end_date')) {
|
||||
request()->query->remove('start_date');
|
||||
request()->query->remove('end_date');
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
// If start_date is invalid, set it to be equal to end_date.
|
||||
if ($validator->errors()->has('start_date')) {
|
||||
request()->merge([
|
||||
'start_date' => request('end_date'),
|
||||
]);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
// If end_date is invalid, set it to be equal to start_date.
|
||||
if ($validator->errors()->has('end_date')) {
|
||||
request()->merge([
|
||||
'end_date' => request('start_date'),
|
||||
]);
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -176,7 +176,7 @@
|
|||
import moment from 'moment';
|
||||
import flatPicker from "vue-flatpickr-component";
|
||||
import "flatpickr/dist/flatpickr.css";
|
||||
import {getQueryVariable} from './../plugins/functions';
|
||||
import {getQueryVariable, removeURLParameter} from './../plugins/functions';
|
||||
|
||||
export default {
|
||||
name: 'akaunting-search',
|
||||
|
|
@ -486,7 +486,7 @@ export default {
|
|||
let dates = this.selected_values[index].key.split('-to-');
|
||||
|
||||
date_range_path += sign + 'start_date=' + dates[0];
|
||||
date_range_path += '&end_date=' + (dates[1] ? dates[1] : dates[0]);
|
||||
date_range_path += '&end_date=' + dates[1];
|
||||
|
||||
return;
|
||||
}
|
||||
|
|
@ -1088,6 +1088,15 @@ export default {
|
|||
}
|
||||
|
||||
if (getQueryVariable('start_date') && getQueryVariable('end_date')) {
|
||||
let start = new Date(getQueryVariable('start_date'));
|
||||
let end = new Date(getQueryVariable('end_date'));
|
||||
let start_date = getQueryVariable('start_date');
|
||||
let end_date = getQueryVariable('end_date');
|
||||
|
||||
if ((start instanceof Date && ! isNaN(start)) || (end instanceof Date && ! isNaN(end))) {
|
||||
start_date = (start instanceof Date && ! isNaN(start)) ? start_date : ((end instanceof Date && ! isNaN(end)) ? end_date : false);
|
||||
end_date = (end instanceof Date && ! isNaN(end)) ? end_date : ((start instanceof Date && ! isNaN(start)) ? start_date : false);
|
||||
|
||||
this.filter_list.forEach(function (_filter, i) {
|
||||
if (_filter.key != 'date_range') {
|
||||
return;
|
||||
|
|
@ -1106,7 +1115,7 @@ export default {
|
|||
|
||||
this.option_values[_filter.key] = filter_values;
|
||||
|
||||
let date_range_value = getQueryVariable('start_date') + '-to-' + getQueryVariable('end_date');
|
||||
let date_range_value = start_date + '-to-' + end_date;
|
||||
|
||||
filter_values.forEach(function (value, j) {
|
||||
if (value.key == date_range_value) {
|
||||
|
|
@ -1141,6 +1150,10 @@ export default {
|
|||
|
||||
this.filter_index++;
|
||||
}, this);
|
||||
} else {
|
||||
removeURLParameter('start_date');
|
||||
removeURLParameter('end_date');
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
|
|
|
|||
|
|
@ -15,6 +15,16 @@ function getQueryVariable(variable) {
|
|||
return(false);
|
||||
}
|
||||
|
||||
function removeURLParameter(param) {
|
||||
let url = window.location.href;
|
||||
let regex = new RegExp("[?&]" + param + "(=[^&#]*)?", "g");
|
||||
|
||||
url = url.replace(regex, "");
|
||||
url = url.replace(/[?&]$/, "");
|
||||
|
||||
window.history.replaceState({}, document.title, url);
|
||||
}
|
||||
|
||||
const { evaluate } = require('mathjs');
|
||||
|
||||
// use the evaluate function to evaluate the expression
|
||||
|
|
@ -30,4 +40,4 @@ const setPromiseTimeout = time =>
|
|||
, time)
|
||||
);
|
||||
|
||||
export {getQueryVariable, calculationToQuantity, setPromiseTimeout}
|
||||
export {getQueryVariable, removeURLParameter, calculationToQuantity, setPromiseTimeout}
|
||||
|
|
|
|||
Loading…
Reference in New Issue