1 24 package org.ofbiz.marketing.report; 25 26 import org.ofbiz.base.util.UtilMisc; 27 import org.ofbiz.base.util.Debug; 28 import org.ofbiz.entity.GenericValue; 29 import org.ofbiz.entity.util.EntityUtil; 30 import org.ofbiz.marketing.tracking.TrackingCodeEvents; 31 32 import java.util.*; 33 34 42 public class ReportHelper { 43 44 public static final String module = ReportHelper.class.getName(); 45 46 55 public static List calcConversionRates(List visits, List orders, String keyFieldName) { 56 List conversionRates = new ArrayList(); 57 58 for (Iterator vit = visits.iterator(); vit.hasNext(); ) { 60 GenericValue visit = (GenericValue) vit.next(); 61 Map reportValue = new HashMap(); 62 reportValue.put(keyFieldName, visit.getString(keyFieldName)); 63 reportValue.put("visits", visit.getLong("visitId")); 65 List ordersForThisKey = EntityUtil.filterByAnd(orders, UtilMisc.toMap(keyFieldName, visit.getString(keyFieldName))); 67 68 if ((ordersForThisKey != null) && (ordersForThisKey.size() > 0)) { 70 GenericValue orderValue = (GenericValue) ordersForThisKey.get(0); 72 73 reportValue.put("orders", orderValue.getLong("orderId")); if (orderValue.getDouble("grandTotal") == null) { 75 reportValue.put("orderAmount", new Double (0)); 76 } else { 77 reportValue.put("orderAmount", orderValue.getDouble("grandTotal")); 78 } 79 if ((orderValue.getLong("orderId") == null) || (visit.getLong("visitId") == null) || 80 (visit.getLong("visitId").intValue() == 0)) { 81 reportValue.put("conversionRate", new Double (0)); 82 } else { 83 reportValue.put("conversionRate", new Double (orderValue.getLong("orderId").doubleValue() / visit.getLong("visitId").doubleValue())); 84 } 85 } else { 86 reportValue.put("orders", new Long (0)); 88 reportValue.put("orderAmount", new Double (0)); 89 reportValue.put("conversionRate", new Double (0)); 90 } 91 92 conversionRates.add(reportValue); 93 } 94 95 return conversionRates; 96 } 97 } 98 99 100 101 102 | Popular Tags |