Lots of new code and first submission thing.

This commit is contained in:
James Cole
2019-05-08 19:57:07 +02:00
parent 4c8f26f25e
commit 43a17d8676
10 changed files with 309 additions and 248 deletions

View File

@@ -19,10 +19,10 @@
-->
<template>
<form method="POST" action="xxxx" accept-charset="UTF-8" class="form-horizontal" id="store" enctype="multipart/form-data">
<form method="POST" action="transactions/store" accept-charset="UTF-8" class="form-horizontal" id="store" enctype="multipart/form-data">
<input name="_token" type="hidden" value="xxx">
<div class="row" v-if="transactions.transactions.length > 1">
<div class="row" v-if="transactions.length > 1">
<div class="col-lg-6">
<div class="box">
<div class="box-header with-border">
@@ -34,7 +34,7 @@
<div class="form-group">
<div class="col-sm-12">
<input type="text" class="form-control" name="group_title"
v-model="transactions.group_title"
v-model="group_title"
title="Description of the split transaction" autocomplete="off" placeholder="Description of the split transaction">
@@ -48,15 +48,18 @@
</div>
</div>
<div v-for="(transaction, index) in transactions.transactions">
<div v-for="(transaction, index) in transactions">
<div class="row">
<div class="col-lg-12">
<div class="box">
<div class="box-header with-border">
<h3 class="box-title splitTitle">
<span v-if="transactions.transactions.length > 1">Split {{ index+1 }} / {{ transactions.transactions.length }}</span>
<span v-if="transactions.transactions.length === 1">Transaction information</span>
<span v-if="transactions.length > 1">Split {{ index+1 }} / {{ transactions.length }}</span>
<span v-if="transactions.length === 1">Transaction information</span>
</h3>
<div class="box-tools pull-right" v-if="transactions.length > 1" x>
<button v-on:click="deleteTransaction(index, $event)" class="btn btn-xs btn-danger"><i class="fa fa-trash"></i></button>
</div>
</div>
<div class="box-body">
<div class="row">
@@ -84,7 +87,7 @@
<div class="form-group">
<div class="col-sm-12">
<input type="text" class="form-control" name="description[]"
:value="transaction.description"
v-model="transaction.description"
title="Description" autocomplete="off" placeholder="Description">
</div>
</div>
@@ -92,7 +95,7 @@
<div class="col-sm-12">
<input type="date" class="form-control" name="date[]"
title="Date" value="" autocomplete="off"
:value="transaction.date"
v-model="transaction.date"
:disabled="index > 0"
placeholder="Date">
</div>
@@ -141,6 +144,7 @@
<div class="col-lg-12">
<p>
<button class="btn btn-primary" v-on:click="addTransaction">Add another split</button>
<button class="btn btn-success">Submit</button>
</p>
</div>
</div>
@@ -150,99 +154,151 @@
<script>
export default {
name: "CreateTransaction",
components: {
},
components: {},
mounted() {
// not sure if something needs to happen here.
this.addTransaction();
},
ready() {
},
methods: {
addTransaction: function (e) {
let latest = this.transactions.transactions[this.transactions.transactions.length - 1];
this.transactions.transactions.push(latest);
e.preventDefault();
this.transactions.push({
description: "",
date: "",
amount: "",
foreign_amount: "",
source_account: {
id: 0,
name: "",
type: "",
//currency_id: window.defaultCurrency.id,
//currency_name: window.defaultCurrency.name,
//currency_code: window.defaultCurrency.code,
//currency_decimal_places: window.defaultCurrency.decimal_places,
currency_id: 0,
currency_name: '',
currency_code: '',
currency_decimal_places: 2,
allowed_types: []
},
destination_account: {
id: 0,
name: "",
type: "",
//currency_id: window.defaultCurrency.id,
//currency_name: window.defaultCurrency.name,
//currency_code: window.defaultCurrency.code,
//currency_decimal_places: window.defaultCurrency.decimal_places,
currency_id: 0,
currency_name: '',
currency_code: '',
currency_decimal_places: 2,
allowed_types: []
}
});
if (e) {
e.preventDefault();
}
},
setTransactionType: function (type) {
this.transactionType = type;
},
deleteTransaction: function (index, event) {
event.preventDefault();
for (const key in this.transactions) {
if (
this.transactions.hasOwnProperty(key) && /^0$|^[1-9]\d*$/.test(key) && key <= 4294967294) {
console.log('Transactions[' + key + '] exists: ' + this.transactions[key].description);
}
}
this.transactions.splice(index, 1);
console.log('Going to remove index ' + index);
for (const key in this.transactions) {
if (
this.transactions.hasOwnProperty(key) && /^0$|^[1-9]\d*$/.test(key) && key <= 4294967294) {
console.log('New: Transactions[' + key + '] exists: ' + this.transactions[key].description);
}
}
},
limitSourceType: function (type) {
let i;
for (i = 0; i < this.transactions.transactions.length; i++) {
this.transactions.transactions[i].source_account.allowed_types = [type];
for (i = 0; i < this.transactions.length; i++) {
this.transactions[i].source_account.allowed_types = [type];
}
},
limitDestinationType: function (type) {
let i;
for (i = 0; i < this.transactions.transactions.length; i++) {
this.transactions.transactions[i].destination_account.allowed_types = [type];
for (i = 0; i < this.transactions.length; i++) {
this.transactions[i].destination_account.allowed_types = [type];
}
},
selectedSourceAccount: function (index, model) {
if (typeof model === 'string') {
// cant change types, only name.
this.transactions.transactions[index].source_account.name = model;
this.transactions[index].source_account.name = model;
} else {
// todo maybe replace the entire model?
this.transactions.transactions[index].source_account.id = model.id;
this.transactions.transactions[index].source_account.name = model.name;
this.transactions.transactions[index].source_account.type = model.type;
this.transactions[index].source_account.id = model.id;
this.transactions[index].source_account.name = model.name;
this.transactions[index].source_account.type = model.type;
this.transactions.transactions[index].source_account.currency_id = model.currency_id;
this.transactions.transactions[index].source_account.currency_name = model.currency_name;
this.transactions.transactions[index].source_account.currency_code = model.currency_code;
this.transactions.transactions[index].source_account.currency_decimal_places = model.currency_decimal_places;
this.transactions[index].source_account.currency_id = model.currency_id;
this.transactions[index].source_account.currency_name = model.currency_name;
this.transactions[index].source_account.currency_code = model.currency_code;
this.transactions[index].source_account.currency_decimal_places = model.currency_decimal_places;
// force types on destination selector.
this.transactions.transactions[index].destination_account.allowed_types = window.allowedOpposingTypes.source[model.type];
this.transactions[index].destination_account.allowed_types = window.allowedOpposingTypes.source[model.type];
}
},
selectedDestinationAccount: function (index, model) {
if (typeof model === 'string') {
// cant change types, only name.
this.transactions.transactions[index].destination_account.name = model;
this.transactions[index].destination_account.name = model;
} else {
// todo maybe replace the entire model?
this.transactions.transactions[index].destination_account.id = model.id;
this.transactions.transactions[index].destination_account.name = model.name;
this.transactions.transactions[index].destination_account.type = model.type;
this.transactions[index].destination_account.id = model.id;
this.transactions[index].destination_account.name = model.name;
this.transactions[index].destination_account.type = model.type;
this.transactions.transactions[index].destination_account.currency_id = model.currency_id;
this.transactions.transactions[index].destination_account.currency_name = model.currency_name;
this.transactions.transactions[index].destination_account.currency_code = model.currency_code;
this.transactions.transactions[index].destination_account.currency_decimal_places = model.currency_decimal_places;
this.transactions[index].destination_account.currency_id = model.currency_id;
this.transactions[index].destination_account.currency_name = model.currency_name;
this.transactions[index].destination_account.currency_code = model.currency_code;
this.transactions[index].destination_account.currency_decimal_places = model.currency_decimal_places;
// force types on destination selector.
this.transactions.transactions[index].source_account.allowed_types = window.allowedOpposingTypes.destination[model.type];
this.transactions[index].source_account.allowed_types = window.allowedOpposingTypes.destination[model.type];
}
},
clearSource: function (index) {
this.transactions.transactions[index].source_account.id = 0;
this.transactions.transactions[index].source_account.name = "";
this.transactions.transactions[index].source_account.type = "";
this.transactions.transactions[index].destination_account.allowed_types = [];
this.transactions[index].source_account.id = 0;
this.transactions[index].source_account.name = "";
this.transactions[index].source_account.type = "";
this.transactions[index].destination_account.allowed_types = [];
// if there is a destination model, reset the types of the source
// by pretending we selected it again.
if (this.transactions.transactions[index].destination_account) {
if (this.transactions[index].destination_account) {
console.log('There is a destination account.');
this.selectedDestinationAccount(index, this.transactions.transactions[index].destination_account);
this.selectedDestinationAccount(index, this.transactions[index].destination_account);
}
},
clearDestination: function (index) {
this.transactions.transactions[index].destination_account.id = 0;
this.transactions.transactions[index].destination_account.name = "";
this.transactions.transactions[index].destination_account.type = "";
this.transactions.transactions[index].source_account.allowed_types = [];
this.transactions[index].destination_account.id = 0;
this.transactions[index].destination_account.name = "";
this.transactions[index].destination_account.type = "";
this.transactions[index].source_account.allowed_types = [];
// if there is a source model, reset the types of the destination
// by pretending we selected it again.
if (this.transactions.transactions[index].source_account) {
if (this.transactions[index].source_account) {
console.log('There is a source account.');
this.selectedSourceAccount(index, this.transactions.transactions[index].source_account);
this.selectedSourceAccount(index, this.transactions[index].source_account);
}
}
},
@@ -253,45 +309,8 @@
data() {
return {
transactionType: null,
transactions: {
group_title: "",
transactions: [
{
description: "",
date: "",
amount: "",
foreign_amount: "",
source_account: {
id: 0,
name: "",
type: "",
//currency_id: window.defaultCurrency.id,
//currency_name: window.defaultCurrency.name,
//currency_code: window.defaultCurrency.code,
//currency_decimal_places: window.defaultCurrency.decimal_places,
currency_id: 0,
currency_name: '',
currency_code: '',
currency_decimal_places: 2,
allowed_types: []
},
destination_account: {
id: 0,
name: "",
type: "",
//currency_id: window.defaultCurrency.id,
//currency_name: window.defaultCurrency.name,
//currency_code: window.defaultCurrency.code,
//currency_decimal_places: window.defaultCurrency.decimal_places,
currency_id: 0,
currency_name: '',
currency_code: '',
currency_decimal_places: 2,
allowed_types: []
}
}
]
}
group_title: "",
transactions: []
};
},
}