use of com.axelor.apps.supplychain.service.StockMoveMultiInvoiceService in project axelor-open-suite by axelor.
the class StockMoveInvoiceController method generateInvoiceConcatInStockMoveCheckMissingFields.
/**
* Called from mass invoicing out stock move form view. Call method to check for missing fields.
* If there are missing fields, show a wizard. Else call {@link
* StockMoveMultiInvoiceService#createInvoiceFromMultiOutgoingStockMove(List)} and show the
* generated invoice.
*
* @param request
* @param response
*/
public void generateInvoiceConcatInStockMoveCheckMissingFields(ActionRequest request, ActionResponse response) {
try {
List<StockMove> stockMoveList = new ArrayList<>();
List<Long> stockMoveIdList = new ArrayList<>();
List<Map> stockMoveMap = (List<Map>) request.getContext().get("supplierStockMoveToInvoice");
for (Map map : stockMoveMap) {
stockMoveIdList.add(Long.valueOf((Integer) map.get("id")));
}
for (Long stockMoveId : stockMoveIdList) {
stockMoveList.add(JPA.em().find(StockMove.class, stockMoveId));
}
Map<String, Object> mapResult = Beans.get(StockMoveMultiInvoiceService.class).areFieldsConflictedToGenerateSupplierInvoice(stockMoveList);
boolean paymentConditionToCheck = (Boolean) mapResult.getOrDefault("paymentConditionToCheck", false);
boolean paymentModeToCheck = (Boolean) mapResult.getOrDefault("paymentModeToCheck", false);
boolean contactPartnerToCheck = (Boolean) mapResult.getOrDefault("contactPartnerToCheck", false);
Partner partner = stockMoveList.get(0).getPartner();
if (paymentConditionToCheck || paymentModeToCheck || contactPartnerToCheck) {
ActionViewBuilder confirmView = ActionView.define("StockMove").model(StockMove.class.getName()).add("form", "stock-move-supplychain-concat-suppl-invoice-confirm-form").param("popup", "true").param("show-toolbar", "false").param("show-confirm", "false").param("popup-save", "false").param("forceEdit", "true");
if (paymentConditionToCheck) {
confirmView.context("contextPaymentConditionToCheck", "true");
} else {
confirmView.context("paymentCondition", mapResult.get("paymentCondition"));
}
if (paymentModeToCheck) {
confirmView.context("contextPaymentModeToCheck", "true");
} else {
confirmView.context("paymentMode", mapResult.get("paymentMode"));
}
if (contactPartnerToCheck) {
confirmView.context("contextContactPartnerToCheck", "true");
confirmView.context("contextPartnerId", partner.getId().toString());
} else {
confirmView.context("contactPartner", mapResult.get("contactPartner"));
}
confirmView.context("supplierStockMoveToInvoice", Joiner.on(",").join(stockMoveIdList));
response.setView(confirmView.map());
} else {
Optional<Invoice> invoice = Beans.get(StockMoveMultiInvoiceService.class).createInvoiceFromMultiIncomingStockMove(stockMoveList);
invoice.ifPresent(inv -> 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(inv.getId())).context("_operationTypeSelect", inv.getOperationTypeSelect()).context("todayDate", Beans.get(AppSupplychainService.class).getTodayDate(inv.getCompany())).map()));
}
} catch (Exception e) {
TraceBackService.trace(response, e);
}
}
use of com.axelor.apps.supplychain.service.StockMoveMultiInvoiceService in project axelor-open-suite by axelor.
the class StockMoveInvoiceController method generateInvoiceConcatInStockMove.
/**
* Called from mass invoicing in stock move confirm view. Get parameters entered by the user, then
* call {@link StockMoveMultiInvoiceService#createInvoiceFromMultiIncomingStockMove(List,
* PaymentCondition, PaymentMode, Partner)} and show the generated invoice.
*
* @param request
* @param response
*/
public void generateInvoiceConcatInStockMove(ActionRequest request, ActionResponse response) {
try {
List<StockMove> stockMoveList = new ArrayList<>();
String stockMoveListStr = (String) request.getContext().get("supplierStockMoveToInvoice");
for (String stockMoveId : stockMoveListStr.split(",")) {
stockMoveList.add(JPA.em().find(StockMove.class, new Long(stockMoveId)));
}
PaymentCondition paymentCondition = null;
PaymentMode paymentMode = null;
Partner contactPartner = null;
if (request.getContext().get("paymentCondition") != null) {
paymentCondition = JPA.em().find(PaymentCondition.class, Long.valueOf((Integer) ((Map) request.getContext().get("paymentCondition")).get("id")));
}
if (request.getContext().get("paymentMode") != null) {
paymentMode = JPA.em().find(PaymentMode.class, Long.valueOf((Integer) ((Map) request.getContext().get("paymentMode")).get("id")));
}
if (request.getContext().get("contactPartner") != null) {
contactPartner = JPA.em().find(Partner.class, Long.valueOf((Integer) ((Map) request.getContext().get("contactPartner")).get("id")));
}
Optional<Invoice> invoice = Beans.get(StockMoveMultiInvoiceService.class).createInvoiceFromMultiIncomingStockMove(stockMoveList, paymentCondition, paymentMode, contactPartner);
invoice.ifPresent(inv -> 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(inv.getId())).context("_operationTypeSelect", inv.getOperationTypeSelect()).context("todayDate", Beans.get(AppSupplychainService.class).getTodayDate(inv.getCompany())).map()));
response.setCanClose(true);
} catch (Exception e) {
TraceBackService.trace(response, e);
}
}
use of com.axelor.apps.supplychain.service.StockMoveMultiInvoiceService in project axelor-open-suite by axelor.
the class StockMoveInvoiceController method generateInvoiceConcatOutStockMoveCheckMissingFields.
/**
* Called from mass invoicing out stock move form view. Call method to check for missing fields.
* If there are missing fields, show a wizard. Else call {@link
* StockMoveMultiInvoiceService#createInvoiceFromMultiOutgoingStockMove(List)} and show the
* generated invoice.
*
* @param request
* @param response
*/
public void generateInvoiceConcatOutStockMoveCheckMissingFields(ActionRequest request, ActionResponse response) {
try {
List<StockMove> stockMoveList = new ArrayList<>();
List<Long> stockMoveIdList = new ArrayList<>();
// No confirmation popup, stock Moves are content in a parameter list
List<Map> stockMoveMap = (List<Map>) request.getContext().get("customerStockMoveToInvoice");
for (Map map : stockMoveMap) {
stockMoveIdList.add(Long.valueOf((Integer) map.get("id")));
}
for (Long stockMoveId : stockMoveIdList) {
stockMoveList.add(JPA.em().find(StockMove.class, stockMoveId));
}
Map<String, Object> mapResult = Beans.get(StockMoveMultiInvoiceService.class).areFieldsConflictedToGenerateCustInvoice(stockMoveList);
boolean paymentConditionToCheck = (Boolean) mapResult.getOrDefault("paymentConditionToCheck", false);
boolean paymentModeToCheck = (Boolean) mapResult.getOrDefault("paymentModeToCheck", false);
boolean contactPartnerToCheck = (Boolean) mapResult.getOrDefault("contactPartnerToCheck", false);
StockMove stockMove = stockMoveList.get(0);
Partner partner = stockMove.getPartner();
if (paymentConditionToCheck || paymentModeToCheck || contactPartnerToCheck) {
ActionViewBuilder confirmView = ActionView.define("StockMove").model(StockMove.class.getName()).add("form", "stock-move-supplychain-concat-cust-invoice-confirm-form").param("popup", "true").param("show-toolbar", "false").param("show-confirm", "false").param("popup-save", "false").param("forceEdit", "true");
if (paymentConditionToCheck) {
confirmView.context("contextPaymentConditionToCheck", "true");
} else {
confirmView.context("paymentCondition", mapResult.get("paymentCondition"));
}
if (paymentModeToCheck) {
confirmView.context("contextPaymentModeToCheck", "true");
} else {
confirmView.context("paymentMode", mapResult.get("paymentMode"));
}
if (contactPartnerToCheck) {
confirmView.context("contextContactPartnerToCheck", "true");
confirmView.context("contextPartnerId", partner.getId().toString());
} else {
confirmView.context("contactPartner", mapResult.get("contactPartner"));
}
confirmView.context("customerStockMoveToInvoice", Joiner.on(",").join(stockMoveIdList));
response.setView(confirmView.map());
} else {
Optional<Invoice> invoice = Beans.get(StockMoveMultiInvoiceService.class).createInvoiceFromMultiOutgoingStockMove(stockMoveList);
invoice.ifPresent(inv -> 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("_operationTypeSelect", inv.getOperationTypeSelect()).context("todayDate", Beans.get(AppSupplychainService.class).getTodayDate(stockMove.getCompany())).context("_showRecord", String.valueOf(inv.getId())).map()));
}
} catch (Exception e) {
TraceBackService.trace(response, e);
}
}
use of com.axelor.apps.supplychain.service.StockMoveMultiInvoiceService in project axelor-open-suite by axelor.
the class StockMoveInvoiceController method generateInvoiceConcatOutStockMove.
/**
* Called from mass invoicing in stock move confirm view. Get parameters entered by the user, then
* call {@link StockMoveMultiInvoiceService#createInvoiceFromMultiOutgoingStockMove(List,
* PaymentCondition, PaymentMode, Partner)} and show the generated invoice.
*
* @param request
* @param response
*/
public void generateInvoiceConcatOutStockMove(ActionRequest request, ActionResponse response) {
try {
List<StockMove> stockMoveList = new ArrayList<>();
String stockMoveListStr = (String) request.getContext().get("customerStockMoveToInvoice");
for (String stockMoveId : stockMoveListStr.split(",")) {
stockMoveList.add(JPA.em().find(StockMove.class, new Long(stockMoveId)));
}
// Check if paymentCondition, paymentMode or contactPartner are content in parameters
PaymentCondition paymentCondition = null;
PaymentMode paymentMode = null;
Partner contactPartner = null;
// paymentCondition, only for customer stockMove
if (request.getContext().get("paymentCondition") != null) {
paymentCondition = JPA.em().find(PaymentCondition.class, Long.valueOf((Integer) ((Map) request.getContext().get("paymentCondition")).get("id")));
}
// paymentMode, only for customer stockMove
if (request.getContext().get("paymentMode") != null) {
paymentMode = JPA.em().find(PaymentMode.class, Long.valueOf((Integer) ((Map) request.getContext().get("paymentMode")).get("id")));
}
if (request.getContext().get("contactPartner") != null) {
contactPartner = JPA.em().find(Partner.class, Long.valueOf((Integer) ((Map) request.getContext().get("contactPartner")).get("id")));
}
Optional<Invoice> invoice = Beans.get(StockMoveMultiInvoiceService.class).createInvoiceFromMultiOutgoingStockMove(stockMoveList, paymentCondition, paymentMode, contactPartner);
invoice.ifPresent(inv -> 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(inv.getId())).context("_operationTypeSelect", inv.getOperationTypeSelect()).context("todayDate", Beans.get(AppSupplychainService.class).getTodayDate(inv.getCompany())).map()));
response.setCanClose(true);
} catch (Exception e) {
TraceBackService.trace(response, e);
}
}
Aggregations