Search in sources :

Example 1 with GroupHeader1

use of com.axelor.apps.bankpayment.xsd.sepa.pain_001_001_02.GroupHeader1 in project axelor-open-suite by axelor.

the class BankOrderFile00100102Service method generateFile.

/**
 * Method to create an XML file for SEPA transfer pain.001.001.02
 *
 * @throws AxelorException
 * @throws DatatypeConfigurationException
 * @throws JAXBException
 * @throws IOException
 */
@Override
public File generateFile() throws JAXBException, IOException, AxelorException, DatatypeConfigurationException {
    DatatypeFactory datatypeFactory = DatatypeFactory.newInstance();
    ObjectFactory factory = new ObjectFactory();
    ServiceLevel2Choice svcLvl = factory.createServiceLevel2Choice();
    svcLvl.setCd(ServiceLevel1Code.SEPA);
    PaymentTypeInformation1 pmtTpInf = factory.createPaymentTypeInformation1();
    pmtTpInf.setSvcLvl(svcLvl);
    // Payer
    PartyIdentification8 dbtr = factory.createPartyIdentification8();
    dbtr.setNm(senderBankDetails.getOwnerName());
    // IBAN
    AccountIdentification3Choice iban = factory.createAccountIdentification3Choice();
    iban.setIBAN(senderBankDetails.getIban());
    CashAccount7 dbtrAcct = factory.createCashAccount7();
    dbtrAcct.setId(iban);
    // BIC
    FinancialInstitutionIdentification5Choice finInstnId = factory.createFinancialInstitutionIdentification5Choice();
    fillBic(finInstnId, senderBankDetails.getBank());
    BranchAndFinancialInstitutionIdentification3 dbtrAgt = factory.createBranchAndFinancialInstitutionIdentification3();
    dbtrAgt.setFinInstnId(finInstnId);
    PaymentInstructionInformation1 pmtInf = factory.createPaymentInstructionInformation1();
    pmtInf.setPmtInfId(bankOrderSeq);
    pmtInf.setPmtMtd(PaymentMethod3Code.TRF);
    pmtInf.setPmtTpInf(pmtTpInf);
    /**
     * RequestedExecutionDate Definition : Date at which the initiating party asks the Debtor's Bank
     * to process the payment. This is the date on which the debtor's account(s) is (are) to be
     * debited. XML Tag : <ReqdExctnDt> Occurrences : [1..1] Format : YYYY-MM-DD Rules : date is
     * limited to maximum one year in the future.
     */
    pmtInf.setReqdExctnDt(datatypeFactory.newXMLGregorianCalendar(bankOrderDate.format(DateTimeFormatter.ofPattern("yyyy-MM-dd"))));
    pmtInf.setDbtr(dbtr);
    pmtInf.setDbtrAcct(dbtrAcct);
    pmtInf.setDbtrAgt(dbtrAgt);
    CreditTransferTransactionInformation1 cdtTrfTxInf = null;
    PaymentIdentification1 pmtId = null;
    AmountType2Choice amt = null;
    CurrencyAndAmount instdAmt = null;
    PartyIdentification8 cbtr = null;
    CashAccount7 cbtrAcct = null;
    BranchAndFinancialInstitutionIdentification3 cbtrAgt = null;
    RemittanceInformation1 rmtInf = null;
    for (BankOrderLine bankOrderLine : bankOrderLineList) {
        BankDetails receiverBankDetails = bankOrderLine.getReceiverBankDetails();
        // Reference
        pmtId = factory.createPaymentIdentification1();
        // pmtId.setInstrId(bankOrderLine.getSequence());
        pmtId.setEndToEndId(bankOrderLine.getSequence());
        // Amount
        instdAmt = factory.createCurrencyAndAmount();
        instdAmt.setCcy(bankOrderCurrency.getCode());
        instdAmt.setValue(bankOrderLine.getBankOrderAmount());
        amt = factory.createAmountType2Choice();
        amt.setInstdAmt(instdAmt);
        // Receiver
        cbtr = factory.createPartyIdentification8();
        cbtr.setNm(receiverBankDetails.getOwnerName());
        // IBAN
        iban = factory.createAccountIdentification3Choice();
        iban.setIBAN(receiverBankDetails.getIban());
        cbtrAcct = factory.createCashAccount7();
        cbtrAcct.setId(iban);
        // BIC
        finInstnId = factory.createFinancialInstitutionIdentification5Choice();
        fillBic(finInstnId, receiverBankDetails.getBank());
        cbtrAgt = factory.createBranchAndFinancialInstitutionIdentification3();
        cbtrAgt.setFinInstnId(finInstnId);
        rmtInf = factory.createRemittanceInformation1();
        String ustrd = "";
        if (!Strings.isNullOrEmpty(bankOrderLine.getReceiverReference())) {
            ustrd += bankOrderLine.getReceiverReference();
        }
        if (!Strings.isNullOrEmpty(bankOrderLine.getReceiverLabel())) {
            if (!Strings.isNullOrEmpty(ustrd)) {
                ustrd += " - ";
            }
            ustrd += bankOrderLine.getReceiverLabel();
        }
        if (!Strings.isNullOrEmpty(ustrd)) {
            rmtInf.getUstrd().add(ustrd);
        }
        // StructuredRemittanceInformation6 strd = factory.createStructuredRemittanceInformation6();
        // 
        // CreditorReferenceInformation1 cdtrRefInf = factory.createCreditorReferenceInformation1();
        // cdtrRefInf.setCdtrRef(bankOrderLine.getReceiverReference());
        // 
        // strd.setCdtrRefInf(cdtrRefInf);
        // 
        // rmtInf.getStrd().add(strd);
        // Transaction
        cdtTrfTxInf = factory.createCreditTransferTransactionInformation1();
        cdtTrfTxInf.setPmtId(pmtId);
        cdtTrfTxInf.setAmt(amt);
        cdtTrfTxInf.setCdtr(cbtr);
        cdtTrfTxInf.setCdtrAcct(cbtrAcct);
        cdtTrfTxInf.setCdtrAgt(cbtrAgt);
        cdtTrfTxInf.setRmtInf(rmtInf);
        pmtInf.getCdtTrfTxInf().add(cdtTrfTxInf);
    }
    // Header
    GroupHeader1 grpHdr = factory.createGroupHeader1();
    /**
     * Référence du message qui n'est pas utilisée comme référence fonctionnelle.
     */
    grpHdr.setMsgId(bankOrderSeq);
    /**
     * CreationDateTime Definition : Date and Time at which a (group of) payment instruction(s) was
     * created by the instructing party. XML Tag : <CreDtTm> Occurrences : [1..1] Format :
     * YYYY-MM-DDThh:mm:ss
     */
    grpHdr.setCreDtTm(datatypeFactory.newXMLGregorianCalendar(generationDateTime.format(DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ss"))));
    grpHdr.setNbOfTxs(Integer.toString(nbOfLines));
    grpHdr.setCtrlSum(arithmeticTotal);
    grpHdr.setGrpg(Grouping1Code.MIXD);
    grpHdr.setInitgPty(dbtr);
    // Parent
    Pain00100102 pain00100102 = factory.createPain00100102();
    pain00100102.setGrpHdr(grpHdr);
    pain00100102.getPmtInf().add(pmtInf);
    // Document
    Document xml = factory.createDocument();
    xml.setPain00100102(pain00100102);
    fileToCreate = factory.createDocument(xml);
    return super.generateFile();
}
Also used : CreditTransferTransactionInformation1(com.axelor.apps.bankpayment.xsd.sepa.pain_001_001_02.CreditTransferTransactionInformation1) BankOrderLine(com.axelor.apps.bankpayment.db.BankOrderLine) DatatypeFactory(javax.xml.datatype.DatatypeFactory) PartyIdentification8(com.axelor.apps.bankpayment.xsd.sepa.pain_001_001_02.PartyIdentification8) BranchAndFinancialInstitutionIdentification3(com.axelor.apps.bankpayment.xsd.sepa.pain_001_001_02.BranchAndFinancialInstitutionIdentification3) BankDetails(com.axelor.apps.base.db.BankDetails) AccountIdentification3Choice(com.axelor.apps.bankpayment.xsd.sepa.pain_001_001_02.AccountIdentification3Choice) ServiceLevel2Choice(com.axelor.apps.bankpayment.xsd.sepa.pain_001_001_02.ServiceLevel2Choice) CurrencyAndAmount(com.axelor.apps.bankpayment.xsd.sepa.pain_001_001_02.CurrencyAndAmount) PaymentTypeInformation1(com.axelor.apps.bankpayment.xsd.sepa.pain_001_001_02.PaymentTypeInformation1) AmountType2Choice(com.axelor.apps.bankpayment.xsd.sepa.pain_001_001_02.AmountType2Choice) Document(com.axelor.apps.bankpayment.xsd.sepa.pain_001_001_02.Document) RemittanceInformation1(com.axelor.apps.bankpayment.xsd.sepa.pain_001_001_02.RemittanceInformation1) ObjectFactory(com.axelor.apps.bankpayment.xsd.sepa.pain_001_001_02.ObjectFactory) CashAccount7(com.axelor.apps.bankpayment.xsd.sepa.pain_001_001_02.CashAccount7) PaymentIdentification1(com.axelor.apps.bankpayment.xsd.sepa.pain_001_001_02.PaymentIdentification1) Pain00100102(com.axelor.apps.bankpayment.xsd.sepa.pain_001_001_02.Pain00100102) PaymentInstructionInformation1(com.axelor.apps.bankpayment.xsd.sepa.pain_001_001_02.PaymentInstructionInformation1) GroupHeader1(com.axelor.apps.bankpayment.xsd.sepa.pain_001_001_02.GroupHeader1) FinancialInstitutionIdentification5Choice(com.axelor.apps.bankpayment.xsd.sepa.pain_001_001_02.FinancialInstitutionIdentification5Choice)

Example 2 with GroupHeader1

use of com.axelor.apps.bankpayment.xsd.sepa.pain_001_001_02.GroupHeader1 in project axelor-open-suite by axelor.

the class BankOrderFile00800101Service method generateFile.

/**
 * Generates the XML SEPA Direct Debit file (pain.008.001.01)
 *
 * @return the SEPA Direct Debit file (pain.008.001.01)
 * @throws JAXBException
 * @throws IOException
 * @throws AxelorException
 * @throws DatatypeConfigurationException
 */
@Override
public File generateFile() throws JAXBException, IOException, AxelorException, DatatypeConfigurationException {
    // Creditor
    PartyIdentification8 creditor = factory.createPartyIdentification8();
    creditor.setNm(senderBankDetails.getOwnerName());
    /*
     * Hierarchy of a XML file
     *
     * GroupHeader                          : This building block is mandatory and present once.
     *                                        It contains elements such as Message Identification,
     *                                        Creation Date And Time, Grouping indicator.
     * Payment Information                  : This building block is mandatory and repetitive.
     *                                        It contains, among other things, elements related
     *                                        to the Credit side of the transaction, such as
     *                                        Creditor and Payment Type Information.
     * Direct Debit Transaction Information : This building block is mandatory and repetitive.
     *                                        It contains, among other things, elements related
     *                                        to the debit side of the transaction, such as
     *                                        Debtor and Remittance Information Rules.
     *
     * <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
     * <Document xmlns="urn:iso:std:iso:20022:tech:xsd:pain.008.001.01">
     *     <pain.008.001.01>
     *         <GrpHdr>                 <-- occ : 1..1
     *         </GrpHdr>
     *         <PmtInf>                 <-- occ : 1..n
     *             <DrctDbtTxInf>       <-- occ : 1..n
     *             </DrctDbtTxInf>
     *         </PmtInf>
     *     </pain.008.001.01>
     * </Document>
     */
    /*
     * Document, <Document> tag
     */
    Document document = factory.createDocument();
    /*
     * pain.008.001.01, <pain.008.001.01> tag
     */
    Pain00800101 pain00800101 = factory.createPain00800101();
    document.setPain00800101(pain00800101);
    /*
     * Group Header, <GrpHdr> tag
     * Set of characteristics shared by all individual transactions included in the message.
     */
    GroupHeader1 groupHeader = factory.createGroupHeader1();
    createGrpHdr(groupHeader, creditor);
    pain00800101.setGrpHdr(groupHeader);
    /*
     * Payment Information, <PmtInf> tag
     * Does not need to set the List<PaymentInstructionInformation2> to the pain00800101 object (see doc).
     */
    createPmtInf(pain00800101.getPmtInf(), creditor);
    fileToCreate = factory.createDocument(document);
    return super.generateFile();
}
Also used : Pain00800101(com.axelor.apps.bankpayment.xsd.sepa.pain_008_001_01.Pain00800101) PartyIdentification8(com.axelor.apps.bankpayment.xsd.sepa.pain_008_001_01.PartyIdentification8) GroupHeader1(com.axelor.apps.bankpayment.xsd.sepa.pain_008_001_01.GroupHeader1) Document(com.axelor.apps.bankpayment.xsd.sepa.pain_008_001_01.Document)

Aggregations

BankOrderLine (com.axelor.apps.bankpayment.db.BankOrderLine)1 AccountIdentification3Choice (com.axelor.apps.bankpayment.xsd.sepa.pain_001_001_02.AccountIdentification3Choice)1 AmountType2Choice (com.axelor.apps.bankpayment.xsd.sepa.pain_001_001_02.AmountType2Choice)1 BranchAndFinancialInstitutionIdentification3 (com.axelor.apps.bankpayment.xsd.sepa.pain_001_001_02.BranchAndFinancialInstitutionIdentification3)1 CashAccount7 (com.axelor.apps.bankpayment.xsd.sepa.pain_001_001_02.CashAccount7)1 CreditTransferTransactionInformation1 (com.axelor.apps.bankpayment.xsd.sepa.pain_001_001_02.CreditTransferTransactionInformation1)1 CurrencyAndAmount (com.axelor.apps.bankpayment.xsd.sepa.pain_001_001_02.CurrencyAndAmount)1 Document (com.axelor.apps.bankpayment.xsd.sepa.pain_001_001_02.Document)1 FinancialInstitutionIdentification5Choice (com.axelor.apps.bankpayment.xsd.sepa.pain_001_001_02.FinancialInstitutionIdentification5Choice)1 GroupHeader1 (com.axelor.apps.bankpayment.xsd.sepa.pain_001_001_02.GroupHeader1)1 ObjectFactory (com.axelor.apps.bankpayment.xsd.sepa.pain_001_001_02.ObjectFactory)1 Pain00100102 (com.axelor.apps.bankpayment.xsd.sepa.pain_001_001_02.Pain00100102)1 PartyIdentification8 (com.axelor.apps.bankpayment.xsd.sepa.pain_001_001_02.PartyIdentification8)1 PaymentIdentification1 (com.axelor.apps.bankpayment.xsd.sepa.pain_001_001_02.PaymentIdentification1)1 PaymentInstructionInformation1 (com.axelor.apps.bankpayment.xsd.sepa.pain_001_001_02.PaymentInstructionInformation1)1 PaymentTypeInformation1 (com.axelor.apps.bankpayment.xsd.sepa.pain_001_001_02.PaymentTypeInformation1)1 RemittanceInformation1 (com.axelor.apps.bankpayment.xsd.sepa.pain_001_001_02.RemittanceInformation1)1 ServiceLevel2Choice (com.axelor.apps.bankpayment.xsd.sepa.pain_001_001_02.ServiceLevel2Choice)1 Document (com.axelor.apps.bankpayment.xsd.sepa.pain_008_001_01.Document)1 GroupHeader1 (com.axelor.apps.bankpayment.xsd.sepa.pain_008_001_01.GroupHeader1)1