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)
Exemplo n.º 2
0
    def post(self):
        data = Admin.parse.parse_args()
        employee = AuthenticationModel(**data)
        employee.save_to_db()

        return {
            "success": True,
            "username": employee.username,
            "password": employee.password
        }
Exemplo n.º 3
0
    def post(self):
        data = Setup.parse.parse_args()
        today = datetime.date.today()
        employee = AuthenticationModel(data['username'], data['password'],
                                       data['role'], data['email'], today)
        employee.save_to_db()

        return {
            "success": True,
            "username": employee.username,
            "password": employee.password
        }
Exemplo n.º 4
0
    def post(self):
        data = EmployeeLogin.parse.parse_args()
        employee = AuthenticationModel.find_by_username(data["username"])
        # if employee.isAuthenticate:
        #     return {
        #         "success": False,
        #         "error": "You Are Already LoggedIn In Another System Please Logout there.."
        #     }

        if employee and safe_str_cmp(data["password"], employee.password):
            # chnage isauthenticate value
            employee.isAuthenticate = True
            Attend = AttendanceModel(
                employee.id,
                datetime.now().strftime("%H:%M:%S"),
                datetime.today().strftime("%d/%m/%Y"),
            )
            Attend.save_to_db()

            # print(employee.id)
            return {
                "access_token":
                create_access_token(identity=employee.id, expires_delta=False),
                "role":
                employee.role,
                "success":
                True,
                "authenticate":
                employee.isAuthenticate,
            }
        return {"error": "Username or password incorrent", "success": False}
 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}
    def post(self):
        data = Salary.parse.parse_args()
        employee = AuthenticationModel.find_by_username(data['username'])
        if employee:
            basic = GradeModel.query.filter_by(emp_id=employee.id).order_by(
                GradeModel.emp_id.desc()).first().basic
            netamount = basic * HRA + basic * DA + basic * TA + basic
            salary = SalaryModel(data['username'], data['month'], netamount)
            salary.save_to_db()
            # salary get mail
            msg = Message('Salary credited!', recipients=[employee.email])
            msg.body = '''
            Hello  ''' + data['username'].split('.')[0] + ''',
            Your ''' + data[
                'month'] + ''' month salary is credited. You can download salary slip from HRMS portal.\n

            If you have any queries, please feel free to contact the Human Resources  Department. 
            We look forward to your success in the company\n

            Thanks & Regards,
            Name of hr
            HR Executive 
            Direct: +91 6353235503 | W: www.lanetteam.com 
            406, Luxuria Business Hub, Nr. VR Mall, Surat, Gujarat - 395007
            Ground Floor, I.T.P.I Building, Beside Celebration Mall, Bhuwana, Udaipur, Rajasthan - 313001'''
            mail.send(msg)
            return {"Status": "Success"}

        return {"status": "404/Not Found"}
Exemplo n.º 7
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.º 8
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.º 9
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.º 10
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.º 11
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.º 12
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.º 13
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.º 14
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.º 15
0
    def delete(self):
        parse = reqparse.RequestParser()
        parse.add_argument('username',
                           type=str,
                           required=True,
                           help='username is required')
        data = parse.parse_args()
        employee = AuthenticationModel.find_by_username(data['username'])

        if employee:
            employee.delete_from_db()
            return {"status": 200, "message": "Account Deleted"}
        return {
            "status": 404,
            "NotFoundError": "Given Username data not Found.."
        }
Exemplo n.º 16
0
    def post(self):
        data = JoiningDetails.parse.parse_args()
        employee = AuthenticationModel.find_by_username(data["username"])
        if employee:
            joining_date = datetime.strptime(data["joining_date"], "%d %B %Y")
            joining_details = JoiningDetailsModel(
                employee.id,
                joining_date,
            )
            joining_details.save_to_db()

            # here grade details
            grade = GradeModel(employee.id, data["grade"],
                               data["joining_date"], data["basic"])
            grade.save_to_db()

            # here annual leave is set
            annual_leave = Annual_Leave(employee.id)
            annual_leave.save_to_db()

            return {"status": True}
        else:
            return {"error": data["username"] + "not Found"}
Exemplo n.º 17
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.º 18
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.º 19
0
    def post(self):
        data = EmployeeRegister.parse.parse_args()
        employee = AuthenticationModel.find_by_username(data["username"])

        if employee:
            return {
                "AlreadyExistsError": {
                    "status": False,
                    "error": "Username already exists",
                }
            }

        joindate = date.fromisoformat(data['joiningdate'].split('T')[0])

        employee = AuthenticationModel(data['username'], data['password'],
                                       data['role'], data['email'], joindate)
        employee.save_to_db()

        # add  joining details

        joiningdetails = JoiningDetailsModel(employee.id, joindate)
        print(joiningdetails.json())
        joiningdetails.save_to_db()

        # fetch basic for particular designation
        des = DesignationModel.find_by_designation(data['designation'])
        print(des.json())

        # add employee level grade
        grade = GradeModel(employee.id, data['designation'], joindate,
                           des.basic)
        grade.save_to_db()

        print(grade.json())

        # annual leave
        annual_leave = Annual_Leave(employee.id)
        annual_leave.save_to_db()

        # credential sent to user via email
        msg = Message('Welcome to LaNet Teams!', recipients=[data['email']])
        msg.body = '''
        Hello  ''' + data['username'].split('.')[0] + ''',
        We are delighted to have you among us as a part of La net team software solutions Pvt. Ltd.
        On behalf of all the members and the management, we would like to extend our warmest welcome and good wishes! Your Joining date will be ''' + data[
            'joiningdate'].split('T')[0] + ''' .\n

        Here your credential for Company HRMS System.            
        username = ''' + data['username'] + '''
        password = ''' + data['password'] + '''
        HRMS Link = 'http://127.0.0.1:3000/'

        If you have any queries, please feel free to contact the Human Resources  Department. 
        We look forward to your success in the company\n

        Thanks & Regards,
        Name of hr
        HR Executive 
        Direct: +91 6353235503 | W: www.lanetteam.com 
        406, Luxuria Business Hub, Nr. VR Mall, Surat, Gujarat - 395007
        Ground Floor, I.T.P.I Building, Beside Celebration Mall, Bhuwana, Udaipur, Rajasthan - 313001'''
        mail.send(msg)

        return {
            "success": True,
            "message": "Employee Registerd",
            "id": employee.id,
            "Employee": employee.json()
        }
Exemplo n.º 20
0
 def get(self):
     employee = AuthenticationModel.find_by_id(get_jwt_identity())
     return {"Employee": employee.json(), "success": True}