diff --git a/app/Http/Requests/AccountFormRequest.php b/app/Http/Requests/AccountFormRequest.php index b9281b9d0a..78b5342eb1 100644 --- a/app/Http/Requests/AccountFormRequest.php +++ b/app/Http/Requests/AccountFormRequest.php @@ -82,7 +82,8 @@ class AccountFormRequest extends FormRequest $data['account_type_name'] = null; $data['account_type_id'] = $this->convertInteger('liability_type_id'); if ('' !== $data['opening_balance']) { - $data['opening_balance'] = app('steam')->negative($data['opening_balance']); + // opening balance is always positive for liabilities + $data['opening_balance'] = app('steam')->positive($data['opening_balance']); } } diff --git a/app/Services/Internal/Update/AccountUpdateService.php b/app/Services/Internal/Update/AccountUpdateService.php index 38800d8d34..e990a7d8c4 100644 --- a/app/Services/Internal/Update/AccountUpdateService.php +++ b/app/Services/Internal/Update/AccountUpdateService.php @@ -298,6 +298,11 @@ class AccountUpdateService $openingBalance = $data['opening_balance']; $openingBalanceDate = $data['opening_balance_date']; + // if liability, make sure the amount is positive for a credit, and negative for a debit. + if($this->isLiability($account)) { + $openingBalance = 'credit' === $data['liability_direction'] ? app('steam')->positive($openingBalance) : app('steam')->negative($openingBalance); + } + $this->updateOBGroupV2($account, $openingBalance, $openingBalanceDate); } diff --git a/public/v1/js/ff/accounts/edit.js b/public/v1/js/ff/accounts/edit.js index 55915cd5b5..192c224145 100644 --- a/public/v1/js/ff/accounts/edit.js +++ b/public/v1/js/ff/accounts/edit.js @@ -30,5 +30,21 @@ $(document).ready(function () { } ); } + // change the 'ffInput_opening_balance' text based on the + // selection of the direction. + $("#ffInput_liability_direction").change(triggerDirection); + triggerDirection(); }); + +function triggerDirection() { + let obj = $("#ffInput_liability_direction"); + let direction = obj.val(); + console.log('Direction is now ' + direction); + if('credit' === direction) { + $('label[for="ffInput_opening_balance"]').text(iAmOwed); + } + if('debit' === direction) { + $('label[for="ffInput_opening_balance"]').text(iOwe); + } +} diff --git a/resources/lang/en_US/firefly.php b/resources/lang/en_US/firefly.php index 646a6e5ee4..461147f153 100644 --- a/resources/lang/en_US/firefly.php +++ b/resources/lang/en_US/firefly.php @@ -1715,6 +1715,8 @@ return [ 'extension_date_is' => 'Extension date is {date}', // accounts: + 'i_am_owed_amount' => 'I am owed amount', + 'i_owe_amount' => 'I owe amount', 'inactive_account_link' => 'You have :count inactive (archived) account, which you can view on this separate page.|You have :count inactive (archived) accounts, which you can view on this separate page.', 'all_accounts_inactive' => 'These are your inactive accounts.', 'active_account_link' => 'This link goes back to your active accounts.', @@ -2468,7 +2470,7 @@ return [ // recurring transactions 'create_right_now' => 'Create right now', - 'no_new_transaction_in_recurrence' => 'No new transaction was created. Perhaps it was already fired for this date?', + 'no_new_transaction_in_recurrence' => 'No new transaction was created. Perhaps it was already fired for this date?', 'recurrences' => 'Recurring transactions', 'repeat_until_in_past' => 'This recurring transaction stopped repeating on :date.', 'recurring_calendar_view' => 'Calendar', diff --git a/resources/views/accounts/edit.twig b/resources/views/accounts/edit.twig index 3e3d523295..edc8df2e58 100644 --- a/resources/views/accounts/edit.twig +++ b/resources/views/accounts/edit.twig @@ -35,7 +35,7 @@ {% if objectType == 'liabilities' %} {{ ExpandedForm.select('liability_type_id', liabilityTypes) }} - {{ ExpandedForm.amountNoCurrency('opening_balance', null, {label:'debt_start_amount'|_, helpText: 'debt_start_amount_help'|_}) }} + {{ ExpandedForm.amountNoCurrency('opening_balance', null, {label:'debt_start_amount'|_}) }} {{ ExpandedForm.select('liability_direction', liabilityDirections) }} {{ ExpandedForm.date('opening_balance_date', null, {label:'debt_start_date'|_}) }} {{ ExpandedForm.percentage('interest') }} @@ -115,6 +115,10 @@ {% endblock %} {% block scripts %} +