use of com.axelor.meta.schema.actions.ActionView.ActionViewBuilder in project axelor-open-suite by axelor.
the class BankOrderController method sign.
public void sign(ActionRequest request, ActionResponse response) throws AxelorException {
BankOrder bankOrder = request.getContext().asType(BankOrder.class);
bankOrder = Beans.get(BankOrderRepository.class).find(bankOrder.getId());
try {
ActionViewBuilder confirmView = ActionView.define("Sign bank order").model(BankOrder.class.getName()).add("form", "bank-order-sign-wizard-form").param("popup", "reload").param("show-toolbar", "false").param("show-confirm", "false").param("popup-save", "false").param("forceEdit", "true").context("_showRecord", bankOrder.getId());
response.setView(confirmView.map());
} catch (Exception e) {
TraceBackService.trace(response, e);
}
}
use of com.axelor.meta.schema.actions.ActionView.ActionViewBuilder in project axelor-open-suite by axelor.
the class PaymentScheduleLineController method showRejectWizard.
@SuppressWarnings("unchecked")
public void showRejectWizard(ActionRequest request, ActionResponse response) {
try {
List<? extends Number> idList;
Number id = (Number) request.getContext().get("id");
if (id != null) {
idList = Lists.newArrayList(id);
} else {
idList = MoreObjects.firstNonNull((List<? extends Number>) request.getContext().get("_ids"), Collections.emptyList());
}
if (idList.isEmpty()) {
response.setError(I18n.get(com.axelor.apps.base.exceptions.IExceptionMessage.RECORD_NONE_SELECTED));
return;
}
ActionViewBuilder view = ActionView.define(I18n.get("Payment schedule lines to reject")).model(Wizard.class.getName()).add("form", "payment-schedule-line-reject-wizard-form").param("popup", "reload").param("show-toolbar", Boolean.FALSE.toString()).param("show-confirm", Boolean.FALSE.toString()).param("popup-save", Boolean.FALSE.toString()).context("idList", idList);
response.setView(view.map());
} catch (Exception e) {
TraceBackService.trace(response, e);
}
}
use of com.axelor.meta.schema.actions.ActionView.ActionViewBuilder in project axelor-open-suite by axelor.
the class MenuBuilderController method showMenuBuilderRecords.
public void showMenuBuilderRecords(ActionRequest request, ActionResponse response) {
MenuBuilder menuBuilder = request.getContext().asType(MenuBuilder.class);
if (menuBuilder.getMetaMenu() == null || menuBuilder.getMetaMenu().getAction() == null) {
return;
}
try {
MetaAction metaAction = menuBuilder.getMetaMenu().getAction();
ObjectViews objectViews = XMLViews.fromXML(metaAction.getXml());
ActionView actionView = (ActionView) objectViews.getActions().get(0);
ActionViewBuilder actionViewBuilder = ActionView.define(I18n.get(actionView.getTitle()));
actionViewBuilder.model(actionView.getModel());
actionViewBuilder.icon(actionView.getIcon());
actionViewBuilder.domain(actionView.getDomain());
actionViewBuilder.context("jsonModel", menuBuilder.getActionBuilder().getModel());
actionView.getViews().forEach(view -> actionViewBuilder.add(view.getType(), view.getName()));
if (ObjectUtils.notEmpty(actionView.getParams())) {
actionView.getParams().forEach(param -> actionViewBuilder.param(param.getName(), param.getValue()));
}
response.setView(actionViewBuilder.map());
} catch (Exception e) {
}
}
use of com.axelor.meta.schema.actions.ActionView.ActionViewBuilder in project axelor-open-suite by axelor.
the class DeclarationOfExchangesController method export.
public void export(ActionRequest request, ActionResponse response) {
try {
DeclarationOfExchanges declarationOfExchanges = request.getContext().asType(DeclarationOfExchanges.class);
declarationOfExchanges = Beans.get(DeclarationOfExchangesRepository.class).find(declarationOfExchanges.getId());
Pair<Path, String> result = Beans.get(DeclarationOfExchangesService.class).export(declarationOfExchanges);
String fileLink = result.getLeft().toString();
String name = result.getRight();
ActionViewBuilder actionViewBuilder = ActionView.define(name).add("html", fileLink);
if (!"pdf".equalsIgnoreCase(declarationOfExchanges.getFormatSelect())) {
actionViewBuilder.param("download", "true");
}
response.setView(actionViewBuilder.map());
} catch (Exception e) {
TraceBackService.trace(response, e);
}
}
use of com.axelor.meta.schema.actions.ActionView.ActionViewBuilder in project axelor-open-suite by axelor.
the class InvoiceController method mergeInvoice.
// Generate single invoice from several
@SuppressWarnings({ "rawtypes", "unchecked" })
public void mergeInvoice(ActionRequest request, ActionResponse response) {
List<Invoice> invoiceList = new ArrayList<Invoice>();
List<Long> invoiceIdList = new ArrayList<Long>();
boolean fromPopup = false;
if (request.getContext().get("invoiceToMerge") != null) {
if (request.getContext().get("invoiceToMerge") instanceof List) {
// No confirmation popup, invoices are content in a parameter list
List<Map> invoiceMap = (List<Map>) request.getContext().get("invoiceToMerge");
for (Map map : invoiceMap) {
invoiceIdList.add(new Long((Integer) map.get("id")));
}
} else {
// After confirmation popup, invoice's id are in a string separated by ","
String invoiceIdListStr = (String) request.getContext().get("invoiceToMerge");
for (String invoiceId : invoiceIdListStr.split(",")) {
invoiceIdList.add(new Long(invoiceId));
}
fromPopup = true;
}
}
// Check if company, currency and partner are the same for all selected invoices
Company commonCompany = null;
Currency commonCurrency = null;
Partner commonPartner = null;
PaymentCondition commonPaymentCondition = null;
// Useful to determine if a difference exists between payment conditions of all invoices
boolean existPaymentConditionDiff = false;
Partner commonContactPartner = null;
// Useful to determine if a difference exists between contact partners of all purchase orders
boolean existContactPartnerDiff = false;
PriceList commonPriceList = null;
// Useful to determine if a difference exists between price lists of all purchase orders
boolean existPriceListDiff = false;
PaymentMode commonPaymentMode = null;
// Useful to determine if a difference exists between stock locations of all purchase orders
boolean existPaymentModeDiff = false;
SaleOrder commonSaleOrder = null;
// Useful to check if all sale orders are null (since this field is not required)
boolean saleOrderIsNull = false;
Invoice invoiceTemp;
int count = 1;
for (Long invoiceId : invoiceIdList) {
invoiceTemp = JPA.em().find(Invoice.class, invoiceId);
invoiceList.add(invoiceTemp);
if (count == 1) {
commonCompany = invoiceTemp.getCompany();
commonCurrency = invoiceTemp.getCurrency();
commonPartner = invoiceTemp.getPartner();
commonPaymentCondition = invoiceTemp.getPaymentCondition();
commonContactPartner = invoiceTemp.getContactPartner();
commonPriceList = invoiceTemp.getPriceList();
commonPaymentMode = invoiceTemp.getPaymentMode();
commonSaleOrder = invoiceTemp.getSaleOrder();
if (commonSaleOrder == null) {
saleOrderIsNull = true;
}
} else {
if (commonCompany != null && !commonCompany.equals(invoiceTemp.getCompany())) {
commonCompany = null;
}
if (commonCurrency != null && !commonCurrency.equals(invoiceTemp.getCurrency())) {
commonCurrency = null;
}
if (commonPartner != null && !commonPartner.equals(invoiceTemp.getPartner())) {
commonPartner = null;
}
if (commonPaymentCondition != null && !commonPaymentCondition.equals(invoiceTemp.getPaymentCondition())) {
commonPaymentCondition = null;
existPaymentConditionDiff = true;
}
if (commonContactPartner != null && !commonContactPartner.equals(invoiceTemp.getContactPartner())) {
commonContactPartner = null;
existContactPartnerDiff = true;
}
if (commonPriceList != null && !commonPriceList.equals(invoiceTemp.getPriceList())) {
commonPriceList = null;
existPriceListDiff = true;
}
if (commonPaymentMode != null && !commonPaymentMode.equals(invoiceTemp.getPaymentMode())) {
commonPaymentMode = null;
existPaymentModeDiff = true;
}
if (commonSaleOrder != null && !commonSaleOrder.equals(invoiceTemp.getSaleOrder())) {
commonSaleOrder = null;
}
if (invoiceTemp.getSaleOrder() != null) {
saleOrderIsNull = false;
}
}
count++;
}
StringBuilder fieldErrors = new StringBuilder();
if (commonCurrency == null) {
fieldErrors.append(I18n.get(IExceptionMessage.INVOICE_MERGE_ERROR_CURRENCY));
}
if (commonCompany == null) {
if (fieldErrors.length() > 0) {
fieldErrors.append("<br/>");
}
fieldErrors.append(I18n.get(IExceptionMessage.INVOICE_MERGE_ERROR_COMPANY));
}
if (commonPartner == null) {
if (fieldErrors.length() > 0) {
fieldErrors.append("<br/>");
}
fieldErrors.append(I18n.get(IExceptionMessage.INVOICE_MERGE_ERROR_PARTNER));
}
if (commonSaleOrder == null && saleOrderIsNull == false) {
if (fieldErrors.length() > 0) {
fieldErrors.append("<br/>");
}
fieldErrors.append(I18n.get(IExceptionMessage.INVOICE_MERGE_ERROR_SALEORDER));
}
if (fieldErrors.length() > 0) {
response.setFlash(fieldErrors.toString());
return;
}
// content in parameters
if (request.getContext().get("contactPartner") != null) {
commonContactPartner = JPA.em().find(Partner.class, new Long((Integer) ((Map) request.getContext().get("contactPartner")).get("id")));
}
if (request.getContext().get("priceList") != null) {
commonPriceList = JPA.em().find(PriceList.class, new Long((Integer) ((Map) request.getContext().get("priceList")).get("id")));
}
if (request.getContext().get("paymentMode") != null) {
commonPaymentMode = JPA.em().find(PaymentMode.class, new Long((Integer) ((Map) request.getContext().get("paymentMode")).get("id")));
}
if (request.getContext().get("paymentCondition") != null) {
commonPaymentCondition = JPA.em().find(PaymentCondition.class, new Long((Integer) ((Map) request.getContext().get("paymentCondition")).get("id")));
}
if (!fromPopup && (existPaymentConditionDiff || existContactPartnerDiff || existPriceListDiff || existPaymentModeDiff)) {
// Need to display intermediate screen to select some values
ActionViewBuilder confirmView = ActionView.define("Confirm merge invoice").model(Wizard.class.getName()).add("form", "customer-invoices-merge-confirm-form").param("popup", "true").param("show-toolbar", "false").param("show-confirm", "false").param("popup-save", "false").param("forceEdit", "true");
if (existContactPartnerDiff) {
confirmView.context("contextContactPartnerToCheck", "true");
confirmView.context("contextPartnerId", commonPartner.getId().toString());
}
if (existPriceListDiff) {
confirmView.context("contextPriceListToCheck", "true");
}
if (existPaymentModeDiff) {
confirmView.context("contextPaymentModeToCheck", "true");
}
if (existPaymentConditionDiff) {
confirmView.context("contextPaymentConditionToCheck", "true");
}
confirmView.context("invoiceToMerge", Joiner.on(",").join(invoiceIdList));
response.setView(confirmView.map());
return;
}
try {
Invoice invoice = Beans.get(SaleOrderInvoiceService.class).mergeInvoice(invoiceList, commonCompany, commonCurrency, commonPartner, commonContactPartner, commonPriceList, commonPaymentMode, commonPaymentCondition, commonSaleOrder);
if (invoice != null) {
// Open the generated invoice in a new tab
response.setView(ActionView.define("Invoice").model(Invoice.class.getName()).add("grid", "invoice-grid").add("form", "invoice-form").param("search-filters", "customer-invoices-filters").param("forceEdit", "true").context("_showRecord", String.valueOf(invoice.getId())).map());
response.setCanClose(true);
}
} catch (Exception e) {
response.setFlash(e.getLocalizedMessage());
}
}
Aggregations