Expand report email.

This commit is contained in:
James Cole
2018-06-26 19:26:10 +02:00
parent 5d01955133
commit 49de4f2200
6 changed files with 53 additions and 15 deletions

View File

@@ -96,10 +96,51 @@ class TransactionJournal extends Twig_Extension
* @return string
*/
public function totalAmount(JournalModel $journal): string
{
$type = $journal->transactionType->type;
$totals = $this->getTotalAmount($journal);
$array = [];
foreach ($totals as $total) {
if (TransactionType::WITHDRAWAL === $type) {
$total['amount'] = bcmul($total['amount'], '-1');
}
$array[] = app('amount')->formatAnything($total['currency'], $total['amount']);
}
return implode(' / ', $array);
}
/**
* @param JournalModel $journal
*
* @return string
*/
public function totalAmountPlain(JournalModel $journal): string
{
$type = $journal->transactionType->type;
$totals = $this->getTotalAmount($journal);
$array = [];
foreach ($totals as $total) {
if (TransactionType::WITHDRAWAL === $type) {
$total['amount'] = bcmul($total['amount'], '-1');
}
$array[] = app('amount')->formatAnything($total['currency'], $total['amount'], false);
}
return implode(' / ', $array);
}
/**
* @param JournalModel $journal
*
* @return string
*/
private function getTotalAmount(JournalModel $journal): array
{
$transactions = $journal->transactions()->where('amount', '>', 0)->get();
$totals = [];
$type = $journal->transactionType->type;
/** @var TransactionModel $transaction */
foreach ($transactions as $transaction) {
$currencyId = $transaction->transaction_currency_id;
@@ -128,14 +169,7 @@ class TransactionJournal extends Twig_Extension
);
}
}
$array = [];
foreach ($totals as $total) {
if (TransactionType::WITHDRAWAL === $type) {
$total['amount'] = bcmul($total['amount'], '-1');
}
$array[] = app('amount')->formatAnything($total['currency'], $total['amount']);
}
return implode(' / ', $array);
return $totals;
}
}