mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-02-25 18:45:27 -06:00
Final changes.
This commit is contained in:
parent
3d49d81856
commit
68b446db18
@ -73,8 +73,9 @@ class CategoryController extends Controller
|
|||||||
$cache = new CacheProperties();
|
$cache = new CacheProperties();
|
||||||
$cache->addProperty('chart.category.all');
|
$cache->addProperty('chart.category.all');
|
||||||
$cache->addProperty($category->id);
|
$cache->addProperty($category->id);
|
||||||
|
$cache->addProperty($this->convertToNative);
|
||||||
if ($cache->has()) {
|
if ($cache->has()) {
|
||||||
return response()->json($cache->get());
|
// return response()->json($cache->get());
|
||||||
}
|
}
|
||||||
|
|
||||||
/** @var CategoryRepositoryInterface $repository */
|
/** @var CategoryRepositoryInterface $repository */
|
||||||
@ -86,6 +87,8 @@ class CategoryController extends Controller
|
|||||||
|
|
||||||
/** @var WholePeriodChartGenerator $chartGenerator */
|
/** @var WholePeriodChartGenerator $chartGenerator */
|
||||||
$chartGenerator = app(WholePeriodChartGenerator::class);
|
$chartGenerator = app(WholePeriodChartGenerator::class);
|
||||||
|
$chartGenerator->convertToNative = $this->convertToNative;
|
||||||
|
|
||||||
$chartData = $chartGenerator->generate($category, $start, $end);
|
$chartData = $chartGenerator->generate($category, $start, $end);
|
||||||
$data = $this->generator->multiSet($chartData);
|
$data = $this->generator->multiSet($chartData);
|
||||||
$cache->store($data);
|
$cache->store($data);
|
||||||
@ -136,8 +139,9 @@ class CategoryController extends Controller
|
|||||||
$cache->addProperty('chart.category.period');
|
$cache->addProperty('chart.category.period');
|
||||||
$cache->addProperty($accounts->pluck('id')->toArray());
|
$cache->addProperty($accounts->pluck('id')->toArray());
|
||||||
$cache->addProperty($category);
|
$cache->addProperty($category);
|
||||||
|
$cache->addProperty($this->convertToNative);
|
||||||
if ($cache->has()) {
|
if ($cache->has()) {
|
||||||
return response()->json($cache->get());
|
// return response()->json($cache->get());
|
||||||
}
|
}
|
||||||
$data = $this->reportPeriodChart($accounts, $start, $end, $category);
|
$data = $this->reportPeriodChart($accounts, $start, $end, $category);
|
||||||
|
|
||||||
|
@ -76,6 +76,10 @@ class DebugController extends Controller
|
|||||||
|| str_starts_with($route->uri(), '_debugbar')
|
|| str_starts_with($route->uri(), '_debugbar')
|
||||||
|| str_starts_with($route->uri(), '_ignition')
|
|| str_starts_with($route->uri(), '_ignition')
|
||||||
|| str_starts_with($route->uri(), 'oauth')
|
|| str_starts_with($route->uri(), 'oauth')
|
||||||
|
|| str_starts_with($route->uri(), 'chart')
|
||||||
|
|| str_starts_with($route->uri(), 'v1/jscript')
|
||||||
|
|| str_starts_with($route->uri(), 'v2/jscript')
|
||||||
|
|| str_starts_with($route->uri(), 'json')
|
||||||
|| str_starts_with($route->uri(), 'sanctum')
|
|| str_starts_with($route->uri(), 'sanctum')
|
||||||
) {
|
) {
|
||||||
continue;
|
continue;
|
||||||
|
@ -112,7 +112,7 @@ class OperationsRepository implements OperationsRepositoryInterface
|
|||||||
return $array;
|
return $array;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function setUser(null|Authenticatable|User $user): void
|
public function setUser(null | Authenticatable | User $user): void
|
||||||
{
|
{
|
||||||
if ($user instanceof User) {
|
if ($user instanceof User) {
|
||||||
$this->user = $user;
|
$this->user = $user;
|
||||||
@ -200,8 +200,7 @@ class OperationsRepository implements OperationsRepositoryInterface
|
|||||||
/** @var GroupCollectorInterface $collector */
|
/** @var GroupCollectorInterface $collector */
|
||||||
$collector = app(GroupCollectorInterface::class);
|
$collector = app(GroupCollectorInterface::class);
|
||||||
$collector->setUser($this->user)->setRange($start, $end)->setTypes([TransactionType::TRANSFER])
|
$collector->setUser($this->user)->setRange($start, $end)->setTypes([TransactionType::TRANSFER])
|
||||||
->setDestinationAccounts($accounts)->excludeSourceAccounts($accounts)
|
->setDestinationAccounts($accounts)->excludeSourceAccounts($accounts);
|
||||||
;
|
|
||||||
if (null !== $categories && $categories->count() > 0) {
|
if (null !== $categories && $categories->count() > 0) {
|
||||||
$collector->setCategories($categories);
|
$collector->setCategories($categories);
|
||||||
}
|
}
|
||||||
@ -263,8 +262,7 @@ class OperationsRepository implements OperationsRepositoryInterface
|
|||||||
/** @var GroupCollectorInterface $collector */
|
/** @var GroupCollectorInterface $collector */
|
||||||
$collector = app(GroupCollectorInterface::class);
|
$collector = app(GroupCollectorInterface::class);
|
||||||
$collector->setUser($this->user)->setRange($start, $end)->setTypes([TransactionType::TRANSFER])
|
$collector->setUser($this->user)->setRange($start, $end)->setTypes([TransactionType::TRANSFER])
|
||||||
->setSourceAccounts($accounts)->excludeDestinationAccounts($accounts)
|
->setSourceAccounts($accounts)->excludeDestinationAccounts($accounts);
|
||||||
;
|
|
||||||
if (null !== $categories && $categories->count() > 0) {
|
if (null !== $categories && $categories->count() > 0) {
|
||||||
$collector->setCategories($categories);
|
$collector->setCategories($categories);
|
||||||
}
|
}
|
||||||
@ -355,15 +353,21 @@ class OperationsRepository implements OperationsRepositoryInterface
|
|||||||
$currencyCode = $journal['currency_code'];
|
$currencyCode = $journal['currency_code'];
|
||||||
$currencyDecimalPlaces = $journal['currency_decimal_places'];
|
$currencyDecimalPlaces = $journal['currency_decimal_places'];
|
||||||
if ($convertToNative) {
|
if ($convertToNative) {
|
||||||
$useNative = $default->id !== (int) $journal['currency_id'];
|
|
||||||
$amount = Amount::getAmountFromJournal($journal);
|
$amount = Amount::getAmountFromJournal($journal);
|
||||||
if ($useNative) {
|
if ($default->id !== (int) $journal['currency_id'] && $default->id !== (int) $journal['foreign_currency_id']) {
|
||||||
$currencyId = $default->id;
|
$currencyId = $default->id;
|
||||||
$currencyName = $default->name;
|
$currencyName = $default->name;
|
||||||
$currencySymbol = $default->symbol;
|
$currencySymbol = $default->symbol;
|
||||||
$currencyCode = $default->code;
|
$currencyCode = $default->code;
|
||||||
$currencyDecimalPlaces = $default->decimal_places;
|
$currencyDecimalPlaces = $default->decimal_places;
|
||||||
}
|
}
|
||||||
|
if ($default->id !== (int) $journal['currency_id'] && $default->id === (int) $journal['foreign_currency_id']) {
|
||||||
|
$currencyId = $journal['foreign_currency_id'];
|
||||||
|
$currencyName = $journal['foreign_currency_name'];
|
||||||
|
$currencySymbol = $journal['foreign_currency_symbol'];
|
||||||
|
$currencyCode = $journal['foreign_currency_code'];
|
||||||
|
$currencyDecimalPlaces = $journal['foreign_currency_decimal_places'];
|
||||||
|
}
|
||||||
Log::debug(sprintf('[a] Add amount %s %s', $currencyCode, $amount));
|
Log::debug(sprintf('[a] Add amount %s %s', $currencyCode, $amount));
|
||||||
}
|
}
|
||||||
if (!$convertToNative) {
|
if (!$convertToNative) {
|
||||||
@ -372,7 +376,6 @@ class OperationsRepository implements OperationsRepositoryInterface
|
|||||||
$amount = $journal['amount'];
|
$amount = $journal['amount'];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
$array[$currencyId] ??= [
|
$array[$currencyId] ??= [
|
||||||
'sum' => '0',
|
'sum' => '0',
|
||||||
'currency_id' => (string) $currencyId,
|
'currency_id' => (string) $currencyId,
|
||||||
@ -395,8 +398,7 @@ class OperationsRepository implements OperationsRepositoryInterface
|
|||||||
/** @var GroupCollectorInterface $collector */
|
/** @var GroupCollectorInterface $collector */
|
||||||
$collector = app(GroupCollectorInterface::class);
|
$collector = app(GroupCollectorInterface::class);
|
||||||
$collector->setUser($this->user)->setRange($start, $end)
|
$collector->setUser($this->user)->setRange($start, $end)
|
||||||
->setTypes([TransactionType::DEPOSIT])
|
->setTypes([TransactionTypeEnum::DEPOSIT->value]);
|
||||||
;
|
|
||||||
|
|
||||||
if (null !== $accounts && $accounts->count() > 0) {
|
if (null !== $accounts && $accounts->count() > 0) {
|
||||||
$collector->setAccounts($accounts);
|
$collector->setAccounts($accounts);
|
||||||
@ -406,19 +408,51 @@ class OperationsRepository implements OperationsRepositoryInterface
|
|||||||
}
|
}
|
||||||
$collector->setCategories($categories);
|
$collector->setCategories($categories);
|
||||||
$journals = $collector->getExtractedJournals();
|
$journals = $collector->getExtractedJournals();
|
||||||
|
$convertToNative = app('preferences')->get('convert_to_native', false)->data;
|
||||||
|
$default = app('amount')->getDefaultCurrency();
|
||||||
$array = [];
|
$array = [];
|
||||||
|
|
||||||
foreach ($journals as $journal) {
|
foreach ($journals as $journal) {
|
||||||
|
// Almost the same as in \FireflyIII\Repositories\Budget\OperationsRepository::sumExpenses
|
||||||
|
$amount = '0';
|
||||||
$currencyId = (int) $journal['currency_id'];
|
$currencyId = (int) $journal['currency_id'];
|
||||||
|
$currencyName = $journal['currency_name'];
|
||||||
|
$currencySymbol = $journal['currency_symbol'];
|
||||||
|
$currencyCode = $journal['currency_code'];
|
||||||
|
$currencyDecimalPlaces = $journal['currency_decimal_places'];
|
||||||
|
if ($convertToNative) {
|
||||||
|
$amount = Amount::getAmountFromJournal($journal);
|
||||||
|
if ($default->id !== (int) $journal['currency_id'] && $default->id !== (int) $journal['foreign_currency_id']) {
|
||||||
|
$currencyId = $default->id;
|
||||||
|
$currencyName = $default->name;
|
||||||
|
$currencySymbol = $default->symbol;
|
||||||
|
$currencyCode = $default->code;
|
||||||
|
$currencyDecimalPlaces = $default->decimal_places;
|
||||||
|
}
|
||||||
|
if ($default->id !== (int) $journal['currency_id'] && $default->id === (int) $journal['foreign_currency_id']) {
|
||||||
|
$currencyId = $journal['foreign_currency_id'];
|
||||||
|
$currencyName = $journal['foreign_currency_name'];
|
||||||
|
$currencySymbol = $journal['foreign_currency_symbol'];
|
||||||
|
$currencyCode = $journal['foreign_currency_code'];
|
||||||
|
$currencyDecimalPlaces = $journal['foreign_currency_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] ??= [
|
$array[$currencyId] ??= [
|
||||||
'sum' => '0',
|
'sum' => '0',
|
||||||
'currency_id' => (string) $currencyId,
|
'currency_id' => (string) $currencyId,
|
||||||
'currency_name' => $journal['currency_name'],
|
'currency_name' => $currencyName,
|
||||||
'currency_symbol' => $journal['currency_symbol'],
|
'currency_symbol' => $currencySymbol,
|
||||||
'currency_code' => $journal['currency_code'],
|
'currency_code' => $currencyCode,
|
||||||
'currency_decimal_places' => $journal['currency_decimal_places'],
|
'currency_decimal_places' => $currencyDecimalPlaces,
|
||||||
];
|
];
|
||||||
$array[$currencyId]['sum'] = bcadd($array[$currencyId]['sum'], app('steam')->positive($journal['amount']));
|
$array[$currencyId]['sum'] = bcadd($array[$currencyId]['sum'], app('steam')->positive($amount));
|
||||||
}
|
}
|
||||||
|
|
||||||
return $array;
|
return $array;
|
||||||
@ -432,8 +466,7 @@ class OperationsRepository implements OperationsRepositoryInterface
|
|||||||
/** @var GroupCollectorInterface $collector */
|
/** @var GroupCollectorInterface $collector */
|
||||||
$collector = app(GroupCollectorInterface::class);
|
$collector = app(GroupCollectorInterface::class);
|
||||||
$collector->setUser($this->user)->setRange($start, $end)
|
$collector->setUser($this->user)->setRange($start, $end)
|
||||||
->setTypes([TransactionType::TRANSFER])
|
->setTypes([TransactionType::TRANSFER]);
|
||||||
;
|
|
||||||
|
|
||||||
if (null !== $accounts && $accounts->count() > 0) {
|
if (null !== $accounts && $accounts->count() > 0) {
|
||||||
$collector->setAccounts($accounts);
|
$collector->setAccounts($accounts);
|
||||||
|
@ -25,6 +25,7 @@ declare(strict_types=1);
|
|||||||
namespace FireflyIII\Support\Chart\Category;
|
namespace FireflyIII\Support\Chart\Category;
|
||||||
|
|
||||||
use Carbon\Carbon;
|
use Carbon\Carbon;
|
||||||
|
use FireflyIII\Enums\AccountTypeEnum;
|
||||||
use FireflyIII\Models\AccountType;
|
use FireflyIII\Models\AccountType;
|
||||||
use FireflyIII\Models\Category;
|
use FireflyIII\Models\Category;
|
||||||
use FireflyIII\Repositories\Account\AccountRepositoryInterface;
|
use FireflyIII\Repositories\Account\AccountRepositoryInterface;
|
||||||
@ -36,6 +37,8 @@ use Illuminate\Support\Collection;
|
|||||||
*/
|
*/
|
||||||
class WholePeriodChartGenerator
|
class WholePeriodChartGenerator
|
||||||
{
|
{
|
||||||
|
public bool $convertToNative;
|
||||||
|
|
||||||
public function generate(Category $category, Carbon $start, Carbon $end): array
|
public function generate(Category $category, Carbon $start, Carbon $end): array
|
||||||
{
|
{
|
||||||
$collection = new Collection([$category]);
|
$collection = new Collection([$category]);
|
||||||
@ -46,7 +49,7 @@ class WholePeriodChartGenerator
|
|||||||
/** @var AccountRepositoryInterface $accountRepository */
|
/** @var AccountRepositoryInterface $accountRepository */
|
||||||
$accountRepository = app(AccountRepositoryInterface::class);
|
$accountRepository = app(AccountRepositoryInterface::class);
|
||||||
|
|
||||||
$types = [AccountType::DEFAULT, AccountType::ASSET, AccountType::LOAN, AccountType::DEBT, AccountType::MORTGAGE];
|
$types = [AccountTypeEnum::DEFAULT->value, AccountTypeEnum::ASSET->value, AccountTypeEnum::LOAN->value, AccountTypeEnum::DEBT->value, AccountTypeEnum::MORTGAGE->value];
|
||||||
$accounts = $accountRepository->getAccountsByType($types);
|
$accounts = $accountRepository->getAccountsByType($types);
|
||||||
$step = $this->calculateStep($start, $end);
|
$step = $this->calculateStep($start, $end);
|
||||||
$chartData = [];
|
$chartData = [];
|
||||||
|
Loading…
Reference in New Issue
Block a user