use of com.axelor.apps.account.db.Invoice in project axelor-open-suite by axelor.
the class StockMoveInvoiceController method generateMultiSupplierInvoice.
@SuppressWarnings({ "rawtypes", "unchecked" })
public void generateMultiSupplierInvoice(ActionRequest request, ActionResponse response) {
try {
List<Map> stockMoveMap = (List<Map>) request.getContext().get("supplierStockMoveToInvoice");
List<Long> stockMoveIdList = new ArrayList<>();
List<StockMove> stockMoveList = new ArrayList<>();
for (Map map : stockMoveMap) {
stockMoveIdList.add(((Number) map.get("id")).longValue());
}
for (Long stockMoveId : stockMoveIdList) {
stockMoveList.add(JPA.em().find(StockMove.class, stockMoveId));
}
Beans.get(StockMoveMultiInvoiceService.class).checkForAlreadyInvoicedStockMove(stockMoveList);
Entry<List<Long>, String> result = Beans.get(StockMoveMultiInvoiceService.class).generateMultipleInvoices(stockMoveIdList);
List<Long> invoiceIdList = result.getKey();
String warningMessage = result.getValue();
if (!invoiceIdList.isEmpty()) {
ActionViewBuilder viewBuilder;
viewBuilder = ActionView.define("Suppl. Invoices");
viewBuilder.model(Invoice.class.getName()).add("grid", "invoice-grid").add("form", "invoice-form").param("search-filters", "customer-invoices-filters").domain("self.id IN (" + Joiner.on(",").join(invoiceIdList) + ")").context("_operationTypeSelect", InvoiceRepository.OPERATION_TYPE_SUPPLIER_PURCHASE).context("todayDate", Beans.get(AppSupplychainService.class).getTodayDate(Optional.ofNullable(AuthUtils.getUser()).map(User::getActiveCompany).orElse(null)));
response.setView(viewBuilder.map());
}
if (warningMessage != null && !warningMessage.isEmpty()) {
response.setFlash(warningMessage);
}
} catch (Exception e) {
TraceBackService.trace(response, e);
}
}
use of com.axelor.apps.account.db.Invoice in project axelor-open-suite by axelor.
the class StockMoveInvoiceController method openInvoicingWizard.
public void openInvoicingWizard(ActionRequest request, ActionResponse response) {
try {
response.setReload(true);
StockMove stockMove = request.getContext().asType(StockMove.class);
stockMove = Beans.get(StockMoveRepository.class).find(stockMove.getId());
StockMoveInvoiceService stockMoveInvoiceService = Beans.get(StockMoveInvoiceService.class);
List<Map<String, Object>> stockMoveLines = stockMoveInvoiceService.getStockMoveLinesToInvoice(stockMove);
Company company = stockMove.getCompany();
SupplyChainConfig supplyChainConfig = Beans.get(SupplyChainConfigService.class).getSupplyChainConfig(company);
boolean isPartialInvoicingActivated = (stockMove.getTypeSelect() == StockMoveRepository.TYPE_INCOMING && supplyChainConfig.getActivateIncStockMovePartialInvoicing()) || (stockMove.getTypeSelect() == StockMoveRepository.TYPE_OUTGOING && supplyChainConfig.getActivateOutStockMovePartialInvoicing());
if (isPartialInvoicingActivated && !stockMoveLines.isEmpty()) {
// open wizard view for partial invoicing
response.setView(ActionView.define(I18n.get(ITranslation.INVOICING)).model(StockMove.class.getName()).add("form", "stock-move-invoicing-wizard-form").param("popup", "reload").param("show-toolbar", "false").param("show-confirm", "false").param("width", "large").param("popup-save", "false").context("_id", stockMove.getId()).map());
} else if (!stockMoveLines.isEmpty()) {
// invoice everything if config is disabled.
Invoice invoice = stockMoveInvoiceService.createInvoice(stockMove, StockMoveRepository.INVOICE_ALL, null);
if (invoice != null) {
response.setView(ActionView.define(I18n.get(ITranslation.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())).context("_operationTypeSelect", invoice.getOperationTypeSelect()).context("todayDate", Beans.get(AppSupplychainService.class).getTodayDate(company)).map());
}
} else {
response.setAlert(I18n.get(IExceptionMessage.STOCK_MOVE_INVOICE_ERROR));
}
} catch (Exception e) {
TraceBackService.trace(response, e);
}
}
use of com.axelor.apps.account.db.Invoice in project axelor-open-suite by axelor.
the class PurchaseOrderInvoiceController method generateInvoice.
public void generateInvoice(ActionRequest request, ActionResponse response) {
PurchaseOrder purchaseOrder = request.getContext().asType(PurchaseOrder.class);
purchaseOrder = Beans.get(PurchaseOrderRepository.class).find(purchaseOrder.getId());
try {
Invoice invoice = Beans.get(PurchaseOrderInvoiceService.class).generateInvoice(purchaseOrder);
if (invoice != null) {
response.setReload(true);
response.setView(ActionView.define(I18n.get(IExceptionMessage.PO_INVOICE_2)).model(Invoice.class.getName()).add("form", "invoice-form").add("grid", "invoice-grid").param("search-filters", "customer-invoices-filters").domain("self.purchaseOrder.id = " + String.valueOf(invoice.getId())).domain("self.operationTypeSelect = " + String.valueOf(invoice.getOperationTypeSelect())).context("_operationTypeSelect", invoice.getOperationTypeSelect()).context("_showRecord", String.valueOf(invoice.getId())).map());
}
} catch (Exception e) {
TraceBackService.trace(response, e);
}
}
use of com.axelor.apps.account.db.Invoice in project axelor-open-suite by axelor.
the class BatchBankPaymentServiceImpl method createBankOrders.
@Transactional(rollbackOn = { Exception.class })
protected void createBankOrders(Batch batch, Collection<PaymentScheduleLine> paymentScheduleLines) throws AxelorException, JAXBException, IOException, DatatypeConfigurationException {
for (PaymentScheduleLine paymentScheduleLine : paymentScheduleLines) {
PaymentSchedule paymentSchedule = paymentScheduleLine.getPaymentSchedule();
MoveLine creditMoveLine = paymentScheduleLine.getAdvanceMoveLine();
for (Invoice invoice : paymentSchedule.getInvoiceSet()) {
MoveLine debitMoveLine = moveService.getMoveLineService().getDebitCustomerMoveLine(invoice);
Reconcile reconcile = reconcileRepo.findByMoveLines(debitMoveLine, creditMoveLine);
if (reconcile == null) {
continue;
}
createBankOrders(batch, reconcile);
}
}
}
use of com.axelor.apps.account.db.Invoice in project axelor-open-suite by axelor.
the class InvoicePaymentValidateServiceBankPayImpl method setInvoicePaymentStatus.
@Override
protected void setInvoicePaymentStatus(InvoicePayment invoicePayment) throws AxelorException {
Invoice invoice = invoicePayment.getInvoice();
PaymentMode paymentMode = invoicePayment.getPaymentMode();
if (paymentMode == null) {
throw new AxelorException(TraceBackRepository.CATEGORY_MISSING_FIELD, I18n.get(IExceptionMessage.INVOICE_PAYMENT_MODE_MISSING), invoice.getInvoiceId());
}
int typeSelect = paymentMode.getTypeSelect();
int inOutSelect = paymentMode.getInOutSelect();
if ((typeSelect == PaymentModeRepository.TYPE_DD && inOutSelect == PaymentModeRepository.IN) || (typeSelect == PaymentModeRepository.TYPE_TRANSFER && inOutSelect == PaymentModeRepository.OUT) && paymentMode.getGenerateBankOrder()) {
invoicePayment.setStatusSelect(InvoicePaymentRepository.STATUS_PENDING);
} else {
invoicePayment.setStatusSelect(InvoicePaymentRepository.STATUS_VALIDATED);
}
}
Aggregations