Search in sources :

Example 76 with InvoiceLine

use of com.axelor.apps.account.db.InvoiceLine in project axelor-open-suite by axelor.

the class InvoiceServiceImpl method compute.

/**
 * Fonction permettant de calculer l'intégralité d'une facture :
 *
 * <ul>
 *   <li>Détermine les taxes;
 *   <li>Détermine la TVA;
 *   <li>Détermine les totaux.
 * </ul>
 *
 * (Transaction)
 *
 * @param invoice Une facture.
 * @throws AxelorException
 */
@Override
public Invoice compute(final Invoice invoice) throws AxelorException {
    log.debug("Calcul de la facture");
    InvoiceGenerator invoiceGenerator = new InvoiceGenerator() {

        @Override
        public Invoice generate() throws AxelorException {
            List<InvoiceLine> invoiceLines = new ArrayList<InvoiceLine>();
            if (invoice.getInvoiceLineList() != null) {
                invoiceLines.addAll(invoice.getInvoiceLineList());
            }
            populate(invoice, invoiceLines);
            return invoice;
        }
    };
    Invoice invoice1 = invoiceGenerator.generate();
    invoice1.setAdvancePaymentInvoiceSet(this.getDefaultAdvancePaymentInvoice(invoice1));
    return invoice1;
}
Also used : RefundInvoice(com.axelor.apps.account.service.invoice.generator.invoice.RefundInvoice) Invoice(com.axelor.apps.account.db.Invoice) InvoiceLine(com.axelor.apps.account.db.InvoiceLine) InvoiceGenerator(com.axelor.apps.account.service.invoice.generator.InvoiceGenerator) ArrayList(java.util.ArrayList)

Example 77 with InvoiceLine

use of com.axelor.apps.account.db.InvoiceLine in project axelor-open-suite by axelor.

the class InvoiceServiceImpl method getInvoiceLinesFromInvoiceList.

@Override
public List<InvoiceLine> getInvoiceLinesFromInvoiceList(List<Invoice> invoiceList) {
    List<InvoiceLine> invoiceLines = new ArrayList<InvoiceLine>();
    for (Invoice invoice : invoiceList) {
        int countLine = 1;
        for (InvoiceLine invoiceLine : invoice.getInvoiceLineList()) {
            invoiceLine.setSequence(countLine * 10);
            invoiceLines.add(invoiceLine);
            countLine++;
        }
    }
    return invoiceLines;
}
Also used : RefundInvoice(com.axelor.apps.account.service.invoice.generator.invoice.RefundInvoice) Invoice(com.axelor.apps.account.db.Invoice) InvoiceLine(com.axelor.apps.account.db.InvoiceLine) ArrayList(java.util.ArrayList)

Example 78 with InvoiceLine

use of com.axelor.apps.account.db.InvoiceLine in project axelor-open-suite by axelor.

the class RefundInvoice method refundInvoiceLines.

/**
 * Mets à jour les lignes de facture en appliquant la négation aux prix unitaires et au total hors
 * taxe.
 *
 * @param invoiceLines
 */
@Deprecated
protected void refundInvoiceLines(List<InvoiceLine> invoiceLines) {
    for (InvoiceLine invoiceLine : invoiceLines) {
        invoiceLine.setQty(invoiceLine.getQty().negate());
        invoiceLine.setExTaxTotal(invoiceLine.getExTaxTotal().negate());
    }
}
Also used : InvoiceLine(com.axelor.apps.account.db.InvoiceLine)

Example 79 with InvoiceLine

use of com.axelor.apps.account.db.InvoiceLine in project axelor-open-suite by axelor.

the class RefundInvoice method generate.

@Override
public Invoice generate() throws AxelorException {
    LOG.debug("Creating a refund for invoice {}", invoice.getInvoiceId());
    Invoice refund = JPA.copy(invoice, true);
    InvoiceToolService.resetInvoiceStatusOnCopy(refund);
    refund.setOperationTypeSelect(this.inverseOperationType(refund.getOperationTypeSelect()));
    List<InvoiceLine> refundLines = new ArrayList<>();
    if (refund.getInvoiceLineList() != null) {
        refundLines.addAll(refund.getInvoiceLineList());
    }
    populate(refund, refundLines);
    // Payment mode should not be the invoice payment mode. It must come
    // from the partner or the company, or be null.
    refund.setPaymentMode(InvoiceToolService.getPaymentMode(refund));
    if (refund.getPaymentMode() == null) {
        throw new AxelorException(TraceBackRepository.CATEGORY_MISSING_FIELD, I18n.get(IExceptionMessage.REFUND_INVOICE_1), I18n.get(com.axelor.apps.base.exceptions.IExceptionMessage.EXCEPTION));
    }
    return refund;
}
Also used : AxelorException(com.axelor.exception.AxelorException) Invoice(com.axelor.apps.account.db.Invoice) InvoiceLine(com.axelor.apps.account.db.InvoiceLine) ArrayList(java.util.ArrayList)

Example 80 with InvoiceLine

use of com.axelor.apps.account.db.InvoiceLine in project axelor-open-suite by axelor.

the class InvoiceLineGenerator method createInvoiceLine.

/**
 * @return
 * @throws AxelorException
 */
protected InvoiceLine createInvoiceLine() throws AxelorException {
    InvoiceLine invoiceLine = new InvoiceLine();
    boolean isPurchase = InvoiceToolService.isPurchase(invoice);
    Partner partner = invoice.getPartner();
    Company company = invoice.getCompany();
    invoiceLine.setInvoice(invoice);
    invoiceLine.setProduct(product);
    invoiceLine.setProductName(productName);
    if (product != null) {
        invoiceLine.setProductCode((String) productCompanyService.get(product, "code", company));
        Account account = accountManagementService.getProductAccount(product, company, partner.getFiscalPosition(), isPurchase, invoiceLine.getFixedAssets());
        invoiceLine.setAccount(account);
    }
    invoiceLine.setDescription(description);
    invoiceLine.setPrice(price);
    invoiceLine.setInTaxPrice(inTaxPrice);
    invoiceLine.setPriceDiscounted(priceDiscounted);
    invoiceLine.setQty(qty);
    invoiceLine.setUnit(unit);
    invoiceLine.setTypeSelect(typeSelect);
    if (taxLine == null) {
        this.determineTaxLine();
    }
    if (product != null) {
        TaxEquiv taxEquiv = Beans.get(AccountManagementService.class).getProductTaxEquiv(product, company, partner.getFiscalPosition(), isPurchase);
        invoiceLine.setTaxEquiv(taxEquiv);
    }
    invoiceLine.setTaxLine(taxLine);
    if (taxLine != null) {
        invoiceLine.setTaxRate(taxLine.getValue());
        invoiceLine.setTaxCode(taxLine.getTax().getCode());
    }
    if ((exTaxTotal == null || inTaxTotal == null)) {
        this.computeTotal();
    }
    invoiceLine.setExTaxTotal(exTaxTotal);
    invoiceLine.setInTaxTotal(inTaxTotal);
    this.computeCompanyTotal(invoiceLine);
    invoiceLine.setSequence(sequence);
    invoiceLine.setDiscountTypeSelect(discountTypeSelect);
    invoiceLine.setDiscountAmount(discountAmount);
    return invoiceLine;
}
Also used : Account(com.axelor.apps.account.db.Account) Company(com.axelor.apps.base.db.Company) AccountManagementService(com.axelor.apps.base.service.tax.AccountManagementService) InvoiceLine(com.axelor.apps.account.db.InvoiceLine) Partner(com.axelor.apps.base.db.Partner) TaxEquiv(com.axelor.apps.account.db.TaxEquiv)

Aggregations

InvoiceLine (com.axelor.apps.account.db.InvoiceLine)80 ArrayList (java.util.ArrayList)36 Invoice (com.axelor.apps.account.db.Invoice)27 BigDecimal (java.math.BigDecimal)22 AxelorException (com.axelor.exception.AxelorException)20 Product (com.axelor.apps.base.db.Product)13 InvoiceLineGenerator (com.axelor.apps.account.service.invoice.generator.InvoiceLineGenerator)12 Transactional (com.google.inject.persist.Transactional)12 Context (com.axelor.rpc.Context)11 Account (com.axelor.apps.account.db.Account)8 InvoiceGenerator (com.axelor.apps.account.service.invoice.generator.InvoiceGenerator)8 TaxLine (com.axelor.apps.account.db.TaxLine)7 InvoiceLineService (com.axelor.apps.account.service.invoice.InvoiceLineService)7 RefundInvoice (com.axelor.apps.account.service.invoice.generator.invoice.RefundInvoice)6 SaleOrderLine (com.axelor.apps.sale.db.SaleOrderLine)6 InvoiceLineGeneratorSupplyChain (com.axelor.apps.supplychain.service.invoice.generator.InvoiceLineGeneratorSupplyChain)6 AnalyticMoveLine (com.axelor.apps.account.db.AnalyticMoveLine)5 InvoiceRepository (com.axelor.apps.account.db.repo.InvoiceRepository)5 HashSet (java.util.HashSet)5 List (java.util.List)5