mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-02-25 18:45:27 -06:00
Fix some report issues.
This commit is contained in:
parent
3e242aaca6
commit
6f78735bc5
@ -46,8 +46,6 @@ use Log;
|
|||||||
*/
|
*/
|
||||||
class GroupCollector implements GroupCollectorInterface
|
class GroupCollector implements GroupCollectorInterface
|
||||||
{
|
{
|
||||||
/** @var array The accounts to filter on. Asset accounts or liabilities. */
|
|
||||||
private $accountIds;
|
|
||||||
/** @var array The standard fields to select. */
|
/** @var array The standard fields to select. */
|
||||||
private $fields;
|
private $fields;
|
||||||
/** @var bool Will be set to true if query result contains account information. (see function withAccountInformation). */
|
/** @var bool Will be set to true if query result contains account information. (see function withAccountInformation). */
|
||||||
@ -86,8 +84,6 @@ class GroupCollector implements GroupCollectorInterface
|
|||||||
$this->hasJoinedTagTables = false;
|
$this->hasJoinedTagTables = false;
|
||||||
|
|
||||||
$this->total = 0;
|
$this->total = 0;
|
||||||
$this->limit = 50;
|
|
||||||
$this->page = 1;
|
|
||||||
$this->fields = [
|
$this->fields = [
|
||||||
# group
|
# group
|
||||||
'transaction_groups.id as transaction_group_id',
|
'transaction_groups.id as transaction_group_id',
|
||||||
@ -157,10 +153,14 @@ class GroupCollector implements GroupCollectorInterface
|
|||||||
$collection = $this->parseArray($result);
|
$collection = $this->parseArray($result);
|
||||||
$this->total = $collection->count();
|
$this->total = $collection->count();
|
||||||
|
|
||||||
// now filter the array according to the page and the
|
// now filter the array according to the page and the limit (if necessary)
|
||||||
|
if (null !== $this->limit && null !== $this->page) {
|
||||||
$offset = ($this->page-1) * $this->limit;
|
$offset = ($this->page-1) * $this->limit;
|
||||||
|
|
||||||
return $collection->slice($offset, $this->limit);
|
return $collection->slice($offset, $this->limit);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $collection;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -182,7 +182,6 @@ class GroupCollector implements GroupCollectorInterface
|
|||||||
}
|
}
|
||||||
);
|
);
|
||||||
app('log')->debug(sprintf('GroupCollector: setAccounts: %s', implode(', ', $accountIds)));
|
app('log')->debug(sprintf('GroupCollector: setAccounts: %s', implode(', ', $accountIds)));
|
||||||
$this->accountIds = $accountIds;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
@ -202,7 +201,6 @@ class GroupCollector implements GroupCollectorInterface
|
|||||||
$this->query->whereIn('source.account_id', $accountIds);
|
$this->query->whereIn('source.account_id', $accountIds);
|
||||||
|
|
||||||
app('log')->debug(sprintf('GroupCollector: setSourceAccounts: %s', implode(', ', $accountIds)));
|
app('log')->debug(sprintf('GroupCollector: setSourceAccounts: %s', implode(', ', $accountIds)));
|
||||||
$this->accountIds = $accountIds;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
@ -222,7 +220,6 @@ class GroupCollector implements GroupCollectorInterface
|
|||||||
$this->query->whereIn('destination.account_id', $accountIds);
|
$this->query->whereIn('destination.account_id', $accountIds);
|
||||||
|
|
||||||
app('log')->debug(sprintf('GroupCollector: setSourceAccounts: %s', implode(', ', $accountIds)));
|
app('log')->debug(sprintf('GroupCollector: setSourceAccounts: %s', implode(', ', $accountIds)));
|
||||||
$this->accountIds = $accountIds;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
@ -847,6 +844,7 @@ class GroupCollector implements GroupCollectorInterface
|
|||||||
/** @var TransactionGroup $augmentedGroup */
|
/** @var TransactionGroup $augmentedGroup */
|
||||||
foreach ($collection as $augmentedGroup) {
|
foreach ($collection as $augmentedGroup) {
|
||||||
$groupId = $augmentedGroup->transaction_group_id;
|
$groupId = $augmentedGroup->transaction_group_id;
|
||||||
|
|
||||||
if (!isset($groups[$groupId])) {
|
if (!isset($groups[$groupId])) {
|
||||||
// make new array
|
// make new array
|
||||||
$parsedGroup = $this->parseAugmentedGroup($augmentedGroup);
|
$parsedGroup = $this->parseAugmentedGroup($augmentedGroup);
|
||||||
@ -877,7 +875,9 @@ class GroupCollector implements GroupCollectorInterface
|
|||||||
$groups[$groupId]['transactions'][$journalId] = $this->parseAugmentedGroup($augmentedGroup);
|
$groups[$groupId]['transactions'][$journalId] = $this->parseAugmentedGroup($augmentedGroup);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$groups = $this->parseSums($groups);
|
$groups = $this->parseSums($groups);
|
||||||
|
|
||||||
return new Collection($groups);
|
return new Collection($groups);
|
||||||
@ -1065,7 +1065,6 @@ class GroupCollector implements GroupCollectorInterface
|
|||||||
$this->query->whereNotIn('source.account_id', $accountIds);
|
$this->query->whereNotIn('source.account_id', $accountIds);
|
||||||
|
|
||||||
app('log')->debug(sprintf('GroupCollector: excludeSourceAccounts: %s', implode(', ', $accountIds)));
|
app('log')->debug(sprintf('GroupCollector: excludeSourceAccounts: %s', implode(', ', $accountIds)));
|
||||||
$this->accountIds = $accountIds;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
@ -1085,7 +1084,6 @@ class GroupCollector implements GroupCollectorInterface
|
|||||||
$this->query->whereNotIn('destination.account_id', $accountIds);
|
$this->query->whereNotIn('destination.account_id', $accountIds);
|
||||||
|
|
||||||
app('log')->debug(sprintf('GroupCollector: excludeDestinationAccounts: %s', implode(', ', $accountIds)));
|
app('log')->debug(sprintf('GroupCollector: excludeDestinationAccounts: %s', implode(', ', $accountIds)));
|
||||||
$this->accountIds = $accountIds;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
|
@ -224,7 +224,7 @@ class ReportController extends Controller
|
|||||||
'count_spent' => 0,
|
'count_spent' => 0,
|
||||||
];
|
];
|
||||||
foreach ($source['earned'] as $amount) {
|
foreach ($source['earned'] as $amount) {
|
||||||
$amount = bcmul($amount,'-1');
|
$amount = bcmul($amount, '-1');
|
||||||
$numbers['sum_earned'] = bcadd($amount, $numbers['sum_earned']);
|
$numbers['sum_earned'] = bcadd($amount, $numbers['sum_earned']);
|
||||||
++$numbers['count_earned'];
|
++$numbers['count_earned'];
|
||||||
}
|
}
|
||||||
|
@ -143,6 +143,7 @@ class AccountTasker implements AccountTaskerInterface
|
|||||||
$collector->excludeDestinationAccounts($accounts);
|
$collector->excludeDestinationAccounts($accounts);
|
||||||
$collector->setTypes([TransactionType::WITHDRAWAL, TransactionType::TRANSFER])->withAccountInformation();
|
$collector->setTypes([TransactionType::WITHDRAWAL, TransactionType::TRANSFER])->withAccountInformation();
|
||||||
$journals = $collector->getExtractedJournals();
|
$journals = $collector->getExtractedJournals();
|
||||||
|
|
||||||
$report = $this->groupExpenseByDestination($journals);
|
$report = $this->groupExpenseByDestination($journals);
|
||||||
|
|
||||||
// TODO sorting
|
// TODO sorting
|
||||||
@ -220,9 +221,8 @@ class AccountTasker implements AccountTaskerInterface
|
|||||||
$sourceId = (int)$journal['destination_account_id'];
|
$sourceId = (int)$journal['destination_account_id'];
|
||||||
$currencyId = (int)$journal['currency_id'];
|
$currencyId = (int)$journal['currency_id'];
|
||||||
$key = sprintf('%s-%s', $sourceId, $currencyId);
|
$key = sprintf('%s-%s', $sourceId, $currencyId);
|
||||||
if (!isset($report['accounts'][$key])) {
|
$currencies[$currencyId] = $currencies[$currencyId] ?? $currencyRepos->findNull($currencyId);
|
||||||
$currencies[$currencyId] = $currencies[$currencyId] ?? $currencyRepos->findNull($currencyId);
|
$report['accounts'][$key] = $report['accounts'][$key] ?? [
|
||||||
$report['accounts'][$key] = [
|
|
||||||
'id' => $sourceId,
|
'id' => $sourceId,
|
||||||
'name' => $journal['destination_account_name'],
|
'name' => $journal['destination_account_name'],
|
||||||
'sum' => '0',
|
'sum' => '0',
|
||||||
@ -234,8 +234,10 @@ class AccountTasker implements AccountTaskerInterface
|
|||||||
'currency_code' => $currencies[$currencyId]->code,
|
'currency_code' => $currencies[$currencyId]->code,
|
||||||
'currency_decimal_places' => $currencies[$currencyId]->decimal_places,
|
'currency_decimal_places' => $currencies[$currencyId]->decimal_places,
|
||||||
];
|
];
|
||||||
}
|
|
||||||
$report['accounts'][$key]['sum'] = bcadd($report['accounts'][$key]['sum'], $journal['amount']);
|
$report['accounts'][$key]['sum'] = bcadd($report['accounts'][$key]['sum'], $journal['amount']);
|
||||||
|
|
||||||
|
Log::debug(sprintf('Sum for %s is now %s', $journal['destination_account_name'], $report['accounts'][$key]['sum']));
|
||||||
|
|
||||||
++$report['accounts'][$key]['count'];
|
++$report['accounts'][$key]['count'];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -113,8 +113,6 @@ trait ChartGeneration
|
|||||||
* @param Carbon $end
|
* @param Carbon $end
|
||||||
*
|
*
|
||||||
* @return array
|
* @return array
|
||||||
*
|
|
||||||
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
|
|
||||||
*/
|
*/
|
||||||
protected function getChartData(Collection $accounts, Carbon $start, Carbon $end): array // chart helper function
|
protected function getChartData(Collection $accounts, Carbon $start, Carbon $end): array // chart helper function
|
||||||
{
|
{
|
||||||
@ -138,25 +136,24 @@ trait ChartGeneration
|
|||||||
$currentEnd = app('navigation')->endOfPeriod($currentStart, '1M');
|
$currentEnd = app('navigation')->endOfPeriod($currentStart, '1M');
|
||||||
$earned = (string)array_sum(
|
$earned = (string)array_sum(
|
||||||
array_map(
|
array_map(
|
||||||
function ($item) {
|
static function ($item) {
|
||||||
return $item['sum'];
|
return $item['sum'];
|
||||||
},
|
},
|
||||||
$tasker->getIncomeReport($currentStart, $currentEnd, $accounts)
|
$tasker->getIncomeReport($currentStart, $currentEnd, $accounts)['accounts']
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
$spent = (string)array_sum(
|
$spent = (string)array_sum(
|
||||||
array_map(
|
array_map(
|
||||||
function ($item) {
|
static function ($item) {
|
||||||
return $item['sum'];
|
return $item['sum'];
|
||||||
},
|
},
|
||||||
$tasker->getExpenseReport($currentStart, $currentEnd, $accounts)
|
$tasker->getExpenseReport($currentStart, $currentEnd, $accounts)['accounts']
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
$label = $currentStart->format('Y-m') . '-01';
|
$label = $currentStart->format('Y-m') . '-01';
|
||||||
$spentArray[$label] = bcmul($spent, '-1');
|
$spentArray[$label] = bcmul($spent, '-1');
|
||||||
$earnedArray[$label] = $earned;
|
$earnedArray[$label] = bcmul($earned, '-1');
|
||||||
$currentStart = app('navigation')->addPeriod($currentStart, '1M', 0);
|
$currentStart = app('navigation')->addPeriod($currentStart, '1M', 0);
|
||||||
}
|
}
|
||||||
$result = [
|
$result = [
|
||||||
|
@ -220,7 +220,7 @@
|
|||||||
var budgetPeriodReportUri = '{{ route('report-data.budget.period', [accountIds, start.format('Ymd'), end.format('Ymd')]) }}';
|
var budgetPeriodReportUri = '{{ route('report-data.budget.period', [accountIds, start.format('Ymd'), end.format('Ymd')]) }}';
|
||||||
var categoryExpenseUri = '{{ route('report-data.category.expenses', [accountIds, start.format('Ymd'), end.format('Ymd')]) }}';
|
var categoryExpenseUri = '{{ route('report-data.category.expenses', [accountIds, start.format('Ymd'), end.format('Ymd')]) }}';
|
||||||
var categoryIncomeUri = '{{ route('report-data.category.income', [accountIds, start.format('Ymd'), end.format('Ymd')]) }}';
|
var categoryIncomeUri = '{{ route('report-data.category.income', [accountIds, start.format('Ymd'), end.format('Ymd')]) }}';
|
||||||
|
var billReportUri = '';
|
||||||
|
|
||||||
</script>
|
</script>
|
||||||
<script type="text/javascript" src="v1/js/ff/reports/all.js?v={{ FF_VERSION }}"></script>
|
<script type="text/javascript" src="v1/js/ff/reports/all.js?v={{ FF_VERSION }}"></script>
|
||||||
|
Loading…
Reference in New Issue
Block a user