Include default currency.

This commit is contained in:
James Cole 2017-08-12 16:42:29 +02:00
parent 83b721a322
commit f684a2900b
No known key found for this signature in database
GPG Key ID: C16961E655E74B5E

View File

@ -11,28 +11,16 @@ declare(strict_types=1);
namespace FireflyIII\Import\Storage; namespace FireflyIII\Import\Storage;
use Carbon\Carbon;
use FireflyIII\Exceptions\FireflyException; use FireflyIII\Exceptions\FireflyException;
use FireflyIII\Import\Object\ImportAccount; use FireflyIII\Import\Object\ImportAccount;
use FireflyIII\Import\Object\ImportJournal; use FireflyIII\Import\Object\ImportJournal;
use FireflyIII\Models\Account; use FireflyIII\Models\Account;
use FireflyIII\Models\AccountType; use FireflyIII\Models\AccountType;
use FireflyIII\Models\Bill;
use FireflyIII\Models\Budget;
use FireflyIII\Models\Category;
use FireflyIII\Models\ImportJob; use FireflyIII\Models\ImportJob;
use FireflyIII\Models\Rule;
use FireflyIII\Models\Transaction;
use FireflyIII\Models\TransactionCurrency;
use FireflyIII\Models\TransactionJournal;
use FireflyIII\Models\TransactionType;
use FireflyIII\Repositories\Currency\CurrencyRepositoryInterface; use FireflyIII\Repositories\Currency\CurrencyRepositoryInterface;
use FireflyIII\Repositories\Tag\TagRepositoryInterface; use FireflyIII\Repositories\Tag\TagRepositoryInterface;
use FireflyIII\Rules\Processor;
use Illuminate\Database\Query\JoinClause;
use Illuminate\Support\Collection; use Illuminate\Support\Collection;
use Log; use Log;
use Steam;
/** /**
* Is capable of storing individual ImportJournal objects. * Is capable of storing individual ImportJournal objects.
@ -50,8 +38,8 @@ class ImportStorage
private $currencyRepository; private $currencyRepository;
/** @var string */ /** @var string */
private $dateFormat = 'Ymd'; private $dateFormat = 'Ymd';
/** @var TransactionCurrency */ /** @var int */
private $defaultCurrency; private $defaultCurrencyId = 0;
/** @var ImportJob */ /** @var ImportJob */
private $job; private $job;
/** @var Collection */ /** @var Collection */
@ -84,7 +72,9 @@ class ImportStorage
*/ */
public function setJob(ImportJob $job) public function setJob(ImportJob $job)
{ {
$this->job = $job; $this->job = $job;
$currency = app('amount')->getDefaultCurrencyByUser($this->job->user);
$this->defaultCurrencyId = $currency->id;
// $repository = app(CurrencyRepositoryInterface::class); // $repository = app(CurrencyRepositoryInterface::class);
// $repository->setUser($job->user); // $repository->setUser($job->user);
// $this->currencyRepository = $repository; // $this->currencyRepository = $repository;
@ -93,7 +83,7 @@ class ImportStorage
// $repository->setUser($job->user); // $repository->setUser($job->user);
// $this->tagRepository = $repository; // $this->tagRepository = $repository;
// $this->rules = $this->getUserRules(); // $this->rules = $this->getUserRules();
// $this->defaultCurrency = Amount::getDefaultCurrencyByUser($this->job->user); //
} }
/** /**
@ -125,158 +115,158 @@ class ImportStorage
return true; return true;
} }
// //
// /** // /**
// * @param TransactionJournal $journal // * @param TransactionJournal $journal
// * // *
// * @return bool // * @return bool
// */ // */
// protected function applyRules(TransactionJournal $journal): bool // protected function applyRules(TransactionJournal $journal): bool
// { // {
// if ($this->rules->count() > 0) { // if ($this->rules->count() > 0) {
// /** @var Rule $rule */ // /** @var Rule $rule */
// foreach ($this->rules as $rule) { // foreach ($this->rules as $rule) {
// Log::debug(sprintf('Going to apply rule #%d to journal %d.', $rule->id, $journal->id)); // Log::debug(sprintf('Going to apply rule #%d to journal %d.', $rule->id, $journal->id));
// $processor = Processor::make($rule); // $processor = Processor::make($rule);
// $processor->handleTransactionJournal($journal); // $processor->handleTransactionJournal($journal);
// //
// if ($rule->stop_processing) { // if ($rule->stop_processing) {
// return true; // return true;
// } // }
// } // }
// } // }
// //
// return true; // return true;
// } // }
// /** // /**
// * @param array $parameters // * @param array $parameters
// * // *
// * @return bool // * @return bool
// * @throws FireflyException // * @throws FireflyException
// */ // */
// private function createTransaction(array $parameters): bool // private function createTransaction(array $parameters): bool
// { // {
// $transaction = new Transaction; // $transaction = new Transaction;
// $transaction->account_id = $parameters['account']; // $transaction->account_id = $parameters['account'];
// $transaction->transaction_journal_id = $parameters['id']; // $transaction->transaction_journal_id = $parameters['id'];
// $transaction->transaction_currency_id = $parameters['currency']; // $transaction->transaction_currency_id = $parameters['currency'];
// $transaction->amount = $parameters['amount']; // $transaction->amount = $parameters['amount'];
// $transaction->foreign_currency_id = $parameters['foreign_currency']; // $transaction->foreign_currency_id = $parameters['foreign_currency'];
// $transaction->foreign_amount = $parameters['foreign_amount']; // $transaction->foreign_amount = $parameters['foreign_amount'];
// $transaction->save(); // $transaction->save();
// if (is_null($transaction->id)) { // if (is_null($transaction->id)) {
// $errorText = join(', ', $transaction->getErrors()->all()); // $errorText = join(', ', $transaction->getErrors()->all());
// throw new FireflyException($errorText); // throw new FireflyException($errorText);
// } // }
// Log::debug(sprintf('Created transaction with ID #%d, account #%d, amount %s', $transaction->id, $parameters['account'], $parameters['amount'])); // Log::debug(sprintf('Created transaction with ID #%d, account #%d, amount %s', $transaction->id, $parameters['account'], $parameters['amount']));
// //
// return true; // return true;
// } // }
// /** // /**
// * @param Collection $set // * @param Collection $set
// * @param ImportJournal $importJournal // * @param ImportJournal $importJournal
// * // *
// * @return bool // * @return bool
// */ // */
// private function filterTransferSet(Collection $set, ImportJournal $importJournal): bool // private function filterTransferSet(Collection $set, ImportJournal $importJournal): bool
// { // {
// $amount = Steam::positive($importJournal->getAmount()); // $amount = Steam::positive($importJournal->getAmount());
// $asset = $importJournal->asset->getAccount(); // $asset = $importJournal->asset->getAccount();
// $opposing = $this->getOpposingAccount($importJournal->opposing, $asset->id, $amount); // $opposing = $this->getOpposingAccount($importJournal->opposing, $asset->id, $amount);
// $description = $importJournal->getDescription(); // $description = $importJournal->getDescription();
// //
// $filtered = $set->filter( // $filtered = $set->filter(
// function (TransactionJournal $journal) use ($asset, $opposing, $description) { // function (TransactionJournal $journal) use ($asset, $opposing, $description) {
// $match = true; // $match = true;
// $original = [app('steam')->tryDecrypt($journal->source_name), app('steam')->tryDecrypt($journal->destination_name)]; // $original = [app('steam')->tryDecrypt($journal->source_name), app('steam')->tryDecrypt($journal->destination_name)];
// $compare = [$asset->name, $opposing->name]; // $compare = [$asset->name, $opposing->name];
// sort($original); // sort($original);
// sort($compare); // sort($compare);
// //
// // description does not match? Then cannot be duplicate. // // description does not match? Then cannot be duplicate.
// if ($journal->description !== $description) { // if ($journal->description !== $description) {
// $match = false; // $match = false;
// } // }
// // not both accounts in journal? Then cannot be duplicate. // // not both accounts in journal? Then cannot be duplicate.
// if ($original !== $compare) { // if ($original !== $compare) {
// $match = false; // $match = false;
// } // }
// //
// if ($match) { // if ($match) {
// return $journal; // return $journal;
// } // }
// //
// return null; // return null;
// } // }
// ); // );
// if (count($filtered) > 0) { // if (count($filtered) > 0) {
// return true; // return true;
// } // }
// //
// return false; // return false;
// } // }
// /** // /**
// * @param ImportJournal $importJournal // * @param ImportJournal $importJournal
// * // *
// * @param Account $account // * @param Account $account
// * // *
// * @return TransactionCurrency // * @return TransactionCurrency
// */ // */
// private function getCurrency(ImportJournal $importJournal, Account $account): TransactionCurrency // private function getCurrency(ImportJournal $importJournal, Account $account): TransactionCurrency
// { // {
// // start with currency pref of account, if any: // // start with currency pref of account, if any:
// $currency = $this->currencyRepository->find(intval($account->getMeta('currency_id'))); // $currency = $this->currencyRepository->find(intval($account->getMeta('currency_id')));
// if (!is_null($currency->id)) { // if (!is_null($currency->id)) {
// return $currency; // return $currency;
// } // }
// //
// // use given currency // // use given currency
// $currency = $importJournal->getCurrency()->getTransactionCurrency(); // $currency = $importJournal->getCurrency()->getTransactionCurrency();
// if (!is_null($currency->id)) { // if (!is_null($currency->id)) {
// return $currency; // return $currency;
// } // }
// //
// // backup to default // // backup to default
// $currency = $this->defaultCurrency; // $currency = $this->defaultCurrency;
// //
// return $currency; // return $currency;
// //
// } // }
// /** // /**
// * @param ImportJournal $importJournal // * @param ImportJournal $importJournal
// * @param TransactionCurrency $localCurrency // * @param TransactionCurrency $localCurrency
// * // *
// * @return int|null // * @return int|null
// */ // */
// private function getForeignCurrencyId(ImportJournal $importJournal, TransactionCurrency $localCurrency): ?int // private function getForeignCurrencyId(ImportJournal $importJournal, TransactionCurrency $localCurrency): ?int
// { // {
// // get journal currency, if any: // // get journal currency, if any:
// $currency = $importJournal->getCurrency()->getTransactionCurrency(); // $currency = $importJournal->getCurrency()->getTransactionCurrency();
// if (is_null($currency->id)) { // if (is_null($currency->id)) {
// Log::debug('getForeignCurrencyId: Journal has no currency, so can\'t be foreign either way.'); // Log::debug('getForeignCurrencyId: Journal has no currency, so can\'t be foreign either way.');
// //
// // journal has no currency, so can't be foreign either way: // // journal has no currency, so can't be foreign either way:
// return null; // return null;
// } // }
// //
// if ($currency->id !== $localCurrency->id) { // if ($currency->id !== $localCurrency->id) {
// Log::debug( // Log::debug(
// sprintf('getForeignCurrencyId: journal is %s, but account is %s. Return id of journal currency.', $currency->code, $localCurrency->code) // sprintf('getForeignCurrencyId: journal is %s, but account is %s. Return id of journal currency.', $currency->code, $localCurrency->code)
// ); // );
// //
// // journal has different currency than account does, return its ID: // // journal has different currency than account does, return its ID:
// return $currency->id; // return $currency->id;
// } // }
// //
// Log::debug('getForeignCurrencyId: journal has no foreign currency.'); // Log::debug('getForeignCurrencyId: journal has no foreign currency.');
// //
// // return null in other cases. // // return null in other cases.
// return null; // return null;
// } // }
/** /**
* @param ImportAccount $account * @param ImportAccount $account
@ -302,86 +292,86 @@ class ImportStorage
return $databaseAccount; return $databaseAccount;
} }
// //
// /** // /**
// * @param string $amount // * @param string $amount
// * // *
// * @return TransactionType // * @return TransactionType
// */ // */
// private function getTransactionType(string $amount): TransactionType // private function getTransactionType(string $amount): TransactionType
// { // {
// $transactionType = new TransactionType(); // $transactionType = new TransactionType();
// // amount is negative, it's a withdrawal, opposing is an expense: // // amount is negative, it's a withdrawal, opposing is an expense:
// if (bccomp($amount, '0') === -1) { // if (bccomp($amount, '0') === -1) {
// $transactionType = TransactionType::whereType(TransactionType::WITHDRAWAL)->first(); // $transactionType = TransactionType::whereType(TransactionType::WITHDRAWAL)->first();
// } // }
// if (bccomp($amount, '0') === 1) { // if (bccomp($amount, '0') === 1) {
// $transactionType = TransactionType::whereType(TransactionType::DEPOSIT)->first(); // $transactionType = TransactionType::whereType(TransactionType::DEPOSIT)->first();
// } // }
// //
// return $transactionType; // return $transactionType;
// } // }
// /** // /**
// * @return Collection // * @return Collection
// */ // */
// private function getUserRules(): Collection // private function getUserRules(): Collection
// { // {
// $set = Rule::distinct() // $set = Rule::distinct()
// ->where('rules.user_id', $this->job->user->id) // ->where('rules.user_id', $this->job->user->id)
// ->leftJoin('rule_groups', 'rule_groups.id', '=', 'rules.rule_group_id') // ->leftJoin('rule_groups', 'rule_groups.id', '=', 'rules.rule_group_id')
// ->leftJoin('rule_triggers', 'rules.id', '=', 'rule_triggers.rule_id') // ->leftJoin('rule_triggers', 'rules.id', '=', 'rule_triggers.rule_id')
// ->where('rule_groups.active', 1) // ->where('rule_groups.active', 1)
// ->where('rule_triggers.trigger_type', 'user_action') // ->where('rule_triggers.trigger_type', 'user_action')
// ->where('rule_triggers.trigger_value', 'store-journal') // ->where('rule_triggers.trigger_value', 'store-journal')
// ->where('rules.active', 1) // ->where('rules.active', 1)
// ->orderBy('rule_groups.order', 'ASC') // ->orderBy('rule_groups.order', 'ASC')
// ->orderBy('rules.order', 'ASC') // ->orderBy('rules.order', 'ASC')
// ->get(['rules.*', 'rule_groups.order']); // ->get(['rules.*', 'rule_groups.order']);
// Log::debug(sprintf('Found %d user rules.', $set->count())); // Log::debug(sprintf('Found %d user rules.', $set->count()));
// //
// return $set; // return $set;
// //
// } // }
// //
// /** // /**
// * @param TransactionJournal $journal // * @param TransactionJournal $journal
// * @param Bill $bill // * @param Bill $bill
// */ // */
// private function storeBill(TransactionJournal $journal, Bill $bill) // private function storeBill(TransactionJournal $journal, Bill $bill)
// { // {
// if (!is_null($bill->id)) { // if (!is_null($bill->id)) {
// Log::debug(sprintf('Linked bill #%d to journal #%d', $bill->id, $journal->id)); // Log::debug(sprintf('Linked bill #%d to journal #%d', $bill->id, $journal->id));
// $journal->bill()->associate($bill); // $journal->bill()->associate($bill);
// $journal->save(); // $journal->save();
// } // }
// } // }
// /** // /**
// * @param TransactionJournal $journal // * @param TransactionJournal $journal
// * @param Budget $budget // * @param Budget $budget
// */ // */
// private function storeBudget(TransactionJournal $journal, Budget $budget) // private function storeBudget(TransactionJournal $journal, Budget $budget)
// { // {
// if (!is_null($budget->id)) { // if (!is_null($budget->id)) {
// Log::debug(sprintf('Linked budget #%d to journal #%d', $budget->id, $journal->id)); // Log::debug(sprintf('Linked budget #%d to journal #%d', $budget->id, $journal->id));
// $journal->budgets()->save($budget); // $journal->budgets()->save($budget);
// } // }
// } // }
// //
// /** // /**
// * @param TransactionJournal $journal // * @param TransactionJournal $journal
// * @param Category $category // * @param Category $category
// */ // */
// private function storeCategory(TransactionJournal $journal, Category $category) // private function storeCategory(TransactionJournal $journal, Category $category)
// { // {
// //
// if (!is_null($category->id)) { // if (!is_null($category->id)) {
// Log::debug(sprintf('Linked category #%d to journal #%d', $category->id, $journal->id)); // Log::debug(sprintf('Linked category #%d to journal #%d', $category->id, $journal->id));
// $journal->categories()->save($category); // $journal->categories()->save($category);
// } // }
// //
// } // }
/** /**
* @param int $index * @param int $index
@ -393,203 +383,203 @@ class ImportStorage
private function storeImportJournal(int $index, ImportJournal $importJournal): bool private function storeImportJournal(int $index, ImportJournal $importJournal): bool
{ {
Log::debug(sprintf('Going to store object #%d with description "%s"', $index, $importJournal->getDescription())); Log::debug(sprintf('Going to store object #%d with description "%s"', $index, $importJournal->getDescription()));
$asset = $importJournal->asset->getAccount(); $asset = $importJournal->asset->getAccount();
$amount = $importJournal->getAmount(); $amount = $importJournal->getAmount();
// $currency = $this->getCurrency($importJournal, $asset); // $currency = $this->getCurrency($importJournal, $asset);
// $foreignCurrencyId = $this->getForeignCurrencyId($importJournal, $currency); // $foreignCurrencyId = $this->getForeignCurrencyId($importJournal, $currency);
// $date = $importJournal->getDate($this->dateFormat); // $date = $importJournal->getDate($this->dateFormat);
// $transactionType = $this->getTransactionType($amount); // $transactionType = $this->getTransactionType($amount);
// $opposing = $this->getOpposingAccount($importJournal->opposing, $asset->id, $amount); // $opposing = $this->getOpposingAccount($importJournal->opposing, $asset->id, $amount);
// //
// // if opposing is an asset account, it's a transfer: // // if opposing is an asset account, it's a transfer:
// if ($opposing->accountType->type === AccountType::ASSET) { // if ($opposing->accountType->type === AccountType::ASSET) {
// Log::debug(sprintf('Opposing account #%d %s is an asset account, make transfer.', $opposing->id, $opposing->name)); // Log::debug(sprintf('Opposing account #%d %s is an asset account, make transfer.', $opposing->id, $opposing->name));
// $transactionType = TransactionType::whereType(TransactionType::TRANSFER)->first(); // $transactionType = TransactionType::whereType(TransactionType::TRANSFER)->first();
// } // }
// //
// // verify that opposing account is of the correct type: // // verify that opposing account is of the correct type:
// if ($opposing->accountType->type === AccountType::EXPENSE && $transactionType->type !== TransactionType::WITHDRAWAL) { // if ($opposing->accountType->type === AccountType::EXPENSE && $transactionType->type !== TransactionType::WITHDRAWAL) {
// $message = sprintf('Row #%d is imported as a %s but opposing is an expense account. This cannot be!', $index, $transactionType->type); // $message = sprintf('Row #%d is imported as a %s but opposing is an expense account. This cannot be!', $index, $transactionType->type);
// Log::error($message); // Log::error($message);
// throw new FireflyException($message); // throw new FireflyException($message);
// //
// } // }
// //
// /*** First step done! */ // /*** First step done! */
// $this->job->addStepsDone(1); // $this->job->addStepsDone(1);
// //
// // could be that transfer is double: verify this. // // could be that transfer is double: verify this.
// if ($this->verifyDoubleTransfer($transactionType, $importJournal)) { // if ($this->verifyDoubleTransfer($transactionType, $importJournal)) {
// // add three steps: // // add three steps:
// $this->job->addStepsDone(3); // $this->job->addStepsDone(3);
// // throw error // // throw error
// throw new FireflyException('Detected a possible duplicate, skip this one.'); // throw new FireflyException('Detected a possible duplicate, skip this one.');
// //
// } // }
// //
// // create a journal: // // create a journal:
// $journal = new TransactionJournal; // $journal = new TransactionJournal;
// $journal->user_id = $this->job->user_id; // $journal->user_id = $this->job->user_id;
// $journal->transaction_type_id = $transactionType->id; // $journal->transaction_type_id = $transactionType->id;
// $journal->transaction_currency_id = $currency->id;// always currency of account // $journal->transaction_currency_id = $currency->id;// always currency of account
// $journal->description = $importJournal->getDescription(); // $journal->description = $importJournal->getDescription();
// $journal->date = $date->format('Y-m-d'); // $journal->date = $date->format('Y-m-d');
// $journal->order = 0; // $journal->order = 0;
// $journal->tag_count = 0; // $journal->tag_count = 0;
// $journal->completed = false; // $journal->completed = false;
// //
// if (!$journal->save()) { // if (!$journal->save()) {
// $errorText = join(', ', $journal->getErrors()->all()); // $errorText = join(', ', $journal->getErrors()->all());
// // add three steps: // // add three steps:
// $this->job->addStepsDone(3); // $this->job->addStepsDone(3);
// // throw error // // throw error
// throw new FireflyException($errorText); // throw new FireflyException($errorText);
// } // }
// //
// // save meta data: // // save meta data:
// $journal->setMeta('importHash', $importJournal->hash); // $journal->setMeta('importHash', $importJournal->hash);
// Log::debug(sprintf('Created journal with ID #%d', $journal->id)); // Log::debug(sprintf('Created journal with ID #%d', $journal->id));
// //
// // create transactions: // // create transactions:
// $one = [ // $one = [
// 'id' => $journal->id, // 'id' => $journal->id,
// 'account' => $asset->id, // 'account' => $asset->id,
// 'currency' => $currency->id, // 'currency' => $currency->id,
// 'amount' => $amount, // 'amount' => $amount,
// 'foreign_currency' => $foreignCurrencyId, // 'foreign_currency' => $foreignCurrencyId,
// 'foreign_amount' => is_null($foreignCurrencyId) ? null : $amount, // 'foreign_amount' => is_null($foreignCurrencyId) ? null : $amount,
// ]; // ];
// $two = [ // $two = [
// 'id' => $journal->id, // 'id' => $journal->id,
// 'account' => $opposing->id, // 'account' => $opposing->id,
// 'currency' => $currency->id, // 'currency' => $currency->id,
// 'amount' => Steam::opposite($amount), // 'amount' => Steam::opposite($amount),
// 'foreign_currency' => $foreignCurrencyId, // 'foreign_currency' => $foreignCurrencyId,
// 'foreign_amount' => is_null($foreignCurrencyId) ? null : Steam::opposite($amount), // 'foreign_amount' => is_null($foreignCurrencyId) ? null : Steam::opposite($amount),
// ]; // ];
// $this->createTransaction($one); // $this->createTransaction($one);
// $this->createTransaction($two); // $this->createTransaction($two);
// //
// /*** Another step done! */ // /*** Another step done! */
// $this->job->addStepsDone(1); // $this->job->addStepsDone(1);
// //
// // store meta object things: // // store meta object things:
// $this->storeCategory($journal, $importJournal->category->getCategory()); // $this->storeCategory($journal, $importJournal->category->getCategory());
// $this->storeBudget($journal, $importJournal->budget->getBudget()); // $this->storeBudget($journal, $importJournal->budget->getBudget());
// $this->storeBill($journal, $importJournal->bill->getBill()); // $this->storeBill($journal, $importJournal->bill->getBill());
// $this->storeMeta($journal, $importJournal->metaDates); // $this->storeMeta($journal, $importJournal->metaDates);
// //
// // sepa thing as note: // // sepa thing as note:
// if (strlen($importJournal->notes) > 0) { // if (strlen($importJournal->notes) > 0) {
// $journal->setMeta('notes', $importJournal->notes); // $journal->setMeta('notes', $importJournal->notes);
// } // }
// //
// // store tags // // store tags
// $this->storeTags($importJournal->tags, $journal); // $this->storeTags($importJournal->tags, $journal);
// //
// // set journal completed: // // set journal completed:
// $journal->completed = true; // $journal->completed = true;
// $journal->save(); // $journal->save();
// //
// $this->job->addStepsDone(1); // $this->job->addStepsDone(1);
// //
// // run rules: // // run rules:
// $this->applyRules($journal); // $this->applyRules($journal);
// $this->job->addStepsDone(1); // $this->job->addStepsDone(1);
// $this->journals->push($journal); // $this->journals->push($journal);
// //
// Log::info( // Log::info(
// sprintf( // sprintf(
// 'Imported new journal #%d with description "%s" and amount %s %s.', $journal->id, $journal->description, $journal->transactionCurrency->code, // 'Imported new journal #%d with description "%s" and amount %s %s.', $journal->id, $journal->description, $journal->transactionCurrency->code,
// $amount // $amount
// ) // )
// ); // );
return true; return true;
} }
// /** // /**
// * @param TransactionJournal $journal // * @param TransactionJournal $journal
// * @param array $dates // * @param array $dates
// */ // */
// private function storeMeta(TransactionJournal $journal, array $dates) // private function storeMeta(TransactionJournal $journal, array $dates)
// { // {
// // all other date fields as meta thing: // // all other date fields as meta thing:
// foreach ($dates as $name => $value) { // foreach ($dates as $name => $value) {
// try { // try {
// $date = new Carbon($value); // $date = new Carbon($value);
// $journal->setMeta($name, $date); // $journal->setMeta($name, $date);
// } catch (\Exception $e) { // } catch (\Exception $e) {
// // don't care, ignore: // // don't care, ignore:
// Log::warning(sprintf('Could not parse "%s" into a valid Date object for field %s', $value, $name)); // Log::warning(sprintf('Could not parse "%s" into a valid Date object for field %s', $value, $name));
// } // }
// } // }
// } // }
// /** // /**
// * @param array $tags // * @param array $tags
// * @param TransactionJournal $journal // * @param TransactionJournal $journal
// */ // */
// private function storeTags(array $tags, TransactionJournal $journal): void // private function storeTags(array $tags, TransactionJournal $journal): void
// { // {
// foreach ($tags as $tag) { // foreach ($tags as $tag) {
// $dbTag = $this->tagRepository->findByTag($tag); // $dbTag = $this->tagRepository->findByTag($tag);
// if (is_null($dbTag->id)) { // if (is_null($dbTag->id)) {
// $dbTag = $this->tagRepository->store( // $dbTag = $this->tagRepository->store(
// ['tag' => $tag, 'date' => null, 'description' => null, 'latitude' => null, 'longitude' => null, // ['tag' => $tag, 'date' => null, 'description' => null, 'latitude' => null, 'longitude' => null,
// 'zoomLevel' => null, 'tagMode' => 'nothing'] // 'zoomLevel' => null, 'tagMode' => 'nothing']
// ); // );
// } // }
// $journal->tags()->save($dbTag); // $journal->tags()->save($dbTag);
// Log::debug(sprintf('Linked tag %d ("%s") to journal #%d', $dbTag->id, $dbTag->tag, $journal->id)); // Log::debug(sprintf('Linked tag %d ("%s") to journal #%d', $dbTag->id, $dbTag->tag, $journal->id));
// } // }
// //
// return; // return;
// } // }
// /** // /**
// * This method checks if the given transaction is a transfer and if so, if it might be a duplicate of an already imported transfer. // * This method checks if the given transaction is a transfer and if so, if it might be a duplicate of an already imported transfer.
// * This is important for import files that cover multiple accounts (and include both A<>B and B<>A transactions). // * This is important for import files that cover multiple accounts (and include both A<>B and B<>A transactions).
// * // *
// * @param TransactionType $transactionType // * @param TransactionType $transactionType
// * @param ImportJournal $importJournal // * @param ImportJournal $importJournal
// * // *
// * @return bool // * @return bool
// */ // */
// private function verifyDoubleTransfer(TransactionType $transactionType, ImportJournal $importJournal): bool // private function verifyDoubleTransfer(TransactionType $transactionType, ImportJournal $importJournal): bool
// { // {
// if ($transactionType->type === TransactionType::TRANSFER) { // if ($transactionType->type === TransactionType::TRANSFER) {
// $amount = Steam::positive($importJournal->getAmount()); // $amount = Steam::positive($importJournal->getAmount());
// $date = $importJournal->getDate($this->dateFormat); // $date = $importJournal->getDate($this->dateFormat);
// $set = TransactionJournal::leftJoin('transaction_types', 'transaction_types.id', '=', 'transaction_journals.transaction_type_id') // $set = TransactionJournal::leftJoin('transaction_types', 'transaction_types.id', '=', 'transaction_journals.transaction_type_id')
// ->leftJoin( // ->leftJoin(
// 'transactions AS source', function (JoinClause $join) { // 'transactions AS source', function (JoinClause $join) {
// $join->on('transaction_journals.id', '=', 'source.transaction_journal_id')->where('source.amount', '<', 0); // $join->on('transaction_journals.id', '=', 'source.transaction_journal_id')->where('source.amount', '<', 0);
// } // }
// ) // )
// ->leftJoin( // ->leftJoin(
// 'transactions AS destination', function (JoinClause $join) { // 'transactions AS destination', function (JoinClause $join) {
// $join->on('transaction_journals.id', '=', 'destination.transaction_journal_id')->where( // $join->on('transaction_journals.id', '=', 'destination.transaction_journal_id')->where(
// 'destination.amount', '>', 0 // 'destination.amount', '>', 0
// ); // );
// } // }
// ) // )
// ->leftJoin('accounts as source_accounts', 'source.account_id', '=', 'source_accounts.id') // ->leftJoin('accounts as source_accounts', 'source.account_id', '=', 'source_accounts.id')
// ->leftJoin('accounts as destination_accounts', 'destination.account_id', '=', 'destination_accounts.id') // ->leftJoin('accounts as destination_accounts', 'destination.account_id', '=', 'destination_accounts.id')
// ->where('transaction_journals.user_id', $this->job->user_id) // ->where('transaction_journals.user_id', $this->job->user_id)
// ->where('transaction_types.type', TransactionType::TRANSFER) // ->where('transaction_types.type', TransactionType::TRANSFER)
// ->where('transaction_journals.date', $date->format('Y-m-d')) // ->where('transaction_journals.date', $date->format('Y-m-d'))
// ->where('destination.amount', $amount) // ->where('destination.amount', $amount)
// ->get( // ->get(
// ['transaction_journals.id', 'transaction_journals.encrypted', 'transaction_journals.description', // ['transaction_journals.id', 'transaction_journals.encrypted', 'transaction_journals.description',
// 'source_accounts.name as source_name', 'destination_accounts.name as destination_name'] // 'source_accounts.name as source_name', 'destination_accounts.name as destination_name']
// ); // );
// //
// return $this->filterTransferSet($set, $importJournal); // return $this->filterTransferSet($set, $importJournal);
// } // }
// //
// //
// return false; // return false;
// } // }
} }