diff --git a/BunqWebApp/settings.py b/BunqWebApp/settings.py index faa616b..cca2a9c 100644 --- a/BunqWebApp/settings.py +++ b/BunqWebApp/settings.py @@ -43,7 +43,7 @@ # SECURITY WARNING: don't run with debug turned on in production! -DEBUG = False +DEBUG = True ALLOWED_HOSTS = ['.combunqweb.herokuapp.com', '.localhost'] diff --git a/DataBase info/Manager_catagories.csv b/DataBase info/Manager_catagories.csv new file mode 100644 index 0000000..e003453 --- /dev/null +++ b/DataBase info/Manager_catagories.csv @@ -0,0 +1,3 @@ +"id","Naam","Rekening" +0,"Aliexpres","[u'DE60700111100250250061']" +3,"Gorilla","[u'DE60700111100250250061']" diff --git a/Manager/forms.py b/Manager/forms.py index 89435d7..01065e8 100644 --- a/Manager/forms.py +++ b/Manager/forms.py @@ -2,4 +2,5 @@ class GetNewData(forms.Form): initialText = '"Datum";"Bedrag";"Rekening";"Tegenrekening";"Naam";"Omschrijving"\n"2017-03-31";"-0,01";"NL01BUNQ1234567890";"NL48ABNA0502830042";"Spotify by Adyen";"Payment description"\n"2017-03-31";"1,64";"NL01BUNQ1234567890";"NL01BUNQ1234567890";"bunq";"Slice heeft deze request verstuurd voor de groep Family."\n\n\n#Only dutch headers supported atm\n#Only Bunq CSV supported atm, or place 2 columns with headers \'Bedrag\'(ammount) and \'Naam\'(name)\n#Press \'via CSV text\' to see this example in action\n#Lines that begin with \'#\' wil be ignored' - JSONTransactions = forms.CharField(initial = initialText, widget = forms.Textarea, label='Update with data', max_length=600) + JSONTransactions = forms.CharField(initial = initialText, widget = forms.Textarea, label='', max_length=600) + # JSONTransactionsFile = forms.FileField(label='') diff --git a/Manager/master.py b/Manager/master.py index dcde296..391b36a 100644 --- a/Manager/master.py +++ b/Manager/master.py @@ -1,7 +1,7 @@ import json import os import sys -from models import transactions +from models import transactions, catagories # NOTE: getting JSON from database # need to chage this to not use global vars @@ -10,7 +10,7 @@ def getInfo(method): if method == 'database': - # print 'Method: ',method + print 'Method: ',method data1 = list(transactions.objects.values_list('attrs', flat=True)) global data data = data1[0] @@ -19,14 +19,31 @@ def getInfo(method): global catagory catagory = catagory1[0] # print catagory + + + # NOTE: testing databse catagory retrieval + catName = list(catagories.objects.filter(Rekening__contains = ['DE60700111100250250061']).values_list('Naam')) + catList = [] + for x in catName: + # print 'catagoryNmae ',x[0] + catList.append(x[0]) + + print 'catagories found: ',catList + # NOTE: this should be implemented in getExpenses or a new fucntion createCatagory + # print type(catName) + # NOTE: endNote + + + + return {'data':data, 'catagory' : catagory} # NOTE: the idea is that these get returned so that Global vars should be used else: - # print 'Method: user input' + print 'Method: user input' data1 = method # print data1 global data data = data1 - print data + # print data catagory1 = list(transactions.objects.values_list('catagory', flat=True)) global catagory catagory = catagory1[0] @@ -64,7 +81,7 @@ def getExpenses(begin, end): elif x == len(catagory) - 1: catagoryObj["Other"] += round(float(data[k] ["Bedrag"].replace(",", ".")), 2) - # print "not in catagory list" + print "not in catagory list" if float(data[k]["Bedrag"].replace(",", ".")) < 0: totalExpanses += float(data[k]["Bedrag"].replace(",", ".")) diff --git a/Manager/migrations/0002_catagories.py b/Manager/migrations/0002_catagories.py new file mode 100644 index 0000000..f78bee5 --- /dev/null +++ b/Manager/migrations/0002_catagories.py @@ -0,0 +1,23 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.10.6 on 2017-04-07 10:03 +from __future__ import unicode_literals + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('Manager', '0001_initial'), + ] + + operations = [ + migrations.CreateModel( + name='catagories', + fields=[ + ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('Naam', models.CharField(max_length=10)), + ('Rekening', models.CharField(max_length=34)), + ], + ), + ] diff --git a/Manager/migrations/0003_auto_20170407_1027.py b/Manager/migrations/0003_auto_20170407_1027.py new file mode 100644 index 0000000..682e4a9 --- /dev/null +++ b/Manager/migrations/0003_auto_20170407_1027.py @@ -0,0 +1,21 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.10.6 on 2017-04-07 10:27 +from __future__ import unicode_literals + +import django.contrib.postgres.fields.jsonb +from django.db import migrations + + +class Migration(migrations.Migration): + + dependencies = [ + ('Manager', '0002_catagories'), + ] + + operations = [ + migrations.AlterField( + model_name='catagories', + name='Rekening', + field=django.contrib.postgres.fields.jsonb.JSONField(), + ), + ] diff --git a/Manager/migrations/0004_auto_20170407_1038.py b/Manager/migrations/0004_auto_20170407_1038.py new file mode 100644 index 0000000..9c59c02 --- /dev/null +++ b/Manager/migrations/0004_auto_20170407_1038.py @@ -0,0 +1,26 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.10.6 on 2017-04-07 10:38 +from __future__ import unicode_literals + +import django.contrib.postgres.fields +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('Manager', '0003_auto_20170407_1027'), + ] + + operations = [ + migrations.RemoveField( + model_name='catagories', + name='Rekening', + ),migrations.AddField( + model_name='catagories', + name= 'Rekening', + field=django.contrib.postgres.fields.ArrayField(base_field=models.CharField(max_length=34), blank=True, size=None), + + ) + + ] diff --git a/Manager/models.py b/Manager/models.py index 6834a43..fb40087 100644 --- a/Manager/models.py +++ b/Manager/models.py @@ -1,5 +1,5 @@ from __future__ import unicode_literals -from django.contrib.postgres.fields import JSONField +from django.contrib.postgres.fields import JSONField, ArrayField from django.db import models # Create your models here. @@ -7,4 +7,12 @@ class transactions(models.Model): """docstring for transactions.""" attrs = JSONField() catagory = JSONField() + +class catagories(models.Model): + Naam = models.CharField(max_length=10) + Rekening = ArrayField(models.CharField(max_length = 34), blank = True) + + def __str__(self): + return self.Naam + diff --git a/Manager/views.py b/Manager/views.py index 92c7bb1..56009c4 100644 --- a/Manager/views.py +++ b/Manager/views.py @@ -3,7 +3,6 @@ from django.template import loader from . import master import json -from models import transactions from .forms import GetNewData # Create your views here. @@ -18,12 +17,12 @@ def Manager(request): # print form inputData = json.loads(request.POST['json']) # print inputData - # print type(inputData) - # print master.getDate('','',inputData) + print type(inputData) + print master.getDate('','',inputData) return HttpResponse(json.dumps(master.getDate('','',inputData))) # print 'This should be the unser input',dict(inputData.lists()) - # if form.is_valid(): - # print "valed form" + if form.is_valid(): + print "valed form" else: form = GetNewData() # print form diff --git a/static/Manager/JS/index.js b/static/Manager/JS/index.js index b36c002..da51bb7 100644 --- a/static/Manager/JS/index.js +++ b/static/Manager/JS/index.js @@ -34,6 +34,8 @@ $(function() { // sendPost() input = $("#id_JSONTransactions").val() + console.log('click'); + console.log(input); parseCSV(input) }); $('#fileCSV').click(function(event) { @@ -161,6 +163,8 @@ function getUserGraphs(results) { function parseCSV(csv) { complete = function(results, file) { + console.log('parse complete'); + console.log(results.data); sendPost(results); }; Configuration = { @@ -194,7 +198,9 @@ function sendPost(json) { } frm = $("#textCSVForm"); frm.submit(function(event) { + console.log('submiting before prevent '); event.preventDefault() + console.log('submitting'); $.ajax({ url: frm.attr('action'), type: frm.attr('method'), @@ -209,13 +215,65 @@ frm.submit(function(event) { } }) .done(function(response) { + console.log(response); + console.log(typeof(response)); + console.log(JSON.parse(response)); sortedJSON = JSON.parse(response); getUserGraphs2(sortedJSON); }) .fail(function() {}) .always(function() { + console.log('send'); }); }); } + +function getUserGraphs2(data) { + income = [], + expenses = []; + for (var i = 0; i < data.length; i++) { + if (data[i][1] > 0) { + income.push({ + 'catName': data[i][0], + 'ammount': data[i][1] + }) + + } else { + expenses.push({ + 'catName': data[i][0], + 'ammount': data[i][1] * -1 + }) + + } + } + + var chart = AmCharts.makeChart("chartdiv4", { + "type": "pie", + "theme": "light", + "dataProvider": income, + "valueField": "ammount", + "titleField": "catName", + "balloon": { + "fixedPosition": true + }, + "export": { + "enabled": false + } + }); + var chart = AmCharts.makeChart("chartdiv3", { + "type": "pie", + "theme": "light", + "dataProvider": expenses, + "valueField": "ammount", + "titleField": "catName", + "balloon": { + "fixedPosition": true + }, + + "export": { + "enabled": false + } + }); +} diff --git a/templates/Manager/index.html b/templates/Manager/index.html index 3d69966..7dc6e96 100644 --- a/templates/Manager/index.html +++ b/templates/Manager/index.html @@ -54,6 +54,7 @@

Whitout 'DB'

+

input data to DB categorized and back

{% csrf_token %} {{from}}