use of org.compiere.model.MRequisition 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.MRequisition 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;
}
use of org.compiere.model.MRequisition in project adempiere by adempiere.
the class MRPApproval method createRequisition.
private MRequisition createRequisition(MPPMRP mrp) {
if (MPPMRP.ORDERTYPE_ManufacturingOrder.equals(mrp.getOrderType())) {
int docTypeId = MPPMRP.getDocType(getCtx(), MDocType.DOCBASETYPE_PurchaseRequisition, mrp.getAD_Org_ID(), Env.getAD_User_ID(getCtx()), get_TrxName());
// Get PriceList from BPartner/Group - teo_sarca, FR [ 2829476 ]
int priceListId = -1;
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, getBusinessPartnerId());
MRequisition requisition = new MRequisition(getCtx(), 0, get_TrxName());
requisition.setAD_Org_ID(mrp.getAD_Org_ID());
requisition.setAD_User_ID(mrp.getPlanner_ID());
requisition.setDateDoc(mrp.getDateStartSchedule());
requisition.setDateRequired(mrp.getDatePromised());
// req.setDescription(""); // TODO: add translation
requisition.setM_Warehouse_ID(mrp.getM_Warehouse_ID());
requisition.setC_DocType_ID(docTypeId);
if (priceListId > 0)
requisition.setM_PriceList_ID(priceListId);
requisition.saveEx();
MRequisitionLine requisitionLine = new MRequisitionLine(requisition);
requisitionLine.setLine(10);
requisitionLine.setAD_Org_ID(mrp.getAD_Org_ID());
requisitionLine.setC_BPartner_ID(mrp.getC_BPartner_ID());
requisitionLine.setM_Product_ID(mrp.getM_Product_ID());
requisitionLine.setPrice();
if (getReferenceNo() != null)
requisitionLine.setDescription(getReferenceNo());
requisitionLine.setPriceActual(Env.ZERO);
requisitionLine.setQty(mrp.getQty());
requisitionLine.saveEx();
requisition.processIt(DocAction.ACTION_Prepare);
requisition.saveEx();
return requisition;
}
return null;
}
use of org.compiere.model.MRequisition in project adempiere by adempiere.
the class MRPApproval method executeRequisitionApproval.
private void executeRequisitionApproval(MPPMRP mrp) {
MRequisition requisition = (MRequisition) mrp.getM_Requisition();
Timestamp dateRequired = getSelectionAsTimestamp(mrp.getPP_MRP_ID(), "R_" + MRequisition.COLUMNNAME_DateRequired);
if (dateRequired != null)
requisition.setDateRequired(dateRequired);
if (mrp.is_Changed())
;
{
validateChanges(mrp, MPPMRP.COLUMNNAME_Priority, requisition, MRequisition.COLUMNNAME_PriorityRule);
requisition.saveEx();
MRequisitionLine requisitionLine = (MRequisitionLine) mrp.getM_RequisitionLine();
validateChanges(mrp, MPPMRP.COLUMNNAME_C_BPartner_ID, requisitionLine, MRequisitionLine.COLUMNNAME_C_BPartner_ID);
validateChanges(mrp, MPPMRP.COLUMNNAME_Qty, requisitionLine, MRequisitionLine.COLUMNNAME_Qty);
requisitionLine.saveEx();
}
requisition.processIt(DocAction.ACTION_Prepare);
requisition.saveEx();
}
use of org.compiere.model.MRequisition in project adempiere by adempiere.
the class MPPMRP method M_RequisitionLine.
/**
* Create MRP record based in Requisition Line
* @param MRequisitionLine Requisition Line
*/
public static void M_RequisitionLine(MRequisitionLine rl) {
MPPMRP mrp = getQuery(rl, null, null).firstOnly();
MRequisition r = rl.getParent();
if (mrp == null) {
mrp = new MPPMRP(rl.getCtx(), 0, rl.get_TrxName());
mrp.setM_Requisition_ID(rl.getM_Requisition_ID());
mrp.setM_RequisitionLine_ID(rl.getM_RequisitionLine_ID());
}
mrp.setM_Requisition(r);
mrp.setAD_Org_ID(rl.getAD_Org_ID());
mrp.setName("MRP");
mrp.setDescription(rl.getDescription());
mrp.setM_Product_ID(rl.getM_Product_ID());
mrp.setC_BPartner_ID(rl.getC_BPartner_ID());
mrp.setPriority(rl.getParent().getPriorityRule());
// We create a MRP record only for Not Ordered Qty. The Order will generate a MRP record for Ordered Qty.
mrp.setQty(rl.getQty().subtract(rl.getQtyOrdered()));
// MRP record for a requisition will be ALWAYS Drafted because
// a requisition generates just Planned Orders (which is a wish list)
// and not Scheduled Receipts
// mrp.setDocStatus(DocAction.STATUS_Drafted);
mrp.saveEx();
}
Aggregations