mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-10-12 15:35:15 +00:00
Various code cleanup and fixed alignments.
This commit is contained in:
@@ -43,7 +43,7 @@ class AccountController extends Controller
|
||||
public function general(Collection $accounts, Carbon $start, Carbon $end): string
|
||||
{
|
||||
// chart properties for cache:
|
||||
$cache = new CacheProperties();
|
||||
$cache = new CacheProperties();
|
||||
$cache->addProperty($start);
|
||||
$cache->addProperty($end);
|
||||
$cache->addProperty('account-report');
|
||||
|
@@ -66,7 +66,7 @@ class BalanceController extends Controller
|
||||
*/
|
||||
public function general(Collection $accounts, Carbon $start, Carbon $end)
|
||||
{
|
||||
$report = [
|
||||
$report = [
|
||||
'budgets' => [],
|
||||
'accounts' => [],
|
||||
];
|
||||
@@ -85,26 +85,26 @@ class BalanceController extends Controller
|
||||
|
||||
/** @var Budget $budget */
|
||||
foreach ($budgets as $budget) {
|
||||
$budgetId = $budget->id;
|
||||
$report['budgets'][$budgetId] = [
|
||||
$budgetId = $budget->id;
|
||||
$report['budgets'][$budgetId] = [
|
||||
'budget_id' => $budgetId,
|
||||
'budget_name' => $budget->name,
|
||||
'spent' => [], // per account
|
||||
'sums' => [], // per currency
|
||||
];
|
||||
$spent = [];
|
||||
$spent = [];
|
||||
|
||||
/** @var GroupCollectorInterface $collector */
|
||||
$collector = app(GroupCollectorInterface::class);
|
||||
$journals = $collector->setRange($start, $end)->setSourceAccounts($accounts)->setTypes([TransactionType::WITHDRAWAL])->setBudget($budget)
|
||||
$collector = app(GroupCollectorInterface::class);
|
||||
$journals = $collector->setRange($start, $end)->setSourceAccounts($accounts)->setTypes([TransactionType::WITHDRAWAL])->setBudget($budget)
|
||||
->getExtractedJournals()
|
||||
;
|
||||
|
||||
/** @var array $journal */
|
||||
foreach ($journals as $journal) {
|
||||
$sourceAccount = $journal['source_account_id'];
|
||||
$currencyId = $journal['currency_id'];
|
||||
$spent[$sourceAccount] ??= [
|
||||
$sourceAccount = $journal['source_account_id'];
|
||||
$currencyId = $journal['currency_id'];
|
||||
$spent[$sourceAccount] ??= [
|
||||
'source_account_id' => $sourceAccount,
|
||||
'currency_id' => $journal['currency_id'],
|
||||
'currency_code' => $journal['currency_code'],
|
||||
@@ -113,10 +113,10 @@ class BalanceController extends Controller
|
||||
'currency_decimal_places' => $journal['currency_decimal_places'],
|
||||
'spent' => '0',
|
||||
];
|
||||
$spent[$sourceAccount]['spent'] = bcadd($spent[$sourceAccount]['spent'], $journal['amount']);
|
||||
$spent[$sourceAccount]['spent'] = bcadd($spent[$sourceAccount]['spent'], $journal['amount']);
|
||||
|
||||
// also fix sum:
|
||||
$report['sums'][$budgetId][$currencyId] ??= [
|
||||
$report['sums'][$budgetId][$currencyId] ??= [
|
||||
'sum' => '0',
|
||||
'currency_id' => $journal['currency_id'],
|
||||
'currency_code' => $journal['currency_code'],
|
||||
@@ -124,8 +124,8 @@ class BalanceController extends Controller
|
||||
'currency_symbol' => $journal['currency_symbol'],
|
||||
'currency_decimal_places' => $journal['currency_decimal_places'],
|
||||
];
|
||||
$report['sums'][$budgetId][$currencyId]['sum'] = bcadd($report['sums'][$budgetId][$currencyId]['sum'], $journal['amount']);
|
||||
$report['accounts'][$sourceAccount]['sum'] = bcadd($report['accounts'][$sourceAccount]['sum'], $journal['amount']);
|
||||
$report['sums'][$budgetId][$currencyId]['sum'] = bcadd($report['sums'][$budgetId][$currencyId]['sum'], $journal['amount']);
|
||||
$report['accounts'][$sourceAccount]['sum'] = bcadd($report['accounts'][$sourceAccount]['sum'], $journal['amount']);
|
||||
|
||||
// add currency info for account sum
|
||||
$report['accounts'][$sourceAccount]['currency_id'] = $journal['currency_id'];
|
||||
|
@@ -42,7 +42,7 @@ class BillController extends Controller
|
||||
*/
|
||||
public function overview(Collection $accounts, Carbon $start, Carbon $end) // chart properties for cache:
|
||||
{
|
||||
$cache = new CacheProperties();
|
||||
$cache = new CacheProperties();
|
||||
$cache->addProperty($start);
|
||||
$cache->addProperty($end);
|
||||
$cache->addProperty('bill-report');
|
||||
|
@@ -79,7 +79,7 @@ class BudgetController extends Controller
|
||||
$generator->setEnd($end);
|
||||
|
||||
$generator->accountPerBudget();
|
||||
$report = $generator->getReport();
|
||||
$report = $generator->getReport();
|
||||
|
||||
return view('reports.budget.partials.account-per-budget', compact('report', 'budgets'));
|
||||
}
|
||||
@@ -95,7 +95,7 @@ class BudgetController extends Controller
|
||||
|
||||
/** @var Account $account */
|
||||
foreach ($accounts as $account) {
|
||||
$accountId = $account->id;
|
||||
$accountId = $account->id;
|
||||
$report[$accountId] ??= [
|
||||
'name' => $account->name,
|
||||
'id' => $account->id,
|
||||
@@ -106,7 +106,7 @@ class BudgetController extends Controller
|
||||
|
||||
// loop expenses.
|
||||
foreach ($spent as $currency) {
|
||||
$currencyId = $currency['currency_id'];
|
||||
$currencyId = $currency['currency_id'];
|
||||
$sums[$currencyId] ??= [
|
||||
'currency_id' => $currency['currency_id'],
|
||||
'currency_symbol' => $currency['currency_symbol'],
|
||||
@@ -117,7 +117,7 @@ class BudgetController extends Controller
|
||||
foreach ($currency['budgets'] as $budget) {
|
||||
foreach ($budget['transaction_journals'] as $journal) {
|
||||
$sourceAccountId = $journal['source_account_id'];
|
||||
$report[$sourceAccountId]['currencies'][$currencyId] ??= [
|
||||
$report[$sourceAccountId]['currencies'][$currencyId] ??= [
|
||||
'currency_id' => $currency['currency_id'],
|
||||
'currency_symbol' => $currency['currency_symbol'],
|
||||
'currency_name' => $currency['currency_name'],
|
||||
@@ -143,14 +143,14 @@ class BudgetController extends Controller
|
||||
*/
|
||||
public function avgExpenses(Collection $accounts, Collection $budgets, Carbon $start, Carbon $end)
|
||||
{
|
||||
$spent = $this->opsRepository->listExpenses($start, $end, $accounts, $budgets);
|
||||
$result = [];
|
||||
$spent = $this->opsRepository->listExpenses($start, $end, $accounts, $budgets);
|
||||
$result = [];
|
||||
foreach ($spent as $currency) {
|
||||
foreach ($currency['budgets'] as $budget) {
|
||||
foreach ($budget['transaction_journals'] as $journal) {
|
||||
$destinationId = $journal['destination_account_id'];
|
||||
$key = sprintf('%d-%d', $destinationId, $currency['currency_id']);
|
||||
$result[$key] ??= [
|
||||
$destinationId = $journal['destination_account_id'];
|
||||
$key = sprintf('%d-%d', $destinationId, $currency['currency_id']);
|
||||
$result[$key] ??= [
|
||||
'transactions' => 0,
|
||||
'sum' => '0',
|
||||
'avg' => '0',
|
||||
@@ -198,7 +198,7 @@ class BudgetController extends Controller
|
||||
|
||||
/** @var Budget $budget */
|
||||
foreach ($budgets as $budget) {
|
||||
$budgetId = $budget->id;
|
||||
$budgetId = $budget->id;
|
||||
$report[$budgetId] ??= [
|
||||
'name' => $budget->name,
|
||||
'id' => $budget->id,
|
||||
@@ -206,7 +206,7 @@ class BudgetController extends Controller
|
||||
];
|
||||
}
|
||||
foreach ($spent as $currency) {
|
||||
$currencyId = $currency['currency_id'];
|
||||
$currencyId = $currency['currency_id'];
|
||||
$sums[$currencyId] ??= [
|
||||
'currency_id' => $currency['currency_id'],
|
||||
'currency_symbol' => $currency['currency_symbol'],
|
||||
@@ -221,7 +221,7 @@ class BudgetController extends Controller
|
||||
|
||||
foreach ($budget['transaction_journals'] as $journal) {
|
||||
// add currency info to report array:
|
||||
$report[$budgetId]['currencies'][$currencyId] ??= [
|
||||
$report[$budgetId]['currencies'][$currencyId] ??= [
|
||||
'sum' => '0',
|
||||
'sum_pct' => '0',
|
||||
'currency_id' => $currency['currency_id'],
|
||||
@@ -238,9 +238,9 @@ class BudgetController extends Controller
|
||||
// loop again to get percentages.
|
||||
foreach ($report as $budgetId => $data) {
|
||||
foreach ($data['currencies'] as $currencyId => $dataX) {
|
||||
$sum = $dataX['sum'];
|
||||
$total = $sums[$currencyId]['sum'] ?? '0';
|
||||
$pct = '0';
|
||||
$sum = $dataX['sum'];
|
||||
$total = $sums[$currencyId]['sum'] ?? '0';
|
||||
$pct = '0';
|
||||
if (0 !== bccomp($sum, '0') && 0 !== bccomp($total, '9')) {
|
||||
$pct = round((float)bcmul(bcdiv($sum, $total), '100')); // intentional float
|
||||
}
|
||||
@@ -269,7 +269,7 @@ class BudgetController extends Controller
|
||||
$generator->setEnd($end);
|
||||
|
||||
$generator->general();
|
||||
$report = $generator->getReport();
|
||||
$report = $generator->getReport();
|
||||
|
||||
return view('reports.partials.budgets', compact('report'))->render();
|
||||
}
|
||||
@@ -283,7 +283,7 @@ class BudgetController extends Controller
|
||||
*/
|
||||
public function period(Collection $accounts, Carbon $start, Carbon $end)
|
||||
{
|
||||
$cache = new CacheProperties();
|
||||
$cache = new CacheProperties();
|
||||
$cache->addProperty($start);
|
||||
$cache->addProperty($end);
|
||||
$cache->addProperty('budget-period-report');
|
||||
@@ -295,9 +295,9 @@ class BudgetController extends Controller
|
||||
$periods = app('navigation')->listOfPeriods($start, $end);
|
||||
$keyFormat = app('navigation')->preferredCarbonFormat($start, $end);
|
||||
// list expenses for budgets in account(s)
|
||||
$expenses = $this->opsRepository->listExpenses($start, $end, $accounts);
|
||||
$expenses = $this->opsRepository->listExpenses($start, $end, $accounts);
|
||||
|
||||
$report = [];
|
||||
$report = [];
|
||||
foreach ($expenses as $currency) {
|
||||
foreach ($currency['budgets'] as $budget) {
|
||||
$count = 0;
|
||||
@@ -346,8 +346,8 @@ class BudgetController extends Controller
|
||||
*/
|
||||
public function topExpenses(Collection $accounts, Collection $budgets, Carbon $start, Carbon $end)
|
||||
{
|
||||
$spent = $this->opsRepository->listExpenses($start, $end, $accounts, $budgets);
|
||||
$result = [];
|
||||
$spent = $this->opsRepository->listExpenses($start, $end, $accounts, $budgets);
|
||||
$result = [];
|
||||
foreach ($spent as $currency) {
|
||||
foreach ($currency['budgets'] as $budget) {
|
||||
foreach ($budget['transaction_journals'] as $journal) {
|
||||
|
@@ -74,7 +74,7 @@ class CategoryController extends Controller
|
||||
|
||||
/** @var Account $account */
|
||||
foreach ($accounts as $account) {
|
||||
$accountId = $account->id;
|
||||
$accountId = $account->id;
|
||||
$report[$accountId] ??= [
|
||||
'name' => $account->name,
|
||||
'id' => $account->id,
|
||||
@@ -90,8 +90,8 @@ class CategoryController extends Controller
|
||||
/** @var array $category */
|
||||
foreach ($currency['categories'] as $category) {
|
||||
foreach ($category['transaction_journals'] as $journal) {
|
||||
$sourceAccountId = $journal['source_account_id'];
|
||||
$report[$sourceAccountId]['currencies'][$currencyId] ??= [
|
||||
$sourceAccountId = $journal['source_account_id'];
|
||||
$report[$sourceAccountId]['currencies'][$currencyId] ??= [
|
||||
'currency_id' => $currency['currency_id'],
|
||||
'currency_symbol' => $currency['currency_symbol'],
|
||||
'currency_name' => $currency['currency_name'],
|
||||
@@ -167,7 +167,7 @@ class CategoryController extends Controller
|
||||
|
||||
/** @var Account $account */
|
||||
foreach ($accounts as $account) {
|
||||
$accountId = $account->id;
|
||||
$accountId = $account->id;
|
||||
$report[$accountId] ??= [
|
||||
'name' => $account->name,
|
||||
'id' => $account->id,
|
||||
@@ -178,7 +178,7 @@ class CategoryController extends Controller
|
||||
|
||||
// loop expenses.
|
||||
foreach ($spent as $currency) {
|
||||
$currencyId = $currency['currency_id'];
|
||||
$currencyId = $currency['currency_id'];
|
||||
$sums[$currencyId] ??= [
|
||||
'currency_id' => $currency['currency_id'],
|
||||
'currency_symbol' => $currency['currency_symbol'],
|
||||
@@ -191,7 +191,7 @@ class CategoryController extends Controller
|
||||
foreach ($currency['categories'] as $category) {
|
||||
foreach ($category['transaction_journals'] as $journal) {
|
||||
$sourceAccountId = $journal['source_account_id'];
|
||||
$report[$sourceAccountId]['currencies'][$currencyId] ??= [
|
||||
$report[$sourceAccountId]['currencies'][$currencyId] ??= [
|
||||
'currency_id' => $currency['currency_id'],
|
||||
'currency_symbol' => $currency['currency_symbol'],
|
||||
'currency_name' => $currency['currency_name'],
|
||||
@@ -216,7 +216,7 @@ class CategoryController extends Controller
|
||||
|
||||
// loop income.
|
||||
foreach ($earned as $currency) {
|
||||
$currencyId = $currency['currency_id'];
|
||||
$currencyId = $currency['currency_id'];
|
||||
$sums[$currencyId] ??= [
|
||||
'currency_id' => $currency['currency_id'],
|
||||
'currency_symbol' => $currency['currency_symbol'],
|
||||
@@ -229,7 +229,7 @@ class CategoryController extends Controller
|
||||
foreach ($currency['categories'] as $category) {
|
||||
foreach ($category['transaction_journals'] as $journal) {
|
||||
$destinationAccountId = $journal['destination_account_id'];
|
||||
$report[$destinationAccountId]['currencies'][$currencyId] ??= [
|
||||
$report[$destinationAccountId]['currencies'][$currencyId] ??= [
|
||||
'currency_id' => $currency['currency_id'],
|
||||
'currency_symbol' => $currency['currency_symbol'],
|
||||
'currency_name' => $currency['currency_name'],
|
||||
@@ -262,14 +262,14 @@ class CategoryController extends Controller
|
||||
*/
|
||||
public function avgExpenses(Collection $accounts, Collection $categories, Carbon $start, Carbon $end)
|
||||
{
|
||||
$spent = $this->opsRepository->listExpenses($start, $end, $accounts, $categories);
|
||||
$result = [];
|
||||
$spent = $this->opsRepository->listExpenses($start, $end, $accounts, $categories);
|
||||
$result = [];
|
||||
foreach ($spent as $currency) {
|
||||
foreach ($currency['categories'] as $category) {
|
||||
foreach ($category['transaction_journals'] as $journal) {
|
||||
$destinationId = $journal['destination_account_id'];
|
||||
$key = sprintf('%d-%d', $destinationId, $currency['currency_id']);
|
||||
$result[$key] ??= [
|
||||
$destinationId = $journal['destination_account_id'];
|
||||
$key = sprintf('%d-%d', $destinationId, $currency['currency_id']);
|
||||
$result[$key] ??= [
|
||||
'transactions' => 0,
|
||||
'sum' => '0',
|
||||
'avg' => '0',
|
||||
@@ -312,13 +312,13 @@ class CategoryController extends Controller
|
||||
*/
|
||||
public function avgIncome(Collection $accounts, Collection $categories, Carbon $start, Carbon $end)
|
||||
{
|
||||
$spent = $this->opsRepository->listIncome($start, $end, $accounts, $categories);
|
||||
$result = [];
|
||||
$spent = $this->opsRepository->listIncome($start, $end, $accounts, $categories);
|
||||
$result = [];
|
||||
foreach ($spent as $currency) {
|
||||
foreach ($currency['categories'] as $category) {
|
||||
foreach ($category['transaction_journals'] as $journal) {
|
||||
$sourceId = $journal['source_account_id'];
|
||||
$key = sprintf('%d-%d', $sourceId, $currency['currency_id']);
|
||||
$sourceId = $journal['source_account_id'];
|
||||
$key = sprintf('%d-%d', $sourceId, $currency['currency_id']);
|
||||
$result[$key] ??= [
|
||||
'transactions' => 0,
|
||||
'sum' => '0',
|
||||
@@ -369,7 +369,7 @@ class CategoryController extends Controller
|
||||
|
||||
/** @var Category $category */
|
||||
foreach ($categories as $category) {
|
||||
$categoryId = $category->id;
|
||||
$categoryId = $category->id;
|
||||
$report[$categoryId] ??= [
|
||||
'name' => $category->name,
|
||||
'id' => $category->id,
|
||||
@@ -377,7 +377,7 @@ class CategoryController extends Controller
|
||||
];
|
||||
}
|
||||
foreach ($spent as $currency) {
|
||||
$currencyId = $currency['currency_id'];
|
||||
$currencyId = $currency['currency_id'];
|
||||
$sums[$currencyId] ??= [
|
||||
'currency_id' => $currency['currency_id'],
|
||||
'currency_symbol' => $currency['currency_symbol'],
|
||||
@@ -394,7 +394,7 @@ class CategoryController extends Controller
|
||||
|
||||
foreach ($category['transaction_journals'] as $journal) {
|
||||
// add currency info to report array:
|
||||
$report[$categoryId]['currencies'][$currencyId] ??= [
|
||||
$report[$categoryId]['currencies'][$currencyId] ??= [
|
||||
'spent' => '0',
|
||||
'earned' => '0',
|
||||
'sum' => '0',
|
||||
@@ -412,14 +412,14 @@ class CategoryController extends Controller
|
||||
$journal['amount']
|
||||
);
|
||||
|
||||
$sums[$currencyId]['spent_sum'] = bcadd($sums[$currencyId]['spent_sum'], $journal['amount']);
|
||||
$sums[$currencyId]['total_sum'] = bcadd($sums[$currencyId]['total_sum'], $journal['amount']);
|
||||
$sums[$currencyId]['spent_sum'] = bcadd($sums[$currencyId]['spent_sum'], $journal['amount']);
|
||||
$sums[$currencyId]['total_sum'] = bcadd($sums[$currencyId]['total_sum'], $journal['amount']);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
foreach ($earned as $currency) {
|
||||
$currencyId = $currency['currency_id'];
|
||||
$currencyId = $currency['currency_id'];
|
||||
$sums[$currencyId] ??= [
|
||||
'currency_id' => $currency['currency_id'],
|
||||
'currency_symbol' => $currency['currency_symbol'],
|
||||
@@ -436,7 +436,7 @@ class CategoryController extends Controller
|
||||
|
||||
foreach ($category['transaction_journals'] as $journal) {
|
||||
// add currency info to report array:
|
||||
$report[$categoryId]['currencies'][$currencyId] ??= [
|
||||
$report[$categoryId]['currencies'][$currencyId] ??= [
|
||||
'spent' => '0',
|
||||
'earned' => '0',
|
||||
'sum' => '0',
|
||||
@@ -454,8 +454,8 @@ class CategoryController extends Controller
|
||||
$journal['amount']
|
||||
);
|
||||
|
||||
$sums[$currencyId]['earned_sum'] = bcadd($sums[$currencyId]['earned_sum'], $journal['amount']);
|
||||
$sums[$currencyId]['total_sum'] = bcadd($sums[$currencyId]['total_sum'], $journal['amount']);
|
||||
$sums[$currencyId]['earned_sum'] = bcadd($sums[$currencyId]['earned_sum'], $journal['amount']);
|
||||
$sums[$currencyId]['total_sum'] = bcadd($sums[$currencyId]['total_sum'], $journal['amount']);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -472,7 +472,7 @@ class CategoryController extends Controller
|
||||
*/
|
||||
public function expenses(Collection $accounts, Carbon $start, Carbon $end)
|
||||
{
|
||||
$cache = new CacheProperties();
|
||||
$cache = new CacheProperties();
|
||||
$cache->addProperty($start);
|
||||
$cache->addProperty($end);
|
||||
$cache->addProperty('category-period-expenses-report');
|
||||
@@ -483,7 +483,7 @@ class CategoryController extends Controller
|
||||
|
||||
// depending on the carbon format (a reliable way to determine the general date difference)
|
||||
// change the "listOfPeriods" call so the entire period gets included correctly.
|
||||
$format = app('navigation')->preferredCarbonFormat($start, $end);
|
||||
$format = app('navigation')->preferredCarbonFormat($start, $end);
|
||||
|
||||
if ('Y' === $format) {
|
||||
$start->startOfYear();
|
||||
@@ -499,7 +499,7 @@ class CategoryController extends Controller
|
||||
foreach ([$with, $without] as $set) {
|
||||
foreach ($set as $currencyId => $currencyRow) {
|
||||
foreach ($currencyRow['categories'] as $categoryId => $categoryRow) {
|
||||
$key = sprintf('%d-%d', $currencyId, $categoryId);
|
||||
$key = sprintf('%d-%d', $currencyId, $categoryId);
|
||||
$data[$key] ??= [
|
||||
'id' => $categoryRow['id'],
|
||||
'title' => sprintf('%s (%s)', $categoryRow['name'], $currencyRow['currency_name']),
|
||||
@@ -523,7 +523,7 @@ class CategoryController extends Controller
|
||||
|
||||
$cache->store($data);
|
||||
|
||||
$report = $data;
|
||||
$report = $data;
|
||||
|
||||
try {
|
||||
$result = view('reports.partials.category-period', compact('report', 'periods'))->render();
|
||||
@@ -546,7 +546,7 @@ class CategoryController extends Controller
|
||||
*/
|
||||
public function income(Collection $accounts, Carbon $start, Carbon $end): string
|
||||
{
|
||||
$cache = new CacheProperties();
|
||||
$cache = new CacheProperties();
|
||||
$cache->addProperty($start);
|
||||
$cache->addProperty($end);
|
||||
$cache->addProperty('category-period-income-report');
|
||||
@@ -557,7 +557,7 @@ class CategoryController extends Controller
|
||||
|
||||
// depending on the carbon format (a reliable way to determine the general date difference)
|
||||
// change the "listOfPeriods" call so the entire period gets included correctly.
|
||||
$format = app('navigation')->preferredCarbonFormat($start, $end);
|
||||
$format = app('navigation')->preferredCarbonFormat($start, $end);
|
||||
|
||||
if ('Y' === $format) {
|
||||
$start->startOfYear();
|
||||
@@ -573,7 +573,7 @@ class CategoryController extends Controller
|
||||
foreach ([$with, $without] as $set) {
|
||||
foreach ($set as $currencyId => $currencyRow) {
|
||||
foreach ($currencyRow['categories'] as $categoryId => $categoryRow) {
|
||||
$key = sprintf('%d-%d', $currencyId, $categoryId);
|
||||
$key = sprintf('%d-%d', $currencyId, $categoryId);
|
||||
$data[$key] ??= [
|
||||
'id' => $categoryRow['id'],
|
||||
'title' => sprintf('%s (%s)', $categoryRow['name'], $currencyRow['currency_name']),
|
||||
@@ -595,7 +595,7 @@ class CategoryController extends Controller
|
||||
}
|
||||
}
|
||||
|
||||
$report = $data;
|
||||
$report = $data;
|
||||
|
||||
try {
|
||||
$result = view('reports.partials.category-period', compact('report', 'periods'))->render();
|
||||
@@ -619,7 +619,7 @@ class CategoryController extends Controller
|
||||
public function operations(Collection $accounts, Carbon $start, Carbon $end): string
|
||||
{
|
||||
// chart properties for cache:
|
||||
$cache = new CacheProperties();
|
||||
$cache = new CacheProperties();
|
||||
$cache->addProperty($start);
|
||||
$cache->addProperty($end);
|
||||
$cache->addProperty('category-report');
|
||||
@@ -634,7 +634,7 @@ class CategoryController extends Controller
|
||||
$generator->setStart($start);
|
||||
$generator->setEnd($end);
|
||||
$generator->operations();
|
||||
$report = $generator->getReport();
|
||||
$report = $generator->getReport();
|
||||
|
||||
try {
|
||||
$result = view('reports.partials.categories', compact('report'))->render();
|
||||
@@ -656,8 +656,8 @@ class CategoryController extends Controller
|
||||
*/
|
||||
public function topExpenses(Collection $accounts, Collection $categories, Carbon $start, Carbon $end)
|
||||
{
|
||||
$spent = $this->opsRepository->listExpenses($start, $end, $accounts, $categories);
|
||||
$result = [];
|
||||
$spent = $this->opsRepository->listExpenses($start, $end, $accounts, $categories);
|
||||
$result = [];
|
||||
foreach ($spent as $currency) {
|
||||
foreach ($currency['categories'] as $category) {
|
||||
foreach ($category['transaction_journals'] as $journal) {
|
||||
@@ -704,8 +704,8 @@ class CategoryController extends Controller
|
||||
*/
|
||||
public function topIncome(Collection $accounts, Collection $categories, Carbon $start, Carbon $end)
|
||||
{
|
||||
$spent = $this->opsRepository->listIncome($start, $end, $accounts, $categories);
|
||||
$result = [];
|
||||
$spent = $this->opsRepository->listIncome($start, $end, $accounts, $categories);
|
||||
$result = [];
|
||||
foreach ($spent as $currency) {
|
||||
foreach ($currency['categories'] as $category) {
|
||||
foreach ($category['transaction_journals'] as $journal) {
|
||||
|
@@ -75,8 +75,8 @@ class DoubleController extends Controller
|
||||
$result = [];
|
||||
foreach ($spent as $currency) {
|
||||
foreach ($currency['transaction_journals'] as $journal) {
|
||||
$sourceId = $journal['source_account_id'];
|
||||
$key = sprintf('%d-%d', $sourceId, $currency['currency_id']);
|
||||
$sourceId = $journal['source_account_id'];
|
||||
$key = sprintf('%d-%d', $sourceId, $currency['currency_id']);
|
||||
$result[$key] ??= [
|
||||
'transactions' => 0,
|
||||
'sum' => '0',
|
||||
@@ -97,7 +97,7 @@ class DoubleController extends Controller
|
||||
}
|
||||
// sort by amount_float
|
||||
// sort temp array by amount.
|
||||
$amounts = array_column($result, 'avg_float');
|
||||
$amounts = array_column($result, 'avg_float');
|
||||
array_multisort($amounts, SORT_ASC, $result);
|
||||
|
||||
try {
|
||||
@@ -125,9 +125,9 @@ class DoubleController extends Controller
|
||||
$result = [];
|
||||
foreach ($spent as $currency) {
|
||||
foreach ($currency['transaction_journals'] as $journal) {
|
||||
$destinationId = $journal['destination_account_id'];
|
||||
$key = sprintf('%d-%d', $destinationId, $currency['currency_id']);
|
||||
$result[$key] ??= [
|
||||
$destinationId = $journal['destination_account_id'];
|
||||
$key = sprintf('%d-%d', $destinationId, $currency['currency_id']);
|
||||
$result[$key] ??= [
|
||||
'transactions' => 0,
|
||||
'sum' => '0',
|
||||
'avg' => '0',
|
||||
@@ -147,7 +147,7 @@ class DoubleController extends Controller
|
||||
}
|
||||
// sort by amount_float
|
||||
// sort temp array by amount.
|
||||
$amounts = array_column($result, 'avg_float');
|
||||
$amounts = array_column($result, 'avg_float');
|
||||
array_multisort($amounts, SORT_DESC, $result);
|
||||
|
||||
try {
|
||||
@@ -174,8 +174,8 @@ class DoubleController extends Controller
|
||||
$report = [];
|
||||
$sums = [];
|
||||
// see what happens when we collect transactions.
|
||||
$spent = $this->opsRepository->listExpenses($start, $end, $together);
|
||||
$earned = $this->opsRepository->listIncome($start, $end, $together);
|
||||
$spent = $this->opsRepository->listExpenses($start, $end, $together);
|
||||
$earned = $this->opsRepository->listIncome($start, $end, $together);
|
||||
// group and list per account name (as long as its not in accounts, only in double)
|
||||
|
||||
/** @var array $currency */
|
||||
@@ -195,11 +195,11 @@ class DoubleController extends Controller
|
||||
|
||||
/** @var array $journal */
|
||||
foreach ($currency['transaction_journals'] as $journal) {
|
||||
$destId = $journal['destination_account_id'];
|
||||
$destName = $journal['destination_account_name'];
|
||||
$destIban = $journal['destination_account_iban'];
|
||||
$genericName = $this->getCounterpartName($withCounterpart, $destId, $destName, $destIban);
|
||||
$objectName = sprintf('%s (%s)', $genericName, $currency['currency_name']);
|
||||
$destId = $journal['destination_account_id'];
|
||||
$destName = $journal['destination_account_name'];
|
||||
$destIban = $journal['destination_account_iban'];
|
||||
$genericName = $this->getCounterpartName($withCounterpart, $destId, $destName, $destIban);
|
||||
$objectName = sprintf('%s (%s)', $genericName, $currency['currency_name']);
|
||||
$report[$objectName] ??= [
|
||||
'dest_name' => '',
|
||||
'dest_iban' => '',
|
||||
@@ -219,10 +219,10 @@ class DoubleController extends Controller
|
||||
$report[$objectName]['dest_iban'] = $destIban;
|
||||
|
||||
// add amounts:
|
||||
$report[$objectName]['spent'] = bcadd($report[$objectName]['spent'], $journal['amount']);
|
||||
$report[$objectName]['sum'] = bcadd($report[$objectName]['sum'], $journal['amount']);
|
||||
$sums[$currencyId]['spent'] = bcadd($sums[$currencyId]['spent'], $journal['amount']);
|
||||
$sums[$currencyId]['sum'] = bcadd($sums[$currencyId]['sum'], $journal['amount']);
|
||||
$report[$objectName]['spent'] = bcadd($report[$objectName]['spent'], $journal['amount']);
|
||||
$report[$objectName]['sum'] = bcadd($report[$objectName]['sum'], $journal['amount']);
|
||||
$sums[$currencyId]['spent'] = bcadd($sums[$currencyId]['spent'], $journal['amount']);
|
||||
$sums[$currencyId]['sum'] = bcadd($sums[$currencyId]['sum'], $journal['amount']);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -243,11 +243,11 @@ class DoubleController extends Controller
|
||||
|
||||
/** @var array $journal */
|
||||
foreach ($currency['transaction_journals'] as $journal) {
|
||||
$sourceId = $journal['source_account_id'];
|
||||
$sourceName = $journal['source_account_name'];
|
||||
$sourceIban = $journal['source_account_iban'];
|
||||
$genericName = $this->getCounterpartName($withCounterpart, $sourceId, $sourceName, $sourceIban);
|
||||
$objectName = sprintf('%s (%s)', $genericName, $currency['currency_name']);
|
||||
$sourceId = $journal['source_account_id'];
|
||||
$sourceName = $journal['source_account_name'];
|
||||
$sourceIban = $journal['source_account_iban'];
|
||||
$genericName = $this->getCounterpartName($withCounterpart, $sourceId, $sourceName, $sourceIban);
|
||||
$objectName = sprintf('%s (%s)', $genericName, $currency['currency_name']);
|
||||
$report[$objectName] ??= [
|
||||
'dest_name' => '',
|
||||
'dest_iban' => '',
|
||||
@@ -268,10 +268,10 @@ class DoubleController extends Controller
|
||||
$report[$objectName]['source_iban'] = $sourceIban;
|
||||
|
||||
// add amounts:
|
||||
$report[$objectName]['earned'] = bcadd($report[$objectName]['earned'], $journal['amount']);
|
||||
$report[$objectName]['sum'] = bcadd($report[$objectName]['sum'], $journal['amount']);
|
||||
$sums[$currencyId]['earned'] = bcadd($sums[$currencyId]['earned'], $journal['amount']);
|
||||
$sums[$currencyId]['sum'] = bcadd($sums[$currencyId]['sum'], $journal['amount']);
|
||||
$report[$objectName]['earned'] = bcadd($report[$objectName]['earned'], $journal['amount']);
|
||||
$report[$objectName]['sum'] = bcadd($report[$objectName]['sum'], $journal['amount']);
|
||||
$sums[$currencyId]['earned'] = bcadd($sums[$currencyId]['earned'], $journal['amount']);
|
||||
$sums[$currencyId]['sum'] = bcadd($sums[$currencyId]['sum'], $journal['amount']);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -288,8 +288,8 @@ class DoubleController extends Controller
|
||||
$report = [];
|
||||
$sums = [];
|
||||
// see what happens when we collect transactions.
|
||||
$spent = $this->opsRepository->listExpenses($start, $end, $together);
|
||||
$earned = $this->opsRepository->listIncome($start, $end, $together);
|
||||
$spent = $this->opsRepository->listExpenses($start, $end, $together);
|
||||
$earned = $this->opsRepository->listIncome($start, $end, $together);
|
||||
// group and list per account name (as long as its not in accounts, only in double)
|
||||
|
||||
/** @var array $currency */
|
||||
@@ -309,7 +309,7 @@ class DoubleController extends Controller
|
||||
|
||||
/** @var array $journal */
|
||||
foreach ($currency['transaction_journals'] as $journal) {
|
||||
$objectName = sprintf('%s (%s)', $journal['source_account_name'], $currency['currency_name']);
|
||||
$objectName = sprintf('%s (%s)', $journal['source_account_name'], $currency['currency_name']);
|
||||
$report[$objectName] ??= [
|
||||
'account_id' => $journal['source_account_id'],
|
||||
'account_name' => $objectName,
|
||||
@@ -348,7 +348,7 @@ class DoubleController extends Controller
|
||||
|
||||
/** @var array $journal */
|
||||
foreach ($currency['transaction_journals'] as $journal) {
|
||||
$objectName = sprintf('%s (%s)', $journal['destination_account_name'], $currency['currency_name']);
|
||||
$objectName = sprintf('%s (%s)', $journal['destination_account_name'], $currency['currency_name']);
|
||||
$report[$objectName] ??= [
|
||||
'account_id' => $journal['destination_account_id'],
|
||||
'account_name' => $objectName,
|
||||
@@ -406,7 +406,7 @@ class DoubleController extends Controller
|
||||
}
|
||||
// sort by amount_float
|
||||
// sort temp array by amount.
|
||||
$amounts = array_column($result, 'amount_float');
|
||||
$amounts = array_column($result, 'amount_float');
|
||||
array_multisort($amounts, SORT_ASC, $result);
|
||||
|
||||
try {
|
||||
@@ -454,7 +454,7 @@ class DoubleController extends Controller
|
||||
}
|
||||
// sort by amount_float
|
||||
// sort temp array by amount.
|
||||
$amounts = array_column($result, 'amount_float');
|
||||
$amounts = array_column($result, 'amount_float');
|
||||
array_multisort($amounts, SORT_DESC, $result);
|
||||
|
||||
try {
|
||||
|
@@ -65,7 +65,7 @@ class OperationsController extends Controller
|
||||
public function expenses(Collection $accounts, Carbon $start, Carbon $end)
|
||||
{
|
||||
// chart properties for cache:
|
||||
$cache = new CacheProperties();
|
||||
$cache = new CacheProperties();
|
||||
$cache->addProperty($start);
|
||||
$cache->addProperty($end);
|
||||
$cache->addProperty('expense-report');
|
||||
@@ -99,7 +99,7 @@ class OperationsController extends Controller
|
||||
public function income(Collection $accounts, Carbon $start, Carbon $end): string
|
||||
{
|
||||
// chart properties for cache:
|
||||
$cache = new CacheProperties();
|
||||
$cache = new CacheProperties();
|
||||
$cache->addProperty($start);
|
||||
$cache->addProperty($end);
|
||||
$cache->addProperty('income-report');
|
||||
@@ -135,7 +135,7 @@ class OperationsController extends Controller
|
||||
public function operations(Collection $accounts, Carbon $start, Carbon $end)
|
||||
{
|
||||
// chart properties for cache:
|
||||
$cache = new CacheProperties();
|
||||
$cache = new CacheProperties();
|
||||
$cache->addProperty($start);
|
||||
$cache->addProperty($end);
|
||||
$cache->addProperty('inc-exp-report');
|
||||
@@ -152,7 +152,7 @@ class OperationsController extends Controller
|
||||
/** @var int $currencyId */
|
||||
foreach ($keys as $currencyId) {
|
||||
$currencyInfo = $incomes['sums'][$currencyId] ?? $expenses['sums'][$currencyId];
|
||||
$sums[$currencyId] ??= [
|
||||
$sums[$currencyId] ??= [
|
||||
'currency_id' => $currencyId,
|
||||
'currency_name' => $currencyInfo['currency_name'],
|
||||
'currency_code' => $currencyInfo['currency_code'],
|
||||
|
@@ -68,7 +68,7 @@ class TagController extends Controller
|
||||
|
||||
/** @var Account $account */
|
||||
foreach ($accounts as $account) {
|
||||
$accountId = $account->id;
|
||||
$accountId = $account->id;
|
||||
$report[$accountId] ??= [
|
||||
'name' => $account->name,
|
||||
'id' => $account->id,
|
||||
@@ -85,8 +85,8 @@ class TagController extends Controller
|
||||
foreach ($currency['tags'] as $tag) {
|
||||
$tagId = $tag['id'];
|
||||
foreach ($tag['transaction_journals'] as $journal) {
|
||||
$sourceAccountId = $journal['source_account_id'];
|
||||
$report[$sourceAccountId]['currencies'][$currencyId] ??= [
|
||||
$sourceAccountId = $journal['source_account_id'];
|
||||
$report[$sourceAccountId]['currencies'][$currencyId] ??= [
|
||||
'currency_id' => $currency['currency_id'],
|
||||
'currency_symbol' => $currency['currency_symbol'],
|
||||
'currency_name' => $currency['currency_name'],
|
||||
@@ -163,7 +163,7 @@ class TagController extends Controller
|
||||
|
||||
/** @var Account $account */
|
||||
foreach ($accounts as $account) {
|
||||
$accountId = $account->id;
|
||||
$accountId = $account->id;
|
||||
$report[$accountId] ??= [
|
||||
'name' => $account->name,
|
||||
'id' => $account->id,
|
||||
@@ -174,7 +174,7 @@ class TagController extends Controller
|
||||
|
||||
// loop expenses.
|
||||
foreach ($spent as $currency) {
|
||||
$currencyId = $currency['currency_id'];
|
||||
$currencyId = $currency['currency_id'];
|
||||
$sums[$currencyId] ??= [
|
||||
'currency_id' => $currency['currency_id'],
|
||||
'currency_symbol' => $currency['currency_symbol'],
|
||||
@@ -187,7 +187,7 @@ class TagController extends Controller
|
||||
foreach ($currency['tags'] as $tag) {
|
||||
foreach ($tag['transaction_journals'] as $journal) {
|
||||
$sourceAccountId = $journal['source_account_id'];
|
||||
$report[$sourceAccountId]['currencies'][$currencyId] ??= [
|
||||
$report[$sourceAccountId]['currencies'][$currencyId] ??= [
|
||||
'currency_id' => $currency['currency_id'],
|
||||
'currency_symbol' => $currency['currency_symbol'],
|
||||
'currency_name' => $currency['currency_name'],
|
||||
@@ -212,7 +212,7 @@ class TagController extends Controller
|
||||
|
||||
// loop income.
|
||||
foreach ($earned as $currency) {
|
||||
$currencyId = $currency['currency_id'];
|
||||
$currencyId = $currency['currency_id'];
|
||||
$sums[$currencyId] ??= [
|
||||
'currency_id' => $currency['currency_id'],
|
||||
'currency_symbol' => $currency['currency_symbol'],
|
||||
@@ -225,7 +225,7 @@ class TagController extends Controller
|
||||
foreach ($currency['tags'] as $tag) {
|
||||
foreach ($tag['transaction_journals'] as $journal) {
|
||||
$destinationAccountId = $journal['destination_account_id'];
|
||||
$report[$destinationAccountId]['currencies'][$currencyId] ??= [
|
||||
$report[$destinationAccountId]['currencies'][$currencyId] ??= [
|
||||
'currency_id' => $currency['currency_id'],
|
||||
'currency_symbol' => $currency['currency_symbol'],
|
||||
'currency_name' => $currency['currency_name'],
|
||||
@@ -258,14 +258,14 @@ class TagController extends Controller
|
||||
*/
|
||||
public function avgExpenses(Collection $accounts, Collection $tags, Carbon $start, Carbon $end)
|
||||
{
|
||||
$spent = $this->opsRepository->listExpenses($start, $end, $accounts, $tags);
|
||||
$result = [];
|
||||
$spent = $this->opsRepository->listExpenses($start, $end, $accounts, $tags);
|
||||
$result = [];
|
||||
foreach ($spent as $currency) {
|
||||
foreach ($currency['tags'] as $tag) {
|
||||
foreach ($tag['transaction_journals'] as $journal) {
|
||||
$destinationId = $journal['destination_account_id'];
|
||||
$key = sprintf('%d-%d', $destinationId, $currency['currency_id']);
|
||||
$result[$key] ??= [
|
||||
$destinationId = $journal['destination_account_id'];
|
||||
$key = sprintf('%d-%d', $destinationId, $currency['currency_id']);
|
||||
$result[$key] ??= [
|
||||
'transactions' => 0,
|
||||
'sum' => '0',
|
||||
'avg' => '0',
|
||||
@@ -308,13 +308,13 @@ class TagController extends Controller
|
||||
*/
|
||||
public function avgIncome(Collection $accounts, Collection $tags, Carbon $start, Carbon $end)
|
||||
{
|
||||
$spent = $this->opsRepository->listIncome($start, $end, $accounts, $tags);
|
||||
$result = [];
|
||||
$spent = $this->opsRepository->listIncome($start, $end, $accounts, $tags);
|
||||
$result = [];
|
||||
foreach ($spent as $currency) {
|
||||
foreach ($currency['tags'] as $tag) {
|
||||
foreach ($tag['transaction_journals'] as $journal) {
|
||||
$sourceId = $journal['source_account_id'];
|
||||
$key = sprintf('%d-%d', $sourceId, $currency['currency_id']);
|
||||
$sourceId = $journal['source_account_id'];
|
||||
$key = sprintf('%d-%d', $sourceId, $currency['currency_id']);
|
||||
$result[$key] ??= [
|
||||
'transactions' => 0,
|
||||
'sum' => '0',
|
||||
@@ -365,7 +365,7 @@ class TagController extends Controller
|
||||
|
||||
/** @var Tag $tag */
|
||||
foreach ($tags as $tag) {
|
||||
$tagId = $tag->id;
|
||||
$tagId = $tag->id;
|
||||
$report[$tagId] ??= [
|
||||
'name' => $tag->tag,
|
||||
'id' => $tag->id,
|
||||
@@ -373,7 +373,7 @@ class TagController extends Controller
|
||||
];
|
||||
}
|
||||
foreach ($spent as $currency) {
|
||||
$currencyId = $currency['currency_id'];
|
||||
$currencyId = $currency['currency_id'];
|
||||
$sums[$currencyId] ??= [
|
||||
'currency_id' => $currency['currency_id'],
|
||||
'currency_symbol' => $currency['currency_symbol'],
|
||||
@@ -392,7 +392,7 @@ class TagController extends Controller
|
||||
}
|
||||
foreach ($tag['transaction_journals'] as $journal) {
|
||||
// add currency info to report array:
|
||||
$report[$tagId]['currencies'][$currencyId] ??= [
|
||||
$report[$tagId]['currencies'][$currencyId] ??= [
|
||||
'spent' => '0',
|
||||
'earned' => '0',
|
||||
$tagId => $tagId,
|
||||
@@ -411,7 +411,7 @@ class TagController extends Controller
|
||||
}
|
||||
|
||||
foreach ($earned as $currency) {
|
||||
$currencyId = $currency['currency_id'];
|
||||
$currencyId = $currency['currency_id'];
|
||||
$sums[$currencyId] ??= [
|
||||
'currency_id' => $currency['currency_id'],
|
||||
'currency_symbol' => $currency['currency_symbol'],
|
||||
@@ -430,7 +430,7 @@ class TagController extends Controller
|
||||
}
|
||||
foreach ($tag['transaction_journals'] as $journal) {
|
||||
// add currency info to report array:
|
||||
$report[$tagId]['currencies'][$currencyId] ??= [
|
||||
$report[$tagId]['currencies'][$currencyId] ??= [
|
||||
'spent' => '0',
|
||||
'earned' => '0',
|
||||
'sum' => '0',
|
||||
@@ -458,8 +458,8 @@ class TagController extends Controller
|
||||
*/
|
||||
public function topExpenses(Collection $accounts, Collection $tags, Carbon $start, Carbon $end)
|
||||
{
|
||||
$spent = $this->opsRepository->listExpenses($start, $end, $accounts, $tags);
|
||||
$result = [];
|
||||
$spent = $this->opsRepository->listExpenses($start, $end, $accounts, $tags);
|
||||
$result = [];
|
||||
foreach ($spent as $currency) {
|
||||
foreach ($currency['tags'] as $tag) {
|
||||
foreach ($tag['transaction_journals'] as $journal) {
|
||||
@@ -506,8 +506,8 @@ class TagController extends Controller
|
||||
*/
|
||||
public function topIncome(Collection $accounts, Collection $tags, Carbon $start, Carbon $end)
|
||||
{
|
||||
$spent = $this->opsRepository->listIncome($start, $end, $accounts, $tags);
|
||||
$result = [];
|
||||
$spent = $this->opsRepository->listIncome($start, $end, $accounts, $tags);
|
||||
$result = [];
|
||||
foreach ($spent as $currency) {
|
||||
foreach ($currency['tags'] as $tag) {
|
||||
foreach ($tag['transaction_journals'] as $journal) {
|
||||
|
Reference in New Issue
Block a user