Exemplo n.º 1
0
    def put(self, id):
        parse = reqparse.RequestParser()
        parse.add_argument("status",
                           type=str,
                           required=True,
                           help="status Type Required")
        data = parse.parse_args()
        leave = LeaveModel.find_by_id(id)
        if leave:
            leave.status = data["status"]
            leave.senction_date = datetime.datetime.now()
            leave.senction_by_id = get_jwt_identity()
            leave.save_to_db()

            # credential sent to user via email
            msg = Message('Leave Application ' + data['status'] + '!',
                          recipients=[
                              AuthenticationModel.find_by_id(
                                  leave.emp_id).email
                          ])
            username = AuthenticationModel.find_by_id(
                leave.emp_id).username.split('.')[0]

            if data['status'] == 'Approved':
                msg.body = leaveApprovedmessage(username, leave.start_date,
                                                leave.end_date)
                # deduct leave from annual leave
                anuualeave = Annual_Leave.find_by_id(leave.emp_id)
                delta = parser.parse(leave.end_date) - \
                    parser.parse(leave.start_date)
                if anuualeave:
                    if leave.leave_type == 'PL':
                        anuualeave.pl = Annual_Leave.find_by_id(
                            leave.emp_id).pl - delta.days
                    elif leave.leave_type == 'CL':
                        anuualeave.cl = Annual_Leave.find_by_id(
                            leave.emp_id).cl - delta.days
                    elif leave.leave_type == 'SL':
                        anuualeave.sl = Annual_Leave.find_by_id(
                            leave.emp_id).sl - delta.days
                    else:
                        # deduct salary also
                        anuualeave.lwp = Annual_Leave.find_by_id(
                            leave.emp_id).lwp - delta.days

                anuualeave.save_to_db()
                # print(anuualeave.json())

            elif data['status'] == 'Cancle':
                msg.body = leaveCanclemessage(username, leave.start_date,
                                              leave.end_date)
            else:
                msg.body = leaveForwardmessage(username, leave.start_date,
                                               leave.end_date)

            mail.send(msg)
 def get(self):
     username = AuthenticationModel.find_by_id(get_jwt_identity()).username
     salary = [
         salary.json() for salary in SalaryModel.query.filter(
             SalaryModel.username == username)
     ]
     return {"salary": salary}
Exemplo n.º 3
0
 def put(self):
     data = ChangePassword.parse.parse_args()
     employee = AuthenticationModel.find_by_id(get_jwt_identity())
     if employee:
         employee.password = data["password"]
         employee.save_to_db()
         return {"status": True}
     return {"Status": False}
Exemplo n.º 4
0
def add_claims_to_access_token(identity):
    user_role = AuthenticationModel.find_by_id(identity)
    if user_role:
        if user_role.role == 'Hr':
            return {'roles': 'Hr'}
        elif user_role.role == 'Admin':
            return {'roles': 'Admin'}
        else:
            return {'roles': 'Employee'}
Exemplo n.º 5
0
 def json(self):
     return {
         "id": self.id,
         "Username": AuthenticationModel.find_by_id(self.emp_id).username,
         "Technology": self.technology,
         "ProjectName": self.projectname,
         "hour": self.hour,
         "desc": self.desc,
         "DateTime": str(self.date).split(".")[0],
     }
Exemplo n.º 6
0
 def json(self):
     return {
         "Start Date": str(self.start_date),
         "End Date": str(self.end_date),
         "Type": self.leave_type,
         "Apply Date": str(self.apply_date),
         "Status": self.status,
         "id": self.emp_id,
         "leave_id": self.id,
         "Username": AuthenticationModel.find_by_id(self.emp_id).username,
         "Description": self.leave_Description,
     }
Exemplo n.º 7
0
 def post(self):
     data = EmployeePersonalDetails.parse.parse_args()
     employee = AuthenticationModel.find_by_id(get_jwt_identity())
     if employee:
         personaldetails = PersonalDetailsModel(get_jwt_identity(), **data)
         personaldetails.save_to_db()
         return {"success": True}
     return {
         "NotFoundError": {
             "success": False,
             "error": "Employee Not Found"
         }
     }
Exemplo n.º 8
0
    def post(self):
        data = EmployeeQualificationDetails.parse.parse_args()
        employee = AuthenticationModel.find_by_id(get_jwt_identity())
        if employee:
            qualification = QualificationModel(
                get_jwt_identity(),
                data["qualification"],
                data["pass_year"],
                data["experience"],
            )
            qualification.save_to_db()
            return {"success": True}

        return {"success": False, "error": "Not Found"}
Exemplo n.º 9
0
 def post(self):
     data = EmployeeSalaryDetails.parse.parse_args()
     employee = AuthenticationModel.find_by_id(get_jwt_identity())
     if employee:
         salary = EmployeeSalaryDetailsModel(
             get_jwt_identity(),
             data["accountno"],
             data["ifsccode"],
             data["bankname"],
             data["pfaccount_no"],
             data["esi_no"],
         )
         salary.save_to_db()
         return {"success": True}
     return {"success": False, "error": "Not Found"}
Exemplo n.º 10
0
    def post(self):
        data = EmployeeAddressDetails.parse.parse_args()
        employee = AuthenticationModel.find_by_id(get_jwt_identity())
        if employee:
            address = AddressModel(
                get_jwt_identity(),
                data["city"],
                data["state"],
                data["pincode"],
                data["fulladdress"],
            )
            address.save_to_db()
            return {"success": True}

        return {"success": False, "error": "Not Found"}
Exemplo n.º 11
0
    def post(self):
        parse = reqparse.RequestParser()
        parse.add_argument("ltype",
                           type=str,
                           required=True,
                           help="Leave Type Required")
        parse.add_argument("startdate",
                           type=str,
                           required=True,
                           help="start_date Type Required")
        parse.add_argument("enddate",
                           type=str,
                           required=True,
                           help="end_date Type Required")
        parse.add_argument("desc",
                           type=str,
                           required=True,
                           help="desc Type Required")

        data = parse.parse_args()
        employee = AuthenticationModel.find_by_id(get_jwt_identity())
        if employee:
            if employee.role == 'Hr':
                leave = LeaveModel(get_jwt_identity(), data["ltype"],
                                   data["startdate"], data["enddate"],
                                   data["desc"], 'Forward')
                leave.save_to_db()
            else:
                leave = LeaveModel(get_jwt_identity(), data["ltype"],
                                   data["startdate"], data["enddate"],
                                   data["desc"], 'Pending')
                leave.save_to_db()

        return {
            "status": 200,
            "data": [leave.json() for leave in LeaveModel.query.all()],
        }
Exemplo n.º 12
0
    def get(self):
        employee = AuthenticationModel.find_by_id(get_jwt_identity())
        if employee:
            employee.isAuthenticate = False
            employee.save_to_db()
            jti = get_raw_jwt()["jti"]
            blacklist.add(jti)

            attend = AttendanceModel.query.filter(
                and_(
                    AttendanceModel.date == datetime.today().strftime(
                        "%d/%m/%Y"),
                    AttendanceModel.emp_id == get_jwt_identity(),
                )).first()

            attend.endtime = datetime.now().strftime("%H:%M:%S")
            attend.save_to_db()

            return {
                "msg": "Successfully logged out",
                "authenticate": employee.isAuthenticate,
            }, 200
        else:
            return {"error": "error in logout"}
Exemplo n.º 13
0
 def get(self):
     employee = AuthenticationModel.find_by_id(get_jwt_identity())
     return {"Employee": employee.json(), "success": True}