package com.brilliance.isc.swift.fremsg.document;

import com.brilliance.mda.runtime.mda.util.Formats;
import com.brilliance.mda.runtime.mda.util.MdaUtils;
import com.brilliance.mda.runtime.mda.util.Strings;
import com.brilliance.isc.bo.Usr;
import com.brilliance.isc.bo.model.*;
import com.brilliance.isc.common.codetable.service.CodetableService;
import com.brilliance.isc.common.context.SettleContext;
import com.brilliance.isc.common.transaction.vo.BaseTransactionVo;
import com.brilliance.isc.common.trndoc.service.DoceotService;
import com.brilliance.isc.common.trndoc.service.TrndocService;
import com.brilliance.isc.common.trndoc.vo.DoceotVo;
import com.brilliance.isc.common.util.DocUtils;
import com.brilliance.isc.common.util.TemplateUtils;
import com.brilliance.isc.common.util.Utils;
import com.brilliance.isc.common.vo.FremsgVo;
import com.brilliance.isc.utils.DateUtils;
import org.springframework.stereotype.Component;
import javax.annotation.Resource;
import java.math.BigDecimal;
import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.Objects;

@Component
public class Xxtdoc {
    @Resource
    private TrndocService trndocService;
    @Resource
    private CodetableService codetableService;
    @Resource
    private DoceotService doceotService;
    @Resource
    private TemplateUtils templateUtils;
    public <T extends BaseTransactionVo> void xmlDocStartLI(Map<String, List<String[]>> dataMap, T transactionVo, DoceotVo doceotVo, String argTitle) {
        //! is used at all letters of Guarantee
        // receiver address
        doceotService.xmlPrintClass_TRX(dataMap, doceotVo);
        doceotService.printAddress(dataMap, doceotVo);
        // document title
        trndocService.xmlPrintTitleBold(dataMap, doceotVo, argTitle);
        // reference block
        xmlPrtRefBlkLI(dataMap, transactionVo, doceotVo);
        // salutation
        trndocService.xmlPrtSalutation(dataMap, doceotVo);

    }
    public <T extends BaseTransactionVo> void xmlDocStartBR(Map<String, List<String[]>> dataMap, T transactionVo, DoceotVo doceotVo, String argTitle) {
        //! is used at all letters of Guarantee
        // receiver address
        doceotService.xmlPrintClass_TRX(dataMap, doceotVo);
        doceotService.printAddress(dataMap, doceotVo);
        // document title
        trndocService.xmlPrintTitleBold(dataMap, doceotVo, argTitle);
        // reference block
        xmlPrtRefBlkBR(dataMap, transactionVo, doceotVo);
        trndocService.xmlPrtEmptyLine(dataMap, 4);
        // salutation
        trndocService.xmlPrtSalutation(dataMap, doceotVo);

    }

    public <T extends BaseTransactionVo> void xmlDocStartBD(Map<String, List<String[]>> dataMap, T transactionVo, DoceotVo doceotVo, String argTitle) {
        //! is used at all letters of Guarantee
        // receiver address
        doceotService.xmlPrintClass_TRX(dataMap, doceotVo);
        doceotService.printAddress(dataMap, doceotVo);
        // document title
        trndocService.xmlPrintTitleBold(dataMap, doceotVo, argTitle);
        // reference block
        xmlPrtRefBlkBD(dataMap, transactionVo, doceotVo);
        trndocService.xmlPrtEmptyLine(dataMap, 4);
        // salutation
        trndocService.xmlPrtSalutation(dataMap, doceotVo);

    }
    public <T extends BaseTransactionVo> void xmlDocStartLE(Map<String, List<String[]>> dataMap, T transactionVo, DoceotVo doceotVo, String argTitle) {
        //! is used at all letters of Guarantee
        // receiver address
        doceotService.xmlPrintClass_TRX(dataMap, doceotVo);
        doceotService.printAddress(dataMap, doceotVo);
        // document title
        trndocService.xmlPrintTitleBold(dataMap, doceotVo, argTitle);
        // reference block
        xmlPrtRefBlkLE(dataMap, transactionVo, doceotVo);
        // salutation
        trndocService.xmlPrtSalutation(dataMap, doceotVo);

    }

    public <T extends BaseTransactionVo> void xmlDocStartDI(Map<String, List<String[]>> dataMap, T transactionVo, DoceotVo doceotVo, String argTitle) {
        //! is used at all letters of Guarantee
        // receiver address
        doceotService.xmlPrintClass_TRX(dataMap, doceotVo);
        doceotService.printAddress(dataMap, doceotVo);
        // document title
        trndocService.xmlPrintTitleBold(dataMap, doceotVo, argTitle);
        // reference block
        xmlPrtRefBlkDI(dataMap, transactionVo, doceotVo);
        // salutation
        trndocService.xmlPrtSalutation(dataMap, doceotVo);

    }
    public <T extends BaseTransactionVo> void xmlDocStartDE(Map<String, List<String[]>> dataMap, T transactionVo, DoceotVo doceotVo, String argTitle) {
        //! is used at all letters of Guarantee
        // receiver address
        doceotService.xmlPrintClass_TRX(dataMap, doceotVo);
        doceotService.printAddress(dataMap, doceotVo);
        // document title
        trndocService.xmlPrintTitleBold(dataMap, doceotVo, argTitle);
        // reference block
        xmlPrtRefBlkDE(dataMap, transactionVo, doceotVo);
        // salutation
        trndocService.xmlPrtSalutation(dataMap, doceotVo);

    }
    public <T extends BaseTransactionVo> void xmlDocStartBC(Map<String, List<String[]>> dataMap, T transactionVo, DoceotVo doceotVo, String argTitle) {
        //! is used at all letters of Guarantee
        // receiver address
        doceotService.xmlPrintClass_TRX(dataMap, doceotVo);
        doceotService.printAddress(dataMap, doceotVo);
        // document title
        trndocService.xmlPrintTitleBold(dataMap, doceotVo, argTitle);
        // reference block
        xmlPrtRefBlkBC(dataMap, transactionVo, doceotVo);
        trndocService.xmlPrtEmptyLine(dataMap, 4);
        // salutation
        trndocService.xmlPrtSalutation(dataMap, doceotVo);

    }
    public <T extends BaseTransactionVo> void xmlDocStartBO(Map<String, List<String[]>> dataMap, T transactionVo, DoceotVo doceotVo, String argTitle) {
        //! is used at all letters of Guarantee
        // receiver address
        doceotService.xmlPrintClass_TRX(dataMap, doceotVo);
        doceotService.printAddress(dataMap, doceotVo);
        // document title
        trndocService.xmlPrintTitleBold(dataMap, doceotVo, argTitle);
        // reference block
        xmlPrtRefBlkBO(dataMap, transactionVo, doceotVo);
        // salutation
        trndocService.xmlPrtSalutation(dataMap, doceotVo);

    }
    public <T extends BaseTransactionVo> void xmlDocStartBP(Map<String, List<String[]>> dataMap, T transactionVo, DoceotVo doceotVo, String argTitle) {
        //! is used at all letters of Guarantee
        // receiver address
        doceotService.xmlPrintClass_TRX(dataMap, doceotVo);
        doceotService.printAddress(dataMap, doceotVo);
        // document title
        trndocService.xmlPrintTitleBold(dataMap, doceotVo, argTitle);
        // reference block
        xmlPrtRefBlkBP(dataMap, transactionVo, doceotVo);
        // salutation
        trndocService.xmlPrtSalutation(dataMap, doceotVo);

    }
    public <T extends BaseTransactionVo> void xmlDocStartTR(Map<String, List<String[]>> dataMap, T transactionVo, DoceotVo doceotVo, String argTitle) {
        //! is used at all letters of Guarantee
        // receiver address
        doceotService.xmlPrintClass_TRX(dataMap, doceotVo);
        doceotService.printAddress(dataMap, doceotVo);
        // document title
        trndocService.xmlPrintTitleBold(dataMap, doceotVo, argTitle);
        // reference block
        xmlPrtRefBlkTR(dataMap, transactionVo, doceotVo);
        // salutation
        trndocService.xmlPrtSalutation(dataMap, doceotVo);

    }
    public <T extends BaseTransactionVo> void xmlDocStartCP(Map<String, List<String[]>> dataMap, T transactionVo, DoceotVo doceotVo, String argTitle) {
        //! is used at all letters of Guarantee
        // receiver address
        doceotService.xmlPrintClass_TRX(dataMap, doceotVo);
        doceotService.printAddress(dataMap, doceotVo);
        // document title
        trndocService.xmlPrintTitleBold(dataMap, doceotVo, argTitle);
        // reference block
        xmlPrtRefBlkCP(dataMap, transactionVo, doceotVo);
        // salutation
        trndocService.xmlPrtSalutation(dataMap, doceotVo);

    }
    public <T extends BaseTransactionVo> void xmlDocStartMC(Map<String, List<String[]>> dataMap, T transactionVo, DoceotVo doceotVo, String argTitle) {
        //! is used at all letters of Guarantee
        // receiver address
        doceotService.xmlPrintClass_TRX(dataMap, doceotVo);
        doceotService.printAddress(dataMap, doceotVo);
        // document title
        trndocService.xmlPrintTitleBold(dataMap, doceotVo, argTitle);
        // reference block
        xmlPrtRefBlkMC(dataMap, transactionVo, doceotVo);
        // salutation
        trndocService.xmlPrtSalutation(dataMap, doceotVo);

    }
    public <T extends BaseTransactionVo> void xmlDocStartMR(Map<String, List<String[]>> dataMap, T transactionVo, DoceotVo doceotVo, String argTitle) {
        //! is used at all letters of Guarantee
        // receiver address
        doceotService.xmlPrintClass_TRX(dataMap, doceotVo);
        doceotService.printAddress(dataMap, doceotVo);
        // document title
        trndocService.xmlPrintTitleBold(dataMap, doceotVo, argTitle);
        // reference block
        xmlPrtRefBlkMR(dataMap, transactionVo, doceotVo);
        // salutation
        trndocService.xmlPrtSalutation(dataMap, doceotVo);

    }
    public <T extends BaseTransactionVo> void xmlDocStartLT(Map<String, List<String[]>> dataMap, T transactionVo, DoceotVo doceotVo, String argTitle) {
        //! is used at all letters of Guarantee
        // receiver address
        doceotService.xmlPrintClass_TRX(dataMap, doceotVo);
        doceotService.printAddress(dataMap, doceotVo);
        // document title
        trndocService.xmlPrintTitleBold(dataMap, doceotVo, argTitle);
        // reference block
        xmlPrtRefBlkLT(dataMap, transactionVo, doceotVo);
        // salutation
        trndocService.xmlPrtSalutation(dataMap, doceotVo);

    }
    public <T extends BaseTransactionVo> void xmlDocStartBT(Map<String, List<String[]>> dataMap, T transactionVo, DoceotVo doceotVo, String argTitle) {
        //! is used at all letters of Guarantee
        // receiver address
        doceotService.xmlPrintClass_TRX(dataMap, doceotVo);
        doceotService.printAddress(dataMap, doceotVo);
        // document title
        trndocService.xmlPrintTitleBold(dataMap, doceotVo, argTitle);
        // reference block
        xmlPrtRefBlkBT(dataMap, transactionVo, doceotVo);
        // salutation
        trndocService.xmlPrtSalutation(dataMap, doceotVo);

    }
    private <T extends BaseTransactionVo> void xmlPrtRefBlkLI(Map<String, List<String[]>> dataMap, T transactionVo, DoceotVo doceotVo) {
        Lidgrp lidgrp = Utils.getFieldValue(transactionVo, "lidgrp");
        xmlPrtRefLineLcNo(dataMap, lidgrp.getRec().getLcrtyp(),lidgrp.getRec().getOwnref(), doceotVo);
        trndocService.xmlPrtRefLineYourRef(dataMap, transactionVo, doceotVo);
        XMLPrtRefLineExpiry(dataMap, lidgrp, doceotVo);
        xmlPrtRefLineLCAmt(dataMap, lidgrp, doceotVo);
        xmlPrtRefLineAddAmt(dataMap, lidgrp, doceotVo);
        XMLPrtRefLineNomSpc(dataMap, lidgrp.getRec().getNomspc(),lidgrp.getRec().getNomtop(),lidgrp.getRec().getNomton(), doceotVo);
        if(!MdaUtils.equals(doceotVo.getRole(),"ADV")){
            trndocService.xmlPrtRefLinePty(dataMap, doceotVo, lidgrp.getAdv());
        }
        if(!MdaUtils.equals(doceotVo.getRole(),"APL")){
            trndocService.xmlPrtRefLinePty(dataMap, doceotVo, lidgrp.getApl());
        }
        if(!MdaUtils.equals(doceotVo.getRole(),"BEN")){
            trndocService.xmlPrtRefLinePty(dataMap, doceotVo, lidgrp.getBen());
        }

    }

    private <T extends BaseTransactionVo> void xmlPrtRefBlkBR(Map<String, List<String[]>> dataMap, T transactionVo, DoceotVo doceotVo) {
        String role = doceotVo.getRole();
        Brdgrp brdgrp = Utils.getFieldValue(transactionVo, "brdgrp");
        trndocService.xmlPrtRefLine(dataMap,doceotVo,"Document set no",brdgrp.getRec().getOwnref());
        trndocService.xmlPrtRefLineYourRef(dataMap, transactionVo, doceotVo);
        if(!MdaUtils.equals(role,"ROG")){
            String cur = brdgrp.getCbs().getMax().getCur();
            BigDecimal amt = brdgrp.getCbs().getMax().getAmt();
            if (!MdaUtils.isEmpty(amt)) {
                trndocService.xmlPrtRefLine(dataMap, doceotVo, "Documents Amount", trndocService.xmlFmtCurAmt(doceotVo, cur, amt));
            }
            if (!MdaUtils.isEmpty(brdgrp.getCbs().getMax2().getAmt())) {
                trndocService.xmlPrtRefLine(dataMap, doceotVo, "Additional Amount", trndocService.xmlFmtCurAmt(doceotVo, brdgrp.getCbs().getMax2().getCur(), brdgrp.getCbs().getMax2().getAmt()));
            }
            if(!MdaUtils.isEmpty(brdgrp.getRec().getMatdat())){
                trndocService.xmlPrtRefLine(dataMap,doceotVo,"Maturity",xmlFmtDate("L",brdgrp.getRec().getMatdat(),doceotVo));
            }
        }
        trndocService.xmlPrtRefLine(dataMap,doceotVo,"Transport Document No.",brdgrp.getRec().getTrpdocnum());
        trndocService.xmlPrtRefLine(dataMap,doceotVo,"Transport Document dated",xmlFmtDate("L",brdgrp.getRec().getTradat(),doceotVo));
        trndocService.xmlPrtRefLine(dataMap,doceotVo,"Transport Document Type",codetableService.getTblLabel(brdgrp.getRec().getTrpdoctyp(),"trptyp"));
        trndocService.xmlPrtRefLine(dataMap,doceotVo,"Mode of Transport",brdgrp.getRec().getTramod());
        trndocService.xmlPrtRefLine(dataMap,doceotVo,"Vessel Name",brdgrp.getBlk().getVesnam());
        trndocService.xmlPrtRefLine(dataMap,doceotVo,"Port of Dischargee",brdgrp.getBlk().getPordis());
        trndocService.xmlPrtRefLine(dataMap,doceotVo,"Place of Delivery",brdgrp.getBlk().getDelplc());
        trndocService.xmlPrtRefLine(dataMap,doceotVo,"Description of Goods",brdgrp.getBlk().getRoggod());
        if(!MdaUtils.equals(role,"ROG")){
            if(!MdaUtils.equals(role,"APL")){
                trndocService.xmlPrtRefLinePty(dataMap, doceotVo, brdgrp.getApl());
            }
            if(!MdaUtils.equals(role,"BEN")){
                trndocService.xmlPrtRefLinePty(dataMap, doceotVo, brdgrp.getBen());
            }
            if(!MdaUtils.equals(role,"PRB")){
                if(MdaUtils.equals(brdgrp.getRec().getDocprbrol(),"PRB")){
                    trndocService.xmlPrtRefLinePty(dataMap, doceotVo, brdgrp.getPrb());
                }
            }
        }
    }

    private <T extends BaseTransactionVo> void xmlPrtRefBlkBD(Map<String, List<String[]>> dataMap, T transactionVo, DoceotVo doceotVo) {
        String role = doceotVo.getRole();
        Bddgrp bddgrp = Utils.getFieldValue(transactionVo, "bddgrp");
        trndocService.xmlPrtRefLine(dataMap,doceotVo,"Document set no",bddgrp.getRec().getOwnref());
        trndocService.xmlPrtRefLineYourRef(dataMap, transactionVo, doceotVo);
        if(!MdaUtils.equals(role,"ROG")){
            String cur = bddgrp.getCbs().getMax().getCur();
            BigDecimal amt = bddgrp.getCbs().getMax().getAmt();
            if (!MdaUtils.isEmpty(amt)) {
                trndocService.xmlPrtRefLine(dataMap, doceotVo, "Documents Amount", trndocService.xmlFmtCurAmt(doceotVo, cur, amt));
            }
            if (!MdaUtils.isEmpty(bddgrp.getCbs().getMax2().getAmt())) {
                trndocService.xmlPrtRefLine(dataMap, doceotVo, "Additional Amount", trndocService.xmlFmtCurAmt(doceotVo, bddgrp.getCbs().getMax2().getCur(), bddgrp.getCbs().getMax2().getAmt()));
            }
            if(!MdaUtils.isEmpty(bddgrp.getRec().getMatdat())){
                trndocService.xmlPrtRefLine(dataMap,doceotVo,"Maturity",xmlFmtDate("L",bddgrp.getRec().getMatdat(),doceotVo));
            }
        }
        trndocService.xmlPrtRefLine(dataMap,doceotVo,"Transport Document No.",bddgrp.getRec().getTrpdocnum());
        trndocService.xmlPrtRefLine(dataMap,doceotVo,"Transport Document dated",xmlFmtDate("L",bddgrp.getRec().getTradat(),doceotVo));
        trndocService.xmlPrtRefLine(dataMap,doceotVo,"Transport Document Type",codetableService.getTblLabel(bddgrp.getRec().getTrpdoctyp(),"trptyp"));
        trndocService.xmlPrtRefLine(dataMap,doceotVo,"Mode of Transport",bddgrp.getRec().getTramod());
        trndocService.xmlPrtRefLine(dataMap,doceotVo,"Vessel Name",bddgrp.getBlk().getVesnam());
        trndocService.xmlPrtRefLine(dataMap,doceotVo,"Port of Dischargee",bddgrp.getBlk().getPordis());
        trndocService.xmlPrtRefLine(dataMap,doceotVo,"Place of Delivery",bddgrp.getBlk().getDelplc());
        trndocService.xmlPrtRefLine(dataMap,doceotVo,"Description of Goods",bddgrp.getBlk().getRoggod());
        if(!MdaUtils.equals(role,"ROG")){
            if(!MdaUtils.equals(role,"APL")){
                trndocService.xmlPrtRefLinePty(dataMap, doceotVo, bddgrp.getApl());
            }
            if(!MdaUtils.equals(role,"BEN")){
                trndocService.xmlPrtRefLinePty(dataMap, doceotVo, bddgrp.getBen());
            }
            if(!MdaUtils.equals(role,"PRB")){
                if(MdaUtils.equals(bddgrp.getRec().getDocprbrol(),"PRB")){
                    trndocService.xmlPrtRefLinePty(dataMap, doceotVo, bddgrp.getPrb());
                }
            }
        }
    }

    private <T extends BaseTransactionVo> void xmlPrtRefBlkLE(Map<String, List<String[]>> dataMap, T transactionVo, DoceotVo doceotVo) {
        Ledgrp ledgrp = Utils.getFieldValue(transactionVo, "ledgrp");
        if(!MdaUtils.equals(doceotVo.getRole(),"ISS")){
            xmlPrtRefLineLcNo(dataMap, ledgrp.getRec().getLcrtyp(),ledgrp.getRec().getOwnref(), doceotVo);
        }
        trndocService.xmlPrtRefLineYourRef(dataMap, transactionVo, doceotVo);
        xmlPrtRefLineOwnRef(dataMap, ledgrp, doceotVo);
        XMLPrtRefLineIssDate(dataMap, ledgrp, doceotVo);
        xmlPrtRefLineLCAmt(dataMap, ledgrp, doceotVo);
        xmlPrtRefLineAddAmt(dataMap, ledgrp, doceotVo);
        XMLPrtRefLineNomSpc(dataMap, ledgrp.getRec().getNomspc(),ledgrp.getRec().getNomtop(),ledgrp.getRec().getNomton(), doceotVo);
        if(!MdaUtils.equals(doceotVo.getRole(),"ADV")){
            trndocService.xmlPrtRefLinePty(dataMap, doceotVo, ledgrp.getAdv());
        }
        if(!MdaUtils.equals(doceotVo.getRole(),"APL")){
            trndocService.xmlPrtRefLinePty(dataMap, doceotVo, ledgrp.getApl());
        }
        if(!MdaUtils.equals(doceotVo.getRole(),"BEN")){
            trndocService.xmlPrtRefLinePty(dataMap, doceotVo, ledgrp.getBen());
        }
        if(!MdaUtils.equals(doceotVo.getRole(),"ISS")){
            trndocService.xmlPrtRefLinePty(dataMap, doceotVo, ledgrp.getIss());
        }
        if(!MdaUtils.equals(doceotVo.getRole(),"APB")){
            trndocService.xmlPrtRefLinePty(dataMap, doceotVo, ledgrp.getApb());
        }
        if(!MdaUtils.equals(doceotVo.getRole(),"CON")){
            trndocService.xmlPrtRefLinePty(dataMap, doceotVo, ledgrp.getCon());
        }

    }

    private <T extends BaseTransactionVo> void xmlPrtRefBlkDE(Map<String, List<String[]>> dataMap, T transactionVo, DoceotVo doceotVo) {
        Dedgrp dedgrp = Utils.getFieldValue(transactionVo, "dedgrp");
        if(!MdaUtils.equals(doceotVo.getRole(),"ISS")){
            xmlPrtRefLineLcNo(dataMap, dedgrp.getRec().getLcrtyp(),dedgrp.getRec().getOwnref(), doceotVo);
        }
        trndocService.xmlPrtRefLineYourRef(dataMap, transactionVo, doceotVo);
        xmlPrtRefLineOwnRef(dataMap, dedgrp, doceotVo);
        XMLPrtRefLineIssDate(dataMap, dedgrp, doceotVo);
        xmlPrtRefLineLCAmt(dataMap, dedgrp, doceotVo);
        xmlPrtRefLineAddAmt(dataMap, dedgrp, doceotVo);
        XMLPrtRefLineNomSpc(dataMap, dedgrp.getRec().getNomspc(),dedgrp.getRec().getNomtop(),dedgrp.getRec().getNomton(), doceotVo);
        if(!MdaUtils.equals(doceotVo.getRole(),"ADV")){
            trndocService.xmlPrtRefLinePty(dataMap, doceotVo, dedgrp.getAdv());
        }
        if(!MdaUtils.equals(doceotVo.getRole(),"APL")){
            trndocService.xmlPrtRefLinePty(dataMap, doceotVo, dedgrp.getApl());
        }
        if(!MdaUtils.equals(doceotVo.getRole(),"BEN")){
            trndocService.xmlPrtRefLinePty(dataMap, doceotVo, dedgrp.getBen());
        }
        if(!MdaUtils.equals(doceotVo.getRole(),"ISS")){
            trndocService.xmlPrtRefLinePty(dataMap, doceotVo, dedgrp.getIss());
        }
        if(!MdaUtils.equals(doceotVo.getRole(),"APB")){
            trndocService.xmlPrtRefLinePty(dataMap, doceotVo, dedgrp.getApb());
        }
        if(!MdaUtils.equals(doceotVo.getRole(),"CON")){
            trndocService.xmlPrtRefLinePty(dataMap, doceotVo, dedgrp.getCon());
        }

    }
    private <T extends BaseTransactionVo> void xmlPrtRefBlkDI(Map<String, List<String[]>> dataMap, T transactionVo, DoceotVo doceotVo) {
        Didgrp didgrp = Utils.getFieldValue(transactionVo, "didgrp");
        xmlPrtRefLineLcNo(dataMap, didgrp.getRec().getLcrtyp(),didgrp.getRec().getOwnref(), doceotVo);
        trndocService.xmlPrtRefLineYourRef(dataMap, transactionVo, doceotVo);
        XMLPrtRefLineExpiry(dataMap, didgrp, doceotVo);
        xmlPrtRefLineLCAmt(dataMap, didgrp, doceotVo);
        xmlPrtRefLineAddAmt(dataMap, didgrp, doceotVo);
        XMLPrtRefLineNomSpc(dataMap, didgrp.getRec().getNomspc(),didgrp.getRec().getNomtop(),didgrp.getRec().getNomton(), doceotVo);
        if(!MdaUtils.equals(doceotVo.getRole(),"ADV")){
            trndocService.xmlPrtRefLinePty(dataMap, doceotVo, didgrp.getAdv());
        }
        if(!MdaUtils.equals(doceotVo.getRole(),"APL")){
            trndocService.xmlPrtRefLinePty(dataMap, doceotVo, didgrp.getApl());
        }
        if(!MdaUtils.equals(doceotVo.getRole(),"BEN")){
            trndocService.xmlPrtRefLinePty(dataMap, doceotVo, didgrp.getBen());
        }

    }
    private <T extends BaseTransactionVo> void xmlPrtRefBlkBC(Map<String, List<String[]>> dataMap, T transactionVo, DoceotVo doceotVo) {
        String role = doceotVo.getRole();
        Bcdgrp bcdgrp = Utils.getFieldValue(transactionVo, "bcdgrp");
        xmlPrtRefLineOwnRef(dataMap,bcdgrp,doceotVo);
        trndocService.xmlPrtRefLineYourRef(dataMap, transactionVo, doceotVo);
        if(!MdaUtils.equals(role,"ROG")){
            trndocService.xmlPrtRefLine(dataMap, doceotVo, "Collection Condition",xmlGetDoctypcod(bcdgrp.getRec().getDoctypcod()));
            String cur = bcdgrp.getCbs().getMax().getCur();
            BigDecimal amt = bcdgrp.getCbs().getMax().getAmt();
            if (!MdaUtils.isEmpty(amt)) {
                trndocService.xmlPrtRefLine(dataMap, doceotVo, "Collection Amount", trndocService.xmlFmtCurAmt(doceotVo, cur, amt));
            }
            xmlPrtRefLineMaturity(dataMap,doceotVo,bcdgrp);
        }

        if(!MdaUtils.equals(role,"DRE")){
            trndocService.xmlPrtRefLinePty(dataMap, doceotVo, bcdgrp.getDre());
        }
        if(!MdaUtils.equals(role,"DRR")){
            trndocService.xmlPrtRefLinePty(dataMap, doceotVo, bcdgrp.getDrr());
        }
        if(!MdaUtils.equals(role,"RMI")){
            trndocService.xmlPrtRefLinePty(dataMap, doceotVo, bcdgrp.getRmi());
        }
        if(!MdaUtils.equals(role,"CO2")){
            trndocService.xmlPrtRefLinePty(dataMap, doceotVo, bcdgrp.getCo2());
        }

    }

    private <T extends BaseTransactionVo> void xmlPrtRefBlkBO(Map<String, List<String[]>> dataMap, T transactionVo, DoceotVo doceotVo) {
        String role = doceotVo.getRole();
        Bodgrp bodgrp = Utils.getFieldValue(transactionVo, "bodgrp");
        xmlPrtRefLineOwnRef(dataMap,bodgrp,doceotVo);
        trndocService.xmlPrtRefLineYourRef(dataMap, transactionVo, doceotVo);
        trndocService.xmlPrtRefLine(dataMap, doceotVo, "Collection Condition",xmlGetDoctypcod(bodgrp.getRec().getDoctypcod()));
        String cur = bodgrp.getCbs().getMax().getCur();
        BigDecimal amt = bodgrp.getCbs().getMax().getAmt();
        if (!MdaUtils.isEmpty(amt)) {
            trndocService.xmlPrtRefLine(dataMap, doceotVo, "Collection Amount", trndocService.xmlFmtCurAmt(doceotVo, cur, amt));
        }
        xmlPrtRefLineMaturity(dataMap,doceotVo,bodgrp);


        if(!MdaUtils.equals(role,"DRE")){
            trndocService.xmlPrtRefLinePty(dataMap, doceotVo, bodgrp.getDre());
        }
        if(!MdaUtils.equals(role,"DRR")){
            trndocService.xmlPrtRefLinePty(dataMap, doceotVo, bodgrp.getDrr());
        }
        if(!MdaUtils.equals(role,"RMI")){
            trndocService.xmlPrtRefLinePty(dataMap, doceotVo, bodgrp.getRmi());
        }
        if(!MdaUtils.equals(role,"COL")){
            trndocService.xmlPrtRefLinePty(dataMap, doceotVo, bodgrp.getCo2());
        }

    }
    private <T extends BaseTransactionVo> void xmlPrtRefBlkBP(Map<String, List<String[]>> dataMap, T transactionVo, DoceotVo doceotVo) {
        String role = doceotVo.getRole();
        Bpdgrp bpdgrp = Utils.getFieldValue(transactionVo, "bpdgrp");
        trndocService.xmlPrtRefLine(dataMap, doceotVo,"Parent Contract",bpdgrp.getRec().getPntref());
        trndocService.xmlPrtRefLine(dataMap, doceotVo,"Advance Reference",bpdgrp.getRec().getOwnref());
        trndocService.xmlPrtRefLine(dataMap, doceotVo,"Advanced Customer",templateUtils.xmlGetPtyNam(bpdgrp.getFia()));
        trndocService.xmlPrtRefLine(dataMap, doceotVo,"Customer Reference",bpdgrp.getFia().getPts().getRef());
        String argTxt = "";
        if(MdaUtils.equals(bpdgrp.getRec().getFintyp(),"D")){
            argTxt = "Amount Discounted";
        }else{
            if(MdaUtils.equals(bpdgrp.getRec().getFintyp(),"P")){
                argTxt = "Amount Purchased";
            }else{
                argTxt = "Advanced Amount";
            }
        }
        trndocService.xmlPrtRefLine(dataMap,doceotVo,argTxt,trndocService.xmlFmtCurAmt(doceotVo, bpdgrp.getCbs().getMax().getCur(), bpdgrp.getCbs().getMax().getAmt()));
    }

    private <T extends BaseTransactionVo> void xmlPrtRefBlkTR(Map<String, List<String[]>> dataMap, T transactionVo, DoceotVo doceotVo) {
        Trdgrp trdgrp = Utils.getFieldValue(transactionVo, "trdgrp");
        trndocService.xmlPrtRefLine(dataMap, doceotVo,"Parent Contract",trdgrp.getRec().getPntref());
        trndocService.xmlPrtRefLine(dataMap, doceotVo,"Financing Reference",trdgrp.getRec().getOwnref());
        trndocService.xmlPrtRefLine(dataMap, doceotVo,"Financed Customer",templateUtils.xmlGetPtyNam(trdgrp.getFip()));
        trndocService.xmlPrtRefLineYourRef(dataMap,transactionVo,doceotVo);
        trndocService.xmlPrtRefLine(dataMap, doceotVo,"Due Date",xmlFmtDate("L",trdgrp.getRec().getMatdat(),doceotVo));
        String argTxt = "";
        if(MdaUtils.equals(trdgrp.getRec().getFintyp(),"PCL")){
            argTxt = "Packing Credit Amount";
        }else{
            argTxt = "Financing Amount";
        }
        trndocService.xmlPrtRefLine(dataMap,doceotVo,argTxt,trndocService.xmlFmtCurAmt(doceotVo, trdgrp.getCbs().getMax().getCur(), trdgrp.getCbs().getMax().getAmt()));
    }
    private <T extends BaseTransactionVo> void xmlPrtRefBlkCP(Map<String, List<String[]>> dataMap, T transactionVo, DoceotVo doceotVo) {
        Cpdgrp cpdgrp = Utils.getFieldValue(transactionVo, "cpdgrp");
        trndocService.xmlPrtRefLineYourRef(dataMap,transactionVo,doceotVo);
        xmlPrtRefLineOwnRef(dataMap,cpdgrp,doceotVo);
        if(!MdaUtils.isEmpty(cpdgrp.getCbs().getMax().getAmt())){
            trndocService.xmlPrtRefLine(dataMap,doceotVo,"Payment Amount",trndocService.xmlFmtCurAmt(doceotVo,cpdgrp.getCbs().getMax().getCur(),cpdgrp.getCbs().getMax().getAmt()));
        }
        if(!MdaUtils.equals(doceotVo.getRole(),"ORI")){
            trndocService.xmlPrtRefLinePty(dataMap,doceotVo,cpdgrp.getOri());
        }
        if(!MdaUtils.equals(doceotVo.getRole(),"ORC")){
            trndocService.xmlPrtRefLinePty(dataMap,doceotVo,cpdgrp.getOrc());
        }
        }

    private <T extends BaseTransactionVo> void xmlPrtRefBlkMC(Map<String, List<String[]>> dataMap, T transactionVo, DoceotVo doceotVo) {
        Mcdgrp mcdgrp = Utils.getFieldValue(transactionVo, "mcdgrp");
        trndocService.xmlPrtRefLineYourRef(dataMap,transactionVo,doceotVo);
        xmlPrtRefLineOwnRef(dataMap,mcdgrp,doceotVo);
        if(!MdaUtils.equals(doceotVo.getRole(),"APL")){
            trndocService.xmlPrtRefLinePty(dataMap,doceotVo,mcdgrp.getApl());
        }
        if(!MdaUtils.equals(doceotVo.getRole(),"ADE")){
            trndocService.xmlPrtRefLinePty(dataMap,doceotVo,mcdgrp.getAde());
        }
    }
    private <T extends BaseTransactionVo> void xmlPrtRefBlkMR(Map<String, List<String[]>> dataMap, T transactionVo, DoceotVo doceotVo) {
        Mcdgrp mcdgrp = Utils.getFieldValue(transactionVo, "mcdgrp");
        if(getCurrentCORLineLength(doceotVo) == -1 || MdaUtils.equals(doceotVo.getCortyp(),"TLX")){
            trndocService.xmlPrtRefLineYourRef(dataMap,transactionVo,doceotVo);
            xmlPrtRefLineOwnRef(dataMap,mcdgrp,doceotVo);
            trndocService.xmlPrtRefLine(dataMap,doceotVo,"Contract amount",trndocService.xmlFmtCurAmt(doceotVo,mcdgrp.getCbs().getOpn1().getCur(),mcdgrp.getCbs().getOpn1().getAmt()));
        }

    }
    private <T extends BaseTransactionVo> void xmlPrtRefBlkLT(Map<String, List<String[]>> dataMap, T transactionVo, DoceotVo doceotVo) {
        Ltdgrp ltdgrp = Utils.getFieldValue(transactionVo, "ltdgrp");
        xmlPrtRefLineLcNo(dataMap, ltdgrp.getRec().getLcrtyp(),ltdgrp.getRec().getOwnref(), doceotVo);
        trndocService.xmlPrtRefLineYourRef(dataMap, transactionVo, doceotVo);
        //XMLPrtRefLineDocRef
        trndocService.xmlPrtRefLine(dataMap,doceotVo,"Document set no",ltdgrp.getRec().getOwnref());
        //XMLPrtRefLineIssDate
        trndocService.xmlPrtRefLine(dataMap,doceotVo,"Issued on",xmlFmtDate("L",ltdgrp.getRec().getOpndat(),doceotVo));
        //XMLPrtRefLineLCAmt
        if(!MdaUtils.isEmpty(ltdgrp.getCbs().getNom1().getAmt())){
            trndocService.xmlPrtRefLine(dataMap,doceotVo,"Transfer Amount",trndocService.xmlFmtCurAmt(doceotVo,ltdgrp.getCbs().getNom1().getCur(),ltdgrp.getCbs().getNom1().getAmt()));
        }
        //XMLPrtRefLineAddAmt
        if(!MdaUtils.isEmpty(ltdgrp.getCbs().getMax2().getAmt())){
            trndocService.xmlPrtRefLine(dataMap,doceotVo,"Additional amount",trndocService.xmlFmtCurAmt(doceotVo,ltdgrp.getCbs().getMax2().getCur(),ltdgrp.getCbs().getMax2().getAmt()));
        }
        //XMLGetNomSpc
        XMLPrtRefLineNomSpc(dataMap, ltdgrp.getRec().getNomspc(),ltdgrp.getRec().getNomtop(),ltdgrp.getRec().getNomton(), doceotVo);
        if(!MdaUtils.equals(doceotVo.getRole(),"BE1")){
            trndocService.xmlPrtRefLinePty(dataMap, doceotVo, ltdgrp.getBe1());
        }
        if(!MdaUtils.equals(doceotVo.getRole(),"BE2")){
            trndocService.xmlPrtRefLinePty(dataMap, doceotVo, ltdgrp.getBe2());
        }
        if(!MdaUtils.equals(doceotVo.getRole(),"ADT")){
            trndocService.xmlPrtRefLinePty(dataMap, doceotVo, ltdgrp.getAdt());
        }


    }

    private <T extends BaseTransactionVo> void xmlPrtRefBlkBT(Map<String, List<String[]>> dataMap, T transactionVo, DoceotVo doceotVo) {
        Btdgrp btdgrp = Utils.getFieldValue(transactionVo, "btdgrp");
        Ltdgrp ltdgrp = Utils.getFieldValue(transactionVo, "ltdgrp");
        Ledgrp ledgrp = Utils.getFieldValue(transactionVo, "ledgrp");
//        \LETMOD\LETDOC.XMLPrtRefLineLCNo
        trndocService.xmlPrtRefLine(dataMap,doceotVo,"Letter of Credit No.",ledgrp.getIss().getPts().getRef());
//                XMLPrtRefLineDocRef
        trndocService.xmlPrtRefLine(dataMap,doceotVo,"Documents Reference",btdgrp.getRec().getOwnref());
//        XMLPrtRefLineYourRef
        trndocService.xmlPrtRefLineYourRef(dataMap,transactionVo,doceotVo);
//                XMLPrtRefLineIssDate
        trndocService.xmlPrtRefLine(dataMap,doceotVo,"Document set Issued on",xmlFmtDate("L",btdgrp.getRec().getOpndat(),doceotVo));
//\LTTMOD\LTTDOC.XMLPrtRefLineLCAmt
        if(!MdaUtils.isEmpty(ltdgrp.getCbs().getNom1().getAmt())){
            trndocService.xmlPrtRefLine(dataMap,doceotVo,"Transfer Amount",trndocService.xmlFmtCurAmt(doceotVo,ltdgrp.getCbs().getNom1().getCur(),ltdgrp.getCbs().getNom1().getAmt()));
        }
//\LTTMOD\LTTDOC.XMLPrtRefLineNomSpc
        XMLPrtRefLineNomSpc(dataMap, ltdgrp.getRec().getNomspc(),ltdgrp.getRec().getNomtop(),ltdgrp.getRec().getNomton(), doceotVo);
//                XMLPrtRefLineDocAmt
        if(!MdaUtils.equals(doceotVo.getRole(),btdgrp.getRec().getDocprbrol())){
            if(!MdaUtils.isEmpty(btdgrp.getCbs().getMax().getAmt())){
                trndocService.xmlPrtRefLine(dataMap,doceotVo,"Value of Documents",trndocService.xmlFmtCurAmt(doceotVo,btdgrp.getCbs().getMax().getCur(),ltdgrp.getCbs().getMax().getAmt()));

            }
        }
//        XMLPrtRefLineAddAmt
        if(!MdaUtils.equals(doceotVo.getRole(),btdgrp.getRec().getDocprbrol())){
            if(!MdaUtils.isEmpty(btdgrp.getCbs().getMax().getAmt())){
                trndocService.xmlPrtRefLine(dataMap,doceotVo,"Additional Amount",trndocService.xmlFmtCurAmt(doceotVo,btdgrp.getCbs().getMax2().getCur(),ltdgrp.getCbs().getMax2().getAmt()));
            }
        }

        if(!MdaUtils.equals(doceotVo.getRole(),"APL")){
            trndocService.xmlPrtRefLinePty(dataMap, doceotVo, ledgrp.getApl());
        }
        if(!MdaUtils.equals(doceotVo.getRole(),"BEN")){
            trndocService.xmlPrtRefLinePty(dataMap, doceotVo, ledgrp.getBen());
        }
        if(!MdaUtils.equals(doceotVo.getRole(),"ISS")){
            trndocService.xmlPrtRefLinePty(dataMap, doceotVo, ledgrp.getIss());
        }
        if(!MdaUtils.equals(doceotVo.getRole(),"APB")){
            trndocService.xmlPrtRefLinePty(dataMap, doceotVo, ledgrp.getApb());
        }
        if(!MdaUtils.equals(doceotVo.getRole(),"CON")){
            trndocService.xmlPrtRefLinePty(dataMap, doceotVo, ledgrp.getCon());
        }

    }
    public int getCurrentCORLineLength(DoceotVo doceotVo) {
        int retMsg = -1;
        switch (doceotVo.getCortyp()) {
            case "TLX":
            case "FAX":
            case "EML":
                retMsg = 69;
                break;
            case "BOL":
                retMsg = 79;
                break;
            case "SWT":
            case "RTG":
            case "TAR":
            case "TCO":
                retMsg = -2;
                break;
            default:
                retMsg = -1;
                break;
        }
        return retMsg;
    }

    private void  xmlPrtRefLineLcNo(Map<String, List<String[]>> dataMap, String lcrtyp, String ownref,DoceotVo doceotVo){
            String txt = "";
            switch (lcrtyp){
                case "I":
                case "IT":
                case "R":
                case "RT":
                    txt = "Letter of Credit no";
                    break;
                default:
                    txt = "Standby L/C no";
                    break;
            }
            trndocService.xmlPrtRefLine(dataMap,doceotVo,txt,ownref);

    }


    private void  XMLPrtRefLineExpiry(Map<String, List<String[]>> dataMap, Lidgrp lidgrp, DoceotVo doceotVo) {
        String txt =  Strings.formatText("$1,$2",lidgrp.getRec().getExpplc(),xmlFmtDate("L",lidgrp.getRec().getExpdat(),doceotVo));
        trndocService.xmlPrtRefLine(dataMap,doceotVo,"Expiry",txt);
    }

    private void  XMLPrtRefLineExpiry(Map<String, List<String[]>> dataMap, Didgrp didgrp, DoceotVo doceotVo) {
        String txt =  Strings.formatText("$1,$2",didgrp.getRec().getExpplc(),xmlFmtDate("L",didgrp.getRec().getExpdat(),doceotVo));
        trndocService.xmlPrtRefLine(dataMap,doceotVo,"Expiry",txt);
    }
    private void  XMLPrtRefLineIssDate(Map<String, List<String[]>> dataMap, Ledgrp ledgrp, DoceotVo doceotVo) {
        trndocService.xmlPrtRefLine(dataMap,doceotVo,"Issued on",xmlFmtDate("L",ledgrp.getRec().getExpdat(),doceotVo));
    }
    private void  XMLPrtRefLineIssDate(Map<String, List<String[]>> dataMap, Dedgrp dedgrp, DoceotVo doceotVo) {
        trndocService.xmlPrtRefLine(dataMap,doceotVo,"Issued on",xmlFmtDate("L",dedgrp.getRec().getExpdat(),doceotVo));
    }
    private void  xmlPrtRefLineLCAmt(Map<String, List<String[]>> dataMap, Lidgrp lidgrp, DoceotVo doceotVo) {
        String cur = lidgrp.getCbs().getNom1().getCur();
        BigDecimal amt = lidgrp.getCbs().getNom1().getAmt();
        if (!MdaUtils.isEmpty(amt)) {
            trndocService.xmlPrtRefLine(dataMap, doceotVo, "L/C Amount", trndocService.xmlFmtCurAmt(doceotVo, cur, amt));
        }
}
    private void  xmlPrtRefLineLCAmt(Map<String, List<String[]>> dataMap, Didgrp didgrp, DoceotVo doceotVo) {
        String cur = didgrp.getCbs().getNom1().getCur();
        BigDecimal amt = didgrp.getCbs().getNom1().getAmt();
        if (!MdaUtils.isEmpty(amt)) {
            trndocService.xmlPrtRefLine(dataMap, doceotVo, "L/C Amount", trndocService.xmlFmtCurAmt(doceotVo, cur, amt));
        }
    }
    private void  xmlPrtRefLineLCAmt(Map<String, List<String[]>> dataMap, Ledgrp ledgrp, DoceotVo doceotVo) {
        String cur = ledgrp.getCbs().getNom1().getCur();
        BigDecimal amt = ledgrp.getCbs().getNom1().getAmt();
        if (!MdaUtils.isEmpty(amt)) {
            trndocService.xmlPrtRefLine(dataMap, doceotVo, "L/C Amount", trndocService.xmlFmtCurAmt(doceotVo, cur, amt));
        }
    }
    private void  xmlPrtRefLineLCAmt(Map<String, List<String[]>> dataMap, Dedgrp dedgrp, DoceotVo doceotVo) {
        String cur = dedgrp.getCbs().getNom1().getCur();
        BigDecimal amt = dedgrp.getCbs().getNom1().getAmt();
        if (!MdaUtils.isEmpty(amt)) {
            trndocService.xmlPrtRefLine(dataMap, doceotVo, "L/C Amount", trndocService.xmlFmtCurAmt(doceotVo, cur, amt));
        }
    }
    private void  xmlPrtRefLineAddAmt(Map<String, List<String[]>> dataMap, Lidgrp lidgrp, DoceotVo doceotVo) {

        String cur = lidgrp.getCbs().getMax2().getCur();
        BigDecimal amt = lidgrp.getCbs().getMax2().getAmt();
        if (!MdaUtils.isEmpty(amt)) {
            trndocService.xmlPrtRefLine(dataMap, doceotVo, "Additional Amount", trndocService.xmlFmtCurAmt(doceotVo, cur, amt));
        }
    }
    private void  xmlPrtRefLineAddAmt(Map<String, List<String[]>> dataMap, Didgrp didgrp, DoceotVo doceotVo) {

        String cur = didgrp.getCbs().getMax2().getCur();
        BigDecimal amt = didgrp.getCbs().getMax2().getAmt();
        if (!MdaUtils.isEmpty(amt)) {
            trndocService.xmlPrtRefLine(dataMap, doceotVo, "Additional Amount", trndocService.xmlFmtCurAmt(doceotVo, cur, amt));
        }
    }
    private void  xmlPrtRefLineAddAmt(Map<String, List<String[]>> dataMap, Ledgrp ledgrp, DoceotVo doceotVo) {

        String cur = ledgrp.getCbs().getMax2().getCur();
        BigDecimal amt = ledgrp.getCbs().getMax2().getAmt();
        if (!MdaUtils.isEmpty(amt)) {
            trndocService.xmlPrtRefLine(dataMap, doceotVo, "Additional Amount", trndocService.xmlFmtCurAmt(doceotVo, cur, amt));
        }
    }
    private void  xmlPrtRefLineAddAmt(Map<String, List<String[]>> dataMap, Dedgrp dedgrp, DoceotVo doceotVo) {

        String cur = dedgrp.getCbs().getMax2().getCur();
        BigDecimal amt = dedgrp.getCbs().getMax2().getAmt();
        if (!MdaUtils.isEmpty(amt)) {
            trndocService.xmlPrtRefLine(dataMap, doceotVo, "Additional Amount", trndocService.xmlFmtCurAmt(doceotVo, cur, amt));
        }
    }

    private void  XMLPrtRefLineNomSpc(Map<String, List<String[]>> dataMap, String nomspc,BigDecimal top,BigDecimal ton, DoceotVo doceotVo) {
        String desc = "";
        String val = "";
        switch (nomspc){
            case "":
                desc = "Amount Tolerance";
                val = Strings.formatText("+ $1 % / - $2 %",top,ton);
                break;
            case "N":
                desc = "Amount Specification";
                val = "Not exceeding";
                break;
            case "X":
                desc = "Amount Specification";
                val = "According to UCP";
                break;
            default:
                break;
        }
        trndocService.xmlPrtRefLine(dataMap,doceotVo,desc,val);
    }
    private void  XMLPrtRefLineNomSpc(Map<String, List<String[]>> dataMap, String nomspc,int top,int ton, DoceotVo doceotVo) {
        String desc = "";
        String val = "";
        switch (nomspc){
            case "":
                desc = "Amount Tolerance";
                val = Strings.formatText("+ $1 % / - $2 %",top,ton);
                break;
            case "N":
                desc = "Amount Specification";
                val = "Not exceeding";
                break;
            case "X":
                desc = "Amount Specification";
                val = "According to UCP";
                break;
            default:
                break;
        }
        trndocService.xmlPrtRefLine(dataMap,doceotVo,desc,val);
    }
        public String xmlFmtDate(String argDatTyp, Date argDate, DoceotVo doceotVo)
    {
        String docUil = doceotVo.getDocuil();
        String typ = Strings.toUpper(argDatTyp);
        switch( typ )
        {
            case "L":
                return DateUtils.parseDateToStr("dd.MMMMyyyy",argDate);
            case "S":
                return  Formats.fmtDateShort(argDate,docUil);
            case "N":
                return  Formats.format(argDate,docUil);
        }
        return "";
    }
    public String getMsgTitl(FremsgVo fremsg){
        String title = "";
        switch (fremsg.getSndmt()){
            case "30":
                title = "Acknowledgment";
                break;
            case "92":
                title = "Cancelation of previous Message";
                break;
            case "95":
                title = "Query Message";
                break;
            case "96":
                title = "Answer Message to a Query";
                break;
            default:
                if(MdaUtils.isEmpty(fremsg.getPrttitle())){
                    title = "Information / Notification";
                }else{
                    title = fremsg.getPrttitle();
                }
                break;
        }
        return title;
    }
    public void getAdrNameC(Map<String, List<String[]>> dataMap,FremsgVo fremsg){
        String adrlin = "";
        if(!MdaUtils.isEmpty(fremsg.getOthcc().getAdr().getAdr1())){
            adrlin += fremsg.getOthcc().getAdr().getAdr1() + "\n";
        }
        if(!MdaUtils.isEmpty(fremsg.getOthcc().getAdr().getAdr2())){
            adrlin += fremsg.getOthcc().getAdr().getAdr2() + "\n";
        }
        if(!MdaUtils.isEmpty(fremsg.getOthcc().getAdr().getAdr3())){
            adrlin += fremsg.getOthcc().getAdr().getAdr3() + "\n";
        }
        if(!MdaUtils.isEmpty(fremsg.getOthcc().getAdr().getPobzip())){
            adrlin += fremsg.getOthcc().getAdr().getPobzip();
        }
        DocUtils.putData(dataMap, "adrlin", adrlin);
    }
    public void getAdrNameO(Map<String, List<String[]>> dataMap,FremsgVo fremsg){
        String adrlin = "";
        if(!MdaUtils.isEmpty(fremsg.getOthcc().getPts().getAdrblk())){
            DocUtils.putData(dataMap, "adrlin", fremsg.getOthcc().getPts().getAdrblk());
        }else{
            if(!MdaUtils.isEmpty(fremsg.getOthcc().getAdr().getInr())){
                if(!MdaUtils.isEmpty(fremsg.getOthcc().getAdr().getNam1())){
                    adrlin += fremsg.getOthcc().getAdr().getNam1() + "\n";
                }
                if(!MdaUtils.isEmpty(fremsg.getOthcc().getAdr().getAdr1())){
                    adrlin += fremsg.getOthcc().getAdr().getAdr1() + "\n";
                }
                if(!MdaUtils.isEmpty(fremsg.getOthcc().getAdr().getAdr2())){
                    adrlin += fremsg.getOthcc().getAdr().getAdr2() + "\n";
                }
                if(!MdaUtils.isEmpty(fremsg.getOthcc().getAdr().getAdr3())){
                    adrlin += fremsg.getOthcc().getAdr().getAdr3() + "\n";
                }
                if(!MdaUtils.isEmpty(fremsg.getOthcc().getAdr().getAdr4())){
                    adrlin += fremsg.getOthcc().getAdr().getAdr4() + "\n";
                }
                if(!MdaUtils.isEmpty(fremsg.getOthcc().getAdr().getLoczip()) || !MdaUtils.isEmpty(fremsg.getOthcc().getAdr().getLoctxt())){
                    adrlin += fremsg.getOthcc().getAdr().getLoczip() + " " + fremsg.getOthcc().getAdr().getLoctxt() + "\n";
                }
                DocUtils.putData(dataMap, "adrlin", adrlin);
            }
        }
    }

    public  void getContactLineDate(Map<String, List<String[]>> dataMap){
        Usr usr = SettleContext.getUserSession().getUsr();
        DocUtils.putData(dataMap, "name", usr.getNam());
        DocUtils.putData(dataMap, "telNum", usr.getTel());
        DocUtils.putData(dataMap, "date", Formats.fmtDateLong(new Date()));
    }

   public String  xmlGetDoctypcod(String doctypcod){
        String desc = "";
        switch (doctypcod){
            case "A":
                desc = "Documents against Acceptance";
                break;
            case "C":
                desc = "Clean Collection";
                break;
            case "D":
                desc = "Documents against Deferred Payment";
                break;
            case "M":
                desc = "Documents against Mixed Payment";
                break;
            case "P":
                desc = "Documents against Sight Payment";
                break;
            default:
                break;
        }
        return desc;
   }
    public String xmlGetMatperbeg(String matperbeg){
        String argTxt = "";
        switch (matperbeg){
            case "BE":
                argTxt = "After date of bill of exchange";
                break;
            case "CC":
                argTxt = "After customer clearance of goods";
                break;
            case "FD":
                argTxt = "After goods pass food and drug administration";
                break;
            case "FP":
                argTxt = "First presentation";
                break;
            case "GA":
                argTxt = "After arrival of goods";
                break;
            case "ID":
                argTxt = "After invoice date";
                break;
            case "ST":
                argTxt = "After sight";
                break;
            case "TD":
                argTxt = "After date of transport document";
                break;
            case "XX":
                argTxt = "See field 72 for specification";
                break;
            default:
                argTxt = codetableService.getTblLabel(matperbeg,"MATBEG");
                break;
        }
        return argTxt;
    }
   public void  xmlPrtRefLineMaturity(Map<String, List<String[]>> dataMap,DoceotVo doceotVo,Bcdgrp bcdgrp){
        String matTxt = "";
        if(!MdaUtils.isEmpty(bcdgrp.getRec().getMattxtflg())){
            matTxt = "Multiple Tenor";
        }else{
            if(!MdaUtils.isEmpty(bcdgrp.getRec().getMatdat())){
                matTxt =  Formats.fmtDateLong(bcdgrp.getRec().getMatdat());
            }else{
                if(!MdaUtils.isEmpty(bcdgrp.getRec().getMatperbeg())){
                    matTxt = Strings.formatText("$1 $2 $3",bcdgrp.getRec().getMatpercnt(),codetableService.getTblLabel(bcdgrp.getRec().getMatpertyp(),"matper",xmlGetMatperbeg(bcdgrp.getRec().getMatperbeg())));
                }
            }
        }
        if(!MdaUtils.isEmpty(matTxt)){
            trndocService.xmlPrtRefLine(dataMap,doceotVo,"Maturity",matTxt);
        }
        if(!MdaUtils.isEmpty(bcdgrp.getBlk().getBcgdet())){
            trndocService.xmlPrtRefLine(dataMap,doceotVo,"Tenor Details",bcdgrp.getBlk().getBcgdet());
        }
    }

    public void  xmlPrtRefLineMaturity(Map<String, List<String[]>> dataMap,DoceotVo doceotVo,Bodgrp bodgrp){
        String matTxt = "";
        if(!MdaUtils.isEmpty(bodgrp.getRec().getMattxtflg())){
            matTxt = "Multiple Tenor";
        }else{
            if(!MdaUtils.isEmpty(bodgrp.getRec().getMatdat())){
                matTxt =  Formats.fmtDateLong(bodgrp.getRec().getMatdat());
            }else{
                if(!MdaUtils.isEmpty(bodgrp.getRec().getMatperbeg())){
                    matTxt = Strings.formatText("$1 $2 $3",bodgrp.getRec().getMatpercnt(),codetableService.getTblLabel(bodgrp.getRec().getMatpertyp(),"matper",xmlGetMatperbeg(bodgrp.getRec().getMatperbeg())));
                }
            }
        }
        if(!MdaUtils.isEmpty(matTxt)){
            trndocService.xmlPrtRefLine(dataMap,doceotVo,"Maturity",matTxt);
        }
        if(!MdaUtils.isEmpty(bodgrp.getBlk().getBogdet())){
            trndocService.xmlPrtRefLine(dataMap,doceotVo,"Tenor Details",bodgrp.getBlk().getBogdet());
        }
    }
   public void  xmlPrtRefLineOwnRef(Map<String, List<String[]>> dataMap, Ledgrp grp, DoceotVo doceotVo){
       if (trndocService.getCurrentCORLineLength(doceotVo) == -1 || MdaUtils.compareTo(doceotVo.getCortyp(), "TLX") == 0) {
           trndocService.xmlPrtRefLine(dataMap, doceotVo, "Our Reference", grp.getRec().getOwnref());
       }
    }
    public void  xmlPrtRefLineOwnRef(Map<String, List<String[]>> dataMap, Dedgrp grp, DoceotVo doceotVo){
        if (trndocService.getCurrentCORLineLength(doceotVo) == -1 || MdaUtils.compareTo(doceotVo.getCortyp(), "TLX") == 0) {
            trndocService.xmlPrtRefLine(dataMap, doceotVo, "Our Reference", grp.getRec().getOwnref());
        }
    }
    public void  xmlPrtRefLineOwnRef(Map<String, List<String[]>> dataMap, Bcdgrp grp, DoceotVo doceotVo){
        if (trndocService.getCurrentCORLineLength(doceotVo) == -1 || MdaUtils.compareTo(doceotVo.getCortyp(), "TLX") == 0) {
            trndocService.xmlPrtRefLine(dataMap, doceotVo, "Our Reference", grp.getRec().getOwnref());
        }
    }
    public void  xmlPrtRefLineOwnRef(Map<String, List<String[]>> dataMap, Bodgrp grp, DoceotVo doceotVo){
        if (trndocService.getCurrentCORLineLength(doceotVo) == -1 || MdaUtils.compareTo(doceotVo.getCortyp(), "TLX") == 0) {
            trndocService.xmlPrtRefLine(dataMap, doceotVo, "Our Reference", grp.getRec().getOwnref());
        }
    }
    public void  xmlPrtRefLineOwnRef(Map<String, List<String[]>> dataMap, Cpdgrp grp, DoceotVo doceotVo){
        if (trndocService.getCurrentCORLineLength(doceotVo) == -1 || MdaUtils.compareTo(doceotVo.getCortyp(), "TLX") == 0) {
            trndocService.xmlPrtRefLine(dataMap, doceotVo, "Our Reference", grp.getRec().getOwnref());
        }
    }

    public void  xmlPrtRefLineOwnRef(Map<String, List<String[]>> dataMap, Mcdgrp grp, DoceotVo doceotVo){
        if (trndocService.getCurrentCORLineLength(doceotVo) == -1 || MdaUtils.compareTo(doceotVo.getCortyp(), "TLX") == 0) {
            trndocService.xmlPrtRefLine(dataMap, doceotVo, "Our Reference", grp.getRec().getOwnref());
        }
    }
}
