mirror of
https://github.com/jcreek/bank-statement-analyser.git
synced 2026-07-13 10:53:46 +00:00
Implemented rudimentary csv import for transactions
This commit is contained in:
@@ -1,7 +1,7 @@
|
|||||||
<template>
|
<template>
|
||||||
<div>
|
<div>
|
||||||
<form @submit="addTransaction">
|
<form @submit="importCSV">
|
||||||
<input type="text" v-model="description" name="description" placeholder="Add transaction description...">
|
<textarea v-model="csv" name="csv" placeholder="Add statement csv..."></textarea>
|
||||||
<input type="submit" value="Submit" class="btn">
|
<input type="submit" value="Submit" class="btn">
|
||||||
</form>
|
</form>
|
||||||
</div>
|
</div>
|
||||||
@@ -13,25 +13,55 @@ export default {
|
|||||||
name: "AddTransaction",
|
name: "AddTransaction",
|
||||||
data() {
|
data() {
|
||||||
return {
|
return {
|
||||||
description: ''
|
csv: ''
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
addTransaction(e) {
|
importCSV(e) {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
const newTransaction = {
|
|
||||||
id: uuid.v4(),
|
|
||||||
date: "Monday 1st Jan",
|
var csv = this.csv;
|
||||||
transactionTypeDescription: "Type desc",
|
var lines = csv.replace(/["]/g, "").split('\n');
|
||||||
description: this.description,
|
var result = [];
|
||||||
isExpenditure: true,
|
|
||||||
amount: 10,
|
// Get the bank details from the top of the statement
|
||||||
balance: 0,
|
// var accountName = lines[0].split(",")[1];
|
||||||
tags: ["tag1", "tag2"]
|
// var accountBalance = lines[1].split(",")[1];
|
||||||
|
// var availableBalance = lines[2].split(",")[1];
|
||||||
|
|
||||||
|
// Get the transaction headers
|
||||||
|
var headers=lines[4].split(",");
|
||||||
|
// Loop through from line after transaction headers
|
||||||
|
for(var i=5;i<lines.length;i++){
|
||||||
|
var obj = {};
|
||||||
|
if (lines[i] != "") {
|
||||||
|
// If not a blank line
|
||||||
|
var currentline=lines[i].split(",");
|
||||||
|
for(var j=0;j<headers.length;j++){
|
||||||
|
obj[headers[j]] = currentline[j];
|
||||||
|
}
|
||||||
|
result.push(obj);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
// Send up to parent
|
|
||||||
this.$emit('add-transaction', newTransaction);
|
result.forEach (function(transaction) {
|
||||||
this.description = '';
|
alert(JSON.stringify(transaction["Date"]));
|
||||||
|
const newTransaction = {
|
||||||
|
id: uuid.v4(),
|
||||||
|
date: transaction["Date"],
|
||||||
|
transactionTypeDescription: transaction["Transaction type"],
|
||||||
|
description: transaction["Description"],
|
||||||
|
isExpenditure: transaction["Paid out"] != "" ? true : false,
|
||||||
|
amount: transaction["Paid out"] != "" ? transaction["Paid out"] : transaction["Paid in"],
|
||||||
|
balance: transaction["Balance"],
|
||||||
|
tags: ["tag1", "tag2"]
|
||||||
|
}
|
||||||
|
// Send up to parent
|
||||||
|
this.$emit('add-transaction', newTransaction);
|
||||||
|
this.description = '';
|
||||||
|
}.bind(this));
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user