Slight change in amount handler. #760

This commit is contained in:
James Cole
2017-08-13 15:30:39 +02:00
parent f9c85d4d81
commit 1633994fbd

View File

@@ -37,6 +37,8 @@ class ImportJournal
public $budget; public $budget;
/** @var ImportCategory */ /** @var ImportCategory */
public $category; public $category;
/** @var ImportCurrency */
public $currency;
/** @var string */ /** @var string */
public $description = ''; public $description = '';
/** @var string */ /** @var string */
@@ -51,8 +53,8 @@ class ImportJournal
public $tags = []; public $tags = [];
/** @var string */ /** @var string */
private $amount; private $amount;
/** @var ImportCurrency */ /** @var string */
public $currency; private $convertedAmount = null;
/** @var string */ /** @var string */
private $date = ''; private $date = '';
/** @var string */ /** @var string */
@@ -89,25 +91,25 @@ class ImportJournal
*/ */
public function getAmount(): string public function getAmount(): string
{ {
if (is_null($this->amount)) { if (is_null($this->convertedAmount)) {
/** @var ConverterInterface $amountConverter */ /** @var ConverterInterface $amountConverter */
$amountConverter = app(Amount::class); $amountConverter = app(Amount::class);
$this->amount = $amountConverter->convert($this->amount); $this->convertedAmount = $amountConverter->convert($this->amount);
// modify // modify
foreach ($this->modifiers as $modifier) { foreach ($this->modifiers as $modifier) {
$class = sprintf('FireflyIII\Import\Converter\%s', config(sprintf('csv.import_roles.%s.converter', $modifier['role']))); $class = sprintf('FireflyIII\Import\Converter\%s', config(sprintf('csv.import_roles.%s.converter', $modifier['role'])));
/** @var ConverterInterface $converter */ /** @var ConverterInterface $converter */
$converter = app($class); $converter = app($class);
if ($converter->convert($modifier['value']) === -1) { if ($converter->convert($modifier['value']) === -1) {
$this->amount = Steam::negative($this->amount); $this->convertedAmount = Steam::negative($this->convertedAmount);
} }
} }
} }
if(bccomp($this->amount,'0') === 0) { if (bccomp($this->convertedAmount, '0') === 0) {
throw new FireflyException('Amount is zero.'); throw new FireflyException('Amount is zero.');
} }
return $this->amount; return $this->convertedAmount;
} }
/** /**