PageRenderTime 40ms CodeModel.GetById 0ms RepoModel.GetById 1ms app.codeStats 0ms

/src/skala/erp/bmp/server/excellexporters/ProdTableExcellExporter.java

https://bitbucket.org/ignatenko/bmp
Java | 131 lines | 106 code | 25 blank | 0 comment | 1 complexity | 29b22e9f7679062a37f97e05c6ab1f35 MD5 | raw file
  1. package skala.erp.bmp.server.excellexporters;
  2. import java.io.FileOutputStream;
  3. import java.text.SimpleDateFormat;
  4. import java.util.List;
  5. import java.util.Map;
  6. import org.apache.poi.hpsf.SummaryInformation;
  7. import org.apache.poi.hssf.usermodel.HSSFRow;
  8. import org.apache.poi.hssf.usermodel.HSSFSheet;
  9. import org.apache.poi.hssf.usermodel.HSSFWorkbook;
  10. import org.apache.poi.ss.usermodel.Cell;
  11. import org.apache.poi.ss.usermodel.CellStyle;
  12. import org.apache.poi.ss.usermodel.PrintSetup;
  13. import org.apache.poi.ss.util.CellRangeAddress;
  14. import skala.erp.bmp.server.dao.InventTableDAO;
  15. import skala.erp.bmp.server.dao.ProdBOMDAO;
  16. import skala.erp.bmp.server.dao.ProdTableDAO;
  17. import skala.erp.bmp.shared.entity.InventTable;
  18. import skala.erp.bmp.shared.entity.ProdBOM;
  19. import skala.erp.bmp.shared.entity.ProdTable;
  20. public class ProdTableExcellExporter extends ExcelExporter {
  21. ProdBOMDAO prodBOMDAO;
  22. ProdTableDAO prodTableDAO;
  23. InventTableDAO inventTableDAO;
  24. public ProdTableExcellExporter(ProdTableDAO prodTableDAO,
  25. ProdBOMDAO prodBOMDAO, InventTableDAO inventTableDAO) {
  26. this.prodBOMDAO = prodBOMDAO;
  27. this.prodTableDAO = prodTableDAO;
  28. this.inventTableDAO = inventTableDAO;
  29. }
  30. public String getProdOrderReportFilename(String orderId, String dataAreaId) {
  31. String filename = "prodOrder-" + orderId + ".xls";
  32. HSSFWorkbook hwb = new HSSFWorkbook();
  33. Map<String, CellStyle> styles = createStyles(hwb);
  34. hwb.createInformationProperties();
  35. SummaryInformation summaryInfo = hwb.getSummaryInformation();
  36. summaryInfo.setAuthor("BMP-System");
  37. HSSFSheet sheet = hwb.createSheet("Производство");
  38. PrintSetup printSetup = sheet.getPrintSetup();
  39. printSetup.setLandscape(false);
  40. sheet.setFitToPage(true);
  41. sheet.setHorizontallyCenter(true);
  42. int rowIndex = 0;
  43. SimpleDateFormat dateFormat = new SimpleDateFormat("dd.MM.YYYY");
  44. ProdTable prod = prodTableDAO.find(orderId, dataAreaId);
  45. InventTable producedItem = inventTableDAO.find(prod.getBOMId(),
  46. dataAreaId);
  47. addHeaderRow(
  48. styles.get("title"),
  49. sheet,
  50. rowIndex,
  51. "Производственный заказ №" + orderId + " от "
  52. + dateFormat.format(prod.getStUpDate()));
  53. rowIndex++;
  54. addHeaderRow(styles.get("title"), sheet, rowIndex, prod.getBOMId()
  55. + " (" + producedItem.getName() + ")");
  56. rowIndex++;
  57. addHeaderRow(styles.get("title"), sheet, rowIndex, "Количество: "
  58. + prod.getQtyStUp() + " " + producedItem.getUOMId());
  59. rowIndex++;
  60. HSSFRow inventHeaderRow = sheet.createRow(rowIndex);
  61. inventHeaderRow.setHeightInPoints(30);
  62. Cell cell = inventHeaderRow.createCell(0);
  63. cell.setCellValue("Номенклатура");
  64. cell.setCellStyle(styles.get("header"));
  65. fillEmptyCells(inventHeaderRow, styles.get("header"), 1, 4);
  66. sheet.addMergedRegion(CellRangeAddress.valueOf("$A$" + (rowIndex + 1)
  67. + ":$E$" + (rowIndex + 1)));
  68. cell = inventHeaderRow.createCell(5);
  69. cell.setCellValue("Количество");
  70. cell.setCellStyle(styles.get("header"));
  71. cell = inventHeaderRow.createCell(6);
  72. cell.setCellValue("Ед. изм.");
  73. cell.setCellStyle(styles.get("header"));
  74. rowIndex++;
  75. List<ProdBOM> list = prodBOMDAO.findByProdId(orderId, dataAreaId);
  76. for (ProdBOM bom : list) {
  77. InventTable item = inventTableDAO.find(bom.getItemId(), dataAreaId);
  78. HSSFRow currentRow = sheet.createRow(rowIndex);
  79. currentRow.setHeightInPoints(30);
  80. cell = currentRow.createCell(0);
  81. cell.setCellStyle(styles.get("cell_left"));
  82. cell.setCellValue(item.getName());
  83. fillEmptyCells(currentRow, styles.get("cell_left"), 1, 4);
  84. sheet.addMergedRegion(CellRangeAddress.valueOf("$A$"
  85. + (rowIndex + 1) + ":$E$" + (rowIndex + 1)));
  86. cell = currentRow.createCell(5);
  87. cell.setCellStyle(styles.get("cell"));
  88. cell.setCellValue(bom.getQty());
  89. cell = currentRow.createCell(6);
  90. cell.setCellStyle(styles.get("cell"));
  91. cell.setCellValue(item.getUOMId());
  92. rowIndex++;
  93. }
  94. sheet.autoSizeColumn(0);
  95. sheet.autoSizeColumn(5);
  96. sheet.autoSizeColumn(6);
  97. try {
  98. FileOutputStream fileOutputStream = new FileOutputStream(filename);
  99. hwb.write(fileOutputStream);
  100. fileOutputStream.close();
  101. } catch (Exception e) {
  102. e.printStackTrace();
  103. }
  104. return filename;
  105. }
  106. }