Skip to content

Commit

Permalink
Merge pull request #78 from uwidcit/Report-Generation
Browse files Browse the repository at this point in the history
Report generation
  • Loading branch information
TheGreatDevourer authored Mar 18, 2024
2 parents 25c4fa7 + c6b797d commit e305451
Show file tree
Hide file tree
Showing 14 changed files with 565 additions and 122 deletions.
6 changes: 3 additions & 3 deletions App/controllers/import_export.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ def import_student(uploaded_file):
for s in student_json:
if len(str(s['faculty'])) > 3:
s['faculty'] = str(s['faculty'])[0:2].upper()
add_new_student(s['student_id'], s['first_name'], s['last_name'], s['faculty'], s['phone_number'],s['email'])
add_new_student(str(s['student_id']), s['first_name'], s['last_name'], s['faculty'], s['phone_number'],s['email'])
return True


Expand Down Expand Up @@ -160,8 +160,8 @@ def import_rent(uploaded_file):
d_return = None
for r in rent_json:
try:
r_dfrom = datetime.strptime(r['rent_date_to'],'%Y-%m-%d %H:%M:%S')
r_dto = datetime.strptime(r['rent_date_from'],'%Y-%m-%d %H:%M:%S')
r_dfrom = datetime.strptime(r['rent_date_from'],'%Y-%m-%d %H:%M:%S')
r_dto = datetime.strptime(r['rent_date_to'],'%Y-%m-%d %H:%M:%S')
d_return = datetime.strptime(r['date_returned'],'%Y-%m-%d %H:%M:%S')
except:
d_return = None
Expand Down
107 changes: 104 additions & 3 deletions App/controllers/rent.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from App.models import Rent,RentTypes,KeyHistory
from App.models.locker import Locker
from App.models.rentTypes import Types as RTypes
from App.models.rent import RentStatus as Status, RentMethod as Method
from math import floor

Expand All @@ -22,8 +23,9 @@
from App.controllers.key_history import getKeyHistory
from datetime import datetime
from App.database import db
from sqlalchemy import and_, Sequence
from sqlalchemy import and_,or_, Sequence
from sqlalchemy.exc import SQLAlchemyError
from sqlalchemy.sql import func

def period_elapsed(type, rent_date_from, rent_date_to):

Expand Down Expand Up @@ -117,7 +119,6 @@ def create_rent(student_id, locker_id,rentType, rent_date_from, rent_date_to,ren
return rent
return None
except SQLAlchemyError as e:
print(e)
db.session.rollback()
raise("Unable to create rent. Check Error Log for more Details")

Expand All @@ -141,7 +142,6 @@ def import_verified_rent(id,student_id,keyHistory_id,rentType,rent_date_from,ren
db.session.commit()
return rent
except SQLAlchemyError as e:
print(e)
db.session.rollback()
return None

Expand Down Expand Up @@ -408,6 +408,107 @@ def get_transactions(id,size,offset):
s_list.append(d.toJSON())

return {"num_pages":num_pages,"data":s_list}

def get_rents_range(start_date, end_date):
rents_query = db.session.query(Locker.locker_type, RentTypes.type, func.count(Rent.rent_type), func.sum(Rent.amount_owed)).join(RentTypes,KeyHistory,Locker).filter(and_(Rent.rent_date_from >= start_date,Rent.rent_date_from <= end_date,Rent.status != Status.VERIFIED)).group_by(Locker.locker_type,RentTypes.type).all()
data = {
"semester":{
"Small":{"amount":0, "length":0},
"Medium":{"amount":0, "length":0},
"Large":{"amount":0, "length":0},
"Combination":{"amount":0, "length":0},
"Total":{"amount":0, "length":0}
},
"yearly":{
"Small":{"amount":0, "length":0},
"Medium":{"amount":0, "length":0},
"Large":{"amount":0, "length":0},
"Combination":{"amount":0, "length":0},
"Total":{"amount":0, "length":0}
},
"daily":{
"Small":{"amount":0, "length":0},
"Medium":{"amount":0, "length":0},
"Large":{"amount":0, "length":0},
"Combination":{"amount":0, "length":0},
"Total":{"amount":0, "length":0}
},
"hourly":{
"Small":{"amount":0, "length":0},
"Medium":{"amount":0, "length":0},
"Large":{"amount":0, "length":0},
"Combination":{"amount":0, "length":0},
"Total":{"amount":0, "length":0}
}
}
index = ''
if rents_query is None:
return data
else:
for rent in rents_query:
if "Semester" in rent[1].value:
index = "semester"
elif "Yearly" in rent[1].value:
index = "yearly"
elif "Daily" in rent[1].value:
index = "daily"
elif "Hourly"in rent[1].value:
index = "hourly"
data[index].update({rent[0].value:{"amount":rent[3],"length":rent[2]}})
data[index]["Total"]["amount"] = data[index]["Total"]["amount"] + rent[3]
data[index]["Total"]["length"] = data[index]["Total"]["length"] + rent[2]
return data

def get_rents_returned_range(start_date, end_date):
rents_query = db.session.query(Locker.locker_type, RentTypes.type, func.count(Rent.rent_type), func.sum(Rent.amount_owed)).join(RentTypes,KeyHistory,Locker).filter(and_(Rent.rent_date_from >= start_date,Rent.rent_date_from <= end_date,Rent.status == Status.VERIFIED)).group_by(Locker.locker_type,RentTypes.type).all()
data = {
"semester":{
"Small":{"amount":0, "length":0},
"Medium":{"amount":0, "length":0},
"Large":{"amount":0, "length":0},
"Combination":{"amount":0, "length":0},
"Total":{"amount":0, "length":0}
},
"yearly":{
"Small":{"amount":0, "length":0},
"Medium":{"amount":0, "length":0},
"Large":{"amount":0, "length":0},
"Combination":{"amount":0, "length":0},
"Total":{"amount":0, "length":0}
},
"daily":{
"Small":{"amount":0, "length":0},
"Medium":{"amount":0, "length":0},
"Large":{"amount":0, "length":0},
"Combination":{"amount":0, "length":0},
"Total":{"amount":0, "length":0}
},
"hourly":{
"Small":{"amount":0, "length":0},
"Medium":{"amount":0, "length":0},
"Large":{"amount":0, "length":0},
"Combination":{"amount":0, "length":0},
"Total":{"amount":0, "length":0}
}
}
index = ''
if rents_query is None:
return data
else:
for rent in rents_query:
if "Semester" in rent[1].value:
index = "semester"
elif "Yearly" in rent[1].value:
index = "yearly"
elif "Daily" in rent[1].value:
index = "daily"
elif "Hourly"in rent[1].value:
index = "hourly"
data[index].update({rent[0].value:{"amount":rent[3],"length":rent[2]}})
data[index]["Total"]["amount"] = data[index]["Total"]["amount"] + rent[3]
data[index]["Total"]["length"] = data[index]["Total"]["length"] + rent[2]
return data




Expand Down
14 changes: 13 additions & 1 deletion App/controllers/transactionLog.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from App.database import db
from App.models import TransactionLog,Rent
from App.models.transactionLog import TransactionType
from sqlalchemy import or_,Sequence
from sqlalchemy import or_,and_,Sequence
from sqlalchemy.exc import SQLAlchemyError

def add_new_transaction(rent_id, currency, transaction_date, amount, description, t_type):
Expand Down Expand Up @@ -120,4 +120,16 @@ def search_transaction(query,size,offset):
t_list.append(transactions.toJSON())
return {"num_pages": num_pages,"data":t_list}

def get_revenue(start_date, end_date):
trans_query = db.session.query(TransactionLog.amount).filter(and_(TransactionLog.transaction_date >= start_date, TransactionLog.transaction_date < end_date)).all()

if not trans_query:
return 0
sum = 0
data = []
for t in trans_query:
sum += t[0]
#data.append(t.toJSON())
return {"sum":sum}


20 changes: 0 additions & 20 deletions App/static/keep_alive.js

This file was deleted.

3 changes: 1 addition & 2 deletions App/static/lockers.js
Original file line number Diff line number Diff line change
Expand Up @@ -170,8 +170,7 @@ var row_id = 0

async function getLockers(){
let result = await sendRequest('/api/locker','GET')

for (let r in result){
for (r in result){
locker_list.push(result[r])
}
initTable(locker_list)
Expand Down
2 changes: 1 addition & 1 deletion App/static/sw.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ const {precacheAndRoute,cleanupOutdatedCaches,addRoute} = workbox.precaching;
const {CacheableResponse, CacheableResponsePlugin} = workbox.cacheableResponse;

cleanupOutdatedCaches()
precacheAndRoute([{"revision":"bc56a6869ac03cd8815461a8a58ca256","url":"autocomplete.js"},{"revision":"9d295ec8b213fdfaac1595e739a950ef","url":"keep_alive.js"},{"revision":"0fda9a296e41254bb2fd735f713fead9","url":"lockers.js"},{"revision":"870b5ea4295065881458d40c6df53a78","url":"main.js"},{"revision":"71728b0cf3a7a88b822b376c69d863af","url":"manage_locker_offline.html"},{"revision":"5c939ef677a57602e5e12eaa34058ead","url":"map_init.js"},{"revision":"b0663391a6dd5efed956259f29fa18dd","url":"materialize.css"},{"revision":"74ac8fd1cd0b94f532c54d4c707a86ae","url":"materialize.js"},{"revision":"ec1df3ba49973dcb9ff212f052d39483","url":"materialize.min.css"},{"revision":"5dcfc8944ed380b2215dc28b3f13835f","url":"materialize.min.js"},{"revision":"b7a97dc36dffb61a3b3e165b9dbe20d2","url":"offline.html"},{"revision":"0fb6fd0b049bd0d880bdb20932250f0b","url":"rent.js"},{"revision":"7a2b4050bd5b0159ba5101b00d60b40f","url":"static-user.html"},{"revision":"ceac046cad1656146e8d521968b87cda","url":"style.css"},{"revision":"1d8179f18fcc6c658c386f9f30ef126b","url":"util.js"},{"revision":"22a2cad39dbdade0d7768ece607324ce","url":"validate_functions.js"},{"revision":"739a6a65fc99c74662841d53c9a988f6","url":"validate_locker.js"},{"revision":"455b81bc035b30f77cf9f8b454475f5f","url":"validate_rent.js"},{"revision":"2cd1cbbe5f9d94f135c89263d2eb4d2b","url":"workbox-a482575e.js"}]);
precacheAndRoute([{"revision":"bc56a6869ac03cd8815461a8a58ca256","url":"autocomplete.js"},{"revision":"0997b8b57b96ce1f58cdf24c520c1d09","url":"lockers.js"},{"revision":"870b5ea4295065881458d40c6df53a78","url":"main.js"},{"revision":"71728b0cf3a7a88b822b376c69d863af","url":"manage_locker_offline.html"},{"revision":"5c939ef677a57602e5e12eaa34058ead","url":"map_init.js"},{"revision":"b0663391a6dd5efed956259f29fa18dd","url":"materialize.css"},{"revision":"74ac8fd1cd0b94f532c54d4c707a86ae","url":"materialize.js"},{"revision":"ec1df3ba49973dcb9ff212f052d39483","url":"materialize.min.css"},{"revision":"5dcfc8944ed380b2215dc28b3f13835f","url":"materialize.min.js"},{"revision":"b7a97dc36dffb61a3b3e165b9dbe20d2","url":"offline.html"},{"revision":"0fb6fd0b049bd0d880bdb20932250f0b","url":"rent.js"},{"revision":"7a2b4050bd5b0159ba5101b00d60b40f","url":"static-user.html"},{"revision":"ceac046cad1656146e8d521968b87cda","url":"style.css"},{"revision":"1d8179f18fcc6c658c386f9f30ef126b","url":"util.js"},{"revision":"22a2cad39dbdade0d7768ece607324ce","url":"validate_functions.js"},{"revision":"739a6a65fc99c74662841d53c9a988f6","url":"validate_locker.js"},{"revision":"455b81bc035b30f77cf9f8b454475f5f","url":"validate_rent.js"},{"revision":"2cd1cbbe5f9d94f135c89263d2eb4d2b","url":"workbox-a482575e.js"}]);

setDefaultHandler(new NetworkFirst());

Expand Down
2 changes: 0 additions & 2 deletions App/templates/addrent.html
Original file line number Diff line number Diff line change
Expand Up @@ -349,5 +349,3 @@ <h6>New Comment</h6>
}
</script>
{% endblock %}

<script src="/static/keep_alive.js"> </script>
2 changes: 0 additions & 2 deletions App/templates/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -52,5 +52,3 @@ <h1 class = "yellow-text black">SAC</h1>
</div>
</div>
{% endblock %}

<script src="/static/keep_alive.js"> </script>
2 changes: 2 additions & 0 deletions App/templates/layout.html
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,8 @@
var instancesColl = M.Collapsible.init(elemsColl);
var elemsFxBtn = document.querySelectorAll('.fixed-action-btn');
var instancesFxBtn = M.FloatingActionButton.init(elemsFxBtn);
var elemsTabs = document.querySelectorAll('.tabs');
var instanceTabs = M.Tabs.init(elemsTabs);
var instancesBtn = M.Dropdown.init(elemsBtn,{
hover:true,
constrainWidth:false
Expand Down
1 change: 0 additions & 1 deletion App/templates/layout_no_nav.html
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@

<script src="https://cdnjs.cloudflare.com/ajax/libs/materialize/1.0.0/js/materialize.min.js"></script>
<script src="/static/util.js"></script>
<script src = "/static/keep_alive.js"></script>
</body>
</html>

Loading

0 comments on commit e305451

Please sign in to comment.