mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-09-04 19:53:44 +00:00
Various improvs to the report generator.
This commit is contained in:
@@ -210,10 +210,9 @@ class PopupReport implements PopupReportInterface
|
|||||||
|
|
||||||
// set report accounts + the request accounts:
|
// set report accounts + the request accounts:
|
||||||
//$set = $attributes['accounts'] ?? new Collection;
|
//$set = $attributes['accounts'] ?? new Collection;
|
||||||
$set = new Collection;
|
//$set->push($account);
|
||||||
$set->push($account);
|
|
||||||
|
|
||||||
$collector->setBothAccounts($set)
|
$collector->setDestinationAccounts(new Collection([$account]))
|
||||||
->setRange($attributes['startDate'], $attributes['endDate'])
|
->setRange($attributes['startDate'], $attributes['endDate'])
|
||||||
->withAccountInformation()
|
->withAccountInformation()
|
||||||
->withBudgetInformation()
|
->withBudgetInformation()
|
||||||
@@ -223,7 +222,6 @@ class PopupReport implements PopupReportInterface
|
|||||||
if (null !== $currency) {
|
if (null !== $currency) {
|
||||||
$collector->setCurrency($currency);
|
$collector->setCurrency($currency);
|
||||||
}
|
}
|
||||||
|
|
||||||
return $collector->getExtractedJournals();
|
return $collector->getExtractedJournals();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -59,7 +59,6 @@ class ReportController extends Controller
|
|||||||
'category-entry' => $this->categoryEntry($attributes),
|
'category-entry' => $this->categoryEntry($attributes),
|
||||||
'budget-entry' => $this->budgetEntry($attributes),
|
'budget-entry' => $this->budgetEntry($attributes),
|
||||||
};
|
};
|
||||||
|
|
||||||
return response()->json(['html' => $html]);
|
return response()->json(['html' => $html]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -648,10 +648,9 @@ class CategoryController extends Controller
|
|||||||
* @param Carbon $start
|
* @param Carbon $start
|
||||||
* @param Carbon $end
|
* @param Carbon $end
|
||||||
*
|
*
|
||||||
* @return mixed|string
|
* @return string
|
||||||
* @throws JsonException
|
|
||||||
*/
|
*/
|
||||||
public function operations(Collection $accounts, Carbon $start, Carbon $end)
|
public function operations(Collection $accounts, Carbon $start, Carbon $end): string
|
||||||
{
|
{
|
||||||
// chart properties for cache:
|
// chart properties for cache:
|
||||||
$cache = new CacheProperties;
|
$cache = new CacheProperties;
|
||||||
@@ -673,7 +672,7 @@ class CategoryController extends Controller
|
|||||||
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
$result = prefixView('reports.partials.categories', compact('report'))->render();
|
$result = (string)prefixView('reports.partials.categories', compact('report'))->render();
|
||||||
$cache->store($result);
|
$cache->store($result);
|
||||||
} catch (Throwable $e) { // @phpstan-ignore-line
|
} catch (Throwable $e) { // @phpstan-ignore-line
|
||||||
Log::error(sprintf('Could not render category::expenses: %s', $e->getMessage()));
|
Log::error(sprintf('Could not render category::expenses: %s', $e->getMessage()));
|
||||||
|
@@ -35,8 +35,7 @@ use Illuminate\Support\Collection;
|
|||||||
*/
|
*/
|
||||||
class OperationsRepository implements OperationsRepositoryInterface
|
class OperationsRepository implements OperationsRepositoryInterface
|
||||||
{
|
{
|
||||||
/** @var User */
|
private User $user;
|
||||||
private $user;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This method returns a list of all the withdrawal transaction journals (as arrays) set in that period
|
* This method returns a list of all the withdrawal transaction journals (as arrays) set in that period
|
||||||
@@ -340,4 +339,136 @@ class OperationsRepository implements OperationsRepositoryInterface
|
|||||||
{
|
{
|
||||||
return $this->user->categories()->get();
|
return $this->user->categories()->get();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @inheritDoc
|
||||||
|
*/
|
||||||
|
public function listTransferredIn(Carbon $start, Carbon $end, Collection $accounts, ?Collection $categories = null): array
|
||||||
|
{
|
||||||
|
/** @var GroupCollectorInterface $collector */
|
||||||
|
$collector = app(GroupCollectorInterface::class);
|
||||||
|
$collector->setUser($this->user)->setRange($start, $end)->setTypes([TransactionType::TRANSFER])
|
||||||
|
->setDestinationAccounts($accounts)->excludeSourceAccounts($accounts);
|
||||||
|
if (null !== $categories && $categories->count() > 0) {
|
||||||
|
$collector->setCategories($categories);
|
||||||
|
}
|
||||||
|
if (null === $categories || (null !== $categories && 0 === $categories->count())) {
|
||||||
|
$collector->setCategories($this->getCategories());
|
||||||
|
}
|
||||||
|
$collector->withCategoryInformation()->withAccountInformation()->withBudgetInformation();
|
||||||
|
$journals = $collector->getExtractedJournals();
|
||||||
|
$array = [];
|
||||||
|
|
||||||
|
foreach ($journals as $journal) {
|
||||||
|
$currencyId = (int)$journal['currency_id'];
|
||||||
|
$categoryId = (int)$journal['category_id'];
|
||||||
|
$categoryName = (string)$journal['category_name'];
|
||||||
|
|
||||||
|
// catch "no category" entries.
|
||||||
|
if (0 === $categoryId) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
// info about the currency:
|
||||||
|
$array[$currencyId] = $array[$currencyId] ?? [
|
||||||
|
'categories' => [],
|
||||||
|
'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'],
|
||||||
|
];
|
||||||
|
|
||||||
|
// info about the categories:
|
||||||
|
$array[$currencyId]['categories'][$categoryId] = $array[$currencyId]['categories'][$categoryId] ?? [
|
||||||
|
'id' => $categoryId,
|
||||||
|
'name' => $categoryName,
|
||||||
|
'transaction_journals' => [],
|
||||||
|
];
|
||||||
|
|
||||||
|
// add journal to array:
|
||||||
|
// only a subset of the fields.
|
||||||
|
$journalId = (int)$journal['transaction_journal_id'];
|
||||||
|
$array[$currencyId]['categories'][$categoryId]['transaction_journals'][$journalId] = [
|
||||||
|
'amount' => app('steam')->positive($journal['amount']),
|
||||||
|
'date' => $journal['date'],
|
||||||
|
'source_account_id' => $journal['source_account_id'],
|
||||||
|
'category_name' => $journal['category_name'],
|
||||||
|
'source_account_name' => $journal['source_account_name'],
|
||||||
|
'destination_account_id' => $journal['destination_account_id'],
|
||||||
|
'destination_account_name' => $journal['destination_account_name'],
|
||||||
|
'description' => $journal['description'],
|
||||||
|
'transaction_group_id' => $journal['transaction_group_id'],
|
||||||
|
];
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
return $array;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @inheritDoc
|
||||||
|
*/
|
||||||
|
public function listTransferredOut(Carbon $start, Carbon $end, Collection $accounts, ?Collection $categories = null): array
|
||||||
|
{
|
||||||
|
/** @var GroupCollectorInterface $collector */
|
||||||
|
$collector = app(GroupCollectorInterface::class);
|
||||||
|
$collector->setUser($this->user)->setRange($start, $end)->setTypes([TransactionType::TRANSFER])
|
||||||
|
->setSourceAccounts($accounts)->excludeDestinationAccounts($accounts);
|
||||||
|
if (null !== $categories && $categories->count() > 0) {
|
||||||
|
$collector->setCategories($categories);
|
||||||
|
}
|
||||||
|
if (null === $categories || (null !== $categories && 0 === $categories->count())) {
|
||||||
|
$collector->setCategories($this->getCategories());
|
||||||
|
}
|
||||||
|
$collector->withCategoryInformation()->withAccountInformation()->withBudgetInformation();
|
||||||
|
$journals = $collector->getExtractedJournals();
|
||||||
|
$array = [];
|
||||||
|
|
||||||
|
foreach ($journals as $journal) {
|
||||||
|
$currencyId = (int)$journal['currency_id'];
|
||||||
|
$categoryId = (int)$journal['category_id'];
|
||||||
|
$categoryName = (string)$journal['category_name'];
|
||||||
|
|
||||||
|
// catch "no category" entries.
|
||||||
|
if (0 === $categoryId) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
// info about the currency:
|
||||||
|
$array[$currencyId] = $array[$currencyId] ?? [
|
||||||
|
'categories' => [],
|
||||||
|
'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'],
|
||||||
|
];
|
||||||
|
|
||||||
|
// info about the categories:
|
||||||
|
$array[$currencyId]['categories'][$categoryId] = $array[$currencyId]['categories'][$categoryId] ?? [
|
||||||
|
'id' => $categoryId,
|
||||||
|
'name' => $categoryName,
|
||||||
|
'transaction_journals' => [],
|
||||||
|
];
|
||||||
|
|
||||||
|
// add journal to array:
|
||||||
|
// only a subset of the fields.
|
||||||
|
$journalId = (int)$journal['transaction_journal_id'];
|
||||||
|
$array[$currencyId]['categories'][$categoryId]['transaction_journals'][$journalId] = [
|
||||||
|
'amount' => app('steam')->negative($journal['amount']),
|
||||||
|
'date' => $journal['date'],
|
||||||
|
'source_account_id' => $journal['source_account_id'],
|
||||||
|
'category_name' => $journal['category_name'],
|
||||||
|
'source_account_name' => $journal['source_account_name'],
|
||||||
|
'destination_account_id' => $journal['destination_account_id'],
|
||||||
|
'destination_account_name' => $journal['destination_account_name'],
|
||||||
|
'description' => $journal['description'],
|
||||||
|
'transaction_group_id' => $journal['transaction_group_id'],
|
||||||
|
];
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
return $array;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@@ -47,6 +47,36 @@ interface OperationsRepositoryInterface
|
|||||||
*/
|
*/
|
||||||
public function listExpenses(Carbon $start, Carbon $end, ?Collection $accounts = null, ?Collection $categories = null): array;
|
public function listExpenses(Carbon $start, Carbon $end, ?Collection $accounts = null, ?Collection $categories = null): array;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This method returns a list of all the transfer transaction journals (as arrays) set in that period
|
||||||
|
* which have the specified category set to them, transferred INTO the listed accounts.
|
||||||
|
* It excludes any transfers between the listed accounts.
|
||||||
|
* It's grouped per currency, with as few details in the array as possible. Amounts are always negative.
|
||||||
|
*
|
||||||
|
* @param Carbon $start
|
||||||
|
* @param Carbon $end
|
||||||
|
* @param Collection $accounts
|
||||||
|
* @param Collection|null $categories
|
||||||
|
*
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public function listTransferredIn(Carbon $start, Carbon $end, Collection $accounts, ?Collection $categories = null): array;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This method returns a list of all the transfer transaction journals (as arrays) set in that period
|
||||||
|
* which have the specified category set to them, transferred FROM the listed accounts.
|
||||||
|
* It excludes any transfers between the listed accounts.
|
||||||
|
* It's grouped per currency, with as few details in the array as possible. Amounts are always negative.
|
||||||
|
*
|
||||||
|
* @param Carbon $start
|
||||||
|
* @param Carbon $end
|
||||||
|
* @param Collection $accounts
|
||||||
|
* @param Collection|null $categories
|
||||||
|
*
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public function listTransferredOut(Carbon $start, Carbon $end, Collection $accounts, ?Collection $categories = null): array;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This method returns a list of all the deposit transaction journals (as arrays) set in that period
|
* This method returns a list of all the deposit transaction journals (as arrays) set in that period
|
||||||
* which have the specified category set to them. It's grouped per currency, with as few details in the array
|
* which have the specified category set to them. It's grouped per currency, with as few details in the array
|
||||||
|
@@ -249,7 +249,7 @@ class BudgetReportGenerator
|
|||||||
'budget_limits' => [],
|
'budget_limits' => [],
|
||||||
];
|
];
|
||||||
|
|
||||||
$noBudget = $this->nbRepository->sumExpenses($this->start, $this->end);
|
$noBudget = $this->nbRepository->sumExpenses($this->start, $this->end, $this->accounts);
|
||||||
foreach ($noBudget as $noBudgetEntry) {
|
foreach ($noBudget as $noBudgetEntry) {
|
||||||
|
|
||||||
// currency information:
|
// currency information:
|
||||||
|
@@ -66,6 +66,11 @@ class CategoryReportGenerator
|
|||||||
{
|
{
|
||||||
$earnedWith = $this->opsRepository->listIncome($this->start, $this->end, $this->accounts);
|
$earnedWith = $this->opsRepository->listIncome($this->start, $this->end, $this->accounts);
|
||||||
$spentWith = $this->opsRepository->listExpenses($this->start, $this->end, $this->accounts);
|
$spentWith = $this->opsRepository->listExpenses($this->start, $this->end, $this->accounts);
|
||||||
|
|
||||||
|
// also transferred out and transferred into these accounts in this category:
|
||||||
|
$transferredIn = $this->opsRepository->listTransferredIn($this->start, $this->end, $this->accounts);
|
||||||
|
$transferredOut = $this->opsRepository->listTransferredOut($this->start, $this->end, $this->accounts);
|
||||||
|
|
||||||
$earnedWithout = $this->noCatRepository->listIncome($this->start, $this->end, $this->accounts);
|
$earnedWithout = $this->noCatRepository->listIncome($this->start, $this->end, $this->accounts);
|
||||||
$spentWithout = $this->noCatRepository->listExpenses($this->start, $this->end, $this->accounts);
|
$spentWithout = $this->noCatRepository->listExpenses($this->start, $this->end, $this->accounts);
|
||||||
|
|
||||||
@@ -75,7 +80,7 @@ class CategoryReportGenerator
|
|||||||
];
|
];
|
||||||
|
|
||||||
// needs four for-each loops.
|
// needs four for-each loops.
|
||||||
foreach ([$earnedWith, $spentWith, $earnedWithout, $spentWithout] as $data) {
|
foreach ([$earnedWith, $spentWith, $earnedWithout, $spentWithout, $transferredIn, $transferredOut] as $data) {
|
||||||
$this->processOpsArray($data);
|
$this->processOpsArray($data);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -41,15 +41,13 @@ trait ValidatesBulkTransactionQuery
|
|||||||
protected function validateTransactionQuery(Validator $validator): void
|
protected function validateTransactionQuery(Validator $validator): void
|
||||||
{
|
{
|
||||||
$data = $validator->getData();
|
$data = $validator->getData();
|
||||||
// assumption is all validation has already taken place
|
// assumption is all validation has already taken place and the query key exists.
|
||||||
// and the query key exists.
|
|
||||||
$json = json_decode($data['query'], true, 8, JSON_THROW_ON_ERROR);
|
$json = json_decode($data['query'], true, 8, JSON_THROW_ON_ERROR);
|
||||||
|
|
||||||
if (array_key_exists('account_id', $json['where'])
|
if (array_key_exists('account_id', $json['where'])
|
||||||
&& array_key_exists('account_id', $json['update'])
|
&& array_key_exists('account_id', $json['update'])
|
||||||
) {
|
) {
|
||||||
// find both accounts
|
// find both accounts, must be same type.
|
||||||
// must be same type.
|
|
||||||
// already validated: belongs to this user.
|
// already validated: belongs to this user.
|
||||||
$repository = app(AccountRepositoryInterface::class);
|
$repository = app(AccountRepositoryInterface::class);
|
||||||
$source = $repository->find((int)$json['where']['account_id']);
|
$source = $repository->find((int)$json['where']['account_id']);
|
||||||
|
Reference in New Issue
Block a user