use of org.mifos.platform.accounting.tally.message.TallyMessage 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;
}
use of org.mifos.platform.accounting.tally.message.TallyMessage in project head by mifos.
the class TallyXMLGenerator method getTallyXML.
public static String getTallyXML(List<AccountingDto> accountingData, String fileName) {
Template temp = getTemplate("master.template");
String masterData = "";
try {
List<TallyMessage> tallyMessages = TALLY_MESSAGE_GENERATOR.generateTallyMessages(accountingData);
masterData = getMasterData(tallyMessages, fileName);
} catch (Exception e) {
masterData = "Contact admin: There was an error encountered :";
masterData += e.getMessage();
return masterData;
}
/* Create a data-model */
Map<String, Object> root = new HashMap<String, Object>();
Map<String, Object> tallyMessage = new HashMap<String, Object>();
root.put("tallyMessage", tallyMessage);
tallyMessage.put("headOfficeName", "HEAD OFFICE");
tallyMessage.put("data", masterData);
StringWriter bow = new StringWriter();
process(temp, root, bow);
return bow.toString();
}
Aggregations