Search in sources :

Example 86 with MOrderLine

use of org.compiere.model.MOrderLine in project lar_361 by comitsrl.

the class SubCurrentLine method loadLine.

private void loadLine(int lineId) {
    if (lineId <= 0)
        return;
    log.fine("loading line " + lineId);
    MOrderLine ol = new MOrderLine(p_ctx, lineId, null);
    if (ol != null) {
        setPrice(ol.getPriceActual());
        setQty(ol.getQtyOrdered());
    }
}
Also used : MOrderLine(org.compiere.model.MOrderLine)

Example 87 with MOrderLine

use of org.compiere.model.MOrderLine in project lar_361 by comitsrl.

the class LAR_CalcularPercepcion method calculateWhithholdingLine.

/**
 * Calcular percion de la OV.
 * @param bp
 * @param line
 * @param type
 * @return
 */
public static String calculateWhithholdingLine(final MBPartner bp, final MOrderLine line, int type) {
    if (type == TYPE_AFTER_NEW || type == TYPE_AFTER_DELETE || (type == TYPE_AFTER_CHANGE && (line.is_ValueChanged("LineNetAmt") || line.is_ValueChanged("M_Product_ID") || line.is_ValueChanged("IsActive") || line.is_ValueChanged("C_Tax_ID") || line.is_ValueChanged("C_BPartner_ID")))) {
        // Check if withholding on sales is needed
        final MPOS pos = MPOS.get(Env.getCtx(), Env.getContextAsInt(Env.getCtx(), Env.POS_ID));
        if (!pos.get_ValueAsBoolean("IsGenerateWithholdingOnSale")) {
            return null;
        }
        final MOrder order = line.getParent();
        // Check if is a sales transaction
        if (!order.isSOTrx())
            return null;
        final WithholdingConfig[] configs = WithholdingConfig.getConfig(bp, true, order.get_TrxName(), order, order.getDateOrdered());
        deleteWhithholdingLine(order);
        // Se crean las líneas de percepción
        for (int i = 0; i < configs.length; i++) {
            final WithholdingConfig wc = configs[i];
            log.info("Withholding conf >> " + wc);
            // Calcula el subtotal y el importe de la percepción
            BigDecimal taxAmt = BigDecimal.ZERO;
            BigDecimal gravado = BigDecimal.ZERO;
            BigDecimal base = BigDecimal.ZERO;
            BigDecimal perceptionAmt = BigDecimal.ZERO;
            for (MOrderTax tax : order.getTaxes(true)) {
                taxAmt = taxAmt.add(tax.getTaxAmt());
            }
            // Acumula la base imponible para calcular la Percepción de IIBB
            for (MOrderLine oline : order.getLines()) gravado = gravado.add(oline.getLineNetAmt());
            if (wc.getBaseType().equals(X_LCO_WithholdingCalc.BASETYPE_Tax))
                base = taxAmt;
            else if (wc.getBaseType().equals(X_LCO_WithholdingCalc.BASETYPE_Document))
                base = gravado;
            else // @fchiappano utilizar como base de calculo, el GranTotal de la Orden.
            if (wc.getBaseType().equals("G"))
                base = order.getGrandTotal();
            /*
                 * @mzuniga: No se tiene en cuenta la condición de IVA del SdN ya que en las
                 * Configuraciones de las percepciones se realiza una entrada para el neto del
                 * documento y otra para el impuesto. Esto permite utilizar los importes base
                 * mínimos para el cálculo.
                 */
            perceptionAmt = (((base.multiply(wc.getAliquot())).divide(new BigDecimal(100))).setScale(2, BigDecimal.ROUND_HALF_UP)).abs();
            // de la Perceción debe quedar en 0 (cero).
            if (base.compareTo(wc.getThresholdMin()) <= 0)
                perceptionAmt = Env.ZERO;
            // Crea la percepción de la orden
            // Si existe recupera la línea anterior y acumula el importe de la percepción.
            MLAROrderPerception perception = MLAROrderPerception.get(order, order.get_TrxName());
            perception.setC_Order_ID(order.get_ID());
            perception.setC_Tax_ID(wc.getC_Tax_ID());
            perception.setLCO_WithholdingRule_ID(wc.getWithholdingRule_ID());
            perception.setLCO_WithholdingType_ID(wc.getWithholdingType_ID());
            // Se acumula el importe
            perception.setTaxAmt(perception.getTaxAmt().add(perceptionAmt));
            perception.setTaxBaseAmt(perception.getTaxBaseAmt().add(base));
            perception.setIsTaxIncluded(false);
            if (!perception.save()) {
                return "Error al craer percepción";
            }
            // Update order amounts
            if (!order.save()) {
                return "Error al intentar actualizar los importes de la orden";
            }
        }
    // Fin recorrido configuraciones
    }
    return null;
}
Also used : MOrder(org.compiere.model.MOrder) MPOS(org.compiere.model.MPOS) MOrderTax(org.compiere.model.MOrderTax) MOrderLine(org.compiere.model.MOrderLine) BigDecimal(java.math.BigDecimal)

Aggregations

MOrderLine (org.compiere.model.MOrderLine)87 BigDecimal (java.math.BigDecimal)44 MOrder (org.compiere.model.MOrder)42 MInOutLine (org.compiere.model.MInOutLine)16 MProduct (org.compiere.model.MProduct)15 MBPartner (org.compiere.model.MBPartner)14 MInOut (org.compiere.model.MInOut)11 ResultSet (java.sql.ResultSet)10 ArrayList (java.util.ArrayList)8 Query (org.compiere.model.Query)8 PreparedStatement (java.sql.PreparedStatement)7 MInvoice (org.compiere.model.MInvoice)7 MInvoiceLine (org.compiere.model.MInvoiceLine)7 AdempiereException (org.adempiere.exceptions.AdempiereException)6 SQLException (java.sql.SQLException)5 MLocator (org.compiere.model.MLocator)5 Timestamp (java.sql.Timestamp)4 MRMALine (org.compiere.model.MRMALine)4 MBPartnerLocation (org.compiere.model.MBPartnerLocation)3 MDocType (org.compiere.model.MDocType)3