use of org.compiere.model.MRequisitionLine in project adempiere by adempiere.
the class ReplenishReportProduction method createRequisition.
// createPO
/**
* Create Requisition
*/
private void createRequisition() {
int noReqs = 0;
String info = "";
//
MRequisition requisition = null;
MWarehouse wh = null;
X_T_Replenish[] replenishs = getReplenish("M_WarehouseSource_ID IS NULL AND C_BPartner_ID > 0");
for (int i = 0; i < replenishs.length; i++) {
X_T_Replenish replenish = replenishs[i];
if (wh == null || wh.getM_Warehouse_ID() != replenish.getM_Warehouse_ID())
wh = MWarehouse.get(getCtx(), replenish.getM_Warehouse_ID());
//
if (requisition == null || requisition.getM_Warehouse_ID() != replenish.getM_Warehouse_ID()) {
requisition = new MRequisition(getCtx(), 0, get_TrxName());
requisition.setAD_User_ID(getAD_User_ID());
requisition.setC_DocType_ID(p_C_DocType_ID);
requisition.setDescription(Msg.getMsg(getCtx(), "Replenishment"));
// Set Org/WH
requisition.setAD_Org_ID(wh.getAD_Org_ID());
requisition.setM_Warehouse_ID(wh.getM_Warehouse_ID());
if (!requisition.save())
return;
log.fine(requisition.toString());
noReqs++;
info += " - " + requisition.getDocumentNo();
}
//
MRequisitionLine line = new MRequisitionLine(requisition);
line.setM_Product_ID(replenish.getM_Product_ID());
line.setC_BPartner_ID(replenish.getC_BPartner_ID());
line.setQty(replenish.getQtyToOrder());
line.setPrice();
line.save();
}
m_info = "#" + noReqs + info;
log.info(m_info);
}
use of org.compiere.model.MRequisitionLine in project adempiere by adempiere.
the class ReleaseInOutBound method createRequisition.
/**
* Create Requisition when the Is create supply is define as yes
* @param outBoundOrderLine
* @param product Product
* @param QtyPlanned Qty Planned
*/
public void createRequisition(MWMInOutBoundLine outBoundOrderLine, MProduct product, BigDecimal QtyPlanned) {
//s_log.info("Create Requisition");
int partnerId = 0;
int priceListId = 0;
MProductPO productPOLast;
MProductPO[] productPOs = MProductPO.getOfProduct(getCtx(), product.getM_Product_ID(), null);
Arrays.stream(productPOs).forEach(productPO -> {
if (productPO.isCurrentVendor() && productPO.getC_BPartner_ID() != 0) {
}
});
if (partnerId == 0 && productPOs.length > 0) {
partnerId = productPOs[0].getC_BPartner_ID();
}
if (partnerId == 0) {
throw new NoVendorForProductException(product.getName());
}
final String sql = "SELECT COALESCE(bp." + MBPartner.COLUMNNAME_PO_PriceList_ID + ",bpg." + X_C_BP_Group.COLUMNNAME_PO_PriceList_ID + ")" + " FROM C_BPartner bp" + " INNER JOIN C_BP_Group bpg ON (bpg.C_BP_Group_ID=bp.C_BP_Group_ID)" + " WHERE bp.C_BPartner_ID=?";
priceListId = DB.getSQLValueEx(get_TrxName(), sql, partnerId);
MRequisition requisition = new MRequisition(getCtx(), 0, get_TrxName());
requisition.setAD_Org_ID(outBoundLocator.getAD_Org_ID());
requisition.setAD_User_ID(getAD_User_ID());
requisition.setDateRequired(outBoundOrderLine.getPickDate());
// TODO: add translation
requisition.setDescription("Generate from Outbound Order");
requisition.setM_Warehouse_ID(outBoundLocator.getM_Warehouse_ID());
requisition.setC_DocType_ID(MDocType.getDocType(MDocType.DOCBASETYPE_PurchaseRequisition));
if (priceListId > 0)
requisition.setM_PriceList_ID(priceListId);
requisition.saveEx();
MRequisitionLine reqline = new MRequisitionLine(requisition);
reqline.setLine(10);
reqline.setAD_Org_ID(outBoundLocator.getAD_Org_ID());
reqline.setC_BPartner_ID(partnerId);
reqline.setM_Product_ID(product.getM_Product_ID());
reqline.setPrice();
reqline.setPriceActual(Env.ZERO);
reqline.setQty(QtyPlanned);
reqline.saveEx();
MOrderLine orderLine = new MOrderLine(getCtx(), outBoundOrderLine.getC_OrderLine_ID(), get_TrxName());
orderLine.setDescription(orderLine.getDescription() + " " + Msg.translate(getCtx(), MRequisition.COLUMNNAME_M_Requisition_ID) + " : " + requisition.getDocumentNo());
orderLine.saveEx();
outBoundOrderLine.setDescription(outBoundOrderLine.getDescription() + " " + Msg.translate(outBoundOrderLine.getCtx(), MRequisition.COLUMNNAME_M_Requisition_ID) + " : " + requisition.getDocumentNo());
}
use of org.compiere.model.MRequisitionLine in project adempiere by adempiere.
the class Doc_Order method loadRequisitions.
// loadLines
/**
* Load Requisitions
* @return requisition lines of Order
*/
private DocLine[] loadRequisitions() {
MOrder order = (MOrder) getPO();
MOrderLine[] oLines = order.getLines();
HashMap<Integer, BigDecimal> qtys = new HashMap<Integer, BigDecimal>();
for (int i = 0; i < oLines.length; i++) {
MOrderLine line = oLines[i];
qtys.put(new Integer(line.getC_OrderLine_ID()), line.getQtyOrdered());
}
//
ArrayList<DocLine> list = new ArrayList<DocLine>();
String sql = "SELECT * FROM M_RequisitionLine rl " + "WHERE EXISTS (SELECT * FROM C_Order o " + " INNER JOIN C_OrderLine ol ON (o.C_Order_ID=ol.C_Order_ID) " + "WHERE ol.C_OrderLine_ID=rl.C_OrderLine_ID" + " AND o.C_Order_ID=?) " + "ORDER BY rl.C_OrderLine_ID";
PreparedStatement pstmt = null;
ResultSet rs = null;
try {
pstmt = DB.prepareStatement(sql, null);
pstmt.setInt(1, order.getC_Order_ID());
rs = pstmt.executeQuery();
while (rs.next()) {
MRequisitionLine line = new MRequisitionLine(getCtx(), rs, null);
DocLine docLine = new DocLine(line, this);
// Quantity - not more then OrderLine
// Issue: Split of Requisition to multiple POs & different price
Integer key = new Integer(line.getC_OrderLine_ID());
BigDecimal maxQty = qtys.get(key);
BigDecimal Qty = line.getQty().max(maxQty);
if (Qty.signum() == 0)
continue;
docLine.setQty(Qty, false);
qtys.put(key, maxQty.subtract(Qty));
//
BigDecimal PriceActual = line.getPriceActual();
BigDecimal LineNetAmt = line.getLineNetAmt();
if (line.getQty().compareTo(Qty) != 0)
LineNetAmt = PriceActual.multiply(Qty);
// DR
docLine.setAmount(LineNetAmt);
list.add(docLine);
}
} catch (Exception e) {
log.log(Level.SEVERE, sql, e);
} finally {
DB.close(rs, pstmt);
rs = null;
pstmt = null;
}
// Return Array
DocLine[] dls = new DocLine[list.size()];
list.toArray(dls);
return dls;
}
use of org.compiere.model.MRequisitionLine in project adempiere by adempiere.
the class RequisitionPOCreate method doIt.
// prepare
/**
* Process
* @return info
* @throws Exception
*/
protected String doIt() throws Exception {
// Specific
if (p_M_Requisition_ID != 0) {
log.info("M_Requisition_ID=" + p_M_Requisition_ID);
MRequisition req = new MRequisition(getCtx(), p_M_Requisition_ID, get_TrxName());
if (!MRequisition.DOCSTATUS_Completed.equals(req.getDocStatus())) {
throw new AdempiereUserError("@DocStatus@ = " + req.getDocStatus());
}
MRequisitionLine[] lines = req.getLines();
for (int i = 0; i < lines.length; i++) {
if (lines[i].getC_OrderLine_ID() == 0) {
process(lines[i]);
}
}
closeOrder();
return "";
}
// single Requisition
//
log.info("AD_Org_ID=" + p_AD_Org_ID + ", M_Warehouse_ID=" + p_M_Warehouse_ID + ", DateDoc=" + p_DateDoc_From + "/" + p_DateDoc_To + ", DateRequired=" + p_DateRequired_From + "/" + p_DateRequired_To + ", PriorityRule=" + p_PriorityRule + ", AD_User_ID=" + p_AD_User_ID + ", M_Product_ID=" + p_M_Product_ID + ", ConsolidateDocument" + p_ConsolidateDocument);
ArrayList<Object> params = new ArrayList<Object>();
StringBuffer whereClause = new StringBuffer("C_OrderLine_ID IS NULL");
if (p_AD_Org_ID > 0) {
whereClause.append(" AND AD_Org_ID=?");
params.add(p_AD_Org_ID);
}
if (p_M_Product_ID > 0) {
whereClause.append(" AND M_Product_ID=?");
params.add(p_M_Product_ID);
} else if (p_M_Product_Category_ID > 0) {
whereClause.append(" AND EXISTS (SELECT 1 FROM M_Product p WHERE M_RequisitionLine.M_Product_ID=p.M_Product_ID").append(" AND p.M_Product_Category_ID=?)");
params.add(p_M_Product_Category_ID);
}
if (p_C_BP_Group_ID > 0) {
whereClause.append(" AND (").append("M_RequisitionLine.C_BPartner_ID IS NULL").append(" OR EXISTS (SELECT 1 FROM C_BPartner bp WHERE M_RequisitionLine.C_BPartner_ID=bp.C_BPartner_ID AND bp.C_BP_Group_ID=?)").append(")");
params.add(p_C_BP_Group_ID);
}
//
// Requisition Header
whereClause.append(" AND EXISTS (SELECT 1 FROM M_Requisition r WHERE M_RequisitionLine.M_Requisition_ID=r.M_Requisition_ID").append(" AND r.DocStatus=?");
params.add(MRequisition.DOCSTATUS_Completed);
if (p_M_Warehouse_ID > 0) {
whereClause.append(" AND r.M_Warehouse_ID=?");
params.add(p_M_Warehouse_ID);
}
if (p_DateDoc_From != null) {
whereClause.append(" AND r.DateDoc >= ?");
params.add(p_DateDoc_From);
}
if (p_DateDoc_To != null) {
whereClause.append(" AND r.DateDoc <= ?");
params.add(p_DateDoc_To);
}
if (p_DateRequired_From != null) {
whereClause.append(" AND r.DateRequired >= ?");
params.add(p_DateRequired_From);
}
if (p_DateRequired_To != null) {
whereClause.append(" AND r.DateRequired <= ?");
params.add(p_DateRequired_To);
}
if (p_PriorityRule != null) {
whereClause.append(" AND r.PriorityRule >= ?");
params.add(p_PriorityRule);
}
if (p_AD_User_ID > 0) {
whereClause.append(" AND r.AD_User_ID=?");
params.add(p_AD_User_ID);
}
// End Requisition Header
whereClause.append(")");
//
// ORDER BY clause
StringBuffer orderClause = new StringBuffer();
if (!p_ConsolidateDocument) {
orderClause.append("M_Requisition_ID, ");
}
orderClause.append("(SELECT DateRequired FROM M_Requisition r WHERE M_RequisitionLine.M_Requisition_ID=r.M_Requisition_ID),");
orderClause.append("M_Product_ID, C_Charge_ID, M_AttributeSetInstance_ID");
POResultSet<MRequisitionLine> rs = new Query(getCtx(), MRequisitionLine.Table_Name, whereClause.toString(), get_TrxName()).setParameters(params).setOrderBy(orderClause.toString()).setClient_ID().scroll();
try {
while (rs.hasNext()) {
process(rs.next());
}
} finally {
DB.close(rs);
rs = null;
}
closeOrder();
return "";
}
use of org.compiere.model.MRequisitionLine in project adempiere by adempiere.
the class MRP method createRequisition.
protected void createRequisition(int AD_Org_ID, int PP_MRP_ID, MProduct product, BigDecimal QtyPlanned, Timestamp DemandDateStartSchedule, String trxName) throws AdempiereException, SQLException {
log.info("Create Requisition");
int duration = MPPMRP.getDurationDays(QtyPlanned, m_product_planning);
// Get PriceList from BPartner/Group - teo_sarca, FR [ 2829476 ]
int M_PriceList_ID = -1;
if (m_product_planning.getC_BPartner_ID() > 0) {
final String sql = "SELECT COALESCE(bp." + MBPartner.COLUMNNAME_PO_PriceList_ID + ",bpg." + X_C_BP_Group.COLUMNNAME_PO_PriceList_ID + ")" + " FROM C_BPartner bp" + " INNER JOIN C_BP_Group bpg ON (bpg.C_BP_Group_ID=bp.C_BP_Group_ID)" + " WHERE bp.C_BPartner_ID=?";
M_PriceList_ID = DB.getSQLValueEx(trxName, sql, m_product_planning.getC_BPartner_ID());
}
MRequisition req = new MRequisition(getCtx(), 0, trxName);
req.setAD_Org_ID(AD_Org_ID);
req.setAD_User_ID(m_product_planning.getPlanner_ID());
req.setDateDoc(TimeUtil.addDays(DemandDateStartSchedule, 0 - duration));
req.setDateRequired(DemandDateStartSchedule);
req.setM_Warehouse_ID(m_product_planning.getM_Warehouse_ID());
req.setC_DocType_ID(docTypeReq_ID);
if (M_PriceList_ID > 0)
req.setM_PriceList_ID(M_PriceList_ID);
req.saveEx();
// TODO: add translation
req.setDescription(Msg.parseTranslation(getCtx(), "@M_Requisition_ID@ @DocumentNo@ " + req.getDocumentNo() + " @Generate@ @from@ " + getName()));
req.saveEx();
MRequisitionLine reqline = new MRequisitionLine(req);
reqline.setLine(10);
reqline.setAD_Org_ID(AD_Org_ID);
reqline.setC_BPartner_ID(m_product_planning.getC_BPartner_ID());
reqline.setM_Product_ID(m_product_planning.getM_Product_ID());
reqline.setPrice();
reqline.setPriceActual(Env.ZERO);
reqline.setQty(QtyPlanned);
reqline.saveEx();
// Set Correct Dates for Plan
final String whereClause = MPPMRP.COLUMNNAME_M_Requisition_ID + "=?";
List<MPPMRP> mrpList = new Query(getCtx(), MPPMRP.Table_Name, whereClause, trxName).setParameters(new Object[] { req.getM_Requisition_ID() }).list();
for (MPPMRP mrp : mrpList) {
mrp.setDateOrdered(getToday());
mrp.setS_Resource_ID(m_product_planning.getS_Resource_ID());
mrp.setDatePromised(req.getDateRequired());
mrp.setDateStartSchedule(req.getDateDoc());
mrp.setDateFinishSchedule(DemandDateStartSchedule);
mrp.saveEx();
if (MPPMRP.TYPEMRP_Supply.equals(mrp.getTypeMRP()))
supplies.put(mrp.get_ID(), mrp.getQty());
}
count_MR += 1;
}
Aggregations