Example #1
0
def employee_edit(emp_code):
   data = request.get_json()
   employee_to_edit = Employee.query.filter_by(code = emp_code).first()
   try:
      employee_to_edit.firstname = data['firstname']
      employee_to_edit.middlename = data['middlename']
      employee_to_edit.lastname = data['lastname']
      employee_to_edit.address = data['address']
      employee_to_edit.gender = data['gender']
      employee_to_edit.code = data['code']
      employee_to_edit.birthday = data['birthday']
      employee_to_edit.position = data['position']
      employee_to_edit.nationality = data['nationality']
      employee_to_edit.status = data['status']
      employee_to_edit.email = data['email']
      employee_to_edit.contact_number = data['contact_number']
      employee_to_edit.department = data['department']
      #logs here
      details = "Edited information of " + employee_to_edit.firstname + " " + employee_to_edit.lastname
      new_log = Logs(log_date=dt.datetime.now(), log_details=details)
      dbase.session.add(new_log)
      dbase.session.commit()
      #End log
      return jsonify({'message': 'Information was edited Successfully!'})
   except:
      return jsonify({'message': 'The code is not available!'})
Example #2
0
def patch():
    c1_json = request.get_json()
    one_customer = session.query(Customer).filter(
        Customer.email == c1_json["email"]).first()
    if one_customer == None:
        return (jsonify({"message": "Mail not found."}), 404)
    else:
        session.add(one_customer)
        session.commit()
        return (jsonify({}), 200)
Example #3
0
def post():
    c1_json = request.get_json()
    if session.query(Customer).filter(
            Customer.email == c1_json["email"]).first() == None:
        c1 = Customer(name=c1_json["name"],
                      address=c1_json["address"],
                      email=c1_json["email"])
        session.add(c1)
        session.commit()
        return (jsonify({"message": "Successfully loaded."}), 200)
    else:
        return (jsonify({"message": "This email already exists."}), 404)
Example #4
0
def delete():
    c1_json = request.get_json()
    try:
        if Customer.check_user_existance_and_apply(c1_json, session):
            session.delete(
                session.query(Customer).filter(
                    Customer.email == c1_json["email"]).first())
            session.commit()
            return (jsonify({"Message": "User deleted."}), 200)
        else:
            return (jsonify({"Message": "User could not be found."}), 404)
    except:
        return (jsonify({"Message":
                         "The database could not be accesed."}), 500)
Example #5
0
def get():
    c1_json = request.get_json()
    try:
        if Customer.check_user_existance_and_apply(c1_json, session):
            a_user = session.query(Customer).filter(
                Customer.email == c1_json["email"]).first()
            return (jsonify({
                "name": a_user.name,
                "address": a_user.address,
                "email": a_user.email
            }), 200)
        else:
            return (jsonify({"Message": "User could not be found."}), 404)
    except:
        return (jsonify({"Message":
                         "The database could not be accesed."}), 500)
Example #6
0
def edit_time():
   data = request.get_json()
   to_edit = CompanyTime.query.filter_by(company_time_id = 1).first()
   if to_edit:
      to_edit.morning_time_in = dt.datetime.strptime(data['morning_time_in'], "%H:%M:%S")
      to_edit.morning_time_out = dt.datetime.strptime(data['morning_time_out'], "%H:%M:%S")
      to_edit.afternoon_time_in = dt.datetime.strptime(data['afternoon_time_in'], "%H:%M:%S")
      to_edit.afternoon_time_out = dt.datetime.strptime(data['afternoon_time_out'], "%H:%M:%S")
      dbase.session.commit()
      #logs here
      details = "Edited time In/Out."
      new_log = Logs(log_date = dt.datetime.now(), log_details = details )
      dbase.session.add(new_log)
      dbase.session.commit()
      #End log
      return jsonify({'message':'Time changed successfully!'})
   return jsonify({'message': 'Operation failed!'})
Example #7
0
def login():
   data = request.get_json()
   print data
   admin = Admin.query.filter_by(username = data['username']).first()
   if not admin:
      return jsonify({'message': 'Invalid username or password'})
   else:
      if check_password_hash(admin.password, data['password']):
         login_user(admin, remember=True)
      #logs here
         details = "Logged in"
         new_log = Logs(log_date=dt.datetime.now(), log_details=details)
         dbase.session.add(new_log)
         dbase.session.commit()
      #End log
         return jsonify({'message': 'Login Successfully!'})
      else:
         return jsonify({'message': 'Invalid username or password'})
Example #8
0
def employee_add():
   data = request.get_json()
   check_avail = Employee.query.filter_by(code = data['code']).first()
   if not check_avail:
      new_employee = Employee(firstname=data['firstname'], middlename=data['middlename'],
       lastname=data['lastname'], address=data['address'], gender=data['gender'], code=data['code'],
       birthday = data['birthday'], position=data['position'], employee_status=1, nationality=data['nationality'], status=data['status'],
       email=data['email'], contact_number=data['contact_number'], department=data['department'])
      dbase.session.add(new_employee)
      dbase.session.commit()
      #logs here
      details = "Added employee " + data['firstname'] + " " + data['lastname']
      new_log = Logs(log_date=dt.datetime.now(), log_details=details)
      dbase.session.add(new_log)
      dbase.session.commit()
      #End log
      return jsonify({'message': 'Employee was added Successfully!'})
   else:
      return jsonify({'message': 'The code is not available employee already exist.'})
Example #9
0
def summary(dates):
   data = request.get_json()
   dates = dt.datetime.strptime(dates, "%Y-%m-%d")
   if data['emp_id'] == "" or data['emp_id'] is None:
      summary = Attendance.query.filter(extract('year', Attendance.attendance_date) == (dates.strftime("%Y"))).filter(extract('month', Attendance.attendance_date) == (dates.strftime("%m"))).order_by(Attendance.attendance_date.desc()).all()
      employees = []
      print summary
      if not summary:
         return jsonify({'Employee': employees})
      for employee in summary:
         employee_data = {}
         name = Employee.query.filter_by(code=employee.employee_code).first()
         if not name:
            employee_data['name'] = "Empty"
         else:
            employee_data['name'] = name.firstname + " " + name.middlename + " " + name.lastname
         employee_data['date'] = str(employee.attendance_date)
         employee_data['morning_remarks'] = employee.morning_remarks
         employee_data['afternoon_remarks'] = employee.afternoon_remarks
         if employee.morning_time_in is None:
            employee_data['morning_time_in'] = "None"
         else:
            employee_data['morning_time_in'] = str(employee.morning_time_in.strftime("%H:%M:%S"))
         if employee.morning_time_out is None:
            employee_data['morning_time_out'] = "None"
         else:
            employee_data['morning_time_out'] = str(employee.morning_time_out.strftime("%H:%M:%S"))
         if employee.afternoon_time_in is None:
            employee_data['afternoon_time_in'] = "None"
         else:
            employee_data['afternoon_time_in'] = str(employee.afternoon_time_in.strftime("%H:%M:%S"))
         if employee.afternoon_time_out is None:
            employee_data['afternoon_time_out'] = "None"
         else:
            employee_data['afternoon_time_out'] = str(employee.afternoon_time_out.strftime("%H:%M:%S"))
         employees.append(employee_data)
      return jsonify({'Employee': employees})
   else:
      summary = Attendance.query.filter(and_((Attendance.employee_code == data['emp_id']),(extract('year', Attendance.attendance_date) == (dates.strftime("%Y"))),(extract('month', Attendance.attendance_date) == (dates.strftime("%m"))))).order_by(Attendance.attendance_date.desc()).all()
      print summary
      employees = []
      if not summary:
         return jsonify({'Employee': employees})
      for employee in summary:
         employee_data = {}
         name = Employee.query.filter_by(code=employee.employee_code).first()
         if not name:
            employee_data['name'] = "Empty"
         else:
            employee_data['name'] = name.firstname + " " + name.middlename + " " + name.lastname
         employee_data['date'] = str(employee.attendance_date)
         employee_data['morning_remarks'] = employee.morning_remarks
         employee_data['afternoon_remarks'] = employee.afternoon_remarks
         if employee.morning_time_in is None:
            employee_data['morning_time_in'] = "None"
         else:
            employee_data['morning_time_in'] = str(employee.morning_time_in.strftime("%H:%M:%S")) 
         if employee.morning_time_out is None:
            employee_data['morning_time_out'] = "None"
         else:
            employee_data['morning_time_out'] = str(employee.morning_time_out.strftime("%H:%M:%S"))
         if employee.afternoon_time_in is None:
            employee_data['afternoon_time_in'] = "None"
         else:
            employee_data['afternoon_time_in'] = str(employee.afternoon_time_in.strftime("%H:%M:%S"))
         if employee.afternoon_time_out is None:
            employee_data['afternoon_time_out'] = "None"
         else:
            employee_data['afternoon_time_out'] = str(employee.afternoon_time_out.strftime("%H:%M:%S"))
         employees.append(employee_data)
      return jsonify({'Employee': employees})