commit 691f5951f0b5e85df7dbaea342e864406d9c55c9
parent 4cc6f477a08b2dd97a643d0d1c199999ad693ffc
Author: Brennen T. Mazur <brennen@madis.cool>
Date: Mon, 3 Apr 2023 03:05:42 -0600
pay-period and hours page calculations, added approximate payment per user. Commented out agreement dev data.
Diffstat:
3 files changed, 60 insertions(+), 13 deletions(-)
diff --git a/app/routes.py b/app/routes.py
@@ -164,13 +164,13 @@ def dashboard():
def clock_user_out(time_id,lunch=False,perdiem=False):
if mongo.db.time_collection.find({'_id': time_id}, {'clock_out':{'$exists':False}}):
if lunch==True and perdiem==True:
- mongo.db.time_collection.update_one({'_id':time_id},{'$set':{'clock_out':datetime.datetime.utcnow(),'lunch':True,'per_diem':True}})
+ mongo.db.time_collection.update_one({'_id':time_id},{'$set':{'clock_out':[datetime.datetime.utcnow()],'lunch':True,'per_diem':True}})
elif lunch==True and perdiem==False:
- mongo.db.time_collection.update_one({'_id':time_id},{'$set':{'clock_out':datetime.datetime.utcnow(),'lunch':True}})
+ mongo.db.time_collection.update_one({'_id':time_id},{'$set':{'clock_out':[datetime.datetime.utcnow()],'lunch':True}})
elif lunch==False and perdiem==True:
- mongo.db.time_collection.update_one({'_id':time_id},{'$set':{'clock_out':datetime.datetime.utcnow(),'per_diem':True}})
+ mongo.db.time_collection.update_one({'_id':time_id},{'$set':{'clock_out':[datetime.datetime.utcnow()],'per_diem':True}})
else:
- mongo.db.time_collection.update_one({'_id':time_id},{'$set':{'clock_out':datetime.datetime.utcnow()}})
+ mongo.db.time_collection.update_one({'_id':time_id},{'$set':{'clock_out':[datetime.datetime.utcnow()]}})
return redirect(url_for('dashboard'))
else:
flash('No time entry found, or user has checked out already')
@@ -333,7 +333,7 @@ def clockout_by_id(modusernm,timeid):
def clock_otheruser_out(time_id,mod_username):
if mongo.db.time_collection.find({'_id': time_id}, {'clock_out':{'$exists':False}}):
- mongo.db.time_collection.update_one({'_id':time_id},{'$set':{'clock_out':datetime.datetime.utcnow()}})
+ mongo.db.time_collection.update_one({'_id':time_id},{'$set':{'clock_out':[datetime.datetime.utcnow()]}})
mongo.db.time_collection.update_one({'_id':time_id},{'$push':{'modified_by':mod_username}})
flash('Clocked out')
else:
@@ -410,15 +410,38 @@ def admin():
@app.route('/hours/<username>')#modify to take userid ex. /hours<userid> for "admin" currently pulls from current_user... simply always pass username to hours(if possible set a default to current_user)
@login_required
def hours(username):#userid goes into call to db to get user[] -> then returns formatted table (punchclock/index.html
+ #set var user_hours = []
+ #query time collection for all time entries
+ #for entry in entries:
+ # time = entry.get('clock_out'[0],datetime.datetime.now()) - entry['clock_in'][0]
+ # if entry['modified_by'][0] in user_hours:
+ # user_hours[entry['modified_by'][0]] =+ time
+ # else:
+ # user_hours.append({entry['modified_by'][0],time})
+
# user = load_user(username)
#dashperms=mongo.db.permissions_collection.find_one({'label': current_user.role},{'dashboard':1,'_id':0})
#dashperms=dashperms['dashboard']
+ #total_hours=0
form = ChangeHoursForm()
projectChoices = mongo.db.project_collection.find({'completed':{'$exists':False}})
user = mongo.db.user_collection.find_one({"username": username})
- hours = mongo.db.time_collection.find({'modified_by.0':user['username']})
+ dbhours = mongo.db.time_collection.find({'modified_by.0':user['username']})
+ hours = []
+ deltas=[]
+ for hour in dbhours:
+ if 'clock_out' not in hour:
+ hour['clock_out']=[datetime.datetime.utcnow()]
+ time = hour['clock_out'][0] - hour['clock_in'][0]
+ hour['total_time'] = time
+ hours.append(hour)
+ deltas.append(time)
+
+ total_hours = sum(deltas,datetime.timedelta())
+ statement_hours = "{} Hours, {} Minutes".format(total_hours.seconds//3600,(total_hours.seconds//60)%60)
+
#hours = mongo.db.time_collection.find({'modified_by.0':user.username})
- return render_template ('dashboard/punchclock/index.html',form=form,hours=hours,user=user,choices=projectChoices,ORGNAME=OrganizationName)
+ return render_template ('dashboard/punchclock/index.html',form=form,hours=hours,total_hours=total_hours,statement_hours=statement_hours,user=user,choices=projectChoices,ORGNAME=OrganizationName)
# Don't really need this until additional functionality is added, not in current project scope
#@app.route("/fleet")
@@ -615,7 +638,30 @@ def project_report():
@login_required
def pay_period_report():
pay = mongo.db.time_collection.find({})
- users = mongo.db.user_collection.find({})
+ dbactiveusers = mongo.db.user_collection.find({'is_active':True})
+ users=[]
+ times_by_user={}
+ for user in dbactiveusers:
+ times_by_user[user['username']]=[datetime.timedelta(seconds=0)]
+ users.append(user)
+ hours = {}
+ deltas=[]
+ for time in pay:
+ if time['modified_by'][0] not in times_by_user:
+ times_by_user[time['modified_by'][0]]=[datetime.timedelta(seconds=0)]
+ user_lookup = mongo.db.user_collection.find_one({'username':time['modified_by'][0]})
+ users.append(user_lookup)
+ if 'clock_out' not in time:
+ time['clock_out']=[datetime.datetime.utcnow()]
+ t = time['clock_out'][0] - time['clock_in'][0]
+ hours['total_time'] = t
+ times_by_user[time['modified_by'][0]].append(t)
+ deltas.append(time)
+
+ for user in users:
+ total_hours = sum(times_by_user[user['username']],datetime.timedelta())
+ statement_hours = (total_hours.seconds//3600,(total_hours.seconds//60)%60)
+ user['total_hours']=statement_hours
return render_template('admin/reports/pay_period_report.html', users=users, pay=pay, ORGNAME=OrganizationName)
# @app.route("/dev/fleetdata")
diff --git a/app/templates/admin/pay_period_report/widget.html b/app/templates/admin/pay_period_report/widget.html
@@ -7,8 +7,8 @@
<div class="usercard">
<h4>{{ user.fname }} {{ user.mname }}. {{ user.lname }}</h3>
<table>
- <tr><td>Estimated Payment:</td><td>${{ (user.pay_value)|round(2) }}</td></tr> <!-- Multiply hours by pay-value -->
- <tr><td>Total Time:</td><td>{{user.total_hours}}.</td></tr>
+ <tr><td>Estimated Payment:</td><td>${{ ((user.pay_value)*(user.total_hours.0 +((user.total_hours.1 /60)|round(2) )))|round(2) }}</td></tr> <!-- Multiply hours by pay-value -->
+ <tr><td>Total Time:</td><td>{{user.total_hours.0}}hrs {{user.total_hours.1}}min.</td></tr>
<tr><td>Pay Rate:</td><td>${{ user.pay_value }}</td></tr>
<tr><td>Pay Period</td><td>Hourly</td></tr>
</table>
@@ -29,4 +29,4 @@
</a>
{% endif %}
{% endfor %}
-</section>
-\ No newline at end of file
+</section>
diff --git a/app/templates/dashboard/punchclock/index.html b/app/templates/dashboard/punchclock/index.html
@@ -8,6 +8,8 @@
<h1 id="clock"></h1>
<div><!-- abstract to payPeriod() -->
<h6>$payperiod range</h6>
+ <h5>Total: {{ total_hours }}</h5>
+ <h5>Total: {{ statement_hours }}</h5>
</div>
{% for choice in choices %}
{%- print(choice) %}
@@ -22,7 +24,7 @@
<tr>
<td>{{ entry.project }}{{ form.projectChg(default=entry.project) }}</td>
<td>{{ entry.clock_in.0 }}{{ form.startTiChg() }}</td>
- <td>{{ entry.clock_out }}{{ form.endTimeChg() }}</td>
+ <td>{{ entry.clock_out.0 }}{{ form.endTimeChg() }}</td>
<td>{{ entry.lunch }}{% if entry.lunch %}{{ form.lunchBxChg(default="checked")}}{%else%}{{ form.lunchBxChg() }}{% endif %} </td>
<td>{{ entry.per_diem }}{{ form.perDiemChg(default='checked') }}</td>
<td>{{ form.updateEntr() }}</td>