flaschengeist/geruecht/model/creditList.py

283 lines
10 KiB
Python
Raw Normal View History

2019-04-11 21:56:55 +00:00
from geruecht import db
from datetime import datetime
class CreditList(db.Model):
2019-04-17 12:46:46 +00:00
""" DataBase Object Credit List:
2019-04-17 12:46:46 +00:00
Attributes:
id: id in Database. Is the Primary Key
<month>_guthaben: Credit of the Month.
<month>_schulden: Debt of the Month.
last_schulden: Debt or Credit of last Year.
year: Year of all Credits and Debts.
2019-04-23 22:08:25 +00:00
user_id: id from the User.
2019-04-17 12:46:46 +00:00
"""
2019-04-11 21:56:55 +00:00
id = db.Column(db.Integer, primary_key=True)
jan_guthaben = db.Column(db.Integer, nullable=False, default=0)
jan_schulden = db.Column(db.Integer, nullable=False, default=0)
feb_guthaben = db.Column(db.Integer, nullable=False, default=0)
feb_schulden = db.Column(db.Integer, nullable=False, default=0)
maer_guthaben = db.Column(db.Integer, nullable=False, default=0)
maer_schulden = db.Column(db.Integer, nullable=False, default=0)
apr_guthaben = db.Column(db.Integer, nullable=False, default=0)
apr_schulden = db.Column(db.Integer, nullable=False, default=0)
mai_guthaben = db.Column(db.Integer, nullable=False, default=0)
mai_schulden = db.Column(db.Integer, nullable=False, default=0)
jun_guthaben = db.Column(db.Integer, nullable=False, default=0)
jun_schulden = db.Column(db.Integer, nullable=False, default=0)
jul_guthaben = db.Column(db.Integer, nullable=False, default=0)
jul_schulden = db.Column(db.Integer, nullable=False, default=0)
aug_guthaben = db.Column(db.Integer, nullable=False, default=0)
aug_schulden = db.Column(db.Integer, nullable=False, default=0)
sep_guthaben = db.Column(db.Integer, nullable=False, default=0)
sep_schulden = db.Column(db.Integer, nullable=False, default=0)
okt_guthaben = db.Column(db.Integer, nullable=False, default=0)
okt_schulden = db.Column(db.Integer, nullable=False, default=0)
nov_guthaben = db.Column(db.Integer, nullable=False, default=0)
nov_schulden = db.Column(db.Integer, nullable=False, default=0)
dez_guthaben = db.Column(db.Integer, nullable=False, default=0)
dez_schulden = db.Column(db.Integer, nullable=False, default=0)
last_schulden = db.Column(db.Integer, nullable=False, default=0)
year = db.Column(db.Integer, nullable=False, default=datetime.now().year)
user_id = db.Column(db.Integer, db.ForeignKey('user.id'), nullable=False)
2019-04-23 22:08:25 +00:00
def getSchulden(self):
2019-05-02 16:50:59 +00:00
""" Get Schulden
This function calculate the total amount of them self.
From the Credit of the Month will the Amount of the Month subtract.
Finaly all Month will added together.
At Last the amount from last year will be subtract.
If the Return Value is negativ, the User has an Credit, else the User has an amount.
Returns:
double of the calculated amount
"""
2019-04-23 22:08:25 +00:00
jan = self.jan_guthaben - self.jan_schulden
feb = self.feb_guthaben - self.feb_schulden
maer = self.maer_guthaben - self.maer_schulden
apr = self.apr_guthaben - self.apr_schulden
mai = self.mai_guthaben - self.mai_schulden
jun = self.jun_guthaben - self.jun_schulden
jul = self.jul_guthaben - self.jul_schulden
aug = self.aug_guthaben - self.aug_schulden
sep = self.sep_guthaben - self.sep_schulden
okt = self.okt_guthaben - self.okt_schulden
nov = self.nov_guthaben - self.nov_schulden
dez = self.dez_guthaben - self.dez_schulden
sum = jan + feb + maer + apr + mai + jun + jul + aug + sep + okt + nov + dez - self.last_schulden
2019-04-23 22:08:25 +00:00
return sum
2019-05-02 16:50:59 +00:00
def getMonth(self, month=datetime.now().month):
""" Get Amount from month
This function returns the amount and credit of the month.
By default is month the actual month
Args:
month: which month you want to get the amount(1-12)
Returns:
double (credit, amount)
"""
2019-04-23 22:08:25 +00:00
retValue = None
if month == 1:
retValue = (self.jan_guthaben, self.jan_schulden)
elif month == 2:
retValue = (self.feb_guthaben, self.feb_schulden)
elif month == 3:
retValue = (self.mear_guthaben, self.maer_schulden)
elif month == 4:
retValue = (self.apr_guthaben, self.apr_schulden)
elif month == 5:
retValue = (self.mai_guthaben, self.mai_schulden)
elif month == 6:
retValue = (self.jun_guthaben, self.jun_schulden)
elif month == 7:
retValue = (self.jul_guthaben, self.jul_schulden)
elif month == 8:
retValue = (self.aug_guthaben, self.aug_schulden)
elif month == 9:
retValue = (self.sep_guthaben, self.sep_schulden)
elif month == 10:
retValue = (self.okt_guthaben, self.okt_schulden)
elif month == 11:
retValue = (self.nov_guthaben, self.nov_schulden)
elif month == 12:
retValue = (self.dez_guthaben, self.dez_schulden)
return retValue
def addAmount(self, amount, month=datetime.now().month):
2019-05-02 16:50:59 +00:00
""" Add Amount
This function add an amount to a month and returns the credit and amount of the month.
By default is month the actual month.
Args:
amount: the amount which is to add
month: in which month to add the amount (1-12)
2019-04-23 22:08:25 +00:00
2019-05-02 16:50:59 +00:00
Returns:
double (credit, amount)
"""
2019-04-23 22:08:25 +00:00
if month == 1:
self.jan_schulden += amount
retValue = (self.jan_guthaben, self.jan_schulden)
elif month == 2:
self.feb_schulden += amount
retValue = (self.feb_guthaben, self.feb_schulden)
elif month == 3:
self.maer_schulden += amount
retValue = (self.maer_guthaben, self.maer_schulden)
elif month == 4:
self.apr_schulden += amount
retValue = (self.apr_guthaben, self.apr_schulden)
elif month == 5:
self.mai_schulden += amount
retValue = (self.mai_guthaben, self.mai_schulden)
elif month == 6:
self.jun_schulden += amount
retValue = (self.jun_guthaben, self.jun_schulden)
elif month == 7:
self.jul_schulden += amount
retValue = (self.jul_guthaben, self.jul_schulden)
elif month == 8:
self.aug_schulden += amount
retValue = (self.aug_guthaben, self.aug_schulden)
elif month == 9:
self.sep_schulden += amount
retValue = (self.sep_guthaben, self.sep_schulden)
elif month == 10:
self.okt_schulden += amount
retValue = (self.okt_guthaben, self.okt_schulden)
elif month == 11:
self.nov_schulden += amount
retValue = (self.nov_guthaben, self.nov_schulden)
elif month == 12:
self.dez_schulden += amount
retValue = (self.dez_guthaben, self.dez_schulden)
db.session.commit()
return retValue
def addCredit(self, credit, month=datetime.now().month):
2019-05-02 16:50:59 +00:00
""" Add Credit
This function add an credit to a month and returns the credit and amount of the month.
By default is month the actual month.
Args:
credit: the credit which is to add
month: in which month to add the credit (1-12)
2019-05-02 16:50:59 +00:00
Returns:
double (credit, amount)
"""
if month == 1:
self.jan_guthaben += credit
retValue = (self.jan_guthaben, self.jan_schulden)
elif month == 2:
self.feb_guthaben += credit
retValue = (self.feb_guthaben, self.feb_schulden)
elif month == 3:
self.maer_guthaben += credit
retValue = (self.maer_guthaben, self.maer_schulden)
elif month == 4:
self.apr_guthaben += credit
retValue = (self.apr_guthaben, self.apr_schulden)
elif month == 5:
self.mai_guthaben += credit
retValue = (self.mai_guthaben, self.mai_schulden)
elif month == 6:
self.jun_guthaben += credit
retValue = (self.jun_guthaben, self.jun_schulden)
elif month == 7:
self.jul_guthaben += credit
retValue = (self.jul_guthaben, self.jul_schulden)
elif month == 8:
self.aug_guthaben += credit
retValue = (self.aug_guthaben, self.aug_schulden)
elif month == 9:
self.sep_guthaben += credit
retValue = (self.sep_guthaben, self.sep_schulden)
elif month == 10:
self.okt_guthaben += credit
retValue = (self.okt_guthaben, self.okt_schulden)
elif month == 11:
self.nov_guthaben += credit
retValue = (self.nov_guthaben, self.nov_schulden)
elif month == 12:
self.dez_guthaben += credit
retValue = (self.dez_guthaben, self.dez_schulden)
db.session.commit()
2019-04-23 22:08:25 +00:00
return retValue
def toJSON(self):
""" Create Dic to dump in JSON
2019-04-23 22:08:25 +00:00
Returns:
A Dic with static Attributes.
"""
dic = {
"jan": {
"credit": self.jan_guthaben,
"depts": self.jan_schulden},
"feb": {
"credit": self.feb_guthaben,
"depts": self.feb_schulden},
"maer": {
"credit": self.maer_guthaben,
"depts": self.maer_schulden},
"apr": {
"credit": self.apr_guthaben,
"depts": self.apr_schulden},
"mai": {
"credit": self.mai_guthaben,
"depts": self.mai_schulden},
"jun": {
"credit": self.jun_guthaben,
"depts": self.jun_schulden},
"jul": {
"credit": self.jul_guthaben,
"depts": self.jul_schulden},
"aug": {
"credit": self.aug_guthaben,
"depts": self.aug_schulden},
"sep": {
"credit": self.sep_guthaben,
"depts": self.sep_schulden},
"okt": {
"credit": self.okt_guthaben,
"depts": self.okt_schulden},
"nov": {
"credit": self.nov_guthaben,
"depts": self.nov_schulden},
"dez": {
"credit": self.dez_guthaben,
"depts": self.dez_schulden},
}
return dic