use of com.axelor.rpc.Context in project axelor-open-suite by axelor.
the class InvoiceController method massPaymentOnSupplierInvoices.
public void massPaymentOnSupplierInvoices(ActionRequest request, ActionResponse response) {
try {
Context context = request.getContext();
if (!ObjectUtils.isEmpty(context.get("_ids"))) {
List<Long> invoiceIdList = (List) (((List) context.get("_ids")).stream().filter(ObjectUtils::notEmpty).map(input -> Long.parseLong(input.toString())).collect(Collectors.toList()));
List<Long> invoiceToPay = Beans.get(InvoicePaymentCreateService.class).getInvoiceIdsToPay(invoiceIdList);
if (invoiceToPay.isEmpty()) {
response.setError(I18n.get(IExceptionMessage.INVOICE_NO_INVOICE_TO_PAY));
}
response.setView(ActionView.define(I18n.get("Register a mass payment")).model(InvoicePayment.class.getName()).add("form", "invoice-payment-mass-form").param("popup", "reload").param("show-toolbar", "false").param("show-confirm", "false").param("popup-save", "false").param("forceEdit", "true").context("_invoices", invoiceToPay).map());
}
} catch (Exception e) {
TraceBackService.trace(response, e, ResponseMessageType.ERROR);
}
}
use of com.axelor.rpc.Context in project axelor-open-suite by axelor.
the class InvoiceLineController method updatePrice.
/**
* Update the ex. tax unit price of an invoice line from its in. tax unit price.
*
* @param request
* @param response
*/
public void updatePrice(ActionRequest request, ActionResponse response) {
Context context = request.getContext();
InvoiceLine invoiceLine = context.asType(InvoiceLine.class);
try {
BigDecimal inTaxPrice = invoiceLine.getInTaxPrice();
TaxLine taxLine = invoiceLine.getTaxLine();
response.setValue("price", Beans.get(InvoiceLineService.class).convertUnitPrice(true, taxLine, inTaxPrice));
} catch (Exception e) {
TraceBackService.trace(response, e);
}
}
use of com.axelor.rpc.Context in project axelor-open-suite by axelor.
the class InvoiceLineController method compute.
public void compute(ActionRequest request, ActionResponse response) throws AxelorException {
Context context = request.getContext();
InvoiceLine invoiceLine = context.asType(InvoiceLine.class);
Invoice invoice = this.getInvoice(context);
if (invoice == null || invoiceLine.getPrice() == null || invoiceLine.getInTaxPrice() == null || invoiceLine.getQty() == null) {
return;
}
InvoiceLineService invoiceLineService = Beans.get(InvoiceLineService.class);
BigDecimal exTaxTotal;
BigDecimal companyExTaxTotal;
BigDecimal inTaxTotal;
BigDecimal companyInTaxTotal;
BigDecimal priceDiscounted = invoiceLineService.computeDiscount(invoiceLine, invoice.getInAti());
response.setValue("priceDiscounted", priceDiscounted);
response.setAttr("priceDiscounted", "hidden", priceDiscounted.compareTo(invoice.getInAti() ? invoiceLine.getInTaxPrice() : invoiceLine.getPrice()) == 0);
BigDecimal taxRate = BigDecimal.ZERO;
if (invoiceLine.getTaxLine() != null) {
taxRate = invoiceLine.getTaxLine().getValue();
response.setValue("taxRate", taxRate);
response.setValue("taxCode", invoiceLine.getTaxLine().getTax().getCode());
}
if (!invoice.getInAti()) {
exTaxTotal = InvoiceLineManagement.computeAmount(invoiceLine.getQty(), priceDiscounted);
inTaxTotal = exTaxTotal.add(exTaxTotal.multiply(taxRate));
} else {
inTaxTotal = InvoiceLineManagement.computeAmount(invoiceLine.getQty(), priceDiscounted);
exTaxTotal = inTaxTotal.divide(taxRate.add(BigDecimal.ONE), 2, BigDecimal.ROUND_HALF_UP);
}
companyExTaxTotal = invoiceLineService.getCompanyExTaxTotal(exTaxTotal, invoice);
companyInTaxTotal = invoiceLineService.getCompanyExTaxTotal(inTaxTotal, invoice);
response.setValue("exTaxTotal", exTaxTotal);
response.setValue("inTaxTotal", inTaxTotal);
response.setValue("companyInTaxTotal", companyInTaxTotal);
response.setValue("companyExTaxTotal", companyExTaxTotal);
}
use of com.axelor.rpc.Context in project axelor-open-suite by axelor.
the class InvoiceLineController method getDiscount.
public void getDiscount(ActionRequest request, ActionResponse response) {
Context context = request.getContext();
InvoiceLine invoiceLine = context.asType(InvoiceLine.class);
Invoice invoice = this.getInvoice(context);
if (invoice == null || invoiceLine.getProduct() == null) {
return;
}
try {
Map<String, Object> discounts = Beans.get(InvoiceLineService.class).getDiscount(invoice, invoiceLine, invoiceLine.getProduct().getInAti() ? Beans.get(InvoiceLineService.class).getInTaxUnitPrice(invoice, invoiceLine, invoiceLine.getTaxLine(), InvoiceToolService.isPurchase(invoice)) : Beans.get(InvoiceLineService.class).getExTaxUnitPrice(invoice, invoiceLine, invoiceLine.getTaxLine(), InvoiceToolService.isPurchase(invoice)));
for (Entry<String, Object> entry : discounts.entrySet()) {
response.setValue(entry.getKey(), entry.getValue());
}
} catch (Exception e) {
response.setFlash(e.getMessage());
}
}
use of com.axelor.rpc.Context in project axelor-open-suite by axelor.
the class InvoiceLineController method updateInTaxPrice.
/**
* Update the in. tax unit price of an invoice line from its ex. tax unit price.
*
* @param request
* @param response
*/
public void updateInTaxPrice(ActionRequest request, ActionResponse response) {
Context context = request.getContext();
InvoiceLine invoiceLine = context.asType(InvoiceLine.class);
try {
BigDecimal exTaxPrice = invoiceLine.getPrice();
TaxLine taxLine = invoiceLine.getTaxLine();
response.setValue("inTaxPrice", Beans.get(InvoiceLineService.class).convertUnitPrice(false, taxLine, exTaxPrice));
} catch (Exception e) {
TraceBackService.trace(response, e);
}
}
Aggregations