mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2026-01-11 00:16:54 +00:00
This commit is contained in:
@@ -9,11 +9,13 @@ use FireflyIII\Rules\IsBoolean;
|
||||
use FireflyIII\Rules\IsValidPositiveAmount;
|
||||
use FireflyIII\Rules\UniqueAccountNumber;
|
||||
use FireflyIII\Rules\UniqueIban;
|
||||
use FireflyIII\Support\Request\ConvertsDataTypes;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use LaravelJsonApi\Laravel\Http\Requests\ResourceRequest;
|
||||
|
||||
class AccountRequest extends ResourceRequest
|
||||
{
|
||||
use ConvertsDataTypes;
|
||||
/**
|
||||
* Get the validation rules for the resource.
|
||||
*/
|
||||
|
||||
@@ -41,9 +41,8 @@ trait DateCalculation
|
||||
{
|
||||
$difference = (int)($start->diffInDays($end, true) + 1);
|
||||
$today = today(config('app.timezone'))->startOfDay();
|
||||
|
||||
if ($start->lte($today) && $end->gte($today)) {
|
||||
$difference = $today->diffInDays($end);
|
||||
$difference = $today->diffInDays($end) + 1;
|
||||
}
|
||||
|
||||
return (int)(0 === $difference ? 1 : $difference);
|
||||
|
||||
@@ -130,6 +130,8 @@ trait GetConfigurationData
|
||||
|
||||
/** @var Carbon $todayEnd */
|
||||
$todayEnd = app('navigation')->endOfPeriod($todayStart, $viewRange);
|
||||
|
||||
|
||||
if ($todayStart->ne($start) || $todayEnd->ne($end)) {
|
||||
$ranges[ucfirst((string)trans('firefly.today'))] = [$todayStart, $todayEnd];
|
||||
}
|
||||
|
||||
@@ -177,6 +177,7 @@ class Navigation
|
||||
'year' => 'startOfYear',
|
||||
'yearly' => 'startOfYear',
|
||||
'1Y' => 'startOfYear',
|
||||
'MTD' => 'startOfMonth',
|
||||
];
|
||||
|
||||
$parameterMap = [
|
||||
@@ -274,13 +275,20 @@ class Navigation
|
||||
|
||||
/** @var Carbon $tEnd */
|
||||
$tEnd = session('end', today(config('app.timezone'))->endOfMonth());
|
||||
$diffInDays = (int)$tStart->diffInDays($tEnd, true);
|
||||
$diffInDays = (int) $tStart->diffInDays($tEnd, true);
|
||||
}
|
||||
Log::debug(sprintf('Diff in days is %d', $diffInDays));
|
||||
$currentEnd->addDays($diffInDays);
|
||||
|
||||
return $currentEnd;
|
||||
}
|
||||
if('MTD' === $repeatFreq) {
|
||||
$today = today();
|
||||
if($today->isSameMonth($end)) {
|
||||
return $today->endOfDay();
|
||||
}
|
||||
return $end->endOfMonth();
|
||||
}
|
||||
|
||||
$result = match ($repeatFreq) {
|
||||
'last7' => $currentEnd->addDays(7)->startOfDay(),
|
||||
@@ -327,7 +335,7 @@ class Navigation
|
||||
{
|
||||
$endOfMonth = $date->copy()->endOfMonth();
|
||||
|
||||
return (int)$date->diffInDays($endOfMonth, true);
|
||||
return (int) $date->diffInDays($endOfMonth, true);
|
||||
}
|
||||
|
||||
public function diffInPeriods(string $period, int $skip, Carbon $beginning, Carbon $end): int
|
||||
@@ -382,7 +390,7 @@ class Navigation
|
||||
));
|
||||
}
|
||||
|
||||
return (int)$diff;
|
||||
return (int) $diff;
|
||||
}
|
||||
|
||||
public function endOfX(Carbon $theCurrentEnd, string $repeatFreq, ?Carbon $maxDate): Carbon
|
||||
@@ -428,7 +436,7 @@ class Navigation
|
||||
if (is_array($range)) {
|
||||
$range = '1M';
|
||||
}
|
||||
$range = (string)$range;
|
||||
$range = (string) $range;
|
||||
if (!$correct) {
|
||||
return $range;
|
||||
}
|
||||
@@ -463,18 +471,18 @@ class Navigation
|
||||
// define period to increment
|
||||
$increment = 'addDay';
|
||||
$format = $this->preferredCarbonFormat($start, $end);
|
||||
$displayFormat = (string)trans('config.month_and_day_js', [], $locale);
|
||||
$displayFormat = (string) trans('config.month_and_day_js', [], $locale);
|
||||
$diff = $start->diffInMonths($end, true);
|
||||
// increment by month (for year)
|
||||
if ($diff >= 1.0001) {
|
||||
$increment = 'addMonth';
|
||||
$displayFormat = (string)trans('config.month_js');
|
||||
$displayFormat = (string) trans('config.month_js');
|
||||
}
|
||||
|
||||
// increment by year (for multi-year)
|
||||
if ($diff >= 12.0001) {
|
||||
$increment = 'addYear';
|
||||
$displayFormat = (string)trans('config.year_js');
|
||||
$displayFormat = (string) trans('config.year_js');
|
||||
}
|
||||
$begin = clone $start;
|
||||
$entries = [];
|
||||
@@ -514,19 +522,19 @@ class Navigation
|
||||
{
|
||||
$date = clone $theDate;
|
||||
$formatMap = [
|
||||
'1D' => (string)trans('config.specific_day_js'),
|
||||
'daily' => (string)trans('config.specific_day_js'),
|
||||
'custom' => (string)trans('config.specific_day_js'),
|
||||
'1W' => (string)trans('config.week_in_year_js'),
|
||||
'week' => (string)trans('config.week_in_year_js'),
|
||||
'weekly' => (string)trans('config.week_in_year_js'),
|
||||
'1M' => (string)trans('config.month_js'),
|
||||
'month' => (string)trans('config.month_js'),
|
||||
'monthly' => (string)trans('config.month_js'),
|
||||
'1Y' => (string)trans('config.year_js'),
|
||||
'year' => (string)trans('config.year_js'),
|
||||
'yearly' => (string)trans('config.year_js'),
|
||||
'6M' => (string)trans('config.half_year_js'),
|
||||
'1D' => (string) trans('config.specific_day_js'),
|
||||
'daily' => (string) trans('config.specific_day_js'),
|
||||
'custom' => (string) trans('config.specific_day_js'),
|
||||
'1W' => (string) trans('config.week_in_year_js'),
|
||||
'week' => (string) trans('config.week_in_year_js'),
|
||||
'weekly' => (string) trans('config.week_in_year_js'),
|
||||
'1M' => (string) trans('config.month_js'),
|
||||
'month' => (string) trans('config.month_js'),
|
||||
'monthly' => (string) trans('config.month_js'),
|
||||
'1Y' => (string) trans('config.year_js'),
|
||||
'year' => (string) trans('config.year_js'),
|
||||
'yearly' => (string) trans('config.year_js'),
|
||||
'6M' => (string) trans('config.half_year_js'),
|
||||
];
|
||||
|
||||
if (array_key_exists($repeatFrequency, $formatMap)) {
|
||||
@@ -567,13 +575,13 @@ class Navigation
|
||||
public function preferredCarbonLocalizedFormat(Carbon $start, Carbon $end): string
|
||||
{
|
||||
$locale = app('steam')->getLocale();
|
||||
$format = (string)trans('config.month_and_day_js', [], $locale);
|
||||
$format = (string) trans('config.month_and_day_js', [], $locale);
|
||||
if ($start->diffInMonths($end, true) > 1) {
|
||||
$format = (string)trans('config.month_js', [], $locale);
|
||||
$format = (string) trans('config.month_js', [], $locale);
|
||||
}
|
||||
|
||||
if ($start->diffInMonths($end, true) > 12) {
|
||||
$format = (string)trans('config.year_js', [], $locale);
|
||||
$format = (string) trans('config.year_js', [], $locale);
|
||||
}
|
||||
|
||||
return $format;
|
||||
@@ -586,11 +594,11 @@ class Navigation
|
||||
public function preferredEndOfPeriod(Carbon $start, Carbon $end): string
|
||||
{
|
||||
$format = 'endOfDay';
|
||||
if ((int)$start->diffInMonths($end, true) > 1) {
|
||||
if ((int) $start->diffInMonths($end, true) > 1) {
|
||||
$format = 'endOfMonth';
|
||||
}
|
||||
|
||||
if ((int)$start->diffInMonths($end, true) > 12) {
|
||||
if ((int) $start->diffInMonths($end, true) > 12) {
|
||||
$format = 'endOfYear';
|
||||
}
|
||||
|
||||
@@ -604,11 +612,11 @@ class Navigation
|
||||
public function preferredRangeFormat(Carbon $start, Carbon $end): string
|
||||
{
|
||||
$format = '1D';
|
||||
if ((int)$start->diffInMonths($end, true) > 1) {
|
||||
if ((int) $start->diffInMonths($end, true) > 1) {
|
||||
$format = '1M';
|
||||
}
|
||||
|
||||
if ((int)$start->diffInMonths($end, true) > 12) {
|
||||
if ((int) $start->diffInMonths($end, true) > 12) {
|
||||
$format = '1Y';
|
||||
}
|
||||
|
||||
@@ -622,11 +630,11 @@ class Navigation
|
||||
public function preferredSqlFormat(Carbon $start, Carbon $end): string
|
||||
{
|
||||
$format = '%Y-%m-%d';
|
||||
if ((int)$start->diffInMonths($end, true) > 1) {
|
||||
if ((int) $start->diffInMonths($end, true) > 1) {
|
||||
$format = '%Y-%m';
|
||||
}
|
||||
|
||||
if ((int)$start->diffInMonths($end, true) > 12) {
|
||||
if ((int) $start->diffInMonths($end, true) > 12) {
|
||||
$format = '%Y';
|
||||
}
|
||||
|
||||
@@ -682,7 +690,7 @@ class Navigation
|
||||
|
||||
/** @var Carbon $tEnd */
|
||||
$tEnd = session('end', today(config('app.timezone'))->endOfMonth());
|
||||
$diffInDays = (int)$tStart->diffInDays($tEnd, true);
|
||||
$diffInDays = (int) $tStart->diffInDays($tEnd, true);
|
||||
$date->subDays($diffInDays * $subtract);
|
||||
|
||||
return $date;
|
||||
|
||||
Reference in New Issue
Block a user