use of com.axelor.apps.base.db.BankDetails 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();
}
use of com.axelor.apps.base.db.BankDetails in project axelor-open-suite by axelor.
the class BankOrderFileAFB320XCTService method createDependentReceiverBankRecord.
/**
* Method to create a dependent receiver bank record for international transfer AFB320
*
* @param bankOrderLine
* @return
* @throws AxelorException
*/
protected String createDependentReceiverBankRecord(BankOrderLine bankOrderLine) throws AxelorException {
try {
BankDetails receiverBankDetails = bankOrderLine.getReceiverBankDetails();
Bank bank = receiverBankDetails.getBank();
// Zone 1 : Code enregistrement
String totalRecord = cfonbToolService.createZone("1", "05", cfonbToolService.STATUS_MANDATORY, cfonbToolService.FORMAT_NUMERIC, 2);
// Zone 2 : Code opération
totalRecord += cfonbToolService.createZone("2", OPERATION_CODE_PI, cfonbToolService.STATUS_MANDATORY, cfonbToolService.FORMAT_ALPHA_NUMERIC, 2);
// Zone 3 : Numéro séquentiel
totalRecord += cfonbToolService.createZone("3", sequence++, cfonbToolService.STATUS_MANDATORY, cfonbToolService.FORMAT_NUMERIC, 6);
// Zone 4 : Nom de la banque du bénéficiaire (A ne renseigner que si le code BIC de la banque
// du bénéficiaire est absent.
// Si cette zone est renseignée ainsi que le code BIC, elle est ignorée par la banque sauf en
// cas d'anomalie sur le code BIC.)
totalRecord += cfonbToolService.createZone(I18n.get("4 - Bank name"), bank.getBankName(), cfonbToolService.STATUS_DEPENDENT, cfonbToolService.FORMAT_ALPHA_NUMERIC, 35);
// Zone 5 : Localisation de l'agence (Si le nom de la banque contient plus de 35 caractères,
// utiliser le début de la première zone
// pour le compléter et le reste de cette zone pour indiquer le début de l'adresse)
String bankAddress = "";
if (bank.getBankName() != null && bank.getBankName().length() > 35) {
bankAddress = bank.getBankName().substring(35) + " ";
}
if (receiverBankDetails.getBankAddress() != null) {
bankAddress += receiverBankDetails.getBankAddress().getAddress();
}
totalRecord += cfonbToolService.createZone(I18n.get("5 - Bank address"), bankAddress, cfonbToolService.STATUS_DEPENDENT, cfonbToolService.FORMAT_ALPHA_NUMERIC, 3 * 35);
// Zone 6 : Code BIC de la banque du bénéficiaire (Si ce code est renseigné, c'est lui qui est
// utilisé pour identifier la banque du bénéficiaire.
// C'est cette option qui est préconisée pour identifier la banque du bénéficiaire. )
totalRecord += cfonbToolService.createZone(I18n.get("6 - Bank code"), bank.getCode(), cfonbToolService.STATUS_OPTIONAL, cfonbToolService.FORMAT_ALPHA_NUMERIC, 11);
// Zone 7 : Code pays de la banque du bénéficiaire (Norme ISO.)
String countryCode = "";
if (bank.getCountry() != null) {
countryCode = bank.getCountry().getAlpha2Code();
}
totalRecord += cfonbToolService.createZone(I18n.get("7 - Country code"), countryCode, cfonbToolService.STATUS_OPTIONAL, cfonbToolService.FORMAT_ALPHA_NUMERIC, 2);
// Zone 8 : Zone réservée
totalRecord += cfonbToolService.createZone("8", "", cfonbToolService.STATUS_NOT_USED, cfonbToolService.FORMAT_ALPHA_NUMERIC, 157);
cfonbToolService.toUpperCase(totalRecord);
cfonbToolService.testLength(totalRecord, NB_CHAR_PER_LINE);
return totalRecord;
} catch (Exception e) {
throw new AxelorException(e.getCause(), bankOrderLine, TraceBackRepository.CATEGORY_MISSING_FIELD, I18n.get(IExceptionMessage.BANK_ORDER_WRONG_BENEFICIARY_BANK_DETAIL_RECORD) + ": " + e.getMessage(), bankOrderLine.getSequence());
}
}
use of com.axelor.apps.base.db.BankDetails in project axelor-open-suite by axelor.
the class BankReconciliationCreateService method createAllFromBankStatement.
@Transactional(rollbackOn = { Exception.class })
public List<BankReconciliation> createAllFromBankStatement(BankStatement bankStatement) throws IOException {
List<BankReconciliation> bankReconciliationList = new ArrayList<>();
List<BankDetails> bankDetailsList = getDistinctBankDetails(bankStatement);
if (bankDetailsList == null) {
return bankReconciliationList;
}
LocalDate fromDate = bankStatement.getFromDate();
LocalDate toDate = bankStatement.getToDate();
for (BankDetails bankDetails : bankDetailsList) {
Company company = companyRepository.all().filter("?1 member of self.bankDetailsList", bankDetails).fetchOne();
Currency currency = bankDetails.getCurrency();
if (currency == null) {
currency = company.getCurrency();
}
BankReconciliation bankReconciliation = createBankReconciliation(company, fromDate, toDate, currency, bankDetails, bankStatement);
bankReconciliationRepository.save(bankReconciliation);
bankReconciliationList.add(bankReconciliation);
}
return bankReconciliationList;
}
use of com.axelor.apps.base.db.BankDetails in project axelor-open-suite by axelor.
the class BankReconciliationService method getAccountManagementCashAccounts.
protected Set<String> getAccountManagementCashAccounts(BankReconciliation bankReconciliation) {
List<AccountManagement> accountManagementList;
Journal journal = bankReconciliation.getJournal();
Set<String> cashAccountIdSet = new HashSet<String>();
BankDetails bankDetails = bankReconciliation.getBankDetails();
if (journal != null) {
accountManagementList = accountManagementRepository.all().filter("self.bankDetails = ?1 AND self.journal = ?2", bankDetails, journal).fetch();
} else {
accountManagementList = accountManagementRepository.all().filter("self.bankDetails = ?1", bankDetails).fetch();
}
for (AccountManagement accountManagement : accountManagementList) {
if (accountManagement.getCashAccount() != null) {
cashAccountIdSet.add(accountManagement.getCashAccount().getId().toString());
}
}
return cashAccountIdSet;
}
use of com.axelor.apps.base.db.BankDetails in project axelor-open-suite by axelor.
the class BankOrderMoveServiceImpl method generateReceiverMove.
protected Move generateReceiverMove(BankOrderLine bankOrderLine) throws AxelorException {
Partner partner = bankOrderLine.getPartner();
Company receiverCompany = bankOrderLine.getReceiverCompany();
BankDetails receiverBankDetails = bankOrderLine.getReceiverBankDetails();
Journal receiverJournal = paymentModeService.getPaymentModeJournal(paymentMode, receiverCompany, receiverBankDetails);
Account receiverBankAccount = paymentModeService.getPaymentModeAccount(paymentMode, receiverCompany, receiverBankDetails);
Move receiverMove = moveService.getMoveCreateService().createMove(receiverJournal, receiverCompany, this.getCurrency(bankOrderLine), partner, this.getDate(bankOrderLine), paymentMode, MoveRepository.TECHNICAL_ORIGIN_AUTOMATIC, MoveRepository.FUNCTIONAL_ORIGIN_PAYMENT);
MoveLine bankMoveLine = moveService.getMoveLineService().createMoveLine(receiverMove, partner, receiverBankAccount, bankOrderLine.getBankOrderAmount(), isDebit, receiverMove.getDate(), 1, bankOrderLine.getReceiverReference(), bankOrderLine.getReceiverLabel());
receiverMove.addMoveLineListItem(bankMoveLine);
MoveLine partnerMoveLine = moveService.getMoveLineService().createMoveLine(receiverMove, partner, getPartnerAccount(partner, receiverCompany, receiverMove.getCompany()), bankOrderLine.getBankOrderAmount(), !isDebit, receiverMove.getDate(), 2, bankOrderLine.getReceiverReference(), bankOrderLine.getReceiverLabel());
receiverMove.addMoveLineListItem(partnerMoveLine);
return receiverMove;
}
Aggregations