Search in sources :

Example 1 with MAssignmentSlot

use of org.compiere.model.MAssignmentSlot 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();
}
Also used : ScheduleUtil(org.compiere.model.ScheduleUtil) GregorianCalendar(java.util.GregorianCalendar) Properties(java.util.Properties) Timestamp(java.sql.Timestamp) ServletException(javax.servlet.ServletException) IOException(java.io.IOException) ParseException(java.text.ParseException) Date(java.util.Date) BufferedWriter(java.io.BufferedWriter) ServerContext(org.adempiere.webui.session.ServerContext) MAssignmentSlot(org.compiere.model.MAssignmentSlot) ParseException(java.text.ParseException) PrintWriter(java.io.PrintWriter)

Example 2 with MAssignmentSlot

use of org.compiere.model.MAssignmentSlot 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.");
    }
}
Also used : MResourceAssignment(org.compiere.model.MResourceAssignment) Calendar(java.util.Calendar) GregorianCalendar(java.util.GregorianCalendar) ScheduleUtil(org.compiere.model.ScheduleUtil) GregorianCalendar(java.util.GregorianCalendar) Timestamp(java.sql.Timestamp) Date(java.util.Date) BigDecimal(java.math.BigDecimal) MAssignmentSlot(org.compiere.model.MAssignmentSlot) ListItem(org.adempiere.webui.component.ListItem) KeyNamePair(org.compiere.util.KeyNamePair)

Example 3 with MAssignmentSlot

use of org.compiere.model.MAssignmentSlot in project adempiere by adempiere.

the class VSchedule method recreate.

//	jbInit
/**
	 * 	Recreate View
	 * 	@param S_Resource_ID Resource
	 * 	@param date Date
	 */
public void recreate(int S_Resource_ID, Timestamp date) {
    //	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);
    if (m_type == TYPE_WEEK)
        cal.set(Calendar.DAY_OF_WEEK, cal.getFirstDayOfWeek());
    else if (m_type == TYPE_MONTH)
        cal.set(Calendar.DAY_OF_MONTH, 1);
    m_startDate = new Timestamp(cal.getTimeInMillis());
    //	Calculate End Date
    cal.add(m_type, 1);
    m_endDate = new Timestamp(cal.getTimeInMillis());
    //
    log.config("(" + m_type + ") Resource_ID=" + S_Resource_ID + ": " + m_startDate + "->" + m_endDate);
    //	Create Slots
    MAssignmentSlot[] mas = m_model.getAssignmentSlots(S_Resource_ID, m_startDate, m_endDate, null, true, null);
    MAssignmentSlot[] mts = m_model.getDayTimeSlots();
    //	Set Panels
    timePanel.setTimeSlots(mts);
    schedulePanel.setAssignmentSlots(mas, S_Resource_ID, m_startDate, m_endDate);
    //	Set Height
    schedulePanel.setHeight(timePanel.getPreferredSize().height);
//	repaint();
}
Also used : MAssignmentSlot(org.compiere.model.MAssignmentSlot) GregorianCalendar(java.util.GregorianCalendar) Timestamp(java.sql.Timestamp)

Example 4 with MAssignmentSlot

use of org.compiere.model.MAssignmentSlot in project adempiere by adempiere.

the class VSchedulePanel method setAssignmentSlots.

//	setTimePanel
/**************************************************************************
	 * 	Set Slots
	 * 	@param mass Assignment Slots
	 *  @param S_Resource_ID resource
	 *  @param startDate start date
	 *  @param endDate end date
	 */
public void setAssignmentSlots(MAssignmentSlot[] mass, int S_Resource_ID, Timestamp startDate, Timestamp endDate) {
    log.fine("S_Resource_ID=" + S_Resource_ID);
    m_S_Resource_ID = S_Resource_ID;
    m_noDays = TimeUtil.getDaysBetween(startDate, endDate);
    m_startDate = startDate;
    //
    m_slots = mass;
    m_where = new Rectangle[m_slots.length];
    //	Calculate Assignments
    for (int i = 0; m_slots != null && i < m_slots.length; i++) {
        MAssignmentSlot mas = m_slots[i];
        int dayIndex = TimeUtil.getDaysBetween(m_startDate, mas.getStartTime());
        if (dayIndex < 0 || dayIndex >= m_noDays)
            System.out.println("Assignment " + i + " Invalid DateRange " + mas.getInfo());
        //
        int xWidth = m_dayWidth / mas.getXMax();
        //	start day slot
        int xStart = dayIndex * m_dayWidth;
        //	offset
        xStart += mas.getXPos() * xWidth;
        int xEnd = xStart + xWidth;
        int yStart = m_timePanel.getSlotYStart(mas.getYStart());
        int yEnd = m_timePanel.getSlotYEnd(mas.getYEnd());
        //	System.out.println("Assignment " + i + ", Xpos=" + mas.getXPos() + ", Xmax=" + mas.getXMax()
        //		+ ", Ystart=" + mas.getYStart() + ", Yend=" + mas.getYEnd() + " " + mas.getInfo());
        m_where[i] = new Rectangle(xStart + 1, yStart + 1, xWidth - 1, yEnd - yStart - 1);
    }
    //	calculate assignments
    //
    setSize();
    repaint();
}
Also used : MAssignmentSlot(org.compiere.model.MAssignmentSlot) Rectangle(java.awt.Rectangle)

Example 5 with MAssignmentSlot

use of org.compiere.model.MAssignmentSlot in project adempiere by adempiere.

the class VSchedulePanel method mouseClicked.

//	getHeading
/**
	 *	Mouse Clicked. Start AssignmentDialog
	 * 	@param e event
	 */
public void mouseClicked(MouseEvent e) {
    if (e.getClickCount() < 2)
        return;
    log.finer(e.toString());
    Rectangle hitRect = new Rectangle(e.getX() - 1, e.getY() - 1, 3, 3);
    //	Day
    int dayIndex = e.getX() / m_dayWidth;
    if (dayIndex >= m_noDays)
        dayIndex = m_noDays - 1;
    //	System.out.println("DayIndex=" + dayIndex + ": " + TimeUtil.addDays(m_startDate, dayIndex));
    //	Time
    int timeIndex = m_timePanel.getTimeSlotIndex(e.getY());
    //	check if there is an existing assignment
    for (int i = 0; i < m_slots.length; i++) {
        if (m_where[i].intersects(hitRect)) {
            MAssignmentSlot mas = m_slots[i];
            System.out.println("Existing=" + mas.getInfo());
            if (!mas.isAssignment())
                return;
            //
            VAssignmentDialog vad = new VAssignmentDialog(Env.getFrame(this), m_slots[i].getMAssignment(), false, m_createNew);
            m_infoSchedule.mAssignmentCallback(vad.getMResourceAssignment());
            return;
        }
    }
    if (m_createNew) {
        MResourceAssignment ma = new MResourceAssignment(Env.getCtx(), 0, null);
        ma.setS_Resource_ID(m_S_Resource_ID);
        ma.setAssignDateFrom(TimeUtil.getDayTime(TimeUtil.addDays(m_startDate, dayIndex), m_timePanel.getTimeSlot(timeIndex).getStartTime()));
        ma.setQty(new BigDecimal(1));
        VAssignmentDialog vad = new VAssignmentDialog(Env.getFrame(this), ma, false, m_createNew);
        m_infoSchedule.mAssignmentCallback(vad.getMResourceAssignment());
        return;
    }
}
Also used : MResourceAssignment(org.compiere.model.MResourceAssignment) MAssignmentSlot(org.compiere.model.MAssignmentSlot) Rectangle(java.awt.Rectangle) VAssignmentDialog(org.compiere.grid.ed.VAssignmentDialog) BigDecimal(java.math.BigDecimal)

Aggregations

MAssignmentSlot (org.compiere.model.MAssignmentSlot)5 Timestamp (java.sql.Timestamp)3 GregorianCalendar (java.util.GregorianCalendar)3 Rectangle (java.awt.Rectangle)2 BigDecimal (java.math.BigDecimal)2 Date (java.util.Date)2 MResourceAssignment (org.compiere.model.MResourceAssignment)2 ScheduleUtil (org.compiere.model.ScheduleUtil)2 BufferedWriter (java.io.BufferedWriter)1 IOException (java.io.IOException)1 PrintWriter (java.io.PrintWriter)1 ParseException (java.text.ParseException)1 Calendar (java.util.Calendar)1 Properties (java.util.Properties)1 ServletException (javax.servlet.ServletException)1 ListItem (org.adempiere.webui.component.ListItem)1 ServerContext (org.adempiere.webui.session.ServerContext)1 VAssignmentDialog (org.compiere.grid.ed.VAssignmentDialog)1 KeyNamePair (org.compiere.util.KeyNamePair)1