List of usage examples for java.math BigDecimal toString
@Override
public String toString()
From source file:com.selfsoft.business.service.impl.TbFixEntrustServiceImpl.java
public void printTbFixEntrustTemplateBlank(OutputStream os, String tpl, Long tbFixEntrustId) { try {/*from w w w .j a va 2s . c om*/ TbFixEntrust tbFixEntrust = this.findById(tbFixEntrustId); TbCustomer tbCustomer = tbCustomerService.findById(tbFixEntrust.getTbCustomer().getId()); TbCarInfo tbCarInfo = tbCarInfoService.findById(tbFixEntrust.getTbCarInfo().getId()); List<TbFixEntrustContent> tbFixEntrustContentList = tbFixEntrustContentService .findTbFixEnTrustContentListByTbFixEntrustId(tbFixEntrustId); /* * List<TbMaintainPartContent> maintainList = * tbMaintainPartContentService * .getViewEntrustMaintianContent(tbFixEntrustId); * * * List<TmStockOutDetVo> solePartList = * tmStockOutService.getSellByEntrustCode * (tbFixEntrust.getEntrustCode()); */ /** * ?? */ List<TbMaintianVo> maintianvos = tbMaintainPartContentService .getTbMaintianDetailVosByEntrustId(tbFixEntrust.getId(), Constants.BALANCE_ALL); /** * ? */ List<TmStockOutDetVo> tmStockOutDetVos = tmStockOutService .getSellDetailByEntrustCode(tbFixEntrust.getEntrustCode(), Constants.BALANCE_ALL); /** * ?? */ List<TbMaintianVo> partAll = new ArrayList<TbMaintianVo>(); if (null != maintianvos && maintianvos.size() > 0) { for (TbMaintianVo tbMaintianVo : maintianvos) { partAll.add(tbMaintianVo); } } if (null != tmStockOutDetVos && tmStockOutDetVos.size() > 0) { for (TmStockOutDetVo tmStockOutDetVo : tmStockOutDetVos) { TbMaintianVo tbMaintianVo = new TbMaintianVo(); tbMaintianVo.setPartId(tmStockOutDetVo.getPartinfoId()); tbMaintianVo.setHouseName(tmStockOutDetVo.getHouseName()); tbMaintianVo.setPartCode(tmStockOutDetVo.getPartCode()); tbMaintianVo.setPartName(tmStockOutDetVo.getPartName()); tbMaintianVo.setUnitName(tmStockOutDetVo.getUnitName()); tbMaintianVo.setPrice(tmStockOutDetVo.getPrice()); tbMaintianVo.setPartQuantity(tmStockOutDetVo.getQuantity()); tbMaintianVo.setTotal(tmStockOutDetVo.getTotal()); tbMaintianVo.setIsFree(tmStockOutDetVo.getIsFree()); tbMaintianVo.setProjectType(tmStockOutDetVo.getProjectType()); tbMaintianVo.setZl(tmStockOutDetVo.getZl()); tbMaintianVo.setXmlx(tmStockOutDetVo.getXmlx()); partAll.add(tbMaintianVo); } } int fixSize = (tbFixEntrustContentList == null ? 0 : tbFixEntrustContentList.size()); int maintainSize = (maintianvos == null ? 0 : maintianvos.size()); int solePartSize = (tmStockOutDetVos == null ? 0 : tmStockOutDetVos.size()); int partAllSize = (partAll == null ? 0 : partAll.size()); HSSFWorkbook workbook = new HSSFWorkbook(this.getClass().getResourceAsStream(tpl)); HSSFSheet sheet = workbook.getSheetAt(0); HSSFCellStyle style = workbook.createCellStyle(); style.setWrapText(true); style.setAlignment(HSSFCellStyle.ALIGN_LEFT); style.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER); HSSFFont font = workbook.createFont(); font.setFontName(""); font.setFontHeightInPoints((short) 9); // style.setFont(font); HSSFCellStyle style11 = workbook.createCellStyle(); style11.setWrapText(true); style11.setAlignment(HSSFCellStyle.ALIGN_LEFT); style11.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER); HSSFFont font11 = workbook.createFont(); font11.setFontName(""); font11.setFontHeightInPoints((short) 11); // style11.setFont(font11); HSSFCellStyle style10 = workbook.createCellStyle(); style10.setWrapText(true); style10.setAlignment(HSSFCellStyle.ALIGN_LEFT); style10.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER); HSSFFont font10 = workbook.createFont(); font10.setFontName(""); font10.setFontHeightInPoints((short) 10); // style10.setFont(font10); HSSFRow row = null; HSSFCell cell = null; row = sheet.getRow(10); cell = row.getCell(0); String entrustCode = tbFixEntrust.getEntrustCode(); String[] es = entrustCode.split("-"); String newCode = "RO" + es[0].substring(2, 6) + es[1]; // cell.setCellValue(tbFixEntrust.getEntrustCode()); cell.setCellValue(newCode); row = sheet.getRow(10); cell = row.getCell(8); cell.setCellValue(tbCarInfo.getPurchaseDate() == null ? "" : CommonMethod.parseDateToString(tbCarInfo.getPurchaseDate(), "yyyy-MM-dd")); row = sheet.getRow(10); cell = row.getCell(14); cell.setCellValue( tbFixEntrust.getTmUser().getUserRealName() == null ? tbFixEntrust.getTmUser().getUserName() : tbFixEntrust.getTmUser().getUserRealName()); row = sheet.getRow(10); cell = row.getCell(19); cell.setCellValue(tbCarInfo.getLicenseCode()); row = sheet.getRow(10); cell = row.getCell(27); // cell.setCellStyle(style); cell.setCellValue(tbCarInfo.getTmCarModelType().getModelName()); row = sheet.getRow(10); cell = row.getCell(32); cell.setCellValue( tbFixEntrust.getEnterStationKilo() == null ? "" : new BigDecimal(tbFixEntrust.getEnterStationKilo().toString()) .divide(new BigDecimal("1.00"), 0, BigDecimal.ROUND_HALF_UP).toString() + " Km"); row = sheet.getRow(10); cell = row.getCell(41); cell.setCellValue(tbCarInfo.getColor() == null ? "" : tbCarInfo.getColor().toString()); row = sheet.getRow(10); cell = row.getCell(45); cell.setCellValue(tbFixEntrust.getFixDate() == null ? "" : CommonMethod.parseDateToString(tbFixEntrust.getFixDate(), Constants.TIMEFORMATOFMINUTE)); row = sheet.getRow(15); cell = row.getCell(0); cell.setCellValue(tbCustomer.getCustomerName() == null ? "" : tbCustomer.getContractPerson()); row = sheet.getRow(15); cell = row.getCell(8); cell.setCellValue(tbCustomer.getTelephone() == null ? "" : tbCustomer.getTelephone()); row = sheet.getRow(15); cell = row.getCell(14); cell.setCellValue(tbCustomer.getPhone() == null ? "" : tbCustomer.getPhone()); row = sheet.getRow(15); cell = row.getCell(20); cell.setCellValue(tbCarInfo.getChassisCode() == null ? "" : tbCarInfo.getChassisCode()); row = sheet.getRow(15); cell = row.getCell(32); // cell.setCellStyle(style); cell.setCellValue(tbCarInfo.getEngineCode() == null ? "" : tbCarInfo.getEngineCode()); row = sheet.getRow(15); cell = row.getCell(45); // cell.setCellStyle(style); cell.setCellValue(tbFixEntrust.getEstimateDate() == null ? "" : CommonMethod.parseDateToString(tbFixEntrust.getEstimateDate(), Constants.TIMEFORMATOFMINUTE)); row = sheet.getRow(18); cell = row.getCell(8); cell.setCellValue(tbCustomer.getCustomerName() == null ? "" : tbCustomer.getCustomerName()); row = sheet.getRow(20); cell = row.getCell(8); // cell.setCellStyle(style); cell.setCellValue(tbCustomer.getAddress() == null ? "" : tbCustomer.getAddress()); row = sheet.getRow(25); cell = row.getCell(8); cell.setCellValue(tbCustomer.getZipCode() == null ? "" : tbCustomer.getZipCode()); row = sheet.getRow(20); cell = row.getCell(23); // cell.setCellStyle(style); cell.setCellValue((tbFixEntrust.getWrongDescribe() == null || "".equals(tbFixEntrust.getWrongDescribe()) ? "" : tbFixEntrust.getWrongDescribe() + ";") + (tbFixEntrust.getBeforeFixState() == null || "".equals(tbFixEntrust.getBeforeFixState()) ? "" : tbFixEntrust.getBeforeFixState() + ";")); Double fixCount = tbFixEntrustContentService.countTbFixEnTrustContentByTbFixEntrustId(tbFixEntrustId); row = sheet.getRow(70); cell = row.getCell(32); // cell.setCellStyle(style); cell.setCellValue(new BigDecimal(fixCount).divide(new BigDecimal("1.00"), 2, BigDecimal.ROUND_HALF_UP) .toString()); row = sheet.getRow(70); cell = row.getCell(48); // cell.setCellStyle(style); cell.setCellValue("0.00"); BigDecimal partPriceAll = new BigDecimal("0.00"); if (partAllSize > 0) { for (int i = 0; i < partAllSize; i++) { TbMaintianVo tbMaintianVo = partAll.get(i); BigDecimal total = new BigDecimal(tbMaintianVo.getPrice()) .multiply(new BigDecimal(tbMaintianVo.getPartQuantity())); partPriceAll = partPriceAll.add(total); } } row = sheet.getRow(73); cell = row.getCell(34); // cell.setCellStyle(style); cell.setCellValue(partPriceAll.divide(new BigDecimal("1.00"), 2, BigDecimal.ROUND_HALF_UP).toString()); BigDecimal total = new BigDecimal(fixCount).add(partPriceAll).divide(new BigDecimal("1.00"), 2, BigDecimal.ROUND_HALF_UP); row = sheet.getRow(76); cell = row.getCell(35); // cell.setCellStyle(style); cell.setCellValue(total.toString()); int page = 1; if (fixSize / 5 >= (maintainSize + solePartSize) / 13) { page = fixSize / 5; } else { page = (maintainSize + solePartSize) / 13; } for (int i = 0; i < page; i++) { int p = 0; int k = 0; HSSFSheet sheetClone = workbook.cloneSheet(0); if (fixSize > 5) { int printFixSize = (fixSize > (i + 2) * 5 ? (i + 2) * 5 : fixSize); for (int j = 5 * (i + 1); j < printFixSize; j++) { TbFixEntrustContent content = tbFixEntrustContentList.get(j); List<TbFixShare> tbFixShareList = tbFixShareService .findTbFixShareListByTbFixEntrustContentId(content.getId()); String fixPersons = ""; if (null != tbFixShareList && tbFixShareList.size() > 0) { for (TbFixShare tbFixShare : tbFixShareList) { if (null != tbFixShare.getTmUser()) { TmUser tmUser = tmUserService.findById(tbFixShare.getTmUser().getId()); fixPersons += (tmUser.getUserRealName() == null || "".equals(tmUser.getUserRealName()) ? tmUser.getUserName() : tmUser.getUserRealName()) + " "; } } } row = sheetClone.getRow(31 + p * 6); cell = row.getCell(0); // cell.setCellStyle(style11); cell.setCellValue(content.getStationCode() + " " + content.getStationName()); cell = row.getCell(20); // cell.setCellStyle(style11); cell.setCellValue(content.getWxlx() == null ? "" : content.getWxlx()); cell = row.getCell(26); // cell.setCellStyle(style11); cell.setCellValue(fixPersons); p++; } } if (partAllSize > 13) { int prinPartSize = (partAllSize > (i + 2) * 13 ? (i + 2) * 13 : partAllSize); for (int j = 13 * (i + 1); j < prinPartSize; j++) { TbMaintianVo t = partAll.get(j); row = sheetClone.getRow(31 + k * 3); cell = row.getCell(32); // cell.setCellStyle(style10); cell.setCellValue(t.getPartName()); cell = row.getCell(40); // cell.setCellStyle(style10); cell.setCellValue(new BigDecimal(t.getPartQuantity()) .divide(new BigDecimal("1.00"), 2, BigDecimal.ROUND_HALF_UP).toString()); cell = row.getCell(44); // cell.setCellStyle(style10); cell.setCellValue(new BigDecimal(t.getPrice()) .divide(new BigDecimal("1.00"), 2, BigDecimal.ROUND_HALF_UP).toString()); k++; } } } if (fixSize > 0) { int printFixSize = (fixSize > 5 ? 5 : fixSize); for (int j = 0; j < printFixSize; j++) { TbFixEntrustContent content = tbFixEntrustContentList.get(j); List<TbFixShare> tbFixShareList = tbFixShareService .findTbFixShareListByTbFixEntrustContentId(content.getId()); String fixPersons = ""; if (null != tbFixShareList && tbFixShareList.size() > 0) { for (TbFixShare tbFixShare : tbFixShareList) { if (null != tbFixShare.getTmUser()) { TmUser tmUser = tmUserService.findById(tbFixShare.getTmUser().getId()); fixPersons += (tmUser.getUserRealName() == null || "".equals(tmUser.getUserRealName()) ? tmUser.getUserName() : tmUser.getUserRealName()) + " "; } } } row = sheet.getRow(31 + j * 6); cell = row.getCell(0); // cell.setCellStyle(style11); cell.setCellValue(content.getStationCode() + " " + content.getStationName()); cell = row.getCell(20); // cell.setCellStyle(style11); cell.setCellValue(content.getWxlx() == null ? "" : content.getWxlx()); cell = row.getCell(26); // cell.setCellStyle(style11); cell.setCellValue(fixPersons); } } if (partAllSize > 0) { int printPartSize = (partAllSize > 13 ? 13 : partAllSize); for (int j = 0; j < printPartSize; j++) { TbMaintianVo t = partAll.get(j); row = sheet.getRow(31 + j * 3); cell = row.getCell(32); // cell.setCellStyle(style10); cell.setCellValue(t.getPartName()); cell = row.getCell(40); // cell.setCellStyle(style10); cell.setCellValue(new BigDecimal(t.getPartQuantity()) .divide(new BigDecimal("1.00"), 2, BigDecimal.ROUND_HALF_UP).toString()); cell = row.getCell(44); // cell.setCellStyle(style10); cell.setCellValue(new BigDecimal(t.getPrice()) .divide(new BigDecimal("1.00"), 2, BigDecimal.ROUND_HALF_UP).toString()); } } workbook.write(os); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } }
From source file:com.selfsoft.business.service.impl.TbFixEntrustServiceImpl.java
public void printTbFixEntrustTemplateBlankXTL(OutputStream os, String tpl, Long tbFixEntrustId) { try {/*from w ww .ja va2 s.c om*/ TbFixEntrust tbFixEntrust = this.findById(tbFixEntrustId); TbCustomer tbCustomer = tbCustomerService.findById(tbFixEntrust.getTbCustomer().getId()); TbCarInfo tbCarInfo = tbCarInfoService.findById(tbFixEntrust.getTbCarInfo().getId()); List<TbFixEntrustContent> tbFixEntrustContentList = tbFixEntrustContentService .findTbFixEnTrustContentListByTbFixEntrustId(tbFixEntrustId); // ?? TmCompany tmCompany = tmCompanyService.acquireUniqueTmCompany(); /* * List<TbMaintainPartContent> maintainList = * tbMaintainPartContentService * .getViewEntrustMaintianContent(tbFixEntrustId); * * * List<TmStockOutDetVo> solePartList = * tmStockOutService.getSellByEntrustCode * (tbFixEntrust.getEntrustCode()); */ /** * ?? */ List<TbMaintianVo> maintianvos = tbMaintainPartContentService .getTbMaintianDetailVosByEntrustId(tbFixEntrust.getId(), Constants.BALANCE_ALL); /** * ? */ List<TmStockOutDetVo> tmStockOutDetVos = tmStockOutService .getSellDetailByEntrustCode(tbFixEntrust.getEntrustCode(), Constants.BALANCE_ALL); /** * ?? */ List<TbMaintianVo> partAll = new ArrayList<TbMaintianVo>(); if (null != maintianvos && maintianvos.size() > 0) { for (TbMaintianVo tbMaintianVo : maintianvos) { partAll.add(tbMaintianVo); } } if (null != tmStockOutDetVos && tmStockOutDetVos.size() > 0) { for (TmStockOutDetVo tmStockOutDetVo : tmStockOutDetVos) { TbMaintianVo tbMaintianVo = new TbMaintianVo(); tbMaintianVo.setPartId(tmStockOutDetVo.getPartinfoId()); tbMaintianVo.setHouseName(tmStockOutDetVo.getHouseName()); tbMaintianVo.setPartCode(tmStockOutDetVo.getPartCode()); tbMaintianVo.setPartName(tmStockOutDetVo.getPartName()); tbMaintianVo.setUnitName(tmStockOutDetVo.getUnitName()); tbMaintianVo.setPrice(tmStockOutDetVo.getPrice()); tbMaintianVo.setPartQuantity(tmStockOutDetVo.getQuantity()); tbMaintianVo.setTotal(tmStockOutDetVo.getTotal()); tbMaintianVo.setIsFree(tmStockOutDetVo.getIsFree()); tbMaintianVo.setProjectType(tmStockOutDetVo.getProjectType()); tbMaintianVo.setZl(tmStockOutDetVo.getZl()); tbMaintianVo.setXmlx(tmStockOutDetVo.getXmlx()); partAll.add(tbMaintianVo); } } int fixSize = (tbFixEntrustContentList == null ? 0 : tbFixEntrustContentList.size()); int maintainSize = (maintianvos == null ? 0 : maintianvos.size()); int solePartSize = (tmStockOutDetVos == null ? 0 : tmStockOutDetVos.size()); int partAllSize = (partAll == null ? 0 : partAll.size()); int pz = (fixSize / 8 > partAllSize / 12 ? (fixSize / 8 + 1) : (partAllSize / 12 + 1)); HSSFWorkbook workbook = new HSSFWorkbook(this.getClass().getResourceAsStream(tpl)); HSSFSheet sheet = workbook.getSheetAt(0); HSSFCellStyle style = workbook.createCellStyle(); style.setWrapText(true); style.setAlignment(HSSFCellStyle.ALIGN_LEFT); style.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER); HSSFFont font = workbook.createFont(); font.setFontName(""); font.setFontHeightInPoints((short) 9); style.setFont(font); HSSFCellStyle style10_5 = workbook.createCellStyle(); style10_5.setWrapText(true); style10_5.setAlignment(HSSFCellStyle.ALIGN_LEFT); style10_5.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER); HSSFFont font10_5 = workbook.createFont(); font10_5.setFontName(""); font10_5.setFontHeightInPoints((short) 11); style10_5.setFont(font10_5); HSSFRow row = null; HSSFCell cell = null; row = sheet.getRow(3); cell = row.getCell(0); cell.setCellValue(" ??:" + "?" + " (?:70691M) ?:" + tmCompany.getCompanyAddress() + " ?: " + (tmCompany.getCompanyPhone() == null ? "" : tmCompany.getCompanyPhone())); row = sheet.getRow(0); cell = row.getCell(40); // cell.setCellStyle(style); cell.setCellValue("*?:" + tbCustomer.getCustomerCode() + "\n" + "??:"); row = sheet.getRow(6); cell = row.getCell(4); cell.setCellValue(tbCustomer.getCustomerName() == null ? "" : tbCustomer.getCustomerName()); row = sheet.getRow(6); cell = row.getCell(24); // cell.setCellStyle(style); cell.setCellValue(tbCustomer.getAddress() == null ? "" : tbCustomer.getAddress()); row = sheet.getRow(6); cell = row.getCell(41); cell.setCellValue(tbCustomer.getContractPerson() == null ? "" : tbCustomer.getContractPerson()); row = sheet.getRow(8); cell = row.getCell(41); cell.setCellValue(tbCustomer.getTelephone() == null ? "" : tbCustomer.getTelephone()); row = sheet.getRow(8); cell = row.getCell(4); cell.setCellValue(tbCustomer.getTelephone() == null ? "" : tbCustomer.getTelephone()); row = sheet.getRow(12); cell = row.getCell(0); String entrustCode = tbFixEntrust.getEntrustCode(); String[] es = entrustCode.split("-"); String newCode = "RO" + es[0].substring(2, 6) + es[1]; cell.setCellValue(/* tbFixEntrust.getEntrustCode() */newCode); row = sheet.getRow(12); cell = row.getCell(9); cell.setCellValue(CommonMethod.parseDateToString(tbFixEntrust.getFixDate(), "yyyy-MM-dd HH:mm")); row = sheet.getRow(12); cell = row.getCell(18); cell.setCellValue(tbCarInfo.getLicenseCode()); row = sheet.getRow(12); cell = row.getCell(26); // cell.setCellStyle(style); cell.setCellValue(tbCarInfo.getTmCarModelType().getModelName()); row = sheet.getRow(12); cell = row.getCell(34); cell.setCellValue(tbCarInfo.getChassisCode()); // ? row = sheet.getRow(16); cell = row.getCell(0); cell.setCellValue(tbFixEntrust.getBjzzh() == null ? "" : tbFixEntrust.getBjzzh()); row = sheet.getRow(16); cell = row.getCell(9); cell.setCellValue(CommonMethod.parseDateToString(tbCarInfo.getPurchaseDate(), "yyyy-MM-dd")); // ? row = sheet.getRow(16); cell = row.getCell(18); cell.setCellValue(tbFixEntrust.getSbrq() == null ? "" : tbFixEntrust.getSbrq()); row = sheet.getRow(16); cell = row.getCell(26); cell.setCellValue(tbFixEntrust.getEnterStationKilo() == null ? "" : new BigDecimal(tbFixEntrust.getEnterStationKilo().toString()) .divide(new BigDecimal("1.00"), 0, BigDecimal.ROUND_HALF_UP).toString()); row = sheet.getRow(16); cell = row.getCell(34); cell.setCellValue(CommonMethod.parseDateToString(tbFixEntrust.getEstimateDate(), "yyyy-MM-dd HH:mm")); Double fixCount = tbFixEntrustContentService.countTbFixEnTrustContentByTbFixEntrustId(tbFixEntrustId); row = sheet.getRow(75); cell = row.getCell(30); cell.setCellValue(new BigDecimal(fixCount).divide(new BigDecimal("1.00"), 2, BigDecimal.ROUND_HALF_UP) .toString()); BigDecimal partPriceAll = new BigDecimal("0.00"); if (partAllSize > 0) { for (int i = 0; i < partAllSize; i++) { TbMaintianVo tbMaintianVo = partAll.get(i); BigDecimal total = new BigDecimal(tbMaintianVo.getPrice()) .multiply(new BigDecimal(tbMaintianVo.getPartQuantity())); partPriceAll = partPriceAll.add(total); } } row = sheet.getRow(77); cell = row.getCell(30); cell.setCellValue(partPriceAll.divide(new BigDecimal("1.00"), 2, BigDecimal.ROUND_HALF_UP).toString()); BigDecimal total = new BigDecimal(fixCount).add(partPriceAll).divide(new BigDecimal("1.00"), 2, BigDecimal.ROUND_HALF_UP); row = sheet.getRow(81); cell = row.getCell(30); cell.setCellValue(total.toString()); row = sheet.getRow(79); cell = row.getCell(30); cell.setCellValue("0.00"); row = sheet.getRow(89); cell = row.getCell(6); cell.setCellValue("1"); row = sheet.getRow(89); cell = row.getCell(1); cell.setCellValue(pz + ""); int page = 1; if (fixSize / 8 >= (maintainSize + solePartSize) / 12) { page = fixSize / 8; } else { page = (maintainSize + solePartSize) / 12; } for (int i = 0; i < page; i++) { int p = 0; int k = 0; HSSFSheet sheetClone = workbook.cloneSheet(0); row = sheetClone.getRow(89); cell = row.getCell(1); cell.setCellValue((i + 1) + ""); row = sheetClone.getRow(89); cell = row.getCell(6); cell.setCellValue(pz + ""); if (fixSize > 8) { int printFixSize = (fixSize > (i + 2) * 8 ? (i + 2) * 8 : fixSize); for (int j = 8 * (i + 1); j < printFixSize; j++) { TbFixEntrustContent content = tbFixEntrustContentList.get(j); List<TbFixShare> tbFixShareList = tbFixShareService .findTbFixShareListByTbFixEntrustContentId(content.getId()); String fixPersons = ""; String workTypes = ""; if (null != tbFixShareList && tbFixShareList.size() > 0) { for (TbFixShare tbFixShare : tbFixShareList) { if (null != tbFixShare.getTmUser()) { TmUser tmUser = tmUserService.findById(tbFixShare.getTmUser().getId()); fixPersons += (tmUser.getUserRealName() == null || "".equals(tmUser.getUserRealName()) ? tmUser.getUserName() : tmUser.getUserRealName()) + " "; workTypes += (tmUser.getTmWorkType() == null ? "" : tmUser.getTmWorkType().getWorkName()) + " "; } } } row = sheetClone.getRow(23 + p * 2); cell = row.getCell(2); // cell.setCellStyle(style10_5); cell.setCellValue(content.getStationName()); cell = row.getCell(20); // cell.setCellStyle(style10_5); cell.setCellValue(new BigDecimal(content.getFixHour()) .divide(new BigDecimal("1.00"), 2, BigDecimal.ROUND_HALF_UP).toString()); cell = row.getCell(24); // cell.setCellStyle(style10_5); cell.setCellValue(new BigDecimal(content.getWorkingHourPrice()) .divide(new BigDecimal("1.00"), 2, BigDecimal.ROUND_HALF_UP).toString()); cell = row.getCell(28); // cell.setCellStyle(style10_5); cell.setCellValue(new BigDecimal(content.getFixHourAll()) .divide(new BigDecimal("1.00"), 2, BigDecimal.ROUND_HALF_UP).toString()); cell = row.getCell(34); // cell.setCellStyle(style10_5); cell.setCellValue(content.getProjectType() == null ? "" : content.getProjectType()); cell = row.getCell(40); // cell.setCellStyle(style10_5); cell.setCellValue(workTypes); cell = row.getCell(45); // cell.setCellStyle(style10_5); cell.setCellValue(fixPersons); p++; } } if (partAllSize > 12) { int prinPartSize = (partAllSize > (i + 2) * 12 ? (i + 2) * 12 : partAllSize); for (int j = 12 * (i + 1); j < prinPartSize; j++) { TbMaintianVo t = partAll.get(j); row = sheetClone.getRow(41 + k * 2); cell = row.getCell(2); // cell.setCellStyle(style10_5); cell.setCellValue(t.getPartCode()); cell = row.getCell(11); // cell.setCellStyle(style10_5); cell.setCellValue(t.getPartName()); cell = row.getCell(20); // cell.setCellStyle(style10_5); cell.setCellValue(new BigDecimal(t.getPartQuantity()) .divide(new BigDecimal("1.00"), 2, BigDecimal.ROUND_HALF_UP).toString()); cell = row.getCell(24); // cell.setCellStyle(style10_5); cell.setCellValue(new BigDecimal(t.getPrice()) .divide(new BigDecimal("1.00"), 2, BigDecimal.ROUND_HALF_UP).toString()); cell = row.getCell(28); // cell.setCellStyle(style10_5); cell.setCellValue(new BigDecimal(t.getPartQuantity()).multiply(new BigDecimal(t.getPrice())) .divide(new BigDecimal("1.00"), 2, BigDecimal.ROUND_HALF_UP).toString()); cell = row.getCell(34); // cell.setCellStyle(style10_5); cell.setCellValue(t.getProjectType() == null ? "" : t.getProjectType()); // cell = row.getCell(40); // cell.setCellStyle(style10_5); cell.setCellValue(""); k++; } } } if (fixSize > 0) { int printFixSize = (fixSize > 8 ? 8 : fixSize); for (int j = 0; j < printFixSize; j++) { TbFixEntrustContent content = tbFixEntrustContentList.get(j); List<TbFixShare> tbFixShareList = tbFixShareService .findTbFixShareListByTbFixEntrustContentId(content.getId()); String fixPersons = ""; String workTypes = ""; if (null != tbFixShareList && tbFixShareList.size() > 0) { for (TbFixShare tbFixShare : tbFixShareList) { if (null != tbFixShare.getTmUser()) { TmUser tmUser = tmUserService.findById(tbFixShare.getTmUser().getId()); fixPersons += (tmUser.getUserRealName() == null || "".equals(tmUser.getUserRealName()) ? tmUser.getUserName() : tmUser.getUserRealName()) + " "; workTypes += (tmUser.getTmWorkType() == null ? "" : tmUser.getTmWorkType().getWorkName()) + " "; } } } row = sheet.getRow(23 + j * 2); cell = row.getCell(2); // cell.setCellStyle(style10_5); cell.setCellValue(content.getStationName()); cell = row.getCell(20); // cell.setCellStyle(style10_5); cell.setCellValue(new BigDecimal(content.getFixHour()) .divide(new BigDecimal("1.00"), 2, BigDecimal.ROUND_HALF_UP).toString()); cell = row.getCell(24); // cell.setCellStyle(style10_5); cell.setCellValue(new BigDecimal(content.getWorkingHourPrice()) .divide(new BigDecimal("1.00"), 2, BigDecimal.ROUND_HALF_UP).toString()); cell = row.getCell(28); // cell.setCellStyle(style10_5); cell.setCellValue(new BigDecimal(content.getFixHourAll()) .divide(new BigDecimal("1.00"), 2, BigDecimal.ROUND_HALF_UP).toString()); cell = row.getCell(34); // cell.setCellStyle(style10_5); cell.setCellValue(content.getProjectType() == null ? "" : content.getProjectType()); cell = row.getCell(40); // cell.setCellStyle(style10_5); cell.setCellValue(workTypes); cell = row.getCell(45); // cell.setCellStyle(style10_5); cell.setCellValue(fixPersons); } } if (partAllSize > 0) { int printPartSize = (partAllSize > 12 ? 12 : partAllSize); for (int j = 0; j < printPartSize; j++) { TbMaintianVo t = partAll.get(j); row = sheet.getRow(41 + j * 2); cell = row.getCell(2); // cell.setCellStyle(style10_5); cell.setCellValue(t.getPartCode()); cell = row.getCell(11); // cell.setCellStyle(style10_5); cell.setCellValue(t.getPartName()); cell = row.getCell(20); // cell.setCellStyle(style10_5); cell.setCellValue(new BigDecimal(t.getPartQuantity()) .divide(new BigDecimal("1.00"), 2, BigDecimal.ROUND_HALF_UP).toString()); cell = row.getCell(24); // cell.setCellStyle(style10_5); cell.setCellValue(new BigDecimal(t.getPrice()) .divide(new BigDecimal("1.00"), 2, BigDecimal.ROUND_HALF_UP).toString()); cell = row.getCell(28); // cell.setCellStyle(style10_5); cell.setCellValue(new BigDecimal(t.getPartQuantity()).multiply(new BigDecimal(t.getPrice())) .divide(new BigDecimal("1.00"), 2, BigDecimal.ROUND_HALF_UP).toString()); cell = row.getCell(34); // cell.setCellStyle(style10_5); cell.setCellValue(t.getProjectType() == null ? "" : t.getProjectType()); // cell = row.getCell(40); // cell.setCellStyle(style10_5); cell.setCellValue(""); } } workbook.write(os); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } }
From source file:com.selfsoft.business.service.impl.TbFixEntrustServiceImpl.java
public void printTbFixEntrustTemplateXTL(OutputStream os, String tpl, Long tbFixEntrustId) { try {//from w ww.jav a 2 s . c om TbFixEntrust tbFixEntrust = this.findById(tbFixEntrustId); TbCustomer tbCustomer = tbCustomerService.findById(tbFixEntrust.getTbCustomer().getId()); TbCarInfo tbCarInfo = tbCarInfoService.findById(tbFixEntrust.getTbCarInfo().getId()); List<TbFixEntrustContent> tbFixEntrustContentList = this.composeContent( tbFixEntrustContentService.findTbFixEnTrustContentListByTbFixEntrustId(tbFixEntrustId)); // ?? TmCompany tmCompany = tmCompanyService.acquireUniqueTmCompany(); /* * List<TbMaintainPartContent> maintainList = * tbMaintainPartContentService * .getViewEntrustMaintianContent(tbFixEntrustId); * * * List<TmStockOutDetVo> solePartList = * tmStockOutService.getSellByEntrustCode * (tbFixEntrust.getEntrustCode()); */ /** * ?? */ List<TbMaintianVo> maintianvos = tbMaintainPartContentService .getTbMaintianDetailVosByEntrustId(tbFixEntrust.getId(), Constants.BALANCE_ALL); /** * ? */ List<TmStockOutDetVo> tmStockOutDetVos = tmStockOutService .getSellDetailByEntrustCode(tbFixEntrust.getEntrustCode(), Constants.BALANCE_ALL); /** * ?? */ List<TbMaintianVo> partAll = new ArrayList<TbMaintianVo>(); if (null != maintianvos && maintianvos.size() > 0) { for (TbMaintianVo tbMaintianVo : maintianvos) { partAll.add(tbMaintianVo); } } if (null != tmStockOutDetVos && tmStockOutDetVos.size() > 0) { for (TmStockOutDetVo tmStockOutDetVo : tmStockOutDetVos) { TbMaintianVo tbMaintianVo = new TbMaintianVo(); tbMaintianVo.setPartId(tmStockOutDetVo.getPartinfoId()); tbMaintianVo.setHouseName(tmStockOutDetVo.getHouseName()); tbMaintianVo.setPartCode(tmStockOutDetVo.getPartCode()); tbMaintianVo.setPartName(tmStockOutDetVo.getPartName()); tbMaintianVo.setUnitName(tmStockOutDetVo.getUnitName()); tbMaintianVo.setPrice(tmStockOutDetVo.getPrice()); tbMaintianVo.setPartQuantity(tmStockOutDetVo.getQuantity()); tbMaintianVo.setTotal(tmStockOutDetVo.getTotal()); tbMaintianVo.setIsFree(tmStockOutDetVo.getIsFree()); tbMaintianVo.setProjectType(tmStockOutDetVo.getProjectType()); tbMaintianVo.setZl(tmStockOutDetVo.getZl()); tbMaintianVo.setXmlx(tmStockOutDetVo.getXmlx()); partAll.add(tbMaintianVo); } } partAll = this.composePart(partAll); int fixSize = (tbFixEntrustContentList == null ? 0 : tbFixEntrustContentList.size()); int maintainSize = (maintianvos == null ? 0 : maintianvos.size()); int solePartSize = (tmStockOutDetVos == null ? 0 : tmStockOutDetVos.size()); int partAllSize = (partAll == null ? 0 : partAll.size()); HSSFWorkbook workbook = new HSSFWorkbook(this.getClass().getResourceAsStream(tpl)); HSSFSheet sheet = workbook.getSheetAt(0); HSSFCellStyle style = workbook.createCellStyle(); style.setWrapText(true); style.setAlignment(HSSFCellStyle.ALIGN_LEFT); style.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER); HSSFFont font = workbook.createFont(); font.setFontName(""); font.setFontHeightInPoints((short) 9); style.setFont(font); HSSFRow row = null; HSSFCell cell = null; row = sheet.getRow(3); cell = row.getCell(0); cell.setCellValue(" ??:" + "?" + " (?:70691M) ?:" + tmCompany.getCompanyAddress() + " ?: " + (tmCompany.getCompanyPhone() == null ? "" : tmCompany.getCompanyPhone())); row = sheet.getRow(0); cell = row.getCell(31); cell.setCellStyle(style); cell.setCellValue("*?:" + tbCustomer.getCustomerCode() + "\n" + "??:"); row = sheet.getRow(6); cell = row.getCell(4); cell.setCellValue(tbCustomer.getCustomerName() == null ? "" : tbCustomer.getCustomerName()); row = sheet.getRow(6); cell = row.getCell(24); cell.setCellStyle(style); cell.setCellValue(tbCustomer.getAddress() == null ? "" : tbCustomer.getAddress()); row = sheet.getRow(6); cell = row.getCell(41); cell.setCellValue(tbCustomer.getContractPerson() == null ? "" : tbCustomer.getContractPerson()); row = sheet.getRow(8); cell = row.getCell(41); cell.setCellValue(tbCustomer.getTelephone() == null ? "" : tbCustomer.getTelephone()); row = sheet.getRow(8); cell = row.getCell(4); cell.setCellValue(tbCustomer.getTelephone() == null ? "" : tbCustomer.getTelephone()); row = sheet.getRow(12); cell = row.getCell(0); String entrustCode = tbFixEntrust.getEntrustCode(); String[] es = entrustCode.split("-"); String newCode = "RO" + es[0].substring(2, 6) + es[1]; cell.setCellValue(/* tbFixEntrust.getEntrustCode() */newCode); row = sheet.getRow(12); cell = row.getCell(9); cell.setCellValue(CommonMethod.parseDateToString(tbFixEntrust.getFixDate(), "yyyy-MM-dd HH:mm")); row = sheet.getRow(12); cell = row.getCell(18); cell.setCellValue(tbCarInfo.getLicenseCode()); row = sheet.getRow(12); cell = row.getCell(26); cell.setCellStyle(style); cell.setCellValue(tbCarInfo.getTmCarModelType().getModelName()); row = sheet.getRow(12); cell = row.getCell(34); cell.setCellValue(tbCarInfo.getChassisCode()); // ? row = sheet.getRow(16); cell = row.getCell(0); cell.setCellValue(""); row = sheet.getRow(16); cell = row.getCell(9); cell.setCellValue(CommonMethod.parseDateToString(tbCarInfo.getPurchaseDate(), "yyyy-MM-dd")); // ? row = sheet.getRow(16); cell = row.getCell(18); cell.setCellValue(""); row = sheet.getRow(16); cell = row.getCell(26); cell.setCellValue(tbFixEntrust.getEnterStationKilo() == null ? "" : new BigDecimal(tbFixEntrust.getEnterStationKilo().toString()) .divide(new BigDecimal("1.00"), 0, BigDecimal.ROUND_HALF_UP).toString()); row = sheet.getRow(16); cell = row.getCell(34); cell.setCellValue(CommonMethod.parseDateToString(tbFixEntrust.getEstimateDate(), "yyyy-MM-dd HH:mm")); Double fixCount = tbFixEntrustContentService.countTbFixEnTrustContentByTbFixEntrustId(tbFixEntrustId); row = sheet.getRow(75); cell = row.getCell(30); cell.setCellValue(new BigDecimal(fixCount).divide(new BigDecimal("1.00"), 2, BigDecimal.ROUND_HALF_UP) .toString()); BigDecimal partPriceAll = new BigDecimal("0.00"); if (partAllSize > 0) { for (int i = 0; i < partAllSize; i++) { TbMaintianVo tbMaintianVo = partAll.get(i); BigDecimal total = new BigDecimal(tbMaintianVo.getPrice()) .multiply(new BigDecimal(tbMaintianVo.getPartQuantity())); partPriceAll = partPriceAll.add(total); } } row = sheet.getRow(77); cell = row.getCell(30); cell.setCellValue(partPriceAll.divide(new BigDecimal("1.00"), 2, BigDecimal.ROUND_HALF_UP).toString()); BigDecimal total = new BigDecimal(fixCount).add(partPriceAll).divide(new BigDecimal("1.00"), 2, BigDecimal.ROUND_HALF_UP); row = sheet.getRow(81); cell = row.getCell(30); cell.setCellValue(total.toString()); row = sheet.getRow(79); cell = row.getCell(30); cell.setCellValue("0.00"); ByteArrayOutputStream byteArrayOutImgLion = new ByteArrayOutputStream(); ByteArrayOutputStream byteArrayOutDBZF = new ByteArrayOutputStream(); BufferedImage bufferImgLion = ImageIO.read(this.getClass().getResourceAsStream("/xtl.png")); BufferedImage bufferImgDFBZ = ImageIO.read(this.getClass().getResourceAsStream("/xtl_logo.png")); ImageIO.write(bufferImgLion, "png", byteArrayOutImgLion); ImageIO.write(bufferImgDFBZ, "png", byteArrayOutDBZF); HSSFPatriarch patriarch = sheet.createDrawingPatriarch(); HSSFClientAnchor anchorLion = new HSSFClientAnchor(0, 0, 1023, 200, (short) 40, 0, (short) 47, 2); HSSFClientAnchor anchorDBZF = new HSSFClientAnchor(0, 0, 1023, 100, (short) 0, 0, (short) 3, 3); patriarch.createPicture(anchorLion, workbook.addPicture(byteArrayOutImgLion.toByteArray(), HSSFWorkbook.PICTURE_TYPE_PNG)); patriarch.createPicture(anchorDBZF, workbook.addPicture(byteArrayOutDBZF.toByteArray(), HSSFWorkbook.PICTURE_TYPE_PNG)); int page = 1; if (fixSize / 8 >= (maintainSize + solePartSize) / 12) { page = fixSize / 8; } else { page = (maintainSize + solePartSize) / 12; } for (int i = 0; i < page; i++) { int p = 0; int k = 0; HSSFSheet sheetClone = workbook.cloneSheet(0); byteArrayOutImgLion = new ByteArrayOutputStream(); byteArrayOutDBZF = new ByteArrayOutputStream(); bufferImgLion = ImageIO.read(this.getClass().getResourceAsStream("/xtl.png")); bufferImgDFBZ = ImageIO.read(this.getClass().getResourceAsStream("/xtl_logo.png")); ImageIO.write(bufferImgLion, "png", byteArrayOutImgLion); ImageIO.write(bufferImgDFBZ, "png", byteArrayOutDBZF); patriarch = sheetClone.createDrawingPatriarch(); anchorLion = new HSSFClientAnchor(0, 0, 1023, 200, (short) 40, 0, (short) 47, 2); anchorDBZF = new HSSFClientAnchor(0, 0, 1023, 200, (short) 0, 0, (short) 3, 3); patriarch.createPicture(anchorLion, workbook.addPicture(byteArrayOutImgLion.toByteArray(), HSSFWorkbook.PICTURE_TYPE_PNG)); patriarch.createPicture(anchorDBZF, workbook.addPicture(byteArrayOutDBZF.toByteArray(), HSSFWorkbook.PICTURE_TYPE_PNG)); if (fixSize > 8) { int printFixSize = (fixSize > (i + 2) * 8 ? (i + 2) * 8 : fixSize); for (int j = 8 * (i + 1); j < printFixSize; j++) { TbFixEntrustContent content = tbFixEntrustContentList.get(j); List<TbFixShare> tbFixShareList = tbFixShareService .findTbFixShareListByTbFixEntrustContentId(content.getId()); String fixPersons = ""; String workTypes = ""; if (null != tbFixShareList && tbFixShareList.size() > 0) { for (TbFixShare tbFixShare : tbFixShareList) { if (null != tbFixShare.getTmUser()) { TmUser tmUser = tmUserService.findById(tbFixShare.getTmUser().getId()); fixPersons += (tmUser.getUserRealName() == null || "".equals(tmUser.getUserRealName()) ? tmUser.getUserName() : tmUser.getUserRealName()) + " "; workTypes += (tmUser.getTmWorkType() == null ? "" : tmUser.getTmWorkType().getWorkName()) + " "; } } } row = sheetClone.getRow(23 + p * 2); cell = row.getCell(2); cell.setCellStyle(style); cell.setCellValue(content.getStationName()); cell = row.getCell(20); cell.setCellStyle(style); cell.setCellValue(new BigDecimal(content.getFixHour()) .divide(new BigDecimal("1.00"), 2, BigDecimal.ROUND_HALF_UP).toString()); cell = row.getCell(24); cell.setCellStyle(style); cell.setCellValue(new BigDecimal(content.getWorkingHourPrice()) .divide(new BigDecimal("1.00"), 2, BigDecimal.ROUND_HALF_UP).toString()); cell = row.getCell(28); cell.setCellStyle(style); cell.setCellValue(new BigDecimal(content.getFixHourAll()) .divide(new BigDecimal("1.00"), 2, BigDecimal.ROUND_HALF_UP).toString()); cell = row.getCell(34); cell.setCellStyle(style); cell.setCellValue(content.getProjectType() == null ? "" : content.getProjectType()); cell = row.getCell(40); cell.setCellStyle(style); cell.setCellValue(workTypes); cell = row.getCell(45); cell.setCellStyle(style); cell.setCellValue(fixPersons); p++; } } if (partAllSize > 12) { int prinPartSize = (partAllSize > (i + 2) * 12 ? (i + 2) * 12 : partAllSize); for (int j = 12 * (i + 1); j < prinPartSize; j++) { TbMaintianVo t = partAll.get(j); row = sheetClone.getRow(41 + k * 2); cell = row.getCell(2); cell.setCellStyle(style); cell.setCellValue(t.getPartCode()); cell = row.getCell(11); cell.setCellStyle(style); cell.setCellValue(t.getPartName()); cell = row.getCell(20); cell.setCellStyle(style); cell.setCellValue(new BigDecimal(t.getPartQuantity()) .divide(new BigDecimal("1.00"), 2, BigDecimal.ROUND_HALF_UP).toString()); cell = row.getCell(24); cell.setCellStyle(style); cell.setCellValue(new BigDecimal(t.getPrice()) .divide(new BigDecimal("1.00"), 2, BigDecimal.ROUND_HALF_UP).toString()); cell = row.getCell(28); cell.setCellStyle(style); cell.setCellValue(new BigDecimal(t.getPartQuantity()).multiply(new BigDecimal(t.getPrice())) .divide(new BigDecimal("1.00"), 2, BigDecimal.ROUND_HALF_UP).toString()); cell = row.getCell(34); cell.setCellStyle(style); cell.setCellValue(t.getProjectType() == null ? "" : t.getProjectType()); // cell = row.getCell(40); cell.setCellStyle(style); cell.setCellValue(""); k++; } } } if (fixSize > 0) { int printFixSize = (fixSize > 8 ? 8 : fixSize); for (int j = 0; j < printFixSize; j++) { TbFixEntrustContent content = tbFixEntrustContentList.get(j); List<TbFixShare> tbFixShareList = tbFixShareService .findTbFixShareListByTbFixEntrustContentId(content.getId()); String fixPersons = ""; String workTypes = ""; if (null != tbFixShareList && tbFixShareList.size() > 0) { for (TbFixShare tbFixShare : tbFixShareList) { if (null != tbFixShare.getTmUser()) { TmUser tmUser = tmUserService.findById(tbFixShare.getTmUser().getId()); fixPersons += (tmUser.getUserRealName() == null || "".equals(tmUser.getUserRealName()) ? tmUser.getUserName() : tmUser.getUserRealName()) + " "; workTypes += (tmUser.getTmWorkType() == null ? "" : tmUser.getTmWorkType().getWorkName()) + " "; } } } row = sheet.getRow(23 + j * 2); cell = row.getCell(2); cell.setCellStyle(style); cell.setCellValue(content.getStationName()); cell = row.getCell(20); cell.setCellStyle(style); cell.setCellValue(new BigDecimal(content.getFixHour()) .divide(new BigDecimal("1.00"), 2, BigDecimal.ROUND_HALF_UP).toString()); cell = row.getCell(24); cell.setCellStyle(style); cell.setCellValue(new BigDecimal(content.getWorkingHourPrice()) .divide(new BigDecimal("1.00"), 2, BigDecimal.ROUND_HALF_UP).toString()); cell = row.getCell(28); cell.setCellStyle(style); cell.setCellValue(new BigDecimal(content.getFixHourAll()) .divide(new BigDecimal("1.00"), 2, BigDecimal.ROUND_HALF_UP).toString()); cell = row.getCell(34); cell.setCellStyle(style); cell.setCellValue(content.getProjectType() == null ? "" : content.getProjectType()); cell = row.getCell(40); cell.setCellStyle(style); cell.setCellValue(workTypes); cell = row.getCell(45); cell.setCellStyle(style); cell.setCellValue(fixPersons); } } if (partAllSize > 0) { int printPartSize = (partAllSize > 12 ? 12 : partAllSize); for (int j = 0; j < printPartSize; j++) { TbMaintianVo t = partAll.get(j); row = sheet.getRow(41 + j * 2); cell = row.getCell(2); cell.setCellStyle(style); cell.setCellValue(t.getPartCode()); cell = row.getCell(11); cell.setCellStyle(style); cell.setCellValue(t.getPartName()); cell = row.getCell(20); cell.setCellStyle(style); cell.setCellValue(new BigDecimal(t.getPartQuantity()) .divide(new BigDecimal("1.00"), 2, BigDecimal.ROUND_HALF_UP).toString()); cell = row.getCell(24); cell.setCellStyle(style); cell.setCellValue(new BigDecimal(t.getPrice()) .divide(new BigDecimal("1.00"), 2, BigDecimal.ROUND_HALF_UP).toString()); cell = row.getCell(28); cell.setCellStyle(style); cell.setCellValue(new BigDecimal(t.getPartQuantity()).multiply(new BigDecimal(t.getPrice())) .divide(new BigDecimal("1.00"), 2, BigDecimal.ROUND_HALF_UP).toString()); cell = row.getCell(34); cell.setCellStyle(style); cell.setCellValue(t.getProjectType() == null ? "" : t.getProjectType()); // cell = row.getCell(40); cell.setCellStyle(style); cell.setCellValue(""); } } workbook.write(os); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } }
From source file:com.selfsoft.business.service.impl.TbFixEntrustServiceImpl.java
public void printTbFixEntrustTemplate(OutputStream os, String tpl, Long tbFixEntrustId) { /*//from www . j a va 2 s . co m * Workbook wb = null; * * WritableWorkbook wwb = null; * * WritableSheet ws = null; * * try { * * wb = Workbook.getWorkbook(this.getClass().getResourceAsStream(tpl)); * * wwb = Workbook.createWorkbook(os, wb); * * ws = wwb.getSheet(0); * * WritableCellFormat wcf = new WritableCellFormat(); * * wcf.setVerticalAlignment(VerticalAlignment.CENTRE); * * wcf.setAlignment(Alignment.CENTRE); * * wcf.setWrap(true); * * TbFixEntrust tbFixEntrust = this.findById(tbFixEntrustId); * * TbCustomer tbCustomer = * tbCustomerService.findById(tbFixEntrust.getTbCustomer().getId()); * * TbCarInfo tbCarInfo = * tbCarInfoService.findById(tbFixEntrust.getTbCarInfo().getId()); * * Label label = null; * * label = new Label(0, 10, tbFixEntrust.getEntrustCode(), wcf); * * ws.addCell(label); * * label = new Label(8, 10, tbCarInfo.getPurchaseDate()== null ? "" : * CommonMethod.parseDateToString(tbCarInfo.getPurchaseDate(), * "yyyy-MM-dd"), wcf); * * ws.addCell(label); * * label = new Label(14, 10, tbFixEntrust.getTmUser().getUserRealName(), * wcf); * * ws.addCell(label); * * label = new Label(20, 10, tbCarInfo.getLicenseCode(), wcf); * * ws.addCell(label); * * label = new Label(27, 10, * tbCarInfo.getTmCarModelType().getModelName(), wcf); * * ws.addCell(label); * * label = new Label(32, 10, tbFixEntrust.getEnterStationKilo() == null * ? "" : tbFixEntrust.getEnterStationKilo().toString(), wcf); * * ws.addCell(label); * * label = new Label(41, 10, tbCarInfo.getColor() == null ? "" : * tbCarInfo.getColor().toString(), wcf); * * ws.addCell(label); * * label = new Label(45, 10, tbFixEntrust.getFixDate() == null ? "" : * CommonMethod.parseDateToString(tbFixEntrust.getFixDate(), * "yyyy-MM-dd HH:mm:ss"), wcf); * * ws.addCell(label); * * label = new Label(0, 15, tbCustomer.getCustomerName() == null ? "" : * tbCustomer.getCustomerName(), wcf); * * ws.addCell(label); * * label = new Label(8, 15, tbCustomer.getTelephone() == null ? "" : * tbCustomer.getTelephone(), wcf); * * ws.addCell(label); * * label = new Label(14, 15, tbCustomer.getPhone() == null ? "" : * tbCustomer.getPhone(), wcf); * * ws.addCell(label); * * label = new Label(20, 15, tbCarInfo.getChassisCode() == null ? "" : * tbCarInfo.getChassisCode(), wcf); * * ws.addCell(label); * * label = new Label(32, 15, tbCarInfo.getEngineCode() == null ? "" : * tbCarInfo.getEngineCode(),wcf); * * ws.addCell(label); * * label = new Label(45, 15, tbFixEntrust.getEstimateDate() == null ? "" * : CommonMethod.parseDateToString(tbFixEntrust.getEstimateDate(), * "yyyy-MM-dd HH:mm:ss"),wcf); * * ws.addCell(label); * * label = new Label(8, 18, tbCustomer.getCustomerName() == null ? "" : * tbCustomer.getCustomerName(), wcf); * * ws.addCell(label); * * label = new Label(0, 22, tbCustomer.getAddress() == null ? "" : * tbCustomer.getAddress(), wcf); * * ws.addCell(label); * * label = new Label(8, 25, tbCustomer.getZipCode() == null ? "" : * tbCustomer.getZipCode(), wcf); * * ws.addCell(label); * * label = new Label(20, 20, (tbFixEntrust.getWrongDescribe() == * null?"":tbFixEntrust.getWrongDescribe()) +";" + * (tbFixEntrust.getBeforeFixState * ()==null?"":tbFixEntrust.getBeforeFixState()) + ";" + * (tbFixEntrust.getCheckResult * ()==null?"":tbFixEntrust.getCheckResult()) + ";" + * (tbFixEntrust.getRemark()==null?"":tbFixEntrust.getRemark()), wcf); * * ws.addCell(label); * * wwb.write(); * * } catch (BiffException e) { * * e.printStackTrace(); } catch (IOException e) { * * e.printStackTrace(); } catch (RowsExceededException e) { // TODO * Auto-generated catch block e.printStackTrace(); } catch * (WriteException e) { // TODO Auto-generated catch block * e.printStackTrace(); } finally { * * if (null != wb) { * * wb.close(); * * } * * if (null != wwb) { * * try { wwb.close(); } catch (WriteException e) { * * e.printStackTrace(); } catch (IOException e) { * * e.printStackTrace(); } } * * } */ try { TbFixEntrust tbFixEntrust = this.findById(tbFixEntrustId); TbCustomer tbCustomer = tbCustomerService.findById(tbFixEntrust.getTbCustomer().getId()); TbCarInfo tbCarInfo = tbCarInfoService.findById(tbFixEntrust.getTbCarInfo().getId()); List<TbFixEntrustContent> tbFixEntrustContentList = tbFixEntrustContentService .findTbFixEnTrustContentListByTbFixEntrustId(tbFixEntrustId); /* * List<TbMaintainPartContent> maintainList = * tbMaintainPartContentService * .getViewEntrustMaintianContent(tbFixEntrustId); * * * List<TmStockOutDetVo> solePartList = * tmStockOutService.getSellByEntrustCode * (tbFixEntrust.getEntrustCode()); */ /** * ?? */ List<TbMaintianVo> maintianvos = tbMaintainPartContentService .getTbMaintianDetailVosByEntrustId(tbFixEntrust.getId(), Constants.BALANCE_ALL); /** * ? */ List<TmStockOutDetVo> tmStockOutDetVos = tmStockOutService .getSellDetailByEntrustCode(tbFixEntrust.getEntrustCode(), Constants.BALANCE_ALL); /** * ?? */ List<TbMaintianVo> partAll = new ArrayList<TbMaintianVo>(); if (null != maintianvos && maintianvos.size() > 0) { for (TbMaintianVo tbMaintianVo : maintianvos) { partAll.add(tbMaintianVo); } } if (null != tmStockOutDetVos && tmStockOutDetVos.size() > 0) { for (TmStockOutDetVo tmStockOutDetVo : tmStockOutDetVos) { TbMaintianVo tbMaintianVo = new TbMaintianVo(); tbMaintianVo.setPartId(tmStockOutDetVo.getPartinfoId()); tbMaintianVo.setHouseName(tmStockOutDetVo.getHouseName()); tbMaintianVo.setPartCode(tmStockOutDetVo.getPartCode()); tbMaintianVo.setPartName(tmStockOutDetVo.getPartName()); tbMaintianVo.setUnitName(tmStockOutDetVo.getUnitName()); tbMaintianVo.setPrice(tmStockOutDetVo.getPrice()); tbMaintianVo.setPartQuantity(tmStockOutDetVo.getQuantity()); tbMaintianVo.setTotal(tmStockOutDetVo.getTotal()); tbMaintianVo.setIsFree(tmStockOutDetVo.getIsFree()); tbMaintianVo.setProjectType(tmStockOutDetVo.getProjectType()); tbMaintianVo.setZl(tmStockOutDetVo.getZl()); tbMaintianVo.setXmlx(tmStockOutDetVo.getXmlx()); partAll.add(tbMaintianVo); } } int fixSize = (tbFixEntrustContentList == null ? 0 : tbFixEntrustContentList.size()); int maintainSize = (maintianvos == null ? 0 : maintianvos.size()); int solePartSize = (tmStockOutDetVos == null ? 0 : tmStockOutDetVos.size()); int partAllSize = (partAll == null ? 0 : partAll.size()); HSSFWorkbook workbook = new HSSFWorkbook(this.getClass().getResourceAsStream(tpl)); HSSFSheet sheet = workbook.getSheetAt(0); sheet.setMargin(HSSFSheet.LeftMargin, (double) 0.5); sheet.setMargin(HSSFSheet.RightMargin, (double) 0.5); HSSFCellStyle style = workbook.createCellStyle(); style.setWrapText(true); style.setAlignment(HSSFCellStyle.ALIGN_LEFT); style.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER); HSSFFont font = workbook.createFont(); font.setFontName(""); font.setFontHeightInPoints((short) 9); style.setFont(font); HSSFRow row = null; HSSFCell cell = null; ByteArrayOutputStream byteArrayOutImgLion = new ByteArrayOutputStream(); ByteArrayOutputStream byteArrayOutDBZF = new ByteArrayOutputStream(); BufferedImage bufferImgLion = ImageIO.read(this.getClass().getResourceAsStream("/lion.png")); BufferedImage bufferImgDFBZ = ImageIO.read(this.getClass().getResourceAsStream("/dfbz.png")); ImageIO.write(bufferImgLion, "png", byteArrayOutImgLion); ImageIO.write(bufferImgDFBZ, "png", byteArrayOutDBZF); HSSFPatriarch patriarch = sheet.createDrawingPatriarch(); HSSFClientAnchor anchorLion = new HSSFClientAnchor(0, 0, 1023, 200, (short) 48, 0, (short) 53, 7); HSSFClientAnchor anchorDBZF = new HSSFClientAnchor(0, 0, 1023, 200, (short) 0, 0, (short) 8, 7); patriarch.createPicture(anchorLion, workbook.addPicture(byteArrayOutImgLion.toByteArray(), HSSFWorkbook.PICTURE_TYPE_PNG)); patriarch.createPicture(anchorDBZF, workbook.addPicture(byteArrayOutDBZF.toByteArray(), HSSFWorkbook.PICTURE_TYPE_PNG)); row = sheet.getRow(10); cell = row.getCell(0); String entrustCode = tbFixEntrust.getEntrustCode(); String[] es = entrustCode.split("-"); String newCode = "RO" + es[0].substring(2, 6) + es[1]; // cell.setCellValue(tbFixEntrust.getEntrustCode()); cell.setCellValue(newCode); row = sheet.getRow(10); cell = row.getCell(8); cell.setCellValue(tbCarInfo.getPurchaseDate() == null ? "" : CommonMethod.parseDateToString(tbCarInfo.getPurchaseDate(), "yyyy-MM-dd")); row = sheet.getRow(10); cell = row.getCell(14); cell.setCellValue( tbFixEntrust.getTmUser().getUserRealName() == null ? tbFixEntrust.getTmUser().getUserName() : tbFixEntrust.getTmUser().getUserRealName()); row = sheet.getRow(10); cell = row.getCell(19); cell.setCellValue(tbCarInfo.getLicenseCode()); row = sheet.getRow(10); cell = row.getCell(27); cell.setCellStyle(style); cell.setCellValue(tbCarInfo.getTmCarModelType().getModelName()); row = sheet.getRow(10); cell = row.getCell(32); cell.setCellValue( tbFixEntrust.getEnterStationKilo() == null ? "" : new BigDecimal(tbFixEntrust.getEnterStationKilo().toString()) .divide(new BigDecimal("1.00"), 0, BigDecimal.ROUND_HALF_UP).toString() + " Km"); row = sheet.getRow(10); cell = row.getCell(41); cell.setCellValue(tbCarInfo.getColor() == null ? "" : tbCarInfo.getColor().toString()); row = sheet.getRow(10); cell = row.getCell(45); cell.setCellValue(tbFixEntrust.getFixDate() == null ? "" : CommonMethod.parseDateToString(tbFixEntrust.getFixDate(), Constants.TIMEFORMATOFMINUTE)); row = sheet.getRow(15); cell = row.getCell(0); cell.setCellValue(tbCustomer.getCustomerName() == null ? "" : tbCustomer.getContractPerson()); row = sheet.getRow(15); cell = row.getCell(8); cell.setCellValue(tbCustomer.getTelephone() == null ? "" : tbCustomer.getTelephone()); row = sheet.getRow(15); cell = row.getCell(14); cell.setCellValue(tbCustomer.getPhone() == null ? "" : tbCustomer.getPhone()); row = sheet.getRow(15); cell = row.getCell(20); cell.setCellValue(tbCarInfo.getChassisCode() == null ? "" : tbCarInfo.getChassisCode()); row = sheet.getRow(15); cell = row.getCell(32); // cell.setCellStyle(style); cell.setCellValue(tbCarInfo.getEngineCode() == null ? "" : tbCarInfo.getEngineCode()); row = sheet.getRow(15); cell = row.getCell(45); // cell.setCellStyle(style); cell.setCellValue(tbFixEntrust.getEstimateDate() == null ? "" : CommonMethod.parseDateToString(tbFixEntrust.getEstimateDate(), Constants.TIMEFORMATOFMINUTE)); row = sheet.getRow(18); cell = row.getCell(8); cell.setCellValue(tbCustomer.getCustomerName() == null ? "" : tbCustomer.getCustomerName()); row = sheet.getRow(20); cell = row.getCell(8); cell.setCellStyle(style); cell.setCellValue(tbCustomer.getAddress() == null ? "" : tbCustomer.getAddress()); row = sheet.getRow(25); cell = row.getCell(8); cell.setCellValue(tbCustomer.getZipCode() == null ? "" : tbCustomer.getZipCode()); row = sheet.getRow(20); cell = row.getCell(23); cell.setCellStyle(style); cell.setCellValue((tbFixEntrust.getWrongDescribe() == null || "".equals(tbFixEntrust.getWrongDescribe()) ? "" : tbFixEntrust.getWrongDescribe() + ";") + (tbFixEntrust.getBeforeFixState() == null || "".equals(tbFixEntrust.getBeforeFixState()) ? "" : tbFixEntrust.getBeforeFixState() + ";")); Double fixCount = tbFixEntrustContentService.countTbFixEnTrustContentByTbFixEntrustId(tbFixEntrustId); row = sheet.getRow(70); cell = row.getCell(32); cell.setCellStyle(style); cell.setCellValue(new BigDecimal(fixCount).divide(new BigDecimal("1.00"), 2, BigDecimal.ROUND_HALF_UP) .toString()); row = sheet.getRow(70); cell = row.getCell(48); cell.setCellStyle(style); cell.setCellValue("0.00"); BigDecimal partPriceAll = new BigDecimal("0.00"); if (partAllSize > 0) { for (int i = 0; i < partAllSize; i++) { TbMaintianVo tbMaintianVo = partAll.get(i); BigDecimal total = new BigDecimal(tbMaintianVo.getPrice()) .multiply(new BigDecimal(tbMaintianVo.getPartQuantity())); partPriceAll = partPriceAll.add(total); } } row = sheet.getRow(73); cell = row.getCell(33); cell.setCellStyle(style); cell.setCellValue(partPriceAll.divide(new BigDecimal("1.00"), 2, BigDecimal.ROUND_HALF_UP).toString()); BigDecimal total = new BigDecimal(fixCount).add(partPriceAll).divide(new BigDecimal("1.00"), 2, BigDecimal.ROUND_HALF_UP); row = sheet.getRow(76); cell = row.getCell(34); cell.setCellStyle(style); cell.setCellValue(total.toString()); int page = 1; if (fixSize / 5 >= (maintainSize + solePartSize) / 13) { page = fixSize / 5; } else { page = (maintainSize + solePartSize) / 13; } for (int i = 0; i < page; i++) { int p = 0; int k = 0; HSSFSheet sheetClone = workbook.cloneSheet(0); byteArrayOutImgLion = new ByteArrayOutputStream(); byteArrayOutDBZF = new ByteArrayOutputStream(); bufferImgLion = ImageIO.read(this.getClass().getResourceAsStream("/lion.png")); bufferImgDFBZ = ImageIO.read(this.getClass().getResourceAsStream("/dfbz.png")); ImageIO.write(bufferImgLion, "png", byteArrayOutImgLion); ImageIO.write(bufferImgDFBZ, "png", byteArrayOutDBZF); patriarch = sheetClone.createDrawingPatriarch(); anchorLion = new HSSFClientAnchor(0, 0, 1023, 200, (short) 48, 0, (short) 53, 7); anchorDBZF = new HSSFClientAnchor(0, 0, 1023, 200, (short) 0, 0, (short) 8, 7); patriarch.createPicture(anchorLion, workbook.addPicture(byteArrayOutImgLion.toByteArray(), HSSFWorkbook.PICTURE_TYPE_PNG)); patriarch.createPicture(anchorDBZF, workbook.addPicture(byteArrayOutDBZF.toByteArray(), HSSFWorkbook.PICTURE_TYPE_PNG)); if (fixSize > 5) { int printFixSize = (fixSize > (i + 2) * 5 ? (i + 2) * 5 : fixSize); for (int j = 5 * (i + 1); j < printFixSize; j++) { TbFixEntrustContent content = tbFixEntrustContentList.get(j); List<TbFixShare> tbFixShareList = tbFixShareService .findTbFixShareListByTbFixEntrustContentId(content.getId()); String fixPersons = ""; if (null != tbFixShareList && tbFixShareList.size() > 0) { for (TbFixShare tbFixShare : tbFixShareList) { if (null != tbFixShare.getTmUser()) { TmUser tmUser = tmUserService.findById(tbFixShare.getTmUser().getId()); fixPersons += (tmUser.getUserRealName() == null || "".equals(tmUser.getUserRealName()) ? tmUser.getUserName() : tmUser.getUserRealName()) + " "; } } } row = sheetClone.getRow(31 + p * 6); cell = row.getCell(0); cell.setCellStyle(style); cell.setCellValue(content.getStationCode() + " " + content.getStationName()); cell = row.getCell(20); cell.setCellStyle(style); cell.setCellValue(content.getXmlx() == null ? "" : content.getXmlx()); cell = row.getCell(26); cell.setCellStyle(style); cell.setCellValue(fixPersons); p++; } } if (partAllSize > 13) { int prinPartSize = (partAllSize > (i + 2) * 13 ? (i + 2) * 13 : partAllSize); for (int j = 13 * (i + 1); j < prinPartSize; j++) { TbMaintianVo t = partAll.get(j); row = sheetClone.getRow(31 + k * 3); cell = row.getCell(32); cell.setCellStyle(style); cell.setCellValue(t.getPartName()); cell = row.getCell(40); cell.setCellStyle(style); cell.setCellValue(t.getPartQuantity()); cell = row.getCell(44); cell.setCellStyle(style); cell.setCellValue(new BigDecimal(t.getPrice()) .divide(new BigDecimal("1.00"), 2, BigDecimal.ROUND_HALF_UP).toString()); k++; } } } if (fixSize > 0) { int printFixSize = (fixSize > 5 ? 5 : fixSize); for (int j = 0; j < printFixSize; j++) { TbFixEntrustContent content = tbFixEntrustContentList.get(j); List<TbFixShare> tbFixShareList = tbFixShareService .findTbFixShareListByTbFixEntrustContentId(content.getId()); String fixPersons = ""; if (null != tbFixShareList && tbFixShareList.size() > 0) { for (TbFixShare tbFixShare : tbFixShareList) { if (null != tbFixShare.getTmUser()) { TmUser tmUser = tmUserService.findById(tbFixShare.getTmUser().getId()); fixPersons += (tmUser.getUserRealName() == null || "".equals(tmUser.getUserRealName()) ? tmUser.getUserName() : tmUser.getUserRealName()) + " "; } } } row = sheet.getRow(31 + j * 6); cell = row.getCell(0); cell.setCellStyle(style); cell.setCellValue(content.getStationCode() + " " + content.getStationName()); cell = row.getCell(20); cell.setCellStyle(style); cell.setCellValue(content.getXmlx() == null ? "" : content.getXmlx()); cell = row.getCell(26); cell.setCellStyle(style); cell.setCellValue(fixPersons); } } if (partAllSize > 0) { int printPartSize = (partAllSize > 13 ? 13 : partAllSize); for (int j = 0; j < printPartSize; j++) { TbMaintianVo t = partAll.get(j); row = sheet.getRow(31 + j * 3); cell = row.getCell(32); cell.setCellStyle(style); cell.setCellValue(t.getPartName()); cell = row.getCell(40); cell.setCellStyle(style); cell.setCellValue(t.getPartQuantity()); cell = row.getCell(44); cell.setCellStyle(style); cell.setCellValue(new BigDecimal(t.getPrice()) .divide(new BigDecimal("1.00"), 2, BigDecimal.ROUND_HALF_UP).toString()); } } workbook.write(os); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } }
From source file:com.lp.server.lieferschein.ejbfac.LieferscheinFacBean.java
/** * Fuer die Nachkalkulation des Auftrags den Ist-Gestehungswert (= * Gestehungswert des Artikels auf Lager Lieferschein pro Stueck * * gelieferter Menge) bezogen auf eine bestimmte Artikelart berechnen. <br> * Beruecksichtigt werden alle mengenbehafteten Lieferscheinpositionen. * //from www . ja v a2s.co m * @param iIdLieferscheinI * PK des Lieferscheins * @param sArtikelartI * die gewuenschte Artikelart * @param theClientDto * der aktuelle Benutzer * @return BigDecimal der Ist-Gestehungswert der gewuenschten Artikelart in * Mandantenwaehrung * @throws EJBExceptionLP * Ausnahme */ public BigDecimal berechneGestehungswertIst(Integer iIdLieferscheinI, HashMap lieferscheinpositionIIds, String sArtikelartI, TheClientDto theClientDto) throws EJBExceptionLP { final String METHOD_NAME = "berechneGestehungswertIst"; myLogger.entry(); if (iIdLieferscheinI == null) { throw new EJBExceptionLP(EJBExceptionLP.FEHLER_PARAMETER_IS_NULL, new Exception("iIdLieferscheinI == null")); } if (sArtikelartI == null) { throw new EJBExceptionLP(EJBExceptionLP.FEHLER_PARAMETER_IS_NULL, new Exception("sArtikelartI == null")); } BigDecimal bdGestehungswertIstO = Helper.getBigDecimalNull(); try { LieferscheinpositionDto[] aLieferscheinpositionDtos = getLieferscheinpositionFac() .lieferscheinpositionFindByLieferscheinIId(iIdLieferscheinI); for (int i = 0; i < aLieferscheinpositionDtos.length; i++) { // alle mengenbehafteten Positionen beruecksichtigen if (aLieferscheinpositionDtos[i].getNMenge() != null && aLieferscheinpositionDtos[i].getArtikelIId() != null) { ArtikelDto oArtikelDto = getArtikelFac() .artikelFindByPrimaryKey(aLieferscheinpositionDtos[i].getArtikelIId(), theClientDto); if (lieferscheinpositionIIds == null || lieferscheinpositionIIds.containsKey(aLieferscheinpositionDtos[i].getIId())) { // Grundlage ist der positionsbezogene Gestehungspreis // des // Artikels. BigDecimal bdGestehungswertIst = Helper.getBigDecimalNull(); if (aLieferscheinpositionDtos[i].getLieferscheinpositionartCNr() .equals(LieferscheinpositionFac.LIEFERSCHEINPOSITIONSART_IDENT)) { bdGestehungswertIst = berechneGestehungswertEinerLieferscheinposition( aLieferscheinpositionDtos[i], theClientDto); } // je nach Artikelart beruecksichtigen // @todo PJ 4399 if (sArtikelartI.equals(ArtikelFac.ARTIKELART_ARBEITSZEIT)) { if (oArtikelDto.getArtikelartCNr().equals(ArtikelFac.ARTIKELART_ARBEITSZEIT)) { bdGestehungswertIstO = bdGestehungswertIstO.add(bdGestehungswertIst); } } else { if (!oArtikelDto.getArtikelartCNr().equals(ArtikelFac.ARTIKELART_ARBEITSZEIT)) { bdGestehungswertIstO = bdGestehungswertIstO.add(bdGestehungswertIst); } } } } } } catch (RemoteException ex) { throwEJBExceptionLPRespectOld(ex); } catch (Throwable t) { throw new EJBExceptionLP(EJBExceptionLP.FEHLER, new Exception(t)); } myLogger.exit("Gestehungswert " + sArtikelartI + " Ist : " + bdGestehungswertIstO.toString()); return bdGestehungswertIstO; }
From source file:com.lp.server.auftrag.ejbfac.AuftragFacBean.java
/** * Fuer die Nachkalkulation des Auftrags den Soll-Verkaufswert (= * NettoVerkaufspreisPlusAufschlaegeMinusRabatte pro Stueck * geplanter * Menge) bezogen auf eine bestimmte Artikelart berechnen. <br> * Beruecksichtigt werden alle mengenbehafteten Auftragpositionen. * //w w w. j a v a2 s. c om * @param iIdAuftragI * PK des Auftrags * @param sArtikelartI * die gewuenschte Artikelart * @param theClientDto * der aktuelle Benutzer * @return BigDecimal der Verkaufswert der Artikelart Soll in * Auftragswaherung * @throws EJBExceptionLP * Ausnahme */ public BigDecimal berechneVerkaufswertSoll(Integer iIdAuftragI, String sArtikelartI, TheClientDto theClientDto) throws EJBExceptionLP { final String METHOD_NAME = "berechneVKWArbeitSoll"; myLogger.entry(); if (iIdAuftragI == null) { throw new EJBExceptionLP(EJBExceptionLP.FEHLER_PARAMETER_IS_NULL, new Exception("iIdAuftragI == null")); } if (sArtikelartI == null) { throw new EJBExceptionLP(EJBExceptionLP.FEHLER_PARAMETER_IS_NULL, new Exception("sArtikelartI == null")); } BigDecimal bdVerkaufswertSollO = Helper.getBigDecimalNull(); try { AuftragpositionDto[] aAuftragpositionDtos = getAuftragpositionFac() .auftragpositionFindByAuftrag(iIdAuftragI); for (int i = 0; i < aAuftragpositionDtos.length; i++) { // alle mengenbehafteten Positionen beruecksichtigen if (aAuftragpositionDtos[i].getNMenge() != null && aAuftragpositionDtos[i].getArtikelIId() != null && aAuftragpositionDtos[i].getPositioniIdArtikelset() == null) { ArtikelDto oArtikelDto = getArtikelFac() .artikelFindByPrimaryKey(aAuftragpositionDtos[i].getArtikelIId(), theClientDto); // je nach Artikelart beruecksichtigen BigDecimal bdBeitragDieserPosition = aAuftragpositionDtos[i].getNMenge().multiply( aAuftragpositionDtos[i].getNNettoeinzelpreisplusversteckteraufschlagminusrabatte()); if (sArtikelartI.equals(ArtikelFac.ARTIKELART_ARBEITSZEIT)) { if (oArtikelDto.getArtikelartCNr().equals(ArtikelFac.ARTIKELART_ARBEITSZEIT)) { bdVerkaufswertSollO = bdVerkaufswertSollO.add(bdBeitragDieserPosition); } } else { if (!oArtikelDto.getArtikelartCNr().equals(ArtikelFac.ARTIKELART_ARBEITSZEIT)) { bdVerkaufswertSollO = bdVerkaufswertSollO.add(bdBeitragDieserPosition); } } } if (aAuftragpositionDtos[i].isIntelligenteZwischensumme() && aAuftragpositionDtos[i] .getNNettoeinzelpreisplusversteckteraufschlagminusrabatte() != null) { if (!sArtikelartI.equals(ArtikelFac.ARTIKELART_ARBEITSZEIT)) { bdVerkaufswertSollO = bdVerkaufswertSollO.add( aAuftragpositionDtos[i].getNNettoeinzelpreisplusversteckteraufschlagminusrabatte()); } } } } catch (RemoteException ex) { // exccatch: immer so! throwEJBExceptionLPRespectOld(ex); } myLogger.exit("Verkaufswert " + sArtikelartI + " Soll : " + bdVerkaufswertSollO.toString()); return bdVerkaufswertSollO; }
From source file:sg.ncl.MainController.java
private TeamQuota extractTeamQuotaInfo(String responseBody) { JSONObject object = new JSONObject(responseBody); TeamQuota teamQuota = new TeamQuota(); Double charges = Double.parseDouble(accountingProperties.getCharges()); // amountUsed from SIO will never be null => not checking for null value String usage = object.getString(KEY_USAGE); // getting usage in String BigDecimal amountUsed = new BigDecimal(usage); // using BigDecimal to handle currency amountUsed = amountUsed.multiply(new BigDecimal(charges)); // usage X charges //quota passed from SIO can be null , so we have to check for null value if (object.has(QUOTA)) { Object budgetObject = object.optString(QUOTA, null); if (budgetObject == null) { teamQuota.setBudget(""); // there is placeholder here teamQuota.setResourcesLeft("Unlimited"); // not placeholder so can pass string over } else {//from w w w . ja v a 2 s. c om Double budgetInDouble = object.getDouble(QUOTA); // retrieve budget from SIO in Double BigDecimal budgetInBD = BigDecimal.valueOf(budgetInDouble); // handling currency using BigDecimal // calculate resoucesLeft BigDecimal resourceLeftInBD = budgetInBD.subtract(amountUsed); resourceLeftInBD = resourceLeftInBD.divide(new BigDecimal(charges), 0, BigDecimal.ROUND_DOWN); budgetInBD = budgetInBD.setScale(2, BigDecimal.ROUND_HALF_UP); // set budget teamQuota.setBudget(budgetInBD.toString()); //set resroucesLeft if (resourceLeftInBD.compareTo(BigDecimal.valueOf(0)) < 0) teamQuota.setResourcesLeft("0"); else teamQuota.setResourcesLeft(resourceLeftInBD.toString()); } } //set teamId and amountUsed teamQuota.setTeamId(object.getString(TEAM_ID)); amountUsed = amountUsed.setScale(2, BigDecimal.ROUND_HALF_UP); teamQuota.setAmountUsed(amountUsed.toString()); return teamQuota; }
From source file:org.openbravo.financial.paymentreport.erpCommon.ad_reports.PaymentReportDao.java
/** * This method creates a field provider with the information of the transaction * /*from w w w. j av a 2 s . c o m*/ * @throws OBException */ private FieldProvider createFieldProviderForTransaction(FIN_FinaccTransaction transaction, String strGroupCrit, String strConvertCurrency, String strConversionDate) throws OBException { String dateFormatString = OBPropertiesProvider.getInstance().getOpenbravoProperties() .getProperty("dateFormat.java"); SimpleDateFormat dateFormat = new SimpleDateFormat(dateFormatString); BigDecimal transAmount = null; ConversionRate convRate = null; // call with null to return empty map without any link to a dal object FieldProvider transactionData = FieldProviderFactory.getFieldProvider(null); // bp_group -- bp_category if (transaction.getBusinessPartner() != null) { FieldProviderFactory.setField(transactionData, "BP_GROUP", transaction.getBusinessPartner().getBusinessPartnerCategory().getName()); // bpartner FieldProviderFactory.setField(transactionData, "BPARTNER", transaction.getBusinessPartner().getName()); } else { // bp_group -- bp_category & bpartner FieldProviderFactory.setField(transactionData, "BP_GROUP", ""); FieldProviderFactory.setField(transactionData, "BPARTNER", ""); } // transCurrency FieldProviderFactory.setField(transactionData, "TRANS_CURRENCY", transaction.getCurrency().getISOCode()); // paymentMethod FieldProviderFactory.setField(transactionData, "PAYMENT_METHOD", ""); // payment FieldProviderFactory.setField(transactionData, "PAYMENT", ""); // description FieldProviderFactory.setField(transactionData, "PAYMENT_DESC", transaction.getDescription()); // payment_id FieldProviderFactory.setField(transactionData, "PAYMENT_ID", ""); // payment_date FieldProviderFactory.setField(transactionData, "PAYMENT_DATE", dateFormat.format(transaction.getDateAcct())); // payment_docNo FieldProviderFactory.setField(transactionData, "PAYMENT_DOCNO", ""); // payment yes / no FieldProviderFactory.setField(transactionData, "PAYMENT_Y_N", "Display:None"); // financialAccount FieldProviderFactory.setField(transactionData, "FINANCIAL_ACCOUNT", transaction.getAccount().getName()); // status FieldProviderFactory.setField(transactionData, "STATUS", translateRefList(transaction.getStatus())); FieldProviderFactory.setField(transactionData, "STATUS_CODE", transaction.getStatus()); // is receipt if (transaction.getStatus().equals("PWNC")) { FieldProviderFactory.setField(transactionData, "ISRECEIPT", "Y"); // isReceipt = true; } else if (transaction.getStatus().equals("RDNC")) { FieldProviderFactory.setField(transactionData, "ISRECEIPT", "N"); // isReceipt = false; } // deposit/withdraw date FieldProviderFactory.setField(transactionData, "DEPOSIT_WITHDRAW_DATE", dateFormat.format(transaction.getDateAcct())); // project FieldProviderFactory.setField(transactionData, "PROJECT", ""); // salesPerson FieldProviderFactory.setField(transactionData, "SALES_PERSON", ""); // invoiceNumber. FieldProviderFactory.setField(transactionData, "INVOICE_NUMBER", ""); // payment plan id FieldProviderFactory.setField(transactionData, "PAYMENT_PLAN_ID", ""); // payment plan yes / no FieldProviderFactory.setField(transactionData, "PAYMENT_PLAN_Y_N", "Display:none"); // payment plan yes / no FieldProviderFactory.setField(transactionData, "NOT_PAYMENT_PLAN_Y_N", "Display:none"); // invoiceDate FieldProviderFactory.setField(transactionData, "INVOICE_DATE", ""); // dueDate. FieldProviderFactory.setField(transactionData, "DUE_DATE", dateFormat.format(transaction.getDateAcct())); // expectedDate. FieldProviderFactory.setField(transactionData, "EXPECTED_DATE", dateFormat.format(transaction.getDateAcct())); // plannedDSO FieldProviderFactory.setField(transactionData, "PLANNED_DSO", "0"); // currentDSO FieldProviderFactory.setField(transactionData, "CURRENT_DSO", "0"); // daysOverdue FieldProviderFactory.setField(transactionData, "OVERDUE", "0"); // transactional and base amounts transAmount = transaction.getDepositAmount().subtract(transaction.getPaymentAmount()); Currency baseCurrency = OBDal.getInstance().get(Currency.class, strConvertCurrency); boolean sameCurrency = baseCurrency.getISOCode().equalsIgnoreCase(transaction.getCurrency().getISOCode()); if (!sameCurrency) { convRate = this.getConversionRate(transaction.getCurrency(), baseCurrency, strConversionDate); if (convRate != null) { final int stdPrecission = convRate.getToCurrency().getStandardPrecision().intValue(); FieldProviderFactory.setField(transactionData, "TRANS_AMOUNT", transAmount.toString()); FieldProviderFactory.setField(transactionData, "BASE_AMOUNT", transAmount.multiply(convRate.getMultipleRateBy()) .setScale(stdPrecission, BigDecimal.ROUND_HALF_UP).toString()); } else { String message = transaction.getCurrency().getISOCode() + " -> " + baseCurrency.getISOCode() + " " + strConversionDate; throw new OBException(message); } } else { // convRate = null; FieldProviderFactory.setField(transactionData, "TRANS_AMOUNT", transAmount.toString()); FieldProviderFactory.setField(transactionData, "BASE_AMOUNT", transAmount.toString()); } // currency FieldProviderFactory.setField(transactionData, "BASE_CURRENCY", baseCurrency.getISOCode()); // group_crit_id this is the column that has the ids of the grouping criteria selected if (strGroupCrit.equalsIgnoreCase("APRM_FATS_BPARTNER")) { FieldProviderFactory.setField(transactionData, "GROUP_CRIT_ID", transactionData.getField("BPARTNER")); FieldProviderFactory.setField(transactionData, "GROUP_CRIT", "Business Partner"); } else if (strGroupCrit.equalsIgnoreCase("Project")) { FieldProviderFactory.setField(transactionData, "GROUP_CRIT_ID", transactionData.getField("PROJECT")); FieldProviderFactory.setField(transactionData, "GROUP_CRIT", "Project"); } else if (strGroupCrit.equalsIgnoreCase("FINPR_BPartner_Category")) { FieldProviderFactory.setField(transactionData, "GROUP_CRIT_ID", transactionData.getField("BP_GROUP")); FieldProviderFactory.setField(transactionData, "GROUP_CRIT", "Business Partner Category"); } else if (strGroupCrit.equalsIgnoreCase("INS_CURRENCY")) { FieldProviderFactory.setField(transactionData, "GROUP_CRIT_ID", transactionData.getField("TRANS_CURRENCY")); FieldProviderFactory.setField(transactionData, "GROUP_CRIT", "Currency"); } else if (strGroupCrit.equalsIgnoreCase("ACCS_ACCOUNT_ID_D")) { FieldProviderFactory.setField(transactionData, "GROUP_CRIT_ID", transactionData.getField("FINANCIAL_ACCOUNT")); FieldProviderFactory.setField(transactionData, "GROUP_CRIT", "Financial Account"); } else { FieldProviderFactory.setField(transactionData, "GROUP_CRIT_ID", ""); FieldProviderFactory.setField(transactionData, "GROUP_CRIT", ""); } return transactionData; }
From source file:org.opentaps.amazon.product.AmazonProductServices.java
/** * Service looks over AmzonProductPrice and collect product prices that haven't been posted yet, * creates XML document for Price Feed and post it to Amazon.com. * @param dctx a <code>DispatchContext</code> value * @param context the service context <code>Map</code> * @return the service response <code>Map</code> *///from w w w. j a v a 2 s .c o m public static Map<String, Object> publishProductPriceToAmazon(DispatchContext dctx, Map<String, Object> context) { Delegator delegator = dctx.getDelegator(); LocalDispatcher dispatcher = dctx.getDispatcher(); Locale locale = (Locale) context.get("locale"); GenericValue userLogin = (GenericValue) context.get("userLogin"); String prodId = (String) context.get("productId"); try { List<EntityCondition> conditions = UtilMisc.<EntityCondition>toList(EntityCondition.makeCondition( "statusId", EntityOperator.IN, Arrays.asList(AmazonConstants.statusProductCreated, AmazonConstants.statusProductChanged, AmazonConstants.statusProductError))); if (UtilValidate.isNotEmpty(prodId)) { conditions.add(EntityCondition.makeCondition("productId", EntityOperator.EQUALS, prodId)); } TransactionUtil.begin(); EntityListIterator amazonPriceIt = delegator.findListIteratorByCondition("AmazonProductPrice", EntityCondition.makeCondition(conditions, EntityOperator.AND), null, Arrays.asList("productId")); TransactionUtil.commit(); // Prepare Price Feed document long messageId = 1; Map<GenericValue, String> invalidAmazonPrices = new HashMap<GenericValue, String>(); List<GenericValue> validAmazonPrices = new ArrayList<GenericValue>(); Document priceFeed = AmazonConstants.soapClient.createDocumentHeader(AmazonConstants.messageTypePrice); Element root = priceFeed.getDocumentElement(); GenericValue amazonPrice = null; while ((amazonPrice = amazonPriceIt.next()) != null) { String errMessage = null; if (AmazonConstants.productPostRetryThreshold <= amazonPrice.getLong("postFailures").intValue()) { String errorLog = UtilProperties.getMessage(AmazonConstants.errorResource, "AmazonError_PostPriceAttemptsOverThreshold", UtilMisc.<String, Object>toMap("productId", amazonPrice.getString("productId"), "threshold", AmazonConstants.productPostRetryThreshold), locale); Debug.logInfo(errorLog, MODULE); continue; } // Ignore products marked deleted if (AmazonUtil.isAmazonProductDeleted(delegator, amazonPrice.getString("productId"))) { String errorLog = UtilProperties.getMessage(AmazonConstants.errorResource, "AmazonError_IgnoringProductPrice_ProductDeleted", UtilMisc.toMap("productId", amazonPrice.getString("productId")), locale); Debug.logError(errorLog, MODULE); continue; } // check if this product was exported and acknowledged earlier if (delegator.findCountByAnd("AmazonProduct", UtilMisc.toMap("productId", amazonPrice.getString("productId"), "statusId", AmazonConstants.statusProductPosted, "ackStatusId", AmazonConstants.statusProductAckRecv)) != 1) { String errorLog = UtilProperties.getMessage(AmazonConstants.errorResource, "AmazonError_PostPriceNonExistentProduct", UtilMisc.toMap("productId", amazonPrice.getString("productId")), locale); Debug.logError(errorLog, MODULE); continue; } /* * Some elements are required. So, we get it first and go to next iteration * if some of these is absent. */ String upc = null; if (AmazonConstants.requireUpcCodes || AmazonConstants.useUPCAsSKU) { // Establish and validate the UPC upc = getProductUPC(delegator, amazonPrice.getString("productId"), locale); if (UtilValidate.isEmpty(upc) && AmazonConstants.requireUpcCodes) { errMessage = AmazonUtil.compoundError(errMessage, UtilProperties.getMessage(AmazonConstants.errorResource, "AmazonError_MissingCodeUPC", UtilMisc.toMap("productId", amazonPrice.getString("productId")), locale)); } else if (UtilValidate.isNotEmpty(upc) && !UtilProduct.isValidUPC(upc)) { errMessage = AmazonUtil.compoundError(errMessage, UtilProperties.getMessage(AmazonConstants.errorResource, "AmazonError_InvalidCodeUPC", UtilMisc.toMap("productId", amazonPrice.getString("productId")), locale)); } } // Establish and validate the SKU String sku = getProductSKU(delegator, amazonPrice, upc); if (UtilValidate.isEmpty(sku) && !AmazonConstants.useUPCAsSKU) { errMessage = AmazonUtil .compoundError(errMessage, UtilProperties.getMessage(AmazonConstants.errorResource, "AmazonError_NoRequiredParameter", UtilMisc.toMap("parameterName", "SKU", "productName", amazonPrice.getString("productId")), locale)); } if (UtilValidate.isNotEmpty(errMessage)) { invalidAmazonPrices.put(amazonPrice, errMessage); continue; } // Standard price - filtered by date BigDecimal standardPrice = null; String standardPriceCurrency = null; // Try to find a price for the Amazon productStoreGroup first EntityCondition cond = EntityCondition.makeCondition(EntityOperator.AND, EntityCondition.makeCondition("productId", EntityOperator.EQUALS, amazonPrice.getString("productId")), EntityCondition.makeCondition("productPriceTypeId", EntityOperator.EQUALS, AmazonConstants.priceStandard), EntityCondition.makeCondition("productStoreGroupId", EntityOperator.EQUALS, AmazonConstants.priceProductStoreGroup), EntityUtil.getFilterByDateExpr()); GenericValue standardPriceVal = EntityUtil.getFirst(delegator.findByCondition("ProductPrice", cond, null, Arrays.asList("lastUpdatedStamp DESC"))); if (UtilValidate.isEmpty(standardPriceVal)) { // If there's no price for the Amazon productStoreGroup, try _NA_ cond = EntityCondition.makeCondition(EntityOperator.AND, EntityCondition.makeCondition("productId", EntityOperator.EQUALS, amazonPrice.getString("productId")), EntityCondition.makeCondition("productPriceTypeId", EntityOperator.EQUALS, AmazonConstants.priceStandard), EntityCondition.makeCondition("productStoreGroupId", EntityOperator.EQUALS, "_NA_"), EntityUtil.getFilterByDateExpr()); standardPriceVal = EntityUtil.getFirst(delegator.findByCondition("ProductPrice", cond, null, Arrays.asList("lastUpdatedStamp DESC"))); } if (UtilValidate.isNotEmpty(standardPriceVal)) { standardPrice = standardPriceVal.getBigDecimal("price").setScale(AmazonConstants.decimals, AmazonConstants.rounding); standardPriceCurrency = standardPriceVal.getString("currencyUomId"); } // Sale price - NOT filtered by date BigDecimal salePrice = null; String salePriceCurrency = null; String saleStartDate = null; String saleEndDate = null; cond = EntityCondition.makeCondition(EntityOperator.AND, EntityCondition.makeCondition("productId", EntityOperator.EQUALS, amazonPrice.getString("productId")), EntityCondition.makeCondition("productPriceTypeId", EntityOperator.EQUALS, AmazonConstants.priceSale), EntityCondition.makeCondition("productStoreGroupId", EntityOperator.EQUALS, AmazonConstants.priceProductStoreGroup)); GenericValue salePriceVal = EntityUtil.getFirst(delegator.findByCondition("ProductPrice", cond, null, Arrays.asList("lastUpdatedStamp DESC"))); if (UtilValidate.isNotEmpty(salePriceVal)) { salePrice = salePriceVal.getBigDecimal("price").setScale(AmazonConstants.decimals, AmazonConstants.rounding); salePriceCurrency = salePriceVal.getString("currencyUomId"); Timestamp fromDate = salePriceVal.getTimestamp("fromDate"); Timestamp thruDate = salePriceVal.getTimestamp("thruDate"); Timestamp now = UtilDateTime.nowTimestamp(); if (UtilValidate.isEmpty(thruDate)) { Debug.logInfo( UtilProperties.getMessage(AmazonConstants.errorResource, "AmazonError_PostPriceNoSaleEndDate", UtilMisc.toMap("productId", amazonPrice.getString("productId")), locale), MODULE); // Amazon requires an end date for the sale, so add twenty years or so saleEndDate = AmazonUtil .convertTimestampToXSDate(new Timestamp(now.getTime() + 631152000000L)); } else if (thruDate.before(now)) { Debug.logInfo( UtilProperties.getMessage(AmazonConstants.errorResource, "AmazonError_PostPriceSalePriceSkipped", UtilMisc.toMap("productId", amazonPrice.getString("productId"), "thruDate", thruDate), locale), MODULE); // The sale is over, so leave out the sale price so that it will be deleted in the Amazon system salePrice = null; } if (UtilValidate.isEmpty(fromDate)) { // Amazon requires a start date for the sale, so use the current time saleStartDate = AmazonUtil.convertTimestampToXSDate(now); } else { // Amazon requires dates to be in the future, so use the current time if the start date for the sale is past saleStartDate = AmazonUtil.convertTimestampToXSDate(fromDate.before(now) ? now : fromDate); } } /* * Create and add required elements and values */ Element message = priceFeed.createElement("Message"); root.appendChild(message); UtilXml.addChildElementValue(message, "MessageID", "" + messageId, priceFeed); Element price = priceFeed.createElement("Price"); message.appendChild(price); UtilXml.addChildElementValue(price, "SKU", sku, priceFeed); // Delist the product (set standard price to zero) if certain conditions are true boolean deListProduct = UtilValidate.isEmpty(standardPrice) || ((UtilValidate.isEmpty(salePriceVal) && AmazonConstants.delistProductIfNoSalePrice)); Element standardPriceElement = UtilXml.addChildElementValue(price, "StandardPrice", deListProduct ? "0.0" : standardPrice.toString(), priceFeed); standardPriceElement.setAttribute("currency", UtilValidate.isNotEmpty(standardPriceCurrency) ? standardPriceCurrency : UtilProperties.getPropertyValue("opentaps.properties", "defaultCurrencyUomId")); if (UtilValidate.isEmpty(standardPrice)) { standardPriceElement.setAttribute("zero", "true"); } if (UtilValidate.isNotEmpty(salePrice)) { Element sale = priceFeed.createElement("Sale"); price.appendChild(sale); UtilXml.addChildElementValue(sale, "StartDate", saleStartDate, priceFeed); UtilXml.addChildElementValue(sale, "EndDate", saleEndDate, priceFeed); Element salePriceElement = UtilXml.addChildElementValue(sale, "SalePrice", salePrice.toString(), priceFeed); salePriceElement.setAttribute("currency", salePriceCurrency); } amazonPrice.set("acknowledgeMessageId", "" + messageId); validAmazonPrices.add(amazonPrice); messageId++; if (messageId % 500 == 0) { Debug.logInfo(UtilProperties.getMessage(AmazonConstants.errorResource, "AmazonError_Processed_Records_Price", UtilMisc.toMap("count", messageId), locale), MODULE); } } amazonPriceIt.close(); LinkedHashMap<GenericValue, String> emailErrorMessages = new LinkedHashMap<GenericValue, String>(); if (UtilValidate.isEmpty(validAmazonPrices)) { String infoMessage = UtilProperties.getMessage(AmazonConstants.errorResource, "AmazonError_PostNoNewPrices", locale); Debug.logInfo(infoMessage, MODULE); } else { boolean success = true; String postErrorMessage = null; long processingDocumentId = -1; try { String xml = UtilXml.writeXmlDocument(priceFeed); Debug.logVerbose(xml, MODULE); Writer writer = new OutputStreamWriter(new FileOutputStream(AmazonConstants.xmlOutputLocation + "AmazonPriceFeed_" + AmazonConstants.xmlOutputDateFormat.format(new Date()) + ".xml"), "UTF-8"); writer.write(xml); writer.close(); processingDocumentId = AmazonConstants.soapClient.postProductPrices(xml); Debug.logInfo(UtilProperties.getMessage(AmazonConstants.errorResource, "AmazonError_ProcessingDocumentId_Price", UtilMisc.toMap("processingDocumentId", processingDocumentId), locale), MODULE); } catch (RemoteException e) { success = false; postErrorMessage = e.getMessage(); List<String> productIds = EntityUtil.getFieldListFromEntityList(validAmazonPrices, "productId", true); String errorLog = UtilProperties.getMessage(AmazonConstants.errorResource, "AmazonError_PostPriceError", UtilMisc.toMap("productIds", productIds, "errorMessage", postErrorMessage), locale); Debug.logError(errorLog, MODULE); } // Store operational data of the post attempt for (GenericValue validAmazonPrice : validAmazonPrices) { validAmazonPrice.set("statusId", success ? AmazonConstants.statusProductPosted : AmazonConstants.statusProductError); validAmazonPrice.set("postTimestamp", UtilDateTime.nowTimestamp()); validAmazonPrice.set("postErrorMessage", success ? null : postErrorMessage); if (!success) { validAmazonPrice.set("postFailures", validAmazonPrice.getLong("postFailures") + 1); } validAmazonPrice.set("processingDocumentId", success ? processingDocumentId : null); validAmazonPrice.set("ackStatusId", AmazonConstants.statusProductNotAcked); validAmazonPrice.set("acknowledgeTimestamp", null); validAmazonPrice.set("acknowledgeErrorMessage", null); validAmazonPrice.store(); if (AmazonConstants.sendErrorEmails && !success) { emailErrorMessages.put(validAmazonPrice, postErrorMessage); } } } for (GenericValue invalidAmazonPrice : invalidAmazonPrices.keySet()) { String errorMessage = invalidAmazonPrices.get(invalidAmazonPrice); invalidAmazonPrice.set("statusId", AmazonConstants.statusProductError); invalidAmazonPrice.set("postTimestamp", UtilDateTime.nowTimestamp()); invalidAmazonPrice.set("postErrorMessage", errorMessage); invalidAmazonPrice.set("postFailures", invalidAmazonPrice.getLong("postFailures") + 1); invalidAmazonPrice.set("processingDocumentId", null); invalidAmazonPrice.set("ackStatusId", AmazonConstants.statusProductNotAcked); invalidAmazonPrice.set("acknowledgeTimestamp", null); invalidAmazonPrice.set("acknowledgeErrorMessage", null); invalidAmazonPrice.store(); if (AmazonConstants.sendErrorEmails) { emailErrorMessages.put(invalidAmazonPrice, errorMessage); } } if (AmazonConstants.sendErrorEmails && UtilValidate.isNotEmpty(emailErrorMessages)) { AmazonUtil.sendBulkErrorEmail(dispatcher, userLogin, emailErrorMessages, UtilProperties.getMessage(AmazonConstants.errorResource, "AmazonError_ErrorEmailSubject_PostPrice", AmazonConstants.errorEmailLocale), AmazonConstants.errorEmailScreenUriProducts); } } catch (GenericEntityException gee) { UtilMessage.createAndLogServiceError(gee, locale, MODULE); } catch (IOException ioe) { UtilMessage.createAndLogServiceError(ioe, locale, MODULE); } catch (GenericServiceException gse) { UtilMessage.createAndLogServiceError(gse, locale, MODULE); } return ServiceUtil.returnSuccess(); }
From source file:com.lp.server.auftrag.ejbfac.AuftragFacBean.java
/** * Fuer die Nachkalkulation des Auftrags den Soll-Gestehungspreis (= * Gestehungspreis am Hauptlager des Mandanten pro Stueck * geplanter Menge) * bezogen auf eine bestimmte Artikelart berechnen. <br> * Beruecksichtigt werden alle mengenbehafteten Auftragpositionen. * /*from w ww . ja v a 2 s. co m*/ * @param iIdAuftragI * PK des Auftrags * @param sArtikelartI * die gewuenschte Artikelart * @param theClientDto * der aktuelle Benutzer * @return BigDecimal der Gestehungswert der Artikelart Soll in * Auftragswaherung * @throws EJBExceptionLP * Ausnahme */ public BigDecimal berechneGestehungswertSoll(Integer iIdAuftragI, String sArtikelartI, boolean bMitEigengefertigtenStuecklisten, TheClientDto theClientDto) throws EJBExceptionLP { final String METHOD_NAME = "berechneGestehungswertSoll"; myLogger.entry(); if (iIdAuftragI == null) { throw new EJBExceptionLP(EJBExceptionLP.FEHLER_PARAMETER_IS_NULL, new Exception("iIdAuftragI == null")); } if (sArtikelartI == null) { throw new EJBExceptionLP(EJBExceptionLP.FEHLER_PARAMETER_IS_NULL, new Exception("sArtikelartI == null")); } BigDecimal bdGestehungswertSollO = Helper.getBigDecimalNull(); try { AuftragDto auftragDto = auftragFindByPrimaryKey(iIdAuftragI); AuftragpositionDto[] aAuftragpositionDtos = getAuftragpositionFac() .auftragpositionFindByAuftrag(iIdAuftragI); for (int i = 0; i < aAuftragpositionDtos.length; i++) { // alle mengenbehafteten Positionen beruecksichtigen if (aAuftragpositionDtos[i].getNMenge() != null && aAuftragpositionDtos[i].getArtikelIId() != null) { ArtikelDto oArtikelDto = getArtikelFac() .artikelFindByPrimaryKey(aAuftragpositionDtos[i].getArtikelIId(), theClientDto); if (bMitEigengefertigtenStuecklisten == false) { StuecklisteDto stklDto = getStuecklisteFac() .stuecklisteFindByMandantCNrArtikelIIdOhneExc(oArtikelDto.getIId(), theClientDto); if (stklDto != null && Helper.short2boolean(stklDto.getBFremdfertigung()) == false) { continue; } } // das Hauptlager des Mandanten LagerDto oHauptlagerDto = getLagerFac().getHauptlagerDesMandanten(theClientDto); // Grundlage ist der Gestehungspreis des Artikels am // Hauptlager des Mandanten BigDecimal bdGestehungspreisSoll = new BigDecimal(0); if (aAuftragpositionDtos[i].getPositioniIdArtikelset() == null) { Query query = em.createNamedQuery("AuftragpositionfindByPositionIIdArtikelset"); query.setParameter(1, aAuftragpositionDtos[i].getIId()); Collection<?> angebotpositionDtos = query.getResultList(); AuftragpositionDto[] zugehoerigeABPosDtos = AuftragpositionDtoAssembler .createDtos(angebotpositionDtos); if (zugehoerigeABPosDtos.length == 0) { bdGestehungspreisSoll = getLagerFac().getGestehungspreisZumZeitpunkt( oArtikelDto.getIId(), oHauptlagerDto.getIId(), auftragDto.getTBelegdatum(), theClientDto); } else { for (int k = 0; k < zugehoerigeABPosDtos.length; k++) { bdGestehungspreisSoll = bdGestehungspreisSoll .add(getLagerFac().getGestehungspreisZumZeitpunkt( zugehoerigeABPosDtos[k].getArtikelIId(), oHauptlagerDto.getIId(), auftragDto.getTBelegdatum(), theClientDto)); } } } // je nach Artikelart beruecksichtigen if (bdGestehungspreisSoll != null) { BigDecimal bdBeitragDieserPosition = aAuftragpositionDtos[i].getNMenge() .multiply(bdGestehungspreisSoll); if (sArtikelartI.equals(ArtikelFac.ARTIKELART_ARBEITSZEIT)) { if (oArtikelDto.getArtikelartCNr().equals(ArtikelFac.ARTIKELART_ARBEITSZEIT)) { bdGestehungswertSollO = bdGestehungswertSollO.add(bdBeitragDieserPosition); } } else { if (!oArtikelDto.getArtikelartCNr().equals(ArtikelFac.ARTIKELART_ARBEITSZEIT)) { bdGestehungswertSollO = bdGestehungswertSollO.add(bdBeitragDieserPosition); } } } } } } catch (RemoteException ex) { // exccatch: immer so! throwEJBExceptionLPRespectOld(ex); } myLogger.exit("Gestehungswert " + sArtikelartI + " Soll : " + bdGestehungswertSollO.toString()); return bdGestehungswertSollO; }