Firefly III: a personal finances manager
PHP accountingbudgetbudgetingbudgetscash-flowcashflowcredit-carddockerexpensesfinancefinancesfinanciallinuxmoneypaycheckpersonal-financephpphp7
Code clean up
James Cole04a8a0e6a139
diff --git a/app/Console/Commands/Import.php b/app/Console/Commands/Import.phpindex d88af868d9..b8cecf4202 100644--- a/app/Console/Commands/Import.php+++ b/app/Console/Commands/Import.php@@ -87,13 +87,8 @@ class Import extends Command$this->error(sprintf('Error importing line #%d: %s', $index, $error));}- // display result to user:- //$this->presentResults($result);$this->line(sprintf('The import has finished. %d transactions have been imported out of %d records.', $routine->journals->count(), $routine->lines));- // get any errors from the importer:- //$this->presentErrors($job);-return;}@@ -120,36 +115,4 @@ class Import extends Commandreturn true;}-- /**- * @param ImportJob $job- */- private function presentErrors(ImportJob $job)- {- $extendedStatus = $job->extended_status;- if (isset($extendedStatus['errors']) && count($extendedStatus['errors']) > 0) {- $this->line(sprintf('The following %d error(s) occured during the import:', count($extendedStatus['errors'])));- foreach ($extendedStatus['errors'] as $error) {- $this->error($error);- }- }- }-- /**- * @param Collection $result- */- private function presentResults(Collection $result)- {- /**- * @var int $index- * @var TransactionJournal $journal- */- foreach ($result as $index => $journal) {- if (!is_null($journal->id)) {- $this->line(sprintf('Line #%d has been imported as transaction #%d.', $index, $journal->id));- continue;- }- $this->error(sprintf('Could not store line #%d', $index));- }- }}diff --git a/app/Http/Controllers/ImportController.php b/app/Http/Controllers/ImportController.phpindex 5ac5b6944d..310b418789 100644--- a/app/Http/Controllers/ImportController.php+++ b/app/Http/Controllers/ImportController.php@@ -85,7 +85,7 @@ class ImportController extends Controller** @param ImportJob $job*- * @return string+ * @return LaravelResponse*/public function download(ImportJob $job){diff --git a/app/Http/Controllers/Transaction/ConvertController.php b/app/Http/Controllers/Transaction/ConvertController.phpindex 2b1e8bf061..b01335dce7 100644--- a/app/Http/Controllers/Transaction/ConvertController.php+++ b/app/Http/Controllers/Transaction/ConvertController.php@@ -229,8 +229,8 @@ class ConvertController extends Controllerswitch ($joined) {default:throw new FireflyException('Cannot handle ' . $joined); // @codeCoverageIgnore- case TransactionType::WITHDRAWAL . '-' . TransactionType::DEPOSIT: // one- case TransactionType::TRANSFER . '-' . TransactionType::DEPOSIT: // six+ case TransactionType::WITHDRAWAL . '-' . TransactionType::DEPOSIT:+ case TransactionType::TRANSFER . '-' . TransactionType::DEPOSIT:if ($data['source_account_revenue'] === '') {// destination is a cash account.@@ -248,14 +248,14 @@ class ConvertController extends Controller];$source = $accountRepository->store($data);break;- case TransactionType::WITHDRAWAL . '-' . TransactionType::TRANSFER: // two- case TransactionType::TRANSFER . '-' . TransactionType::WITHDRAWAL: // five+ case TransactionType::WITHDRAWAL . '-' . TransactionType::TRANSFER:+ case TransactionType::TRANSFER . '-' . TransactionType::WITHDRAWAL:$source = $sourceAccount;break;- case TransactionType::DEPOSIT . '-' . TransactionType::WITHDRAWAL: // three+ case TransactionType::DEPOSIT . '-' . TransactionType::WITHDRAWAL:$source = $destinationAccount;break;- case TransactionType::DEPOSIT . '-' . TransactionType::TRANSFER: // four+ case TransactionType::DEPOSIT . '-' . TransactionType::TRANSFER:$source = $accountRepository->find(intval($data['source_account_asset']));break;}diff --git a/app/Http/Controllers/Transaction/SplitController.php b/app/Http/Controllers/Transaction/SplitController.phpindex e6668bc43e..32f0807c3b 100644--- a/app/Http/Controllers/Transaction/SplitController.php+++ b/app/Http/Controllers/Transaction/SplitController.php@@ -218,7 +218,7 @@ class SplitController extends Controller'journal_destination_account_id' => $request->old('journal_destination_account_id', $destinationAccounts->first()->id),'destinationAccounts' => $destinationAccounts,'what' => strtolower($journal->transactionTypeStr()),- 'date' => $request->old('date', $journal->date),+ 'date' => $request->old('date', $journal->date->format('Y-m-d')),'tags' => join(',', $journal->tags->pluck('tag')->toArray()),// all custom fields:diff --git a/app/Import/Configurator/CsvConfigurator.php b/app/Import/Configurator/CsvConfigurator.phpindex ea92d0fcfa..a3c9750fee 100644--- a/app/Import/Configurator/CsvConfigurator.php+++ b/app/Import/Configurator/CsvConfigurator.php@@ -134,7 +134,7 @@ class CsvConfigurator implements ConfiguratorInterface{$class = false;switch (true) {- case(!$this->job->configuration['initial-config-complete']):+ case (!$this->job->configuration['initial-config-complete']):$class = Initial::class;break;case (!$this->job->configuration['column-roles-complete']):diff --git a/app/Import/FileProcessor/CsvProcessor.php b/app/Import/FileProcessor/CsvProcessor.phpindex d7a7469cda..5585cf4b04 100644--- a/app/Import/FileProcessor/CsvProcessor.php+++ b/app/Import/FileProcessor/CsvProcessor.php@@ -192,8 +192,7 @@ class CsvProcessor implements FileProcessorInterface$string = json_encode($array);$hash = hash('sha256', json_encode($string));$json = json_encode($hash);- $entry = TransactionJournalMeta::- leftJoin('transaction_journals', 'transaction_journals.id', '=', 'journal_meta.transaction_journal_id')+ $entry = TransactionJournalMeta::leftJoin('transaction_journals', 'transaction_journals.id', '=', 'journal_meta.transaction_journal_id')->where('data', $json)->where('name', 'importHash')->first();diff --git a/app/Import/Object/ImportAccount.php b/app/Import/Object/ImportAccount.phpindex 65d0460bab..19ff1c8f40 100644--- a/app/Import/Object/ImportAccount.php+++ b/app/Import/Object/ImportAccount.php@@ -140,7 +140,7 @@ class ImportAccount}/** @var Collection $accounts */$accounts = $this->repository->getAccountsByType([$accountType->type]);- // 2: find by IBAN (and type):+ // Two: find by IBAN (and type):if (count($this->accountIban) === 3) {$iban = $this->accountIban['value'];Log::debug(sprintf('Finding account of type %d and IBAN %s', $accountType->id, $iban));@@ -163,7 +163,7 @@ class ImportAccountLog::debug('Found nothing.');}- // 3: find by name (and type):+ // Three: find by name (and type):if (count($this->accountName) === 3) {$name = $this->accountName['value'];Log::debug(sprintf('Finding account of type %d and name %s', $accountType->id, $name));diff --git a/app/Import/Object/ImportCurrency.php b/app/Import/Object/ImportCurrency.phpindex b982e9c6b5..8427f3ce5f 100644--- a/app/Import/Object/ImportCurrency.php+++ b/app/Import/Object/ImportCurrency.php@@ -54,7 +54,6 @@ class ImportCurrencyLog::debug('In createCurrency()');// check if any of them is mapped:$mapped = $this->findMappedObject();- $searched = null;if (!is_null($mapped->id)) {diff --git a/app/Import/Object/ImportJournal.php b/app/Import/Object/ImportJournal.phpindex 60d9edb2f9..a86cdffe5d 100644--- a/app/Import/Object/ImportJournal.php+++ b/app/Import/Object/ImportJournal.php@@ -251,7 +251,6 @@ class ImportJournalcase 'tags-space':$this->tags[] = $array;break;- // 'interest_date', 'book_date', 'process_date', 'due_date', 'payment_date', 'invoice_date',case 'date-interest':$this->metaDates['interest_date'] = $array['value'];break;diff --git a/app/Import/Storage/ImportStorage.php b/app/Import/Storage/ImportStorage.phpindex 98c418553b..e2fc54235a 100644--- a/app/Import/Storage/ImportStorage.php+++ b/app/Import/Storage/ImportStorage.php@@ -155,7 +155,7 @@ class ImportStorage$transaction->amount = $amount;$transaction->save();if (is_null($transaction->id)) {- $errorText = join(', ', $one->getErrors()->all());+ $errorText = join(', ', $transaction->getErrors()->all());throw new FireflyException($errorText);}Log::debug(sprintf('Created transaction with ID #%d and account #%d', $transaction->id, $accountId));diff --git a/app/Repositories/Account/FindAccountsTrait.php b/app/Repositories/Account/FindAccountsTrait.phpindex c5186187cc..a3a4248ab2 100644--- a/app/Repositories/Account/FindAccountsTrait.php+++ b/app/Repositories/Account/FindAccountsTrait.php@@ -13,11 +13,14 @@ namespace FireflyIII\Repositories\Account;use FireflyIII\Models\Account;use FireflyIII\Models\AccountType;+use FireflyIII\User;use Illuminate\Database\Eloquent\Relations\HasMany;use Illuminate\Support\Collection;use Log;/**+ * @property User $user+ ** Trait FindAccountsTrait** @package FireflyIII\Repositories\Accountdiff --git a/app/Repositories/Journal/CreateJournalsTrait.php b/app/Repositories/Journal/CreateJournalsTrait.phpindex dbfa818e84..6bf4fb6d2f 100644--- a/app/Repositories/Journal/CreateJournalsTrait.php+++ b/app/Repositories/Journal/CreateJournalsTrait.php@@ -19,10 +19,13 @@ use FireflyIII\Models\Transaction;use FireflyIII\Models\TransactionJournal;use FireflyIII\Models\TransactionType;use FireflyIII\Repositories\Tag\TagRepositoryInterface;+use FireflyIII\User;use Illuminate\Support\Collection;use Log;/**+ * @property User $user+ ** Trait CreateJournalsTrait** @package FireflyIII\Repositories\Journaldiff --git a/app/Support/Import/Configuration/Csv/Map.php b/app/Support/Import/Configuration/Csv/Map.phpindex 1f8df8449b..eb51c04e4d 100644--- a/app/Support/Import/Configuration/Csv/Map.php+++ b/app/Support/Import/Configuration/Csv/Map.php@@ -55,6 +55,7 @@ class Map implements ConfigurationInterface$results = $reader->setOffset($offset)->fetch();$this->validSpecifics = array_keys(config('csv.import_specifics'));$indexes = array_keys($this->data);+ $rowIndex = 0;foreach ($results as $rowIndex => $row) {$row = $this->runSpecifics($row);@@ -73,13 +74,13 @@ class Map implements ConfigurationInterface// which is exclusively to fix the tags:if (!is_null($this->data[$index]['preProcessMap']) && strlen($this->data[$index]['preProcessMap']) > 0) {/** @var PreProcessorInterface $preProcessor */- $preProcessor = app($this->data[$index]['preProcessMap']);- $result = $preProcessor->run($value);- $data[$index]['values'] = array_merge($this->data[$index]['values'], $result);+ $preProcessor = app($this->data[$index]['preProcessMap']);+ $result = $preProcessor->run($value);+ $this->data[$index]['values'] = array_merge($this->data[$index]['values'], $result);Log::debug($rowIndex . ':' . $index . 'Value before preprocessor', ['value' => $value]);Log::debug($rowIndex . ':' . $index . 'Value after preprocessor', ['value-new' => $result]);- Log::debug($rowIndex . ':' . $index . 'Value after joining', ['value-complete' => $data[$index]['values']]);+ Log::debug($rowIndex . ':' . $index . 'Value after joining', ['value-complete' => $this->data[$index]['values']]);continue;@@ -95,7 +96,7 @@ class Map implements ConfigurationInterface// save number of rows, thus number of steps, in job:$steps = $rowIndex * 5;$extended = $this->job->extended_status;- $extended['steps'] = $steps;+ $extended['steps'] = $steps;$this->job->extended_status = $extended;$this->job->save();diff --git a/app/Support/Import/CsvImportSupportTrait.php b/app/Support/Import/CsvImportSupportTrait.phpdeleted file mode 100644index dbf915f50f..0000000000--- a/app/Support/Import/CsvImportSupportTrait.php+++ /dev/null@@ -1,245 +0,0 @@-<?php-/**- * CsvImportSupportTrait.php- * Copyright (c) 2017 [email protected]- * This software may be modified and distributed under the terms of the Creative Commons Attribution-ShareAlike 4.0 International License.- *- * See the LICENSE file for details.- */--declare(strict_types=1);--namespace FireflyIII\Support\Import;---use FireflyIII\Exceptions\FireflyException;-use FireflyIII\Import\Mapper\MapperInterface;-use FireflyIII\Import\MapperPreProcess\PreProcessorInterface;-use FireflyIII\Import\Specifics\SpecificInterface;-use FireflyIII\Models\ImportJob;-use League\Csv\Reader;-use Log;--/**- * Trait CsvImportSupportTrait- *- * @property ImportJob $job- *- * @package FireflyIII\Support\Import- */-trait CsvImportSupportTrait-{- /**- * @return bool- */- protected function doColumnMapping(): bool- {- $mapArray = $this->job->configuration['column-do-mapping'] ?? [];- $doMap = false;- foreach ($mapArray as $value) {- if ($value === true) {- $doMap = true;- break;- }- }-- return $this->job->configuration['column-mapping-complete'] === false && $doMap;- }-- /**- * @return bool- */- protected function doColumnRoles(): bool- {- return $this->job->configuration['column-roles-complete'] === false;- }-- /**- * @return array- * @throws FireflyException- */- protected function getDataForColumnMapping(): array- {- $config = $this->job->configuration;- $data = [];- $indexes = [];-- foreach ($config['column-do-mapping'] as $index => $mustBeMapped) {- if ($mustBeMapped) {-- $column = $config['column-roles'][$index] ?? '_ignore';-- // is valid column?- $validColumns = array_keys(config('csv.import_roles'));- if (!in_array($column, $validColumns)) {- throw new FireflyException(sprintf('"%s" is not a valid column.', $column));- }-- $canBeMapped = config('csv.import_roles.' . $column . '.mappable');- $preProcessMap = config('csv.import_roles.' . $column . '.pre-process-map');- if ($canBeMapped) {- $mapperClass = config('csv.import_roles.' . $column . '.mapper');- $mapperName = sprintf('\\FireflyIII\\Import\Mapper\\%s', $mapperClass);- /** @var MapperInterface $mapper */- $mapper = new $mapperName;- $indexes[] = $index;- $data[$index] = [- 'name' => $column,- 'mapper' => $mapperName,- 'index' => $index,- 'options' => $mapper->getMap(),- 'preProcessMap' => null,- 'values' => [],- ];- if ($preProcessMap) {- $preClass = sprintf(- '\\FireflyIII\\Import\\MapperPreProcess\\%s',- config('csv.import_roles.' . $column . '.pre-process-mapper')- );- $data[$index]['preProcessMap'] = $preClass;- }- }-- }- }-- // in order to actually map we also need all possible values from the CSV file.- $content = $this->job->uploadFileContents();- /** @var Reader $reader */- $reader = Reader::createFromString($content);- $reader->setDelimiter($config['delimiter']);- $results = $reader->fetch();- $validSpecifics = array_keys(config('csv.import_specifics'));-- foreach ($results as $rowIndex => $row) {-- // skip first row?- if ($rowIndex === 0 && $config['has-headers']) {- continue;- }-- // run specifics here:- // and this is the point where the specifix go to work.- foreach ($config['specifics'] as $name => $enabled) {-- if (!in_array($name, $validSpecifics)) {- throw new FireflyException(sprintf('"%s" is not a valid class name', $name));- }- $class = config('csv.import_specifics.' . $name);- /** @var SpecificInterface $specific */- $specific = app($class);-- // it returns the row, possibly modified:- $row = $specific->run($row);- }-- //do something here- foreach ($indexes as $index) { // this is simply 1, 2, 3, etc.- if (!isset($row[$index])) {- // don't really know how to handle this. Just skip, for now.- continue;- }- $value = $row[$index];- if (strlen($value) > 0) {-- // we can do some preprocessing here,- // which is exclusively to fix the tags:- if (!is_null($data[$index]['preProcessMap'])) {- /** @var PreProcessorInterface $preProcessor */- $preProcessor = app($data[$index]['preProcessMap']);- $result = $preProcessor->run($value);- $data[$index]['values'] = array_merge($data[$index]['values'], $result);-- Log::debug($rowIndex . ':' . $index . 'Value before preprocessor', ['value' => $value]);- Log::debug($rowIndex . ':' . $index . 'Value after preprocessor', ['value-new' => $result]);- Log::debug($rowIndex . ':' . $index . 'Value after joining', ['value-complete' => $data[$index]['values']]);--- continue;- }-- $data[$index]['values'][] = $value;- }- }- }- foreach ($data as $index => $entry) {- $data[$index]['values'] = array_unique($data[$index]['values']);- }-- return $data;- }-- /**- * This method collects the data that will enable a user to choose column content.- *- * @return array- */- protected function getDataForColumnRoles(): array- {- Log::debug('Now in getDataForColumnRoles()');- $config = $this->job->configuration;- $data = [- 'columns' => [],- 'columnCount' => 0,- 'columnHeaders' => [],- ];-- // show user column role configuration.- $content = $this->job->uploadFileContents();-- // create CSV reader.- $reader = Reader::createFromString($content);- $reader->setDelimiter($config['delimiter']);- $start = $config['has-headers'] ? 1 : 0;- $end = $start + config('csv.example_rows');- $header = [];- if ($config['has-headers']) {- $header = $reader->fetchOne(0);- }--- // collect example data in $data['columns']- Log::debug(sprintf('While %s is smaller than %d', $start, $end));- while ($start < $end) {- $row = $reader->fetchOne($start);- Log::debug(sprintf('Row %d has %d columns', $start, count($row)));- // run specifics here:- // and this is the point where the specifix go to work.- foreach ($config['specifics'] as $name => $enabled) {- /** @var SpecificInterface $specific */- $specific = app('FireflyIII\Import\Specifics\\' . $name);- Log::debug(sprintf('Will now apply specific "%s" to row %d.', $name, $start));- // it returns the row, possibly modified:- $row = $specific->run($row);- }-- foreach ($row as $index => $value) {- $value = trim($value);- $data['columnHeaders'][$index] = $header[$index] ?? '';- if (strlen($value) > 0) {- $data['columns'][$index][] = $value;- }- }- $start++;- $data['columnCount'] = count($row) > $data['columnCount'] ? count($row) : $data['columnCount'];- }-- // make unique example data- foreach ($data['columns'] as $index => $values) {- $data['columns'][$index] = array_unique($values);- }-- $data['set_roles'] = [];- // collect possible column roles:- $data['available_roles'] = [];- foreach (array_keys(config('csv.import_roles')) as $role) {- $data['available_roles'][$role] = trans('csv.column_' . $role);- }-- $config['column-count'] = $data['columnCount'];- $this->job->configuration = $config;- $this->job->save();-- return $data;- }-}\ No newline at end of filediff --git a/app/Support/Steam.php b/app/Support/Steam.phpindex 1acca74857..32e07f08dc 100644--- a/app/Support/Steam.php+++ b/app/Support/Steam.php@@ -13,7 +13,7 @@ declare(strict_types=1);namespace FireflyIII\Support;-use Amount;+use \Amount as GlobalAmount;use Carbon\Carbon;use Crypt;use DB;@@ -48,9 +48,9 @@ class Steamreturn $cache->get(); // @codeCoverageIgnore}$currencyId = intval($account->getMeta('currency_id'));- // if null, use system default currency:+ // use system default currency:if ($currencyId === 0) {- $currency = Amount::getDefaultCurrency();+ $currency = GlobalAmount::getDefaultCurrency();$currencyId = $currency->id;}// first part: get all balances in own currency:diff --git a/public/js/ff/budgets/index.js b/public/js/ff/budgets/index.jsindex 01a00c9b0f..06e696ebed 100644--- a/public/js/ff/budgets/index.js+++ b/public/js/ff/budgets/index.js@@ -8,7 +8,7 @@* See the LICENSE file for details.*/-/** global: spent, budgeted, available, currencySymbol, budgetIndexURI */+/** global: spent, budgeted, available, currencySymbol, budgetIndexURI, accounting */function drawSpentBar() {"use strict";diff --git a/resources/views/import/status.twig b/resources/views/import/status.twigindex 487293de8e..f1a8bcd5c6 100644--- a/resources/views/import/status.twig+++ b/resources/views/import/status.twig@@ -133,97 +133,6 @@</div></div>--- {#--- <div class="row status_finished" style="display:none;">- <div class="col-lg-8 col-lg-offset-2 col-md-12 col-sm-12">- <div class="box box-default">- <div class="box-header with-border">- <h3 class="box-title">{{ 'import_status_report'|_ }}</h3>- </div>- <div class="box-body">- <p id="import-status-intro">- {{ 'import_finished_report'|_ }}- </p>- <p id="import-status-more-info"></p>- </div>- </div>- </div>- </div>-- <div class="row info_errors" style="display:none;">- <div class="col-lg-8 col-lg-offset-2 col-md-12 col-sm-12">- <div class="box box-danger">- <div class="box-header with-border">- <h3 class="box-title">{{ 'import_status_errors'|_ }}</h3>- </div>- <div class="box-body">- <p id="import-status-error-intro">- No errors detected.- </p>- <ul id="import-status-error-list"></ul>- </div>- </div>- </div>- </div>- #}--- {#- <div class="row">- <div class="col-lg-8 col-lg-offset-2 col-md-12 col-sm-12">- <div class="box box-primary">- <div class="box-header with-border">- <h3 class="box-title">{{ 'import_status_header'|_ }}</h3>- </div>- <div class="box-body">- <div class="progress" id="import-status-holder">- <div id="import-status-bar" class="progress-bar progress-bar-info active progress-bar-striped" role="progressbar"- aria-valuenow="100" aria-valuemin="0"- aria-valuemax="100" style="width: 100%">- </div>- </div>- <p id="import-status-txt">{{ 'import_status_settings_complete'|_ }}</p>- </div>- </div>- </div>- </div>-- <div class="row">- <div class="col-lg-8 col-lg-offset-2 col-md-12 col-sm-12">- <div class="box box-danger">- <div class="box-header with-border">- <h3 class="box-title">{{ 'import_status_errors'|_ }}</h3>- </div>- <div class="box-body">- <p id="import-status-error-intro">- No errors detected.- </p>- <ul id="import-status-error-list"></ul>- </div>- </div>- </div>- </div>-- <div class="row">- <div class="col-lg-8 col-lg-offset-2 col-md-12 col-sm-12">- <div class="box box-default">- <div class="box-header with-border">- <h3 class="box-title">{{ 'import_status_report'|_ }}</h3>- </div>- <div class="box-body">- <p id="import-status-intro">- {{ 'import_finished_report'|_ }}- </p>- <p id="import-status-more-info"></p>- </div>- </div>- </div>- </div>- #}{% endblock %}{% block scripts %}<script type="text/javascript">