Search in sources :

Example 1 with ServiceLevel8Choice

use of com.axelor.apps.bankpayment.xsd.sepa.pain_001_001_03.ServiceLevel8Choice in project axelor-open-suite by axelor.

the class BankOrderFile00100103Service method generateFile.

/**
 * Method to create an XML file for SEPA transfer pain.001.001.03
 *
 * @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();
    ServiceLevel8Choice svcLvl = factory.createServiceLevel8Choice();
    svcLvl.setCd("SEPA");
    PaymentTypeInformation19 pmtTpInf = factory.createPaymentTypeInformation19();
    pmtTpInf.setSvcLvl(svcLvl);
    // Payer
    PartyIdentification32 dbtr = factory.createPartyIdentification32();
    dbtr.setNm(senderBankDetails.getOwnerName());
    // IBAN
    AccountIdentification4Choice iban = factory.createAccountIdentification4Choice();
    iban.setIBAN(senderBankDetails.getIban());
    CashAccount16 dbtrAcct = factory.createCashAccount16();
    dbtrAcct.setId(iban);
    // BIC
    FinancialInstitutionIdentification7 finInstnId = factory.createFinancialInstitutionIdentification7();
    fillBic(finInstnId, senderBankDetails.getBank());
    BranchAndFinancialInstitutionIdentification4 dbtrAgt = factory.createBranchAndFinancialInstitutionIdentification4();
    dbtrAgt.setFinInstnId(finInstnId);
    PaymentInstructionInformation3 pmtInf = factory.createPaymentInstructionInformation3();
    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);
    CreditTransferTransactionInformation10 cdtTrfTxInf = null;
    PaymentIdentification1 pmtId = null;
    AmountType3Choice amt = null;
    ActiveOrHistoricCurrencyAndAmount instdAmt = null;
    PartyIdentification32 cbtr = null;
    CashAccount16 cbtrAcct = null;
    BranchAndFinancialInstitutionIdentification4 cbtrAgt = null;
    RemittanceInformation5 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.createActiveOrHistoricCurrencyAndAmount();
        instdAmt.setCcy(bankOrderCurrency.getCode());
        instdAmt.setValue(bankOrderLine.getBankOrderAmount());
        amt = factory.createAmountType3Choice();
        amt.setInstdAmt(instdAmt);
        // Receiver
        cbtr = factory.createPartyIdentification32();
        cbtr.setNm(receiverBankDetails.getOwnerName());
        // IBAN
        iban = factory.createAccountIdentification4Choice();
        iban.setIBAN(receiverBankDetails.getIban());
        cbtrAcct = factory.createCashAccount16();
        cbtrAcct.setId(iban);
        // BIC
        finInstnId = factory.createFinancialInstitutionIdentification7();
        fillBic(finInstnId, receiverBankDetails.getBank());
        cbtrAgt = factory.createBranchAndFinancialInstitutionIdentification4();
        cbtrAgt.setFinInstnId(finInstnId);
        rmtInf = factory.createRemittanceInformation5();
        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);
        }
        // StructuredRemittanceInformation7 strd = factory.createStructuredRemittanceInformation7();
        // 
        // CreditorReferenceInformation2 cdtrRefInf = factory.createCreditorReferenceInformation2();
        // cdtrRefInf.setRef(bankOrderLine.getReceiverReference());
        // 
        // strd.setCdtrRefInf(cdtrRefInf);
        // 
        // rmtInf.getStrd().add(strd);
        // Transaction
        cdtTrfTxInf = factory.createCreditTransferTransactionInformation10();
        cdtTrfTxInf.setPmtId(pmtId);
        cdtTrfTxInf.setAmt(amt);
        cdtTrfTxInf.setCdtr(cbtr);
        cdtTrfTxInf.setCdtrAcct(cbtrAcct);
        cdtTrfTxInf.setCdtrAgt(cbtrAgt);
        cdtTrfTxInf.setRmtInf(rmtInf);
        pmtInf.getCdtTrfTxInf().add(cdtTrfTxInf);
    }
    // Header
    GroupHeader32 grpHdr = factory.createGroupHeader32();
    /**
     * 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.setInitgPty(dbtr);
    // Parent
    CustomerCreditTransferInitiationV03 customerCreditTransferInitiationV03 = factory.createCustomerCreditTransferInitiationV03();
    customerCreditTransferInitiationV03.setGrpHdr(grpHdr);
    customerCreditTransferInitiationV03.getPmtInf().add(pmtInf);
    // Document
    Document xml = factory.createDocument();
    xml.setCstmrCdtTrfInitn(customerCreditTransferInitiationV03);
    fileToCreate = factory.createDocument(xml);
    return super.generateFile();
}
Also used : BankOrderLine(com.axelor.apps.bankpayment.db.BankOrderLine) DatatypeFactory(javax.xml.datatype.DatatypeFactory) ActiveOrHistoricCurrencyAndAmount(com.axelor.apps.bankpayment.xsd.sepa.pain_001_001_03.ActiveOrHistoricCurrencyAndAmount) BranchAndFinancialInstitutionIdentification4(com.axelor.apps.bankpayment.xsd.sepa.pain_001_001_03.BranchAndFinancialInstitutionIdentification4) BankDetails(com.axelor.apps.base.db.BankDetails) CashAccount16(com.axelor.apps.bankpayment.xsd.sepa.pain_001_001_03.CashAccount16) Document(com.axelor.apps.bankpayment.xsd.sepa.pain_001_001_03.Document) PartyIdentification32(com.axelor.apps.bankpayment.xsd.sepa.pain_001_001_03.PartyIdentification32) AmountType3Choice(com.axelor.apps.bankpayment.xsd.sepa.pain_001_001_03.AmountType3Choice) ObjectFactory(com.axelor.apps.bankpayment.xsd.sepa.pain_001_001_03.ObjectFactory) RemittanceInformation5(com.axelor.apps.bankpayment.xsd.sepa.pain_001_001_03.RemittanceInformation5) GroupHeader32(com.axelor.apps.bankpayment.xsd.sepa.pain_001_001_03.GroupHeader32) PaymentTypeInformation19(com.axelor.apps.bankpayment.xsd.sepa.pain_001_001_03.PaymentTypeInformation19) PaymentIdentification1(com.axelor.apps.bankpayment.xsd.sepa.pain_001_001_03.PaymentIdentification1) CreditTransferTransactionInformation10(com.axelor.apps.bankpayment.xsd.sepa.pain_001_001_03.CreditTransferTransactionInformation10) ServiceLevel8Choice(com.axelor.apps.bankpayment.xsd.sepa.pain_001_001_03.ServiceLevel8Choice) FinancialInstitutionIdentification7(com.axelor.apps.bankpayment.xsd.sepa.pain_001_001_03.FinancialInstitutionIdentification7) PaymentInstructionInformation3(com.axelor.apps.bankpayment.xsd.sepa.pain_001_001_03.PaymentInstructionInformation3) CustomerCreditTransferInitiationV03(com.axelor.apps.bankpayment.xsd.sepa.pain_001_001_03.CustomerCreditTransferInitiationV03) AccountIdentification4Choice(com.axelor.apps.bankpayment.xsd.sepa.pain_001_001_03.AccountIdentification4Choice)

Example 2 with ServiceLevel8Choice

use of com.axelor.apps.bankpayment.xsd.sepa.pain_001_001_03.ServiceLevel8Choice in project axelor-open-suite by axelor.

the class BankOrderFile00800102Service method createPmtInf.

/**
 * Builds the PaymentInformation part ({@code <PmtInf>} tag) of the file, and adds it into the
 * provided {@link PaymentInstructionInformation4} list
 *
 * @param paymentInstructionInformationList the list to add the {@link
 *     PaymentInstructionInformation4} objects into
 * @param creditor the creditor of the SEPA Direct Debit file
 * @throws DatatypeConfigurationException
 */
protected void createPmtInf(List<PaymentInstructionInformation4> paymentInstructionInformationList, PartyIdentification32 creditor) throws AxelorException, DatatypeConfigurationException {
    DatatypeFactory datatypeFactory = DatatypeFactory.newInstance();
    /*
     * Payment Information (mandatory)
     * Set of characteristics that apply to the credit side of the payment transactions included in the direct debit transaction initiation.
     */
    PaymentInstructionInformation4 paymentInstructionInformation4 = factory.createPaymentInstructionInformation4();
    paymentInstructionInformationList.add(paymentInstructionInformation4);
    /*
     * Payment Information Identification (mandatory)
     * Reference assigned by a sending party to unambiguously identify the payment information block within the message.
     */
    paymentInstructionInformation4.setPmtInfId(bankOrderSeq);
    /*
     * Payment Method (mandatory, always 'DD')
     * Specifies the means of payment that will be used to move the amount of money.
     */
    paymentInstructionInformation4.setPmtMtd(PaymentMethod2Code.DD);
    /*
     * Batch Booking (optional)
     * Identifies whether a single entry per individual transaction or a batch entry for the sum of the amounts of all transactions in the group is required.
     *
     * Usage : Recommended "true". If absent then default "true".
     *
     * 'true'  if : Identifies that a batch entry for the sum of the amounts of all
     *              transactions in a Payment Information Block is required.
     *              (one credit for all transactions in a Payment Information Block)
     * 'false' if : Identifies that a single entry for each of the transactions
     *              in a message is required.
     */
    paymentInstructionInformation4.setBtchBookg(true);
    /*
     * Number Of Transactions (optional)
     * Number of individual transactions contained in the message.
     */
    paymentInstructionInformation4.setNbOfTxs(Integer.toString(nbOfLines));
    /*
     * Control Sum (optional)
     * Total of all individual amounts included in the payment block, irrespective of currencies.
     *
     * Format : Max. 18 digits of which 2 for the fractional part.
     *          Decimal separator is "."
     */
    paymentInstructionInformation4.setCtrlSum(arithmeticTotal);
    /*
     * Payment Type Information (mandatory)
     * Set of elements that further specifies the type of transaction.
     */
    PaymentTypeInformation20 paymentTypeInformation20 = factory.createPaymentTypeInformation20();
    paymentInstructionInformation4.setPmtTpInf(paymentTypeInformation20);
    /*
     * ServiceLevel (mandatory)
     * Agreement under which or rules under which the transaction should be processed.
     */
    ServiceLevel8Choice serviceLevel8Choice = factory.createServiceLevel8Choice();
    paymentTypeInformation20.setSvcLvl(serviceLevel8Choice);
    /*
     * Code (mandatory, always 'SEPA')
     * Identification of a pre-agreed level of service between the parties in a coded form.
     */
    serviceLevel8Choice.setCd("SEPA");
    /*
     * Local Instrument (mandatory)
     * User community specific instrument.
     */
    LocalInstrument2Choice localInstrument2Choice = factory.createLocalInstrument2Choice();
    /*
     * Code (mandatory)
     *
     * Format : either 'CORE' or 'B2B'
     * Rule : The mixing of Core Direct Debits and Business-to-Business Direct Debits is not
     *        allowed in the same message.
     */
    switch(sepaType) {
        case SEPA_TYPE_CORE:
            localInstrument2Choice.setCd(SEPA_TYPE_CORE);
            break;
        case SEPA_TYPE_SBB:
            localInstrument2Choice.setCd(SEPA_TYPE_SBB);
            break;
        default:
            throw new AxelorException(TraceBackRepository.CATEGORY_CONFIGURATION_ERROR, I18n.get(IExceptionMessage.BANK_ORDER_FILE_UNKNOWN_SEPA_TYPE));
    }
    paymentTypeInformation20.setLclInstrm(localInstrument2Choice);
    /*
     * Sequence Type (mandatory) // TO CHECK
     * Identifies the direct debit sequence, e.g. first, recurrent, final or one-off.
     *
     * Either one of the following values.
     * CODE  Name       Definition
     * ------------------------------------------------------------------------------------
     * FRST  First      First collection of a series of direct debit instructions.
     * RCUR  Recurrent  Direct debit instruction where the debtor's authorisation is used for
     *                  regular direct debit transactions initiated by the creditor.
     * FNAL  Final      Final collection of a series of direct debit instructions.
     * OOFF  One Off    Direct debit instruction where the debtor's authorisation is used to
     *                  initiate one single direct debit transaction.
     */
    paymentTypeInformation20.setSeqTp(SequenceType1Code.FRST);
    /*
     * Category Purpose (optional)
     * Specifies the purpose of the payment based on a set of pre-defined categories.
     */
    // CategoryPurpose1Choice categoryPurpose1Choice = factory.createCategoryPurpose1Choice();
    // paymentTypeInformation20.setCtgyPurp(categoryPurpose1Choice);
    /*
     * Code (mandatory)
     * Specifies the underlying reason of the payment transaction.
     *
     * iso20022.org -> 'PaymentCategoryPurpose1Code' for all codes available and definitions.
     */
    // categoryPurpose1Choice.setCd("CASH");
    /*
     * Requested Collection Date (mandatory)
     * Date at which the creditor requests the amount of money to be collected from the debtor.
     *
     * Format : YYYY-MM-DD
     * Usage  : The minimum delay between sending date and requested collection date is depending
     *          on the type of direct debit (B2B or CORE) and on the sequence type (FRST, OOFF,
     *          RCUR, FNAL).
     */
    paymentInstructionInformation4.setReqdColltnDt(datatypeFactory.newXMLGregorianCalendar(bankOrderDate.format(DateTimeFormatter.ofPattern("yyyy-MM-dd"))));
    /*
     * Creditor (mandatory)
     * Party to which an amount of money is due.
     */
    paymentInstructionInformation4.setCdtr(creditor);
    /*
     * Creditor Account (mandatory)
     * Unambiguous identification of the account of the creditor to which a credit entry will be posted as a result of the payment transaction.
     */
    CashAccount16 cashAccount16 = factory.createCashAccount16();
    /*
     * IBAN (mandatory)
     */
    AccountIdentification4Choice accountIdentification4Choice = factory.createAccountIdentification4Choice();
    accountIdentification4Choice.setIBAN(senderBankDetails.getIban());
    cashAccount16.setId(accountIdentification4Choice);
    /*
     * Currency (optional)
     *
     * Rule : Currency of the account must be EUR. For usage of another currency, please
     *        contact your bank.
     */
    cashAccount16.setCcy(CURRENCY_CODE);
    paymentInstructionInformation4.setCdtrAcct(cashAccount16);
    /*
     * Creditor Agent (mandatory)
     * Financial institution servicing an account for the creditor.
     *
     * Note : The Bank Identifier Code (BIC) is composed of 8 or 11 characters, of which only the
     *        first 8 characters are significant.
     */
    FinancialInstitutionIdentification7 financialInstitutionIdentification7 = factory.createFinancialInstitutionIdentification7();
    // BIC
    fillBic(financialInstitutionIdentification7, senderBankDetails.getBank());
    BranchAndFinancialInstitutionIdentification4 branchAndFinancialInstitutionIdentification4 = factory.createBranchAndFinancialInstitutionIdentification4();
    branchAndFinancialInstitutionIdentification4.setFinInstnId(financialInstitutionIdentification7);
    paymentInstructionInformation4.setCdtrAgt(branchAndFinancialInstitutionIdentification4);
    /*
     * Ultimate Creditor (optional)
     * Ultimate party to which an amount of money is due. Ultimate Creditor is only to be used if different from Creditor.
     */
    // paymentInstructionInformation4.setUltmtCdtr();
    /*
     * Charge Bearer (mandatory) // TO CHECK
     * Specifies which party/parties will bear the charges associated with the processing of the payment transaction.
     *
     * CODE  Name                   Description
     * ----------------------------------------------------------------------------------------
     * DEBT  BorneByDebtor          All transaction charges are to be borne by the debtor
     * CRED  BorneByCreditor        All transaction charges are to be borne by the creditor
     * SHAR  Shared                 In a direct debit context, means that transaction charges on
     *                              the sender side are to be borne by the creditor, transaction
     *                              charges on the receiver side are to be borne by the debtor.
     * SLEV  FollowingServiceLevel  Charges are to be applied following the rules agreed in the
     *                              service level and/or scheme.
     */
    paymentInstructionInformation4.setChrgBr(ChargeBearerType1Code.SLEV);
    /*
     * Creditor Scheme Identification (optional)
     * Credit party that signs the Direct Debit mandate.
     */
    // paymentInstructionInformation4.setCdtrSchmeId(creditor);
    /*
     * Direct Debit Transaction Information, <DrctDbtTxInf> tag
     * Does not need to set the List<DirectDebitTransactionInformation1> to the paymentInstructionInformation2 object (see doc)
     */
    createDrctDbtTxInf(paymentInstructionInformation4.getDrctDbtTxInf(), creditor);
}
Also used : LocalInstrument2Choice(com.axelor.apps.bankpayment.xsd.sepa.pain_008_001_02.LocalInstrument2Choice) AxelorException(com.axelor.exception.AxelorException) DatatypeFactory(javax.xml.datatype.DatatypeFactory) PaymentInstructionInformation4(com.axelor.apps.bankpayment.xsd.sepa.pain_008_001_02.PaymentInstructionInformation4) BranchAndFinancialInstitutionIdentification4(com.axelor.apps.bankpayment.xsd.sepa.pain_008_001_02.BranchAndFinancialInstitutionIdentification4) CashAccount16(com.axelor.apps.bankpayment.xsd.sepa.pain_008_001_02.CashAccount16) PaymentTypeInformation20(com.axelor.apps.bankpayment.xsd.sepa.pain_008_001_02.PaymentTypeInformation20) ServiceLevel8Choice(com.axelor.apps.bankpayment.xsd.sepa.pain_008_001_02.ServiceLevel8Choice) FinancialInstitutionIdentification7(com.axelor.apps.bankpayment.xsd.sepa.pain_008_001_02.FinancialInstitutionIdentification7) AccountIdentification4Choice(com.axelor.apps.bankpayment.xsd.sepa.pain_008_001_02.AccountIdentification4Choice)

Aggregations

DatatypeFactory (javax.xml.datatype.DatatypeFactory)2 BankOrderLine (com.axelor.apps.bankpayment.db.BankOrderLine)1 AccountIdentification4Choice (com.axelor.apps.bankpayment.xsd.sepa.pain_001_001_03.AccountIdentification4Choice)1 ActiveOrHistoricCurrencyAndAmount (com.axelor.apps.bankpayment.xsd.sepa.pain_001_001_03.ActiveOrHistoricCurrencyAndAmount)1 AmountType3Choice (com.axelor.apps.bankpayment.xsd.sepa.pain_001_001_03.AmountType3Choice)1 BranchAndFinancialInstitutionIdentification4 (com.axelor.apps.bankpayment.xsd.sepa.pain_001_001_03.BranchAndFinancialInstitutionIdentification4)1 CashAccount16 (com.axelor.apps.bankpayment.xsd.sepa.pain_001_001_03.CashAccount16)1 CreditTransferTransactionInformation10 (com.axelor.apps.bankpayment.xsd.sepa.pain_001_001_03.CreditTransferTransactionInformation10)1 CustomerCreditTransferInitiationV03 (com.axelor.apps.bankpayment.xsd.sepa.pain_001_001_03.CustomerCreditTransferInitiationV03)1 Document (com.axelor.apps.bankpayment.xsd.sepa.pain_001_001_03.Document)1 FinancialInstitutionIdentification7 (com.axelor.apps.bankpayment.xsd.sepa.pain_001_001_03.FinancialInstitutionIdentification7)1 GroupHeader32 (com.axelor.apps.bankpayment.xsd.sepa.pain_001_001_03.GroupHeader32)1 ObjectFactory (com.axelor.apps.bankpayment.xsd.sepa.pain_001_001_03.ObjectFactory)1 PartyIdentification32 (com.axelor.apps.bankpayment.xsd.sepa.pain_001_001_03.PartyIdentification32)1 PaymentIdentification1 (com.axelor.apps.bankpayment.xsd.sepa.pain_001_001_03.PaymentIdentification1)1 PaymentInstructionInformation3 (com.axelor.apps.bankpayment.xsd.sepa.pain_001_001_03.PaymentInstructionInformation3)1 PaymentTypeInformation19 (com.axelor.apps.bankpayment.xsd.sepa.pain_001_001_03.PaymentTypeInformation19)1 RemittanceInformation5 (com.axelor.apps.bankpayment.xsd.sepa.pain_001_001_03.RemittanceInformation5)1 ServiceLevel8Choice (com.axelor.apps.bankpayment.xsd.sepa.pain_001_001_03.ServiceLevel8Choice)1 AccountIdentification4Choice (com.axelor.apps.bankpayment.xsd.sepa.pain_008_001_02.AccountIdentification4Choice)1