Search in sources :

Example 36 with Context

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);
    }
}
Also used : Context(com.axelor.rpc.Context) AppAccountService(com.axelor.apps.account.service.app.AppAccountService) PartnerService(com.axelor.apps.base.service.PartnerService) LoggerFactory(org.slf4j.LoggerFactory) PaymentCondition(com.axelor.apps.account.db.PaymentCondition) BankDetailsService(com.axelor.apps.base.service.BankDetailsService) Pair(org.apache.commons.lang3.tuple.Pair) ActionResponse(com.axelor.rpc.ActionResponse) Map(java.util.Map) InvoicePaymentCreateService(com.axelor.apps.account.service.payment.invoice.payment.InvoicePaymentCreateService) Function(com.google.common.base.Function) MethodHandles(java.lang.invoke.MethodHandles) Collection(java.util.Collection) Set(java.util.Set) InvoiceService(com.axelor.apps.account.service.invoice.InvoiceService) Collectors(java.util.stream.Collectors) Currency(com.axelor.apps.base.db.Currency) InvoiceToolService(com.axelor.apps.account.service.invoice.InvoiceToolService) List(java.util.List) ObjectUtils(com.axelor.common.ObjectUtils) PriceList(com.axelor.apps.base.db.PriceList) AccountingSituationService(com.axelor.apps.account.service.AccountingSituationService) Partner(com.axelor.apps.base.db.Partner) Joiner(com.google.common.base.Joiner) Singleton(com.google.inject.Singleton) Company(com.axelor.apps.base.db.Company) InvoicePrintService(com.axelor.apps.account.service.invoice.print.InvoicePrintService) LanguageRepository(com.axelor.apps.base.db.repo.LanguageRepository) ActionView(com.axelor.meta.schema.actions.ActionView) AddressService(com.axelor.apps.base.service.AddressService) PrintingSettings(com.axelor.apps.base.db.PrintingSettings) ArrayList(java.util.ArrayList) IExceptionMessage(com.axelor.apps.account.exception.IExceptionMessage) InvoicePayment(com.axelor.apps.account.db.InvoicePayment) AccountingSituation(com.axelor.apps.account.db.AccountingSituation) AxelorException(com.axelor.exception.AxelorException) IrrecoverableService(com.axelor.apps.account.service.IrrecoverableService) I18n(com.axelor.i18n.I18n) Wizard(com.axelor.apps.base.db.Wizard) ActionRequest(com.axelor.rpc.ActionRequest) ResponseMessageType(com.axelor.exception.ResponseMessageType) ActionViewBuilder(com.axelor.meta.schema.actions.ActionView.ActionViewBuilder) StringTool(com.axelor.apps.tool.StringTool) JPA(com.axelor.db.JPA) Logger(org.slf4j.Logger) TraceBackRepository(com.axelor.exception.db.repo.TraceBackRepository) PartnerPriceListService(com.axelor.apps.base.service.PartnerPriceListService) TraceBackService(com.axelor.exception.service.TraceBackService) PartnerRepository(com.axelor.apps.base.db.repo.PartnerRepository) Invoice(com.axelor.apps.account.db.Invoice) TradingNameService(com.axelor.apps.base.service.TradingNameService) InvoiceRepository(com.axelor.apps.account.db.repo.InvoiceRepository) Beans(com.axelor.inject.Beans) PaymentMode(com.axelor.apps.account.db.PaymentMode) BankDetails(com.axelor.apps.base.db.BankDetails) Context(com.axelor.rpc.Context) List(java.util.List) PriceList(com.axelor.apps.base.db.PriceList) ArrayList(java.util.ArrayList) ObjectUtils(com.axelor.common.ObjectUtils) InvoicePaymentCreateService(com.axelor.apps.account.service.payment.invoice.payment.InvoicePaymentCreateService) AxelorException(com.axelor.exception.AxelorException)

Example 37 with Context

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);
    }
}
Also used : Context(com.axelor.rpc.Context) InvoiceLine(com.axelor.apps.account.db.InvoiceLine) BigDecimal(java.math.BigDecimal) AxelorException(com.axelor.exception.AxelorException) TaxLine(com.axelor.apps.account.db.TaxLine)

Example 38 with Context

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);
}
Also used : Context(com.axelor.rpc.Context) Invoice(com.axelor.apps.account.db.Invoice) InvoiceLine(com.axelor.apps.account.db.InvoiceLine) InvoiceLineService(com.axelor.apps.account.service.invoice.InvoiceLineService) BigDecimal(java.math.BigDecimal)

Example 39 with Context

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());
    }
}
Also used : Context(com.axelor.rpc.Context) Invoice(com.axelor.apps.account.db.Invoice) InvoiceLine(com.axelor.apps.account.db.InvoiceLine) InvoiceLineService(com.axelor.apps.account.service.invoice.InvoiceLineService) AxelorException(com.axelor.exception.AxelorException)

Example 40 with Context

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);
    }
}
Also used : Context(com.axelor.rpc.Context) InvoiceLine(com.axelor.apps.account.db.InvoiceLine) BigDecimal(java.math.BigDecimal) AxelorException(com.axelor.exception.AxelorException) TaxLine(com.axelor.apps.account.db.TaxLine)

Aggregations

Context (com.axelor.rpc.Context)149 AxelorException (com.axelor.exception.AxelorException)52 BigDecimal (java.math.BigDecimal)37 Map (java.util.Map)37 HashMap (java.util.HashMap)26 ArrayList (java.util.ArrayList)23 SaleOrder (com.axelor.apps.sale.db.SaleOrder)19 List (java.util.List)18 SaleOrderLine (com.axelor.apps.sale.db.SaleOrderLine)17 Invoice (com.axelor.apps.account.db.Invoice)16 LinkedHashMap (java.util.LinkedHashMap)15 Product (com.axelor.apps.base.db.Product)14 Model (com.axelor.db.Model)13 StockMove (com.axelor.apps.stock.db.StockMove)12 StockMoveLine (com.axelor.apps.stock.db.StockMoveLine)12 InvoiceLine (com.axelor.apps.account.db.InvoiceLine)11 PurchaseOrder (com.axelor.apps.purchase.db.PurchaseOrder)11 LocalDate (java.time.LocalDate)11 Beans (com.axelor.inject.Beans)10 ActionRequest (com.axelor.rpc.ActionRequest)10