Search in sources :

Example 1 with InvoiceLine

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

the class IrrecoverableService method createIrrecoverableReportLineList.

/**
 * Fonction permettant de créer une liste de ligne de reporting pour une ligne Facture
 *
 * @param iil Une ligne Facture
 * @param invoice Une facture
 * @param prorataRate Un taux de restant à payer d'une facture
 * @return
 */
public List<IrrecoverableReportLine> createIrrecoverableReportLineList(IrrecoverableInvoiceLine iil, Invoice invoice, BigDecimal prorataRate) {
    int seq = 1;
    List<IrrecoverableReportLine> irlList = new ArrayList<IrrecoverableReportLine>();
    for (InvoiceLine invoiceLine : invoice.getInvoiceLineList()) {
        irlList.add(this.createIrrecoverableReportLine(iil, invoiceLine.getName(), invoiceLine.getExTaxTotal().multiply(prorataRate).setScale(AppBaseService.DEFAULT_NB_DECIMAL_DIGITS, RoundingMode.HALF_UP), seq));
        seq++;
    }
    for (InvoiceLineTax invoiceLineTax : invoice.getInvoiceLineTaxList()) {
        irlList.add(this.createIrrecoverableReportLine(iil, invoiceLineTax.getTaxLine().getTax().getName(), invoiceLineTax.getTaxTotal().multiply(prorataRate).setScale(AppBaseService.DEFAULT_NB_DECIMAL_DIGITS, RoundingMode.HALF_UP), seq));
        seq++;
    }
    // Afin de ne pas modifier les valeurs des lignes de factures, on les recharges depuis la base
    invoiceRepo.refresh(invoice);
    return irlList;
}
Also used : InvoiceLine(com.axelor.apps.account.db.InvoiceLine) IrrecoverableInvoiceLine(com.axelor.apps.account.db.IrrecoverableInvoiceLine) ArrayList(java.util.ArrayList) IrrecoverableReportLine(com.axelor.apps.account.db.IrrecoverableReportLine) InvoiceLineTax(com.axelor.apps.account.db.InvoiceLineTax)

Example 2 with InvoiceLine

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

the class InvoiceGenerator method computeInvoice.

/**
 * Compute the invoice total amounts
 *
 * @param invoice
 * @throws AxelorException
 */
public void computeInvoice(Invoice invoice) throws AxelorException {
    // In the invoice currency
    invoice.setExTaxTotal(BigDecimal.ZERO);
    invoice.setTaxTotal(BigDecimal.ZERO);
    invoice.setInTaxTotal(BigDecimal.ZERO);
    // In the company accounting currency
    invoice.setCompanyExTaxTotal(BigDecimal.ZERO);
    invoice.setCompanyTaxTotal(BigDecimal.ZERO);
    invoice.setCompanyInTaxTotal(BigDecimal.ZERO);
    for (InvoiceLine invoiceLine : invoice.getInvoiceLineList()) {
        if (invoiceLine.getTypeSelect() != InvoiceLineRepository.TYPE_NORMAL) {
            continue;
        }
        // In the invoice currency
        invoice.setExTaxTotal(invoice.getExTaxTotal().add(invoiceLine.getExTaxTotal()));
        // In the company accounting currency
        invoice.setCompanyExTaxTotal(invoice.getCompanyExTaxTotal().add(invoiceLine.getCompanyExTaxTotal()));
    }
    for (InvoiceLineTax invoiceLineTax : invoice.getInvoiceLineTaxList()) {
        // In the invoice currency
        invoice.setTaxTotal(invoice.getTaxTotal().add(invoiceLineTax.getTaxTotal()));
        // In the company accounting currency
        invoice.setCompanyTaxTotal(invoice.getCompanyTaxTotal().add(invoiceLineTax.getCompanyTaxTotal()));
    }
    // In the invoice currency
    invoice.setInTaxTotal(invoice.getExTaxTotal().add(invoice.getTaxTotal()));
    // In the company accounting currency
    invoice.setCompanyInTaxTotal(invoice.getCompanyExTaxTotal().add(invoice.getCompanyTaxTotal()));
    invoice.setAmountRemaining(invoice.getInTaxTotal());
    invoice.setHasPendingPayments(false);
    logger.debug("Invoice amounts : W.T. = {}, Tax = {}, A.T.I. = {}", new Object[] { invoice.getExTaxTotal(), invoice.getTaxTotal(), invoice.getInTaxTotal() });
}
Also used : InvoiceLine(com.axelor.apps.account.db.InvoiceLine) TaxInvoiceLine(com.axelor.apps.account.service.invoice.generator.tax.TaxInvoiceLine) InvoiceLineTax(com.axelor.apps.account.db.InvoiceLineTax)

Example 3 with InvoiceLine

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

the class InvoiceLineGenerator method substractInvoiceLine.

protected InvoiceLine substractInvoiceLine(InvoiceLine invoiceLine1, InvoiceLine invoiceLine2) {
    InvoiceLine substract = JPA.copy(invoiceLine1, false);
    substract.setQty(invoiceLine1.getQty().add(invoiceLine2.getQty()));
    substract.setExTaxTotal(computeAmount(substract.getQty(), substract.getPrice()));
    LOG.debug("Soustraction de deux lignes de factures: {}", substract);
    return substract;
}
Also used : InvoiceLine(com.axelor.apps.account.db.InvoiceLine)

Example 4 with InvoiceLine

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

the class InvoiceLineGenerator method refundInvoiceLine.

/**
 * Rembourser une ligne de facture.
 *
 * @param invoice La facture concernée.
 * @param invoiceLine La ligne de facture.
 * @return La ligne de facture de remboursement.
 */
protected InvoiceLine refundInvoiceLine(InvoiceLine invoiceLine, boolean daysQty) {
    LOG.debug("Remboursement d'une ligne de facture (quantité = nb jour ? {}).", daysQty);
    InvoiceLine refundInvoiceLine = JPA.copy(invoiceLine, true);
    refundInvoiceLine.setInvoice(invoice);
    BigDecimal quantity = invoiceLine.getQty();
    refundInvoiceLine.setQty(quantity.negate());
    LOG.debug("Quantité remboursée : {}", refundInvoiceLine.getQty());
    refundInvoiceLine.setExTaxTotal(computeAmount(refundInvoiceLine.getQty(), refundInvoiceLine.getPrice()));
    LOG.debug("Remboursement de la ligne de facture {} => montant HT: {}", new Object[] { invoiceLine.getId(), refundInvoiceLine.getExTaxTotal() });
    return refundInvoiceLine;
}
Also used : InvoiceLine(com.axelor.apps.account.db.InvoiceLine) BigDecimal(java.math.BigDecimal)

Example 5 with InvoiceLine

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

the class InvoiceServiceImpl method mergeInvoice.

@Override
@Transactional(rollbackOn = { Exception.class })
public Invoice mergeInvoice(List<Invoice> invoiceList, Company company, Currency currency, Partner partner, Partner contactPartner, PriceList priceList, PaymentMode paymentMode, PaymentCondition paymentCondition) throws AxelorException {
    String numSeq = "";
    String externalRef = "";
    for (Invoice invoiceLocal : invoiceList) {
        if (!numSeq.isEmpty()) {
            numSeq += "-";
        }
        if (invoiceLocal.getInternalReference() != null) {
            numSeq += invoiceLocal.getInternalReference();
        }
        if (!externalRef.isEmpty()) {
            externalRef += "|";
        }
        if (invoiceLocal.getExternalReference() != null) {
            externalRef += invoiceLocal.getExternalReference();
        }
    }
    InvoiceGenerator invoiceGenerator = new InvoiceGenerator(InvoiceRepository.OPERATION_TYPE_CLIENT_SALE, company, paymentCondition, paymentMode, partnerService.getInvoicingAddress(partner), partner, contactPartner, currency, priceList, numSeq, externalRef, null, company.getDefaultBankDetails(), null, null) {

        @Override
        public Invoice generate() throws AxelorException {
            return super.createInvoiceHeader();
        }
    };
    Invoice invoiceMerged = invoiceGenerator.generate();
    List<InvoiceLine> invoiceLines = this.getInvoiceLinesFromInvoiceList(invoiceList);
    invoiceGenerator.populate(invoiceMerged, invoiceLines);
    this.setInvoiceForInvoiceLines(invoiceLines, invoiceMerged);
    invoiceRepo.save(invoiceMerged);
    return invoiceMerged;
}
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) Transactional(com.google.inject.persist.Transactional)

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