You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ofbiz.apache.org by le...@apache.org on 2008/06/13 05:17:39 UTC

svn commit: r667321 - in /ofbiz/trunk/applications/accounting: webapp/accounting/WEB-INF/actions/fixedasset/ViewCalendar.groovy webapp/accounting/WEB-INF/actions/invoice/CreateApplicationList.groovy widget/InvoiceScreens.xml

Author: lektran
Date: Thu Jun 12 20:17:38 2008
New Revision: 667321

URL: http://svn.apache.org/viewvc?rev=667321&view=rev
Log:
Couple of script cleanups

Modified:
    ofbiz/trunk/applications/accounting/webapp/accounting/WEB-INF/actions/fixedasset/ViewCalendar.groovy
    ofbiz/trunk/applications/accounting/webapp/accounting/WEB-INF/actions/invoice/CreateApplicationList.groovy
    ofbiz/trunk/applications/accounting/widget/InvoiceScreens.xml

Modified: 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=667321&r1=667320&r2=667321&view=diff
==============================================================================
--- ofbiz/trunk/applications/accounting/webapp/accounting/WEB-INF/actions/fixedasset/ViewCalendar.groovy (original)
+++ ofbiz/trunk/applications/accounting/webapp/accounting/WEB-INF/actions/fixedasset/ViewCalendar.groovy Thu Jun 12 20:17:38 2008
@@ -25,25 +25,22 @@
 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);
-}
+viewMode = parameters.viewMode ?: "W";
+parameters.viewMode = viewMode;
 
 // Prepare vars for mode-specific date calculations
-String startParam = parameters.get("start");
-if(startParam == null) {
+startParam = parameters.start;
+if(!startParam) {
     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;
+numPeriods = 24;
+periodType = Calendar.HOUR;
+getFrom = null;
+prev = null;
+next = null;
+end = null;
 
 if ("D".equals(viewMode)) {
     // Day view
@@ -55,22 +52,22 @@
     // 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);
+    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));
+    tempCal = UtilDateTime.toCalendar(start, timeZone, locale);
+    firstWeekNum = tempCal.get(Calendar.WEEK_OF_YEAR);
+    globalContext.firstWeekNum = 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();
+    prevMonthDays = tempCal.get(Calendar.DAY_OF_WEEK) - tempCal.getFirstDayOfWeek();
     if (prevMonthDays < 0) {
         prevMonthDays = 7 + prevMonthDays;
     }
@@ -78,23 +75,23 @@
     numPeriods += prevMonthDays;
     getFrom = new Timestamp(tempCal.getTimeInMillis());
     periodType = Calendar.DATE;
-    globalContext.put("end", end);
+    globalContext.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 = [EntityCondition.makeCondition("currentStatusId", EntityOperator.NOT_EQUAL, "CAL_CANCELLED"),
+    EntityCondition.makeCondition("workEffortTypeId", EntityOperator.EQUALS, "TASK"), EntityCondition.makeCondition("workEffortPurposeTypeId", EntityOperator.EQUALS, "WEPT_MAINTENANCE")];
+fixedAssetId = parameters.fixedAssetId;
+if (fixedAssetId) {
     entityExprList.add(EntityCondition.makeCondition("fixedAssetId", EntityOperator.EQUALS, fixedAssetId));
-    globalContext.put("fixedAssetId", fixedAssetId);
-    globalContext.put("addlParam", "&fixedAssetId=" + fixedAssetId);
+    globalContext.fixedAssetId = fixedAssetId;
+    globalContext.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));
+serviceCtx = [userLogin : userLogin, start : getFrom, numPeriods : numPeriods, periodType : periodType];
+serviceCtx.putAll([entityExprList : entityExprList, locale : locale, timeZone : timeZone]);
 result = dispatcher.runSync("getWorkEffortEventsByPeriod", serviceCtx);
-globalContext.put("periods", result.get("periods"));
-globalContext.put("maxConcurrentEntries", result.get("maxConcurrentEntries"));
+globalContext.periods = result.periods;
+globalContext.maxConcurrentEntries = result.maxConcurrentEntries;
 
-globalContext.put("start", start);
-globalContext.put("prev", prev);
-globalContext.put("next", next);
+globalContext.start = start;
+globalContext.prev = prev;
+globalContext.next = next;

Modified: ofbiz/trunk/applications/accounting/webapp/accounting/WEB-INF/actions/invoice/CreateApplicationList.groovy
URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/accounting/webapp/accounting/WEB-INF/actions/invoice/CreateApplicationList.groovy?rev=667321&r1=667320&r2=667321&view=diff
==============================================================================
--- ofbiz/trunk/applications/accounting/webapp/accounting/WEB-INF/actions/invoice/CreateApplicationList.groovy (original)
+++ ofbiz/trunk/applications/accounting/webapp/accounting/WEB-INF/actions/invoice/CreateApplicationList.groovy Thu Jun 12 20:17:38 2008
@@ -28,82 +28,50 @@
 import java.text.*;
 import java.text.NumberFormat;
 
-decimals = UtilNumber.getBigDecimalScale("invoice.decimals");
-rounding = UtilNumber.getBigDecimalRoundingMode("invoice.rounding");
-ZERO = BigDecimal.ZERO;
+// @param GenericValue invoice - The Invoice entity to find payment applications for
+if (!invoice) return;
 
-invoiceId = request.getParameter("invoiceId") ?: context.invoiceId;
-invoice = delegator.findByPrimaryKey("Invoice", [invoiceId : invoiceId]);
-tabButtonItem = context.tabButtonItem;
-
-invoiceItems = [];  // to pass back to the screeen with payment applications added
-if (invoice) {    
-    // retrieve related applications with null itemnumber
-    invoiceAppl = null;  
-    invoiceAppls = delegator.findByAnd("PaymentApplication", [invoiceId : invoiceId, invoiceItemSeqId : null]);
-    invoiceAppls.each { invoiceAppl ->
-        itemmap = [:];
-        itemmap.invoiceId = invoiceId;
-        itemmap.invoiceItemSeqId = invoiceAppl.invoiceItemSeqId;
-        itemmap.total = InvoiceWorker.getInvoiceTotalBd(invoice).doubleValue();
-        itemmap.paymentApplicationId = invoiceAppl.paymentApplicationId;
-        itemmap.paymentId = invoiceAppl.paymentId;
-        itemmap.billingAccountId = invoiceAppl.billingAccountId;
-        itemmap.taxAuthGeoId = invoiceAppl.taxAuthGeoId;
-        itemmap.amountToApply = invoiceAppl.amountApplied;
-        itemmap.amountApplied = invoiceAppl.amountApplied;
-        invoiceItems.add(itemmap);
-    }
-
-	
-	// retrieve related applications with an existing itemnumber
-    invoice.getRelated("InvoiceItem").each { item ->
-        BigDecimal itemTotal = null;
-        if (item.amount != null) {
-              if (item.quantity == null || item.getBigDecimal("quantity").compareTo(ZERO) == 0) {
-                  itemTotal = item.getBigDecimal("amount");
-              } else {
-                  itemTotal = item.getBigDecimal("amount").multiply(item.getBigDecimal("quantity"));
-              }
-        }
+invoiceApplications = [];  // to pass back to the screen with payment applications added
+// retrieve related applications with null itemnumber
+invoiceAppls = invoice.getRelated("PaymentApplication", [invoiceItemSeqId : null]);
+invoiceAppls.each { invoiceAppl ->
+    itemmap = [:];
+    itemmap.invoiceId = invoiceAppl.invoiceId;
+    itemmap.invoiceItemSeqId = invoiceAppl.invoiceItemSeqId;
+    itemmap.total = InvoiceWorker.getInvoiceTotalBd(invoice).doubleValue();
+    itemmap.paymentApplicationId = invoiceAppl.paymentApplicationId;
+    itemmap.paymentId = invoiceAppl.paymentId;
+    itemmap.billingAccountId = invoiceAppl.billingAccountId;
+    itemmap.taxAuthGeoId = invoiceAppl.taxAuthGeoId;
+    itemmap.amountToApply = invoiceAppl.amountApplied;
+    itemmap.amountApplied = invoiceAppl.amountApplied;
+    invoiceApplications.add(itemmap);
+}
 
-        // get relation payment applications for every item(can be more than 1 per item number)
-        paymentApplications = item.getRelated("PaymentApplication");
-        if (paymentApplications) {
-              paymentApplications.each { paymentApplication ->
-                  itemmap = [:];
-                  itemmap.putAll(item);
-                  itemmap.total = NumberFormat.getInstance(locale).format(itemTotal);
-                  itemmap.paymentApplicationId = paymentApplication.paymentApplicationId;
-                  itemmap.paymentId = paymentApplication.paymentId;
-                  itemmap.toPaymentId = paymentApplication.toPaymentId;
-                  itemmap.amountApplied = paymentApplication.getBigDecimal("amountApplied");
-                  itemmap.amountToApply = paymentApplication.getBigDecimal("amountApplied");
-                  itemmap.billingAccountId = paymentApplication.billingAccountId;
-                  itemmap.taxAuthGeoId = paymentApplication.taxAuthGeoId;
-                  invoiceItems.add(itemmap);
-              }
-        }
 
-/*
-        // create an extra line for input when not completely applied but not in the overview 
-        if (tabButtonItem.equals("invoiceOverview") != true && 
-                      (paymentApplications == null || paymentApplications.size() == 0 
-                      || (applied < itemTotal && appliedAmount < invoiceAmount)))    {
-                  Map itemmap = new HashMap();
-                  itemmap.putAll(item);
-                  itemmap.put("total",itemTotal);
-                  itemmap.put("paymentApplicationId","");
-                  itemmap.put("paymentId","");
-                  itemmap.put("amountToApply", NumberFormat.getNumberInstance(locale).format(itemTotal - applied));
-                  itemmap.put("billingAccountId","");
-                  itemmap.put("taxAuthGeoId","");
-                  invoiceItems.add(itemmap);
-        }
-*/
+// retrieve related applications with an existing itemnumber
+invoice.getRelated("InvoiceItem").each { item ->
+    BigDecimal itemTotal = null;
+    if (item.amount != null) {
+          if (!item.quantity) {
+              itemTotal = item.getBigDecimal("amount");
+          } else {
+              itemTotal = item.getBigDecimal("amount").multiply(item.getBigDecimal("quantity"));
+          }
+    }
+    // get relation payment applications for every item(can be more than 1 per item number)
+    item.getRelated("PaymentApplication").each { paymentApplication ->
+        itemmap = [:];
+        itemmap.putAll(item);
+        itemmap.total = NumberFormat.getInstance(locale).format(itemTotal);
+        itemmap.paymentApplicationId = paymentApplication.paymentApplicationId;
+        itemmap.paymentId = paymentApplication.paymentId;
+        itemmap.toPaymentId = paymentApplication.toPaymentId;
+        itemmap.amountApplied = paymentApplication.getBigDecimal("amountApplied");
+        itemmap.amountToApply = paymentApplication.getBigDecimal("amountApplied");
+        itemmap.billingAccountId = paymentApplication.billingAccountId;
+        itemmap.taxAuthGeoId = paymentApplication.taxAuthGeoId;
+        invoiceApplications.add(itemmap);
     }
-	context.invoice = invoice;
-	context.invoiceId = invoiceId;
 }
-
-if(invoiceItems) context.invoiceApplications = invoiceItems;
+if (invoiceApplications) context.invoiceApplications = invoiceApplications;

Modified: ofbiz/trunk/applications/accounting/widget/InvoiceScreens.xml
URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/accounting/widget/InvoiceScreens.xml?rev=667321&r1=667320&r2=667321&view=diff
==============================================================================
--- ofbiz/trunk/applications/accounting/widget/InvoiceScreens.xml (original)
+++ ofbiz/trunk/applications/accounting/widget/InvoiceScreens.xml Thu Jun 12 20:17:38 2008
@@ -529,6 +529,7 @@
                 <set field="tabButtonItem" value="editInvoiceApplications"/>
                 
                 <set field="invoiceId" from-field="parameters.invoiceId"/>
+                <entity-one entity-name="Invoice" value-name="invoice"/>
                 <script location="component://accounting/webapp/accounting/WEB-INF/actions/invoice/CreateApplicationList.groovy"/>
                 <script location="component://accounting/webapp/accounting/WEB-INF/actions/invoice/ListNotAppliedPayments.groovy"/>
                 <set field="invoiceAmount" value="${bsh:org.ofbiz.accounting.invoice.InvoiceWorker.getInvoiceTotalBd(invoice)}"/>