diff --git a/app/Api/V1/Requests/Models/Account/ShowRequest.php b/app/Api/V1/Requests/Models/Account/ShowRequest.php index b9fa82c179..155193953e 100644 --- a/app/Api/V1/Requests/Models/Account/ShowRequest.php +++ b/app/Api/V1/Requests/Models/Account/ShowRequest.php @@ -43,14 +43,14 @@ class ShowRequest extends FormRequest if (0 === $limit) { // get default for user: /** @var User $user */ - $user = auth()->user(); + $user = auth()->user(); /** @var Preference $pageSize */ $limit = (int)Preferences::getForUser($user, 'listPageSize', 50)->data; } - $page = $this->convertInteger('page'); - $page = min(max(1, $page), 2 ** 16); + $page = $this->convertInteger('page'); + $page = min(max(1, $page), 2 ** 16); return [ 'type' => $this->convertString('type', 'all'), @@ -63,6 +63,7 @@ class ShowRequest extends FormRequest public function rules(): array { $keys = implode(',', array_keys($this->types)); + return [ 'date' => 'date', 'start' => 'date|present_with:end|before_or_equal:end|before:2038-01-17|after:1970-01-02', diff --git a/app/Support/JsonApi/Enrichments/AccountEnrichment.php b/app/Support/JsonApi/Enrichments/AccountEnrichment.php index a089727786..5f188b8002 100644 --- a/app/Support/JsonApi/Enrichments/AccountEnrichment.php +++ b/app/Support/JsonApi/Enrichments/AccountEnrichment.php @@ -142,9 +142,10 @@ class AccountEnrichment implements EnrichmentInterface private function collectMetaData(): void { - $set = AccountMeta::whereIn('name', ['is_multi_currency', 'include_net_worth', 'currency_id', 'account_role', 'account_number', 'BIC', 'liability_direction', 'interest', 'interest_period', 'current_debt']) - ->whereIn('account_id', $this->ids) - ->get(['account_meta.id', 'account_meta.account_id', 'account_meta.name', 'account_meta.data'])->toArray(); + $set = AccountMeta::whereIn('name', ['is_multi_currency', 'include_net_worth', 'currency_id', 'account_role', 'account_number', 'BIC', 'liability_direction', 'interest', 'interest_period', 'current_debt']) + ->whereIn('account_id', $this->ids) + ->get(['account_meta.id', 'account_meta.account_id', 'account_meta.name', 'account_meta.data'])->toArray() + ; /** @var array $entry */ foreach ($set as $entry) { @@ -170,9 +171,10 @@ class AccountEnrichment implements EnrichmentInterface private function collectNotes(): void { $notes = Note::query()->whereIn('noteable_id', $this->ids) - ->whereNotNull('notes.text') - ->where('notes.text', '!=', '') - ->where('noteable_type', Account::class)->get(['notes.noteable_id', 'notes.text'])->toArray(); + ->whereNotNull('notes.text') + ->where('notes.text', '!=', '') + ->where('noteable_type', Account::class)->get(['notes.noteable_id', 'notes.text'])->toArray() + ; foreach ($notes as $note) { $this->notes[(int)$note['noteable_id']] = (string)$note['text']; } @@ -182,14 +184,15 @@ class AccountEnrichment implements EnrichmentInterface private function collectLocations(): void { $locations = Location::query()->whereIn('locatable_id', $this->ids) - ->where('locatable_type', Account::class)->get(['locations.locatable_id', 'locations.latitude', 'locations.longitude', 'locations.zoom_level'])->toArray(); + ->where('locatable_type', Account::class)->get(['locations.locatable_id', 'locations.latitude', 'locations.longitude', 'locations.zoom_level'])->toArray() + ; foreach ($locations as $location) { $this->locations[(int)$location['locatable_id']] = [ - 'latitude' => (float)$location['latitude'], - 'longitude' => (float)$location['longitude'], - 'zoom_level' => (int)$location['zoom_level'], - ]; + 'latitude' => (float)$location['latitude'], + 'longitude' => (float)$location['longitude'], + 'zoom_level' => (int)$location['zoom_level'], + ]; } Log::debug(sprintf('Enrich with %d locations(s)', count($this->locations))); } @@ -204,19 +207,20 @@ class AccountEnrichment implements EnrichmentInterface ->setUserGroup($this->userGroup) ->setAccounts($this->collection) ->withAccountInformation() - ->setTypes([TransactionTypeEnum::OPENING_BALANCE->value]); - $journals = $collector->getExtractedJournals(); + ->setTypes([TransactionTypeEnum::OPENING_BALANCE->value]) + ; + $journals = $collector->getExtractedJournals(); foreach ($journals as $journal) { $this->openingBalances[(int)$journal['source_account_id']] = [ - 'amount' => Steam::negative($journal['amount']), - 'date' => $journal['date'], - ]; + 'amount' => Steam::negative($journal['amount']), + 'date' => $journal['date'], + ]; $this->openingBalances[(int)$journal['destination_account_id']] = [ - 'amount' => Steam::positive($journal['amount']), - 'date' => $journal['date'], - ]; + 'amount' => Steam::positive($journal['amount']), + 'date' => $journal['date'], + ]; } } @@ -234,9 +238,9 @@ class AccountEnrichment implements EnrichmentInterface private function appendCollectedData(): void { $this->collection = $this->collection->map(function (Account $item) { - $id = (int)$item->id; - $item->full_account_type = $this->accountTypes[(int)$item->account_type_id] ?? null; - $meta = [ + $id = (int)$item->id; + $item->full_account_type = $this->accountTypes[(int)$item->account_type_id] ?? null; + $meta = [ 'currency' => null, 'location' => [ 'latitude' => null, @@ -283,30 +287,30 @@ class AccountEnrichment implements EnrichmentInterface // add balances // get currencies: - $currency = $this->primaryCurrency; // assume primary currency + $currency = $this->primaryCurrency; // assume primary currency if (null !== $meta['currency']) { $currency = $meta['currency']; } // get the current balance: - $date = $this->getDate(); + $date = $this->getDate(); // $finalBalance = Steam::finalAccountBalance($item, $date, $this->primaryCurrency, $this->convertToPrimary); - $finalBalance = $this->balances[$id]; - $balanceDifference = $this->getBalanceDifference($id, $currency); + $finalBalance = $this->balances[$id]; + $balanceDifference = $this->getBalanceDifference($id, $currency); Log::debug(sprintf('Call finalAccountBalance(%s) with date/time "%s"', var_export($this->convertToPrimary, true), $date->toIso8601String()), $finalBalance); // collect current balances: - $currentBalance = Steam::bcround($finalBalance[$currency->code] ?? '0', $currency->decimal_places); - $openingBalance = Steam::bcround($meta['opening_balance_amount'] ?? '0', $currency->decimal_places); - $virtualBalance = Steam::bcround($account->virtual_balance ?? '0', $currency->decimal_places); - $debtAmount = $meta['current_debt'] ?? null; + $currentBalance = Steam::bcround($finalBalance[$currency->code] ?? '0', $currency->decimal_places); + $openingBalance = Steam::bcround($meta['opening_balance_amount'] ?? '0', $currency->decimal_places); + $virtualBalance = Steam::bcround($account->virtual_balance ?? '0', $currency->decimal_places); + $debtAmount = $meta['current_debt'] ?? null; // set some pc_ default values to NULL: - $pcCurrentBalance = null; - $pcOpeningBalance = null; - $pcVirtualBalance = null; - $pcDebtAmount = null; - $pcBalanceDifference = null; + $pcCurrentBalance = null; + $pcOpeningBalance = null; + $pcVirtualBalance = null; + $pcDebtAmount = null; + $pcBalanceDifference = null; // convert to primary currency if needed: if ($this->convertToPrimary && $currency->id !== $this->primaryCurrency->id) { @@ -333,19 +337,19 @@ class AccountEnrichment implements EnrichmentInterface } $meta['current_balance_date'] = $this->getDate(); $meta['balances'] = [ - 'current_balance' => $currentBalance, - 'pc_current_balance' => $pcCurrentBalance, - 'opening_balance' => $openingBalance, - 'pc_opening_balance' => $pcOpeningBalance, - 'virtual_balance' => $virtualBalance, - 'pc_virtual_balance' => $pcVirtualBalance, - 'debt_amount' => $debtAmount, - 'pc_debt_amount' => $pcDebtAmount, - 'balance_difference' => $balanceDifference, + 'current_balance' => $currentBalance, + 'pc_current_balance' => $pcCurrentBalance, + 'opening_balance' => $openingBalance, + 'pc_opening_balance' => $pcOpeningBalance, + 'virtual_balance' => $virtualBalance, + 'pc_virtual_balance' => $pcVirtualBalance, + 'debt_amount' => $debtAmount, + 'pc_debt_amount' => $pcDebtAmount, + 'balance_difference' => $balanceDifference, 'pc_balance_difference' => $pcBalanceDifference, ]; // end add balances - $item->meta = $meta; + $item->meta = $meta; return $item; }); @@ -367,12 +371,13 @@ class AccountEnrichment implements EnrichmentInterface private function collectObjectGroups(): void { - $set = DB::table('object_groupables') - ->whereIn('object_groupable_id', $this->ids) - ->where('object_groupable_type', Account::class) - ->get(['object_groupable_id', 'object_group_id']); + $set = DB::table('object_groupables') + ->whereIn('object_groupable_id', $this->ids) + ->where('object_groupable_type', Account::class) + ->get(['object_groupable_id', 'object_group_id']) + ; - $ids = array_unique($set->pluck('object_group_id')->toArray()); + $ids = array_unique($set->pluck('object_group_id')->toArray()); foreach ($set as $entry) { $this->mappedObjects[(int)$entry->object_groupable_id] = (int)$entry->object_group_id; @@ -421,14 +426,12 @@ class AccountEnrichment implements EnrichmentInterface } $startBalance = $this->startBalances[$id] ?? []; $endBalance = $this->endBalances[$id] ?? []; - if (count($startBalance) === 0 || count($endBalance) === 0) { + if (0 === count($startBalance) || 0 === count($endBalance)) { return null; } - $start = $startBalance[$currency->code] ?? '0'; - $end = $endBalance[$currency->code] ?? '0'; + $start = $startBalance[$currency->code] ?? '0'; + $end = $endBalance[$currency->code] ?? '0'; return bcsub($end, $start); } - - } diff --git a/app/Transformers/AccountTransformer.php b/app/Transformers/AccountTransformer.php index 2c05c23324..2bd930f6e0 100644 --- a/app/Transformers/AccountTransformer.php +++ b/app/Transformers/AccountTransformer.php @@ -66,20 +66,20 @@ class AccountTransformer extends AbstractTransformer } // get account type: - $accountType = (string)config(sprintf('firefly.shortNamesByFullName.%s', $account->full_account_type)); - $liabilityType = (string)config(sprintf('firefly.shortLiabilityNameByFullName.%s', $account->full_account_type)); - $liabilityType = '' === $liabilityType ? null : strtolower($liabilityType); - $liabilityDirection = $account->meta['liability_direction'] ?? null; - $accountRole = $this->getAccountRole($account, $accountType); - $hasCurrencySettings = null !== $account->meta['currency']; - $includeNetWorth = 1 === (int)($account->meta['include_net_worth'] ?? 0); - $longitude = $account->meta['location']['longitude'] ?? null; - $latitude = $account->meta['location']['latitude'] ?? null; - $zoomLevel = $account->meta['location']['zoom_level'] ?? null; - $order = $account->order; + $accountType = (string)config(sprintf('firefly.shortNamesByFullName.%s', $account->full_account_type)); + $liabilityType = (string)config(sprintf('firefly.shortLiabilityNameByFullName.%s', $account->full_account_type)); + $liabilityType = '' === $liabilityType ? null : strtolower($liabilityType); + $liabilityDirection = $account->meta['liability_direction'] ?? null; + $accountRole = $this->getAccountRole($account, $accountType); + $hasCurrencySettings = null !== $account->meta['currency']; + $includeNetWorth = 1 === (int)($account->meta['include_net_worth'] ?? 0); + $longitude = $account->meta['location']['longitude'] ?? null; + $latitude = $account->meta['location']['latitude'] ?? null; + $zoomLevel = $account->meta['location']['zoom_level'] ?? null; + $order = $account->order; // get primary currency as fallback: - $currency = $this->primary; // assume primary currency + $currency = $this->primary; // assume primary currency if ($hasCurrencySettings) { $currency = $account->meta['currency']; } @@ -91,32 +91,32 @@ class AccountTransformer extends AbstractTransformer // get some listed information from the account meta-data: [$creditCardType, $monthlyPaymentDate] = $this->getCCInfo($account, $accountRole, $accountType); - $openingBalanceDate = $this->getOpeningBalance($account, $accountType); - [$interest, $interestPeriod] = $this->getInterest($account, $accountType); + $openingBalanceDate = $this->getOpeningBalance($account, $accountType); + [$interest, $interestPeriod] = $this->getInterest($account, $accountType); return [ - 'id' => (string)$account->id, - 'created_at' => $account->created_at->toAtomString(), - 'updated_at' => $account->updated_at->toAtomString(), - 'active' => $account->active, - 'order' => $order, - 'name' => $account->name, - 'type' => strtolower($accountType), - 'account_role' => $accountRole, + 'id' => (string)$account->id, + 'created_at' => $account->created_at->toAtomString(), + 'updated_at' => $account->updated_at->toAtomString(), + 'active' => $account->active, + 'order' => $order, + 'name' => $account->name, + 'type' => strtolower($accountType), + 'account_role' => $accountRole, - 'object_group_id' => $account->meta['object_group_id'], - 'object_group_order' => $account->meta['object_group_order'], - 'object_group_title' => $account->meta['object_group_title'], + 'object_group_id' => $account->meta['object_group_id'], + 'object_group_order' => $account->meta['object_group_order'], + 'object_group_title' => $account->meta['object_group_title'], // currency information, structured for 6.3.0. - 'object_has_currency_setting' => $hasCurrencySettings, + 'object_has_currency_setting' => $hasCurrencySettings, // currency is object specific or primary, already determined above. - 'currency_id' => (string)$currency['id'], - 'currency_name' => $currency['name'], - 'currency_code' => $currency['code'], - 'currency_symbol' => $currency['symbol'], - 'currency_decimal_places' => $currency['decimal_places'], + 'currency_id' => (string)$currency['id'], + 'currency_name' => $currency['name'], + 'currency_code' => $currency['code'], + 'currency_symbol' => $currency['symbol'], + 'currency_decimal_places' => $currency['decimal_places'], 'primary_currency_id' => (string)$this->primary->id, 'primary_currency_name' => $this->primary->name, @@ -128,36 +128,36 @@ class AccountTransformer extends AbstractTransformer 'current_balance' => $account->meta['balances']['current_balance'], 'pc_current_balance' => $account->meta['balances']['pc_current_balance'], - 'opening_balance' => $account->meta['balances']['opening_balance'], - 'pc_opening_balance' => $account->meta['balances']['pc_opening_balance'], + 'opening_balance' => $account->meta['balances']['opening_balance'], + 'pc_opening_balance' => $account->meta['balances']['pc_opening_balance'], - 'virtual_balance' => $account->meta['balances']['virtual_balance'], - 'pc_virtual_balance' => $account->meta['balances']['pc_virtual_balance'], + 'virtual_balance' => $account->meta['balances']['virtual_balance'], + 'pc_virtual_balance' => $account->meta['balances']['pc_virtual_balance'], - 'debt_amount' => $account->meta['balances']['debt_amount'], - 'pc_debt_amount' => $account->meta['balances']['pc_debt_amount'], + 'debt_amount' => $account->meta['balances']['debt_amount'], + 'pc_debt_amount' => $account->meta['balances']['pc_debt_amount'], - 'balance_difference' => $account->meta['balances']['balance_difference'], - 'pc_balance_difference' => $account->meta['balances']['pc_balance_difference'], + 'balance_difference' => $account->meta['balances']['balance_difference'], + 'pc_balance_difference' => $account->meta['balances']['pc_balance_difference'], - 'current_balance_date' => $account->meta['current_balance_date']->toAtomString(), - 'notes' => $account->meta['notes'] ?? null, - 'monthly_payment_date' => $monthlyPaymentDate, - 'credit_card_type' => $creditCardType, - 'account_number' => $account->meta['account_number'], - 'iban' => '' === $account->iban ? null : $account->iban, - 'bic' => $account->meta['BIC'] ?? null, - 'opening_balance_date' => $openingBalanceDate, - 'liability_type' => $liabilityType, - 'liability_direction' => $liabilityDirection, - 'interest' => $interest, - 'interest_period' => $interestPeriod, - 'include_net_worth' => $includeNetWorth, - 'longitude' => $longitude, - 'latitude' => $latitude, - 'zoom_level' => $zoomLevel, - 'last_activity' => $account->meta['last_activity']?->toAtomString(), - 'links' => [ + 'current_balance_date' => $account->meta['current_balance_date']->toAtomString(), + 'notes' => $account->meta['notes'] ?? null, + 'monthly_payment_date' => $monthlyPaymentDate, + 'credit_card_type' => $creditCardType, + 'account_number' => $account->meta['account_number'], + 'iban' => '' === $account->iban ? null : $account->iban, + 'bic' => $account->meta['BIC'] ?? null, + 'opening_balance_date' => $openingBalanceDate, + 'liability_type' => $liabilityType, + 'liability_direction' => $liabilityDirection, + 'interest' => $interest, + 'interest_period' => $interestPeriod, + 'include_net_worth' => $includeNetWorth, + 'longitude' => $longitude, + 'latitude' => $latitude, + 'zoom_level' => $zoomLevel, + 'last_activity' => $account->meta['last_activity']?->toAtomString(), + 'links' => [ [ 'rel' => 'self', 'uri' => sprintf('/accounts/%d', $account->id), @@ -199,7 +199,7 @@ class AccountTransformer extends AbstractTransformer if (null !== $monthlyPaymentDate) { // try classic date: if (10 === strlen($monthlyPaymentDate)) { - $object = Carbon::createFromFormat('!Y-m-d', $monthlyPaymentDate, config('app.timezone')); + $object = Carbon::createFromFormat('!Y-m-d', $monthlyPaymentDate, config('app.timezone')); if (!$object instanceof Carbon) { $object = today(config('app.timezone')); } @@ -220,7 +220,7 @@ class AccountTransformer extends AbstractTransformer $openingBalanceDate = $account->meta['opening_balance_date'] ?? null; } if (null !== $openingBalanceDate) { - $object = Carbon::createFromFormat('Y-m-d H:i:s', $openingBalanceDate, config('app.timezone')); + $object = Carbon::createFromFormat('Y-m-d H:i:s', $openingBalanceDate, config('app.timezone')); if (!$object instanceof Carbon) { $object = today(config('app.timezone')); } diff --git a/config/firefly.php b/config/firefly.php index fa4f84c25e..e9ef7b4cc9 100644 --- a/config/firefly.php +++ b/config/firefly.php @@ -79,7 +79,7 @@ return [ // see cer.php for exchange rates feature flag. ], 'version' => 'develop/2025-09-01', - 'build_time' => 1756729173, + 'build_time' => 1756752129, 'api_version' => '2.1.0', // field is no longer used. 'db_version' => 26,