2019-01-14 23:25:42 +00:00
|
|
|
from geruecht import db, login_manager
|
2019-01-13 23:25:25 +00:00
|
|
|
from threading import Timer
|
2019-01-14 23:25:42 +00:00
|
|
|
from flask_login import UserMixin
|
|
|
|
from datetime import date
|
|
|
|
|
|
|
|
|
|
|
|
@login_manager.user_loader
|
|
|
|
def load_finanzer(finanzer_id):
|
|
|
|
return Finanzer.query.get(int(finanzer_id))
|
|
|
|
|
2019-01-13 19:07:46 +00:00
|
|
|
|
|
|
|
class User(db.Model):
|
|
|
|
id = db.Column(db.Integer, primary_key=True)
|
|
|
|
username = db.Column(db.String(20), unique=True, nullable=False)
|
|
|
|
sum = db.Column(db.Float, nullable=False, default=0.0)
|
|
|
|
|
2019-01-14 23:25:42 +00:00
|
|
|
jan = db.Column(db.Float, nullable=False, default=0)
|
|
|
|
jan_sub = db.Column(db.Float, nullable=False, default=0)
|
|
|
|
jan_year = db.Column(db.Integer, nullable=False, default=date.today().year)
|
|
|
|
|
|
|
|
feb = db.Column(db.Float, nullable=False, default=0)
|
|
|
|
feb_sub = db.Column(db.Float, nullable=False, default=0)
|
|
|
|
feb_year = db.Column(db.Integer, nullable=False, default=date.today().year)
|
|
|
|
|
|
|
|
maer = db.Column(db.Float, nullable=False, default=0)
|
|
|
|
maer_sub = db.Column(db.Float, nullable=False, default=0)
|
|
|
|
maer_year = db.Column(db.Integer, nullable=False, default=date.today().year)
|
|
|
|
|
|
|
|
apr = db.Column(db.Float, nullable=False, default=0)
|
|
|
|
apr_sub = db.Column(db.Float, nullable=False, default=0)
|
|
|
|
apr_year = db.Column(db.Integer, nullable=False, default=date.today().year)
|
|
|
|
|
|
|
|
mai = db.Column(db.Float, nullable=False, default=0)
|
|
|
|
mai_sub = db.Column(db.Float, nullable=False, default=0)
|
|
|
|
mai_year = db.Column(db.Integer, nullable=False, default=date.today().year)
|
|
|
|
|
|
|
|
jun = db.Column(db.Float, nullable=False, default=0)
|
|
|
|
jun_sub = db.Column(db.Float, nullable=False, default=0)
|
|
|
|
jun_year = db.Column(db.Integer, nullable=False, default=date.today().year)
|
|
|
|
|
|
|
|
jul = db.Column(db.Float, nullable=False, default=0)
|
|
|
|
jul_sub = db.Column(db.Float, nullable=False, default=0)
|
|
|
|
jul_year = db.Column(db.Integer, nullable=False, default=date.today().year)
|
|
|
|
|
|
|
|
aug = db.Column(db.Float, nullable=False, default=0)
|
|
|
|
aug_sub = db.Column(db.Float, nullable=False, default=0)
|
|
|
|
aug_year = db.Column(db.Integer, nullable=False, default=date.today().year)
|
|
|
|
|
|
|
|
sep = db.Column(db.Float, nullable=False, default=0)
|
|
|
|
sep_sub = db.Column(db.Float, nullable=False, default=0)
|
|
|
|
sep_year = db.Column(db.Integer, nullable=False, default=date.today().year)
|
|
|
|
|
|
|
|
okt = db.Column(db.Float, nullable=False, default=0)
|
|
|
|
okt_sub = db.Column(db.Float, nullable=False, default=0)
|
|
|
|
okt_year = db.Column(db.Integer, nullable=False, default=date.today().year)
|
|
|
|
|
|
|
|
nov = db.Column(db.Float, nullable=False, default=0)
|
|
|
|
nov_sub = db.Column(db.Float, nullable=False, default=0)
|
|
|
|
nov_year = db.Column(db.Integer, nullable=False, default=date.today().year)
|
|
|
|
|
|
|
|
dez = db.Column(db.Float, nullable=False, default=0)
|
|
|
|
dez_sub = db.Column(db.Float, nullable=False, default=0)
|
|
|
|
dez_year = db.Column(db.Integer, nullable=False, default=date.today().year)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def getsum(self):
|
|
|
|
jan = self.jan - self.jan_sub
|
|
|
|
feb = self.feb - self.feb_sub
|
|
|
|
maer = self.maer - self.maer_sub
|
|
|
|
apr = self.apr - self.apr_sub
|
|
|
|
mai = self.mai - self.mai_sub
|
|
|
|
jun = self.jun - self.jun_sub
|
|
|
|
jul = self.jul - self.jul_sub
|
|
|
|
aug = self.aug - self.aug_sub
|
|
|
|
sep = self.sep - self.sep_sub
|
|
|
|
okt = self.okt - self.okt_sub
|
|
|
|
nov = self.nov - self.nov_sub
|
|
|
|
dez = self.dez - self.dez_sub
|
|
|
|
|
|
|
|
result = jan + feb + maer + apr + mai + jun + jul + aug + sep + okt + nov + dez
|
|
|
|
return result
|
|
|
|
|
|
|
|
def add_sub(self, value):
|
|
|
|
year = date.today().year
|
|
|
|
month = date.today().month
|
|
|
|
|
|
|
|
if month == 1:
|
|
|
|
if year == self.jan_year:
|
|
|
|
self.jan_sub += value
|
|
|
|
else:
|
|
|
|
self.jan = 0
|
|
|
|
self.jan_sub = value
|
|
|
|
self.jan_year = year;
|
|
|
|
elif month == 2:
|
|
|
|
if year == self.feb_year:
|
|
|
|
self.feb_sub += value
|
|
|
|
else:
|
|
|
|
self.feb = 0
|
|
|
|
self.feb_sub = value
|
|
|
|
self.feb_year = year
|
|
|
|
elif month == 3:
|
|
|
|
if year == self.maer_year:
|
|
|
|
self.maer_sub += value
|
|
|
|
else:
|
|
|
|
self.maer = 0
|
|
|
|
self.maer_sub = value
|
|
|
|
self.maer_year = year
|
|
|
|
elif month == 4:
|
|
|
|
if year == self.apr_year:
|
|
|
|
self.apr_sub += value
|
|
|
|
else:
|
|
|
|
self.apr = 0
|
|
|
|
self.apr_sub = value
|
|
|
|
self.apr_year = year
|
|
|
|
elif month == 5:
|
|
|
|
if year == self.mai_year:
|
|
|
|
self.mai_sub += value
|
|
|
|
else:
|
|
|
|
self.mai = 0
|
|
|
|
self.mai_sub = value
|
|
|
|
self.mai_year = year
|
|
|
|
elif month == 6:
|
|
|
|
if year == self.jun_year:
|
|
|
|
self.jun_sub += value
|
|
|
|
else:
|
|
|
|
self.jun = 0
|
|
|
|
self.jun_sub = value
|
|
|
|
self.jun_year = year
|
|
|
|
elif month == 7:
|
|
|
|
if year == self.jul_year:
|
|
|
|
self.jul_sub += value
|
|
|
|
else:
|
|
|
|
self.jul = 0
|
|
|
|
self.jul_sub = value
|
|
|
|
self.jul_year = year
|
|
|
|
elif month == 8:
|
|
|
|
if year == self.aug_year:
|
|
|
|
self.aug_sub += value
|
|
|
|
else:
|
|
|
|
self.aug = 0
|
|
|
|
self.aug_sub = value
|
|
|
|
self.aug_year = year
|
|
|
|
elif month == 9:
|
|
|
|
if year == self.sep_year:
|
|
|
|
self.sep_sub += value
|
|
|
|
else:
|
|
|
|
self.sep = 0
|
|
|
|
self.sep_sub = value
|
|
|
|
self.sep_year = year
|
|
|
|
elif month == 10:
|
|
|
|
if year == self.okt_year:
|
|
|
|
self.okt_sub += value
|
|
|
|
else:
|
|
|
|
self.okt = 0
|
|
|
|
self.okt_sub = value
|
|
|
|
self.okt_year = year
|
|
|
|
elif month == 11:
|
|
|
|
if year == self.nov_year:
|
|
|
|
self.nov_sub += value
|
|
|
|
else:
|
|
|
|
self.nov = 0
|
|
|
|
self.nov_sub = value
|
|
|
|
self.nov_year = year
|
|
|
|
elif month == 12:
|
|
|
|
if year == self.dez_year:
|
|
|
|
self.dez_sub += value
|
|
|
|
else:
|
|
|
|
self.dez = 0
|
|
|
|
self.dez_sub = value
|
|
|
|
self.dez_year = year
|
|
|
|
else:
|
|
|
|
raise IndexError('Mehr monate gibt es nicht')
|
|
|
|
|
|
|
|
|
2019-01-13 19:07:46 +00:00
|
|
|
def add(self, value):
|
2019-01-14 23:25:42 +00:00
|
|
|
|
|
|
|
year = date.today().year
|
|
|
|
month = date.today().month
|
|
|
|
|
|
|
|
if month == 1 :
|
|
|
|
if year == self.jan_year:
|
|
|
|
self.jan += value
|
|
|
|
else:
|
|
|
|
self.jan = value
|
|
|
|
self.jan_sub = 0
|
|
|
|
self.jan_year = year
|
|
|
|
elif month == 2:
|
|
|
|
if year == self.feb_year:
|
|
|
|
self.feb += value
|
|
|
|
else:
|
|
|
|
self.feb = value
|
|
|
|
self.feb_sub = 0
|
|
|
|
self.feb_year = year
|
|
|
|
elif month == 3:
|
|
|
|
if year == self.maer_year:
|
|
|
|
self.maer += value
|
|
|
|
else:
|
|
|
|
self.maer = value
|
|
|
|
self.mear_sub = 0
|
|
|
|
self.mear_year = year
|
|
|
|
elif month == 4:
|
|
|
|
if year == self.apr_year:
|
|
|
|
self.apr += value
|
|
|
|
else:
|
|
|
|
self.apr = value
|
|
|
|
self.apr_sub = 0
|
|
|
|
self.apr_year = year
|
|
|
|
elif month == 5:
|
|
|
|
if year == self.mai_year:
|
|
|
|
self.mai += value
|
|
|
|
else:
|
|
|
|
self.mai = value
|
|
|
|
self.mai_sub = 0
|
|
|
|
self.mai_year = year
|
|
|
|
elif month == 6:
|
|
|
|
if year == self.jun_year:
|
|
|
|
self.jun += value
|
|
|
|
else:
|
|
|
|
self.jun = value
|
|
|
|
self.jun_sub = 0
|
|
|
|
self.jun_year = year
|
|
|
|
elif month == 7:
|
|
|
|
if year == self.jul_year:
|
|
|
|
self.jul += value
|
|
|
|
else:
|
|
|
|
self.jul = value
|
|
|
|
self.jul_sub = 0
|
|
|
|
self.jul_year = year
|
|
|
|
elif month == 8:
|
|
|
|
if year == self.aug_year:
|
|
|
|
self.aug += value
|
|
|
|
else:
|
|
|
|
self.aug = value
|
|
|
|
self.aug_sub = 0
|
|
|
|
self.aug_year = year
|
|
|
|
elif month == 9:
|
|
|
|
if year == self.sep_year:
|
|
|
|
self.sep += value
|
|
|
|
else:
|
|
|
|
self.sep = value
|
|
|
|
self.sep_sub = 0
|
|
|
|
self.sep_year = year
|
|
|
|
elif month == 10:
|
|
|
|
if year == self.okt_year:
|
|
|
|
self.okt += value
|
|
|
|
else:
|
|
|
|
self.okt = value
|
|
|
|
self.okt_sub = 0
|
|
|
|
self.okt_year = year
|
|
|
|
elif month == 11:
|
|
|
|
if year == self.nov_year:
|
|
|
|
self.nov += value
|
|
|
|
else:
|
|
|
|
self.nov = value
|
|
|
|
self.nov_sub = 0
|
|
|
|
self.nov_year = year
|
|
|
|
elif month == 12:
|
|
|
|
if year == self.dez_year:
|
|
|
|
self.dez += value
|
|
|
|
else:
|
|
|
|
self.dez = value
|
|
|
|
self.dez_sub = 0
|
|
|
|
self.dez_year = year
|
|
|
|
else:
|
|
|
|
raise IndexError('Mehr monate gibt es nicht')
|
|
|
|
|
|
|
|
|
|
|
|
def storner(self, value, month):
|
|
|
|
|
|
|
|
if month == 1:
|
|
|
|
self.jan = self.jan - value
|
|
|
|
elif month == 2:
|
|
|
|
self.feb = self.feb - value
|
|
|
|
elif month == 3:
|
|
|
|
self.maer = self.maer - value
|
|
|
|
elif month == 4:
|
|
|
|
self.apr = self.apr - value
|
|
|
|
elif month == 5:
|
|
|
|
self.mai = self.mai - value
|
|
|
|
elif month == 6:
|
|
|
|
self.jun = self.jun - value
|
|
|
|
elif month == 7:
|
|
|
|
self.jul = self.jul - value
|
|
|
|
elif month == 8:
|
|
|
|
self.aug = self.aug - value
|
|
|
|
elif month == 9:
|
|
|
|
self.sep = self.sep - value
|
|
|
|
elif month == 10:
|
|
|
|
self.okt = self.okt - value
|
|
|
|
elif month == 11:
|
|
|
|
self.nov = self.nov - value
|
|
|
|
elif month == 12:
|
|
|
|
self.dez = self.dez - value
|
|
|
|
else:
|
|
|
|
raise IndexError('Mehr monate gibt es nicht')
|
2019-01-13 19:07:46 +00:00
|
|
|
|
|
|
|
def __repr__(self):
|
|
|
|
return f"User('{self.username}', '{self.sum}')"
|
2019-01-13 23:25:25 +00:00
|
|
|
|
|
|
|
|
2019-01-14 23:25:42 +00:00
|
|
|
class Finanzer(db.Model, UserMixin):
|
|
|
|
id = db.Column(db.Integer, primary_key=True)
|
|
|
|
username = db.Column(db.String(20), unique=True, nullable=False)
|
|
|
|
password = db.Column(db.String(60), nullable=False)
|
|
|
|
|
|
|
|
def __repr__(self):
|
|
|
|
return f"Finanzer('{self.username}')"
|
|
|
|
|
|
|
|
|
2019-01-13 23:25:25 +00:00
|
|
|
class History:
|
|
|
|
history = []
|
|
|
|
user = None
|
|
|
|
|
|
|
|
def __init__(self, history, user, value):
|
2019-01-14 23:25:42 +00:00
|
|
|
self.history = history
|
2019-01-13 23:25:25 +00:00
|
|
|
self.history.append(self)
|
|
|
|
self.user = user
|
2019-01-14 23:25:42 +00:00
|
|
|
self.month = date.today().month
|
2019-01-13 23:25:25 +00:00
|
|
|
self.value = value
|
|
|
|
self.timer = Timer(60, self.kill)
|
|
|
|
self.timer.start()
|
|
|
|
|
|
|
|
def exec(self):
|
|
|
|
self.timer.cancel()
|
2019-01-14 23:25:42 +00:00
|
|
|
User.query.filter_by(username=self.user.username).first().storner(self.value, self.month)
|
2019-01-13 23:25:25 +00:00
|
|
|
self.kill()
|
|
|
|
|
|
|
|
def kill(self):
|
|
|
|
print("{} deledet from history".format(self.user))
|
|
|
|
self.history.remove(self)
|
|
|
|
print(self.history)
|
2019-01-14 23:25:42 +00:00
|
|
|
|
|
|
|
|
2019-01-13 23:25:25 +00:00
|
|
|
'''
|
|
|
|
def __repr__(self):
|
|
|
|
print(f'self:{self}, history:{self.history}, user:{self.user}, value:{self.value}')
|
|
|
|
|
|
|
|
def __str__(self):
|
|
|
|
print(f'self:{self}, history:{self.history}, user:{self.user}, value:{self.value}')
|
2019-01-14 23:25:42 +00:00
|
|
|
'''
|