Fix available budgets.

This commit is contained in:
James Cole
2024-12-30 12:22:39 +01:00
parent 62f4da6063
commit d37304fa68
5 changed files with 30 additions and 14 deletions

View File

@@ -46,7 +46,7 @@ class AvailableBudgetObserver
private function updateNativeAmount(AvailableBudget $availableBudget): void private function updateNativeAmount(AvailableBudget $availableBudget): void
{ {
if (!Amount::convertToNative($availableBudget->user)) { if (!Amount::convertToNative($availableBudget->user)) {
Log::debug('Do not update native available amount of the available budget.'); //Log::debug('Do not update native available amount of the available budget.');
return; return;
} }

View File

@@ -46,7 +46,7 @@ class BudgetLimitObserver
private function updateNativeAmount(BudgetLimit $budgetLimit): void private function updateNativeAmount(BudgetLimit $budgetLimit): void
{ {
if (!Amount::convertToNative($budgetLimit->budget->user)) { if (!Amount::convertToNative($budgetLimit->budget->user)) {
Log::debug('Do not update native amount of the budget limit.'); //Log::debug('Do not update native amount of the budget limit.');
return; return;
} }

View File

@@ -23,6 +23,7 @@ declare(strict_types=1);
namespace FireflyIII\Models; namespace FireflyIII\Models;
use Carbon\Carbon;
use FireflyIII\Support\Models\ReturnsIntegerIdTrait; use FireflyIII\Support\Models\ReturnsIntegerIdTrait;
use FireflyIII\Support\Models\ReturnsIntegerUserIdTrait; use FireflyIII\Support\Models\ReturnsIntegerUserIdTrait;
use FireflyIII\User; use FireflyIII\User;
@@ -91,14 +92,29 @@ class AvailableBudget extends Model
protected function amount(): Attribute protected function amount(): Attribute
{ {
return Attribute::make( return Attribute::make(
get: static fn ($value) => (string) $value, get: static fn($value) => (string) $value,
); );
} }
protected function transactionCurrencyId(): Attribute protected function transactionCurrencyId(): Attribute
{ {
return Attribute::make( return Attribute::make(
get: static fn ($value) => (int) $value, get: static fn($value) => (int) $value,
);
}
protected function startDate(): Attribute
{
return Attribute::make(
get: fn (string $value) => Carbon::parse($value),
set: fn (Carbon $value) => $value->format('Y-m-d'),
);
}
protected function endDate(): Attribute
{
return Attribute::make(
get: fn (string $value) => Carbon::parse($value),
set: fn (Carbon $value) => $value->format('Y-m-d'),
); );
} }
} }

View File

@@ -74,7 +74,7 @@ class AvailableBudgetRepository implements AvailableBudgetRepositoryInterface
); );
} }
$result = $query->get(['available_budgets.*']); $result = $query->get(['available_budgets.*']);
Log::debug(sprintf('Found %d available budgets between %s and %s', $result->count(), $start->format('Y-m-d'), $end->format('Y-m-d'))); Log::debug(sprintf('Found %d available budgets between %s and %s', $result->count(), $start->format('Y-m-d H:i:s'), $end->format('Y-m-d H:i:s')));
return $result; return $result;
} }
@@ -215,9 +215,9 @@ class AvailableBudgetRepository implements AvailableBudgetRepositoryInterface
$availableBudget = new AvailableBudget(); $availableBudget = new AvailableBudget();
$availableBudget->user()->associate($this->user); $availableBudget->user()->associate($this->user);
$availableBudget->transactionCurrency()->associate($currency); $availableBudget->transactionCurrency()->associate($currency);
$availableBudget->start_date = $start->startOfDay()->format('Y-m-d'); // @phpstan-ignore-line $availableBudget->start_date = $start->startOfDay();
$availableBudget->start_date_tz = $start->format('e'); $availableBudget->start_date_tz = $start->format('e');
$availableBudget->end_date = $end->endOfDay()->format('Y-m-d'); // @phpstan-ignore-line $availableBudget->end_date = $end->endOfDay();
$availableBudget->end_date_tz = $end->format('e'); $availableBudget->end_date_tz = $end->format('e');
} }
$availableBudget->amount = $amount; $availableBudget->amount = $amount;
@@ -250,9 +250,9 @@ class AvailableBudgetRepository implements AvailableBudgetRepositoryInterface
'user_group_id' => $this->user->user_group_id, 'user_group_id' => $this->user->user_group_id,
'transaction_currency_id' => $data['currency_id'], 'transaction_currency_id' => $data['currency_id'],
'amount' => $data['amount'], 'amount' => $data['amount'],
'start_date' => $start->format('Y-m-d'), 'start_date' => $start,
'start_date_tz' => $start->format('e'), 'start_date_tz' => $start->format('e'),
'end_date' => $end->format('Y-m-d'), 'end_date' => $end,
'end_date_tz' => $end->format('e'), 'end_date_tz' => $end->format('e'),
] ]
); );
@@ -274,7 +274,7 @@ class AvailableBudgetRepository implements AvailableBudgetRepositoryInterface
$start = $data['start']; $start = $data['start'];
if ($start instanceof Carbon) { if ($start instanceof Carbon) {
$start = $data['start']->startOfDay(); $start = $data['start']->startOfDay();
$availableBudget->start_date = $start->format('Y-m-d'); $availableBudget->start_date = $start;
$availableBudget->start_date_tz = $start->format('e'); $availableBudget->start_date_tz = $start->format('e');
$availableBudget->save(); $availableBudget->save();
} }
@@ -284,7 +284,7 @@ class AvailableBudgetRepository implements AvailableBudgetRepositoryInterface
$end = $data['end']; $end = $data['end'];
if ($end instanceof Carbon) { if ($end instanceof Carbon) {
$end = $data['end']->endOfDay(); $end = $data['end']->endOfDay();
$availableBudget->end_date = $end->format('Y-m-d'); $availableBudget->end_date = $end;
$availableBudget->end_date_tz = $end->format('e'); $availableBudget->end_date_tz = $end->format('e');
$availableBudget->save(); $availableBudget->save();
} }

View File

@@ -25,7 +25,7 @@
"postcss": "^8.4.47", "postcss": "^8.4.47",
"uiv": "^1.4", "uiv": "^1.4",
"vue": "^2.7", "vue": "^2.7",
"vue-i18n": "^8", "vue-i18n": "^11",
"vue-loader": "^15", "vue-loader": "^15",
"vue-template-compiler": "^2.7" "vue-template-compiler": "^2.7"
} }