package com.ffii.lioner.modules.lioner.pdf.service;

import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.text.DecimalFormat;
import java.text.NumberFormat;
import java.util.HashMap;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Set;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.math.NumberUtils;
import org.apache.pdfbox.Loader;
import org.apache.pdfbox.pdmodel.PDDocument;
import org.apache.pdfbox.pdmodel.interactive.form.PDAcroForm;
import org.apache.pdfbox.pdmodel.interactive.form.PDButton;
import org.apache.pdfbox.pdmodel.interactive.form.PDField;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.ffii.core.exception.NotFoundException;
import com.ffii.core.exception.UnprocessableEntityException;
import com.ffii.core.support.AbstractBaseEntityService;
import com.ffii.core.support.JdbcDao;
import com.ffii.core.utils.BeanUtils;
import com.ffii.lioner.modules.common.service.AuditLogService;
import com.ffii.lioner.modules.lioner.client.entity.Client;
import com.ffii.lioner.modules.lioner.client.service.ClientService;
import com.ffii.lioner.modules.lioner.commonField.entity.CommonField;
import com.ffii.lioner.modules.lioner.commonField.service.CommonFieldService;
import com.ffii.lioner.modules.lioner.pdf.entity.Consultant;
import com.ffii.lioner.modules.lioner.pdf.entity.Pdf;
import com.ffii.lioner.modules.lioner.pdf.entity.PdfRepository;
import com.ffii.lioner.modules.lioner.pdf.req.UpdatePdfReq;
import com.ffii.lioner.modules.lioner.service.FileService;
import com.ffii.lioner.modules.lioner.template.service.TemplateService;
import com.ffii.lioner.modules.lioner.userActionLog.service.UserActionLogService;
import com.itextpdf.forms.PdfAcroForm;
import com.itextpdf.forms.fields.PdfFormField;
import com.itextpdf.io.source.ByteArrayOutputStream;
import com.itextpdf.kernel.pdf.PdfDocument;
import com.itextpdf.kernel.pdf.PdfName;
import com.itextpdf.kernel.pdf.PdfReader;
import com.itextpdf.kernel.pdf.PdfWriter;

@Service
public class PdfService extends AbstractBaseEntityService<Pdf, Long, PdfRepository> {

    @Autowired
    private UserActionLogService userActionLogService;

	private String pdf_path = "templates/pdf/"; 
    
	private AuditLogService auditLogService;
	private FileService fileService;
	private TemplateService templateService;
	private CommonFieldService commonFieldService;
    private ClientService clientService;
    private ConsultantService consultantService;
	
	public PdfService(JdbcDao jdbcDao, PdfRepository repository, AuditLogService auditLogService, FileService fileService,
                        TemplateService templateService, ClientService clientService, ConsultantService consultantService, CommonFieldService commonFieldService) {
		super(jdbcDao, repository);
		this.auditLogService = auditLogService;
		this.fileService = fileService;
		this.templateService = templateService;
        this.clientService = clientService;
        this.consultantService = consultantService;
		this.commonFieldService = commonFieldService;
	}

	// public Map<String,Object> getAuditLogObject(Map<String,Object> req){
	// 	StringBuilder sql = new StringBuilder("SELECT"
	// 		+ " e.id,    "
	// 		+ " e.created,    "
	// 		+ " e.createdBy AS createdById,    "
	// 		+ " u1.name AS createdBy,    "
	// 		+ " e.version,    "
	// 		+ " e.modified,    "
	// 		+ " e.modifiedBy AS modifiedById,    "
	// 		+ " e.deleted, "
	// 		+ " u2.name AS modifiedBy,    "
	// 		+ " e.name, "
	// 		+ " e.nameCht, "
	// 		+ " e.description, "
	// 		+ " e.region, "
	// 		+ " e.organization, "
	// 		+ " e.eventType, "
	// 		+ " e.frequency, "
	// 		+ " e.series, "
	// 		+ " e.startDate, "
	// 		+ " e.eventFrom, "
	// 		+ " e.eventTo, "
	// 		+ " e.applicationDeadline, "
	// 		+ " e.nextApplicationDate, "
	// 		+ " e.announcementDate, "
	// 		+ " e.awardDate, "
	// 		+ " e.reminderFlag, "
	// 		+ " e.reminderThreshold, "
	// 		+ " e.reminderInterval, "
	// 		+ " e.reminderLimit  "
	// 		+ " FROM event e 	   "
	// 		+ " LEFT JOIN `user` u1 ON u1.id = e.createdBy     "
	// 		+ " LEFT JOIN `user` u2 ON u2.id = e.modifiedBy       "
	// 		+ " WHERE e.id = :id    "
	// 	);
	// 	return jdbcDao.queryForMap(sql.toString(), req).get();
	// }

	public Map<String, Object> saveOrUpdate(String recordJson, MultipartFile file) {
		ObjectMapper objectMapper = new ObjectMapper();
        UpdatePdfReq req;
        try {
            req = objectMapper.readValue(recordJson, UpdatePdfReq.class);
        } catch (Exception e) {
            throw new UnprocessableEntityException("Invalid JSON format");
        }
		
		Pdf instance;
		// List<SubDivision> onUsingIdList = new ArrayList<SubDivision>();
		if(req.getId()>0){
			instance = find(req.getId()).get();
			fileService.deleteFile(instance.getFileId());	// Delete previous record - WIP
			// onUsingIdList = this.getSelectedSubDivisionList(req.getId());
		}
		else{
			instance = new Pdf();
		}
        
		BeanUtils.copyProperties(req, instance);

		Map<String, Object> pdf = new HashMap<>();
		Map<String, Object> response = new HashMap<>();

		if (file.isEmpty()) {
			throw new UnprocessableEntityException("No file uploaded.");
            // return ResponseEntity.badRequest().body(Map.of("message", "No file uploaded."));
        }
        try {
            // Convert the MultipartFile to a byte array
            byte[] pdfData = file.getBytes();

            MultipartFile[] files = new MultipartFile[1];
            files[0] = file;

            try {
                pdf = fileService.saveOrUpdate(files, (long) 0, "pdf");
            } catch (Exception e) {
                System.out.println(e);
            }

			saveCmField(convertMultipartFileToFile(file), instance);

            response.put("message", "PDF saved successfully.");
            // response.put("id", pdfForm.getId().toString()); // Return the ID of the saved PDF

        } catch (IOException e) {
			throw new UnprocessableEntityException(
				"Failed to save PDF: "
				+ e
			);
        }
		
		Object fileIdList = pdf.get("fileIdList");
		List<?> list = (List<?>) fileIdList;
		Long fileId = (long) list.get(0);

		instance.setFileId(fileId);
		instance = save(instance);

        boolean reload = false;
        Map<String, Object> template = templateService.loadTemplate(instance.getTemplateId());
        if("IDA".equals(template.get("remarks")))
            reload = true;

		response = Map.of(
			"id", instance.getId(),
            "reload", reload
		);

		return response;
	}

	// Converter -- WIP
	public File convertMultipartFileToFile(MultipartFile multipartFile) throws IOException {
        // Convert MultipartFile to byte array
        byte[] bytes = multipartFile.getBytes();

        // Create a temporary file
        File file = File.createTempFile("tempFile", multipartFile.getOriginalFilename());

        // Write byte array to the file
        try (FileOutputStream fos = new FileOutputStream(file)) {
            fos.write(bytes);
        }

        return file;
    }

    public Map<String, Object> getTemplate(Long templateId, Long clientId) throws IOException{
        Map<String, Object> template = templateService.loadTemplate(templateId);
        
		byte[] pdfBytes = (byte[])template.get("blobValue");
        template.put("blobValue", getTemplateForm(pdfBytes, clientId, templateId));
        
        return template;
    }

    public Map<String, Object> getLastPdf(Long clientId, Long templateId) {
		StringBuilder sql = new StringBuilder("SELECT"
			+ " ff.id, "
			+ " ff.remarks, "
			+ " f.filename, "
			+ " fb.bytes AS blobValue "
			+ " FROM filled_form ff "
			+ " LEFT JOIN file f ON f.id = ff.fileId "            
			+ " LEFT JOIN file_blob fb ON f.id = fb.fileId "
			+ " WHERE ff.deleted = FALSE "
			+ " AND ff.clientId = :clientId "
			+ " AND ff.templateId = :templateId "
            + " ORDER BY ff.id DESC LIMIT 1 "
        );
        return jdbcDao.queryForMap(sql.toString(), Map.of("clientId", clientId, "templateId", templateId)).orElse(null);
    }

    //This included the common fields getting
	public byte[] getTemplateForm(byte[] pdfBytes, Long clientId, Long templateId) throws IOException {
    
        // --- 1. Initial Data Loading & Extraction Phase (iText Read) ---
        
        Map<String, Object> template = templateService.loadTemplate(templateId);

        // Search if there have an old form having the form code
        Map<String, Object> sourcePdf = getLastPdf(clientId, templateId); 
        if (sourcePdf == null) { sourcePdf = template; } 
        byte[] sourcePdfBytes = (byte[])sourcePdf.get("blobValue");
        String formCode = (String)template.get("remarks");
        Client client = clientService.find(clientId).orElseThrow();

        // Map to hold ALL extracted field data from the source PDF (historical values)
        Map<String, String> sourceFieldValues = new HashMap<>();

        // Load common field data (used by both phases)
        Long commonFieldId = commonFieldService.getByClientId(clientId);
        CommonField commonField = commonFieldService.find(commonFieldId).orElse(null);
        if(commonField == null){
            commonField = new CommonField();
            commonField.setClientId(clientId);
            commonFieldService.save(commonField);
        }
        
        // --- 1A. Extract ALL Field Values from Historical Source PDF (iText Read Only) ---
        // This uses iText to reliably read field data BEFORE any writing/modification happens.
        if (sourcePdfBytes != null) {
            try (ByteArrayInputStream inputStream = new ByteArrayInputStream(sourcePdfBytes)) {
                PdfReader sourceReader = new PdfReader(inputStream);
                PdfDocument sourcePdfDoc = new PdfDocument(sourceReader);
                PdfAcroForm sourceForm = PdfAcroForm.getAcroForm(sourcePdfDoc, true);
                
                if (sourceForm != null) {
                    for (Map.Entry<String, PdfFormField> entry : sourceForm.getFormFields().entrySet()) {
                        PdfFormField sourceField = entry.getValue();
                        if (sourceField.getFieldName() != null && sourceField.getValue() != null) {
                            sourceFieldValues.put(sourceField.getFieldName().toUnicodeString(), sourceField.getValueAsString());
                        }
                    }
                }
                sourcePdfDoc.close();
            }
        }
        
        // --- 2. Phase 1: Text Field Filling (iText Write) ---
        logger.info("Phase 1 (iText): Starting text field processing for form code: {}" + formCode);
        byte[] modifiedPdfBytes = pdfBytes;

        try (ByteArrayInputStream inputStream = new ByteArrayInputStream(pdfBytes);
            ByteArrayOutputStream outputStream = new ByteArrayOutputStream()) {

            PdfReader reader = new PdfReader(inputStream);
            PdfWriter writer = new PdfWriter(outputStream);
            PdfDocument pdfDoc = new PdfDocument(reader, writer);
            PdfAcroForm form = PdfAcroForm.getAcroForm(pdfDoc, true);

            if (form != null) {
                
                // ** START: Historical Text Field Copy **
                logger.info("Copying historical text fields...");
                for (Map.Entry<String, String> entry : sourceFieldValues.entrySet()) { 
                    String sourceFieldName = entry.getKey();
                    String sourceFieldValue = entry.getValue();
                    PdfFormField targetField = form.getField(sourceFieldName);
                    
                    if (targetField != null && targetField.getFormType().equals(PdfName.Tx)) {
                        targetField.setValue(sourceFieldValue); 
                        logger.info("Historical Text Field '{}' set." + sourceFieldName);
                    }
                }
                // ** END: Historical Text Field Copy **

                // Apply current business logic to Text Fields
                logger.info("Applying form code text fields: {}" + formCode);
                if("IDA".equals(formCode)){ 
                    IDA_textBox(form, commonField, client);
                } else if("FNA".equals(formCode)){ 
                    FNA_textBox(form, commonField, client);
                } else if("HSBCFIN".equals(formCode)){ 
                    HSBCFIN_textBox(form, commonField, client);
                } else if ("MLB03S".equals(formCode)) {
                    MLB03S_textBox(form, commonField, client);
                } else if("MLFNA_EN".equals(formCode) || "MLFNA_CHI".equals(formCode)){ 
                    MLFNA_EN_textBox(form, commonField, client);
                } else if("SLFNA_EN".equals(formCode) || "SLFNA_CHI".equals(formCode)){ 
                    SLFNA_EN_textBox(form, commonField, client);
                } else if("SLAPP".equals(formCode)){ 
                    SLAPP_textBox(form, commonField, client);
                } else if("HSBCA31".equals(formCode)){ 
                    HSBCA31_textBox(form, commonField, client);
                } else if("SLGII".equals(formCode)){
                    SLGII_textBox(form, commonField, client);
                }

                pdfDoc.close();
                modifiedPdfBytes = outputStream.toByteArray();
            } else {
                logger.warn("iText found no AcroForm. Proceeding to PDFBox phase with original bytes.");
            }

        } catch (IOException e) {
            logger.error("Error during iText text field processing.", e);
            throw e;
        }

        // --- 3. Phase 2: Checkbox Filling (PDFBox Write) ---
        logger.info("Phase 2 (PDFBox): Starting checkbox processing.");

        try (PDDocument targetDoc = Loader.loadPDF(modifiedPdfBytes); // Load iText's output
            ByteArrayOutputStream outputStream = new ByteArrayOutputStream()) {
            
            PDAcroForm form2 = targetDoc.getDocumentCatalog().getAcroForm();

            if (form2 != null) {
                
                // ** START: Historical Checkbox/Button Copy **
                logger.info("Copying historical button fields from map...");
                for (Map.Entry<String, String> entry : sourceFieldValues.entrySet()) { 
                    String sourceFieldName = entry.getKey();
                    String sourceValue = entry.getValue();

                    PDField targetField = form2.getField(sourceFieldName);

                    // CRITICAL: Check the field type before casting!
                    if (targetField instanceof PDButton) { 
                        PDButton button = (PDButton) targetField;
                        
                        Set<String> onValues = button.getOnValues(); 
                        
                        if (sourceValue != null && onValues != null && onValues.contains(sourceValue)) {
                            button.setValue(sourceValue); 
                            logger.info("Historical Checkbox '{}' set to CHECKED." + sourceFieldName);
                        } else {
                            button.setValue("Off");
                            logger.info("Historical Checkbox '{}' set to UNCHECKED." + sourceFieldName);
                        }
                    } 
                    // Ignore other field types (Text was handled by iText).
                }
                // ** END: Historical Checkbox/Button Copy **

                // Apply current business logic to Checkboxes/Buttons (overwrites historical)
                logger.info("Applying form code checkbox fields: {}" + formCode);
                if ("IDA".equals(formCode)) {
                    IDA_checkBox(form2, commonField);
                } else if ("FNA".equals(formCode)) {
                    FNA_checkBox(form2, commonField);
                } else if ("HSBCFIN".equals(formCode)) {
                    HSBCFIN_checkBox(form2, commonField);
                } else if ("MLB03S".equals(formCode)) {
                    MLB03S_checkBox(form2, commonField);
                } else if("MLFNA_EN".equals(formCode) || "MLFNA_CHI".equals(formCode)){ 
                    MLFNA_EN_checkBox(form2, commonField, client);
                } else if("SLFNA_EN".equals(formCode) || "SLFNA_CHI".equals(formCode)){ 
                    SLFNA_EN_checkBox(form2, commonField);
                } else if("SLAPP".equals(formCode)){ 
                    SLAPP_checkBox(form2, commonField);
                } else if("HSBCA31".equals(formCode)){ 
                    HSBCA31_checkBox(form2, commonField, client);
                } else if ("SLGII".equals(formCode)) {
                    SLGII_checkBox(form2, commonField);
                }
                
                // Save the final modified document
                targetDoc.save(outputStream);
                targetDoc.close();
                return outputStream.toByteArray();
            
            } else {
                logger.warn("PDFBox found no AcroForm. Returning iText output.");
                return modifiedPdfBytes; 
            }
            
        } catch (Exception e) { 
            logger.error("Error during PDFBox checkbox processing.", e);
            throw new IOException("Failed to process checkboxes with PDFBox.", e);
        }
    }

    private void IDA_textBox(PdfAcroForm form, CommonField commonField, Client client){
        logger.info("Processing IDA form (ID: 1)");
        /* Page1 Start */
        setValueIfPresent(form, "gender_m", commonField.getGenderMale());
        setValueIfPresent(form, "gender_f", commonField.getGenderFemale());
        
        setValueIfPresent(form, "fill_6", StringUtils.trimToEmpty(client.getLastname()));
        setValueIfPresent(form, "fill_7", StringUtils.trimToEmpty(client.getFirstname()));
        setValueIfPresent(form, "fill_chinese_name", commonField.getNameChi());
        setValueIfPresent(form, "fill_11", commonField.getIdCard());
        setValueIfPresent(form, "fill_12", commonField.getCountryOfIssue());
        setValueIfPresent(form, "fill_13", commonField.getPassportNo());
        setValueIfPresent(form, "fill_14_date", commonField.getOthers().get("passportExpiryDate"));                        
        setValueIfPresent(form, "fill_15", commonField.getPlaceOfBirth());
        setValueIfPresent(form, "fill_16", commonField.getCountryOfCitizenship());

        
        setValueIfPresent(form, "date_dd", commonField.getDdDateOfBirth());
        setValueIfPresent(form, "date_mm", commonField.getMmDateOfBirth());
        setValueIfPresent(form, "date_yyyy", commonField.getYyyyDateOfBirth());
        
        setValueIfPresent(form, "fill_phone_code", client.getPhone1Code());
        setValueIfPresent(form, "fill_17", client.getPhone1());
        setValueIfPresent(form, "fill_18", client.getEmail());
        setValueIfPresent(form, "fill_19", getCrAddress1(client));
        setValueIfPresent(form, "fill_19_1", getCrAddress2(client));
        setValueIfPresent(form, "fill_23", getCorAddress1(client));
        setValueIfPresent(form, "fill_23_1", getCorAddress2(client));
        
        /* Page1 End */
        /* Page2 Start */
        setValueIfPresent(form, "own_income", commonField.getOwn_income());
        setValueIfPresent(form, "savings", commonField.getSavings());
        setValueIfPresent(form, "premium_financing", commonField.getPremium_financing());
        setValueIfPresent(form, "others_funds", commonField.getOthers_funds());
        setValueIfPresent(form, "others_funds_desc", commonField.getOthers_funds_desc());
        /* Page2 End */
        /* Page3 Start */
        setValueIfPresent(form, "fill_18_1", commonField.getBankruptDesc());

        setValueIfPresent(form, "fill_3_3", commonField.getOthers().get("travelCity1"));
        setValueIfPresent(form, "fill_6_3", commonField.getOthers().get("travelCity2"));
        setValueIfPresent(form, "fill_9_3", commonField.getOthers().get("travelCity3"));
        setValueIfPresent(form, "fill_5_3", commonField.getOthers().get("travelPurpose1"));
        setValueIfPresent(form, "fill_8_3", commonField.getOthers().get("travelPurpose2"));
        setValueIfPresent(form, "fill_11_3", commonField.getOthers().get("travelPurpose3"));
        setValueIfPresent(form, "fill_4_3", commonField.getOthers().get("travelFrequency1"));
        setValueIfPresent(form, "fill_7_3", commonField.getOthers().get("travelFrequency2"));
        setValueIfPresent(form, "fill_10_3", commonField.getOthers().get("travelFrequency3"));
        /* Page3 End */
        /* Page4 Start */
        setValueIfPresent(form, "toggle_1_3", commonField.getOthers().get("futureAddressYes"));
        setValueIfPresent(form, "toggle_2_2", commonField.getOthers().get("futureAddressNo"));
        setValueIfPresent(form, "fill_1_4_1", commonField.getOthers().get("futureAddress"));
        //setValueIfPresent(form, "fill_1_4_2", commonField.getOthers().get("futureAddress2"));
        setValueIfPresent(form, "fill_2_4", commonField.getOthers().get("futureAddressReasonHowLong"));

        setValueIfPresent(form, "fill_3_4", commonField.getOthers().get("travelCity1"));
        setValueIfPresent(form, "fill_6_4", commonField.getOthers().get("travelCity2"));
        setValueIfPresent(form, "fill_9_4", commonField.getOthers().get("travelCity3"));
        setValueIfPresent(form, "fill_5_4", commonField.getOthers().get("travelPurpose1"));
        setValueIfPresent(form, "fill_8_4", commonField.getOthers().get("travelPurpose2"));
        setValueIfPresent(form, "fill_11_4", commonField.getOthers().get("travelPurpose3"));
        setValueIfPresent(form, "fill_4_4", commonField.getOthers().get("travelFrequency1"));
        setValueIfPresent(form, "fill_7_4", commonField.getOthers().get("travelFrequency2"));
        setValueIfPresent(form, "fill_10_4", commonField.getOthers().get("travelFrequency3"));
        /* Page4 End */
        /* Page5 Start */
        setValueIfPresent(form, "hazardousActivity", commonField.getHazardousActivity());
        /* Page5 End */
        /* Page6 Start */
        setValueIfPresent(form, "fill_8_country_1", commonField.getTaxResidency1());
        setValueIfPresent(form, "fill_1_6", commonField.getTaxPin1());
        setValueIfPresent(form, "fill_2_6", commonField.getTaxReason1());
        setValueIfPresent(form, "fill_3_6", commonField.getTaxReasonB1());
        setValueIfPresent(form, "fill_3_6a", commonField.getOthers().get("TaxReasonB1a"));
        setValueIfPresent(form, "fill_8_country_2", commonField.getTaxResidency2());
        setValueIfPresent(form, "fill_4_5", commonField.getTaxPin2());
        setValueIfPresent(form, "fill_5_6", commonField.getTaxReason2());
        setValueIfPresent(form, "fill_6_6", commonField.getTaxReasonB2());
        setValueIfPresent(form, "fill_6_6a", commonField.getOthers().get("TaxReasonB2a"));
        setValueIfPresent(form, "fill_8_country_3", commonField.getTaxResidency3());
        setValueIfPresent(form, "fill_7_6", commonField.getTaxPin3());
        setValueIfPresent(form, "fill_8_6", commonField.getTaxReason3());
        setValueIfPresent(form, "fill_9_6", commonField.getTaxReasonB3());
        setValueIfPresent(form, "fill_9_6a", commonField.getOthers().get("TaxReasonB3a"));
        /* Page6 End */
        /* Page7 Start */
        setValueIfPresent(form, "fill_11_7", commonField.getInsuranceCompany1_1());
        setValueIfPresent(form, "fill_11_7_1", commonField.getInsuranceCompany1_2());
        //setValueIfPresent(form, "fill_11_7_2", commonField.getInsuranceCompany1_3());
        setValueIfPresent(form, "fill_12_7_1", commonField.getOthers().get("insuranceSumInsured1_1"));
        setValueIfPresent(form, "fill_12_7_2", commonField.getOthers().get("insuranceSumInsured1_2"));
        setValueIfPresent(form, "fill_12_7_3", commonField.getOthers().get("insuranceSumInsured1_3"));
        setValueIfPresent(form, "toggle_3_5", commonField.getInsuranceLife1());
        setValueIfPresent(form, "toggle_4_4", commonField.getInsuranceSaving1());
        setValueIfPresent(form, "toggle_5_5", commonField.getInsuranceCritical1());
        setValueIfPresent(form, "toggle_6_3", commonField.getInsuranceOther1());
        setValueIfPresent(form, "undefined_21", commonField.getInsuranceOtherDesc1());
        setValueIfPresent(form, "fill_1_7", commonField.getInsuranceYear1());
        
        setValueIfPresent(form, "fill_13_7", commonField.getInsuranceCompany2_1());
        setValueIfPresent(form, "fill_13_7_1", commonField.getInsuranceCompany2_2());
        //setValueIfPresent(form, "fill_13_7_2", commonField.getInsuranceCompany2_3());
        setValueIfPresent(form, "fill_14_7_1", commonField.getOthers().get("insuranceSumInsured2_1"));
        setValueIfPresent(form, "fill_14_7_2", commonField.getOthers().get("insuranceSumInsured2_2"));
        setValueIfPresent(form, "fill_14_7_3", commonField.getOthers().get("insuranceSumInsured2_3"));
        setValueIfPresent(form, "undefined_22", commonField.getInsuranceOtherDesc2());
        setValueIfPresent(form, "fill_3_7", commonField.getInsuranceYear2());
        setValueIfPresent(form, "fill_15_7", commonField.getInsuranceCompany3_1());
        setValueIfPresent(form, "fill_15_7_1", commonField.getInsuranceCompany3_2());
        //setValueIfPresent(form, "fill_15_7_2", commonField.getInsuranceCompany3_3());
        setValueIfPresent(form, "fill_16_7_1", commonField.getOthers().get("insuranceSumInsured3_1"));
        setValueIfPresent(form, "fill_16_7_2", commonField.getOthers().get("insuranceSumInsured3_2"));
        setValueIfPresent(form, "fill_16_7_3", commonField.getOthers().get("insuranceSumInsured3_3"));
        setValueIfPresent(form, "undefined_23", commonField.getInsuranceOtherDesc3());
        setValueIfPresent(form, "fill_5_7", commonField.getInsuranceYear3());

        setValueIfPresent(form, "ultimateTotalLife", commonField.getUltimateTotalLife());
        setValueIfPresent(form, "declinedDesc", commonField.getDeclinedDesc());
        /* Page7 End */
        /* Page8 Start */
        setValueIfPresent(form, "fill_1_8", commonField.getOthers().get("companyStartYear"));
        setValueIfPresent(form, "fill_2_7", commonField.getOthers().get("companyEndYear"));
        setValueIfPresent(form, "fill_3_8", commonField.getOccupationTitle());
        setValueIfPresent(form, "fill_4_6_1", commonField.getCompanyName());
        setValueIfPresent(form, "fill_4_6_2", commonField.getOthers().get("companyAddress1"));
        setValueIfPresent(form, "fill_4_6_3", commonField.getOthers().get("companyAddress2"));
        setValueIfPresent(form, "fill_5_8_1", commonField.getCompanyNature1());
        setValueIfPresent(form, "fill_5_8_2", commonField.getCompanyNature2());
        /* Page8 End */
        /* Page9 Start */
        //setValueIfPresent(form, "fill_26_4", commonField.getFna_c1a_amount());
        setValueIfPresent(form, "fill_30_4", commonField.getOthers().get("realEstateAddress1_1"));
        setValueIfPresent(form, "fill_30_4_1", commonField.getOthers().get("realEstateAddress1_2"));
        setValueIfPresent(form, "fill_35_2", commonField.getOthers().get("realEstateAddress2_1"));
        setValueIfPresent(form, "fill_35_2_1", commonField.getOthers().get("realEstateAddress2_2"));
        setValueIfPresent(form, "fill_40_2", commonField.getOthers().get("realEstateAddress3_1"));
        setValueIfPresent(form, "fill_40_2_1", commonField.getOthers().get("realEstateAddress3_2"));
        setValueIfPresent(form, "fill_31_4", commonField.getRealEstatePurchaseDate1());
        setValueIfPresent(form, "fill_36_2", commonField.getRealEstatePurchaseDate2());
        setValueIfPresent(form, "fill_41_2", commonField.getRealEstatePurchaseDate3());
        /* Page9 End */
        /* Page10 Start */
        setValueIfPresent(form, "fill_2_9", commonField.getOthers().get("fill_2_9"));
        /* Page10 End */

        if(client != null && client.getConsultantId() != null){
            Consultant consultant = consultantService.find(Long.valueOf(client.getConsultantId())).orElseThrow();

            if(consultant.getName() != null){
                setValueIfPresent(form, "Name of Appointed Representative", consultant.getName());
            }                            
        }    
        
        setValueIfPresent(form, "Name of Client", StringUtils.trimToEmpty(StringUtils.trimToEmpty(client.getLastname()) + " " + StringUtils.trimToEmpty(client.getFirstname())));
        //setValueIfPresent(form, "Name of Client1", commonField.getOthers().get("name1"));
        //setValueIfPresent(form, "Name of Client2", commonField.getOthers().get("name2"));

        /* Page11 Start */
        setValueIfPresent(form, "incomeSalary", formatNum(client.getSalaryCurrent()));
        setValueIfPresent(form, "incomeSalaryLastYear", formatNum(client.getSalaryLast()));
        setValueIfPresent(form, "incomeBonus", formatNum(client.getBonusCurrent()));
        setValueIfPresent(form, "incomeBonusLastYear", formatNum(client.getBonusLast()));
        setValueIfPresent(form, "incomeOther", formatNum(client.getOtherEarnedCurrent()));
        setValueIfPresent(form, "incomeOtherLastYear", formatNum(client.getOtherEarnedLast()));

        setValueIfPresent(form, "total_earned_income_current", formatNum(client.getTotalEarnedCurrent()));
        setValueIfPresent(form, "total_earned_income_last", formatNum(client.getTotalEarnedLast()));
    
        setValueIfPresent(form, "incomeInterest", formatNum(client.getCompanyInterestCurrent()));
        setValueIfPresent(form, "incomeInterestLastYear", formatNum(client.getCompanyInterestLast()));
        setValueIfPresent(form, "incomeDividents", formatNum(client.getDividendsCurrent()));
        setValueIfPresent(form, "incomeDividentsLastYear", formatNum(client.getDividendsLast()));
        setValueIfPresent(form, "incomeRentals", formatNum(client.getRentalsCurrent()));
        setValueIfPresent(form, "incomeRentalsLastYear", formatNum(client.getRentalsLast()));
        setValueIfPresent(form, "fill_24_4", formatNum(client.getInvestmentIncomeCurrent()));
        setValueIfPresent(form, "fill_25_4", formatNum(client.getInvestmentIncomeLast()));
        setValueIfPresent(form, "fill_28_4", formatNum(client.getOtherUnearnedCurrent()));
        setValueIfPresent(form, "fill_29_4", formatNum(client.getOtherUnearnedLast()));

        setValueIfPresent(form, "total_unearned_income", formatNum(client.getTotalUnearnedCurrent()));
        setValueIfPresent(form, "total_unearned_income_last", formatNum(client.getTotalUnearnedLast()));
        
        setValueIfPresent(form, "total_income", formatNum(client.getTotalIncomeCurrent()));
        setValueIfPresent(form, "total_income_last", formatNum(client.getTotalIncomeLast()));

        setValueIfPresent(form, "mortgage", formatNum(client.getMortgageCurrent()));
        setValueIfPresent(form, "mortgageLastYear", formatNum(client.getMortgageLast()));
        setValueIfPresent(form, "rent", formatNum(client.getRentCurrent()));
        setValueIfPresent(form, "rentLastYear", formatNum(client.getRentLast()));
        setValueIfPresent(form, "schooling", formatNum(client.getSchoolingCurrent()));
        setValueIfPresent(form, "schoolingLastYear", formatNum(client.getSchoolingLast()));
        setValueIfPresent(form, "membership", formatNum(client.getMembershipsCurrent()));
        setValueIfPresent(form, "membershipLastYear", formatNum(client.getMembershipsLast()));
        setValueIfPresent(form, "otherExpenditure", formatNum(client.getOtherExpenditureCurrent()));
        setValueIfPresent(form, "otherExpenditureLastYear", formatNum(client.getOtherExpenditureLast()));
        
        setValueIfPresent(form, "interest", formatNum(client.getInterestCurrent()));
        setValueIfPresent(form, "interestLastYear", formatNum(client.getInterestLast()));
        setValueIfPresent(form, "principal", formatNum(client.getPrincipalCurrent()));
        setValueIfPresent(form, "principalLastYear", formatNum(client.getPrincipalLast()));
        setValueIfPresent(form, "otherPrefFinance", formatNum(client.getOtherPrefFinanceCurrent()));
        setValueIfPresent(form, "otherPrefFinanceLastYear", formatNum(client.getOtherPrefFinanceLast()));
        
        setValueIfPresent(form, "totalExpenditure", formatNum(client.getTotalExpenditureCurrent()));
        setValueIfPresent(form, "totalExpenditureLastYear", formatNum(client.getTotalExpenditureLast()));
        
        setValueIfPresent(form, "assetCash", formatNum(client.getCashDepositsCurrent()));
        setValueIfPresent(form, "assetCashLast", formatNum(client.getCashDepositsLast()));
        setValueIfPresent(form, "assetInvestment", formatNum(client.getInvestmentsCurrent()));
        setValueIfPresent(form, "assetInvestmentLast", formatNum(client.getInvestmentsLast()));
        setValueIfPresent(form, "assetOtherLiquid", formatNum(client.getOtherLiquidCurrent()));
        setValueIfPresent(form, "assetOtherLiquidLast", formatNum(client.getOtherLiquidLast()));
        setValueIfPresent(form, "totalLiquidAsset", formatNum(client.getTotalLiquidAssetCurrent()));
        setValueIfPresent(form, "totalLiquidAssetLast", formatNum(client.getTotalLiquidAssetLast()));
        
        setValueIfPresent(form, "assetNetBusinessInterest", formatNum(client.getNetBusinessInterestCurrent()));
        setValueIfPresent(form, "assetNetBusinessInterestLast", formatNum(client.getNetBusinessInterestLast()));
        setValueIfPresent(form, "assetProperties", formatNum(client.getPersonalPropertiesCurrent()));
        setValueIfPresent(form, "assetPropertiesLast", formatNum(client.getPersonalPropertiesLast()));
        setValueIfPresent(form, "assetRealEstate", formatNum(client.getRealEstateCurrent()));
        setValueIfPresent(form, "assetRealEstateLast", formatNum(client.getRealEstateLast()));

        setValueIfPresent(form, "assetOtherNonLiquid", formatNum(client.getOtherNonLiquidCurrent()));
        setValueIfPresent(form, "assetOtherNonLiquidLast", formatNum(client.getOtherNonLiquidLast()));
        setValueIfPresent(form, "totalNonLiquidAsset", formatNum(client.getTotalNonLiquidAssetCurrent()));
        setValueIfPresent(form, "totalNonLiquidAssetLast", formatNum(client.getTotalNonLiquidAssetLast()));
        setValueIfPresent(form, "total_asset", formatNum(client.getTotalAssetsCurrent()));
        setValueIfPresent(form, "total_assetLast", formatNum(client.getTotalAssetsLast()));
        
        setValueIfPresent(form, "liaLoan", formatNum(client.getPersonalLoansCurrent()));
        setValueIfPresent(form, "liaLoanLast", formatNum(client.getPersonalLoansLast()));
        setValueIfPresent(form, "liaMortgage", formatNum(client.getMortgagesLast()));
        setValueIfPresent(form, "liaMortgageLast", formatNum(client.getMortgagesLast()));
        setValueIfPresent(form, "liaMargin", formatNum(client.getMarginAccountCurrent()));
        setValueIfPresent(form, "liaMarginLast", formatNum(client.getMarginAccountLast()));
        setValueIfPresent(form, "liaLoanGuarantee", formatNum(client.getLoanGuaranteesCurrent()));
        setValueIfPresent(form, "liaLoanGuaranteeLast", formatNum(client.getLoanGuaranteesLast()));
        setValueIfPresent(form, "liaBankingFacility", formatNum(client.getBankingFacilityCurrent()));
        setValueIfPresent(form, "liaBankingFacilityLast", formatNum(client.getBankingFacilityLast()));
        
        setValueIfPresent(form, "liaPrincipal", formatNum(client.getPrefFinancePrincipalCurrent()));
        setValueIfPresent(form, "liaPrincipalLast", formatNum(client.getPrefFinancePrincipalLast()));
        setValueIfPresent(form, "liaOther", formatNum(client.getPrefFinanceOtherCurrent()));
        setValueIfPresent(form, "liaOtherLast", formatNum(client.getPrefFinanceOtherLast()));
        setValueIfPresent(form, "fill_6_8", formatNum(client.getTotalLiabilitiesCurrent()));
        setValueIfPresent(form, "totalLiabilitiesLast", formatNum(client.getTotalLiabilitiesLast()));
        
        setValueIfPresent(form, "totalNet", substractNums(client.getTotalAssetsCurrent(), client.getTotalLiabilitiesCurrent()));
        
        /* Page11 End */
    }

    private void IDA_checkBox(PDAcroForm form2, CommonField commonField){
        setValueIfPresent(form2, "gender_m", commonField.getGenderMale());
        setValueIfPresent(form2, "gender_f", commonField.getGenderFemale());
        setValueIfPresent(form2, "ch_hkid", commonField.getOthers().get("hkidPerm"));
        setValueIfPresent(form2, "ch_hkid_non", commonField.getOthers().get("hkidNon"));
        setValueIfPresent(form2, "ch_prcid", commonField.getOthers().get("prcId"));
        setValueIfPresent(form2, "ch_othersid", commonField.getOthers().get("othersId"));

        //setValueIfPresent(form2, "fill_7", commonField.getNameChi());

        setValueIfPresent(form2, "edu_pri", commonField.getEduPri());
        setValueIfPresent(form2, "edu_sec", commonField.getEduSec());
        setValueIfPresent(form2, "edu_post_sec", commonField.getEduPostSec());
        setValueIfPresent(form2, "own_income", commonField.getOwn_income());
        setValueIfPresent(form2, "savings", commonField.getSavings());
        setValueIfPresent(form2, "premium_financing", commonField.getPremium_financing());
        setValueIfPresent(form2, "others_funds", commonField.getOthers_funds());
        setValueIfPresent(form2, "others_funds_desc", commonField.getOthers_funds_desc());
        /* Page3 Start */
        setValueIfPresent(form2, "toggle_5_2", commonField.getBankruptYes());
        setValueIfPresent(form2, "toggle_6_2", commonField.getBankruptNo());
        /* Page3 End */
        /* Page5 Start */
        setValueIfPresent(form2, "toggle_3_4", commonField.getOthers().get("pendingChargeYes"));
        setValueIfPresent(form2, "undefined_11", commonField.getOthers().get("pendingChargeNo"));

        setValueIfPresent(form2, "tobaccoYes", commonField.getTobarccoYes());
        setValueIfPresent(form2, "tobaccoNo", commonField.getTobarccoNo());
        /* Page5 End */
        /* Page7 Start */
        //if(commonField.getOthers().get("insuranceSumInsured1_1") != null && !commonField.getOthers().get("insuranceSumInsured1_1").isBlank()){
            setValueIfPresent(form2, "toggle_3_5", commonField.getInsuranceLife1());
            setValueIfPresent(form2, "toggle_4_4", commonField.getInsuranceSaving1());
            setValueIfPresent(form2, "toggle_5_5", commonField.getInsuranceCritical1());
            setValueIfPresent(form2, "toggle_6_3", commonField.getInsuranceOther1());
        //}
        
        //if(commonField.getInsuranceSumInsured2() != null && !commonField.getInsuranceSumInsured2().isBlank()){
            setValueIfPresent(form2, "toggle_9_3", commonField.getInsuranceLife2());
            setValueIfPresent(form2, "toggle_10_3", commonField.getInsuranceSaving2());
            setValueIfPresent(form2, "toggle_11_3", commonField.getInsuranceCritical2());
            setValueIfPresent(form2, "toggle_12_2", commonField.getInsuranceOther2());
        //}
        
        //if(commonField.getInsuranceSumInsured3() != null && !commonField.getInsuranceSumInsured3().isBlank()){
            setValueIfPresent(form2, "toggle_15", commonField.getInsuranceLife3());
            setValueIfPresent(form2, "toggle_16_2", commonField.getInsuranceSaving3());
            setValueIfPresent(form2, "toggle_17_3", commonField.getInsuranceCritical3());
            setValueIfPresent(form2, "toggle_18_2", commonField.getInsuranceOther3());
        //}
        setValueIfPresent(form2, "declinedYes", commonField.getDeclinedYes());
        setValueIfPresent(form2, "declinedNo", commonField.getDeclinedNo());

        setValueIfPresent(form2, "replaceInsuranceYes", commonField.getReplaceInsuranceYes());
        setValueIfPresent(form2, "replaceInsuranceNo", commonField.getReplaceInsuranceNo());
        
        /* Page7 End */
        /* Page 8 Start */
        setValueIfPresent(form2, "employed", commonField.getEmployed());
        setValueIfPresent(form2, "homemaker", commonField.getHomemaker());
        setValueIfPresent(form2, "student", commonField.getStudent());
        setValueIfPresent(form2, "investor", commonField.getInvestor());
        setValueIfPresent(form2, "retired", commonField.getRetired());
        /* Page 8 End */
        logger.info("12");
        /* Page10 Start */
        setValueIfPresent(form2, "toggle_3_7", commonField.getOthers().get("sourceIncome"));
        setValueIfPresent(form2, "toggle_4_6", commonField.getOthers().get("sourceBusiness"));
        setValueIfPresent(form2, "toggle_6_5", commonField.getOthers().get("sourceInvestment"));
        setValueIfPresent(form2, "undefined_33", commonField.getOthers().get("sourceInheritance"));
        setValueIfPresent(form2, "toggle_7_5", commonField.getOthers().get("sourceOther"));
        /* Page10 End */
        /* Page11 Start */
        setValueIfPresent(form2, "emp_other_benefits_yes", commonField.getOthers().get("empOtherBenefitsYes"));
        setValueIfPresent(form2, "emp_other_benefits_no", commonField.getOthers().get("empOtherBenefitsNo"));
        /* Page11 End */
            
    }

    private void FNA_textBox(PdfAcroForm form, CommonField commonField, Client client){
        //logger.info("Processing FNA form (ID: 2)");
        /* Page1 Start */
        //setValueIfPresent(form, "fna_a_name", commonField.getName());
        setValueIfPresent(form, "fna_a_name", StringUtils.trimToEmpty(StringUtils.trimToEmpty(client.getLastname()) + " " + StringUtils.trimToEmpty(client.getFirstname())));
        
        //setValueIfPresent(form, "fna_a_name_1", commonField.getOthers().get("name1"));
        //setValueIfPresent(form, "fna_a_name_2", commonField.getOthers().get("name2"));
        setValueIfPresent(form, "fna_a_birth", commonField.getDateOfBirth());
        setValueIfPresent(form, "fna_a_id_card", commonField.getIdCard());
        setValueIfPresent(form, "fna_a_occupation", commonField.getOthers().get("empPosition"));
        setValueIfPresent(form, "fna_a_primary", commonField.getEduPri());
        setValueIfPresent(form, "fna_a_secondary", commonField.getEduSec());
        setValueIfPresent(form, "fna_a_tertiary", commonField.getEduPostSec());

        if("Yes".equals(commonField.getOthers().get("maritalStatusSingle"))){
            setValueIfPresent(form, "fna_a_marital", "Single");
        }else if("Yes".equals(commonField.getOthers().get("maritalStatusMarried"))){
            setValueIfPresent(form, "fna_a_marital", "Married");
        }else if("Yes".equals(commonField.getOthers().get("maritalStatusOther")) && StringUtils.trimToNull(commonField.getOthers().get("maritalStatusOtherDesc")) != null){
            setValueIfPresent(form, "fna_a_marital", commonField.getOthers().get("maritalStatusOtherDesc"));
        }
        
        setValueIfPresent(form, "fna_a_contact", StringUtils.trimToEmpty(client.getPhone1Code()) + " " + StringUtils.trimToEmpty(client.getPhone1()));
        setValueIfPresent(form, "fna_a_dependents", commonField.getNoOfDependents());

        setValueIfPresent(form, "fna_c1a_amount", formatNum(client.getTotalIncomeCurrent()));
        setValueIfPresent(form, "fna_c1b_amount", formatNum(client.getTotalExpenditureCurrent()));
        setValueIfPresent(form, "fna_c1c_1_amount", commonField.getFna_c1c_1_amount());
        setValueIfPresent(form, "fna_c1c_2_amount", commonField.getFna_c1c_2_amount());
        setValueIfPresent(form, "fna_c1c_3_amount", commonField.getFna_c1c_3_amount());
        setValueIfPresent(form, "fna_c1d_amount", formatNum(substractNums(substractNums(client.getTotalIncomeCurrent(), client.getTotalExpenditureCurrent()), form.getField("fna_c1c_3_amount").getValueAsString())));
        setValueIfPresent(form, "fna_c2a_amount", commonField.getFna_c2a_amount());

        setValueIfPresent(form, "fna_c2b_amount", formatNum(client.getTotalLiabilitiesCurrent()));
        setValueIfPresent(form, "fna_c2c_amount", commonField.getFna_c2c_amount());
        setValueIfPresent(form, "fna_c2d_amount", formatNum(client.getPrincipalCurrent()));
        setValueIfPresent(form, "fna_c2e_amount", formatNum(client.getTotalLiquidAssetCurrent()));
        setValueIfPresent(form, "fna_b1_a", commonField.getFna_b1_a());
        setValueIfPresent(form, "fna_b1_a_amount", commonField.getFna_b1_a_amount());

        setValueIfPresent(form, "fna_b1a_4_amount", commonField.getFna_b1a_4_amount());
        
        setValueIfPresent(form, "fna_b1_d_year", commonField.getFna_b1_d_year());
        setValueIfPresent(form, "fna_b1_d_amount", formatNum(commonField.getFna_b1_d_amount()));
        /* Page1 End */
        /* Page2 Start */
        setValueIfPresent(form, "fna_b1_f_other", commonField.getFna_b1_f_other());
        setValueIfPresent(form, "fna_b1_f_desc", commonField.getFna_b1_f_desc());

        /* Page2 End */
        /* Page3 Start */
        
        /* Page3 End */
        /* Page4 Start */
        setValueIfPresent(form, "fna_c2a_desc", commonField.getFna_c2a_desc());                        
        /* Page4 End */
        /* Page5 Start */                       
        setValueIfPresent(form, "fna_a_retire", commonField.getFna_a_retire());

        setValueIfPresent(form, "fna_c3a_single_pay_max", formatNum(commonField.getOthers().get("singlePayAmount")));
        setValueIfPresent(form, "fna_c3a_single_pay_max_ch", formatNum(commonField.getOthers().get("singlePayAmount")));
        
        setValueIfPresent(form, "fna_c3b_desc", commonField.getFna_c3b_desc());                    
        /* Page5 End */

        /* Page6 Start */ 
        setValueIfPresent(form, "fna_d_desc", commonField.getFna_d_desc());

        setValueIfPresent(form, "fna_d_b1_1", commonField.getOthers().get("recObj1"));
        setValueIfPresent(form, "fna_d_b1_2", commonField.getOthers().get("recObj2"));
        setValueIfPresent(form, "fna_d_b1_3", commonField.getOthers().get("recObj3"));
        setValueIfPresent(form, "fna_d_b1_4", commonField.getOthers().get("recObj4"));
        setValueIfPresent(form, "fna_d_b1_5", commonField.getOthers().get("recObj5"));
        setValueIfPresent(form, "fna_d_b1_6", commonField.getOthers().get("recObj6"));

        setValueIfPresent(form, "fna_d_name_1", commonField.getOthers().get("recProd1_1"));
        setValueIfPresent(form, "fna_d_name_2", commonField.getOthers().get("recProd2_1"));
        setValueIfPresent(form, "fna_d_name_3", commonField.getOthers().get("recProd3_1"));
        setValueIfPresent(form, "fna_d_name_4", commonField.getOthers().get("recProd4_1"));
        setValueIfPresent(form, "fna_d_name_5", commonField.getOthers().get("recProd5_1"));
        setValueIfPresent(form, "fna_d_name_6", commonField.getOthers().get("recProd6_1"));
        
        setValueIfPresent(form, "fna_d_product_1", commonField.getOthers().get("recSelect1_1"));
        setValueIfPresent(form, "fna_d_product_2", commonField.getOthers().get("recSelect2_1"));
        setValueIfPresent(form, "fna_d_product_3", commonField.getOthers().get("recSelect3_1"));
        setValueIfPresent(form, "fna_d_product_4", commonField.getOthers().get("recSelect4_1"));
        setValueIfPresent(form, "fna_d_product_5", commonField.getOthers().get("recSelect5_1"));
        setValueIfPresent(form, "fna_d_product_6", commonField.getOthers().get("recSelect6_1"));
        /* Page6 End */

        
        if(client != null && client.getConsultantId() != null){
            Consultant consultant = consultantService.find(Long.valueOf(client.getConsultantId())).orElseThrow();

            if(consultant.getName() != null){
                setValueIfPresent(form, "fna_name_intermediary", consultant.getName());
            }                            
        }    
        
        setValueIfPresent(form, "fna_name_policyowner", StringUtils.trimToEmpty(StringUtils.trimToEmpty(client.getLastname()) + " " + StringUtils.trimToEmpty(client.getFirstname())));
        
    }

    private void FNA_checkBox(PDAcroForm form2, CommonField commonField){
        setValueIfPresent(form2, "fna_a_primary", commonField.getEduPri());
        setValueIfPresent(form2, "fna_a_secondary", commonField.getEduSec());
        setValueIfPresent(form2, "fna_a_tertiary", commonField.getEduPostSec());
        setValueIfPresent(form2, "fna_a_life_0", commonField.getFna_a_life_0());
        setValueIfPresent(form2, "fna_a_life_less_5", commonField.getFna_a_life_less_5());
        setValueIfPresent(form2, "fna_a_life_above_5", commonField.getFna_a_life_above_5());

        if(convertStringToNum(commonField.getFna_b1_d_amount()) > 0){
            setValueIfPresent(form2, "fna_b1_d", "Yes");
        }

        setValueIfPresent(form2, "fna_b1_a", commonField.getFna_b1_a());
        setValueIfPresent(form2, "fna_b1b_1", commonField.getFna_b1b_1());
        setValueIfPresent(form2, "fna_b1b_2", commonField.getFna_b1b_2());
        setValueIfPresent(form2, "fna_b1b_3", commonField.getFna_b1b_3());
        setValueIfPresent(form2, "fna_b1_b", commonField.getFna_b1_b());
        setValueIfPresent(form2, "fna_b1_c", commonField.getFna_b1_c());
        setValueIfPresent(form2, "fna_b1_d", commonField.getFna_b1_d());
        setValueIfPresent(form2, "fna_b1_e", commonField.getFna_b1_e());
        setValueIfPresent(form2, "fna_b1_f", commonField.getFna_b1_f());
        setValueIfPresent(form2, "fna_b2_a", commonField.getFna_b2_a());
        setValueIfPresent(form2, "fna_b2_b", commonField.getFna_b2_b());
        setValueIfPresent(form2, "fna_b2_d", commonField.getFna_b2_d());
        setValueIfPresent(form2, "fna_b2_e", commonField.getFna_b2_e());
        setValueIfPresent(form2, "fna_b2_f", commonField.getFna_b2_f());
        setValueIfPresent(form2, "fna_b2_g", commonField.getFna_b2_g());
        setValueIfPresent(form2, "fna_c1e_10", commonField.getFna_c1e_10());
        setValueIfPresent(form2, "fna_c1e_10_20", commonField.getFna_c1e_10_20());
        setValueIfPresent(form2, "fna_c1e_21_30", commonField.getFna_c1e_21_30());
        setValueIfPresent(form2, "fna_c1e_31_40", commonField.getFna_c1e_31_40());
        setValueIfPresent(form2, "fna_c1e_41_50", commonField.getFna_c1e_41_50());
        setValueIfPresent(form2, "fna_c1e_50", commonField.getFna_c1e_50());

        setValueIfPresent(form2, "fna_c2a_cash", commonField.getFna_c2a_cash());
        setValueIfPresent(form2, "fna_c2a_market_account", commonField.getFna_c2a_market_account());
        setValueIfPresent(form2, "fna_c2a_bank_account", commonField.getFna_c2a_bank_account());
        setValueIfPresent(form2, "fna_c2a_stocks", commonField.getFna_c2a_stocks());
        setValueIfPresent(form2, "fna_c2a_bonds", commonField.getFna_c2a_bonds());
        setValueIfPresent(form2, "fna_c2a_us", commonField.getFna_c2a_us());
        setValueIfPresent(form2, "fna_c2a_others", commonField.getFna_c2a_others());

        setValueIfPresent(form2, "fna_c2f_10", commonField.getFna_c2f_10());
        setValueIfPresent(form2, "fna_c2f_10_20", commonField.getFna_c2f_10_20());
        setValueIfPresent(form2, "fna_c2f_21_30", commonField.getFna_c2f_21_30());
        setValueIfPresent(form2, "fna_c2f_31_40", commonField.getFna_c2f_31_40());
        setValueIfPresent(form2, "fna_c2f_41_50", commonField.getFna_c2f_41_50());
        setValueIfPresent(form2, "fna_c2f_50", commonField.getFna_c2f_50());
        setValueIfPresent(form2, "fna_c3a_2_5", commonField.getFna_c3a_2_5());
        setValueIfPresent(form2, "fna_c3a_6_10", commonField.getFna_c3a_6_10());
        setValueIfPresent(form2, "fna_c3a_11_15", commonField.getFna_c3a_11_15());
        setValueIfPresent(form2, "fna_c3a_16_20", commonField.getFna_c3a_16_20());
        setValueIfPresent(form2, "fna_c3a_20", commonField.getFna_c3a_20());
        setValueIfPresent(form2, "fna_c3a_life", commonField.getFna_c3a_life());
        if(convertStringToNum(commonField.getOthers().get("singlePayAmount")) > 0){
            setValueIfPresent(form2, "fna_c3a_single_pay", "Yes");
        }
        
        setValueIfPresent(form2, "fna_c3b_salary", commonField.getFna_c3b_salary());
        setValueIfPresent(form2, "fna_c3b_income", commonField.getFna_c3b_income());
        setValueIfPresent(form2, "fna_c3b_saving", commonField.getFna_c3b_saving());
        setValueIfPresent(form2, "fna_c3b_investments", commonField.getFna_c3b_investments());
        setValueIfPresent(form2, "fna_c3b_policy", commonField.getFna_c3b_policy());
        setValueIfPresent(form2, "fna_c3b_others", commonField.getFna_c3b_others());
        
        setValueIfPresent(form2, "fna_c3c_yes", commonField.getFna_c3c_yes());
        setValueIfPresent(form2, "fna_c3c_no", commonField.getFna_c3c_no());

        setValueIfPresent(form2, "fna_d_1", commonField.getFna_d_1());
        setValueIfPresent(form2, "fna_d_2", commonField.getFna_d_2());
        setValueIfPresent(form2, "fna_d_3", commonField.getFna_d_3());

    }

    private void HSBCFIN_textBox(PdfAcroForm form, CommonField commonField, Client client){
        //logger.info("Processing HSBCFIN form (ID: 3)");
        /* Page1 Start */
        setValueIfPresent(form, "fill_3", StringUtils.trimToEmpty(StringUtils.trimToEmpty(client.getLastname()) + " " + StringUtils.trimToEmpty(client.getFirstname())));
        
        //setValueIfPresent(form, "fill_3_1", commonField.getOthers().get("name1"));
        //setValueIfPresent(form, "fill_3_2", commonField.getOthers().get("name2"));
        setValueIfPresent(form, "fill_4", commonField.getNameChi());
        setValueIfPresent(form, "fill_5", commonField.getGender());
        setValueIfPresent(form, "fill_6", commonField.getDateOfBirth());
        setValueIfPresent(form, "fill_9", commonField.getOthers().get("empPosition"));

        setValueIfPresent(form, "fill_7", commonField.getMaritalStatus());
        setValueIfPresent(form, "fill_8", commonField.getNoOfDependents());
        setValueIfPresent(form, "fill_10", client.getPhone1Code() + " " + client.getPhone1());;
                                
        if(StringUtils.isNotEmpty(commonField.getTotalAnnualIncome())){
            setValueIfPresent(form, "fill_11",  commonField.getTotalAnnualIncome() ); //annual 
        }
        if(StringUtils.isNotEmpty(commonField.getFna_c1b_amount())){
            setValueIfPresent(form, "fill_12",  commonField.getFna_c1b_amount() ); //annual
        }
        
        setValueIfPresent(form, "fill_12a", addNums(commonField.getFna_c1c_3_amount(), commonField.getFna_c1c_2_amount()));
        setValueIfPresent(form, "fill_13", commonField.getFna_c1c_3_amount());
        setValueIfPresent(form, "fill_14", commonField.getFna_c1c_2_amount());
        setValueIfPresent(form, "fill_16", substractNums(commonField.getTotalAnnualIncome(), substractNums(commonField.getFna_c1b_amount(), addNums(commonField.getFna_c1c_3_amount(), commonField.getFna_c1c_2_amount()))));
        
        /* Page1 End */
        /* Page2 Start */
        setValueIfPresent(form, "fill_01", formatNum(client.getTotalLiquidAssetCurrent()));
        setValueIfPresent(form, "fill_02", commonField.getFna_c2b_amount());
        setValueIfPresent(form, "fill_03", commonField.getFna_c2c_amount());
        setValueIfPresent(form, "fill_04", commonField.getFna_c2d_amount());
        setValueIfPresent(form, "fill_05", commonField.getFna_c2e_amount());

        setValueIfPresent(form, "fill_8_2", commonField.getFna_b1_f_other());
        setValueIfPresent(form, "fill_8_21", commonField.getFna_b1_f_desc());
        /* Page2 End */
        /* Page3 Start */

        setValueIfPresent(form, "fill_1_4", commonField.getFna_b1_a_amount());
        setValueIfPresent(form, "fill_1_4b", commonField.getFna_b1a_4_amount());

        setValueIfPresent(form, "fill_1_4c", commonField.getFna_b1_d_year());
        setValueIfPresent(form, "fill_1_4d", commonField.getFna_b1_d_year());
        setValueIfPresent(form, "fill_1_4e", commonField.getFna_b1_d_amount());

        setValueIfPresent(form, "fill_98_04", commonField.getFna_a_retire());

        /* Page4 End */
        /* Page5 Start */
        setValueIfPresent(form, "Text3", commonField.getFna_c3b_desc());

        
        /* Page5 End */
        if(client != null && client.getConsultantId() != null){
            Consultant consultant = consultantService.find(Long.valueOf(client.getConsultantId())).orElseThrow();

            if(consultant.getName() != null){
                setValueIfPresent(form, "undefined_6", consultant.getName());
            }                            
        }    
        
        setValueIfPresent(form, "fill_1_2", StringUtils.trimToEmpty(StringUtils.trimToEmpty(client.getLastname()) + " " + StringUtils.trimToEmpty(client.getFirstname())));
        
    }

    private void HSBCFIN_checkBox(PDAcroForm form2, CommonField commonField){
        setValueIfPresent(form2, "toggle_1", commonField.getEduPri());
        setValueIfPresent(form2, "toggle_2", commonField.getEduSec());
        setValueIfPresent(form2, "toggle_3", commonField.getEduPostSec());
        setValueIfPresent(form2, "Financial Protection", commonField.getFna_b1_a());
        setValueIfPresent(form2, "Preparation", commonField.getFna_b1_b());
        setValueIfPresent(form2, "Providing", commonField.getFna_b1_c());
        setValueIfPresent(form2, "Saving", commonField.getFna_b1_d());
        setValueIfPresent(form2, "Investment", commonField.getFna_b1_e());
        setValueIfPresent(form2, "Others", commonField.getFna_b1_f());
        setValueIfPresent(form2, "fill_8_2", commonField.getFna_b1_f_other());
        setValueIfPresent(form2, "toggle_91", commonField.getFna_b1_a());
        
        if("yes".equals(commonField.getFna_b1b_1()) || "yes".equals(commonField.getFna_b1b_2()))
            setValueIfPresent(form2, "toggle_93", "yes");

        setValueIfPresent(form2, "toggle_94", commonField.getFna_b1b_3());

        setValueIfPresent(form2, "toggle_4_2", commonField.getFna_b2_a());
        setValueIfPresent(form2, "toggle_5", commonField.getFna_b2_b());
        setValueIfPresent(form2, "toggle_6", commonField.getFna_b2_c());
        setValueIfPresent(form2, "toggle_7", commonField.getFna_b2_d());
        setValueIfPresent(form2, "toggle_8", commonField.getFna_b2_e());
        setValueIfPresent(form2, "toggle_9", commonField.getFna_b2_f());
        setValueIfPresent(form2, "toggle_10", commonField.getFna_b2_g());

        setValueIfPresent(form2, "toggle_1_2", commonField.getFna_c3a_2_5());
        setValueIfPresent(form2, "toggle_2_2", commonField.getFna_c3a_6_10());
        setValueIfPresent(form2, "toggle_3_2", commonField.getFna_c3a_11_15());
        setValueIfPresent(form2, "toggle_4_3", commonField.getFna_c3a_16_20());
        setValueIfPresent(form2, "toggle_5_2", commonField.getFna_c3a_20());
        setValueIfPresent(form2, "toggle_6_2", commonField.getFna_c3a_life());
        setValueIfPresent(form2, "toggle_6_2_sum", commonField.getFna_c3a_single_pay());
        if("Yes".equals(commonField.getFna_c3a_single_pay())){
            setValueIfPresent(form2, "toggle_1c", "Yes");
        }

        if("Yes".equals(commonField.getFna_c3b_investments()) 
            || ("Yes".equals(commonField.getFna_c3b_salary())
            && "Yes".equals(commonField.getFna_c3b_income())
            )
        ){
            setValueIfPresent(form2, "toggle_1f", "Yes");
        }
        if("Yes".equals(commonField.getFna_c3b_saving())
            && "Yes".equals(commonField.getFna_c3b_investments())){
            setValueIfPresent(form2, "toggle_1g", "Yes");
        }
        setValueIfPresent(form2, "toggle_1h", commonField.getFna_c3c_yes());
        setValueIfPresent(form2, "Check Box6", commonField.getFna_c1e_10());
        setValueIfPresent(form2, "Check Box7", commonField.getFna_c1e_10_20());
        setValueIfPresent(form2, "Check Box8", commonField.getFna_c1e_21_30());
        setValueIfPresent(form2, "Check Box9", commonField.getFna_c1e_31_40());
        setValueIfPresent(form2, "Check Box10", commonField.getFna_c1e_41_50());
        setValueIfPresent(form2, "Check Box11", commonField.getFna_c1e_50());
        setValueIfPresent(form2, "Check Box12", commonField.getFna_c2f_10());
        setValueIfPresent(form2, "Check Box13", commonField.getFna_c2f_10_20());
        setValueIfPresent(form2, "Check Box14", commonField.getFna_c2f_21_30());
        setValueIfPresent(form2, "Check Box15", commonField.getFna_c2f_31_40());
        setValueIfPresent(form2, "Check Box16", commonField.getFna_c2f_41_50());
        setValueIfPresent(form2, "Check Box17", commonField.getFna_c2f_50());

        //one way mapping now
        setValueIfPresent(form2, "toggle_1c", commonField.getFna_c3a_single_pay());

        
    }

    private void MLFNA_EN_textBox(PdfAcroForm form, CommonField commonField, Client client){
        /* Page1 Start */
        setValueIfPresent(form, "part1", StringUtils.trimToEmpty(StringUtils.trimToEmpty(client.getLastname()) + " " + StringUtils.trimToEmpty(client.getFirstname())));
        
        setValueIfPresent(form, "part2_1a_amount", commonField.getFna_b1_a_amount());
        setValueIfPresent(form, "part2_1c_amount", commonField.getFna_b1_d_amount());
        
        setValueIfPresent(form, "part2_1f_desc", commonField.getFna_b1_f_other());
        /* Page1 End */
        /* Page2 Start */
        setValueIfPresent(form, "part3_3_1", formatNum(client.getTotalIncomeCurrent()));
        setValueIfPresent(form, "part3_3_2", formatNum(client.getTotalExpenditureCurrent()));

        setValueIfPresent(form, "part3_3_4", commonField.getFna_c2a_amount());
        setValueIfPresent(form, "part3_3_5_2c_other", commonField.getFna_c3b_desc());

        
        //case "undefined_6" -> commonField.setFna_c3b_desc(fieldValue);
        
        setValueIfPresent(form, "part3_3_6_2", commonField.getFna_c1c_3_amount());                            
        /* Page2 End */
        /* Page3 Start */

        /* Page3 End */

        if(client != null && client.getConsultantId() != null){
            Consultant consultant = consultantService.find(Long.valueOf(client.getConsultantId())).orElseThrow();

            if(consultant.getName() != null){
                setValueIfPresent(form, "Full Name of Advisor", consultant.getName());
            }                            
        }   
        setValueIfPresent(form, "Full Name of Applicants", StringUtils.trimToEmpty(StringUtils.trimToEmpty(client.getLastname()) + " " + StringUtils.trimToEmpty(client.getFirstname())));
            
    }

    private void MLFNA_EN_checkBox(PDAcroForm form2, CommonField commonField, Client client){
        /* Page1 Start */                       
        //if(convertStringToNum(commonField.getFna_b1_d_amount()) > 0){
        //    setValueIfPresent(form2, "part2_1c", commonField.getFna_b1_a());
        //}
        // exported year? only can one way from FNA b1 d year
        setValueIfPresent(form2, "part2_1a", commonField.getFna_b1_a());
        setValueIfPresent(form2, "part2_1b", commonField.getFna_b1_c());
        setValueIfPresent(form2, "part2_1c", commonField.getFna_b1_d());
        setValueIfPresent(form2, "part2_1d", commonField.getFna_b1_e());

        setValueIfPresent(form2, "part2_1c_a", commonField.getFna_b2_a());
        setValueIfPresent(form2, "part2_1c_b", commonField.getFna_b2_b());
        setValueIfPresent(form2, "part2_1c_c", commonField.getFna_b2_c());
        setValueIfPresent(form2, "part2_1c_d", commonField.getFna_b2_d());
        setValueIfPresent(form2, "part2_1c_e", commonField.getFna_b2_e());
        setValueIfPresent(form2, "part2_1c_f", commonField.getFna_b2_f());
        setValueIfPresent(form2, "part2_1c_g", commonField.getFna_b2_g());
        
        setValueIfPresent(form2, "part2_1d_1", commonField.getFna_b1b_1());
        setValueIfPresent(form2, "part2_1d_2", commonField.getFna_b1b_2());
        setValueIfPresent(form2, "part2_1d_3", commonField.getFna_b1b_3());
        
        setValueIfPresent(form2, "part2_1e", commonField.getFna_b1_b());
        setValueIfPresent(form2, "part2_1f", commonField.getFna_b1_f());

        setValueIfPresent(form2, "part2_2_a", commonField.getFna_b2_a());
        setValueIfPresent(form2, "part2_2_b", commonField.getFna_b2_b());
        setValueIfPresent(form2, "part2_2_c", commonField.getFna_b2_c());
        setValueIfPresent(form2, "part2_2_d", commonField.getFna_b2_d());
        setValueIfPresent(form2, "part2_2_e", commonField.getFna_b2_e());
        setValueIfPresent(form2, "part2_2_f", commonField.getFna_b2_f());
        setValueIfPresent(form2, "part2_2_g", commonField.getFna_b2_g());
        /* Page1 End */
        /* Page2 Start */
        if(convertStringToNum(client.getCashDepositsCurrent()) > 0){
            setValueIfPresent(form2, "part3_3_5_2a", "Yes");
        }
        if(convertStringToNum(client.getInvestmentsCurrent()) > 0){
            setValueIfPresent(form2, "part3_3_5_2b", "Yes");
        } 
        if(convertStringToNum(client.getOtherLiquidCurrent()) > 0){
            setValueIfPresent(form2, "part3_3_5_2c", "Yes");
        }

        //setValueIfPresent(form2, "part3_3_5_2a", commonField.getFna_c3b_saving());
        //setValueIfPresent(form2, "part3_3_5_2b", commonField.getFna_c3b_investments());
        //setValueIfPresent(form2, "part3_3_5_2c", commonField.getFna_c3b_others());
        //setValueIfPresent(form2, "part3_3_5_2c_other", commonField.getFna_c3b_desc());

        setValueIfPresent(form2, "part3_3_6_yes", commonField.getFna_c3c_yes());
        setValueIfPresent(form2, "part3_3_6_no", commonField.getFna_c3c_no());

        if(convertStringToNum(commonField.getFna_c1c_3_amount()) > 0){
            setValueIfPresent(form2, "part3_3_6_1_yes", "Yes");
            setValueIfPresent(form2, "part3_3_6_1_no", "Off");
        }                            

        /* Page2 End */
        /* Page3 Start */
        setValueIfPresent(form2, "part3_4_4_1a", commonField.getFna_c3a_2_5());
        setValueIfPresent(form2, "part3_4_4_1b", commonField.getFna_c3a_6_10());
        setValueIfPresent(form2, "part3_4_4_1c", commonField.getFna_c3a_11_15());
        setValueIfPresent(form2, "part3_4_4_1d", commonField.getFna_c3a_16_20());
        setValueIfPresent(form2, "part3_4_4_1f", commonField.getFna_c3a_life());
        if("Yes".equals(commonField.getFna_c3a_life()) || "Yes".equals(commonField.getFna_c3a_6_10())
            || "Yes".equals(commonField.getFna_c3a_11_15()) || "Yes".equals(commonField.getFna_c3a_16_20()) || "Yes".equals(commonField.getFna_c3a_20()) ||"Yes".equals(commonField.getFna_c3a_life())){
            setValueIfPresent(form2, "part3_4_regular", "Yes");
        }
        setValueIfPresent(form2, "part3_4_single_pay", commonField.getFna_c3a_single_pay());

        setValueIfPresent(form2, "a Business Earning", commonField.getFna_c3b_salary());
        setValueIfPresent(form2, "b Others Please specify", commonField.getFna_c3b_income());
        setValueIfPresent(form2, "Check Box15", commonField.getFna_c3b_investments());
        setValueIfPresent(form2, "Check Box16", commonField.getFna_c3b_others());

        /* Page3 End */
    }

    private void SLFNA_EN_textBox(PdfAcroForm form, CommonField commonField, Client client){
        /* Page1 Start */
        //setValueIfPresent(form, "name", StringUtils.trimToEmpty(StringUtils.trimToEmpty(client.getLastname()) + " " + StringUtils.trimToEmpty(client.getFirstname())));
    
        //setValueIfPresent(form, "date_of_birth", commonField.getDateOfBirth());
        /*setValueIfPresent(form, "address1", getCrAddress1(client));
        setValueIfPresent(form, "address2", getCrAddress2(client));
        setValueIfPresent(form, "contact", commonField.getContactNo());
        setValueIfPresent(form, "email", commonField.getEmail());
        setValueIfPresent(form, "occupation", commonField.getOccupationTitle());
        */
        if(client != null && client.getConsultantId() != null){
            Consultant consultant = consultantService.find(Long.valueOf(client.getConsultantId())).orElseThrow();

            if(consultant.getName() != null){
                setValueIfPresent(form, "s Names", consultant.getName());
            }                            
        } 
        setValueIfPresent(form, "Policy No", commonField.getOthers().get("SLAppPolicyNo"));
        setValueIfPresent(form, "age", commonField.getOthers().get("SLAppAge"));

        setValueIfPresent(form, "name", StringUtils.trimToEmpty(StringUtils.trimToEmpty(client.getLastname()) + " " + StringUtils.trimToEmpty(client.getFirstname())));
        setValueIfPresent(form, "date_of_birth", commonField.getDateOfBirth());

        setValueIfPresent(form, "contact", client.getPhone1Code() + " " + client.getPhone1());
        setValueIfPresent(form, "email", client.getEmail());
        setValueIfPresent(form, "occupation", commonField.getOthers().get("empPosition"));
        setValueIfPresent(form, "address1", getCrAddress1(client));
        setValueIfPresent(form, "address2", getCrAddress2(client));
        
        setValueIfPresent(form, "1amount", commonField.getFna_b1_d_amount());
        setValueIfPresent(form, "cb1f", commonField.getFna_b1_f_other());

        /* Page1 End */
        /* Page2 Start */
        //setValueIfPresent(form, "4a1", commonField.getFna_c1d_amount());
        
        setValueIfPresent(form, "4a3", commonField.getFna_c1d_amount());
        setValueIfPresent(form, "4b1", commonField.getFna_c2a_amount());
        setValueIfPresent(form, "4b2", commonField.getFna_c2a_desc());
        setValueIfPresent(form, "4b3", commonField.getFna_c2b_amount());        
        
        setValueIfPresent(form, "4b5", substractNums(commonField.getFna_c2a_amount(), commonField.getFna_c2b_amount())); 
        
        //tick cb4c7
        setValueIfPresent(form, "4c3", formatNum(commonField.getOthers().get("singlePayAmount")));
        /* Page2 End */
        
        /* Page4 Start */
        setValueIfPresent(form, "6a2_other1", commonField.getFna_d_desc());

        setValueIfPresent(form, "5obj1", commonField.getOthers().get("recObj1"));
        setValueIfPresent(form, "5obj2", commonField.getOthers().get("recObj2"));
        setValueIfPresent(form, "5obj3", commonField.getOthers().get("recObj3"));
        setValueIfPresent(form, "5obj4", commonField.getOthers().get("recObj4"));
        setValueIfPresent(form, "5obj5", commonField.getOthers().get("recObj5"));
        setValueIfPresent(form, "5obj6", commonField.getOthers().get("recObj6"));

        setValueIfPresent(form, "5name1_1", commonField.getOthers().get("recProd1_1"));
        setValueIfPresent(form, "5name2_1", commonField.getOthers().get("recProd2_1"));
        setValueIfPresent(form, "5name3_1", commonField.getOthers().get("recProd3_1"));
        setValueIfPresent(form, "5name4_1", commonField.getOthers().get("recProd4_1"));
        setValueIfPresent(form, "5name5_1", commonField.getOthers().get("recProd5_1"));
        setValueIfPresent(form, "5name6_1", commonField.getOthers().get("recProd6_1"));
        
        setValueIfPresent(form, "5slected1_1", commonField.getOthers().get("recSelect1_1"));
        setValueIfPresent(form, "5slected2_1", commonField.getOthers().get("recSelect2_1"));
        setValueIfPresent(form, "5slected3_1", commonField.getOthers().get("recSelect3_1"));
        setValueIfPresent(form, "5slected4_1", commonField.getOthers().get("recSelect4_1"));
        setValueIfPresent(form, "5slected5_1", commonField.getOthers().get("recSelect5_1"));
        setValueIfPresent(form, "5slected6_1", commonField.getOthers().get("recSelect6_1"));
        
        /* Page4 End */

        if(client != null && client.getConsultantId() != null){
            Consultant consultant = consultantService.find(Long.valueOf(client.getConsultantId())).orElseThrow();

            if(consultant.getName() != null){
                setValueIfPresent(form, "consultant_name_and_num", consultant.getName());
            }                            
        }    
        setValueIfPresent(form, "applicant_name", StringUtils.trimToEmpty(StringUtils.trimToEmpty(client.getLastname()) + " " + StringUtils.trimToEmpty(client.getFirstname())));
        
    }
    
    private void SLFNA_EN_checkBox(PDAcroForm form2, CommonField commonField){
        /* Page1 Start */
        if("Yes".equals(commonField.getOthers().get("maritalStatusSingle"))){
            setValueIfPresent(form2, "chhs", "Yes"); 
        }
        if("Yes".equals(commonField.getOthers().get("maritalStatusMarried"))){
            setValueIfPresent(form2, "chhm", "Yes"); 
        }
        if("Yes".equals(commonField.getOthers().get("maritalStatusOther"))){
            setValueIfPresent(form2, "chho", "Yes"); 
        } 

        if(convertStringToNum(commonField.getFna_b1_d_amount()) > 0){
            setValueIfPresent(form2, "cb6", "Yes");                                     
        }
        //if(convertStringToNum(commonField.getFna_c1d_amount()) > 0){
        //    setValueIfPresent(form2, "cb4a1", "Yes");                                     
        //}
        logger.info("singlePayAmount:" + commonField.getOthers().get("singlePayAmount") + " " + convertStringToNum(commonField.getOthers().get("singlePayAmount")));
        if(convertStringToNum(commonField.getOthers().get("singlePayAmount")) > 0){
            setValueIfPresent(form2, "cb4c7", "Yes");                                     
        }

        setValueIfPresent(form2, "chh1", commonField.getEduPri()); 
        setValueIfPresent(form2, "chh2", commonField.getEduSec()); 
        setValueIfPresent(form2, "chh3", commonField.getEduPostSec()); 
        if("Yes".equals(commonField.getEduUni())){
            setValueIfPresent(form2, "chh3", "Off");
            setValueIfPresent(form2, "chh4", commonField.getEduUni());
        }

        setValueIfPresent(form2, "chh5", commonField.getFna_a_life_0()); 
        setValueIfPresent(form2, "chh6", commonField.getFna_a_life_less_5()); 
        setValueIfPresent(form2, "chh7", commonField.getFna_a_life_above_5()); 

        setValueIfPresent(form2, "cb1a", commonField.getFna_b1_a()); 
        setValueIfPresent(form2, "cb1b", commonField.getFna_b1_b()); 
        setValueIfPresent(form2, "cb1c", commonField.getFna_b1_c()); 
        setValueIfPresent(form2, "cb1d", commonField.getFna_b1_d()); 
        setValueIfPresent(form2, "cb1e", commonField.getFna_b1_e()); 

        setValueIfPresent(form2, "cb10", commonField.getFna_b1b_1());
        setValueIfPresent(form2, "cb11", commonField.getFna_b1b_2());
        setValueIfPresent(form2, "cb12", commonField.getFna_b1b_3());

        setValueIfPresent(form2, "cb13", commonField.getFna_b2_a());
        setValueIfPresent(form2, "cb14", commonField.getFna_b2_b());
        setValueIfPresent(form2, "cb15", commonField.getFna_b2_c());
        setValueIfPresent(form2, "cb16", commonField.getFna_b2_d());
        setValueIfPresent(form2, "cb17", commonField.getFna_b2_e());
        setValueIfPresent(form2, "cb18", commonField.getFna_b2_f());
        setValueIfPresent(form2, "cb19", commonField.getFna_b2_g());

        /* Page1 END */
        /* Page2 Start */                                           
        //tick chech > 0
        if(convertStringToNum(commonField.getFna_c1d_amount()) > 0){
            setValueIfPresent(form2, "cb4a2", "Yes");
            setValueIfPresent(form2, "cb4a2f", "Yes");
        }
        setValueIfPresent(form2, "cb4b1", commonField.getFna_c2a_cash());
        setValueIfPresent(form2, "cb4b2", commonField.getFna_c2a_bank_account());
        setValueIfPresent(form2, "cb4b3", commonField.getFna_c2a_market_account());
        setValueIfPresent(form2, "cb4b4", commonField.getFna_c2a_stocks());
        setValueIfPresent(form2, "cb4b5", commonField.getFna_c2a_bonds());
        setValueIfPresent(form2, "cb4b6", commonField.getFna_c2a_us());
        setValueIfPresent(form2, "cb4b7", commonField.getFna_c2a_others());

        setValueIfPresent(form2, "cb4c1", commonField.getFna_c3a_2_5());
        setValueIfPresent(form2, "cb4c2", commonField.getFna_c3a_6_10());
        setValueIfPresent(form2, "cb4c3", commonField.getFna_c3a_11_15());
        setValueIfPresent(form2, "cb4c4", commonField.getFna_c3a_16_20());
        setValueIfPresent(form2, "cb4c5", commonField.getFna_c3a_20());
        setValueIfPresent(form2, "cb4c6", commonField.getFna_c3a_life());
        
        
        setValueIfPresent(form2, "cb4d1", commonField.getFna_c1e_10());
        setValueIfPresent(form2, "cb4d2", commonField.getFna_c1e_10_20());
        setValueIfPresent(form2, "cb4d3", commonField.getFna_c1e_21_30());  
        setValueIfPresent(form2, "cb4d4", commonField.getFna_c1e_31_40());
        setValueIfPresent(form2, "cb4d5", commonField.getFna_c1e_41_50());
        setValueIfPresent(form2, "cb4d6", commonField.getFna_c1e_50());

        setValueIfPresent(form2, "cb4e1", commonField.getFna_c3b_salary());
        setValueIfPresent(form2, "cb4e2", commonField.getFna_c3b_income());
        setValueIfPresent(form2, "cb4e3", commonField.getFna_c3b_investments());
        setValueIfPresent(form2, "cb4e4", commonField.getFna_c3b_saving());
        setValueIfPresent(form2, "cb4e5", commonField.getFna_c3b_others());
        
        setValueIfPresent(form2, "cb4h1", commonField.getFna_c3c_yes());
        setValueIfPresent(form2, "cb4h2", commonField.getFna_c3c_no());
        
        /* Page2 End */

        /* Page4 Start */
        setValueIfPresent(form2, "cb6a1", commonField.getFna_d_1());
        setValueIfPresent(form2, "cb6a2", commonField.getFna_d_3());                        
        /* Page4 End */
    }

    private void SLAPP_textBox(PdfAcroForm form, CommonField commonField, Client client){
        /* Page1 Start */
        if(client != null && client.getConsultantId() != null){
            Consultant consultant = consultantService.find(Long.valueOf(client.getConsultantId())).orElseThrow();

            if(consultant.getName() != null){
                setValueIfPresent(form, "inter1", consultant.getName());
            }                            
        }  
        
        setValueIfPresent(form, "1_1_surname", client.getLastname());
        setValueIfPresent(form, "1_1_given_name", client.getFirstname());

        setValueIfPresent(form, "1_2_name_ch", commonField.getNameChi());

        setValueIfPresent(form, "1_6_dd", commonField.getDdDateOfBirth());
        setValueIfPresent(form, "1_6_mm", commonField.getMmDateOfBirth());
        setValueIfPresent(form, "1_6_yyyy", commonField.getYyyyDateOfBirth());

        setValueIfPresent(form, "1_7_country", commonField.getPlaceOfBirth());
        setValueIfPresent(form, "1_8", commonField.getCountryOfCitizenship());

        //page 2
        setValueIfPresent(form, "1_12_3", commonField.getOthers().get("workHighDesc"));
        
        
        if("Yes".equals(commonField.getOthers().get("hkidPerm")) || "Yes".equals(commonField.getOthers().get("hkidNon")))
            setValueIfPresent(form, "1_10_id_num", commonField.getIdCard());
        else if("Yes".equals(commonField.getOthers().get("prcId")))
            setValueIfPresent(form, "1_10_num", commonField.getIdCard());
        else if(StringUtils.trimToNull(commonField.getPassportNo()) != null || "Yes".equals(commonField.getOthers().get("passportYes")) || "Yes".equals(commonField.getOthers().get("travelDocYes")) ){
            setValueIfPresent(form, "1_10_passport_num", commonField.getPassportNo());

            setValueIfPresent(form, "1_10_passport_dd", commonField.getOthers().get("passportExpiryDD"));
            setValueIfPresent(form, "1_10_passport_mm", commonField.getOthers().get("passportExpiryMM"));
            setValueIfPresent(form, "1_10_passport_yyyy", commonField.getOthers().get("passportExpiryYYYY"));
            
            
        }
            
        /*
        if("HK".equals(commonField.getCountryOfIssue()) || "Hong Kong".equals(commonField.getCountryOfIssue())){
            setValueIfPresent(form, "1_10_id_num", commonField.getIdCard());
        }*/

        setValueIfPresent(form, "1_8", commonField.getCountryOfCitizenship());
        
        setValueIfPresent(form, "1_12_1", commonField.getOthers().get("empPosition"));
        setValueIfPresent(form, "1_12_2", commonField.getOthers().get("empDuties"));
        
        setValueIfPresent(form, "1_12_5", commonField.getTotalAnnualIncome());
        if(commonField.getTotalAnnualIncome() != null && !commonField.getTotalAnnualIncome().isBlank()){
            setValueIfPresent(form, "1_12_5_usd", "USD");
            setValueIfPresent(form, "1_12_5_pa", "P.A.");
        }
        setValueIfPresent(form, "1_12_6", commonField.getOthers().get("empCompanyName"));
        
        setValueIfPresent(form, "1_12_7_1", commonField.getOthers().get("empCompanyAddress"));
        
        setValueIfPresent(form, "1_12_8_1", commonField.getOthers().get("empNatureA"));
        setValueIfPresent(form, "1_12_8_2", commonField.getOthers().get("empNatureB"));
        
        /*
        setValueIfPresent(form, "ch1_13_rm", commonField.getCrAddressRoom());
        setValueIfPresent(form, "ch1_13_floor", commonField.getCrAddressFloor());
        setValueIfPresent(form, "ch1_13_block", commonField.getCrAddressBlock());
        setValueIfPresent(form, "ch1_13_building", commonField.getCrAddressBuilding());
        setValueIfPresent(form, "ch1_13_street", commonField.getCrAddressStreet());
        setValueIfPresent(form, "ch1_13_country", commonField.getCrAddressCountry());
        setValueIfPresent(form, "1_13_zip", commonField.getCrAddressPostalCode());
        
        setValueIfPresent(form, "ch1_13_corr_rm", commonField.getCorAddressRoom());
        setValueIfPresent(form, "ch1_13_corr_floor", commonField.getCorAddressFloor());
        setValueIfPresent(form, "ch1_13_corr_block", commonField.getCorAddressBlock());
        setValueIfPresent(form, "ch1_13_corr_building", commonField.getCorAddressBuilding());
        setValueIfPresent(form, "ch1_13_corr_street", commonField.getCorAddressStreet());
        setValueIfPresent(form, "ch1_13_corr_zip", commonField.getCorAddressPostalCode());
            */
        setValueIfPresent(form, "ch1_13_rm", client.getCrAddressRoom());
        setValueIfPresent(form, "ch1_13_floor", client.getCrAddressFloor());
        setValueIfPresent(form, "ch1_13_block", client.getCrAddressBlock());
        setValueIfPresent(form, "ch1_13_building", client.getCrAddressBuilding());
        setValueIfPresent(form, "ch1_13_street", client.getCrAddressStreet());
        setValueIfPresent(form, "ch1_13_country", client.getCrAddressArea() + " " +client.getCrAddressCountry());
        setValueIfPresent(form, "1_13_zip", client.getCrAddressPostalCode());
        /*
        if("HK".equals(client.getCrAddressArea()))
            setValueIfPresent(form, "ch1_13_hk", "Yes");
        if("KLN".equals(client.getCrAddressArea()) || "KL".equals(client.getCrAddressArea()) || "KWOLOON".equals(client.getCrAddressArea()))
            setValueIfPresent(form, "ch1_13_kln", "Yes");
        if("NT".equals(client.getCrAddressArea()))
            setValueIfPresent(form, "ch1_13_nt", "Yes");
            */

        setValueIfPresent(form, "ch1_13_corr_rm", client.getCorAddressRoom());
        setValueIfPresent(form, "ch1_13_corr_floor", client.getCorAddressFloor());
        setValueIfPresent(form, "ch1_13_corr_block", client.getCorAddressBlock());
        setValueIfPresent(form, "ch1_13_corr_building", client.getCorAddressBuilding());
        setValueIfPresent(form, "ch1_13_corr_street", client.getCorAddressStreet());
        setValueIfPresent(form, "ch1_13_corr_country", client.getCorAddressArea() + " " + client.getCorAddressCountry());
        setValueIfPresent(form, "ch1_13_corr_zip", client.getCorAddressPostalCode());
        setValueIfPresent(form, "ch1_13_corr_hk", commonField.getOthers().get("corAddressHk"));
        setValueIfPresent(form, "ch1_13_corr_kln", commonField.getOthers().get("corAddressKln"));
        setValueIfPresent(form, "ch1_13_corr_nt", commonField.getOthers().get("corAddressNt"));
        
        setValueIfPresent(form, "1_13_tel_mobile_code", client.getPhone1Code());
        setValueIfPresent(form, "1_13_tel_mobile", client.getPhone1());
        setValueIfPresent(form, "1_13_delete", client.getEmail());
        
        setValueIfPresent(form, "1_14d_tax1", commonField.getTaxResidency1());
        setValueIfPresent(form, "1_14d_tax_num1", commonField.getTaxPin1());
        setValueIfPresent(form, "1_14d_explain1", commonField.getTaxReasonB1());
        setValueIfPresent(form, "1_14d_explain1a", commonField.getOthers().get("TaxReasonB1a"));
        
        setValueIfPresent(form, "1_14d_tax2", commonField.getTaxResidency2());
        setValueIfPresent(form, "1_14d_tax_num2", commonField.getTaxPin2());
        setValueIfPresent(form, "1_14d_explain2", commonField.getTaxReasonB2());
        setValueIfPresent(form, "1_14d_explain2a", commonField.getOthers().get("TaxReasonB2a"));
        
        setValueIfPresent(form, "1_14d_tax3", commonField.getTaxResidency3());
        setValueIfPresent(form, "1_14d_tax_num3", commonField.getTaxPin3());
        setValueIfPresent(form, "1_14d_explain3", commonField.getTaxReasonB3());
        setValueIfPresent(form, "1_14d_explain3a", commonField.getOthers().get("TaxReasonB3a"));
        
        /*
        setValueIfPresent(form, "4_1_name1_1", commonField.getInsuranceCompany1_1());
        setValueIfPresent(form, "4_1_name1_2", commonField.getInsuranceCompany1_2());
        setValueIfPresent(form, "4_1_year1", commonField.getInsuranceYear1());
        setValueIfPresent(form, "4_1_currency1", commonField.getInsuranceCurrency1());
        setValueIfPresent(form, "4_1_sum1_1", commonField.getOthers().get("insuranceSumInsured1_1"));
        setValueIfPresent(form, "4_1_sum1_2", commonField.getOthers().get("insuranceSumInsured1_2"));
        setValueIfPresent(form, "4_1_sum1_3", commonField.getOthers().get("insuranceSumInsured1_3"));
        
        setValueIfPresent(form, "4_1_name2_1", commonField.getInsuranceCompany2_1());
        setValueIfPresent(form, "4_1_name2_2", commonField.getInsuranceCompany2_2());
        setValueIfPresent(form, "4_1_year2", commonField.getInsuranceYear2());
        setValueIfPresent(form, "4_1_currency2", commonField.getInsuranceCurrency2());
        setValueIfPresent(form, "4_1_sum2_1", commonField.getOthers().get("insuranceSumInsured2_1"));
        setValueIfPresent(form, "4_1_sum2_2", commonField.getOthers().get("insuranceSumInsured2_2"));
        setValueIfPresent(form, "4_1_sum2_3", commonField.getOthers().get("insuranceSumInsured2_3"));
        
        setValueIfPresent(form, "4_1_name3_1", commonField.getInsuranceCompany3_1());
        setValueIfPresent(form, "4_1_name3_2", commonField.getInsuranceCompany3_2());
        setValueIfPresent(form, "4_1_year3", commonField.getInsuranceYear3());
        setValueIfPresent(form, "4_1_currency3", commonField.getInsuranceCurrency3());
        setValueIfPresent(form, "4_1_sum3_1", commonField.getOthers().get("insuranceSumInsured3_1"));
        setValueIfPresent(form, "4_1_sum3_2", commonField.getOthers().get("insuranceSumInsured3_2"));
        setValueIfPresent(form, "4_1_sum3_3", commonField.getOthers().get("insuranceSumInsured3_3"));
        */
       setValueIfPresent(form, "others_funds_desc", commonField.getFna_c3b_desc());
    }

    private void SLAPP_checkBox(PDAcroForm form2, CommonField commonField){
        setValueIfPresent(form2, "hnm", commonField.getOthers().get("formNonMedical"));
        setValueIfPresent(form2, "hm", commonField.getOthers().get("formMedical"));
        
        /* Page1 Start */
        setValueIfPresent(form2, "ch1_4_m", commonField.getGenderMale());
        setValueIfPresent(form2, "ch1_4_f", commonField.getGenderFemale());

        setValueIfPresent(form2, "1_11_s", commonField.getOthers().get("maritalStatusSingle"));
        setValueIfPresent(form2, "1_11_m", commonField.getOthers().get("maritalStatusMarried"));
        setValueIfPresent(form2, "1_11_o", commonField.getOthers().get("maritalStatusOther"));

        if("Yes".equals(commonField.getOthers().get("hkidPerm")) 
            || "Yes".equals(commonField.getOthers().get("hkidNon"))
        ){
            setValueIfPresent(form2, "1_10_1", commonField.getOthers().get("hkidPerm"));
            setValueIfPresent(form2, "1_10_2", commonField.getOthers().get("hkidNon"));
        }else if("Yes".equals(commonField.getOthers().get("prcId"))){
            setValueIfPresent(form2, "1_10_3", commonField.getOthers().get("prcId"));
        }else if(StringUtils.trimToNull(commonField.getPassportNo()) != null || "Yes".equals(commonField.getOthers().get("passportYes")) || "Yes".equals(commonField.getOthers().get("travelDocYes")) ){
            setValueIfPresent(form2, "1_10_6", "Yes");
                    
        }

        setValueIfPresent(form2, "ch1_5_s", commonField.getTobarccoYes());
        setValueIfPresent(form2, "ch1_5_n", commonField.getTobarccoNo());
        
        //page 2
        setValueIfPresent(form2, "ch1_12_yes", commonField.getOthers().get("workHighYes"));
        setValueIfPresent(form2, "ch1_12_no", commonField.getOthers().get("workHighNo"));
        
        /*
        if(!form2.getField("1_14d_tax1").getValueAsString().isBlank()){
            setValueIfPresent(form2, "ch1_14d_reason1_b", "On");
            setValueIfPresent(form2, "ch1_14d_reason1_b", "On");
            setValueIfPresent(form2, "ch1_14d_reason1_b", "On");
        }           
        if(!form2.getField("1_14d_tax2").getValueAsString().isBlank()){
            setValueIfPresent(form2, "ch1_14d_reason2_b", "On");
            setValueIfPresent(form2, "ch1_14d_reason2_b", "On");
            setValueIfPresent(form2, "ch1_14d_reason2_b", "On");
        }     
        if(!form2.getField("1_14d_tax3").getValueAsString().isBlank()){
            setValueIfPresent(form2, "ch1_14d_reason3_b", "On");
            setValueIfPresent(form2, "ch1_14d_reason3_b", "On");
            setValueIfPresent(form2, "ch1_14d_reason3_b", "On");
        }                
        
        if("A".equals(commonField.getTaxReason1())){
            setValueIfPresent(form2, "ch1_14d_reason1_a", "Off");
        }
        if("B".equals(commonField.getTaxReason1())){
            setValueIfPresent(form2, "ch1_14d_reason1_b", "Off");
        }
        if("C".equals(commonField.getTaxReason1())){
            setValueIfPresent(form2, "ch1_14d_reason1_c", "Yes");
        }
        
        if("A".equals(commonField.getTaxReason2())){
            setValueIfPresent(form2, "ch1_14d_reason2_a", "Yes");
        }
        if("B".equals(commonField.getTaxReason2())){
            setValueIfPresent(form2, "ch1_14d_reason2_b", "Yes");
        }
        if("C".equals(commonField.getTaxReason2())){
            setValueIfPresent(form2, "ch1_14d_reason2_c", "Yes");
        }
        
        if("A".equals(commonField.getTaxReason3())){
            setValueIfPresent(form2, "ch1_14d_reason3_a", "Yes");
        }
        if("B".equals(commonField.getTaxReason3())){
            setValueIfPresent(form2, "ch1_14d_reason3_b", "Yes");
        }
        if("C".equals(commonField.getTaxReason3())){
            setValueIfPresent(form2, "ch1_14d_reason3_c", "Yes");
        }
        */
        
        setValueIfPresent(form2, "ch2_5_1p", commonField.getEduPri());
        setValueIfPresent(form2, "ch2_5_1s", commonField.getEduSec());
        setValueIfPresent(form2, "ch2_5_1m", commonField.getEduPostSec());
        if("Yes".equals(commonField.getEduUni())){
            setValueIfPresent(form2, "ch2_5_1m", "Off");
            setValueIfPresent(form2, "ch2_5_1u", commonField.getEduUni());
        }

        setValueIfPresent(form2, "ch2_5_2w", commonField.getFna_a_life_0());
        setValueIfPresent(form2, "ch2_5_2_less5", commonField.getFna_a_life_less_5());
        setValueIfPresent(form2, "ch2_5_2_5above", commonField.getFna_a_life_above_5());
        
        if("Yes".equals(commonField.getInsuranceLife1())){
            setValueIfPresent(form2, "ch4_1_life", "Off");
            setValueIfPresent(form2, "ch4_1_accident", "On");
            setValueIfPresent(form2, "ch4_1_critical", "On");
            setValueIfPresent(form2, "ch4_1_hospital", "On");
        }else if("Yes".equals(commonField.getInsuranceCritical1())){
            setValueIfPresent(form2, "ch4_1_life", "On");
            setValueIfPresent(form2, "ch4_1_accident", "On");
            setValueIfPresent(form2, "ch4_1_critical", "Off");
            setValueIfPresent(form2, "ch4_1_hospital", "On");
        }else if("Yes".equals(commonField.getInsuranceOther1())
            && "Accident".equals(commonField.getInsuranceOtherDesc1())){
            setValueIfPresent(form2, "ch4_1_life", "On");
            setValueIfPresent(form2, "ch4_1_accident", "Off");
            setValueIfPresent(form2, "ch4_1_critical", "On");
            setValueIfPresent(form2, "ch4_1_hospital", "On");
        }else if("Yes".equals(commonField.getInsuranceOther1())
            && "Hospital".equals(commonField.getInsuranceOtherDesc1())){
            setValueIfPresent(form2, "ch4_1_life", "On");
            setValueIfPresent(form2, "ch4_1_accident", "On");
            setValueIfPresent(form2, "ch4_1_critical", "On");
            setValueIfPresent(form2, "ch4_1_hospital", "Off");
        }
        
        if("Yes".equals(commonField.getInsuranceLife2())){
            setValueIfPresent(form2, "ch4_2_life", "Off");
            setValueIfPresent(form2, "ch4_2_accident", "On");
            setValueIfPresent(form2, "ch4_2_critical", "On");
            setValueIfPresent(form2, "ch4_2_hospital", "On");
        }else if("Yes".equals(commonField.getInsuranceCritical2())){
            setValueIfPresent(form2, "ch4_2_life", "On");
            setValueIfPresent(form2, "ch4_2_accident", "On");
            setValueIfPresent(form2, "ch4_2_critical", "Off");
            setValueIfPresent(form2, "ch4_2_hospital", "On");
        }else if("Yes".equals(commonField.getInsuranceOther2())
            && "Accident".equals(commonField.getInsuranceOtherDesc2())){
            setValueIfPresent(form2, "ch4_2_life", "On");
            setValueIfPresent(form2, "ch4_2_accident", "Off");
            setValueIfPresent(form2, "ch4_2_critical", "On");
            setValueIfPresent(form2, "ch4_2_hospital", "On");
        }else if("Yes".equals(commonField.getInsuranceOther2())
            && "Hospital".equals(commonField.getInsuranceOtherDesc2())){
            setValueIfPresent(form2, "ch4_2_life", "On");
            setValueIfPresent(form2, "ch4_2_accident", "On");
            setValueIfPresent(form2, "ch4_2_critical", "On");
            setValueIfPresent(form2, "ch4_2_hospital", "Off");
        }

        if("Yes".equals(commonField.getInsuranceLife3())){
            setValueIfPresent(form2, "ch4_3_life", "Off");
            setValueIfPresent(form2, "ch4_3_accident", "On");
            setValueIfPresent(form2, "ch4_3_critical", "On");
            setValueIfPresent(form2, "ch4_3_hospital", "On");
        }else if("Yes".equals(commonField.getInsuranceCritical3())){
            setValueIfPresent(form2, "ch4_3_life", "On");
            setValueIfPresent(form2, "ch4_3_accident", "On");
            setValueIfPresent(form2, "ch4_3_critical", "Off");
            setValueIfPresent(form2, "ch4_3_hospital", "On");
        }else if("Yes".equals(commonField.getInsuranceOther3())
            && "Accident".equals(commonField.getInsuranceOtherDesc3())){
            setValueIfPresent(form2, "ch4_3_life", "On");
            setValueIfPresent(form2, "ch4_3_accident", "Off");
            setValueIfPresent(form2, "ch4_3_critical", "On");
            setValueIfPresent(form2, "ch4_3_hospital", "On");
        }else if("Yes".equals(commonField.getInsuranceOther3())
            && "Hospital".equals(commonField.getInsuranceOtherDesc3())){
            setValueIfPresent(form2, "ch4_3_life", "On");
            setValueIfPresent(form2, "ch4_3_accident", "On");
            setValueIfPresent(form2, "ch4_3_critical", "On");
            setValueIfPresent(form2, "ch4_3_hospital", "Off");
        }

        setValueIfPresent(form2, "ch1_13_hk", commonField.getOthers().get("crAddressHk"));
        setValueIfPresent(form2, "ch1_13_kln", commonField.getOthers().get("crAddressKln"));
        setValueIfPresent(form2, "ch1_13_nt", commonField.getOthers().get("crAddressNt"));

        setValueIfPresent(form2, "ch1_13_corr_hk", commonField.getOthers().get("corAddressHk"));
        setValueIfPresent(form2, "ch1_13_corr_kln", commonField.getOthers().get("corAddressKln"));
        setValueIfPresent(form2, "ch1_13_corr_nt", commonField.getOthers().get("corAddressNt"));                        
    
        setValueIfPresent(form2, "de_yes", commonField.getReplaceInsuranceYes());
        setValueIfPresent(form2, "de_no", commonField.getReplaceInsuranceNo());
        setValueIfPresent(form2, "de_not", commonField.getOthers().get("replaceInsuranceNotYet"));
         
        setValueIfPresent(form2, "salary", commonField.getFna_c3b_salary());
        setValueIfPresent(form2, "investment", commonField.getFna_c3b_investments());
        setValueIfPresent(form2, "savings", commonField.getFna_c3b_saving());
        setValueIfPresent(form2, "rental_income", commonField.getFna_c3b_income());
        setValueIfPresent(form2, "others", commonField.getFna_c3b_others());
        
        // case "policy_replacement" -> commonField.setFna_c3b_policy(fieldValue);\
    }
        
    private void HSBCA31_textBox(PdfAcroForm form, CommonField commonField, Client client){
        /* Page1 Start */
        setValueIfPresent(form, "fill_15", StringUtils.trimToEmpty(client.getLastname()));
        setValueIfPresent(form, "fill_16", StringUtils.trimToEmpty(client.getFirstname()));
        //setValueIfPresent(form, "applicant_name", StringUtils.trimToEmpty(StringUtils.trimToEmpty(client.getLastname()) + " " + StringUtils.trimToEmpty(client.getFirstname())));

        setValueIfPresent(form, "fill_17", commonField.getNameChi());

        if("Yes".equals(commonField.getOthers().get("hkidNon")) || "Yes".equals(commonField.getOthers().get("hkidPerm"))){
            setValueIfPresent(form, "Text1", commonField.getIdCard());
        //}else if("Yes".equals(commonField.getOthers().get("prcId"))){
        //    setValueIfPresent(form, "ID1", commonField.getIdCard());
        }else if("Yes".equals(commonField.getOthers().get("passportYes")) || "Yes".equals(commonField.getOthers().get("travelDocYes")) ){
            setValueIfPresent(form, "passportNo", commonField.getPassportNo());
            setValueIfPresent(form, "Text12", commonField.getCountryOfIssue());
        }
        
        setValueIfPresent(form, "fill_18", commonField.getDateOfBirth());
        setValueIfPresent(form, "fill_18", commonField.getDateOfBirth());
        setValueIfPresent(form, "fill_19", commonField.getCountryOfCitizenship());
        setValueIfPresent(form, "fill_20", commonField.getPlaceOfBirth());
        /* Page1 End */
        /* Page2 Start */
        setValueIfPresent(form, "Text16_1", getCrAddress1(client));
        setValueIfPresent(form, "Text16_2", getCrAddress2(client));
        setValueIfPresent(form, "fill_2b_1", client.getCrAddressPostalCode());

        //setValueIfPresent(form, "address1", commonField.getOthers().get("address1"));
        //setValueIfPresent(form, "address2", commonField.getOthers().get("address2"));
                  
        setValueIfPresent(form, "fill_12", client.getPhone1Code());
        setValueIfPresent(form, "undefined_6",  client.getPhone1());

        setValueIfPresent(form, "Text182", client.getEmail());

        setValueIfPresent(form, "Text174", commonField.getOthers().get("empCompanyName"));
        setValueIfPresent(form, "Text173_1", StringUtils.trimToNull(StringUtils.trimToEmpty(StringUtils.trimToEmpty(commonField.getOthers().get("empNatureA")) + " " + StringUtils.trimToEmpty(commonField.getOthers().get("empNatureB")))));
        setValueIfPresent(form, "fill_16_2", commonField.getOthers().get("empPosition"));
        setValueIfPresent(form, "fill_17_1", commonField.getOthers().get("empCompanyAddress"));

        String taxId = "";
        String taxCountry = "";

        if(!"".equals(StringUtils.trimToEmpty(commonField.getTaxPin1()))){
            taxId += StringUtils.trimToEmpty(commonField.getTaxPin1()) + " ";
            taxCountry += StringUtils.trimToEmpty(commonField.getTaxResidency1()) + "";
        }
        if(!"".equals(StringUtils.trimToEmpty(commonField.getTaxPin2()))){
            taxId += StringUtils.trimToEmpty(commonField.getTaxPin2()) + " ";
            taxCountry += StringUtils.trimToEmpty(commonField.getTaxResidency2()) + "";
        }
        if(!"".equals(StringUtils.trimToEmpty(commonField.getTaxPin3()))){
            taxId += StringUtils.trimToEmpty(commonField.getTaxPin3()) + " ";
            taxCountry += StringUtils.trimToEmpty(commonField.getTaxResidency3()) + "";
        }

        setValueIfPresent(form, "fill_17_3", StringUtils.trimToEmpty(taxId));
        setValueIfPresent(form, "fill_0004", StringUtils.trimToEmpty(taxCountry));
        
        /* Page2 End */
        /* Page3 Start */
        //setValueIfPresent(form, "undefined_51", commonField.getContactNo());
        /* Page3 End */
        /* Page10 Start */
        /*
        setValueIfPresent(form, "Text164", commonField.getOthers().get("empCompanyName"));
        setValueIfPresent(form, "Text163", StringUtils.trimToNull(StringUtils.trimToEmpty(StringUtils.trimToEmpty(commonField.getOthers().get("empNatureA")) + " " + StringUtils.trimToEmpty(commonField.getOthers().get("empNatureB")))));
        setValueIfPresent(form, "fill_14", commonField.getOthers().get("empPosition"));
        setValueIfPresent(form, "fill_15_3", commonField.getOthers().get("empCompanyAddress"));
         */
        /* Page10 End */
        /* Page12 Start */
        setValueIfPresent(form, "undefined_17ha_1", commonField.getInsuranceCompany1_1());
        setValueIfPresent(form, "undefined_17hk_1", commonField.getOthers().get("insuranceSumInsured1_1"));

        setValueIfPresent(form, "undefined_17hl", commonField.getInsuranceYear1());

        setValueIfPresent(form, "undefined_17hn_1", commonField.getInsuranceCompany2_1());
        setValueIfPresent(form, "undefined_17ho_1", commonField.getOthers().get("insuranceSumInsured2_1"));
        //setValueIfPresent(form, "undefined_17ho_3", commonField.getOthers().get("insuranceSumInsured2_3"));
        setValueIfPresent(form, "undefined_17hp", commonField.getInsuranceYear1());
        
        setValueIfPresent(form, "undefined_17hr_1", commonField.getInsuranceCompany3_1());
        //setValueIfPresent(form, "undefined_17hr_3", commonField.getInsuranceCompany3_3());
        setValueIfPresent(form, "undefined_17hsb_1", commonField.getOthers().get("insuranceSumInsured3_1"));
        //setValueIfPresent(form, "undefined_17hsb_3", commonField.getOthers().get("insuranceSumInsured3_3"));
        setValueIfPresent(form, "undefined_17ht", commonField.getInsuranceYear1());
        
        setValueIfPresent(form, "fill_2_6", commonField.getUltimateTotalLife());
        setValueIfPresent(form, "fill_2_6e", commonField.getDeclinedDesc());
        setValueIfPresent(form, "fill_15_7y", commonField.getDeclinedDesc());
        
        setValueIfPresent(form, "fill_15_7", commonField.getOthers().get("workHighDesc"));
        /* Page12 End */
        /* Page13 Start */
        setValueIfPresent(form, "fill_9_6", formatNum(client.getSalaryCurrent()));
        setValueIfPresent(form, "fill_1k0_5", formatNum(client.getSalaryLast()));
        setValueIfPresent(form, "fill_13_4", formatNum(client.getBonusCurrent()));
        setValueIfPresent(form, "fill_14_4", formatNum(client.getBonusLast()));
        setValueIfPresent(form, "fill_17_7", formatNum(client.getCompanyInterestCurrent()));
        setValueIfPresent(form, "fill_18_6", formatNum(client.getCompanyInterestLast()));
        setValueIfPresent(form, "fill_2k1_5", formatNum(client.getInvestmentIncomeCurrent()));
        setValueIfPresent(form, "fill_2k2_5", formatNum(client.getInvestmentIncomeLast()));
        setValueIfPresent(form, "fill_2k9_3", formatNum(client.getDividendsCurrent()));
        setValueIfPresent(form, "fill_3k0_3", formatNum(client.getDividendsLast()));
        setValueIfPresent(form, "fill_k33_3", formatNum(client.getRentalsCurrent()));
        setValueIfPresent(form, "fill_34_2", formatNum(client.getRentalsLast()));
        setValueIfPresent(form, "fill_k37_2", formatNum(client.getOtherUnearnedCurrent()));
        setValueIfPresent(form, "fill_38_2", formatNum(client.getOtherUnearnedLast()));
        setValueIfPresent(form, "fill_37_2", formatNum(client.getTotalIncomeCurrent()));
        setValueIfPresent(form, "fill_38_222", formatNum(client.getTotalIncomeLast()));        
        
        setValueIfPresent(form, "fill_1k1_5", formatNum(client.getMortgageCurrent()));
        setValueIfPresent(form, "fill_12_511", formatNum(client.getMortgageLast()));
        setValueIfPresent(form, "fill_15_8", formatNum(client.getRentCurrent()));
        setValueIfPresent(form, "fill_16_7", formatNum(client.getRentLast()));
        setValueIfPresent(form, "fill_19_4", formatNum(client.getSchoolingCurrent()));
        setValueIfPresent(form, "fill_2k0_4", formatNum(client.getSchoolingLast()));
        setValueIfPresent(form, "fill_2k3_5", formatNum(client.getMembershipsCurrent()));
        setValueIfPresent(form, "fill_24_5", formatNum(client.getMembershipsLast()));
        setValueIfPresent(form, "fill_3k1_3", addNums(formatNum(client.getOtherExpenditureCurrent()), formatNum(client.getOtherPrefFinanceCurrent())));
        setValueIfPresent(form, "fill_32_2", addNums(formatNum(client.getOtherExpenditureLast()), formatNum(client.getOtherPrefFinanceLast())));
        setValueIfPresent(form, "fill_35_2", formatNum(client.getInterestCurrent()));
        setValueIfPresent(form, "fill_36_2", formatNum(client.getInterestLast()));
        setValueIfPresent(form, "fill_39_212", formatNum(client.getPrincipalCurrent()));
        setValueIfPresent(form, "fill_36_2", formatNum(client.getPrincipalLast()));
        setValueIfPresent(form, "fill_39_2", formatNum(client.getTotalExpenditureCurrent()));
        setValueIfPresent(form, "fill_40", formatNum(client.getTotalExpenditureLast()));

        setValueIfPresent(form, "fill_4114", formatNum(client.getCashDepositsCurrent()));
        setValueIfPresent(form, "fill_4215", formatNum(client.getCashDepositsLast()));
        setValueIfPresent(form, "fill_4916", formatNum(client.getRealEstateCurrent()));
        setValueIfPresent(form, "fill_5017", formatNum(client.getRealEstateLast()));
        setValueIfPresent(form, "fill_5318", formatNum(client.getPersonalPropertiesCurrent()));
        setValueIfPresent(form, "fill_5419", formatNum(client.getPersonalPropertiesLast()));
        setValueIfPresent(form, "fill_5720", formatNum(client.getInvestmentsCurrent()));
        setValueIfPresent(form, "fill_5821", formatNum(client.getInvestmentsLast()));
        setValueIfPresent(form, "fill_6123", formatNum(client.getOtherLiquidCurrent()));
        setValueIfPresent(form, "fill_6224", formatNum(client.getOtherLiquidLast()));
        setValueIfPresent(form, "fill_6526", formatNum(client.getOtherNonLiquidCurrent()));
        setValueIfPresent(form, "fill_6627", formatNum(client.getOtherNonLiquidLast()));
        setValueIfPresent(form, "fill_6928", formatNum(client.getNetBusinessInterestCurrent()));
        setValueIfPresent(form, "fill_7029", formatNum(client.getNetBusinessInterestLast()));
        setValueIfPresent(form, "fill_111130", formatNum(client.getTotalAssetsCurrent()));
        setValueIfPresent(form, "fill_111231", formatNum(client.getTotalAssetsLast()));

        setValueIfPresent(form, "fill_41", formatNum(client.getPersonalLoansCurrent()));
        setValueIfPresent(form, "fill_42", formatNum(client.getPersonalLoansLast()));
        setValueIfPresent(form, "fill_49", formatNum(client.getMortgagesCurrent()));
        setValueIfPresent(form, "fill_50", formatNum(client.getMortgagesLast()));
        setValueIfPresent(form, "fill_53", formatNum(client.getMarginAccountCurrent()));
        setValueIfPresent(form, "fill_54", formatNum(client.getMarginAccountLast()));
        setValueIfPresent(form, "fill_57", formatNum(client.getLoanGuaranteesCurrent()));
        setValueIfPresent(form, "fill_58", formatNum(client.getLoanGuaranteesLast()));
        setValueIfPresent(form, "fill_61", formatNum(client.getBankingFacilityCurrent()));
        setValueIfPresent(form, "fill_62", formatNum(client.getBankingFacilityLast()));
        //other 1
        logger.info("getPrefFinancePrincipalCurrent:" + convertStringToNum(client.getPrefFinancePrincipalCurrent()));
        if(convertStringToNum(client.getPrefFinancePrincipalCurrent()) > 0){
            setValueIfPresent(form, "fill_5_7", "Principal");
        }
        setValueIfPresent(form, "fill_65", formatNum(client.getPrefFinancePrincipalCurrent()));
        setValueIfPresent(form, "fill_66", formatNum(client.getPrefFinancePrincipalLast()));
        setValueIfPresent(form, "fill_69", formatNum(client.getPrefFinanceOtherCurrent()));
        setValueIfPresent(form, "fill_70", formatNum(client.getPrefFinanceOtherLast()));

        setValueIfPresent(form, "fill_1111", formatNum(client.getTotalLiabilitiesCurrent()));
        setValueIfPresent(form, "fill_1112", formatNum(client.getTotalLiabilitiesLast()));
        
        /* Page13 End */
        /* Page14 Start */
        setValueIfPresent(form, "fill_73_1", commonField.getOthers().get("realEstateAddress1_1"));
        setValueIfPresent(form, "fill_73_2", commonField.getOthers().get("realEstateAddress1_2"));
        setValueIfPresent(form, "fill_77_1", commonField.getOthers().get("realEstateAddress2_1"));
        setValueIfPresent(form, "fill_77_2", commonField.getOthers().get("realEstateAddress2_2"));
        setValueIfPresent(form, "fill_81_1", commonField.getOthers().get("realEstateAddress3_1"));
        setValueIfPresent(form, "fill_81_2", commonField.getOthers().get("realEstateAddress3_2"));
        setValueIfPresent(form, "fill_74", commonField.getRealEstatePurchaseDate1());
        setValueIfPresent(form, "fill_78", commonField.getRealEstatePurchaseDate2());
        setValueIfPresent(form, "fill_82", commonField.getRealEstatePurchaseDate3());

        setValueIfPresent(form, "Text26001", commonField.getBankruptDesc());
        /* Page14 End */
        setValueIfPresent(form, "fill_4_12", commonField.getFna_a_retire());
        
    }

    private void HSBCA31_checkBox(PDAcroForm form2, CommonField commonField, Client client){
        /* Page1 Start */
        setValueIfPresent(form2, "Checkk Box6", commonField.getGenderMale());
        setValueIfPresent(form2, "Check kBox7", commonField.getGenderFemale());

        if(!"".equals(client.getCrAddressCity())){
            setValueIfPresent(form2, "Check Box10", "Yes");
        }       

        if(!"".equals(StringUtils.trimToEmpty(client.getPhone1Code()))){
            if("852".equals(client.getPhone1Code()) || "+852".equals(client.getPhone1Code())){
                setValueIfPresent(form2, "Check Box12_2", "Yes");
            }else if("1".equals(client.getPhone1Code()) || "+1".equals(client.getPhone1Code())){
                setValueIfPresent(form2, "Check Box13_2", "Yes");
            }else if("86".equals(client.getPhone1Code()) || "+86".equals(client.getPhone1Code())){
                setValueIfPresent(form2, "Check Box14_2", "Yes");
            }else{
                setValueIfPresent(form2, "Check Box15_2", "Yes");
            }
        }
        
        if(form2.getField("Text1") != null && form2.getField("Text1").getValueAsString() != null && !form2.getField("Text1").getValueAsString().isBlank()
            && ("HK".equals(commonField.getCountryOfIssue().toUpperCase()) 
                || "HONG KONG".equals(commonField.getCountryOfIssue().toUpperCase())
                || "香港".equals(commonField.getCountryOfIssue()) )
            ){
            setValueIfPresent(form2, "Check Bokx21", "Yes");
        }

        if("Yes".equals(commonField.getOthers().get("hkidNon")) || "Yes".equals(commonField.getOthers().get("hkidPerm"))){
            setValueIfPresent(form2, "Check Bokx21", "Yes");
        }else{
            setValueIfPresent(form2, "Check Box22", commonField.getOthers().get("passportYes"));
            setValueIfPresent(form2, "Check Boxk23", commonField.getOthers().get("travelDocYes"));
        }

        
        if("Yes".equals(commonField.getGenderMale())){
             setValueIfPresent(form2, "Check Box2", "Yes");
        }else if("Yes".equals(commonField.getGenderMale())){
            if("Yes".equals(commonField.getOthers().get("maritalStatusMarried"))){
                setValueIfPresent(form2, "Check Box3", "Yes");
            }else{
                setValueIfPresent(form2, "Check Box4", "Yes");
            }
        }
        
        /* Page1 End */
        
        /* Page2 Start */
        Map<String, String> d = getCountryAndPhoneNo(commonField.getContactNo());
        if(d.get("countryCode") != null){
            switch((String)d.get("countryCode")){
                case "+852" ->
                    setValueIfPresent(form2, "Check Box12_2", "Yes");
                case "+1" ->
                    setValueIfPresent(form2, "Check Box13_2", "Yes");
                case "+86" ->
                    setValueIfPresent(form2, "Check Box14_2", "Yes");
            }

            /*
            if("+852".equals((String)d.get("countryCode")))
                setValueIfPresent(form2, "Check Box12_2", "Yes");
            else if("+1".equals((String)d.get("countryCode")))
                setValueIfPresent(form2, "Check Box13_2", "Yes");
            else if("+86".equals((String)d.get("countryCode")))
                setValueIfPresent(form2, "Check Box14_2", "Yes");
            */

        }

        setValueIfPresent(form2, "Check Box175", commonField.getEmployedSelf());
        setValueIfPresent(form2, "Check Box177", commonField.getEmployed());
        setValueIfPresent(form2, "Check Box179", commonField.getPartTime());
        setValueIfPresent(form2, "Check Box181", commonField.getEmployedNon());
        setValueIfPresent(form2, "Check Box176", commonField.getStudent());
        setValueIfPresent(form2, "Check Box178", commonField.getHomemaker());
        setValueIfPresent(form2, "Check Box180", commonField.getRetired());
        /* Page2 End 

        /* Page7 Start */
        setValueIfPresent(form2, "Check Box74", commonField.getOthers().get("formMedical"));
        setValueIfPresent(form2, "Check Box75", commonField.getOthers().get("formNonMedical"));
        /* Page7 End */
        /* Page8 Start */
        if("Yes".equals(commonField.getFna_c3a_single_pay())){
            setValueIfPresent(form2, "Check Box1a01", "Yes");
        }
        
        /* Page8 End */
        /* Page9 Start */
        setValueIfPresent(form2, "Check Box72_1a", commonField.getOthers().get("appyOtherInsuranceYes"));
        setValueIfPresent(form2, "Check Box73_1", commonField.getOthers().get("appyOtherInsuranceNo"));
        /* Page9 End */
            
        /* Page12 Start */
        setValueIfPresent(form2, "Check Box74bb", commonField.getOthers().get("travelYes"));
        setValueIfPresent(form2, "Check Box74_1ag", commonField.getOthers().get("travelNo"));

        setValueIfPresent(form2, "Check Box74b", commonField.getDeclinedYes());
        setValueIfPresent(form2, "Check Box74_1a", commonField.getDeclinedNo());

        setValueIfPresent(form2, "Check Box74bc", commonField.getOthers().get("futureAddressYes"));
        setValueIfPresent(form2, "Check Box74_1ah", commonField.getOthers().get("futureAddressNo"));        
        
        setValueIfPresent(form2, "Check Box74be", commonField.getOthers().get("workHighYes"));
        setValueIfPresent(form2, "Check Box74_1aj", commonField.getOthers().get("workHighNo"));
        
        setValueIfPresent(form2, "Check Box74bd", commonField.getOthers().get("hazardYes"));
        setValueIfPresent(form2, "Check Box74_1ai", commonField.getOthers().get("hazardNo"));
        setValueIfPresent(form2, "fill_15_7y", commonField.getHazardousActivity());
        
        /* Page12 End */
        /* Page13 Start */
        setValueIfPresent(form2, "Check Box81", commonField.getOthers().get("empOtherBenefitsYes"));
        setValueIfPresent(form2, "Check Box82", commonField.getOthers().get("empOtherBenefitsNo"));
        /* Page13 End */
        /* Page14 Start */
        setValueIfPresent(form2, "Check Box65f", commonField.getOthers().get("sourceIncome"));
        setValueIfPresent(form2, "Check Box65", commonField.getOthers().get("sourceBusiness"));
        setValueIfPresent(form2, "Check Box65c", commonField.getOthers().get("sourceInvestment"));
        setValueIfPresent(form2, "Check Box65d", commonField.getOthers().get("premiumFinanceYes"));
        setValueIfPresent(form2, "Check Box65e", commonField.getOthers().get("sourceOther"));

        setValueIfPresent(form2, "Check Box65b", commonField.getBankruptYes());
        setValueIfPresent(form2, "Check Box83", commonField.getBankruptNo());
            
        /* Page14 End */
        /* Page25 Start */
        setValueIfPresent(form2, "Check Box18211", commonField.getReplaceInsuranceYes());
        setValueIfPresent(form2, "Check Box18222", commonField.getReplaceInsuranceNo());
        setValueIfPresent(form2, "Check Box18233", commonField.getOthers().get("replaceInsuranceNotYet"));
        /* Page25 End */
        /* Page27 Start */
        setValueIfPresent(form2, "toggle_7_47", commonField.getFna_c3a_single_pay());
        /* Page27 End */
    }

    private void MLB03S_textBox(PdfAcroForm form, CommonField commonField, Client client){
        /* Page1 Start */        
        if(client != null && client.getConsultantId() != null){
            Consultant consultant = consultantService.find(Long.valueOf(client.getConsultantId())).orElseThrow();

            if(consultant.getName() != null){
                setValueIfPresent(form, "BranchName", consultant.getName());
            }                            
        }  

        setValueIfPresent(form, "SurName1", StringUtils.trimToEmpty(client.getLastname()));
        setValueIfPresent(form, "GivenName1", StringUtils.trimToEmpty(client.getFirstname()));

        setValueIfPresent(form, "ChineseName1", commonField.getNameChi());

        setValueIfPresent(form, "DD1", commonField.getDdDateOfBirth());
        setValueIfPresent(form, "MM1", commonField.getMmDateOfBirth());
        setValueIfPresent(form, "YYYY1", commonField.getYyyyDateOfBirth());
                                    
        setValueIfPresent(form, "Field_LocationA1", commonField.getPlaceOfBirth());
        setValueIfPresent(form, "Field_LocationB1", commonField.getCountryOfCitizenship());
       
        if("Yes".equals(commonField.getOthers().get("hkidPerm")) || "Yes".equals(commonField.getOthers().get("hkidNon"))){
            setValueIfPresent(form, "ID1", commonField.getIdCard());
        }else if("Yes".equals(commonField.getOthers().get("prcId"))){
            setValueIfPresent(form, "ID1", commonField.getIdCard());
        }else if(StringUtils.trimToNull(commonField.getPassportNo()) != null || "Yes".equals(commonField.getOthers().get("passportYes")) || "Yes".equals(commonField.getOthers().get("travelDocYes")) ){
            setValueIfPresent(form, "ID1", commonField.getPassportNo());
        }
        
        setValueIfPresent(form, "Nationality1", commonField.getCountryOfCitizenship());
        setValueIfPresent(form, "Company1", commonField.getOthers().get("empCompanyName"));
        setValueIfPresent(form, "BusinessNature1", StringUtils.trimToEmpty(commonField.getOthers().get("empNatureA")) + " " + StringUtils.trimToEmpty(commonField.getOthers().get("empNatureB")));
        setValueIfPresent(form, "Occupation1", commonField.getOthers().get("empPosition"));
        setValueIfPresent(form, "JobNature1", StringUtils.trimToEmpty(commonField.getOthers().get("empDuties")));
                                
        setValueIfPresent(form, "Income1", formatNum(client.getTotalEarnedCurrent()));

        setValueIfPresent(form, "Room1", client.getCrAddressRoom());
        setValueIfPresent(form, "Floor1", client.getCrAddressFloor());
        setValueIfPresent(form, "Block1", client.getCrAddressBlock());
        setValueIfPresent(form, "Building1", client.getCrAddressBuilding());
        setValueIfPresent(form, "Street1", client.getCrAddressStreet());
        setValueIfPresent(form, "City1", client.getCrAddressCity());
        setValueIfPresent(form, "District1", client.getCrAddressArea());
        setValueIfPresent(form, "Country1", client.getCrAddressCountry());
        setValueIfPresent(form, "PostalCode1", client.getCrAddressPostalCode());
        
        /* Page1 End */
        /* Page2 Start */
        setValueIfPresent(form, "Room3", client.getCorAddressRoom());
        setValueIfPresent(form, "Floor3", client.getCorAddressBlock());
        setValueIfPresent(form, "Block3", client.getCorAddressBlock());
        setValueIfPresent(form, "Building3", client.getCorAddressBuilding());
        setValueIfPresent(form, "Street3", client.getCorAddressStreet());
        setValueIfPresent(form, "City3", client.getCorAddressCity());
        setValueIfPresent(form, "District3", client.getCorAddressArea());
        setValueIfPresent(form, "Country3", client.getCorAddressCountry());
        setValueIfPresent(form, "PostalCode3", client.getCorAddressPostalCode());

        setValueIfPresent(form, "ContactA1", client.getPhone1Code());
        setValueIfPresent(form, "ContactB1", client.getPhone1());
        setValueIfPresent(form, "Email", client.getEmail());
        /* Page2 End */
        /* Page3 Start */
        setValueIfPresent(form, "Field_Wealth4", commonField.getOthers().get("sourceOtherDesc"));
        /* Page3 End */
        /* Page7 Start */
        setValueIfPresent(form, "Residency1", commonField.getTaxResidency1());
        setValueIfPresent(form, "Residency2", commonField.getTaxResidency2());
        setValueIfPresent(form, "Residency3", commonField.getTaxResidency3());
        setValueIfPresent(form, "TIN1", commonField.getTaxPin1());
        setValueIfPresent(form, "TIN2", commonField.getTaxPin2());
        setValueIfPresent(form, "TIN3", commonField.getTaxPin3());
        setValueIfPresent(form, "ABC1", commonField.getTaxReason1());
        setValueIfPresent(form, "ABC2", commonField.getTaxReason2());
        setValueIfPresent(form, "ABC3", commonField.getTaxReason3());
        setValueIfPresent(form, "Reason1", commonField.getTaxReasonB1());
        setValueIfPresent(form, "Reason1a", commonField.getOthers().get("TaxReasonB1a"));
        setValueIfPresent(form, "Reason2", commonField.getTaxReasonB2());
        setValueIfPresent(form, "Reason2a", commonField.getOthers().get("TaxReasonB2a"));
        setValueIfPresent(form, "Reason3", commonField.getTaxReasonB3());
        setValueIfPresent(form, "Reason3a", commonField.getOthers().get("TaxReasonB3a"));
        /* Page7 End */
        
    }

    private void MLB03S_checkBox(PDAcroForm form2, CommonField commonField){
        /* Page1 Start */
        setValueIfPresent(form2, "male", commonField.getGenderMale());
        setValueIfPresent(form2, "female", commonField.getGenderFemale());
        
        if((commonField.getPlaceOfBirth() != null && !"".equals(StringUtils.trimToEmpty(commonField.getPlaceOfBirth())))
            || (commonField.getCountryOfCitizenship() != null && !"".equals(commonField.getCountryOfCitizenship()))
        ){
            if("HONG KONG".equals(commonField.getPlaceOfBirth().toUpperCase())
                || "HK".equals(commonField.getPlaceOfBirth().toUpperCase())
                || "HONGKONG".equals(commonField.getPlaceOfBirth().toUpperCase())
                || "HK SAR".equals(commonField.getPlaceOfBirth().toUpperCase())
                || "HKSAR".equals(commonField.getPlaceOfBirth().toUpperCase())
                || "香港".equals(commonField.getPlaceOfBirth().toUpperCase())){
                setValueIfPresent(form2, "hk", "Yes");
            }else if("MACAU".equals(commonField.getPlaceOfBirth().toUpperCase())
                || "澳門".equals(commonField.getPlaceOfBirth().toUpperCase())){
                setValueIfPresent(form2, "macau", "Yes");
            }else{
                setValueIfPresent(form2, "Checkbox_Location1", "Yes");
            }
        }

        setValueIfPresent(form2, "Checkbox_ID11", commonField.getOthers().get("hkidPerm"));
        logger.info("##### prcId:" +commonField.getOthers().get("prcId"));
        if(!"Yes".equals(commonField.getOthers().get("hkidPerm"))){
            setValueIfPresent(form2, "Checkbox_ID12", commonField.getOthers().get("hkidNon"));
            setValueIfPresent(form2, "Checkbox_ID14", commonField.getOthers().get("prcId"));
            setValueIfPresent(form2, "Checkbox_ID16", commonField.getOthers().get("passportYes"));
            setValueIfPresent(form2, "Checkbox_ID17", commonField.getOthers().get("othersId"));
        }
        
        setValueIfPresent(form2, "Checkbox_Y", commonField.getTobarccoYes());
        setValueIfPresent(form2, "Checkbox_N", commonField.getTobarccoNo());
        /* Page1 End */
        /* Page3 Start */
        setValueIfPresent(form2, "Checkbox_Wealth1", commonField.getOthers().get("sourceIncome"));
        if("Yes".equals(commonField.getOthers().get("sourceInvestment")) 
            || "Yes".equals(commonField.getOthers().get("sourceInvestment")) ){
            setValueIfPresent(form2, "Checkbox_Wealth2", "Yes");
        }
        setValueIfPresent(form2, "Checkbox_Wealth3", commonField.getOthers().get("sourceInheritance"));
        setValueIfPresent(form2, "Checkbox_Wealth4", commonField.getOthers().get("sourceOther"));

        setValueIfPresent(form2, "Checkbox_EudcationPri", commonField.getEduPri());
        setValueIfPresent(form2, "Checkbox_EudcationSec", commonField.getEduSec());
        setValueIfPresent(form2, "Checkbox_EudcationPostSec", commonField.getEduPostSec());
        setValueIfPresent(form2, "Checkbox_EudcationTer", commonField.getEduUni());
        
        
        /* Page3 End */
        /* Page6 Start */
        
        setValueIfPresent(form2, "c_USACitizen1yes", commonField.getOthers().get("usPerson"));
        setValueIfPresent(form2, "c_USACitizen1no", commonField.getOthers().get("usPersonNot"));

        /* Page6 End */
        /* Page8 Start */
        setValueIfPresent(form2, "c_DeclartionYes", commonField.getReplaceInsuranceYes());
        setValueIfPresent(form2, "c_DeclartionNo", commonField.getReplaceInsuranceNo());
        /* Page8 End */  
        /* Page9 Start */
        setValueIfPresent(form2, "c_Assessment1", commonField.getOthers().get("replaceInsuranceNotYet"));
        setValueIfPresent(form2, "c_Assessment12", commonField.getReplaceInsuranceYes());
        setValueIfPresent(form2, "c_Assessment13", commonField.getReplaceInsuranceNo());
        /* Page9 End */
        
    }

    private void SLGII_textBox(PdfAcroForm form, CommonField commonField, Client client){
        /* Page1 Start */
        setValueIfPresent(form, "surname", StringUtils.trimToEmpty(client.getLastname()));
        setValueIfPresent(form, "given_name", StringUtils.trimToEmpty(client.getFirstname()));

        setValueIfPresent(form, "chinese_name", commonField.getNameChi());

        setValueIfPresent(form, "ch1_4_m", commonField.getGenderMale());
        setValueIfPresent(form, "ch1_4_f", commonField.getGenderFemale());
           
        setValueIfPresent(form, "1_6dd", commonField.getDdDateOfBirth());
        setValueIfPresent(form, "1_6mm", commonField.getMmDateOfBirth());
        setValueIfPresent(form, "1_6yyyy", commonField.getYyyyDateOfBirth());
        
        setValueIfPresent(form, "1_7", commonField.getPlaceOfBirth());
        setValueIfPresent(form, "1_8", commonField.getCountryOfCitizenship());

        if("Yes".equals(commonField.getOthers().get("hkidPerm")) || "Yes".equals(commonField.getOthers().get("hkidNon"))){
            setValueIfPresent(form, "1_10id", commonField.getIdCard());
        }else if("Yes".equals(commonField.getOthers().get("prcId"))){
            setValueIfPresent(form, "1_10prc", commonField.getPassportNo());
         
        }else if(StringUtils.trimToNull(commonField.getPassportNo()) != null || "Yes".equals(commonField.getOthers().get("passportYes")) || "Yes".equals(commonField.getOthers().get("travelDocYes")) ){
            setValueIfPresent(form, "1_10passport", commonField.getPassportNo());

            setValueIfPresent(form, "1_10_pexpiry_dd", commonField.getOthers().get("passportExpiryDD"));
            setValueIfPresent(form, "1_10_pexpiry_mm", commonField.getOthers().get("passportExpiryMM"));
            setValueIfPresent(form, "1_10_pexpiry_yyyy", commonField.getOthers().get("passportExpiryYYYY"));
            
        }
        
        /* Page1 End */
        /* Page2 Start */        
        setValueIfPresent(form, "1_12_detail1", commonField.getOthers().get("workHighDesc"));

        setValueIfPresent(form, "1_12_occupation", commonField.getOthers().get("empPosition"));
        setValueIfPresent(form, "1_12_exact_duty", commonField.getOthers().get("empDuties"));
        setValueIfPresent(form, "1_12_employer", commonField.getOthers().get("empCompanyName"));
        setValueIfPresent(form, "1_12_employer_address_1", commonField.getOthers().get("empCompanyAddress"));
        //setValueIfPresent(form, "1_12_employer_address_2", commonField.getOthers().get("companyAddress2"));

        setValueIfPresent(form, "1_12_nature_1", commonField.getOthers().get("empNatureA")); 
        setValueIfPresent(form, "1_12_nature_2", commonField.getOthers().get("empNatureB")); 

        setValueIfPresent(form, "1_13a_rm", client.getCrAddressRoom());
        setValueIfPresent(form, "1_13a_floor", client.getCrAddressFloor());
        setValueIfPresent(form, "1_13a_block", client.getCrAddressBlock());
        setValueIfPresent(form, "1_13a_building", client.getCrAddressBuilding());
        setValueIfPresent(form, "1_13a_street", client.getCrAddressStreet());
        setValueIfPresent(form, "1_13a_district", client.getCrAddressArea());
        setValueIfPresent(form, "1_13a_zip", client.getCrAddressPostalCode());
        if("HK".equals(client.getCrAddressArea()))
            setValueIfPresent(form, "ch1_13a_hk", "Yes");
        if("KLN".equals(client.getCrAddressArea()) || "KL".equals(client.getCrAddressArea()) || "KWOLOON".equals(client.getCrAddressArea()))
            setValueIfPresent(form, "ch1_13a_kln", "Yes");
        if("NT".equals(client.getCrAddressArea()))
            setValueIfPresent(form, "ch1_13a_nt", "Yes");
        
        setValueIfPresent(form, "1_13bc_rm", client.getCorAddressRoom());
        setValueIfPresent(form, "1_13bc_floor", client.getCorAddressFloor());
        setValueIfPresent(form, "1_13bc_block", client.getCorAddressBlock());
        setValueIfPresent(form, "1_13bc_building", client.getCorAddressBuilding());
        setValueIfPresent(form, "1_13bc_street", client.getCorAddressStreet());
        setValueIfPresent(form, "1_13bc_district", client.getCorAddressArea());
        
        /* Page2 End */                                                
        /* Page3 Start */
        setValueIfPresent(form, "1_13b_tel_mobile_code", client.getPhone1Code());
        setValueIfPresent(form, "1_13b_tel_mobile", client.getPhone1());
        setValueIfPresent(form, "1_13b_email", client.getEmail());

        setValueIfPresent(form, "1_14d_tax1", commonField.getTaxResidency1());
        setValueIfPresent(form, "1_14d_tax2", commonField.getTaxResidency2());
        setValueIfPresent(form, "1_14d_tax3", commonField.getTaxResidency3());

        setValueIfPresent(form, "1_14d_tax_num1", commonField.getTaxPin1());
        setValueIfPresent(form, "1_14d_tax_num2", commonField.getTaxPin2());
        setValueIfPresent(form, "1_14d_tax_num3", commonField.getTaxPin3());

        /*
        if(commonField.getTaxResidency1() != null && !commonField.getTaxResidency1().isBlank()){
            setValueIfPresent(form, "ch1_14d_reason1_a", "On");
            setValueIfPresent(form, "ch1_14d_reason1_b", "On");
            setValueIfPresent(form, "ch1_14d_reason1_c", "On");
        }
        if(commonField.getTaxResidency2() != null && !commonField.getTaxResidency2().isBlank()){
            setValueIfPresent(form, "ch1_14d_reason2_a", "On");
            setValueIfPresent(form, "ch1_14d_reason2_b", "On");
            setValueIfPresent(form, "ch1_14d_reason2_c", "On");
        }
        if(commonField.getTaxResidency3() != null && !commonField.getTaxResidency3().isBlank()){
            setValueIfPresent(form, "ch1_14d_reason3_a", "On");
            setValueIfPresent(form, "ch1_14d_reason3_b", "On");
            setValueIfPresent(form, "ch1_14d_reason3_c", "On");
        }
        
        if("A".equals(commonField.getTaxReason1())){
            setValueIfPresent(form, "ch1_14d_reason1_a", "OFF");
        }
        if("B".equals(commonField.getTaxReason1())){
            setValueIfPresent(form, "ch1_14d_reason1_b", "OFF");
        }
        if("C".equals(commonField.getTaxReason1())){
            setValueIfPresent(form, "ch1_14d_reason1_c", "OFF");
        }
        if("A".equals(commonField.getTaxReason2())){
            setValueIfPresent(form, "ch1_14d_reason2_a", "OFF");
        }
        if("B".equals(commonField.getTaxReason2())){
            setValueIfPresent(form, "ch1_14d_reason2_b", "OFF");
        }
        if("C".equals(commonField.getTaxReason2())){
            setValueIfPresent(form, "ch1_14d_reason2_c", "OFF");
        }
        if("A".equals(commonField.getTaxReason3())){
            setValueIfPresent(form, "ch1_14d_reason3_a", "OFF");
        }
        if("B".equals(commonField.getTaxReason3())){
            setValueIfPresent(form, "ch1_14d_reason3_b", "OFF");
        }
        if("C".equals(commonField.getTaxReason3())){
            setValueIfPresent(form, "ch1_14d_reason3_c", "OFF");
        }
        */

        setValueIfPresent(form, "1_14d_explain1", commonField.getTaxReasonB1());
        setValueIfPresent(form, "1_14d_explain1a", commonField.getOthers().get("TaxReasonB1a"));
        setValueIfPresent(form, "1_14d_explain2", commonField.getTaxReasonB2());
        setValueIfPresent(form, "1_14d_explain2a", commonField.getOthers().get("TaxReasonB2a"));
        setValueIfPresent(form, "1_14d_explain3", commonField.getTaxReasonB3());
        setValueIfPresent(form, "1_14d_explain3a", commonField.getOthers().get("TaxReasonB3a"));
         
        /* Page3 End */
        /* Page6 Start */               

        /*
        setValueIfPresent(form, "4_1_name1_1", commonField.getInsuranceCompany1_1());
        setValueIfPresent(form, "4_1_name2_1", commonField.getInsuranceCompany2_1());
        setValueIfPresent(form, "4_1_name3_1", commonField.getInsuranceCompany3_1());

        setValueIfPresent(form, "4_1_year1", commonField.getInsuranceYear1());
        setValueIfPresent(form, "4_1_year2", commonField.getInsuranceYear2());
        setValueIfPresent(form, "4_1_year3", commonField.getInsuranceYear3());

        setValueIfPresent(form, "4_1_sum1_1", commonField.getOthers().get("insuranceSumInsured1_1"));
        setValueIfPresent(form, "4_1_sum2_1", commonField.getOthers().get("insuranceSumInsured2_1"));
        setValueIfPresent(form, "4_1_sum3_1", commonField.getOthers().get("insuranceSumInsured3_1"));
        
        //if(commonField.getInsuranceSumInsured1() != null && !commonField.getInsuranceSumInsured1().isBlank()){
            setValueIfPresent(form, "ch4_1_life", "On");
            setValueIfPresent(form, "ch4_1_accident", "On");
            setValueIfPresent(form, "ch4_1_critical", "On");
            setValueIfPresent(form, "ch4_1_hospital", "On");
            
        //}
        if("Yes".equals(commonField.getInsuranceLife1())){
            setValueIfPresent(form, "ch4_1_life", "Off");
        }
        if("Yes".equals(commonField.getInsuranceCritical1())){
            setValueIfPresent(form, "ch4_1_critical", "Off");
        }

        //if(commonField.getInsuranceSumInsured2() != null && !commonField.getInsuranceSumInsured2().isBlank()){
            setValueIfPresent(form, "ch4_2_life", "On");
            setValueIfPresent(form, "ch4_2_accident", "On");
            setValueIfPresent(form, "ch4_2_critical", "On");
            setValueIfPresent(form, "ch4_2_hospital", "On");
            
        //}
        if("Yes".equals(commonField.getInsuranceLife2())){
            setValueIfPresent(form, "ch4_2_life", "Off");
        }
        if("Yes".equals(commonField.getInsuranceCritical2())){
            setValueIfPresent(form, "ch4_2_critical", "Off");
        }

        //if(commonField.getInsuranceSumInsured3() != null && !commonField.getInsuranceSumInsured3().isBlank()){
            setValueIfPresent(form, "ch4_3_life", "On");
            setValueIfPresent(form, "ch4_3_accident", "On");
            setValueIfPresent(form, "ch4_3_critical", "On");
            setValueIfPresent(form, "ch4_3_hospital", "On");
            
        //}
        if("Yes".equals(commonField.getInsuranceLife3())){
            setValueIfPresent(form, "ch4_3_life", "Off");
        }
        if("Yes".equals(commonField.getInsuranceCritical3())){
            setValueIfPresent(form, "ch4_3_critical", "Off");
        }
             */
            
        setValueIfPresent(form, "5_1a_city1", commonField.getOthers().get("travelCity1"));
        setValueIfPresent(form, "5_1a_city2", commonField.getOthers().get("travelCity2"));
        setValueIfPresent(form, "5_1a_city3", commonField.getOthers().get("travelCity3"));
        setValueIfPresent(form, "5_1a_purpose1", commonField.getOthers().get("travelPurpose1"));
        setValueIfPresent(form, "5_1a_purpose2", commonField.getOthers().get("travelPurpose2"));
        setValueIfPresent(form, "5_1a_purpose3", commonField.getOthers().get("travelPurpose3"));
        setValueIfPresent(form, "5_1a_frequency1", commonField.getOthers().get("5_1a_frequency1"));
        setValueIfPresent(form, "5_1a_frequency2", commonField.getOthers().get("travelFrequency2"));
        setValueIfPresent(form, "5_1a_frequency3", commonField.getOthers().get("travelFrequency3"));

        setValueIfPresent(form, "5_1b_city1", commonField.getOthers().get("travelNextCity1"));
        setValueIfPresent(form, "5_1b_city2", commonField.getOthers().get("travelNextCity2"));
        setValueIfPresent(form, "5_1b_city3", commonField.getOthers().get("travelNextCity3"));
        setValueIfPresent(form, "5_1b_purpose1", commonField.getOthers().get("travelNextPurpose1"));
        setValueIfPresent(form, "5_1b_purpose2", commonField.getOthers().get("travelNextPurpose2"));
        setValueIfPresent(form, "5_1b_purpose3", commonField.getOthers().get("travelNextPurpose3"));
        setValueIfPresent(form, "5_1b_frequency1", commonField.getOthers().get("travelNextFrequency1"));
        setValueIfPresent(form, "5_1b_frequency2", commonField.getOthers().get("travelNextFrequency2"));
        setValueIfPresent(form, "5_1b_frequency3", commonField.getOthers().get("travelNextFrequency3"));
        
        /* Page6 End */
        /* Page7 Start */
        setValueIfPresent(form, "ch5_1c_yes", commonField.getOthers().get("futureAddressYes"));
        setValueIfPresent(form, "ch5_1c_no", commonField.getOthers().get("futureAddressNo"));
        setValueIfPresent(form, "5_1c_address_1", commonField.getOthers().get("futureAddress"));
        //setValueIfPresent(form, "5_1c_address_2", commonField.getOthers().get("futureAddress2"));
        setValueIfPresent(form, "5_1c_reason", commonField.getOthers().get("futureAddressReason"));
        setValueIfPresent(form, "5_1c_how_long", commonField.getOthers().get("futureAddressHowLong"));
        if(StringUtils.trimToNull(commonField.getOthers().get("futureAddressReason")) != null 
            && StringUtils.trimToNull(commonField.getOthers().get("futureAddressHowLong")) != null ){
                setValueIfPresent(form, "fill_2_4", commonField.getOthers().get("futureAddressReasonHowLong"));
            }
        if("Yes".equals(commonField.getOthers().get("hazard"))){
            setValueIfPresent(form, "ch5_2_yes", "Yes");
        }
        if("Off".equals(commonField.getOthers().get("hazard"))){
            setValueIfPresent(form, "ch5_2_no", "Yes");
        }
        setValueIfPresent(form, "ch5_3_yes", commonField.getDeclinedYes());
        setValueIfPresent(form, "ch5_3_no", commonField.getDeclinedNo());
        setValueIfPresent(form, "ch5_6_yes", commonField.getOthers().get("pendingChargeYes"));
        setValueIfPresent(form, "ch5_6_no", commonField.getOthers().get("pendingChargeNo"));
        /* Page7 End */
        /* Page10 Start */

        for(int i=1; i<=4; i++){
            setValueIfPresent(form, "7_1a_name" + i, commonField.getOthers().get("relate" + i + "_name"));
            setValueIfPresent(form, "7_1a_age" + i, commonField.getOthers().get("relate" + i + "_age"));
            setValueIfPresent(form, "7_1a_relation" + i, commonField.getOthers().get("relate" + i + "_relationship"));
        }

        if(commonField.getOthers().get("companyStartYear") != null && commonField.getOthers().get("companyEndYear") != null
           && !commonField.getOthers().get("companyStartYear").isBlank() &&  !commonField.getOthers().get("companyEndYear").isBlank()){
            setValueIfPresent(form, "7_1b", commonField.getOthers().get("companyStartYear") + " - "  + commonField.getOthers().get("companyEndYear"));
        }
        if("Yes".equals(commonField.getOthers().get("businessOwnerYes"))){
            setValueIfPresent(form, "7_1c", commonField.getOthers().get("businessOwnerPercent"));
        }
        setValueIfPresent(form, "7_1d", commonField.getOthers().get("businessOwnerNoEmployee"));
        /* Page10 End */

        setValueIfPresent(form, "7_2a_salary", formatNum(client.getSalaryCurrent()));
        setValueIfPresent(form, "7_2a_salary_24", formatNum(client.getSalaryLast()));
        setValueIfPresent(form, "7_2a_bonuses", formatNum(client.getBonusCurrent()));
        setValueIfPresent(form, "7_2a_bonuses_24", formatNum(client.getBonusLast()));
        setValueIfPresent(form, "7_2a_company", formatNum(client.getCompanyInterestCurrent()));
        setValueIfPresent(form, "7_2a_company_24", formatNum(client.getCompanyInterestLast()));
        setValueIfPresent(form, "7_2a_invest", formatNum(client.getInvestmentIncomeCurrent()));
        setValueIfPresent(form, "7_2a_invest_24", formatNum(client.getInvestmentIncomeLast()));
        setValueIfPresent(form, "7_2a_dividends", formatNum(client.getDividendsCurrent()));
        setValueIfPresent(form, "7_2a_dividends_24", formatNum(client.getDividendsLast()));
        setValueIfPresent(form, "7_2a_rental", formatNum(client.getRentalsCurrent()));
        setValueIfPresent(form, "7_2a_rental_24", formatNum(client.getRentalsLast()));
        setValueIfPresent(form, "7_2a_other", addNums(formatNum(client.getOtherEarnedCurrent()), formatNum(client.getOtherUnearnedCurrent())));
        setValueIfPresent(form, "7_2a_other_24", addNums(formatNum(client.getOtherEarnedLast()), formatNum(client.getOtherUnearnedLast())));
        
        //sum income
        setValueIfPresent(form, "7_2a_sum", formatNum(client.getTotalIncomeCurrent()));
        setValueIfPresent(form, "7_2a_sum_24", formatNum(client.getTotalIncomeLast()));

        setValueIfPresent(form, "7_2c_cash", formatNum(client.getCashDepositsCurrent()));
        setValueIfPresent(form, "7_2c_cash_24", formatNum(client.getCashDepositsLast()));
        setValueIfPresent(form, "7_2c_high", formatNum(client.getPersonalPropertiesCurrent()));
        setValueIfPresent(form, "7_2c_high_24", formatNum(client.getPersonalPropertiesLast()));
        setValueIfPresent(form, "7_2c_real", formatNum(client.getRealEstateCurrent()));
        setValueIfPresent(form, "7_2c_real_24", formatNum(client.getRealEstateLast()));
        setValueIfPresent(form, "7_2c_stocks", formatNum(client.getInvestmentsCurrent()));
        setValueIfPresent(form, "7_2c_stocks_24", formatNum(client.getInvestmentsLast()));
        setValueIfPresent(form, "7_2c_business", formatNum(client.getNetBusinessInterestCurrent()));
        setValueIfPresent(form, "7_2c_business_24", formatNum(client.getNetBusinessInterestLast()));
        //setValueIfPresent(form, "7_2c_high", formatNum(client.getPersonalPropertiesCurrent()));
        //setValueIfPresent(form, "7_2c_high_24", formatNum(client.getPersonalPropertiesLast()));
        setValueIfPresent(form, "7_2c_other", addNums(formatNum(client.getOtherLiquidCurrent()), formatNum(client.getOtherNonLiquidCurrent())));
        setValueIfPresent(form, "7_2c_other_24", addNums(formatNum(client.getOtherLiquidLast()), formatNum(client.getOtherNonLiquidLast())));

        //sum asset
        setValueIfPresent(form, "7_2c_total", addNums(form.getField("7_2c_cash").getValueAsString(), form.getField("7_2c_real").getValueAsString(), form.getField("7_2c_stocks").getValueAsString(), form.getField("7_2c_high").getValueAsString(), form.getField("7_2c_business").getValueAsString(), form.getField("7_2c_other").getValueAsString()));
        setValueIfPresent(form, "7_2c_total_24", addNums(form.getField("7_2c_cash_24").getValueAsString(), form.getField("7_2c_real_24").getValueAsString(), form.getField("7_2c_stocks_24").getValueAsString(), form.getField("7_2c_high_24").getValueAsString(), form.getField("7_2c_business_24").getValueAsString(), form.getField("7_2c_other_24").getValueAsString()));

        
        setValueIfPresent(form, "7_2c_lia_loan", formatNum(client.getPersonalLoansCurrent()));
        setValueIfPresent(form, "7_2c_lia_loan_24", formatNum(client.getPersonalLoansLast()));
        setValueIfPresent(form, "7_2c_lia_mortgages", formatNum(client.getMortgageCurrent()));
        setValueIfPresent(form, "7_2c_lia_mortgages_24", formatNum(client.getMortgageLast()));
        setValueIfPresent(form, "7_2c_lia_margin", formatNum(client.getMarginAccountCurrent()));
        setValueIfPresent(form, "7_2c_lia_margin_24", formatNum(client.getMarginAccountLast()));
        setValueIfPresent(form, "7_2c_lia_loan_gr", formatNum(client.getLoanGuaranteesCurrent()));
        setValueIfPresent(form, "7_2c_lia_loan_gr_24", formatNum(client.getLoanGuaranteesLast()));
        setValueIfPresent(form, "7_2c_lia_banking", formatNum(client.getBankingFacilityCurrent()));
        setValueIfPresent(form, "7_2c_lia_banking_24", formatNum(client.getBankingFacilityLast()));
        
        setValueIfPresent(form, "7_2c_lia_other", addNums(formatNum(client.getOtherPrefFinanceCurrent()), formatNum(client.getPrincipalCurrent())));
        setValueIfPresent(form, "7_2c_lia_other_24", addNums(formatNum(client.getOtherPrefFinanceLast()), formatNum(client.getPrincipalLast())));
        //sum liabilities
        setValueIfPresent(form, "7_2c_lia_total", addNums(form.getField("7_2c_lia_loan").getValueAsString(), form.getField("7_2c_lia_loan_gr").getValueAsString(), form.getField("7_2c_lia_mortgages").getValueAsString(), form.getField("7_2c_lia_margin").getValueAsString(), form.getField("7_2c_lia_banking").getValueAsString(), form.getField("7_2c_lia_other").getValueAsString()));
        setValueIfPresent(form, "7_2c_lia_total_24", addNums(form.getField("7_2c_lia_loan_24").getValueAsString(), form.getField("7_2c_lia_loan_gr_24").getValueAsString(), form.getField("7_2c_lia_mortgages_24").getValueAsString(), form.getField("7_2c_lia_margin_24").getValueAsString(), form.getField("7_2c_lia_banking_24").getValueAsString(), form.getField("7_2c_lia_other_24").getValueAsString()));
        
        setValueIfPresent(form, "7_2d_address1_1", commonField.getOthers().get("realEstateAddress1_1"));
        setValueIfPresent(form, "7_2d_address1_2", commonField.getOthers().get("realEstateAddress1_2"));
        setValueIfPresent(form, "7_2d_address2_1", commonField.getOthers().get("realEstateAddress2_1"));
        setValueIfPresent(form, "7_2d_address2_2", commonField.getOthers().get("realEstateAddress2_2"));
        setValueIfPresent(form, "7_2d_address3_1", commonField.getOthers().get("realEstateAddress3_1"));
        setValueIfPresent(form, "7_2d_address3_2", commonField.getOthers().get("realEstateAddress3_2"));

        setValueIfPresent(form, "7_2d_year1", commonField.getRealEstatePurchaseDate1());
        setValueIfPresent(form, "7_2d_year2", commonField.getRealEstatePurchaseDate2());
        setValueIfPresent(form, "7_2d_year3", commonField.getRealEstatePurchaseDate3());

            
    }

    private void SLGII_checkBox(PDAcroForm form2, CommonField commonField){
        //setValueIfPresent(form2, "Checkbox_EudcationPri", commonField.getEduPri());
        setValueIfPresent(form2, "chhn", commonField.getOthers().get("formNonMedical"));
        setValueIfPresent(form2, "chhm", commonField.getOthers().get("formMedical"));
        
        /* Page1 Start */
        setValueIfPresent(form2, "ch1_4_m", commonField.getGenderMale());
        setValueIfPresent(form2, "ch1_4_f", commonField.getGenderFemale());

        
        setValueIfPresent(form2, "ch1_5n", commonField.getTobarccoYes());
        setValueIfPresent(form2, "ch1_5s", commonField.getTobarccoNo());
        
        if("Yes".equals(commonField.getOthers().get("hkidPerm")) || "Yes".equals(commonField.getOthers().get("hkidNon")))
            setValueIfPresent(form2, "ch1_10birth", "Yes");
        else if("Yes".equals(commonField.getOthers().get("prcId")))
            setValueIfPresent(form2, "ch1_10orc", commonField.getIdCard());
        else if(StringUtils.trimToNull(commonField.getPassportNo()) != null || "Yes".equals(commonField.getOthers().get("passportYes")) || "Yes".equals(commonField.getOthers().get("travelDocYes")) ){
            setValueIfPresent(form2, "ch1_10passport", "Yes");
            if(StringUtils.trimToNull(commonField.getOthers().get("passportExpiryDD")) != null){
                setValueIfPresent(form2, "ch1_10_pexpiry", "Yes");
            }
        }
        
        /* Page1 End */
        /* Page2 Start */
        setValueIfPresent(form2, "ch1_12_yes", commonField.getOthers().get("workHighYes"));
        setValueIfPresent(form2, "ch1_12_no", commonField.getOthers().get("workHighNo"));

        setValueIfPresent(form2, "ch1_11_s", commonField.getOthers().get("maritalStatusSingle"));
        setValueIfPresent(form2, "ch1_11_m", commonField.getOthers().get("maritalStatusMarried"));
        setValueIfPresent(form2, "ch1_11_o", commonField.getOthers().get("maritalStatusOther"));
        
        setValueIfPresent(form2, "ch1_12_self", commonField.getEmployedSelf());
        setValueIfPresent(form2, "ch1_12_full", commonField.getEmployed());
        setValueIfPresent(form2, "ch1_12_student", commonField.getStudent());
        setValueIfPresent(form2, "ch1_12_housewife", commonField.getPartTime());
        setValueIfPresent(form2, "ch1_12_part", commonField.getHomemaker());
        setValueIfPresent(form2, "ch1_12_retired", commonField.getRetired());

        setValueIfPresent(form2, "ch1_13a_hk", commonField.getOthers().get("crAddressHK"));
        setValueIfPresent(form2, "ch1_13a_kln", commonField.getOthers().get("crAddressKln"));
        setValueIfPresent(form2, "ch1_13a_nt", commonField.getOthers().get("crAddressNt"));

        setValueIfPresent(form2, "ch1_13bc_hk", commonField.getOthers().get("corAddressHK"));
        setValueIfPresent(form2, "ch1_13bc_kln", commonField.getOthers().get("corAddressKln"));
        setValueIfPresent(form2, "ch1_13bc_nt", commonField.getOthers().get("corAddressNt"));
        
        /* Page2 End */                                                
        /* Page3 Start */
        /*
        if(commonField.getTaxResidency1() != null && !commonField.getTaxResidency1().isBlank()){
            setValueIfPresent(form2, "ch1_14d_reason1_a", "On");
            setValueIfPresent(form2, "ch1_14d_reason1_b", "On");
            setValueIfPresent(form2, "ch1_14d_reason1_c", "On");
        }
        if(commonField.getTaxResidency2() != null && !commonField.getTaxResidency2().isBlank()){
            setValueIfPresent(form2, "ch1_14d_reason2_a", "On");
            setValueIfPresent(form2, "ch1_14d_reason2_b", "On");
            setValueIfPresent(form2, "ch1_14d_reason2_c", "On");
        }
        if(commonField.getTaxResidency3() != null && !commonField.getTaxResidency3().isBlank()){
            setValueIfPresent(form2, "ch1_14d_reason3_a", "On");
            setValueIfPresent(form2, "ch1_14d_reason3_b", "On");
            setValueIfPresent(form2, "ch1_14d_reason3_c", "On");
        }

        if("A".equals(commonField.getTaxReason1())){
            setValueIfPresent(form2, "ch1_14d_reason1_a", "OFF");
        }
        if("B".equals(commonField.getTaxReason1())){
            setValueIfPresent(form2, "ch1_14d_reason1_b", "OFF");
        }
        if("C".equals(commonField.getTaxReason1())){
            setValueIfPresent(form2, "ch1_14d_reason1_c", "OFF");
        }
        if("A".equals(commonField.getTaxReason2())){
            setValueIfPresent(form2, "ch1_14d_reason2_a", "OFF");
        }
        if("B".equals(commonField.getTaxReason2())){
            setValueIfPresent(form2, "ch1_14d_reason2_b", "OFF");
        }
        if("C".equals(commonField.getTaxReason2())){
            setValueIfPresent(form2, "ch1_14d_reason2_c", "OFF");
        }
        if("A".equals(commonField.getTaxReason3())){
            setValueIfPresent(form2, "ch1_14d_reason3_a", "OFF");
        }
        if("B".equals(commonField.getTaxReason3())){
            setValueIfPresent(form2, "ch1_14d_reason3_b", "OFF");
        }
        if("C".equals(commonField.getTaxReason3())){
            setValueIfPresent(form2, "ch1_14d_reason3_c", "OFF");
        }
        */
        /* Page3 End */
        /* Page6 Start */
        /*
                //f(commonField.getInsuranceSumInsured1() != null && !commonField.getInsuranceSumInsured1().isBlank()){
            setValueIfPresent(form2, "ch4_1_life", "On");
            setValueIfPresent(form2, "ch4_1_accident", "On");
            setValueIfPresent(form2, "ch4_1_critical", "On");
            setValueIfPresent(form2, "ch4_1_hospital", "On");
            
        //}
        if("Yes".equals(commonField.getInsuranceLife1())){
            setValueIfPresent(form2, "ch4_1_life", "Off");
        }
        if("Yes".equals(commonField.getInsuranceCritical1())){
            setValueIfPresent(form2, "ch4_1_critical", "Off");
        }

        //if(commonField.getInsuranceSumInsured2() != null && !commonField.getInsuranceSumInsured2().isBlank()){
            setValueIfPresent(form2, "ch4_2_life", "On");
            setValueIfPresent(form2, "ch4_2_accident", "On");
            setValueIfPresent(form2, "ch4_2_critical", "On");
            setValueIfPresent(form2, "ch4_2_hospital", "On");
            
        //}
        if("Yes".equals(commonField.getInsuranceLife2())){
            setValueIfPresent(form2, "ch4_2_life", "Off");
        }
        if("Yes".equals(commonField.getInsuranceCritical2())){
            setValueIfPresent(form2, "ch4_2_critical", "Off");
        }

        //if(commonField.getInsuranceSumInsured3() != null && !commonField.getInsuranceSumInsured3().isBlank()){
            setValueIfPresent(form2, "ch4_3_life", "On");
            setValueIfPresent(form2, "ch4_3_accident", "On");
            setValueIfPresent(form2, "ch4_3_critical", "On");
            setValueIfPresent(form2, "ch4_3_hospital", "On");
            
        //}
        if("Yes".equals(commonField.getInsuranceLife3())){
            setValueIfPresent(form2, "ch4_3_life", "Off");
        }
        if("Yes".equals(commonField.getInsuranceCritical3())){
            setValueIfPresent(form2, "ch4_3_critical", "Off");
        }
        */
        setValueIfPresent(form2, "ch5_1_yes", commonField.getOthers().get("travelYes"));
        setValueIfPresent(form2, "ch5_1_no", commonField.getOthers().get("travelNo"));
        
        /* Page6 End */
        /* Page7 Start */
        setValueIfPresent(form2, "ch5_1c_yes", commonField.getOthers().get("futureAddressYes"));
        setValueIfPresent(form2, "ch5_1c_no", commonField.getOthers().get("futureAddressNo"));
    
        setValueIfPresent(form2, "ch5_2_yes", commonField.getOthers().get("hazardYes"));
        setValueIfPresent(form2, "ch5_2_no", commonField.getOthers().get("hazardNo"));
        
        setValueIfPresent(form2, "ch5_3_yes", commonField.getDeclinedYes());
        setValueIfPresent(form2, "ch5_3_no", commonField.getDeclinedNo());

        setValueIfPresent(form2, "ch5_5_yes", commonField.getOthers().get("politicalYes"));
        setValueIfPresent(form2, "ch5_5_no", commonField.getOthers().get("politicalNo"));
        
        setValueIfPresent(form2, "ch5_6_yes", commonField.getOthers().get("pendingChargeYes"));
        setValueIfPresent(form2, "ch5_6_no", commonField.getOthers().get("pendingChargeNo"));

        /* Page7 End */

        /* Page10 Start */
        setValueIfPresent(form2, "7_2b_yes", commonField.getOthers().get("empOtherBenefitsYes"));
        setValueIfPresent(form2, "6_2b_no", commonField.getOthers().get("empOtherBenefitsNo"));
        /* Page10 End */

        /* Page13 Start */
        setValueIfPresent(form2, "8_yes", commonField.getReplaceInsuranceYes());
        setValueIfPresent(form2, "8_no", commonField.getReplaceInsuranceNo());
        setValueIfPresent(form2, "8_not", commonField.getOthers().get("replaceInsuranceNotYet"));
        
    }

	public List<Map<String,Object>> list(Map<String, Object> args){
		StringBuilder sql = new StringBuilder("SELECT"
            + " (select concat('V', count(1) + 1) from filled_form where clientId = ff.clientId and templateId = ff.templateId and id < ff.id) as vNum, "
            + " (select f.id from file_ref fr left join file f on fr.fileId = f.id where fr.refType = 'upload1' and fr.refId = ff.id order by fr.id desc limit 1) as upload1FileId, "
            + " (select f.skey from file_ref fr left join file f on fr.fileId = f.id where fr.refType = 'upload1' and fr.refId = ff.id order by fr.id desc limit 1) as uploadFileSkey, "
            + " (select f.id from file_ref fr left join file f on fr.fileId = f.id where fr.refType = 'upload2' and fr.refId = ff.id order by fr.id desc limit 1) as upload2FileId, "
            + " (select f.skey from file_ref fr left join file f on fr.fileId = f.id where fr.refType = 'upload2' and fr.refId = ff.id order by fr.id desc limit 1) as upload2FileSkey, "
        
			+ " ff.id, "
			+ " ff.templateId, "
			+ " ff.fileId, "
			+ " ff.created, "
			+ " ff.modified, "
            + " ff.version, "
            + " t.remarks AS formCode, "
            + " t.name AS templateName "
			+ " FROM filled_form ff "
			+ " LEFT JOIN template t ON t.id = ff.templateId "
			+ " WHERE ff.deleted = FALSE "
		);

		if (args != null) {
			if (args.containsKey("clientId")) 
				sql.append(" AND ff.clientId = :clientId ");
			if (args.containsKey("templateId")) 
				sql.append(" AND ff.templateId = :templateId ");
			if (args.containsKey("remarks")) 
				sql.append(" AND ff.remarks LIKE :remarks ");
			if (args.containsKey("createDateFrom")) 
				sql.append(" AND ff.created >= :createDateFrom ");
			if (args.containsKey("createDateTo")) 
				sql.append(" AND ff.created <= :createDateTo ");
		}
		sql.append(" ORDER BY id desc ");

		return jdbcDao.queryForList(sql.toString(), args);
	}

	public Map<String, Object> loadPDF(Long id) {
		// Pdf pdfInstance = find(id).orElseThrow(NotFoundException::new);
		// byte[] blobBytes = fileService.getfileBlob(pdfInstance.getFileId());

		StringBuilder sql = new StringBuilder("SELECT"
			+ " ff.*, "
			+ " f.filename, "
			+ " fb.bytes AS blobValue"
			+ " FROM filled_form ff "
			+ " LEFT JOIN file_blob fb ON ff.fileId = fb.fileId "
			+ " LEFT JOIN file f ON fb.fileId = f.id "
			+ " WHERE ff.deleted = FALSE"
			+ " AND ff.id = :id "
        );
        // Map<String, Object> result = jdbcDao.queryForMap(sql.toString(), Map.of("id", id)).orElseThrow(NotFoundException::new);
		// result.put("blobValue", new ByteArrayResource(blobBytes));
		// return result;
        return jdbcDao.queryForMap(sql.toString(), Map.of("id", id)).orElseThrow(NotFoundException::new);
    }

	public Map<String, Object> getPdfBlob(Long id) {
		String sql = "SELECT " +
			" fb.*, " +
			" fb.bytes AS blobValue " +
			" FROM file_blob fb " +
			" WHERE fb.deleted = FALSE " +
			" AND fb.id = :id ";
			
		return jdbcDao.queryForMap(sql, Map.of("id", id)).orElseThrow(NotFoundException::new);
    }
	
	public Integer getIdByName(String name) {
        StringBuilder sql = new StringBuilder("SELECT"
			+ " e.id "
			+ " FROM event e  "
			+ " WHERE e.deleted = FALSE"
			+ " AND e.name = :name "
        );
        
        return jdbcDao.queryForInt(sql.toString(), Map.of("name", name));
    }
	
    //This included the common fields saving
	public void saveCmField(File file, Pdf record) throws IOException {
        // byte[] pdfBytes = Files.readAllBytes(file.toPath());

        // try (FileOutputStream fos = new FileOutputStream(file)) {
        //     IOUtils.write(pdfBytes, fos);
        // }

        //PDDocument document = PDDocument.load(targetLocation.toFile());
        PDDocument document = Loader.loadPDF(file); // Changed!
        PDAcroForm acroForm = document.getDocumentCatalog().getAcroForm();

        //logger.info("acroForm? " + (acroForm != null) );
        if (acroForm != null) {
            //create CommonField if not exists for this client Id
            Long id = commonFieldService.getByClientId(record.getClientId());
            //logger.info("id? " + id);
            CommonField commonField = null;
            if(id > 0){
                commonField  = commonFieldService.find(id).orElse(new CommonField());
            }else{
                commonField = new CommonField();
            }
            //logger.info("commonField? " + commonField.toString());
            commonField.setClientId(record.getClientId());
            Map<String, Object> template = templateService.loadTemplate(record.getTemplateId());
                
            //logger.info("commonField? " + commonField.getId());
            // Example: Iterate through fields and print values
            for (PDField field : acroForm.getFields()) {
                String fieldName = field.getPartialName();
                String fieldValue = field.getValueAsString();

                String formCode = (String)template.get("remarks");

                if ("IDA".equals(formCode)) {
                   IDA(fieldName, fieldValue, commonField, acroForm);
                }

                if("FNA".equals(formCode)){
                    FNA(fieldName, fieldValue, commonField, acroForm);
                }

                if("HSBCFIN".equals(formCode)){
                    HSBCFIN(fieldName, fieldValue, commonField, acroForm);
                }

                if ("MLB03S".equals(formCode)) {
                    MLB03S(fieldName, fieldValue, commonField, acroForm);
                }

                if("MLFNA_EN".equals(formCode)){    
                    MLFNA_EN(fieldName, fieldValue, commonField, acroForm);                 
                }

                if("MLFNA_CHI".equals(formCode)){    
                    MLFNA_EN(fieldName, fieldValue, commonField, acroForm);                 
                }
                //

                if ("SLFNA_EN".equals(formCode)) {
                    SLFNA_EN(fieldName, fieldValue, commonField, acroForm);
                }

                if ("SLFNA_CHI".equals(formCode)) {
                    SLFNA_EN(fieldName, fieldValue, commonField, acroForm);
                }

                if ("SLAPP".equals(formCode)) {
                    SLAPP(fieldName, fieldValue, commonField, acroForm);
                }

                if ("HSBCA31".equals(formCode)) {
                    HSBCA31(fieldName, fieldValue, commonField, acroForm);
                }

                if ("SLGII".equals(formCode)) {
                    SLGII(fieldName, fieldValue, commonField, acroForm);
                    
                }
                
                //logger.info("end Field: " + field.getPartialName() + ", Value: " + field.getValueAsString());
                // You can save this data to a database, or perform other operations
            }

            commonFieldService.save(commonField);

            Client client = clientService.find(record.getClientId()).orElseThrow();
            //action log
            userActionLogService.createLog("Update PDF Form of Client Code:" + client.getClientCode() + " Form:" + (String)template.get("templateName") , commonField.getId(), "saveCmField");
        }
        //logger.info("ended");
        document.close(); 
        
    }

    private void IDA(String fieldName, String fieldValue, CommonField commonField,PDAcroForm acroForm){
        switch (fieldName) {
            /* Page1 Start */
            case "fill_chinese_name" -> commonField.setNameChi(fieldValue);

            case "formMedical" -> commonField.getOthers().put("formMedical", fieldValue);
            case "formNonMedical" -> commonField.getOthers().put("formNonMedical", fieldValue);
            
            case "ch_single" -> commonField.getOthers().put("maritalStatusSingle", fieldValue);
            case "ch_married" -> commonField.getOthers().put("maritalStatusMarried", fieldValue);
            case "ch_marital_others" -> commonField.getOthers().put("maritalStatusOther", fieldValue);
            case "fill_marital_others" -> commonField.getOthers().put("maritalStatusOtherDesc", fieldValue);
            
            case "fill_11" -> commonField.setIdCard(fieldValue);
            case "ch_hkid" -> commonField.getOthers().put("hkidPerm", fieldValue);
            case "ch_hkid_non" -> commonField.getOthers().put("hkidNon", fieldValue);
            case "ch_prcid" -> commonField.getOthers().put("prcId", fieldValue);
            case "ch_othersid" -> commonField.getOthers().put("othersId", fieldValue);
            case "ch_passport" -> commonField.getOthers().put("passportYes", fieldValue);
            case "ch_travel_doc" -> commonField.getOthers().put("travelDocYes", fieldValue);
            case "fill_13" -> commonField.setPassportNo(fieldValue);
            case "fill_14" -> commonField.getOthers().put("othersIdType", fieldValue);

            case "fill_12" -> commonField.setCountryOfIssue(fieldValue);
            case "fill_14_dd" -> commonField.getOthers().put("passportExpiryDD", fieldValue);
            case "fill_14_mm" -> commonField.getOthers().put("passportExpiryMM", fieldValue);
            case "fill_14_yyyy" -> commonField.getOthers().put("passportExpiryYYYY", fieldValue);
            case "fill_15" -> commonField.setPlaceOfBirth(fieldValue);
            case "fill_16" -> commonField.setCountryOfCitizenship(fieldValue);

            case "gender_m" -> {
                commonField.setGenderMale(fieldValue); 
                if("Yes".equals(fieldValue)) {
                    commonField.setGender("M");
                }
            }
            case "gender_f" -> {
                commonField.setGenderFemale(fieldValue); 
                if("Yes".equals(fieldValue)) {
                    commonField.setGender("F");
                }
            }

            case "date_dd" -> commonField.setDdDateOfBirth(fieldValue);
            case "date_mm" -> commonField.setMmDateOfBirth(fieldValue);
            case "date_yyyy" -> commonField.setYyyyDateOfBirth(fieldValue);

            //case "fill_phone_code" -> commonField.getOthers().put("contactNoCode", fieldValue);
            //case "fill_17" -> commonField.setContactNo(fieldValue);
            //case "fill_18" -> commonField.setEmail(fieldValue);
            //case "fill_19" -> commonField.getOthers().put("address1", fieldValue);
            //case "fill_19_1" -> commonField.getOthers().put("address2", fieldValue);
            //case "fill_23" -> commonField.getOthers().put("crAddress1", fieldValue);
            //case "fill_23_1" -> commonField.getOthers().put("crAddress2", fieldValue);
                                    
            case "edu_pri" -> commonField.setEduPri(fieldValue);
            case "edu_sec" -> commonField.setEduSec(fieldValue);
            case "edu_post_sec" -> {
                commonField.setEduPostSec(fieldValue);
                commonField.setEduUni(fieldValue);
            }
            /* Page1 End */
            /* Page2 Start */
            case "salary" -> commonField.setFna_c3b_salary(fieldValue);
            case "income" -> commonField.setFna_c3b_income(fieldValue);
            case "savings" -> commonField.setFna_c3b_saving(fieldValue);
            case "investments" -> commonField.setFna_c3b_investments(fieldValue);
            case "policy_replacement" -> commonField.setFna_c3b_policy(fieldValue);
            case "others_funds" -> commonField.setFna_c3b_others(fieldValue);
            case "others_funds_desc" -> commonField.setFna_c3b_desc(fieldValue);

            case "politicalYes" -> commonField.getOthers().put("politicalYes", fieldValue);
            case "politicalNo" -> commonField.getOthers().put("politicalNo", fieldValue);

            case "relate1_name" -> {
                for(int i=1; i<=9; i++){
                    if(StringUtils.trimToNull(acroForm.getField("relate" + i + "_name").getValueAsString()) != null){
                        commonField.getOthers().put("relate" + i + "_name", acroForm.getField("relate" + i + "_name").getValueAsString());
                        commonField.getOthers().put("relate" + i + "_relationship", acroForm.getField("relate" + i + "_relationship").getValueAsString());
                        commonField.getOthers().put("relate" + i + "_age", acroForm.getField("relate" + i + "_age").getValueAsString());
                        commonField.getOthers().put("relate" + i + "_occ", acroForm.getField("relate" + i + "_occ").getValueAsString());
                        commonField.getOthers().put("relate" + i + "_marital", acroForm.getField("relate" + i + "_marital").getValueAsString());
                        commonField.getOthers().put("relate" + i + "_dep_dd", acroForm.getField("relate" + i + "_dep_dd").getValueAsString());
                    }
                }
            }
            
            /* Page2 End */
            /* Page3 Start */
            case "toggle_3_2" -> commonField.setBankruptYes(fieldValue);
            case "toggle_4_2" -> commonField.setBankruptNo(fieldValue);
            case "fill_18_1" -> commonField.setBankruptDesc(fieldValue);

            case "fill_3_3" -> commonField.getOthers().put("travelCity1",fieldValue);
            case "fill_6_3" -> commonField.getOthers().put("travelCity2",fieldValue);
            case "fill_9_3" -> commonField.getOthers().put("travelCity3",fieldValue);
            case "fill_5_3" -> commonField.getOthers().put("travelPurpose1",fieldValue);
            case "fill_7_3" -> commonField.getOthers().put("travelPurpose2",fieldValue);
            case "fill_10_3" -> commonField.getOthers().put("travelPurpose3",fieldValue);
            case "fill_4_3" -> commonField.getOthers().put("travelFrequency1",fieldValue);
            case "fill_8_3" -> commonField.getOthers().put("travelFrequency2",fieldValue);
            case "fill_11_3" -> commonField.getOthers().put("travelFrequency3",fieldValue);

            /* Page3 End */
            /* Page4 Start */
            case "ch_travel_yes" -> commonField.getOthers().put("travelYes", fieldValue);
            case "ch_travel_no" -> commonField.getOthers().put("travelNo", fieldValue);

            case "toggle_1_3" -> commonField.getOthers().put("futureAddressYes", fieldValue);
            case "toggle_2_2" -> commonField.getOthers().put("futureAddressNo", fieldValue);
            case "fill_1_4_1" -> commonField.getOthers().put("futureAddress", fieldValue);
            //case "fill_1_4_2" -> commonField.getOthers().put("futureAddress2", fieldValue);
            case "fill_2_4" -> commonField.getOthers().put("futureAddressReasonHowLong", fieldValue);

            case "toggle_3_3" -> commonField.getOthers().put("futureAddressReturnYes", fieldValue);
            case "toggle_4_3" -> commonField.getOthers().put("futureAddressReturnNo", fieldValue);
            case "toggle_5_3" -> commonField.getOthers().put("futureAddressReturnNa", fieldValue);

            case "fill_3_4" -> commonField.getOthers().put("travelNextCity1", fieldValue);
            case "fill_6_4" -> commonField.getOthers().put("travelNextCity2", fieldValue);
            case "fill_9_4" -> commonField.getOthers().put("travelNextCity3", fieldValue);
            case "fill_5_4" -> commonField.getOthers().put("travelNextPurpose1", fieldValue);
            case "fill_8_4" -> commonField.getOthers().put("travelNextPurpose2", fieldValue);
            case "fill_11_4" -> commonField.getOthers().put("travelNextPurpose3", fieldValue);
            case "fill_4_4" -> commonField.getOthers().put("travelNextFrequency1", fieldValue);
            case "fill_7_4" -> commonField.getOthers().put("travelNextFrequency2", fieldValue);
            case "fill_10_4" -> commonField.getOthers().put("travelNextFrequency3", fieldValue);

            /* Page4 End */
            /* Page5 Start */                        
            case "toggle_3_4" -> commonField.getOthers().put("pendingChargeYes", fieldValue);
            case "undefined_11" -> commonField.getOthers().put("pendingChargeNo", fieldValue);

            case "tobaccoYes" -> commonField.setTobarccoYes(fieldValue);
            case "tobaccoNo" -> commonField.setTobarccoNo(fieldValue);
            
            /* Page5 End */
            /* Page6 Start */
            case "fill_8_country_1" -> commonField.setTaxResidency1(fieldValue);
            case "fill_1_6" -> commonField.setTaxPin1(fieldValue);
            case "fill_2_6" -> commonField.setTaxReason1(fieldValue);
            case "fill_3_6" -> commonField.setTaxReasonB1(fieldValue);
            case "fill_3_6a" -> commonField.getOthers().put("TaxReasonB1a", fieldValue);
            case "fill_8_country_2" -> commonField.setTaxResidency2(fieldValue);
            case "fill_4_5" -> commonField.setTaxPin2(fieldValue);
            case "fill_5_6" -> commonField.setTaxReason2(fieldValue);
            case "fill_6_6" -> commonField.setTaxReasonB2(fieldValue);
            case "fill_6_6a" -> commonField.getOthers().put("TaxReasonB2a", fieldValue);
            case "fill_8_country_3" -> commonField.setTaxResidency3(fieldValue);
            case "fill_7_6" -> commonField.setTaxPin3(fieldValue);
            case "fill_8_6" -> commonField.setTaxReason3(fieldValue);
            case "fill_9_6" -> commonField.setTaxReasonB3(fieldValue);
            case "fill_9_6a" -> commonField.getOthers().put("TaxReasonB3a", fieldValue);
            
            case "ch_high_yes" -> commonField.getOthers().put("workHighYes", fieldValue);
            case "ch_high_no" -> commonField.getOthers().put("workHighNo", fieldValue);
            case "fill_high" -> commonField.getOthers().put("workHighDesc", fieldValue);
            
            case "ch_hazard_yes" -> commonField.getOthers().put("hazardYes", fieldValue);
            case "ch_hazard_no" -> commonField.getOthers().put("hazardNo", fieldValue);
            case "toggle_17_2" -> commonField.getOthers().put("hazardAviation", fieldValue);
            case "toggle_18" -> commonField.getOthers().put("hazardSky", fieldValue);
            case "toggle_19" -> commonField.getOthers().put("hazardScuba", fieldValue);
            case "toggle_20" -> commonField.getOthers().put("hazardPowerboat", fieldValue);
            case "toggle_21" -> commonField.getOthers().put("hazardSportsCar", fieldValue);
            case "toggle_22" -> commonField.getOthers().put("hazardMotocycle", fieldValue);
            case "toggle_23" -> commonField.getOthers().put("hazardRock", fieldValue);
            case "undefined_20" -> commonField.getOthers().put("hazardOther", fieldValue);
            case "hazardousActivity" -> commonField.setHazardousActivity(fieldValue);
            
            /* Page6 End */
            /* Page7 Start */
            case "fill_11_7" -> commonField.setInsuranceCompany1_1(fieldValue);
            case "fill_12_7_1" -> {
                commonField.getOthers().put("insuranceSumInsured1_1", fieldValue);

                if(commonField.getOthers().get("insuranceSumInsured1_1") != null && !commonField.getOthers().get("insuranceSumInsured1_1").isBlank()){
                    commonField.setInsuranceCurrency1("USD");
                }
            }
            case "toggle_3_5" -> commonField.setInsuranceLife1(fieldValue);
            case "toggle_4_4" -> commonField.setInsuranceSaving1(fieldValue);
            case "toggle_5_5" -> commonField.setInsuranceCritical1(fieldValue);
            case "toggle_6_3" -> commonField.setInsuranceOther1(fieldValue);
            case "undefined_21" -> commonField.setInsuranceOtherDesc1(fieldValue);
            case "fill_1_7" -> commonField.setInsuranceYear1(fieldValue);

            case "fill_13_7" -> commonField.setInsuranceCompany2_1(fieldValue);
            case "fill_14_7_1" -> {
                commonField.getOthers().put("insuranceSumInsured2_1", fieldValue);

                if(commonField.getOthers().get("insuranceSumInsured2_1") != null && !commonField.getOthers().get("insuranceSumInsured2_1").isBlank()){
                    commonField.setInsuranceCurrency2("USD");
                }
            }
            case "toggle_9_3" -> commonField.setInsuranceLife2(fieldValue);
            case "toggle_10_3" -> commonField.setInsuranceSaving2(fieldValue);
            case "toggle_11_3" -> commonField.setInsuranceCritical2(fieldValue);
            case "toggle_12_2" -> commonField.setInsuranceOther2(fieldValue);
            case "undefined_22" -> commonField.setInsuranceOtherDesc2(fieldValue);
            case "fill_3_7" -> commonField.setInsuranceYear2(fieldValue);


            case "fill_15_7" -> commonField.setInsuranceCompany3_1(fieldValue);
            case "fill_16_7_1" -> {
                commonField.getOthers().put("insuranceSumInsured3_1", fieldValue);

                if(commonField.getOthers().get("insuranceSumInsured3_1") != null && !commonField.getOthers().get("insuranceSumInsured3_1").isBlank()){
                    commonField.setInsuranceCurrency3("USD");
                }
            }
            case "toggle_15" -> commonField.setInsuranceLife3(fieldValue);
            case "toggle_16_2" -> commonField.setInsuranceSaving3(fieldValue);
            case "toggle_17_3" -> commonField.setInsuranceCritical3(fieldValue);
            case "toggle_18_2" -> commonField.setInsuranceOther3(fieldValue);
            case "undefined_23" -> commonField.setInsuranceOtherDesc3(fieldValue);
            case "fill_5_7" -> commonField.setInsuranceYear3(fieldValue);

            case "ultimateTotalLife" -> commonField.setUltimateTotalLife(fieldValue);

            
            case "ch_apply_other_insurance_yes" -> commonField.getOthers().put("appyOtherInsuranceYes", fieldValue);
            case "ch_apply_other_insurance_no" -> commonField.getOthers().put("appyOtherInsuranceNo", fieldValue);

            case "declinedYes" -> commonField.setDeclinedYes(fieldValue);
            case "declinedNo" -> commonField.setDeclinedNo(fieldValue);
            case "declinedDesc" -> commonField.setDeclinedDesc(fieldValue);

            case "replaceInsuranceYes" -> commonField.setReplaceInsuranceYes(fieldValue);
            case "replaceInsuranceNo" -> commonField.setReplaceInsuranceNo(fieldValue);
            case "replaceInsuranceNotYet" -> commonField.getOthers().put("replaceInsuranceNotYet", fieldValue);
            case "fill_10_7" -> commonField.getOthers().put("replaceInsuranceDesc", fieldValue);
            /* Page7 End */
            /* Page8 Start */
            case "toggle_2_3" -> commonField.getOthers().put("usPerson", fieldValue);
            case "toggle_1_4" -> commonField.getOthers().put("usPersonNot", fieldValue);
            
            case "employed" -> commonField.setEmployed(fieldValue);
            case "homemaker" -> commonField.setHomemaker(fieldValue);
            case "student" -> commonField.setStudent(fieldValue);
            case "investor" -> commonField.setInvestor(fieldValue);
            case "retired" -> commonField.setRetired(fieldValue);

            case "fill_3_8" -> commonField.setOccupationTitle(fieldValue);
            case "fill_4_6_1" -> commonField.setCompanyName(fieldValue);
            case "fill_4_6_2" -> commonField.getOthers().put("companyAddress1", fieldValue);
            case "fill_4_6_3" -> commonField.getOthers().put("companyAddress2", fieldValue);
            case "fill_5_8_1" -> commonField.setCompanyNature1(fieldValue);
            case "fill_5_8_2" -> commonField.setCompanyNature2(fieldValue);

            case "toggle_6_4" -> commonField.getOthers().put("businessOwnerYes", fieldValue);
            case "fill_22_5" -> commonField.getOthers().put("businessOwnerPercent", fieldValue);
            case "fill_25_3" -> commonField.getOthers().put("businessOwnerNoEmployee", fieldValue);

            /* Page8 End */
            /* Page9 Start */
            //case "fill_26_4" -> commonField.setFna_c1a_amount(fieldValue);
            case "totalAnnualIncome" -> commonField.setTotalAnnualIncome(fieldValue);
            case "fill_26_4" -> commonField.getOthers().put("totalEarnedIncome", fieldValue);
            case "fill_27_4" -> commonField.getOthers().put("totalEarnedIncomeLastYear", fieldValue);
            case "fill_28_4" -> commonField.getOthers().put("totalUnearnedIncome", fieldValue);
            case "fill_29_4" -> commonField.getOthers().put("totalUnearnedIncomeLastYear", fieldValue);

            case "totalLiquidAsset" -> commonField.setFna_c2a_amount(fieldValue);
            case "totalLiquidLia" -> commonField.setFna_c2b_amount(fieldValue);

            case "fill_30_4" -> commonField.getOthers().put("realEstateAddress1_1", fieldValue);
            case "fill_30_4_1" -> commonField.getOthers().put("realEstateAddress1_2", fieldValue);
            case "fill_35_2" -> commonField.getOthers().put("realEstateAddress2_1", fieldValue);
            case "fill_35_2_1" -> commonField.getOthers().put("realEstateAddress2_2", fieldValue);
            case "fill_40_2" -> commonField.getOthers().put("realEstateAddress3_1", fieldValue);
            case "fill_40_2_1" -> commonField.getOthers().put("realEstateAddress3_2", fieldValue);
            case "fill_31_4" -> commonField.setRealEstatePurchaseDate1(fieldValue);
            case "fill_36_2" -> commonField.setRealEstatePurchaseDate2(fieldValue);
            case "fill_41_2" -> commonField.setRealEstatePurchaseDate3(fieldValue);

            /* Page9 End */

            /* Page10 Start */

            //case "ch1_12_self" -> commonField.setEmployedSelf(fieldValue);
            case "emp_employed" -> commonField.setEmployed(fieldValue);
            case "emp_homemaker" -> commonField.setHomemaker(fieldValue);
            case "emp_student" -> commonField.setStudent(fieldValue);
            //case "ch1_12_housewife" -> commonField.setEmployedSelf(fieldValue);
            case "emp_retired" -> commonField.setRetired(fieldValue);

            case "emp1_position" -> commonField.getOthers().put("empPosition", fieldValue);
            case "emp1_company_name" -> commonField.getOthers().put("empCompanyName", fieldValue);
            case "emp1_duties" -> commonField.getOthers().put("empDuties", fieldValue);
            case "emp1_company_address" -> commonField.getOthers().put("empCompanyAddress", fieldValue);
            case "emp1_natureA" -> commonField.getOthers().put("empNatureA", fieldValue);
            case "emp1_natureB" -> commonField.getOthers().put("empNatureB", fieldValue);

            case "toggle_3_7" -> commonField.getOthers().put("sourceIncome", fieldValue);
            case "toggle_4_6" -> commonField.getOthers().put("sourceBusiness", fieldValue);
            case "toggle_6_5" -> commonField.getOthers().put("sourceInvestment", fieldValue);
            case "undefined_33" -> commonField.getOthers().put("sourceInheritance", fieldValue);
            case "toggle_7_5" -> commonField.getOthers().put("sourceOther", fieldValue);
            case "fill_2_9" -> commonField.getOthers().put("sourceOtherDesc", fieldValue);
            /* Page10 End */

            /* Page11 Start */
            case "emp_other_benefits_yes" -> commonField.getOthers().put("empOtherBenefitsYes", fieldValue);
            case "emp_other_benefits_no" -> commonField.getOthers().put("empOtherBenefitsNo", fieldValue);


            /* Page11 End */
            case "toggle_12_3" -> commonField.setFna_c3c_yes(fieldValue);
            case "toggle_13_3" -> commonField.setFna_c3c_no(fieldValue);
            
        }

        /* Special logic Start */
        //test the concat 
        if( ("date_dd".equals(fieldName) || "date_mm".equals(fieldName) || "date_yyyy".equals(fieldName) ) 
            && StringUtils.isNotEmpty(commonField.getDdDateOfBirth()) && StringUtils.isNotEmpty(commonField.getMmDateOfBirth()) && StringUtils.isNotEmpty(commonField.getYyyyDateOfBirth()) ) {
            commonField.setDateOfBirth(commonField.getDdDateOfBirth() + "/" +  commonField.getMmDateOfBirth()  + "/" + commonField.getYyyyDateOfBirth());
        }

        if( ("toggle_17_2".equals(fieldName) ) ){
            if("Yes".equals(acroForm.getField("toggle_17_2").getValueAsString()) ||"Yes".equals(acroForm.getField("toggle_18").getValueAsString())||"Yes".equals(acroForm.getField("toggle_19").getValueAsString())
                || "Yes".equals(acroForm.getField("toggle_20").getValueAsString()) ||"Yes".equals(acroForm.getField("toggle_21").getValueAsString())||"Yes".equals(acroForm.getField("toggle_22").getValueAsString())
                || "Yes".equals(acroForm.getField("toggle_23").getValueAsString()) ||"Yes".equals(acroForm.getField("undefined_20").getValueAsString())){
                    commonField.getOthers().put("hazard", "Yes");
                }
        }
            
        /* Special logic End */
    } 

    private void FNA(String fieldName, String fieldValue, CommonField commonField,PDAcroForm acroForm){
        switch (fieldName) {
            /* Page1 Start */
            //case "fna_a_birth" -> commonField.setDateOfBirth(fieldValue);
            case "fna_a_id_card" -> commonField.setIdCard(fieldValue);
            //case "fna_a_occupation" -> commonField.setOccupationTitle(fieldValue);

            case "fna_a_life_0" -> commonField.setFna_a_life_0(fieldValue);
            case "fna_a_life_less_5" -> commonField.setFna_a_life_less_5(fieldValue);
            case "fna_a_life_above_5" -> commonField.setFna_a_life_above_5(fieldValue);
            
            case "fna_a_primary" -> commonField.setEduPri(fieldValue);
            case "fna_a_secondary" -> commonField.setEduSec(fieldValue);
            case "fna_a_tertiary" -> commonField.setEduPostSec(fieldValue);

            case "fna_a_marital" -> commonField.setMaritalStatus(fieldValue);
            case "fna_a_contact" -> commonField.setContactNo(fieldValue);
            case "fna_a_dependents" -> commonField.setNoOfDependents(fieldValue);

            case "fna_c1a_amount" -> commonField.setTotalAnnualIncome(fieldValue);
            case "fna_c1b_amount" -> commonField.setFna_c1b_amount(fieldValue);
            case "fna_c1c_1_amount" -> commonField.setFna_c1c_1_amount(fieldValue);
            case "fna_c1c_2_amount" -> commonField.setFna_c1c_2_amount(fieldValue);
            case "fna_c1c_3_amount" -> commonField.setFna_c1c_3_amount(fieldValue);
            case "fna_c1d_amount" -> commonField.setFna_c1d_amount(fieldValue);
            case "fna_c2a_amount" -> commonField.setFna_c2a_amount(fieldValue);

            case "fna_c2a_cash" -> commonField.setFna_c2a_cash(fieldValue);
            case "fna_c2a_market_account" -> commonField.setFna_c2a_market_account(fieldValue);
            case "fna_c2a_bank_account" -> commonField.setFna_c2a_bank_account(fieldValue);
            case "fna_c2a_stocks" -> commonField.setFna_c2a_stocks(fieldValue);
            case "fna_c2a_bonds" -> commonField.setFna_c2a_bonds(fieldValue);
            case "fna_c2a_us" -> commonField.setFna_c2a_us(fieldValue);
            case "fna_c2a_others" -> commonField.setFna_c2a_others(fieldValue);
            case "fna_c2a_desc" -> commonField.setFna_c2a_desc(fieldValue);
            
            case "fna_c2b_amount" -> commonField.setFna_c2b_amount(fieldValue);
            case "fna_c2c_amount" -> commonField.setFna_c2c_amount(fieldValue);
            case "fna_c2d_amount" -> commonField.setFna_c2d_amount(fieldValue);
            case "fna_c2e_amount" -> commonField.setFna_c2e_amount(fieldValue);
            case "fna_b1_a" -> commonField.setFna_b1_a(fieldValue);
            case "fna_b1_a_amount" -> commonField.setFna_b1_a_amount(fieldValue);
            case "fna_b1_b" -> commonField.setFna_b1_b(fieldValue);
            case "fna_b1a_4_amount" -> commonField.setFna_b1a_4_amount(fieldValue);
            case "fna_b1b_1" -> commonField.setFna_b1b_1(fieldValue);
            case "fna_b1b_2" -> commonField.setFna_b1b_2(fieldValue);
            case "fna_b1b_3" -> commonField.setFna_b1b_3(fieldValue);
            case "fna_b1_c" -> commonField.setFna_b1_c(fieldValue);
            case "fna_b1_d" -> commonField.setFna_b1_d(fieldValue);
            case "fna_b1_d_year" -> commonField.setFna_b1_d_year(fieldValue);
            case "fna_b1_d_amount" -> commonField.setFna_b1_d_amount(fieldValue);

            /* Page1 End */
            /* Page2 Start */
            case "fna_b1_e" -> commonField.setFna_b1_e(fieldValue);
            case "fna_b1_f" -> commonField.setFna_b1_f(fieldValue);
            case "fna_b1_f_other" -> commonField.setFna_b1_f_other(fieldValue);
            case "fna_b1_f_desc" -> commonField.setFna_b1_f_desc(fieldValue);
            case "fna_b2_a" -> commonField.setFna_b2_a(fieldValue);
            case "fna_b2_b" -> commonField.setFna_b2_b(fieldValue);
            case "fna_b2_c" -> commonField.setFna_b2_c(fieldValue);
            case "fna_b2_d" -> commonField.setFna_b2_d(fieldValue);
            case "fna_b2_e" -> commonField.setFna_b2_e(fieldValue);
            case "fna_b2_f" -> commonField.setFna_b2_f(fieldValue);
            case "fna_b2_g" -> commonField.setFna_b2_g(fieldValue);
            /* Page2 End */
            /* Page3 Start */
            case "fna_c1e_10" -> commonField.setFna_c1e_10(fieldValue);
            case "fna_c1e_10_20" -> commonField.setFna_c1e_10_20(fieldValue);
            case "fna_c1e_21_30" -> commonField.setFna_c1e_21_30(fieldValue);
            case "fna_c1e_31_40" -> commonField.setFna_c1e_31_40(fieldValue);
            case "fna_c1e_41_50" -> commonField.setFna_c1e_41_50(fieldValue);
            case "fna_c1e_50" -> commonField.setFna_c1e_50(fieldValue);                        
            /* Page3 End */
            /* Page4 Start */
            case "fna_c2f_10" -> commonField.setFna_c2f_10(fieldValue);
            case "fna_c2f_10_20" -> commonField.setFna_c2f_10_20(fieldValue);
            case "fna_c2f_21_30" -> commonField.setFna_c2f_21_30(fieldValue);
            case "fna_c2f_31_40" -> commonField.setFna_c2f_31_40(fieldValue);
            case "fna_c2f_41_50" -> commonField.setFna_c2f_41_50(fieldValue);
            case "fna_c2f_50" -> commonField.setFna_c2f_50(fieldValue);
            /* Page4 End */
            /* Page5 End */
            case "fna_c3a_2_5" -> commonField.setFna_c3a_2_5(fieldValue);
            case "fna_c3a_6_10" -> commonField.setFna_c3a_6_10(fieldValue);
            case "fna_c3a_11_15" -> commonField.setFna_c3a_11_15(fieldValue);
            case "fna_c3a_16_20" -> commonField.setFna_c3a_16_20(fieldValue);
            case "fna_c3a_20" -> commonField.setFna_c3a_20(fieldValue);
            case "fna_c3a_life" -> commonField.setFna_c3a_life(fieldValue);
            case "fna_c3a_single_pay" -> commonField.setFna_c3a_single_pay(fieldValue);
            case "fna_c3a_single_pay_max" -> commonField.getOthers().put("singlePayAmount", fieldValue);
            
            case "fna_a_retire" -> commonField.setFna_a_retire(fieldValue);
            case "fna_c3b_salary" -> commonField.setFna_c3b_salary(fieldValue);
            case "fna_c3b_income" -> commonField.setFna_c3b_income(fieldValue);
            case "fna_c3b_saving" -> commonField.setFna_c3b_saving(fieldValue);
            case "fna_c3b_investments" -> commonField.setFna_c3b_investments(fieldValue);
            case "fna_c3b_policy" -> commonField.setFna_c3b_policy(fieldValue);
            case "fna_c3b_others" -> commonField.setFna_c3b_others(fieldValue);
            case "fna_c3b_desc" -> commonField.setFna_c3b_desc(fieldValue);

            case "fna_c3c_yes" -> commonField.setFna_c3c_yes(fieldValue);
            case "fna_c3c_no" -> commonField.setFna_c3c_no(fieldValue);
            /* Page5 End */
            /* Page6 Start */
            case "fna_d_1" -> commonField.setFna_d_1(fieldValue);
            case "fna_d_2" -> commonField.setFna_d_2(fieldValue);
            case "fna_d_3" -> commonField.setFna_d_3(fieldValue);
            case "fna_d_desc" -> commonField.setFna_d_desc(fieldValue);

            case "fna_d_b1_1" -> commonField.getOthers().put("recObj1", fieldValue);
            case "fna_d_b1_2" -> commonField.getOthers().put("recObj2", fieldValue);
            case "fna_d_b1_3" -> commonField.getOthers().put("recObj3", fieldValue);
            case "fna_d_b1_4" -> commonField.getOthers().put("recObj4", fieldValue);
            case "fna_d_b1_5" -> commonField.getOthers().put("recObj5", fieldValue);
            case "fna_d_b1_6" -> commonField.getOthers().put("recObj6", fieldValue);

            case "fna_d_name_1" -> commonField.getOthers().put("recProd1_1", fieldValue);
            case "fna_d_name_2" -> commonField.getOthers().put("recProd2_1", fieldValue);
            case "fna_d_name_3" -> commonField.getOthers().put("recProd3_1", fieldValue);
            case "fna_d_name_4" -> commonField.getOthers().put("recProd4_1", fieldValue);
            case "fna_d_name_5" -> commonField.getOthers().put("recProd5_1", fieldValue);
            case "fna_d_name_6" -> commonField.getOthers().put("recProd6_1", fieldValue);
             
            case "fna_d_product_1" -> commonField.getOthers().put("recSelect1_1", fieldValue);
            case "fna_d_product_2" -> commonField.getOthers().put("recSelect2_1", fieldValue);
            case "fna_d_product_3" -> commonField.getOthers().put("recSelect3_1", fieldValue);
            case "fna_d_product_4" -> commonField.getOthers().put("recSelect4_1", fieldValue);
            case "fna_d_product_5" -> commonField.getOthers().put("recSelect5_1", fieldValue);
            case "fna_d_product_6" -> commonField.getOthers().put("recSelect6_1", fieldValue);
            /* Page6 End */
        }
    }

    private void HSBCFIN(String fieldName, String fieldValue, CommonField commonField,PDAcroForm acroForm){
        switch (fieldName) {
            /* Page1 Start */
            case "fill_4" -> commonField.setNameChi(fieldValue);
            //case "fill_5" -> commonField.setGender(fieldValue);
            //case "fill_6" -> commonField.setDateOfBirth(fieldValue);

            case "fill_7" -> commonField.setMaritalStatus(fieldValue);
            case "fill_8" -> commonField.setNoOfDependents(fieldValue);
            case "fill_9" -> commonField.setOccupationTitle(fieldValue);
            case "fill_10" -> commonField.setContactNo(fieldValue);

            case "toggle_1" -> commonField.setEduPri(fieldValue);
            case "toggle_2" -> commonField.setEduSec(fieldValue);
            case "toggle_3" -> commonField.setEduPostSec(fieldValue);
            
            case "fill_11" -> {
                if(fieldValue != null){
                    //convert to annual income
                    //commonField.setFna_c1a_amount( String.valueOf(Math.round(NumberUtils.toDouble(fieldValue)/12)) );
                }
            }

            case "fill_12" -> {
                if(fieldValue != null){
                    //convert to annual income
                    commonField.setFna_c1b_amount( String.valueOf(Math.round(NumberUtils.toDouble(fieldValue)/12)) );
                }
            }
            
            case "fill_12a" -> commonField.setFna_c1c_3_amount(fieldValue);
            case "fill_13" -> commonField.setFna_c1c_1_amount(fieldValue);
            case "fill_14" -> commonField.setFna_c1c_2_amount(fieldValue);
            case "fill_16" -> commonField.setFna_c1d_amount(fieldValue);
            /* Page1 End */
            /* Page2 Start */
            case "fill_01" -> commonField.setFna_c2a_amount(fieldValue);
            case "fill_02" -> commonField.setFna_c2b_amount(fieldValue);
            case "fill_03" -> commonField.setFna_c2c_amount(fieldValue);
            case "fill_04" -> commonField.setFna_c2d_amount(fieldValue);
            case "fill_05" -> commonField.setFna_c2e_amount(fieldValue);
            
            case "Financial Protection" -> commonField.setFna_b1_a(fieldValue);
            case "Preparation" -> commonField.setFna_b1_b(fieldValue);
            case "Providing" -> commonField.setFna_b1_c(fieldValue);
            case "Saving" -> commonField.setFna_b1_d(fieldValue);
            case "Investment" -> commonField.setFna_b1_e(fieldValue);
            case "Others" -> commonField.setFna_b1_f(fieldValue);
            case "fill_8_2" -> commonField.setFna_b1_f_other(fieldValue);
            case "fill_8_21" -> commonField.setFna_b1_f_desc(fieldValue);
            /* Page2 End */
            /* Page3 Start */
            case "toggle_91" -> commonField.setFna_b1_a(fieldValue);
            case "fill_1_4" -> commonField.setFna_b1_a_amount(fieldValue);
            case "fill_1_4b" -> commonField.setFna_b1a_4_amount(fieldValue);
            
            case "toggle_93" -> commonField.setFna_b1b_1(fieldValue);
            case "toggle_94" -> commonField.setFna_b1b_3(fieldValue);

            case "fill_1_4c" -> commonField.setFna_b1_d_year(fieldValue);
            case "fill_1_4d" -> commonField.setFna_b1_d_year(fieldValue);
            case "fill_1_4e" -> commonField.setFna_b1_d_amount(fieldValue);

            case "toggle_4_2" -> commonField.setFna_b2_a(fieldValue);
            case "toggle_5" -> commonField.setFna_b2_b(fieldValue);
            case "toggle_6" -> commonField.setFna_b2_c(fieldValue);
            case "toggle_7" -> commonField.setFna_b2_d(fieldValue);
            case "toggle_8" -> commonField.setFna_b2_e(fieldValue);
            case "toggle_9" -> commonField.setFna_b2_f(fieldValue);
            case "toggle_10" -> commonField.setFna_b2_g(fieldValue);
            /* Page3 End */
            /* Page4 Start */
            case "toggle_1_2" -> commonField.setFna_c3a_2_5(fieldValue);
            case "toggle_2_2" -> commonField.setFna_c3a_6_10(fieldValue);
            case "toggle_3_2" -> commonField.setFna_c3a_11_15(fieldValue);
            case "toggle_4_3" -> commonField.setFna_c3a_16_20(fieldValue);
            case "toggle_5_2" -> commonField.setFna_c3a_20(fieldValue);
            case "toggle_6_2" -> commonField.setFna_c3a_life(fieldValue);
            case "toggle_6_2_sum" -> commonField.setFna_c3a_single_pay(fieldValue);

            case "fill_98_04" -> commonField.setFna_a_retire(fieldValue);
            /* Page4 End */
            /* Page5 Start */
            
            //since it will tick both income and salary and make SLHK income and salary ticked
            //case "toggle_1f" -> {commonField.setFna_c3b_income(fieldValue); commonField.setFna_c3b_salary(fieldValue);}
            //case "toggle_1g" -> {commonField.setFna_c3b_saving(fieldValue); commonField.setFna_c3b_investments(fieldValue);}
            //case "toggle_1h" -> commonField.setFna_c3b_policy(fieldValue);
            case "toggle_1i56" -> commonField.setFna_c3b_others(fieldValue);
            case "Text3" -> commonField.setFna_c3b_desc(fieldValue);
            
            case "Check Box6" -> commonField.setFna_c1e_10(fieldValue);
            case "Check Box7" -> commonField.setFna_c1e_10_20(fieldValue);
            case "Check Box8" -> commonField.setFna_c1e_21_30(fieldValue);
            case "Check Box9" -> commonField.setFna_c1e_31_40(fieldValue);
            case "Check Box10" -> commonField.setFna_c1e_41_50(fieldValue);
            case "Check Box11" -> commonField.setFna_c1e_50(fieldValue);

            case "Check Box12" -> commonField.setFna_c2f_10(fieldValue);
            case "Check Box13" -> commonField.setFna_c2f_10_20(fieldValue);
            case "Check Box14" -> commonField.setFna_c2f_21_30(fieldValue);
            case "Check Box15" -> commonField.setFna_c2f_31_40(fieldValue);
            case "Check Box16" -> commonField.setFna_c2f_41_50(fieldValue);
            case "Check Box17" -> commonField.setFna_c2f_50(fieldValue);
            /* Page5 End */

        }
    }

    private void MLB03S(String fieldName, String fieldValue, CommonField commonField,PDAcroForm acroForm){
        switch (fieldName) {
            /* Page1 Start */
            case "ChineseName1" -> commonField.setNameChi(fieldValue);

            case "male" -> commonField.setGenderMale(fieldValue);
            case "female" -> commonField.setGenderFemale(fieldValue);

            //case "DD1" -> commonField.setDdDateOfBirth(fieldValue);
            //case "MM1" -> commonField.setMmDateOfBirth(fieldValue);
            //case "YYYY1" -> commonField.setYyyyDateOfBirth(fieldValue);

            /*
            case "hk" -> {
                if("Yes".equals(fieldValue))
                    commonField.setPlaceOfBirth("Hong Kong");
            }
            case "macau" -> {
                if("Yes".equals(fieldValue))
                    commonField.setPlaceOfBirth("Macau");
            }
            */
            //case "Field_LocationA1" -> commonField.setPlaceOfBirth(fieldValue);
            //case "Field_LocationB1" -> commonField.setPlaceOfBirth(fieldValue);

            //case "ID1" -> commonField.setIdCard(fieldValue);

            /*
            case "Nationality1" -> commonField.setCountryOfCitizenship(fieldValue);
            case "Company1" -> commonField.setCompanyName(fieldValue);
            case "BusinessNature1" -> commonField.setCompanyNature1(fieldValue);
            case "BusinessNature2" -> commonField.setCompanyNature2(fieldValue);
            case "Occupation1" -> commonField.setOccupation(fieldValue);
            case "JobNature1" -> commonField.setOccupationTitle(fieldValue);
            */

            //Income1 = IDA commonField.getIncomeSalary() + commonField.getIncomeBonus() ??? beware of it may have , and english P.A. or even USD
            case "Checkbox_Y" -> commonField.setTobarccoYes(fieldValue);
            case "Checkbox_N" -> commonField.setTobarccoNo(fieldValue);
            /* Page1 End */
            /* Page2 Start */
            /*
            case "Room3" -> commonField.getOthers().put("corAddressRoom", fieldValue);
            case "Floor3" -> commonField.getOthers().put("corAddressFloor", fieldValue);
            case "Block3" -> commonField.getOthers().put("corAddressBlock", fieldValue);
            case "Building3" -> commonField.getOthers().put("corAddressBuilding", fieldValue);
            case "Street3" -> commonField.getOthers().put("corAddressStreet", fieldValue);
            case "City3" -> commonField.getOthers().put("corAddressCity", fieldValue);
            case "District3" -> commonField.getOthers().put("corAddressDistrict", fieldValue);
            case "Country3" -> commonField.getOthers().put("corAddressCountry", fieldValue);
            case "PostalCode3" -> commonField.getOthers().put("corAddressPostalCode", fieldValue);

            case "ContactB1" -> commonField.setContactNo(fieldValue);
            case "Email" -> commonField.setEmail(fieldValue);
            */
            /* Page2 End */
            /* Page3 Start */
            case "Checkbox_Wealth1" -> commonField.getOthers().put("sourceIncome", fieldValue);
            case "Checkbox_Wealth2" -> commonField.getOthers().put("sourceInvestment", fieldValue);
            case "Checkbox_Wealth3" -> commonField.getOthers().put("sourceInheritance", fieldValue);
            case "Checkbox_Wealth4" -> commonField.getOthers().put("sourceOther", fieldValue);
            case "Field_Wealth4" -> commonField.getOthers().put("sourceOtherDesc", fieldValue);
            
            case "Checkbox_EudcationPri" -> commonField.setEduPri(fieldValue);
            case "Checkbox_EudcationSec" -> commonField.setEduSec(fieldValue);
            case "Checkbox_EudcationPostSec" -> commonField.setEduPostSec(fieldValue);
            case "Checkbox_EudcationTer" -> commonField.setEduUni(fieldValue);
            /* Page3 End */
            /* Page7 Start */
            
            /*
            case "Residency1" -> commonField.setTaxResidency1(fieldValue);
            case "Residency2" -> commonField.setTaxResidency2(fieldValue);
            case "Residency3" -> commonField.setTaxResidency3(fieldValue);
            case "TIN1" -> commonField.setTaxPin1(fieldValue);
            case "TIN2" -> commonField.setTaxPin2(fieldValue);
            case "TIN3" -> commonField.setTaxPin3(fieldValue);
            case "ABC1" -> commonField.setTaxReason1(fieldValue);
            case "ABC2" -> commonField.setTaxReason2(fieldValue);
            case "ABC3" -> commonField.setTaxReason3(fieldValue);
            case "Reason1" -> commonField.setTaxReasonB1(fieldValue);
            case "Reason2" -> commonField.setTaxReasonB2(fieldValue);
            case "Reason3" -> commonField.setTaxReasonB3(fieldValue);
            */
                                    
            /* Page7 End */
            /* Page8 Start */
            case "c_DeclartionYes" -> commonField.setReplaceInsuranceYes(fieldValue);
            case "c_DeclartionNo" -> commonField.setReplaceInsuranceNo(fieldValue);
            /* Page8 End */
            
        }
    }

    private void MLFNA_EN(String fieldName, String fieldValue, CommonField commonField,PDAcroForm acroForm){
        switch (fieldName) {
            /* Page1 Start */
            case "part2_1a" -> commonField.setFna_b1_a(fieldValue);
            case "part2_1a_amount" -> commonField.setFna_b1_a_amount(fieldValue);

            case "part2_1b" -> commonField.setFna_b1_c(fieldValue);

            case "part2_1c" -> commonField.setFna_b1_d(fieldValue);
            case "part2_1c_amount" -> commonField.setFna_b1_d_amount(fieldValue);                        

            case "part2_1d" -> commonField.setFna_b1_e(fieldValue);

            /* exported year? only can one way from FNA b1 d year
            case "part2_1c_a" -> commonField.setFna_b2_a(fieldValue);
            case "part2_1c_b" -> commonField.setFna_b2_b(fieldValue);
            case "part2_1c_c" -> commonField.setFna_b2_c(fieldValue);
            case "part2_1c_d" -> commonField.setFna_b2_d(fieldValue);
            case "part2_1c_e" -> commonField.setFna_b2_e(fieldValue);
            case "part2_1c_f" -> commonField.setFna_b2_f(fieldValue);
            case "part2_1c_g" -> commonField.setFna_b2_g(fieldValue);
                */

            case "part2_1d_1" -> commonField.setFna_b1b_1(fieldValue);
            case "part2_1d_2" -> commonField.setFna_b1b_2(fieldValue);
            case "part2_1d_3" -> commonField.setFna_b1b_3(fieldValue);

            case "part2_1e" -> commonField.setFna_b1_b(fieldValue);

            case "part2_1f" -> commonField.setFna_b1_f(fieldValue);
            case "part2_1f_desc" -> commonField.setFna_b1_f_other(fieldValue);

            
            case "a Business Earning" -> commonField.setFna_c3b_salary(fieldValue);
            case "b Others Please specify" -> commonField.setFna_c3b_income(fieldValue);
            case "Check Box15" -> commonField.setFna_c3b_investments(fieldValue);
            case "Check Box16" -> commonField.setFna_c3b_others(fieldValue);                        
            case "undefined_6" -> commonField.setFna_c3b_desc(fieldValue);
            
            case "part2_2_a" -> commonField.setFna_b2_a(fieldValue);
            case "part2_2_b" -> commonField.setFna_b2_b(fieldValue);
            case "part2_2_c" -> commonField.setFna_b2_c(fieldValue);
            case "part2_2_d" -> commonField.setFna_b2_d(fieldValue);
            case "part2_2_e" -> commonField.setFna_b2_e(fieldValue);
            case "part2_2_f" -> commonField.setFna_b2_f(fieldValue);
            case "part2_2_g" -> commonField.setFna_b2_g(fieldValue);
            /* Page1 End */
            /* Page2 Start */
            case "part3_3_1" -> commonField.setTotalAnnualIncome(fieldValue); //need to /7.78
            case "part3_3_2" -> commonField.setFna_c1b_amount(fieldValue); //need to /7.78

            case "part3_3_4" -> commonField.setFna_c2a_amount(fieldValue); //need to /7.78

            //case "part3_3_5_2a" -> commonField.setFna_c3b_saving(fieldValue);
            //case "part3_3_5_2b" -> commonField.setFna_c3b_investments(fieldValue);
            //case "part3_3_5_2c" -> commonField.setFna_c3b_others(fieldValue);
            //case "part3_3_5_2c_other" -> commonField.setFna_c3b_desc(fieldValue);

            case "part3_3_6_yes" -> commonField.setFna_c3c_yes(fieldValue);
            case "part3_3_6_no" -> commonField.setFna_c3c_no(fieldValue);

            case "part3_3_6_2" -> commonField.setFna_c1c_3_amount(fieldValue); //monthly!

            /* Page2 End */
            /* Page3 Start */
            /*
            case "part3_4_4_1a" -> commonField.setFna_c3a_2_5(fieldValue); 
            case "part3_4_4_1b" -> commonField.setFna_c3a_6_10(fieldValue); 
            case "part3_4_4_1c" -> commonField.setFna_c3a_11_15(fieldValue); 
            case "part3_4_4_1d" -> commonField.setFna_c3a_16_20(fieldValue); 
            //case "part3_4_4_1e" -> commonField.setFna_c3a_life(fieldValue); 
            case "part3_4_4_1f" -> commonField.setFna_c3a_life(fieldValue); 
        
            case "part3_4_single_pay" -> commonField.setFna_c3a_single_pay(fieldValue); 
            */
            /* Page3 End */

        }
    }

    private void SLFNA_EN(String fieldName, String fieldValue, CommonField commonField,PDAcroForm acroForm){
        switch (fieldName) {
            /* Page1 Start */
            //case "date_of_birth" -> commonField.setDateOfBirth(fieldValue);
            //case "occupation" -> commonField.setOccupationTitle(fieldValue);
            //case "address1" -> commonField.getOthers().put("address1", fieldValue);
            //case "address2" -> commonField.getOthers().put("address2", fieldValue);
            //case "contact" -> commonField.setContactNo(fieldValue);
            //case "email" -> commonField.setEmail(fieldValue);

            /*            case "chh1" -> commonField.setEduPri(fieldValue);
            case "chh2" -> commonField.setEduSec(fieldValue);
            case "chh3" -> commonField.setEduPostSec(fieldValue);
            case "chh4" -> commonField.setEduPostSec(fieldValue); //duplicate now
             */


            case "chh5" -> commonField.setFna_a_life_0(fieldValue);
            case "chh6" -> commonField.setFna_a_life_less_5(fieldValue);
            case "chh7" -> commonField.setFna_a_life_above_5(fieldValue);

            case "cb1a" -> commonField.setFna_b1_a(fieldValue);
            case "cb1b" -> commonField.setFna_b1_b(fieldValue);
            case "cb1c" -> commonField.setFna_b1_c(fieldValue);
            case "cb1d" -> commonField.setFna_b1_d(fieldValue);
            case "1amount" -> commonField.setFna_b1_d_amount(fieldValue);
            case "cb1e" -> commonField.setFna_b1_e(fieldValue);
            case "cb1f" -> commonField.setFna_b1_f_other(fieldValue);

            case "cb10" -> commonField.setFna_b1b_1(fieldValue);
            case "cb11" -> commonField.setFna_b1b_2(fieldValue);
            case "cb12" -> commonField.setFna_b1b_3(fieldValue);
            
            case "cb13" -> commonField.setFna_b2_a(fieldValue);
            case "cb14" -> commonField.setFna_b2_b(fieldValue);
            case "cb15" -> commonField.setFna_b2_c(fieldValue);
            case "cb16" -> commonField.setFna_b2_d(fieldValue);
            case "cb17" -> commonField.setFna_b2_e(fieldValue);
            case "cb18" -> commonField.setFna_b2_f(fieldValue);
            case "cb19" -> commonField.setFna_b2_g(fieldValue);
            /* Page1 End */

            /* Page2 Start */                        
            //case "cb4a1" -> commonField.setFna_c1d_amount(fieldValue); //need to set the check box when get                        

            //case "4a1" -> commonField.setFna_c1d_amount(fieldValue);                        
            case "4b1" -> commonField.setFna_c2a_amount(fieldValue);
            
            case "cb4b1" -> commonField.setFna_c2a_cash(fieldValue);
            case "cb4b2" -> commonField.setFna_c2a_bank_account(fieldValue);
            case "cb4b3" -> commonField.setFna_c2a_market_account(fieldValue);
            case "cb4b4" -> commonField.setFna_c2a_stocks(fieldValue);
            case "cb4b5" -> commonField.setFna_c2a_bonds(fieldValue);
            case "cb4b6" -> commonField.setFna_c2a_us(fieldValue);
            case "cb4b7" -> commonField.setFna_c2a_others(fieldValue);
            case "4b2" -> commonField.setFna_c2a_desc(fieldValue);

            case "4b3" -> commonField.setFna_c2b_amount(fieldValue);

            case "cb4c1" -> commonField.setFna_c3a_2_5(fieldValue);
            case "cb4c2" -> commonField.setFna_c3a_6_10(fieldValue);
            case "cb4c3" -> commonField.setFna_c3a_11_15(fieldValue);
            case "cb4c4" -> commonField.setFna_c3a_16_20(fieldValue);
            case "cb4c5" -> commonField.setFna_c3a_20(fieldValue);
            case "cb4c6" -> commonField.setFna_c3a_life(fieldValue);

            case "cb4d1" -> commonField.setFna_c1e_10(fieldValue);
            case "cb4d2" -> commonField.setFna_c1e_10_20(fieldValue);
            case "cb4d3" -> commonField.setFna_c1e_21_30(fieldValue);
            case "cb4d4" -> commonField.setFna_c1e_31_40(fieldValue);
            case "cb4d5" -> commonField.setFna_c1e_41_50(fieldValue);
            case "cb4d6" -> commonField.setFna_c1e_50(fieldValue);

            case "cb4e1" -> commonField.setFna_c3b_salary(fieldValue);
            case "cb4e2" -> commonField.setFna_c3b_income(fieldValue);
            case "cb4e3" -> commonField.setFna_c3b_investments(fieldValue);
            case "cb4e4" -> commonField.setFna_c3b_saving(fieldValue);
            case "cb4e5" -> commonField.setFna_c3b_others(fieldValue);
            case "4e" -> commonField.setFna_c3b_desc(fieldValue);

            case "cb4h1" -> commonField.setFna_c3c_yes(fieldValue);
            case "cb4h2" -> commonField.setFna_c3c_no(fieldValue);
            
            /* Page2 End */


            /* Page4 Start */
            case "cb6a1" -> commonField.setFna_d_1(fieldValue);
            case "cb6a2" -> commonField.setFna_d_3(fieldValue);
            case "6a2_other1" -> commonField.setFna_d_desc(fieldValue);

            case "5obj1" -> commonField.getOthers().put("recObj1", fieldValue);
            case "5obj2" -> commonField.getOthers().put("recObj2", fieldValue);
            case "5obj3" -> commonField.getOthers().put("recObj3", fieldValue);
            case "5obj4" -> commonField.getOthers().put("recObj4", fieldValue);
            case "5obj5" -> commonField.getOthers().put("recObj5", fieldValue);
            case "5obj6" -> commonField.getOthers().put("recObj6", fieldValue);

            case "5name1_1" -> commonField.getOthers().put("recProd1_1", fieldValue);
            case "5name2_1" -> commonField.getOthers().put("recProd2_1", fieldValue);
            case "5name3_1" -> commonField.getOthers().put("recProd3_2", fieldValue);
            case "5name4_1" -> commonField.getOthers().put("recProd4_1", fieldValue);
            case "5name5_1" -> commonField.getOthers().put("recProd5_1", fieldValue);
            case "5name6_1" -> commonField.getOthers().put("recProd6_1", fieldValue);
            
            case "5slected1_1" -> commonField.getOthers().put("recSelect1_1", fieldValue);
            case "5slected2_1" -> commonField.getOthers().put("recSelect2_1", fieldValue);
            case "5slected3_1" -> commonField.getOthers().put("recSelect3_1", fieldValue);
            case "5slected4_1" -> commonField.getOthers().put("recSelect4_1", fieldValue);
            case "5slected5_1" -> commonField.getOthers().put("recSelect5_1", fieldValue);
            case "5slected6_1" -> commonField.getOthers().put("recSelect6_1", fieldValue);
            /* Page4 End */

        }

        /* Special logic Start */
        
        /* Special logic End */
    }

    private void SLAPP(String fieldName, String fieldValue, CommonField commonField,PDAcroForm acroForm){
        switch (fieldName) {
            /* Page1 Start */
            case "policyNo" -> commonField.getOthers().put("SLAppPolicyNo", "611" + fieldValue);
            case "1_6_last" -> commonField.getOthers().put("SLAppAge", fieldValue);

            case "1_2_name_ch" -> commonField.setNameChi(fieldValue);
            
            case "ch1_4_m" -> commonField.setGenderMale(fieldValue);
            case "ch1_4_f" -> commonField.setGenderFemale(fieldValue);

            //case "1_6_dd" -> commonField.setDdDateOfBirth(fieldValue);
            //case "1_6_mm" -> commonField.setMmDateOfBirth(fieldValue);
            //case "1_6_yyyy" -> commonField.setYyyyDateOfBirth(fieldValue);

            //case "1_7_country" -> commonField.setPlaceOfBirth(fieldValue);
            //case "1_8" -> commonField.setCountryOfCitizenship(fieldValue);
            
            //if set countryOfIssue = HK
            //tick th 1_10_2 if have value
            /*
            case "1_10_id_num" -> {
                commonField.setIdCard(fieldValue);
                commonField.setCountryOfIssue("HK");
            }
            */

            //case "1_10_passport_num" -> commonField.setPassportNo(fieldValue);

            /*
            case "1_12_1" -> commonField.setOccupation(fieldValue);
            case "1_12_2" -> commonField.setOccupationTitle(fieldValue);

            //case "1_12_5" -> commonField.setFna_c1a_amount(fieldValue);
            case "1_12_6" -> commonField.setCompanyName(fieldValue);
            
            case "1_12_7_1" -> commonField.getOthers().put("companyAddress1", fieldValue);
            case "1_12_7_2" -> commonField.getOthers().put("companyAddress2", fieldValue);

            case "1_12_8_1" -> commonField.setCompanyNature1(fieldValue);
            case "1_12_8_2" -> commonField.setCompanyNature2(fieldValue);

            case "ch1_13_corr_rm" -> commonField.getOthers().put("corAddressRoom", fieldValue);
            case "ch1_13_corr_floor" -> commonField.getOthers().put("corAddressFloor", fieldValue);
            case "ch1_13_corr_block" -> commonField.getOthers().put("corAddressBlock", fieldValue);
            case "ch1_13_corr_building" -> commonField.getOthers().put("corAddressBuilding", fieldValue);
            case "ch1_13_corr_street" -> commonField.getOthers().put("corAddressStreet", fieldValue);
            case "ch1_13_corr_country" -> commonField.getOthers().put("corAddressCountry", fieldValue);
            case "ch1_13_corr_zip" -> commonField.getOthers().put("corAddressPostalCode", fieldValue);
            case "ch1_13_corr_hk" -> commonField.getOthers().put("corAddressHk", fieldValue);
            case "ch1_13_corr_kln" -> commonField.getOthers().put("corAddressKln", fieldValue);
            case "ch1_13_corr_nt" -> commonField.getOthers().put("corAddressNt", fieldValue);

            case "1_13_tel_mobile" -> commonField.setContactNo(fieldValue);
            
            case "1_14d_tax1" -> commonField.setTaxResidency1(fieldValue);
            case "1_14d_tax_num1" -> commonField.setTaxPin1(fieldValue);
            //case "ch1_14d_reason1_a" -> commonField.setTaxReason1("A");
            //case "ch1_14d_reason1_b" -> commonField.setTaxReason1("B");
            //case "ch1_14d_reason1_c" -> commonField.setTaxReason1("C");
            case "1_14d_explain1" -> commonField.setTaxReasonB1(fieldValue);

            case "1_14d_tax2" -> commonField.setTaxResidency2(fieldValue);
            case "1_14d_tax_num2" -> commonField.setTaxPin2(fieldValue);
            //case "ch1_14d_reason2_a" -> commonField.setTaxReason2("A");
            //case "ch1_14d_reason2_b" -> commonField.setTaxReason2("B");
            //case "ch1_14d_reason2_c" -> commonField.setTaxReason2("C");
            case "1_14d_explain2" -> commonField.setTaxReasonB2(fieldValue);

            case "1_14d_tax3" -> commonField.setTaxResidency3(fieldValue);
            case "1_14d_tax_num3" -> commonField.setTaxPin3(fieldValue);
            //case "ch1_14d_reason3_a" -> commonField.setTaxReason3("A");
            //case "ch1_14d_reason3_b" -> commonField.setTaxReason3("B");
            //case "ch1_14d_reason3_c" -> commonField.setTaxReason3("C");
            case "1_14d_explain3" -> commonField.setTaxReasonB3(fieldValue);

            */

            case "ch2_5_1p" -> commonField.setEduPri(fieldValue);
            case "ch2_5_1s" -> commonField.setEduSec(fieldValue);
            case "ch2_5_1m" -> commonField.setEduPostSec(fieldValue);
            case "ch2_5_1u" -> commonField.setEduUni(fieldValue);

            case "ch2_5_2w" -> commonField.setFna_a_life_0(fieldValue);
            case "ch2_5_2_less5" -> commonField.setFna_a_life_less_5(fieldValue);
            case "ch2_5_2_5above" -> commonField.setFna_a_life_above_5(fieldValue);
            
            case "4_1_name1_1" -> commonField.setInsuranceCompany1_1(fieldValue);
            case "4_1_name1_2" -> commonField.setInsuranceCompany1_2(fieldValue);
            //case "4_1_name1_3" -> commonField.setInsuranceCompany1_3(fieldValue);
            case "4_1_year1" -> commonField.setInsuranceYear1(fieldValue);
            case "4_1_currency1" -> commonField.setInsuranceCurrency1(fieldValue);
            case "4_1_sum1_1" -> commonField.getOthers().put("insuranceSumInsured1_1", fieldValue);
            case "4_1_sum1_2" -> commonField.getOthers().put("insuranceSumInsured1_2", fieldValue);
            case "4_1_sum1_3" -> commonField.getOthers().put("insuranceSumInsured1_3", fieldValue);
            case "ch4_1_life" -> {
                if(acroForm.getField("4_1_sum1") != null && acroForm.getField("4_1_sum1").getValueAsString() != null ){
                    if("Off".equals(fieldValue) && !acroForm.getField("4_1_sum1").getValueAsString().isBlank())
                        commonField.setInsuranceLife1("Yes");
                    else if("On".equals(fieldValue) && !acroForm.getField("4_1_sum1").getValueAsString().isBlank())
                        commonField.setInsuranceLife1("Off");
                }
                
            }
            case "ch4_1_accident" -> {
                if(acroForm.getField("4_1_sum1") != null && acroForm.getField("4_1_sum1").getValueAsString() != null ){
                    if("Off".equals(fieldValue) && !acroForm.getField("4_1_sum1").getValueAsString().isBlank()){
                        commonField.setInsuranceOther1("Yes");
                        commonField.setInsuranceOtherDesc1("Accident");
                    }else if("On".equals(fieldValue) && !acroForm.getField("4_1_sum1").getValueAsString().isBlank()){
                        //commonField.setInsuranceOther1("Off");
                        //commonField.setInsuranceOtherDesc1("");
                    }
                }
                
            }
            case "ch4_1_critical" -> {
                if(acroForm.getField("4_1_sum1") != null && acroForm.getField("4_1_sum1").getValueAsString() != null ){
                    if("Off".equals(fieldValue) && !acroForm.getField("4_1_sum1").getValueAsString().isBlank())
                        commonField.setInsuranceCritical1("Yes");
                    else if("On".equals(fieldValue) && !acroForm.getField("4_1_sum1").getValueAsString().isBlank())
                        commonField.setInsuranceCritical1("Off");
                }
                
            }
            case "ch4_1_hospital" -> {
                if(acroForm.getField("4_1_sum1") != null && acroForm.getField("4_1_sum1").getValueAsString() != null ){
                    if("Off".equals(fieldValue) && !acroForm.getField("4_1_sum1").getValueAsString().isBlank()){
                        commonField.setInsuranceOther1("Yes");
                        commonField.setInsuranceOtherDesc1("Hospital");
                    }else if("On".equals(fieldValue)){
                        //commonField.setInsuranceOther1("Off");
                        //commonField.setInsuranceOtherDesc1("");
                    }
                }
                
            }
            
            case "4_1_name2_1" -> commonField.setInsuranceCompany2_1(fieldValue);
            case "4_1_name2_2" -> commonField.setInsuranceCompany2_2(fieldValue);
            //case "4_1_name2_3" -> commonField.setInsuranceCompany2_3(fieldValue);
            case "4_1_year2" -> commonField.setInsuranceYear2(fieldValue);
            case "4_1_currency2" -> commonField.setInsuranceCurrency2(fieldValue);
            case "4_1_sum2_1" -> commonField.getOthers().put("insuranceSumInsured2_1", fieldValue);
            case "4_1_sum2_2" -> commonField.getOthers().put("insuranceSumInsured2_2", fieldValue);
            case "4_1_sum2_3" -> commonField.getOthers().put("insuranceSumInsured12_3", fieldValue);
            case "ch4_2_life" -> {
                if(acroForm.getField("4_1_sum2") != null && acroForm.getField("4_1_sum2").getValueAsString() != null ){
                    if("Off".equals(fieldValue) && !acroForm.getField("4_1_sum2").getValueAsString().isBlank())
                        commonField.setInsuranceLife2("Yes");
                    else if("On".equals(fieldValue) && !acroForm.getField("4_1_sum2").getValueAsString().isBlank())
                        commonField.setInsuranceLife2("Off");
                }
                
            }
            case "ch4_2_accident" -> {
                if(acroForm.getField("4_1_sum2") != null && acroForm.getField("4_1_sum2").getValueAsString() != null ){
                    if("Off".equals(fieldValue) && !acroForm.getField("4_1_sum2").getValueAsString().isBlank()){
                        commonField.setInsuranceOther2("Yes");
                        commonField.setInsuranceOtherDesc2("Accident");
                    }else if("On".equals(fieldValue) && !acroForm.getField("4_1_sum2").getValueAsString().isBlank()){
                        //commonField.setInsuranceOther1("Off");
                        //commonField.setInsuranceOtherDesc1("");
                    }
                }
                
            }
            case "ch4_2_critical" -> {
                if(acroForm.getField("4_1_sum2") != null && acroForm.getField("4_1_sum2").getValueAsString() != null ){
                    if("Off".equals(fieldValue) && !acroForm.getField("4_1_sum2").getValueAsString().isBlank())
                        commonField.setInsuranceCritical2("Yes");
                    else if("On".equals(fieldValue) && !acroForm.getField("4_1_sum2").getValueAsString().isBlank())
                        commonField.setInsuranceCritical2("Off");
                }
                
            }
            case "ch4_2_hospital" -> {
                if(acroForm.getField("4_1_sum2") != null && acroForm.getField("4_1_sum2").getValueAsString() != null ){
                    if("Off".equals(fieldValue) && !acroForm.getField("4_1_sum2").getValueAsString().isBlank()){
                        commonField.setInsuranceOther2("Yes");
                        commonField.setInsuranceOtherDesc2("Hospital");
                    }else if("On".equals(fieldValue) && !acroForm.getField("4_1_sum2").getValueAsString().isBlank()){
                        //commonField.setInsuranceOther1("Off");
                        //commonField.setInsuranceOtherDesc1("");
                    }
                }
                
            }

            case "4_1_name3_1" -> commonField.setInsuranceCompany3_1(fieldValue);
            case "4_1_name3_2" -> commonField.setInsuranceCompany3_2(fieldValue);
            //case "4_1_name3_3" -> commonField.setInsuranceCompany3_3(fieldValue);
            case "4_1_year3" -> commonField.setInsuranceYear3(fieldValue);
            case "4_1_currency3" -> commonField.setInsuranceCurrency3(fieldValue);
            case "4_1_sum3_1" -> commonField.getOthers().put("insuranceSumInsured3_1", fieldValue);
            case "4_1_sum3_2" -> commonField.getOthers().put("insuranceSumInsured3_2", fieldValue);
            case "4_1_sum3_3" -> commonField.getOthers().put("insuranceSumInsured3_3", fieldValue);
            case "ch4_3_life" -> {
                if(acroForm.getField("4_1_sum3") != null && acroForm.getField("4_1_sum3").getValueAsString() != null ){
                    if("Off".equals(fieldValue) && !acroForm.getField("4_1_sum3").getValueAsString().isBlank())
                        commonField.setInsuranceLife3("Yes");
                    else if("On".equals(fieldValue) && !acroForm.getField("4_1_sum3").getValueAsString().isBlank())
                        commonField.setInsuranceLife3("Off");
                }
                
            }
            case "ch4_3_accident" -> {
                if(acroForm.getField("4_1_sum3") != null && acroForm.getField("4_1_sum3").getValueAsString() != null ){
                    if("Off".equals(fieldValue) && !acroForm.getField("4_1_sum3").getValueAsString().isBlank()){
                        commonField.setInsuranceOther3("Yes");
                        commonField.setInsuranceOtherDesc3("Accident");
                    }else if("On".equals(fieldValue) && !acroForm.getField("4_1_sum3").getValueAsString().isBlank()){
                        //commonField.setInsuranceOther1("Off");
                        //commonField.setInsuranceOtherDesc1("");
                    }
                }
                
            }
            case "ch4_3_critical" -> {
                if(acroForm.getField("4_1_sum3") != null && acroForm.getField("4_1_sum3").getValueAsString() != null ){
                    if("Off".equals(fieldValue) && !acroForm.getField("4_1_sum3").getValueAsString().isBlank())
                        commonField.setInsuranceCritical3("Yes");
                    else if("On".equals(fieldValue) && !acroForm.getField("4_1_sum3").getValueAsString().isBlank())
                        commonField.setInsuranceCritical3("Off");
                }
                
            }
            case "ch4_3_hospital" -> {
                if(acroForm.getField("4_1_sum3") != null && acroForm.getField("4_1_sum3").getValueAsString() != null ){
                    if("Off".equals(fieldValue) && !acroForm.getField("4_1_sum3").getValueAsString().isBlank()){
                        commonField.setInsuranceOther3("Yes");
                        commonField.setInsuranceOtherDesc3("Hospital");
                    }else if("On".equals(fieldValue) && !acroForm.getField("4_1_sum3").getValueAsString().isBlank()){
                        //commonField.setInsuranceOther1("Off");
                        //commonField.setInsuranceOtherDesc1("");
                    }
                }
                
            }

            /* Page13 Start */
            case "ch7e_1_yes" -> commonField.getOthers().put("travelYes", fieldValue);
            case "ch7e_1_no" -> commonField.getOthers().put("travelNo", fieldValue);

            /* Page13 End */
        }
    }

    private void HSBCA31(String fieldName, String fieldValue, CommonField commonField,PDAcroForm acroForm){
        switch (fieldName) {
            /* Page1 Start */
            case "fill_17" -> commonField.setNameChi(fieldValue);
            
            /*
            case "Text1" -> commonField.setIdCard(fieldValue);
            case "passportNo" -> commonField.setPassportNo(fieldValue);
            case "Text12" -> commonField.setCountryOfIssue(fieldValue);
            case "fill_18" -> commonField.setDateOfBirth(fieldValue);
            case "Checkk Box6" -> commonField.setGenderMale(fieldValue);
            case "Check kBox7" -> commonField.setGenderFemale(fieldValue);

            case "fill_19" -> commonField.setCountryOfCitizenship(fieldValue);
            case "fill_20" -> commonField.setPlaceOfBirth(fieldValue);
             */

            /* Page1 End */
            /* Page2 Start */
            //case "Text16_1" -> commonField.getOthers().put("crAddress1", fieldValue);
            //case "Text16_2" -> commonField.getOthers().put("crAddress2", fieldValue);

            //case "address1" -> commonField.getOthers().put("address1", fieldValue);
            //case "address2" -> commonField.getOthers().put("address2", fieldValue);

            //case "undefined_6" -> commonField.setContactNo(fieldValue);

            //case "Text182" -> commonField.setEmail(fieldValue);
            case "Check Box175" -> commonField.setEmployedSelf(fieldValue);
            case "Check Box177" -> commonField.setEmployed(fieldValue);
            case "Check Box179" -> commonField.setPartTime(fieldValue);
            case "Check Box181" -> commonField.setEmployedNon(fieldValue);
            case "Check Box176" -> commonField.setStudent(fieldValue);
            case "Check Box178" -> commonField.setHomemaker(fieldValue);
            case "Check Box180" -> commonField.setRetired(fieldValue);

            /*
            case "Text174" -> commonField.setCompanyName(fieldValue);
            case "Text173_1" -> commonField.setCompanyNature1(fieldValue);
            case "Text173_2" -> commonField.setCompanyNature2(fieldValue);
            case "fill_16_2" -> commonField.setOccupationTitle(fieldValue);
            case "fill_17_1" -> commonField.getOthers().put("companyAddress1", fieldValue);
            case "fill_17_2" -> commonField.getOthers().put("companyAddress2", fieldValue);
             */

            /* Page2 End */
            /* Page3 Start */
            //case "undefined_51" -> commonField.setContactNo(fieldValue);
            /* Page3 End */
            /* Page12 Start */
            case "undefined_17ha_1" -> commonField.setInsuranceCompany1_1(fieldValue);
            case "undefined_17ha_2" -> commonField.setInsuranceCompany1_2(fieldValue);
            //case "undefined_17ha_3" -> commonField.setInsuranceCompany1_3(fieldValue);
            case "undefined_17hk_1" -> commonField.getOthers().put("insuranceSumInsured1_1", fieldValue);
            case "undefined_17hk_2" -> commonField.getOthers().put("insuranceSumInsured1_2", fieldValue);
            //case "undefined_17hk_3" -> commonField.getOthers().put("insuranceSumInsured1_3", fieldValue);

            case "undefined_17hl" -> commonField.setInsuranceYear1(fieldValue);

            case "undefined_17hn_1" -> commonField.setInsuranceCompany2_1(fieldValue);
            case "undefined_17hn_2" -> commonField.setInsuranceCompany2_2(fieldValue);
            //case "undefined_17hn_3" -> commonField.setInsuranceCompany2_3(fieldValue);
            case "undefined_17ho_1" -> commonField.getOthers().put("insuranceSumInsured2_1", fieldValue);
            case "undefined_17ho_2" -> commonField.getOthers().put("insuranceSumInsured2_2", fieldValue);
            //case "undefined_17ho_3" -> commonField.getOthers().put("insuranceSumInsured2_3", fieldValue);

            case "undefined_17hp" -> commonField.setInsuranceYear1(fieldValue);

            case "undefined_17hr_1" -> commonField.setInsuranceCompany3_1(fieldValue);
            case "undefined_17hr_2" -> commonField.setInsuranceCompany3_2(fieldValue);
            //case "undefined_17hr_3" -> commonField.setInsuranceCompany3_3(fieldValue);
            case "undefined_17hsb_1" -> commonField.getOthers().put("insuranceSumInsured3_1", fieldValue);
            case "undefined_17hsb_2" -> commonField.getOthers().put("insuranceSumInsured3_2", fieldValue);
            //case "undefined_17hsb_3" -> commonField.getOthers().put("insuranceSumInsured3_3", fieldValue);
            case "undefined_17ht" -> commonField.setInsuranceYear1(fieldValue);

            case "fill_2_6" -> commonField.setUltimateTotalLife(fieldValue);

            case "Check Box74b" -> commonField.setDeclinedYes(fieldValue);
            case "Check Box74_1a" -> commonField.setDeclinedNo(fieldValue);
            case "fill_2_6e" -> commonField.setDeclinedDesc(fieldValue);

            case "fill_15_7y" -> commonField.setDeclinedDesc(fieldValue);

            case "Check Box74bc" -> commonField.getOthers().put("futureAddressYes", fieldValue);
            case "Check Box74_1ah" -> commonField.getOthers().put("futureAddressNo", fieldValue);
            /* Page12 End */
            /* Page13 Start */
            /*
            case "fill_9_6" -> commonField.setIncomeSalary(fieldValue);
            case "fill_1k0_5" -> commonField.setIncomeSalaryLastYear(fieldValue);
            case "fill_13_4" -> commonField.setIncomeBonus(fieldValue);
            case "fill_14_4" -> commonField.setIncomeBonusLastYear(fieldValue);
            case "fill_17_7" -> commonField.setIncomeInterest(fieldValue);
            case "fill_18_6" -> commonField.setIncomeInterestLastYear(fieldValue);
            case "fill_2k1_5" -> commonField.setAssetInvestment(fieldValue);
            
            case "fill_2k9_3" -> commonField.setIncomeDividents(fieldValue);
            case "fill_3k0_3" -> commonField.setIncomeDividentsLastYear(fieldValue);
            case "fill_k33_3" -> commonField.setIncomeRentals(fieldValue);
            case "fill_34_2" -> commonField.setIncomeRentalsLastYear(fieldValue);
            case "fill_k37_2" -> commonField.setIncomeOther(fieldValue);
            case "fill_38_2" -> commonField.setIncomeOtherLastYear(fieldValue);
           
            case "fill_39_2" -> commonField.setFna_c1b_amount(fieldValue);

            case "fill_4114" -> commonField.setAssetCash(fieldValue);
            case "fill_4916" -> commonField.setAssetRealEstate(fieldValue);
            case "fill_5720" -> commonField.setAssetInvestment(fieldValue);
            case "fill_5318" -> commonField.setAssetProperties(fieldValue);

            case "fill_111130" -> commonField.setFna_c2a_amount(fieldValue);
            case "fill_1111" -> commonField.setFna_c2b_amount(fieldValue);
            */

            /* Page13 End */
            /* Page14 Start */
            case "fill_73_1" -> commonField.getOthers().put("realEstateAddress1_1", fieldValue);
            case "fill_73_2" -> commonField.getOthers().put("realEstateAddress1_2", fieldValue);
            case "fill_77_1" -> commonField.getOthers().put("realEstateAddress2_1", fieldValue);
            case "fill_77_2" -> commonField.getOthers().put("realEstateAddress2_2", fieldValue);
            case "fill_81_1" -> commonField.getOthers().put("realEstateAddress3_1", fieldValue);
            case "fill_81_2" -> commonField.getOthers().put("realEstateAddress3_2", fieldValue);
            case "fill_74" -> commonField.setRealEstatePurchaseDate1(fieldValue);
            case "fill_78" -> commonField.setRealEstatePurchaseDate2(fieldValue);
            case "fill_82" -> commonField.setRealEstatePurchaseDate3(fieldValue);

            case "Check Box65f" -> commonField.setOwn_income(fieldValue);
            case "Check Box65d" -> commonField.setPremium_financing(fieldValue);
            case "Check Box65c" -> commonField.setSavings(fieldValue);

            case "Check Box65b" -> commonField.setBankruptYes(fieldValue);
            case "Check Box83" -> commonField.setBankruptNo(fieldValue);
            case "Text26001" -> commonField.setBankruptDesc(fieldValue);
            /* Page14 End */
            case "fill_4_12" -> commonField.setFna_a_retire(fieldValue);

            /* Page27 Start */
            case "toggle_7_47" -> commonField.setFna_c3a_single_pay(fieldValue);
            /* Page27 End */

        }
    }

    private void SLGII(String fieldName, String fieldValue, CommonField commonField,PDAcroForm acroForm){
        switch (fieldName) {
            /* Page1 Start */
            case "ChineseName1" -> commonField.setNameChi(fieldValue);

            case "ch1_4_m" -> commonField.setGenderMale(fieldValue);
            case "ch1_4_f" -> commonField.setGenderFemale(fieldValue);
            
            case "ch1_5n" -> commonField.setTobarccoYes(fieldValue);
            case "ch1_5s" -> commonField.setTobarccoNo(fieldValue);

            //case "1_7" -> commonField.setPlaceOfBirth(fieldValue);
            //case "1_8" -> commonField.setCountryOfCitizenship(fieldValue);
            
            /*
            case "1_10id" -> {
                commonField.setIdCard(fieldValue);
                commonField.setPlaceOfBirth("Hong Kong");
            } 
            case "1_10passport" -> {
                commonField.setPassportNo(fieldValue);
            } 
                
            case "fill_14_date" -> commonField.getOthers().put("passportExpiryDate", fieldValue);
             */
            /* Page1 End */
            /* Page2 Start */                        
            case "ch1_12_self" -> commonField.setEmployedSelf(fieldValue);
            case "ch1_12_full" -> commonField.setEmployed(fieldValue);
            case "ch1_12_student" -> commonField.setStudent(fieldValue);
            case "ch1_12_housewife" -> commonField.setPartTime(fieldValue);
            case "ch1_12_part" -> commonField.setHomemaker(fieldValue);
            case "ch1_12_retired" -> commonField.setRetired(fieldValue);

            //case "1_12_occupation" -> commonField.setOccupation(fieldValue);
            //case "1_12_exact_duty" -> commonField.setOccupationTitle(fieldValue);

            //case "1_12_employer" -> commonField.setCompanyName(fieldValue);
            //case "1_12_employer_address_1" -> commonField.getOthers().put("companyAddress1", fieldValue);
            //case "1_12_employer_address_2" -> commonField.getOthers().put("companyAddress2", fieldValue);

            //case "1_12_nature_1" -> commonField.setCompanyNature1(fieldValue);
            //case "1_12_nature_2" -> commonField.setCompanyNature2(fieldValue);
            
            /* Page2 End */                                                
            /* Page3 Start */
            //case "1_13b_tel_mobile_code" -> commonField.setContactNo(fieldValue);
            //case "1_13b_email" -> commonField.setEmail(fieldValue);
            
            case "1_14d_tax1" -> commonField.setTaxResidency1(fieldValue);
            case "1_14d_tax2" -> commonField.setTaxResidency2(fieldValue);
            case "1_14d_tax3" -> commonField.setTaxResidency3(fieldValue);
            case "1_14d_tax_num1" -> commonField.setTaxPin1(fieldValue);
            case "1_14d_tax_num2" -> commonField.setTaxPin2(fieldValue);
            case "1_14d_tax_num3" -> commonField.setTaxPin3(fieldValue);
            /*
            case "ch1_14d_reason1_a" -> {
                if("Off".equals(fieldValue)){
                    commonField.setTaxReason1("A");
                }
            }
            case "ch1_14d_reason1_b" -> {
                if("Off".equals(fieldValue)){
                    commonField.setTaxReason1("B");
                }
            }
            case "ch1_14d_reason1_c" -> {
                if("Off".equals(fieldValue)){
                    commonField.setTaxReason1("C");
                }
            }
            case "ch1_14d_reason2_a" -> {
                if("Off".equals(fieldValue)){
                    commonField.setTaxReason2("A");
                }
            }
            case "ch1_14d_reason2_b" -> {
                if("Off".equals(fieldValue)){
                    commonField.setTaxReason2("B");
                }
            }
            case "ch1_14d_reason2_c" -> {
                if("Off".equals(fieldValue)){
                    commonField.setTaxReason2("C");
                }
            }
            case "ch1_14d_reason3_a" -> {
                if("Off".equals(fieldValue)){
                    commonField.setTaxReason3("A");
                }
            }
            case "ch1_14d_reason3_b" -> {
                if("Off".equals(fieldValue)){
                    commonField.setTaxReason3("B");
                }
            }
            case "ch1_14d_reason3_c" -> {
                if("Off".equals(fieldValue)){
                    commonField.setTaxReason3("C");
                }
            }
            */
            case "1_14d_explain1" -> commonField.setTaxReasonB1(fieldValue);
            case "1_14d_explain2" -> commonField.setTaxReasonB2(fieldValue);
            case "1_14d_explain3" -> commonField.setTaxReasonB3(fieldValue);
            /* Page3 End */
            /* Page6 Start */
            case "4_1_name1_1" -> commonField.setInsuranceCompany1_1(fieldValue);
            case "4_1_name2_1" -> commonField.setInsuranceCompany2_1(fieldValue);
            case "4_1_name3_1" -> commonField.setInsuranceCompany3_1(fieldValue);
            case "4_1_year1" -> commonField.setInsuranceYear1(fieldValue);
            case "4_1_year2" -> commonField.setInsuranceYear2(fieldValue);
            case "4_1_year3" -> commonField.setInsuranceYear3(fieldValue);

            case "4_1_sum1_1" -> commonField.getOthers().put("insuranceSumInsured1_1", fieldValue);
            case "4_1_sum2_1" -> commonField.getOthers().put("insuranceSumInsured2_1", fieldValue);
            case "4_1_sum3_1" -> commonField.getOthers().put("insuranceSumInsured3_1", fieldValue);
            case "ch4_1_life" -> {
                if(acroForm.getField("4_1_sum1") != null && acroForm.getField("4_1_sum1").getValueAsString() != null ){
                    if("Off".equals(fieldValue) && !acroForm.getField("4_1_sum1").getValueAsString().isBlank())
                        commonField.setInsuranceLife1("Yes");
                    else if("On".equals(fieldValue) && !acroForm.getField("4_1_sum1").getValueAsString().isBlank())
                        commonField.setInsuranceLife1("Off");
                }
                
            }
            case "ch4_1_accident" -> {
                if(acroForm.getField("4_1_sum1") != null && acroForm.getField("4_1_sum1").getValueAsString() != null ){
                    if("Off".equals(fieldValue) && !acroForm.getField("4_1_sum1").getValueAsString().isBlank()){
                        commonField.setInsuranceOther1("Yes");
                        commonField.setInsuranceOtherDesc1("Accident");
                    }else if("On".equals(fieldValue) && !acroForm.getField("4_1_sum1").getValueAsString().isBlank()){
                        //commonField.setInsuranceOther1("Off");
                        //commonField.setInsuranceOtherDesc1("");
                    }
                }
                
            }
            case "ch4_1_critical" -> {
                if(acroForm.getField("4_1_sum1") != null && acroForm.getField("4_1_sum1").getValueAsString() != null ){
                    if("Off".equals(fieldValue) && !acroForm.getField("4_1_sum1").getValueAsString().isBlank())
                        commonField.setInsuranceCritical1("Yes");
                    else if("On".equals(fieldValue) && !acroForm.getField("4_1_sum1").getValueAsString().isBlank())
                        commonField.setInsuranceCritical1("Off");
                }
                
            }
            case "ch4_1_hospital" -> {
                if(acroForm.getField("4_1_sum1") != null && acroForm.getField("4_1_sum1").getValueAsString() != null ){
                    if("Off".equals(fieldValue) && !acroForm.getField("4_1_sum1").getValueAsString().isBlank()){
                        commonField.setInsuranceOther1("Yes");
                        commonField.setInsuranceOtherDesc1("Hospital");
                    }else if("On".equals(fieldValue)){
                        //commonField.setInsuranceOther1("Off");
                        //commonField.setInsuranceOtherDesc1("");
                    }
                }
                
            }
            case "ch4_2_life" -> {
                if(acroForm.getField("4_1_sum2") != null && acroForm.getField("4_1_sum2").getValueAsString() != null ){
                    if("Off".equals(fieldValue) && !acroForm.getField("4_1_sum2").getValueAsString().isBlank())
                        commonField.setInsuranceLife2("Yes");
                    else if("On".equals(fieldValue) && !acroForm.getField("4_1_sum2").getValueAsString().isBlank())
                        commonField.setInsuranceLife2("Off");
                }
                
            }
            case "ch4_2_accident" -> {
                if(acroForm.getField("4_1_sum2") != null && acroForm.getField("4_1_sum2").getValueAsString() != null ){
                    if("Off".equals(fieldValue) && !acroForm.getField("4_1_sum2").getValueAsString().isBlank()){
                        commonField.setInsuranceOther2("Yes");
                        commonField.setInsuranceOtherDesc2("Accident");
                    }else if("On".equals(fieldValue) && !acroForm.getField("4_1_sum2").getValueAsString().isBlank()){
                        //commonField.setInsuranceOther1("Off");
                        //commonField.setInsuranceOtherDesc1("");
                    }
                }
                
            }
            case "ch4_2_critical" -> {
                if(acroForm.getField("4_1_sum2") != null && acroForm.getField("4_1_sum2").getValueAsString() != null ){
                    if("Off".equals(fieldValue) && !acroForm.getField("4_1_sum2").getValueAsString().isBlank())
                        commonField.setInsuranceCritical2("Yes");
                    else if("On".equals(fieldValue) && !acroForm.getField("4_1_sum2").getValueAsString().isBlank())
                        commonField.setInsuranceCritical2("Off");
                }
                
            }
            case "ch4_2_hospital" -> {
                if(acroForm.getField("4_1_sum2") != null && acroForm.getField("4_1_sum2").getValueAsString() != null ){
                    if("Off".equals(fieldValue) && !acroForm.getField("4_1_sum2").getValueAsString().isBlank()){
                        commonField.setInsuranceOther2("Yes");
                        commonField.setInsuranceOtherDesc2("Hospital");
                    }else if("On".equals(fieldValue) && !acroForm.getField("4_1_sum2").getValueAsString().isBlank()){
                        //commonField.setInsuranceOther1("Off");
                        //commonField.setInsuranceOtherDesc1("");
                    }
                }
                
            }
            case "ch4_3_life" -> {
                if(acroForm.getField("4_1_sum3") != null && acroForm.getField("4_1_sum3").getValueAsString() != null ){
                    if("Off".equals(fieldValue) && !acroForm.getField("4_1_sum3").getValueAsString().isBlank())
                        commonField.setInsuranceLife3("Yes");
                    else if("On".equals(fieldValue) && !acroForm.getField("4_1_sum3").getValueAsString().isBlank())
                        commonField.setInsuranceLife3("Off");
                }
                
            }
            case "ch4_3_accident" -> {
                if(acroForm.getField("4_1_sum3") != null && acroForm.getField("4_1_sum3").getValueAsString() != null ){
                    if("Off".equals(fieldValue) && !acroForm.getField("4_1_sum3").getValueAsString().isBlank()){
                        commonField.setInsuranceOther3("Yes");
                        commonField.setInsuranceOtherDesc3("Accident");
                    }else if("On".equals(fieldValue) && !acroForm.getField("4_1_sum3").getValueAsString().isBlank()){
                        //commonField.setInsuranceOther1("Off");
                        //commonField.setInsuranceOtherDesc1("");
                    }
                }
                
            }
            case "ch4_3_critical" -> {
                if(acroForm.getField("4_1_sum3") != null && acroForm.getField("4_1_sum3").getValueAsString() != null ){
                    if("Off".equals(fieldValue) && !acroForm.getField("4_1_sum3").getValueAsString().isBlank())
                        commonField.setInsuranceCritical3("Yes");
                    else if("On".equals(fieldValue) && !acroForm.getField("4_1_sum3").getValueAsString().isBlank())
                        commonField.setInsuranceCritical3("Off");
                }
                
            }
            case "ch4_3_hospital" -> {
                if(acroForm.getField("4_1_sum3") != null && acroForm.getField("4_1_sum3").getValueAsString() != null ){
                    if("Off".equals(fieldValue) && !acroForm.getField("4_1_sum3").getValueAsString().isBlank()){
                        commonField.setInsuranceOther3("Yes");
                        commonField.setInsuranceOtherDesc3("Hospital");
                    }else if("On".equals(fieldValue) && !acroForm.getField("4_1_sum3").getValueAsString().isBlank()){
                        //commonField.setInsuranceOther1("Off");
                        //commonField.setInsuranceOtherDesc1("");
                    }
                }
                
            }
            
            
            case "5_1a_city1" -> commonField.getOthers().put("travelCity1", fieldValue);
            case "5_1a_city2" -> commonField.getOthers().put("travelCity2", fieldValue);
            case "5_1a_city3" -> commonField.getOthers().put("travelCity3", fieldValue);
            case "5_1a_purpose1" -> commonField.getOthers().put("travelPurpose1", fieldValue);
            case "5_1a_purpose2" -> commonField.getOthers().put("travelPurpose2", fieldValue);
            case "5_1a_purpose3" -> commonField.getOthers().put("travelPurpose3", fieldValue);
            case "5_1a_frequency1" -> commonField.getOthers().put("travelFrequency1", fieldValue);
            case "5_1a_frequency2" -> commonField.getOthers().put("travelFrequency2", fieldValue);
            case "5_1a_frequency3" -> commonField.getOthers().put("travelFrequency3", fieldValue);
            /*
            setValueIfPresent(form, "5_1a_city1", commonField.getOthers().get("travelCity1"));
            setValueIfPresent(form, "5_1a_city2", commonField.getOthers().get("travelCity2"));
            setValueIfPresent(form, "5_1a_city3", commonField.getOthers().get("travelCity3"));
            setValueIfPresent(form, "5_1a_purpose1", commonField.getOthers().get("travelPurpose1"));
            setValueIfPresent(form, "5_1a_purpose2", commonField.getOthers().get("travelPurpose2"));
            setValueIfPresent(form, "5_1a_purpose3", commonField.getOthers().get("travelPurpose3"));
            setValueIfPresent(form, "5_1a_frequency1", commonField.getOthers().get("travelFrequency1"));
            setValueIfPresent(form, "5_1a_frequency2", commonField.getOthers().get("travelFrequency2"));
            setValueIfPresent(form, "5_1a_frequency3", commonField.getOthers().get("travelFrequency3"));
                */
            case "5_1b_city1" -> commonField.getOthers().put("travelNextCity1", fieldValue);
            case "5_1b_city2" -> commonField.getOthers().put("travelNextCity2", fieldValue);
            case "5_1b_city3" -> commonField.getOthers().put("travelNextCity3", fieldValue);
            case "5_1b_purpose1" -> commonField.getOthers().put("travelNextPurpose1", fieldValue);
            case "5_1b_purpose2" -> commonField.getOthers().put("travelNextPurpose2", fieldValue);
            case "5_1b_purpose3" -> commonField.getOthers().put("travelNextPurpose3", fieldValue);
            case "5_1b_frequency1" -> commonField.getOthers().put("travelNextFrequency1", fieldValue);
            case "5_1b_frequency2" -> commonField.getOthers().put("travelNextFrequency2", fieldValue);
            case "5_1b_frequency3" -> commonField.getOthers().put("travelNextFrequency3", fieldValue);

            /* Page6 End */
            /* Page7 Start */
            case "ch5_1c_yes" -> commonField.getOthers().put("futureAddressYes", fieldValue);
            case "ch5_1c_no" -> commonField.getOthers().put("futureAddressNo", fieldValue);
            case "5_1c_address_1" -> commonField.getOthers().put("futureAddress", fieldValue);
            //case "5_1c_address_2" -> commonField.getOthers().put("futureAddress2", fieldValue);
            case "5_1c_reason" -> commonField.getOthers().put("futureAddressReason", fieldValue);
            case "5_1c_how_long" -> commonField.getOthers().put("futureAddressHowLong", fieldValue);
            //set it by this if both null futureAddressReason futureAddressHowLong; setValueIfPresent(form, "fill_2_4", commonField.getOthers().get("futureAddressReasonHowLong")); 
            
            //set 5_1c_return if commonField.getOthers().put("futureAddressReturnYes" "futureAddressReturnNo" "futureAddressReturnNa"
            // if commonField.getOthers().put("hazard", "Yes"); then set ch5_2_yes else no
            
            case "ch5_3_yes" -> commonField.setDeclinedYes(fieldValue);
            case "ch5_3_no" -> commonField.setDeclinedNo(fieldValue);
            case "ch5_6_yes" -> commonField.getOthers().put("pendingChargeYes", fieldValue);
            case "ch5_6_no" -> commonField.getOthers().put("pendingChargeNo", fieldValue);


            /* Page7 End */
            /* Page10 Start */

            /*
                * case "fill_1_2" -> {
                commonField.getOthers().put("relateFatherRelation", "Father");
                commonField.getOthers().put("relateFatherName", fieldValue);
            }
            case "fill_2_2" -> commonField.getOthers().put("relateFatherAge", fieldValue);
            case "fill_6_2" -> {
                commonField.getOthers().put("relateMotherRelation", "Mother");
                commonField.getOthers().put("relateMotherName", fieldValue);
            }
            case "fill_7_2" -> commonField.getOthers().put("relateMotherAge", fieldValue);
            case "fill_11_2" -> {
                commonField.getOthers().put("relateSpouseRelation", "Spouse");
                commonField.getOthers().put("relateSpouseName", fieldValue);
            }
            case "fill_12_2" -> commonField.getOthers().put("relateSpouseAge", fieldValue);
            case "fill_16_2" -> {
                commonField.getOthers().put("relateSonRelation", "Son");
                commonField.getOthers().put("relateSonName", fieldValue);
            }
            case "fill_17_2" -> commonField.getOthers().put("relateSonAge", fieldValue);
            case "fill_21_2" -> {
                commonField.getOthers().put("relateSonRelation", "Daughter");
                commonField.getOthers().put("relateSonName", fieldValue);
            }
            case "fill_22_2" -> commonField.getOthers().put("relateSonAge", fieldValue);
            case "fill_26" -> {
                commonField.getOthers().put("relateBotherRelation", "Bother");
                commonField.getOthers().put("relateBotherName", fieldValue);
            }
            case "fill_27" -> commonField.getOthers().put("relateBotherAge", fieldValue);
            case "fill_31" -> {
                commonField.getOthers().put("relateSisterRelation", "Sister");
                commonField.getOthers().put("relateSisterName", fieldValue);
            }
            case "fill_32" -> commonField.getOthers().put("relateSisterAge", fieldValue);
                */

                //setValueIfPresent(form, "fill_1_8", commonField.getOthers().get("companyStartYear"));
            //setValueIfPresent(form, "fill_2_7", commonField.getOthers().get("companyEndYear"));

            //case "toggle_6_4" -> commonField.getOthers().put("businessOwnerYes", fieldValue);
            //case "fill_22_5" -> commonField.getOthers().put("businessOwnerPercent", fieldValue);

            //case "fill_25_3" -> commonField.getOthers().put("businessOwnerNoEmployee", fieldValue);

            
            /* Page10 End */
        }
    }

	private void setValueIfPresent(PdfAcroForm form, String fieldName, String value) {
        PdfFormField field = form.getField(fieldName);
        if (field != null) {
            if (value != null && field.getFormType().equals(PdfName.Tx)) {
                try {
                    field.setValue(value);
                    // logger.info("Set field '{}' to value '{}' (from {})", fieldName, value, valueSource);
                } catch (Exception e) {
                    // logger.error("Error setting value for field '{}' with value '{}' (from {}): {}", fieldName, value, valueSource, e.getMessage());
                }
            } else {
                // logger.warn("Value for field '{}' (from {}) is null. Skipping setting value.", fieldName, valueSource);
            }
        } else {
            // logger.warn("PDF field '{}' not found in the document. Skipping setting value.", fieldName);
        }
    }

    private void setValueIfPresent(PDAcroForm form, String fieldName, String value) {
        PDField field = form.getField(fieldName);
        if (field != null) {
            //only do for check box
            if ("Btn".equals(field.getFieldType()) || "Ch".equals(field.getFieldType())){
                if (value != null) {
                    try {
                        logger.info("writing2 " + fieldName + " " + value);
                        field.setValue(value);
                    } catch (Exception e) {
                        // Handle exception if needed
                    }
                }
            }
            
        }
    }
    
    public static double convertStringToNum(String inputString) {
        if(inputString == null)
            return 0;
            
        inputString = inputString.replaceAll(",", "");

        if (inputString == null || inputString.trim().isEmpty()) {
            return 0.0;
        }

        double sum = 0.0;

        // The regular expression `[0-9]+([,.][0-9]+)?` is used to find numbers.
        // - `[0-9]+`: Matches one or more digits.
        // - `([,.][0-9]+)?`: This is an optional group that matches a comma or
        //   a period followed by one or more digits. This allows for decimal numbers.
        Pattern pattern = Pattern.compile("[0-9]+([,.][0-9]+)?");
        Matcher matcher = pattern.matcher(inputString);

        while (matcher.find()) {
            String numberStr = matcher.group();
            try {
                // Replace commas with periods to handle different decimal separators
                // for consistent parsing.
                numberStr = numberStr.replace(',', '.');
                sum += Double.parseDouble(numberStr);
            } catch (NumberFormatException e) {
                // This block handles potential parsing issues, although the regex
                // should prevent most of them. It simply logs the error and
                // continues to the next match.
                System.err.println("Could not parse number: " + numberStr);
            }
        }
        return sum;
    }

    private static double convertWithSuffix(String s) {
        if (s == null || s.trim().isEmpty()) {
            return 0.0;
        }

        String trimmed = s.trim().toUpperCase();
        double multiplier = 1.0;
        String baseNumber = s;

        // Check for suffixes and set multiplier
        if (trimmed.endsWith("K")) {
            multiplier = 1000.0;
            baseNumber = s.substring(0, s.length() - 1);
        } else if (trimmed.endsWith("M")) {
            multiplier = 1000000.0;
            baseNumber = s.substring(0, s.length() - 1);
        }

        // Use the original convertStringToNum on the base number part
        double value = convertStringToNum(baseNumber); 
        
        return value * multiplier;
    }

    public static String addNums(String... strings) {
        double totalSum = 0.0;
        boolean withSymbol = false;
        
        for (String s : strings) {
            if(s != null && (s.toUpperCase().contains("M") || s.toUpperCase().contains("K"))){
                withSymbol = true;
            }
            totalSum += convertWithSuffix(s);
        }
        
        return formatScaledNumber(withSymbol, totalSum);
    }
    
    public static String substractNums(String a, String b) {
        double aValue = convertWithSuffix(a);
        double bValue = convertWithSuffix(b);
        boolean withSymbol = false;

        if(a != null && (a.toUpperCase().contains("M") || a.toUpperCase().contains("K"))){
            withSymbol = true;
        }

        if (aValue >= bValue) {
            double difference = aValue - bValue;
            return formatScaledNumber(withSymbol, difference);
        } else {
            return "";
        }
    }

    private static String formatNum(String value){
        return formatScaledNumber(false, convertStringToNum(value));
    }
    
    private static String formatScaledNumber(boolean withSymbol, double value) {
        if (value == 0.0) {
            return "0";
        }
        
        String suffix = "";
        double scaledValue = value;

        // Determine the most appropriate scaling factor and suffix
        if (Math.abs(value) >= 1000000) {
            suffix = "M";
            scaledValue = value / 1000000.0;
        } else if (Math.abs(value) >= 1000) {
            suffix = "K";
            scaledValue = value / 1000.0;
        }
        
        if (withSymbol) {
             // For K/M output, use precision (up to two decimals, dropping trailing zeros)
             DecimalFormat formatter = new DecimalFormat("#,##0"); 
             return formatter.format(scaledValue) + suffix;
        } else {
             // For numbers < 1000, return the number with standard separator and mandatory two decimals
             NumberFormat numberFormatter = NumberFormat.getNumberInstance(Locale.US);
             DecimalFormat decimalFormatter = (DecimalFormat) numberFormatter;
             decimalFormatter.applyPattern("#,##0");
             
             return decimalFormatter.format(value);
        }
    }

    public static Map<String, String> getCountryAndPhoneNo(String contactNo){
        String countryCode = "";
        String phoneNo = "";
        if(StringUtils.trimToNull(contactNo) != null){
            if(contactNo.replaceAll(" ", "").length() > 8){
                //it may contain conttry code
                if(contactNo.contains("+852")){       
                    countryCode = "+852";
                    phoneNo = contactNo.replace("+852", "");            
                }else if(contactNo.contains("+853")){            
                    countryCode = "+853";
                    phoneNo = contactNo.replace("+853", "");
                }else if(contactNo.contains("+86")){    
                    countryCode = "+86";
                    phoneNo = contactNo.replace("+86", "");        
                    
                }else if(contactNo.contains("+1")){       
                    countryCode = "+1";
                    phoneNo = contactNo.replace("+1", "");      
                    
                }else if(contactNo.contains("+81")){            
                    countryCode = "+81";
                    phoneNo = contactNo.replace("+81", "");  
                }else if(contactNo.contains("+82")){            
                    countryCode = "+82";
                    phoneNo = contactNo.replace("+82", ""); 
                }
            }else{
                phoneNo = contactNo;
            }     
        }

        Map<String, String> d = new HashMap<>();
        d.put("contactNo", contactNo);
        d.put("countryCode", countryCode);
        d.put("phoneNo", phoneNo);

        return d;
    }

    public Map<String, Object> getFilledFormPdf(Long id) {
		StringBuilder sql = new StringBuilder("SELECT"
			+ " ff.fileId, "
            + " f.skey as fileSkey, "

            + " (select f.id from file_ref fr left join file f on fr.fileId = f.id where fr.refType = 'upload1' and fr.refId = ff.id order by fr.id desc limit 1) as upload1FileId, "
            + " (select f.id from file_ref fr left join file f on fr.fileId = f.id where fr.refType = 'upload2' and fr.refId = ff.id order by fr.id desc limit 1) as upload2FileId, "
            
            + " ff.id, "
			+ " ff.remarks, "
			+ " f.filename, "
            + " c.clientCode, "
            + " c.lastname, "
            + " c.firstname, "
            + " t.name as templateName, "
            + " t.remarks AS formCode, "
			+ " fb.bytes AS blobValue "
			+ " FROM filled_form ff "
			+ " LEFT JOIN file f ON f.id = ff.fileId "            
			+ " LEFT JOIN file_blob fb ON f.id = fb.fileId "
            + " LEFT JOIN template t ON t.id = ff.templateId "
            + " LEFT JOIN client c ON ff.clientId = c.id "
			+ " WHERE ff.deleted = FALSE "
			+ " AND ff.id = :id "
        );
        return jdbcDao.queryForMap(sql.toString(), Map.of("id", id)).orElse(null);
    }

    public String getCrAddress1(Client client){
        String value = "";
        if(!"".equals(StringUtils.trimToEmpty(client.getCrAddressRoom()))){
            value += StringUtils.trimToEmpty(client.getCrAddressRoom()) + " ";
        }
        if(!"".equals(StringUtils.trimToEmpty(client.getCrAddressFloor()))){
            value += StringUtils.trimToEmpty(client.getCrAddressFloor()) + " ";
        }
        if(!"".equals(StringUtils.trimToEmpty(client.getCrAddressBlock()))){
            value += StringUtils.trimToEmpty(client.getCrAddressBlock()) + " ";
        }
        if(!"".equals(StringUtils.trimToEmpty(client.getCrAddressBuilding()))){
            value += StringUtils.trimToEmpty(client.getCrAddressBuilding()) + " ";
        }
        if(!"".equals(StringUtils.trimToEmpty(client.getCrAddressStreet()))){
            value += StringUtils.trimToEmpty(client.getCrAddressStreet()) + " ";
        }
        return StringUtils.trimToEmpty(value);
    }

    public String getCrAddress2(Client client){
        String value = "";
        if(!"".equals(StringUtils.trimToEmpty(client.getCrAddressArea()))){
            value += StringUtils.trimToEmpty(client.getCrAddressArea()) + " ";
        }
        if(!"".equals(StringUtils.trimToEmpty(client.getCrAddressCity()))){
            value += StringUtils.trimToEmpty(client.getCrAddressCity()) + " ";
        }
        if(!"".equals(StringUtils.trimToEmpty(client.getCrAddressPostalCode()))){
            value += StringUtils.trimToEmpty(client.getCrAddressPostalCode()) + " ";
        }
        if(!"".equals(StringUtils.trimToEmpty(client.getCrAddressCountry()))){
            value += StringUtils.trimToEmpty(client.getCrAddressCountry()) + " ";
        }
        return StringUtils.trimToEmpty(value);
    }

    public String getCorAddress1(Client client){
        String value = "";
        if(!"".equals(StringUtils.trimToEmpty(client.getCorAddressRoom()))){
            value += StringUtils.trimToEmpty(client.getCorAddressRoom()) + " ";
        }
        if(!"".equals(StringUtils.trimToEmpty(client.getCorAddressFloor()))){
            value += StringUtils.trimToEmpty(client.getCorAddressFloor()) + " ";
        }
        if(!"".equals(StringUtils.trimToEmpty(client.getCorAddressBlock()))){
            value += StringUtils.trimToEmpty(client.getCorAddressBlock()) + " ";
        }
        if(!"".equals(StringUtils.trimToEmpty(client.getCorAddressBuilding()))){
            value += StringUtils.trimToEmpty(client.getCorAddressBuilding()) + " ";
        }
        if(!"".equals(StringUtils.trimToEmpty(client.getCorAddressStreet()))){
            value += StringUtils.trimToEmpty(client.getCorAddressStreet()) + " ";
        }
        return StringUtils.trimToEmpty(value);
    }

    public String getCorAddress2(Client client){
        String value = "";
        if(!"".equals(StringUtils.trimToEmpty(client.getCorAddressArea()))){
            value += StringUtils.trimToEmpty(client.getCorAddressArea()) + " ";
        }
        if(!"".equals(StringUtils.trimToEmpty(client.getCorAddressCity()))){
            value += StringUtils.trimToEmpty(client.getCorAddressCity()) + " ";
        }
        if(!"".equals(StringUtils.trimToEmpty(client.getCorAddressPostalCode()))){
            value += StringUtils.trimToEmpty(client.getCorAddressPostalCode()) + " ";
        }
        if(!"".equals(StringUtils.trimToEmpty(client.getCorAddressCountry()))){
            value += StringUtils.trimToEmpty(client.getCorAddressCountry()) + " ";
        }
        return StringUtils.trimToEmpty(value);
    }

}