Search in sources :

Example 6 with InvoiceLineTax

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

the class StockMoveMultiInvoiceServiceImpl method transformToRefund.

/**
 * Change the operation type and invert all prices in the invoice.
 *
 * @param invoice an invoice
 * @return the refund invoice
 */
protected Invoice transformToRefund(Invoice invoice) throws AxelorException {
    Invoice refund = new RefundInvoice(invoice).generate();
    if (refund.getInvoiceLineList() != null) {
        for (InvoiceLine invoiceLine : refund.getInvoiceLineList()) {
            invoiceLine.setPrice(invoiceLine.getPrice().negate());
            invoiceLine.setPriceDiscounted(invoiceLine.getPriceDiscounted().negate());
            invoiceLine.setInTaxPrice(invoiceLine.getInTaxPrice().negate());
            invoiceLine.setExTaxTotal(invoiceLine.getExTaxTotal().negate());
            invoiceLine.setInTaxTotal(invoiceLine.getInTaxTotal().negate());
            invoiceLine.setCompanyExTaxTotal(invoiceLine.getCompanyExTaxTotal().negate());
            invoiceLine.setCompanyInTaxTotal(invoiceLine.getCompanyInTaxTotal().negate());
        }
    }
    if (refund.getInvoiceLineTaxList() != null) {
        for (InvoiceLineTax invoiceLineTax : refund.getInvoiceLineTaxList()) {
            invoiceLineTax.setExTaxBase(invoiceLineTax.getExTaxBase().negate());
            invoiceLineTax.setTaxTotal(invoiceLineTax.getTaxTotal().negate());
            invoiceLineTax.setCompanyExTaxBase(invoiceLineTax.getCompanyExTaxBase().negate());
            invoiceLineTax.setInTaxTotal(invoiceLineTax.getInTaxTotal().negate());
            invoiceLineTax.setCompanyInTaxTotal(invoiceLineTax.getCompanyInTaxTotal().negate());
        }
    }
    refund.setExTaxTotal(refund.getExTaxTotal().negate());
    refund.setInTaxTotal(refund.getInTaxTotal().negate());
    refund.setCompanyExTaxTotal(refund.getCompanyExTaxTotal().negate());
    refund.setCompanyInTaxTotal(refund.getCompanyInTaxTotal().negate());
    refund.setTaxTotal(refund.getTaxTotal().negate());
    refund.setAmountRemaining(refund.getAmountRemaining().negate());
    refund.setCompanyTaxTotal(refund.getCompanyTaxTotal().negate());
    refund.setPaymentMode(InvoiceToolService.getPaymentMode(refund));
    return invoiceRepository.save(refund);
}
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) InvoiceLineTax(com.axelor.apps.account.db.InvoiceLineTax) RefundInvoice(com.axelor.apps.account.service.invoice.generator.invoice.RefundInvoice)

Example 7 with InvoiceLineTax

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

the class IrrecoverableService method createIrrecoverableMove.

/**
 * Fonction permettant de créer l'écriture de passage en irrécouvrable d'une facture
 *
 * @param invoice Une facture
 * @param prorataRate Le taux de restant à payer sur la facture
 * @param isInvoiceReject La facture est-elle rejetée?
 * @return
 * @throws AxelorException
 */
public Move createIrrecoverableMove(Invoice invoice, BigDecimal prorataRate, boolean isInvoiceReject, String irrecoverableName) throws AxelorException {
    Company company = invoice.getCompany();
    Partner payerPartner = invoice.getPartner();
    AccountConfig accountConfig = company.getAccountConfig();
    // Move
    Move move = moveService.getMoveCreateService().createMove(accountConfig.getIrrecoverableJournal(), company, null, payerPartner, null, MoveRepository.TECHNICAL_ORIGIN_AUTOMATIC, MoveRepository.FUNCTIONAL_ORIGIN_SALE);
    int seq = 1;
    BigDecimal amount = BigDecimal.ZERO;
    MoveLine debitMoveLine = null;
    BigDecimal creditAmount = null;
    BigDecimal debitAmount = null;
    if (isInvoiceReject) {
        creditAmount = invoice.getRejectMoveLine().getAmountRemaining();
        debitAmount = creditAmount;
    } else {
        creditAmount = invoice.getCompanyInTaxTotalRemaining();
        debitAmount = creditAmount;
    }
    // Debits MoveLines Tva
    for (InvoiceLineTax invoiceLineTax : invoice.getInvoiceLineTaxList()) {
        amount = (invoiceLineTax.getTaxTotal().multiply(prorataRate)).setScale(2, RoundingMode.HALF_UP);
        // do not generate move line with amount equal to zero
        if (amount.signum() == 0) {
            continue;
        }
        debitMoveLine = moveLineService.createMoveLine(move, payerPartner, taxAccountService.getAccount(invoiceLineTax.getTaxLine().getTax(), company, false, false), amount, true, appAccountService.getTodayDate(company), seq, irrecoverableName, invoice.getInvoiceId());
        move.getMoveLineList().add(debitMoveLine);
        seq++;
        debitAmount = debitAmount.subtract(amount);
    }
    // Debit MoveLine 654 (irrecoverable account)
    debitMoveLine = moveLineService.createMoveLine(move, payerPartner, accountConfig.getIrrecoverableAccount(), debitAmount, true, appAccountService.getTodayDate(company), seq, irrecoverableName, invoice.getInvoiceId());
    move.getMoveLineList().add(debitMoveLine);
    seq++;
    // Getting customer MoveLine from Facture
    MoveLine customerMoveLine = moveService.getMoveToolService().getCustomerMoveLineByQuery(invoice);
    if (customerMoveLine == null) {
        throw new AxelorException(TraceBackRepository.CATEGORY_INCONSISTENCY, I18n.get(IExceptionMessage.IRRECOVERABLE_3), I18n.get(com.axelor.apps.base.exceptions.IExceptionMessage.EXCEPTION), invoice.getInvoiceId());
    }
    customerMoveLine.setIrrecoverableStatusSelect(MoveLineRepository.IRRECOVERABLE_STATUS_PASSED_IN_IRRECOUVRABLE);
    // Credit MoveLine Customer account (411, 416, ...)
    MoveLine creditMoveLine = moveLineService.createMoveLine(move, payerPartner, customerMoveLine.getAccount(), creditAmount, false, appAccountService.getTodayDate(company), seq, irrecoverableName, invoice.getInvoiceId());
    move.getMoveLineList().add(creditMoveLine);
    Reconcile reconcile = reconcileService.createReconcile(customerMoveLine, creditMoveLine, creditAmount, false);
    if (reconcile != null) {
        reconcileService.confirmReconcile(reconcile, true);
    }
    return move;
}
Also used : AxelorException(com.axelor.exception.AxelorException) Company(com.axelor.apps.base.db.Company) Move(com.axelor.apps.account.db.Move) MoveLine(com.axelor.apps.account.db.MoveLine) Partner(com.axelor.apps.base.db.Partner) InvoiceLineTax(com.axelor.apps.account.db.InvoiceLineTax) BigDecimal(java.math.BigDecimal) AccountConfig(com.axelor.apps.account.db.AccountConfig) Reconcile(com.axelor.apps.account.db.Reconcile)

Example 8 with InvoiceLineTax

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

the class MoveLineServiceImpl method generateTaxPaymentMoveLineList.

@Override
@Transactional(rollbackOn = { Exception.class })
public MoveLine generateTaxPaymentMoveLineList(MoveLine customerMoveLine, Invoice invoice, Reconcile reconcile) throws AxelorException {
    BigDecimal paymentAmount = reconcile.getAmount();
    BigDecimal invoiceTotalAmount = invoice.getCompanyInTaxTotal();
    for (InvoiceLineTax invoiceLineTax : invoice.getInvoiceLineTaxList()) {
        TaxLine taxLine = invoiceLineTax.getTaxLine();
        BigDecimal vatRate = taxLine.getValue();
        BigDecimal baseAmount = invoiceLineTax.getCompanyExTaxBase();
        BigDecimal detailPaymentAmount = baseAmount.multiply(paymentAmount).divide(invoiceTotalAmount, 6, RoundingMode.HALF_UP).setScale(2, RoundingMode.HALF_UP);
        TaxPaymentMoveLine taxPaymentMoveLine = new TaxPaymentMoveLine(customerMoveLine, taxLine, reconcile, vatRate, detailPaymentAmount, Beans.get(AppBaseService.class).getTodayDate(reconcile.getCompany()));
        taxPaymentMoveLine = taxPaymentMoveLineService.computeTaxAmount(taxPaymentMoveLine);
        customerMoveLine.addTaxPaymentMoveLineListItem(taxPaymentMoveLine);
    }
    this.computeTaxAmount(customerMoveLine);
    return Beans.get(MoveLineRepository.class).save(customerMoveLine);
}
Also used : TaxPaymentMoveLine(com.axelor.apps.account.db.TaxPaymentMoveLine) AnalyticMoveLineRepository(com.axelor.apps.account.db.repo.AnalyticMoveLineRepository) MoveLineRepository(com.axelor.apps.account.db.repo.MoveLineRepository) InvoiceLineTax(com.axelor.apps.account.db.InvoiceLineTax) BigDecimal(java.math.BigDecimal) TaxLine(com.axelor.apps.account.db.TaxLine) Transactional(com.google.inject.persist.Transactional)

Example 9 with InvoiceLineTax

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

the class TaxInvoiceLine method createOrUpdateInvoiceLineTaxRc.

protected void createOrUpdateInvoiceLineTaxRc(InvoiceLine invoiceLine, TaxLine taxLineRC, TaxEquiv taxEquiv, Map<TaxLine, InvoiceLineTax> map) {
    if (map.containsKey(taxLineRC)) {
        InvoiceLineTax invoiceLineTaxRC = map.get(taxEquiv.getReverseChargeTax().getActiveTaxLine());
        updateInvoiceLineTax(invoiceLine, invoiceLineTaxRC);
        invoiceLineTaxRC.setReverseCharged(true);
    } else {
        InvoiceLineTax invoiceLineTaxRC = createInvoiceLineTax(invoiceLine, taxLineRC);
        invoiceLineTaxRC.setReverseCharged(true);
        map.put(taxLineRC, invoiceLineTaxRC);
    }
}
Also used : InvoiceLineTax(com.axelor.apps.account.db.InvoiceLineTax)

Example 10 with InvoiceLineTax

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

the class TaxInvoiceLine method finalizeInvoiceLineTaxes.

protected List<InvoiceLineTax> finalizeInvoiceLineTaxes(Map<TaxLine, InvoiceLineTax> map) {
    List<InvoiceLineTax> invoiceLineTaxList = new ArrayList<>();
    for (InvoiceLineTax invoiceLineTax : map.values()) {
        BigDecimal taxValue = invoiceLineTax.getTaxLine().getValue();
        // Dans la devise de la facture
        BigDecimal exTaxBase = (invoiceLineTax.getReverseCharged()) ? invoiceLineTax.getExTaxBase().negate() : invoiceLineTax.getExTaxBase();
        BigDecimal taxTotal = computeAmount(exTaxBase, taxValue);
        invoiceLineTax.setTaxTotal(taxTotal);
        invoiceLineTax.setInTaxTotal(invoiceLineTax.getExTaxBase().add(taxTotal));
        // Dans la devise de la société
        BigDecimal companyExTaxBase = (invoiceLineTax.getReverseCharged()) ? invoiceLineTax.getCompanyExTaxBase().negate() : invoiceLineTax.getCompanyExTaxBase();
        BigDecimal companyTaxTotal = computeAmount(companyExTaxBase, taxValue);
        invoiceLineTax.setCompanyTaxTotal(companyTaxTotal);
        invoiceLineTax.setCompanyInTaxTotal(invoiceLineTax.getCompanyExTaxBase().add(companyTaxTotal));
        BigDecimal subTotalExcludingFixedAssets = invoiceLineTax.getReverseCharged() ? invoiceLineTax.getSubTotalExcludingFixedAssets().negate() : invoiceLineTax.getSubTotalExcludingFixedAssets();
        invoiceLineTax.setSubTotalExcludingFixedAssets(computeAmount(subTotalExcludingFixedAssets, taxValue));
        invoiceLineTax.setSubTotalOfFixedAssets(taxTotal.subtract(invoiceLineTax.getSubTotalExcludingFixedAssets()).setScale(2, RoundingMode.HALF_UP));
        BigDecimal companySubTotalExcludingFixedAssets = invoiceLineTax.getReverseCharged() ? invoiceLineTax.getCompanySubTotalExcludingFixedAssets().negate() : invoiceLineTax.getCompanySubTotalExcludingFixedAssets();
        invoiceLineTax.setCompanySubTotalExcludingFixedAssets(computeAmount(companySubTotalExcludingFixedAssets, taxValue));
        invoiceLineTax.setCompanySubTotalOfFixedAssets(companyTaxTotal.subtract(invoiceLineTax.getCompanySubTotalExcludingFixedAssets()).setScale(2, RoundingMode.HALF_UP));
        invoiceLineTaxList.add(invoiceLineTax);
        LOG.debug("Ligne de TVA : Total TVA => {}, Total HT => {}", invoiceLineTax.getTaxTotal(), invoiceLineTax.getInTaxTotal());
    }
    return invoiceLineTaxList;
}
Also used : ArrayList(java.util.ArrayList) InvoiceLineTax(com.axelor.apps.account.db.InvoiceLineTax) BigDecimal(java.math.BigDecimal)

Aggregations

InvoiceLineTax (com.axelor.apps.account.db.InvoiceLineTax)10 InvoiceLine (com.axelor.apps.account.db.InvoiceLine)4 BigDecimal (java.math.BigDecimal)4 ArrayList (java.util.ArrayList)3 MoveLine (com.axelor.apps.account.db.MoveLine)2 TaxLine (com.axelor.apps.account.db.TaxLine)2 TaxPaymentMoveLine (com.axelor.apps.account.db.TaxPaymentMoveLine)2 AnalyticMoveLineRepository (com.axelor.apps.account.db.repo.AnalyticMoveLineRepository)2 AxelorException (com.axelor.exception.AxelorException)2 Account (com.axelor.apps.account.db.Account)1 AccountConfig (com.axelor.apps.account.db.AccountConfig)1 AnalyticAccount (com.axelor.apps.account.db.AnalyticAccount)1 AnalyticMoveLine (com.axelor.apps.account.db.AnalyticMoveLine)1 Invoice (com.axelor.apps.account.db.Invoice)1 IrrecoverableInvoiceLine (com.axelor.apps.account.db.IrrecoverableInvoiceLine)1 IrrecoverableReportLine (com.axelor.apps.account.db.IrrecoverableReportLine)1 Move (com.axelor.apps.account.db.Move)1 Reconcile (com.axelor.apps.account.db.Reconcile)1 Tax (com.axelor.apps.account.db.Tax)1 MoveLineRepository (com.axelor.apps.account.db.repo.MoveLineRepository)1