use of org.compiere.model.ScheduleUtil in project adempiere by adempiere.
the class TimelineEventFeed method doGet.
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
Properties ctx = (Properties) req.getSession().getAttribute(SessionContextListener.SESSION_CTX);
if (ctx == null) {
return;
}
ServerContext serverContext = ServerContext.getCurrentInstance();
if (serverContext == null) {
serverContext = ServerContext.newInstance();
}
serverContext.clear();
serverContext.putAll(ctx);
int resourceId = 0;
String resourceIdParam = req.getParameter("S_Resource_ID");
if (resourceIdParam != null && resourceIdParam.trim().length() > 0) {
try {
resourceId = Integer.parseInt(resourceIdParam.trim());
} catch (Exception e) {
return;
}
} else {
return;
}
String uuid = req.getParameter("uuid");
if (uuid == null || uuid.trim().length() == 0)
return;
String timeLineId = req.getParameter("tlid");
Date date = null;
String dateParam = req.getParameter("date");
if (dateParam != null && dateParam.trim().length() > 0) {
try {
date = DateFormat.getInstance().parse(dateParam);
} catch (ParseException e) {
return;
}
} else {
return;
}
resp.setContentType("application/xml");
ScheduleUtil m_model = new ScheduleUtil(Env.getCtx());
// Calculate Start Day
GregorianCalendar cal = new GregorianCalendar();
cal.setTime(date);
cal.set(Calendar.HOUR, 0);
cal.set(Calendar.MINUTE, 0);
cal.set(Calendar.SECOND, 0);
cal.set(Calendar.MILLISECOND, 0);
cal.set(Calendar.DAY_OF_MONTH, 1);
Timestamp startDate = new Timestamp(cal.getTimeInMillis());
// Calculate End Date
cal.add(Calendar.MONTH, 1);
Timestamp endDate = new Timestamp(cal.getTimeInMillis());
MAssignmentSlot[] mas = m_model.getAssignmentSlots(resourceId, startDate, endDate, null, true, null);
if (mas == null || mas.length == 0)
return;
StringBuffer xml = new StringBuffer();
xml.append("<data>").append("\r\n");
for (MAssignmentSlot slot : mas) {
xml.append("<event ").append("\r\n");
xml.append(XmlFns.attr("start", TimelineUtil.formatDateTime(new Date(slot.getStartTime().getTime()))));
if (slot.getEndTime() != null) {
xml.append("\r\n");
xml.append(XmlFns.attr("end", TimelineUtil.formatDateTime(new Date(slot.getEndTime().getTime()))));
xml.append("\r\n");
xml.append(XmlFns.attr("isDuration", "true"));
}
xml.append(XmlFns.attr("color", "#" + ZkCssHelper.createHexColorString(slot.getColor(true))));
xml.append("\r\n").append(XmlFns.attr("title", slot.getName())).append("\r\n").append(">");
if (slot.getDescription() != null && slot.getDescription().trim().length() > 0) {
xml.append("\r\n").append(XMLs.encodeText(slot.getDescription() + "<br/>"));
}
if (slot.getMAssignment() != null) {
//encode assignment id as coordinate x
String link = "<a href=\"javascript:void(0)\" onclick=\"" + "ad_closeBuble('" + timeLineId + "');" + "zkau.send({uuid: '" + uuid + "', cmd: 'onClick', data: " + "[" + slot.getMAssignment().getS_ResourceAssignment_ID() + ", 0]" + ", ctl: true})\">Edit</a>";
xml.append("\r\n").append(XMLs.encodeText(link));
}
xml.append("\r\n").append("</event>").append("\r\n");
}
xml.append("</data>").append("\r\n");
PrintWriter writer = resp.getWriter();
BufferedWriter buffer = new BufferedWriter(writer);
buffer.write(xml.toString());
buffer.flush();
}
use of org.compiere.model.ScheduleUtil in project adempiere by adempiere.
the class InfoSchedule method doAdd.
// adjustDate
//
private void doAdd() {
ListItem listItem = fieldResource.getSelectedItem();
if (listItem == null)
return;
// Get Resource Type
KeyNamePair pp = new KeyNamePair((Integer) listItem.getValue(), listItem.getLabel());
int S_Resource_ID = pp.getKey();
ScheduleUtil schedule = new ScheduleUtil(Env.getCtx());
Timestamp start = m_dateFrom;
java.sql.Date startDate = new java.sql.Date(start.getTime());
Calendar cal = new GregorianCalendar();
cal.setTimeInMillis(startDate.getTime());
start = new Timestamp(startDate.getTime());
start = new Timestamp(cal.getTimeInMillis());
cal.set(Calendar.HOUR_OF_DAY, 0);
cal.set(Calendar.MINUTE, 0);
cal.set(Calendar.SECOND, 0);
cal.set(Calendar.MILLISECOND, 0);
start = new Timestamp(cal.getTimeInMillis());
cal.add(Calendar.DAY_OF_MONTH, 1);
Timestamp end = new Timestamp(cal.getTimeInMillis());
MAssignmentSlot[] mas = schedule.getAssignmentSlots(S_Resource_ID, start, end, null, true, null);
MAssignmentSlot[] mts = schedule.getDayTimeSlots();
MAssignmentSlot slot = null;
for (int i = 0; i < mts.length; i++) {
slot = mts[i];
for (int j = 0; j < mas.length; j++) {
if (mts[i].getStartTime().getTime() == mas[j].getStartTime().getTime()) {
slot = null;
break;
}
if (mas[j].getEndTime() != null) {
if (mts[i].getStartTime().getTime() > mas[j].getStartTime().getTime() && mts[i].getStartTime().getTime() < mas[j].getEndTime().getTime()) {
slot = null;
break;
} else if (mts[i].getEndTime().getTime() > mas[j].getStartTime().getTime() && mts[i].getEndTime().getTime() < mas[j].getEndTime().getTime()) {
slot = null;
break;
} else if (mts[i].getStartTime().getTime() < mas[j].getStartTime().getTime() && mts[i].getEndTime().getTime() >= mas[j].getEndTime().getTime()) {
slot = null;
break;
}
}
}
if (slot != null)
break;
}
if (slot != null) {
MResourceAssignment ma;
if (m_mAssignment == null)
ma = new MResourceAssignment(Env.getCtx(), 0, null);
else
ma = m_mAssignment;
ma.setS_Resource_ID(S_Resource_ID);
ma.setAssignDateFrom(TimeUtil.getDayTime(start, slot.getStartTime()));
ma.setQty(new BigDecimal(1));
WAssignmentDialog vad = new WAssignmentDialog(ma, false, m_createNew);
mAssignmentCallback(vad.getMResourceAssignment());
} else {
FDialog.error(0, this, "No available time slot for the selected day.");
}
}
Aggregations