Beispiel #1
0
  public static Map<String, Object> assembleCrmsfaPartyFormMergeContext(
      Delegator delegator, String partyId) {
    Map<String, Object> templateContext = new HashMap<String, Object>();
    if (UtilValidate.isNotEmpty(partyId)) {
      try {
        String email =
            PartyContactHelper.getElectronicAddressByPurpose(
                partyId, "EMAIL_ADDRESS", "PRIMARY_EMAIL", delegator);
        if (UtilValidate.isNotEmpty(email)) {
          templateContext.put("email", email);
        }
        GenericValue address =
            PartyContactHelper.getPostalAddressValueByPurpose(
                partyId, "PRIMARY_LOCATION", true, delegator);
        if (UtilValidate.isNotEmpty(address)) {
          templateContext.put("attnName", address.get("attnName"));
          templateContext.put("toName", address.get("toName"));
          templateContext.put("address1", address.get("address1"));
          templateContext.put("address2", address.get("address2"));
          templateContext.put("city", address.get("city"));
          templateContext.put("zip", address.get("postalCode"));

          GenericValue stateProvGeo = address.getRelatedOne("StateProvinceGeo");
          if (UtilValidate.isNotEmpty(stateProvGeo)) {
            templateContext.put("state", stateProvGeo.get("geoName"));
          }
          GenericValue countryGeo = address.getRelatedOne("CountryGeo");
          if (UtilValidate.isNotEmpty(countryGeo)) {
            templateContext.put("country", countryGeo.get("geoName"));
          }
        }
        GenericValue party =
            delegator.findByPrimaryKey("PartySummaryCRMView", UtilMisc.toMap("partyId", partyId));
        Map<String, Object> partyMap = party.getAllFields();
        if (UtilValidate.isNotEmpty(partyMap)) {
          Iterator<String> pmf = partyMap.keySet().iterator();
          while (pmf.hasNext()) {
            String fieldName = pmf.next();
            Object value = partyMap.get(fieldName);
            if (UtilValidate.isNotEmpty(value)) {
              templateContext.put(fieldName, value);
            }
          }
        }

        templateContext.put(
            "fullName", org.ofbiz.party.party.PartyHelper.getPartyName(party, false));

      } catch (GenericEntityException ge) {
        Debug.logError(ge, MODULE);
      }
    }
    return templateContext;
  }
  @Override
  public void doAfterCompose(Component comp) throws Exception {
    super.doAfterCompose(comp);

    GenericValue userLogin =
        (GenericValue) comp.getDesktop().getSession().getAttribute("userLogin");

    GenericDelegator delegator = (GenericDelegator) userLogin.getDelegator();
    if (delegator == null) GenericDelegator.getGenericDelegator("default");

    GenericValue person = userLogin.getRelatedOne("Person");

    Map<String, Object> allFields = person.getAllFields();

    int count = 0;

    Collection<Component> leftHalf = new LinkedList<Component>();
    Collection<Component> rightHalf = new LinkedList<Component>();
    Label label = null;
    Label labelDesc = null;
    for (String key : allFields.keySet()) {

      Object obj = allFields.get(key);
      label = new Label();
      labelDesc = new Label();
      labelDesc.setValue(key);
      label.setValue(obj != null ? obj.toString() : "");
      Hbox hbox = new Hbox(new Component[] {labelDesc, label});
      if (count % 2 == 0) {
        leftHalf.add(hbox);
      } else {
        rightHalf.add(hbox);
      }
      count++;
    }

    Vbox vbox_1 = new org.zkoss.zul.Vbox(leftHalf.toArray(new Component[leftHalf.size()]));
    Vbox vbox_2 = new org.zkoss.zul.Vbox(rightHalf.toArray(new Component[rightHalf.size()]));
    comp.appendChild(vbox_1);
    comp.appendChild(vbox_2);
  }
Beispiel #3
0
  public static Map<String, Object> assembleCrmsfaOrderFormMergeContext(
      Delegator delegator, String orderId) {
    Map<String, Object> templateContext = new HashMap<String, Object>();
    if (UtilValidate.isNotEmpty(orderId)) {
      try {
        OrderReadHelper orh = new OrderReadHelper(delegator, orderId);
        templateContext.put("orderId", orderId);
        templateContext.put("externalOrderId", orh.getOrderHeader().get("externalId"));
        templateContext.put("orderDate", orh.getOrderHeader().getTimestamp("orderDate"));

        GenericValue billingParty = orh.getBillToParty();
        if (UtilValidate.isNotEmpty(billingParty)) {
          if ("Person".equalsIgnoreCase(billingParty.getEntityName())) {
            templateContext.put("orderBillingFirstName", billingParty.get("firstName"));
            templateContext.put("orderBillingLastName", billingParty.get("lastName"));
          }
          templateContext.put("orderPartyId", billingParty.get("partyId"));
          templateContext.put(
              "orderBillingFullName",
              org.ofbiz.party.party.PartyHelper.getPartyName(billingParty, false));
        }

        templateContext.put("orderSubtotal", orh.getOrderItemsSubTotal());
        templateContext.put("orderTaxTotal", orh.getTaxTotal());
        templateContext.put("orderShippingTotal", orh.getShippingTotal());
        templateContext.put("orderGrandTotal", orh.getOrderGrandTotal());
        templateContext.put(
            "orderPaymentTotal",
            orh.getOrderGrandTotal().subtract(UtilOrder.getOrderOpenAmount(orh)));

        GenericValue shippingParty = orh.getShipToParty();
        if (UtilValidate.isNotEmpty(shippingParty)) {
          if ("Person".equalsIgnoreCase(shippingParty.getEntityName())) {
            templateContext.put("orderShippingFirstName", shippingParty.get("firstName"));
            templateContext.put("orderShippingLastName", shippingParty.get("lastName"));
          } else {
            templateContext.put("orderShippingCompanyName", shippingParty.get("groupName"));
          }
          templateContext.put(
              "orderShippingFullName",
              org.ofbiz.party.party.PartyHelper.getPartyName(shippingParty, false));
        }

        List<GenericValue> orderItemVals = orh.getOrderItems();
        List<Map<String, Object>> orderItems = new ArrayList<Map<String, Object>>();
        for (GenericValue orderItemVal : orderItemVals) {
          Map<String, Object> orderItem = orderItemVal.getAllFields();
          GenericValue product = orderItemVal.getRelatedOne("Product");
          if (UtilValidate.isEmpty(product)) {
            continue;
          }
          for (String fieldName : (Set<String>) product.keySet()) {
            orderItem.put(fieldName, product.get(fieldName));
          }
          orderItems.add(orderItem);
        }
        templateContext.put("orderItems", orderItems);

      } catch (GenericEntityException e) {
        Debug.logError(e, MODULE);
      }
    }
    return templateContext;
  }