Search in sources :

Example 1 with MTax

use of org.compiere.model.MTax in project adempiere by adempiere.

the class Doc_Invoice method loadLines.

//	loadTaxes
/**
	 *	Load Invoice Line
	 *	@param invoice invoice
	 *  @return DocLine Array
	 */
private DocLine[] loadLines(MInvoice invoice) {
    ArrayList<DocLine> list = new ArrayList<DocLine>();
    //
    MInvoiceLine[] lines = invoice.getLines(false);
    for (int i = 0; i < lines.length; i++) {
        MInvoiceLine line = lines[i];
        if (line.isDescription())
            continue;
        DocLine docLine = new DocLine(line, this);
        //	Qty
        BigDecimal Qty = line.getQtyInvoiced();
        boolean cm = getDocumentType().equals(DOCTYPE_ARCredit) || getDocumentType().equals(DOCTYPE_APCredit);
        docLine.setQty(cm ? Qty.negate() : Qty, invoice.isSOTrx());
        //
        BigDecimal LineNetAmt = line.getLineNetAmt();
        BigDecimal PriceList = line.getPriceList();
        int C_Tax_ID = docLine.getC_Tax_ID();
        //	Correct included Tax
        if (isTaxIncluded() && C_Tax_ID != 0) {
            MTax tax = MTax.get(getCtx(), C_Tax_ID);
            if (!tax.isZeroTax()) {
                BigDecimal LineNetAmtTax = tax.calculateTax(LineNetAmt, true, getStdPrecision());
                log.fine("LineNetAmt=" + LineNetAmt + " - Tax=" + LineNetAmtTax);
                LineNetAmt = LineNetAmt.subtract(LineNetAmtTax);
                for (int t = 0; t < m_taxes.length; t++) {
                    if (m_taxes[t].getC_Tax_ID() == C_Tax_ID) {
                        m_taxes[t].addIncludedTax(LineNetAmtTax);
                        break;
                    }
                }
                BigDecimal PriceListTax = tax.calculateTax(PriceList, true, getStdPrecision());
                PriceList = PriceList.subtract(PriceListTax);
            }
        }
        //	correct included Tax
        //	qty for discount calc
        docLine.setAmount(LineNetAmt, PriceList, Qty);
        if (docLine.isItem())
            m_allLinesService = false;
        else
            m_allLinesItem = false;
        //
        log.fine(docLine.toString());
        list.add(docLine);
    }
    //	Convert to Array
    DocLine[] dls = new DocLine[list.size()];
    list.toArray(dls);
    //	Included Tax - make sure that no difference
    if (isTaxIncluded()) {
        for (int i = 0; i < m_taxes.length; i++) {
            if (m_taxes[i].isIncludedTaxDifference()) {
                BigDecimal diff = m_taxes[i].getIncludedTaxDifference();
                for (int j = 0; j < dls.length; j++) {
                    if (dls[j].getC_Tax_ID() == m_taxes[i].getC_Tax_ID()) {
                        dls[j].setLineNetAmtDifference(diff);
                        break;
                    }
                }
            //	for all lines
            }
        //	tax difference
        }
    //	for all taxes
    }
    //	Return Array
    return dls;
}
Also used : MInvoiceLine(org.compiere.model.MInvoiceLine) ArrayList(java.util.ArrayList) MTax(org.compiere.model.MTax) BigDecimal(java.math.BigDecimal)

Example 2 with MTax

use of org.compiere.model.MTax in project adempiere by adempiere.

the class Doc_Order method loadLines.

//  loadDocumentDetails
/**
	 *	Load Invoice Line
	 *	@param order order
	 *  @return DocLine Array
	 */
private DocLine[] loadLines(MOrder order) {
    ArrayList<DocLine> list = new ArrayList<DocLine>();
    MOrderLine[] lines = order.getLines();
    for (int i = 0; i < lines.length; i++) {
        MOrderLine line = lines[i];
        DocLine docLine = new DocLine(line, this);
        BigDecimal Qty = line.getQtyOrdered();
        docLine.setQty(Qty, order.isSOTrx());
        //
        BigDecimal PriceActual = line.getPriceActual();
        BigDecimal PriceCost = null;
        if (//	PO
        getDocumentType().equals(DOCTYPE_POrder))
            PriceCost = line.getPriceCost();
        BigDecimal LineNetAmt = null;
        if (PriceCost != null && PriceCost.signum() != 0)
            LineNetAmt = Qty.multiply(PriceCost);
        else
            LineNetAmt = line.getLineNetAmt();
        //	DR
        docLine.setAmount(LineNetAmt);
        BigDecimal PriceList = line.getPriceList();
        int C_Tax_ID = docLine.getC_Tax_ID();
        //	Correct included Tax
        if (isTaxIncluded() && C_Tax_ID != 0) {
            MTax tax = MTax.get(getCtx(), C_Tax_ID);
            if (!tax.isZeroTax()) {
                BigDecimal LineNetAmtTax = tax.calculateTax(LineNetAmt, true, getStdPrecision());
                log.fine("LineNetAmt=" + LineNetAmt + " - Tax=" + LineNetAmtTax);
                LineNetAmt = LineNetAmt.subtract(LineNetAmtTax);
                for (int t = 0; t < m_taxes.length; t++) {
                    if (m_taxes[t].getC_Tax_ID() == C_Tax_ID) {
                        m_taxes[t].addIncludedTax(LineNetAmtTax);
                        break;
                    }
                }
                BigDecimal PriceListTax = tax.calculateTax(PriceList, true, getStdPrecision());
                PriceList = PriceList.subtract(PriceListTax);
            }
        }
        //	correct included Tax
        docLine.setAmount(LineNetAmt, PriceList, Qty);
        list.add(docLine);
    }
    //	Return Array
    DocLine[] dl = new DocLine[list.size()];
    list.toArray(dl);
    return dl;
}
Also used : ArrayList(java.util.ArrayList) MTax(org.compiere.model.MTax) MOrderLine(org.compiere.model.MOrderLine) BigDecimal(java.math.BigDecimal)

Example 3 with MTax

use of org.compiere.model.MTax in project adempiere by adempiere.

the class Doc_Order method getCommitments.

//	updateProductPO
/**
	 * 	Get Commitments
	 * 	@param doc document
	 * 	@param maxQty Qty invoiced/matched
	 * 	@param C_InvoiceLine_ID invoice line
	 *	@return commitments (order lines)
	 */
protected static DocLine[] getCommitments(Doc doc, BigDecimal maxQty, int C_InvoiceLine_ID) {
    int precision = -1;
    //
    ArrayList<DocLine> list = new ArrayList<DocLine>();
    String sql = "SELECT * FROM C_OrderLine ol " + "WHERE EXISTS " + "(SELECT * FROM C_InvoiceLine il " + "WHERE il.C_OrderLine_ID=ol.C_OrderLine_ID" + " AND il.C_InvoiceLine_ID=?)" + " OR EXISTS " + "(SELECT * FROM M_MatchPO po " + "WHERE po.C_OrderLine_ID=ol.C_OrderLine_ID" + " AND po.C_InvoiceLine_ID=?)";
    PreparedStatement pstmt = null;
    ResultSet rs = null;
    try {
        pstmt = DB.prepareStatement(sql, null);
        pstmt.setInt(1, C_InvoiceLine_ID);
        pstmt.setInt(2, C_InvoiceLine_ID);
        rs = pstmt.executeQuery();
        while (rs.next()) {
            if (maxQty.signum() == 0)
                continue;
            MOrderLine line = new MOrderLine(doc.getCtx(), rs, null);
            DocLine docLine = new DocLine(line, doc);
            //	Currency
            if (precision == -1) {
                doc.setC_Currency_ID(docLine.getC_Currency_ID());
                precision = MCurrency.getStdPrecision(doc.getCtx(), docLine.getC_Currency_ID());
            }
            //	Qty
            BigDecimal Qty = line.getQtyOrdered().max(maxQty);
            docLine.setQty(Qty, false);
            //
            BigDecimal PriceActual = line.getPriceActual();
            BigDecimal PriceCost = line.getPriceCost();
            BigDecimal LineNetAmt = null;
            if (PriceCost != null && PriceCost.signum() != 0)
                LineNetAmt = Qty.multiply(PriceCost);
            else if (Qty.equals(maxQty))
                LineNetAmt = line.getLineNetAmt();
            else
                LineNetAmt = Qty.multiply(PriceActual);
            maxQty = maxQty.subtract(Qty);
            //	DR
            docLine.setAmount(LineNetAmt);
            BigDecimal PriceList = line.getPriceList();
            int C_Tax_ID = docLine.getC_Tax_ID();
            //	Correct included Tax
            if (C_Tax_ID != 0 && line.getParent().isTaxIncluded()) {
                MTax tax = MTax.get(doc.getCtx(), C_Tax_ID);
                if (!tax.isZeroTax()) {
                    BigDecimal LineNetAmtTax = tax.calculateTax(LineNetAmt, true, precision);
                    s_log.fine("LineNetAmt=" + LineNetAmt + " - Tax=" + LineNetAmtTax);
                    LineNetAmt = LineNetAmt.subtract(LineNetAmtTax);
                    BigDecimal PriceListTax = tax.calculateTax(PriceList, true, precision);
                    PriceList = PriceList.subtract(PriceListTax);
                }
            }
            //	correct included Tax
            docLine.setAmount(LineNetAmt, PriceList, Qty);
            list.add(docLine);
        }
    } catch (Exception e) {
        s_log.log(Level.SEVERE, sql, e);
    } finally {
        DB.close(rs, pstmt);
        rs = null;
        pstmt = null;
    }
    //	Return Array
    DocLine[] dl = new DocLine[list.size()];
    list.toArray(dl);
    return dl;
}
Also used : ArrayList(java.util.ArrayList) ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement) MTax(org.compiere.model.MTax) MOrderLine(org.compiere.model.MOrderLine) BigDecimal(java.math.BigDecimal) SQLException(java.sql.SQLException)

Example 4 with MTax

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

the class LCO_CalloutWithholding method fillPercentFromTax.

// fillIsUse
// Called from LCO_InvoiceWithholding.C_Tax_ID
public String fillPercentFromTax(Properties ctx, int WindowNo, GridTab mTab, GridField mField, Object value, Object oldValue) {
    log.info("");
    int taxint = 0;
    BigDecimal percent = null;
    if (value != null)
        taxint = ((Integer) value).intValue();
    if (taxint != 0) {
        MTax tax = new MTax(ctx, taxint, null);
        percent = tax.getRate();
    }
    mTab.setValue(MLCOInvoiceWithholding.COLUMNNAME_Percent, percent);
    return recalc_taxamt(ctx, WindowNo, mTab, mField, value, oldValue);
}
Also used : MTax(org.compiere.model.MTax) BigDecimal(java.math.BigDecimal)

Example 5 with MTax

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

the class WsfeV1 method createInputFile.

/**
 * @author: Horacio Alvarez
 * @descripcion: Crea el archivo de entrada para el WSFE.PY.
 * Setea los valores necesarios con el objeto MInvoice.
 */
@Override
protected void createInputFile() {
    try {
        StringBuffer line = new StringBuffer();
        // *****NRO. COMPROBANTE
        if (this.getInvoice().getNumeroComprobante() == 0) {
            this.setMessageError(Msg.translate(this.getM_ctx(), "CaeNoNumeroComprobante"));
            return;
        }
        line.append(this.getInvoice().getNumeroComprobante() + "\n");
        // *****PUNTO DE VENTA
        final MPOS pos = new MPOS(getM_ctx(), this.getInvoice().get_ValueAsInt("C_Pos_ID"), getTrxName());
        if (pos.get_ValueAsInt("PosNumber") == 0) {
            this.setMessageError(Msg.translate(this.getM_ctx(), "CaeNoPuntoDeVenta"));
            return;
        }
        line.append(pos.get_ValueAsInt("PosNumber") + "\n");
        // *****TIPO DE COMPROBANTE
        MDocType docType = new MDocType(Env.getCtx(), this.getInvoice().getC_DocTypeTarget_ID(), getTrxName());
        line.append(docType.getdocsubtypecae() + "\n");
        // *****TIPO DOC: 80 CUIT / 96 DNI
        MBPartner partner = new MBPartner(this.getM_ctx(), this.getInvoice().getC_BPartner_ID(), getTrxName());
        final X_LCO_TaxPayerType taxPayerType = new X_LCO_TaxPayerType(getM_ctx(), partner.get_ValueAsInt("LCO_TaxPayerType_ID"), getTrxName());
        if (taxPayerType.getName().equals("ConsumidorFinal")) {
            line.append("96" + "\n");
            line.append("1" + "\n");
        } else {
            line.append("80" + "\n");
            if (partner.getTaxID() == null || partner.getTaxID().equals("")) {
                this.setMessageError(Msg.translate(this.getM_ctx(), "CaeNoCUIT"));
                return;
            }
            line.append(partner.getTaxID().replaceAll("-", "") + "\n");
        }
        // *****IMPORTE TOTAL
        // line.append(this.getInvoice().getGrandTotal().toString().replace(".", "")+"\n");
        line.append(this.getInvoice().getGrandTotal().setScale(2, BigDecimal.ROUND_HALF_UP) + "\n");
        // *****IMPORTE NETO
        // line.append(this.getInvoice().getTotalLines().toString().replace(".", "")+"\n");
        line.append(this.getInvoice().getTotalLines().setScale(2, BigDecimal.ROUND_HALF_UP) + "\n");
        // *****FECHA
        if (this.getInvoice().getDateAcct() == null) {
            this.setMessageError(Msg.translate(this.getM_ctx(), "CaeNoDateAcct"));
            return;
        }
        line.append(formatTime(this.getInvoice().getDateAcct(), "yyyyMMdd") + "\n");
        // *****PRESTA SERVICIOS 0-->NO  1-->SI
        line.append(MSysConfig.getValue("LAR_PrestaServicios_FE", Env.getAD_Client_ID(Env.getCtx())) + "\n");
        // *****MONEDA
        MCurrency currency = new MCurrency(this.getM_ctx(), this.getInvoice().getC_Currency_ID(), getTrxName());
        line.append(currency.get_ValueAsString("WSFECode") + "\n");
        // *****CONVERSION
        // Se debe convertir a la moneda del comprobante desde la moneda de la compañía
        BigDecimal cotizacion = MCurrency.currencyConvert(Env.ONE, Env.getContextAsInt(this.getM_ctx(), "$C_Currency_ID"), this.getInvoice().getC_Currency_ID(), this.getInvoice().getDateInvoiced(), 0, this.getM_ctx());
        line.append(cotizacion + "\n");
        // *****IMPUESTO
        BigDecimal total_Impuesto = BigDecimal.ZERO;
        MInvoiceTax[] taxes = this.getInvoice().getTaxes(false);
        MTax tax = null;
        int size = taxes.length;
        boolean firstLineAppended = false;
        for (int i = 0; i < size; i++) {
            tax = MTax.get(this.getM_ctx(), taxes[i].getC_Tax_ID());
            if (!tax.get_ValueAsBoolean("IsPerception")) {
                total_Impuesto = total_Impuesto.add(taxes[i].getTaxAmt().setScale(2, BigDecimal.ROUND_HALF_UP));
                taxes[i].getTaxAmt();
                taxes[i].getTaxBaseAmt();
                tax.get_ValueAsString("WSFECode");
                if (firstLineAppended) {
                    line.append(";");
                }
                line.append(tax.get_ValueAsString("WSFECode") + ":" + (getTaxBaseAmt(taxes[i].getTaxBaseAmt(), this.getInvoice().getGrandTotal(), getTaxesAmt(this.getInvoice()))).setScale(2, BigDecimal.ROUND_HALF_UP) + ":" + taxes[i].getTaxAmt().setScale(2, BigDecimal.ROUND_HALF_UP));
                firstLineAppended = true;
            }
        }
        line.append("\n");
        // *****MONTO TOTAL DE IMPUESTOS
        line.append(total_Impuesto + "\n");
        // *****IMPUESTOS PERCEPCIONES
        BigDecimal total_Perception = BigDecimal.ZERO;
        MInvoiceTax[] taxesPerc = this.getInvoice().getTaxes(true);
        MTax taxPerc = null;
        int sizePerc = taxesPerc.length;
        boolean firstLineAppended2 = false;
        for (int i = 0; i < sizePerc; i++) {
            taxPerc = MTax.get(this.getM_ctx(), taxesPerc[i].getC_Tax_ID());
            if (taxPerc.get_ValueAsBoolean("IsPerception")) {
                total_Perception = total_Perception.add(taxesPerc[i].getTaxAmt().setScale(2, BigDecimal.ROUND_HALF_UP));
                taxesPerc[i].getTaxAmt();
                taxesPerc[i].getTaxBaseAmt();
                taxPerc.get_ValueAsInt("WSFECode");
                if (firstLineAppended2) {
                    line.append(";");
                }
                BigDecimal alic = (taxPerc.getRate().setScale(2, BigDecimal.ROUND_HALF_UP)).negate();
                line.append(taxPerc.get_ValueAsInt("WSFECode") + ":" + (getTaxBaseAmt(taxesPerc[i].getTaxBaseAmt(), this.getInvoice().getGrandTotal(), getTaxesAmt(this.getInvoice()))).setScale(2, BigDecimal.ROUND_HALF_UP) + ":" + taxesPerc[i].getTaxAmt().setScale(2, BigDecimal.ROUND_HALF_UP) + ":" + alic);
                firstLineAppended2 = true;
            }
        }
        if (total_Perception.equals(Env.ZERO))
            line.append("0");
        line.append("\n");
        // *****MONTO TOTAL DE PERCEPCIONES
        line.append(total_Perception + "\n");
        // *****C_INVOICE_ID para seguimiento
        line.append(this.getInvoice().getC_Invoice_ID() + "\n");
        File textFile = new File(getPath() + "entrada.txt");
        FileWriter textOut;
        textOut = new FileWriter(textFile);
        textOut.write(line.toString());
        textOut.close();
    } catch (Exception ex) {
        this.setMessageError(Msg.translate(this.getM_ctx(), "caeErrorCreateInputFile"));
        log.log(Level.SEVERE, this.getMessageError(), ex);
    }
}
Also used : MDocType(org.compiere.model.MDocType) MPOS(org.compiere.model.MPOS) MCurrency(org.compiere.model.MCurrency) FileWriter(java.io.FileWriter) MBPartner(org.compiere.model.MBPartner) BigDecimal(java.math.BigDecimal) X_LCO_TaxPayerType(org.globalqss.model.X_LCO_TaxPayerType) MTax(org.compiere.model.MTax) MInvoiceTax(org.compiere.model.MInvoiceTax) File(java.io.File)

Aggregations

BigDecimal (java.math.BigDecimal)11 MTax (org.compiere.model.MTax)11 ArrayList (java.util.ArrayList)6 PreparedStatement (java.sql.PreparedStatement)5 ResultSet (java.sql.ResultSet)5 SQLException (java.sql.SQLException)5 MBPartner (org.compiere.model.MBPartner)3 MDocType (org.compiere.model.MDocType)3 MOrderLine (org.compiere.model.MOrderLine)3 MBPartnerLocation (org.compiere.model.MBPartnerLocation)2 MInvoiceLine (org.compiere.model.MInvoiceLine)2 MInvoiceTax (org.compiere.model.MInvoiceTax)2 MLocation (org.compiere.model.MLocation)2 MOrgInfo (org.compiere.model.MOrgInfo)2 MPayment (org.compiere.model.MPayment)2 X_LCO_WithholdingType (org.globalqss.model.X_LCO_WithholdingType)2 DiscountLine (ar.com.ergio.print.fiscal.document.DiscountLine)1 DocumentLine (ar.com.ergio.print.fiscal.document.DocumentLine)1 PerceptionLine (ar.com.ergio.print.fiscal.document.PerceptionLine)1 File (java.io.File)1