public void setOrder(Order order) {

    for (SalesOrderEntry entry : order.getFiles(SalesOrderEntry.class).toList()) {
      CartItem item = new CartItem();

      String productCode = entry.getProductCode();

      QueryParameters params = new QueryParameters();
      List l =
          SpringUtil.getRepositoryService()
              .executeQuery(
                  params
                      .setEntity(Product.class)
                      .addRestriction(Restrictions.eq("providedBy", order.getOrderedFrom()))
                      .addRestriction(Restrictions.eq("code", item.getCode())),
                  Util.getRemoteUser());

      if (l.size() > 0) {
        Product p = (Product) l.get(0);
        entry.setProduct(item, p);
        item.setProduct(p);
        item.setQty(entry.getQuantity());
      }
    }
    update();
  }
  public static void teminateOnDeath(Container source) {
    final Order order =
        (Order)
            SpringUtil.getRepositoryService()
                .getFile(source.getAttribute("path"), Util.getRemoteUser());
    BillingInformation bi = order.getBillingInformation();
    final String email = bi.getEmail();

    EXDynaformPanel panel = new EXDynaformPanel("deceased", "Termination on Death");
    panel.setStyle("z-index", "4000");
    source.getAncestorOfType(PopupContainer.class).addPopup(panel);

    panel.addField("Name of person deceased :", new EXInput("nameofperson"));
    panel.addButton(new EXButton("Send", "Send Mail"));
    panel.addButton(new EXButton("cancel", "Cancel"));
    panel
        .getDescendentByName("Send")
        .addEvent(
            new Event() {

              @Override
              public void Success(ClientProxy container, Map<String, String> request)
                  throws UIException {
                // TODO Auto-generated method stub

              }

              @Override
              public boolean ServerAction(Container container, Map<String, String> request)
                  throws UIException {

                String person =
                    container
                        .getAncestorOfType(EXDynaformPanel.class)
                        .getField("nameofperson")
                        .getValue()
                        .toString();

                sendMail(person, email);

                container.getAncestorOfType(EXDynaformPanel.class).remove();

                order.setStatus(21);
                BillingInformation b = order.getBillingInformation();
                b.setOtherProperty(
                    "dateTerminated", new SimpleDateFormat("dd/MM/yyyy").format(new Date()));
                order.save();
                return true;
              }

              @Override
              public void ClientAction(ClientProxy container) {
                container
                    .mask(container.getAncestorOfType(EXDynaformPanel.class))
                    .makeServerRequest(this);
              }
            },
            Event.CLICK);
  }
 public static void cancel(Container source) {
   final Order order =
       (Order)
           SpringUtil.getRepositoryService()
               .getFile(source.getAttribute("path"), Util.getRemoteUser());
   BillingInformation bi = order.getBillingInformation();
   bi.setOtherProperty("dateCancelled", new SimpleDateFormat("dd/MM/yyyy").format(new Date()));
   bi.save();
 }
  public static void useInvNumber(String invNumber) {
    Merchant merchant = MallUtil.getCurrentMerchant();
    String dir = merchant.getAbsolutePath() + "/invoiceCodes" + "/" + invNumber;
    try {
      Value val = (Value) SpringUtil.getRepositoryService().getFile(dir, Util.getRemoteUser());
      val.setStatus(40);
      val.save();
    } catch (FileNotFoundException fne) {

    }
  }
  @Override
  public boolean ServerAction(Container container, Map<String, String> request) throws UIException {
    String selectedFile =
        container.getAncestorOfType(EXFinderContainer.class).getAttribute("selectedFile");
    File f = SpringUtil.getRepositoryService().getFile(selectedFile, Util.getRemoteUser());
    File parent = f.getParent();
    f.remove();
    parent.save();

    Container c = container.getAncestorOfType(EXFinder.class).getDescendentByName(selectedFile);
    c.setDisplay(false);
    // SpringUtil.getRepositoryService().delete(SpringUtil.getRepositoryService().getFile(selectedFile, Util.getRemoteUser()), Util.getRemoteUser());

    return true;
  }
 @Override
 public boolean ServerAction(Container container, Map<String, String> request) throws UIException {
   BinaryFile file =
       (BinaryFile)
           container
               .getAncestorOfType(EXMacFinderColumn.class)
               .getDescendentOfType(EXUpload.class)
               .getFile();
   file.makeOwner(Util.getRemoteUser());
   file.putInto(filePath);
   file.getParent().save();
   // SpringUtil.getRepositoryService().update(file, Util.getRemoteUser());
   // SpringUtil.getRepositoryService().saveIn(filePath, file, Util.getRemoteUser());
   return true;
   // parent.openUsing(caller)
 }
 public static String checkInvNumber(String invNumber) {
   Merchant merchant = MallUtil.getCurrentMerchant();
   String dir = merchant.getAbsolutePath() + "/invoiceCodes" + "/" + invNumber;
   try {
     Value val = (Value) SpringUtil.getRepositoryService().getFile(dir, Util.getRemoteUser());
     if (val.getStatus() == 40) {
       return "used";
     } else if (val.getStatus() == File.STATE_PUBLISHED) {
       return "ok";
     } else {
       return "notprinted";
     }
   } catch (FileNotFoundException fne) {
     Order order = getOrder(invNumber);
     if (order != null) {
       return "used";
     } else {
       return "ok";
     }
   }
 }
示例#8
0
  public FileIterator<File> getFiles(FileFilter filter) {

    List<File> result = new ArrayList<File>();

    try {
      if (children.size() > 0) {
        for (File f : children) {
          if (f.getStatus() != File.STATE_DELETED
              && f.canRead()
              && (filter == null || filter.accept(f))) {
            result.add(f);
          }
        }
      }

    } catch (Exception li) {
      if (getAbsolutePath() != null) {
        QueryParameters params =
            new QueryParameters()
                .setEntity(FileImpl.class)
                .addRestriction(Restrictions.eq("parent.absolutePath", getAbsolutePath()));
        List<File> files =
            SpringUtil.getRepositoryService().executeQuery(params, Util.getRemoteUser());
        for (File f : files) {
          if (f.getStatus() != File.STATE_DELETED
              && f.canRead()
              && (filter == null || filter.accept(f))) {
            result.add(f);
          }
        }
      } else {
        throw new RepositoryException(
            new IllegalStateException("illegal state when getting children", li));
      }
    }

    return new SimpleFileIterator(result);
  }
 public static List<Order> loadOrders() {
   List result =
       SpringUtil.getRepositoryService()
           .executeQuery(new QueryParameters().setEntity(Order.class), Util.getRemoteUser());
   return result;
 }
  @Override
  public Container getTabContentAt(TabPanel pane, int index) {

    if (index == 3) {
      Product p =
          (Product)
              SpringUtil.getRepositoryService().getFile(getAttribute("path"), Util.getRemoteUser());
      Container c = new EXContainer("", "div");

      List<Product> sameProvider =
          MallUtil.getMerchant(p.getProvidedBy())
              .getManager()
              .getMyProducts(Product.STATE_PUBLISHED);
      for (int i = 0; i < sameProvider.size(); i++) {

        Product pp = sameProvider.get(i);
        if (pp.getAbsolutePath().equalsIgnoreCase(getAttribute("path"))) continue;
        String url = pp.getImageUrl("");
        if (!StringUtil.isNotEmpty(url)) {
          url = "emimg/detail/img1.png";
        }
        Container cc =
            new EXContainer("sp" + i, "img")
                .setAttribute("src", "emimg/detail/img1.png")
                .setStyle("cursor", "pointer");
        c.addChild(cc.setAttribute("src", url).setAttribute("path", pp.getAbsolutePath()));
      }
      return c.setStyle("min-height", "250px");

    } else if (index == 4) {
      Product p =
          (Product)
              SpringUtil.getRepositoryService().getFile(getAttribute("path"), Util.getRemoteUser());
      Container c = new EXContainer("", "div");

      List<Product> sameProvider =
          MallUtil.getMerchant(p.getProvidedBy())
              .getManager()
              .getMyProducts(Product.STATE_PUBLISHED);
      for (int i = 0; i < sameProvider.size(); i++) {

        Product pp = sameProvider.get(i);
        if (pp.getAbsolutePath().equalsIgnoreCase(getAttribute("path"))) continue;
        String url = pp.getImageUrl("");
        if (!StringUtil.isNotEmpty(url)) {
          url = "emimg/detail/img1.png";
        }
        Container cc =
            new EXContainer("hap" + i, "img")
                .setAttribute("src", "emimg/detail/img1.png")
                .setStyle("cursor", "pointer");
        c.addChild(cc.setAttribute("src", url).setAttribute("path", pp.getAbsolutePath()));
      }
      return c.setStyle("min-height", "250px");
    } else if (index == 0) {
      if (StringUtil.isNotEmpty(getAttribute("path"))) {
        Product p =
            (Product)
                SpringUtil.getRepositoryService()
                    .getFile(getAttribute("path"), Util.getRemoteUser());
        return new EXContainer("summary", "div")
            .setText(p.getSummary())
            .setStyle("min-height", "250px");
      } else {
        return new EXContainer("sd", "div");
      }

    } else if (index == 2) {
      return new EXContainer("", "div")
          .addChild(new EXContainer("sas", "h5").setText("Coming soon"))
          .setStyle("min-height", "250px");
    } else if (index == 1) {
      Product p =
          (Product)
              SpringUtil.getRepositoryService().getFile(getAttribute("path"), Util.getRemoteUser());
      List<KeyValuePair> vnps = p.getCategories();
      EXFieldSet fs = new EXFieldSet("categories", "Specifications", false);
      for (KeyValuePair vk : vnps) fs.addField(vk.getKey(), new EXLabel("", vk.getValue()));

      return new EXContainer("", "div").addChild(fs).setStyle("min-height", "250px");
      // return new EXContainer("sas", "h3").setText("Coming soon");
    } else return null;
  }
  @Override
  public boolean ServerAction(Container container, Map<String, String> request) throws UIException {
    if (container.getName().equals("title")
        || container.getName().equals("image")
        || container.getName().equals("img")) {

      return false;
    }

    if (container.getName().startsWith("sp")) {
      String path = container.getAttribute("path");
      if (StringUtil.isNotEmpty(path) && !path.equalsIgnoreCase("null")) {
        Product p =
            (Product)
                SpringUtil.getRepositoryService()
                    .getFile(container.getAttribute("path"), Util.getRemoteUser());
        setProduct(p);
      }
      return true;
    }

    if (container.getName().startsWith("star")) {
      int index = Integer.parseInt(container.getName().replace("star", "")) + 1;
      Product p =
          (Product)
              SpringUtil.getRepositoryService().getFile(getAttribute("path"), Util.getRemoteUser());
      for (int i = 0; i < index; i++) {
        getChild("star" + i).setStyle("background", "green");
      }

      String u = Util.getRemoteUser();
      if (!StringUtil.isNotEmpty(u)) {
        u = "anonymous";
      }
      Directory votes = (Directory) p.getFile("votes");
      if (votes == null) {
        votes = p.createFile("votes", Directory.class);
      }

      String cur = votes.getProperty(u);

      if (cur == null) {
        cur = "0";
      }
      try {
        Integer.parseInt(cur);

      } catch (Exception e) {
        cur = "0";
      }

      votes.setProperty(u, (Integer.parseInt(cur) + index) + "");

      p.save();
      return true;
    }

    if (container.getName().startsWith("tn")) {
      for (Container c : getChildren()) {
        if (c.getName().startsWith("tn")) {
          c.setStyleClass("uibutton");
        }
      }
      container.setStyleClass("uibutton uibutton_active");
      getChild("image").setAttribute("src", container.getAttribute("src"));
      return true;
    }

    if (container.getName().equals("merchant")) {
      Merchant m = MallUtil.getMerchant(container.getAttribute("merchant"));
      // EXMerchantInfo info = new EXMerchantInfo("");
      EXMerchantCardV2 info = new EXMerchantCardV2("sd", m);
      EXPanel panel = new EXPanel("mm", m.getCompanyName());
      panel.setBody(info);
      // info.setMerchant(m);
      container
          .getAncestorOfType(PopupContainer.class)
          .addPopup(panel.setStyle("z-index", "3000").setStyle("width", "704px"));
      return true;
    }

    if (container.getName().equals("thumbUp")) {
      Product p =
          (Product)
              SpringUtil.getRepositoryService().getFile(getAttribute("path"), Util.getRemoteUser());
      p.thumbUp();
      p.save();
      return true;
    }

    if (container.getName().equals("thumbDown")) {
      Product p =
          (Product)
              SpringUtil.getRepositoryService().getFile(getAttribute("path"), Util.getRemoteUser());
      p.thumbDown();
      p.save();
      return true;
    }

    EXInput in = getDescendentOfType(EXInput.class);
    int value = Integer.parseInt(in.getValue().toString());
    if (container.getName().equals("addQty")) {
      in.setValue((value + 1) + "");
    } else if (container.getName().equals("delQty")) {
      if (value > 0) {
        in.setValue((value - 1) + "");
      }
    } else if (container.getName().equals("addToCart")) {
      if (container.getAncestorOfType(EXMall.class) != null) {
        Product p =
            (Product)
                SpringUtil.getRepositoryService()
                    .getFile(getAttribute("path"), Util.getRemoteUser());
        EXMiniCarts carts = getRoot().getDescendentOfType(EXMiniCarts.class);
        if (carts.getChildren().size() == 0) {
          carts.addChild(
              new EXContainer("totalll", "h4")
                  .addClass("ui-widget-header")
                  .setStyle("margin", "0")
                  .setStyle("width", "100%")
                  .setStyle("text-align", "center"));
        }
        EXMiniCart cart =
            getRoot().getDescendentOfType(EXMiniCarts.class).getMiniCart(p.getProvidedBy());
        if (!cart.getTemplateLocation().endsWith("EXMinicartNG.xhtml")) {
          cart.setTemplateLocation("templates/ng/EXMinicartNG.xhtml");
          cart.getParent().setStyle("float", "right").setStyle("margin-top", "12px");
          cart.addChild(new EXContainer("images", "div").setStyle("height", "20px"));
          cart.removeClass("cart-widget")
              .setStyle("margin", "0")
              .setStyle("padding", "0")
              .setStyle("margin-top", "0");
          cart.addChild(
              new EXContainer("checkout", "a")
                  .addEvent(new CartDetailEvent(), Event.CLICK)
                  .setAttribute("href", "#")
                  .setText("<img src=\"blueprint/images/checkout.png\"></img>"));
        }
        CartItem item = cart.getItem(p.getAbsolutePath());
        if (item == null) {
          cart.getChild("images")
              .addChild(
                  new EXContainer("img", "img")
                      .setStyle("cursor", "pointer")
                      .setAttribute("path", p.getAbsolutePath())
                      .addEvent(this, CLICK)
                      .setStyle("margin", "4px 4px 0px 4px")
                      .setStyle("width", "30px")
                      .setStyle("height", "30px")
                      .setAttribute("src", p.getImageUrl("")));
        }
        CartItem citem = cart.addToCart(p, value, container);
      } else {
        Product p =
            (Product)
                SpringUtil.getRepositoryService()
                    .getFile(getAttribute("path"), Util.getRemoteUser());
        getRoot().getDescendentOfType(EXMiniCart.class).addToCart(p, 1, container);
      }
    } else {
      Product p =
          (Product)
              SpringUtil.getRepositoryService().getFile(getAttribute("path"), Util.getRemoteUser());
      try {
        MallUtil.getCurrentUser().addToFavorite(p.getAbsolutePath());
      } catch (Exception e) {
        e.printStackTrace();
      }
    }
    return true;
  }
  public static void partlyTerminate(Container source) {
    final Order order =
        (Order)
            SpringUtil.getRepositoryService()
                .getFile(source.getAttribute("path"), Util.getRemoteUser());
    BillingInformation bi = order.getBillingInformation();
    final String email = bi.getEmail();

    EXDynaformPanel panel = new EXDynaformPanel("deceased", "Partly terminate on Death");
    panel.setStyle("z-index", "4000");
    source.getAncestorOfType(PopupContainer.class).addPopup(panel);
    Map<String, String> props = order.getBillingInformation().getOtherProperties();

    List<String> dict = new ArrayList<String>();
    for (int i = 1; i <= 6; i++) {
      // "c1surname","c1name"
      String key1 = "c" + i + "surname";
      String key2 = "c" + i + "name";

      if (StringUtil.isNotEmpty(props.get(key1)) || StringUtil.isNotEmpty(props.get(key2))) {
        String val =
            (StringUtil.isNotEmpty(props.get(key1)) ? props.get(key1) + " " : "")
                + (StringUtil.isNotEmpty(props.get(key2)) ? props.get(key2) : "");
        dict.add(val);
      }
    }

    panel.addField("Name of person deceased :", new EXAutoComplete("nameofperson", "", dict));
    panel.addButton(new EXButton("Send", "Send Mail"));
    panel.addButton(new EXButton("cancel", "Cancel"));
    panel
        .getDescendentByName("Send")
        .addEvent(
            new Event() {

              @Override
              public void Success(ClientProxy container, Map<String, String> request)
                  throws UIException {
                // TODO Auto-generated method stub

              }

              @Override
              public boolean ServerAction(Container container, Map<String, String> request)
                  throws UIException {

                String person =
                    container
                        .getAncestorOfType(EXDynaformPanel.class)
                        .getField("nameofperson")
                        .getValue()
                        .toString();

                sendMail(person, email);

                container.getAncestorOfType(EXDynaformPanel.class).remove();

                order.setStatus(21);
                BillingInformation b = order.getBillingInformation();
                b.setOtherProperty(
                    "datePartlyTerminated", new SimpleDateFormat("dd/MM/yyyy").format(new Date()));
                order.save();
                return true;
              }

              @Override
              public void ClientAction(ClientProxy container) {
                container
                    .mask(container.getAncestorOfType(EXDynaformPanel.class))
                    .makeServerRequest(this);
              }
            },
            Event.CLICK);
  }