-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.py
288 lines (252 loc) · 10.8 KB
/
app.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
from audioop import add
from crypt import methods
import email
from hashlib import new
from locale import currency
from multiprocessing.connection import Client
from socketserver import ThreadingUnixStreamServer
from flask import Flask, render_template, url_for, request, session
from flask_sqlalchemy import SQLAlchemy
from sqlalchemy.exc import SQLAlchemyError
from sqlalchemy import create_engine, MetaData, Table, Column, Integer, String
import pymysql
import sqlalchemy
from auth import User, verificationComplete
from config_db import Admin, BankAccount, CLientAccount, ClientDetails, Company, Currency, Employee, ToVerify, Vendor, VendorDetails, app
app.secret_key = "somekey"
# index page
@app.route("/")
def index():
return render_template("index.html")
# client page # ENTRANCE PAGE # TO DO
@app.route("/client")
def client():
return render_template("client.html")
# employee page # ENTRANCE PAGE # TO DO
@app.route("/employee")
def employee():
return render_template("employee.html")
# register section # TO DO
@app.route("/register")
def register():
return render_template("register.html")
@app.route("/register", methods=["POST", "GET"])
def register_submit():
name = request.form["name"]
surname = request.form["surname"]
user_name = request.form["user_name"]
user_pass = request.form["user_pass"]
pass_again = request.form["user_pass_again"]
email = request.form["email"]
companies = Company.query.all()
if user_pass != pass_again:
return render_template("register.html", invalid="no matching passwords")
newToVerify = ToVerify(name, surname, user_name, user_pass, email)
if newToVerify.addToVerify():
return render_template("messagePage.html", my_message="waiting for verification")
else:
return render_template("register.html", invalid="something went wrong")
# employee sign in section
@app.route("/employeeEnter")
def employeeEnterPage():
return render_template("employeeEnter.html", ses_type=session["type"])
@app.route("/employeeEnter", methods=["POST", "GET"])
def employeeEnter():
username = request.form["name"]
userpass = request.form["password"]
newUser = User(username, userpass)
if newUser.auth_employee() == True:
session["type"] = "employee"
session["user"] = newUser.id
session["company"] = Employee.query.filter_by(user=newUser.id).first().company
return render_template("employee.html", ses_type=session["type"])
return render_template('employeeEnter.html', invalid="incorrect entry")
# client sign in section
@app.route("/clientEnter")
def clientEnterPage():
return render_template("clientEnter.html")
@app.route("/clientEnter", methods=["POST", "GET"])
def clientEnter():
username = request.form["name"]
userpass = request.form["password"]
newUser = User(username, userpass)
if newUser.auth_client() != False:
session["type"] = "client"
session["user"] = newUser.id
return render_template("client.html", name=newUser.id, idexists=newUser.id, ses_type=session["type"])
return render_template('clientEnter.html', invalid="incorrect entry")
# verify
@app.route("/verify")
def verifyPage():
all_companies = Company.query.all()
return render_template("verify.html", company_data=all_companies)
@app.route("/verify", methods=["POST", "GET"])
def verify():
all_companies = Company.query.all()
user_email = request.form["user_email"]
verification_code = request.form["verif_code"]
type = request.form.get('type')
company = request.form.get("companies")
if verificationComplete(user_email, verification_code, type, company):
return render_template("messagePage.html", my_message="succesfully verified")
else:
return render_template("verify.html", company_data=all_companies)
# employee add new vendor
@app.route("/createNewVendor")
def createNewVendorPage():
return render_template("createNewVendor.html", ses_type=session["type"])
@app.route("/createNewVendor", methods=["POST", "Get"])
def createNewVendor():
vendor_name = request.form["vendor_name"]
vendor_address = request.form["vendor_address"]
vendor_zip = request.form["vendor_zip"]
vendor_city = request.form["vendor_city"]
vendor_country = request.form["vendor_country"]
vendor_email = request.form["vendor_email"]
vendor_phone = request.form["vendor_phone"]
vendor_vat = request.form["vendor_vat"]
vendor_commerce = request.form["vendor_commerce"]
thecompany = Company.query.filter_by(id=session["company"]).first()
new_vendor = Vendor(name=vendor_name, company=thecompany)
if new_vendor.newVendor():
new_vendor_det = VendorDetails(vendor=new_vendor, address=vendor_address, zip=vendor_zip, city=vendor_city, country=vendor_country, email=vendor_email, phone=vendor_phone, vat=vendor_vat, commerce=vendor_commerce)
if new_vendor_det.newVendorDetails():
return render_template("messagePage.html", my_message="created new vendor", ses_type=session["type"])
return render_template("createNewVendor.html", message="something went wrong", ses_type=session["type"])
# employee add new BankAccount
@app.route("/newBankAccount")
def newBankAccountPage():
currencies = Currency.query.all()
return render_template("newBankAccount.html", ses_type=session["type"], currency_data=currencies)
@app.route("/newBankAccount", methods=["POST", "GET"])
def newBankAccount():
currencies = Currency.query.all()
init_amount = request.form["init_amount"]
name = request.form["account_name"]
iban = request.form["account_iban"]
currency = request.form.get("currency")
selected_currency = Currency.query.filter_by(name=currency).first()
thecompany = Company.query.filter_by(id=session["company"]).first()
new_account = BankAccount(start_amount=init_amount, name=name, iban=iban, curreny=selected_currency, company=thecompany)
if new_account.createAccount():
return render_template("messagePage.html", my_message="new account created succesfully", ses_type=session["type"])
return render_template("newBankAccount.html", message="something went wrong", ses_type=session["type"], currency_data=currencies)
# admin sign in section
@app.route("/admin")
def adminPage():
return render_template("admin.html")
@app.route("/admin", methods=["POST", "GET"])
def admin():
admin_name = request.form["admin_name"]
admin_pass = request.form["admin_pass"]
admin = Admin.query.filter_by(admin_name=admin_name,admin_pass=admin_pass).first()
if admin != None:
session["type"] = "admin"
#session["user"] = admin.id
return render_template("adminPanel.html")
return render_template("admin.html", message="invalid name or pass")
# admin add new currency
@app.route("/currencies", methods=["POST", "GET"])
def currenciesPage():
currencies = Currency.query.all()
data = []
for currency in currencies:
newdata = {}
newdata["id"] = currency.id
newdata["name"] = currency.name
newdata["code"] = currency.code
data.append(newdata)
return render_template("currencies.html", rowdata=data, ses_type=session["type"])
@app.route("/deleteRow")
def deleteRow():
mid = request.args.get("mid")
toDel = Currency.query.filter_by(id=mid).first()
if toDel != None:
toDel.delCurrency()
return currenciesPage()
return render_template("currencies.html", message="something went wrong")
@app.route("/addToCurrencies", methods=["POST", "GET"])
def addToCurrencies():
print("created new currency")
cr_name = request.form["currency_name"]
cr_code = request.form["currency_code"]
newCr = Currency(name=cr_name, code=cr_code)
if newCr.createCurrency():
return currenciesPage()
return render_template("currencies.html", message="something went wrong")
# admin add new company
@app.route("/companies", methods=["POST", "GET"])
def companiesPage():
companies = Company.query.all()
currencies = Currency.query.all()
data = []
for company in companies:
newdata = {}
newdata["id"] = company.id
newdata["name"] = company.name
newdata["default_currency"] = company.default_currency
data.append(newdata)
return render_template("companies.html", rowdata=data, currency_data=currencies)
@app.route("/deleteCompany")
def deleteCompany():
mid = request.args.get("mid")
toDel = Company.query.filter_by(id=mid).first()
if toDel != None:
if toDel.delCompany():
return companiesPage()
return render_template("companies.html", message="something went wrong")
@app.route("/addToCompanies", methods=["POST", "GET"])
def addToCompanies():
companyname = request.form["company_name"]
def_currency = request.form["default_currency"]
mycurreny = Currency.query.filter_by(name=def_currency).first()
if mycurreny != None:
newComp = Company(name=companyname, curreny=mycurreny.id)
if newComp.addCompany():
return companiesPage()
return render_template("companies.html", message="something went wrong")
# client settings
@app.route("/clientSettings", methods=["GET", "POST"])
def clientSettingsPage():
if session["type"] != "client":
return render_template("index.html", ses_type=session["type"])
thisData = {}
clAccount = CLientAccount.query.filter_by(User=session["user"]).first()
clientData = ClientDetails.query.filter_by(id=clAccount.id).first()
if clientData != None:
thisData["address"] = clientData.address
thisData["zip"] = clientData.zip
thisData["city"] = clientData.city
thisData["country"] = clientData.country
thisData["email"] = clientData.email
thisData["phone"] = clientData.phone
thisData["vat"] = clientData.vat
thisData["commerce"] = clientData.commerce
return render_template("clientSettings.html", data=thisData)
@app.route("/clientSettingsUpdate", methods=["POST", "GET"])
def clientSettingsUpdate():
address = request.form["address"]
zip = request.form["zip"]
city = request.form["city"]
country = request.form["country"]
email = request.form["email"]
phone = request.form["phone"]
vat = request.form["vat"]
commerce = request.form["commerce"]
id = CLientAccount.query.filter_by(User=session["user"]).first().Client
clSettings = ClientDetails(client=id, address=address, zip=zip, city=city, country=country, email=email, phone=phone, vat=vat, commerce=commerce)
clSettings.clientUpdate()
return clientSettingsPage()
# client add invoice
@app.route("/invoices", methods=["POST", "GET"])
def invoicesPage():
return render_template("invoices.html")
# employee response invoice
# employee create bill
# message page
@app.route("/messagePage")
def messagePage():
return render_template("messagePage.html")
# run the app
if __name__ == "__main__":
app.run(port=5000, debug = True)