mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-09-25 06:51:08 +00:00
make sure reports work as expected.
This commit is contained in:
@@ -74,7 +74,7 @@ class MonthReportGenerator extends Support implements ReportGeneratorInterface
|
|||||||
$reportType = 'category';
|
$reportType = 'category';
|
||||||
$expenses = $this->getExpenses();
|
$expenses = $this->getExpenses();
|
||||||
$income = $this->getIncome();
|
$income = $this->getIncome();
|
||||||
$accountSummary = $this->getObjectSummary($this->summarizeByAccount($expenses), $this->summarizeByAccount($income));
|
$accountSummary = $this->getObjectSummary($this->summarizeByAssetAccount($expenses), $this->summarizeByAssetAccount($income));
|
||||||
$categorySummary = $this->getObjectSummary($this->summarizeByCategory($expenses), $this->summarizeByCategory($income));
|
$categorySummary = $this->getObjectSummary($this->summarizeByCategory($expenses), $this->summarizeByCategory($income));
|
||||||
$averageExpenses = $this->getAverages($expenses, SORT_ASC);
|
$averageExpenses = $this->getAverages($expenses, SORT_ASC);
|
||||||
$averageIncome = $this->getAverages($income, SORT_DESC);
|
$averageIncome = $this->getAverages($income, SORT_DESC);
|
||||||
|
@@ -24,7 +24,7 @@ declare(strict_types=1);
|
|||||||
|
|
||||||
namespace FireflyIII\Generator\Report;
|
namespace FireflyIII\Generator\Report;
|
||||||
|
|
||||||
use Illuminate\Support\Collection;
|
use FireflyIII\Models\TransactionType;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class Support.
|
* Class Support.
|
||||||
@@ -146,6 +146,7 @@ class Support
|
|||||||
* @var string $entry
|
* @var string $entry
|
||||||
*/
|
*/
|
||||||
foreach ($earned as $objectId => $entry) {
|
foreach ($earned as $objectId => $entry) {
|
||||||
|
$entry = bcmul($entry, '-1');
|
||||||
if (!isset($return[$objectId])) {
|
if (!isset($return[$objectId])) {
|
||||||
$return[$objectId] = ['spent' => '0', 'earned' => '0'];
|
$return[$objectId] = ['spent' => '0', 'earned' => '0'];
|
||||||
}
|
}
|
||||||
@@ -176,4 +177,36 @@ class Support
|
|||||||
|
|
||||||
return $result;
|
return $result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Summarize the data by the asset account or liability, depending on the type.
|
||||||
|
*
|
||||||
|
* In case of transfers, it will choose the source account.
|
||||||
|
*
|
||||||
|
* @param array $array
|
||||||
|
*
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
protected function summarizeByAssetAccount(array $array): array
|
||||||
|
{
|
||||||
|
$result = [];
|
||||||
|
/** @var array $journal */
|
||||||
|
foreach ($array as $journal) {
|
||||||
|
$accountId = 0;
|
||||||
|
switch ($journal['transaction_type_type']) {
|
||||||
|
case TransactionType::WITHDRAWAL:
|
||||||
|
case TransactionType::TRANSFER:
|
||||||
|
$accountId = $journal['source_account_id'] ?? 0;
|
||||||
|
break;
|
||||||
|
case TransactionType::DEPOSIT:
|
||||||
|
$accountId = $journal['destination_account_id'] ?? 0;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
$result[$accountId] = $result[$accountId] ?? '0';
|
||||||
|
$result[$accountId] = bcadd($journal['amount'], $result[$accountId]);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $result;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@@ -24,11 +24,7 @@ declare(strict_types=1);
|
|||||||
namespace FireflyIII\Helpers\Chart;
|
namespace FireflyIII\Helpers\Chart;
|
||||||
|
|
||||||
use Carbon\Carbon;
|
use Carbon\Carbon;
|
||||||
use FireflyIII\Helpers\Collector\TransactionCollectorInterface;
|
use FireflyIII\Helpers\Collector\GroupCollectorInterface;
|
||||||
use FireflyIII\Helpers\Filter\NegativeAmountFilter;
|
|
||||||
use FireflyIII\Helpers\Filter\OpposingAccountFilter;
|
|
||||||
use FireflyIII\Helpers\Filter\PositiveAmountFilter;
|
|
||||||
use FireflyIII\Helpers\Filter\TransferFilter;
|
|
||||||
use FireflyIII\Models\Tag;
|
use FireflyIII\Models\Tag;
|
||||||
use FireflyIII\Models\Transaction;
|
use FireflyIII\Models\Transaction;
|
||||||
use FireflyIII\Models\TransactionType;
|
use FireflyIII\Models\TransactionType;
|
||||||
@@ -48,9 +44,9 @@ class MetaPieChart implements MetaPieChartInterface
|
|||||||
/** @var array The ways to group transactions, given the type of chart. */
|
/** @var array The ways to group transactions, given the type of chart. */
|
||||||
static protected $grouping
|
static protected $grouping
|
||||||
= [
|
= [
|
||||||
'account' => ['opposing_account_id'],
|
'account' => ['destination_account_id'],
|
||||||
'budget' => ['transaction_journal_budget_id', 'transaction_budget_id'],
|
'budget' => ['budget_id'],
|
||||||
'category' => ['transaction_journal_category_id', 'transaction_category_id'],
|
'category' => ['category_id'],
|
||||||
'tag' => [],
|
'tag' => [],
|
||||||
];
|
];
|
||||||
/** @var Collection Involved accounts. */
|
/** @var Collection Involved accounts. */
|
||||||
@@ -114,25 +110,29 @@ class MetaPieChart implements MetaPieChartInterface
|
|||||||
|
|
||||||
// also collect all other transactions
|
// also collect all other transactions
|
||||||
if ($this->collectOtherObjects && 'expense' === $direction) {
|
if ($this->collectOtherObjects && 'expense' === $direction) {
|
||||||
/** @var TransactionCollectorInterface $collector */
|
|
||||||
$collector = app(TransactionCollectorInterface::class);
|
/** @var GroupCollectorInterface $collector */
|
||||||
|
$collector = app(GroupCollectorInterface::class);
|
||||||
|
|
||||||
$collector->setUser($this->user);
|
$collector->setUser($this->user);
|
||||||
$collector->setAccounts($this->accounts)->setRange($this->start, $this->end)->setTypes([TransactionType::WITHDRAWAL]);
|
$collector->setAccounts($this->accounts)->setRange($this->start, $this->end)->setTypes([TransactionType::WITHDRAWAL]);
|
||||||
|
|
||||||
$journals = $collector->getTransactions();
|
$journals = $collector->getExtractedJournals();
|
||||||
$sum = (string)$journals->sum('transaction_amount');
|
$sum = $this->sumJournals($journals);
|
||||||
$sum = bcmul($sum, '-1');
|
$sum = bcmul($sum, '-1');
|
||||||
$sum = bcsub($sum, $this->total);
|
$sum = bcsub($sum, $this->total);
|
||||||
$chartData[$key] = $sum;
|
$chartData[$key] = $sum;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($this->collectOtherObjects && 'income' === $direction) {
|
if ($this->collectOtherObjects && 'income' === $direction) {
|
||||||
/** @var TransactionCollectorInterface $collector */
|
|
||||||
$collector = app(TransactionCollectorInterface::class);
|
/** @var GroupCollectorInterface $collector */
|
||||||
|
$collector = app(GroupCollectorInterface::class);
|
||||||
|
|
||||||
$collector->setUser($this->user);
|
$collector->setUser($this->user);
|
||||||
$collector->setAccounts($this->accounts)->setRange($this->start, $this->end)->setTypes([TransactionType::DEPOSIT]);
|
$collector->setAccounts($this->accounts)->setRange($this->start, $this->end)->setTypes([TransactionType::DEPOSIT]);
|
||||||
$journals = $collector->getTransactions();
|
$journals = $collector->getExtractedJournals();
|
||||||
$sum = (string)$journals->sum('transaction_amount');
|
$sum = $this->sumJournals($journals);
|
||||||
$sum = bcsub($sum, $this->total);
|
$sum = bcsub($sum, $this->total);
|
||||||
$chartData[$key] = $sum;
|
$chartData[$key] = $sum;
|
||||||
}
|
}
|
||||||
@@ -140,6 +140,152 @@ class MetaPieChart implements MetaPieChartInterface
|
|||||||
return $chartData;
|
return $chartData;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get all transactions.
|
||||||
|
*
|
||||||
|
* @param string $direction
|
||||||
|
*
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
protected function getTransactions(string $direction): array
|
||||||
|
{
|
||||||
|
/** @var GroupCollectorInterface $collector */
|
||||||
|
$collector = app(GroupCollectorInterface::class);
|
||||||
|
|
||||||
|
$types = [TransactionType::DEPOSIT, TransactionType::TRANSFER];
|
||||||
|
if ('expense' === $direction) {
|
||||||
|
$types = [TransactionType::WITHDRAWAL, TransactionType::TRANSFER];
|
||||||
|
}
|
||||||
|
|
||||||
|
$collector->setUser($this->user);
|
||||||
|
$collector->setAccounts($this->accounts);
|
||||||
|
$collector->setRange($this->start, $this->end);
|
||||||
|
$collector->setTypes($types);
|
||||||
|
$collector->withAccountInformation();
|
||||||
|
|
||||||
|
$collector->setBudgets($this->budgets);
|
||||||
|
$collector->setCategories($this->categories);
|
||||||
|
|
||||||
|
$collector->withCategoryInformation();
|
||||||
|
$collector->withBudgetInformation();
|
||||||
|
|
||||||
|
// @codeCoverageIgnoreStart
|
||||||
|
if ($this->tags->count() > 0) {
|
||||||
|
$collector->setTags($this->tags);
|
||||||
|
}
|
||||||
|
|
||||||
|
// @codeCoverageIgnoreEnd
|
||||||
|
|
||||||
|
return $collector->getExtractedJournals();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Group by a specific field.
|
||||||
|
*
|
||||||
|
* @param array $array
|
||||||
|
* @param array $fields
|
||||||
|
*
|
||||||
|
* @return array
|
||||||
|
*
|
||||||
|
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
protected function groupByFields(array $array, array $fields): array
|
||||||
|
{
|
||||||
|
$grouped = [];
|
||||||
|
if (0 === count($fields) && $this->tags->count() > 0) {
|
||||||
|
// do a special group on tags:
|
||||||
|
$grouped = $this->groupByTag($array); // @codeCoverageIgnore
|
||||||
|
}
|
||||||
|
|
||||||
|
if (0 !== count($fields) || $this->tags->count() <= 0) {
|
||||||
|
$grouped = [];
|
||||||
|
/** @var array $journal */
|
||||||
|
foreach ($array as $journal) {
|
||||||
|
$values = [];
|
||||||
|
foreach ($fields as $field) {
|
||||||
|
$values[] = (int)$journal[$field];
|
||||||
|
}
|
||||||
|
$value = max($values);
|
||||||
|
$grouped[$value] = $grouped[$value] ?? '0';
|
||||||
|
$grouped[$value] = bcadd($journal['amount'], $grouped[$value]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return $grouped;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Group by tag (slightly different).
|
||||||
|
*
|
||||||
|
* @codeCoverageIgnore
|
||||||
|
*
|
||||||
|
* @param Collection $set
|
||||||
|
*
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
private function groupByTag(Collection $set): array
|
||||||
|
{
|
||||||
|
$grouped = [];
|
||||||
|
/** @var Transaction $transaction */
|
||||||
|
foreach ($set as $transaction) {
|
||||||
|
$journal = $transaction->transactionJournal;
|
||||||
|
$tags = $journal->tags;
|
||||||
|
/** @var Tag $tag */
|
||||||
|
foreach ($tags as $tag) {
|
||||||
|
$tagId = $tag->id;
|
||||||
|
$grouped[$tagId] = $grouped[$tagId] ?? '0';
|
||||||
|
$grouped[$tagId] = bcadd($transaction->transaction_amount, $grouped[$tagId]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return $grouped;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Organise by certain type.
|
||||||
|
*
|
||||||
|
* @param string $type
|
||||||
|
* @param array $array
|
||||||
|
*
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
protected function organizeByType(string $type, array $array): array
|
||||||
|
{
|
||||||
|
$chartData = [];
|
||||||
|
$names = [];
|
||||||
|
$repository = app($this->repositories[$type]);
|
||||||
|
$repository->setUser($this->user);
|
||||||
|
foreach ($array as $objectId => $amount) {
|
||||||
|
if (!isset($names[$objectId])) {
|
||||||
|
$object = $repository->findNull((int)$objectId);
|
||||||
|
$name = null === $object ? '(no name)' : $object->name;
|
||||||
|
$names[$objectId] = $name ?? $object->tag;
|
||||||
|
}
|
||||||
|
$amount = app('steam')->positive($amount);
|
||||||
|
$this->total = bcadd($this->total, $amount);
|
||||||
|
$chartData[$names[$objectId]] = $amount;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $chartData;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param array $journals
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
private function sumJournals(array $journals): string
|
||||||
|
{
|
||||||
|
$sum = '0';
|
||||||
|
/** @var array $journal */
|
||||||
|
foreach ($journals as $journal) {
|
||||||
|
$amount = (string)$journal['amount'];
|
||||||
|
$sum = bcadd($sum, $amount);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $sum;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Accounts setter.
|
* Accounts setter.
|
||||||
*
|
*
|
||||||
@@ -267,140 +413,4 @@ class MetaPieChart implements MetaPieChartInterface
|
|||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Get all transactions.
|
|
||||||
*
|
|
||||||
* @param string $direction
|
|
||||||
*
|
|
||||||
* @return Collection
|
|
||||||
*/
|
|
||||||
protected function getTransactions(string $direction): Collection
|
|
||||||
{
|
|
||||||
/** @var TransactionCollectorInterface $collector */
|
|
||||||
$collector = app(TransactionCollectorInterface::class);
|
|
||||||
$types = [TransactionType::DEPOSIT, TransactionType::TRANSFER];
|
|
||||||
$collector->addFilter(NegativeAmountFilter::class);
|
|
||||||
if ('expense' === $direction) {
|
|
||||||
$types = [TransactionType::WITHDRAWAL, TransactionType::TRANSFER];
|
|
||||||
$collector->addFilter(PositiveAmountFilter::class);
|
|
||||||
$collector->removeFilter(NegativeAmountFilter::class);
|
|
||||||
}
|
|
||||||
|
|
||||||
$collector->setUser($this->user);
|
|
||||||
$collector->setAccounts($this->accounts);
|
|
||||||
$collector->setRange($this->start, $this->end);
|
|
||||||
$collector->setTypes($types);
|
|
||||||
$collector->withOpposingAccount();
|
|
||||||
$collector->addFilter(OpposingAccountFilter::class);
|
|
||||||
|
|
||||||
if ('income' === $direction) {
|
|
||||||
$collector->removeFilter(TransferFilter::class);
|
|
||||||
}
|
|
||||||
|
|
||||||
$collector->setBudgets($this->budgets);
|
|
||||||
$collector->setCategories($this->categories);
|
|
||||||
|
|
||||||
// @codeCoverageIgnoreStart
|
|
||||||
if ($this->tags->count() > 0) {
|
|
||||||
$collector->setTags($this->tags);
|
|
||||||
$collector->withCategoryInformation();
|
|
||||||
$collector->withBudgetInformation();
|
|
||||||
}
|
|
||||||
|
|
||||||
// @codeCoverageIgnoreEnd
|
|
||||||
|
|
||||||
return $collector->getTransactions();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Group by a specific field.
|
|
||||||
*
|
|
||||||
* @param Collection $set
|
|
||||||
* @param array $fields
|
|
||||||
*
|
|
||||||
* @return array
|
|
||||||
*
|
|
||||||
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
protected function groupByFields(Collection $set, array $fields): array
|
|
||||||
{
|
|
||||||
$grouped = [];
|
|
||||||
if (0 === \count($fields) && $this->tags->count() > 0) {
|
|
||||||
// do a special group on tags:
|
|
||||||
$grouped = $this->groupByTag($set); // @codeCoverageIgnore
|
|
||||||
}
|
|
||||||
|
|
||||||
if (0 !== \count($fields) || $this->tags->count() <= 0) {
|
|
||||||
$grouped = [];
|
|
||||||
/** @var Transaction $transaction */
|
|
||||||
foreach ($set as $transaction) {
|
|
||||||
$values = [];
|
|
||||||
foreach ($fields as $field) {
|
|
||||||
$values[] = (int)$transaction->$field;
|
|
||||||
}
|
|
||||||
$value = max($values);
|
|
||||||
$grouped[$value] = $grouped[$value] ?? '0';
|
|
||||||
$grouped[$value] = bcadd($transaction->transaction_amount, $grouped[$value]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return $grouped;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Organise by certain type.
|
|
||||||
*
|
|
||||||
* @param string $type
|
|
||||||
* @param array $array
|
|
||||||
*
|
|
||||||
* @return array
|
|
||||||
*/
|
|
||||||
protected function organizeByType(string $type, array $array): array
|
|
||||||
{
|
|
||||||
$chartData = [];
|
|
||||||
$names = [];
|
|
||||||
$repository = app($this->repositories[$type]);
|
|
||||||
$repository->setUser($this->user);
|
|
||||||
foreach ($array as $objectId => $amount) {
|
|
||||||
if (!isset($names[$objectId])) {
|
|
||||||
$object = $repository->findNull((int)$objectId);
|
|
||||||
$name = null === $object ? '(no name)' : $object->name;
|
|
||||||
$names[$objectId] = $name ?? $object->tag;
|
|
||||||
}
|
|
||||||
$amount = app('steam')->positive($amount);
|
|
||||||
$this->total = bcadd($this->total, $amount);
|
|
||||||
$chartData[$names[$objectId]] = $amount;
|
|
||||||
}
|
|
||||||
|
|
||||||
return $chartData;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Group by tag (slightly different).
|
|
||||||
*
|
|
||||||
* @codeCoverageIgnore
|
|
||||||
*
|
|
||||||
* @param Collection $set
|
|
||||||
*
|
|
||||||
* @return array
|
|
||||||
*/
|
|
||||||
private function groupByTag(Collection $set): array
|
|
||||||
{
|
|
||||||
$grouped = [];
|
|
||||||
/** @var Transaction $transaction */
|
|
||||||
foreach ($set as $transaction) {
|
|
||||||
$journal = $transaction->transactionJournal;
|
|
||||||
$tags = $journal->tags;
|
|
||||||
/** @var Tag $tag */
|
|
||||||
foreach ($tags as $tag) {
|
|
||||||
$tagId = $tag->id;
|
|
||||||
$grouped[$tagId] = $grouped[$tagId] ?? '0';
|
|
||||||
$grouped[$tagId] = bcadd($transaction->transaction_amount, $grouped[$tagId]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return $grouped;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@@ -24,6 +24,7 @@ declare(strict_types=1);
|
|||||||
namespace FireflyIII\Helpers\Collector;
|
namespace FireflyIII\Helpers\Collector;
|
||||||
|
|
||||||
use Carbon\Carbon;
|
use Carbon\Carbon;
|
||||||
|
use Carbon\Exceptions\InvalidDateException;
|
||||||
use Exception;
|
use Exception;
|
||||||
use FireflyIII\Models\Bill;
|
use FireflyIII\Models\Bill;
|
||||||
use FireflyIII\Models\Budget;
|
use FireflyIII\Models\Budget;
|
||||||
@@ -37,8 +38,7 @@ use Illuminate\Database\Eloquent\Relations\HasMany;
|
|||||||
use Illuminate\Database\Query\JoinClause;
|
use Illuminate\Database\Query\JoinClause;
|
||||||
use Illuminate\Pagination\LengthAwarePaginator;
|
use Illuminate\Pagination\LengthAwarePaginator;
|
||||||
use Illuminate\Support\Collection;
|
use Illuminate\Support\Collection;
|
||||||
use function count;
|
use Log;
|
||||||
use function get_class;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class GroupCollector
|
* Class GroupCollector
|
||||||
@@ -226,16 +226,28 @@ class GroupCollector implements GroupCollectorInterface
|
|||||||
{
|
{
|
||||||
$result = $augmentedGroup->toArray();
|
$result = $augmentedGroup->toArray();
|
||||||
$result['tags'] = [];
|
$result['tags'] = [];
|
||||||
$result['tag_ids'] = [];
|
|
||||||
$result['date'] = new Carbon($result['date']);
|
$result['date'] = new Carbon($result['date']);
|
||||||
$result['created_at'] = new Carbon($result['created_at']);
|
$result['created_at'] = new Carbon($result['created_at']);
|
||||||
$result['updated_at'] = new Carbon($result['updated_at']);
|
$result['updated_at'] = new Carbon($result['updated_at']);
|
||||||
$result['reconciled'] = 1 === (int)$result['reconciled'];
|
$result['reconciled'] = 1 === (int)$result['reconciled'];
|
||||||
if (isset($augmentedGroup['tag'])) {
|
if (isset($augmentedGroup['tag_id'])) { // assume the other fields are present as well.
|
||||||
$result['tags'][] = $augmentedGroup['tag'];
|
$tagId = (int)$augmentedGroup['tag_id'];
|
||||||
|
$tagDate = null;
|
||||||
|
try {
|
||||||
|
$tagDate = Carbon::parse($augmentedGroup['tag_date']);
|
||||||
|
} catch (InvalidDateException $e) {
|
||||||
|
Log::debug(sprintf('Could not parse date: %s', $e->getMessage()));
|
||||||
}
|
}
|
||||||
if (isset($augmentedGroup['tag_id'])) {
|
|
||||||
$result['tag_ids'][] = $augmentedGroup['tag_id'];
|
$result['tags'][$tagId] = [
|
||||||
|
'id' => (int)$result['tag_id'],
|
||||||
|
'name' => $result['tag_name'],
|
||||||
|
'date' => $tagDate,
|
||||||
|
'description' => $result['tag_description'],
|
||||||
|
'latitude' => $result['tag_latitude'],
|
||||||
|
'longitude' => $result['tag_longitude'],
|
||||||
|
'zoom_level' => $result['tag_zoom_level'],
|
||||||
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
return $result;
|
return $result;
|
||||||
@@ -249,15 +261,26 @@ class GroupCollector implements GroupCollectorInterface
|
|||||||
private function mergeTags(array $existingJournal, TransactionGroup $newGroup): array
|
private function mergeTags(array $existingJournal, TransactionGroup $newGroup): array
|
||||||
{
|
{
|
||||||
$newArray = $newGroup->toArray();
|
$newArray = $newGroup->toArray();
|
||||||
if (isset($newArray['tag_id'])) {
|
if (isset($newArray['tag_id'])) { // assume the other fields are present as well.
|
||||||
$existingJournal['tag_ids'][] = (int)$newArray['tag_id'];
|
$tagId = (int)$newGroup['tag_id'];
|
||||||
}
|
|
||||||
if (isset($newArray['tag'])) {
|
|
||||||
$existingJournal['tags'][] = $newArray['tag'];
|
|
||||||
|
|
||||||
|
$tagDate = null;
|
||||||
|
try {
|
||||||
|
$tagDate = Carbon::parse($newArray['tag_date']);
|
||||||
|
} catch (InvalidDateException $e) {
|
||||||
|
Log::debug(sprintf('Could not parse date: %s', $e->getMessage()));
|
||||||
|
}
|
||||||
|
|
||||||
|
$existingJournal['tags'][$tagId] = [
|
||||||
|
'id' => (int)$newArray['tag_id'],
|
||||||
|
'name' => $newArray['tag_name'],
|
||||||
|
'date' => $tagDate,
|
||||||
|
'description' => $newArray['tag_description'],
|
||||||
|
'latitude' => $newArray['tag_latitude'],
|
||||||
|
'longitude' => $newArray['tag_longitude'],
|
||||||
|
'zoom_level' => $newArray['tag_zoom_level'],
|
||||||
|
];
|
||||||
}
|
}
|
||||||
$existingJournal['tags'] = array_unique($existingJournal['tags']);
|
|
||||||
$existingJournal['tag_ids'] = array_unique($existingJournal['tag_ids']);
|
|
||||||
|
|
||||||
return $existingJournal;
|
return $existingJournal;
|
||||||
}
|
}
|
||||||
@@ -403,8 +426,10 @@ class GroupCollector implements GroupCollectorInterface
|
|||||||
*/
|
*/
|
||||||
public function setBudgets(Collection $budgets): GroupCollectorInterface
|
public function setBudgets(Collection $budgets): GroupCollectorInterface
|
||||||
{
|
{
|
||||||
|
if ($budgets->count() > 0) {
|
||||||
$this->withBudgetInformation();
|
$this->withBudgetInformation();
|
||||||
$this->query->whereIn('budgets.id', $budgets->pluck('id')->toArray());
|
$this->query->whereIn('budgets.id', $budgets->pluck('id')->toArray());
|
||||||
|
}
|
||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
@@ -560,7 +585,12 @@ class GroupCollector implements GroupCollectorInterface
|
|||||||
$this->query->leftJoin('tag_transaction_journal', 'tag_transaction_journal.transaction_journal_id', '=', 'transaction_journals.id');
|
$this->query->leftJoin('tag_transaction_journal', 'tag_transaction_journal.transaction_journal_id', '=', 'transaction_journals.id');
|
||||||
$this->query->leftJoin('tags', 'tag_transaction_journal.tag_id', '=', 'tags.id');
|
$this->query->leftJoin('tags', 'tag_transaction_journal.tag_id', '=', 'tags.id');
|
||||||
$this->fields[] = 'tags.id as tag_id';
|
$this->fields[] = 'tags.id as tag_id';
|
||||||
$this->fields[] = 'tags.tag as tag';
|
$this->fields[] = 'tags.tag as tag_name';
|
||||||
|
$this->fields[] = 'tags.date as tag_date';
|
||||||
|
$this->fields[] = 'tags.description as tag_description';
|
||||||
|
$this->fields[] = 'tags.latitude as tag_latitude';
|
||||||
|
$this->fields[] = 'tags.longitude as tag_longitude';
|
||||||
|
$this->fields[] = 'tags.zoomLevel as tag_zoom_level';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -726,8 +756,10 @@ class GroupCollector implements GroupCollectorInterface
|
|||||||
*/
|
*/
|
||||||
public function setCategories(Collection $categories): GroupCollectorInterface
|
public function setCategories(Collection $categories): GroupCollectorInterface
|
||||||
{
|
{
|
||||||
|
if ($categories->count() > 0) {
|
||||||
$this->withCategoryInformation();
|
$this->withCategoryInformation();
|
||||||
$this->query->where('categories.id', $categories->pluck('id')->toArray());
|
$this->query->whereIn('categories.id', $categories->pluck('id')->toArray());
|
||||||
|
}
|
||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
@@ -24,7 +24,7 @@ namespace FireflyIII\Http\Controllers;
|
|||||||
|
|
||||||
use Carbon\Carbon;
|
use Carbon\Carbon;
|
||||||
use FireflyIII\Helpers\Attachments\AttachmentHelperInterface;
|
use FireflyIII\Helpers\Attachments\AttachmentHelperInterface;
|
||||||
use FireflyIII\Helpers\Collector\TransactionCollectorInterface;
|
use FireflyIII\Helpers\Collector\GroupCollectorInterface;
|
||||||
use FireflyIII\Http\Requests\BillFormRequest;
|
use FireflyIII\Http\Requests\BillFormRequest;
|
||||||
use FireflyIII\Models\Attachment;
|
use FireflyIII\Models\Attachment;
|
||||||
use FireflyIII\Models\Bill;
|
use FireflyIII\Models\Bill;
|
||||||
@@ -304,13 +304,12 @@ class BillController extends Controller
|
|||||||
$object = $manager->createData($resource)->toArray();
|
$object = $manager->createData($resource)->toArray();
|
||||||
$object['data']['currency'] = $bill->transactionCurrency;
|
$object['data']['currency'] = $bill->transactionCurrency;
|
||||||
|
|
||||||
// use collector:
|
/** @var GroupCollectorInterface $collector */
|
||||||
/** @var TransactionCollectorInterface $collector */
|
$collector = app(GroupCollectorInterface::class);
|
||||||
$collector = app(TransactionCollectorInterface::class);
|
$collector->setBill($bill)->setLimit($pageSize)->setPage($page)->withBudgetInformation()
|
||||||
$collector->setAllAssetAccounts()->setBills(new Collection([$bill]))->setLimit($pageSize)->setPage($page)->withBudgetInformation()
|
->withCategoryInformation()->withAccountInformation();
|
||||||
->withCategoryInformation();
|
$groups = $collector->getPaginatedGroups();
|
||||||
$transactions = $collector->getPaginatedTransactions();
|
$groups->setPath(route('bills.show', [$bill->id]));
|
||||||
$transactions->setPath(route('bills.show', [$bill->id]));
|
|
||||||
|
|
||||||
// transform any attachments as well.
|
// transform any attachments as well.
|
||||||
$collection = $this->billRepository->getAttachments($bill);
|
$collection = $this->billRepository->getAttachments($bill);
|
||||||
@@ -326,7 +325,7 @@ class BillController extends Controller
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
return view('bills.show', compact('attachments', 'transactions', 'rules', 'yearAverage', 'overallAverage', 'year', 'object', 'bill', 'subTitle'));
|
return view('bills.show', compact('attachments', 'groups', 'rules', 'yearAverage', 'overallAverage', 'year', 'object', 'bill', 'subTitle'));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@@ -152,7 +152,7 @@ class BudgetReportController extends Controller
|
|||||||
$cache->addProperty($start);
|
$cache->addProperty($start);
|
||||||
$cache->addProperty($end);
|
$cache->addProperty($end);
|
||||||
if ($cache->has()) {
|
if ($cache->has()) {
|
||||||
return response()->json($cache->get()); // @codeCoverageIgnore
|
//return response()->json($cache->get()); // @codeCoverageIgnore
|
||||||
}
|
}
|
||||||
$format = app('navigation')->preferredCarbonLocalizedFormat($start, $end);
|
$format = app('navigation')->preferredCarbonLocalizedFormat($start, $end);
|
||||||
$function = app('navigation')->preferredEndOfPeriod($start, $end);
|
$function = app('navigation')->preferredEndOfPeriod($start, $end);
|
||||||
|
@@ -207,7 +207,7 @@ class CategoryReportController extends Controller
|
|||||||
$cache->addProperty($start);
|
$cache->addProperty($start);
|
||||||
$cache->addProperty($end);
|
$cache->addProperty($end);
|
||||||
if ($cache->has()) {
|
if ($cache->has()) {
|
||||||
return response()->json($cache->get()); // @codeCoverageIgnore
|
//return response()->json($cache->get()); // @codeCoverageIgnore
|
||||||
}
|
}
|
||||||
|
|
||||||
$format = app('navigation')->preferredCarbonLocalizedFormat($start, $end);
|
$format = app('navigation')->preferredCarbonLocalizedFormat($start, $end);
|
||||||
@@ -261,7 +261,7 @@ class CategoryReportController extends Controller
|
|||||||
$labelOut = $category->id . '-out';
|
$labelOut = $category->id . '-out';
|
||||||
$labelSumIn = $category->id . '-total-in';
|
$labelSumIn = $category->id . '-total-in';
|
||||||
$labelSumOut = $category->id . '-total-out';
|
$labelSumOut = $category->id . '-total-out';
|
||||||
$currentIncome = $income[$category->id] ?? '0';
|
$currentIncome = bcmul($income[$category->id] ?? '0','-1');
|
||||||
$currentExpense = $expenses[$category->id] ?? '0';
|
$currentExpense = $expenses[$category->id] ?? '0';
|
||||||
|
|
||||||
// add to sum:
|
// add to sum:
|
||||||
@@ -279,6 +279,7 @@ class CategoryReportController extends Controller
|
|||||||
/** @var Carbon $currentStart */
|
/** @var Carbon $currentStart */
|
||||||
$currentStart = clone $currentEnd;
|
$currentStart = clone $currentEnd;
|
||||||
$currentStart->addDay();
|
$currentStart->addDay();
|
||||||
|
$currentStart->startOfDay();
|
||||||
}
|
}
|
||||||
// remove all empty entries to prevent cluttering:
|
// remove all empty entries to prevent cluttering:
|
||||||
$newSet = [];
|
$newSet = [];
|
||||||
@@ -287,7 +288,7 @@ class CategoryReportController extends Controller
|
|||||||
$newSet[$key] = $chartData[$key];
|
$newSet[$key] = $chartData[$key];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (0 === \count($newSet)) {
|
if (0 === count($newSet)) {
|
||||||
$newSet = $chartData;
|
$newSet = $chartData;
|
||||||
}
|
}
|
||||||
$data = $this->generator->multiSet($newSet);
|
$data = $this->generator->multiSet($newSet);
|
||||||
|
@@ -23,9 +23,9 @@ declare(strict_types=1);
|
|||||||
namespace FireflyIII\Http\Controllers;
|
namespace FireflyIII\Http\Controllers;
|
||||||
|
|
||||||
use Carbon\Carbon;
|
use Carbon\Carbon;
|
||||||
|
use Exception;
|
||||||
use FireflyIII\Events\RequestedVersionCheckStatus;
|
use FireflyIII\Events\RequestedVersionCheckStatus;
|
||||||
use FireflyIII\Helpers\Collector\GroupCollectorInterface;
|
use FireflyIII\Helpers\Collector\GroupCollectorInterface;
|
||||||
use FireflyIII\Helpers\Collector\TransactionCollectorInterface;
|
|
||||||
use FireflyIII\Http\Middleware\Installer;
|
use FireflyIII\Http\Middleware\Installer;
|
||||||
use FireflyIII\Models\AccountType;
|
use FireflyIII\Models\AccountType;
|
||||||
use FireflyIII\Repositories\Account\AccountRepositoryInterface;
|
use FireflyIII\Repositories\Account\AccountRepositoryInterface;
|
||||||
@@ -35,7 +35,7 @@ use Illuminate\Http\JsonResponse;
|
|||||||
use Illuminate\Http\Request;
|
use Illuminate\Http\Request;
|
||||||
use Illuminate\Support\Collection;
|
use Illuminate\Support\Collection;
|
||||||
use Log;
|
use Log;
|
||||||
use Exception;
|
|
||||||
/**
|
/**
|
||||||
* Class HomeController.
|
* Class HomeController.
|
||||||
*/
|
*/
|
||||||
@@ -56,8 +56,8 @@ class HomeController extends Controller
|
|||||||
* Change index date range.
|
* Change index date range.
|
||||||
*
|
*
|
||||||
* @param Request $request
|
* @param Request $request
|
||||||
* @throws Exception
|
|
||||||
* @return JsonResponse
|
* @return JsonResponse
|
||||||
|
* @throws Exception
|
||||||
*/
|
*/
|
||||||
public function dateRange(Request $request): JsonResponse
|
public function dateRange(Request $request): JsonResponse
|
||||||
{
|
{
|
||||||
@@ -97,8 +97,8 @@ class HomeController extends Controller
|
|||||||
* Show index.
|
* Show index.
|
||||||
*
|
*
|
||||||
* @param AccountRepositoryInterface $repository
|
* @param AccountRepositoryInterface $repository
|
||||||
* @throws Exception
|
|
||||||
* @return \Illuminate\Contracts\View\Factory|\Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector|\Illuminate\View\View
|
* @return \Illuminate\Contracts\View\Factory|\Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector|\Illuminate\View\View
|
||||||
|
* @throws Exception
|
||||||
*/
|
*/
|
||||||
public function index(AccountRepositoryInterface $repository)
|
public function index(AccountRepositoryInterface $repository)
|
||||||
{
|
{
|
||||||
|
@@ -44,8 +44,6 @@ use Illuminate\Support\Collection;
|
|||||||
*/
|
*/
|
||||||
trait AugumentData
|
trait AugumentData
|
||||||
{
|
{
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Searches for the opposing account.
|
* Searches for the opposing account.
|
||||||
*
|
*
|
||||||
@@ -388,6 +386,63 @@ trait AugumentData
|
|||||||
return $return;
|
return $return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* Returns an array with the following values:
|
||||||
|
* 0 =>
|
||||||
|
* 'name' => name of budget + repetition
|
||||||
|
* 'left' => left in budget repetition (always zero)
|
||||||
|
* 'overspent' => spent more than budget repetition? (always zero)
|
||||||
|
* 'spent' => actually spent in period for budget
|
||||||
|
* 1 => (etc)
|
||||||
|
*
|
||||||
|
* @param Budget $budget
|
||||||
|
* @param Collection $limits
|
||||||
|
*
|
||||||
|
* @return array
|
||||||
|
*
|
||||||
|
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
protected function spentInPeriodMulti(Budget $budget, Collection $limits): array // get data + augment with info
|
||||||
|
{
|
||||||
|
/** @var BudgetRepositoryInterface $repository */
|
||||||
|
$repository = app(BudgetRepositoryInterface::class);
|
||||||
|
|
||||||
|
$return = [];
|
||||||
|
$format = (string)trans('config.month_and_day');
|
||||||
|
$name = $budget->name;
|
||||||
|
/** @var BudgetLimit $budgetLimit */
|
||||||
|
foreach ($limits as $budgetLimit) {
|
||||||
|
$expenses = $repository->spentInPeriod(new Collection([$budget]), new Collection, $budgetLimit->start_date, $budgetLimit->end_date);
|
||||||
|
$expenses = app('steam')->positive($expenses);
|
||||||
|
|
||||||
|
if ($limits->count() > 1) {
|
||||||
|
$name = $budget->name . ' ' . trans(
|
||||||
|
'firefly.between_dates',
|
||||||
|
[
|
||||||
|
'start' => $budgetLimit->start_date->formatLocalized($format),
|
||||||
|
'end' => $budgetLimit->end_date->formatLocalized($format),
|
||||||
|
]
|
||||||
|
);
|
||||||
|
}
|
||||||
|
$amount = $budgetLimit->amount;
|
||||||
|
$leftInLimit = bcsub($amount, $expenses);
|
||||||
|
$hasOverspent = bccomp($leftInLimit, '0') === -1;
|
||||||
|
$left = $hasOverspent ? '0' : bcsub($amount, $expenses);
|
||||||
|
$spent = $hasOverspent ? $amount : $expenses;
|
||||||
|
$overspent = $hasOverspent ? app('steam')->positive($leftInLimit) : '0';
|
||||||
|
|
||||||
|
$return[$name] = [
|
||||||
|
'left' => $left,
|
||||||
|
'overspent' => $overspent,
|
||||||
|
'spent' => $spent,
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
return $return;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets all budget limits for a budget.
|
* Gets all budget limits for a budget.
|
||||||
*
|
*
|
||||||
@@ -425,25 +480,22 @@ trait AugumentData
|
|||||||
return $set;
|
return $set;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Helper function that groups expenses.
|
* Helper function that groups expenses.
|
||||||
*
|
*
|
||||||
* @param Collection $set
|
* @param array $array
|
||||||
*
|
*
|
||||||
* @return array
|
* @return array
|
||||||
*/
|
*/
|
||||||
protected function groupByBudget(Collection $set): array // filter + group data
|
protected function groupByBudget(array $array): array // filter + group data
|
||||||
{
|
{
|
||||||
// group by category ID:
|
// group by category ID:
|
||||||
$grouped = [];
|
$grouped = [];
|
||||||
/** @var Transaction $transaction */
|
/** @var array $journal */
|
||||||
foreach ($set as $transaction) {
|
foreach ($array as $journal) {
|
||||||
$jrnlBudId = (int)$transaction->transaction_journal_budget_id;
|
$budgetId = (int)$journal['budget_id'];
|
||||||
$transBudId = (int)$transaction->transaction_budget_id;
|
|
||||||
$budgetId = max($jrnlBudId, $transBudId);
|
|
||||||
$grouped[$budgetId] = $grouped[$budgetId] ?? '0';
|
$grouped[$budgetId] = $grouped[$budgetId] ?? '0';
|
||||||
$grouped[$budgetId] = bcadd($transaction->transaction_amount, $grouped[$budgetId]);
|
$grouped[$budgetId] = bcadd($journal['amount'], $grouped[$budgetId]);
|
||||||
}
|
}
|
||||||
|
|
||||||
return $grouped;
|
return $grouped;
|
||||||
@@ -452,21 +504,19 @@ trait AugumentData
|
|||||||
/**
|
/**
|
||||||
* Group transactions by category.
|
* Group transactions by category.
|
||||||
*
|
*
|
||||||
* @param Collection $set
|
* @param array $array
|
||||||
*
|
*
|
||||||
* @return array
|
* @return array
|
||||||
*/
|
*/
|
||||||
protected function groupByCategory(Collection $set): array // filter + group data
|
protected function groupByCategory(array $array): array // filter + group data
|
||||||
{
|
{
|
||||||
// group by category ID:
|
// group by category ID:
|
||||||
$grouped = [];
|
$grouped = [];
|
||||||
/** @var Transaction $transaction */
|
/** @var array $journal */
|
||||||
foreach ($set as $transaction) {
|
foreach($array as $journal) {
|
||||||
$jrnlCatId = (int)$transaction->transaction_journal_category_id;
|
$categoryId = (int)$journal['category_id'];
|
||||||
$transCatId = (int)$transaction->transaction_category_id;
|
|
||||||
$categoryId = max($jrnlCatId, $transCatId);
|
|
||||||
$grouped[$categoryId] = $grouped[$categoryId] ?? '0';
|
$grouped[$categoryId] = $grouped[$categoryId] ?? '0';
|
||||||
$grouped[$categoryId] = bcadd($transaction->transaction_amount, $grouped[$categoryId]);
|
$grouped[$categoryId] = bcadd($journal['amount'], $grouped[$categoryId]);
|
||||||
}
|
}
|
||||||
|
|
||||||
return $grouped;
|
return $grouped;
|
||||||
@@ -493,6 +543,10 @@ trait AugumentData
|
|||||||
return $grouped;
|
return $grouped;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/** @noinspection MoreThanThreeArgumentsInspection */
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Group transactions by tag.
|
* Group transactions by tag.
|
||||||
*
|
*
|
||||||
@@ -519,8 +573,6 @@ trait AugumentData
|
|||||||
return $grouped;
|
return $grouped;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/** @noinspection MoreThanThreeArgumentsInspection */
|
/** @noinspection MoreThanThreeArgumentsInspection */
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -698,65 +750,6 @@ trait AugumentData
|
|||||||
|
|
||||||
/** @noinspection MoreThanThreeArgumentsInspection */
|
/** @noinspection MoreThanThreeArgumentsInspection */
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* Returns an array with the following values:
|
|
||||||
* 0 =>
|
|
||||||
* 'name' => name of budget + repetition
|
|
||||||
* 'left' => left in budget repetition (always zero)
|
|
||||||
* 'overspent' => spent more than budget repetition? (always zero)
|
|
||||||
* 'spent' => actually spent in period for budget
|
|
||||||
* 1 => (etc)
|
|
||||||
*
|
|
||||||
* @param Budget $budget
|
|
||||||
* @param Collection $limits
|
|
||||||
*
|
|
||||||
* @return array
|
|
||||||
*
|
|
||||||
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
protected function spentInPeriodMulti(Budget $budget, Collection $limits): array // get data + augment with info
|
|
||||||
{
|
|
||||||
/** @var BudgetRepositoryInterface $repository */
|
|
||||||
$repository = app(BudgetRepositoryInterface::class);
|
|
||||||
|
|
||||||
$return = [];
|
|
||||||
$format = (string)trans('config.month_and_day');
|
|
||||||
$name = $budget->name;
|
|
||||||
/** @var BudgetLimit $budgetLimit */
|
|
||||||
foreach ($limits as $budgetLimit) {
|
|
||||||
$expenses = $repository->spentInPeriod(new Collection([$budget]), new Collection, $budgetLimit->start_date, $budgetLimit->end_date);
|
|
||||||
$expenses = app('steam')->positive($expenses);
|
|
||||||
|
|
||||||
if ($limits->count() > 1) {
|
|
||||||
$name = $budget->name . ' ' . trans(
|
|
||||||
'firefly.between_dates',
|
|
||||||
[
|
|
||||||
'start' => $budgetLimit->start_date->formatLocalized($format),
|
|
||||||
'end' => $budgetLimit->end_date->formatLocalized($format),
|
|
||||||
]
|
|
||||||
);
|
|
||||||
}
|
|
||||||
$amount = $budgetLimit->amount;
|
|
||||||
$leftInLimit = bcsub($amount, $expenses);
|
|
||||||
$hasOverspent = bccomp($leftInLimit, '0') === -1;
|
|
||||||
$left = $hasOverspent ? '0' : bcsub($amount, $expenses);
|
|
||||||
$spent = $hasOverspent ? $amount : $expenses;
|
|
||||||
$overspent = $hasOverspent ? app('steam')->positive($leftInLimit) : '0';
|
|
||||||
|
|
||||||
$return[$name] = [
|
|
||||||
'left' => $left,
|
|
||||||
'overspent' => $overspent,
|
|
||||||
'spent' => $spent,
|
|
||||||
];
|
|
||||||
}
|
|
||||||
|
|
||||||
return $return;
|
|
||||||
}
|
|
||||||
|
|
||||||
/** @noinspection MoreThanThreeArgumentsInspection */
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns an array with the following values:
|
* Returns an array with the following values:
|
||||||
* 'name' => "no budget" in local language
|
* 'name' => "no budget" in local language
|
||||||
|
@@ -24,11 +24,7 @@ declare(strict_types=1);
|
|||||||
namespace FireflyIII\Support\Http\Controllers;
|
namespace FireflyIII\Support\Http\Controllers;
|
||||||
|
|
||||||
use Carbon\Carbon;
|
use Carbon\Carbon;
|
||||||
use FireflyIII\Helpers\Collector\TransactionCollectorInterface;
|
use FireflyIII\Helpers\Collector\GroupCollectorInterface;
|
||||||
use FireflyIII\Helpers\Filter\NegativeAmountFilter;
|
|
||||||
use FireflyIII\Helpers\Filter\OpposingAccountFilter;
|
|
||||||
use FireflyIII\Helpers\Filter\PositiveAmountFilter;
|
|
||||||
use FireflyIII\Helpers\Filter\TransferFilter;
|
|
||||||
use FireflyIII\Models\TransactionType;
|
use FireflyIII\Models\TransactionType;
|
||||||
use Illuminate\Support\Collection;
|
use Illuminate\Support\Collection;
|
||||||
|
|
||||||
@@ -46,15 +42,18 @@ trait TransactionCalculation
|
|||||||
* @param Carbon $start
|
* @param Carbon $start
|
||||||
* @param Carbon $end
|
* @param Carbon $end
|
||||||
*
|
*
|
||||||
* @return Collection
|
* @return array
|
||||||
*/
|
*/
|
||||||
protected function getExpensesForOpposing(Collection $accounts, Collection $opposing, Carbon $start, Carbon $end): Collection // get data + augument
|
protected function getExpensesForOpposing(Collection $accounts, Collection $opposing, Carbon $start, Carbon $end): array
|
||||||
{
|
{
|
||||||
/** @var TransactionCollectorInterface $collector */
|
/** @var GroupCollectorInterface $collector */
|
||||||
$collector = app(TransactionCollectorInterface::class);
|
$collector = app(GroupCollectorInterface::class);
|
||||||
$collector->setAccounts($accounts)->setRange($start, $end)->setTypes([TransactionType::WITHDRAWAL])->setOpposingAccounts($opposing);
|
$collector->setAccounts($accounts)
|
||||||
|
->setRange($start, $end)
|
||||||
|
->setTypes([TransactionType::WITHDRAWAL])
|
||||||
|
->setAccounts($opposing);
|
||||||
|
|
||||||
return $collector->getTransactions();
|
return $collector->getExtractedJournals();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -65,21 +64,18 @@ trait TransactionCalculation
|
|||||||
* @param Carbon $start
|
* @param Carbon $start
|
||||||
* @param Carbon $end
|
* @param Carbon $end
|
||||||
*
|
*
|
||||||
* @return Collection
|
* @return array
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
protected function getExpensesForTags(Collection $accounts, Collection $tags, Carbon $start, Carbon $end): Collection // get data + augument
|
protected function getExpensesForTags(Collection $accounts, Collection $tags, Carbon $start, Carbon $end): array
|
||||||
{
|
{
|
||||||
/** @var TransactionCollectorInterface $collector */
|
/** @var GroupCollectorInterface $collector */
|
||||||
$collector = app(TransactionCollectorInterface::class);
|
$collector = app(GroupCollectorInterface::class);
|
||||||
|
|
||||||
$collector->setAccounts($accounts)->setRange($start, $end)->setTypes([TransactionType::WITHDRAWAL, TransactionType::TRANSFER])
|
$collector->setAccounts($accounts)->setRange($start, $end)->setTypes([TransactionType::WITHDRAWAL, TransactionType::TRANSFER])
|
||||||
->setTags($tags)->withOpposingAccount();
|
->setTags($tags)->withAccountInformation();
|
||||||
$collector->removeFilter(TransferFilter::class);
|
|
||||||
|
|
||||||
$collector->addFilter(OpposingAccountFilter::class);
|
return $collector->getExtractedJournals();
|
||||||
$collector->addFilter(PositiveAmountFilter::class);
|
|
||||||
|
|
||||||
return $collector->getTransactions();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -90,20 +86,16 @@ trait TransactionCalculation
|
|||||||
* @param Carbon $start
|
* @param Carbon $start
|
||||||
* @param Carbon $end
|
* @param Carbon $end
|
||||||
*
|
*
|
||||||
* @return Collection
|
* @return array
|
||||||
*/
|
*/
|
||||||
protected function getExpensesInBudgets(Collection $accounts, Collection $budgets, Carbon $start, Carbon $end): Collection // get data + augment with info
|
protected function getExpensesInBudgets(Collection $accounts, Collection $budgets, Carbon $start, Carbon $end): array
|
||||||
{
|
{
|
||||||
/** @var TransactionCollectorInterface $collector */
|
/** @var GroupCollectorInterface $collector */
|
||||||
$collector = app(TransactionCollectorInterface::class);
|
$collector = app(GroupCollectorInterface::class);
|
||||||
$collector->setAccounts($accounts)->setRange($start, $end)->setTypes([TransactionType::WITHDRAWAL, TransactionType::TRANSFER])
|
$collector->setAccounts($accounts)->setRange($start, $end)->setTypes([TransactionType::WITHDRAWAL, TransactionType::TRANSFER])
|
||||||
->setBudgets($budgets)->withOpposingAccount();
|
->setBudgets($budgets)->withAccountInformation();
|
||||||
$collector->removeFilter(TransferFilter::class);
|
|
||||||
|
|
||||||
$collector->addFilter(OpposingAccountFilter::class);
|
return $collector->getExtractedJournals();
|
||||||
$collector->addFilter(PositiveAmountFilter::class);
|
|
||||||
|
|
||||||
return $collector->getTransactions();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -114,22 +106,22 @@ trait TransactionCalculation
|
|||||||
* @param Carbon $start
|
* @param Carbon $start
|
||||||
* @param Carbon $end
|
* @param Carbon $end
|
||||||
*
|
*
|
||||||
* @return Collection
|
* @return array
|
||||||
*
|
*
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
protected function getExpensesInCategories(Collection $accounts, Collection $categories, Carbon $start, Carbon $end): Collection // get data + augument
|
protected function getExpensesInCategories(Collection $accounts, Collection $categories, Carbon $start, Carbon $end): array
|
||||||
{
|
{
|
||||||
/** @var TransactionCollectorInterface $collector */
|
/** @var GroupCollectorInterface $collector */
|
||||||
$collector = app(TransactionCollectorInterface::class);
|
$collector = app(GroupCollectorInterface::class);
|
||||||
$collector->setAccounts($accounts)->setRange($start, $end)->setTypes([TransactionType::WITHDRAWAL, TransactionType::TRANSFER])
|
$collector
|
||||||
->setCategories($categories)->withOpposingAccount();
|
->setAccounts($accounts)
|
||||||
$collector->removeFilter(TransferFilter::class);
|
->setRange($start, $end)
|
||||||
|
->setTypes([TransactionType::WITHDRAWAL, TransactionType::TRANSFER])
|
||||||
|
->setCategories($categories)
|
||||||
|
->withAccountInformation();
|
||||||
|
|
||||||
$collector->addFilter(OpposingAccountFilter::class);
|
return $collector->getExtractedJournals();
|
||||||
$collector->addFilter(PositiveAmountFilter::class);
|
|
||||||
|
|
||||||
return $collector->getTransactions();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -140,19 +132,16 @@ trait TransactionCalculation
|
|||||||
* @param Carbon $start
|
* @param Carbon $start
|
||||||
* @param Carbon $end
|
* @param Carbon $end
|
||||||
*
|
*
|
||||||
* @return Collection
|
* @return array
|
||||||
*/
|
*/
|
||||||
protected function getIncomeForCategories(Collection $accounts, Collection $categories, Carbon $start, Carbon $end): Collection // get data + augument
|
protected function getIncomeForCategories(Collection $accounts, Collection $categories, Carbon $start, Carbon $end): array
|
||||||
{
|
{
|
||||||
/** @var TransactionCollectorInterface $collector */
|
/** @var GroupCollectorInterface $collector */
|
||||||
$collector = app(TransactionCollectorInterface::class);
|
$collector = app(GroupCollectorInterface::class);
|
||||||
$collector->setAccounts($accounts)->setRange($start, $end)->setTypes([TransactionType::DEPOSIT, TransactionType::TRANSFER])
|
$collector->setAccounts($accounts)->setRange($start, $end)->setTypes([TransactionType::DEPOSIT, TransactionType::TRANSFER])
|
||||||
->setCategories($categories)->withOpposingAccount();
|
->setCategories($categories)->withAccountInformation();
|
||||||
|
|
||||||
$collector->addFilter(OpposingAccountFilter::class);
|
return $collector->getExtractedJournals();
|
||||||
$collector->addFilter(NegativeAmountFilter::class);
|
|
||||||
|
|
||||||
return $collector->getTransactions();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -163,15 +152,16 @@ trait TransactionCalculation
|
|||||||
* @param Carbon $start
|
* @param Carbon $start
|
||||||
* @param Carbon $end
|
* @param Carbon $end
|
||||||
*
|
*
|
||||||
* @return Collection
|
* @return array
|
||||||
*/
|
*/
|
||||||
protected function getIncomeForOpposing(Collection $accounts, Collection $opposing, Carbon $start, Carbon $end): Collection // get data + augument
|
protected function getIncomeForOpposing(Collection $accounts, Collection $opposing, Carbon $start, Carbon $end): array
|
||||||
{
|
{
|
||||||
/** @var TransactionCollectorInterface $collector */
|
/** @var GroupCollectorInterface $collector */
|
||||||
$collector = app(TransactionCollectorInterface::class);
|
$collector = app(GroupCollectorInterface::class);
|
||||||
$collector->setAccounts($accounts)->setRange($start, $end)->setTypes([TransactionType::DEPOSIT])->setOpposingAccounts($opposing);
|
$collector->setAccounts($accounts)->setRange($start, $end)->setTypes([TransactionType::DEPOSIT])
|
||||||
|
->setAccounts($opposing);
|
||||||
|
|
||||||
return $collector->getTransactions();
|
return $collector->getExtractedJournals();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -186,17 +176,14 @@ trait TransactionCalculation
|
|||||||
*
|
*
|
||||||
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
|
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
|
||||||
*/
|
*/
|
||||||
protected function getIncomeForTags(Collection $accounts, Collection $tags, Carbon $start, Carbon $end): Collection // get data + augument
|
protected function getIncomeForTags(Collection $accounts, Collection $tags, Carbon $start, Carbon $end): array
|
||||||
{
|
{
|
||||||
/** @var TransactionCollectorInterface $collector */
|
/** @var GroupCollectorInterface $collector */
|
||||||
$collector = app(TransactionCollectorInterface::class);
|
$collector = app(GroupCollectorInterface::class);
|
||||||
$collector->setAccounts($accounts)->setRange($start, $end)->setTypes([TransactionType::DEPOSIT, TransactionType::TRANSFER])
|
$collector->setAccounts($accounts)->setRange($start, $end)->setTypes([TransactionType::DEPOSIT, TransactionType::TRANSFER])
|
||||||
->setTags($tags)->withOpposingAccount();
|
->setTags($tags)->withAccountInformation();
|
||||||
|
|
||||||
$collector->addFilter(OpposingAccountFilter::class);
|
return $collector->getExtractedJournals();
|
||||||
$collector->addFilter(NegativeAmountFilter::class);
|
|
||||||
|
|
||||||
return $collector->getTransactions();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@@ -163,7 +163,7 @@
|
|||||||
<h3 class="box-title">{{ 'connected_journals'|_ }}</h3>
|
<h3 class="box-title">{{ 'connected_journals'|_ }}</h3>
|
||||||
</div>
|
</div>
|
||||||
<div class="box-body">
|
<div class="box-body">
|
||||||
{% include 'list.transactions' with {showCategories: true, showBudgets: true} %}
|
{% include 'list.groups' %}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
@@ -230,7 +230,7 @@
|
|||||||
<tr>
|
<tr>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
<td data-sortable="false">
|
<td data-sortable="false">
|
||||||
<a href="{{ route('transactions.show', 1+row.transaction_group_id) }}">
|
<a href="{{ route('transactions.show', row.transaction_group_id) }}">
|
||||||
{% if row.group_title|length > 0 %}
|
{% if row.group_title|length > 0 %}
|
||||||
{{ row.group_title }} ({{ row.description }})
|
{{ row.group_title }} ({{ row.description }})
|
||||||
{% else %}
|
{% else %}
|
||||||
|
@@ -259,7 +259,7 @@
|
|||||||
<tbody>
|
<tbody>
|
||||||
{% set totalSum = 0 %}
|
{% set totalSum = 0 %}
|
||||||
{% for row in topExpenses %}
|
{% for row in topExpenses %}
|
||||||
{% set totalSum = totalSum + row.sum %}
|
{% set totalSum = totalSum + row.amount %}
|
||||||
{% if loop.index > listLength %}
|
{% if loop.index > listLength %}
|
||||||
<tr class="overListLength">
|
<tr class="overListLength">
|
||||||
{% else %}
|
{% else %}
|
||||||
@@ -338,10 +338,10 @@
|
|||||||
<a href="{{ route('accounts.show', row.id) }}">{{ row.name }}</a>
|
<a href="{{ route('accounts.show', row.id) }}">{{ row.name }}</a>
|
||||||
</td>
|
</td>
|
||||||
<td data-value="{{ row.average }}" style="text-align:right;">
|
<td data-value="{{ row.average }}" style="text-align:right;">
|
||||||
{{ row.average|formatAmount }}
|
{{ (row.average*-1)|formatAmount }}
|
||||||
</td>
|
</td>
|
||||||
<td data-value="{{ row.sum }}" style="text-align:right;">
|
<td data-value="{{ row.sum }}" style="text-align:right;">
|
||||||
{{ row.sum|formatAmount }}
|
{{ (row.sum*-1)|formatAmount }}
|
||||||
</td>
|
</td>
|
||||||
<td data-value="{{ row.count }}">
|
<td data-value="{{ row.count }}">
|
||||||
{{ row.count }}
|
{{ row.count }}
|
||||||
@@ -352,7 +352,7 @@
|
|||||||
<td colspan="2">
|
<td colspan="2">
|
||||||
{{ 'sum'|_ }}
|
{{ 'sum'|_ }}
|
||||||
</td>
|
</td>
|
||||||
<td style="text-align:right">{{ totalSum|formatAmount }}</td>
|
<td style="text-align:right">{{ (totalSum*-1)|formatAmount }}</td>
|
||||||
<td>{{ totalCount }}</td>
|
<td>{{ totalCount }}</td>
|
||||||
</tr>
|
</tr>
|
||||||
</tbody>
|
</tbody>
|
||||||
@@ -362,7 +362,7 @@
|
|||||||
</div>
|
</div>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
<div class="col-lg-6">
|
<div class="col-lg-6">
|
||||||
{% if topIncome.count > 0 %}
|
{% if topIncome|length > 0 %}
|
||||||
<div class="box">
|
<div class="box">
|
||||||
<div class="box-header with-border">
|
<div class="box-header with-border">
|
||||||
<h3 class="box-title">{{ 'income'|_ }} ({{ trans('firefly.topX', {number: listLength}) }})</h3>
|
<h3 class="box-title">{{ 'income'|_ }} ({{ trans('firefly.topX', {number: listLength}) }})</h3>
|
||||||
@@ -380,37 +380,37 @@
|
|||||||
<tbody>
|
<tbody>
|
||||||
{% set totalSum = 0 %}
|
{% set totalSum = 0 %}
|
||||||
{% for row in topIncome %}
|
{% for row in topIncome %}
|
||||||
{% set totalSum = totalSum + row.transaction_amount %}
|
{% set totalSum = totalSum + row.amount %}
|
||||||
{% if loop.index > listLength %}
|
{% if loop.index > listLength %}
|
||||||
<tr class="overListLength">
|
<tr class="overListLength">
|
||||||
{% else %}
|
{% else %}
|
||||||
<tr>
|
<tr>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
<td>
|
<td data-sortable="false">
|
||||||
<a href="{{ route('transactions.show', row.journal_id) }}">
|
<a href="{{ route('transactions.show', 1+row.transaction_group_id) }}">
|
||||||
{% if row.transaction_description|length > 0 %}
|
{% if row.group_title|length > 0 %}
|
||||||
{{ row.transaction_description }} ({{ row.description }})
|
{{ row.group_title }} ({{ row.description }})
|
||||||
{% else %}
|
{% else %}
|
||||||
{{ row.description }}
|
{{ row.description }}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
</a>
|
</a>
|
||||||
</td>
|
</td>
|
||||||
<td data-value="{{ row.date.format('Y-m-d H-i-s') }}">
|
<td data-value="{{ row.date.format('Y-m-d') }}">
|
||||||
{{ row.date.formatLocalized(monthAndDayFormat) }}
|
{{ row.date.formatLocalized(monthAndDayFormat) }}
|
||||||
</td>
|
</td>
|
||||||
<td data-value="{{ row.opposing_account_name }}">
|
<td data-value="{{ row.destination_account_name }}">
|
||||||
<a href="{{ route('accounts.show', row.opposing_account_id) }}">
|
<a href="{{ route('accounts.show', row.destination_account_id) }}">
|
||||||
{{ row.opposing_account_name }}
|
{{ row.destination_account_name }}
|
||||||
</a>
|
</a>
|
||||||
</td>
|
</td>
|
||||||
<td data-value="{{ row.transaction_amount }}" style="text-align:right">
|
<td data-value="{{ row.amount }}" style="text-align: right;">
|
||||||
{{ row.transaction_amount|formatAmount }}
|
{{ formatAmountBySymbol(row.amount*-1, row.currency_symbol, row.currency_symbol_decimal_places) }}
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</tbody>
|
</tbody>
|
||||||
<tfoot>
|
<tfoot>
|
||||||
{% if topIncome.count > listLength %}
|
{% if topIncome|length > listLength %}
|
||||||
<tr>
|
<tr>
|
||||||
<td colspan="3" class="active">
|
<td colspan="3" class="active">
|
||||||
<a href="#"
|
<a href="#"
|
||||||
@@ -422,7 +422,7 @@
|
|||||||
<td colspan="3">
|
<td colspan="3">
|
||||||
{{ 'sum'|_ }}
|
{{ 'sum'|_ }}
|
||||||
</td>
|
</td>
|
||||||
<td style="text-align:right">{{ totalSum|formatAmount }}</td>
|
<td style="text-align:right">{{ (totalSum*-1)|formatAmount }}</td>
|
||||||
</tr>
|
</tr>
|
||||||
</tfoot>
|
</tfoot>
|
||||||
</table>
|
</table>
|
||||||
|
Reference in New Issue
Block a user