Beispiel #1
0
  private void addDetails(String no, Order order) {
    Details details = order.addNewDetails();

    // query for data and put generate lines in a loop
    Vector<com.order.src.objects.Line> lines = getDetails(no);
    Enumeration<com.order.src.objects.Line> e = lines.elements();

    while (e.hasMoreElements()) {
      com.order.src.objects.Line dLine = e.nextElement();
      Line line = details.addNewLine();

      if (!dLine.getNo().equalsIgnoreCase("")) { // $NON-NLS-1$
        line.setNo((short) Float.valueOf(dLine.getNo()).intValue());
      }
      if (!dLine.getItem().equalsIgnoreCase("")) { // $NON-NLS-1$
        if (dLine.getWarehouse().equalsIgnoreCase(TOR)) {
          line.setItem(dLine.getItem() + S + TOR);
        } else {
          line.setItem(dLine.getItem() + S + I2I);
        }
      }
      if (!dLine.getSerial().equalsIgnoreCase("")) { // $NON-NLS-1$
        line.setSerial(dLine.getSerial());
      }
      if (!dLine.getDescription().equalsIgnoreCase("")) { // $NON-NLS-1$
        line.setDescription(dLine.getDescription());
      }
      if (dLine.getQty() >= 0) {
        line.setQty(dLine.getQty() + ""); // $NON-NLS-1$
      }
      if (dLine.getComment() != null && !dLine.getComment().equalsIgnoreCase("")) { // $NON-NLS-1$
        line.setComment(dLine.getComment());
      }
    }
  }
Beispiel #2
0
  private void createXML(Vector<Header> headers) {
    OrdersDocument ordsDoc = null;

    ordsDoc = OrdersDocument.Factory.newInstance();

    Orders orders = ordsDoc.addNewOrders();

    Enumeration<Header> e = headers.elements();
    while (e.hasMoreElements()) {
      Header header = e.nextElement();

      Order order = orders.addNewOrder();

      noNamespace.OrdersDocument.Orders.Order.Header xHeader = order.addNewHeader();
      if (!header.getNo().equalsIgnoreCase("")) { // $NON-NLS-1$
        xHeader.setNumber(header.getNo());
        if ("WALMART.CA".equalsIgnoreCase(header.getNumber().trim())) {
          xHeader.setNumber(header.getRefNo());
        }
      }
      if (!header.getNumber().equalsIgnoreCase("")) { // $NON-NLS-1$
        xHeader.setRefNo(header.getNumber());
      }
      if (!header.getPoNo().equalsIgnoreCase("")) { // $NON-NLS-1$
        xHeader.setPoNo(header.getPoNo());
      }
      if (!header.getShipOn().equalsIgnoreCase("")) { // $NON-NLS-1$
        // no shipon data
      }
      if (!header.getComment().equalsIgnoreCase("")) { // $NON-NLS-1$
        xHeader.setComment(header.getComment());
      }
      if (!header.getContact().equalsIgnoreCase("")) { // $NON-NLS-1$
        xHeader.setContact(header.getContact());
      }
      if (!header.getShipVia().equalsIgnoreCase("")) { // $NON-NLS-1$
        xHeader.setShipVia(header.getShipVia());
      }
      if (!header.getService().equalsIgnoreCase("")) { // $NON-NLS-1$
        xHeader.setService(header.getService());
      }
      if (!header.getInvoice().equalsIgnoreCase("")) { // $NON-NLS-1$
        xHeader.setInvoice(header.getInvoice());
      }

      com.order.src.objects.SoldTo headerSoldTo = getSoldTo(header.getNo(), header.getNumber());
      // SoldTo Element
      if (headerSoldTo != null) {
        Soldto soldTo = xHeader.addNewSoldto();
        if (!headerSoldTo.getAddress1().equalsIgnoreCase("")) { // $NON-NLS-1$
          soldTo.setAddress1(headerSoldTo.getAddress1());
        }
        if (!headerSoldTo.getAddress2().equalsIgnoreCase("")) { // $NON-NLS-1$
          soldTo.setAddress2(headerSoldTo.getAddress2());
        }
        if (!headerSoldTo.getCity().equalsIgnoreCase("")) { // $NON-NLS-1$
          soldTo.setCity(headerSoldTo.getCity());
        }
        if (!headerSoldTo.getCode().equalsIgnoreCase("")) { // $NON-NLS-1$
          soldTo.setCode(header.getNumber().trim() + "_" + headerSoldTo.getCode()); // $NON-NLS-1$
        }
        if (!headerSoldTo.getContact().equalsIgnoreCase("")) { // $NON-NLS-1$
          soldTo.setContact(headerSoldTo.getContact());
        }
        if (!headerSoldTo.getCountry().equalsIgnoreCase("")) { // $NON-NLS-1$
          soldTo.setCountry(headerSoldTo.getCountry());
        }
        if (!headerSoldTo.getEmail().equalsIgnoreCase("")) { // $NON-NLS-1$
          soldTo.setEmail(headerSoldTo.getEmail());
        }
        if (!headerSoldTo.getFax().equalsIgnoreCase("")) { // $NON-NLS-1$
          soldTo.setFax(headerSoldTo.getFax());
        }
        if (!headerSoldTo.getName().equalsIgnoreCase("")) { // $NON-NLS-1$
          soldTo.setName(headerSoldTo.getName());
        }
        if (!headerSoldTo.getPhone().equalsIgnoreCase("")) { // $NON-NLS-1$
          soldTo.setPhone(headerSoldTo.getPhone());
        }
        if (!headerSoldTo.getPostal().equalsIgnoreCase("")) { // $NON-NLS-1$
          soldTo.setPostal(headerSoldTo.getPostal());
        }
        if (!headerSoldTo.getProvince().equalsIgnoreCase("")) { // $NON-NLS-1$
          soldTo.setProvince(headerSoldTo.getProvince());
        } else {
          soldTo.setProvince("XX"); // $NON-NLS-1$
        }
      }

      com.order.src.objects.ShipTo headerShipTo = getShipTo(header.getNo());
      // SoldTo Element
      if (headerShipTo != null) {
        Shipto shipTo = xHeader.addNewShipto();
        if (!headerShipTo.getAddress1().equalsIgnoreCase("")) { // $NON-NLS-1$
          shipTo.setAddress1(headerShipTo.getAddress1());
        }
        if (!headerShipTo.getAddress2().equalsIgnoreCase("")) { // $NON-NLS-1$
          shipTo.setAddress2(headerShipTo.getAddress2());
        }
        if (!headerShipTo.getCity().equalsIgnoreCase("")) { // $NON-NLS-1$
          shipTo.setCity(headerShipTo.getCity());
        }
        if (!headerShipTo.getCode().equalsIgnoreCase("")) { // $NON-NLS-1$
          shipTo.setCode(header.getNumber().trim() + "_" + headerShipTo.getCode()); // $NON-NLS-1$
        }
        if (!headerShipTo.getContact().equalsIgnoreCase("")) { // $NON-NLS-1$
          shipTo.setContact(headerShipTo.getContact());
        }
        if (!headerShipTo.getCountry().equalsIgnoreCase("")) { // $NON-NLS-1$
          shipTo.setCountry(headerShipTo.getCountry());
        }
        if (!headerShipTo.getEmail().equalsIgnoreCase("")) { // $NON-NLS-1$
          shipTo.setEmail(headerShipTo.getEmail());
        }
        if (!headerShipTo.getFax().equalsIgnoreCase("")) { // $NON-NLS-1$
          shipTo.setFax(headerShipTo.getFax());
        }
        if (!headerShipTo.getName().equalsIgnoreCase("")) { // $NON-NLS-1$
          shipTo.setName(headerShipTo.getName());
        }
        if (!headerShipTo.getPhone().equalsIgnoreCase("")) { // $NON-NLS-1$
          shipTo.setPhone(headerShipTo.getPhone());
        }
        if (!headerShipTo.getPostal().equalsIgnoreCase("")) { // $NON-NLS-1$
          shipTo.setPostal(headerShipTo.getPostal());
        }
        if (!headerShipTo.getProvince().equalsIgnoreCase("")) { // $NON-NLS-1$
          shipTo.setProvince(headerShipTo.getProvince());
        } else {
          shipTo.setProvince("XX"); // $NON-NLS-1$
        }
      }

      // Add Details
      addDetails(header.getNo(), order);
    }

    OrdersDocument ordsDoc_TOR = OrdersDocument.Factory.newInstance();
    Orders orders_TOR = ordsDoc_TOR.addNewOrders();

    OrdersDocument ordsDoc_I2I = OrdersDocument.Factory.newInstance();
    Orders orders_I2I = ordsDoc_I2I.addNewOrders();

    Order[] ordDoc_Order = ordsDoc.getOrders().getOrderArray();
    for (int i = 0; i < ordDoc_Order.length; i++) {
      String item = ordDoc_Order[i].getDetails().getLineArray(0).getItem();
      System.out.println("item: " + item);
      if (item.contains(S + TOR)) {
        // add to TOR orders_TOR
        Order order = orders_TOR.addNewOrder();
        order.set(ordDoc_Order[i]);
        Line[] order_lines = order.getDetails().getLineArray();
        for (int j = 0; j < order_lines.length; j++) {
          String order_item = order_lines[j].getItem();
          System.out.println("  order_item_tor:before: " + order_item);
          order_item = order_item.substring(0, order_item.indexOf(S));
          System.out.println("    order_item_tor:after: " + order_item);
          order_lines[j].setItem(order_item.trim());
        }
      } else {
        Order order = orders_I2I.addNewOrder();
        order.set(ordDoc_Order[i]);
        Line[] order_lines = order.getDetails().getLineArray();
        for (int j = 0; j < order_lines.length; j++) {
          String order_item = order_lines[j].getItem();
          System.out.println("  order_item_i2i:before: " + order_item);
          order_item = order_item.substring(0, order_item.indexOf(S));
          System.out.println("    order_item_i2i:after: " + order_item);
          order_lines[j].setItem(order_item.trim());
        }
      }
    }
    System.out.println("orders tor size " + ordsDoc_TOR.getOrders().getOrderArray().length);
    System.out.println("orders i2i size " + ordsDoc_I2I.getOrders().getOrderArray().length);

    String filename1 = ""; // $NON-NLS-1$
    String filename2 = "";
    DateFormat dateFormat = new SimpleDateFormat("yyyyMMdd_HHmm"); // $NON-NLS-1$
    java.util.Date date = new java.util.Date();
    filename1 =
        "ORD" + TOR + "_" + dateFormat.format(date) + "_orders.xml"; // $NON-NLS-1$ //$NON-NLS-2$
    filename2 =
        "ORD" + I2I + "_" + dateFormat.format(date) + "_orders.xml"; // $NON-NLS-1$ //$NON-NLS-2$

    // System.out.println(ordsDoc.toString());
    System.out.println("XML Generated is Valid TOR: " + ordsDoc_TOR.validate()); // $NON-NLS-1$
    System.out.println("XML Generated is Valid I2I: " + ordsDoc_I2I.validate()); // $NON-NLS-1$
    System.out.println(
        "Writing to File: " + Messages.getString("directory") + filename1); // $NON-NLS-1$
    System.out.println(
        "Writing to File: " + Messages.getString("directory") + filename2); // $NON-NLS-1$
    XmlOptions option = new XmlOptions();
    option.setSavePrettyPrint();
    try {
      ordsDoc_TOR.save(
          new File(Messages.getString("directory") + filename1), option); // $NON-NLS-1$
      ordsDoc_I2I.save(
          new File(Messages.getString("directory") + filename2), option); // $NON-NLS-1$
    } catch (IOException e1) {
      e1.printStackTrace();
    }

    ftpFile(ordsDoc_TOR, filename1, TOR);
    ftpFile(ordsDoc_I2I, filename2, I2I);

    System.out.println("The end"); // $NON-NLS-1$
  }