parent
d51e50402e
commit
f3487bc607
|
@ -20,20 +20,18 @@ import java.sql.Timestamp;
|
||||||
import java.text.MessageFormat;
|
import java.text.MessageFormat;
|
||||||
import java.util.Calendar;
|
import java.util.Calendar;
|
||||||
import java.util.GregorianCalendar;
|
import java.util.GregorianCalendar;
|
||||||
import java.util.logging.*;
|
import java.util.logging.Level;
|
||||||
|
|
||||||
import org.compiere.model.MResource;
|
import org.compiere.model.MResource;
|
||||||
import org.compiere.model.MResourceType;
|
import org.compiere.model.MResourceType;
|
||||||
import org.compiere.model.MResourceUnAvailable;
|
import org.compiere.model.MResourceUnAvailable;
|
||||||
import org.compiere.model.PO;
|
import org.compiere.model.PO;
|
||||||
|
import org.compiere.util.CLogger;
|
||||||
import org.compiere.util.Env;
|
import org.compiere.util.Env;
|
||||||
import org.compiere.util.*;
|
|
||||||
|
|
||||||
import org.eevolution.tools.DateTimeUtil;
|
|
||||||
|
|
||||||
import org.eevolution.model.MPPOrder;
|
import org.eevolution.model.MPPOrder;
|
||||||
import org.eevolution.model.MPPOrderNode;
|
import org.eevolution.model.MPPOrderNode;
|
||||||
import org.eevolution.model.MPPOrderWorkflow;
|
import org.eevolution.model.MPPOrderWorkflow;
|
||||||
|
import org.eevolution.tools.DateTimeUtil;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -41,17 +39,17 @@ import org.eevolution.model.MPPOrderWorkflow;
|
||||||
* @version 1.0, October 14th 2005
|
* @version 1.0, October 14th 2005
|
||||||
*/
|
*/
|
||||||
public class CRPReasoner {
|
public class CRPReasoner {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* All the below cases expect exactly two parameters: The (1) begin and the (2) end of a day
|
* All the below cases expect exactly two parameters: The (1) begin and the (2) end of a day
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Case 1: The time dependent process has already begun and ends at this day.
|
* Case 1: The time dependent process has already begun and ends at this day.
|
||||||
*/
|
*/
|
||||||
public static final String RESTRICTION_DAY_CASE_1 =
|
public static final String RESTRICTION_DAY_CASE_1 =
|
||||||
"(datestartschedule<=''{0}'' AND datefinishschedule>=''{0}'' AND datefinishschedule<=''{1}'')";
|
"(datestartschedule<=''{0}'' AND datefinishschedule>=''{0}'' AND datefinishschedule<=''{1}'')";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Case 2: The time dependent process begins and ends at this day.
|
* Case 2: The time dependent process begins and ends at this day.
|
||||||
*/
|
*/
|
||||||
|
@ -63,214 +61,214 @@ public class CRPReasoner {
|
||||||
*/
|
*/
|
||||||
public static final String RESTRICTION_DAY_CASE_3 =
|
public static final String RESTRICTION_DAY_CASE_3 =
|
||||||
"(datestartschedule>=''{0}'' AND datestartschedule<=''{1}'' AND datefinishschedule>=''{1}'')";
|
"(datestartschedule>=''{0}'' AND datestartschedule<=''{1}'' AND datefinishschedule>=''{1}'')";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Case 4: The time dependent process has already begun and ends few days later.
|
* Case 4: The time dependent process has already begun and ends few days later.
|
||||||
*/
|
*/
|
||||||
public static final String RESTRICTION_DAY_CASE_4 =
|
public static final String RESTRICTION_DAY_CASE_4 =
|
||||||
"(datestartschedule<=''{0}'' AND datefinishschedule>=''{1}'')";
|
"(datestartschedule<=''{0}'' AND datefinishschedule>=''{1}'')";
|
||||||
|
|
||||||
private static CLogger log = CLogger.getCLogger (CRPReasoner.class);
|
private static CLogger log = CLogger.getCLogger (CRPReasoner.class);
|
||||||
|
|
||||||
|
|
||||||
private String getDayRestriction(Timestamp dateTime, MResource r) {
|
private String getDayRestriction(Timestamp dateTime, MResource r) {
|
||||||
|
|
||||||
Object[] params = { getBorderDayMin(dateTime, r).toString(), getBorderDayMax(dateTime, r).toString() };
|
Object[] params = { getBorderDayMin(dateTime, r).toString(), getBorderDayMax(dateTime, r).toString() };
|
||||||
|
|
||||||
return
|
return
|
||||||
MessageFormat.format(RESTRICTION_DAY_CASE_1, params)+
|
MessageFormat.format(RESTRICTION_DAY_CASE_1, params)+
|
||||||
" OR "+MessageFormat.format(RESTRICTION_DAY_CASE_2, params)+
|
" OR "+MessageFormat.format(RESTRICTION_DAY_CASE_2, params)+
|
||||||
" OR "+MessageFormat.format(RESTRICTION_DAY_CASE_3, params)+
|
" OR "+MessageFormat.format(RESTRICTION_DAY_CASE_3, params)+
|
||||||
" OR "+MessageFormat.format(RESTRICTION_DAY_CASE_4, params);
|
" OR "+MessageFormat.format(RESTRICTION_DAY_CASE_4, params);
|
||||||
}
|
}
|
||||||
|
|
||||||
public MPPOrder[] getPPOrdersNotCompleted(MResource r) {
|
|
||||||
|
|
||||||
//String sql = "SELECT owf.PP_Order_Workflow_ID , o.DateStartSchedule , o.DateFinishSchedule ,o.QtyOrdered - o.QtyDelivered - o.QtyScrap AS QtyOpen FROM PP_Order o INNER JOIN PP_Order_Workflow owf ON (owf.PP_ORDER_ID = o.PP_Order_ID) WHERE o.DocStatus <> 'CL' AND o.AD_Client_ID = ? AND o.S_Resource_ID= ? ORDER BY DatePromised" ;
|
public MPPOrder[] getPPOrdersNotCompleted(MResource r) {
|
||||||
String where =
|
|
||||||
// Checks the requested resource id directly on order node, not on resource id of the order
|
|
||||||
//"PP_Order_ID IN (SELECT PP_Order_ID FROM PP_Order_Node on WHERE on.S_Resource_ID="+r.getID()+")"
|
|
||||||
"S_Resource_ID="+r.get_ID() +" AND DocStatus <> 'CL' AND AD_Client_ID = " + r.getAD_Client_ID() ; //+ " AND PP_Order_ID = 1000031" ;
|
|
||||||
// ... and completed orders needn't to be observed
|
|
||||||
|
|
||||||
int[] orderIds = PO.getAllIDs("PP_Order", where, null);
|
|
||||||
MPPOrder[] orders = new MPPOrder[orderIds.length];
|
|
||||||
for(int i = 0; i < orderIds.length; i++) {
|
|
||||||
|
|
||||||
orders[i] = new MPPOrder(Env.getCtx(), orderIds[i], null);
|
|
||||||
}
|
|
||||||
|
|
||||||
return orders;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Timestamp getBorderDayMin(Timestamp dateTime, MResource r) {
|
|
||||||
|
|
||||||
MResourceType t = new MResourceType(Env.getCtx(), r.getS_ResourceType_ID(), null);
|
|
||||||
Timestamp dMin = null;
|
|
||||||
return (t.isTimeSlot()) ?
|
|
||||||
DateTimeUtil.getDayBorder(dateTime, t.getTimeSlotStart(), false) :
|
|
||||||
DateTimeUtil.getDayBorder(dateTime, null, false);
|
|
||||||
}
|
|
||||||
|
|
||||||
public Timestamp getBorderDayMax(Timestamp dateTime, MResource r) {
|
//String sql = "SELECT owf.PP_Order_Workflow_ID , o.DateStartSchedule , o.DateFinishSchedule ,o.QtyOrdered - o.QtyDelivered - o.QtyScrap AS QtyOpen FROM PP_Order o INNER JOIN PP_Order_Workflow owf ON (owf.PP_ORDER_ID = o.PP_Order_ID) WHERE o.DocStatus <> 'CL' AND o.AD_Client_ID = ? AND o.S_Resource_ID= ? ORDER BY DatePromised" ;
|
||||||
|
String where =
|
||||||
MResourceType t = new MResourceType(Env.getCtx(), r.getS_ResourceType_ID(), null);
|
// Checks the requested resource id directly on order node, not on resource id of the order
|
||||||
Timestamp dMin = null;
|
//"PP_Order_ID IN (SELECT PP_Order_ID FROM PP_Order_Node on WHERE on.S_Resource_ID="+r.getID()+")"
|
||||||
return (t.isTimeSlot()) ?
|
"S_Resource_ID="+r.get_ID() +" AND DocStatus <> 'CL' AND AD_Client_ID = " + r.getAD_Client_ID() ; //+ " AND PP_Order_ID = 1000031" ;
|
||||||
DateTimeUtil.getDayBorder(dateTime, t.getTimeSlotEnd(), true) :
|
// ... and completed orders needn't to be observed
|
||||||
DateTimeUtil.getDayBorder(dateTime, null, true);
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean isResourceAvailable(Timestamp dateTime, MResource r) {
|
|
||||||
|
|
||||||
MResourceType t = new MResourceType(Env.getCtx(), r.getS_ResourceType_ID(), null);
|
|
||||||
|
|
||||||
return ( checkResourceAvailability(dateTime, r) && checkResourceTypeAvailability(dateTime, t) );
|
int[] orderIds = PO.getAllIDs("PP_Order", where, null);
|
||||||
}
|
MPPOrder[] orders = new MPPOrder[orderIds.length];
|
||||||
|
for(int i = 0; i < orderIds.length; i++) {
|
||||||
public MPPOrder[] getPPOrders(Timestamp dateTime, MResource r) {
|
|
||||||
|
|
||||||
if(!isResourceAvailable(dateTime, r)) {
|
orders[i] = new MPPOrder(Env.getCtx(), orderIds[i], null);
|
||||||
|
}
|
||||||
return new MPPOrder[0];
|
|
||||||
}
|
|
||||||
|
|
||||||
String where =
|
|
||||||
// Checks the requested resource id directly on order node, not on resource id of the order
|
|
||||||
"PP_order_id in (select PP_order_id from PP_order_node where s_resource_id="+r.get_ID()
|
|
||||||
// ... and only the orders running on given day
|
|
||||||
+" AND ("+getDayRestriction(dateTime, r)+") ) AND AD_Client_ID =" + r.getAD_Client_ID();
|
|
||||||
|
|
||||||
int[] orderIds = PO.getAllIDs("PP_Order", where, null);
|
|
||||||
MPPOrder[] orders = new MPPOrder[orderIds.length];
|
|
||||||
for(int i = 0; i < orderIds.length; i++) {
|
|
||||||
|
|
||||||
orders[i] = new MPPOrder(Env.getCtx(), orderIds[i], null);
|
|
||||||
}
|
|
||||||
|
|
||||||
return orders;
|
|
||||||
}
|
|
||||||
|
|
||||||
public MPPOrderNode[] getPPOrderNodes(Timestamp dateTime, MResource r) {
|
|
||||||
|
|
||||||
if(!isResourceAvailable(dateTime, r)) {
|
return orders;
|
||||||
|
}
|
||||||
return new MPPOrderNode[0];
|
|
||||||
}
|
|
||||||
|
|
||||||
String where =
|
public Timestamp getBorderDayMin(Timestamp dateTime, MResource r) {
|
||||||
"s_resource_id = "+r.get_ID()
|
|
||||||
+" AND ("+getDayRestriction(dateTime, r)+") AND AD_Client_ID = " + r.getAD_Client_ID();
|
|
||||||
log.log(Level.FINE,"getPPOrderNodes --> Where:" + where);
|
|
||||||
int[] ids = PO.getAllIDs("PP_Order_Node", where, null);
|
|
||||||
|
|
||||||
MPPOrderNode[] nodes = new MPPOrderNode[ids.length];
|
|
||||||
for(int i = 0; i < ids.length; i++) {
|
|
||||||
|
|
||||||
nodes[i] = new MPPOrderNode(Env.getCtx(), ids[i], null);
|
|
||||||
}
|
|
||||||
|
|
||||||
return nodes;
|
|
||||||
}
|
|
||||||
|
|
||||||
public MPPOrderWorkflow getPPOrderWorkflow(MPPOrder o) {
|
MResourceType t = new MResourceType(Env.getCtx(), r.getS_ResourceType_ID(), null);
|
||||||
|
Timestamp dMin = null;
|
||||||
|
return (t.isTimeSlot()) ?
|
||||||
|
DateTimeUtil.getDayBorder(dateTime, t.getTimeSlotStart(), false) :
|
||||||
|
DateTimeUtil.getDayBorder(dateTime, null, false);
|
||||||
|
}
|
||||||
|
|
||||||
int[] ids = PO.getAllIDs("PP_Order_Workflow", "PP_Order_ID = "+o.get_ID() + " AND AD_Client_ID = " + o.getAD_Client_ID(), null);
|
public Timestamp getBorderDayMax(Timestamp dateTime, MResource r) {
|
||||||
|
|
||||||
|
MResourceType t = new MResourceType(Env.getCtx(), r.getS_ResourceType_ID(), null);
|
||||||
|
Timestamp dMin = null;
|
||||||
|
return (t.isTimeSlot()) ?
|
||||||
|
DateTimeUtil.getDayBorder(dateTime, t.getTimeSlotEnd(), true) :
|
||||||
|
DateTimeUtil.getDayBorder(dateTime, null, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isResourceAvailable(Timestamp dateTime, MResource r) {
|
||||||
|
|
||||||
|
MResourceType t = new MResourceType(Env.getCtx(), r.getS_ResourceType_ID(), null);
|
||||||
|
|
||||||
|
return ( checkResourceAvailability(dateTime, r) && checkResourceTypeAvailability(dateTime, t) );
|
||||||
|
}
|
||||||
|
|
||||||
|
public MPPOrder[] getPPOrders(Timestamp dateTime, MResource r) {
|
||||||
|
|
||||||
|
if(!isResourceAvailable(dateTime, r)) {
|
||||||
|
|
||||||
|
return new MPPOrder[0];
|
||||||
|
}
|
||||||
|
|
||||||
|
String where =
|
||||||
|
// Checks the requested resource id directly on order node, not on resource id of the order
|
||||||
|
"PP_order_id in (select PP_order_id from PP_order_node where s_resource_id="+r.get_ID()
|
||||||
|
// ... and only the orders running on given day
|
||||||
|
+" AND ("+getDayRestriction(dateTime, r)+") ) AND AD_Client_ID =" + r.getAD_Client_ID();
|
||||||
|
|
||||||
|
int[] orderIds = PO.getAllIDs("PP_Order", where, null);
|
||||||
|
MPPOrder[] orders = new MPPOrder[orderIds.length];
|
||||||
|
for(int i = 0; i < orderIds.length; i++) {
|
||||||
|
|
||||||
|
orders[i] = new MPPOrder(Env.getCtx(), orderIds[i], null);
|
||||||
|
}
|
||||||
|
|
||||||
|
return orders;
|
||||||
|
}
|
||||||
|
|
||||||
|
public MPPOrderNode[] getPPOrderNodes(Timestamp dateTime, MResource r) {
|
||||||
|
|
||||||
|
if(!isResourceAvailable(dateTime, r)) {
|
||||||
|
|
||||||
|
return new MPPOrderNode[0];
|
||||||
|
}
|
||||||
|
|
||||||
|
String where =
|
||||||
|
"s_resource_id = "+r.get_ID()
|
||||||
|
+" AND ("+getDayRestriction(dateTime, r)+") AND AD_Client_ID = " + r.getAD_Client_ID();
|
||||||
|
log.log(Level.FINE,"getPPOrderNodes --> Where:" + where);
|
||||||
|
int[] ids = PO.getAllIDs("PP_Order_Node", where, null);
|
||||||
|
|
||||||
|
MPPOrderNode[] nodes = new MPPOrderNode[ids.length];
|
||||||
|
for(int i = 0; i < ids.length; i++) {
|
||||||
|
|
||||||
|
nodes[i] = new MPPOrderNode(Env.getCtx(), ids[i], null);
|
||||||
|
}
|
||||||
|
|
||||||
|
return nodes;
|
||||||
|
}
|
||||||
|
|
||||||
|
public MPPOrderWorkflow getPPOrderWorkflow(MPPOrder o) {
|
||||||
|
|
||||||
|
int[] ids = PO.getAllIDs("PP_Order_Workflow", "PP_Order_ID = "+o.get_ID() + " AND AD_Client_ID = " + o.getAD_Client_ID(), null);
|
||||||
|
|
||||||
|
return (ids.length != 1) ? null : new MPPOrderWorkflow(Env.getCtx(), ids[0], null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean checkResourceTypeAvailability(MResourceType t) {
|
||||||
|
|
||||||
return (ids.length != 1) ? null : new MPPOrderWorkflow(Env.getCtx(), ids[0], null);
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean checkResourceTypeAvailability(MResourceType t) {
|
|
||||||
|
|
||||||
if(!t.isDateSlot()) {
|
if(!t.isDateSlot()) {
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
Timestamp dateTime = new Timestamp(System.currentTimeMillis());
|
Timestamp dateTime = new Timestamp(System.currentTimeMillis());
|
||||||
for(int i = 0; i < 7; i++) {
|
for(int i = 0; i < 7; i++) {
|
||||||
|
|
||||||
if(checkResourceTypeAvailability(dateTime, t)) {
|
if(checkResourceTypeAvailability(dateTime, t)) {
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
//dateTime = DateTimeUtil.incrementDay(dateTime);
|
//dateTime = DateTimeUtil.incrementDay(dateTime);
|
||||||
dateTime = org.compiere.util.TimeUtil.addDays(dateTime, 1);
|
dateTime = org.compiere.util.TimeUtil.addDays(dateTime, 1);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean checkResourceAvailability(Timestamp dateTime, MResource r) {
|
public boolean checkResourceAvailability(Timestamp dateTime, MResource r) {
|
||||||
|
|
||||||
int[] ids = PO.getAllIDs("S_ResourceUnAvailable", "S_Resource_ID = "+r.get_ID() + " AND AD_Client_ID = " + r.getAD_Client_ID(), null);
|
int[] ids = PO.getAllIDs("S_ResourceUnAvailable", "S_Resource_ID = "+r.get_ID() + " AND AD_Client_ID = " + r.getAD_Client_ID(), null);
|
||||||
|
|
||||||
Timestamp dateFrom = null;
|
Timestamp dateFrom = null;
|
||||||
Timestamp dateTo = null;
|
Timestamp dateTo = null;
|
||||||
Timestamp dateActual = null;
|
Timestamp dateActual = null;
|
||||||
|
|
||||||
MResourceUnAvailable rua = null;
|
MResourceUnAvailable rua = null;
|
||||||
for(int i = 0; i < ids.length; i++) {
|
for(int i = 0; i < ids.length; i++) {
|
||||||
|
|
||||||
rua = new MResourceUnAvailable(Env.getCtx(), ids[i], null);
|
rua = new MResourceUnAvailable(Env.getCtx(), ids[i], null);
|
||||||
|
|
||||||
dateFrom = DateTimeUtil.getDayBorder(rua.getDateFrom(), null, false);
|
dateFrom = DateTimeUtil.getDayBorder(rua.getDateFrom(), null, false);
|
||||||
dateTo = DateTimeUtil.getDayBorder(rua.getDateTo(), null, true);
|
dateTo = DateTimeUtil.getDayBorder(rua.getDateTo(), null, true);
|
||||||
dateActual = DateTimeUtil.getDayBorder(dateTime, null, false);
|
dateActual = DateTimeUtil.getDayBorder(dateTime, null, false);
|
||||||
|
|
||||||
if(dateFrom.compareTo(dateActual) <= 0 && dateTo.compareTo(dateActual) >= 0 ) {
|
if(dateFrom.compareTo(dateActual) <= 0 && dateTo.compareTo(dateActual) >= 0 ) {
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean checkResourceTypeAvailability(Timestamp dateTime, MResourceType t) {
|
public boolean checkResourceTypeAvailability(Timestamp dateTime, MResourceType t) {
|
||||||
|
|
||||||
if(!t.isDateSlot()) {
|
if(!t.isDateSlot()) {
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
GregorianCalendar gc = new GregorianCalendar();
|
GregorianCalendar gc = new GregorianCalendar();
|
||||||
gc.setTimeInMillis(dateTime.getTime());
|
gc.setTimeInMillis(dateTime.getTime());
|
||||||
|
|
||||||
boolean retValue = false;
|
boolean retValue = false;
|
||||||
switch(gc.get(Calendar.DAY_OF_WEEK)) {
|
switch(gc.get(Calendar.DAY_OF_WEEK)) {
|
||||||
|
|
||||||
case Calendar.SUNDAY:
|
case Calendar.SUNDAY:
|
||||||
retValue = t.isOnSunday();
|
retValue = t.isOnSunday();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case Calendar.MONDAY:
|
case Calendar.MONDAY:
|
||||||
retValue = t.isOnMonday();
|
retValue = t.isOnMonday();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case Calendar.TUESDAY:
|
case Calendar.TUESDAY:
|
||||||
retValue = t.isOnTuesday();
|
retValue = t.isOnTuesday();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case Calendar.WEDNESDAY:
|
case Calendar.WEDNESDAY:
|
||||||
retValue = t.isOnWednesday();
|
retValue = t.isOnWednesday();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case Calendar.THURSDAY:
|
case Calendar.THURSDAY:
|
||||||
retValue = t.isOnThursday();
|
retValue = t.isOnThursday();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case Calendar.FRIDAY:
|
case Calendar.FRIDAY:
|
||||||
retValue = t.isOnFriday();
|
retValue = t.isOnFriday();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case Calendar.SATURDAY:
|
case Calendar.SATURDAY:
|
||||||
retValue = t.isOnSaturday();
|
retValue = t.isOnSaturday();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
return retValue;
|
return retValue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue