use of com.axelor.apps.account.db.PaymentMode in project axelor-open-suite by axelor.
the class StockMoveInvoiceController method generateInvoiceConcatOutStockMove.
/**
* Called from mass invoicing in stock move confirm view. Get parameters entered by the user, then
* call {@link StockMoveMultiInvoiceService#createInvoiceFromMultiOutgoingStockMove(List,
* PaymentCondition, PaymentMode, Partner)} and show the generated invoice.
*
* @param request
* @param response
*/
public void generateInvoiceConcatOutStockMove(ActionRequest request, ActionResponse response) {
try {
List<StockMove> stockMoveList = new ArrayList<>();
String stockMoveListStr = (String) request.getContext().get("customerStockMoveToInvoice");
for (String stockMoveId : stockMoveListStr.split(",")) {
stockMoveList.add(JPA.em().find(StockMove.class, new Long(stockMoveId)));
}
// Check if paymentCondition, paymentMode or contactPartner are content in parameters
PaymentCondition paymentCondition = null;
PaymentMode paymentMode = null;
Partner contactPartner = null;
// paymentCondition, only for customer stockMove
if (request.getContext().get("paymentCondition") != null) {
paymentCondition = JPA.em().find(PaymentCondition.class, Long.valueOf((Integer) ((Map) request.getContext().get("paymentCondition")).get("id")));
}
// paymentMode, only for customer stockMove
if (request.getContext().get("paymentMode") != null) {
paymentMode = JPA.em().find(PaymentMode.class, Long.valueOf((Integer) ((Map) request.getContext().get("paymentMode")).get("id")));
}
if (request.getContext().get("contactPartner") != null) {
contactPartner = JPA.em().find(Partner.class, Long.valueOf((Integer) ((Map) request.getContext().get("contactPartner")).get("id")));
}
Optional<Invoice> invoice = Beans.get(StockMoveMultiInvoiceService.class).createInvoiceFromMultiOutgoingStockMove(stockMoveList, paymentCondition, paymentMode, contactPartner);
invoice.ifPresent(inv -> response.setView(ActionView.define("Invoice").model(Invoice.class.getName()).add("grid", "invoice-grid").add("form", "invoice-form").param("search-filters", "customer-invoices-filters").param("forceEdit", "true").context("_showRecord", String.valueOf(inv.getId())).context("_operationTypeSelect", inv.getOperationTypeSelect()).context("todayDate", Beans.get(AppSupplychainService.class).getTodayDate(inv.getCompany())).map()));
response.setCanClose(true);
} catch (Exception e) {
TraceBackService.trace(response, e);
}
}
use of com.axelor.apps.account.db.PaymentMode in project axelor-open-suite by axelor.
the class PurchaseOrderController method fillCompanyBankDetails.
/**
* Called on partner, company or payment change. Fill the bank details with a default value.
*
* @param request
* @param response
*/
public void fillCompanyBankDetails(ActionRequest request, ActionResponse response) {
try {
PurchaseOrder purchaseOrder = request.getContext().asType(PurchaseOrder.class);
PaymentMode paymentMode = (PaymentMode) request.getContext().get("paymentMode");
Company company = purchaseOrder.getCompany();
Partner partner = purchaseOrder.getSupplierPartner();
if (company == null) {
return;
}
if (partner != null) {
partner = Beans.get(PartnerRepository.class).find(partner.getId());
}
BankDetails defaultBankDetails = Beans.get(BankDetailsService.class).getDefaultCompanyBankDetails(company, paymentMode, partner, null);
response.setValue("companyBankDetails", defaultBankDetails);
} catch (Exception e) {
TraceBackService.trace(response, e);
}
}
use of com.axelor.apps.account.db.PaymentMode 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.account.db.PaymentMode 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.account.db.PaymentMode in project axelor-open-suite by axelor.
the class BankOrderServiceImpl method sendFile.
protected void sendFile(BankOrder bankOrder, File dataFileToSend, File signatureFileToSend) throws AxelorException {
PaymentMode paymentMode = bankOrder.getPaymentMode();
if (paymentMode != null && !paymentMode.getAutomaticTransmission()) {
return;
}
EbicsUser signatoryEbicsUser = bankOrder.getSignatoryEbicsUser();
ebicsService.sendFULRequest(signatoryEbicsUser.getEbicsPartner().getTransportEbicsUser(), signatoryEbicsUser, null, dataFileToSend, bankOrder.getBankOrderFileFormat(), signatureFileToSend);
}
Aggregations