From f627fb1303cdd69b4a4691f4e8775c76da219e89 Mon Sep 17 00:00:00 2001 From: Tanshu Date: Wed, 17 Oct 2012 13:27:14 +0530 Subject: [PATCH] Employee list/add/edit done. --- brewman/brewman/models/master.py | 14 +- .../static/partial/account-detail.html | 70 +++++----- .../static/partial/employee-detail.html | 77 ++++++++++ .../brewman/static/partial/employee-list.html | 28 ++++ .../brewman/static/scripts/angular_service.js | 8 ++ brewman/brewman/static/scripts/employee.js | 29 ++++ brewman/brewman/static/scripts/overlord.js | 4 + brewman/brewman/templates/angular_base.mako | 1 + brewman/brewman/templates/employee/list.pt | 44 ------ brewman/brewman/templates/nav_bar/employee.pt | 3 +- brewman/brewman/views/blog.py.exclude | 60 -------- brewman/brewman/views/employee.py | 132 ++++++++++-------- 12 files changed, 268 insertions(+), 202 deletions(-) create mode 100644 brewman/brewman/static/partial/employee-detail.html create mode 100644 brewman/brewman/static/partial/employee-list.html create mode 100644 brewman/brewman/static/scripts/employee.js delete mode 100644 brewman/brewman/templates/employee/list.pt delete mode 100644 brewman/brewman/views/blog.py.exclude diff --git a/brewman/brewman/models/master.py b/brewman/brewman/models/master.py index 84225f0f..c4db6676 100644 --- a/brewman/brewman/models/master.py +++ b/brewman/brewman/models/master.py @@ -1,5 +1,5 @@ import uuid -from sqlalchemy import UniqueConstraint, Column, Integer, Unicode, Numeric, Boolean, ForeignKey, func, DateTime +from sqlalchemy import UniqueConstraint, Column, Integer, Unicode, Numeric, Boolean, ForeignKey, func, DateTime, desc from sqlalchemy.orm import relationship from brewman.models import Base, DBSession from brewman.models.guidtype import GUID @@ -26,7 +26,6 @@ class Product(Base): batches = relationship('Batch', backref='product') inventories = relationship('Inventory', backref='product') - ledger = relationship('Ledger', primaryjoin="Ledger.id==Product.ledger_id") def __init__(self, code=None, name=None, units=None, fraction=None, fraction_units=None, yeild=None, @@ -247,14 +246,14 @@ class Employee(LedgerBase): attendances = relationship('Attendance', backref='employe', cascade=None, cascade_backrefs=False) - def __init__(self, code=None, name=None, type=None, parent_ledger_id=None, is_active=None, costcenter_id=None, - designation=None, salary=None, service_points=None, joining_date=None, leaving_date=None): + def __init__(self, code=None, name=None, is_active=None, costcenter_id=None, designation=None, salary=None, + service_points=None, joining_date=None, leaving_date=None): self.designation = designation self.salary = salary self.service_points = service_points self.joining_date = joining_date self.leaving_date = leaving_date - super().__init__(code, name, type, parent_ledger_id, is_active, costcenter_id) + super().__init__(code, name, 10, is_active, costcenter_id) def create(self): code = DBSession.query(func.max(LedgerBase.code)).filter(LedgerBase.type == self.type).one()[0] @@ -266,6 +265,11 @@ class Employee(LedgerBase): DBSession.add(self) return self + @classmethod + def list(cls): + return DBSession.query(Employee).order_by(desc(Employee.is_active)).order_by(Ledger.costcenter_id).order_by( + Employee.designation).order_by(Employee.name).all() + class Ledger(LedgerBase): __mapper_args__ = {'polymorphic_identity': ''} diff --git a/brewman/brewman/static/partial/account-detail.html b/brewman/brewman/static/partial/account-detail.html index 599794bd..baf3f151 100644 --- a/brewman/brewman/static/partial/account-detail.html +++ b/brewman/brewman/static/partial/account-detail.html @@ -1,52 +1,52 @@ -
- Account Detail -
- + + Account Detail +
+ -
- -
+
+
-
- +
+
+ -
- -
+
+
+
-
- +
+ -
- +
+ -
+
-
-
- -
+
+
+
+
-
- +
+ -
- +
+ -
+
-
+
-
- -
+
+
- +
+ diff --git a/brewman/brewman/static/partial/employee-detail.html b/brewman/brewman/static/partial/employee-detail.html new file mode 100644 index 00000000..df819f6e --- /dev/null +++ b/brewman/brewman/static/partial/employee-detail.html @@ -0,0 +1,77 @@ +
+ Employee Detail +
+ + +
+ +
+
+
+ + +
+ +
+
+
+ + +
+ +
+
+
+ + +
+ +
+
+
+ + +
+ +
+
+
+
+ +
+
+ +
+ + +
+ + +
+
+
+ + +
+ +
+
+ +
+ + +
+ +
+
+ +
+ +
+ +
+
+
diff --git a/brewman/brewman/static/partial/employee-list.html b/brewman/brewman/static/partial/employee-list.html new file mode 100644 index 00000000..f45d9dd6 --- /dev/null +++ b/brewman/brewman/static/partial/employee-list.html @@ -0,0 +1,28 @@ +Employees Add + + + + + + + + + + + + + + + + + + + + + + + + + + +
CodeNameDesignationSalaryService PointsDepartmentJoining DateLeaving Date
{{item.Code}}{{item.Name}}{{item.Designation}}{{item.Salary}}{{item.ServicePoints}}{{item.CostCenter}}{{item.JoiningDate}}{{item.LeavingDate}}
diff --git a/brewman/brewman/static/scripts/angular_service.js b/brewman/brewman/static/scripts/angular_service.js index c7017cb0..99b40727 100644 --- a/brewman/brewman/static/scripts/angular_service.js +++ b/brewman/brewman/static/scripts/angular_service.js @@ -21,6 +21,14 @@ overlord_service.factory('Account', ['$resource', function ($resource) { }); }]); +// TODO: Replace hardcoded url with route_url +overlord_service.factory('Employee', ['$resource', function ($resource) { + return $resource('/Employee/:id', + {id:'@LedgerID'}, { + query:{method:'GET', params:{list:true}, isArray:true} + }); +}]); + // TODO: Replace hardcoded url with route_url overlord_service.factory('Ledger', ['$resource', function ($resource) { return $resource('/Ledger/:id'); diff --git a/brewman/brewman/static/scripts/employee.js b/brewman/brewman/static/scripts/employee.js new file mode 100644 index 00000000..5da586fb --- /dev/null +++ b/brewman/brewman/static/scripts/employee.js @@ -0,0 +1,29 @@ +function EmployeeListCtrl($scope, Employee) { + $scope.info = Employee.query(); +} + +function EmployeeCtrl($scope, $routeParams, $location, Employee, CostCenter) { + $scope.employee = Employee.get({id: $routeParams.id}); + + $scope.cost_centers = CostCenter.query(); + + $scope.save = function () { + $scope.employee.$save(function (u, putResponseHeaders) { + $scope.toasts.push({Type:'Success', Message:u.Code}); + $location.path('/Employees') + }, function (data, status) { + $scope.toasts.push({Type:'Error', Message:data.data}); + }); + }; + + $scope.delete = function () { + $scope.employee.$delete(function (u, putResponseHeaders) { + $scope.toasts.push({Type:'Success', Message:''}); + $location.path('/Employees') + }, function (data, status) { + $scope.toasts.push({Type:'Error', Message:data.data}); + }); + }; + $('#txtName').focus(); + +} diff --git a/brewman/brewman/static/scripts/overlord.js b/brewman/brewman/static/scripts/overlord.js index e158e795..174d0376 100644 --- a/brewman/brewman/static/scripts/overlord.js +++ b/brewman/brewman/static/scripts/overlord.js @@ -42,6 +42,10 @@ var overlord = angular.module('overlord', ['overlord.directive', 'overlord.filte when('/Account', {templateUrl:'/partial/account-detail.html', controller:AccountCtrl}). when('/Account/:id', {templateUrl:'/partial/account-detail.html', controller:AccountCtrl}). + when('/Employees', {templateUrl:'/partial/employee-list.html', controller:EmployeeListCtrl}). + when('/Employee', {templateUrl:'/partial/employee-detail.html', controller:EmployeeCtrl}). + when('/Employee/:id', {templateUrl:'/partial/employee-detail.html', controller:EmployeeCtrl}). + when('/CostCenters', {templateUrl:'/partial/cost-center-list.html', controller:CostCenterListCtrl}). when('/CostCenter', {templateUrl:'/partial/cost-center-detail.html', controller:CostCenterCtrl}). when('/CostCenter/:id', {templateUrl:'/partial/cost-center-detail.html', controller:CostCenterCtrl}). diff --git a/brewman/brewman/templates/angular_base.mako b/brewman/brewman/templates/angular_base.mako index 0fc02b8f..1e48fe78 100644 --- a/brewman/brewman/templates/angular_base.mako +++ b/brewman/brewman/templates/angular_base.mako @@ -46,6 +46,7 @@ ${h.ScriptLink(request, 'unposted.js')} ${h.ScriptLink(request, 'account.js')} + ${h.ScriptLink(request, 'employee.js')} ${h.ScriptLink(request, 'user.js')} ${h.ScriptLink(request, 'cost-center.js')} ${h.ScriptLink(request, 'product.js')} diff --git a/brewman/brewman/templates/employee/list.pt b/brewman/brewman/templates/employee/list.pt deleted file mode 100644 index 95f0ac71..00000000 --- a/brewman/brewman/templates/employee/list.pt +++ /dev/null @@ -1,44 +0,0 @@ - - -
-
-

Cost Centers

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
LedgerIDCodeNameDesignationIs Active?CostCenterIDCost CenterJoining DateLeaving Date
${item.id}${item.code}${item.name}${item.designation}${item.is_active}${item.costcenter_id}${item.costcenter.name}${'' if item.joining_date is None else item.joining_date.strftime('%d-%b-%Y')}${'' if item.leaving_date is None else item.leaving_date.strftime('%d-%b-%Y')}
- -
-
- -
- \ No newline at end of file diff --git a/brewman/brewman/templates/nav_bar/employee.pt b/brewman/brewman/templates/nav_bar/employee.pt index 222d3ce5..a0a9bd95 100644 --- a/brewman/brewman/templates/nav_bar/employee.pt +++ b/brewman/brewman/templates/nav_bar/employee.pt @@ -1,8 +1,7 @@