Search in sources :

Example 1 with PurchaseOrderLineTax

use of com.axelor.apps.purchase.db.PurchaseOrderLineTax in project axelor-open-suite by axelor.

the class PurchaseOrderServiceImpl method _computePurchaseOrder.

/**
 * Compute the purchase order total amounts
 *
 * @param purchaseOrder
 * @throws AxelorException
 */
@Override
public void _computePurchaseOrder(PurchaseOrder purchaseOrder) throws AxelorException {
    purchaseOrder.setExTaxTotal(BigDecimal.ZERO);
    purchaseOrder.setCompanyExTaxTotal(BigDecimal.ZERO);
    purchaseOrder.setTaxTotal(BigDecimal.ZERO);
    purchaseOrder.setInTaxTotal(BigDecimal.ZERO);
    for (PurchaseOrderLine purchaseOrderLine : purchaseOrder.getPurchaseOrderLineList()) {
        purchaseOrder.setExTaxTotal(purchaseOrder.getExTaxTotal().add(purchaseOrderLine.getExTaxTotal()));
        // In the company accounting currency
        purchaseOrder.setCompanyExTaxTotal(purchaseOrder.getCompanyExTaxTotal().add(purchaseOrderLine.getCompanyExTaxTotal()));
    }
    for (PurchaseOrderLineTax purchaseOrderLineVat : purchaseOrder.getPurchaseOrderLineTaxList()) {
        // In the purchase order currency
        purchaseOrder.setTaxTotal(purchaseOrder.getTaxTotal().add(purchaseOrderLineVat.getTaxTotal()));
    }
    purchaseOrder.setInTaxTotal(purchaseOrder.getExTaxTotal().add(purchaseOrder.getTaxTotal()));
    logger.debug("Montant de la facture: HTT = {},  HT = {}, TVA = {}, TTC = {}", new Object[] { purchaseOrder.getExTaxTotal(), purchaseOrder.getTaxTotal(), purchaseOrder.getInTaxTotal() });
}
Also used : PurchaseOrderLine(com.axelor.apps.purchase.db.PurchaseOrderLine) PurchaseOrderLineTax(com.axelor.apps.purchase.db.PurchaseOrderLineTax)

Example 2 with PurchaseOrderLineTax

use of com.axelor.apps.purchase.db.PurchaseOrderLineTax in project axelor-open-suite by axelor.

the class PurchaseOrderLineTaxService method createsPurchaseOrderLineTax.

/**
 * Créer les lignes de TVA de la commande. La création des lignes de TVA se basent sur les lignes
 * de commande.
 *
 * @param purchaseOrder La commande.
 * @param purchaseOrderLineList Les lignes de commandes.
 * @return La liste des lignes de TVA de la commande.
 */
public List<PurchaseOrderLineTax> createsPurchaseOrderLineTax(PurchaseOrder purchaseOrder, List<PurchaseOrderLine> purchaseOrderLineList) {
    List<PurchaseOrderLineTax> purchaseOrderLineTaxList = new ArrayList<PurchaseOrderLineTax>();
    Map<TaxLine, PurchaseOrderLineTax> map = new HashMap<TaxLine, PurchaseOrderLineTax>();
    if (purchaseOrderLineList != null && !purchaseOrderLineList.isEmpty()) {
        LOG.debug("Création des lignes de tva pour les lignes de commande.");
        for (PurchaseOrderLine purchaseOrderLine : purchaseOrderLineList) {
            TaxLine taxLine = purchaseOrderLine.getTaxLine();
            TaxEquiv taxEquiv = purchaseOrderLine.getTaxEquiv();
            TaxLine taxLineRC = (taxEquiv != null && taxEquiv.getReverseCharge() && taxEquiv.getReverseChargeTax() != null) ? taxEquiv.getReverseChargeTax().getActiveTaxLine() : null;
            if (taxLine != null) {
                LOG.debug("TVA {}", taxLine);
                if (map.containsKey(taxLine)) {
                    PurchaseOrderLineTax purchaseOrderLineVat = map.get(taxLine);
                    purchaseOrderLineVat.setExTaxBase(purchaseOrderLineVat.getExTaxBase().add(purchaseOrderLine.getExTaxTotal()));
                    purchaseOrderLineVat.setReverseCharged(false);
                } else {
                    PurchaseOrderLineTax purchaseOrderLineTax = new PurchaseOrderLineTax();
                    purchaseOrderLineTax.setPurchaseOrder(purchaseOrder);
                    purchaseOrderLineTax.setExTaxBase(purchaseOrderLine.getExTaxTotal());
                    purchaseOrderLineTax.setReverseCharged(false);
                    purchaseOrderLineTax.setTaxLine(taxLine);
                    map.put(taxLine, purchaseOrderLineTax);
                }
            }
            if (taxLineRC != null) {
                LOG.debug("TVA {}", taxLineRC);
                if (map.containsKey(taxLineRC)) {
                    PurchaseOrderLineTax purchaseOrderLineRC = map.get(taxEquiv.getReverseChargeTax().getActiveTaxLine());
                    purchaseOrderLineRC.setExTaxBase(purchaseOrderLineRC.getExTaxBase().add(purchaseOrderLine.getExTaxTotal()));
                    purchaseOrderLineRC.setReverseCharged(true);
                } else {
                    PurchaseOrderLineTax purchaseOrderLineTaxRC = new PurchaseOrderLineTax();
                    purchaseOrderLineTaxRC.setPurchaseOrder(purchaseOrder);
                    purchaseOrderLineTaxRC.setExTaxBase(purchaseOrderLine.getExTaxTotal());
                    purchaseOrderLineTaxRC.setReverseCharged(true);
                    purchaseOrderLineTaxRC.setTaxLine(taxLineRC);
                    map.put(taxLineRC, purchaseOrderLineTaxRC);
                }
            }
        }
    }
    for (PurchaseOrderLineTax purchaseOrderLineTax : map.values()) {
        // Dans la devise de la commande
        BigDecimal exTaxBase = (purchaseOrderLineTax.getReverseCharged()) ? purchaseOrderLineTax.getExTaxBase().negate() : purchaseOrderLineTax.getExTaxBase();
        BigDecimal taxTotal = BigDecimal.ZERO;
        if (purchaseOrderLineTax.getTaxLine() != null)
            taxTotal = purchaseOrderToolService.computeAmount(exTaxBase, purchaseOrderLineTax.getTaxLine().getValue());
        purchaseOrderLineTax.setTaxTotal(taxTotal);
        purchaseOrderLineTax.setInTaxTotal(purchaseOrderLineTax.getExTaxBase().add(taxTotal));
        purchaseOrderLineTaxList.add(purchaseOrderLineTax);
        LOG.debug("Ligne de TVA : Total TVA => {}, Total HT => {}", new Object[] { purchaseOrderLineTax.getTaxTotal(), purchaseOrderLineTax.getInTaxTotal() });
    }
    return purchaseOrderLineTaxList;
}
Also used : PurchaseOrderLine(com.axelor.apps.purchase.db.PurchaseOrderLine) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) TaxEquiv(com.axelor.apps.account.db.TaxEquiv) BigDecimal(java.math.BigDecimal) PurchaseOrderLineTax(com.axelor.apps.purchase.db.PurchaseOrderLineTax) TaxLine(com.axelor.apps.account.db.TaxLine)

Aggregations

PurchaseOrderLine (com.axelor.apps.purchase.db.PurchaseOrderLine)2 PurchaseOrderLineTax (com.axelor.apps.purchase.db.PurchaseOrderLineTax)2 TaxEquiv (com.axelor.apps.account.db.TaxEquiv)1 TaxLine (com.axelor.apps.account.db.TaxLine)1 BigDecimal (java.math.BigDecimal)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1