Search in sources :

Example 11 with MInOut

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

the class CreateFromInvoice method getShipmentData.

/**
	 *  Load Data - Shipment not invoiced
	 *  @param M_InOut_ID InOut
	 */
protected Vector<Vector<Object>> getShipmentData(int M_InOut_ID) {
    log.config("M_InOut_ID=" + M_InOut_ID);
    MInOut inout = new MInOut(Env.getCtx(), M_InOut_ID, null);
    p_order = null;
    if (inout.getC_Order_ID() != 0)
        p_order = new MOrder(Env.getCtx(), inout.getC_Order_ID(), null);
    m_rma = null;
    if (inout.getM_RMA_ID() != 0)
        m_rma = new MRMA(Env.getCtx(), inout.getM_RMA_ID(), null);
    //
    Vector<Vector<Object>> data = new Vector<Vector<Object>>();
    StringBuffer sql = new StringBuffer(//	QtyEntered
    "SELECT " + "l.MovementQty-SUM(NVL(mi.Qty, 0)), l.QtyEntered/l.MovementQty," + //  3..4
    " l.C_UOM_ID, COALESCE(uom.UOMSymbol, uom.Name)," + //  5..9
    " l.M_Product_ID, p.Name, po.VendorProductNo, l.M_InOutLine_ID, l.Line," + //  10
    " l.C_OrderLine_ID " + " FROM M_InOutLine l ");
    if (Env.isBaseLanguage(Env.getCtx(), "C_UOM"))
        sql.append(" LEFT OUTER JOIN C_UOM uom ON (l.C_UOM_ID=uom.C_UOM_ID)");
    else
        sql.append(" LEFT OUTER JOIN C_UOM_Trl uom ON (l.C_UOM_ID=uom.C_UOM_ID AND uom.AD_Language='").append(Env.getAD_Language(Env.getCtx())).append("')");
    sql.append(" LEFT OUTER JOIN M_Product p ON (l.M_Product_ID=p.M_Product_ID)").append(" INNER JOIN M_InOut io ON (l.M_InOut_ID=io.M_InOut_ID)").append(" LEFT OUTER JOIN M_Product_PO po ON (l.M_Product_ID = po.M_Product_ID AND io.C_BPartner_ID = po.C_BPartner_ID)").append(" LEFT OUTER JOIN M_MatchInv mi ON (l.M_InOutLine_ID=mi.M_InOutLine_ID)").append(" WHERE l.M_InOut_ID=? AND l.MovementQty<>0 ").append("GROUP BY l.MovementQty, l.QtyEntered/l.MovementQty, " + "l.C_UOM_ID, COALESCE(uom.UOMSymbol, uom.Name), " + "l.M_Product_ID, p.Name, po.VendorProductNo, l.M_InOutLine_ID, l.Line, l.C_OrderLine_ID ").append("ORDER BY l.Line");
    try {
        PreparedStatement pstmt = DB.prepareStatement(sql.toString(), null);
        pstmt.setInt(1, M_InOut_ID);
        ResultSet rs = pstmt.executeQuery();
        while (rs.next()) {
            Vector<Object> line = new Vector<Object>(7);
            //  0-Selection
            line.add(new Boolean(false));
            BigDecimal qtyMovement = rs.getBigDecimal(1);
            BigDecimal multiplier = rs.getBigDecimal(2);
            BigDecimal qtyEntered = qtyMovement.multiply(multiplier);
            //  1-Qty
            line.add(qtyEntered);
            KeyNamePair pp = new KeyNamePair(rs.getInt(3), rs.getString(4).trim());
            //  2-UOM
            line.add(pp);
            pp = new KeyNamePair(rs.getInt(5), rs.getString(6));
            //  3-Product
            line.add(pp);
            // 4-VendorProductNo
            line.add(rs.getString(7));
            int C_OrderLine_ID = rs.getInt(10);
            if (rs.wasNull())
                //  5-Order
                line.add(null);
            else
                line.add(new KeyNamePair(C_OrderLine_ID, "."));
            pp = new KeyNamePair(rs.getInt(8), rs.getString(9));
            //  6-Ship
            line.add(pp);
            //  7-RMA
            line.add(null);
            data.add(line);
        }
        rs.close();
        pstmt.close();
    } catch (SQLException e) {
        log.log(Level.SEVERE, sql.toString(), e);
    }
    return data;
}
Also used : MInOut(org.compiere.model.MInOut) SQLException(java.sql.SQLException) PreparedStatement(java.sql.PreparedStatement) BigDecimal(java.math.BigDecimal) MOrder(org.compiere.model.MOrder) ResultSet(java.sql.ResultSet) KeyNamePair(org.compiere.util.KeyNamePair) MRMA(org.compiere.model.MRMA) Vector(java.util.Vector)

Example 12 with MInOut

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

the class WebInfo method getShipments.

//	getOrder
/**
	 * 	Get Shipments
	 *	@return shipments of BP
	 */
public ArrayList<MInOut> getShipments() {
    m_infoMessage = null;
    ArrayList<MInOut> list = new ArrayList<MInOut>();
    if (m_wu != null && !m_wu.hasBPAccess(X_AD_UserBPAccess.BPACCESSTYPE_BusinessDocuments, new Object[] { MDocType.DOCBASETYPE_MaterialReceipt, MDocType.DOCBASETYPE_MaterialDelivery })) {
        log.info("No Access");
        return list;
    }
    String sql = "SELECT * FROM M_InOut WHERE C_BPartner_ID=?" + " AND DocStatus NOT IN ('DR','IN') " + " ORDER BY DocumentNo DESC";
    PreparedStatement pstmt = null;
    ResultSet rs = null;
    try {
        pstmt = DB.prepareStatement(sql, null);
        pstmt.setInt(1, getC_BPartner_ID());
        rs = pstmt.executeQuery();
        while (rs.next()) list.add(new MInOut(m_ctx, rs, null));
    } catch (Exception e) {
        log.log(Level.SEVERE, sql, e);
    } finally {
        DB.close(rs, pstmt);
        rs = null;
        pstmt = null;
    }
    log.fine("#" + list.size());
    return list;
}
Also used : MInOut(org.compiere.model.MInOut) ArrayList(java.util.ArrayList) ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement)

Example 13 with MInOut

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

the class CostResult method createBusinessCaseTest.

/**
	 * create Business Test Case
	 * @param trxName
	 */
void createBusinessCaseTest(String trxName) {
    createDataMaster();
    generateHistoryCost();
    Timestamp dateAcct;
    //First Purchase Receipt 
    dateAcct = today;
    MOrder purchase1 = createPurchaseOrder(dateAcct, new BigDecimal(100), new BigDecimal(36));
    MInOut receipt1 = null;
    for (MOrderLine line : purchase1.getLines()) {
        receipt1 = createMaterialReceipt(dateAcct, new BigDecimal(10), line.getC_OrderLine_ID());
    }
    for (MInOutLine line : receipt1.getLines()) {
        CostResult costResult = new CostResult(product.getM_Product_ID(), //currentCostPrice
        new BigDecimal("47.7292"), // cumulateQty
        new BigDecimal("30"), //cumulateAmt
        new BigDecimal("1431.8748"), //cdAmt
        new BigDecimal("477.2920"), //cdAdjutment
        new BigDecimal("0"), //cdQty
        new BigDecimal("10"), //cdCurrentCostPrice
        new BigDecimal("53.5937"), //cdCumulateQty
        new BigDecimal("20"), //cdCumulateAmt
        new BigDecimal("1071.8748"), dateAcct);
        assertCostReceipt(costResult, line.getM_InOutLine_ID(), as, trxName);
    }
    //Create Sales Order Order Credit by 5
    dateAcct = TimeUtil.addDays(today, 15);
    MOrder sales1 = createSalesOrder(dateAcct, new BigDecimal(5), new BigDecimal(45));
    for (MOrderLine line : sales1.getLines()) {
        CostResult costResult = new CostResult(product.getM_Product_ID(), new BigDecimal("47.7292"), new BigDecimal("25"), new BigDecimal("1193.2288"), new BigDecimal("238.6460"), new BigDecimal("0"), new BigDecimal("-5"), new BigDecimal("47.7292"), new BigDecimal("30"), new BigDecimal("1431.8748"), dateAcct);
        assertCostShipment(costResult, line.getC_OrderLine_ID(), as, trxName);
    }
    //Second Purchase Receipt 7 day forward
    dateAcct = TimeUtil.addDays(today, 31);
    MOrder purchase2 = createPurchaseOrder(dateAcct, new BigDecimal(100), new BigDecimal(34));
    MInOut receipt2 = null;
    for (MOrderLine line : purchase2.getLines()) {
        receipt2 = createMaterialReceipt(dateAcct, new BigDecimal(10), line.getC_OrderLine_ID());
    }
    for (MInOutLine line : receipt2.getLines()) {
        CostResult costResult = new CostResult(product.getM_Product_ID(), //currentCostPrice
        new BigDecimal("43.8065"), // cumulateQty
        new BigDecimal("35"), //cumulateAmt
        new BigDecimal("1533.2288"), //cdAmt
        new BigDecimal("438.0650"), //cdAdjutment
        new BigDecimal("0"), //cdQty
        new BigDecimal("10"), //cdCurrentCostPrice
        new BigDecimal("47.7292"), //cdCumulateQty
        new BigDecimal("25"), //cdCumulateAmt
        new BigDecimal("1193.2288"), dateAcct);
        assertCostReceipt(costResult, line.getM_InOutLine_ID(), as, trxName);
    }
    //Create Sales Order Order Credit by 5
    dateAcct = TimeUtil.addDays(today, 60);
    MOrder sales2 = createSalesOrder(dateAcct, new BigDecimal(10), new BigDecimal(45));
    for (MOrderLine line : sales2.getLines()) {
        CostResult costResult = new CostResult(product.getM_Product_ID(), new BigDecimal("43.8065"), new BigDecimal("25"), new BigDecimal("1095.1638"), new BigDecimal("438.0650"), new BigDecimal("0"), new BigDecimal("-10"), new BigDecimal("43.8065"), new BigDecimal("35"), new BigDecimal("1533.2288"), dateAcct);
        assertCostShipment(costResult, line.getC_OrderLine_ID(), as, trxName);
    }
    dateAcct = receipt1.getDateAcct();
    int M_InOutLine_ID = 0;
    for (MInOutLine line : receipt1.getLines()) {
        M_InOutLine_ID = line.getM_InOutLine_ID();
        MInvoice invoice = createInvoiceVendor(dateAcct, new BigDecimal(10), new BigDecimal(38), line.getM_InOutLine_ID());
    }
    CostResult costResult = new CostResult(product.getM_Product_ID(), //currentCostPrice
    new BigDecimal("44.2827"), // cumulateQty
    new BigDecimal("25"), //cumulateAmt
    new BigDecimal("1107.0688"), //cdAmt
    new BigDecimal("380.0000"), //cdAdjutment
    new BigDecimal("20.0000"), //cdQty
    new BigDecimal("10"), //cdCurrentCostPrice
    new BigDecimal("53.5937"), //cdCumulateQty
    new BigDecimal("20"), //cdCumulateAmt
    new BigDecimal("1071.8748"), dateAcct);
    assertCostInvoice(costResult, M_InOutLine_ID, as, trxName);
    dateAcct = Timestamp.valueOf("2010-01-16 00:00:00.0");
    for (MOrderLine line : sales1.getLines()) {
        costResult = new CostResult(line.getM_Product_ID(), new BigDecimal("44.2827"), new BigDecimal("25"), new BigDecimal("1107.0688"), new BigDecimal("241.9790"), new BigDecimal("0"), new BigDecimal("-5"), new BigDecimal("48.3958"), new BigDecimal("30"), new BigDecimal("1451.8748"), dateAcct);
        assertCostShipmentAdjust(costResult, line.getC_OrderLine_ID(), as, trxName);
    }
    //Reverse Material Receipt		
    dateAcct = today;
    receipt1.processIt(DocAction.ACTION_Reverse_Correct);
    receipt1.saveEx();
    for (MInOutLine line : receipt1.getLines(true)) {
        costResult = new CostResult(product.getM_Product_ID(), //currentCostPrice
        new BigDecimal("44.2827"), // cumulateQty
        new BigDecimal("25"), //cumulateAmt
        new BigDecimal("1107.0688"), //cdAmt
        new BigDecimal("380.0000"), //cdAdjutment
        new BigDecimal("20.0000"), //cdQty
        new BigDecimal("10"), //cdCurrentCostPrice
        new BigDecimal("53.5937"), //cdCumulateQty
        new BigDecimal("20"), //cdCumulateAmt
        new BigDecimal("1071.8748"), dateAcct);
        assertCostReceiptReversal(costResult, line.getM_InOutLine_ID(), as, trxName);
    }
    MInOut reversal = new MInOut(getCtx(), receipt1.getReversal_ID(), trxName);
    for (MInOutLine line : reversal.getLines(true)) {
        costResult = new CostResult(product.getM_Product_ID(), //currentCostPrice
        new BigDecimal("46.8373"), // cumulateQty
        new BigDecimal("19"), //cumulateAmt
        new BigDecimal("889.9081"), //cdAmt
        new BigDecimal("380"), //cdAdjutment
        new BigDecimal("20"), //cdQty
        new BigDecimal("-10"), //cdCurrentCostPrice
        new BigDecimal("49.0073"), //cdCumulateQty
        new BigDecimal("34"), //cdCumulateAmt
        new BigDecimal("1666.2496"), dateAcct);
        assertCostReceiptReversal(costResult, line.getM_InOutLine_ID(), as, trxName);
    }
    //Second Purchase Receipt 7 day forward
    dateAcct = TimeUtil.addDays(today, 7);
    MOrder purchase3 = createPurchaseOrder(dateAcct, new BigDecimal(100), new BigDecimal(37));
    MInOut receipt3 = null;
    for (MOrderLine line : purchase3.getLines()) {
        receipt3 = createMaterialReceipt(dateAcct, new BigDecimal(20), line.getC_OrderLine_ID());
    }
    for (MInOutLine line : receipt3.getLines()) {
        costResult = new CostResult(product.getM_Product_ID(), //currentCostPrice
        new BigDecimal("42.0489"), // cumulateQty
        new BigDecimal("45"), //cumulateAmt
        new BigDecimal("1892.1983"), //cdAmt
        new BigDecimal("876.7500"), //cdAdjutment
        new BigDecimal("0"), //cdQty
        new BigDecimal("20"), //cdCurrentCostPrice
        new BigDecimal("48.3958"), //cdCumulateQty
        new BigDecimal("30"), //cdCumulateAmt
        new BigDecimal("1451.8748"), dateAcct);
        assertCostReceipt(costResult, line.getM_InOutLine_ID(), as, trxName);
    }
    dateAcct = TimeUtil.addDays(today, 65);
    MMovement move = createMovement(dateAcct, new BigDecimal("5"));
    for (MMovementLine line : move.getLines(true)) {
        costResult = new CostResult(product.getM_Product_ID(), //currentCostPrice
        new BigDecimal("53.5938"), // cumulateQty
        new BigDecimal("9"), //cumulateAmt
        new BigDecimal("482.3442"), //cdAmt
        new BigDecimal("267.9690"), //cdAdjutment
        new BigDecimal("0"), //cdQty
        new BigDecimal("5"), //cdCurrentCostPrice
        new BigDecimal("53.5938"), //cdCumulateQty
        new BigDecimal("4"), //cdCumulateAmt
        new BigDecimal("214.3752"), dateAcct);
        assertCostMovement(costResult, line.getM_MovementLine_ID(), as, trxName);
    }
    dateAcct = TimeUtil.addDays(today, 70);
    MInventory inventory = createPhisicalInventory(dateAcct, new BigDecimal("20"), costResult.cumulateQty);
    for (MInventoryLine line : inventory.getLines(true)) {
        costResult = new CostResult(product.getM_Product_ID(), //currentCostPrice
        new BigDecimal("42.0488"), // cumulateQty
        new BigDecimal("51"), //cumulateAmt
        new BigDecimal("2144.4906"), //cdAmt
        new BigDecimal("462.5368"), //cdAdjutment
        new BigDecimal("0"), //cdQty
        new BigDecimal("11"), //cdCurrentCostPrice
        new BigDecimal("42.0488"), //cdCumulateQty
        new BigDecimal("40"), //cdCumulateAmt
        new BigDecimal("1681.9538"), dateAcct);
        assertCostPhisicalInventory(costResult, line.getM_InventoryLine_ID(), as, trxName);
        break;
    }
    dateAcct = TimeUtil.addDays(today, 80);
    inventory = createInvetoryInternalUse(dateAcct, new BigDecimal("-5"));
    for (MInventoryLine line : inventory.getLines(true)) {
        costResult = new CostResult(product.getM_Product_ID(), //currentCostPrice
        new BigDecimal("42.0488"), // cumulateQty
        new BigDecimal("56"), //cumulateAmt
        new BigDecimal("2354.7346"), //cdAmt
        new BigDecimal("210.2440"), //cdAdjutment
        new BigDecimal("0"), //cdQty
        new BigDecimal("5"), //cdCurrentCostPrice
        new BigDecimal("42.0488"), //cdCumulateQty
        new BigDecimal("51"), //cdCumulateAmt
        new BigDecimal("2144.4906"), dateAcct);
        assertCostPhisicalInventory(costResult, line.getM_InventoryLine_ID(), as, trxName);
        ;
    }
    createTrxAndInventoryValuationReport();
}
Also used : MInOut(org.compiere.model.MInOut) MInOutLine(org.compiere.model.MInOutLine) MInventoryLine(org.compiere.model.MInventoryLine) MInvoice(org.compiere.model.MInvoice) Timestamp(java.sql.Timestamp) BigDecimal(java.math.BigDecimal) MOrder(org.compiere.model.MOrder) MInventory(org.compiere.model.MInventory) MOrderLine(org.compiere.model.MOrderLine) MMovementLine(org.compiere.model.MMovementLine) MMovement(org.compiere.model.MMovement)

Example 14 with MInOut

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

the class InventoryUtil method createInOut.

public static MInOut createInOut(MMDocument doc, String trxName) {
    MOrder order;
    if (MDocType.DOCBASETYPE_MaterialReceipt.equals(doc.DocBaseType)) {
        order = (MOrder) doc.scenario.get(MDocType.DOCBASETYPE_PurchaseOrder, doc.PODocumentNo).document;
    } else if (MDocType.DOCBASETYPE_MaterialDelivery.equals(doc.DocBaseType)) {
        order = (MOrder) doc.scenario.get(MDocType.DOCBASETYPE_SalesOrder, doc.PODocumentNo).document;
    } else {
        throw new IllegalArgumentException("DocBaseType not supported - " + doc);
    }
    //		if (trxName != null && trxName.equals(order.get_TrxName()))
    //			throw new AdempiereException("Internal exception - not same trxName");
    MInOut io = new MInOut(order, 0, doc.Date);
    setGeneratedTag(io);
    io.saveEx();
    //
    MInOutLine iol = null;
    for (MOrderLine oline : order.getLines(true, null)) {
        iol = new MInOutLine(io);
        iol.setOrderLine(oline, 0, doc.Qty);
        iol.setQty(doc.Qty);
        iol.saveEx();
        break;
    }
    final boolean checkPrice = (doc.Price != null && doc.Price.signum() != 0);
    // Check Receipt Price Match
    if (checkPrice && !io.isSOTrx()) {
        BigDecimal receiptPrice = iol.getPriceActual();
        if (doc.Price.compareTo(receiptPrice) != 0) {
            throw new RuntimeException("MMR - Price Not Match - target=" + doc.Price + ", actual=" + iol.getPriceActual());
        }
    }
    //
    doc.document = io;
    processDocument(doc, MInOut.DOCACTION_Complete, MInOut.DOCSTATUS_Completed);
    if (!Util.isEmpty(doc.ASI)) {
        iol.load(trxName);
        doc.scenario.registerASICode(doc.ASI, iol.getM_AttributeSetInstance_ID(), !io.isSOTrx());
    }
    checkLineCosts(doc, iol, io.isSOTrx());
    return io;
}
Also used : MInOut(org.compiere.model.MInOut) MOrder(org.compiere.model.MOrder) MInOutLine(org.compiere.model.MInOutLine) MOrderLine(org.compiere.model.MOrderLine) BigDecimal(java.math.BigDecimal)

Example 15 with MInOut

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

the class LiberoValidator method updateMPPOrder.

//	getAD_Client_ID
private void updateMPPOrder(MInOutLine outline) {
    MPPOrder order = null;
    BigDecimal qtyShipment = Env.ZERO;
    MInOut inout = outline.getParent();
    String movementType = inout.getMovementType();
    int orderLineId = 0;
    if (MInOut.MOVEMENTTYPE_CustomerShipment.equals(movementType)) {
        orderLineId = outline.getC_OrderLine_ID();
        qtyShipment = outline.getMovementQty();
    } else if (MInOut.MOVEMENTTYPE_CustomerReturns.equals(movementType)) {
        MRMALine rmaline = new MRMALine(outline.getCtx(), outline.getM_RMALine_ID(), null);
        MInOutLine line = (MInOutLine) rmaline.getM_InOutLine();
        orderLineId = line.getC_OrderLine_ID();
        qtyShipment = outline.getMovementQty().negate();
    }
    final String whereClause = " C_OrderLine_ID = ? " + " AND DocStatus IN  (?,?)" + " AND EXISTS (SELECT 1 FROM  PP_Order_BOM " + " WHERE PP_Order_BOM.PP_Order_ID=PP_Order.PP_Order_ID AND PP_Order_BOM.BOMType =? )";
    order = new Query(outline.getCtx(), MPPOrder.Table_Name, whereClause, outline.get_TrxName()).setParameters(orderLineId, MPPOrder.DOCSTATUS_InProgress, MPPOrder.DOCSTATUS_Completed, MPPOrderBOM.BOMTYPE_Make_To_Kit).firstOnly();
    if (order == null || order.get_ID() <= 0)
        return;
    if (MPPOrder.DOCSTATUS_InProgress.equals(order.getDocStatus())) {
        order.completeIt();
        order.setDocStatus(MPPOrder.ACTION_Complete);
        order.setDocAction(MPPOrder.DOCACTION_Close);
        order.saveEx();
    }
    if (MPPOrder.DOCSTATUS_Completed.equals(order.getDocStatus())) {
        String description = order.getDescription() != null ? order.getDescription() : "" + Msg.translate(inout.getCtx(), MInOut.COLUMNNAME_M_InOut_ID) + " : " + Msg.translate(inout.getCtx(), MInOut.COLUMNNAME_DocumentNo);
        order.setDescription(description);
        order.updateMakeToKit(qtyShipment);
        order.saveEx();
    }
    if (order.getQtyToDeliver().signum() == 0) {
        order.closeIt();
        order.setDocStatus(MPPOrder.DOCACTION_Close);
        order.setDocAction(MPPOrder.DOCACTION_None);
        order.saveEx();
    }
    return;
}
Also used : MInOut(org.compiere.model.MInOut) Query(org.compiere.model.Query) MInOutLine(org.compiere.model.MInOutLine) MRMALine(org.compiere.model.MRMALine) BigDecimal(java.math.BigDecimal)

Aggregations

MInOut (org.compiere.model.MInOut)38 MInOutLine (org.compiere.model.MInOutLine)22 BigDecimal (java.math.BigDecimal)13 MOrder (org.compiere.model.MOrder)13 MInvoice (org.compiere.model.MInvoice)10 MOrderLine (org.compiere.model.MOrderLine)9 ArrayList (java.util.ArrayList)6 MProduct (org.compiere.model.MProduct)5 MRMA (org.compiere.model.MRMA)5 ResultSet (java.sql.ResultSet)4 Timestamp (java.sql.Timestamp)4 MInvoiceLine (org.compiere.model.MInvoiceLine)4 MRMALine (org.compiere.model.MRMALine)4 MBPartner (org.compiere.model.MBPartner)3 MInOutConfirm (org.compiere.model.MInOutConfirm)3 MInvoiceSchedule (org.compiere.model.MInvoiceSchedule)3 MLocator (org.compiere.model.MLocator)3 MStorage (org.compiere.model.MStorage)3 PreparedStatement (java.sql.PreparedStatement)2 AdempiereException (org.adempiere.exceptions.AdempiereException)2