2022-01-20 02:15:33 +01:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* Invoice Ninja (https://invoiceninja.com).
|
|
|
|
*
|
|
|
|
* @link https://github.com/invoiceninja/invoiceninja source repository
|
|
|
|
*
|
2024-04-12 06:15:41 +02:00
|
|
|
* @copyright Copyright (c) 2024. Invoice Ninja LLC (https://invoiceninja.com)
|
2022-01-20 02:15:33 +01:00
|
|
|
*
|
|
|
|
* @license https://www.elastic.co/licensing/elastic-license
|
|
|
|
*/
|
|
|
|
|
|
|
|
namespace App\Http\Requests\Chart;
|
|
|
|
|
|
|
|
use App\Http\Requests\Request;
|
2023-06-26 07:14:58 +02:00
|
|
|
use App\Utils\Traits\MakesDates;
|
2022-01-20 02:15:33 +01:00
|
|
|
|
|
|
|
class ShowChartRequest extends Request
|
|
|
|
{
|
2023-06-26 07:14:58 +02:00
|
|
|
use MakesDates;
|
|
|
|
|
2022-01-20 02:15:33 +01:00
|
|
|
/**
|
|
|
|
* Determine if the user is authorized to make this request.
|
|
|
|
*
|
|
|
|
* @return bool
|
|
|
|
*/
|
2024-01-14 05:05:00 +01:00
|
|
|
public function authorize(): bool
|
2022-01-20 02:15:33 +01:00
|
|
|
{
|
2023-06-26 07:14:58 +02:00
|
|
|
/**@var \App\Models\User auth()->user */
|
|
|
|
$user = auth()->user();
|
|
|
|
|
2023-08-06 23:33:33 +02:00
|
|
|
return $user->isAdmin() || $user->hasPermission('view_dashboard');
|
2022-01-20 02:15:33 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public function rules()
|
|
|
|
{
|
|
|
|
return [
|
2023-06-26 04:56:57 +02:00
|
|
|
'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',
|
2022-01-20 02:15:33 +01:00
|
|
|
];
|
|
|
|
}
|
2022-01-21 02:00:32 +01:00
|
|
|
|
2022-06-24 03:55:41 +02:00
|
|
|
public function prepareForValidation()
|
2022-01-21 02:00:32 +01:00
|
|
|
{
|
2024-01-14 05:05:00 +01:00
|
|
|
|
2023-08-06 23:34:37 +02:00
|
|
|
/**@var \App\Models\User auth()->user */
|
|
|
|
$user = auth()->user();
|
|
|
|
|
2022-01-21 02:00:32 +01:00
|
|
|
$input = $this->all();
|
|
|
|
|
2023-06-26 07:14:58 +02:00
|
|
|
if(isset($input['date_range'])) {
|
2023-08-06 23:34:37 +02:00
|
|
|
$dates = $this->calculateStartAndEndDates($input, $user->company());
|
2023-06-26 07:14:58 +02:00
|
|
|
$input['start_date'] = $dates[0];
|
|
|
|
$input['end_date'] = $dates[1];
|
2022-06-21 11:57:17 +02:00
|
|
|
}
|
2022-01-21 02:00:32 +01:00
|
|
|
|
2023-06-26 07:14:58 +02:00
|
|
|
if (! isset($input['start_date'])) {
|
|
|
|
$input['start_date'] = now()->subDays(20)->format('Y-m-d');
|
2022-06-21 11:57:17 +02:00
|
|
|
}
|
2022-01-21 02:00:32 +01:00
|
|
|
|
2023-06-26 07:14:58 +02:00
|
|
|
if (! isset($input['end_date'])) {
|
2024-03-28 02:24:01 +01:00
|
|
|
// $input['end_date'] = now()->lastOfMonth()->format('Y-m-d');
|
2023-06-26 07:14:58 +02:00
|
|
|
$input['end_date'] = now()->format('Y-m-d');
|
|
|
|
}
|
|
|
|
|
2022-01-21 02:00:32 +01:00
|
|
|
$this->replace($input);
|
|
|
|
}
|
2022-01-20 02:15:33 +01:00
|
|
|
}
|