Update code for proper index.

This commit is contained in:
James Cole 2021-04-27 07:55:54 +02:00
parent be844b82af
commit a83578d1ae
No known key found for this signature in database
GPG Key ID: B5669F9493CDE38D
8 changed files with 80 additions and 4 deletions

View File

@ -7,6 +7,7 @@ use FireflyIII\Models\Account;
use FireflyIII\Models\Transaction;
use FireflyIII\Models\TransactionJournal;
use FireflyIII\Repositories\Account\AccountRepositoryInterface;
use FireflyIII\Services\Internal\Support\CreditRecalculateService;
use FireflyIII\User;
use Illuminate\Console\Command;
use Log;
@ -145,6 +146,9 @@ class UpgradeLiabilities extends Command
/** @var Account $account */
foreach ($accounts as $account) {
$this->upgradeLiability($account);
$service = app(CreditRecalculateService::class);
$service->setAccount($account);
$service->recalculate();
}
}

View File

@ -123,6 +123,9 @@ class EditController extends Controller
$request->session()->forget('accounts.edit.fromUpdate');
$openingBalanceAmount = app('steam')->positive((string)$repository->getOpeningBalanceAmount($account));
if('0' === $openingBalanceAmount) {
$openingBalanceAmount = '';
}
$openingBalanceDate = $repository->getOpeningBalanceDate($account);
$currency = $this->repository->getAccountCurrency($account) ?? app('amount')->getDefaultCurrency();

View File

@ -789,5 +789,5 @@ class AccountRepository implements AccountRepositoryInterface
return $dbQuery->first(['accounts.*']);
}
}

View File

@ -119,6 +119,7 @@ class AccountTransformer extends AbstractTransformer
'liability_direction' => $liabilityDirection,
'interest' => $interest,
'interest_period' => $interestPeriod,
'current_debt' => $this->repository->getMetaValue($account,'current_debt'),
'include_net_worth' => $includeNetWorth,
'longitude' => $longitude,
'latitude' => $latitude,

View File

@ -54,6 +54,31 @@
<span v-if="null === data.item.iban && null !== data.item.account_number">{{ data.item.account_number }}</span>
<span v-if="null !== data.item.iban && null !== data.item.account_number">{{ data.item.iban }} ({{ data.item.account_number }})</span>
</template>
<template #cell(last_activity)="data">
<span v-if="'asset' === type && 'loading' === data.item.last_activity">
<i class="fas fa-spinner fa-spin"></i>
</span>
<span v-if="'asset' === type && 'none' === data.item.last_activity" class="text-muted">
{{ $t('firefly.never') }}
</span>
<span v-if="'asset' === type && 'loading' !== data.item.last_activity && 'none' !== data.item.last_activity">
{{ data.item.last_activity }}
</span>
</template>
<template #cell(amount_due)="data">
<span class="text-success" v-if="parseFloat(data.item.amount_due) > 0">
{{ Intl.NumberFormat('en-US', {style: 'currency', currency: data.item.currency_code}).format(data.item.amount_due) }}
</span>
<span class="text-danger" v-if="parseFloat(data.item.amount_due) < 0">
{{ Intl.NumberFormat('en-US', {style: 'currency', currency: data.item.currency_code}).format(data.item.amount_due) }}
</span>
<span class="text-muted" v-if="parseFloat(data.item.amount_due) === 0.0">
{{ Intl.NumberFormat('en-US', {style: 'currency', currency: data.item.currency_code}).format(data.item.amount_due) }}
</span>
</template>
<template #cell(current_balance)="data">
<span class="text-success" v-if="parseFloat(data.item.current_balance) > 0">
{{
@ -102,6 +127,9 @@
}}</span>)
</span>
</template>
<template #cell(interest)="data">
{{ parseFloat(data.item.interest) }}% ({{ data.item.interest_period }})
</template>
<template #cell(menu)="data">
<div class="btn-group btn-group-sm">
<div class="dropdown">
@ -249,14 +277,24 @@ export default {
updateFieldList: function () {
this.fields = [];
this.fields = [{key: 'title', label: this.$t('list.name'), sortable: !this.orderMode}];
if ('asset' === this.type) {
this.fields.push({key: 'role', label: this.$t('list.role'), sortable: !this.orderMode});
}
if ('liabilities' === this.type) {
this.fields.push({key: 'liability_type', label: this.$t('list.liability_type'), sortable: !this.orderMode});
this.fields.push({key: 'liability_direction', label: this.$t('list.liability_direction'), sortable: !this.orderMode});
this.fields.push({key: 'interest', label: this.$t('list.interest') + ' (' + this.$t('list.interest_period') + ')', sortable: !this.orderMode});
}
// add the rest
this.fields.push({key: 'number', label: this.$t('list.iban'), sortable: !this.orderMode});
this.fields.push({key: 'current_balance', label: this.$t('list.currentBalance'), sortable: !this.orderMode});
if ('liabilities' === this.type) {
this.fields.push({key: 'amount_due', label: this.$t('firefly.left_in_debt'), sortable: !this.orderMode});
}
if ('asset' === this.type || 'liabilities' === this.type) {
this.fields.push({key: 'last_activity', label: this.$t('list.lastActivity'), sortable: !this.orderMode});
}
this.fields.push({key: 'menu', label: ' ', sortable: false});
},
getAccountList: function () {
@ -273,7 +311,6 @@ export default {
// console.log('Index ready, not loading and not downloaded.');
this.loading = true;
this.filterAccountList();
// TODO filter accounts.
}
},
downloadAccountList: function (page) {
@ -344,19 +381,45 @@ export default {
acct.account_number = current.attributes.account_number;
acct.current_balance = current.attributes.current_balance;
acct.currency_code = current.attributes.currency_code;
if ('liabilities' === this.type) {
acct.liability_type = this.$t('firefly.account_type_' + current.attributes.liability_type);
acct.liability_direction = this.$t('firefly.liability_direction_' + current.attributes.liability_direction + '_short');
acct.interest = current.attributes.interest;
acct.interest_period = this.$t('firefly.interest_calc_' + current.attributes.interest_period);
acct.amount_due = current.attributes.current_debt;
}
acct.balance_diff = 'loading';
acct.last_activity = 'loading';
if (null !== current.attributes.iban) {
acct.iban = current.attributes.iban.match(/.{1,4}/g).join(' ');
}
if (null === current.attributes.iban) {
acct.iban = null;
}
this.allAccounts.push(acct);
if ('asset' === this.type) {
this.getAccountBalanceDifference(this.allAccounts.length - 1, current);
this.getAccountLastActivity(this.allAccounts.length - 1, current);
}
}
}
},
getAccountLastActivity: function (index, acct) {
// console.log('getAccountLastActivity(' + index + ')');
// get single transaction for account:
// /api/v1/accounts/1/transactions?limit=1
axios.get('./api/v1/accounts/' + acct.id + '/transactions?limit=1').then(response => {
if (0 === response.data.data.length) {
this.allAccounts[index].last_activity = 'none';
return;
}
let date = new Date(response.data.data[0].attributes.transactions[0].date);
this.allAccounts[index].last_activity = format(date, this.$t('config.month_and_day_fns'));
});
},
getAccountBalanceDifference: function (index, acct) {
// console.log('getAccountBalanceDifference(' + index + ')');
// get account on day 0

View File

@ -28,6 +28,7 @@ return [
'month' => '%B %Y',
'month_and_day' => '%B %e, %Y',
'month_and_day_moment_js' => 'MMM D, YYYY',
'month_and_day_fns' => 'MMMM d, y',
'month_and_date_day' => '%A %B %e, %Y',
'month_and_day_no_year' => '%B %e',
'date_time' => '%B %e, %Y, @ %T',

View File

@ -1325,6 +1325,9 @@ return [
'account_type_Debt' => 'Debt',
'account_type_Loan' => 'Loan',
'account_type_Mortgage' => 'Mortgage',
'account_type_debt' => 'Debt',
'account_type_loan' => 'Loan',
'account_type_mortgage' => 'Mortgage',
'account_type_Credit card' => 'Credit card',
'liability_direction_credit' => 'I am owed this debt',
'liability_direction_debit' => 'I owe this debt to somebody else',

View File

@ -130,6 +130,7 @@ return [
'field' => 'Field',
'value' => 'Value',
'interest' => 'Interest',
'interest_period' => 'interest period',
'interest_period' => 'Interest period',
'liability_type' => 'Type of liability',
'liability_direction' => 'Liability in/out',
];