def bse_investor_info_generator(user_id):
    """
    
    :param user_id: id of user for whom the bse investor info is to be generated
    :return: 
    """
    user = models.User.objects.get(id=user_id)
    investor = models.InvestorInfo.objects.get(user=user)
    nominee = models.NomineeInfo.objects.get(user=user)
    contact = models.ContactInfo.objects.get(user=user)
    investor_bank = models.InvestorBankDetails.objects.get(user=user)
    curr_date = datetime.now()

    nominee_address = nominee.nominee_address
    if nominee.nominee_address == None:
        blank_pincode = Pincode(None, None, None)
        blank_address = models.Address(None, None, None, None)
        blank_address.pincode = blank_pincode
        nominee.nominee_address = blank_address

    investor_dict = {
        "ACNo":
        investor_bank.account_number,
        "AcType":
        investor_bank.account_type,
        "BankAddress":
        investor_bank.ifsc_code.address,
        "BankCity":
        investor_bank.ifsc_code.city,
        "BankCountry":
        constants.INDIA,
        "BankPincode":
        None,
        "BankState":
        investor_bank.ifsc_code.state,
        "Branch":
        investor_bank.ifsc_code.bank_branch,
        "BrokerAgentCodeARN":
        "108537",
        "City":
        contact.communication_address.pincode.city,
        "ContactAddress":
        contact.communication_address.address_line_1,
        "Country":
        constants.INDIA,
        "CountryofTaxResidence":
        constants.INDIA,
        "CountryofTaxResidence_2":
        None,
        "CountryofTaxResidence_3":
        None,
        "DateofBirth":
        investor.dob.strftime('%d-%m-%Y'),
        "DateofBirth_2":
        None,
        "DateofBirth_3":
        None,
        "EUIN":
        "E148376",
        "Email":
        contact.email,
        "FatherName":
        investor.father_name,
        "FaxOff":
        None,
        "FaxRes":
        None,
        "GuardianNameIfNomineeMinor":
        nominee.guardian_name if nominee else None,
        "GuardianPAN":
        None,
        "IFSCCode":
        investor_bank.ifsc_code.ifsc_code,
        "IncomeTaxSlabNetworth":
        None,  # TODO
        "IncomeTaxSlabNetworth_2":
        None,
        "IncomeTaxSlabNetworth_3":
        None,
        "KYC":
        investor.kra_verified,
        "KYC_2":
        None,
        "KYC_3":
        None,
        "Mobile":
        contact.phone_number,
        "ModeofHolding":
        None,  # TODO
        "MotherName":
        None,  # TODO
        "NameofThirdApplicant":
        None,
        "NameFirstApplicant":
        investor.applicant_name,
        "NameGuardian":
        nominee.guardian_name if nominee else None,
        "NameofBank":
        investor_bank.ifsc_code.name,
        "NameofSecondApplicant":
        None,
        "NomineeAddress":
        nominee.nominee_address.address_line_1,
        "NomineeCity":
        nominee.nominee_address.pincode.city,
        "NomineeName":
        nominee.nominee_name if nominee else None,
        "NomineePincode":
        nominee.nominee_address.pincode.pincode,
        "NomineeRelationship":
        nominee.get_relationship_with_investor_display() if nominee else None,
        "NomineeState":
        nominee.nominee_address.pincode.state,
        "Occupation":
        investor.get_occupation_type_display()
        if investor.occupation_type != "OTH" else investor.occupation_specific,
        "OccupationDetails":
        None,
        "OccupationDetails_2":
        None,
        "OccupationDetails_3":
        None,
        "OverseasAddress":
        None,
        "OverseasCity":
        None,
        "OverseasCountry":
        None,
        "OverseasPincode":
        None,
        "PANNumber":
        investor.pan_number,
        "PANNumber_2":
        None,
        "PANNumber_3":
        None,
        "Pincode":
        contact.communication_address.pincode.pincode,
        "PlaceofBirth":
        None,
        "PlaceofBirth_2":
        None,
        "PlaceofBirth_3":
        None,
        "PoliticallyExposedNo":
        False if investor.political_exposure == 2 else True,
        "PoliticallyExposedNo_2":
        None,
        "PoliticallyExposedNo_3":
        None,
        "PoliticallyExposedYes":
        True if investor.political_exposure == 2 else False,
        "PoliticallyExposedYes_2":
        None,
        "PoliticallyExposedYes_3":
        None,
        "SUBBROKER":
        None,
        "SignatureDate":
        curr_date.strftime('%d-%m-%Y'),
        "SignaturePlace":
        contact.communication_address.pincode.city,
        "State":
        contact.communication_address.pincode.state,
        "TaxIdNo":
        None,  # TODO
        "TaxIdNo_2":
        None,
        "TaxIdNo_3":
        None,
        "TelOff":
        None,
        "TelRes":
        None
    }

    for key, value in investor_dict.items():
        if value is None:
            investor_dict[key] = ""
        if value is True:
            investor_dict[key] = "Yes"
        if value is False:
            investor_dict[key] = "Off"

    for key, value in investor_dict.items():
        if value not in ("", "Yes", "Off"):
            if type(value) == str:
                if "@" in value:
                    continue
            investor_dict[key] = str(value).upper()

    timestamp = time.strftime("%Y%m%d-%H%M%S")

    temp_file_name = "temp" + timestamp + ".fdf"
    out_file_name = "out" + timestamp + ".pdf"

    fields = [(key, value) for key, value in investor_dict.items()]
    fdf = forge_fdf("", fields, [], [], [])
    fdf_file = open(temp_file_name, "wb")
    fdf_file.write(fdf)
    fdf_file.close()

    base_dir = os.path.dirname(os.path.dirname(__file__)).replace(
        '/webapp/apps/external_api', '')
    bse_investor_pdf_path = base_dir + '/bse_docs/'
    output_path = base_dir + '/webapp/static/'
    aof_file_name = bse_investor_pdf_path + "aof.pdf"

    call(("pdftk " + aof_file_name + " fill_form %s output " % temp_file_name +
          output_path + "%s flatten" % out_file_name).split())
    # remove the temporary generated fdf file.
    call(("rm " + temp_file_name).split())

    if settings.USING_S3:
        prefix = ""  # prefix is needed to access the images from media directory.
    else:
        prefix = settings.SITE_BASE_URL  # prefix is needed to access the images from media directory.

    # the list of images to be embedded into the pdf follows
    user_signature = prefix + user.signature.url if user.signature != "" else constants.DEFAULT_IMAGE  # signature_image location.
    list_of_embeddable_images = [
        user_signature,
    ]

    # list of individual image type/size (passport/signature) they are based on international standards.
    image_sizes = [
        constants.TIFF_SIGNATURE_SIZE,
    ]

    aof_destination_file_name = "aof_destination" + timestamp + ".pdf"

    dest = output_path + aof_destination_file_name  # the final pdf with all images in place.
    exist = output_path + out_file_name  # the source pdf without the images.
    coords = [
        (125, 24),
    ]  # the lower left bottom corner
    #  co-ordinates for each of the images.

    target_pages = (
        0,
    )  # pages of the existing/source pdf into which the images from the images list must be
    #  embedded onto

    images_count_each_page = [
        1,
    ]  # number of images on each of the target pages.

    # following makes a call to the embed images function in the utils
    embed_images(list_of_embeddable_images, image_sizes, coords, target_pages,
                 images_count_each_page, dest, exist)
    # following generates the tiff file.

    final_tiff_file_name = generate_tiff(
        output_path + aof_destination_file_name,
        investor_bank.bank_cheque_image)
    return output_path + final_tiff_file_name
Exemple #2
0
def generate_kyc_pdf(user_id):
    """

    :param user_id: id of user for whom the kyc info is to be generated.
    :return: url of the generated kyc pdf
    """
    user = models.User.objects.get(id=user_id)
    investor = models.InvestorInfo.objects.get(user=user)
    nominee = models.NomineeInfo.objects.get(user=user)
    contact = models.ContactInfo.objects.get(user=user)
    investor_bank = models.InvestorBankDetails.objects.get(user=user)
    curr_date = datetime.now()

    if nominee.nominee_address is None:
        blank_pincode = Pincode(None, None, None)
        blank_address = models.Address(None, None, None, None)
        blank_address.pincode = blank_pincode
        nominee.nominee_address = blank_address

    base_dir = os.path.dirname(os.path.dirname(__file__)).replace(
        '/webapp/apps', '')
    pdf_path = base_dir + '/bse_docs/'
    output_path = base_dir + '/webapp/static/'
    kyc_pdf_name = pdf_path + "kyc.pdf"

    timestamp = time.strftime("%Y%m%d-%H%M%S")

    kyc_fdf = kyc_fdf_generator(user, investor, nominee, contact,
                                investor_bank, curr_date)

    if len(kyc_fdf) != 0:
        fdf = forge_fdf("", kyc_fdf, [], [], [])
        kyc_temp_file_name = "kyc_temp" + timestamp + ".fdf"
        kyc_middle_file_name = "kyc_middle" + timestamp + ".pdf"
        fdf_file = open(kyc_temp_file_name, "wb")
        fdf_file.write(fdf)
        fdf_file.close()
        create_kyc = "pdftk " + kyc_pdf_name + " fill_form %s output " % kyc_temp_file_name + output_path + \
                     "%s flatten" % kyc_middle_file_name
        call(create_kyc.split())

        call((("rm %s") % kyc_temp_file_name).split())

    prefix = ""  # prefix is needed to access the images from media directory.
    # the list of images to be embedded into the pdf follows
    list_of_embeddable_images = []

    # list of individual image type/size (passport/signature) they are based on international standards.
    image_sizes = []

    coords = []  # the lower left bottom corner
    #  co-ordinates for each of the images.

    target_pages = [
    ]  # pages of the existing/source pdf into which the images from the images list must be
    #  embedded onto

    images_count_each_page = [
    ]  # number of images on each of the target pages.

    user_identity = prefix + user.identity_info_image.url if user.identity_info_image != "" else constants.DEFAULT_IMAGE  # identity_info image location.
    user_signature = prefix + user.signature.url if user.signature != "" else constants.DEFAULT_IMAGE  # signature_image location.
    list_of_embeddable_images.extend([user_identity, user_signature])
    image_sizes.extend([constants.PASSPORT_SIZE, constants.SIGNATURE_SIZE])
    coords.extend([(470.14, 620.3), (410.17, 90.03)])
    target_pages.extend((0, 0))
    images_count_each_page.extend([2])

    # file initializations.
    kyc_middle_file_name = "kyc_middle" + timestamp + ".pdf"
    exist = output_path + kyc_middle_file_name  # the source pdf without the images.
    kyc_destination_file_name = "kyc_destination" + timestamp + ".pdf"
    output_file = output_path + kyc_destination_file_name  # final_output of the completed kyc_pdf.

    if kyc_pdf_name.endswith("kyc.pdf"):
        # additional pan card and address_proof embeds.
        if investor.pan_image:
            list_of_embeddable_images.append(prefix + investor.pan_image.url)
            image_sizes.append(constants.FIT_SIZE)
            coords.append((100, 270))
            target_pages.append(2)
            images_count_each_page.append(1)

        if contact.front_image:
            list_of_embeddable_images.append(prefix + contact.front_image.url)
            image_sizes.append(constants.FIT_SIZE)
            coords.append((100, 400))
            target_pages.append(3)

        if contact.back_image:
            list_of_embeddable_images.append(prefix + contact.back_image.url)
            image_sizes.append(constants.FIT_SIZE)
            coords.append((100, 50))
            target_pages.append(3)

        if contact.front_image and contact.back_image:
            images_count_each_page.append(2)
        else:
            images_count_each_page.append(1)

        # finally_embed the images.
        embed_images(list_of_embeddable_images, image_sizes, coords,
                     target_pages, images_count_each_page, output_file, exist)

    else:
        # if not embed mode,  then attach pan and contact images at the end.
        attachable_images = []
        investor_image = prefix + investor.pan_image.url if investor.pan_image != "" else None
        contact_front = prefix + contact.front_image.url if contact.front_image != "" else None
        contact_back = prefix + contact.back_image.url if contact.back_image != "" else None
        attachable_images.extend((investor_image, contact_front, contact_back))
        # finally append the images to the end of the generated pdf.
        attach_images(attachable_images, exist, output_file)

    return output_file
def createcustomerrequest(root, user_id):
    """

    :param user_id: id of user for whom the nse_request is to be generated
    :return:
    """
    user = models.User.objects.get(id=user_id)
    investor = models.InvestorInfo.objects.get(user=user)
    nominee = models.NomineeInfo.objects.get(user=user)
    nominee_present = True if nominee and nominee.nominee_absent == False else False
    contact = models.ContactInfo.objects.get(user=user)
    investor_bank = models.InvestorBankDetails.objects.get(user=user)
    curr_date = datetime.now()

    nominee_address = nominee.nominee_address
    if nominee.nominee_address == None:
        blank_pincode = Pincode(None, None, None)
        blank_address = models.Address(None, None, None, None)
        blank_address.pincode = blank_pincode
        nominee.nominee_address = blank_address

    investor_dict = {
        constants.TITLE_XPATH:
        None,
        constants.INV_NAME_XPATH:
        investor.applicant_name,
        constants.PAN_XPATH:
        investor.pan_number,
        constants.VALID_PAN_XPATH:
        'Y',
        constants.EXEMPTION_XPATH:
        'N',
        constants.EXEMPT_CATEGORY_XPATH:
        None,  # TODO
        constants.EXEMPT_REF_NO_XPATH:
        None,  # TODO
        constants.DOB_XPATH:
        changeDobFormat(investor.dob),
        constants.HOLD_NATURE_XPATH:
        api_constants.CLIENT_HOLDING_MAP["Single"],
        constants.TAX_STATUS_XPATH:
        api_constants.CLIENT_TAX_STATUS_MAP["Individual"],
        constants.KYC_XPATH:
        investor.kra_verified,
        constants.OCCUPATION_XPATH:
        get_occupation_code(investor.occupation_type),
        # TODO : Refer master services for 2 letter occupation code
        constants.MFU_CAN_XPATH:
        None,  # TODO
        constants.DP_ID_XPATH:
        None,  # TODO
        constants.FATHER_NAME_XPATH:
        investor.father_name,
        constants.MOTHER_NAME_XPATH:
        None,  # TODO
        constants.TRXN_ACCEPTANCE_XPATH:
        "ALL",
        constants.ADDR1_XPATH:
        contact.communication_address.address_line_1,
        constants.ADDR2_XPATH:
        contact.communication_address.address_line_2,
        constants.ADDR3_XPATH:
        contact.communication_address.nearest_landmark,
        constants.CITY_XPATH:
        contact.communication_address.pincode.city,
        constants.STATE_XPATH:
        get_state_code(contact.communication_address.pincode.state),
        constants.PINCODE_XPATH:
        contact.communication_address.pincode.pincode,
        constants.COUNTRY_XPATH:
        get_country_code(api_constants.INDIA),
        constants.MOBILE_XPATH:
        contact.phone_number,
        constants.RES_PHONE_XPATH:
        None,
        constants.OFF_PHONE_XPATH:
        None,
        constants.OFF_FAX_XPATH:
        None,
        constants.RES_FAX_XPATH:
        None,
        constants.EMAIL_XPATH:
        contact.email,
        constants.NRI_ADDR1_XPATH:
        None,
        constants.NRI_ADDR2_XPATH:
        None,
        constants.NRI_ADDR3_XPATH:
        None,
        constants.NRI_CITY_XPATH:
        None,
        constants.NRI_STATE_XPATH:
        None,
        constants.NRI_PINCODE_XPATH:
        None,
        constants.NRI_COUNTRY_XPATH:
        None,
        constants.BANK_NAME_XPATH:
        bankcodes.bank_code_map.get(investor_bank.ifsc_code.name, None),
        constants.ACC_NO_XPATH:
        investor_bank.account_number,
        constants.ACC_TYPE_XPATH:
        'SB',  #TODO: investor_bank.account_type
        constants.IFSC_CODE_XPATH:
        investor_bank.ifsc_code.ifsc_code,
        constants.BRANCH_NAME_XPATH:
        investor_bank.ifsc_code.bank_branch,
        constants.BRANCH_ADDR1_XPATH:
        investor_bank.ifsc_code.address,
        constants.BRANCH_ADDR2_XPATH:
        None,
        constants.BRANCH_ADDR3_XPATH:
        None,
        constants.BRANCH_CITY_XPATH:
        investor_bank.ifsc_code.city,
        constants.BRANCH_PINCODE_XPATH:
        None,  # TODO
        constants.BRANCH_COUNTRY_XPATH:
        get_country_code(api_constants.INDIA),
        constants.JH1_NAME_XPATH:
        None,
        constants.JH1_PAN_XPATH:
        None,
        constants.JH1_VALID_PAN_XPATH:
        None,
        constants.JH1_EXEMPTION_XPATH:
        None,
        constants.JH1_EXEMPT_CATEGORY_XPATH:
        None,
        constants.JH1_EXEMPT_REF_NO_XPATH:
        None,
        constants.JH1_DOB_XPATH:
        None,
        constants.JH1_KYC_XPATH:
        None,
        constants.JH2_NAME_XPATH:
        None,
        constants.JH2_PAN_XPATH:
        None,
        constants.JH2_VALID_PAN_XPATH:
        None,
        constants.JH2_EXEMPTION_XPATH:
        None,
        constants.JH2_EXEMPT_CATEGORY_XPATH:
        None,
        constants.JH2_EXEMPT_REF_NO_XPATH:
        None,
        constants.JH2_DOB_XPATH:
        None,
        constants.JH2_KYC_XPATH:
        None,
        constants.NO_OF_NOMINEE_XPATH:
        '1' if nominee_present else '0',
        constants.NOMINEE1_TYPE_XPATH:
        'Y' if nominee_present and nominee.guardian_name else
        'N' if nominee_present else None,
        constants.NOMINEE1_NAME_XPATH:
        nominee.nominee_name if nominee_present else None,
        constants.NOMINEE1_DOB_XPATH:
        changeDobFormat(nominee.nominee_dob) if nominee_present else None,
        constants.NOMINEE1_ADDR1_XPATH:
        nominee.nominee_address.address_line_1 if nominee_present else None,
        constants.NOMINEE1_ADDR2_XPATH:
        nominee.nominee_address.address_line_2 if nominee_present else None,
        constants.NOMINEE1_ADDR3_XPATH:
        nominee.nominee_address.nearest_landmark if nominee_present else None,
        constants.NOMINEE1_CITY_XPATH:
        nominee.nominee_address.pincode.city if nominee_present else None,
        constants.NOMINEE1_STATE_XPATH:
        get_state_code(nominee.nominee_address.pincode.state)
        if nominee_present else None,
        constants.NOMINEE1_PINCODE_XPATH:
        nominee.nominee_address.pincode.pincode if nominee_present else None,
        constants.NOMINEE1_RELATION_XPATH:
        nominee.get_relationship_with_investor_display()
        if nominee_present else None,
        constants.NOMINEE1_PERCENT_XPATH:
        '100' if nominee_present else None,
        constants.NOMINEE1_GUARD_NAME_XPATH:
        nominee.guardian_name if nominee_present else None,
        constants.NOMINEE1_GUARD_PAN_XPATH:
        None,
        constants.NOMINEE2_TYPE_XPATH:
        None,
        constants.NOMINEE2_NAME_XPATH:
        None,
        constants.NOMINEE2_DOB_XPATH:
        None,
        constants.NOMINEE2_RELATION_XPATH:
        None,
        constants.NOMINEE2_PERCENT_XPATH:
        None,
        constants.NOMINEE2_GUARD_NAME_XPATH:
        None,
        constants.NOMINEE2_GUARD_PAN_XPATH:
        None,
        constants.NOMINEE3_TYPE_XPATH:
        None,
        constants.NOMINEE3_NAME_XPATH:
        None,
        constants.NOMINEE3_DOB_XPATH:
        None,
        constants.NOMINEE3_RELATION_XPATH:
        None,
        constants.NOMINEE3_PERCENT_XPATH:
        None,
        constants.NOMINEE3_GUARD_NAME_XPATH:
        None,
        constants.NOMINEE3_GUARD_PAN_XPATH:
        None,
        constants.GUARD_NAME_XPATH:
        None,
        constants.GUARD_PAN_XPATH:
        None,
        constants.GUARD_VALID_PAN_XPATH:
        None,
        constants.GUARD_EXEMPTION_XPATH:
        None,
        constants.GUARD_EXEMPT_CATEGORY_XPATH:
        None,
        constants.GUARD_PAN_REF_NO_XPATH:
        None,
        constants.GUARD_DOB_XPATH:
        None
    }

    return getValidRequest(investor_dict, root)
def investor_info_generator(user_id):
    """
    :param user_id: the id of user for which we need to generate investor form
    :return:
    """
    user = models.User.objects.get(id=user_id)
    investor = models.InvestorInfo.objects.get(user=user)
    nominee = models.NomineeInfo.objects.get(user=user)
    contact = models.ContactInfo.objects.get(user=user)
    investor_bank = models.InvestorBankDetails.objects.get(user=user)
    curr_date = datetime.now()
    bank_mandate_helper_instance = bank_mandate_helper.BankMandateHelper()
    bank_mandate = bank_mandate_helper_instance.get_current_mandate(user)
    user_vendor = models.UserVendor.objects.get(
        user=user, vendor__name=bank_mandate.vendor.name)

    if nominee.nominee_address == None:
        blank_pincode = Pincode(None, None, None)
        blank_address = models.Address(None, None, None, None)
        blank_address.pincode = blank_pincode
        nominee.nominee_address = blank_address

    investor_dict = {
        # 'MandateDebitTypeMaxAmount': True,
        # 'MandateFreqAsWhenPresented': True,
        # 'MandateUntilCancelled': True,  # TODO: verify with rashmi
        'DebitSB':
        True,  # TODO: Check with rashmi
        'AccountNumber':
        bank_mandate.mandate_bank_details.account_number,
        'AccountType':
        investor_bank.get_account_type_display(),
        'ApplicantName':
        investor.applicant_name,
        'BankName':
        investor_bank.ifsc_code.name,
        'BranchName':
        investor_bank.ifsc_code.bank_branch,
        'CorrespondenceAddress1':
        contact.communication_address.address_line_1,
        'CorrespondenceAddress2':
        contact.communication_address.address_line_2,
        'CorrespondenceAddressCity':
        contact.communication_address.pincode.city,
        'CorrespondenceAddressState':
        contact.communication_address.pincode.state,
        'CorrespondenceAddressCountry':
        user.nationality,
        'CorrespondenceAddressPincode':
        contact.communication_address.pincode.pincode,
        'PermanentAddressSameAsCorrespondenceAddress':
        True if contact.address_are_equal else False,
        'PermanentAddress1':
        contact.permanent_address.address_line_1
        if not contact.address_are_equal else None,
        'PermanentAddress2':
        contact.permanent_address.address_line_2
        if not contact.address_are_equal else None,
        'PermanentAddressCity':
        contact.permanent_address.pincode.city
        if not contact.address_are_equal else None,
        'PermanentAddressState':
        contact.permanent_address.pincode.state
        if not contact.address_are_equal else None,
        'PermanentAddressPincode':
        contact.permanent_address.pincode.pincode
        if not contact.address_are_equal else None,
        'PermanentAddressCountry':
        user.nationality if not contact.address_are_equal else None,
        'DateofBirth':
        investor.dob.strftime("%d/%m/%Y"),
        'EmailID':
        investor.user.email,
        'FinaskusInvestorID':
        user.finaskus_id,
        'GrossAnnualIncome':
        investor.get_income_display(),
        'IFSCCode':
        investor_bank.ifsc_code.ifsc_code,
        'InvestorsRelationwithNominee':
        nominee.get_relationship_with_investor_display() if nominee else None,
        'MandateAccountHolderName':
        investor_bank.account_holder_name,
        'MandateAmountNumber':
        bank_mandate.mandate_amount,
        'MandateAmountWords':
        str(num2words(bank_mandate.mandate_amount, lang="en_IN")) + " ONLY",
        'MandateBank':
        bank_mandate.mandate_bank_details.ifsc_code.name,
        'MandateBankACNumber':
        bank_mandate.mandate_bank_details.account_number,
        'MandateCreate':
        True,
        'MandateDate-dd':
        bank_mandate.created_at.strftime("%d"),
        'MandateDate-mm':
        bank_mandate.created_at.strftime("%m"),
        'MandateDate-yyyy':
        bank_mandate.created_at.strftime("%Y"),
        'MandateEmailID':
        contact.email,
        'MandateIFSC':
        investor_bank.ifsc_code.ifsc_code,
        'MandatePeriodFrom-dd':
        bank_mandate.mandate_start_date.strftime("%d"),
        'MandatePeriodFrom-mm':
        bank_mandate.mandate_start_date.strftime("%m"),
        'MandatePeriodFrom-yyyy':
        bank_mandate.mandate_start_date.strftime("%Y"),
        'MandatePhoneNo':
        contact.phone_number,
        'MandateReferenceNo':
        bank_mandate.mandate_reg_no,
        'MandateUCC':
        user_vendor.ucc,
        'Mobile':
        contact.phone_number,
        'NameofGuardian':
        nominee.guardian_name if nominee else None,
        'NominationNotRequired':
        nominee.nominee_absent,
        'NomineeAddressSameAsInvestorAddress':
        True if nominee and nominee.address_are_equal else False,
        'NomineeAddress1':
        nominee.nominee_address.address_line_1,
        'NomineeAddress2':
        nominee.nominee_address.address_line_2,
        'NomineeAddressCity':
        nominee.nominee_address.pincode.city,
        'NomineeAddressCountry':
        user.nationality,
        'NomineeAddressPinCode':
        nominee.nominee_address.pincode,
        'NomineeAddressState':
        nominee.nominee_address.pincode.state,
        'NomineeName':
        nominee.nominee_name if nominee else None,
        'Occupation':
        investor.get_occupation_type_display()
        if investor.occupation_type != "OTH" else investor.occupation_specific,
        'OnlineApplicationDate':
        curr_date.strftime("%d/%m/%Y"),
        'PAN':
        investor.pan_number,
        'Place':
        contact.communication_address.pincode.city,
        'PoliticalStatusExposed':
        True if investor.political_exposure == 2 else False,
        'PoliticalStatusRelated':
        True if investor.political_exposure == 3 else False,
        'ResidentStatus':
        investor.investor_status,
        'TaxPayer':
        investor.other_tax_payer,
        'UMRN':
        None
    }

    for key, value in investor_dict.items():
        if value is None:
            investor_dict[key] = ""
        if value is True:
            investor_dict[key] = "Yes"
        if value is False:
            investor_dict[key] = "Off"

    for key, value in investor_dict.items():
        if value not in ("", "Yes", "Off"):
            if type(value) == str:
                if "@" in value:
                    continue
            investor_dict[key] = str(value).upper()

    timestamp = time.strftime("%Y%m%d-%H%M%S")
    fields = [(key, value) for key, value in investor_dict.items()]
    fdf = forge_fdf("", fields, [], [], [])
    temp_file_name = "temp" + timestamp + ".fdf"
    fdf_file = open(temp_file_name, "wb")
    fdf_file.write(fdf)
    fdf_file.close()

    base_dir = os.path.dirname(os.path.dirname(__file__)).replace(
        '/webapp/apps', '')
    pdf_path = base_dir + '/bse_docs/'
    output_path = base_dir + '/webapp/static/'
    investor_pdf_name = pdf_path + "investor.pdf"
    out_file_name = "out" + timestamp + ".pdf"
    call(("pdftk " + investor_pdf_name +
          " fill_form %s output " % temp_file_name + output_path +
          "%s flatten" % out_file_name).split())

    remove_command = "rm %s" % temp_file_name

    if settings.USING_S3:
        prefix = ""  # prefix is needed to access the images from media directory.
    else:
        prefix = settings.SITE_BASE_URL  # prefix is needed to access the images from media directory.

    exist = output_path + out_file_name
    investor_only = output_path + "investor_only" + timestamp + ".pdf"
    combined_pdf_path = output_path + "investor_form_final" + timestamp + ".pdf"
    # the list of images to be embedded into the pdf follows
    list_of_embeddable_images = []

    # list of individual image type/size (passport/signature) they are based on international standards.
    image_sizes = []

    coords = []  # the lower left bottom corner
    #  co-ordinates for each of the images.

    target_pages = [
    ]  # pages of the existing/source pdf into which the images from the images list must be
    #  embedded onto

    images_count_each_page = [
    ]  # number of images on each of the target pages.

    nominee_signature = prefix + nominee.nominee_signature.url if nominee.nominee_signature != "" else cons.DEFAULT_IMAGE  # nominee signature image location.
    user_signature = prefix + user.signature.url if user.signature != "" else cons.DEFAULT_IMAGE  # signature_image location.
    list_of_embeddable_images.extend([nominee_signature, user_signature])
    image_sizes.extend([cons.SIGNATURE_SIZE, cons.SIGNATURE_SIZE])
    coords.extend([(390.97, 205.89), (390.97, 23.32)])
    target_pages.extend((0, 0))
    images_count_each_page.extend([2])

    if investor.pan_image:
        list_of_embeddable_images.append(prefix + investor.pan_image.url)
        image_sizes.append(cons.FIT_SIZE)
        coords.append((100, 270))
        target_pages.append(2)
        images_count_each_page.append(1)

    if investor_bank.bank_cheque_image:
        list_of_embeddable_images.append(prefix +
                                         investor_bank.bank_cheque_image.url)
        image_sizes.append(cons.FIT_SIZE)
        coords.append((100, 300))
        target_pages.append(4)
        images_count_each_page.append(1)

    if contact.front_image:
        list_of_embeddable_images.append(prefix + contact.front_image.url)
        image_sizes.append(cons.FIT_SIZE)
        coords.append((100, 400))
        target_pages.append(5)

    if contact.back_image:
        list_of_embeddable_images.append(prefix + contact.back_image.url)
        image_sizes.append(cons.FIT_SIZE)
        coords.append((100, 50))
        target_pages.append(5)

    if contact.front_image and contact.back_image:
        images_count_each_page.append(2)
    else:
        images_count_each_page.append(1)
    call(remove_command.split())
    embed_images(list_of_embeddable_images, image_sizes, coords, target_pages,
                 images_count_each_page, investor_only, exist)

    kyc_pdf = generate_kyc_pdf(user_id)
    call(("pdftk " + investor_only + " " + kyc_pdf + " cat output " +
          combined_pdf_path).split())
    return combined_pdf_path