Exemplo n.º 1
0
def get_person_list_api():
    if not session.get('logged_in'):
        return dumps({'result': False, 'msg': 'Login required.'})
    query = request.form['query']
    search_filter = request.form['search_filter']
    if query == None:
        result = models.Person().get()
    else:
        if search_filter in ('number', 'email'):
            search_filter += 's'
        result = models.Person().find([search_filter], query)
    return dumps({'result': True, 'data': result.sort('name', 1)})
Exemplo n.º 2
0
def add_vehicle_api():
    if not session.get('logged_in'):
        return json.dumps({'result': False, 'msg': 'Login required.'})
    user_id = ObjectId(session['user']['_id'])
    person_id = ObjectId(request.form.get('person_id'))
    registration_number = request.form.get('registration_number')
    registration_name = request.form.get('registration_name')
    registration_date = request.form.get('registration_date')
    company = request.form.get('company')
    company_other = request.form.get('company_other')
    model = request.form.get('model')
    model_other = request.form.get('model_other')
    cc = request.form.get('cc')
    fuel = request.form.get('fuel')
    mfg = request.form.get('mfg')
    if company_other not in ('', None):
        add_company = models.vehicle().add_vehicle_company(
            user_id=user_id, company_name=company_other)
        company_id = add_company['new_id']
        company = company_other
    else:
        company_id = db.vehicle_collection.find_one({'company_name':
                                                     company})['_id']
    if model_other not in ('', None):
        add_model = models.vehicle().add_vehicle_model(user_id=user_id,
                                                       company_id=company_id,
                                                       model_name=model_other)
        model = model_other
    return dumps(
        models.Person(person_id).add_registration(registration_number,
                                                  registration_name,
                                                  registration_date, company,
                                                  model, cc, fuel, mfg))
Exemplo n.º 3
0
def add_renewal_health_policy():
    if not session.get('logged_in'):
        return json.dumps({'result': False, 'msg': 'Login required.'})
    result = {}
    result['result'] = False
    result['msg'] = 'Something went wrong.'
    policy_id = ObjectId(request.form.get('policy_id'))
    remark = request.form.get('remark')
    policy = models.Policy_health(policy_id)
    expiry_date = request.form.get('expiry_date')
    policy_owner = policy.policy_owner
    policy_number = request.form.get('policy_number')
    policy_type = request.form.get('policy_type')
    company = request.form.get('company')
    idv = request.form.get('idv')
    ncb = request.form.get('ncb')
    premium = request.form.get('premium')
    own_business = True if 'own_business' in request.form else False
    insert_new_policy = models.Person(policy.person_id).add_health_policy(
        expiry_date, policy_owner, policy_number, policy_type, company, idv,
        ncb, premium, own_business)
    if insert_new_policy['result']:
        result['result'] = True
        result['new_id'] = insert_new_policy['new_id']
        # add new policy id & policy status in old policy data
        db.health_policy_collection.update_one(
            {'_id': policy._id}, {'$set': {
                'renewal_id': result['new_id']
            }})
        # add followup
        remark = 'Policy renewed!\n' + str.strip(remark)
        models.Policy_health(policy_id).post_policy_followup(remark, 'renewed')
    return dumps(result)
Exemplo n.º 4
0
def admin_contacts_page():
    if not session.get('logged_in'):
        return login_page()
    recent_added = models.Person().get().limit(10).sort('_id', -1)
    active_page['contacts'] = 'active'
    return render_template('admin/contacts.html',
                           recent_added=recent_added,
                           functions=functions)
Exemplo n.º 5
0
def view_person_page(_id):
    if not session.get('logged_in'):
        return login_page()
    person_id = ObjectId(_id)
    person = models.Person(person_id)
    person.get_registration_list()
    for registration in person.registration_list:
        registration.get_motor_policy_list()
    person.get_health_policy_list()
    return render_template('admin/view_person.html',
                           person=person,
                           functions=functions)
Exemplo n.º 6
0
def add_health_policy_api():
    if not session.get('logged_in'):
        return json.dumps({'result': False, 'msg': 'Login required.'})
    person_id = ObjectId(request.form.get('person_id'))
    expiry_date = request.form.get('expiry_date')
    policy_owner = request.form.get('policy_owner')
    policy_number = request.form.get('policy_number')
    policy_type = request.form.get('policy_type')
    company = request.form.get('company')
    idv = request.form.get('idv')
    ncb = request.form.get('ncb')
    premium = request.form.get('premium')
    own_business = True if 'own_business' in request.form else False
    return dumps(
        models.Person(person_id).add_health_policy(expiry_date, policy_owner,
                                                   policy_number, policy_type,
                                                   company, idv, ncb, premium,
                                                   own_business))
Exemplo n.º 7
0
def delete_person_api():
    if not session.get('logged_in'):
        return json.dumps({'result': False, 'msg': 'Login required.'})
    person_id = ObjectId(request.form.get('person_id'))
    return dumps(models.Person(person_id).delete_person())
Exemplo n.º 8
0
def remove_email_api():
    if not session.get('logged_in'):
        return json.dumps({'result': False, 'msg': 'Login required.'})
    person_id = ObjectId(request.form.get('_id'))
    email = request.form.get('email')
    return dumps(models.Person(person_id).remove_contact_email(email))
Exemplo n.º 9
0
def remove_contact_number_api():
    if not session.get('logged_in'):
        return json.dumps({'result': False, 'msg': 'Login required.'})
    person_id = ObjectId(request.form.get('_id'))
    number = request.form.get('number')
    return dumps(models.Person(person_id).remove_contact_number(number))
Exemplo n.º 10
0
def update_contact_dob_api():
    if not session.get('logged_in'):
        return json.dumps({'result': False, 'msg': 'Login required.'})
    person_id = ObjectId(request.form.get('_id'))
    dob = request.form.get('dob')
    return dumps(models.Person(person_id).update_dob(dob))