Search in sources :

Example 1 with MResourceAssignment

use of org.compiere.model.MResourceAssignment 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 2 with MResourceAssignment

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

the class WAssignmentEditor method onEvent.

public void onEvent(Event event) throws Exception {
    //
    if (Events.ON_CLICK.equalsIgnoreCase(event.getName())) {
        Integer oldValue = (Integer) getValue();
        int S_ResourceAssignment_ID = oldValue == null ? 0 : oldValue.intValue();
        MResourceAssignment ma = new MResourceAssignment(Env.getCtx(), S_ResourceAssignment_ID, null);
        if (S_ResourceAssignment_ID == 0) {
            if (gridField != null && gridField.getGridTab() != null) {
                // assign the resource of the document if any
                Object org = gridField.getGridTab().getValue("AD_Org_ID");
                if (org != null && org instanceof Integer)
                    ma.setAD_Org_ID((Integer) org);
            }
        }
        //	Start VAssignment Dialog
        if (S_ResourceAssignment_ID != 0) {
            WAssignmentDialog vad = new WAssignmentDialog(ma, true, true);
            ma = vad.getMResourceAssignment();
        } else //	Start InfoSchedule directly
        {
            InfoSchedule is = new InfoSchedule(ma, true);
            ma = is.getMResourceAssignment();
        }
        //	Set Value
        if (ma != null && ma.getS_ResourceAssignment_ID() != 0) {
            setValue(new Integer(ma.getS_ResourceAssignment_ID()));
            ValueChangeEvent vce = new ValueChangeEvent(this, gridField.getColumnName(), oldValue, getValue());
            fireValueChange(vce);
        }
    }
}
Also used : MResourceAssignment(org.compiere.model.MResourceAssignment) ValueChangeEvent(org.adempiere.exceptions.ValueChangeEvent) WAssignmentDialog(org.adempiere.webui.window.WAssignmentDialog) InfoSchedule(org.adempiere.webui.window.InfoSchedule)

Example 3 with MResourceAssignment

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

the class WSchedule method onEvent.

public void onEvent(Event event) throws Exception {
    if (event instanceof MouseEvent) {
        MouseEvent me = (MouseEvent) event;
        if (me.getX() > 0) {
            MResourceAssignment assignment = new MResourceAssignment(Env.getCtx(), me.getX(), null);
            WAssignmentDialog wad = new WAssignmentDialog(assignment, false, infoSchedule.isCreateNew());
            if (!wad.isCancelled()) {
                _assignmentDialogResult = wad.getMResourceAssignment();
                Events.echoEvent("onAssignmentCallback", this, null);
            }
        }
    } else if (event instanceof BandScrollEvent) {
        BandScrollEvent e = (BandScrollEvent) event;
        Date end = e.getMax();
        Date start = e.getMin();
        Date mid = e.getCenter();
        if (mid != null) {
            m_center = mid;
            infoSchedule.dateCallback(mid);
        }
    }
}
Also used : MResourceAssignment(org.compiere.model.MResourceAssignment) MouseEvent(org.zkoss.zk.ui.event.MouseEvent) WAssignmentDialog(org.adempiere.webui.window.WAssignmentDialog) BandScrollEvent(org.zkforge.timeline.event.BandScrollEvent) Date(java.util.Date)

Example 4 with MResourceAssignment

use of org.compiere.model.MResourceAssignment 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)

Example 5 with MResourceAssignment

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

the class VAssignment method actionPerformed.

//  addActionListener
/**
	 * 	Action Listener - start dialog
	 * 	@param e Event
	 */
public void actionPerformed(ActionEvent e) {
    if (e.getActionCommand().equals(RecordInfo.CHANGE_LOG_COMMAND)) {
        RecordInfo.start(m_mField);
        return;
    }
    if (!m_button.isEnabled())
        return;
    m_button.setEnabled(false);
    //
    Integer oldValue = (Integer) getValue();
    int S_ResourceAssignment_ID = oldValue == null ? 0 : oldValue.intValue();
    MResourceAssignment ma = new MResourceAssignment(Env.getCtx(), S_ResourceAssignment_ID, null);
    //	Start VAssignment Dialog
    if (S_ResourceAssignment_ID != 0) {
        VAssignmentDialog vad = new VAssignmentDialog(Env.getFrame(this), ma, true, true);
        ma = vad.getMResourceAssignment();
    } else //	Start InfoSchedule directly
    {
        InfoSchedule is = new InfoSchedule(Env.getFrame(this), ma, true);
        ma = is.getMResourceAssignment();
    }
    //	Set Value
    if (ma != null && ma.getS_ResourceAssignment_ID() != 0) {
        setValue(new Integer(ma.getS_ResourceAssignment_ID()));
        try {
            fireVetoableChange(this.getName(), new Object(), getValue());
        } catch (PropertyVetoException pve) {
            log.log(Level.SEVERE, "", pve);
        }
    }
    m_button.setEnabled(true);
    requestFocus();
}
Also used : PropertyVetoException(java.beans.PropertyVetoException) MResourceAssignment(org.compiere.model.MResourceAssignment) InfoSchedule(org.compiere.apps.search.InfoSchedule)

Aggregations

MResourceAssignment (org.compiere.model.MResourceAssignment)5 BigDecimal (java.math.BigDecimal)2 Date (java.util.Date)2 WAssignmentDialog (org.adempiere.webui.window.WAssignmentDialog)2 MAssignmentSlot (org.compiere.model.MAssignmentSlot)2 Rectangle (java.awt.Rectangle)1 PropertyVetoException (java.beans.PropertyVetoException)1 Timestamp (java.sql.Timestamp)1 Calendar (java.util.Calendar)1 GregorianCalendar (java.util.GregorianCalendar)1 ValueChangeEvent (org.adempiere.exceptions.ValueChangeEvent)1 ListItem (org.adempiere.webui.component.ListItem)1 InfoSchedule (org.adempiere.webui.window.InfoSchedule)1 InfoSchedule (org.compiere.apps.search.InfoSchedule)1 VAssignmentDialog (org.compiere.grid.ed.VAssignmentDialog)1 ScheduleUtil (org.compiere.model.ScheduleUtil)1 KeyNamePair (org.compiere.util.KeyNamePair)1 BandScrollEvent (org.zkforge.timeline.event.BandScrollEvent)1 MouseEvent (org.zkoss.zk.ui.event.MouseEvent)1