commit 50354bf7ca26978128bdf6762f08aedb1c3c4a19
parent 0fe971f2800747d914d5ea9622cc1978e9e1d6b4
Author: Youth Employment Program Production <youthemployment22@gmail.com>
Date: Sat, 5 Aug 2023 13:22:33 -0600
Add time_bound_report, fix per_diem typo
Diffstat:
M | app/routes.py | | | 61 | ++++++++++++++++++++++++++++++++++++++++++++++++------------- |
1 file changed, 48 insertions(+), 13 deletions(-)
diff --git a/app/routes.py b/app/routes.py
@@ -11,6 +11,7 @@ from werkzeug.security import generate_password_hash, check_password_hash
from flask_login import current_user, login_user, logout_user, login_required
from app.models import User, Time, Fleet, Agreement, Projects
from bson.objectid import ObjectId
+import bson.json_util as json_util
#from .config import EXEMPT_METHODS
import functools
@@ -1252,7 +1253,7 @@ def time_bound_report(startday,endday):
"project":"$project"},
"totalTime": { "$sum": { "$subtract": [{"$last":"$clock_out"}, {"$last":"$clock_in"}] } },
"lunchCount":{ "$sum":{'$cond':["$lunch",1,0] } },
- "perdiemCount":{ "$sum":{'$cond':["$perdiem",1,0] } }
+ "perdiemCount":{ "$sum":{'$cond':["$per_diem",1,0] } }
}
},
{
@@ -1279,7 +1280,7 @@ def time_bound_report(startday,endday):
},
"totalTime": { "$sum": { "$subtract": [{"$last":"$clock_out"}, {"$last":"$clock_in"}] } },
"lunchCount":{ "$sum":{'$cond':["$lunch",1,0] } },
- "perdiemCount":{ "$sum":{'$cond':["$perdiem",1,0] } }
+ "perdiemCount":{ "$sum":{'$cond':["$per_diem",1,0] } }
}
},
{
@@ -1298,11 +1299,19 @@ def time_bound_report(startday,endday):
}
},
{
+ "$lookup":{
+ 'from':'projects_collection',
+ 'localField':'project',
+ 'foreignField':'_id',
+ 'as':'project_data'
+ }
+ },
+ {
"$group": {
- "_id":"$project",
+ "_id":"$project_data",
"laborHoursWorked": { "$sum": { "$subtract": [{"$last":"$clock_out"}, {"$last":"$clock_in"}] } },
"lunchCount": { "$sum" : { '$cond':["$lunch",1,0] } },
- "perdiemCount": { "$sum" :{'$cond':["$perdiem",1,0] } }
+ "perdiemCount": { "$sum" :{'$cond':["$per_diem",1,0] } }
}
},
{
@@ -1333,7 +1342,7 @@ def time_bound_report(startday,endday):
"$addFields": {
"totalTime": { "$sum": { "$subtract": [{"$last":"$clock_out"}, {"$last":"$clock_in"}] } },
"lunchCount": { "$sum" : { '$cond':["$lunch",1,0] } },
- "perdiemCount": { "$sum" :{'$cond':["$perdiem",1,0] } }
+ "perdiemCount": { "$sum" :{'$cond':["$per_diem",1,0] } }
}
},
{
@@ -1345,18 +1354,44 @@ def time_bound_report(startday,endday):
"$sort": {'date': -1}
}
] )
+
by_project = {}
+ for project in tspp:
+ by_project[project['_id'][0]['project_name']]=project['_id'][0]
+ by_project[project['_id'][0]['project_name']]['totalHoursWorked']=project['totalHoursWorked']
+ by_project[project['_id'][0]['project_name']]['lunchCount']=project['lunchCount']
+ by_project[project['_id'][0]['project_name']]['perdiemCount']=project['perdiemCount']
+
by_user ={}
+ for user in hours:
+ by_user[user['_id']]=user
+
for time in ptl:
- if time['modified_by'][0] not in by_user:
- by_user[time['modified_by'][0]]=[time]
- else:
- by_user[time['modified_by'][0]].append(time)
- if time['project_data'][0]['project_name'] not in by_project:
- by_project[time['project_data'][0]['project_name']]=[time]
- else:
- by_project[time['project_data'][0]['project_name']].append(time)
+ for user in by_user:
+ if time['modified_by'][0] in user:
+ if by_user[user].get('times'):
+ by_user[user]['times'].append(time)
+ else:
+ by_user[user].update({'times':[time]})
+ for project in by_project:
+ if time['project_data'][0]['project_name'] in project:
+ if by_project[project].get('times'):
+ by_project[project]['times'].append(time)
+ else:
+ by_project[project].update({'times':[time]})
+
+# for time in ptl:
+# if time['modified_by'][0] not in by_user:
+# by_user[time['modified_by'][0]]=[time]
+# else:
+# by_user[time['modified_by'][0]].append(time)
+# if time['project_data'][0]['project_name'] not in by_project:
+# by_project[time['project_data'][0]['project_name']]=[time]
+# else:
+# by_project[time['project_data'][0]['project_name']].append(time)
+ #return json_util.dumps(by_user)
+ #return json_util.dumps(by_project)
return render_template ('admin/reports/total_timedata_report.html', by_project=by_project, by_user=by_user, usertimes=usertimes, allhours=allhours, hours=hours, tspp=tspp, projectlookup=ptl, ORGNAME=OrganizationName)
####### TESTING END #######