fixes some issues

This commit is contained in:
vpj-cd 2008-08-29 02:59:34 +00:00
parent 6695c5a99e
commit 6ba1731fae
2 changed files with 22 additions and 46 deletions

View File

@ -589,17 +589,16 @@ public class DistributionRun extends SvrProcess
+"rl.AD_Client_ID,rl.AD_Org_ID, rl.IsActive, rl.Created,rl.CreatedBy, rl.Updated,rl.UpdatedBy, " +"rl.AD_Client_ID,rl.AD_Org_ID, rl.IsActive, rl.Created,rl.CreatedBy, rl.Updated,rl.UpdatedBy, "
+"ll.C_BPartner_ID, ll.C_BPartner_Location_ID, rl.M_Product_ID," +"ll.C_BPartner_ID, ll.C_BPartner_Location_ID, rl.M_Product_ID,"
// Ration for this process is equal QtyToDeliver // Ration for this process is equal QtyToDeliver
+" (ol.QtyOrdered-ol.QtyDelivered-TargetQty) , " +"COALESCE (ol.QtyOrdered-ol.QtyDelivered-TargetQty, 0) , "
// Min Qty for this process is equal to TargetQty // Min Qty for this process is equal to TargetQty
+" 0 , 0 FROM M_DistributionRunLine rl " +" 0 , 0 FROM M_DistributionRunLine rl "
+"INNER JOIN M_DistributionList l ON (rl.M_DistributionList_ID=l.M_DistributionList_ID) " +"INNER JOIN M_DistributionList l ON (rl.M_DistributionList_ID=l.M_DistributionList_ID) "
+"INNER JOIN M_DistributionListLine ll ON (rl.M_DistributionList_ID=ll.M_DistributionList_ID) " +"INNER JOIN M_DistributionListLine ll ON (rl.M_DistributionList_ID=ll.M_DistributionList_ID) "
+"INNER JOIN DD_Order o ON (o.C_BPartner_ID=ll.C_BPartner_ID) " +"INNER JOIN DD_Order o ON (o.C_BPartner_ID=ll.C_BPartner_ID) "
+"INNER JOIN DD_OrderLine ol ON (ol.DD_Order_ID=o.DD_Order_ID AND ol.M_Product_ID=rl.M_Product_ID) AND ol.DatePromised" +"INNER JOIN DD_OrderLine ol ON (ol.DD_Order_ID=o.DD_Order_ID AND ol.M_Product_ID=rl.M_Product_ID) "
//+ " BETWEEN "+ DB.TO_DATE(p_DatePromised) +" AND "+ DB.TO_DATE(p_DatePromised_To) +"INNER JOIN M_Locator loc ON (loc.M_Locator_ID=ol.M_Locator_ID AND loc.M_Warehouse_ID="+p_M_Warehouse_ID+") "
+ " <= "+DB.TO_DATE(p_DatePromised) +"WHERE rl.M_DistributionRun_ID="+p_M_DistributionRun_ID+" AND rl.IsActive='Y' AND ll.IsActive='Y' AND ol.DatePromised <= "+DB.TO_DATE(p_DatePromised);
+" INNER JOIN M_Locator loc ON (loc.M_Locator_ID=ol.M_Locator_ID AND loc.M_Warehouse_ID="+p_M_Warehouse_ID+") " //+ " BETWEEN "+ DB.TO_DATE(p_DatePromised) +" AND "+ DB.TO_DATE(p_DatePromised_To)
+" WHERE rl.M_DistributionRun_ID="+p_M_DistributionRun_ID+" AND rl.IsActive='Y' AND ll.IsActive='Y'";
no = DB.executeUpdate(sql, get_TrxName()); no = DB.executeUpdate(sql, get_TrxName());
Query query = MTable.get(getCtx(), MDistributionRunDetail.Table_ID). Query query = MTable.get(getCtx(), MDistributionRunDetail.Table_ID).
@ -780,9 +779,9 @@ public class DistributionRun extends SvrProcess
line.setM_Product_ID(detail.getM_Product_ID()); line.setM_Product_ID(detail.getM_Product_ID());
line.setConfirmedQty(line.getTargetQty().add(detail.getActualAllocation())); line.setConfirmedQty(line.getTargetQty().add(detail.getActualAllocation()));
if(p_M_Warehouse_ID>0) if(p_M_Warehouse_ID>0)
line.setDescription("Distribucion Pull"); line.setDescription(Msg.translate(getCtx(), "PlannedQty"));
else else
line.setDescription("Distribution Push"); line.setDescription(m_run.getDescription());
if (!line.save()) if (!line.save())
{ {
log.log(Level.SEVERE, "OrderLine not saved"); log.log(Level.SEVERE, "OrderLine not saved");
@ -927,6 +926,7 @@ public class DistributionRun extends SvrProcess
//MDDOrder.COLUMNNAME_DatePromised +" BETWEEN ? AND ? ", get_TrxName()); //MDDOrder.COLUMNNAME_DatePromised +" BETWEEN ? AND ? ", get_TrxName());
//query.setParameters(new Object[]{lastC_BPartner_ID, ws[0].getM_Warehouse_ID(), p_DatePromised,p_DatePromised_To}); //query.setParameters(new Object[]{lastC_BPartner_ID, ws[0].getM_Warehouse_ID(), p_DatePromised,p_DatePromised_To});
query.setParameters(new Object[]{lastC_BPartner_ID, ws[0].getM_Warehouse_ID(), p_DatePromised}); query.setParameters(new Object[]{lastC_BPartner_ID, ws[0].getM_Warehouse_ID(), p_DatePromised});
query.setOrderBy(MDDOrder.COLUMNNAME_DatePromised +" DESC");
order = query.first(); order = query.first();
} }
@ -987,7 +987,7 @@ public class DistributionRun extends SvrProcess
{ {
//String sql = "SELECT DD_OrderLine_ID FROM DD_OrderLine ol INNER JOIN DD_Order o ON (o.DD_Order_ID=ol.DD_Order_ID) WHERE o.DocStatus IN ('DR','IN') AND o.C_BPartner_ID = ? AND M_Product_ID=? AND ol.M_Locator_ID=? AND ol.DatePromised BETWEEN ? AND ? "; //String sql = "SELECT DD_OrderLine_ID FROM DD_OrderLine ol INNER JOIN DD_Order o ON (o.DD_Order_ID=ol.DD_Order_ID) WHERE o.DocStatus IN ('DR','IN') AND o.C_BPartner_ID = ? AND M_Product_ID=? AND ol.M_Locator_ID=? AND ol.DatePromised BETWEEN ? AND ? ";
String sql = "SELECT DD_OrderLine_ID FROM DD_OrderLine ol INNER JOIN DD_Order o ON (o.DD_Order_ID=ol.DD_Order_ID) WHERE o.DocStatus IN ('DR','IN') AND o.C_BPartner_ID = ? AND M_Product_ID=? AND ol.M_Locator_ID=? AND ol.DatePromised <= ?"; String sql = "SELECT DD_OrderLine_ID FROM DD_OrderLine ol INNER JOIN DD_Order o ON (o.DD_Order_ID=ol.DD_Order_ID) WHERE o.DocStatus IN ('DR','IN') AND o.C_BPartner_ID = ? AND M_Product_ID=? AND ol.M_Locator_ID=? AND ol.DatePromised <= ? ORDER BY DatePromised DESC";
//int DD_OrderLine_ID = DB.getSQLValue(get_TrxName(), sql, new Object[]{detail.getC_BPartner_ID(),product.getM_Product_ID(), m_locator.getM_Locator_ID(), p_DatePromised,p_DatePromised_To}); //int DD_OrderLine_ID = DB.getSQLValue(get_TrxName(), sql, new Object[]{detail.getC_BPartner_ID(),product.getM_Product_ID(), m_locator.getM_Locator_ID(), p_DatePromised,p_DatePromised_To});
int DD_OrderLine_ID = DB.getSQLValue(get_TrxName(), sql, new Object[]{detail.getC_BPartner_ID(),product.getM_Product_ID(), m_locator.getM_Locator_ID(), p_DatePromised}); int DD_OrderLine_ID = DB.getSQLValue(get_TrxName(), sql, new Object[]{detail.getC_BPartner_ID(),product.getM_Product_ID(), m_locator.getM_Locator_ID(), p_DatePromised});
if (DD_OrderLine_ID <= 0) if (DD_OrderLine_ID <= 0)
@ -1002,13 +1002,13 @@ public class DistributionRun extends SvrProcess
line.setTargetQty(detail.getActualAllocation()); line.setTargetQty(detail.getActualAllocation());
line.setQtyEntered(detail.getActualAllocation()); line.setQtyEntered(detail.getActualAllocation());
line.setConfirmedQty(detail.getActualAllocation()); line.setConfirmedQty(detail.getActualAllocation());
line.setDescription("Distribution Push"); line.setDescription(m_run.getDescription());
line.saveEx(); line.saveEx();
} }
else else
{ {
MDDOrderLine line = new MDDOrderLine(getCtx(), DD_OrderLine_ID, get_TrxName()); MDDOrderLine line = new MDDOrderLine(getCtx(), DD_OrderLine_ID, get_TrxName());
line.setDescription(line.getDescription().concat(" "+Msg.translate(getCtx(), "Qty")+" Push " +m_run.getDescription()+ " " + detail.getActualAllocation())); line.setDescription(line.getDescription().concat(" " +m_run.getDescription()+ Msg.translate(getCtx(), "Qty")+ " = " +detail.getActualAllocation()));
line.setConfirmedQty(line.getConfirmedQty().add(detail.getActualAllocation())); line.setConfirmedQty(line.getConfirmedQty().add(detail.getActualAllocation()));
line.saveEx(); line.saveEx();
} }
@ -1035,7 +1035,7 @@ public class DistributionRun extends SvrProcess
line.setTargetQty(detail.getActualAllocation()); line.setTargetQty(detail.getActualAllocation());
line.setQtyEntered(detail.getActualAllocation()); line.setQtyEntered(detail.getActualAllocation());
line.setConfirmedQty(detail.getActualAllocation()); line.setConfirmedQty(detail.getActualAllocation());
line.setDescription("Distribution Push"); line.setDescription(m_run.getDescription());
if (!line.save()) if (!line.save())
{ {
log.log(Level.SEVERE, "OrderLine not saved"); log.log(Level.SEVERE, "OrderLine not saved");

View File

@ -29,6 +29,7 @@ import org.compiere.model.MPInstance;
import org.compiere.model.MPInstancePara; import org.compiere.model.MPInstancePara;
import org.compiere.model.MProcess; import org.compiere.model.MProcess;
import org.compiere.model.MStorage; import org.compiere.model.MStorage;
import org.compiere.model.Query;
import org.compiere.process.ProcessInfo; import org.compiere.process.ProcessInfo;
import org.compiere.process.ProcessInfoParameter; import org.compiere.process.ProcessInfoParameter;
import org.compiere.process.SvrProcess; import org.compiere.process.SvrProcess;
@ -37,6 +38,7 @@ import org.compiere.util.DB;
import org.compiere.util.Env; import org.compiere.util.Env;
import org.compiere.util.Msg; import org.compiere.util.Msg;
import org.compiere.util.Trx; import org.compiere.util.Trx;
import org.eevolution.model.MDDOrderLine;
/** /**
* DistributionRun Orders * DistributionRun Orders
@ -198,8 +200,6 @@ public class DistributionRunOrders extends SvrProcess
StringBuffer sql = new StringBuffer("SELECT M_Product_ID , SUM (TargetQty) AS MinQty, SUM (QtyOrdered-QtyDelivered) AS TotalQty, l.M_Warehouse_ID 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) "); StringBuffer sql = new StringBuffer("SELECT M_Product_ID , SUM (TargetQty) AS MinQty, SUM (QtyOrdered-QtyDelivered) AS TotalQty, l.M_Warehouse_ID 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=? GROUP BY M_Product_ID, l.M_Warehouse_ID"); //sql.append(" WHERE o.DocStatus IN ('DR','IN') AND ol.DatePromised BETWEEN ? AND ? AND l.M_Warehouse_ID=? GROUP BY M_Product_ID, l.M_Warehouse_ID");
sql.append(" WHERE o.DocStatus IN ('DR','IN') AND ol.DatePromised <= ? AND l.M_Warehouse_ID=? GROUP BY M_Product_ID, l.M_Warehouse_ID"); sql.append(" WHERE o.DocStatus IN ('DR','IN') AND ol.DatePromised <= ? AND l.M_Warehouse_ID=? GROUP BY M_Product_ID, l.M_Warehouse_ID");
PreparedStatement pstmt = null; PreparedStatement pstmt = null;
ResultSet rs = null; ResultSet rs = null;
try try
@ -265,38 +265,14 @@ public class DistributionRunOrders extends SvrProcess
private BigDecimal getQtyReserved(int M_Product_ID) private BigDecimal getQtyReserved(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) "); 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"); //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");
sql.append(" WHERE o.DocStatus IN ('DR','IN') AND ol.DatePromised <= ? AND l.M_Warehouse_ID=? AND ol.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});
PreparedStatement pstmt = null; // SQL may return no rows or null
ResultSet rs = null; if (qty == null)
Timestamp today = new Timestamp (System.currentTimeMillis()); return Env.ZERO;
try
{ return qty;
pstmt = DB.prepareStatement (sql.toString(), get_TrxName());
pstmt.setTimestamp(1, today);
pstmt.setTimestamp(2, p_DatePromised);
pstmt.setInt(3, p_M_Warehouse_ID);
pstmt.setInt(4, M_Product_ID);
rs = pstmt.executeQuery();
while (rs.next())
{
return rs.getBigDecimal(1);
}
}
catch (Exception e)
{
log.log(Level.SEVERE,"doIt - " + sql, e);
return Env.ZERO;
}
finally
{
DB.close(rs, pstmt);
rs = null;
pstmt = null;
}
return Env.ZERO;
} }
/** /**