use of com.axelor.apps.bankpayment.db.BankOrder 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.bankpayment.db.BankOrder in project axelor-open-suite by axelor.
the class BankOrderCreateService method createBankOrder.
/**
* Créer un ordre bancaire avec tous les paramètres
*
* @param
* @return
* @throws AxelorException
*/
public BankOrder createBankOrder(PaymentMode paymentMode, Integer partnerType, LocalDate bankOrderDate, Company senderCompany, BankDetails senderBankDetails, Currency currency, String senderReference, String senderLabel, int technicalOriginSelect) throws AxelorException {
BankOrderFileFormat bankOrderFileFormat = paymentMode.getBankOrderFileFormat();
BankOrder bankOrder = new BankOrder();
bankOrder.setOrderTypeSelect(paymentMode.getOrderTypeSelect());
bankOrder.setPaymentMode(paymentMode);
bankOrder.setPartnerTypeSelect(partnerType);
if (!bankOrderFileFormat.getIsMultiDate()) {
bankOrder.setBankOrderDate(bankOrderDate);
}
bankOrder.setStatusSelect(BankOrderRepository.STATUS_DRAFT);
bankOrder.setRejectStatusSelect(BankOrderRepository.REJECT_STATUS_NOT_REJECTED);
bankOrder.setSenderCompany(senderCompany);
bankOrder.setSenderBankDetails(senderBankDetails);
EbicsUser signatoryEbicsUser = bankOrderService.getDefaultEbicsUserFromBankDetails(senderBankDetails);
User signatoryUser = null;
if (signatoryEbicsUser != null) {
signatoryUser = signatoryEbicsUser.getAssociatedUser();
bankOrder.setSignatoryEbicsUser(signatoryEbicsUser);
}
if (signatoryUser != null) {
bankOrder.setSignatoryUser(signatoryUser);
}
if (!bankOrderFileFormat.getIsMultiCurrency()) {
bankOrder.setBankOrderCurrency(currency);
}
bankOrder.setCompanyCurrency(senderCompany.getCurrency());
bankOrder.setSenderReference(senderReference);
bankOrder.setSenderLabel(senderLabel);
bankOrder.setBankOrderLineList(new ArrayList<BankOrderLine>());
bankOrder.setBankOrderFileFormat(bankOrderFileFormat);
bankOrder.setTechnicalOriginSelect(technicalOriginSelect);
return bankOrder;
}
use of com.axelor.apps.bankpayment.db.BankOrder 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.bankpayment.db.BankOrder in project axelor-open-suite by axelor.
the class BatchBankPaymentServiceImpl method createBankOrderFromMonthlyPaymentScheduleLines.
@Override
@Transactional(rollbackOn = { Exception.class })
public BankOrder createBankOrderFromMonthlyPaymentScheduleLines(Batch batch) throws AxelorException, JAXBException, IOException, DatatypeConfigurationException {
AccountingBatch accountingBatch = batch.getAccountingBatch();
LocalDate bankOrderDate = accountingBatch.getDueDate();
Company senderCompany = accountingBatch.getCompany();
BankDetails senderBankDetails = accountingBatch.getBankDetails();
if (senderBankDetails == null) {
senderBankDetails = accountingBatch.getCompany().getDefaultBankDetails();
}
PaymentMode paymentMode = accountingBatch.getPaymentMode();
Currency currency = senderCompany.getCurrency();
int partnerType = BankOrderRepository.PARTNER_TYPE_CUSTOMER;
String senderReference = "";
String senderLabel = "";
if (bankOrderDate == null) {
bankOrderDate = appBaseService.getTodayDate(senderCompany);
}
BankOrder bankOrder = bankOrderCreateService.createBankOrder(paymentMode, partnerType, bankOrderDate, senderCompany, senderBankDetails, currency, senderReference, senderLabel, BankOrderRepository.TECHNICAL_ORIGIN_AUTOMATIC);
bankOrder = JPA.save(bankOrder);
List<PaymentScheduleLine> paymentScheduleLineList;
int offset = 0;
try {
while (!(paymentScheduleLineList = fetchPaymentScheduleLineDoneList(batch, offset)).isEmpty()) {
bankOrder = bankOrderRepo.find(bankOrder.getId());
for (PaymentScheduleLine paymentScheduleLine : paymentScheduleLineList) {
PaymentSchedule paymentSchedule = paymentScheduleLine.getPaymentSchedule();
Partner partner = paymentSchedule.getPartner();
BankDetails bankDetails = paymentScheduleService.getBankDetails(paymentSchedule);
BigDecimal amount = paymentScheduleLine.getInTaxAmount();
String receiverReference = paymentScheduleLine.getName();
String receiverLabel = paymentScheduleLine.getDebitNumber();
BankOrderLine bankOrderLine = bankOrderLineService.createBankOrderLine(paymentMode.getBankOrderFileFormat(), null, partner, bankDetails, amount, currency, bankOrderDate, receiverReference, receiverLabel, paymentScheduleLine);
bankOrder.addBankOrderLineListItem(bankOrderLine);
}
bankOrder = JPA.save(bankOrder);
offset += paymentScheduleLineList.size();
JPA.clear();
}
} catch (Exception e) {
bankOrder = bankOrderRepo.find(bankOrder.getId());
bankOrderRepo.remove(bankOrder);
throw e;
}
bankOrder = bankOrderRepo.find(bankOrder.getId());
bankOrder = bankOrderRepo.save(bankOrder);
bankOrderService.confirm(bankOrder);
batch = batchRepo.find(batch.getId());
batch.setBankOrder(bankOrder);
return bankOrder;
}
use of com.axelor.apps.bankpayment.db.BankOrder in project axelor-open-suite by axelor.
the class BankOrderController method setBankDetailDomain.
public void setBankDetailDomain(ActionRequest request, ActionResponse response) {
BankOrder bankOrder = request.getContext().asType(BankOrder.class);
String domain = Beans.get(BankOrderService.class).createDomainForBankDetails(bankOrder);
// if nothing was found for the domain, we set it at a default value.
if (domain.equals("")) {
response.setAttr("senderBankDetails", "domain", "self.id IN (0)");
} else {
response.setAttr("senderBankDetails", "domain", domain);
}
}
Aggregations