Files
firefly-iii/frontend/src/components/transactions/Create.vue

433 lines
15 KiB
Vue
Raw Normal View History

2020-11-12 05:58:06 +01:00
<!--
- Create.vue
- Copyright (c) 2020 james@firefly-iii.org
-
- This file is part of Firefly III (https://github.com/firefly-iii).
-
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU Affero General Public License as
- published by the Free Software Foundation, either version 3 of the
- License, or (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU Affero General Public License for more details.
-
- You should have received a copy of the GNU Affero General Public License
- along with this program. If not, see <https://www.gnu.org/licenses/>.
-->
<template>
2020-12-24 18:48:00 +01:00
<div>
2021-01-17 08:52:40 +01:00
<div class="row" v-for="(transaction, index) in this.transactions">
2020-12-24 18:48:00 +01:00
<div class="col">
<div class="card">
<div class="card-header">
2020-12-25 12:49:28 +01:00
<h3 class="card-title">
<span v-if="0 === transactions.length">{{ $t('firefly.create_new_transaction') }}</span>
<span v-if="transactions.length > 1">{{ $t('firefly.single_split') }} {{ index + 1 }} / {{ transactions.length }}</span>
2020-12-25 12:49:28 +01:00
</h3>
<div v-if="transactions.length > 1" class="card-tools">
2021-01-17 08:52:40 +01:00
<button class="btn btn-xs btn-danger" type="button" v-on:click="removeTransaction(index)"><i
2020-12-25 12:49:28 +01:00
class="fa fa-trash"></i></button>
</div>
2020-12-24 18:48:00 +01:00
</div>
<!-- /.card-header -->
<div class="card-body">
2021-01-17 19:52:53 +01:00
<h4>{{ $t('firefly.basic_journal_information') }}</h4>
2020-12-30 18:43:16 +01:00
<div class="row">
<div class="col">
<p class="d-block d-sm-none">XS</p>
<p class="d-none d-sm-block d-md-none">SM</p>
<p class="d-none d-md-block d-lg-none">MD</p>
<p class="d-none d-lg-block d-xl-none">LG</p>
<p class="d-none d-xl-block">XL</p>
</div>
</div>
<!-- description etc, 3 rows -->
<div class="row">
<div class="col">
2021-01-17 08:52:40 +01:00
Description:
<TransactionDescription
2021-01-17 19:52:53 +01:00
v-model="transaction.description"
:index="index"
></TransactionDescription>
</div>
</div>
<!-- source and destination -->
<div class="row">
<div class="col-xl-5 col-lg-5 col-md-10 col-sm-12 col-xs-12">
<!-- SOURCE -->
<TransactionAccount
2021-01-17 19:52:53 +01:00
v-model="transaction.source_account"
direction="source"
:index="index"
2020-12-30 18:43:16 +01:00
/>
</div>
<!-- switcharoo! -->
<div class="col-xl-2 col-lg-2 col-md-2 col-sm-12 text-center d-none d-sm-block">
2020-12-30 18:43:16 +01:00
<SwitchAccount
2021-01-03 07:11:44 +01:00
:index="index"
2020-12-30 18:43:16 +01:00
/>
</div>
<!-- destination -->
<div class="col-xl-5 col-lg-5 col-md-12 col-sm-12 col-xs-12">
2020-12-30 18:43:16 +01:00
<!-- DESTINATION -->
<TransactionAccount
2021-01-17 19:52:53 +01:00
v-model="transaction.destination_account"
2020-12-30 18:43:16 +01:00
direction="destination"
:index="index"
/>
</div>
</div>
<!-- amount -->
<div class="row">
<div class="col-xl-5 col-lg-5 col-md-10 col-sm-12 col-xs-12">
2020-12-30 18:43:16 +01:00
<!-- AMOUNT -->
2021-01-03 07:11:44 +01:00
<TransactionAmount :index="index"/>
<!--
2020-12-30 18:43:16 +01:00
-->
</div>
<div class="col-xl-2 col-lg-2 col-md-2 col-sm-12 text-center d-none d-sm-block">
2021-01-03 07:11:44 +01:00
<TransactionForeignCurrency :index="index"/>
2020-11-12 05:58:06 +01:00
</div>
<div class="col-xl-5 col-lg-5 col-md-12 col-sm-12 col-xs-12">
2021-01-03 07:11:44 +01:00
<TransactionForeignAmount :index="index"/>
</div>
</div>
<!-- dates -->
<div class="row">
2020-12-30 18:43:16 +01:00
<div class="col-xl-5 col-lg-5 col-md-12 col-sm-12 col-xs-12">
<TransactionDate
:index="index"
/>
</div>
2020-12-30 18:43:16 +01:00
<div class="col-xl-5 col-lg-5 col-md-12 col-sm-12 col-xs-12 offset-xl-2 offset-lg-2">
2021-01-17 19:52:53 +01:00
<TransactionCustomDates :index="index" :enabled-dates="customDateFields" />
</div>
</div>
<h4>{{ $t('firefly.transaction_journal_meta') }}</h4>
<!-- meta -->
<div class="row">
<div class="col">
<TransactionBudget
2021-01-17 19:52:53 +01:00
v-model="transaction.budget_id"
:index="index"
/>
2021-01-17 08:52:40 +01:00
<TransactionCategory
2021-01-17 19:52:53 +01:00
v-model="transaction.category"
2021-01-17 08:52:40 +01:00
:index="index"
/>
</div>
<div class="col">
2021-01-17 08:52:40 +01:00
<TransactionBill
2021-01-17 19:52:53 +01:00
v-model="transaction.bill_id"
2021-01-17 08:52:40 +01:00
:index="index"
/>
<TransactionTags
:index="index"
2021-01-17 19:52:53 +01:00
v-model="transaction.tags"
2021-01-17 08:52:40 +01:00
/>
<TransactionPiggyBank
:index="index"
2021-01-17 19:52:53 +01:00
v-model="transaction.piggy_bank_id"
2021-01-17 08:52:40 +01:00
/>
2020-11-12 05:58:06 +01:00
</div>
</div>
<h4>{{ $t('firefly.transaction_journal_extra') }}</h4>
<div class="row">
<div class="col">
2021-01-17 08:52:40 +01:00
<TransactionInternalReference
:index="index"
2021-01-17 19:52:53 +01:00
v-model="transaction.internal_reference"
2021-01-17 08:52:40 +01:00
/>
<TransactionExternalUrl
:index="index"
2021-01-17 19:52:53 +01:00
v-model="transaction.external_url"
2021-01-17 08:52:40 +01:00
/>
<TransactionNotes
:index="index"
2021-01-17 19:52:53 +01:00
v-model="transaction.notes"
2021-01-17 08:52:40 +01:00
/>
</div>
<div class="col">
2021-01-17 08:52:40 +01:00
<div class="form-group">
<div class="text-xs d-none d-lg-block d-xl-block">
{{ $t('firefly.journal_links') }}
</div>
<div class="row">
<div class="col">
<p>
<em>No transaction links</em>
</p>
<ul class="list-group">
<li class="list-group-item">
<em>is paid by</em>
<a href="#">Some other transaction</a> (<span class="text-success">$ 12.34</span>)
<div class="btn-group btn-group-xs float-right">
<a href="#" class="btn btn-xs btn-default"><i class="far fa-edit"></i></a>
<a href="#" class="btn btn-xs btn-danger"><i class="far fa-trash-alt"></i></a>
</div>
</li>
<li class="list-group-item">
<em>is paid by</em>
<a href="#">Some other transaction</a> (<span class="text-success">$ 12.34</span>)
<div class="btn-group btn-group-xs float-right">
<a href="#" class="btn btn-xs btn-default"><i class="far fa-edit"></i></a>
<a href="#" class="btn btn-xs btn-danger"><i class="far fa-trash-alt"></i></a>
</div>
</li>
</ul>
<div class="form-text">
<a href="#" class="btn btn-default"><i class="fas fa-plus"></i></a>
</div>
</div>
</div>
</div>
</div>
</div>
2021-01-17 19:52:53 +01:00
2020-11-12 05:58:06 +01:00
</div>
2020-12-24 18:48:00 +01:00
<!-- /.card-body -->
2020-11-12 05:58:06 +01:00
</div>
</div>
2020-12-24 18:48:00 +01:00
</div>
<!-- buttons -->
<!-- button -->
<div class="row">
<div class="col">
<button @click="addTransaction" class="btn btn-primary">{{ $t('firefly.add_another_split') }}</button>
2020-11-12 05:58:06 +01:00
</div>
2020-12-24 18:48:00 +01:00
<div class="col">
<p class="float-right">
<button @click="submitTransaction" :disabled="isSubmitting" class="btn btn-success">Store transaction</button>
<br/>
</p>
</div>
</div>
<div class="row">
<div class="col float-right">
<p class="text-right">
<small class="text-muted">Create another another another <input type="checkbox"/></small><br/>
<small class="text-muted">Return here <input type="checkbox"/></small><br/>
</p>
2020-11-12 05:58:06 +01:00
</div>
</div>
2020-12-24 18:48:00 +01:00
2020-11-12 05:58:06 +01:00
</div>
</template>
<script>
2021-01-17 08:52:40 +01:00
import {createNamespacedHelpers} from 'vuex'
2020-12-24 18:48:00 +01:00
import TransactionDescription from "./TransactionDescription";
import TransactionDate from "./TransactionDate";
import TransactionBudget from "./TransactionBudget";
import TransactionAccount from "./TransactionAccount";
2020-12-30 18:43:16 +01:00
import SwitchAccount from "./SwitchAccount";
import TransactionAmount from "./TransactionAmount";
2021-01-03 07:11:44 +01:00
import TransactionForeignAmount from "./TransactionForeignAmount";
import TransactionForeignCurrency from "./TransactionForeignCurrency";
import TransactionCustomDates from "./TransactionCustomDates";
2021-01-17 08:52:40 +01:00
import TransactionCategory from "./TransactionCategory";
import TransactionBill from "./TransactionBill";
import TransactionTags from "./TransactionTags";
import TransactionPiggyBank from "./TransactionPiggyBank";
import TransactionInternalReference from "./TransactionInternalReference";
import TransactionExternalUrl from "./TransactionExternalUrl";
import TransactionNotes from "./TransactionNotes";
2020-12-24 18:48:00 +01:00
const {mapState, mapGetters, mapActions, mapMutations} = createNamespacedHelpers('transactions/create')
2020-11-12 05:58:06 +01:00
export default {
2020-12-24 18:48:00 +01:00
name: "Create",
2021-01-03 07:11:44 +01:00
components: {
2021-01-17 08:52:40 +01:00
TransactionNotes,
TransactionExternalUrl,
TransactionInternalReference,
TransactionPiggyBank,
TransactionTags,
TransactionBill,
TransactionCategory,
2021-01-03 07:11:44 +01:00
TransactionCustomDates,
TransactionForeignCurrency,
TransactionForeignAmount, TransactionAmount, SwitchAccount, TransactionAccount, TransactionBudget, TransactionDescription, TransactionDate
},
2020-12-24 18:48:00 +01:00
created() {
2020-12-30 18:43:16 +01:00
this.storeAllowedOpposingTypes();
this.storeAccountToTransaction();
2021-01-03 07:11:44 +01:00
this.storeCustomDateFields();
2020-12-24 18:48:00 +01:00
this.addTransaction();
},
data() {
return {
groupTitle: '',
isSubmitting: false
}
},
computed: {
...mapGetters([
'transactionType', // -> this.someGetter
'transactions', // -> this.someOtherGetter
2021-01-17 19:52:53 +01:00
'customDateFields',
'date'
2020-12-24 18:48:00 +01:00
])
},
methods: {
...mapMutations(
[
'addTransaction',
2020-12-30 18:43:16 +01:00
'deleteTransaction',
'setAllowedOpposingTypes',
'setAccountToTransaction',
],
2020-12-24 18:48:00 +01:00
),
2021-01-17 08:52:40 +01:00
removeTransaction: function(index) {
// store.commit('addCustomer'
this.$store.commit('transactions/create/deleteTransaction', {index: index});
},
2021-01-03 07:11:44 +01:00
storeCustomDateFields: function () {
// TODO may include all custom fields in the future.
axios.get('./api/v1/preferences/transaction_journal_optional_fields').then(response => {
let fields = response.data.data.attributes.data;
let allDateFields = ['interest_date', 'book_date', 'process_date', 'due_date', 'payment_date', 'invoice_date'];
let selectedDateFields = {
interest_date: false,
book_date: false,
process_date: false,
due_date: false,
payment_date: false,
invoice_date: false,
};
for (let key in fields) {
if (fields.hasOwnProperty(key)) {
2021-01-17 08:52:40 +01:00
if (-1 !== allDateFields.indexOf(key)) {
2021-01-03 07:11:44 +01:00
selectedDateFields[key] = fields[key];
}
}
}
this.$store.commit('transactions/create/setCustomDateFields', selectedDateFields);
});
},
2020-12-30 18:43:16 +01:00
/**
*
*/
storeAllowedOpposingTypes: function () {
this.setAllowedOpposingTypes(window.allowedOpposingTypes);
},
2021-01-03 07:11:44 +01:00
storeAccountToTransaction: function () {
2020-12-30 18:43:16 +01:00
this.setAccountToTransaction(window.accountToTransaction);
},
2020-12-24 18:48:00 +01:00
/**
*
*/
submitTransaction: function () {
this.isSubmitting = true;
2020-12-30 18:43:16 +01:00
// console.log('Now in submit()');
2020-12-24 18:48:00 +01:00
const uri = './api/v1/transactions';
const data = this.convertData();
console.log('Would have submitted:');
console.log(data);
this.isSubmitting = false;
},
/**
*
*/
convertData: function () {
2020-12-30 18:43:16 +01:00
// console.log('now in convertData');
2020-12-24 18:48:00 +01:00
let data = {
//'group_title': null,
'transactions': []
};
for (let key in this.transactions) {
if (this.transactions.hasOwnProperty(key) && /^0$|^[1-9]\d*$/.test(key) && key <= 4294967294) {
data.transactions.push(this.convertSplit(key, this.transactions[key]));
}
}
return data;
},
/**
*
* @param key
* @param array
*/
convertSplit: function (key, array) {
let currentSplit = {
// basic
description: array.description,
2021-01-03 07:11:44 +01:00
date: (array.date + ' ' + array.time).trim(),
2020-12-30 18:43:16 +01:00
// account
source_id: array.source_account.id ?? null,
source_name: array.source_account.name ?? null,
destination_id: array.destination_account.id ?? null,
destination_name: array.destination_account.name ?? null,
2021-01-03 07:11:44 +01:00
// amount:
currency_id: array.currency_id,
amount: array.amount,
foreign_currency_id: array.foreign_currency_id,
foreign_amount: array.foreign_amount,
2021-01-17 08:52:40 +01:00
// meta data
budget_id: array.budget_id,
2021-01-17 08:52:40 +01:00
category: array.category,
bill_id: array.bill_id,
tags: array.tags,
piggy_bank_id: array.piggy_bank_id,
// optional date fields (6x):
interest_date: array.interest_date,
book_date: array.book_date,
process_date: array.process_date,
due_date: array.due_date,
payment_date: array.payment_date,
invoice_date: array.invoice_date,
// other optional fields:
internal_reference: array.internal_reference,
external_url: array.external_url,
notes: array.notes,
2020-12-24 18:48:00 +01:00
};
// return it.
return currentSplit;
}
// addTransactionToArray: function (e) {
// console.log('Now in addTransactionToArray()');
// this.$store.
//
// this.transactions.push({
// description: '',
// });
// if (e) {
// e.preventDefault();
// }
},
2020-11-12 05:58:06 +01:00
}
</script>
<style scoped>
</style>