use of com.axelor.apps.account.db.Invoice in project axelor-open-suite by axelor.
the class SaleOrderInvoiceServiceImpl method generateAdvancePayment.
@Override
@Transactional(rollbackOn = { Exception.class })
public Invoice generateAdvancePayment(SaleOrder saleOrder, BigDecimal amountToInvoice, boolean isPercent) throws AxelorException {
List<SaleOrderLineTax> taxLineList = saleOrder.getSaleOrderLineTaxList();
AccountConfigService accountConfigService = Beans.get(AccountConfigService.class);
BigDecimal percentToInvoice = computeAmountToInvoicePercent(saleOrder, amountToInvoice, isPercent);
Product invoicingProduct = accountConfigService.getAccountConfig(saleOrder.getCompany()).getAdvancePaymentProduct();
Account advancePaymentAccount = accountConfigService.getAccountConfig(saleOrder.getCompany()).getAdvancePaymentAccount();
if (invoicingProduct == null) {
throw new AxelorException(saleOrder, TraceBackRepository.CATEGORY_CONFIGURATION_ERROR, I18n.get(IExceptionMessage.SO_INVOICE_MISSING_ADVANCE_PAYMENT_PRODUCT));
}
if (advancePaymentAccount == null) {
throw new AxelorException(saleOrder, TraceBackRepository.CATEGORY_CONFIGURATION_ERROR, I18n.get(IExceptionMessage.SO_INVOICE_MISSING_ADVANCE_PAYMENT_ACCOUNT), saleOrder.getCompany().getName());
}
Invoice invoice = createInvoiceAndLines(saleOrder, taxLineList, invoicingProduct, percentToInvoice, InvoiceRepository.OPERATION_SUB_TYPE_ADVANCE, advancePaymentAccount);
// no need for link to sale order lines for an advance payment
if (invoice.getInvoiceLineList() != null) {
invoice.getInvoiceLineList().forEach(invoiceLine -> invoiceLine.setSaleOrderLine(null));
}
return invoiceRepo.save(invoice);
}
use of com.axelor.apps.account.db.Invoice in project axelor-open-suite by axelor.
the class SaleOrderInvoiceServiceImpl method generateInvoice.
@Override
@Transactional(rollbackOn = { Exception.class })
public Invoice generateInvoice(SaleOrder saleOrder, List<SaleOrderLine> saleOrderLinesSelected) throws AxelorException {
Invoice invoice = this.createInvoice(saleOrder, saleOrderLinesSelected);
invoiceRepo.save(invoice);
saleOrderRepo.save(fillSaleOrder(saleOrder, invoice));
return invoice;
}
use of com.axelor.apps.account.db.Invoice in project axelor-open-suite by axelor.
the class SaleOrderInvoiceServiceImpl method getInvoicingWizardOperationDomain.
@Override
public List<Integer> getInvoicingWizardOperationDomain(SaleOrder saleOrder) {
boolean manageAdvanceInvoice = Beans.get(AppAccountService.class).getAppAccount().getManageAdvancePaymentInvoice();
boolean allowTimetableInvoicing = Beans.get(AppSupplychainService.class).getAppSupplychain().getAllowTimetableInvoicing();
BigDecimal amountInvoiced = saleOrder.getAmountInvoiced();
BigDecimal exTaxTotal = saleOrder.getExTaxTotal();
Invoice invoice = Query.of(Invoice.class).filter(" self.saleOrder.id = :saleOrderId " + "AND self.statusSelect != :invoiceStatus " + "AND self.operationSubTypeSelect != :advancePaymentSubType").bind("saleOrderId", saleOrder.getId()).bind("invoiceStatus", InvoiceRepository.STATUS_CANCELED).bind("advancePaymentSubType", InvoiceRepository.OPERATION_SUB_TYPE_ADVANCE).fetchOne();
List<Integer> operationSelectList = new ArrayList<>();
if (exTaxTotal.compareTo(BigDecimal.ZERO) != 0) {
operationSelectList.add(SaleOrderRepository.INVOICE_LINES);
}
if (manageAdvanceInvoice && exTaxTotal.compareTo(BigDecimal.ZERO) != 0) {
operationSelectList.add(SaleOrderRepository.INVOICE_ADVANCE_PAYMENT);
}
if (allowTimetableInvoicing) {
operationSelectList.add(SaleOrderRepository.INVOICE_TIMETABLES);
}
if (invoice == null && amountInvoiced.compareTo(BigDecimal.ZERO) == 0 || exTaxTotal.compareTo(BigDecimal.ZERO) == 0) {
operationSelectList.add(SaleOrderRepository.INVOICE_ALL);
}
return operationSelectList;
}
use of com.axelor.apps.account.db.Invoice in project axelor-open-suite by axelor.
the class SaleOrderInvoiceServiceImpl method displayErrorMessageBtnGenerateInvoice.
@Override
public void displayErrorMessageBtnGenerateInvoice(SaleOrder saleOrder) throws AxelorException {
List<Invoice> invoices = Query.of(Invoice.class).filter(" self.saleOrder.id = :saleOrderId AND self.operationSubTypeSelect = :operationSubTypeSelect" + " AND self.statusSelect != :invoiceStatus").bind("saleOrderId", saleOrder.getId()).bind("operationSubTypeSelect", InvoiceRepository.OPERATION_SUB_TYPE_DEFAULT).bind("invoiceStatus", InvoiceRepository.STATUS_CANCELED).fetch();
BigDecimal sumInvoices = computeSumInvoices(invoices);
if (sumInvoices.compareTo(saleOrder.getExTaxTotal()) >= 0) {
throw new AxelorException(saleOrder, TraceBackRepository.CATEGORY_INCONSISTENCY, I18n.get(IExceptionMessage.SO_INVOICE_GENERATE_ALL_INVOICES));
}
}
use of com.axelor.apps.account.db.Invoice in project axelor-open-suite by axelor.
the class SaleOrderInvoiceServiceImpl method createInvoiceAndLines.
public Invoice createInvoiceAndLines(SaleOrder saleOrder, List<SaleOrderLineTax> taxLineList, Product invoicingProduct, BigDecimal percentToInvoice, int operationSubTypeSelect, Account partnerAccount) throws AxelorException {
InvoiceGenerator invoiceGenerator = this.createInvoiceGenerator(saleOrder);
Invoice invoice = invoiceGenerator.generate();
List<InvoiceLine> invoiceLinesList = (taxLineList != null && !taxLineList.isEmpty()) ? this.createInvoiceLinesFromTax(invoice, taxLineList, invoicingProduct, percentToInvoice) : this.createInvoiceLinesFromSO(invoice, saleOrder, invoicingProduct, percentToInvoice);
invoiceGenerator.populate(invoice, invoiceLinesList);
invoice.setAddressStr(saleOrder.getMainInvoicingAddressStr());
invoice.setOperationSubTypeSelect(operationSubTypeSelect);
if (partnerAccount != null) {
Partner partner = invoice.getPartner();
if (partner != null) {
partnerAccount = Beans.get(FiscalPositionAccountService.class).getAccount(partner.getFiscalPosition(), partnerAccount);
}
invoice.setPartnerAccount(partnerAccount);
}
return invoice;
}
Aggregations