Skip to content

Firefly III: a personal finances manager

Code for #833

James Coledd9577614472
diff --git a/app/Http/Controllers/BillController.php b/app/Http/Controllers/BillController.php
index 539c2e2441..2990b32e35 100644
--- a/app/Http/Controllers/BillController.php
+++ b/app/Http/Controllers/BillController.php
@@ -200,7 +200,10 @@ class BillController extends Controller
/** @var Collection $bills */
$bills = $paginator->getCollection()->map(
function (Bill $bill) use ($transformer) {
- return $transformer->transform($bill);
+ $return = $transformer->transform($bill);
+ $return['currency'] = $bill->transactionCurrency;
+
+ return $return;
}
);
$bills = $bills->sortBy(
@@ -291,8 +294,9 @@ class BillController extends Controller
$parameters = new ParameterBag();
$parameters->set('start', $start);
$parameters->set('end', $end);
- $resource = new Item($bill, new BillTransformer($parameters), 'bill');
- $object = $manager->createData($resource)->toArray();
+ $resource = new Item($bill, new BillTransformer($parameters), 'bill');
+ $object = $manager->createData($resource)->toArray();
+ $object['data']['currency'] = $bill->transactionCurrency;
// use collector:
/** @var TransactionCollectorInterface $collector */
diff --git a/app/Http/Controllers/Chart/BillController.php b/app/Http/Controllers/Chart/BillController.php
index c0477edcba..9936e2125a 100644
--- a/app/Http/Controllers/Chart/BillController.php
+++ b/app/Http/Controllers/Chart/BillController.php
@@ -109,9 +109,9 @@ class BillController extends Controller
}
);
$chartData = [
- ['type' => 'bar', 'label' => (string)trans('firefly.min-amount'), 'entries' => []],
- ['type' => 'bar', 'label' => (string)trans('firefly.max-amount'), 'entries' => []],
- ['type' => 'line', 'label' => (string)trans('firefly.journal-amount'), 'entries' => []],
+ ['type' => 'bar', 'label' => (string)trans('firefly.min-amount'),'currency_symbol' => $bill->transactionCurrency->symbol, 'entries' => []],
+ ['type' => 'bar', 'label' => (string)trans('firefly.max-amount'),'currency_symbol' => $bill->transactionCurrency->symbol, 'entries' => []],
+ ['type' => 'line', 'label' => (string)trans('firefly.journal-amount'),'currency_symbol' => $bill->transactionCurrency->symbol, 'entries' => []],
];
/** @var Transaction $entry */
diff --git a/app/Transformers/BillTransformer.php b/app/Transformers/BillTransformer.php
index 68b1b0559f..acc49db569 100644
--- a/app/Transformers/BillTransformer.php
+++ b/app/Transformers/BillTransformer.php
@@ -174,6 +174,7 @@ class BillTransformer extends TransformerAbstract
'name' => $bill->name,
'currency_id' => $bill->transaction_currency_id,
'currency_code' => $bill->transactionCurrency->code,
+ 'currency_symbol' => $bill->transactionCurrency->symbol,
'amount_min' => round((float)$bill->amount_min, 2),
'amount_max' => round((float)$bill->amount_max, 2),
'date' => $bill->date->format('Y-m-d'),
diff --git a/public/js/ff/bills/show.js b/public/js/ff/bills/show.js
index 39ef1ca95e..f2838cbf5f 100644
--- a/public/js/ff/bills/show.js
+++ b/public/js/ff/bills/show.js
@@ -22,6 +22,7 @@
$(function () {
"use strict";
+ configAccounting(billCurrencySymbol);
columnChart(billUri, 'bill-overview');
}
);
\ No newline at end of file
diff --git a/public/js/ff/charts.defaults.js b/public/js/ff/charts.defaults.js
index 3070d20e5c..ad00dd96fa 100644
--- a/public/js/ff/charts.defaults.js
+++ b/public/js/ff/charts.defaults.js
@@ -85,7 +85,7 @@ var defaultChartOptions = {
display: false
},
ticks: {
- // Include a dollar sign in the ticks
+ // break ticks when too long.
callback: function (value, index, values) {
return formatLabel(value, 20);
}
diff --git a/public/js/ff/charts.js b/public/js/ff/charts.js
index 275f3fb144..301b9a3d6d 100644
--- a/public/js/ff/charts.js
+++ b/public/js/ff/charts.js
@@ -202,7 +202,6 @@ function columnChart(URI, container) {
var chartType = 'bar';
drawAChart(URI, container, chartType, options, colorData);
-
}
/**
diff --git a/resources/views/bills/show.twig b/resources/views/bills/show.twig
index 571fe05780..a5c6c12816 100644
--- a/resources/views/bills/show.twig
+++ b/resources/views/bills/show.twig
@@ -27,7 +27,7 @@
<table class="table table-striped">
<tr>
<td colspan="2">
- {{ trans('firefly.match_between_amounts', {low: object.data.amount_min|formatAmount, high: object.data.amount_max|formatAmount })|raw }}
+ {{ trans('firefly.match_between_amounts', {low: formatAmountByCurrency(object.data.currency,object.data.amount_min), high: formatAmountByCurrency(object.data.currency,object.data.amount_max) })|raw }}
{{ 'repeats'|_ }}
{{ trans('firefly.repeat_freq_' ~object.data.repeat_freq) }}.
</td>
@@ -55,11 +55,11 @@
</tr>
<tr>
<td>{{ trans('firefly.average_bill_amount_year', {year: year}) }}</td>
- <td>{{ yearAverage|formatAmount }}</td>
+ <td>{{ formatAmountByCurrency(object.data.currency,yearAverage) }}</td>
</tr>
<tr>
<td>{{ 'average_bill_amount_overall'|_ }}</td>
- <td>{{ overallAverage|formatAmount }}</td>
+ <td>{{ formatAmountByCurrency(object.data.currency, overallAverage) }}</td>
</tr>
</table>
</div>
@@ -174,6 +174,7 @@
{% block scripts %}
<script type="text/javascript">
+ var billCurrencySymbol = "{{ object.data.currency.symbol }}";
var billUri = '{{ route('chart.bill.single', [object.data.id]) }}';
</script>
<script type="text/javascript" src="js/lib/Chart.bundle.min.js?v={{ FF_VERSION }}"></script>
diff --git a/resources/views/list/bills.twig b/resources/views/list/bills.twig
index 33ab891135..3707f84bd4 100644
--- a/resources/views/list/bills.twig
+++ b/resources/views/list/bills.twig
@@ -57,8 +57,8 @@
{% endif %}
</td>
<td data-value="{{ entry.amount_min }}" style="text-align: right;">
- <span style="margin-right:5px;" title="{{ entry.amount_min|formatAmountPlain }} - {{ entry.amount_max|formatAmountPlain }}">
- ~ {{ ((entry.amount_max+ entry.amount_min)/2)|formatAmount }}
+ <span style="margin-right:5px;">
+ ~ {{ formatAmountByCurrency(entry.currency, (entry.amount_max + entry.amount_min)/2) }}
</span>
</td>
@@ -127,12 +127,12 @@
<td style="text-align:right;" colspan="3">{{ 'sum'|_ }} ({{ 'active_bills_only'|_ }})</td>
<td style="text-align:right;" colspan="1">
<span style="margin-right:5px;">
- {{ sum_min|formatAmount }}
+ {{ formatAmountBySymbol(sum_min,'¤') }}
</span>
</td>
<td style="text-align:right;" colspan="1">
<span style="margin-right:5px;">
- {{ sum_max|formatAmount }}
+ {{ formatAmountBySymbol(sum_max,'¤') }}
</span>
</td>
<td colspan="5">&nbsp;</td>
@@ -151,12 +151,12 @@
<td style="text-align:right;" colspan="3">{{ 'average_per_bill'|_ }} ({{ 'active_bills_only'|_ }})</td>
<td style="text-align:right;" colspan="1">
<span style="margin-right:5px;">
- {{ avg_min|formatAmount }}
+ {{ formatAmountBySymbol(avg_min,'¤') }}
</span>
</td>
<td style="text-align:right;" colspan="1">
<span style="margin-right:5px;">
- {{ avg_max|formatAmount }}
+ {{ formatAmountBySymbol(avg_max,'¤') }}
</span>
</td>
<td colspan="6">&nbsp;</td>
@@ -165,7 +165,7 @@
<td style="text-align:right;" colspan="3">{{ 'expected_total'|_ }} ({{ 'active_bills_only'|_ }})</td>
<td style="text-align:right;" colspan="1">
<span style="margin-right:5px;">
- ~ {{ expected_total|formatAmount }}
+ ~ {{ formatAmountBySymbol(expected_total,'¤') }}
</span>
</td>
<td colspan="6">&nbsp;</td>