This commit is contained in:
James Cole 2020-03-13 12:46:52 +01:00
parent 5145707b94
commit 8724ba05ca
No known key found for this signature in database
GPG Key ID: C16961E655E74B5E
13 changed files with 104 additions and 26 deletions

View File

@ -90,6 +90,9 @@ class CreateController extends Controller
{
app('preferences')->mark();
$sourceId = (int)request()->get('source');
$destinationId = (int)request()->get('destination');
/** @var AccountRepositoryInterface $repository */
$repository = app(AccountRepositoryInterface::class);
$cash = $repository->getCashAccount();
@ -112,7 +115,7 @@ class CreateController extends Controller
'transactions.create', compact(
'subTitleIcon', 'cash', 'objectType', 'subTitle', 'defaultCurrency', 'previousUri', 'optionalFields', 'preFilled',
'allowedOpposingTypes',
'accountToTypes'
'accountToTypes','sourceId','destinationId'
)
);
}

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -115,6 +115,10 @@
transactionType() {
this.triggerTransactionType();
},
accountName() {
console.log('AccountSelect watch accountName!');
this.name = this.accountName;
},
accountTypeFilters() {
let types = this.accountTypeFilters.join(',');
if (0 === this.accountTypeFilters.length) {

View File

@ -214,11 +214,60 @@
components: {},
mounted() {
this.addTransactionToArray();
},
ready() {
document.onreadystatechange = () => {
if (document.readyState === "complete") {
this.prefillSourceAccount();
this.prefillDestinationAccount();
}
}
},
methods: {
prefillSourceAccount() {
if (0 === window.sourceId) {
return;
}
this.getAccount(window.sourceId, 'source_account');
},
prefillDestinationAccount() {
if (0 === destinationId) {
return;
}
this.getAccount(window.destinationId, 'destination_account');
},
getAccount(accountId, slot) {
const uri = './api/v1/accounts/' + accountId + '?_token=' + document.head.querySelector('meta[name="csrf-token"]').content;
axios.get(uri).then(response => {
let model = response.data.data.attributes;
model.type = this.fullAccountType(model.type, model.liability_type);
model.id = parseInt(response.data.data.id);
if ('source_account' === slot) {
this.selectedSourceAccount(0, model);
}
if('destination_account' === slot) {
this.selectedDestinationAccount(0, model);
}
}).catch(error => {
console.warn('Could not auto fill account');
console.warn(error);
});
},
fullAccountType: function (shortType, liabilityType) {
let searchType = shortType;
if ('liabilities' === shortType) {
searchType = liabilityType;
}
let arr = {
'asset': 'Asset account',
'loan': 'Loan',
'debt': 'Debt',
'mortgage': 'Mortgage'
};
let value = arr[searchType] ?? searchType;
console.log('FULL account type: ' + value);
return value;
},
convertData: function () {
// console.log('Now in convertData()');
let data = {
@ -239,12 +288,13 @@
// the presence of a source or destination account
firstSource = this.transactions[0].source_account.type;
firstDestination = this.transactions[0].destination_account.type;
console.log('Type of first source is ' + firstSource);
if ('invalid' === transactionType && ['Asset account', 'Loan', 'Debt', 'Mortgage'].includes(firstSource)) {
if ('invalid' === transactionType && ['asset', 'Asset account', 'Loan', 'Debt', 'Mortgage'].includes(firstSource)) {
transactionType = 'withdrawal';
}
if ('invalid' === transactionType && ['Asset account', 'Loan', 'Debt', 'Mortgage'].includes(firstDestination)) {
if ('invalid' === transactionType && ['asset', 'Asset account', 'Loan', 'Debt', 'Mortgage'].includes(firstDestination)) {
transactionType = 'deposit';
}
@ -759,11 +809,13 @@
},
selectedSourceAccount: function (index, model) {
// console.log('Now in selectedSourceAccount()');
console.log('Now in selectedSourceAccount()');
if (typeof model === 'string') {
console.log('model is string.')
// cant change types, only name.
this.transactions[index].source_account.name = model;
} else {
console.log('model is NOT string.')
this.transactions[index].source_account = {
id: model.id,
name: model.name,
@ -773,12 +825,14 @@
currency_code: model.currency_code,
currency_decimal_places: model.currency_decimal_places,
allowed_types: this.transactions[index].source_account.allowed_types,
default_allowed_types: ['Asset account','Revenue account','Loan','Debt','Mortgage']
default_allowed_types: ['Asset account', 'Revenue account', 'Loan', 'Debt', 'Mortgage']
};
// force types on destination selector.
this.transactions[index].destination_account.allowed_types = window.allowedOpposingTypes.source[model.type];
}
console.log('Transactions:');
console.log(this.transactions);
},
selectedDestinationAccount: function (index, model) {
// console.log('Now in selectedDestinationAccount()');

View File

@ -68,7 +68,7 @@
props: ['source', 'destination', 'transactionType', 'value', 'error', 'no_currency', 'title',],
mounted() {
console.log('ForeignAmountSelect mounted()');
//console.log('ForeignAmountSelect mounted()');
this.liability = false;
this.loadCurrencies();
},
@ -83,15 +83,15 @@
},
watch: {
source: function () {
console.log('ForeignAmountSelect watch source');
//console.log('ForeignAmountSelect watch source');
this.changeData();
},
destination: function () {
console.log('ForeignAmountSelect watch destination');
//console.log('ForeignAmountSelect watch destination');
this.changeData();
},
transactionType: function () {
console.log('ForeignAmountSelect watch transaction type (is now ' + this.transactionType + ')');
//console.log('ForeignAmountSelect watch transaction type (is now ' + this.transactionType + ')');
this.changeData();
}
},
@ -103,11 +103,11 @@
this.$emit('clear:amount')
},
hasError: function () {
console.log('ForeignAmountSelect hasError');
//console.log('ForeignAmountSelect hasError');
return this.error.length > 0;
},
handleInput(e) {
console.log('ForeignAmountSelect handleInput');
//console.log('ForeignAmountSelect handleInput');
let obj = {
amount: this.$refs.amount.value,
currency_id: this.$refs.currency_select.value,
@ -117,7 +117,7 @@
);
},
changeData: function () {
console.log('ForeignAmountSelect changeData');
//console.log('ForeignAmountSelect changeData');
this.enabledCurrencies = [];
let destType = this.destination.type ? this.destination.type.toLowerCase() : 'invalid';
let srcType = this.source.type ? this.source.type.toLowerCase() : 'invalid';

View File

@ -62,7 +62,6 @@
</template>
<script>
import Autocomplete from '@trevoreyre/autocomplete-vue'
export default {
props: ['error', 'value', 'index'],
name: "TransactionDescription",
@ -71,7 +70,6 @@
this.descriptionAutoCompleteURI = document.getElementsByTagName('base')[0].href + "json/transaction-journals/all?search=";
},
components: {
Autocomplete
},
data() {
return {

View File

@ -970,6 +970,7 @@ return [
'no_budget' => '(no budget)',
'account_per_budget' => 'Account per budget',
'account_per_category' => 'Account per category',
'create_new_object' => 'Create',
'empty' => '(empty)',
'all_other_budgets' => '(all other budgets)',
'all_other_accounts' => '(all other accounts)',

View File

@ -74,20 +74,36 @@
{% endif %}
<div class="box-footer clearfix">
<!-- Single button -->
<div class="btn-group">
<a type="button" class="btn btn-success dropdown-toggle" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
{{ 'create_new_object'|_ }} <span class="caret"></span>
</a>
<a class="btn btn-default"
href="{{ route('accounts.show', [data[1].id]) }}">{{ formatAmountByAccount(data[1], data[1]|balance, false) }}</a>
<ul class="dropdown-menu">
<li><a href="{{ route('transactions.create', ['withdrawal']) }}?source={{ data[1].id }}">{{ 'create_new_withdrawal'|_ }}</a></li>
<li><a href="{{ route('transactions.create', ['deposit']) }}?destination={{ data[1].id }}">{{ 'create_new_deposit'|_ }}</a></li>
<li><a href="{{ route('transactions.create', ['transfer']) }}?source={{ data[1].id }}">{{ 'create_new_transfer'|_ }}</a></li>
</ul>
</div>
<!--
<div class="btn-group" role="group">
</div>
<div class="btn-group" role="group" aria-label="...">
<div class="btn-group" role="group">
<a href="{{ route('transactions.create', ['withdrawal']) }}" class="btn btn-success"><i
<a href="" class="btn btn-success"><i
class="fa fa-plus fa-fw"></i> {{ 'create_new_transaction'|_ }}</a>
</div>
<a class="btn btn-default"
href="{{ route('accounts.show',data[1].id) }}">{{ formatAmountByAccount(data[1], data[1]|balance, false) }}</a>
</div>
</div>
-->
</div>
</div>
{% endfor %}

View File

@ -14,5 +14,7 @@
var defaultCurrency = {{ defaultCurrency.toArray()|json_encode|raw }};
var cashAccountId = {{ cash.id }};
var previousUri = '{{ previousUri }}';
window.sourceId = {{ sourceId }};
window.destinationId = {{ destinationId }};
</script>
{% endblock %}