Example #1
0
  public static com.uslc.pe.jpa.entity.PurchaseOrder createPurchaseOrder(
      int departmentNumber,
      String referenceNumber,
      String shipFrom,
      String shipTo,
      int totalCartons,
      int totalItems,
      List<Object[]> poDetails)
      throws Exception {
    com.uslc.pe.jpa.entity.PurchaseOrder po = null;

    po.setReferenceNumber(referenceNumber);
    po.setShipFrom(shipFrom);
    po.setShipTo(shipTo);
    po.setTotalCartons(totalCartons);
    po.setTotalItems(totalItems);
    po.setDeleted(true);

    po = PurchaseOrderRepo.createPurchaseOrder(po);
    if (po.getId() > 0) {
      List<PurchaseOrderDetail> purchaseOrderDetailList = new ArrayList<PurchaseOrderDetail>();
      int sku = 0;
      for (Object[] ob : poDetails) {
        Upc upc = (Upc) ob[0];
        int qty = Integer.parseInt(String.valueOf(ob[1]));
        int itemsPerCarton = Integer.parseInt(String.valueOf(ob[2]));
        boolean preticketed = Boolean.parseBoolean(String.valueOf(ob[3]));

        PurchaseOrderDetail pod =
            PurchaseOrderDetailRepo.createPurchaseOrderDetail(preticketed, qty, po, upc);
        int cartons = (int) Math.ceil(new Double(totalItems) / new Double(itemsPerCarton));
        List<PackingDetail> packingDetailList = new ArrayList<PackingDetail>();
        for (int i = 0; i < cartons; i++) {
          int itemsInCarton = 0;
          if (qty < itemsPerCarton) {
            itemsInCarton = qty;
          } else {
            itemsInCarton = itemsPerCarton;
          }
          qty = qty - itemsInCarton;

          PackingDetail pd = PackingDetailRepo.createPackingDetail(itemsInCarton, ++sku, pod);
          packingDetailList.add(pd);
        }
        PurchaseOrderDetailRepo.setDeleted(pod, false);
        purchaseOrderDetailList.add(pod);
      }

    } else {
      return null;
    }

    return po;
  }
Example #2
0
 private HashMap<Integer, PackingDetail[]> getPackingDetail() throws Exception {
   if (packingDetails == null) {
     packingDetails = new HashMap<Integer, PackingDetail[]>();
     for (PurchaseOrderDetail pod : getDetails()) {
       PackingDetail[] pds = new PackingDetail[0];
       List<PackingDetail> pdList = PackingDetailRepo.findByPurchaseOrderDetail(pod);
       if (pdList != null) {
         pds = new PackingDetail[pdList.size()];
         for (int i = 0; i < pdList.size(); i++) {
           pds[i] = pdList.get(i);
         }
       }
       packingDetails.put(pod.getId(), pds);
     }
   }
   return packingDetails;
 }