use of org.eevolution.model.MPPMRP in project adempiere by adempiere.
the class GenerateInOutBound method doIt.
/**
* Process - Generate Export Format
* @return info
*/
protected String doIt() throws Exception {
// Create Outbound Order
MWMInOutBound outBoundOrder = null;
// Based on Sales Order Line
if ("ol".equals(getAliasForTableSelection())) {
outBoundOrder = createOutBoundOrder();
createBasedOnSalesOrders(outBoundOrder, (List<MOrderLine>) getInstancesForSelection(get_TrxName()));
}
// Based on MRP
if ("demand".equals(getAliasForTableSelection())) {
getProcessInfo().setTableSelectionId(MPPMRP.Table_ID);
outBoundOrder = createOutBoundOrder();
createBasedOnDemand(outBoundOrder, (List<MPPMRP>) getInstancesForSelection(get_TrxName()));
}
return "@DocumentNo@ " + outBoundOrder.getDocumentNo();
}
use of org.eevolution.model.MPPMRP in project adempiere by adempiere.
the class MRP method createDDOrder.
protected void createDDOrder(int AD_Org_ID, int PP_MRP_ID, MProduct product, BigDecimal QtyPlanned, Timestamp DemandDateStartSchedule, String trxName) throws AdempiereException, SQLException {
//TODO vpj-cd I need to create logic for DRP-040 Shipment Due Action Notice
//Indicates that a shipment for a Order Distribution is due.
// Action should be taken at the source warehouse to ensure that the order is received on time.
//TODO vpj-cd I need to create logic for DRP-050 Shipment Pas Due Action Notice
//Indicates that a shipment for a Order Distribution is past due. You should either delay the orders created the requirement for the product
//or expedite them when the product does arrive.
//Setting DRP Change net Update out the model validator
MPPMRP.setIsRequired(m_product_planning, MPPProductPlanning.COLUMNNAME_IsRequiredDRP, false, trxName);
if (m_product_planning.getDD_NetworkDistribution_ID() == 0) {
//Indicates that the Product Planning Data for this product does not specify a valid network distribution.
createMRPNote("DRP-060", AD_Org_ID, PP_MRP_ID, product, (String) null, null, null, trxName);
}
//TODO: Create functionality for Valid form and Valid To for an Network Distribution
MDDNetworkDistribution network = MDDNetworkDistribution.get(getCtx(), m_product_planning.getDD_NetworkDistribution_ID());
MDDNetworkDistributionLine[] network_lines = network.getLines(m_product_planning.getM_Warehouse_ID());
int M_Shipper_ID = 0;
MDDOrder order = null;
Integer DD_Order_ID = 0;
for (MDDNetworkDistributionLine network_line : network_lines) {
if (network_line.getM_Shipper_ID() == 0) {
String comment = Msg.translate(getCtx(), MDDNetworkDistribution.COLUMNNAME_Name) + " : " + network.getName();
createMRPNote("DRP-030", AD_Org_ID, PP_MRP_ID, product, null, null, comment, trxName);
continue;
}
//get supply source warehouse and locator
MWarehouse source = new MWarehouse(getCtx(), network_line.getM_WarehouseSource_ID(), trxName);
MLocator locator = MLocator.getDefault(source);
if (locator == null || locator.getM_Locator_ID() <= 0) {
String comment = Msg.translate(getCtx(), " @M_Locator_ID@ @Default@ @NotFound@ @To@ ") + source.getName();
createMRPNote("DRP-001", AD_Org_ID, PP_MRP_ID, product, null, null, comment, trxName);
continue;
}
//get supply target warehouse and locator
MWarehouse target = new MWarehouse(getCtx(), network_line.getM_Warehouse_ID(), trxName);
MLocator locator_to = MLocator.getDefault(target);
if (locator_to == null || locator_to.getM_Locator_ID() <= 0) {
String comment = Msg.translate(getCtx(), " @M_Locator_ID@ @Default@ @NotFound@ @To@ ") + source.getName();
createMRPNote("DRP-001", AD_Org_ID, PP_MRP_ID, product, null, null, comment, trxName);
continue;
}
//get the transfer time
BigDecimal transferTime = network_line.getTransferTime();
if (transferTime.compareTo(Env.ZERO) <= 0) {
transferTime = m_product_planning.getTransferTime();
}
if (locator == null || locator_to == null) {
String comment = Msg.translate(getCtx(), MDDNetworkDistributionLine.COLUMNNAME_M_WarehouseSource_ID) + " : " + source.getName();
createMRPNote("DRP-001", AD_Org_ID, PP_MRP_ID, product, null, null, comment, trxName);
continue;
}
//get the warehouse in transit
MWarehouse[] wsts = MWarehouse.getInTransitForOrg(getCtx(), source.getAD_Org_ID());
if (wsts == null || wsts.length == 0) {
String comment = Msg.translate(getCtx(), MOrg.COLUMNNAME_Name) + " : " + MOrg.get(getCtx(), AD_Org_ID).getName();
createMRPNote("DRP-010", AD_Org_ID, PP_MRP_ID, product, null, null, comment, trxName);
continue;
}
if (M_Shipper_ID != network_line.getM_Shipper_ID()) {
//Org Must be linked to BPartner
MOrg org = MOrg.get(getCtx(), locator_to.getAD_Org_ID());
int C_BPartner_ID = org.getLinkedC_BPartner_ID(trxName);
if (C_BPartner_ID == 0) {
String comment = Msg.translate(getCtx(), MOrg.COLUMNNAME_Name) + " : " + MOrg.get(getCtx(), AD_Org_ID).getName();
createMRPNote("DRP-020", AD_Org_ID, PP_MRP_ID, product, null, null, comment, trxName);
continue;
}
MBPartner bp = getBPartner(C_BPartner_ID);
// Try found some order with Shipper , Business Partner and Doc Status = Draft
// Consolidate the demand in a single order for each Shipper , Business Partner , DemandDateStartSchedule
DD_Order_ID = getDDOrder_ID(AD_Org_ID, wsts[0].get_ID(), network_line.getM_Shipper_ID(), bp.getC_BPartner_ID(), TimeUtil.getDay(DemandDateStartSchedule.getTime()), trxName);
if (DD_Order_ID <= 0) {
order = new MDDOrder(getCtx(), 0, trxName);
order.setAD_Org_ID(target.getAD_Org_ID());
order.setC_BPartner_ID(C_BPartner_ID);
order.setAD_User_ID(bp.getPrimaryAD_User_ID());
order.setC_DocType_ID(docTypeDO_ID);
order.setM_Warehouse_ID(wsts[0].get_ID());
order.setDocAction(MDDOrder.DOCACTION_Complete);
order.setDateOrdered(TimeUtil.addDays(DemandDateStartSchedule, (m_product_planning.getDeliveryTime_Promised().add(transferTime)).negate().intValueExact()));
order.setDatePromised(DemandDateStartSchedule);
order.setM_Shipper_ID(network_line.getM_Shipper_ID());
order.setIsInDispute(false);
order.setIsInTransit(false);
order.setSalesRep_ID(m_product_planning.getPlanner_ID());
order.setProcessed(false);
order.setProcessing(false);
order.saveEx();
order.addDescription(Msg.parseTranslation(getCtx(), "@DD_Order_ID@ @DocumentNo@ " + order.getDocumentNo() + " @Generate@ @from@ " + getName()));
order.saveEx();
DD_Order_ID = order.get_ID();
String key = order.getAD_Org_ID() + "#" + order.getM_Warehouse_ID() + "#" + network_line.getM_Shipper_ID() + "#" + C_BPartner_ID + "#" + TimeUtil.getDay(DemandDateStartSchedule.getTime()) + "DR";
dd_order_id_cache.put(key, DD_Order_ID);
} else {
order = new MDDOrder(getCtx(), DD_Order_ID, trxName);
}
M_Shipper_ID = network_line.getM_Shipper_ID();
}
BigDecimal QtyOrdered = QtyPlanned.multiply(network_line.getPercent()).divide(Env.ONEHUNDRED);
MDDOrderLine oline = new MDDOrderLine(getCtx(), 0, trxName);
oline.setDD_Order_ID(order.getDD_Order_ID());
oline.setAD_Org_ID(target.getAD_Org_ID());
oline.setM_Locator_ID(locator.getM_Locator_ID());
oline.setM_LocatorTo_ID(locator_to.getM_Locator_ID());
oline.setM_Product_ID(m_product_planning.getM_Product_ID());
oline.setDateOrdered(order.getDateOrdered());
oline.setDatePromised(DemandDateStartSchedule);
oline.setQtyEntered(QtyOrdered);
oline.setQtyOrdered(QtyOrdered);
oline.setTargetQty(MPPMRP.getQtyReserved(getCtx(), target.getM_Warehouse_ID(), m_product_planning.getM_Product_ID(), DemandDateStartSchedule, trxName));
oline.setIsInvoiced(false);
oline.saveEx();
// Set Correct Dates for Plan
final String whereClause = MPPMRP.COLUMNNAME_DD_OrderLine_ID + "=?";
List<MPPMRP> mrpList = new Query(getCtx(), MPPMRP.Table_Name, whereClause, trxName).setParameters(new Object[] { oline.getDD_OrderLine_ID() }).list();
for (MPPMRP mrp : mrpList) {
mrp.setDateOrdered(getToday());
mrp.setDateOrdered(mrp.getDD_Order().getDateOrdered());
mrp.setDateStartSchedule(mrp.getDateOrdered());
mrp.setDatePromised(DemandDateStartSchedule);
mrp.setDateFinishSchedule(DemandDateStartSchedule);
mrp.saveEx();
if (MPPMRP.TYPEMRP_Supply.equals(mrp.getTypeMRP()))
supplies.put(mrp.get_ID(), mrp.getQty());
}
count_DO += 1;
}
}
use of org.eevolution.model.MPPMRP 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.eevolution.model.MPPMRP in project adempiere by adempiere.
the class MRP method getNetRequirements.
/**
* Get ScheduledReceipts to cover the ProjectQtyOnhand
* @param AD_Client_ID
* @param AD_Org_ID
* @param M_Warehouse_ID
* @param product
* @param ProjectQtyOnhand
* @param DemandDateStartSchedule
* @return Net Requirements:
* <li>positive qty means entire qty is available or scheduled to receipt
* <li>negative qty means qty net required
* @throws SQLException
*/
private BigDecimal getNetRequirements(int AD_Client_ID, int AD_Org_ID, int M_Warehouse_ID, MProduct product, Timestamp DemandDateStartSchedule, String trxName) throws SQLException {
BigDecimal QtyNetReqs = QtyProjectOnHand.subtract(QtyGrossReqs);
final String whereClause = // Planning Dimension
"AD_Client_ID=? AND AD_Org_ID=?" + " AND M_Product_ID=? AND M_Warehouse_ID=?" + // Scheduled Receipts & Planned Orders
" AND TypeMRP=? AND DocStatus IN (?,?,?)" + // NonZero Qty
" AND Qty<>0" + // Only available
" AND " + MPPMRP.COLUMNNAME_IsAvailable + "=?";
ArrayList<Object> parameters = new ArrayList<Object>();
parameters.add(AD_Client_ID);
parameters.add(AD_Org_ID);
parameters.add(product.get_ID());
parameters.add(M_Warehouse_ID);
parameters.add(MPPMRP.TYPEMRP_Supply);
parameters.add(MPPMRP.DOCSTATUS_Completed);
parameters.add(MPPMRP.DOCSTATUS_InProgress);
parameters.add(MPPMRP.DOCSTATUS_Drafted);
parameters.add(true);
Collection<MPPMRP> mrps = new Query(getCtx(), MPPMRP.Table_Name, whereClause, trxName).setParameters(parameters).setOrderBy(MPPMRP.COLUMNNAME_DateStartSchedule).list();
for (MPPMRP mrp : mrps) {
if (mrp.isReleased()) {
QtyScheduledReceipts = QtyScheduledReceipts.add(mrp.getQty());
supplies.put(mrp.get_ID(), mrp.getQty());
}
if (DemandDateStartSchedule != null) {
// aka: Push Out
if (mrp.isReleased() && QtyNetReqs.negate().signum() > 0 && mrp.getDateStartSchedule() != null && mrp.getDateStartSchedule().compareTo(DemandDateStartSchedule) < 0) {
String comment = Msg.translate(getCtx(), MPPMRP.COLUMNNAME_DateStartSchedule) + " : " + mrp.getDateStartSchedule() + "\n" + Msg.translate(getCtx(), MPPMRP.COLUMNNAME_DatePromised) + " : " + DemandDateStartSchedule;
createMRPNote("MRP-030", mrp, product, comment, trxName);
}
// aka: Pull In
if (mrp.isReleased() && QtyNetReqs.negate().signum() > 0 && mrp.getDateStartSchedule() != null && mrp.getDateStartSchedule().compareTo(DemandDateStartSchedule) > 0) {
String comment = Msg.translate(getCtx(), MPPMRP.COLUMNNAME_DateStartSchedule) + " : " + mrp.getDateStartSchedule() + "\n " + Msg.translate(getCtx(), MPPMRP.COLUMNNAME_DatePromised) + " : " + DemandDateStartSchedule;
createMRPNote("MRP-040", mrp, product, comment, trxName);
}
// if(date release > today && date release + after floating)
if (!mrp.isReleased() && QtyNetReqs.negate().signum() > 0 && mrp.getDateStartSchedule() != null && mrp.getDatePromised().compareTo(getToday()) >= 0) {
String comment = Msg.translate(getCtx(), MPPMRP.COLUMNNAME_DatePromised) + " : " + mrp.getDatePromised();
createMRPNote("MRP-060", mrp, product, comment, trxName);
}
// if (date release < today && date erelese + before floating)
if (!mrp.isReleased() && QtyNetReqs.negate().signum() > 0 && mrp.getDateStartSchedule() != null && mrp.getDatePromised().compareTo(getToday()) < 0) {
String comment = Msg.translate(getCtx(), MPPMRP.COLUMNNAME_DatePromised) + " : " + mrp.getDatePromised();
createMRPNote("MRP-070", mrp, product, comment, trxName);
}
//Indicates that a schedule supply order receipt is past due.
if (mrp.isReleased() && mrp.getDateStartSchedule() != null && mrp.getDatePromised().compareTo(getToday()) < 0) {
String comment = Msg.translate(getCtx(), MPPMRP.COLUMNNAME_DatePromised) + " : " + mrp.getDatePromised();
createMRPNote("MRP-110", mrp, product, comment, trxName);
}
mrp.setIsAvailable(false);
mrp.saveEx();
QtyNetReqs = QtyNetReqs.add(mrp.getQty());
if (QtyNetReqs.signum() >= 0) {
return QtyNetReqs;
}
} else {
//Indicate that a scheduled supply order is no longer needed and should be deleted.
if (mrp.isReleased() && QtyScheduledReceipts.signum() > 0) {
String comment = Msg.translate(getCtx(), MPPMRP.COLUMNNAME_DatePromised) + " : " + mrp.getDatePromised();
createMRPNote("MRP-050", mrp, product, comment, trxName);
}
mrp.setIsAvailable(false);
mrp.saveEx();
QtyNetReqs = QtyNetReqs.add(mrp.getQty());
}
}
return QtyNetReqs;
}
use of org.eevolution.model.MPPMRP in project adempiere by adempiere.
the class MRP method createPPOrder.
protected void createPPOrder(int AD_Org_ID, int PP_MRP_ID, MProduct product, BigDecimal QtyPlanned, Timestamp DemandDateStartSchedule, String trxName) throws AdempiereException, SQLException {
log.info("PP_Product_BOM_ID:" + m_product_planning.getPP_Product_BOM_ID() + ", AD_Workflow_ID:" + m_product_planning.getAD_Workflow_ID());
if (m_product_planning.getPP_Product_BOM_ID() == 0 || m_product_planning.getAD_Workflow_ID() == 0) {
throw new AdempiereException("@FillMandatory@ @PP_Product_BOM_ID@, @AD_Workflow_ID@ ( @M_Product_ID@=" + product.getValue() + ")");
}
int duration = MPPMRP.getDurationDays(QtyPlanned, m_product_planning);
MPPOrder order = new MPPOrder(getCtx(), 0, trxName);
order.setAD_Org_ID(AD_Org_ID);
order.setLine(10);
if (MPPProductBOM.BOMTYPE_Maintenance.equals(getBOMType(trxName))) {
log.info("Maintenance Order Created");
order.setC_DocTypeTarget_ID(docTypeMF_ID);
order.setC_DocType_ID(docTypeMF_ID);
} else {
log.info("Manufacturing Order Created");
order.setC_DocTypeTarget_ID(docTypeMO_ID);
order.setC_DocType_ID(docTypeMO_ID);
}
order.setS_Resource_ID(m_product_planning.getS_Resource_ID());
order.setM_Warehouse_ID(m_product_planning.getM_Warehouse_ID());
order.setM_Product_ID(m_product_planning.getM_Product_ID());
order.setM_AttributeSetInstance_ID(0);
order.setPP_Product_BOM_ID(m_product_planning.getPP_Product_BOM_ID());
order.setAD_Workflow_ID(m_product_planning.getAD_Workflow_ID());
order.setPlanner_ID(m_product_planning.getPlanner_ID());
order.setDateOrdered(getToday());
order.setDatePromised(DemandDateStartSchedule);
order.setDateStartSchedule(TimeUtil.addDays(DemandDateStartSchedule, 0 - duration));
order.setDateFinishSchedule(DemandDateStartSchedule);
order.setQty(QtyPlanned);
// QtyBatchSize : do not set it, let the MO to take it from workflow
order.setC_UOM_ID(product.getC_UOM_ID());
order.setYield(Env.ZERO);
order.setScheduleType(MPPMRP.TYPEMRP_Demand);
order.setPriorityRule(MPPOrder.PRIORITYRULE_Medium);
order.setDocAction(MPPOrder.DOCACTION_Complete);
order.saveEx();
order.addDescription(Msg.parseTranslation(getCtx(), "@PP_Order_ID@ @DocumentNo@ " + order.getDocumentNo() + " @Generate@ @from@ " + getName()));
order.saveEx();
MPPMRP mrp = getSupply(MPPOrder.COLUMNNAME_PP_Order_ID, order.get_ID(), null, null, trxName);
supplies.put(mrp.get_ID(), mrp.getQty());
count_MO += 1;
}
Aggregations