Basic storage routine works, basic file handling.

This commit is contained in:
James Cole
2018-05-10 09:10:16 +02:00
parent 116f7ed613
commit cabcb9c6d0
16 changed files with 278 additions and 157 deletions

View File

@@ -68,7 +68,8 @@ class TransactionCurrencyFactory
$currencyCode = (string)$currencyCode;
$currencyId = (int)$currencyId;
if (\strlen($currencyCode) === 0 && (int)$currencyId === 0) {
if ('' === $currencyCode && $currencyId === 0) {
Log::warning('Cannot find anything on empty currency code and empty currency ID!');
return null;
}
@@ -78,6 +79,7 @@ class TransactionCurrencyFactory
if (null !== $currency) {
return $currency;
}
Log::warning(sprintf('Currency ID is %d but found nothing!', $currencyId));
}
// then by code:
if (\strlen($currencyCode) > 0) {
@@ -85,7 +87,9 @@ class TransactionCurrencyFactory
if (null !== $currency) {
return $currency;
}
Log::warning(sprintf('Currency code is %d but found nothing!', $currencyCode));
}
Log::warning('Found nothing for currency.');
return null;
}

View File

@@ -31,6 +31,7 @@ use FireflyIII\Models\TransactionType;
use FireflyIII\Services\Internal\Support\TransactionServiceTrait;
use FireflyIII\User;
use Illuminate\Support\Collection;
use Log;
/**
* Class TransactionFactory
@@ -50,10 +51,17 @@ class TransactionFactory
*/
public function create(array $data): ?Transaction
{
$currencyId = isset($data['currency']) ? $data['currency']->id : $data['currency_id'];
Log::debug('Start of TransactionFactory::create()');
$currencyId = $data['currency_id'] ?? null;
$currencyId = isset($data['currency']) ? $data['currency']->id : $currencyId;
Log::debug('We dont make it here');
if ('' === $data['amount']) {
throw new FireflyException('Amount is an empty string, which Firefly III cannot handle. Apologies.');
}
if (null === $currencyId) {
throw new FireflyException('Cannot store transaction without currency information.');
}
$data['foreign_amount'] = '' === (string)$data['foreign_amount'] ? null : $data['foreign_amount'];
return Transaction::create(
[
@@ -81,6 +89,7 @@ class TransactionFactory
*/
public function createPair(TransactionJournal $journal, array $data): Collection
{
Log::debug('Start of TransactionFactory::createPair()');
// all this data is the same for both transactions:
$currency = $this->findCurrency($data['currency_id'], $data['currency_code']);
$description = $journal->description === $data['description'] ? null : $data['description'];

View File

@@ -70,8 +70,10 @@ class TransactionJournalFactory
$factory = app(TransactionFactory::class);
$factory->setUser($this->user);
Log::debug(sprintf('Found %d transactions in array.', \count($data['transactions'])));
/** @var array $trData */
foreach ($data['transactions'] as $trData) {
foreach ($data['transactions'] as $index => $trData) {
Log::debug(sprintf('Now storing transaction %d of %d', $index + 1, \count($data['transactions'])));
$factory->createPair($journal, $trData);
}
$journal->completed = true;