use of com.axelor.apps.supplychain.service.SaleOrderInvoiceService in project axelor-open-suite by axelor.
the class SaleOrderController method changeWizardOperationDomain.
/**
* Called on sale order invoicing wizard form. Call {@link
* SaleOrderInvoiceService#getInvoicingWizardOperationDomain(SaleOrder)}
*
* @param request
* @param response
*/
public void changeWizardOperationDomain(ActionRequest request, ActionResponse response) {
SaleOrder saleOrder = request.getContext().asType(SaleOrder.class);
List<Integer> operationSelectValues = Beans.get(SaleOrderInvoiceService.class).getInvoicingWizardOperationDomain(saleOrder);
response.setAttr("operationSelect", "value", operationSelectValues.stream().min(Integer::compareTo).orElse(null));
response.setAttr("operationSelect", "selection-in", operationSelectValues);
}
use of com.axelor.apps.supplychain.service.SaleOrderInvoiceService in project axelor-open-suite by axelor.
the class BatchOrderInvoicingSale method process.
@Override
protected void process() {
SupplychainBatch supplychainBatch = batch.getSupplychainBatch();
List<String> filterList = new ArrayList<>();
Query<SaleOrder> query = Beans.get(SaleOrderRepository.class).all();
if (supplychainBatch.getCompany() != null) {
filterList.add("self.company = :company");
query.bind("company", supplychainBatch.getCompany());
}
if (supplychainBatch.getSalespersonOrBuyerSet() != null && !supplychainBatch.getSalespersonOrBuyerSet().isEmpty()) {
filterList.add("self.salespersonUser IN (:salespersonSet)");
query.bind("salespersonSet", supplychainBatch.getSalespersonOrBuyerSet());
}
if (supplychainBatch.getTeam() != null) {
filterList.add("self.team = :team " + "OR self.team IS NULL AND self.salespersonUser IS NOT NULL AND self.salespersonUser.activeTeam = :team");
query.bind("team", supplychainBatch.getTeam());
}
if (!Strings.isNullOrEmpty(supplychainBatch.getDeliveryOrReceiptState())) {
List<Integer> delivereyStateList = StringTool.getIntegerList(supplychainBatch.getDeliveryOrReceiptState());
filterList.add("self.deliveryState IN (:delivereyStateList)");
query.bind("delivereyStateList", delivereyStateList);
}
if (!Strings.isNullOrEmpty(supplychainBatch.getStatusSelect())) {
List<Integer> statusSelectList = StringTool.getIntegerList(supplychainBatch.getStatusSelect());
filterList.add("self.statusSelect IN (:statusSelectList)");
query.bind("statusSelectList", statusSelectList);
}
if (supplychainBatch.getOrderUpToDate() != null) {
filterList.add("self.orderDate <= :orderUpToDate");
query.bind("orderUpToDate", supplychainBatch.getOrderUpToDate());
}
filterList.add("self.amountInvoiced < self.exTaxTotal");
filterList.add("NOT EXISTS (SELECT 1 FROM Invoice invoice WHERE invoice.statusSelect != :invoiceStatusSelect " + "AND (invoice.saleOrder = self " + "OR invoice.saleOrder IS NULL AND EXISTS (SELECT 1 FROM invoice.invoiceLineList invoiceLine " + "WHERE invoiceLine.saleOrderLine MEMBER OF self.saleOrderLineList)))");
filterList.add("self.clientPartner.id NOT IN (" + Beans.get(BlockingService.class).listOfBlockedPartner(supplychainBatch.getCompany(), BlockingRepository.INVOICING_BLOCKING) + ")");
query.bind("invoiceStatusSelect", InvoiceRepository.STATUS_CANCELED);
List<Long> anomalyList = Lists.newArrayList(0L);
filterList.add("self.id NOT IN (:anomalyList)");
query.bind("anomalyList", anomalyList);
String filter = filterList.stream().map(item -> String.format("(%s)", item)).collect(Collectors.joining(" AND "));
query.filter(filter);
SaleOrderInvoiceService saleOrderInvoiceService = Beans.get(SaleOrderInvoiceService.class);
Set<Long> treatedSet = new HashSet<>();
for (List<SaleOrder> saleOrderList; !(saleOrderList = query.fetch(FETCH_LIMIT)).isEmpty(); JPA.clear()) {
for (SaleOrder saleOrder : saleOrderList) {
if (treatedSet.contains(saleOrder.getId())) {
throw new IllegalArgumentException("Invoice generation error");
}
treatedSet.add(saleOrder.getId());
try {
saleOrderInvoiceService.generateInvoice(saleOrder);
incrementDone();
} catch (Exception e) {
incrementAnomaly();
anomalyList.add(saleOrder.getId());
query.bind("anomalyList", anomalyList);
TraceBackService.trace(e, ExceptionOriginRepository.INVOICE_ORIGIN, batch.getId());
e.printStackTrace();
break;
}
}
}
}
use of com.axelor.apps.supplychain.service.SaleOrderInvoiceService in project axelor-open-suite by axelor.
the class SaleOrderController method generateInvoice.
/**
* Called from the sale order invoicing wizard. Call {@link
* com.axelor.apps.supplychain.service.SaleOrderInvoiceService#generateInvoice(SaleOrder, int,
* BigDecimal, boolean, Map)} } Return to the view the generated invoice.
*
* @param request
* @param response
*/
@SuppressWarnings(value = "unchecked")
public void generateInvoice(ActionRequest request, ActionResponse response) {
Context context = request.getContext();
try {
SaleOrder saleOrder = context.asType(SaleOrder.class);
int operationSelect = Integer.parseInt(context.get("operationSelect").toString());
boolean isPercent = (Boolean) context.getOrDefault("isPercent", false);
BigDecimal amountToInvoice = new BigDecimal(context.getOrDefault("amountToInvoice", "0").toString());
SaleOrderInvoiceService saleOrderInvoiceService = Beans.get(SaleOrderInvoiceService.class);
saleOrderInvoiceService.displayErrorMessageIfSaleOrderIsInvoiceable(saleOrder, amountToInvoice, isPercent);
Map<Long, BigDecimal> qtyToInvoiceMap = new HashMap<>();
List<Map<String, Object>> saleOrderLineListContext;
saleOrderLineListContext = (List<Map<String, Object>>) request.getRawContext().get("saleOrderLineList");
for (Map<String, Object> map : saleOrderLineListContext) {
if (map.get(SO_LINES_WIZARD_QTY_TO_INVOICE_FIELD) != null) {
BigDecimal qtyToInvoiceItem = new BigDecimal(map.get(SO_LINES_WIZARD_QTY_TO_INVOICE_FIELD).toString());
if (qtyToInvoiceItem.compareTo(BigDecimal.ZERO) != 0) {
Long soLineId = Long.valueOf((Integer) map.get("id"));
qtyToInvoiceMap.put(soLineId, qtyToInvoiceItem);
}
}
}
// Information to send to the service to handle an invoicing on timetables
List<Long> timetableIdList = new ArrayList<>();
ArrayList<LinkedHashMap<String, Object>> uninvoicedTimetablesList = (context.get("uninvoicedTimetablesList") != null) ? (ArrayList<LinkedHashMap<String, Object>>) context.get("uninvoicedTimetablesList") : null;
if (uninvoicedTimetablesList != null && !uninvoicedTimetablesList.isEmpty()) {
for (LinkedHashMap<String, Object> timetable : uninvoicedTimetablesList) {
if (timetable.get("toInvoice") != null && (boolean) timetable.get("toInvoice")) {
timetableIdList.add(Long.parseLong(timetable.get("id").toString()));
}
}
}
saleOrder = Beans.get(SaleOrderRepository.class).find(saleOrder.getId());
Invoice invoice = saleOrderInvoiceService.generateInvoice(saleOrder, operationSelect, amountToInvoice, isPercent, qtyToInvoiceMap, timetableIdList);
if (invoice != null) {
response.setCanClose(true);
response.setView(ActionView.define(I18n.get("Invoice generated")).model(Invoice.class.getName()).add("form", "invoice-form").add("grid", "invoice-grid").param("search-filters", "customer-invoices-filters").context("_showRecord", String.valueOf(invoice.getId())).context("_operationTypeSelect", InvoiceRepository.OPERATION_TYPE_CLIENT_SALE).context("todayDate", Beans.get(AppSupplychainService.class).getTodayDate(saleOrder.getCompany())).map());
}
} catch (Exception e) {
TraceBackService.trace(response, e);
}
}
Aggregations