svn commit: r664228 - in /ofbiz/trunk/applications/accounting/webapp/accounting/WEB-INF/actions/fixedasset: ./ ViewCalendar.groovy

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

svn commit: r664228 - in /ofbiz/trunk/applications/accounting/webapp/accounting/WEB-INF/actions/fixedasset: ./ ViewCalendar.groovy

adrianc
Author: adrianc
Date: Fri Jun  6 18:05:21 2008
New Revision: 664228

URL: http://svn.apache.org/viewvc?rev=664228&view=rev
Log:
Added a file that somehow got missed in a previous commit.

Added:
    ofbiz/trunk/applications/accounting/webapp/accounting/WEB-INF/actions/fixedasset/
    ofbiz/trunk/applications/accounting/webapp/accounting/WEB-INF/actions/fixedasset/ViewCalendar.groovy

Added: ofbiz/trunk/applications/accounting/webapp/accounting/WEB-INF/actions/fixedasset/ViewCalendar.groovy
URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/accounting/webapp/accounting/WEB-INF/actions/fixedasset/ViewCalendar.groovy?rev=664228&view=auto
==============================================================================
--- ofbiz/trunk/applications/accounting/webapp/accounting/WEB-INF/actions/fixedasset/ViewCalendar.groovy (added)
+++ ofbiz/trunk/applications/accounting/webapp/accounting/WEB-INF/actions/fixedasset/ViewCalendar.groovy Fri Jun  6 18:05:21 2008
@@ -0,0 +1,100 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import java.util.*;
+import org.ofbiz.entity.*;
+import org.ofbiz.entity.condition.*;
+import org.ofbiz.base.util.*;
+import java.sql.Timestamp;
+import java.text.*;
+
+// The view mode - Day, Week, or Month
+String viewMode = parameters.get("viewMode");
+if (UtilValidate.isEmpty(viewMode)) {
+    viewMode = "W";
+    parameters.put("viewMode", viewMode);
+}
+
+// Prepare vars for mode-specific date calculations
+String startParam = parameters.get("start");
+if(startParam == null) {
+    start = nowTimestamp.clone();
+} else {
+    start = new Timestamp(Long.parseLong(startParam));
+}
+int numPeriods = 24;
+int periodType = Calendar.HOUR;
+Timestamp getFrom = null;
+Timestamp prev = null;
+Timestamp next = null;
+Timestamp end = null;
+
+if ("D".equals(viewMode)) {
+    // Day view
+    start = UtilDateTime.getDayStart(start, timeZone, locale);
+    getFrom = new Timestamp(start.getTime());
+    prev = UtilDateTime.getDayStart(start, -1, timeZone, locale);
+    next = UtilDateTime.getDayStart(start, 1, timeZone, locale);
+} else if ("W".equals(viewMode)) {
+    // Week view
+    start = UtilDateTime.getWeekStart(start, timeZone, locale);
+    getFrom = new Timestamp(start.getTime());
+    prev = UtilDateTime.getDayStart(start,-7, timeZone, locale);
+    next = UtilDateTime.getDayStart(start,7, timeZone, locale);
+    end = UtilDateTime.getDayStart(start,6, timeZone, locale);
+    numPeriods = 7;
+    periodType = Calendar.DATE;
+} else {
+    // Month view
+    start = UtilDateTime.getMonthStart(start, timeZone, locale);
+    Calendar tempCal = UtilDateTime.toCalendar(start, timeZone, locale);
+    int firstWeekNum = tempCal.get(Calendar.WEEK_OF_YEAR);
+    globalContext.put("firstWeekNum", new Integer(firstWeekNum));
+    numPeriods = tempCal.getActualMaximum(Calendar.DAY_OF_MONTH);
+    prev = UtilDateTime.getDayStart(start, -1, timeZone, locale);
+    next = UtilDateTime.getDayStart(start, numPeriods+1, timeZone, locale);
+    end = UtilDateTime.getDayStart(start, numPeriods, timeZone, locale);
+    int prevMonthDays = tempCal.get(Calendar.DAY_OF_WEEK) - tempCal.getFirstDayOfWeek();
+    if (prevMonthDays < 0) {
+        prevMonthDays = 7 + prevMonthDays;
+    }
+    tempCal.add(Calendar.DATE, -(prevMonthDays));
+    numPeriods += prevMonthDays;
+    getFrom = new Timestamp(tempCal.getTimeInMillis());
+    periodType = Calendar.DATE;
+    globalContext.put("end", end);
+}
+
+List entityExprList = UtilMisc.toList(EntityCondition.makeCondition("currentStatusId", EntityOperator.NOT_EQUAL, "CAL_CANCELLED"),
+    EntityCondition.makeCondition("workEffortTypeId", EntityOperator.EQUALS, "TASK"), EntityCondition.makeCondition("workEffortPurposeTypeId", EntityOperator.EQUALS, "WEPT_MAINTENANCE"));
+String fixedAssetId = parameters.get("fixedAssetId");
+if (UtilValidate.isNotEmpty(fixedAssetId)) {
+    entityExprList.add(EntityCondition.makeCondition("fixedAssetId", EntityOperator.EQUALS, fixedAssetId));
+    globalContext.put("fixedAssetId", fixedAssetId);
+    globalContext.put("addlParam", "&fixedAssetId=" + fixedAssetId);
+}
+serviceCtx = UtilMisc.toMap("userLogin", userLogin, "start", getFrom, "numPeriods", new Integer(numPeriods), "periodType", new Integer(periodType));
+serviceCtx.putAll(UtilMisc.toMap("entityExprList", entityExprList, "locale", locale, "timeZone", timeZone));
+result = dispatcher.runSync("getWorkEffortEventsByPeriod", serviceCtx);
+globalContext.put("periods", result.get("periods"));
+globalContext.put("maxConcurrentEntries", result.get("maxConcurrentEntries"));
+
+globalContext.put("start", start);
+globalContext.put("prev", prev);
+globalContext.put("next", next);