[OFBiz] SVN: r6463 - in trunk/applications/marketing: src/org/ofbiz/marketing src/org/ofbiz/marketing/report webapp/marketing/WEB-INF/actions webapp/marketing/WEB-INF/actions/reports widget

sichen@svn.ofbiz.org sichen at svn.ofbiz.org
Tue Jan 3 11:03:30 CST 2006


Author: sichen
Date: 2006-01-03 11:03:21 -0600 (Tue, 03 Jan 2006)
New Revision: 6463

Added:
   trunk/applications/marketing/src/org/ofbiz/marketing/report/
   trunk/applications/marketing/src/org/ofbiz/marketing/report/ReportHelper.java
   trunk/applications/marketing/webapp/marketing/WEB-INF/actions/reports/
   trunk/applications/marketing/webapp/marketing/WEB-INF/actions/reports/MarketingCampaignReport.bsh
   trunk/applications/marketing/webapp/marketing/WEB-INF/actions/reports/TrackingCodeReport.bsh
Modified:
   trunk/applications/marketing/widget/ReportForms.xml
Log:
New .BSH methods and helper method to generate tracking code and marketing campaign visit, order, and conversion reports.  Changed forms to standardize display and names of input fields.  A lot of this is based on work from Mu Jinsong.  OFBIZ-572 is done.

Added: trunk/applications/marketing/src/org/ofbiz/marketing/report/ReportHelper.java
===================================================================
--- trunk/applications/marketing/src/org/ofbiz/marketing/report/ReportHelper.java	2006-01-03 17:02:26 UTC (rev 6462)
+++ trunk/applications/marketing/src/org/ofbiz/marketing/report/ReportHelper.java	2006-01-03 17:03:21 UTC (rev 6463)
@@ -0,0 +1,101 @@
+/*
+ *  $Id: ReportHelper.java 6395 2005-12-21 21:35:48  mujinsong $
+ *
+ *  Copyright (c) 2001-2005 The Open For Business Project - www.ofbiz.org
+ *
+ *  Permission is hereby granted, free of charge, to any person obtaining a
+ *  copy of this software and associated documentation files (the "Software"),
+ *  to deal in the Software without restriction, including without limitation
+ *  the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ *  and/or sell copies of the Software, and to permit persons to whom the
+ *  Software is furnished to do so, subject to the following conditions:
+ *
+ *  The above copyright notice and this permission notice shall be included
+ *  in all copies or substantial portions of the Software.
+ *
+ *  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+ *  OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ *  MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+ *  IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
+ *  CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT
+ *  OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR
+ *  THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+package org.ofbiz.marketing.report;
+
+import org.ofbiz.base.util.UtilMisc;
+import org.ofbiz.base.util.Debug;
+import org.ofbiz.entity.GenericValue;
+import org.ofbiz.entity.util.EntityUtil;
+import org.ofbiz.marketing.tracking.TrackingCodeEvents;
+
+import java.util.*;
+
+/**
+ * Marketing Report Helper
+ *
+ * @author <a href="mailto:mujinsong at gmail.com">Mu Jinsong</a>
+ * @author <a href="mailto:sichen at opensourcestrategies.com">Si Chen</a>
+ * @version $Rev:  6395
+ * @since 3.2
+ */
+public class ReportHelper {
+
+    public static final String module = ReportHelper.class.getName();
+    
+/**
+ * Calculate conversion rates based on a List of visits and orders.  Designed to be used for reporting on 
+ * tracking code or marketing campaigns
+ * @param visits
+ * @param orders
+ * @param keyFieldName - name of key field for visits and orders Lists, ie "trackingCodeId" or "marketingCampaignId"
+ * @return a List of Maps with keys (${keyFieldName}, visits - # visits, orders - # orders, orderAmount - total amount of orders,
+ * conversionRate - # orders/# visits
+ */
+    public static List calcConversionRates(List visits, List orders, String keyFieldName) {
+        List conversionRates = new ArrayList();
+        
+        // loop through all the visits
+        for (Iterator vit = visits.iterator(); vit.hasNext(); ) {
+            GenericValue visit = (GenericValue) vit.next();
+            Map reportValue = new HashMap();
+            reportValue.put(keyFieldName, visit.getString(keyFieldName));
+            reportValue.put("visits", visit.getLong("visitId")); // actually # of visits
+            
+            // find the matching entry in orders for the given key field
+            List ordersForThisKey = EntityUtil.filterByAnd(orders, UtilMisc.toMap(keyFieldName, visit.getString(keyFieldName)));
+            
+            // if there are matching orders, then calculate orders, order amount, and conversion rate
+            if ((ordersForThisKey != null) && (ordersForThisKey.size() > 0)) {
+                // note: there should be only one line of order stats per key, so .get(0) should work
+                GenericValue orderValue = (GenericValue) ordersForThisKey.get(0);
+
+                reportValue.put("orders", orderValue.getLong("orderId")); // # of orders
+                if (orderValue.getDouble("grandTotal") == null) {
+                    reportValue.put("orderAmount", new Double(0));                    
+                } else {
+                    reportValue.put("orderAmount", orderValue.getDouble("grandTotal")); 
+                }
+                if ((orderValue.getLong("orderId") == null) || (visit.getLong("visitId") == null) || 
+                    (visit.getLong("visitId").intValue() == 0)) {
+                    reportValue.put("conversionRate", new Double(0));
+                } else {
+                    reportValue.put("conversionRate", new Double(orderValue.getLong("orderId").doubleValue() / visit.getLong("visitId").doubleValue()));    
+                }
+            } else {
+                // no matching orders - all those values are zeroes
+                reportValue.put("orders", new Long(0));
+                reportValue.put("orderAmount", new Double(0));
+                reportValue.put("conversionRate", new Double(0));
+            }
+            
+            conversionRates.add(reportValue);
+        }
+        
+        return conversionRates;
+    }
+}
+
+
+
+


Property changes on: trunk/applications/marketing/src/org/ofbiz/marketing/report/ReportHelper.java
___________________________________________________________________
Name: svn:mime-type
   + text/plain
Name: svn:keywords
   + "Date Rev Author URL Id"
Name: svn:eol-style
   + native

Added: trunk/applications/marketing/webapp/marketing/WEB-INF/actions/reports/MarketingCampaignReport.bsh
===================================================================
--- trunk/applications/marketing/webapp/marketing/WEB-INF/actions/reports/MarketingCampaignReport.bsh	2006-01-03 17:02:26 UTC (rev 6462)
+++ trunk/applications/marketing/webapp/marketing/WEB-INF/actions/reports/MarketingCampaignReport.bsh	2006-01-03 17:03:21 UTC (rev 6463)
@@ -0,0 +1,68 @@
+/*
+ *  Copyright (c) 2001-2005 The Open For Business Project - www.ofbiz.org
+ *
+ *  Permission is hereby granted, free of charge, to any person obtaining a
+ *  copy of this software and associated documentation files (the "Software"),
+ *  to deal in the Software without restriction, including without limitation
+ *  the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ *  and/or sell copies of the Software, and to permit persons to whom the
+ *  Software is furnished to do so, subject to the following conditions:
+ *
+ *  The above copyright notice and this permission notice shall be included
+ *  in all copies or substantial portions of the Software.
+ *
+ *  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+ *  OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ *  MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+ *  IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
+ *  CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT
+ *  OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR
+ *  THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ *
+ * @author <a href="mailto:mujinsong at gmail.com">Mu Jinsong</a>
+ * @version $Rev:  6395
+ * @since 3.2
+ */
+
+import org.ofbiz.entity.GenericValue;
+import org.ofbiz.entity.GenericDelegator;
+import org.ofbiz.entity.GenericEntityException;
+import org.ofbiz.entity.transaction.TransactionUtil;
+import org.ofbiz.entity.util.EntityListIterator;
+import org.ofbiz.entity.condition.EntityOperator;
+import org.ofbiz.entity.condition.EntityExpr;
+import org.ofbiz.entity.condition.EntityConditionList;
+import org.ofbiz.marketing.report.ReportHelper;
+import org.ofbiz.base.util.UtilMisc;
+import org.ofbiz.base.util.Debug;
+
+//query for both number of visits and number of orders
+
+marketingCampaignId = request.getParameter("marketingCampaignId");
+fromDateStr = request.getParameter("fromDate");
+thruDateStr = request.getParameter("thruDate");
+visitConditionList = new LinkedList();
+orderConditionList = new LinkedList();
+
+if ((fromDateStr != null) && !(fromDateStr.equals(""))) {
+    visitConditionList.add(new EntityExpr("fromDate", EntityOperator.GREATER_THAN_EQUAL_TO, fromDateStr));
+    orderConditionList.add(new EntityExpr("orderDate",EntityOperator.GREATER_THAN_EQUAL_TO,fromDateStr));
+}
+if ((thruDateStr != null) && !(thruDateStr.equals(""))) {
+    visitConditionList.add(new EntityExpr("fromDate",EntityOperator.LESS_THAN_EQUAL_TO,thruDateStr));
+    orderConditionList.add(new EntityExpr("orderDate",EntityOperator.LESS_THAN_EQUAL_TO,thruDateStr));
+}
+if ((marketingCampaignId != null) && !(marketingCampaignId.equals(""))) {
+    visitConditionList.add(new EntityExpr("marketingCampaignId", EntityOperator.EQUALS, marketingCampaignId));
+    orderConditionList.add(new EntityExpr("marketingCampaignId", EntityOperator.EQUALS, marketingCampaignId));
+}
+
+visitConditions = new EntityConditionList(visitConditionList, EntityOperator.AND);
+orderConditions = new EntityConditionList(orderConditionList, EntityOperator.AND);
+
+visits = delegator.findByCondition("MarketingCampaignAndVisit", visitConditions, UtilMisc.toList("marketingCampaignId", "visitId"),UtilMisc.toList("marketingCampaignId"));
+orders = delegator.findByCondition("MarketingCampaignAndOrderHeader", orderConditions, UtilMisc.toList("marketingCampaignId", "orderId", "grandTotal"), UtilMisc.toList("marketingCampaignId"));
+
+//use this helper to build a List of visits, orders, order totals, and conversion rates
+marketingCampaignVisitAndOrders = ReportHelper.calcConversionRates(visits, orders, "marketingCampaignId");
+context.put("marketingCampaignVisitAndOrders", marketingCampaignVisitAndOrders);
\ No newline at end of file


Property changes on: trunk/applications/marketing/webapp/marketing/WEB-INF/actions/reports/MarketingCampaignReport.bsh
___________________________________________________________________
Name: svn:mime-type
   + text/plain
Name: svn:keywords
   + "Date Rev Author URL Id"
Name: svn:eol-style
   + native

Added: trunk/applications/marketing/webapp/marketing/WEB-INF/actions/reports/TrackingCodeReport.bsh
===================================================================
--- trunk/applications/marketing/webapp/marketing/WEB-INF/actions/reports/TrackingCodeReport.bsh	2006-01-03 17:02:26 UTC (rev 6462)
+++ trunk/applications/marketing/webapp/marketing/WEB-INF/actions/reports/TrackingCodeReport.bsh	2006-01-03 17:03:21 UTC (rev 6463)
@@ -0,0 +1,68 @@
+/*
+ *  Copyright (c) 2001-2005 The Open For Business Project - www.ofbiz.org
+ *
+ *  Permission is hereby granted, free of charge, to any person obtaining a
+ *  copy of this software and associated documentation files (the "Software"),
+ *  to deal in the Software without restriction, including without limitation
+ *  the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ *  and/or sell copies of the Software, and to permit persons to whom the
+ *  Software is furnished to do so, subject to the following conditions:
+ *
+ *  The above copyright notice and this permission notice shall be included
+ *  in all copies or substantial portions of the Software.
+ *
+ *  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+ *  OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ *  MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+ *  IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
+ *  CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT
+ *  OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR
+ *  THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ *
+ * @author <a href="mailto:mujinsong at gmail.com">Mu Jinsong</a>
+ * @version $Rev:  6395
+ * @since 3.2
+ */
+
+import org.ofbiz.entity.GenericValue;
+import org.ofbiz.entity.GenericDelegator;
+import org.ofbiz.entity.GenericEntityException;
+import org.ofbiz.entity.transaction.TransactionUtil;
+import org.ofbiz.entity.condition.EntityOperator;
+import org.ofbiz.entity.condition.EntityExpr;
+import org.ofbiz.entity.condition.EntityConditionList;
+import org.ofbiz.marketing.report.ReportHelper;
+import org.ofbiz.base.util.UtilMisc;
+import org.ofbiz.base.util.Debug;
+
+trackingCodeIdStr = request.getParameter("trackingCodeId");
+fromDateStr = request.getParameter("fromDate");
+thruDateStr = request.getParameter("thruDate");
+
+// query for both number of visits and number of orders
+
+visitConditionList = new LinkedList();
+orderConditionList = new LinkedList();
+
+if ((fromDateStr != null) && !(fromDateStr.equals(""))) {
+    visitConditionList.add(new EntityExpr("fromDate", EntityOperator.GREATER_THAN_EQUAL_TO, fromDateStr));
+    orderConditionList.add(new EntityExpr("orderDate",EntityOperator.GREATER_THAN_EQUAL_TO,fromDateStr));
+}
+if ((thruDateStr != null) && !(thruDateStr.equals(""))) {
+     visitConditionList.add(new EntityExpr("fromDate",EntityOperator.LESS_THAN_EQUAL_TO,thruDateStr));
+     orderConditionList.add(new EntityExpr("orderDate",EntityOperator.LESS_THAN_EQUAL_TO,thruDateStr));
+}
+if ((trackingCodeIdStr != null) && !(trackingCodeIdStr.equals(""))) {
+     visitConditionList.add(new EntityExpr("trackingCodeId", EntityOperator.EQUALS, trackingCodeIdStr));
+     orderConditionList.add(new EntityExpr("trackingCodeId", EntityOperator.EQUALS, trackingCodeIdStr));
+}
+
+visitConditions = new EntityConditionList(visitConditionList, EntityOperator.AND);
+orderConditions = new EntityConditionList(orderConditionList, EntityOperator.AND);
+
+visits = delegator.findByCondition("TrackingCodeAndVisit", visitConditions, UtilMisc.toList("trackingCodeId", "visitId"),UtilMisc.toList("trackingCodeId"));
+orders = delegator.findByCondition("TrackingCodeAndOrderHeader", orderConditions, UtilMisc.toList("trackingCodeId", "orderId", "grandTotal"), UtilMisc.toList("trackingCodeId"));
+
+// use this helper to build a List of visits, orders, order totals, and conversion rates
+trackingCodeVisitAndOrders = ReportHelper.calcConversionRates(visits, orders, "trackingCodeId");
+context.put("trackingCodeVisitAndOrders", trackingCodeVisitAndOrders);


Property changes on: trunk/applications/marketing/webapp/marketing/WEB-INF/actions/reports/TrackingCodeReport.bsh
___________________________________________________________________
Name: svn:mime-type
   + text/plain
Name: svn:keywords
   + "Date Rev Author URL Id"
Name: svn:eol-style
   + native

Modified: trunk/applications/marketing/widget/ReportForms.xml
===================================================================
--- trunk/applications/marketing/widget/ReportForms.xml	2006-01-03 17:02:26 UTC (rev 6462)
+++ trunk/applications/marketing/widget/ReportForms.xml	2006-01-03 17:03:21 UTC (rev 6463)
@@ -55,7 +55,7 @@
             <date-time type="timestamp"/>
         </field>
 
-         <field name="campaignName" title="Marketing Campaign">
+         <field name="marketingCampaignId" title="Marketing Campaign">
             <drop-down allow-empty="true">
                 <option key="" description="- Any -"/>
                 <entity-options entity-name="MarketingCampaign" description="${campaignName}">
@@ -68,12 +68,12 @@
         </field>
     </form>
 
-      <form name="TrackingCodeReport" default-title-style="tableheadtext"
+    <form name="TrackingCodeReport" default-title-style="tableheadtext"
         default-tooltip-style="tabletext" default-widget-area-style="tabletextright"
-        list-iterator-name="trackingCodeIterator" target="" paginate-target="TrackingCodeReport"
+        list-name="trackingCodeVisitAndOrders" target="" paginate-target="TrackingCodeReport"
         title="${uiLabelMap.TrackingCodeReportTitle}" type="list">
         <field name="trackingCodeId"  widget-area-style="tabletext" title="${uiLabelMap.TrackingCode}">
-            <display/>
+            <display-entity entity-name="TrackingCode" key-field-name="trackingCodeId" description="${description} [${trackingCodeId}]"/>
         </field>
         <field name="visits" title="${uiLabelMap.MarketingVisits}"><display/></field>
         <field name="orders" title="${uiLabelMap.MarketingOrders}"><display/></field>
@@ -83,10 +83,11 @@
 
    <form name="MarketCampaignReport" default-title-style="tableheadtext"
         default-tooltip-style="tabletext" default-widget-area-style="tabletextright"
-        list-iterator-name="marketingCampaignIterator" target="" paginate-target="MarketCampaignReport"
+        list-name="marketingCampaignVisitAndOrders" target="" paginate-target="MarketCampaignReport"
         title="${uiLabelMap.MarketingCampaignReportTitle}" type="list">
-        <field name="campaignName" title="${uiLabelMap.MarketingCampaignName}"><display/></field>
-        <field name="trackingCodeId" title="${uiLabelMap.TrackingCode}"><display/></field>
+        <field name="marketingCampaignId" title="${uiLabelMap.MarketingCampaignName}" widget-area-style="tabletext">
+            <display-entity entity-name="MarketingCampaign" key-field-name="marketingCampaignId" description="${campaignName} [${marketingCampaignId}]"/>
+        </field>
         <field name="visits" title="${uiLabelMap.MarketingVisits}"><display/></field>
         <field name="orders" title="${uiLabelMap.MarketingOrders}"><display/></field>
         <field name="orderAmount" title="${uiLabelMap.MarketingOrderAmount}"><display/></field>



More information about the Svn mailing list