コード例 #1
0
 public void poComboBoxSelected() {
   try {
     /*
     if(selectedPOType == null || selectedPOType.equalsIgnoreCase("-1")) {
     	selectedPrID = Long.valueOf(-1);
     	throw new ControllerException("¡ÃسÒàÅ×Í¡»ÃÐàÀ·¡ÒèѴ«×éÍ/¨éÒ§");
     }
     */
     // newGR();
     editPO = poController.getPurchaseOrder(selectedPoID);
     if (editPO == null) return;
     // ÊÃéÒ§ PO â´Â copy ¢éÍÁÙÅÁÒ¨Ò¡ PR
     editGR.setPurchaseOrder(editPO);
     editGR.setReason(editPO.getReason());
     editGR.setRecipientName(editPO.getReceiverName());
     GoodsReceiptItem grItem;
     grItemList.clear();
     for (PurchaseOrderItem poItem : editPO.getPurchaseOrderItems()) {
       if (poItem.getRemainQty().doubleValue() > 0) {
         grItem = new GoodsReceiptItem();
         grItem.setGoodsReceipt(editGR);
         grItem.setItemNumber(poItem.getItemNumber());
         grItem.setMaterial(poItem.getMaterial());
         grItem.setOtherMaterial(poItem.getOtherMaterial());
         grItem.setBudgetItem(poItem.getBudgetItem());
         grItem.setReceivedQty(poItem.getRemainQty());
         grItem.setOrderQty(poItem.getRemainQty());
         grItem.setOrderUnitPrice(poItem.getUnitPrice());
         grItem.setReceiveUnit(poItem.getOrderUnit());
         grItem.setUnitPrice(poItem.getUnitPrice());
         grItem.setTotalprice(poItem.getRemainQty().multiply(poItem.getUnitPrice()));
         grItem.setNetPrice(poItem.getRemainQty().multiply(poItem.getUnitPrice()));
         grItem.setAvgPrice(poItem.getUnitPrice());
         grItemList.add(grItem);
       }
     }
   } catch (ControllerException e) {
     FacesUtils.reportError(FacesContext.getCurrentInstance(), e.getMessage(), e.getMessage(), e);
     e.printStackTrace();
   }
 }
コード例 #2
0
  private void recalculate(BigDecimal difference, int itemNumber) {
    ArrayList<GoodsReceiptItem> tempGrItemList = new ArrayList<GoodsReceiptItem>();
    GoodsReceiptItem grItem;

    tempGrItemList.addAll(grItemList);
    grItemList.clear();

    for (GoodsReceiptItem item : tempGrItemList) {
      grItem = new GoodsReceiptItem();
      grItem.setBudgetItem(item.getBudgetItem());
      grItem.setGoodsReceipt(item.getGoodsReceipt());
      grItem.setId(item.getId());
      grItem.setItemNumber(item.getItemNumber());
      grItem.setMaterial(item.getMaterial());
      grItem.setOldReceivedQty(item.getOldReceivedQty());
      grItem.setOrderQty(item.getOrderQty());
      grItem.setOrderUnitPrice(item.getOrderUnitPrice());
      grItem.setOtherMaterial(item.getOtherMaterial());
      grItem.setReceivedQty(item.getReceivedQty());
      grItem.setReceiveUnit(item.getReceiveUnit());
      grItem.setStatus(item.getStatus());
      grItem.setStockMovements(item.getStockMovements());
      grItem.setStorageLocation(item.getStorageLocation());
      grItem.setUnitPrice(item.getUnitPrice());
      grItem.setTotalprice(item.getTotalprice());
      if (item.getItemNumber() == itemNumber) {
        grItem.setDiscountAmount(item.getDiscountAmount().add(difference));
        grItem.setNetPrice(item.getNetPrice().subtract(difference));
        grItem.setAvgPrice(
            (item.getNetPrice()
                .subtract(difference)
                .divide(item.getReceivedQty(), 2, RoundingMode.HALF_UP)));
      } else {
        grItem.setDiscountAmount(item.getDiscountAmount());
        grItem.setNetPrice(item.getNetPrice());
        grItem.setAvgPrice(item.getAvgPrice());
      }
      grItemList.add(grItem);
    }
  }
コード例 #3
0
  public void grTableRowClicked() {
    try {
      editGR = grController.getGoodsReceipt(editGR.getId());
      selectedGRType = editGR.getGrType().getID();
      grItemList.clear();
      // grItemList.addAll(editGR.getGoodsReceiptItems());
      ArrayList<GoodsReceiptItem> grList = new ArrayList<GoodsReceiptItem>();
      grList.addAll(editGR.getGoodsReceiptItems());

      for (GoodsReceiptItem grItem : grList) {
        GoodsReceiptItem item = new GoodsReceiptItem();
        item.setBudgetExpensedAmount(grItem.getBudgetExpensedAmount());
        item.setBudgetItem(grItem.getBudgetItem());
        item.setGoodsReceipt(grItem.getGoodsReceipt());
        item.setId(grItem.getId());
        item.setItemNumber(grItem.getItemNumber());
        item.setMaterial(grItem.getMaterial());
        item.setOldReceivedQty(grItem.getReceivedQty());
        item.setOrderQty(grItem.getOrderQty());
        item.setOrderUnitPrice(grItem.getOrderUnitPrice());
        item.setOtherMaterial(grItem.getOtherMaterial());
        item.setReceivedQty(grItem.getReceivedQty());
        item.setReceiveUnit(grItem.getReceiveUnit());
        item.setStatus(grItem.getStatus());
        item.setStockMovements(grItem.getStockMovements());
        item.setStorageLocation(grItem.getStorageLocation());
        item.setUnitPrice(grItem.getUnitPrice());
        item.setTotalprice(grItem.getTotalprice());
        item.setAvgPrice(grItem.getAvgPrice());
        item.setNetPrice(grItem.getNetPrice());
        item.setDiscountAmount(grItem.getDiscountAmount());
        grItemList.add(item);
      }
      fakeItemNo = grItemList.size() + 1;
      System.out.println(editGR.getTotalPrice());
    } catch (ControllerException e) {
      FacesUtils.reportError(FacesContext.getCurrentInstance(), e.getMessage(), e.getMessage(), e);
      e.printStackTrace();
    }
  }
コード例 #4
0
  public void saveGRItem() {
    try {
      /*editGRItem.setMaterial(selectedMaterial);
      if (selectedMaterial != null ){
      	editGRItem.setReceiveUnit(selectedMaterial.getOrderUnit());
      	editGRItem.setUnitPrice(selectedMaterial.getOrderUnitPrice());
      }*/
      if (editGRItem.getBudgetItem() == null) {
        throw new ControllerException("¡ÃسÒàÅ×Í¡ËÁÇ´§º»ÃÐÁÒ³");
      }
      if (selectedGRType.equalsIgnoreCase(GRType.PO.getID())) {
        if (editGRItem.getReceivedQty().compareTo(editGRItem.getOrderQty()) == 1) {
          editGRItem.setReceivedQty(editGRItem.getOrderQty());
          throw new ControllerException("äÁèÊÒÁÒöÃѺ¢Í§à¡Ô¹¨Ó¹Ç¹·ÕèÊÑ觫×éÍä´é");
        }
        if (!editGRItem.getOrderUnitPrice().equals(zero)) {
          if (editGRItem.getUnitPrice().compareTo(editGRItem.getOrderUnitPrice()) == 1) {
            editGRItem.setUnitPrice(editGRItem.getOrderUnitPrice());
            throw new ControllerException("äÁèÊÒÁÒöãÊèÃÒ¤ÒµèÍ˹èÇÂà¡Ô¹ÃÒ¤Ò·ÕèÊÑ觫×éÍä´é");
          }
        }
      }
      // µÃǨÊͺÇèÒÁÕ¡ÒÃàÅ×Í¡ material ËÃ×Í ãÊè other material ËÃ×ÍäÁè
      if (editGRItem.getMaterial() == null
          && (editGRItem.getOtherMaterial() == null
              || editGRItem.getOtherMaterial().trim().equals(""))) {
        throw new ControllerException("¡ÃسÒàÅ×Í¡ÇÑÊ´Ø·Õèµéͧ¡ÒÃÃѺ");
      }
      // äÁèãËéãÊè·Ñé§ material áÅÐ othermaterial
      if (editGRItem.getMaterial() != null
          && (editGRItem.getOtherMaterial() != null
              && !editGRItem.getOtherMaterial().trim().equals(""))) {
        throw new ControllerException("¡ÃسÒàÅ×Í¡ÇÑÊ´Ø ËÃ×Í ÇÑÊ´ØÍ×è¹æÍÂèÒ§ã´ÍÂèҧ˹Öè§à·èÒ¹Ñé¹");
      }
      // µÃǨÊͺÇèÒÁÕÃÒ¡ÒëéÓËÃ×ÍäÁè
      for (GoodsReceiptItem grItem : grItemList) {
        System.out.println("editPrITem otherMaterial" + editGRItem.getOtherMaterial());
        System.out.println("prITem otherMaterial" + editGRItem.getOtherMaterial());
        if (editGRItem.getItemNumber() != grItem.getItemNumber()) {
          if (editGRItem.getMaterial() != null
              && grItem.getMaterial() != null
              && editGRItem.getMaterial().getId().equals(grItem.getMaterial().getId())) {
            System.out.println("Same material");
            throw new ControllerException(
                "ÇÑÊ´Ø " + editGRItem.getMaterial() + " ÁÕÍÂÙèáÅéÇäÁèÊÒÁÒôÓà¹Ô¹¡ÒõèÍä´é");
          } else if (editGRItem.getOtherMaterial() != null
              && grItem.getOtherMaterial() != null
              && !editGRItem.getOtherMaterial().trim().equals("")
              && !editGRItem.getOtherMaterial().trim().equals("")
              && editGRItem.getOtherMaterial().equals(grItem.getOtherMaterial())) {
            System.out.println("Same othermaterial");
            throw new ControllerException(
                "ÇÑÊ´Ø " + editGRItem.getOtherMaterial() + " ÁÕÍÂÙèáÅéÇäÁèÊÒÁÒôÓà¹Ô¹¡ÒõèÍä´é");
          }
        }
      }
      /*if (storageLocation.equals("-1")){
      	throw new ControllerException("¡ÃسÒàÅ×͡ʶҹ·Õè¨Ñ´à¡çº");
      }*/
      editGRItem.setStorageLocation(StorageLocation.find(storageLocation));
      editGRItem.setTotalprice(editGRItem.getReceivedQty().multiply(editGRItem.getUnitPrice()));

      if (editGRItem.getDiscountAmount().compareTo(zero) != 0) {
        editGRItem.setNetPrice(editGRItem.getTotalprice().subtract(editGRItem.getDiscountAmount()));
        editGRItem.setAvgPrice(
            editGRItem.getNetPrice().divide(editGRItem.getReceivedQty(), 2, RoundingMode.HALF_UP));
      } else {
        editGRItem.setNetPrice(editGRItem.getTotalprice());
        editGRItem.setAvgPrice(editGRItem.getUnitPrice());
      }
      if (isNewGrItem) {
        grItemList.add(editGRItem);
      }
      if ((editGRItem.getOrderQty().compareTo(editGRItem.getReceivedQty()) != 0)
          || (editGRItem.getOrderUnitPrice().compareTo(editGRItem.getUnitPrice()) != 0)) {
        isItemAmountOrPriceChanged = true;
        System.out.println("true");
      } else {
        isItemAmountOrPriceChanged = false;
        System.out.println("false");
      }
      newGRItem();
    } catch (ControllerException e) {
      e.printStackTrace();
      FacesUtils.reportError(FacesContext.getCurrentInstance(), e.getMessage(), e.getMessage(), e);
    }
    /*if (isNewGrItem) {
    	grItemList.add(editGRItem);
    }*/
  }
コード例 #5
0
  public void distributeDiscount() {
    System.out.println("distributed discount");
    BigDecimal sumTotalPrice = new BigDecimal("0.00");
    BigDecimal maxTotalPrice = new BigDecimal("0.00");
    BigDecimal sumOfTotalDiscount = new BigDecimal("0.00");
    BigDecimal difference = new BigDecimal("0.00");
    int itemNumberOfmaxTotalPrice = 0;
    GoodsReceiptItem grItem;
    ArrayList<GoodsReceiptItem> tempGrItemList = new ArrayList<GoodsReceiptItem>();

    tempGrItemList.addAll(grItemList);
    grItemList.clear();

    for (GoodsReceiptItem item : tempGrItemList) {
      if (maxTotalPrice.compareTo(item.getTotalprice()) == -1) {
        maxTotalPrice = item.getTotalprice();
        itemNumberOfmaxTotalPrice = item.getItemNumber();
      }
      sumTotalPrice = sumTotalPrice.add(item.getTotalprice());
    }

    for (GoodsReceiptItem item : tempGrItemList) {
      BigDecimal discountAmount = new BigDecimal("0.00");
      BigDecimal netPrice = new BigDecimal("0.00");
      BigDecimal avgprice = new BigDecimal("0.00");

      discountAmount =
          (item.getTotalprice().divide(sumTotalPrice, 2, RoundingMode.HALF_UP))
              .multiply(editGR.getTotalDiscountAmount());
      netPrice = item.getTotalprice().subtract(discountAmount);
      avgprice = netPrice.divide(item.getReceivedQty(), 2, RoundingMode.HALF_UP);
      sumOfTotalDiscount = sumOfTotalDiscount.add(discountAmount);

      grItem = new GoodsReceiptItem();
      grItem.setBudgetItem(item.getBudgetItem());
      grItem.setGoodsReceipt(item.getGoodsReceipt());
      grItem.setId(item.getId());
      grItem.setItemNumber(item.getItemNumber());
      grItem.setMaterial(item.getMaterial());
      grItem.setOldReceivedQty(item.getOldReceivedQty());
      grItem.setOrderQty(item.getOrderQty());
      grItem.setOrderUnitPrice(item.getOrderUnitPrice());
      grItem.setOtherMaterial(item.getOtherMaterial());
      grItem.setReceivedQty(item.getReceivedQty());
      grItem.setReceiveUnit(item.getReceiveUnit());
      grItem.setStatus(item.getStatus());
      grItem.setStockMovements(item.getStockMovements());
      grItem.setStorageLocation(item.getStorageLocation());
      grItem.setUnitPrice(item.getUnitPrice());
      grItem.setTotalprice(item.getTotalprice());
      grItem.setDiscountAmount(discountAmount);
      grItem.setNetPrice(netPrice);
      grItem.setAvgPrice(avgprice);
      grItemList.add(grItem);
    }

    difference = editGR.getTotalDiscountAmount().subtract(sumOfTotalDiscount);
    if (difference.compareTo(zero) != 0) {
      recalculate(difference, itemNumberOfmaxTotalPrice);
    }
    isItemAmountOrPriceChanged = false;
  }