mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2024-11-10 21:22:58 +01:00
64 lines
1.6 KiB
PHP
64 lines
1.6 KiB
PHP
<?php
|
|
/**
|
|
* Invoice Ninja (https://invoiceninja.com).
|
|
*
|
|
* @link https://github.com/invoiceninja/invoiceninja source repository
|
|
*
|
|
* @copyright Copyright (c) 2023. Invoice Ninja LLC (https://invoiceninja.com)
|
|
*
|
|
* @license https://www.elastic.co/licensing/elastic-license
|
|
*/
|
|
|
|
namespace App\Http\Requests\Chart;
|
|
|
|
use App\Http\Requests\Request;
|
|
use App\Utils\Traits\MakesDates;
|
|
|
|
class ShowChartRequest extends Request
|
|
{
|
|
use MakesDates;
|
|
|
|
/**
|
|
* Determine if the user is authorized to make this request.
|
|
*
|
|
* @return bool
|
|
*/
|
|
public function authorize() : bool
|
|
{
|
|
/**@var \App\Models\User auth()->user */
|
|
$user = auth()->user();
|
|
|
|
return $user->isAdmin();
|
|
}
|
|
|
|
public function rules()
|
|
{
|
|
return [
|
|
'date_range' => 'bail|sometimes|string|in:last7_days,last30_days,last365_days,this_month,last_month,this_quarter,last_quarter,this_year,last_year,all_time,custom',
|
|
'start_date' => 'bail|sometimes|date',
|
|
'end_date' => 'bail|sometimes|date',
|
|
];
|
|
}
|
|
|
|
public function prepareForValidation()
|
|
{
|
|
$input = $this->all();
|
|
|
|
if(isset($input['date_range'])) {
|
|
$dates = $this->calculateStartAndEndDates($input);
|
|
$input['start_date'] = $dates[0];
|
|
$input['end_date'] = $dates[1];
|
|
}
|
|
|
|
if (! isset($input['start_date'])) {
|
|
$input['start_date'] = now()->subDays(20)->format('Y-m-d');
|
|
}
|
|
|
|
if (! isset($input['end_date'])) {
|
|
$input['end_date'] = now()->format('Y-m-d');
|
|
}
|
|
|
|
$this->replace($input);
|
|
}
|
|
}
|