diff --git a/brewman/brewman/static/css/table.css b/brewman/brewman/static/css/table.css index 596cca43..111665c7 100644 --- a/brewman/brewman/static/css/table.css +++ b/brewman/brewman/static/css/table.css @@ -6,51 +6,42 @@ { display: none; } -.table tbody tr.success td { - background-color: #1F7A1F; -} - -.table tbody tr.success td { - background-color: #1F7A1F; -} - - -.table tbody tr.Present td { +.table tbody tr.Present td:not(.no-bg) { background-color: #228B22; } -.table tbody tr.Off td { +.table tbody tr.Off td:not(.no-bg) { background-color: #87CEFA; } -.table tbody tr.Leave td { +.table tbody tr.Leave td:not(.no-bg) { background-color: #CD5C5C; } -.table tbody tr.Absent td { +.table tbody tr.Absent td:not(.no-bg) { background-color: #CD0000; } -.table tbody tr.HalfDay td { +.table tbody tr.HalfDay td:not(.no-bg) { background-color: #98FB98; } -.table tbody tr.Double td { +.table tbody tr.Double td:not(.no-bg) { background-color: #006400; } -.table tbody tr.PaidLeaveAvailed td { +.table tbody tr.PaidLeaveAvailed td:not(.no-bg) { background-color: #EEEE00; } -.table tbody tr.CasualLeaveAvailed td { +.table tbody tr.CasualLeaveAvailed td:not(.no-bg) { background-color: #800080; } -.table tbody tr.Overtime td { +.table tbody tr.Overtime td:not(.no-bg) { background-color: #006400; } -.table tbody tr.OffWorked td { +.table tbody tr.OffWorked td:not(.no-bg) { background-color: #F5DEB3; } -.table tbody tr.COff td { +.table tbody tr.COff td:not(.no-bg) { background-color: #F5DEB3; } -.table tbody tr.HalfPL td { +.table tbody tr.HalfPL td:not(.no-bg) { background-color: #FFF68F; } -.table tbody tr.HalfCL td { +.table tbody tr.HalfCL td:not(.no-bg) { background-color: #FF00FF; } \ No newline at end of file diff --git a/brewman/brewman/static/partial/attendance.html b/brewman/brewman/static/partial/attendance.html index f2ea266b..f86d5824 100644 --- a/brewman/brewman/static/partial/attendance.html +++ b/brewman/brewman/static/partial/attendance.html @@ -36,7 +36,9 @@ ng-options="i.AttendanceTypeID as i.Name for i in attendance_types"> - {{item.Prints}} + {{item.Prints}} {{item.Hours}} + diff --git a/brewman/brewman/static/partial/employee-attendance.html b/brewman/brewman/static/partial/employee-attendance.html index ae8bd243..b9b7b0fb 100644 --- a/brewman/brewman/static/partial/employee-attendance.html +++ b/brewman/brewman/static/partial/employee-attendance.html @@ -40,7 +40,9 @@ ng-options="i.AttendanceTypeID as i.Name for i in attendance_types"> - {{item.Prints}} + {{item.Prints}} {{item.Hours}} + diff --git a/brewman/brewman/static/scripts/attendance.js b/brewman/brewman/static/scripts/attendance.js index 85d67bb1..b155d56e 100644 --- a/brewman/brewman/static/scripts/attendance.js +++ b/brewman/brewman/static/scripts/attendance.js @@ -20,6 +20,22 @@ var AttendanceSubCtrl = ['$scope', function ($scope) { $scope.original = {}; angular.copy($scope.item, $scope.original); + $scope.isLabel = function(){ + return true; + } + + $scope.isError = function(){ + return $scope.item.Worked === 'Error'; + } + + $scope.isGood = function(){ + return $scope.item.Worked === true; + } + + $scope.isBad = function(){ + return $scope.item.Worked === false; + } + $scope.isDirty = function(){ return !angular.equals($scope.original, $scope.item) } diff --git a/brewman/brewman/static/scripts/employee-attendance.js b/brewman/brewman/static/scripts/employee-attendance.js index ae181bb1..8be6f04e 100644 --- a/brewman/brewman/static/scripts/employee-attendance.js +++ b/brewman/brewman/static/scripts/employee-attendance.js @@ -30,6 +30,22 @@ function EmployeeAttendanceSubCtrl($scope) { $scope.original = {}; angular.copy($scope.item, $scope.original); + $scope.isLabel = function(){ + return true; + } + + $scope.isError = function(){ + return $scope.item.Worked === 'Error'; + } + + $scope.isGood = function(){ + return $scope.item.Worked === true; + } + + $scope.isBad = function(){ + return $scope.item.Worked === false; + } + $scope.isDirty = function(){ return !angular.equals($scope.original, $scope.item) } diff --git a/brewman/brewman/views/attendance.py b/brewman/brewman/views/attendance.py index 97d1ac6c..82264e09 100644 --- a/brewman/brewman/views/attendance.py +++ b/brewman/brewman/views/attendance.py @@ -8,7 +8,8 @@ import transaction from brewman.models import DBSession from brewman.models.master import AttendanceType, Employee from brewman.models.validation_exception import ValidationError -from brewman.models.voucher import Attendance, Fingerprint +from brewman.models.voucher import Attendance +from brewman.views.fingerprint import get_prints from brewman.views.services.session import session_period_start, session_period_finish, session_current_date __author__ = 'tanshu' @@ -57,14 +58,10 @@ def attendance_date_report(date): Attendance.date == date).filter(Attendance.is_valid == True).first() att = 0 if att is None else att.attendance_type - start_fp = date + datetime.timedelta(hours=7) - finish_fp = date + datetime.timedelta(hours=7, days=1) - prints = DBSession.query(Fingerprint).filter(Fingerprint.employee_code == item.code)\ - .filter(Fingerprint.date >= start_fp).filter(Fingerprint.date < finish_fp).order_by(Fingerprint.date).all() - prints = ', '.join([x.date.strftime('%H:%M') for x in prints]) - + prints, hours, worked = get_prints(item.code, date) report['Body'].append({'id': item.id, 'Code': item.code, 'Name': item.name, 'Designation': item.designation, - 'Department': item.costcenter.name, 'AttendanceTypeID': att, 'Prints': prints}) + 'Department': item.costcenter.name, 'AttendanceTypeID': att, 'Prints': prints, + 'Hours': hours, 'Worked': worked}) return report @@ -124,12 +121,9 @@ def employee_attendance(employee, start_date, finish_date): .filter(Attendance.is_valid == True)\ .first() att = 0 if att is None else att.attendance_type - start_fp = item + datetime.timedelta(hours=7) - finish_fp = item + datetime.timedelta(hours=7, days=1) - prints = DBSession.query(Fingerprint).filter(Fingerprint.employee_code == employee.code)\ - .filter(Fingerprint.date >= start_fp).filter(Fingerprint.date < finish_fp).order_by(Fingerprint.date).all() - prints = ', '.join([x.date.strftime('%H:%M') for x in prints]) - list.append({'Date': item.strftime('%d-%b-%Y'), 'AttendanceTypeID': att, 'Prints': prints}) + prints, hours, worked = get_prints(employee.code, item) + list.append({'Date': item.strftime('%d-%b-%Y'), 'AttendanceTypeID': att, 'Prints': prints, 'Hours': hours, + 'Worked': worked}) return list diff --git a/brewman/brewman/views/fingerprint.py b/brewman/brewman/views/fingerprint.py index 43d710f8..32b1efec 100644 --- a/brewman/brewman/views/fingerprint.py +++ b/brewman/brewman/views/fingerprint.py @@ -2,6 +2,7 @@ import csv import datetime from io import StringIO from pyramid.view import view_config +from brewman.models import DBSession from brewman.models.voucher import Fingerprint __author__ = 'tanshu' @@ -34,3 +35,38 @@ def add_fingerprint(row): except ValueError: return Fingerprint(employee_code=employee_code, date=date).create() + + +def get_prints(employee_code, date): + start_fp = date + datetime.timedelta(hours=7) + finish_fp = date + datetime.timedelta(hours=7, days=1) + prints = DBSession.query(Fingerprint).filter(Fingerprint.employee_code == employee_code)\ + .filter(Fingerprint.date >= start_fp).filter(Fingerprint.date < finish_fp).order_by(Fingerprint.date).all() + + last = None + for i in range(len(prints), 0, -1): + item = prints[i - 1].date + if last is not None and last - item < datetime.timedelta(minutes=10): + prints.remove(prints[i - 1]) + else: + last = item + + if len(prints) == 0: + hours = '', '' + elif len(prints) == 2: + hours = prints[1].date - prints[0].date + hours = working_hours(hours) + elif len(prints) == 4: + hours = (prints[1].date - prints[0].date) + (prints[3].date - prints[2].date) + hours = working_hours(hours) + else: + hours = 'Error', 'Error' + return ', '.join([x.date.strftime('%H:%M') for x in prints]) + ' ', hours[0], hours[1] + + +def working_hours(delta): + minutes = (delta.seconds // 60) % 60 + minutes = int(5 * round(float(minutes) / 5)) + hours = delta.seconds // 3600 + worked = str(hours).zfill(2) + ':' + str(minutes).zfill(2) + return worked, delta.seconds >= 60 * 60 * 9 # 9hrs \ No newline at end of file diff --git a/brewman/setup.py b/brewman/setup.py index 46710dc6..56193296 100644 --- a/brewman/setup.py +++ b/brewman/setup.py @@ -16,7 +16,7 @@ requires = [ ] setup(name='brewman', - version='0.0', + version='3.2', description='brewman', long_description=README + '\n\n' + CHANGES, classifiers=[