Search in sources :

Example 46 with Invoice

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);
}
Also used : Account(com.axelor.apps.account.db.Account) AxelorException(com.axelor.exception.AxelorException) Invoice(com.axelor.apps.account.db.Invoice) SaleOrderLineTax(com.axelor.apps.sale.db.SaleOrderLineTax) AccountConfigService(com.axelor.apps.account.service.config.AccountConfigService) Product(com.axelor.apps.base.db.Product) BigDecimal(java.math.BigDecimal) Transactional(com.google.inject.persist.Transactional)

Example 47 with 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;
}
Also used : Invoice(com.axelor.apps.account.db.Invoice) Transactional(com.google.inject.persist.Transactional)

Example 48 with 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;
}
Also used : Invoice(com.axelor.apps.account.db.Invoice) ArrayList(java.util.ArrayList) BigDecimal(java.math.BigDecimal)

Example 49 with Invoice

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));
    }
}
Also used : AxelorException(com.axelor.exception.AxelorException) Invoice(com.axelor.apps.account.db.Invoice) BigDecimal(java.math.BigDecimal)

Example 50 with Invoice

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;
}
Also used : Invoice(com.axelor.apps.account.db.Invoice) InvoiceLine(com.axelor.apps.account.db.InvoiceLine) InvoiceGenerator(com.axelor.apps.account.service.invoice.generator.InvoiceGenerator) Partner(com.axelor.apps.base.db.Partner)

Aggregations

Invoice (com.axelor.apps.account.db.Invoice)195 AxelorException (com.axelor.exception.AxelorException)69 ArrayList (java.util.ArrayList)48 Transactional (com.google.inject.persist.Transactional)46 BigDecimal (java.math.BigDecimal)32 Company (com.axelor.apps.base.db.Company)31 InvoiceLine (com.axelor.apps.account.db.InvoiceLine)29 Partner (com.axelor.apps.base.db.Partner)27 InvoiceRepository (com.axelor.apps.account.db.repo.InvoiceRepository)22 InvoiceService (com.axelor.apps.account.service.invoice.InvoiceService)22 PaymentMode (com.axelor.apps.account.db.PaymentMode)21 Map (java.util.Map)21 List (java.util.List)20 StockMove (com.axelor.apps.stock.db.StockMove)19 RefundInvoice (com.axelor.apps.account.service.invoice.generator.invoice.RefundInvoice)18 MoveLine (com.axelor.apps.account.db.MoveLine)17 LocalDate (java.time.LocalDate)17 InvoiceGenerator (com.axelor.apps.account.service.invoice.generator.InvoiceGenerator)16 Context (com.axelor.rpc.Context)15 InvoicePayment (com.axelor.apps.account.db.InvoicePayment)14