| | |
| | | if (startMonth.isAfter(endMonth)) { |
| | | throw new ServiceException("开始月份不能大于结束月份"); |
| | | } |
| | | return buildLedgerRows(queryDto.getSubjectCode(), startMonth, endMonth, null, null); |
| | | return Collections.singletonList(buildGeneralLedgerTotalRow(queryDto.getSubjectCode(), startMonth, endMonth)); |
| | | } |
| | | |
| | | @Override |
| | |
| | | return rows; |
| | | } |
| | | |
| | | private FinLedgerRowVo buildGeneralLedgerTotalRow(String subjectCode, YearMonth startMonth, YearMonth endMonth) { |
| | | LocalDate startDate = startMonth.atDay(1); |
| | | LocalDate endDate = endMonth.atEndOfMonth(); |
| | | |
| | | List<FinLedgerEntryRecordVo> openingEntries = finVoucherEntryMapper.listPostedEntriesBefore( |
| | | subjectCode, startDate, null, null |
| | | ); |
| | | BigDecimal openingBalance = calculateBalance(openingEntries); |
| | | |
| | | List<FinLedgerEntryRecordVo> currentPeriodEntries = finVoucherEntryMapper.listPostedEntries( |
| | | subjectCode, startDate, endDate, null, null |
| | | ); |
| | | |
| | | BigDecimal totalDebit = ZERO; |
| | | BigDecimal totalCredit = ZERO; |
| | | for (FinLedgerEntryRecordVo entry : currentPeriodEntries) { |
| | | totalDebit = totalDebit.add(money(entry.getDebit())); |
| | | totalCredit = totalCredit.add(money(entry.getCredit())); |
| | | } |
| | | |
| | | BigDecimal endingBalance = openingBalance.add(totalDebit).subtract(totalCredit); |
| | | FinLedgerRowVo totalRow = new FinLedgerRowVo(); |
| | | totalRow.setRowType("yearly_total"); |
| | | totalRow.setDate(endDate); |
| | | totalRow.setDebit(money(totalDebit)); |
| | | totalRow.setCredit(money(totalCredit)); |
| | | totalRow.setBalance(money(endingBalance)); |
| | | totalRow.setDirection(resolveDirection(endingBalance)); |
| | | return totalRow; |
| | | } |
| | | |
| | | private Map<YearMonth, List<FinLedgerEntryRecordVo>> groupEntriesByMonth(List<FinLedgerEntryRecordVo> entries) { |
| | | Map<YearMonth, List<FinLedgerEntryRecordVo>> map = new LinkedHashMap<>(); |
| | | for (FinLedgerEntryRecordVo entry : entries) { |