Basic list, no functionalities.

This commit is contained in:
James Cole
2019-04-18 20:05:40 +02:00
parent 66c55b7bbe
commit 4d3af1dcde
15 changed files with 469 additions and 318 deletions

View File

@@ -24,6 +24,7 @@ declare(strict_types=1);
namespace FireflyIII\Support\Http\Controllers;
use Carbon\Carbon;
use FireflyIII\Helpers\Collector\GroupCollectorInterface;
use FireflyIII\Helpers\Collector\TransactionCollectorInterface;
use FireflyIII\Helpers\Filter\InternalTransferFilter;
use FireflyIII\Models\Account;
@@ -451,13 +452,12 @@ trait PeriodOverview
foreach ($dates as $currentDate) {
// get all expenses, income or transfers:
/** @var TransactionCollectorInterface $collector */
$collector = app(TransactionCollectorInterface::class);
$collector->setAllAssetAccounts()->setRange($currentDate['start'], $currentDate['end'])->withOpposingAccount()->setTypes($types);
$collector->removeFilter(InternalTransferFilter::class);
$transactions = $collector->getTransactions();
/** @var GroupCollectorInterface $collector */
$collector = app(GroupCollectorInterface::class);
$collector->setRange($currentDate['start'], $currentDate['end'])->withAccountInformation()->setTypes($types);
$journals = $collector->getExtractedJournals();
$title = app('navigation')->periodShow($currentDate['end'], $currentDate['period']);
$grouped = $this->groupByCurrency($transactions);
$grouped = $this->groupByCurrency($journals);
$spent = [];
$earned = [];
$transferred = [];
@@ -472,7 +472,7 @@ trait PeriodOverview
}
$entries->push(
[
'transactions' => $transactions->count(),
'transactions' => count($journals),
'title' => $title,
'spent' => $spent,
'earned' => $earned,
@@ -525,27 +525,27 @@ trait PeriodOverview
}
/**
* @param Collection $transactions
* @param array $journals
*
* @return array
*/
private function groupByCurrency(Collection $transactions): array
private function groupByCurrency(array $journals): array
{
$return = [];
/** @var Transaction $transaction */
foreach ($transactions as $transaction) {
$currencyId = (int)$transaction->transaction_currency_id;
/** @var array $journal */
foreach ($journals as $journal) {
$currencyId = (int)$journal['currency_id'];
if (!isset($return[$currencyId])) {
$currency = new TransactionCurrency;
$currency->symbol = $transaction->transaction_currency_symbol;
$currency->decimal_places = $transaction->transaction_currency_dp;
$currency->name = $transaction->transaction_currency_name;
$currency->symbol = $journal['currency_symbol'];
$currency->decimal_places = $journal['currency_decimal_places'];
$currency->name = $journal['currency_name'];
$return[$currencyId] = [
'amount' => '0',
'currency' => $currency,
];
}
$return[$currencyId]['amount'] = bcadd($return[$currencyId]['amount'], $transaction->transaction_amount);
$return[$currencyId]['amount'] = bcadd($return[$currencyId]['amount'], $journal['amount']);
}
return $return;

View File

@@ -34,8 +34,10 @@ use Twig_SimpleFunction;
*/
class TransactionGroupTwig extends Twig_Extension
{
/** @noinspection PhpMissingParentCallCommonInspection */
/**
* @return array
*
*/
public function getFunctions(): array
{
@@ -44,7 +46,7 @@ class TransactionGroupTwig extends Twig_Extension
$this->groupAmount(),
$this->journalHasMeta(),
$this->journalGetMetaDate(),
$this->journalGetMetaField()
$this->journalGetMetaField(),
];
}
@@ -55,15 +57,30 @@ class TransactionGroupTwig extends Twig_Extension
{
return new Twig_SimpleFunction(
'groupAmount',
function (array $array): string {
$result = $this->normalGroupAmount($array);
// now append foreign amount, if any.
if (0 !== bccomp('0', $array['foreign_sum'])) {
$foreign = $this->foreignGroupAmount($array);
$result = sprintf('%s (%s)', $result, $foreign);
static function (array $array): string {
$sums = $array['sums'];
$return = [];
$first = reset($array['transactions']);
$type = $first['transaction_type_type'] ?? TransactionType::WITHDRAWAL;
$colored = true;
if ($type === TransactionType::TRANSFER) {
$colored = false;
}
return $result;
/** @var array $sum */
foreach ($sums as $sum) {
$amount = $sum['amount'];
// do multiplication thing.
if ($type !== TransactionType::WITHDRAWAL) {
$amount = bcmul($amount, '-1');
}
$return[] = app('amount')->formatFlat($sum['currency_symbol'], (int)$sum['currency_decimal_places'], $amount, $colored);
}
return implode(', ', $return);
},
['is_safe' => ['html']]
);
@@ -182,32 +199,6 @@ class TransactionGroupTwig extends Twig_Extension
return $result;
}
/**
* @param array $array
*
* @return string
*/
private function foreignGroupAmount(array $array): string
{
// take cue from the first entry in the array:
$first = $array['transactions'][0];
$type = $first['transaction_type_type'] ?? TransactionType::WITHDRAWAL;
$amount = $array['foreign_sum'] ?? '0';
$colored = true;
if ($type !== TransactionType::WITHDRAWAL) {
$amount = bcmul($amount, '-1');
}
if ($type === TransactionType::TRANSFER) {
$colored = false;
}
$result = app('amount')->formatFlat($first['foreign_currency_symbol'], (int)$first['foreign_currency_decimal_places'], $amount, $colored);
if ($type === TransactionType::TRANSFER) {
$result = sprintf('<span class="text-info">%s</span>', $result);
}
return $result;
}
/**
* Generate normal amount for transaction from a transaction group.
*
@@ -233,30 +224,4 @@ class TransactionGroupTwig extends Twig_Extension
return $result;
}
/**
* @param array $array
*
* @return string
*/
private function normalGroupAmount(array $array): string
{
// take cue from the first entry in the array:
$first = reset($array['transactions']);
$type = $first['transaction_type_type'] ?? TransactionType::WITHDRAWAL;
$amount = $array['sum'] ?? '0';
$colored = true;
if ($type !== TransactionType::WITHDRAWAL) {
$amount = bcmul($amount, '-1');
}
if ($type === TransactionType::TRANSFER) {
$colored = false;
}
$result = app('amount')->formatFlat($first['currency_symbol'], (int)$first['currency_decimal_places'], $amount, $colored);
if ($type === TransactionType::TRANSFER) {
$result = sprintf('<span class="text-info">%s</span>', $result);
}
return $result;
}
}