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)
def update_health_policy(): if not session.get('logged_in'): return json.dumps({'result': False, 'msg': 'Login required.'}) policy_id = ObjectId(request.form.get('policy_id')) policy = models.Policy_health(policy_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') claim_status = request.form.get('claim_status') own_business = True if 'own_business' in request.form else False result = policy.update_health_policy(expiry_date, policy_owner, policy_number, policy_type, company, idv, ncb, premium, own_business, claim_status=claim_status) return dumps(result)
def get_health_renewal_list(): if not session.get('logged_in'): return json.dumps({'result': False, 'msg': 'Login required.'}) result = {'result': False} month = request.form.get('month') year = request.form.get('year') result['data'] = models.Policy_health().get_renewal_list(month, year) result['result'] = True print(result) return dumps(result)
def view_health_policy_api(policy_id): if not session.get('logged_in'): return json.dumps({'result': False, 'msg': 'Login required.'}) result = {'result': False} policy_id = ObjectId(policy_id) policy = models.Policy_health(policy_id) if policy.db_data != None: result['result'] = True result['data'] = policy.db_data return dumps(result)
def admin_index_page(): if 'logged_in' in session: if session['logged_in'] == True: user_id = ObjectId(session['user']['_id']) if session['user']['type'] == 'admin': today = datetime.today() day = today.day month = today.month year = today.year motor_renewal_list = models.Policy_motor().get_renewal_list( month, year) policy_list_expiry_today = [] for policy in motor_renewal_list: if policy['day'] == day: policy['type'] = 'motor' policy_list_expiry_today.append(policy) motor_renewal_count = { 'total': 0, 'not_touch': 0, 'followup': 0, 'won': 0, 'lost': 0 } for policy in motor_renewal_list: motor_renewal_count['total'] += 1 if 'policy_status' in policy: motor_renewal_count[policy['policy_status']] += 1 else: motor_renewal_count['not_touch'] += 1 health_renewal_list = models.Policy_health().get_renewal_list( month, year) for policy in health_renewal_list: if policy['day'] == day: policy['type'] = 'health' policy_list_expiry_today.append(policy) health_renewal_count = { 'total': 0, 'not_touch': 0, 'followup': 0, 'won': 0, 'lost': 0 } for policy in health_renewal_list: health_renewal_count['total'] += 1 if 'policy_status' in policy: health_renewal_count[policy['policy_status']] += 1 else: health_renewal_count['not_touch'] += 1 return render_template( 'admin/index.html', motor_renewal_count=motor_renewal_count, health_renewal_count=health_renewal_count, policy_list_expiry_today=policy_list_expiry_today) return render_template('login.html')
def api_update_claim_status(): result = {'result': False, 'msg': 'Something went wrong.'} policy_type = request.form.get('policy_type') _id = ObjectId(request.form.get('_id')) claim_status = request.form.get('claim_status') if policy_type == 'motor': result = models.Policy_motor(_id).update_motor_policy( claim_status=claim_status) elif policy_type == 'health': result = models.Policy_health(_id).update_health_policy( claim_status=claim_status) return dumps(result)
def post_policy_followup(): if not session.get('logged_in'): return json.dumps({'result': False, 'msg': 'Login required.'}) policy_id = ObjectId(request.form.get('policy_id')) remark = request.form.get('remark') type = request.form.get('type') if str.strip(remark) == '': return dumps({'result': False, 'msg': 'Remark cannot be empty.'}) policy = None if type == 'motor': policy = models.Policy_motor(policy_id) elif type == 'health': policy = models.Policy_health(policy_id) return dumps(policy.post_policy_followup(remark))
def get_followup_list_api(): 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')) type = request.form.get('type') policy = None if type == 'motor': policy = models.Policy_motor(policy_id) elif type == 'health': policy = models.Policy_health(policy_id) result['followup_list'] = [] for followup in policy.get_followup_list(): result['followup_list'].append(followup) result['result'] = True return dumps(result)
def view_health_renewal(_id): if not session.get('logged_in'): return json.dumps({'result': False, 'msg': 'Login required.'}) result = {} result['result'] = False policy = models.Policy_health(ObjectId(_id)) if policy.person == None: result['msg'] = 'Person ID not found.' return result data = {} data['policy'] = policy.db_data data['person'] = policy.person.db_data data['renewal_policy'] = policy.renewal_policy.db_data data['old_policy'] = policy.old_policy data['followup_list'] = policy.get_followup_list() result['data'] = data result['result'] = True return dumps(result)
def delete_health_policy_api(): if not session.get('logged_in'): return json.dumps({'result': False, 'msg': 'Login required.'}) policy_id = ObjectId(request.form['policy_id']) return dumps(models.Policy_health(policy_id).delete_policy())