Search in sources :

Example 41 with MInvoiceLine

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

the class FiscalDocumentPrint method loadShipmentOrderNumbers.

/**
 * Retrieve shipment and sales order numbers, if they exists.
 *
 * @param mInvoice ADempiere invoice document
 * @param document fiscal printer document
 */
private void loadShipmentOrderNumbers(final MInvoice mInvoice, final Invoice document) {
    final I_C_Order order = mInvoice.getC_Order();
    if (order.getC_Order_ID() > 0)
        document.addObservation(Msg.translate(ctx, "C_Order_ID") + ": " + order.getDocumentNo());
    final MInvoiceLine[] iLines = mInvoice.getLines();
    for (final MInvoiceLine line : iLines) {
        final I_M_InOutLine ioline = line.getM_InOutLine();
        if (ioline.getM_InOutLine_ID() > 0) {
            String obs = ioline.getM_InOut().getDocumentNo();
            if (!document.getObservations().contains(obs))
                document.addObservation(obs);
        }
    }
}
Also used : I_C_Order(org.compiere.model.I_C_Order) MInvoiceLine(org.compiere.model.MInvoiceLine) I_M_InOutLine(org.compiere.model.I_M_InOutLine)

Example 42 with MInvoiceLine

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

the class FiscalDocumentPrint method loadDocumentLines.

// loadDNFHLines
/**
 * Carga las líneas que se encuentran en el documento de ADempiere hacia
 * el documento de impresoras fiscales.
 * @param mInvoice Documento de ADempiere.
 * @param document Documento de impresoras fiscales.
 */
private void loadDocumentLines(final MInvoice mInvoice, final Document document) {
    // Se obtiene el indicador de si los precios contienen los impuestos incluido
    boolean taxIncluded = MPriceList.get(ctx, mInvoice.getM_PriceList_ID(), getTrxName()).isTaxIncluded();
    // Se obtiene el redondeo para precios de la moneda de la factura
    // int scale = MCurrency.get(oxpDocument.getCtx(), oxpDocument.getC_Currency_ID()).getCostingPrecision();
    MInvoiceLine[] lines = mInvoice.getLines();
    BigDecimal totalLineAmt = BigDecimal.ZERO;
    // String description = "";
    for (int i = 0; i < lines.length; i++) {
        MInvoiceLine mLine = lines[i];
        BigDecimal qtyEntered = mLine.getQtyEntered();
        // @emmie - avoid "special" invoice lines (as shipments comments lines)
        if (qtyEntered.compareTo(BigDecimal.ZERO) > 0) {
            DocumentLine docLine = new DocumentLine();
            docLine.setLineNumber(mLine.getLine());
            docLine.setDescription(manageLineDescription(docLine, mLine));
            // TODO - Review discounts at invoice behavior
            // Calcula el precio unitario de la línea.
            // Aquí tenemos dos casos de línea: Con Bonificaciones o Sin
            // Bonificaciones
            // 1. Sin Bonificaciones
            // El precio unitario es entonces simplemente el precio actual
            // de la
            // línea, es decir el PriceActual.
            // if (!mLine.hasBonus()) {
            BigDecimal unitPrice = mLine.getPriceActual();
            totalLineAmt = totalLineAmt.add(unitPrice);
            // } else {
            // 2. Con Bonificaciones
            // Aquí NO se puede utilizar el mLine.getPriceActual() ya que el
            // mismo tiene contemplado las bonificaciones mientras que en la
            // impresión del ticket, las bonificaciones se restan al final
            // del mismo. De esta forma, el precio unitario para el ticket
            // va a ser mayor que el PriceActual de la línea en caso de que
            // la misma contenga bonificaciones.
            // El cálculo a realizar es:
            // (PriceList * Qty - LineDiscountAmt) / Qty
            // 
            // unitPrice =
            // (mLine.getPriceList().multiply(mLine.getQtyEntered())
            // .subtract(mLine.getLineDiscountAmt())).divide(
            // mLine.getQtyEntered(), scale, RoundingMode.HALF_UP);
            // }
            // LAR - Process discount for invoice
            final I_C_OrderLine ol = mLine.getC_OrderLine();
            final BigDecimal discountRate = ol.getDiscount();
            if (discountRate.compareTo(BigDecimal.ZERO) > 0) {
                final BigDecimal originalAmt = BigDecimal.valueOf(100).multiply(unitPrice).divide(BigDecimal.valueOf(100).subtract(discountRate), 2, BigDecimal.ROUND_FLOOR);
                final DiscountLine discountLine = new DiscountLine("Dto aplicado", originalAmt.subtract(unitPrice).multiply(mLine.getQtyEntered()), true, false, discountRate);
                // Add discount to document line
                docLine.setDiscount(discountLine);
                // Set proper unitPrice
                unitPrice = originalAmt;
            }
            // LAR - Process discount for invoice
            docLine.setUnitPrice(unitPrice);
            docLine.setQuantity(mLine.getQtyEntered());
            docLine.setPriceIncludeIva(taxIncluded);
            // Se obtiene la tasa del IVA de la línea
            // Se asume que el impuesto es siempre IVA, a futuro se verá
            // que hacer si el producto tiene otro impuesto que no sea IVA.
            MTax mTax = MTax.get(Env.getCtx(), mLine.getC_Tax_ID());
            docLine.setIvaRate(mTax.getRate());
            // Se agrega la línea al documento.
            document.addLine(docLine);
        }
    }
    // TODO - Improve this behavior
    BigDecimal amt = mInvoice.get_Value("WithHoldingAmt") == null ? Env.ZERO : // LAR perception are negative
    ((BigDecimal) mInvoice.get_Value("WithHoldingAmt")).negate();
    if (amt.compareTo(BigDecimal.ZERO) > 0) {
        // TODO Corregir el calculo del porcentaje de percepción.
        // BigDecimal rate = amt.divide(totalLineAmt, 2, BigDecimal.ROUND_HALF_UP).multiply(BigDecimal.valueOf(100));
        // @mzuniga - Se agrega la provincia correspondiente a la Percepción en la descripción de la línea
        String sql = "SELECT l.RegionName FROM AD_OrgInfo oi JOIN C_Location l ON oi.C_Location_ID = l.C_Location_ID WHERE oi.AD_Org_ID=?";
        String prov = DB.getSQLValueString(mInvoice.get_TrxName(), sql, (Integer) mInvoice.get_Value("AD_Org_ID"));
        // String.format("Percepci\u00f3n", rate);
        String desc = "Perc. IIBB " + prov;
        // @mzuniga
        PerceptionLine perceptionLine = new PerceptionLine(desc, amt, null);
        document.setPerceptionLine(perceptionLine);
    }
}
Also used : PerceptionLine(ar.com.ergio.print.fiscal.document.PerceptionLine) MInvoiceLine(org.compiere.model.MInvoiceLine) DocumentLine(ar.com.ergio.print.fiscal.document.DocumentLine) MTax(org.compiere.model.MTax) I_C_OrderLine(org.compiere.model.I_C_OrderLine) DiscountLine(ar.com.ergio.print.fiscal.document.DiscountLine) BigDecimal(java.math.BigDecimal)

Example 43 with MInvoiceLine

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

the class LCO_Validator method modelChange.

// initialize
/**
 *	Model Change of a monitored Table.
 *	Called after PO.beforeSave/PO.beforeDelete
 *	when you called addModelChange for the table
 *	@param po persistent object
 *	@param type TYPE_
 *	@return error message or null
 *	@exception Exception if the recipient wishes the change to be not accept.
 */
public String modelChange(PO po, int type) throws Exception {
    log.info(po.get_TableName() + " Type: " + type);
    String msg;
    if (po.get_TableName().equals(MInvoice.Table_Name) && type == ModelValidator.TYPE_BEFORE_CHANGE) {
        msg = clearInvoiceWithholdingAmtFromInvoice((MInvoice) po);
        if (msg != null)
            return msg;
    }
    // in order to force a regeneration
    if (po.get_TableName().equals(MInvoiceLine.Table_Name) && (type == ModelValidator.TYPE_BEFORE_NEW || type == ModelValidator.TYPE_BEFORE_CHANGE || type == ModelValidator.TYPE_BEFORE_DELETE)) {
        msg = clearInvoiceWithholdingAmtFromInvoiceLine((MInvoiceLine) po, type);
        if (msg != null)
            return msg;
    }
    // Check Digit based on TaxID
    if (po.get_TableName().equals(MBPartner.Table_Name) && (type == TYPE_BEFORE_NEW || type == TYPE_BEFORE_CHANGE)) {
        MBPartner bpartner = (MBPartner) po;
        msg = mcheckTaxIdDigit(bpartner);
        if (msg != null)
            return msg;
        msg = mfillName(bpartner);
        if (msg != null)
            return msg;
    }
    if (po.get_TableName().equals(X_LCO_TaxIdType.Table_Name) && (type == TYPE_BEFORE_NEW || type == TYPE_BEFORE_CHANGE)) {
        X_LCO_TaxIdType taxidtype = (X_LCO_TaxIdType) po;
        if ((!taxidtype.isUseTaxIdDigit()) && taxidtype.isDigitChecked())
            taxidtype.setIsDigitChecked(false);
    }
    if (po.get_TableName().equals(X_LCO_WithholdingCalc.Table_Name) && (type == ModelValidator.TYPE_BEFORE_CHANGE || type == ModelValidator.TYPE_BEFORE_NEW)) {
        X_LCO_WithholdingCalc lwc = (X_LCO_WithholdingCalc) po;
        if (lwc.isCalcOnInvoice() && lwc.isCalcOnPayment())
            lwc.setIsCalcOnPayment(false);
    }
    return null;
}
Also used : MInvoiceLine(org.compiere.model.MInvoiceLine) MInvoice(org.compiere.model.MInvoice) MBPartner(org.compiere.model.MBPartner)

Example 44 with MInvoiceLine

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

the class InvoiceGenerateRMA method generateInvoice.

private void generateInvoice(int M_RMA_ID) {
    MRMA rma = new MRMA(getCtx(), M_RMA_ID, get_TrxName());
    MInvoice invoice = createInvoice(rma);
    MInvoiceLine[] invoiceLines = createInvoiceLines(rma, invoice);
    if (invoiceLines.length == 0) {
        log.log(Level.WARNING, "No invoice lines created: M_RMA_ID=" + M_RMA_ID + ", M_Invoice_ID=" + invoice.get_ID());
    }
    StringBuffer processMsg = new StringBuffer(invoice.getDocumentNo());
    if (!invoice.processIt(p_docAction)) {
        processMsg.append(" (NOT Processed)");
        log.warning("Invoice Processing failed: " + invoice + " - " + invoice.getProcessMsg());
        throw new IllegalStateException("Invoice Processing failed: " + invoice + " - " + invoice.getProcessMsg());
    }
    if (!invoice.save()) {
        throw new IllegalStateException("Could not update invoice");
    } else // @fchiappano Impresion Fiscal, si se completa la factura.
    {
        if (p_docAction.equals(MInvoice.DOCACTION_Complete) && LAR_Utils.isFiscalDocType(invoice.getC_DocType_ID())) {
            final InvoiceFiscalDocumentPrintManager manager = new InvoiceFiscalDocumentPrintManager(invoice);
            manager.print();
        }
    }
    // Add processing information to process log
    addLog(invoice.getC_Invoice_ID(), invoice.getDateInvoiced(), null, invoice.getDocumentNo());
    m_created++;
}
Also used : InvoiceFiscalDocumentPrintManager(ar.com.ergio.print.fiscal.view.InvoiceFiscalDocumentPrintManager) MInvoiceLine(org.compiere.model.MInvoiceLine) MInvoice(org.compiere.model.MInvoice) MRMA(org.compiere.model.MRMA)

Aggregations

MInvoiceLine (org.compiere.model.MInvoiceLine)44 MInvoice (org.compiere.model.MInvoice)27 BigDecimal (java.math.BigDecimal)16 MInOutLine (org.compiere.model.MInOutLine)10 MBPartner (org.compiere.model.MBPartner)9 MProduct (org.compiere.model.MProduct)8 MOrderLine (org.compiere.model.MOrderLine)7 MRMALine (org.compiere.model.MRMALine)7 MLocation (org.compiere.model.MLocation)6 ArrayList (java.util.ArrayList)5 MDocType (org.compiere.model.MDocType)5 MClient (org.compiere.model.MClient)4 MInOut (org.compiere.model.MInOut)4 PreparedStatement (java.sql.PreparedStatement)3 ResultSet (java.sql.ResultSet)3 AdempiereException (org.adempiere.exceptions.AdempiereException)3 MTax (org.compiere.model.MTax)3 SQLException (java.sql.SQLException)2 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)2 FillMandatoryException (org.adempiere.exceptions.FillMandatoryException)2