Search in sources :

Example 1 with TallyMessage

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;
}
Also used : TallyMessage(org.mifos.platform.accounting.tally.message.TallyMessage) TallyMessageBuilder(org.mifos.platform.accounting.tally.message.TallyMessageBuilder) ArrayList(java.util.ArrayList) AccountingDto(org.mifos.platform.accounting.AccountingDto) VoucherType(org.mifos.platform.accounting.VoucherType)

Example 2 with TallyMessage

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();
}
Also used : StringWriter(java.io.StringWriter) TallyMessage(org.mifos.platform.accounting.tally.message.TallyMessage) HashMap(java.util.HashMap) TemplateException(freemarker.template.TemplateException) IOException(java.io.IOException) AccountingRuntimeException(org.mifos.platform.accounting.AccountingRuntimeException) Template(freemarker.template.Template)

Aggregations

TallyMessage (org.mifos.platform.accounting.tally.message.TallyMessage)2 Template (freemarker.template.Template)1 TemplateException (freemarker.template.TemplateException)1 IOException (java.io.IOException)1 StringWriter (java.io.StringWriter)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 AccountingDto (org.mifos.platform.accounting.AccountingDto)1 AccountingRuntimeException (org.mifos.platform.accounting.AccountingRuntimeException)1 VoucherType (org.mifos.platform.accounting.VoucherType)1 TallyMessageBuilder (org.mifos.platform.accounting.tally.message.TallyMessageBuilder)1