mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-02-25 18:45:27 -06:00
Small code cleanup.
This commit is contained in:
parent
fb73baca6a
commit
4c2d9e0eee
2
.github/CONTRIBUTING.md
vendored
2
.github/CONTRIBUTING.md
vendored
@ -16,4 +16,4 @@ Take the time to read the [installation guide FAQ](https://firefly-iii.github.io
|
|||||||
|
|
||||||
## Pull requests
|
## Pull requests
|
||||||
|
|
||||||
I can only accept pull requests against the `develop` branch, never the `master` branch
|
I can only accept pull requests against the `develop` branch, never the `master` branch.
|
||||||
|
@ -14,6 +14,7 @@ declare(strict_types = 1);
|
|||||||
namespace FireflyIII\Generator\Chart\Basic;
|
namespace FireflyIII\Generator\Chart\Basic;
|
||||||
|
|
||||||
use FireflyIII\Support\ChartColour;
|
use FireflyIII\Support\ChartColour;
|
||||||
|
use Steam;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class ChartJsGenerator
|
* Class ChartJsGenerator
|
||||||
@ -108,11 +109,7 @@ class ChartJsGenerator implements GeneratorInterface
|
|||||||
foreach ($data as $key => $value) {
|
foreach ($data as $key => $value) {
|
||||||
|
|
||||||
// make larger than 0
|
// make larger than 0
|
||||||
if (bccomp($value, '0') === -1) {
|
$chartData['datasets'][0]['data'][] = floatval(Steam::positive($value));
|
||||||
$value = bcmul($value, '-1');
|
|
||||||
}
|
|
||||||
|
|
||||||
$chartData['datasets'][0]['data'][] = $value;
|
|
||||||
$chartData['datasets'][0]['backgroundColor'][] = ChartColour::getColour($index);
|
$chartData['datasets'][0]['backgroundColor'][] = ChartColour::getColour($index);
|
||||||
$chartData['labels'][] = $key;
|
$chartData['labels'][] = $key;
|
||||||
$index++;
|
$index++;
|
||||||
|
@ -21,6 +21,7 @@ use FireflyIII\Repositories\Budget\BudgetRepositoryInterface;
|
|||||||
use FireflyIII\Repositories\Category\CategoryRepositoryInterface;
|
use FireflyIII\Repositories\Category\CategoryRepositoryInterface;
|
||||||
use FireflyIII\User;
|
use FireflyIII\User;
|
||||||
use Illuminate\Support\Collection;
|
use Illuminate\Support\Collection;
|
||||||
|
use Steam;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class MetaPieChart
|
* Class MetaPieChart
|
||||||
@ -268,10 +269,7 @@ class MetaPieChart implements MetaPieChartInterface
|
|||||||
$object = $repository->find(intval($objectId));
|
$object = $repository->find(intval($objectId));
|
||||||
$names[$objectId] = $object->name;
|
$names[$objectId] = $object->name;
|
||||||
}
|
}
|
||||||
if (bccomp($amount, '0') === -1) {
|
$amount = Steam::positive($amount);
|
||||||
$amount = bcmul($amount, '-1');
|
|
||||||
}
|
|
||||||
|
|
||||||
$this->total = bcadd($this->total, $amount);
|
$this->total = bcadd($this->total, $amount);
|
||||||
$chartData[$names[$objectId]] = $amount;
|
$chartData[$names[$objectId]] = $amount;
|
||||||
}
|
}
|
||||||
|
@ -27,6 +27,7 @@ use FireflyIII\Rules\Processor;
|
|||||||
use FireflyIII\User;
|
use FireflyIII\User;
|
||||||
use Illuminate\Support\Collection;
|
use Illuminate\Support\Collection;
|
||||||
use Log;
|
use Log;
|
||||||
|
use Steam;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class ImportStorage
|
* Class ImportStorage
|
||||||
@ -197,21 +198,6 @@ class ImportStorage
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @param float $amount
|
|
||||||
*
|
|
||||||
* @return string
|
|
||||||
*/
|
|
||||||
private function makePositive(float $amount): string
|
|
||||||
{
|
|
||||||
$amount = strval($amount);
|
|
||||||
if (bccomp($amount, '0', 4) === -1) { // left is larger than right
|
|
||||||
$amount = bcmul($amount, '-1');
|
|
||||||
}
|
|
||||||
|
|
||||||
return $amount;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param $entry
|
* @param $entry
|
||||||
*
|
*
|
||||||
@ -370,7 +356,7 @@ class ImportStorage
|
|||||||
|
|
||||||
|
|
||||||
$journal = $this->storeJournal($entry);
|
$journal = $this->storeJournal($entry);
|
||||||
$amount = $this->makePositive($entry->fields['amount']);
|
$amount = Steam::positive($entry->fields['amount']);
|
||||||
$accounts = $this->storeAccounts($entry);
|
$accounts = $this->storeAccounts($entry);
|
||||||
|
|
||||||
// create new transactions. This is something that needs a rewrite for multiple/split transactions.
|
// create new transactions. This is something that needs a rewrite for multiple/split transactions.
|
||||||
|
@ -60,7 +60,7 @@ final class AmountExactly extends AbstractTrigger implements TriggerInterface
|
|||||||
{
|
{
|
||||||
$amount = $journal->destination_amount ?? TransactionJournal::amountPositive($journal);
|
$amount = $journal->destination_amount ?? TransactionJournal::amountPositive($journal);
|
||||||
$compare = $this->triggerValue;
|
$compare = $this->triggerValue;
|
||||||
$result = bccomp($amount, $compare, 4);
|
$result = bccomp($amount, $compare);
|
||||||
if ($result === 0) {
|
if ($result === 0) {
|
||||||
Log::debug(sprintf('RuleTrigger AmountExactly for journal #%d: %d matches %d exactly, so return true', $journal->id, $amount, $compare));
|
Log::debug(sprintf('RuleTrigger AmountExactly for journal #%d: %d matches %d exactly, so return true', $journal->id, $amount, $compare));
|
||||||
|
|
||||||
|
@ -60,7 +60,7 @@ final class AmountLess extends AbstractTrigger implements TriggerInterface
|
|||||||
{
|
{
|
||||||
$amount = $journal->destination_amount ?? TransactionJournal::amountPositive($journal);
|
$amount = $journal->destination_amount ?? TransactionJournal::amountPositive($journal);
|
||||||
$compare = $this->triggerValue;
|
$compare = $this->triggerValue;
|
||||||
$result = bccomp($amount, $compare, 4);
|
$result = bccomp($amount, $compare);
|
||||||
if ($result === -1) {
|
if ($result === -1) {
|
||||||
Log::debug(sprintf('RuleTrigger AmountLess for journal #%d: %d is less than %d, so return true', $journal->id, $amount, $compare));
|
Log::debug(sprintf('RuleTrigger AmountLess for journal #%d: %d is less than %d, so return true', $journal->id, $amount, $compare));
|
||||||
|
|
||||||
|
@ -66,7 +66,7 @@ final class AmountMore extends AbstractTrigger implements TriggerInterface
|
|||||||
{
|
{
|
||||||
$amount = $journal->destination_amount ?? TransactionJournal::amountPositive($journal);
|
$amount = $journal->destination_amount ?? TransactionJournal::amountPositive($journal);
|
||||||
$compare = $this->triggerValue;
|
$compare = $this->triggerValue;
|
||||||
$result = bccomp($amount, $compare, 4);
|
$result = bccomp($amount, $compare);
|
||||||
if ($result === 1) {
|
if ($result === 1) {
|
||||||
Log::debug(sprintf('RuleTrigger AmountMore for journal #%d: %d is more than %d, so return true', $journal->id, $amount, $compare));
|
Log::debug(sprintf('RuleTrigger AmountMore for journal #%d: %d is more than %d, so return true', $journal->id, $amount, $compare));
|
||||||
|
|
||||||
|
@ -245,7 +245,7 @@ class Steam
|
|||||||
*/
|
*/
|
||||||
public function positive(string $amount): string
|
public function positive(string $amount): string
|
||||||
{
|
{
|
||||||
if (bccomp($amount, '0') === 1) {
|
if (bccomp($amount, '0') === -1) {
|
||||||
$amount = bcmul($amount, '-1');
|
$amount = bcmul($amount, '-1');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user