Search in sources :

Example 71 with Context

use of com.axelor.rpc.Context in project axelor-open-suite by axelor.

the class InvoiceController method regenerateAndShowInvoice.

public void regenerateAndShowInvoice(ActionRequest request, ActionResponse response) {
    Context context = request.getContext();
    Invoice invoice = Beans.get(InvoiceRepository.class).find(Long.parseLong(context.get("id").toString()));
    Integer reportType = context.get("reportType") != null ? Integer.parseInt(context.get("reportType").toString()) : null;
    try {
        response.setCanClose(true);
        response.setView(ActionView.define(I18n.get("Invoice")).add("html", Beans.get(InvoicePrintService.class).printInvoice(invoice, true, "pdf", reportType, null)).map());
    } catch (Exception e) {
        TraceBackService.trace(response, e);
    }
}
Also used : Context(com.axelor.rpc.Context) Invoice(com.axelor.apps.account.db.Invoice) InvoiceRepository(com.axelor.apps.account.db.repo.InvoiceRepository) AxelorException(com.axelor.exception.AxelorException)

Example 72 with Context

use of com.axelor.rpc.Context in project axelor-open-suite by axelor.

the class InvoiceController method showInvoice.

/**
 * Method to generate invoice as a Pdf
 */
@SuppressWarnings("unchecked")
public void showInvoice(ActionRequest request, ActionResponse response) {
    Context context = request.getContext();
    String fileLink;
    String title;
    try {
        if (!ObjectUtils.isEmpty(request.getContext().get("_ids"))) {
            List<Long> ids = (List) (((List) context.get("_ids")).stream().filter(ObjectUtils::notEmpty).map(input -> Long.parseLong(input.toString())).collect(Collectors.toList()));
            fileLink = Beans.get(InvoicePrintService.class).printInvoices(ids);
            title = I18n.get("Invoices");
        } else if (context.get("id") != null) {
            String format = context.get("format") != null ? context.get("format").toString() : "pdf";
            Integer reportType = context.get("reportType") != null ? Integer.parseInt(context.get("reportType").toString()) : null;
            Map languageMap = reportType != null && (reportType == 1 || reportType == 3) && context.get("language") != null ? (Map<String, Object>) request.getContext().get("language") : null;
            String locale = languageMap != null && languageMap.get("id") != null ? Beans.get(LanguageRepository.class).find(Long.parseLong(languageMap.get("id").toString())).getCode() : null;
            fileLink = Beans.get(InvoicePrintService.class).printInvoice(Beans.get(InvoiceRepository.class).find(Long.parseLong(context.get("id").toString())), false, format, reportType, locale);
            title = I18n.get("Invoice");
        } else {
            throw new AxelorException(TraceBackRepository.CATEGORY_MISSING_FIELD, I18n.get(IExceptionMessage.INVOICE_3));
        }
        response.setView(ActionView.define(title).add("html", fileLink).map());
    } catch (Exception e) {
        TraceBackService.trace(response, e);
    }
}
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) AxelorException(com.axelor.exception.AxelorException) InvoicePrintService(com.axelor.apps.account.service.invoice.print.InvoicePrintService) List(java.util.List) PriceList(com.axelor.apps.base.db.PriceList) ArrayList(java.util.ArrayList) Map(java.util.Map) ObjectUtils(com.axelor.common.ObjectUtils) AxelorException(com.axelor.exception.AxelorException)

Example 73 with Context

use of com.axelor.rpc.Context in project axelor-open-suite by axelor.

the class InvoiceLineController method convertUnitPrice.

public void convertUnitPrice(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 || invoiceLine.getPrice() == null || invoiceLine.getInTaxPrice() == null) {
        return;
    }
    try {
        BigDecimal price = invoiceLine.getPrice();
        BigDecimal inTaxPrice = price.add(price.multiply(invoiceLine.getTaxLine().getValue()));
        response.setValue("inTaxPrice", inTaxPrice);
    } 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) BigDecimal(java.math.BigDecimal) AxelorException(com.axelor.exception.AxelorException)

Example 74 with Context

use of com.axelor.rpc.Context in project axelor-open-suite by axelor.

the class InvoiceLineController method filterAccount.

public void filterAccount(ActionRequest request, ActionResponse response) throws AxelorException {
    Context context = request.getContext();
    Invoice invoice = this.getInvoice(context);
    InvoiceLine invoiceLine = request.getContext().asType(InvoiceLine.class);
    if (invoice != null && invoice.getCompany() != null) {
        List<String> technicalTypeSelectList = new ArrayList<>();
        if (InvoiceToolService.isPurchase(invoice)) {
            if (invoiceLine.getFixedAssets()) {
                technicalTypeSelectList.add(AccountTypeRepository.TYPE_IMMOBILISATION);
            } else {
                technicalTypeSelectList.add(AccountTypeRepository.TYPE_DEBT);
                technicalTypeSelectList.add(AccountTypeRepository.TYPE_CHARGE);
            }
        } else {
            technicalTypeSelectList.add(AccountTypeRepository.TYPE_INCOME);
        }
        String domain = "self.company.id = " + invoice.getCompany().getId() + " AND self.accountType.technicalTypeSelect IN " + technicalTypeSelectList.stream().collect(Collectors.joining("','", "('", "')"));
        response.setAttr("account", "domain", domain);
    }
}
Also used : Context(com.axelor.rpc.Context) Invoice(com.axelor.apps.account.db.Invoice) InvoiceLine(com.axelor.apps.account.db.InvoiceLine) ArrayList(java.util.ArrayList)

Example 75 with Context

use of com.axelor.rpc.Context in project axelor-open-suite by axelor.

the class InvoiceLineController method getFixedAssetCategory.

public void getFixedAssetCategory(ActionRequest request, ActionResponse response) {
    Context context = request.getContext();
    InvoiceLine invoiceLine = context.asType(InvoiceLine.class);
    Invoice invoice = this.getInvoice(context);
    Product product = invoiceLine.getProduct();
    if (invoice == null || product == null) {
        return;
    }
    FixedAssetCategory fixedAssetCategory = null;
    if (!product.getAccountManagementList().isEmpty() && (invoice.getOperationTypeSelect() == InvoiceRepository.OPERATION_TYPE_SUPPLIER_PURCHASE || invoice.getOperationTypeSelect() == InvoiceRepository.OPERATION_TYPE_SUPPLIER_REFUND)) {
        Optional<AccountManagement> optionalFixedAssetCategory = product.getAccountManagementList().stream().filter(am -> invoice.getCompany().equals(am.getCompany())).findFirst();
        fixedAssetCategory = optionalFixedAssetCategory.isPresent() ? optionalFixedAssetCategory.get().getFixedAssetCategory() : null;
    }
    response.setValue("fixedAssetCategory", fixedAssetCategory);
}
Also used : Context(com.axelor.rpc.Context) FixedAssetCategory(com.axelor.apps.account.db.FixedAssetCategory) InvoiceLineService(com.axelor.apps.account.service.invoice.InvoiceLineService) AppAccountService(com.axelor.apps.account.service.app.AppAccountService) HashMap(java.util.HashMap) AccountManagementServiceAccountImpl(com.axelor.apps.account.service.AccountManagementServiceAccountImpl) Mapper(com.axelor.db.mapper.Mapper) ArrayList(java.util.ArrayList) Strings(com.google.common.base.Strings) BigDecimal(java.math.BigDecimal) AccountTypeRepository(com.axelor.apps.account.db.repo.AccountTypeRepository) AxelorException(com.axelor.exception.AxelorException) InvoiceLine(com.axelor.apps.account.db.InvoiceLine) TaxLine(com.axelor.apps.account.db.TaxLine) ActionResponse(com.axelor.rpc.ActionResponse) Map(java.util.Map) I18n(com.axelor.i18n.I18n) FixedAssetCategory(com.axelor.apps.account.db.FixedAssetCategory) ActionRequest(com.axelor.rpc.ActionRequest) AccountManagement(com.axelor.apps.account.db.AccountManagement) InvoiceLineManagement(com.axelor.apps.account.service.invoice.generator.line.InvoiceLineManagement) ITranslation(com.axelor.apps.account.translation.ITranslation) InvoiceLineRepository(com.axelor.apps.account.db.repo.InvoiceLineRepository) TraceBackService(com.axelor.exception.service.TraceBackService) Invoice(com.axelor.apps.account.db.Invoice) Collectors(java.util.stream.Collectors) Account(com.axelor.apps.account.db.Account) InvoiceToolService(com.axelor.apps.account.service.invoice.InvoiceToolService) List(java.util.List) InvoiceRepository(com.axelor.apps.account.db.repo.InvoiceRepository) Beans(com.axelor.inject.Beans) Product(com.axelor.apps.base.db.Product) Entry(java.util.Map.Entry) Optional(java.util.Optional) Context(com.axelor.rpc.Context) Singleton(com.google.inject.Singleton) Invoice(com.axelor.apps.account.db.Invoice) InvoiceLine(com.axelor.apps.account.db.InvoiceLine) Product(com.axelor.apps.base.db.Product) AccountManagement(com.axelor.apps.account.db.AccountManagement)

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