diff --git a/app/Console/Commands/Import.php b/app/Console/Commands/Import.php index 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 Command return 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.php index 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.php index 2b1e8bf061..b01335dce7 100644 --- a/app/Http/Controllers/Transaction/ConvertController.php +++ b/app/Http/Controllers/Transaction/ConvertController.php @@ -229,8 +229,8 @@ class ConvertController extends Controller switch ($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.php index 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.php index 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.php index 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.php index 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 ImportAccount Log::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.php index b982e9c6b5..8427f3ce5f 100644 --- a/app/Import/Object/ImportCurrency.php +++ b/app/Import/Object/ImportCurrency.php @@ -54,7 +54,6 @@ class ImportCurrency Log::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.php index 60d9edb2f9..a86cdffe5d 100644 --- a/app/Import/Object/ImportJournal.php +++ b/app/Import/Object/ImportJournal.php @@ -251,7 +251,6 @@ class ImportJournal case '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.php index 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.php index 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\Account diff --git a/app/Repositories/Journal/CreateJournalsTrait.php b/app/Repositories/Journal/CreateJournalsTrait.php index 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\Journal diff --git a/app/Support/Import/Configuration/Csv/Map.php b/app/Support/Import/Configuration/Csv/Map.php index 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.php deleted file mode 100644 index dbf915f50f..0000000000 --- a/app/Support/Import/CsvImportSupportTrait.php +++ /dev/null @@ -1,245 +0,0 @@ -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 file diff --git a/app/Support/Steam.php b/app/Support/Steam.php index 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 Steam return $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.js index 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.twig index 487293de8e..f1a8bcd5c6 100644 --- a/resources/views/import/status.twig +++ b/resources/views/import/status.twig @@ -133,97 +133,6 @@ - - - {# - - -
- - - #} - - - {# -{{ 'import_status_settings_complete'|_ }}
-- No errors detected. -
-- {{ 'import_finished_report'|_ }} -
- -