mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-02-25 18:45:27 -06:00
Fix #931
This commit is contained in:
parent
6bda5c2d53
commit
cd42399c29
@ -88,6 +88,7 @@ class Amount implements ConverterInterface
|
|||||||
Log::debug(sprintf('No decimal character found. Converted amount from "%s" to "%s".', $oldValue, $value));
|
Log::debug(sprintf('No decimal character found. Converted amount from "%s" to "%s".', $oldValue, $value));
|
||||||
}
|
}
|
||||||
|
|
||||||
return strval(round(floatval($value), 12));
|
$number = strval(number_format(round(floatval($value), 12), 12));
|
||||||
|
return $number;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
44
app/Import/Converter/AmountCredit.php
Normal file
44
app/Import/Converter/AmountCredit.php
Normal file
@ -0,0 +1,44 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* AmountCredit.php
|
||||||
|
* Copyright (c) 2017 thegrumpydictator@gmail.com
|
||||||
|
*
|
||||||
|
* This file is part of Firefly III.
|
||||||
|
*
|
||||||
|
* Firefly III is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* Firefly III is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with Firefly III. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace FireflyIII\Import\Converter;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Class AmountCredit
|
||||||
|
*/
|
||||||
|
class AmountCredit implements ConverterInterface
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* @param $value
|
||||||
|
*
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public function convert($value): string
|
||||||
|
{
|
||||||
|
/** @var ConverterInterface $converter */
|
||||||
|
$converter = app(Amount::class);
|
||||||
|
$result = $converter->convert($value);
|
||||||
|
$result = app('steam')->positive($result);
|
||||||
|
|
||||||
|
return $result;
|
||||||
|
}
|
||||||
|
}
|
45
app/Import/Converter/AmountDebet.php
Normal file
45
app/Import/Converter/AmountDebet.php
Normal file
@ -0,0 +1,45 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* AmountDebet.php
|
||||||
|
* Copyright (c) 2017 thegrumpydictator@gmail.com
|
||||||
|
*
|
||||||
|
* This file is part of Firefly III.
|
||||||
|
*
|
||||||
|
* Firefly III is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* Firefly III is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with Firefly III. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace FireflyIII\Import\Converter;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Class AmountDebet
|
||||||
|
*/
|
||||||
|
class AmountDebet implements ConverterInterface
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* @param $value
|
||||||
|
*
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public function convert($value): string
|
||||||
|
{
|
||||||
|
/** @var ConverterInterface $converter */
|
||||||
|
$converter = app(Amount::class);
|
||||||
|
$result = $converter->convert($value);
|
||||||
|
$result = app('steam')->positive($result);
|
||||||
|
$result = bcmul($result, '-1');
|
||||||
|
|
||||||
|
return $result;
|
||||||
|
}
|
||||||
|
}
|
@ -59,8 +59,12 @@ class ImportJournal
|
|||||||
public $opposing;
|
public $opposing;
|
||||||
/** @var array */
|
/** @var array */
|
||||||
public $tags = [];
|
public $tags = [];
|
||||||
/** @var string */
|
/** @var array */
|
||||||
private $amount;
|
private $amount;
|
||||||
|
/** @var array */
|
||||||
|
private $amountCredit;
|
||||||
|
/** @var array */
|
||||||
|
private $amountDebet;
|
||||||
/** @var string */
|
/** @var string */
|
||||||
private $convertedAmount = null;
|
private $convertedAmount = null;
|
||||||
/** @var string */
|
/** @var string */
|
||||||
@ -101,11 +105,40 @@ class ImportJournal
|
|||||||
public function getAmount(): string
|
public function getAmount(): string
|
||||||
{
|
{
|
||||||
Log::debug('Now in getAmount()');
|
Log::debug('Now in getAmount()');
|
||||||
|
Log::debug(sprintf('amount is %s', var_export($this->amount, true)));
|
||||||
|
Log::debug(sprintf('debet amount is %s', var_export($this->amountDebet, true)));
|
||||||
|
Log::debug(sprintf('credit amount is %s', var_export($this->amountCredit, true)));
|
||||||
|
|
||||||
if (null === $this->convertedAmount) {
|
if (null === $this->convertedAmount) {
|
||||||
|
// first check if the amount is set:
|
||||||
Log::debug('convertedAmount is NULL');
|
Log::debug('convertedAmount is NULL');
|
||||||
|
|
||||||
|
$info = [];
|
||||||
|
$converterClass = '';
|
||||||
|
|
||||||
|
if (!is_null($this->amount)) {
|
||||||
|
Log::debug('Amount value is not NULL, assume this is the correct value.');
|
||||||
|
$converterClass = sprintf('FireflyIII\Import\Converter\%s', config(sprintf('csv.import_roles.%s.converter', $this->amount['role'])));
|
||||||
|
$info = $this->amount;
|
||||||
|
}
|
||||||
|
if (!is_null($this->amountDebet)) {
|
||||||
|
Log::debug('Amount DEBET value is not NULL, assume this is the correct value (overrules Amount).');
|
||||||
|
$converterClass = sprintf('FireflyIII\Import\Converter\%s', config(sprintf('csv.import_roles.%s.converter', $this->amountDebet['role'])));
|
||||||
|
$info = $this->amountDebet;
|
||||||
|
}
|
||||||
|
if (!is_null($this->amountCredit)) {
|
||||||
|
Log::debug('Amount CREDIT value is not NULL, assume this is the correct value (overrules Amount and AmountDebet).');
|
||||||
|
$converterClass = sprintf('FireflyIII\Import\Converter\%s', config(sprintf('csv.import_roles.%s.converter', $this->amountCredit['role'])));
|
||||||
|
$info = $this->amountCredit;
|
||||||
|
}
|
||||||
|
if (count($info) === 0) {
|
||||||
|
throw new FireflyException('No amount information for this row.');
|
||||||
|
}
|
||||||
|
|
||||||
|
Log::debug(sprintf('Converter class is %s', $converterClass));
|
||||||
/** @var ConverterInterface $amountConverter */
|
/** @var ConverterInterface $amountConverter */
|
||||||
$amountConverter = app(Amount::class);
|
$amountConverter = app($converterClass);
|
||||||
$this->convertedAmount = $amountConverter->convert($this->amount);
|
$this->convertedAmount = $amountConverter->convert($info['value']);
|
||||||
Log::debug(sprintf('First attempt to convert gives "%s"', $this->convertedAmount));
|
Log::debug(sprintf('First attempt to convert gives "%s"', $this->convertedAmount));
|
||||||
// modify
|
// modify
|
||||||
foreach ($this->modifiers as $modifier) {
|
foreach ($this->modifiers as $modifier) {
|
||||||
@ -196,7 +229,13 @@ class ImportJournal
|
|||||||
$this->asset->setAccountId($array);
|
$this->asset->setAccountId($array);
|
||||||
break;
|
break;
|
||||||
case 'amount':
|
case 'amount':
|
||||||
$this->amount = $array['value'];
|
$this->amount = $array;
|
||||||
|
break;
|
||||||
|
case 'amount_debet':
|
||||||
|
$this->amountDebet = $array;
|
||||||
|
break;
|
||||||
|
case 'amount_credit':
|
||||||
|
$this->amountCredit = $array;
|
||||||
break;
|
break;
|
||||||
case 'account-iban':
|
case 'account-iban':
|
||||||
$this->asset->setAccountIban($array);
|
$this->asset->setAccountIban($array);
|
||||||
|
@ -168,7 +168,7 @@ class CurrencyRepository implements CurrencyRepositoryInterface
|
|||||||
*/
|
*/
|
||||||
public function get(): Collection
|
public function get(): Collection
|
||||||
{
|
{
|
||||||
return TransactionCurrency::get();
|
return TransactionCurrency::orderBy('code', 'ASC')->get();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -178,7 +178,7 @@ class CurrencyRepository implements CurrencyRepositoryInterface
|
|||||||
*/
|
*/
|
||||||
public function getByIds(array $ids): Collection
|
public function getByIds(array $ids): Collection
|
||||||
{
|
{
|
||||||
return TransactionCurrency::whereIn('id', $ids)->get();
|
return TransactionCurrency::orderBy('code', 'ASC')->whereIn('id', $ids)->get();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -351,7 +351,7 @@ class TagRepository implements TagRepositoryInterface
|
|||||||
$tagsWithAmounts[$tag->id] = strval($tag->amount_sum);
|
$tagsWithAmounts[$tag->id] = strval($tag->amount_sum);
|
||||||
}
|
}
|
||||||
|
|
||||||
$tags = $query->orderBy('tags.id', 'desc')->get(['tags.id', 'tags.tag']);
|
$tags = $allTags->orderBy('tags.id', 'desc')->get(['tags.id', 'tags.tag']);
|
||||||
$temporary = [];
|
$temporary = [];
|
||||||
/** @var Tag $tag */
|
/** @var Tag $tag */
|
||||||
foreach ($tags as $tag) {
|
foreach ($tags as $tag) {
|
||||||
@ -364,13 +364,17 @@ class TagRepository implements TagRepositoryInterface
|
|||||||
|
|
||||||
$temporary[] = [
|
$temporary[] = [
|
||||||
'amount' => $amount,
|
'amount' => $amount,
|
||||||
'tag' => $tag,
|
'tag' => [
|
||||||
|
'id' => $tag->id,
|
||||||
|
'tag' => $tag->tag,
|
||||||
|
],
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
/** @var array $entry */
|
/** @var array $entry */
|
||||||
foreach ($temporary as $entry) {
|
foreach ($temporary as $entry) {
|
||||||
$scale = $this->cloudScale([12, 20], floatval($entry['amount']), floatval($min), floatval($max));
|
$scale = $this->cloudScale([12, 20], floatval($entry['amount']), floatval($min), floatval($max));
|
||||||
$tagId = $entry['tag']->id;
|
$tagId = $entry['tag']['id'];
|
||||||
$return[$tagId] = [
|
$return[$tagId] = [
|
||||||
'scale' => $scale,
|
'scale' => $scale,
|
||||||
'tag' => $entry['tag'],
|
'tag' => $entry['tag'],
|
||||||
|
@ -258,7 +258,7 @@ class Roles implements ConfigurationInterface
|
|||||||
if ('_ignore' !== $role) {
|
if ('_ignore' !== $role) {
|
||||||
++$assigned;
|
++$assigned;
|
||||||
}
|
}
|
||||||
if ('amount' === $role) {
|
if (in_array($role, ['amount','amount_credit','amount_debet'])) {
|
||||||
$hasAmount = true;
|
$hasAmount = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -280,6 +280,18 @@ return [
|
|||||||
'converter' => 'Amount',
|
'converter' => 'Amount',
|
||||||
'field' => 'amount',
|
'field' => 'amount',
|
||||||
],
|
],
|
||||||
|
'amount_debet' => [
|
||||||
|
'mappable' => false,
|
||||||
|
'pre-process-map' => false,
|
||||||
|
'converter' => 'AmountDebet',
|
||||||
|
'field' => 'amount_debet',
|
||||||
|
],
|
||||||
|
'amount_credit' => [
|
||||||
|
'mappable' => false,
|
||||||
|
'pre-process-map' => false,
|
||||||
|
'converter' => 'AmountCredit',
|
||||||
|
'field' => 'amount_credit',
|
||||||
|
],
|
||||||
'sepa-ct-id' => [
|
'sepa-ct-id' => [
|
||||||
'mappable' => false,
|
'mappable' => false,
|
||||||
'pre-process-map' => false,
|
'pre-process-map' => false,
|
||||||
|
@ -51,6 +51,8 @@ return [
|
|||||||
'column_account-id' => 'Asset account ID (matching Firefly)',
|
'column_account-id' => 'Asset account ID (matching Firefly)',
|
||||||
'column_account-name' => 'Asset account (name)',
|
'column_account-name' => 'Asset account (name)',
|
||||||
'column_amount' => 'Amount',
|
'column_amount' => 'Amount',
|
||||||
|
'column_amount_debet' => 'Amount (debet column)',
|
||||||
|
'column_amount_credit' => 'Amount (credit column)',
|
||||||
'column_amount-comma-separated' => 'Amount (comma as decimal separator)',
|
'column_amount-comma-separated' => 'Amount (comma as decimal separator)',
|
||||||
'column_bill-id' => 'Bill ID (matching Firefly)',
|
'column_bill-id' => 'Bill ID (matching Firefly)',
|
||||||
'column_bill-name' => 'Bill name',
|
'column_bill-name' => 'Bill name',
|
||||||
|
Loading…
Reference in New Issue
Block a user