use of org.compiere.model.MDistributionRunLine in project adempiere by adempiere.
the class DistributionRun method addAllocations.
// insertDetails
/**************************************************************************
* Add up Allocations
*/
private void addAllocations() {
// Reset
for (int j = 0; j < m_runLines.length; j++) {
MDistributionRunLine runLine = m_runLines[j];
runLine.resetCalculations();
}
// Add Up
for (int i = 0; i < m_details.length; i++) {
MDistributionRunDetail detail = m_details[i];
for (int j = 0; j < m_runLines.length; j++) {
MDistributionRunLine runLine = m_runLines[j];
if (runLine.getM_DistributionRunLine_ID() == detail.getM_DistributionRunLine_ID()) {
// Round
detail.round(runLine.getUOMPrecision());
// Add
runLine.addActualMin(detail.getMinQty());
runLine.addActualQty(detail.getQty());
runLine.addActualAllocation(detail.getActualAllocation());
runLine.setMaxAllocation(detail.getActualAllocation(), false);
//
log.fine("RunLine=" + runLine.getLine() + ": BP_ID=" + detail.getC_BPartner_ID() + ", Min=" + detail.getMinQty() + ", Qty=" + detail.getQty() + ", Allocation=" + detail.getActualAllocation());
continue;
}
}
}
// Info
for (int j = 0; j < m_runLines.length; j++) {
MDistributionRunLine runLine = m_runLines[j];
log.fine("Run - " + runLine.getInfo());
}
}
use of org.compiere.model.MDistributionRunLine in project adempiere by adempiere.
the class DistributionRun method insertDetailsDistributionDemand.
// createOrders
/**
* Insert Details
* @return number of rows inserted
*/
private int insertDetailsDistributionDemand() {
// Handle NULL
String sql = "UPDATE M_DistributionRunLine SET MinQty = 0 WHERE MinQty IS NULL";
int no = DB.executeUpdate(sql, get_TrxName());
sql = "UPDATE M_DistributionListLine SET MinQty = 0 WHERE MinQty IS NULL";
no = DB.executeUpdate(sql, get_TrxName());
// Delete Old
sql = "DELETE FROM T_DistributionRunDetail WHERE M_DistributionRun_ID=" + p_M_DistributionRun_ID;
no = DB.executeUpdate(sql, get_TrxName());
log.fine("insertDetails - deleted #" + no);
// Insert New
sql = "INSERT INTO T_DistributionRunDetail " + "(M_DistributionRun_ID, M_DistributionRunLine_ID, M_DistributionList_ID, M_DistributionListLine_ID," + "AD_Client_ID,AD_Org_ID, IsActive, Created,CreatedBy, Updated,UpdatedBy," + "C_BPartner_ID, C_BPartner_Location_ID, M_Product_ID," + "Ratio, MinQty, Qty) " + "SELECT MAX(rl.M_DistributionRun_ID), MAX(rl.M_DistributionRunLine_ID),MAX(ll.M_DistributionList_ID), MAX(ll.M_DistributionListLine_ID), " + "MAX(rl.AD_Client_ID),MAX(rl.AD_Org_ID), MAX(rl.IsActive), MAX(rl.Created),MAX(rl.CreatedBy), MAX(rl.Updated),MAX(rl.UpdatedBy), " + "MAX(ll.C_BPartner_ID), MAX(ll.C_BPartner_Location_ID), MAX(rl.M_Product_ID)," + // Ration for this process is equal QtyToDeliver
"COALESCE (SUM(ol.QtyOrdered-ol.QtyDelivered-TargetQty), 0) , " + // Min Qty for this process is equal to TargetQty
" 0 , 0 FROM M_DistributionRunLine rl " + "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 DD_Order o ON (o.C_BPartner_ID=ll.C_BPartner_ID AND o.DocStatus IN ('DR','IN')) " + "INNER JOIN DD_OrderLine ol ON (ol.DD_Order_ID=o.DD_Order_ID AND ol.M_Product_ID=rl.M_Product_ID) " + "INNER JOIN M_Locator loc ON (loc.M_Locator_ID=ol.M_Locator_ID AND loc.M_Warehouse_ID=" + p_M_Warehouse_ID + ") " + "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) + " GROUP BY o.M_Shipper_ID , ll.C_BPartner_ID, ol.M_Product_ID";
//+ " BETWEEN "+ DB.TO_DATE(p_DatePromised) +" AND "+ DB.TO_DATE(p_DatePromised_To)
no = DB.executeUpdate(sql, get_TrxName());
List<MDistributionRunDetail> records = new Query(getCtx(), MDistributionRunDetail.Table_Name, MDistributionRunDetail.COLUMNNAME_M_DistributionRun_ID + "=?", get_TrxName()).setParameters(new Object[] { p_M_DistributionRun_ID }).list();
for (MDistributionRunDetail record : records) {
MDistributionRunLine drl = (MDistributionRunLine) MTable.get(getCtx(), MDistributionRunLine.Table_ID).getPO(record.getM_DistributionRunLine_ID(), get_TrxName());
MProduct product = MProduct.get(getCtx(), record.getM_Product_ID());
BigDecimal ration = record.getRatio();
BigDecimal totalration = getQtyDemand(record.getM_Product_ID());
log.info("Value:" + product.getValue());
log.info("Product:" + product.getName());
log.info("Qty To Deliver:" + record.getRatio());
log.info("Qty Target:" + record.getMinQty());
log.info("Qty Total Available:" + drl.getTotalQty());
log.info("Qty Total Demand:" + totalration);
BigDecimal factor = ration.divide(totalration, 12, BigDecimal.ROUND_HALF_UP);
record.setQty(drl.getTotalQty().multiply(factor));
record.saveEx();
}
log.fine("inserted #" + no);
return no;
}
use of org.compiere.model.MDistributionRunLine in project adempiere by adempiere.
the class DistributionRunOrders method groovy1.
public String groovy1(String A_TrxName, Properties A_Ctx, int P_M_Warehouse_ID, int P_M_PriceList_Version_ID, int P_M_DistributionList_ID) {
MDistributionRunLine main = new MDistributionRunLine(A_Ctx, 0, A_TrxName);
MProduct product = MProduct.get(A_Ctx, main.getM_Product_ID());
BigDecimal Qty = main.getTotalQty();
int seq = main.getLine();
int num = 1;
if (product.isBOM() && Qty.signum() > 0) {
seq += 1;
MPPProductBOM bom = MPPProductBOM.getDefault(product, A_TrxName);
//Explotando los componentes
for (MPPProductBOMLine line : bom.getLines()) {
num += 1;
int M_Product_ID = line.getM_Product_ID();
BigDecimal QtyRequired = line.getQtyBOM().multiply(Qty);
BigDecimal QtyAvailable = MStorage.getQtyAvailable(P_M_Warehouse_ID, M_Product_ID, 0, 0, A_TrxName);
BigDecimal QtyOnHand = MPPMRP.getQtyOnHand(A_Ctx, P_M_Warehouse_ID, M_Product_ID, A_TrxName);
BigDecimal QtyToDeliver = QtyRequired;
if (QtyRequired.compareTo(QtyAvailable) > 0)
QtyToDeliver = QtyAvailable;
MDistributionRunLine drl = new MDistributionRunLine(A_Ctx, 0, A_TrxName);
drl.setM_DistributionRun_ID(main.getM_DistributionRun_ID());
drl.setLine(seq);
drl.setM_Product_ID(M_Product_ID);
drl.setM_DistributionList_ID(main.getM_DistributionList_ID());
drl.setDescription(Msg.translate(A_Ctx, "QtyRequired") + " = " + QtyRequired.intValue() + " | " + Msg.translate(A_Ctx, "QtyAvailable") + " = " + QtyAvailable + " | " + Msg.translate(A_Ctx, "QtyOnHand") + " = " + QtyOnHand);
drl.setTotalQty(QtyToDeliver);
drl.saveEx();
}
}
main.setIsActive(false);
return "Componentes del Juego:" + num;
}
use of org.compiere.model.MDistributionRunLine in project adempiere by adempiere.
the class DistributionRunOrders method generateDistribution.
//Create Distribution Run Line
public boolean generateDistribution() {
m_run = new MDistributionRun(this.getCtx(), 0, this.get_TrxName());
m_run.setName("Generate from DRP " + p_DatePromised);
//m_run.setDescription("Generate from DRP");
m_run.save();
StringBuffer sql = new StringBuffer("SELECT M_Product_ID , 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 <= ? AND l.M_Warehouse_ID=? GROUP BY M_Product_ID");
PreparedStatement pstmt = null;
ResultSet rs = null;
try {
pstmt = DB.prepareStatement(sql.toString(), get_TrxName());
pstmt.setTimestamp(1, p_DatePromised);
//pstmt.setTimestamp(2, p_DatePromised_To);
pstmt.setInt(2, p_M_Warehouse_ID);
rs = pstmt.executeQuery();
int line = 10;
while (rs.next()) {
int M_Product_ID = rs.getInt("M_Product_ID");
BigDecimal QtyAvailable = MStorage.getQtyAvailable(p_M_Warehouse_ID, 0, M_Product_ID, 0, get_TrxName());
BigDecimal QtyOrdered = rs.getBigDecimal("TotalQty");
MDistributionRunLine m_runLine = new MDistributionRunLine(getCtx(), 0, get_TrxName());
m_runLine.setM_DistributionRun_ID(m_run.getM_DistributionRun_ID());
m_runLine.setAD_Org_ID(p_AD_Org_ID);
m_runLine.setM_DistributionList_ID(p_M_DistributionList_ID);
m_runLine.setLine(line);
m_runLine.setM_Product_ID(M_Product_ID);
m_runLine.setDescription(Msg.getMsg(getCtx(), "QtyAvailable") + " : " + QtyAvailable + " " + Msg.getMsg(getCtx(), "QtyOrdered") + " : " + QtyOrdered);
if (QtyOrdered.compareTo(QtyAvailable) > 0) {
QtyOrdered = QtyAvailable;
}
m_runLine.setTotalQty(QtyOrdered);
m_runLine.save();
line += 10;
}
} catch (Exception e) {
log.log(Level.SEVERE, "doIt - " + sql, e);
return false;
} finally {
DB.close(rs, pstmt);
rs = null;
pstmt = null;
}
return true;
}
use of org.compiere.model.MDistributionRunLine in project adempiere by adempiere.
the class DistributionRunOrders method groovy.
public String groovy(String A_TrxName, Properties A_Ctx, int P_M_Warehouse_ID, int P_M_PriceList_Version_ID, int P_M_DistributionList_ID) {
MPriceListVersion plv = new MPriceListVersion(A_Ctx, P_M_PriceList_Version_ID, A_TrxName);
MPriceList pl = new MPriceList(A_Ctx, plv.getM_PriceList_ID(), A_TrxName);
MWarehouse w = new MWarehouse(A_Ctx, P_M_Warehouse_ID, A_TrxName);
MDistributionRun dr = new MDistributionRun(A_Ctx, 0, A_TrxName);
dr.setName(plv.getName());
dr.setIsActive(true);
dr.setAD_Org_ID(w.getAD_Org_ID());
dr.saveEx();
MProductPrice[] products = plv.getProductPrice(true);
int seq = 10;
for (MProductPrice pp : products) {
int M_Product_ID = pp.getM_Product_ID();
BigDecimal QtyAvailable = MStorage.getQtyAvailable(P_M_Warehouse_ID, M_Product_ID, 0, 0, A_TrxName);
BigDecimal QtyOnHand = MPPMRP.getQtyOnHand(A_Ctx, P_M_Warehouse_ID, M_Product_ID, A_TrxName);
MDistributionRunLine drl = new MDistributionRunLine(A_Ctx, 0, A_TrxName);
drl.setM_DistributionRun_ID(dr.get_ID());
drl.setLine(seq);
drl.setM_Product_ID(M_Product_ID);
drl.setM_DistributionList_ID(P_M_DistributionList_ID);
drl.setDescription(Msg.translate(A_Ctx, "QtyAvailable") + " = " + QtyAvailable + " | " + Msg.translate(A_Ctx, "QtyOnHand") + " = " + QtyOnHand);
drl.setTotalQty(QtyAvailable);
drl.saveEx();
}
return "";
}
Aggregations