Skip to content

Commit

Permalink
Merge branch 'release/0.9.11'
Browse files Browse the repository at this point in the history
  • Loading branch information
JC5 committed Jul 16, 2022
2 parents 44c012d + 1329070 commit ef7cf80
Show file tree
Hide file tree
Showing 18 changed files with 1,505 additions and 1,511 deletions.
4 changes: 3 additions & 1 deletion app/Exceptions/AgreementExpiredException.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?php
declare(strict_types=1);

/*
* AgreementExpiredException.php
* Copyright (c) 2022 [email protected]
Expand All @@ -21,6 +21,8 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/

declare(strict_types=1);

namespace App\Exceptions;

use Exception;
Expand Down
6 changes: 6 additions & 0 deletions app/Services/CSV/Conversion/Routine/ColumnValueConverter.php
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,12 @@ private function processValueArray(array $line): array
app('log')->debug(sprintf('Column #%d with role "%s" (in field "%s") must NOT be appended to the previous value.', $columnIndex + 1, $role, $transactionField));
$transaction['transactions'][0][$transactionField] = $parsedValue;
}
// if this is an account field, AND the column is mapped, store the original value just in case.
$saveRoles = ['account-name', 'opposing-name', 'account-iban', 'opposing-iban', 'account-number', 'opposing-number'];
if (0 !== $value->getMappedValue() && in_array($value->getOriginalRole(), $saveRoles, true)) {
app('log')->debug(sprintf('The original value ("%s") in column "%s" (originally stored in "%s") was saved just in case.', $value->getValue(), $value->getRole(), $value->getOriginalRole()));
$transaction['transactions'][0][sprintf('original-%s', $value->getOriginalRole())] = $value->getValue();
}
}
app('log')->debug('Almost final transaction', $transaction);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,13 +64,20 @@ protected function determineType(?string $sourceType, ?string $destinationType):
}


// if destination is asset and source is NULL, its a deposit
// if destination is asset and source is NULL, it's a deposit
if (null === $sourceType && 'asset' === $destinationType) {
app('log')->debug('Return deposit, destination is asset');

return 'deposit';
}

// if the source is an expense account and the destination is an asset
// it could be a bad mapping. We return "deposit"
if('expense' === $sourceType && 'asset' === $destinationType) {
app('log')->warning('Return "deposit" but the source type is not correct.');
return 'deposit';
}

// if destination is liabilities and source is NULL, it's a deposit
if (null === $sourceType && 'liabilities' === $destinationType) {
app('log')->debug('Return liabilities, destination is asset');
Expand Down
18 changes: 17 additions & 1 deletion app/Services/CSV/Conversion/Task/Accounts.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ private function processTransaction(array $transaction): array
* Try to find the source and destination accounts in the transaction.
*
* The source account will default back to the user's submitted default account.
* So when everything fails, the transaction will be a deposit for amount X.
* So when everything fails, the transaction will be a expense for amount X.
*/
$sourceArray = $this->getSourceArray($transaction);
$destArray = $this->getDestinationArray($transaction);
Expand Down Expand Up @@ -132,6 +132,22 @@ private function processTransaction(array $transaction): array
app('log')->debug('Transaction is a deposit, and amount is positive. Will not change account types.');
}

/*
* If deposit and amount is positive, but the source is not a revenue, fall back to
* some "original-field-name" values (if they exist) and hope for the best.
*/
if ('deposit' === $transaction['type'] && 1 === bccomp($amount, '0') && 'revenue' !== $source['type']) {
app('log')->warning('Transaction is a deposit, and amount is positive, but source is not a revenue. Will fall back to original field names.');
$newSource = [
'id' => null,
'name' => $transaction['original-opposing-name'] ?? '(no name)',
'iban' => $transaction['original-opposing-iban'] ?? null,
'number' => $transaction['original-opposing-number'] ?? null,
'bic' => null,
];
$transaction = $this->setSource($transaction, $newSource);
}

/*
* If amount is negative and type is transfer, make sure accounts are "original".
*/
Expand Down
1 change: 1 addition & 0 deletions app/Services/Nordigen/Model/Transaction.php
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,7 @@ public function getDescription(): string
app('log')->debug('Description is now remittanceInformationStructured');
$description = $this->remittanceInformationStructured;
}
$description = trim($description);

if ('' === $description) {
app('log')->warning(sprintf('Transaction "%s" has no description.', $this->transactionId));
Expand Down
15 changes: 8 additions & 7 deletions app/Services/Nordigen/Services/AccountInformationCollector.php
Original file line number Diff line number Diff line change
Expand Up @@ -98,13 +98,13 @@ protected static function getAccountDetails(Account $account): Account
$request = new GetAccountInformationRequest($url, $accessToken, $account->getIdentifier());
/** @var ArrayResponse $response */

$response = $request->get();
$response = $request->get();

if(!array_key_exists('account', $response->data)) {
if (!array_key_exists('account', $response->data)) {
app('log')->error('Missing account array', $response->data);
throw new ImporterHttpException('No account array, exit.');
}

$information = $response->data['account'];

app('log')->debug('getAccountDetails: Collected information for account', $information);
Expand Down Expand Up @@ -157,10 +157,11 @@ private static function getBalanceDetails(Account $account): Account
$request->setTimeOut(config('importer.connection.timeout'));
/** @var ArrayResponse $response */
$response = $request->get();

foreach ($response->data['balances'] as $array) {
app('log')->debug(sprintf('Added "%s" balance "%s"', $array['balanceType'], $array['balanceAmount']['amount']));
$account->addBalance(Balance::createFromArray($array));
if (array_key_exists('balances', $response->data)) {
foreach ($response->data['balances'] as $array) {
app('log')->debug(sprintf('Added "%s" balance "%s"', $array['balanceType'], $array['balanceAmount']['amount']));
$account->addBalance(Balance::createFromArray($array));
}
}
return $account;
}
Expand Down
6 changes: 3 additions & 3 deletions app/Services/Shared/Configuration/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -952,14 +952,14 @@ public function updateDateRange(): void
app('log')->debug('Range is "range", both will be created from a string.');
$before = $this->dateNotBefore; // string
$after = $this->dateNotAfter; // string
if (null !== $before) {
if ('' !== $before) {
$before = Carbon::createFromFormat('Y-m-d', $before);
}
if (null !== $after) {
if ('' !== $after) {
$after = Carbon::createFromFormat('Y-m-d', $after);
}

if (null !== $before && null !== $after && $before > $after) {
if ('' !== $before && '' !== $after && $before > $after) {
[$before, $after] = [$after, $before];
}

Expand Down
7 changes: 5 additions & 2 deletions app/Services/Shared/Import/Routine/ApiSubmitter.php
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ private function searchField(string $field, string $value): int
*/
private function processTransaction(int $index, array $line): array
{
$line = $this->replaceMappings($line);
$line = $this->cleanupLine($line);
$return = [];
$url = SecretManager::getBaseUrl();
$token = SecretManager::getAccessToken();
Expand Down Expand Up @@ -329,7 +329,7 @@ private function processTransaction(int $index, array $line): array
* @param array $line
* @return array
*/
private function replaceMappings(array $line): array
private function cleanupLine(array $line): array
{
app('log')->debug('Going to map data for this line.');
if (array_key_exists(0, $this->mapping)) {
Expand Down Expand Up @@ -359,6 +359,9 @@ private function replaceMappings(array $line): array
app('log')->debug(sprintf('Replaced source name "%s" with a reference to account id #%d', $source, $this->mapping[0][$source]));
}
}
if ('' === trim((string) $transaction['description'] ?? '')) {
$transaction['description'] = '(no description)';
}
$line['transactions'][$index] = $this->updateTransactionType($transaction);
}
}
Expand Down
3 changes: 1 addition & 2 deletions app/Services/Spectre/Model/Transaction.php
Original file line number Diff line number Diff line change
Expand Up @@ -114,8 +114,7 @@ public function getDescription(): string
if (null !== $additional) {
$description = trim(sprintf('%s %s', $description, app('steam')->cleanString($additional)));
}

return $description;
return trim($description);
}

/**
Expand Down
13 changes: 11 additions & 2 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,20 @@
All notable changes to this project will be documented in this file.
This project adheres to [Semantic Versioning](http://semver.org/).

## 0.9.10 - 2021-05-03
## 0.9.11 - 2022-07-16

### Fixed
- Issue where config files with empty strings would break the date selection.
- [Issue 6146](https://github.com/firefly-iii/firefly-iii/issues/6146) Fix issue where missing Nordigen data would break the import.
- [Issue 6233](https://github.com/firefly-iii/firefly-iii/issues/6233) Fix issue where mapping an expense account to a revenue spot would break the import.
- Fix issue where the importer would not detect empty descriptions. Thanks @BerghsJelmer

## 0.9.10 - 2022-05-03

### Changed
- Require the most recent version of Firefly III

## 0.9.9 - 2021-05-03
## 0.9.9 - 2022-05-03

### Changed
- Made the texts more generic to accommodate future changes
Expand Down
Loading

0 comments on commit ef7cf80

Please sign in to comment.