use of com.axelor.apps.base.db.BankDetails in project axelor-open-suite by axelor.
the class BankOrderFileAFB160Service method createOptionalFurtherInformationRecord.
/**
* Method to create an optional further information record for national transfer AFB160
*
* @param bankOrderLine
* @return
* @throws AxelorException
*/
protected String createOptionalFurtherInformationRecord(BankOrderLine bankOrderLine) throws AxelorException {
try {
BankDetails receiverBankDetails = bankOrderLine.getReceiverBankDetails();
// Zone A : Code enregistrement
String totalRecord = cfonbToolService.createZone("A", "07", cfonbToolService.STATUS_MANDATORY, cfonbToolService.FORMAT_NUMERIC, 2);
// Zone B1 : Code opération
totalRecord += cfonbToolService.createZone("B1", getB1Area(), cfonbToolService.STATUS_MANDATORY, cfonbToolService.FORMAT_ALPHA_NUMERIC, 2);
// Zone B2 : Zone réservée
totalRecord += cfonbToolService.createZone("B2", "", cfonbToolService.STATUS_NOT_USED, cfonbToolService.FORMAT_ALPHA_NUMERIC, 8);
// Zone B3 : Numéro d'émetteur ou d'identification pour le virement particulier code 22
// (Virement APL)
totalRecord += cfonbToolService.createZone("B3", getB3Area(), cfonbToolService.STATUS_DEPENDENT, cfonbToolService.FORMAT_ALPHA_NUMERIC, 6);
// Zone C1 : Référence
totalRecord += cfonbToolService.createZone(I18n.get("C1 - Sequence"), bankOrderLine.getSequence(), cfonbToolService.STATUS_MANDATORY, cfonbToolService.FORMAT_ALPHA_NUMERIC, 12);
// Zone C2 : Nom/Raison sociale du bénéficiaire
totalRecord += cfonbToolService.createZone(I18n.get("C2 - Receiver company name"), bankOrderLine.getReceiverCompany().getName(), cfonbToolService.STATUS_MANDATORY, cfonbToolService.FORMAT_ALPHA_NUMERIC, 24);
// Zone D1 : Domiciliation
if (bankOrderLine.getReceiverBankDetails().getBankAddress() == null) {
throw new AxelorException(TraceBackRepository.CATEGORY_MISSING_FIELD, I18n.get(IExceptionMessage.BANK_ORDER_RECEIVER_BANK_DETAILS_MISSING_BANK_ADDRESS));
}
totalRecord += cfonbToolService.createZone(I18n.get("D1 - Bank address"), receiverBankDetails.getBankAddress().getAddress(), cfonbToolService.STATUS_DEPENDENT, cfonbToolService.FORMAT_ALPHA_NUMERIC, 24);
// Zone D2 : Zone réservée
totalRecord += cfonbToolService.createZone("D2", "", cfonbToolService.STATUS_NOT_USED, cfonbToolService.FORMAT_ALPHA_NUMERIC, 8);
// Zone D3 : Code guichet de la banque qui tient le compte du bénéficiaire
totalRecord += cfonbToolService.createZone(I18n.get("D3 - Sort code"), receiverBankDetails.getSortCode(), cfonbToolService.STATUS_MANDATORY, cfonbToolService.FORMAT_NUMERIC, 5);
// Zone D4 : Numéro de compte du bénéficiaire
totalRecord += cfonbToolService.createZone(I18n.get("D4 - Account number"), receiverBankDetails.getAccountNbr(), cfonbToolService.STATUS_MANDATORY, cfonbToolService.FORMAT_ALPHA_NUMERIC, 11);
// Zone E : Montant du virement
totalRecord += cfonbToolService.createZone(I18n.get("E - Bank order amount"), bankOrderLine.getBankOrderAmount(), cfonbToolService.STATUS_MANDATORY, cfonbToolService.FORMAT_NUMERIC, 16);
// Zone F : Libellé complémentaire
totalRecord += cfonbToolService.createZone(I18n.get("F - Receiver label"), bankOrderLine.getPaymentReasonLine1(), cfonbToolService.STATUS_MANDATORY, cfonbToolService.FORMAT_ALPHA_NUMERIC, 31);
// Zone G1 : Code établissement de la banque qui tient le compte du bénéficiaire
totalRecord += cfonbToolService.createZone(I18n.get("G1 - Bank establisment code"), receiverBankDetails.getBankCode(), cfonbToolService.STATUS_MANDATORY, cfonbToolService.FORMAT_NUMERIC, 5);
// Zone G2 : Zone réservée
totalRecord += cfonbToolService.createZone("G2", "", cfonbToolService.STATUS_NOT_USED, cfonbToolService.FORMAT_ALPHA_NUMERIC, 6);
cfonbToolService.toUpperCase(totalRecord);
cfonbToolService.testLength(totalRecord, NB_CHAR_PER_LINE);
return totalRecord;
} catch (Exception e) {
throw new AxelorException(e, bankOrderLine, TraceBackRepository.CATEGORY_MISSING_FIELD, I18n.get(IExceptionMessage.BANK_ORDER_WRONG_FURTHER_INFORMATION_DETAIL_RECORD) + ": " + e.getMessage(), bankOrderLine.getSequence());
}
}
use of com.axelor.apps.base.db.BankDetails in project axelor-open-suite by axelor.
the class BankOrderFileAFB320XCTService method createDetailRecord.
/**
* Method to create a recipient record for international transfer AFB320
*
* @param bankOrderLine
* @return
* @throws AxelorException
*/
protected String createDetailRecord(BankOrderLine bankOrderLine) throws AxelorException {
try {
BankDetails receiverBankDetails = bankOrderLine.getReceiverBankDetails();
// Zone 1 : Code enregistrement
String detailRecord = cfonbToolService.createZone("1", "04", cfonbToolService.STATUS_MANDATORY, cfonbToolService.FORMAT_NUMERIC, 2);
// Zone 2 : Code opération
detailRecord += cfonbToolService.createZone("2", OPERATION_CODE_PI, cfonbToolService.STATUS_MANDATORY, cfonbToolService.FORMAT_ALPHA_NUMERIC, 2);
// Zone 3 : Numéro séquentiel
detailRecord += cfonbToolService.createZone("3", sequence++, cfonbToolService.STATUS_MANDATORY, cfonbToolService.FORMAT_NUMERIC, 6);
// national, "0" : Autre )
if (receiverBankDetails.getBank() == null) {
throw new AxelorException(TraceBackRepository.CATEGORY_MISSING_FIELD, I18n.get(IExceptionMessage.BANK_ORDER_RECEIVER_BANK_DETAILS_MISSING_BANK));
}
detailRecord += cfonbToolService.createZone(I18n.get("4 - Bank details type"), receiverBankDetails.getBank().getBankDetailsTypeSelect(), cfonbToolService.STATUS_DEPENDENT, cfonbToolService.FORMAT_ALPHA_NUMERIC, 1);
// Zone 5 : Identifiant du compte du bénéficiaire
detailRecord += cfonbToolService.createZone(I18n.get("5 - Bank details IBAN"), getIban(receiverBankDetails), cfonbToolService.STATUS_DEPENDENT, cfonbToolService.FORMAT_ALPHA_NUMERIC, 34);
// Zone 6 et 7 attribution des longueurs des zones en fonction de la longueur du nom:
int ownerNameLength = receiverBankDetails.getOwnerName().length();
int adressLength = 3 * 35;
if (ownerNameLength <= 35) {
ownerNameLength = 35;
} else if (35 < ownerNameLength && ownerNameLength <= 70) {
adressLength = 3 * 35 - (ownerNameLength - 35);
} else if (ownerNameLength > 70) {
ownerNameLength = 2 * 35;
adressLength = 2 * 35;
}
// Zone 6 : Nom du bénéficiaire
detailRecord += cfonbToolService.createZone(I18n.get("6 - Bank details owner name"), receiverBankDetails.getOwnerName(), cfonbToolService.STATUS_MANDATORY, cfonbToolService.FORMAT_ALPHA_NUMERIC, ownerNameLength);
// Zone 7 : Adresse du bénéficiaire (Obligatoire si mode de règlement par chèque (zone 18 =
// "1" ou "2")
// Si le nom du bénéficiaire 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)
detailRecord += cfonbToolService.createZone("7", getReceiverAddress(bankOrderLine), cfonbToolService.STATUS_DEPENDENT, cfonbToolService.FORMAT_ALPHA_NUMERIC, adressLength);
// Zone 8 : Identification nationale du bénéficiaire (Cette zone n'est pas utilisée)
detailRecord += cfonbToolService.createZone("8", "", cfonbToolService.STATUS_OPTIONAL, cfonbToolService.FORMAT_ALPHA_NUMERIC, 17);
// Zone 9 : Code pays du bénéficiaire (Norme ISO)
Country receiverCountry = bankOrderLine.getReceiverCountry();
String countryCode = "";
if (receiverCountry != null) {
countryCode = receiverCountry.getAlpha2Code();
}
detailRecord += cfonbToolService.createZone(I18n.get("9 - Country code"), countryCode, cfonbToolService.STATUS_MANDATORY, cfonbToolService.FORMAT_ALPHA_NUMERIC, 2);
// Zone 10 : Référence de l'opération
detailRecord += cfonbToolService.createZone(I18n.get("10 - Sequence"), bankOrderLine.getSequence(), cfonbToolService.STATUS_MANDATORY, cfonbToolService.FORMAT_ALPHA_NUMERIC, 16);
// Zone 11 : Qualifiant du montant de l'ordre :
// "T" : Montant exprimé dans la devise du transfert
// "D" : Montant équivalent exprimé dans la devise du compte à débiter. Cette valeur ne doit
// être utilisée que lorsque la devise du compte à débiter est différente de celle du
// transfert.
String qualifyngOfAmountStr;
if (senderCurrency.equals(bankOrderCurrency)) {
qualifyngOfAmountStr = BankOrderFileFormatRepository.QUALIFYING_AMOUNT_TRANSFER_CURRENCY;
} else {
qualifyngOfAmountStr = qualityOfAmount;
if (Strings.isNullOrEmpty(qualifyngOfAmountStr)) {
qualifyngOfAmountStr = BankOrderFileFormatRepository.QUALIFYING_AMOUNT_TRANSFER_CURRENCY;
}
}
detailRecord += cfonbToolService.createZone("11", qualifyngOfAmountStr, cfonbToolService.STATUS_MANDATORY, cfonbToolService.FORMAT_ALPHA_NUMERIC, 1);
// Zone 12 : Zone réservée
detailRecord += cfonbToolService.createZone("12", "", cfonbToolService.STATUS_NOT_USED, cfonbToolService.FORMAT_ALPHA_NUMERIC, 4);
// Zone 13 : Montant de l'ordre (Le montant comporte le nombre de décimales indiqué dans la
// zone "Nombre de décimales" du même enregistrement)
BigDecimal orderAmount;
if (qualifyngOfAmountStr.equals(BankOrderFileFormatRepository.QUALIFYING_AMOUNT_SENDER_BANK_DETAILS_CURRENCY)) {
orderAmount = bankOrderLine.getCompanyCurrencyAmount();
} else {
orderAmount = bankOrderLine.getBankOrderAmount();
}
detailRecord += cfonbToolService.createZone("13", orderAmount, cfonbToolService.STATUS_MANDATORY, cfonbToolService.FORMAT_NUMERIC, 14);
// Zone 14 : Nombre de décimales
detailRecord += cfonbToolService.createZone("14", "2", cfonbToolService.STATUS_MANDATORY, cfonbToolService.FORMAT_NUMERIC, // TODO
1);
// Zone 15 : Zone réservée
detailRecord += cfonbToolService.createZone("15", "", cfonbToolService.STATUS_NOT_USED, cfonbToolService.FORMAT_ALPHA_NUMERIC, 1);
// Zone 16 : Code motif économique (3 caract. numériques ou valeur "NNN" )
BankOrderEconomicReason bankOrderEconomicReason = bankOrderLine.getBankOrderEconomicReason();
String bankOrderEconomicReasonCode = "NNN";
if (bankOrderEconomicReason != null) {
bankOrderEconomicReasonCode = bankOrderEconomicReason.getCode();
}
detailRecord += cfonbToolService.createZone(I18n.get("16 - Economic reason code"), bankOrderEconomicReasonCode, cfonbToolService.STATUS_OPTIONAL, cfonbToolService.FORMAT_ALPHA_NUMERIC, 3);
// Zone 17 : Zone réservée
detailRecord += cfonbToolService.createZone("17", "", cfonbToolService.STATUS_NOT_USED, cfonbToolService.FORMAT_ALPHA_NUMERIC, 2);
// Zone 18 : Mode de règlement ("0" = Virement ou autre sauf chèque, "1" ou "2" = par chèque)
detailRecord += cfonbToolService.createZone(I18n.get("18 - Payment mode select"), bankOrderLine.getPaymentModeSelect(), cfonbToolService.STATUS_MANDATORY, cfonbToolService.FORMAT_ALPHA_NUMERIC, 1);
// Zone 19 : Code imputation des frais ("13" = Bénéficiaire (BEN), "14" = Emetteur et
// Bénéficiaire (SHA), "15" = Emetteur (OUR))
detailRecord += cfonbToolService.createZone(I18n.get("19 - Fees imputation mode"), bankOrderLine.getFeesImputationModeSelect(), cfonbToolService.STATUS_MANDATORY, cfonbToolService.FORMAT_NUMERIC, 2);
// Zone 23 : Zone réservée
detailRecord += cfonbToolService.createZone("23", "", cfonbToolService.STATUS_NOT_USED, cfonbToolService.FORMAT_ALPHA_NUMERIC, 57);
// Zone 24-1 : Qualifiant de la date ("203" (date d'exécution demandée))
detailRecord += cfonbToolService.createZone(I18n.get("24-1 - Qualifying of date"), bankOrderFileFormat.getQualifyingOfDate(), cfonbToolService.STATUS_OPTIONAL, cfonbToolService.FORMAT_ALPHA_NUMERIC, 3);
// l'"Entête" = "3" ou "4"), pour les autres remises, elle ne doit pas être renseignée.)
if (isMultiDates) {
String bankOrderDate = "";
if (bankOrderLine.getBankOrderDate() != null) {
bankOrderDate = bankOrderLine.getBankOrderDate().format(DateTimeFormatter.ofPattern("yyyyMMdd"));
}
detailRecord += cfonbToolService.createZone(I18n.get("24-2 - Date"), bankOrderDate, cfonbToolService.STATUS_MANDATORY, cfonbToolService.FORMAT_NUMERIC, 8);
} else {
detailRecord += cfonbToolService.createZone(I18n.get("24-2 - Date"), "", cfonbToolService.STATUS_NOT_USED, cfonbToolService.FORMAT_NUMERIC, 8);
}
// renseignée.
if (isMultiCurrencies) {
String bankOrderCurrencyCode = "";
if (bankOrderLine.getBankOrderCurrency() != null) {
bankOrderCurrencyCode = bankOrderLine.getBankOrderCurrency().getCode();
}
detailRecord += cfonbToolService.createZone(I18n.get("25 - Currency"), bankOrderCurrencyCode, cfonbToolService.STATUS_MANDATORY, cfonbToolService.FORMAT_ALPHA_NUMERIC, 3);
} else {
detailRecord += cfonbToolService.createZone(I18n.get("25 - Currency"), "", cfonbToolService.STATUS_NOT_USED, cfonbToolService.FORMAT_ALPHA_NUMERIC, 3);
}
cfonbToolService.toUpperCase(detailRecord);
cfonbToolService.testLength(detailRecord, NB_CHAR_PER_LINE);
return detailRecord;
} catch (Exception e) {
throw new AxelorException(e, bankOrderLine, TraceBackRepository.CATEGORY_MISSING_FIELD, I18n.get(IExceptionMessage.BANK_ORDER_WRONG_MAIN_DETAIL_RECORD) + ": " + e.getMessage(), bankOrderLine.getSequence());
}
}
use of com.axelor.apps.base.db.BankDetails in project axelor-open-suite by axelor.
the class BankOrderCreateService method createBankOrder.
/**
* Method to create a bank order for an invoice Payment
*
* @param invoicePayment An invoice payment
* @throws AxelorException
*/
public BankOrder createBankOrder(InvoicePayment invoicePayment) throws AxelorException {
Invoice invoice = invoicePayment.getInvoice();
Company company = invoice.getCompany();
PaymentMode paymentMode = invoicePayment.getPaymentMode();
Partner partner = invoice.getPartner();
BigDecimal amount = invoicePayment.getAmount();
Currency currency = invoicePayment.getCurrency();
LocalDate paymentDate = invoicePayment.getPaymentDate();
BankDetails companyBankDetails = invoicePayment.getCompanyBankDetails() != null ? invoicePayment.getCompanyBankDetails() : this.getSenderBankDetails(invoice);
String reference = InvoiceToolService.isPurchase(invoice) ? invoice.getSupplierInvoiceNb() : invoice.getInvoiceId();
BankOrder bankOrder = this.createBankOrder(paymentMode, this.getBankOrderPartnerType(invoice), paymentDate, company, companyBankDetails, currency, reference, null, BankOrderRepository.TECHNICAL_ORIGIN_AUTOMATIC);
BankDetails receiverBankDetails = invoiceService.getBankDetails(invoice);
BankOrderLine bankOrderLine = bankOrderLineService.createBankOrderLine(paymentMode.getBankOrderFileFormat(), null, partner, receiverBankDetails, amount, currency, paymentDate, reference, null, invoice);
bankOrder.addBankOrderLineListItem(bankOrderLine);
bankOrder = bankOrderRepo.save(bankOrder);
return bankOrder;
}
use of com.axelor.apps.base.db.BankDetails in project axelor-open-suite by axelor.
the class BankOrderMergeServiceImpl method checkSameElements.
protected void checkSameElements(Collection<BankOrder> bankOrders) throws AxelorException {
BankOrder refBankOrder = bankOrders.iterator().next();
int refStatusSelect = refBankOrder.getStatusSelect();
int orderTypeSelect = refBankOrder.getOrderTypeSelect();
PaymentMode refPaymentMode = refBankOrder.getPaymentMode();
int refPartnerTypeSelect = refBankOrder.getPartnerTypeSelect();
Company refSenderCompany = refBankOrder.getSenderCompany();
BankDetails refSenderBankDetails = refBankOrder.getSenderBankDetails();
Currency refCurrency = refBankOrder.getBankOrderCurrency();
boolean isMultiCurrency = refBankOrder.getIsMultiCurrency();
for (BankOrder bankOrder : bankOrders) {
int statusSelect = bankOrder.getStatusSelect();
if (statusSelect != BankOrderRepository.STATUS_DRAFT && statusSelect != BankOrderRepository.STATUS_AWAITING_SIGNATURE) {
throw new AxelorException(bankOrder, TraceBackRepository.CATEGORY_INCONSISTENCY, I18n.get(IExceptionMessage.BANK_ORDER_MERGE_STATUS));
}
if (statusSelect != refStatusSelect) {
throw new AxelorException(bankOrder, TraceBackRepository.CATEGORY_INCONSISTENCY, I18n.get(IExceptionMessage.BANK_ORDER_MERGE_SAME_STATUS));
}
if (!bankOrder.getOrderTypeSelect().equals(orderTypeSelect)) {
throw new AxelorException(bankOrder, TraceBackRepository.CATEGORY_INCONSISTENCY, I18n.get(IExceptionMessage.BANK_ORDER_MERGE_SAME_ORDER_TYPE_SELECT));
}
if (!bankOrder.getPaymentMode().equals(refPaymentMode)) {
throw new AxelorException(bankOrder, TraceBackRepository.CATEGORY_INCONSISTENCY, I18n.get(IExceptionMessage.BANK_ORDER_MERGE_SAME_PAYMENT_MODE));
}
if (!bankOrder.getPartnerTypeSelect().equals(refPartnerTypeSelect)) {
throw new AxelorException(bankOrder, TraceBackRepository.CATEGORY_INCONSISTENCY, I18n.get(IExceptionMessage.BANK_ORDER_MERGE_SAME_PARTNER_TYPE_SELECT));
}
if (!bankOrder.getSenderCompany().equals(refSenderCompany)) {
throw new AxelorException(bankOrder, TraceBackRepository.CATEGORY_INCONSISTENCY, I18n.get(IExceptionMessage.BANK_ORDER_MERGE_SAME_SENDER_COMPANY));
}
if (bankOrder.getSenderBankDetails() == null && refSenderBankDetails != null || (bankOrder.getSenderBankDetails() != null && !bankOrder.getSenderBankDetails().equals(refSenderBankDetails))) {
throw new AxelorException(bankOrder, TraceBackRepository.CATEGORY_INCONSISTENCY, I18n.get(IExceptionMessage.BANK_ORDER_MERGE_SAME_SENDER_BANK_DETAILS));
}
if (bankOrder.getIsMultiCurrency() != isMultiCurrency || !bankOrder.getIsMultiCurrency() && !bankOrder.getBankOrderCurrency().equals(refCurrency)) {
throw new AxelorException(bankOrder, TraceBackRepository.CATEGORY_INCONSISTENCY, I18n.get(IExceptionMessage.BANK_ORDER_MERGE_SAME_CURRENCY));
}
}
}
use of com.axelor.apps.base.db.BankDetails in project axelor-open-suite by axelor.
the class BankOrderServiceImpl method getDefaultBankDetails.
@Override
public BankDetails getDefaultBankDetails(BankOrder bankOrder) {
BankDetails candidateBankDetails;
if (bankOrder.getSenderCompany() == null) {
return null;
}
candidateBankDetails = bankOrder.getSenderCompany().getDefaultBankDetails();
try {
this.checkBankDetails(candidateBankDetails, bankOrder);
} catch (AxelorException e) {
return null;
}
return candidateBankDetails;
}
Aggregations