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);
}
}
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);
}
}
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());
}
}
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);
}
}
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);
}
Aggregations