use of com.axelor.apps.base.db.Currency 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.Currency in project axelor-open-suite by axelor.
the class BankOrderLineService method createDomainForBankDetails.
public String createDomainForBankDetails(BankOrderLine bankOrderLine, BankOrder bankOrder) {
String domain = "";
String bankDetailsIds = "";
if ((bankOrderLine == null) || (bankOrder == null)) {
return domain;
}
// the case where the bank order is for a company
if (bankOrder.getPartnerTypeSelect() == BankOrderRepository.PARTNER_TYPE_COMPANY) {
if (bankOrderLine.getReceiverCompany() != null) {
bankDetailsIds = StringTool.getIdListString(bankOrderLine.getReceiverCompany().getBankDetailsList());
if (bankOrderLine.getReceiverCompany().getDefaultBankDetails() != null) {
bankDetailsIds += bankDetailsIds.equals("") ? "" : ",";
bankDetailsIds += bankOrderLine.getReceiverCompany().getDefaultBankDetails().getId().toString();
}
}
} else // case where the bank order is for a partner
if (bankOrderLine.getPartner() != null) {
bankDetailsIds = StringTool.getIdListString(bankOrderLine.getPartner().getBankDetailsList());
}
if (bankDetailsIds.equals("")) {
return domain = "";
}
domain = "self.id IN(" + bankDetailsIds + ")";
// filter the result on active bank details
domain += " AND self.active = true";
// filter on the result from bankPartner if the option is active.
EbicsPartner ebicsPartner = Beans.get(EbicsPartnerRepository.class).all().filter("? MEMBER OF self.bankDetailsSet", bankOrder.getSenderBankDetails()).fetchOne();
if (ebicsPartnerIsFiltering(ebicsPartner, bankOrder.getOrderTypeSelect())) {
domain += " AND self.id IN (" + StringTool.getIdListString(ebicsPartner.getReceiverBankDetailsSet()) + ")";
}
// filter on the bank details identifier type from the bank order file format
if (bankOrder.getBankOrderFileFormat() != null) {
String acceptedIdentifiers = bankOrder.getBankOrderFileFormat().getBankDetailsTypeSelect();
if (acceptedIdentifiers != null && !acceptedIdentifiers.equals("")) {
domain += " AND self.bank.bankDetailsTypeSelect IN (" + acceptedIdentifiers + ")";
}
}
// filter on the currency if it is set in bank order and in the bankdetails
// and if the bankOrder is not multicurrency
// and if the partner type select is a company
Currency currency = bankOrder.getBankOrderCurrency();
if (!bankOrder.getIsMultiCurrency() && currency != null && bankOrder.getPartnerTypeSelect() == BankOrderRepository.PARTNER_TYPE_COMPANY) {
String fileFormatCurrencyId = currency.getId().toString();
domain += " AND (self.currency IS NULL OR self.currency.id = " + fileFormatCurrencyId + ")";
}
return domain;
}
use of com.axelor.apps.base.db.Currency 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.Currency in project axelor-open-suite by axelor.
the class BankOrderServiceImpl method createDomainForBankDetails.
@Override
public String createDomainForBankDetails(BankOrder bankOrder) {
String domain = Beans.get(BankDetailsService.class).getActiveCompanyBankDetails(bankOrder.getSenderCompany());
// format
if (bankOrder.getBankOrderFileFormat() != null) {
String acceptedIdentifiers = bankOrder.getBankOrderFileFormat().getBankDetailsTypeSelect();
if (acceptedIdentifiers != null && !acceptedIdentifiers.equals("")) {
domain += " AND self.bank.bankDetailsTypeSelect IN (" + acceptedIdentifiers + ")";
}
}
// filter on the currency if it is set in file format and in the bankdetails
Currency currency = bankOrder.getBankOrderCurrency();
if (currency != null && !bankOrder.getBankOrderFileFormat().getAllowOrderCurrDiffFromBankDetails()) {
String fileFormatCurrencyId = currency.getId().toString();
domain += " AND (self.currency IS NULL OR self.currency.id = " + fileFormatCurrencyId + ")";
}
return domain;
}
use of com.axelor.apps.base.db.Currency in project axelor-open-suite by axelor.
the class SopLineController method fillMrpForecast.
public void fillMrpForecast(ActionRequest request, ActionResponse response) {
Context context = request.getContext();
@SuppressWarnings("unchecked") LinkedHashMap<String, Object> productCategoryMap = (LinkedHashMap<String, Object>) context.get("_productCategory");
@SuppressWarnings("unchecked") LinkedHashMap<String, Object> sopLineMap = (LinkedHashMap<String, Object>) context.get("_sopLine");
@SuppressWarnings("unchecked") LinkedHashMap<String, Object> currencyMap = (LinkedHashMap<String, Object>) sopLineMap.get("currency");
BigDecimal sopSalesForecast = new BigDecimal(sopLineMap.get("sopSalesForecast").toString());
Long productCategoryId = Long.parseLong(productCategoryMap.get("id").toString());
Currency currency = currencyRepo.find(Long.parseLong(currencyMap.get("id").toString()));
BigDecimal totalForecast = BigDecimal.ZERO;
SortedSet<Map<String, Object>> mrpForecastSet = new TreeSet<Map<String, Object>>(Comparator.comparing(m -> (String) m.get("code")));
List<Product> productList = Beans.get(ProductRepository.class).all().filter("self.productCategory.id = ?1 ", productCategoryId).fetch();
if (productList != null) {
for (Product product : productList) {
Map<String, Object> map = new HashMap<String, Object>();
MrpForecast mrpForecast = mrpForecastRepo.all().filter("self.product.id = ?1 AND self.technicalOrigin = ?2", product.getId(), MrpForecastRepository.TECHNICAL_ORIGIN_CREATED_FROM_SOP).fetchOne();
if (mrpForecast != null) {
map = Mapper.toMap(mrpForecast);
BigDecimal totalPrice = mrpForecast.getQty().multiply(product.getSalePrice());
map.put("$totalPrice", totalPrice);
map.put("$unitPrice", product.getSalePrice());
map.put("code", product.getCode());
totalForecast = totalForecast.add(totalPrice);
mrpForecastSet.add(map);
continue;
}
map.put("product", product);
map.put("qty", BigDecimal.ZERO);
map.put("$totalPrice", BigDecimal.ZERO);
map.put("$unitPrice", product.getSalePrice());
map.put("code", product.getCode());
mrpForecastSet.add(map);
}
}
response.setValue("$mrpForecasts", mrpForecastSet);
response.setValue("$sopSalesForecast", sopSalesForecast);
response.setValue("$totalForecast", totalForecast);
response.setValue("$difference", sopSalesForecast.subtract(totalForecast).setScale(Beans.get(AppBaseService.class).getNbDecimalDigitForUnitPrice()));
response.setValue("$currency", currency);
}
Aggregations