List of usage examples for java.util Calendar getActualMaximum
public int getActualMaximum(int field)
Calendar
. From source file:com.rr.wabshs.ui.surveys.surveyController.java
/** * @param filter START for start date of month e.g. Nov 01, 2013 END for end date of month e.g. Nov 30, 2013 * @return/*from w w w. jav a 2 s .c om*/ */ public Date getMonthDate(String filter) { String MM_DD_YYYY = "yyyy-mm-dd"; SimpleDateFormat sdf = new SimpleDateFormat(MM_DD_YYYY); sdf.setTimeZone(TimeZone.getTimeZone("EST")); sdf.format(GregorianCalendar.getInstance().getTime()); Calendar cal = GregorianCalendar.getInstance(); int date = cal.getActualMinimum(Calendar.DATE); if ("END".equalsIgnoreCase(filter)) { date = cal.getActualMaximum(Calendar.DATE); cal.set(Calendar.DATE, date); cal.set(Calendar.HOUR_OF_DAY, 23); cal.set(Calendar.MINUTE, 59); cal.set(Calendar.SECOND, 59); cal.set(Calendar.MILLISECOND, 0); } else { cal.set(Calendar.DATE, date); cal.set(Calendar.HOUR_OF_DAY, 0); cal.set(Calendar.MINUTE, 0); cal.set(Calendar.SECOND, 0); cal.set(Calendar.MILLISECOND, 0); } return cal.getTime(); }
From source file:org.everit.jira.timetracker.plugin.JiraTimetrackerWebAction.java
/** * Make summary today, this week and this month. * * @throws GenericEntityException/*from w w w. j av a 2s . c om*/ * GenericEntityException. */ public void makeSummary() throws GenericEntityException { ApplicationProperties applicationProperties = ComponentAccessor.getApplicationProperties(); boolean useISO8601 = applicationProperties.getOption(APKeys.JIRA_DATE_TIME_PICKER_USE_ISO8601); Calendar startCalendar = Calendar.getInstance(); if (useISO8601) { startCalendar.setFirstDayOfWeek(Calendar.MONDAY); } startCalendar.setTime(date); startCalendar.set(Calendar.HOUR_OF_DAY, 0); startCalendar.set(Calendar.MINUTE, 0); startCalendar.set(Calendar.SECOND, 0); startCalendar.set(Calendar.MILLISECOND, 0); Calendar originalStartcalendar = (Calendar) startCalendar.clone(); Date start = startCalendar.getTime(); Calendar endCalendar = (Calendar) startCalendar.clone(); endCalendar.add(Calendar.DAY_OF_MONTH, 1); Date end = endCalendar.getTime(); daySummary = jiraTimetrackerPlugin.summary(selectedUser, start, end, null); if ((issuesRegex != null) && !issuesRegex.isEmpty()) { dayFilteredSummary = jiraTimetrackerPlugin.summary(selectedUser, start, end, issuesRegex); } startCalendar = (Calendar) originalStartcalendar.clone(); while (startCalendar.get(Calendar.DAY_OF_WEEK) != startCalendar.getFirstDayOfWeek()) { startCalendar.add(Calendar.DATE, -1); // Substract 1 day until first day of week. } start = startCalendar.getTime(); endCalendar = (Calendar) startCalendar.clone(); endCalendar.add(Calendar.DATE, DateTimeConverterUtil.DAYS_PER_WEEK); end = endCalendar.getTime(); weekSummary = jiraTimetrackerPlugin.summary(selectedUser, start, end, null); if ((issuesRegex != null) && !issuesRegex.isEmpty()) { weekFilteredSummary = jiraTimetrackerPlugin.summary(selectedUser, start, end, issuesRegex); } startCalendar = (Calendar) originalStartcalendar.clone(); startCalendar.set(Calendar.DAY_OF_MONTH, 1); start = startCalendar.getTime(); endCalendar = (Calendar) originalStartcalendar.clone(); endCalendar.set(Calendar.DAY_OF_MONTH, endCalendar.getActualMaximum(Calendar.DAY_OF_MONTH)); endCalendar.add(Calendar.DAY_OF_MONTH, 1); end = endCalendar.getTime(); monthSummary = jiraTimetrackerPlugin.summary(selectedUser, start, end, null); if ((issuesRegex != null) && !issuesRegex.isEmpty()) { monthFilteredSummary = jiraTimetrackerPlugin.summary(selectedUser, start, end, issuesRegex); } }
From source file:es.tekniker.framework.ktek.questionnaire.mng.server.QuestionnaireMngServer.java
public boolean setQuestionnaireMonitoringSchedule(String token, KtekQuestionnaireMonitoringScheduleEntitySet data) throws KtekExceptionEntity { boolean boolOK = false; boolean boolTokenValid = false; QuestionnaireManagerDB db = null;//from ww w. ja va 2s . c om List<Ktek_userquestionnaire_planning> list = null; Ktek_userquestionnaire_planning objKtek_userquestionnaire_planning = null; Ktek_questionnaire objKtekQuestionnaire = null; long datefromQuestionnaire = 0, datetoQuestionnaire = 0, periodicityvalueQuestionnaire = 0; long collectiontimefromQuestionnaire = 0, collectiontimetoQuestionnaire = 0, completionintervalvalueQuestionnaire = 0; int looplimit = 0, secondlooplimit = 0; short status = 0; long plannedfrom = 0, plannedto = 0; long datefrom = 0, dateto = 0; String codtelecareprogram = null; long milliseconds = 1000; long dayinmilliseconds = 24 * 60 * 60 * milliseconds; long weekinmilliseconds = 7 * dayinmilliseconds; long monthinmilliseconds = 30 * dayinmilliseconds; long monthmillisincrease = 0; int dayOfWeek = 0; String sFunction = "QuestionnaireMngServer.setQuestionnaireMonitoringSchedule"; boolTokenValid = true; if (boolTokenValid) { if (data != null) { db = new QuestionnaireManagerDB(); list = new ArrayList<Ktek_userquestionnaire_planning>(); for (int i = 0; i < data.getListquestionnaire().size(); i++) { //GET questionnaire data objKtekQuestionnaire = db.getQuestionnaire(data.getListquestionnaire().get(i)); if (objKtekQuestionnaire == null) { String exceptionText = getExceptionText( KtekExceptionMessage.EXCEPTION_CODE_QUESTIONNAIRE_DOES_NOT_EXIST); KtekExceptionEntity e = new KtekExceptionEntity(); e.setCode(KtekExceptionCode.EXCEPTION_CODE_QUESTIONNAIRE_DOES_NOT_EXIST); e.setMessage(exceptionText); e.setFunction(sFunction); e.setParams(String.valueOf(data.getListquestionnaire().get(i))); throw e; } else { //SET STATUS AS PENDING status = KtekQuestionnaireMonitoringScheduleTypes.QUESTIONNAIRE_MONITORING_SCHEDULE_STATUS_PENDING; if (objKtekQuestionnaire.getDatevalidfrom() > 0) datefromQuestionnaire = objKtekQuestionnaire.getDatevalidfrom(); else { String exceptionText = getExceptionText( KtekExceptionMessage.EXCEPTION_CODE_QUESTIONNAIRE_DATEVALIDFROM_NOT_DEFINED); KtekExceptionEntity e = new KtekExceptionEntity(); e.setCode(KtekExceptionCode.EXCEPTION_CODE_QUESTIONNAIRE_DATEVALIDFROM_NOT_DEFINED); e.setMessage(exceptionText); e.setFunction(sFunction); e.setParams(String.valueOf(data.getListquestionnaire().get(i))); throw e; } if (objKtekQuestionnaire.getDatevalidto() != null) datetoQuestionnaire = objKtekQuestionnaire.getDatevalidto(); else { // nacho 201/25/11 datevalidto can be null datetoQuestionnaire = data.getDateto(); } if (objKtekQuestionnaire.getPeriodictyvalue() != null) periodicityvalueQuestionnaire = objKtekQuestionnaire.getPeriodictyvalue(); else if (objKtekQuestionnaire.getPeriodicityunit() != null && objKtekQuestionnaire .getPeriodicityunit() != KtekQuestionnaireMonitoringScheduleTypes.QUESTIONNAIRE_MONITORING_SCHEDULE_PERIODICITY_UNIT_MILESTONE) { String exceptionText = getExceptionText( KtekExceptionMessage.EXCEPTION_CODE_QUESTIONNAIRE_PERIODICITYVALUE_NOT_DEFINED); KtekExceptionEntity e = new KtekExceptionEntity(); e.setCode(KtekExceptionCode.EXCEPTION_CODE_QUESTIONNAIRE_PERIODICITYVALUE_NOT_DEFINED); e.setMessage(exceptionText); e.setFunction(sFunction); e.setParams(String.valueOf(data.getListquestionnaire().get(i))); throw e; } if (objKtekQuestionnaire.getCollectiontimeto() != null) collectiontimetoQuestionnaire = objKtekQuestionnaire.getCollectiontimeto(); else { collectiontimetoQuestionnaire = 0; } if (objKtekQuestionnaire.getCollectiontimefrom() != null) collectiontimefromQuestionnaire = objKtekQuestionnaire.getCollectiontimefrom(); else { collectiontimefromQuestionnaire = 0; } if (objKtekQuestionnaire.getCompletionintervalvalue() != null) completionintervalvalueQuestionnaire = objKtekQuestionnaire .getCompletionintervalvalue(); else if (objKtekQuestionnaire.getCompletionintervalunit() == null) { //nothing to do completionintervalvalueQuestionnaire = 0; } else { completionintervalvalueQuestionnaire = 0; } //Calculate datefrom dateto for the time range to create the schedule if (data.getDatefrom() <= datefromQuestionnaire) { datefrom = datefromQuestionnaire; } else { datefrom = data.getDatefrom(); } if (datetoQuestionnaire == 0) { dateto = data.getDateto(); } else { if (data.getDateto() >= datetoQuestionnaire) { dateto = datetoQuestionnaire; } else { dateto = data.getDateto(); } } int year, month, day; int hours, minutes, seconds; Calendar dateStart = Utils.getCalendarGMT(); dateStart.setTimeInMillis(datefrom); year = dateStart.get(Calendar.YEAR); month = dateStart.get(Calendar.MONTH); day = dateStart.get(Calendar.DAY_OF_MONTH); hours = 0; minutes = 0; seconds = 0; datefrom = Utils.getTimeinMillis4FullDateTimeGMT(year, month, day, hours, minutes, seconds); Calendar dateEnd = Utils.getCalendarGMT(); dateEnd.setTimeInMillis(dateto); year = dateEnd.get(Calendar.YEAR); month = dateEnd.get(Calendar.MONTH); day = dateEnd.get(Calendar.DAY_OF_MONTH); hours = 23; minutes = 59; seconds = 59; dateto = Utils.getTimeinMillis4FullDateTimeGMT(year, month, day, hours, minutes, seconds); codtelecareprogram = data.getCodtelecareprogram(); if (objKtekQuestionnaire.getPeriodicityunit() != null && objKtekQuestionnaire .getPeriodicityunit() == KtekQuestionnaireMonitoringScheduleTypes.QUESTIONNAIRE_MONITORING_SCHEDULE_PERIODICITY_UNIT_DAY) { looplimit = (int) ((int) ((dateto - datefrom) / dayinmilliseconds) / periodicityvalueQuestionnaire); //add 1 more to avoid missing one questionnaire schedule looplimit = looplimit + 1; for (int j = 0; j < looplimit; j++) { plannedfrom = datefrom + periodicityvalueQuestionnaire * j * dayinmilliseconds + collectiontimefromQuestionnaire; plannedto = datefrom + periodicityvalueQuestionnaire * j * dayinmilliseconds + collectiontimetoQuestionnaire; if (objKtekQuestionnaire.getCompletionintervalunit() != null) { if (objKtekQuestionnaire .getCompletionintervalunit() == KtekQuestionnaireMonitoringScheduleTypes.QUESTIONNAIRE_MONITORING_SCHEDULE_COMPLETION_INTERVAL_UNIT_DAY) { plannedto = plannedto + completionintervalvalueQuestionnaire * dayinmilliseconds; } else if (objKtekQuestionnaire .getCompletionintervalunit() == KtekQuestionnaireMonitoringScheduleTypes.QUESTIONNAIRE_MONITORING_SCHEDULE_COMPLETION_INTERVAL_UNIT_WEEK) { plannedto = plannedto + (completionintervalvalueQuestionnaire * weekinmilliseconds);//*(j+1); } else if (objKtekQuestionnaire .getCompletionintervalunit() == KtekQuestionnaireMonitoringScheduleTypes.QUESTIONNAIRE_MONITORING_SCHEDULE_COMPLETION_INTERVAL_UNIT_MONTH) { plannedto = plannedto + (completionintervalvalueQuestionnaire * monthinmilliseconds);//*(j+1); } } objKtek_userquestionnaire_planning = new Ktek_userquestionnaire_planning(); objKtek_userquestionnaire_planning.setCoduser(data.getCodUser()); objKtek_userquestionnaire_planning.setKtek_fk_idquestionnaire(objKtekQuestionnaire); objKtek_userquestionnaire_planning.setPlannedfrom(plannedfrom); objKtek_userquestionnaire_planning.setPlannedto(plannedto); objKtek_userquestionnaire_planning.setStatusquestionnaire(status); objKtek_userquestionnaire_planning.setCodtelecareprogram(codtelecareprogram); list.add(objKtek_userquestionnaire_planning); } } else if (objKtekQuestionnaire.getPeriodicityunit() != null && objKtekQuestionnaire .getPeriodicityunit() == KtekQuestionnaireMonitoringScheduleTypes.QUESTIONNAIRE_MONITORING_SCHEDULE_PERIODICITY_UNIT_WEEK) { looplimit = (int) ((int) ((dateto - datefrom) / weekinmilliseconds) / periodicityvalueQuestionnaire); //add 1 more to avoid missing one questionnaire schedule looplimit = looplimit + 1; for (int j = 0; j < looplimit; j++) { plannedfrom = datefrom + periodicityvalueQuestionnaire * j * weekinmilliseconds + collectiontimefromQuestionnaire; plannedto = datefrom + periodicityvalueQuestionnaire * j * weekinmilliseconds + collectiontimetoQuestionnaire; if (objKtekQuestionnaire.getCompletionintervalunit() != null) { if (objKtekQuestionnaire .getCompletionintervalunit() == KtekQuestionnaireMonitoringScheduleTypes.QUESTIONNAIRE_MONITORING_SCHEDULE_COMPLETION_INTERVAL_UNIT_DAY) { plannedto = plannedto + periodicityvalueQuestionnaire * completionintervalvalueQuestionnaire * dayinmilliseconds; } else if (objKtekQuestionnaire .getCompletionintervalunit() == KtekQuestionnaireMonitoringScheduleTypes.QUESTIONNAIRE_MONITORING_SCHEDULE_COMPLETION_INTERVAL_UNIT_WEEK) { plannedto = plannedto + periodicityvalueQuestionnaire * completionintervalvalueQuestionnaire * weekinmilliseconds; } else if (objKtekQuestionnaire .getCompletionintervalunit() == KtekQuestionnaireMonitoringScheduleTypes.QUESTIONNAIRE_MONITORING_SCHEDULE_COMPLETION_INTERVAL_UNIT_MONTH) { plannedto = plannedto + periodicityvalueQuestionnaire * completionintervalvalueQuestionnaire * monthinmilliseconds; } if (plannedto > dateto) { plannedto = dateto + collectiontimetoQuestionnaire; } } objKtek_userquestionnaire_planning = new Ktek_userquestionnaire_planning(); objKtek_userquestionnaire_planning.setCoduser(data.getCodUser()); objKtek_userquestionnaire_planning.setKtek_fk_idquestionnaire(objKtekQuestionnaire); objKtek_userquestionnaire_planning.setPlannedfrom(plannedfrom); objKtek_userquestionnaire_planning.setPlannedto(plannedto); objKtek_userquestionnaire_planning.setStatusquestionnaire(status); list.add(objKtek_userquestionnaire_planning); } } else if (objKtekQuestionnaire.getPeriodicityunit() != null && objKtekQuestionnaire .getPeriodicityunit() == KtekQuestionnaireMonitoringScheduleTypes.QUESTIONNAIRE_MONITORING_SCHEDULE_PERIODICITY_UNIT_WEEKDAY) { looplimit = (int) ((dateto - datefrom) / dayinmilliseconds); secondlooplimit = (int) ((dateto - datefrom) / weekinmilliseconds); //add 1 more to avoid missing one questionnaire schedule secondlooplimit = secondlooplimit + 1; for (int j = 0; j < looplimit; j++) { plannedfrom = datefrom + j * dayinmilliseconds; Calendar calendarDayOfWeek = Utils.getCalendarGMT(); calendarDayOfWeek.setTimeInMillis(plannedfrom); dayOfWeek = calendarDayOfWeek.get(Calendar.DAY_OF_WEEK); //DAY_OF_WEEK 1 : sunday 2: monday... dayOfWeek = dayOfWeek - 1; if (dayOfWeek == periodicityvalueQuestionnaire) { datefrom = plannedfrom; break; } } for (int k = 0; k < secondlooplimit; k++) { plannedfrom = datefrom + k * weekinmilliseconds + collectiontimefromQuestionnaire; plannedto = datefrom + k * weekinmilliseconds + collectiontimetoQuestionnaire; if (objKtekQuestionnaire.getCompletionintervalunit() != null) { if (objKtekQuestionnaire .getCompletionintervalunit() == KtekQuestionnaireMonitoringScheduleTypes.QUESTIONNAIRE_MONITORING_SCHEDULE_COMPLETION_INTERVAL_UNIT_DAY) { plannedto = plannedto + completionintervalvalueQuestionnaire * dayinmilliseconds; } else if (objKtekQuestionnaire .getCompletionintervalunit() == KtekQuestionnaireMonitoringScheduleTypes.QUESTIONNAIRE_MONITORING_SCHEDULE_COMPLETION_INTERVAL_UNIT_WEEK) { plannedto = plannedto + completionintervalvalueQuestionnaire * weekinmilliseconds; } else if (objKtekQuestionnaire .getCompletionintervalunit() == KtekQuestionnaireMonitoringScheduleTypes.QUESTIONNAIRE_MONITORING_SCHEDULE_COMPLETION_INTERVAL_UNIT_MONTH) { plannedto = plannedto + completionintervalvalueQuestionnaire * monthinmilliseconds; } if (plannedto > dateto) { plannedto = dateto + collectiontimetoQuestionnaire; } } objKtek_userquestionnaire_planning = new Ktek_userquestionnaire_planning(); objKtek_userquestionnaire_planning.setCoduser(data.getCodUser()); objKtek_userquestionnaire_planning.setKtek_fk_idquestionnaire(objKtekQuestionnaire); objKtek_userquestionnaire_planning.setPlannedfrom(plannedfrom); objKtek_userquestionnaire_planning.setPlannedto(plannedto); objKtek_userquestionnaire_planning.setStatusquestionnaire(status); list.add(objKtek_userquestionnaire_planning); } } else if (objKtekQuestionnaire.getPeriodicityunit() != null && objKtekQuestionnaire .getPeriodicityunit() == KtekQuestionnaireMonitoringScheduleTypes.QUESTIONNAIRE_MONITORING_SCHEDULE_PERIODICITY_UNIT_MONTH) { looplimit = (int) (((dateto - datefrom) / monthinmilliseconds) / periodicityvalueQuestionnaire); // add 1 more to avoid missing one questionnaire schedule looplimit = looplimit + 1; // maybe the for (int j = 0; j < looplimit; j++) { if (j == 0) { monthmillisincrease = 0; } else { Calendar calendarMonth = Utils.getCalendarGMT(); calendarMonth.setTimeInMillis(plannedfrom); int days = calendarMonth.getActualMaximum(Calendar.DAY_OF_MONTH); monthinmilliseconds = days * dayinmilliseconds; monthmillisincrease = monthmillisincrease + monthinmilliseconds; } plannedfrom = datefrom + monthmillisincrease + collectiontimefromQuestionnaire; plannedto = datefrom + monthmillisincrease + collectiontimetoQuestionnaire; if (objKtekQuestionnaire.getCompletionintervalunit() != null) { if (objKtekQuestionnaire .getCompletionintervalunit() == KtekQuestionnaireMonitoringScheduleTypes.QUESTIONNAIRE_MONITORING_SCHEDULE_COMPLETION_INTERVAL_UNIT_DAY) { plannedto = plannedto + completionintervalvalueQuestionnaire * dayinmilliseconds; } else if (objKtekQuestionnaire .getCompletionintervalunit() == KtekQuestionnaireMonitoringScheduleTypes.QUESTIONNAIRE_MONITORING_SCHEDULE_COMPLETION_INTERVAL_UNIT_WEEK) { plannedto = plannedto + completionintervalvalueQuestionnaire * weekinmilliseconds; } else if (objKtekQuestionnaire .getCompletionintervalunit() == KtekQuestionnaireMonitoringScheduleTypes.QUESTIONNAIRE_MONITORING_SCHEDULE_COMPLETION_INTERVAL_UNIT_MONTH) { plannedto = plannedto + completionintervalvalueQuestionnaire * monthinmilliseconds; } if (plannedto > dateto) { plannedto = dateto + collectiontimetoQuestionnaire; } } objKtek_userquestionnaire_planning = new Ktek_userquestionnaire_planning(); objKtek_userquestionnaire_planning.setCoduser(data.getCodUser()); objKtek_userquestionnaire_planning.setKtek_fk_idquestionnaire(objKtekQuestionnaire); objKtek_userquestionnaire_planning.setPlannedfrom(plannedfrom); objKtek_userquestionnaire_planning.setPlannedto(plannedto); objKtek_userquestionnaire_planning.setStatusquestionnaire(status); objKtek_userquestionnaire_planning.setCodtelecareprogram(codtelecareprogram); list.add(objKtek_userquestionnaire_planning); } } else if (objKtekQuestionnaire.getPeriodicityunit() != null && objKtekQuestionnaire .getPeriodicityunit() == KtekQuestionnaireMonitoringScheduleTypes.QUESTIONNAIRE_MONITORING_SCHEDULE_PERIODICITY_UNIT_MILESTONE) { if (objKtekQuestionnaire .getPeriodictyvalue() == KtekQuestionnaireMonitoringScheduleTypes.QUESTIONNAIRE_MONITORING_SCHEDULE_PERIODICITY_VALUE_START) { plannedfrom = datefrom + collectiontimefromQuestionnaire; plannedto = datefrom + collectiontimetoQuestionnaire; objKtek_userquestionnaire_planning = new Ktek_userquestionnaire_planning(); objKtek_userquestionnaire_planning.setCoduser(data.getCodUser()); objKtek_userquestionnaire_planning.setKtek_fk_idquestionnaire(objKtekQuestionnaire); objKtek_userquestionnaire_planning.setPlannedfrom(plannedfrom); objKtek_userquestionnaire_planning.setPlannedto(plannedto); objKtek_userquestionnaire_planning.setStatusquestionnaire(status); list.add(objKtek_userquestionnaire_planning); } else if (objKtekQuestionnaire .getPeriodictyvalue() == KtekQuestionnaireMonitoringScheduleTypes.QUESTIONNAIRE_MONITORING_SCHEDULE_PERIODICITY_VALUE_END) { plannedfrom = dateto + collectiontimefromQuestionnaire; plannedto = dateto + collectiontimetoQuestionnaire; objKtek_userquestionnaire_planning = new Ktek_userquestionnaire_planning(); objKtek_userquestionnaire_planning.setCoduser(data.getCodUser()); objKtek_userquestionnaire_planning.setKtek_fk_idquestionnaire(objKtekQuestionnaire); objKtek_userquestionnaire_planning.setPlannedfrom(plannedfrom); objKtek_userquestionnaire_planning.setPlannedto(plannedto); objKtek_userquestionnaire_planning.setStatusquestionnaire(status); list.add(objKtek_userquestionnaire_planning); } else if (objKtekQuestionnaire .getPeriodictyvalue() == KtekQuestionnaireMonitoringScheduleTypes.QUESTIONNAIRE_MONITORING_SCHEDULE_PERIODICITY_VALUE_START_END) { //FIRST plannedfrom = datefrom + collectiontimefromQuestionnaire; plannedto = datefrom + collectiontimetoQuestionnaire; objKtek_userquestionnaire_planning = new Ktek_userquestionnaire_planning(); objKtek_userquestionnaire_planning.setCoduser(data.getCodUser()); objKtek_userquestionnaire_planning.setKtek_fk_idquestionnaire(objKtekQuestionnaire); objKtek_userquestionnaire_planning.setPlannedfrom(plannedfrom); objKtek_userquestionnaire_planning.setPlannedto(plannedto); objKtek_userquestionnaire_planning.setStatusquestionnaire(status); list.add(objKtek_userquestionnaire_planning); //SECOND plannedfrom = dateto + collectiontimefromQuestionnaire; plannedto = dateto + collectiontimetoQuestionnaire; objKtek_userquestionnaire_planning = new Ktek_userquestionnaire_planning(); objKtek_userquestionnaire_planning.setCoduser(data.getCodUser()); objKtek_userquestionnaire_planning.setKtek_fk_idquestionnaire(objKtekQuestionnaire); objKtek_userquestionnaire_planning.setPlannedfrom(plannedfrom); objKtek_userquestionnaire_planning.setPlannedto(plannedto); objKtek_userquestionnaire_planning.setStatusquestionnaire(status); list.add(objKtek_userquestionnaire_planning); } } } } boolOK = db.saveQuestionnaireMonitoringSchedule(list); } else { String exceptionText = getExceptionText( KtekExceptionMessage.EXCEPTION_CODE_QUESTIONNAIRE_MONITORING_SCHEDULE_DATA_NOT_DEFINED); KtekExceptionEntity e = new KtekExceptionEntity(); e.setCode(KtekExceptionCode.EXCEPTION_CODE_QUESTIONNAIRE_MONITORING_SCHEDULE_DATA_NOT_DEFINED); e.setMessage(exceptionText); e.setFunction(sFunction); e.setParams(String.valueOf(token)); throw e; } } return boolOK; }
From source file:egovframework.oe1.cms.cmm.web.EgovOe1SchdulManageController.java
/** * ? /* w w w.j av a 2 s . c o m*/ * @param searchVO * @param commandMap * @param deptSchdulManageVO * @param model * @return "/cms/cmm/EgovSchdulManageWeekList" * @throws Exception */ @RequestMapping(value = "/cms/cmm/EgovOe1SchdulManageWeekList.do") public String EgovDeptSchdulManageWeekList(@ModelAttribute("searchVO") EgovOe1ComDefaultVO searchVO, Map commandMap, EgovOe1SchdulManageVO deptSchdulManageVO, ModelMap model) throws Exception { //Spring Security Boolean isAuthenticated = EgovUserDetailsHelper.isAuthenticated(); if (!isAuthenticated) { return "/cms/com/EgovLoginUsr"; //? ?? } //? model.addAttribute("searchKeyword", commandMap.get("searchKeyword") == null ? "" : (String) commandMap.get("searchKeyword")); model.addAttribute("searchCondition", commandMap.get("searchCondition") == null ? "" : (String) commandMap.get("searchCondition")); // ? EgovOe1ComDefaultCodeVO vo = new EgovOe1ComDefaultCodeVO(); vo.setCodeId("OE1028"); List schdulSeCode_result = cmmUseService.selectCmmCodeDetail(vo); model.addAttribute("schdulSeCode_result", schdulSeCode_result); // ? vo = new EgovOe1ComDefaultCodeVO(); vo.setCodeId("OE1008"); List year_result = cmmUseService.selectCmmCodeDetail(vo); model.addAttribute("year_result", year_result); // vo = new EgovOe1ComDefaultCodeVO(); vo.setCodeId("OE1013"); List month_result = cmmUseService.selectCmmCodeDetail(vo); model.addAttribute("month_result", month_result); /* ***************************************************************** // ? ? ****************************************************************** */ Calendar calNow = Calendar.getInstance(); Calendar calBefore = Calendar.getInstance(); Calendar calNext = Calendar.getInstance(); String strYear = deptSchdulManageVO.getSearchYear(); String strMonth = deptSchdulManageVO.getSearchMonth(); String strWeek = deptSchdulManageVO.getSearchWeek(); String strSchdulSeCode = deptSchdulManageVO.getSearchSchdulSeCode(); int iNowYear = 0; int iNowMonth = 0; int iNowDate = 0; int iNowWeek = 0; if ((strYear != null && !"".equals(strYear)) && (strMonth != null && !"".equals(strMonth)) && (strWeek != null && !"".equals(strWeek))) { iNowYear = Integer.parseInt(strYear); iNowMonth = Integer.parseInt(strMonth); iNowWeek = Integer.parseInt(strWeek); } else { iNowYear = calNow.get(Calendar.YEAR); iNowMonth = (calNow.get(Calendar.MONTH) + 1); iNowDate = calNow.get(Calendar.DATE); } //System.out.println("strYear=====>" + strYear); //System.out.println("strMonth=====>" + strMonth); //System.out.println("strWeek=====>" + strWeek); //System.out.println("iNowYear=====>" + iNowYear); //System.out.println("iNowMonth=====>"+ iNowMonth); //System.out.println("iNowDate=====>" + iNowDate); //System.out.println("Calendar.WEEK_OF_MONTH==>"+Calendar.WEEK_OF_MONTH); //?/ calNow.set(iNowYear, iNowMonth - 1, 1); calBefore.set(iNowYear, iNowMonth - 1, 1); calNext.set(iNowYear, iNowMonth - 1, 1); calBefore.add(Calendar.MONTH, -1); calNext.add(Calendar.MONTH, +1); int startDay = calNow.getMinimum(Calendar.DATE); int endDay = calNow.getActualMaximum(Calendar.DAY_OF_MONTH); int startWeek = calNow.get(Calendar.DAY_OF_WEEK); //System.out.println(" ?===>"+startWeek); ArrayList listWeekGrop = new ArrayList(); ArrayList listWeekDate = new ArrayList(); String sUseDate = ""; calBefore.add(Calendar.DATE, calBefore.getActualMaximum(Calendar.DAY_OF_MONTH) - (startWeek - 1)); for (int i = 1; i < startWeek; i++) { sUseDate = Integer.toString(calBefore.get(Calendar.YEAR)); sUseDate += DateTypeIntForString(calBefore.get(Calendar.MONTH) + 1); sUseDate += DateTypeIntForString(calBefore.get(Calendar.DATE)); listWeekDate.add(sUseDate); calBefore.add(Calendar.DATE, +1); } int iBetweenCount = startWeek; // ?. BETWEEN for (int i = 1; i <= endDay; i++) { sUseDate = Integer.toString(iNowYear); sUseDate += Integer.toString(iNowMonth).length() == 1 ? "0" + Integer.toString(iNowMonth) : Integer.toString(iNowMonth); sUseDate += Integer.toString(i).length() == 1 ? "0" + Integer.toString(i) : Integer.toString(i); listWeekDate.add(sUseDate); if (iBetweenCount % 7 == 0) { listWeekGrop.add(listWeekDate); listWeekDate = new ArrayList(); if ((strYear == null || "".equals(strYear)) && i < iNowDate) { iNowWeek++; } } // 7? ?? if (i == endDay) { for (int j = listWeekDate.size(); j < 7; j++) { String sUseNextDate = Integer.toString(calNext.get(Calendar.YEAR)); sUseNextDate += DateTypeIntForString(calNext.get(Calendar.MONTH) + 1); sUseNextDate += DateTypeIntForString(calNext.get(Calendar.DATE)); listWeekDate.add(sUseNextDate); calNext.add(Calendar.DATE, +1); } listWeekGrop.add(listWeekDate); } iBetweenCount++; } model.addAttribute("year", iNowYear + ""); model.addAttribute("month", ((iNowMonth) + "").length() == 1 ? "0" + (iNowMonth) : (iNowMonth)); model.addAttribute("week", iNowWeek + ""); model.addAttribute("dayOfMonth", (Calendar.WEEK_OF_MONTH) + ""); model.addAttribute("listWeekGrop", listWeekGrop); List listWeek = (List) listWeekGrop.get(iNowWeek); commandMap.put("searchMode", "WEEK"); commandMap.put("schdulBgnde", (String) listWeek.get(0)); commandMap.put("schdulEndde", (String) listWeek.get(listWeek.size() - 1)); commandMap.put("searchSchdulSeCode", strSchdulSeCode); String sNowMonth = ""; if (((iNowMonth) + "").length() == 1) { sNowMonth = "0" + (iNowMonth); } else { sNowMonth = (iNowMonth) + ""; } deptSchdulManageVO.setSearchYear(iNowYear + ""); deptSchdulManageVO.setSearchMonth(sNowMonth); deptSchdulManageVO.setSearchWeek(iNowWeek + ""); //? ? ??. model.addAttribute("searchMode", deptSchdulManageVO); List resultList = egovDeptSchdulManageService.selectDeptSchdulManageRetrieve(commandMap); model.addAttribute("resultList", resultList); return "/cms/cmm/EgovSchdulManageWeekList"; }
From source file:JapaneseCalendar.java
public void paintComponent(Graphics g) { int width = 400; int height = 400; Calendar cal = Calendar.getInstance(locale); cal.setTime(new Date()); String header = cal.getDisplayName(Calendar.MONTH, Calendar.LONG, locale); header += " " + cal.get(Calendar.YEAR); FontMetrics fm = g.getFontMetrics(); Insets insets = getInsets();//w ww . java 2s. c o m g.setColor(Color.black); g.drawString(header, (width - fm.stringWidth(header)) / 2, insets.top + fm.getHeight()); DateFormatSymbols dfs = new DateFormatSymbols(locale); String[] weekdayNames = dfs.getShortWeekdays(); int fieldWidth = (width - insets.left - insets.right) / 7; g.drawString(weekdayNames[Calendar.SUNDAY], insets.left + (fieldWidth - fm.stringWidth(weekdayNames[Calendar.SUNDAY])) / 2, insets.top + 3 * fm.getHeight()); g.drawString(weekdayNames[Calendar.MONDAY], insets.left + fieldWidth + (fieldWidth - fm.stringWidth(weekdayNames[Calendar.MONDAY])) / 2, insets.top + 3 * fm.getHeight()); g.drawString(weekdayNames[Calendar.TUESDAY], insets.left + 2 * fieldWidth + (fieldWidth - fm.stringWidth(weekdayNames[Calendar.TUESDAY])) / 2, insets.top + 3 * fm.getHeight()); g.drawString(weekdayNames[Calendar.WEDNESDAY], insets.left + 3 * fieldWidth + (fieldWidth - fm.stringWidth(weekdayNames[Calendar.WEDNESDAY])) / 2, insets.top + 3 * fm.getHeight()); g.drawString(weekdayNames[Calendar.THURSDAY], insets.left + 4 * fieldWidth + (fieldWidth - fm.stringWidth(weekdayNames[Calendar.THURSDAY])) / 2, insets.top + 3 * fm.getHeight()); g.drawString(weekdayNames[Calendar.FRIDAY], insets.left + 5 * fieldWidth + (fieldWidth - fm.stringWidth(weekdayNames[Calendar.FRIDAY])) / 2, insets.top + 3 * fm.getHeight()); g.drawString(weekdayNames[Calendar.SATURDAY], insets.left + 6 * fieldWidth + (fieldWidth - fm.stringWidth(weekdayNames[Calendar.SATURDAY])) / 2, insets.top + 3 * fm.getHeight()); int dom = cal.get(Calendar.DAY_OF_MONTH); cal.set(Calendar.DAY_OF_MONTH, 1); int col = 0; switch (cal.get(Calendar.DAY_OF_WEEK)) { case Calendar.MONDAY: col = 1; break; case Calendar.TUESDAY: col = 2; break; case Calendar.WEDNESDAY: col = 3; break; case Calendar.THURSDAY: col = 4; break; case Calendar.FRIDAY: col = 5; break; case Calendar.SATURDAY: col = 6; } cal.set(Calendar.DAY_OF_MONTH, dom); int row = 5 * fm.getHeight(); for (int i = 1; i <= cal.getActualMaximum(Calendar.DAY_OF_MONTH); i++) { g.drawString("" + i, insets.left + fieldWidth * col + (fieldWidth - fm.stringWidth("" + i)) / 2, row); if (++col > 6) { col = 0; row += fm.getHeight(); } } }
From source file:org.openconcerto.erp.core.humanresources.payroll.element.FichePayeSQLElement.java
public SQLComponent createComponent() { return new BaseSQLComponent(this) { private FichePayeModel model; private ElementComboBox comboSelProfil, selSalCombo; private EditFrame edit = null; private ElementComboBox selMois; private int dernMois, dernAnnee; private JTextField textAnnee; JDate dateDu, dateAu;//from ww w . j a v a2s . co m private JScrollPane paneTreeLeft; private JPanel pDate; private JButton buttonValider, buttonGenCompta; public void addViews() { this.dernMois = 0; this.dernAnnee = 0; this.setLayout(new GridBagLayout()); final GridBagConstraints c = new DefaultGridBagConstraints(); // Tree elt Fiche de Paye On the left c.fill = GridBagConstraints.BOTH; c.weightx = 1; c.weighty = 1; c.gridheight = GridBagConstraints.REMAINDER; final RubriquePayeTree tree = new RubriquePayeTree(); tree.expandRow(0); this.paneTreeLeft = new JScrollPane(tree); // this.add(this.paneTreeLeft, c); // Panel Fiche paye on the right // Salarie JPanel panelRight = new JPanel(); panelRight.setLayout(new GridBagLayout()); c.fill = GridBagConstraints.HORIZONTAL; c.weightx = 1; c.weighty = 0; c.gridheight = 1; c.gridwidth = 2; this.selSalCombo = new ElementComboBox(); // c.gridx++; panelRight.add(this.selSalCombo, c); // Mois c.gridy++; // c.gridx++; c.fill = GridBagConstraints.HORIZONTAL; c.weightx = 1; c.weighty = 0; c.gridheight = 1; c.gridwidth = 3; JLabel labelMois = new JLabel("Fiche de paye du mois de"); this.selMois = new ElementComboBox(true, 20); // this.selMois.setEditable(true); // /this.selMois.setEnabled(true); JLabel labelDu = new JLabel("Du"); JLabel labelAu = new JLabel("Au"); this.dateDu = new JDate(); this.dateAu = new JDate(); // JTextField textMois = new JTextField(); JLabel labelAnnee = new JLabel("Anne"); this.textAnnee = new JTextField(); { this.pDate = new JPanel(); this.pDate.setOpaque(false); this.pDate.add(labelMois); this.pDate.add(this.selMois); this.pDate.add(labelAnnee); this.pDate.add(this.textAnnee); this.pDate.add(labelDu); this.pDate.add(this.dateDu); this.pDate.add(labelAu); this.pDate.add(this.dateAu); panelRight.add(this.pDate, c); } c.gridx += 2; c.weightx = 1; c.gridwidth = 1; c.fill = GridBagConstraints.HORIZONTAL; panelRight.add(new JPanel(), c); // Action Button c.gridx++; c.fill = GridBagConstraints.HORIZONTAL; c.weightx = 0; c.weighty = 0; JPanel pButtons = new JPanel(); pButtons.setOpaque(false); JButton buttonUp = new JNiceButton(IListFrame.class.getResource("fleche_haut.png")); JButton buttonDown = new JNiceButton(IListFrame.class.getResource("fleche_bas.png")); JButton buttonRemove = new JNiceButton(SQLComponent.class.getResource("delete.png")); { pButtons.add(buttonUp); pButtons.add(buttonDown); pButtons.add(buttonRemove); } panelRight.add(pButtons, c); // Table c.fill = GridBagConstraints.BOTH; c.weightx = 1; c.weighty = 1; c.gridx = 1; c.gridy++; c.gridwidth = GridBagConstraints.REMAINDER; this.model = new FichePayeModel(1); final JTable table = new JTable(this.model); panelRight.add(new JScrollPane(table), c); FichePayeRenderer rend = new FichePayeRenderer(); table.setDefaultRenderer(String.class, rend); table.setDefaultRenderer(Float.class, rend); // Import profil c.gridx = 1; c.gridy++; c.weightx = 0; c.weighty = 0; c.gridwidth = 1; c.fill = GridBagConstraints.HORIZONTAL; JLabel labelProfil = new JLabel("Importer depuis un profil prdfini"); panelRight.add(labelProfil, c); c.gridwidth = 1; this.comboSelProfil = new ElementComboBox(); // this.comboSelProfil = new ElementComboBox(); this.comboSelProfil.setListIconVisible(false); c.gridx++; c.gridwidth = 1; // this.comboSelProfil.init(eltProfil.getTable().getField("NOM"), null); panelRight.add(this.comboSelProfil, c); JButton buttonImportProfil = new JButton("Importer"); c.gridx++; panelRight.add(buttonImportProfil, c); // Total Periode JPanel panelTotal = new JPanel(); panelTotal.setBorder(BorderFactory.createTitledBorder("Total priode")); panelTotal.setLayout(new GridBagLayout()); GridBagConstraints cPanel = new DefaultGridBagConstraints(); // Salaire brut JLabel labelBrut = new JLabel(getLabelFor("SAL_BRUT")); panelTotal.add(labelBrut, cPanel); JTextField textSalBrut = new JTextField(10); cPanel.gridx++; cPanel.weightx = 0; panelTotal.add(textSalBrut, cPanel); textSalBrut.setEditable(false); textSalBrut.setEnabled(false); // acompte cPanel.gridx++; JLabel labelAcompte = new JLabel(getLabelFor("ACOMPTE")); panelTotal.add(labelAcompte, cPanel); JTextField textAcompte = new JTextField(10); cPanel.gridx++; panelTotal.add(textAcompte, cPanel); // textAcompte.setEditable(false); // textAcompte.setEnabled(false); // Conges Acquis cPanel.gridx++; JLabel labelCongesAcquis = new JLabel(getLabelFor("CONGES_ACQUIS")); panelTotal.add(labelCongesAcquis, cPanel); JTextField textCongesAcquis = new JTextField(10); cPanel.gridx++; panelTotal.add(textCongesAcquis, cPanel); // cotisation salariale cPanel.gridx = 0; cPanel.gridy++; JLabel labelCotSal = new JLabel(getLabelFor("COT_SAL")); panelTotal.add(labelCotSal, cPanel); JTextField textCotSal = new JTextField(10); cPanel.gridx++; panelTotal.add(textCotSal, cPanel); textCotSal.setEditable(false); textCotSal.setEnabled(false); // cotisation patronale cPanel.gridx++; JLabel labelCotPat = new JLabel(getLabelFor("COT_PAT")); panelTotal.add(labelCotPat, cPanel); JTextField textCotPat = new JTextField(10); cPanel.gridx++; panelTotal.add(textCotPat, cPanel); textCotPat.setEditable(false); textCotPat.setEnabled(false); JLabel labelCSG = new JLabel(getLabelFor("CSG")); cPanel.gridx++; panelTotal.add(labelCSG, cPanel); JTextField textCSG = new JTextField(10); cPanel.gridx++; panelTotal.add(textCSG, cPanel); textCSG.setEditable(false); textCSG.setEnabled(false); // net imposable cPanel.gridx = 0; cPanel.gridy++; JLabel labelNetImp = new JLabel(getLabelFor("NET_IMP")); panelTotal.add(labelNetImp, cPanel); JTextField textNetImp = new JTextField(10); cPanel.gridx++; panelTotal.add(textNetImp, cPanel); textNetImp.setEditable(false); textNetImp.setEnabled(false); cPanel.gridx++; JLabel labelNetAPayer = new JLabel(getLabelFor("NET_A_PAYER")); panelTotal.add(labelNetAPayer, cPanel); JTextField textNetAPayer = new JTextField(10); cPanel.gridx++; panelTotal.add(textNetAPayer, cPanel); textNetAPayer.setEditable(false); textNetAPayer.setEnabled(false); c.gridx = 1; c.gridy++; c.gridwidth = GridBagConstraints.REMAINDER; panelRight.add(panelTotal, c); // Cumuls c.gridx = 1; c.gridy++; c.gridwidth = 1; c.fill = GridBagConstraints.NONE; this.buttonValider = new JButton("Valider"); // panelRight.add(buttonValider, c); c.gridx++; c.gridwidth = 1; this.buttonGenCompta = new JButton("Generer la comptabilit"); // panelRight.add(buttonGenCompta, c); c.gridx = 0; c.gridy = 0; c.gridwidth = 1; c.gridheight = 1; c.fill = GridBagConstraints.BOTH; c.weightx = 1; c.weighty = 1; this.add(new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, this.paneTreeLeft, panelRight), c); // Listeners this.buttonGenCompta.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { int[] i = new int[1]; i[0] = getSelectedID(); SQLRow rowMois = getTable().getBase().getTable("MOIS").getRow(selMois.getSelectedId()); new GenerationMvtFichePaye(i, rowMois.getString("NOM"), textAnnee.getText()); } }); this.buttonValider.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { System.err.println("Validation de la fiche de paye"); validationFiche(); } }); buttonUp.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { int newRowSelected = model.upRow(table.getSelectedRow()); if (newRowSelected >= 0) { table.setRowSelectionInterval(newRowSelected, newRowSelected); } } }); buttonDown.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { int newRowSelected = model.downRow(table.getSelectedRow()); if (newRowSelected >= 0) { table.setRowSelectionInterval(newRowSelected, newRowSelected); } } }); buttonRemove.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { model.removeRow(table.getSelectedRow()); } }); tree.addMouseListener(new MouseAdapter() { public void mousePressed(MouseEvent mE) { TreePath path = tree.getClosestPathForLocation(mE.getPoint().x, mE.getPoint().y); final Object obj = path.getLastPathComponent(); if (obj == null) { return; } if (mE.getClickCount() == 2 && mE.getButton() == MouseEvent.BUTTON1) { if (obj instanceof VariableRowTreeNode) { model.addRowAt(((VariableRowTreeNode) obj).getRow(), table.getSelectedRow()); } } else { if (mE.getButton() == 3) { if (obj instanceof VariableRowTreeNode) { final SQLRow row = ((VariableRowTreeNode) obj).getRow(); JPopupMenu menuDroit = new JPopupMenu(); menuDroit.add(new AbstractAction("Editer") { public void actionPerformed(ActionEvent e) { if (edit != null) { edit.dispose(); } edit = new EditFrame(Configuration.getInstance().getDirectory() .getElement(row.getTable()), EditFrame.MODIFICATION); edit.selectionId(row.getID(), 0); edit.pack(); edit.setVisible(true); } }); menuDroit.add(new AbstractAction("Nouvelle rubrique") { public void actionPerformed(ActionEvent e) { if (edit != null) { edit.dispose(); } edit = new EditFrame(Configuration.getInstance().getDirectory() .getElement(row.getTable())); edit.pack(); edit.setVisible(true); } }); menuDroit.show(mE.getComponent(), mE.getPoint().x, mE.getPoint().y); } } } } }); this.dateDu.addValueListener(new PropertyChangeListener() { public void propertyChange(PropertyChangeEvent evt) { if (!dateDu.isEmpty()) { Date d = dateDu.getValue(); if (d != null) { Calendar cal = Calendar.getInstance(); cal.setTime(d); if (selMois.getSelectedId() > 1 && cal.get(Calendar.MONTH) + 2 != selMois.getSelectedId()) { cal.set(Calendar.DAY_OF_MONTH, 1); cal.set(Calendar.MONTH, selMois.getSelectedId() - 2); System.err.println("Du " + cal.getTime()); dateDu.setValue(cal.getTime()); } } } } }); this.dateAu.addValueListener(new PropertyChangeListener() { public void propertyChange(PropertyChangeEvent evt) { if (!dateAu.isEmpty()) { Date d = dateAu.getValue(); if (d != null) { Calendar cal = Calendar.getInstance(); cal.setTime(d); if (selMois.getSelectedId() > 1 && cal.get(Calendar.MONTH) + 2 != selMois.getSelectedId()) { // TODO checker l'annee // TODO ajouter dans le isValidated du au compris dans le mois // selectionne // Calendar.getInstance().set(Calendar.DAY_OF_MONTH, maxDay); cal.set(Calendar.DAY_OF_MONTH, 1); cal.set(Calendar.MONTH, selMois.getSelectedId() - 2); cal.set(Calendar.DAY_OF_MONTH, cal.getActualMaximum(Calendar.DAY_OF_MONTH)); System.err.println("Au " + cal.getTime()); dateAu.setValue(cal.getTime()); } } } } }); this.addRequiredSQLObject(this.textAnnee, "ANNEE"); this.addRequiredSQLObject(this.selMois, "ID_MOIS"); this.addSQLObject(this.comboSelProfil, "ID_PROFIL_PAYE"); this.addSQLObject(textCongesAcquis, "CONGES_ACQUIS"); this.addSQLObject(textCotPat, "COT_PAT"); this.addSQLObject(textCotSal, "COT_SAL"); this.addSQLObject(textCSG, "CSG"); this.addSQLObject(textNetAPayer, "NET_A_PAYER"); this.addSQLObject(textNetImp, "NET_IMP"); this.addSQLObject(textSalBrut, "SAL_BRUT"); this.addSQLObject(textAcompte, "ACOMPTE"); this.addSQLObject(this.selSalCombo, "ID_SALARIE"); this.addRequiredSQLObject(this.dateDu, "DU"); this.addRequiredSQLObject(this.dateAu, "AU"); this.selSalCombo.setEditable(false); this.selSalCombo.setEnabled(false); this.selSalCombo.setButtonsVisible(false); // this.selSalCombo.setVisible(false); buttonImportProfil.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { model.loadFromProfil(comboSelProfil.getSelectedId()); } }); } private boolean isDateValid() { String yearS = this.textAnnee.getText().trim(); int annee = (yearS.length() == 0) ? 0 : Integer.parseInt(yearS); int mois = this.selMois.getSelectedId(); // System.err.println("anne " + annee + " dernAnnee " + this.dernAnnee + " mois " + // mois + " dernMois " + this.dernMois); return ((this.dernAnnee == 0) ? true : annee > this.dernAnnee) || ((this.dernMois == 0 || this.dernMois == 13) ? true : mois > this.dernMois); } @Override public synchronized ValidState getValidState() { // FIXME add fireValidChange() return super.getValidState().and(ValidState.createCached(isDateValid(), "Date invalide")); } public int insert(SQLRow order) { int id = super.insert(order); this.model.updateFields(id); return id; } @Override public void update() { super.update(); this.model.updateFields(this.getSelectedID()); } @Override public void select(SQLRowAccessor r) { // System.err.println("SELECT FICHE ID -> " + r.getID()); super.select(r); if (r != null && r.getID() > 1) { this.model.setFicheID(r.getID()); SQLTable tableSal = getTable().getBase().getTable("SALARIE"); SQLRow rowSal = tableSal.getRow(r.getInt("ID_SALARIE")); this.dernMois = rowSal.getInt("DERNIER_MOIS"); this.dernAnnee = rowSal.getInt("DERNIERE_ANNEE"); this.selSalCombo.setVisible(((Boolean) r.getObject("VALIDE")).booleanValue()); this.paneTreeLeft.setVisible(!((Boolean) r.getObject("VALIDE")).booleanValue()); this.buttonValider.setVisible(!((Boolean) r.getObject("VALIDE")).booleanValue()); setpDateEnabled(!((Boolean) r.getObject("VALIDE")).booleanValue()); } this.selSalCombo.setEditable(false); this.selSalCombo.setEnabled(false); this.selMois.setButtonsVisible(false); this.selSalCombo.setButtonsVisible(false); } private void setpDateEnabled(boolean b) { // System.err.println("Set date enable --> " + b); this.selMois.setEditable(b); // this.selMois.setEnabled(b); this.textAnnee.setEditable(b); this.textAnnee.setEnabled(b); this.dateDu.setEditable(b); this.dateDu.setEnabled(b); this.dateAu.setEditable(b); this.dateAu.setEnabled(b); } private void validationFiche() { this.update(); FichePayeSQLElement.validationFiche(this.getSelectedID()); } protected SQLRowValues createDefaults() { System.err.println("**********Set Defaults on FichePaye.date"); SQLRowValues rowVals = new SQLRowValues(getTable()); Calendar cal = Calendar.getInstance(); rowVals.put("ID_MOIS", cal.get(Calendar.MONTH) + 2); rowVals.put("ANNEE", cal.get(Calendar.YEAR)); cal.set(Calendar.DAY_OF_MONTH, 1); rowVals.put("DU", new java.sql.Date(cal.getTime().getTime())); cal.set(Calendar.DAY_OF_MONTH, cal.getActualMaximum(Calendar.DAY_OF_MONTH)); rowVals.put("AU", new java.sql.Date(cal.getTime().getTime())); return rowVals; } }; }
From source file:org.sakaiproject.tool.summarycalendar.ui.CalendarBean.java
private CalendarEventVector getEventsFromSchedule() { if (calendarEventVector == null) { Calendar firstDay;// w w w . j a v a 2s . c om Calendar lastDay; if (viewMode.equals(MODE_WEEKVIEW)) { // WEEK VIEW // select first day firstDay = Calendar.getInstance(getCurrentUserTimezone(), msgs.getLocale()); firstDay.setTime(getViewingDate()); firstDay.set(Calendar.HOUR_OF_DAY, 0); firstDay.set(Calendar.MINUTE, 0); firstDay.set(Calendar.SECOND, 0); firstDay.set(Calendar.MILLISECOND, 0); int dayOfWeek = firstDay.get(Calendar.DAY_OF_WEEK); // TODO Allow dynamic choice of first day of week while (dayOfWeek != Calendar.SUNDAY) { firstDay.add(Calendar.DAY_OF_WEEK, -1); dayOfWeek = firstDay.get(Calendar.DAY_OF_WEEK); } // select last day lastDay = (Calendar) firstDay.clone(); lastDay.add(Calendar.DAY_OF_WEEK, 6); lastDay.set(Calendar.HOUR_OF_DAY, 23); lastDay.set(Calendar.MINUTE, 59); lastDay.set(Calendar.SECOND, 59); lastDay.set(Calendar.MILLISECOND, 999); } else { // MONTH VIEW // select first day firstDay = Calendar.getInstance(getCurrentUserTimezone(), msgs.getLocale()); firstDay.setTime(getViewingDate()); int selYear = firstDay.get(Calendar.YEAR); int selMonth = firstDay.get(Calendar.MONTH); firstDay.set(Calendar.YEAR, selYear); firstDay.set(Calendar.DAY_OF_MONTH, 1); firstDay.set(Calendar.HOUR_OF_DAY, 0); firstDay.set(Calendar.MINUTE, 0); firstDay.set(Calendar.SECOND, 0); firstDay.set(Calendar.MILLISECOND, 0); int dayOfWeek = firstDay.get(Calendar.DAY_OF_WEEK); // TODO Allow dynamic choice of first day of week while (dayOfWeek != Calendar.SUNDAY) { firstDay.add(Calendar.DAY_OF_WEEK, -1); dayOfWeek = firstDay.get(Calendar.DAY_OF_WEEK); } // select last day lastDay = (Calendar) firstDay.clone(); lastDay.set(Calendar.YEAR, selYear); lastDay.set(Calendar.MONTH, selMonth); lastDay.set(Calendar.DAY_OF_MONTH, lastDay.getActualMaximum(Calendar.DAY_OF_MONTH)); lastDay.set(Calendar.HOUR_OF_DAY, 23); lastDay.set(Calendar.MINUTE, 59); lastDay.set(Calendar.SECOND, 59); lastDay.set(Calendar.MILLISECOND, 999); dayOfWeek = lastDay.get(Calendar.DAY_OF_WEEK); // TODO Allow dynamic choice of first day of week while (dayOfWeek != Calendar.SATURDAY) { lastDay.add(Calendar.DAY_OF_WEEK, 1); dayOfWeek = lastDay.get(Calendar.DAY_OF_WEEK); } } Time firstTime = M_ts.newTime(firstDay.getTimeInMillis()); Time lastTime = M_ts.newTime(lastDay.getTimeInMillis()); TimeRange range = M_ts.newTimeRange(firstTime, lastTime); calendarEventVector = M_ca.getEvents(getCalendarReferences(), range); } return calendarEventVector; }
From source file:Implement.Service.ProviderServiceImpl.java
@Override public String getSales(String data, int providerID) throws ParseException { int packageID; Date fromDate;// w ww .j a v a2 s . c o m Date toDate; Calendar calendar = Calendar.getInstance(); DateFormat MMddyyyyFormat = new SimpleDateFormat("MM/dd/yyyy"); DateFormat ddMMyyyyFormat = new SimpleDateFormat("dd/MM/yyyy"); ddMMyyyyFormat.setLenient(false); if (data == null) { packageID = 0; calendar.set(Calendar.DAY_OF_MONTH, 1); fromDate = calendar.getTime(); calendar.set(Calendar.DAY_OF_MONTH, calendar.getActualMaximum(Calendar.DAY_OF_MONTH)); toDate = calendar.getTime(); } else { JsonObject jsonObject = gson.fromJson(data, JsonObject.class); String fromDateStr = jsonObject.get("fromDate").getAsString(); String toDateStr = jsonObject.get("toDate").getAsString(); packageID = jsonObject.get("packageID").getAsInt(); fromDate = MMddyyyyFormat.parse(fromDateStr); toDate = MMddyyyyFormat.parse(toDateStr); } List<BookingDTO> bookings = bookingDAO.getSales(packageID, providerID); List<Sale> sales = new ArrayList<Sale>(); Date toDay = new Date(); DateFormat MMddyyyyHHmmssFormat = new SimpleDateFormat("MM/dd/yyyy HH:ss:mm"); MMddyyyyFormat.setLenient(false); for (BookingDTO booking : bookings) { String bookingDateStr = booking.getBookingDate().substring(0, 10); Date bookingDate = MMddyyyyFormat.parse(bookingDateStr); if (bookingDate.compareTo(fromDate) >= 0 && bookingDate.compareTo(toDate) <= 0) { int tripperID = booking.getTripperID(); String tripperName = booking.getTripperFirstName() + " " + booking.getTripperLastName(); int mainPackageID = booking.getPackageID(); String packageName = booking.getPackageName(); int status; String paidDateStr = booking.getPaid(); if (paidDateStr != null && !paidDateStr.equals("none")) { status = 1; } else { status = 4; } double revenue = (booking.getAdultPrice() * booking.getNumberOfAdults() + booking.getChildPrice() * booking.getNumberOfChilds()) * (100 - booking.getYouTripperPercentage() - booking.getProfitPercentage()) / 100; Sale sale = new Sale(bookingDateStr, tripperID, tripperName, mainPackageID, packageName, status, revenue); sales.add(sale); } } return gson.toJson(sales); }
From source file:Main.java
/** * <p>Internal calculation method.</p> * //w ww .ja v a 2 s . co m * @param val the calendar * @param field the field constant * @param round true to round, false to truncate * @throws ArithmeticException if the year is over 280 million */ private static void modify(Calendar val, int field, boolean round) { if (val.get(Calendar.YEAR) > 280000000) { throw new ArithmeticException("Calendar value too large for accurate calculations"); } if (field == Calendar.MILLISECOND) { return; } // ----------------- Fix for LANG-59 ---------------------- START --------------- // see http://issues.apache.org/jira/browse/LANG-59 // // Manually truncate milliseconds, seconds and minutes, rather than using // Calendar methods. Date date = val.getTime(); long time = date.getTime(); boolean done = false; // truncate milliseconds int millisecs = val.get(Calendar.MILLISECOND); if (!round || millisecs < 500) { time = time - millisecs; } if (field == Calendar.SECOND) { done = true; } // truncate seconds int seconds = val.get(Calendar.SECOND); if (!done && (!round || seconds < 30)) { time = time - (seconds * 1000L); } if (field == Calendar.MINUTE) { done = true; } // truncate minutes int minutes = val.get(Calendar.MINUTE); if (!done && (!round || minutes < 30)) { time = time - (minutes * 60000L); } // reset time if (date.getTime() != time) { date.setTime(time); val.setTime(date); } // ----------------- Fix for LANG-59 ----------------------- END ---------------- boolean roundUp = false; for (int i = 0; i < fields.length; i++) { for (int j = 0; j < fields[i].length; j++) { if (fields[i][j] == field) { //This is our field... we stop looping if (round && roundUp) { if (field == DateUtils.SEMI_MONTH) { //This is a special case that's hard to generalize //If the date is 1, we round up to 16, otherwise // we subtract 15 days and add 1 month if (val.get(Calendar.DATE) == 1) { val.add(Calendar.DATE, 15); } else { val.add(Calendar.DATE, -15); val.add(Calendar.MONTH, 1); } } else { //We need at add one to this field since the // last number causes us to round up val.add(fields[i][0], 1); } } return; } } //We have various fields that are not easy roundings int offset = 0; boolean offsetSet = false; //These are special types of fields that require different rounding rules switch (field) { case DateUtils.SEMI_MONTH: if (fields[i][0] == Calendar.DATE) { //If we're going to drop the DATE field's value, // we want to do this our own way. //We need to subtrace 1 since the date has a minimum of 1 offset = val.get(Calendar.DATE) - 1; //If we're above 15 days adjustment, that means we're in the // bottom half of the month and should stay accordingly. if (offset >= 15) { offset -= 15; } //Record whether we're in the top or bottom half of that range roundUp = offset > 7; offsetSet = true; } break; case Calendar.AM_PM: if (fields[i][0] == Calendar.HOUR_OF_DAY) { //If we're going to drop the HOUR field's value, // we want to do this our own way. offset = val.get(Calendar.HOUR_OF_DAY); if (offset >= 12) { offset -= 12; } roundUp = offset > 6; offsetSet = true; } break; } if (!offsetSet) { int min = val.getActualMinimum(fields[i][0]); int max = val.getActualMaximum(fields[i][0]); //Calculate the offset from the minimum allowed value offset = val.get(fields[i][0]) - min; //Set roundUp if this is more than half way between the minimum and maximum roundUp = offset > ((max - min) / 2); } //We need to remove this field if (offset != 0) { val.set(fields[i][0], val.get(fields[i][0]) - offset); } } throw new IllegalArgumentException("The field " + field + " is not supported"); }
From source file:com.silverpeas.scheduler.simple.SchedulerJob.java
/** * Generates a new timestamp/*from ww w . j a v a2 s. c o m*/ * @return */ protected long getNextTimeStamp() { Calendar calcCalendar; long currentTime; boolean validTimeStamp; boolean carryMinute; boolean carryHour; boolean carryDayOfMonth; boolean carryMonth; boolean firstYearAccess; calcCalendar = Calendar.getInstance(); SilverTrace.debug(MODULE_NAME, "SchedulerJob.getNextTimeStamp", "Current TimeStamp: " + logDateFormat.format(new Date(getMillisecondsOfCalendar(calcCalendar)))); currentTime = getMillisecondsOfCalendar(calcCalendar); calcCalendar.set(Calendar.YEAR, currentYear); calcCalendar.set(Calendar.MONTH, currentMonth); calcCalendar.set(Calendar.DAY_OF_MONTH, currentDayOfMonth); calcCalendar.set(Calendar.HOUR_OF_DAY, currentHour); calcCalendar.set(Calendar.MINUTE, currentMinute); SilverTrace.debug(MODULE_NAME, "SchedulerJob.getNextTimeStamp", "Start TimeStamp: " + logDateFormat.format(new Date(getMillisecondsOfCalendar(calcCalendar)))); // !!!!!! The values must be ordered ascend !!!!! validTimeStamp = false; carryMinute = false; carryHour = false; carryDayOfMonth = false; carryMonth = false; firstYearAccess = true; while (!validTimeStamp) { // Get new minute if (vMinutes.isEmpty()) { // Default ('*') -> Hit every minute // If the cron setting for minutes is *, we don't have to care about // incrementing minutes // So do a carryHour carryMinute = true; } else { // Special handling for lists with one element if (vMinutes.size() == 1) { currentMinute = vMinutes.get(0); carryMinute = !carryMinute; if (!carryMinute) { carryHour = false; carryDayOfMonth = false; carryMonth = false; } } else { int indexOfMinutes = vMinutes.indexOf(currentMinute); if ((indexOfMinutes == -1) || (indexOfMinutes == (vMinutes.size() - 1))) { currentMinute = vMinutes.get(0); carryMinute = true; } else { currentMinute = vMinutes.get(indexOfMinutes + 1); carryMinute = false; carryHour = false; carryDayOfMonth = false; carryMonth = false; } } } calcCalendar.set(Calendar.MINUTE, currentMinute); // Get new hour if (carryMinute) { if (vHours.isEmpty()) // Default ('*') -> Hit every hour { int maxHour = calcCalendar.getActualMaximum(Calendar.HOUR_OF_DAY); if (currentHour < maxHour) { currentHour = currentHour + 1; carryHour = false; carryDayOfMonth = false; carryMonth = false; } else { currentHour = calcCalendar.getActualMinimum(Calendar.HOUR_OF_DAY); carryHour = true; } } else { // Special handling for lists with one element if (vHours.size() == 1) { currentHour = vHours.get(0); carryHour = !carryHour; if (!carryHour) { carryDayOfMonth = false; carryMonth = false; } } else { int indexOfHours = vHours.indexOf(currentHour); if ((indexOfHours == -1) || (indexOfHours == (vHours.size() - 1))) { currentHour = vHours.get(0); carryHour = true; } else { currentHour = vHours.get(indexOfHours + 1); carryHour = false; carryDayOfMonth = false; carryMonth = false; } } } calcCalendar.set(Calendar.HOUR_OF_DAY, currentHour); } // Get new day of month if (carryHour) { if (vDaysOfMonth.isEmpty()) // Default ('*') -> Hit every month { int maxMonth = calcCalendar.getActualMaximum(Calendar.DAY_OF_MONTH); if (currentDayOfMonth < maxMonth) { currentDayOfMonth = currentDayOfMonth + 1; carryDayOfMonth = false; carryMonth = false; } else { currentDayOfMonth = calcCalendar.getActualMinimum(Calendar.DAY_OF_MONTH); carryDayOfMonth = true; } } else { // Special handling for lists with one element if (vMinutes.size() == 1) { currentDayOfMonth = vDaysOfMonth.get(0); carryDayOfMonth = !carryDayOfMonth; if (!carryDayOfMonth) { carryMonth = false; } } else { int indexOfMonths = vDaysOfMonth.indexOf(currentDayOfMonth); if ((indexOfMonths == -1) || (indexOfMonths == (vDaysOfMonth.size() - 1))) { currentDayOfMonth = vDaysOfMonth.get(0); carryDayOfMonth = true; } else { currentDayOfMonth = vDaysOfMonth.get(indexOfMonths + 1); carryDayOfMonth = false; carryMonth = false; } } } calcCalendar.set(Calendar.DAY_OF_MONTH, currentDayOfMonth); } // Get new month if (carryDayOfMonth) { if (vMonths.isEmpty()) // Default ('*') -> Hit every month { int maxMonth = calcCalendar.getActualMaximum(Calendar.MONTH); if (currentMonth < maxMonth) { currentMonth = currentMonth + 1; carryMonth = false; } else { currentMonth = calcCalendar.getActualMinimum(Calendar.MONTH); carryMonth = true; } } else { // Special handling for lists with one element if (vMinutes.size() == 1) { currentMonth = vMonths.get(0); carryMonth = !carryMonth; } else { int indexOfMonths = vMonths.indexOf(currentMonth); if ((indexOfMonths == -1) || (indexOfMonths == (vMonths.size() - 1))) { currentMonth = vMonths.get(0); carryMonth = true; } else { currentMonth = vMonths.get(indexOfMonths + 1); carryMonth = false; } } } calcCalendar.set(Calendar.MONTH, currentMonth); } // Get new year if (carryMonth) { // Prevent Check for the 'ever carry' of one element lists if ((!firstYearAccess) || ((currentMinute == 0) && (currentHour == 0) && (currentDayOfMonth == 1) && (currentMonth == 0))) { // Hit every year currentYear = currentYear + 1; calcCalendar.set(Calendar.YEAR, currentYear); } firstYearAccess = false; } // If time stamp is greater than the current time check the day of week if (getMillisecondsOfCalendar(calcCalendar) > currentTime) { // Check eventualy day movement while calculations if (calcCalendar.get(Calendar.DAY_OF_MONTH) == currentDayOfMonth) { // Check for correct day of week if (vDaysOfWeek.isEmpty()) { validTimeStamp = true; } else { for (Integer dayOfWeek : vDaysOfWeek) { if (calcCalendar.get(Calendar.DAY_OF_WEEK) == dayOfWeek) { validTimeStamp = true; break; } } } } } } // while (getMillisecondsOfCurrentTimeStamp (calcCalendar) < currentTime) SilverTrace.debug(MODULE_NAME, "SchedulerJob.getNextTimeStamp", "New TimeStamp: " + logDateFormat.format(new Date(getMillisecondsOfCalendar(calcCalendar)))); return getMillisecondsOfCalendar(calcCalendar); }