Firefly III: a personal finances manager
PHP accountingbudgetbudgetingbudgetscash-flowcashflowcredit-carddockerexpensesfinancefinancesfinanciallinuxmoneypaycheckpersonal-financephpphp7
Can now also edit transfers.
James Cole32b6e030ef35
diff --git a/public/js/ff/transactions/single/common.js b/public/js/ff/transactions/single/common.jsindex fe86aedf6c..d98ac6afce 100644--- a/public/js/ff/transactions/single/common.js+++ b/public/js/ff/transactions/single/common.js@@ -122,4 +122,85 @@ function updateNativeAmount(data) {console.log('Returned data:');console.log(data);$('#ffInput_native_amount').val(data.amount);+}++/**+ * Instructions for transfers+ */+function getTransferExchangeInstructions() {+ var sourceAccount = $('select[name="source_account_id"]').val();+ var destAccount = $('select[name="destination_account_id"]').val();++ var sourceCurrency = accountInfo[sourceAccount].preferredCurrency;+ var destinationCurrency = accountInfo[destAccount].preferredCurrency;++ return transferInstructions.replace('@source_name', accountInfo[sourceAccount].name)+ .replace('@dest_name', accountInfo[destAccount].name)+ .replace(/@source_currency/g, currencyInfo[sourceCurrency].name)+ .replace(/@dest_currency/g, currencyInfo[destinationCurrency].name);+}++/**+ * When the transaction to create is a transfer some more checks are necessary.+ */+function validateCurrencyForTransfer() {+ if (what !== "transfer") {+ return;+ }+ $('#source_amount_holder').show();+ var sourceAccount = $('select[name="source_account_id"]').val();+ var destAccount = $('select[name="destination_account_id"]').val();+ var sourceCurrency = accountInfo[sourceAccount].preferredCurrency;+ var sourceSymbol = currencyInfo[sourceCurrency].symbol;+ var destinationCurrency = accountInfo[destAccount].preferredCurrency;+ var destinationSymbol = currencyInfo[destinationCurrency].symbol;++ $('#source_amount_holder').show().find('.non-selectable-currency-symbol').text(sourceSymbol);++ if (sourceCurrency === destinationCurrency) {+ console.log('Both accounts accept ' + sourceCurrency);+ $('#destination_amount_holder').hide();+ $('#amount_holder').hide();+ return;+ }+ console.log('Source accepts #' + sourceCurrency + ', destination #' + destinationCurrency);+ $('#ffInput_exchange_rate_instruction').text(getTransferExchangeInstructions());+ $('#exchange_rate_instruction_holder').show();+ $('input[name="source_amount"]').val($('input[name="amount"]').val());+ convertSourceToDestination();++ $('#destination_amount_holder').show().find('.non-selectable-currency-symbol').text(destinationSymbol);+ $('#amount_holder').hide();+}++/**+ * Convert from source amount currency to destination currency for transfers.+ *+ */+function convertSourceToDestination() {+ var sourceAccount = $('select[name="source_account_id"]').val();+ var destAccount = $('select[name="destination_account_id"]').val();++ var sourceCurrency = accountInfo[sourceAccount].preferredCurrency;+ var destinationCurrency = accountInfo[destAccount].preferredCurrency;++ var sourceCurrencyCode = currencyInfo[sourceCurrency].code;+ var destinationCurrencyCode = currencyInfo[destinationCurrency].code;++ var date = $('#ffInput_date').val();+ var amount = $('#ffInput_source_amount').val();+ $('#ffInput_amount').val(amount);+ var uri = 'json/rate/' + sourceCurrencyCode + '/' + destinationCurrencyCode + '/' + date + '?amount=' + amount;+ console.log('Will grab ' + uri);+ $.get(uri).done(updateDestinationAmount);+}++/**+ * Once the data has been grabbed will update the field (for transfers)+ * @param data+ */+function updateDestinationAmount(data) {+ console.log('Returned data:');+ console.log(data);+ $('#ffInput_destination_amount').val(data.amount);}\ No newline at end of filediff --git a/public/js/ff/transactions/single/create.js b/public/js/ff/transactions/single/create.jsindex c30ef4a2fd..ed48eb28a3 100644--- a/public/js/ff/transactions/single/create.js+++ b/public/js/ff/transactions/single/create.js@@ -41,38 +41,6 @@ $(document).ready(function () {$('.currency-option').on('click', selectsForeignCurrency);});-/**- * Convert from source amount currency to destination currency for transfers.- *- */-function convertSourceToDestination() {- var sourceAccount = $('select[name="source_account_id"]').val();- var destAccount = $('select[name="destination_account_id"]').val();-- var sourceCurrency = accountInfo[sourceAccount].preferredCurrency;- var destinationCurrency = accountInfo[destAccount].preferredCurrency;-- var sourceCurrencyCode = currencyInfo[sourceCurrency].code;- var destinationCurrencyCode = currencyInfo[destinationCurrency].code;-- var date = $('#ffInput_date').val();- var amount = $('#ffInput_source_amount').val();- $('#ffInput_amount').val(amount);- var uri = 'json/rate/' + sourceCurrencyCode + '/' + destinationCurrencyCode + '/' + date + '?amount=' + amount;- console.log('Will grab ' + uri);- $.get(uri).done(updateDestinationAmount);-}--/**- * Once the data has been grabbed will update the field (for transfers)- * @param data- */-function updateDestinationAmount(data) {- console.log('Returned data:');- console.log(data);- $('#ffInput_destination_amount').val(data.amount);-}-/*** This function generates a small helper text to explain the user* that they have selected a foreign currency.@@ -89,22 +57,6 @@ function getExchangeInstructions() {return text;}-/**- * Same as above but for transfers- */-function getTransferExchangeInstructions() {- var sourceAccount = $('select[name="source_account_id"]').val();- var destAccount = $('select[name="destination_account_id"]').val();-- var sourceCurrency = accountInfo[sourceAccount].preferredCurrency;- var destinationCurrency = accountInfo[destAccount].preferredCurrency;-- return transferInstructions.replace('@source_name', accountInfo[sourceAccount].name)- .replace('@dest_name', accountInfo[destAccount].name)- .replace(/@source_currency/g, currencyInfo[sourceCurrency].name)- .replace(/@dest_currency/g, currencyInfo[destinationCurrency].name);-}-/*** There is an input that shows the currency symbol that is native to the selected* acccount. So when the user changes the selected account, the native currency is updated:@@ -122,39 +74,6 @@ function updateNativeCurrency() {validateCurrencyForTransfer();}-/**- * When the transaction to create is a transfer some more checks are necessary.- */-function validateCurrencyForTransfer() {- if (what !== "transfer") {- return;- }- $('#source_amount_holder').show();- var sourceAccount = $('select[name="source_account_id"]').val();- var destAccount = $('select[name="destination_account_id"]').val();- var sourceCurrency = accountInfo[sourceAccount].preferredCurrency;- var sourceSymbol = currencyInfo[sourceCurrency].symbol;- var destinationCurrency = accountInfo[destAccount].preferredCurrency;- var destinationSymbol = currencyInfo[destinationCurrency].symbol;-- $('#source_amount_holder').show().find('.non-selectable-currency-symbol').text(sourceSymbol);-- if (sourceCurrency === destinationCurrency) {- console.log('Both accounts accept ' + sourceCurrency);- $('#destination_amount_holder').hide();- $('#amount_holder').hide();- return;- }- console.log('Source accepts #' + sourceCurrency + ', destination #' + destinationCurrency);- $('#ffInput_exchange_rate_instruction').text(getTransferExchangeInstructions());- $('#exchange_rate_instruction_holder').show();- $('input[name="source_amount"]').val($('input[name="amount"]').val());- convertSourceToDestination();-- $('#destination_amount_holder').show().find('.non-selectable-currency-symbol').text(destinationSymbol);- $('#amount_holder').hide();-}-/****/@@ -211,10 +130,6 @@ function updateForm() {$('#destination_amount_holder').hide();// show normal amount:$('#amount_holder').show();-- // update the amount thing:- updateNativeCurrency();-break;case 'deposit':// show source_name and dest_id:@@ -242,10 +157,6 @@ function updateForm() {$('#destination_amount_holder').hide();// show normal amount:$('#amount_holder').show();-- // update the amount thing:- updateNativeCurrency();-break;case 'transfer':// show source_id and dest_id:@@ -263,15 +174,13 @@ function updateForm() {} else {$('#piggy_bank_id_holder').show();}-- // update the amount thing:- updateNativeCurrency();-break;default:// no action.break;}+ // update the amount thing:+ updateNativeCurrency();}/**diff --git a/public/js/ff/transactions/single/edit.js b/public/js/ff/transactions/single/edit.jsindex bb05169fa2..62e0380e30 100644--- a/public/js/ff/transactions/single/edit.js+++ b/public/js/ff/transactions/single/edit.js@@ -15,10 +15,16 @@ $(document).ready(function () {setAutocompletes();updateInitialPage();-// respond to user input:$('.currency-option').on('click', selectsForeignCurrency);$('#ffInput_amount').on('change', convertForeignToNative);++ // respond to transfer changes:+ $('#ffInput_source_account_id').on('change',validateCurrencyForTransfer);+ $('#ffInput_destination_account_id').on('change',validateCurrencyForTransfer);++ // convert source currency to destination currency (slightly different routine for transfers)+ $('#ffInput_source_amount').on('change', convertSourceToDestination);});/**@@ -27,6 +33,24 @@ $(document).ready(function () {function updateInitialPage() {console.log('Native currency is #' + journalData.native_currency.id + ' and (foreign) currency id is #' + journalData.currency.id);++ if (journal.transaction_type.type === "Transfer") {+ $('#native_amount_holder').hide();+ $('#amount_holder').hide();++ if (journalData.native_currency.id === journalData.currency.id) {+ $('#exchange_rate_instruction_holder').hide();+ $('#destination_amount_holder').hide();+ }+ if (journalData.native_currency.id !== journalData.currency.id) {+ $('#exchange_rate_instruction_holder').show().find('p').text(getTransferExchangeInstructions());++ }++ return;+ }++if (journalData.native_currency.id === journalData.currency.id) {$('#exchange_rate_instruction_holder').hide();$('#native_amount_holder').hide();@@ -35,6 +59,7 @@ function updateInitialPage() {if (journalData.native_currency.id !== journalData.currency.id) {$('#ffInput_exchange_rate_instruction').text(getExchangeInstructions());}+}diff --git a/resources/views/transactions/single/edit.twig b/resources/views/transactions/single/edit.twigindex f1110fd358..4ef0d2ceaa 100644--- a/resources/views/transactions/single/edit.twig+++ b/resources/views/transactions/single/edit.twig@@ -62,7 +62,11 @@{# INSTRUCTIONS FOR EXCHANGE RATES #}{{ ExpandedForm.staticText('exchange_rate_instruction','(here be text)') }}- {{ ExpandedForm.nonSelectableAmount('native_amount', data.native_amount, {'currency' : data.native_currency}) }}+ {{ ExpandedForm.nonSelectableAmount('native_amount', data.native_amount, {currency: data.native_currency}) }}++ {{ ExpandedForm.nonSelectableAmount('source_amount', data.native_amount, {currency: data.native_currency }) }}++ {{ ExpandedForm.nonSelectableAmount('destination_amount', data.amount, {currency: data.currency }) }}{# ALWAYS SHOW DATE #}{{ ExpandedForm.date('date',data['date']) }}@@ -245,6 +249,7 @@var journal = {{ journal.toArray()|json_encode|raw }};var journalData = {{ data|json_encode|raw }};var exchangeRateInstructions = "{{ 'exchange_rate_instructions'|_|escape('js') }}";+ var transferInstructions = "{{ 'transfer_exchange_rate_instructions'|_|escape('js') }}";</script><script type="text/javascript" src="js/ff/transactions/single/common.js"></script><script type="text/javascript" src="js/ff/transactions/single/edit.js"></script>