mirror of
https://github.com/jcreek/bank-statement-analyser.git
synced 2026-07-12 18:33:46 +00:00
Implemented rudimentary csv import for transactions
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
<template>
|
||||
<div>
|
||||
<form @submit="addTransaction">
|
||||
<input type="text" v-model="description" name="description" placeholder="Add transaction description...">
|
||||
<form @submit="importCSV">
|
||||
<textarea v-model="csv" name="csv" placeholder="Add statement csv..."></textarea>
|
||||
<input type="submit" value="Submit" class="btn">
|
||||
</form>
|
||||
</div>
|
||||
@@ -13,25 +13,55 @@ export default {
|
||||
name: "AddTransaction",
|
||||
data() {
|
||||
return {
|
||||
description: ''
|
||||
csv: ''
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
addTransaction(e) {
|
||||
importCSV(e) {
|
||||
e.preventDefault();
|
||||
|
||||
|
||||
var csv = this.csv;
|
||||
var lines = csv.replace(/["]/g, "").split('\n');
|
||||
var result = [];
|
||||
|
||||
// Get the bank details from the top of the statement
|
||||
// var accountName = lines[0].split(",")[1];
|
||||
// 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);
|
||||
}
|
||||
}
|
||||
|
||||
result.forEach (function(transaction) {
|
||||
alert(JSON.stringify(transaction["Date"]));
|
||||
const newTransaction = {
|
||||
id: uuid.v4(),
|
||||
date: "Monday 1st Jan",
|
||||
transactionTypeDescription: "Type desc",
|
||||
description: this.description,
|
||||
isExpenditure: true,
|
||||
amount: 10,
|
||||
balance: 0,
|
||||
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