예제 #1
0
def getTimeBy():
    session = Session()
    data = request.get_json()
    time_type = data['type']
    user = data['user']
    print(user)
    print(time_type)
    if user == 'total':
        if time_type =="project":
            time_type_list = ['wfh','REG']
        else:
            time_type_list = [time_type]
        sub_objects = session.query(timesubmissions).filter(timesubmissions.status=='approved',timesubmissions.time_type.in_(time_type_list)).all()
        serialized_obj = serialize_all(sub_objects)
        session.close()
        return (jsonify(serialized_obj)),200
        
    else:
        if time_type =="project":
            time_type_list = ['wfh','REG']
        else:
            time_type_list = [time_type]
        sub_objects = session.query(timesubmissions).filter(timesubmissions.status=='approved',timesubmissions.time_type.in_(time_type_list),timesubmissions.user_id==user).all()
        serialized_obj = serialize_all(sub_objects)
        session.close()
        return (jsonify(serialized_obj)),200
예제 #2
0
def getResourceInfo():
    session =Session()
    data =request.get_json()
    print(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>")
    project_ = session.query(project).filter(project.project_code==data).first()
  
    project_resources_list = project_.resource_info.split(",")
    for i in project_resources_list:
        if i=="":
            project_resources_list.remove(i)
    resource_info_data = session.query(employee).filter(employee.emp_id.in_(project_resources_list)).all()
    print(serialize_all(resource_info_data))
    return jsonify(serialize_all(resource_info_data))
예제 #3
0
def getSubmissionsBy():
    session = Session()
    user = request.get_json()
    if user == 'total':
        sub_objects = session.query(timesubmissions).filter(timesubmissions.status=='submitted-pending approval').all()
        serialized_obj = serialize_all(sub_objects)
        session.close()
        return (jsonify(serialized_obj)),200
        
    else:
        sub_objects = session.query(timesubmissions).filter(timesubmissions.status=='submitted-pending approval', timesubmissions.user_id==user).all()
        serialized_obj = serialize_all(sub_objects)
        session.close()
        return (jsonify(serialized_obj)),200
예제 #4
0
def reset_pass():
    session = Session()
    email = request.json.get('email')
    password = request.json.get('password')
    confirm_pass = request.json.get('password')
    token = request.json.get('reset_token')

    if email is None:
        return jsonify({"error:": "incorrect username or password"}), 400

    forget_pass_objects = session.query(forget_pass).filter(forget_pass.email_address == email)
    forget_pass_obj = serialize_all(forget_pass_objects)

    reset_token = forget_pass_obj[0]['reset_token']
    if reset_token == token:
        # update auth table password
        auth_object = session.query(authUser).filter(authUser.email == email).first()
        if auth_object is None:
            return jsonify({'error': 'User not found, This user is not added yet'}), 401
        auth_object.password = password
        session.add(auth_object)
        session.commit()

        return "Password Reset successfully", 200
    else:
        return "Please generate token for reset password  token expired"
예제 #5
0
def employees():
    session = Session()
    emp_objects = session.query(employee).all()
    serialized_obj = serialize_all(emp_objects)
    #serialized_obj = [{"title":obj.title,"description":obj.description} for obj in emp_objects]
    session.close()
    return (jsonify(serialized_obj))
예제 #6
0
def timeData():
    manager_id = request.get_json()
    session = Session()
    emp_list = session.query(employee.emp_id).filter(employee.manager_id==manager_id).all()
    emp_final = [emp[0].lower() for emp in emp_list]
    time_final = []
    for emp in emp_final:
        project_time = 0
        sl = 0
        cl=0
        al=0
        bench=0
        user_id = emp
        unapproved=0

        user_name = session.query(employee.first_name).filter(employee.emp_id==emp).first()[0]
        submission_obj = session.query(timesubmissions).filter(timesubmissions.user_id==emp).all()
        serialized_obj = serialize_all(submission_obj)
        for time in serialized_obj:
            #print(time)
            if time['status']=='approved':
                if time['time_type']=='wfh' or time['time_type']=='REG':
                    project_time = project_time + time['hours']
                elif time['time_type']=='sl':
                    sl = sl + time['hours']
                elif time['time_type']=='cl':
                    cl = cl + time['hours']
                elif time['time_type']=='al':
                    al = al + time['hours']
                elif time['time_type']=='bench':
                    bench = bench + time['hours']
            else:
                unapproved = unapproved + time['hours']    
        
        total_hrs = project_time + sl + cl + al + bench
        time_final.append({'user_id':user_id, 'user_name': user_name, 'project_time':project_time,'sl':sl,'cl':cl,'al':al,'bench':bench,'unapproved':unapproved, 'total_hrs':total_hrs})
    print(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>")
    print(time_final)  
    print(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>")
    total_project = 0
    total_sl = 0
    total_cl = 0
    total_al = 0
    total_bench = 0
    total_unapproved = 0

    for emp_data in time_final:
        total_project = total_project  + emp_data['project_time']
        total_sl = total_sl  + emp_data['sl']
        total_cl = total_cl  + emp_data['cl']
        total_al = total_al  + emp_data['al']
        total_bench = total_bench  + emp_data['bench']
        total_unapproved = total_unapproved + emp_data['unapproved']
    total_time_list = {'total_project':total_project,'total_sl':total_sl,'total_cl':total_cl,'total_al':total_al,'total_bench':total_bench,'total_unapproved':total_unapproved, }
    print(total_time_list)
    #time_final.append({'total_project':total_project,'total_sl':total_sl,'total_cl':total_cl,'total_al':total_al,'total_bench':total_bench,'total_unapproved':total_unapproved, })
    return (jsonify({'result':time_final,'total':total_time_list}))
예제 #7
0
def projects():
    session = Session()
    project_objects = session.query(project).all()
    serialized_obj = serialize_all(project_objects)
    # serialized_obj = [{"project_id":obj.project_id,
    #                     "project_title":obj.project_title,
    #                     "project_start_date":obj.project_start_date,
    #                     "project_status":obj.project_status} for obj in project_objects]
    session.close()
    return (jsonify(serialized_obj))
예제 #8
0
def employees():
    session = Session()
    emp_objects = session.query(employee).all()
    serialized_obj = serialize_all(emp_objects)
    serialed_out = []
    for dictionary in serialized_obj:
        dictionary['full_name'] = dictionary['first_name'] + dictionary['last_name']
        serialed_out.append(dictionary)

    project_objects = session.query(project).all()
    serialized_project = serialize_all(project_objects)
    for dictionary in serialed_out:
        emp_id = dictionary["project_code"]
        for proj_item in serialized_project:
            if proj_item["project_code"]==emp_id:
                proj_item["project_code"] = [emp_id] #Project id should return list instead of string in employee
                dictionary.update(proj_item)
                break
    session.close()
    return (jsonify(serialed_out))
예제 #9
0
def events():
    session = Session()
    time_objects = session.query(timesubmissions).all()
    serialized_obj = serialize_all(time_objects)
    events_data = []
    for event in serialized_obj:
        eve={}
        eve["title"]="*" + str(event["time_type"]) + " : "+ str(event["hours"]) + " Hours"
        eve["start"]=event["date_info"]
        events_data.append(eve)   
    return jsonify(events_data)
예제 #10
0
def get_announcements():
    session = Session()
    data = request.get_json()
    user_id = data.get("user_id")
    existing_announcements = session.query(announcements).filter(announcements.user_id==user_id).order_by(announcements.id.desc())[-30:]
    if existing_announcements:
    #ann = announcements.select([announcements]).order_by(-announcements.c.id.desc()).limit(2)
    #if ann:
        serialized_obj = serialize_all(existing_announcements)
        print(serialized_obj)
        return jsonify(serialized_obj),200  
    return jsonify({'info':'No announcements are available for you'}),200
예제 #11
0
def viewEmpInfo():
    emp_id = request.json.get("emp_id", None)
    print("????????????")
    print(emp_id)
    if emp_id is None:
        return jsonify({"error":"Employee ID is empty"}), 201
    session = Session()
    emp_objects = session.query(employee).filter(employee.emp_id==emp_id).all()
    print(">>>>>>>>>>>>")
    print(emp_objects)
    if emp_objects == []:
        return jsonify({"error":"Employee Not found !"}), 201
    emp_serialized = serialize_all(emp_objects)
    print(emp_serialized)
    emp_dict = emp_serialized[0]
    project_objects = session.query(project).filter(project.project_code==emp_serialized[0]['project_code']).all()
    if project_objects:
        project_serialized = serialize_all(project_objects)
        proj_dict = project_serialized[0]
        emp_dict.update(proj_dict)
    emp_dict['full_name'] = emp_dict['salutation'] + emp_dict['first_name'] + emp_dict['last_name']
    return jsonify(emp_dict), 201
예제 #12
0
def viewsubmissions():
    session = Session()
    data = request.get_json()
    manager_name = data  
    print(manager_name)
    emp_list = session.query(employee.emp_id).filter(employee.manager_id==manager_name).all()
    emp_final = [emp[0].lower() for emp in emp_list]
    print(emp_final)
    submission_obj = session.query(timesubmissions).filter(timesubmissions.manager_id.in_(emp_final),timesubmissions.status=='submitted-pending approval' ).all()
    print(submission_obj)
    if submission_obj:
        serialized_obj = serialize_all(submission_obj)
        print(serialized_obj)
        return jsonify(serialized_obj),200
    return jsonify({'info':'No submission available for you'}),200
예제 #13
0
def timesubmission():
    session = Session()
    sub_objects = session.query(timesubmissions).all()
    serialized_obj = serialize_all(sub_objects)
    session.close()
    return (jsonify(serialized_obj))
예제 #14
0
def projects():
    session = Session()
    project_objects = session.query(project).all()
    serialized_obj = serialize_all(project_objects)
    session.close()
    return (jsonify(serialized_obj))
예제 #15
0
def announcement():
    session = Session()
    announcement_objects = session.query(announcements).all()
    serialized_obj = serialize_all(announcement_objects)
    session.close()
    return (jsonify(serialized_obj))