mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-10-12 23:45:10 +00:00
Expand balances.
This commit is contained in:
@@ -91,7 +91,7 @@ class AccountTransformer extends AbstractTransformer
|
||||
|
||||
$decimalPlaces = (int)$account->meta['currency']?->decimal_places;
|
||||
$decimalPlaces = 0 === $decimalPlaces ? 2 : $decimalPlaces;
|
||||
$openingBalance = Steam::bcround($openingBalance, $decimalPlaces);
|
||||
$openingBalanceRounded = Steam::bcround($openingBalance, $decimalPlaces);
|
||||
$includeNetWorth = 1 === (int)($account->meta['include_net_worth'] ?? 0);
|
||||
$longitude = $account->meta['location']['longitude'] ?? null;
|
||||
$latitude = $account->meta['location']['latitude'] ?? null;
|
||||
@@ -112,6 +112,53 @@ class AccountTransformer extends AbstractTransformer
|
||||
$currentBalance = Steam::bcround($finalBalance['balance'] ?? '0', $decimalPlaces);
|
||||
$nativeCurrentBalance = $this->convertToNative ? Steam::bcround($finalBalance['native_balance'] ?? '0', $native->decimal_places) : null;
|
||||
|
||||
// set up balances array:
|
||||
$balances = [];
|
||||
$balances[] =
|
||||
[
|
||||
'type' => 'current',
|
||||
'amount' => $currentBalance,
|
||||
'currency_id' => $account->meta['currency_id'] ?? null,
|
||||
'currency_code' => $account->meta['currency']?->code,
|
||||
'currency_symbol' => $account->meta['currency']?->symbol,
|
||||
'currency_decimal_places' => $account->meta['currency']?->decimal_places,
|
||||
'date' => $date->toAtomString()
|
||||
];
|
||||
if (null !== $nativeCurrentBalance) {
|
||||
$balances[] = [
|
||||
'type' => 'native_current',
|
||||
'amount' => $nativeCurrentBalance,
|
||||
'currency_id' => $native instanceof TransactionCurrency ? (string)$native->id : null,
|
||||
'currency_code' => $native?->code,
|
||||
'currency_symbol' => $native?->symbol,
|
||||
'ccurrency_decimal_places' => $native?->decimal_places,
|
||||
'date' => $date->toAtomString()
|
||||
|
||||
];
|
||||
}
|
||||
if (null !== $openingBalance) {
|
||||
$balances[] = [
|
||||
'type' => 'opening',
|
||||
'amount' => $openingBalanceRounded,
|
||||
'currency_id' => $account->meta['currency_id'] ?? null,
|
||||
'currency_code' => $account->meta['currency']?->code,
|
||||
'currency_symbol' => $account->meta['currency']?->symbol,
|
||||
'currency_decimal_places' => $account->meta['currency']?->decimal_places,
|
||||
'date' => $openingBalanceDate
|
||||
];
|
||||
}
|
||||
if(null !== $account->virtual_balance) {
|
||||
$balances[] = [
|
||||
'type' => 'virtual',
|
||||
'amount' => Steam::bcround($account->virtual_balance, $decimalPlaces),
|
||||
'currency_id' => $account->meta['currency_id'] ?? null,
|
||||
'currency_code' => $account->meta['currency']?->code,
|
||||
'currency_symbol' => $account->meta['currency']?->symbol,
|
||||
'currency_decimal_places' => $account->meta['currency']?->decimal_places,
|
||||
'date' => $date->toAtomString()
|
||||
];
|
||||
}
|
||||
|
||||
return [
|
||||
'id' => (string)$account->id,
|
||||
'created_at' => $account->created_at->toAtomString(),
|
||||
@@ -140,7 +187,7 @@ class AccountTransformer extends AbstractTransformer
|
||||
'bic' => $account->meta['BIC'] ?? null,
|
||||
'virtual_balance' => Steam::bcround($account->virtual_balance, $decimalPlaces),
|
||||
'native_virtual_balance' => $this->convertToNative ? Steam::bcround($account->native_virtual_balance, $native->decimal_places) : null,
|
||||
'opening_balance' => $openingBalance,
|
||||
'opening_balance' => $openingBalanceRounded,
|
||||
'native_opening_balance' => $nativeOpeningBalance,
|
||||
'opening_balance_date' => $openingBalanceDate,
|
||||
'liability_type' => $liabilityType,
|
||||
@@ -153,6 +200,7 @@ class AccountTransformer extends AbstractTransformer
|
||||
'latitude' => $latitude,
|
||||
'zoom_level' => $zoomLevel,
|
||||
'last_activity' => array_key_exists('last_activity', $account->meta) ? $account->meta['last_activity']->toAtomString() : null,
|
||||
'balances' => $balances,
|
||||
'links' => [
|
||||
[
|
||||
'rel' => 'self',
|
||||
|
@@ -352,12 +352,15 @@ let index = function () {
|
||||
|
||||
// filter instructions
|
||||
let filters = {};
|
||||
let type = this.filters.type;
|
||||
let active = this.filters.active;
|
||||
for (let k in this.filters) {
|
||||
if (this.filters.hasOwnProperty(k) && null !== this.filters[k]) {
|
||||
filters[k] = this.filters[k];
|
||||
//filters.push({column: k, filter: this.filters[k]});
|
||||
}
|
||||
}
|
||||
delete filters.type;
|
||||
|
||||
// get start and end from the store:
|
||||
const start = new Date(window.store.get('start'));
|
||||
@@ -367,24 +370,23 @@ let index = function () {
|
||||
let params = {
|
||||
sort: sorting,
|
||||
filter: filters,
|
||||
active: active,
|
||||
currentMoment: today,
|
||||
// type: type,
|
||||
page: {number: this.page},
|
||||
type: type,
|
||||
page: this.page,
|
||||
startPeriod: start,
|
||||
endPeriod: end
|
||||
};
|
||||
|
||||
if (!this.tableColumns.balance_difference.enabled) {
|
||||
delete params.startPeriod;
|
||||
delete params.enPeriod;
|
||||
delete params.endPeriod;
|
||||
}
|
||||
this.accounts = [];
|
||||
let groupedAccounts = {};
|
||||
// one page only.o
|
||||
(new Get()).index(params).then(response => {
|
||||
console.log(response);
|
||||
this.totalPages = response.meta.pagination.total_pages;
|
||||
console.log('a');
|
||||
for (let i = 0; i < response.data.length; i++) {
|
||||
if (response.data.hasOwnProperty(i)) {
|
||||
let current = response.data[i];
|
||||
@@ -399,18 +401,14 @@ let index = function () {
|
||||
account_number: null === current.attributes.account_number ? '' : current.attributes.account_number,
|
||||
current_balance: current.attributes.current_balance,
|
||||
currency_code: current.attributes.currency_code,
|
||||
//native_current_balance: current.attributes.native_current_balance,
|
||||
//native_currency_code: current.attributes.native_currency_code,
|
||||
last_activity: null === current.attributes.last_activity ? '' : format(new Date(current.attributes.last_activity), i18next.t('config.month_and_day_fns')),
|
||||
//balance_difference: current.attributes.balance_difference,
|
||||
//native_balance_difference: current.attributes.native_balance_difference,
|
||||
liability_type: current.attributes.liability_type,
|
||||
liability_direction: current.attributes.liability_direction,
|
||||
interest: current.attributes.interest,
|
||||
interest_period: current.attributes.interest_period,
|
||||
//current_debt: current.attributes.current_debt,
|
||||
balance: current.attributes.balance,
|
||||
native_balance: current.attributes.native_balance,
|
||||
balances: current.attributes.balances,
|
||||
};
|
||||
// get group info:
|
||||
let groupId = current.attributes.object_group_id;
|
||||
|
@@ -196,6 +196,14 @@ export default () => ({
|
||||
(new Get).show(accountId, new Date(window.store.get('end'))).then((response) => {
|
||||
let parent = response.data.data;
|
||||
|
||||
// apply function to each element of parent:
|
||||
parent.attributes.balances = parent.attributes.balances.map((balance) => {
|
||||
balance.amount_formatted = formatMoney(balance.amount, balance.currency_code);
|
||||
return balance;
|
||||
});
|
||||
console.log(parent);
|
||||
|
||||
|
||||
// get groups for account:
|
||||
const params = {
|
||||
page: 1,
|
||||
@@ -243,8 +251,7 @@ export default () => ({
|
||||
name: parent.attributes.name,
|
||||
order: parent.attributes.order,
|
||||
id: parent.id,
|
||||
balance: parent.attributes.balance,
|
||||
//native_balance: parent.attributes.native_balance,
|
||||
balances: parent.attributes.balances,
|
||||
groups: groups,
|
||||
});
|
||||
// console.log(parent.attributes);
|
||||
|
@@ -76,7 +76,7 @@ function parsePaidTransactions(paid_dates, bill) {
|
||||
for (let i in paid_dates) {
|
||||
if (paid_dates.hasOwnProperty(i)) {
|
||||
const currentPayment = paid_dates[i];
|
||||
console.log(currentPayment);
|
||||
// console.log(currentPayment);
|
||||
// math: -100+(paid/expected)*100
|
||||
let percentage = Math.round(-100 + ((parseFloat(currentPayment.amount) ) / parseFloat(bill.amount)) * 100);
|
||||
let currentTransaction = {
|
||||
|
@@ -13,11 +13,11 @@
|
||||
x-text="account.name"></a>
|
||||
|
||||
<span class="small">
|
||||
<template x-for="balance in account.balance">
|
||||
<span>x</span>
|
||||
<template x-for="balance in account.balances">
|
||||
<template x-if="balance.type === 'current'">
|
||||
<span class="text-muted">(<span x-text="balance.amount_formatted"></span>)
|
||||
</span>
|
||||
</template>
|
||||
<template x-for="balance in account.native_balance">
|
||||
<span>Y</span>
|
||||
</template>
|
||||
</span>
|
||||
</h3>
|
||||
|
Reference in New Issue
Block a user