| | |
| | | setNumeric(sheet, row.getRowNum(), yearColumn, values.get(day.getValue())); |
| | | } |
| | | if (comparisonBaseColumn != null && HolidayConstants.supportsComparisonBase(year)) { |
| | | // Column C (comparison base) is written as an operator backup value only. The ring |
| | | // ratio in column E always compares the current day with the previous day row of |
| | | // the same year, so the base never changes the calculated percentage. |
| | | Map<LocalDate, BigDecimal> bases = loadComparisonBaseValues(year); |
| | | for (Map.Entry<Integer, LocalDate> day : dayDates.entrySet()) { |
| | | if (!bases.containsKey(day.getValue())) continue; |
| | |
| | | if (row == null) continue; |
| | | setNumeric(sheet, row.getRowNum(), comparisonBaseColumn, bases.get(day.getValue())); |
| | | } |
| | | Integer previousRowIndex = null; |
| | | for (Map.Entry<Integer, LocalDate> day : dayDates.entrySet()) { |
| | | if (!bases.containsKey(day.getValue())) continue; |
| | | Row row = findDayRow(sheet, evaluator, day.getKey()); |
| | | if (row == null) continue; |
| | | int rowIndex = row.getRowNum(); |
| | | int excelRow = rowIndex + 1; |
| | | setFormula(sheet, rowIndex, 4, "=(D" + excelRow + "-C" + excelRow + ")/C" + excelRow); |
| | | if (row == null) { |
| | | previousRowIndex = null; |
| | | continue; |
| | | } |
| | | if (previousRowIndex != null) { |
| | | setFormula(sheet, row.getRowNum(), 4, |
| | | ringRatioFormula(row.getRowNum() + 1, previousRowIndex + 1)); |
| | | } |
| | | previousRowIndex = row.getRowNum(); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | |
| | | // Ring ratio = (current day value - previous day value) / previous day value, always taken |
| | | // from the active year column (D). This intentionally ignores the comparison base column. |
| | | static String ringRatioFormula(int excelRow, int previousExcelRow) { |
| | | return "=(D" + excelRow + "-D" + previousExcelRow + ")/D" + previousExcelRow; |
| | | } |
| | | |
| | | private void fillCoefficients(XSSFWorkbook workbook, FormulaEvaluator evaluator, int selectedYear, String holidayType) { |
| | |
| | | if (row == null) row = sheet.createRow(rowIndex); |
| | | Cell cell = row.getCell(columnIndex); |
| | | if (cell == null) cell = row.createCell(columnIndex); |
| | | cell.setCellFormula(formula); |
| | | // POI's setCellFormula rejects a leading '='; the helper accepts either form. |
| | | String normalized = formula.startsWith("=") ? formula.substring(1) : formula; |
| | | cell.setCellFormula(normalized); |
| | | } |
| | | |
| | | private Map<String, Object> toMap(HolidayCalendar calendar) { |