mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-10-15 00:27:30 +00:00
Add conversion
This commit is contained in:
@@ -90,6 +90,7 @@ class SubscriptionEnrichment implements EnrichmentInterface
|
|||||||
|
|
||||||
// Convert amounts to native currency if needed
|
// Convert amounts to native currency if needed
|
||||||
if ($this->convertToNative && $item->currency_id !== $this->nativeCurrency->id) {
|
if ($this->convertToNative && $item->currency_id !== $this->nativeCurrency->id) {
|
||||||
|
Log::debug('Convert to native currency');
|
||||||
$converter = new ExchangeRateConverter();
|
$converter = new ExchangeRateConverter();
|
||||||
$amounts = [
|
$amounts = [
|
||||||
'amount_min' => Steam::bcround($converter->convert($item->transactionCurrency, $this->nativeCurrency, today(), $item->amount_min), $this->nativeCurrency->decimal_places),
|
'amount_min' => Steam::bcround($converter->convert($item->transactionCurrency, $this->nativeCurrency, today(), $item->amount_min), $this->nativeCurrency->decimal_places),
|
||||||
@@ -235,6 +236,7 @@ class SubscriptionEnrichment implements EnrichmentInterface
|
|||||||
Log::debug(sprintf('Count %d entries in set', $set->count()));
|
Log::debug(sprintf('Count %d entries in set', $set->count()));
|
||||||
|
|
||||||
// for each bill, do a loop.
|
// for each bill, do a loop.
|
||||||
|
$converter = new ExchangeRateConverter();
|
||||||
/** @var Bill $subscription */
|
/** @var Bill $subscription */
|
||||||
foreach ($this->collection as $subscription) {
|
foreach ($this->collection as $subscription) {
|
||||||
// Grab from array the most recent payment. If none exist, fall back to the start date and pretend *that* was the last paid date.
|
// Grab from array the most recent payment. If none exist, fall back to the start date and pretend *that* was the last paid date.
|
||||||
@@ -265,6 +267,13 @@ class SubscriptionEnrichment implements EnrichmentInterface
|
|||||||
$array['foreign_currency_decimal_places'] = $entry->foreign_currency_decimal_places;
|
$array['foreign_currency_decimal_places'] = $entry->foreign_currency_decimal_places;
|
||||||
$array['foreign_amount'] = Steam::bcround($entry->foreign_amount, $entry->foreign_currency_decimal_places);
|
$array['foreign_amount'] = Steam::bcround($entry->foreign_amount, $entry->foreign_currency_decimal_places);
|
||||||
}
|
}
|
||||||
|
if($this->convertToNative) {
|
||||||
|
$array['amount'] = $converter->convert($entry->transactionCurrency, $this->nativeCurrency, $entry->date, $entry->amount);
|
||||||
|
$array['currency_id'] = $this->nativeCurrency->id;
|
||||||
|
$array['currency_code'] = $this->nativeCurrency->code;
|
||||||
|
$array['currency_decimal_places'] = $this->nativeCurrency->decimal_places;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
$result[] = $array;
|
$result[] = $array;
|
||||||
}
|
}
|
||||||
@@ -334,6 +343,10 @@ class SubscriptionEnrichment implements EnrichmentInterface
|
|||||||
|
|
||||||
private function collectPayDates(): void
|
private function collectPayDates(): void
|
||||||
{
|
{
|
||||||
|
if(null === $this->start || null === $this->end) {
|
||||||
|
Log::debug('Parameters are NULL, set empty array');
|
||||||
|
return;
|
||||||
|
}
|
||||||
/** @var Bill $subscription */
|
/** @var Bill $subscription */
|
||||||
foreach ($this->collection as $subscription) {
|
foreach ($this->collection as $subscription) {
|
||||||
$id = (int)$subscription->id;
|
$id = (int)$subscription->id;
|
||||||
|
@@ -30,6 +30,7 @@ import i18next from "i18next";
|
|||||||
let afterPromises = false;
|
let afterPromises = false;
|
||||||
let apiData = [];
|
let apiData = [];
|
||||||
let subscriptionData = {};
|
let subscriptionData = {};
|
||||||
|
let convertToNative = false;
|
||||||
|
|
||||||
function addObjectGroupInfo(data) {
|
function addObjectGroupInfo(data) {
|
||||||
let objectGroupId = parseInt(data.object_group_id);
|
let objectGroupId = parseInt(data.object_group_id);
|
||||||
@@ -70,6 +71,11 @@ function parseBillInfo(data) {
|
|||||||
pay_dates: parsePayDates(data.attributes.pay_dates),
|
pay_dates: parsePayDates(data.attributes.pay_dates),
|
||||||
paid: data.attributes.paid_dates.length > 0,
|
paid: data.attributes.paid_dates.length > 0,
|
||||||
};
|
};
|
||||||
|
if(convertToNative) {
|
||||||
|
result.currency_code = data.attributes.native_currency_code;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// set variables
|
// set variables
|
||||||
result.expected_amount = formatMoney(result.amount, result.currency_code);
|
result.expected_amount = formatMoney(result.amount, result.currency_code);
|
||||||
result.expected_times = i18next.t('firefly.subscr_expected_x_times', {
|
result.expected_times = i18next.t('firefly.subscr_expected_x_times', {
|
||||||
@@ -214,6 +220,7 @@ export default () => ({
|
|||||||
['@convert-to-native.window'](event){
|
['@convert-to-native.window'](event){
|
||||||
console.log('I heard that! (dashboard/subscriptions)');
|
console.log('I heard that! (dashboard/subscriptions)');
|
||||||
this.convertToNative = event.detail;
|
this.convertToNative = event.detail;
|
||||||
|
convertToNative = event.detail;
|
||||||
this.startSubscriptions();
|
this.startSubscriptions();
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@@ -308,6 +315,7 @@ export default () => ({
|
|||||||
init() {
|
init() {
|
||||||
Promise.all([getVariable('convert_to_native', false)]).then((values) => {
|
Promise.all([getVariable('convert_to_native', false)]).then((values) => {
|
||||||
this.convertToNative = values[0];
|
this.convertToNative = values[0];
|
||||||
|
convertToNative = values[0];
|
||||||
afterPromises = true;
|
afterPromises = true;
|
||||||
|
|
||||||
if (false === this.loading) {
|
if (false === this.loading) {
|
||||||
|
Reference in New Issue
Block a user