Esempio n. 1
0
    def onboard_client(self, role, user_id, user_details):
        # Use user's role to determine where the details will be stored
        if role == "IA":
            # If it's an independent agency
            new_independent_agency = IndependentAgent(
                user_details["org_name"], user_details["org_phone"],
                user_details["org_email"], user_id)
            new_independent_agency.save()

        elif role == "IC":
            # if it's an insurance company
            new_insurance_company = InsuranceCompany(
                user_id, user_details['company_id'], user_details['org_phone'])
            new_insurance_company.save()

        elif role == "TA":
            # If it's a tied agent
            # You only need a user_id to create a Tied agent object.
            new_tied_agent = TiedAgents(user_id)
            new_tied_agent.save()

        elif role == "BR":
            # if it's a broker
            new_broker = Broker(user_details["org_name"],
                                user_details["org_phone"],
                                user_details["org_email"], user_id)
            new_broker.save()
        else:
            return
Esempio n. 2
0
    def post(self):
        details = policy_parser.parse_args()
        # get the current agency details
        uid = get_jwt_identity()
        # use the uid to get company through the company contact_id
        company = InsuranceCompany.get_company_by_contact_person(uid)
        """
        First add the extension to the extensions table, regardless of insurance company
        """
        exisiting_extensions = Extension.get_all_extensions()
        names = [extension['name'] for extension in exisiting_extensions]
        extension_name = details['name']

        # check whether the benefits to be added already exist
        if extension_name not in names:
            new_extension = Extension(extension_name)
            new_extension.save()
        """
        Store benefits offered by a particular company together with limit
        """
        # get the extension_id
        extension = Extension.get_extension_id_by_name(extension_name)

        company_extension = ICExtensions(company.id, extension.id,
                                         details['free_limit'],
                                         details['max_limit'], details['rate'])
        company_extension.save()
        """
        Send success response
        """
        response_msg = helper.make_rest_success_response(
            "Extension added successfully")
        return make_response(response_msg, 200)
Esempio n. 3
0
    def post(self):
        # benefits handler
        details = policy_parser.parse_args()
        # get the current agency details
        uid = get_jwt_identity()
        # use the uid to get company through the company contact_id
        company = InsuranceCompany.get_company_by_contact_person(uid)
        # First add the benefit to the benefits table, regardless of insurance company
        exisiting_benefits = Benefit.get_all_benefits()
        names = [benefit['name'] for benefit in exisiting_benefits]
        benefit_name = details['name']

        # check whether the benefits to be added already exist
        if benefit_name not in names:
            new_benefit = Benefit(benefit_name)
            new_benefit.save()

        # Store benefits offered by a particular company together with limit
        # get the benefit_id
        benefit = Benefit.get_benefit_by_name(benefit_name)

        company_benefit = ICBenefits(company.id, benefit.id,
                                     details['free_limit'],
                                     details['max_limit'], details['rate'])
        company_benefit.save()

        # Send success response
        response_msg = helper.make_rest_success_response(
            "Benefit added successfully")
        return make_response(response_msg, 200)
Esempio n. 4
0
    def post(self):
        details = policy_parser.parse_args()
        # get the current agency details
        uid = get_jwt_identity()
        # use the uid to get company through the company contact_id
        company = InsuranceCompany.get_company_by_contact_person(uid)
        """
        First add the loading to the loadingss table, regardless of insurance company
        """
        existing_loadings = Loadings.get_all_loadings()
        names = [loading['name'] for loading in existing_loadings]
        loading_name = details['name']

        # check whether the benefits to be added already exist
        if loading_name not in names:
            new_loading = Loadings(loading_name)
            new_loading.save()
        """
        Store loadings offered by a particular company together with limit
        """
        # get the loading_id
        loading_id = Loadings.get_loading_id_by_name(loading_name)
        company_loading = ICLoadings(company.id, loading_id, details['rate'])
        company_loading.save()
        """
        Send success response
        """
        response_msg = helper.make_rest_success_response(
            "Loading added successfully")
        return make_response(response_msg, 200)
Esempio n. 5
0
 def create_master_policy(policy_number, customer_number, date_expiry,
                          insurance_company):
     # Get insurance company given the company details
     new_company = InsuranceCompany.get_by_associated_company(
         insurance_company)
     # create new master policy
     master = MasterPolicy(policy_number, customer_number, date_expiry,
                           new_company.id)
     master.save()
     return master
Esempio n. 6
0
    def get(self, company_id):
        # get the company linked to the associated company
        company = InsuranceCompany.get_by_associated_company(company_id)
        # get the benefits, loadings and extensions

        benefits = ICBenefits.get_benefits_by_company_id(company.id)
        loadings = ICLoadings.get_loadings_by_company_id(company.id)
        extensions = ICExtensions.get_extensions_by_company_id(company.id)
        data = {
            "benefits": benefits,
            "loadings": loadings,
            "extensions": extensions,
            "discount": company.ncd_rate,
            "rate": company.rate
        }
        response_msg = helper.make_rest_success_response("Success", data)
        return make_response(response_msg, 200)
Esempio n. 7
0
    def fetch_profile_data(self, role, user_id):
        profile_data = {}
        if role in ('IND', 'TA'):
            profile_data = User.get_user_by_id(user_id).serialize()
        elif role == 'BR':
            profile_data = Broker.get_broker_by_contact_id(user_id).serialize()
        elif role == 'IA':
            profile_data = IndependentAgent.get_agency_by_contact_person(
                user_id).serialize()
        elif role == 'IC':
            profile_data = InsuranceCompany.get_company_by_contact_person(
                user_id).serialize()
        elif role == 'ORG':
            profile_data = OrganizationCustomer.get_customer_by_contact(
                user_id).serialize()
        else:
            return

        return profile_data
Esempio n. 8
0
    def get_agency_id(role, uid):
        """
        Fetch the agent id depending the active user's role. Could be an independent agency, brokerage or tied agent
        """
        if role == "BR":
            # get brokerage by contact person
            broker = Broker.get_broker_by_contact_id(uid)
            return broker.broker_id

        elif role == "IC":
            insurance = InsuranceCompany.get_company_by_contact_person(uid)
            return insurance

        elif role == "TA":
            # get tied agency
            tied_agent = TiedAgents.get_tied_agent_by_user_id(uid)
            return tied_agent.id

        elif role == "IA":
            # get Independent agency by contact person
            ind_agent = IndependentAgent.get_agency_by_contact_person(uid)
            return ind_agent.id