public void saveGR() { LogManager log = new LogManager(); try { // µÃǨÇèÒµéͧÁÕ¡ÒáÓ˹´ StorageLocation /*for (GoodsReceiptItem grItem : grItemList) { if (grItem.getStorageLocation()== null ){ throw new ControllerException("¡ÃسÒÃкØʶҹ·Õè¨Ñ´à¡çºãËé¡Ñº·Ø¡ÃÒ¡Ò÷Õèµéͧ¡ÒÃÃѺà¢éÒ¤Åѧ"); } }*/ if (isItemAmountOrPriceChanged == true && !editGR.getTotalDiscountAmount().equals(zero)) { throw new ControllerException("¡Ãسҡ´»ØèÁ¡ÃШÒÂÊèǹŴÍÕ¡¤ÃÑé§"); } editGR.setGoodsReceiptItems(grItemList); if (editGR.getId() == null) { editGR.setBudgetYear(budgetYear); editGR = grController.saveGoodsReceipt(editGR); log.recordCreateGr(editGR.getFormattedGrNumber(), editGR.getTotalPrice()); } else { editGR = grController.saveGoodsReceipt(editGR); log.recordUpdateGr(editGR.getFormattedGrNumber(), editGR.getTotalPrice()); } createPOSelectItemList(); listGR(); grTableRowClicked(); isGrSaved = true; } catch (ControllerException e) { FacesUtils.reportError(FacesContext.getCurrentInstance(), e.getMessage(), e.getMessage(), e); e.printStackTrace(); } }
public void closeGR() { LogManager log = new LogManager(); try { if (editGR.getId() == null) { throw new ControllerException("äÁèÊÒÁÒö»Ô´ãºÃѺ·ÕèÂѧäÁèä´éºÑ¹·Ö¡ä´é"); } log.recordCloseGr(editGR.getFormattedGrNumber()); editGR = grController.closeGoodsReceipt(editGR); createPOSelectItemList(); listGR(); grTableRowClicked(); } catch (ControllerException e) { FacesUtils.reportError(FacesContext.getCurrentInstance(), e.getMessage(), e.getMessage(), e); e.printStackTrace(); } }
public boolean isGrEditable() { return budget != null && budget.isAvailable() && editGR != null && editGR.isEditable() && !selectedGRType.equals("-1"); }
public void newGR() { editGR = new GoodsReceipt(); editGR.setPostingDate(CalendarUtils.getDateTimeInstance().getTime()); editGR.setWarehouseCode(warehouseCode); selectedMaterialGroupID = Long.valueOf(-1); selectedMaterialID = Long.valueOf(-1); selectedPoID = Long.valueOf(-1); storageLocation = "-1"; // selectedGRType = GRType.PO.getID(); selectedGRType = "-1"; grItemList.clear(); fakeItemNo = 0; newGRItem(); isGrSaved = false; selectedBudgetItem = null; selectedBudgetItemID = Long.valueOf(-1); }
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(); } }
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(); } }
public void printGR() { LogManager log = new LogManager(); try { JasperReport report = null; report = (JasperReport) JRLoader.loadObject(this.getClass().getResource("/welfare/reports/grForm.jasper")); // report = (JasperReport)JRLoader.loadObject("D:/grForm.jasper"); ArrayList<PurchasingGRReportData> grReportList = new ArrayList<PurchasingGRReportData>(); for (GoodsReceiptItem goodsReceiptItem : grItemList) { PurchasingGRReportData grReport = new PurchasingGRReportData(); grReport.setItemNo(goodsReceiptItem.getItemNumber()); grReport.setOrderQty(goodsReceiptItem.getOrderQty()); grReport.setReceivedQty(goodsReceiptItem.getReceivedQty()); grReport.setUnit(goodsReceiptItem.getReceiveUnit()); grReport.setUnitPrice(goodsReceiptItem.getUnitPrice()); String material = ""; if (goodsReceiptItem.getMaterial() == null) { material = goodsReceiptItem.getOtherMaterial(); } else { material = goodsReceiptItem.getMaterial().getDescription(); } grReport.setMaterial(material); grReportList.add(grReport); } vendor = poController.getVendorForReport(editGR.getPurchaseOrder().getId()); String text = ""; if (editGR.getStatus().toString().equals("GR-FULL")) { text = "ÃѺàµçÁ¨Ó¹Ç¹"; } if (editGR.getStatus().toString().equals("GR-PAR")) { text = "ÃѺäÁèàµçÁ¨Ó¹Ç¹"; } HashMap grReportHashMap = new HashMap(); grReportHashMap.put("grNo", editGR.getFormattedGrNumber()); grReportHashMap.put("receivedDate", editGR.getReceivedDate()); grReportHashMap.put("poNo", editGR.getPurchaseOrder().getFormattedPoNumber()); grReportHashMap.put("status", editGR.getStatus().toString()); grReportHashMap.put("invoiceNo", editGR.getInvoiceNumber()); if (vendor != null) { grReportHashMap.put("vendor", vendor.getName()); } else { grReportHashMap.put("vendor", editGR.getPurchaseOrder().getOtherVendor()); } grReportHashMap.put("text", text); grReportHashMap.put("recipientName", editGR.getRecipientName()); grReportHashMap.put("entryName", editGR.getEntryName()); grReportHashMap.put("recipientPos", editGR.getRecipientPos()); grReportHashMap.put("entryPos", editGR.getEntryPos()); grReportHashMap.put("totalPrice", editGR.getTotalPrice()); grReportHashMap.put("totalDiscount", editGR.getTotalDiscountAmount()); grReportHashMap.put("LOGO", this.getClass().getResource("/welfare/reports/logo.gif")); grReportHashMap.put("logo", this.getClass().getResource("/welfare/reports/aerologo.png")); JasperPrint jasperPrint = JasperFillManager.fillReport( report, grReportHashMap, new JRBeanCollectionDataSource(grReportList)); // JasperExportManager.exportReportToPdfFile(jasperPrint,"D:/testGR.pdf"); byte[] bytes = JasperExportManager.exportReportToPdf(jasperPrint); ReportUtils.displayPdfReport(bytes); log.recordPrintGr(editGR.getFormattedGrNumber()); } catch (JRException e) { // TODO: handle exception e.printStackTrace(); e.getMessage(); } catch (ControllerException e) { FacesUtils.reportError(FacesContext.getCurrentInstance(), e.getMessage(), e.getMessage(), e); e.printStackTrace(); } catch (IOException e) { // TODO: handle exception e.printStackTrace(); } }
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; }
public void grTypeComboBoxSelected() { editGR.setGrType(GRType.find(selectedGRType)); }
public boolean isItemDiscountable() { return editGR.getTotalDiscountAmount().compareTo(zero) == 0; }
public boolean isGrCreatable() { return editGR != null && editGR.getId() != null; }
public boolean isGrClosable() { return isGrEditable() && editGR.getId() != null; }
public boolean isGrPrintable() { return editGR != null && editGR.getId() != null && !(editGR.getStatus().equals(GRStatus.CLOSED) || editGR.getStatus().equals(GRStatus.DELETED)); }