mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-10-22 20:16:22 +00:00
Convert more charts.
This commit is contained in:
@@ -27,9 +27,11 @@ namespace FireflyIII\Repositories\Category;
|
||||
use Carbon\Carbon;
|
||||
use FireflyIII\Helpers\Collector\GroupCollectorInterface;
|
||||
use FireflyIII\Models\TransactionType;
|
||||
use FireflyIII\Support\Facades\Amount;
|
||||
use FireflyIII\User;
|
||||
use Illuminate\Contracts\Auth\Authenticatable;
|
||||
use Illuminate\Support\Collection;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
|
||||
/**
|
||||
* Class NoCategoryRepository
|
||||
@@ -151,18 +153,46 @@ class NoCategoryRepository implements NoCategoryRepositoryInterface
|
||||
}
|
||||
$journals = $collector->getExtractedJournals();
|
||||
$array = [];
|
||||
// default currency information for native stuff.
|
||||
$convertToNative = app('preferences')->get('convert_to_native', false)->data;
|
||||
$default = app('amount')->getDefaultCurrency();
|
||||
|
||||
foreach ($journals as $journal) {
|
||||
$currencyId = (int) $journal['currency_id'];
|
||||
$array[$currencyId] ??= [
|
||||
// Almost the same as in \FireflyIII\Repositories\Budget\OperationsRepository::sumExpenses
|
||||
$amount = '0';
|
||||
$currencyId = (int) $journal['currency_id'];
|
||||
$currencyName = $journal['currency_name'];
|
||||
$currencySymbol = $journal['currency_symbol'];
|
||||
$currencyCode = $journal['currency_code'];
|
||||
$currencyDecimalPlaces = $journal['currency_decimal_places'];
|
||||
if ($convertToNative) {
|
||||
$useNative = $default->id !== (int) $journal['currency_id'];
|
||||
$amount = Amount::getAmountFromJournal($journal);
|
||||
if ($useNative) {
|
||||
$currencyId = $default->id;
|
||||
$currencyName = $default->name;
|
||||
$currencySymbol = $default->symbol;
|
||||
$currencyCode = $default->code;
|
||||
$currencyDecimalPlaces = $default->decimal_places;
|
||||
}
|
||||
Log::debug(sprintf('[a] Add amount %s %s', $currencyCode, $amount));
|
||||
}
|
||||
if (!$convertToNative) {
|
||||
// ignore the amount in foreign currency.
|
||||
Log::debug(sprintf('[b] Add amount %s %s', $currencyCode, $journal['amount']));
|
||||
$amount = $journal['amount'];
|
||||
}
|
||||
|
||||
|
||||
$array[$currencyId] ??= [
|
||||
'sum' => '0',
|
||||
'currency_id' => $currencyId,
|
||||
'currency_name' => $journal['currency_name'],
|
||||
'currency_symbol' => $journal['currency_symbol'],
|
||||
'currency_code' => $journal['currency_code'],
|
||||
'currency_decimal_places' => $journal['currency_decimal_places'],
|
||||
'currency_id' => (string) $currencyId,
|
||||
'currency_name' => $currencyName,
|
||||
'currency_symbol' => $currencySymbol,
|
||||
'currency_code' => $currencyCode,
|
||||
'currency_decimal_places' => $currencyDecimalPlaces,
|
||||
];
|
||||
$array[$currencyId]['sum'] = bcadd($array[$currencyId]['sum'], app('steam')->negative($journal['amount'] ?? '0'));
|
||||
$array[$currencyId]['sum'] = bcadd($array[$currencyId]['sum'], app('steam')->negative($amount));
|
||||
}
|
||||
|
||||
return $array;
|
||||
|
@@ -25,11 +25,14 @@ declare(strict_types=1);
|
||||
namespace FireflyIII\Repositories\Category;
|
||||
|
||||
use Carbon\Carbon;
|
||||
use FireflyIII\Enums\TransactionTypeEnum;
|
||||
use FireflyIII\Helpers\Collector\GroupCollectorInterface;
|
||||
use FireflyIII\Models\TransactionType;
|
||||
use FireflyIII\Support\Facades\Amount;
|
||||
use FireflyIII\User;
|
||||
use Illuminate\Contracts\Auth\Authenticatable;
|
||||
use Illuminate\Support\Collection;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
|
||||
/**
|
||||
* Class OperationsRepository
|
||||
@@ -60,13 +63,13 @@ class OperationsRepository implements OperationsRepositoryInterface
|
||||
$collector->setCategories($this->getCategories());
|
||||
}
|
||||
$collector->withCategoryInformation()->withAccountInformation()->withBudgetInformation();
|
||||
$journals = $collector->getExtractedJournals();
|
||||
$array = [];
|
||||
$journals = $collector->getExtractedJournals();
|
||||
$array = [];
|
||||
|
||||
foreach ($journals as $journal) {
|
||||
$currencyId = (int) $journal['currency_id'];
|
||||
$categoryId = (int) $journal['category_id'];
|
||||
$categoryName = (string) $journal['category_name'];
|
||||
$currencyId = (int) $journal['currency_id'];
|
||||
$categoryId = (int) $journal['category_id'];
|
||||
$categoryName = (string) $journal['category_name'];
|
||||
|
||||
// catch "no category" entries.
|
||||
if (0 === $categoryId) {
|
||||
@@ -74,7 +77,7 @@ class OperationsRepository implements OperationsRepositoryInterface
|
||||
}
|
||||
|
||||
// info about the currency:
|
||||
$array[$currencyId] ??= [
|
||||
$array[$currencyId] ??= [
|
||||
'categories' => [],
|
||||
'currency_id' => (string) $currencyId,
|
||||
'currency_name' => $journal['currency_name'],
|
||||
@@ -109,7 +112,7 @@ class OperationsRepository implements OperationsRepositoryInterface
|
||||
return $array;
|
||||
}
|
||||
|
||||
public function setUser(null|Authenticatable|User $user): void
|
||||
public function setUser(null | Authenticatable | User $user): void
|
||||
{
|
||||
if ($user instanceof User) {
|
||||
$this->user = $user;
|
||||
@@ -144,13 +147,13 @@ class OperationsRepository implements OperationsRepositoryInterface
|
||||
$collector->setCategories($this->getCategories());
|
||||
}
|
||||
$collector->withCategoryInformation()->withAccountInformation();
|
||||
$journals = $collector->getExtractedJournals();
|
||||
$array = [];
|
||||
$journals = $collector->getExtractedJournals();
|
||||
$array = [];
|
||||
|
||||
foreach ($journals as $journal) {
|
||||
$currencyId = (int) $journal['currency_id'];
|
||||
$categoryId = (int) $journal['category_id'];
|
||||
$categoryName = (string) $journal['category_name'];
|
||||
$currencyId = (int) $journal['currency_id'];
|
||||
$categoryId = (int) $journal['category_id'];
|
||||
$categoryName = (string) $journal['category_name'];
|
||||
|
||||
// catch "no category" entries.
|
||||
if (0 === $categoryId) {
|
||||
@@ -158,7 +161,7 @@ class OperationsRepository implements OperationsRepositoryInterface
|
||||
}
|
||||
|
||||
// info about the currency:
|
||||
$array[$currencyId] ??= [
|
||||
$array[$currencyId] ??= [
|
||||
'categories' => [],
|
||||
'currency_id' => (string) $currencyId,
|
||||
'currency_name' => $journal['currency_name'],
|
||||
@@ -197,8 +200,7 @@ class OperationsRepository implements OperationsRepositoryInterface
|
||||
/** @var GroupCollectorInterface $collector */
|
||||
$collector = app(GroupCollectorInterface::class);
|
||||
$collector->setUser($this->user)->setRange($start, $end)->setTypes([TransactionType::TRANSFER])
|
||||
->setDestinationAccounts($accounts)->excludeSourceAccounts($accounts)
|
||||
;
|
||||
->setDestinationAccounts($accounts)->excludeSourceAccounts($accounts);
|
||||
if (null !== $categories && $categories->count() > 0) {
|
||||
$collector->setCategories($categories);
|
||||
}
|
||||
@@ -206,13 +208,13 @@ class OperationsRepository implements OperationsRepositoryInterface
|
||||
$collector->setCategories($this->getCategories());
|
||||
}
|
||||
$collector->withCategoryInformation()->withAccountInformation()->withBudgetInformation();
|
||||
$journals = $collector->getExtractedJournals();
|
||||
$array = [];
|
||||
$journals = $collector->getExtractedJournals();
|
||||
$array = [];
|
||||
|
||||
foreach ($journals as $journal) {
|
||||
$currencyId = (int) $journal['currency_id'];
|
||||
$categoryId = (int) $journal['category_id'];
|
||||
$categoryName = (string) $journal['category_name'];
|
||||
$currencyId = (int) $journal['currency_id'];
|
||||
$categoryId = (int) $journal['category_id'];
|
||||
$categoryName = (string) $journal['category_name'];
|
||||
|
||||
// catch "no category" entries.
|
||||
if (0 === $categoryId) {
|
||||
@@ -220,7 +222,7 @@ class OperationsRepository implements OperationsRepositoryInterface
|
||||
}
|
||||
|
||||
// info about the currency:
|
||||
$array[$currencyId] ??= [
|
||||
$array[$currencyId] ??= [
|
||||
'categories' => [],
|
||||
'currency_id' => (string) $currencyId,
|
||||
'currency_name' => $journal['currency_name'],
|
||||
@@ -260,8 +262,7 @@ class OperationsRepository implements OperationsRepositoryInterface
|
||||
/** @var GroupCollectorInterface $collector */
|
||||
$collector = app(GroupCollectorInterface::class);
|
||||
$collector->setUser($this->user)->setRange($start, $end)->setTypes([TransactionType::TRANSFER])
|
||||
->setSourceAccounts($accounts)->excludeDestinationAccounts($accounts)
|
||||
;
|
||||
->setSourceAccounts($accounts)->excludeDestinationAccounts($accounts);
|
||||
if (null !== $categories && $categories->count() > 0) {
|
||||
$collector->setCategories($categories);
|
||||
}
|
||||
@@ -269,13 +270,13 @@ class OperationsRepository implements OperationsRepositoryInterface
|
||||
$collector->setCategories($this->getCategories());
|
||||
}
|
||||
$collector->withCategoryInformation()->withAccountInformation()->withBudgetInformation();
|
||||
$journals = $collector->getExtractedJournals();
|
||||
$array = [];
|
||||
$journals = $collector->getExtractedJournals();
|
||||
$array = [];
|
||||
|
||||
foreach ($journals as $journal) {
|
||||
$currencyId = (int) $journal['currency_id'];
|
||||
$categoryId = (int) $journal['category_id'];
|
||||
$categoryName = (string) $journal['category_name'];
|
||||
$currencyId = (int) $journal['currency_id'];
|
||||
$categoryId = (int) $journal['category_id'];
|
||||
$categoryName = (string) $journal['category_name'];
|
||||
|
||||
// catch "no category" entries.
|
||||
if (0 === $categoryId) {
|
||||
@@ -283,7 +284,7 @@ class OperationsRepository implements OperationsRepositoryInterface
|
||||
}
|
||||
|
||||
// info about the currency:
|
||||
$array[$currencyId] ??= [
|
||||
$array[$currencyId] ??= [
|
||||
'categories' => [],
|
||||
'currency_id' => (string) $currencyId,
|
||||
'currency_name' => $journal['currency_name'],
|
||||
@@ -325,10 +326,11 @@ class OperationsRepository implements OperationsRepositoryInterface
|
||||
{
|
||||
/** @var GroupCollectorInterface $collector */
|
||||
$collector = app(GroupCollectorInterface::class);
|
||||
$collector->setUser($this->user)->setRange($start, $end)
|
||||
->setTypes([TransactionType::WITHDRAWAL])
|
||||
;
|
||||
$collector->setUser($this->user)->setRange($start, $end)->setTypes([TransactionTypeEnum::WITHDRAWAL->value]);
|
||||
|
||||
// default currency information for native stuff.
|
||||
$convertToNative = app('preferences')->get('convert_to_native', false)->data;
|
||||
$default = app('amount')->getDefaultCurrency();
|
||||
if (null !== $accounts && $accounts->count() > 0) {
|
||||
$collector->setAccounts($accounts);
|
||||
}
|
||||
@@ -337,20 +339,47 @@ class OperationsRepository implements OperationsRepositoryInterface
|
||||
}
|
||||
$collector->setCategories($categories);
|
||||
$collector->withCategoryInformation();
|
||||
$journals = $collector->getExtractedJournals();
|
||||
$array = [];
|
||||
$journals = $collector->getExtractedJournals();
|
||||
$array = [];
|
||||
|
||||
Log::debug(sprintf('Collected %d journals', count($journals)));
|
||||
|
||||
foreach ($journals as $journal) {
|
||||
$currencyId = (int) $journal['currency_id'];
|
||||
$array[$currencyId] ??= [
|
||||
// Almost the same as in \FireflyIII\Repositories\Budget\OperationsRepository::sumExpenses
|
||||
$amount = '0';
|
||||
$currencyId = (int) $journal['currency_id'];
|
||||
$currencyName = $journal['currency_name'];
|
||||
$currencySymbol = $journal['currency_symbol'];
|
||||
$currencyCode = $journal['currency_code'];
|
||||
$currencyDecimalPlaces = $journal['currency_decimal_places'];
|
||||
if ($convertToNative) {
|
||||
$useNative = $default->id !== (int) $journal['currency_id'];
|
||||
$amount = Amount::getAmountFromJournal($journal);
|
||||
if ($useNative) {
|
||||
$currencyId = $default->id;
|
||||
$currencyName = $default->name;
|
||||
$currencySymbol = $default->symbol;
|
||||
$currencyCode = $default->code;
|
||||
$currencyDecimalPlaces = $default->decimal_places;
|
||||
}
|
||||
Log::debug(sprintf('[a] Add amount %s %s', $currencyCode, $amount));
|
||||
}
|
||||
if (!$convertToNative) {
|
||||
// ignore the amount in foreign currency.
|
||||
Log::debug(sprintf('[b] Add amount %s %s', $currencyCode, $journal['amount']));
|
||||
$amount = $journal['amount'];
|
||||
}
|
||||
|
||||
|
||||
$array[$currencyId] ??= [
|
||||
'sum' => '0',
|
||||
'currency_id' => (string) $currencyId,
|
||||
'currency_name' => $journal['currency_name'],
|
||||
'currency_symbol' => $journal['currency_symbol'],
|
||||
'currency_code' => $journal['currency_code'],
|
||||
'currency_decimal_places' => (int) $journal['currency_decimal_places'],
|
||||
'currency_name' => $currencyName,
|
||||
'currency_symbol' => $currencySymbol,
|
||||
'currency_code' => $currencyCode,
|
||||
'currency_decimal_places' => $currencyDecimalPlaces,
|
||||
];
|
||||
$array[$currencyId]['sum'] = bcadd($array[$currencyId]['sum'], app('steam')->negative($journal['amount']));
|
||||
$array[$currencyId]['sum'] = bcadd($array[$currencyId]['sum'], app('steam')->negative($amount));
|
||||
}
|
||||
|
||||
return $array;
|
||||
@@ -364,8 +393,7 @@ class OperationsRepository implements OperationsRepositoryInterface
|
||||
/** @var GroupCollectorInterface $collector */
|
||||
$collector = app(GroupCollectorInterface::class);
|
||||
$collector->setUser($this->user)->setRange($start, $end)
|
||||
->setTypes([TransactionType::DEPOSIT])
|
||||
;
|
||||
->setTypes([TransactionType::DEPOSIT]);
|
||||
|
||||
if (null !== $accounts && $accounts->count() > 0) {
|
||||
$collector->setAccounts($accounts);
|
||||
@@ -374,12 +402,12 @@ class OperationsRepository implements OperationsRepositoryInterface
|
||||
$categories = $this->getCategories();
|
||||
}
|
||||
$collector->setCategories($categories);
|
||||
$journals = $collector->getExtractedJournals();
|
||||
$array = [];
|
||||
$journals = $collector->getExtractedJournals();
|
||||
$array = [];
|
||||
|
||||
foreach ($journals as $journal) {
|
||||
$currencyId = (int) $journal['currency_id'];
|
||||
$array[$currencyId] ??= [
|
||||
$array[$currencyId] ??= [
|
||||
'sum' => '0',
|
||||
'currency_id' => (string) $currencyId,
|
||||
'currency_name' => $journal['currency_name'],
|
||||
@@ -401,8 +429,7 @@ class OperationsRepository implements OperationsRepositoryInterface
|
||||
/** @var GroupCollectorInterface $collector */
|
||||
$collector = app(GroupCollectorInterface::class);
|
||||
$collector->setUser($this->user)->setRange($start, $end)
|
||||
->setTypes([TransactionType::TRANSFER])
|
||||
;
|
||||
->setTypes([TransactionType::TRANSFER]);
|
||||
|
||||
if (null !== $accounts && $accounts->count() > 0) {
|
||||
$collector->setAccounts($accounts);
|
||||
@@ -411,12 +438,12 @@ class OperationsRepository implements OperationsRepositoryInterface
|
||||
$categories = $this->getCategories();
|
||||
}
|
||||
$collector->setCategories($categories);
|
||||
$journals = $collector->getExtractedJournals();
|
||||
$array = [];
|
||||
$journals = $collector->getExtractedJournals();
|
||||
$array = [];
|
||||
|
||||
foreach ($journals as $journal) {
|
||||
$currencyId = (int) $journal['currency_id'];
|
||||
$array[$currencyId] ??= [
|
||||
$array[$currencyId] ??= [
|
||||
'sum' => '0',
|
||||
'currency_id' => (string) $currencyId,
|
||||
'currency_name' => $journal['currency_name'],
|
||||
|
Reference in New Issue
Block a user