Make sure edit of liability always works.

This commit is contained in:
James Cole
2023-01-15 07:20:58 +01:00
parent 1f9e0b48c9
commit 7111aec101
5 changed files with 31 additions and 3 deletions

View File

@@ -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']);
}
}

View File

@@ -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);
}

View File

@@ -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);
}
}

View File

@@ -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.',

View File

@@ -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 @@
</form>
{% endblock %}
{% block scripts %}
<script type="text/javascript" nonce="{{ JS_NONCE }}">
var iAmOwed = '{{ 'i_am_owed_amount'|_|escape('js') }}';
var iOwe = '{{ 'i_owe_amount'|_|escape('js') }}';
</script>
<script src="v1/lib/leaflet/leaflet.js?v={{ FF_VERSION }}" nonce="{{ JS_NONCE }}"></script>
<script type="text/javascript" src="v1/js/lib/modernizr-custom.js?v={{ FF_VERSION }}" nonce="{{ JS_NONCE }}"></script>
<script type="text/javascript" src="v1/js/lib/jquery-ui.min.js?v={{ FF_VERSION }}" nonce="{{ JS_NONCE }}"></script>