def employees(): all_my_depts = DepartmentModel.fetch_all_departments() allemps = EmployeeModel.fetch_all() # flash(type(allemps)) if request.method == 'POST': name = request.form['fullname'] gender = request.form['gender'] email = request.form['email'] phonenumber = request.form['phonenumber'] department = request.form['department'] idnumber = request.form['idnumber'] krapin = request.form['krapin'] basicsalary = request.form['basicsalary'] benefits = request.form['benefits'] if EmployeeModel.check_idnumber_exists(idnumber): flash('already exists') return redirect(url_for('employees')) else: emp = EmployeeModel(fullname=name,gender=gender,email=email,phonenumber=phonenumber,idnumber=idnumber, department=department,krapin=krapin,basicsalary=basicsalary,benefits=benefits) emp.create_record() flash('success') return redirect(url_for('employees')) return render_template('employees.html', madepts=all_my_depts, employees= allemps)
def find_all(cls, user, department_id): from models.department import DepartmentModel records = cls.query.filter_by(department_id=department_id).all() if records and DepartmentModel.find_by_id(department_id, user): return records
def find_all(cls, user): from models.department import DepartmentModel departments = DepartmentModel.find_all(user) d_ids = [department.id for department in departments] return cls.query.filter(cls.department_id.in_(d_ids)).all()
def find_by_id(cls, _id, user): from models.department import DepartmentModel record = cls.query.filter_by(id=_id).first() if record: if DepartmentModel.find_by_id(record.department_id, user): return record
def department_employees(id): dpt_emp = DepartmentModel.fetch_by_id(id) employees = dpt_emp.employee return render_template('departmentemp.html', wafanyakazi=employees, dep=dpt_emp)
def departments(): # fetching all departments and store them in a variable called all_my_depts all_my_depts = DepartmentModel.fetch_all_departments() # flash(type(all_my_depts)) # for x in all_my_depts: # flash(x.name) if request.method == 'POST': # fetch the user's input from the modal/form dept = request.form['department'] # check if a department alread exists if DepartmentModel.check_dept_exist(dept): # if true warn the user it already exists flash('Department Already Exists, 'Danger') else: # if it is false, add the record to the database record = DepartmentModel(name=dept) record.create() flash('success') return redirect(url_for('departments')) return render_template('departments.html', madepts=all_my_depts)
def find_all(cls, user): from models.department import DepartmentModel from models.employee import EmployeeModel departments = DepartmentModel.find_all(user) d_ids = [department.id for department in departments] employees = EmployeeModel.query.filter( EmployeeModel.department_id.in_(d_ids)).all() e_ids = [employee.id for employee in employees] return cls.query.filter(cls.userid.in_(e_ids), cls.was_processed == False).all()
def post(self, name): if DepartmentModel.find_by_name(name): return { 'message': "A department with name {} already exists".format(name) }, 400 department = DepartmentModel(name) try: department.save_to_db() except: return {"message": "An error occure"}, 500 return department.json(), 200
def employees(): all_my_depts = DepartmentModel.fetch_all_departments() allemps = EmployeeModel.fetch_all() # print(type(allemps)) if request.method == 'POST': name = request.form['fullName'] gender = request.form['gender'] email = request.form['email'] phone = request.form['phone'] deptId = request.form['department'] natId = request.form['natId'] kraPin = request.form['krapin'] basicsalary = request.form['basicsalary'] benefits = request.form['benefits'] if EmployeeModel.check_nationalId_exists(natId): flash('Employee exists', 'danger') return redirect(url_for('employees')) else: emp = EmployeeModel(fullName=name, gender=gender, email=email, phoneNumber=phone, nationalId=natId, department_id=deptId, kraPin=kraPin, basicSalary=basicsalary, benefits=benefits) emp.create_record() flash('Employee has successfully been added!', 'success') return redirect(url_for('employees')) return render_template('employees.html', madepts=all_my_depts, employees=allemps)
def employees(): all_records = DepartmentModel.fetch_department_records() all_employee_records = EmployeeModel.fetch_employee_records() if request.method == 'POST': employee_name = request.form['fullName'] department_name = request.form['department'] gender_name = request.form['gender'] email_name = request.form['email'] phoneNumber_name = request.form['phoneNumber'] idNumber_name = request.form['idNumber'] KRApin_name = request.form['KRApin'] salary_name = request.form['salary'] benefits_name = request.form['benefits'] if EmployeeModel.check_employee_exist(idNumber_name): print('existing record') else: try: employee_record = EmployeeModel(full_name=employee_name, gender=gender_name, email=email_name, phone_number=phoneNumber_name, national_id=idNumber_name, kra_pin=KRApin_name, salary=salary_name, benefits=benefits_name, department_id=department_name) employee_record.create_record() print('Successfully added') return redirect(url_for('employees')) except Exception as e: print("Unable to add record") return render_template("employees.html", mydepartments=all_records, myemployees=all_employee_records)
def departments(): all_records = DepartmentModel.fetch_department_records( ) #Request all current records # print(all_records) if request.method == 'POST': department_name = request.form['departmentname'] if DepartmentModel.check_department_exist(department_name): print('existing record') else: try: department_record = DepartmentModel(name=department_name) department_record.create_record() print('Successfully added') return redirect(url_for('departments')) except Exception as e: print("Unable to add record") return render_template("departments.html", mydepartments=all_records)
def mutate(self, info, name): new_department = DepartmentModel(name=name) db_session.add(new_department) db_session.commit() return CreateDepartment(id=new_department.id, name=new_department.name)
def get(self, name): department = DepartmentModel.find_by_name(name) if department: return department.json() return {'message': 'department not found'}, 404
def delete(self, name): department = DepartmentModel.find_by_name(name) if department: department.delete_from_db() return {'message': 'department deleted'}