little fixed

This commit is contained in:
vpj-cd 2008-09-04 02:55:58 +00:00
parent 23b4715fe9
commit 1672bf5c18
2 changed files with 39 additions and 27 deletions

View File

@ -542,16 +542,15 @@ public class MPPMRP extends X_PP_MRP
* @param ctx
* @param M_Warehouse_ID
* @param M_Product_ID
* @param to
* @param Ordertype separate for SOO,POO,
* @param To
* @param trxName
* @return BibDecimal
*/
public static BigDecimal getQtyReserved(Properties ctx, int M_Warehouse_ID ,int M_Product_ID, Timestamp to,String trxName)
public static BigDecimal getQtyReserved(Properties ctx, int M_Warehouse_ID ,int M_Product_ID, Timestamp To,String trxName)
{
StringBuffer sql = new StringBuffer("SELECT SUM(Qty) FROM PP_MRP WHERE TypeMRP='D' AND DocStatus IN ('IN','CO')");
sql.append("AND OrderType IN ('SOO','MOP','DOO') AD_Client_ID= ? AND DatePromised <=? AND M_Warehouse_ID =? AND M_Product_ID=?");
BigDecimal qty = DB.getSQLValueBD(trxName, sql.toString(), new Object[]{Env.getAD_Client_ID(ctx), to , M_Warehouse_ID, M_Product_ID});
StringBuffer sql = new StringBuffer("SELECT SUM(Qty) FROM PP_MRP WHERE TypeMRP='D' AND DocStatus IN ('IN','CO')");
sql.append(" AND OrderType IN ('SOO','MOP','DOO') AND AD_Client_ID= ? AND DatePromised <=? AND M_Warehouse_ID =? AND M_Product_ID=?");
BigDecimal qty = DB.getSQLValueBD(trxName, sql.toString(), new Object[]{Env.getAD_Client_ID(ctx), To , M_Warehouse_ID, M_Product_ID});
// SQL may return no rows or null
if (qty == null)
return Env.ZERO;
@ -564,8 +563,6 @@ public class MPPMRP extends X_PP_MRP
* @param ctx
* @param M_Warehouse_ID
* @param M_Product_ID
* @param to
* @param Ordertype separate for SOO,POO,
* @param trxName
* @return BibDecimal
*/
@ -579,15 +576,15 @@ public class MPPMRP extends X_PP_MRP
* @param ctx
* @param M_Warehouse_ID
* @param M_Product_ID
* @param to
* @param To
* @param trxName
* @return
*/
public static BigDecimal getQtyOrdered(Properties ctx, int M_Warehouse_ID ,int M_Product_ID, Timestamp to,String trxName)
public static BigDecimal getQtyOrdered(Properties ctx, int M_Warehouse_ID ,int M_Product_ID, Timestamp To,String trxName)
{
StringBuffer sql = new StringBuffer("SELECT SUM(Qty) FROM PP_MRP WHERE TypeMRP='S' AND DocStatus IN ('IN','CO')");
sql.append("AND OrderType IN ('POO','MOP','DOO') AD_Client_ID= ? AND DatePromised <=? AND M_Warehouse_ID =? AND M_Product_ID=?");
BigDecimal qty = DB.getSQLValueBD(trxName, sql.toString(), new Object[]{Env.getAD_Client_ID(ctx), to , M_Warehouse_ID, M_Product_ID});
sql.append(" AND OrderType IN ('POO','MOP','DOO') AND AD_Client_ID= ? AND DatePromised <=? AND M_Warehouse_ID =? AND M_Product_ID=?");
BigDecimal qty = DB.getSQLValueBD(trxName, sql.toString(), new Object[]{Env.getAD_Client_ID(ctx), To , M_Warehouse_ID, M_Product_ID});
// SQL may return no rows or null
if (qty == null)
return Env.ZERO;
@ -600,7 +597,6 @@ public class MPPMRP extends X_PP_MRP
* @param AD_Client_ID
* @param M_Warehouse_ID
* @param M_Product_ID
* @param to
* @param trxName
* @return
*/

View File

@ -215,7 +215,16 @@ public class DistributionRunOrders extends SvrProcess
{
int M_Product_ID = rs.getInt("M_Product_ID");
BigDecimal QtyAvailable = MStorage.getQtyAvailable(p_M_Warehouse_ID,0 , M_Product_ID , 0, get_TrxName());
if(QtyAvailable.signum()< 0)
continue;
BigDecimal QtyToDistribute = rs.getBigDecimal("TotalQty");
if(QtyAvailable.compareTo(QtyToDistribute) >= 0)
QtyAvailable = QtyToDistribute;
else
{
BigDecimal QtyReserved = getTargetQty(M_Product_ID);
QtyToDistribute = QtyAvailable.subtract(QtyReserved);
}
MDistributionRunLine m_runLine = new MDistributionRunLine(getCtx(),0 ,get_TrxName());
m_runLine.setM_DistributionRun_ID(m_run.getM_DistributionRun_ID());
@ -226,20 +235,9 @@ public class DistributionRunOrders extends SvrProcess
m_runLine.setDescription(Msg.translate(getCtx(), "QtyAvailable") +" : " + QtyAvailable + " " +Msg.translate(getCtx(), "QtyOrdered") + " : " + QtyToDistribute);
//m_runLine.setMinQty(rs.getBigDecimal("MinQty"));
BigDecimal QtyReserved = getQtyReserved(M_Product_ID);
//if(QtyToDistribute.compareTo(QtyAvailable) > 0)
//{
/*if(QtyReserved.compareTo(QtyAvailable) > 0)
{
QtyToDistribute = QtyAvailable;
}
else*/
QtyToDistribute = QtyAvailable.subtract(QtyReserved);
//}
m_runLine.setTotalQty(QtyToDistribute);
m_runLine.save();
m_runLine.saveEx();
line += 10;
}
}
@ -258,11 +256,11 @@ public class DistributionRunOrders extends SvrProcess
return true;
}
/**
* Get Qty Reserved for a Warehouse
* Get Qty TargetQty for a Warehouse
* @param M_Product_ID
* @return
*/
private BigDecimal getQtyReserved(int M_Product_ID)
private BigDecimal getTargetQty(int M_Product_ID)
{
StringBuffer sql = new StringBuffer("SELECT SUM (TargetQty) FROM DD_OrderLine ol INNER JOIN M_Locator l ON (l.M_Locator_ID=ol.M_Locator_ID) INNER JOIN DD_Order o ON (o.DD_Order_ID=ol.DD_Order_ID) ");
//sql.append(" WHERE o.DocStatus IN ('DR','IN') AND ol.DatePromised BETWEEN ? AND ? AND l.M_Warehouse_ID=? AND ol.M_Product_ID=? GROUP BY M_Product_ID, l.M_Warehouse_ID");
@ -275,6 +273,24 @@ public class DistributionRunOrders extends SvrProcess
return qty;
}
/**
* Set Qty TargetQty for a Warehouse
* @param M_Product_ID
* @return
*/
private BigDecimal setTargetQty(int M_Product_ID)
{
StringBuffer sql = new StringBuffer("SELECT SUM(Qty) FROM PP_MRP mrp "
+"WHERE TypeMRP='D' AND OrderType='SOO' AND DocStatus IN ('IN','CO') AND mrp.DatePromised <=? "
+"AND mrp.M_Warehouse_ID =? AND M_Product_ID=? GROUP BY M_Product_ID, l.M_Warehouse_ID");
BigDecimal qty = DB.getSQLValueBD(get_TrxName(), sql.toString(), new Object[]{p_DatePromised, p_M_Warehouse_ID, M_Product_ID});
// SQL may return no rows or null
if (qty == null)
return Env.ZERO;
return qty;
}
/**
* Execute Distribution Run
* @return