use of org.mifos.platform.accounting.tally.message.TallyMessageBuilder in project head by mifos.
the class TallyMessageGenerator method generateTallyMessages.
public final List<TallyMessage> generateTallyMessages(List<AccountingDto> accountingData) throws TallyMessageBuilderException, ParseException {
List<TallyMessage> tallyMessages = new ArrayList<TallyMessage>();
for (int i = 1; i < accountingData.size(); i++) {
List<AccountingDto> voucher = new ArrayList<AccountingDto>();
voucher.add(accountingData.get(i - 1));
AccountingDto prevLine = accountingData.get(i - 1);
AccountingDto currentLine = accountingData.get(i);
while (i < accountingData.size() && prevLine.getBranchName().equals(currentLine.getBranchName()) && prevLine.getVoucherDate().equals(currentLine.getVoucherDate()) && prevLine.getVoucherType().equals(currentLine.getVoucherType())) {
voucher.add(currentLine);
i++;
prevLine = accountingData.get(i - 1);
if (i < accountingData.size()) {
currentLine = accountingData.get(i);
}
}
VoucherType voucherType = getVoucherType(voucher.get(0).getVoucherType());
TallyMessageBuilder builder = new TallyMessageBuilder(voucherType, voucher.get(0).getBranchName());
builder.withVoucherDate(getVoucherDate(voucher.get(0).getVoucherDate()));
for (AccountingDto voucherEntry : voucher) {
builder.addCreditEntry(voucherEntry);
builder.addDebitEntry(voucherEntry);
}
tallyMessages.add(builder.build());
}
return tallyMessages;
}
Aggregations