Search in sources :

Example 6 with MInvoiceLine

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

the class SB_InvoiceGenerateFromOrderLine method createLine.

//	generate
/**************************************************************************
	 * 	Create Invoice Line from Order Line
	 *	@param order order
	 *	@param orderLine line
	 *	@param qtyInvoiced qty
	 *	@param qtyEntered qty
	 */
private void createLine(MOrder order, MOrderLine orderLine, BigDecimal qtyInvoiced, BigDecimal qtyEntered) {
    if (m_invoice == null) {
        m_invoice = new MInvoice(order, 0, p_DateInvoiced);
        if (!m_invoice.save())
            throw new IllegalStateException("Could not create Invoice (o)");
    }
    //	
    MInvoiceLine line = new MInvoiceLine(m_invoice);
    line.setOrderLine(orderLine);
    line.setQtyInvoiced(qtyInvoiced);
    line.setQtyEntered(qtyEntered);
    line.setLine(m_line + orderLine.getLine());
    if (!line.save())
        throw new IllegalStateException("Could not create Invoice Line (o)");
    log.fine(line.toString());
}
Also used : MInvoiceLine(org.compiere.model.MInvoiceLine) MInvoice(org.compiere.model.MInvoice)

Example 7 with MInvoiceLine

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

the class InOutGenerateRMA method createShipmentLines.

private MInOutLine[] createShipmentLines(MRMA rma, MInOut shipment) {
    ArrayList<MInOutLine> shipLineList = new ArrayList<MInOutLine>();
    MRMALine[] rmaLines = rma.getLines(true);
    for (MRMALine rmaLine : rmaLines) {
        if (rmaLine.getM_InOutLine_ID() != 0) {
            MInOutLine shipLine = new MInOutLine(shipment);
            shipLine.setM_RMALine_ID(rmaLine.get_ID());
            shipLine.setLine(rmaLine.getLine());
            shipLine.setDescription(rmaLine.getDescription());
            shipLine.setM_Product_ID(rmaLine.getM_Product_ID());
            shipLine.setM_AttributeSetInstance_ID(rmaLine.getM_AttributeSetInstance_ID());
            shipLine.setC_UOM_ID(rmaLine.getC_UOM_ID());
            shipLine.setQty(rmaLine.getQty());
            shipLine.setM_Locator_ID(rmaLine.getM_Locator_ID());
            shipLine.setC_Project_ID(rmaLine.getC_Project_ID());
            shipLine.setC_Campaign_ID(rmaLine.getC_Campaign_ID());
            shipLine.setC_Activity_ID(rmaLine.getC_Activity_ID());
            shipLine.setC_ProjectPhase_ID(rmaLine.getC_ProjectPhase_ID());
            shipLine.setC_ProjectTask_ID(rmaLine.getC_ProjectTask_ID());
            shipLine.setUser1_ID(rmaLine.getUser1_ID());
            shipLine.setUser2_ID(rmaLine.getUser2_ID());
            shipLine.setUser3_ID(rmaLine.getUser3_ID());
            shipLine.setUser4_ID(rmaLine.getUser4_ID());
            shipLine.saveEx();
            shipLineList.add(shipLine);
            //
            // Link to corresponding Invoice Line (if any) - teo_sarca [ 2818523 ]
            // The MMatchInv records will be automatically generated on MInOut.completeIt()
            MInvoiceLine invoiceLine = new Query(shipment.getCtx(), I_C_InvoiceLine.Table_Name, I_C_InvoiceLine.COLUMNNAME_M_RMALine_ID + "=?", shipment.get_TrxName()).setParameters(rmaLine.getM_RMALine_ID()).firstOnly();
            if (invoiceLine != null) {
                invoiceLine.setM_InOutLine_ID(shipLine.getM_InOutLine_ID());
                invoiceLine.saveEx();
            }
        }
    }
    MInOutLine[] shipLines = new MInOutLine[shipLineList.size()];
    shipLineList.toArray(shipLines);
    return shipLines;
}
Also used : Query(org.compiere.model.Query) MInOutLine(org.compiere.model.MInOutLine) MInvoiceLine(org.compiere.model.MInvoiceLine) ArrayList(java.util.ArrayList) MRMALine(org.compiere.model.MRMALine)

Example 8 with MInvoiceLine

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

the class InvoiceGenerateRMA method createInvoiceLines.

private MInvoiceLine[] createInvoiceLines(MRMA rma, MInvoice invoice) {
    ArrayList<MInvoiceLine> invLineList = new ArrayList<MInvoiceLine>();
    MRMALine[] rmaLines = rma.getLines(true);
    for (MRMALine rmaLine : rmaLines) {
        if (rmaLine.getM_InOutLine_ID() == 0) {
            throw new IllegalStateException("No customer return line - RMA = " + rma.getDocumentNo() + ", Line = " + rmaLine.getLine());
        }
        MInvoiceLine invLine = new MInvoiceLine(invoice);
        invLine.setRMALine(rmaLine);
        if (!invLine.save()) {
            throw new IllegalStateException("Could not create invoice line");
        }
        invLineList.add(invLine);
    }
    MInvoiceLine[] invLines = new MInvoiceLine[invLineList.size()];
    invLineList.toArray(invLines);
    return invLines;
}
Also used : MInvoiceLine(org.compiere.model.MInvoiceLine) ArrayList(java.util.ArrayList) MRMALine(org.compiere.model.MRMALine)

Example 9 with MInvoiceLine

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

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());
    }
    if (!invoice.save()) {
        throw new IllegalStateException("Could not update invoice");
    }
    // Add processing information to process log
    addLog(invoice.getC_Invoice_ID(), invoice.getDateInvoiced(), null, processMsg.toString());
    m_created++;
}
Also used : MInvoiceLine(org.compiere.model.MInvoiceLine) MInvoice(org.compiere.model.MInvoice) MRMA(org.compiere.model.MRMA)

Example 10 with MInvoiceLine

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

the class CreateFromShipment method save.

/**
	 *  Save - Create Invoice Lines
	 *  @return true if saved
	 */
public boolean save(IMiniTable miniTable, String trxName) {
    /*
		dataTable.stopEditor(true);
		log.config("");
		TableModel model = dataTable.getModel();
		int rows = model.getRowCount();
		if (rows == 0)
			return false;
		//
		Integer defaultLoc = (Integer) locatorField.getValue();
		if (defaultLoc == null || defaultLoc.intValue() == 0) {
			locatorField.setBackground(AdempierePLAF.getFieldBackground_Error());
			return false;
		}
		*/
    int M_Locator_ID = defaultLocator_ID;
    if (M_Locator_ID == 0) {
        return false;
    }
    // Get Shipment
    MInOut inout = new MInOut(Env.getCtx(), m_Record_ID, trxName);
    log.config(inout + ", C_Locator_ID=" + M_Locator_ID);
    // Lines
    for (int i = 0; i < miniTable.getRowCount(); i++) {
        if (((Boolean) miniTable.getValueAt(i, 0)).booleanValue()) {
            // variable values
            // Qty
            BigDecimal QtyEntered = (BigDecimal) miniTable.getValueAt(i, 1);
            // UOM
            KeyNamePair pp = (KeyNamePair) miniTable.getValueAt(i, 2);
            int C_UOM_ID = pp.getKey();
            // Locator
            pp = (KeyNamePair) miniTable.getValueAt(i, 3);
            // If a locator is specified on the product, choose that otherwise default locator
            M_Locator_ID = pp != null && pp.getKey() != 0 ? pp.getKey() : defaultLocator_ID;
            // Product
            pp = (KeyNamePair) miniTable.getValueAt(i, 4);
            int M_Product_ID = pp.getKey();
            int C_OrderLine_ID = 0;
            // OrderLine
            pp = (KeyNamePair) miniTable.getValueAt(i, 6);
            if (pp != null)
                C_OrderLine_ID = pp.getKey();
            int M_RMALine_ID = 0;
            // RMA
            pp = (KeyNamePair) miniTable.getValueAt(i, 7);
            // If we have RMA
            if (pp != null)
                M_RMALine_ID = pp.getKey();
            int C_InvoiceLine_ID = 0;
            MInvoiceLine il = null;
            // InvoiceLine
            pp = (KeyNamePair) miniTable.getValueAt(i, 8);
            if (pp != null)
                C_InvoiceLine_ID = pp.getKey();
            if (C_InvoiceLine_ID != 0)
                il = new MInvoiceLine(Env.getCtx(), C_InvoiceLine_ID, trxName);
            //boolean isInvoiced = (C_InvoiceLine_ID != 0);
            //	Precision of Qty UOM
            int precision = 2;
            if (M_Product_ID != 0) {
                MProduct product = MProduct.get(Env.getCtx(), M_Product_ID);
                precision = product.getUOMPrecision();
            }
            QtyEntered = QtyEntered.setScale(precision, BigDecimal.ROUND_HALF_DOWN);
            //
            log.fine("Line QtyEntered=" + QtyEntered + ", Product=" + M_Product_ID + ", OrderLine=" + C_OrderLine_ID + ", InvoiceLine=" + C_InvoiceLine_ID);
            //	Credit Memo - negative Qty
            if (m_invoice != null && m_invoice.isCreditMemo())
                QtyEntered = QtyEntered.negate();
            //	Create new InOut Line
            MInOutLine iol = new MInOutLine(inout);
            //	Line UOM
            iol.setM_Product_ID(M_Product_ID, C_UOM_ID);
            //	Movement/Entered
            iol.setQty(QtyEntered);
            //
            MOrderLine ol = null;
            MRMALine rmal = null;
            if (C_OrderLine_ID != 0) {
                iol.setC_OrderLine_ID(C_OrderLine_ID);
                ol = new MOrderLine(Env.getCtx(), C_OrderLine_ID, trxName);
                if (ol.getQtyEntered().compareTo(ol.getQtyOrdered()) != 0) {
                    iol.setMovementQty(QtyEntered.multiply(ol.getQtyOrdered()).divide(ol.getQtyEntered(), 12, BigDecimal.ROUND_HALF_UP));
                    iol.setC_UOM_ID(ol.getC_UOM_ID());
                }
                iol.setM_AttributeSetInstance_ID(ol.getM_AttributeSetInstance_ID());
                iol.setDescription(ol.getDescription());
                //
                iol.setC_Project_ID(ol.getC_Project_ID());
                iol.setC_ProjectPhase_ID(ol.getC_ProjectPhase_ID());
                iol.setC_ProjectTask_ID(ol.getC_ProjectTask_ID());
                iol.setC_Activity_ID(ol.getC_Activity_ID());
                iol.setC_Campaign_ID(ol.getC_Campaign_ID());
                iol.setAD_OrgTrx_ID(ol.getAD_OrgTrx_ID());
                iol.setUser1_ID(ol.getUser1_ID());
                iol.setUser2_ID(ol.getUser2_ID());
                iol.setUser3_ID(ol.getUser3_ID());
                iol.setUser4_ID(ol.getUser4_ID());
            } else if (il != null) {
                if (il.getQtyEntered().compareTo(il.getQtyInvoiced()) != 0) {
                    iol.setQtyEntered(QtyEntered.multiply(il.getQtyInvoiced()).divide(il.getQtyEntered(), 12, BigDecimal.ROUND_HALF_UP));
                    iol.setC_UOM_ID(il.getC_UOM_ID());
                }
                iol.setDescription(il.getDescription());
                iol.setC_Project_ID(il.getC_Project_ID());
                iol.setC_ProjectPhase_ID(il.getC_ProjectPhase_ID());
                iol.setC_ProjectTask_ID(il.getC_ProjectTask_ID());
                iol.setC_Activity_ID(il.getC_Activity_ID());
                iol.setC_Campaign_ID(il.getC_Campaign_ID());
                iol.setAD_OrgTrx_ID(il.getAD_OrgTrx_ID());
                iol.setUser1_ID(il.getUser1_ID());
                iol.setUser2_ID(il.getUser2_ID());
                iol.setUser3_ID(il.getUser3_ID());
                iol.setUser4_ID(il.getUser4_ID());
            } else if (M_RMALine_ID != 0) {
                rmal = new MRMALine(Env.getCtx(), M_RMALine_ID, trxName);
                iol.setM_RMALine_ID(M_RMALine_ID);
                iol.setQtyEntered(QtyEntered);
                iol.setDescription(rmal.getDescription());
                iol.setM_AttributeSetInstance_ID(rmal.getM_AttributeSetInstance_ID());
                iol.setC_Project_ID(rmal.getC_Project_ID());
                iol.setC_ProjectPhase_ID(rmal.getC_ProjectPhase_ID());
                iol.setC_ProjectTask_ID(rmal.getC_ProjectTask_ID());
                iol.setC_Activity_ID(rmal.getC_Activity_ID());
                iol.setAD_OrgTrx_ID(rmal.getAD_OrgTrx_ID());
                iol.setUser1_ID(rmal.getUser1_ID());
                iol.setUser2_ID(rmal.getUser2_ID());
                iol.setUser3_ID(rmal.getUser3_ID());
                iol.setUser4_ID(rmal.getUser4_ID());
            }
            //	Charge
            if (M_Product_ID == 0) {
                if (//	from order
                ol != null && ol.getC_Charge_ID() != 0)
                    iol.setC_Charge_ID(ol.getC_Charge_ID());
                else if (//	from invoice
                il != null && il.getC_Charge_ID() != 0)
                    iol.setC_Charge_ID(il.getC_Charge_ID());
                else if (// from rma
                rmal != null && rmal.getC_Charge_ID() != 0)
                    iol.setC_Charge_ID(rmal.getC_Charge_ID());
            }
            // Set locator
            iol.setM_Locator_ID(M_Locator_ID);
            if (!iol.save())
                log.log(Level.SEVERE, "Line NOT created #" + i);
            else //	Create Invoice Line Link
            if (il != null) {
                il.setM_InOutLine_ID(iol.getM_InOutLine_ID());
                il.saveEx();
            }
        }
    //   if selected
    }
    /**
		 *  Update Header
		 *  - if linked to another order/invoice/rma - remove link
		 *  - if no link set it
		 */
    if (p_order != null && p_order.getC_Order_ID() != 0) {
        inout.setC_Order_ID(p_order.getC_Order_ID());
        inout.setAD_OrgTrx_ID(p_order.getAD_OrgTrx_ID());
        inout.setC_Project_ID(p_order.getC_Project_ID());
        inout.setC_Campaign_ID(p_order.getC_Campaign_ID());
        inout.setC_Activity_ID(p_order.getC_Activity_ID());
        inout.setUser1_ID(p_order.getUser1_ID());
        inout.setUser2_ID(p_order.getUser2_ID());
        inout.setUser3_ID(p_order.getUser3_ID());
        inout.setUser4_ID(p_order.getUser4_ID());
        if (p_order.isDropShip()) {
            inout.setM_Warehouse_ID(p_order.getM_Warehouse_ID());
            inout.setIsDropShip(p_order.isDropShip());
            inout.setDropShip_BPartner_ID(p_order.getDropShip_BPartner_ID());
            inout.setDropShip_Location_ID(p_order.getDropShip_Location_ID());
            inout.setDropShip_User_ID(p_order.getDropShip_User_ID());
        }
    }
    if (m_invoice != null && m_invoice.getC_Invoice_ID() != 0) {
        if (inout.getC_Order_ID() == 0)
            inout.setC_Order_ID(m_invoice.getC_Order_ID());
        inout.setC_Invoice_ID(m_invoice.getC_Invoice_ID());
        inout.setAD_OrgTrx_ID(m_invoice.getAD_OrgTrx_ID());
        inout.setC_Project_ID(m_invoice.getC_Project_ID());
        inout.setC_Campaign_ID(m_invoice.getC_Campaign_ID());
        inout.setC_Activity_ID(m_invoice.getC_Activity_ID());
        inout.setUser1_ID(m_invoice.getUser1_ID());
        inout.setUser2_ID(m_invoice.getUser2_ID());
        inout.setUser3_ID(m_invoice.getUser3_ID());
        inout.setUser4_ID(m_invoice.getUser4_ID());
    }
    if (m_rma != null && m_rma.getM_RMA_ID() != 0) {
        MInOut originalIO = m_rma.getShipment();
        inout.setIsSOTrx(m_rma.isSOTrx());
        inout.setC_Order_ID(0);
        inout.setC_Invoice_ID(0);
        inout.setM_RMA_ID(m_rma.getM_RMA_ID());
        inout.setAD_OrgTrx_ID(originalIO.getAD_OrgTrx_ID());
        inout.setC_Project_ID(originalIO.getC_Project_ID());
        inout.setC_Campaign_ID(originalIO.getC_Campaign_ID());
        inout.setC_Activity_ID(originalIO.getC_Activity_ID());
        inout.setUser1_ID(originalIO.getUser1_ID());
        inout.setUser2_ID(originalIO.getUser2_ID());
        inout.setUser3_ID(originalIO.getUser3_ID());
        inout.setUser4_ID(originalIO.getUser4_ID());
    }
    inout.saveEx();
    return true;
}
Also used : MInOut(org.compiere.model.MInOut) MProduct(org.compiere.model.MProduct) MInOutLine(org.compiere.model.MInOutLine) MInvoiceLine(org.compiere.model.MInvoiceLine) KeyNamePair(org.compiere.util.KeyNamePair) MOrderLine(org.compiere.model.MOrderLine) MRMALine(org.compiere.model.MRMALine) BigDecimal(java.math.BigDecimal)

Aggregations

MInvoiceLine (org.compiere.model.MInvoiceLine)34 MInvoice (org.compiere.model.MInvoice)23 BigDecimal (java.math.BigDecimal)13 MInOutLine (org.compiere.model.MInOutLine)10 MProduct (org.compiere.model.MProduct)7 MBPartner (org.compiere.model.MBPartner)6 MOrderLine (org.compiere.model.MOrderLine)6 MRMALine (org.compiere.model.MRMALine)6 ArrayList (java.util.ArrayList)4 MInOut (org.compiere.model.MInOut)4 MLocation (org.compiere.model.MLocation)4 PreparedStatement (java.sql.PreparedStatement)3 ResultSet (java.sql.ResultSet)3 AdempiereException (org.adempiere.exceptions.AdempiereException)3 MClient (org.compiere.model.MClient)3 MDocType (org.compiere.model.MDocType)3 SQLException (java.sql.SQLException)2 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)2 FillMandatoryException (org.adempiere.exceptions.FillMandatoryException)2 ALayoutConstraint (org.compiere.apps.ALayoutConstraint)2