From 328f294e1abc4bf101b8d0317cc5eccc2f1d5c17 Mon Sep 17 00:00:00 2001 From: Vishwas Babu AJ Date: Sun, 24 Feb 2013 14:22:38 +0530 Subject: [PATCH] fixing minor issues detected while testing cash based accounting --- .../patches/13-more-jounal-entry-updates.sql | 11 +++++++++++ .../journalentry/data/JournalEntryData.java | 4 ++-- .../journalentry/domain/JournalEntry.java | 10 +++++----- .../JournalEntryReadPlatformServiceImpl.java | 19 ++++++++++++------- ...WritePlatformServiceJpaRepositoryImpl.java | 15 ++++++--------- 5 files changed, 36 insertions(+), 23 deletions(-) create mode 100755 mifosng-db/patches/13-more-jounal-entry-updates.sql diff --git a/mifosng-db/patches/13-more-jounal-entry-updates.sql b/mifosng-db/patches/13-more-jounal-entry-updates.sql new file mode 100755 index 000000000..c41bd87ef --- /dev/null +++ b/mifosng-db/patches/13-more-jounal-entry-updates.sql @@ -0,0 +1,11 @@ +update acc_gl_journal_entry +set acc_gl_journal_entry.entity_type=1 +where acc_gl_journal_entry.entity_type='LOAN'; + +ALTER TABLE `acc_gl_journal_entry` + ALTER `type_enum` DROP DEFAULT; +ALTER TABLE `acc_gl_journal_entry` + CHANGE COLUMN `type_enum` `type_enum` SMALLINT(5) NOT NULL AFTER `entry_date`, + CHANGE COLUMN `entity_type` `entity_type_enum` SMALLINT(5) NULL DEFAULT NULL AFTER `description`; + + diff --git a/mifosng-provider/src/main/java/org/mifosplatform/accounting/journalentry/data/JournalEntryData.java b/mifosng-provider/src/main/java/org/mifosplatform/accounting/journalentry/data/JournalEntryData.java index 479498d1c..6a7792e6c 100755 --- a/mifosng-provider/src/main/java/org/mifosplatform/accounting/journalentry/data/JournalEntryData.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/accounting/journalentry/data/JournalEntryData.java @@ -43,7 +43,7 @@ public class JournalEntryData { @SuppressWarnings("unused") private final Boolean manualEntry; @SuppressWarnings("unused") - private final String entityType; + private final EnumOptionData entityType; @SuppressWarnings("unused") private final Long entityId; @SuppressWarnings("unused") @@ -60,7 +60,7 @@ public class JournalEntryData { public JournalEntryData(final Long id, final Long officeId, final String officeName, final String glAccountName, final Long glAccountId, final String glAccountCode, final EnumOptionData glAccountClassification, final LocalDate transactionDate, final EnumOptionData entryType, final BigDecimal amount, final String transactionId, - final Boolean manualEntry, final String entityType, final Long entityId, final Long createdByUserId, + final Boolean manualEntry, final EnumOptionData entityType, final Long entityId, final Long createdByUserId, final LocalDate createdDate, final String createdByUserName, final String comments, final Boolean reversed) { this.id = id; this.officeId = officeId; diff --git a/mifosng-provider/src/main/java/org/mifosplatform/accounting/journalentry/domain/JournalEntry.java b/mifosng-provider/src/main/java/org/mifosplatform/accounting/journalentry/domain/JournalEntry.java index 0ec0ba9ee..6a9227754 100755 --- a/mifosng-provider/src/main/java/org/mifosplatform/accounting/journalentry/domain/JournalEntry.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/accounting/journalentry/domain/JournalEntry.java @@ -67,8 +67,8 @@ public class JournalEntry extends AbstractAuditableCustom { private String description; @SuppressWarnings("unused") - @Column(name = "entity_type", length = 50) - private String entityType; + @Column(name = "entity_type_enum", length = 50) + private Integer entityType; @SuppressWarnings("unused") @Column(name = "entity_id") @@ -76,7 +76,7 @@ public class JournalEntry extends AbstractAuditableCustom { public static JournalEntry createNew(final Office office, final GLAccount glAccount, final String transactionId, final boolean manualEntry, final Date transactionDate, final JournalEntryType journalEntryType, final BigDecimal amount, - final String description, final String entityType, final Long entityId) { + final String description, final Integer entityType, final Long entityId) { return new JournalEntry(office, glAccount, transactionId, manualEntry, transactionDate, journalEntryType.getValue(), amount, description, entityType, entityId); } @@ -86,7 +86,7 @@ public class JournalEntry extends AbstractAuditableCustom { } public JournalEntry(final Office office, final GLAccount glAccount, final String transactionId, final boolean manualEntry, - final Date transactionDate, final Integer type, final BigDecimal amount, final String description, final String entityType, + final Date transactionDate, final Integer type, final BigDecimal amount, final String description, final Integer entityType, final Long entityId) { this.office = office; this.glAccount = glAccount; @@ -98,7 +98,7 @@ public class JournalEntry extends AbstractAuditableCustom { this.type = type; this.amount = amount; this.description = StringUtils.defaultIfEmpty(description, null); - this.entityType = StringUtils.defaultIfEmpty(entityType, null); + this.entityType = entityType; this.entityId = entityId; } diff --git a/mifosng-provider/src/main/java/org/mifosplatform/accounting/journalentry/service/JournalEntryReadPlatformServiceImpl.java b/mifosng-provider/src/main/java/org/mifosplatform/accounting/journalentry/service/JournalEntryReadPlatformServiceImpl.java index 6bb5ea510..271a5f810 100755 --- a/mifosng-provider/src/main/java/org/mifosplatform/accounting/journalentry/service/JournalEntryReadPlatformServiceImpl.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/accounting/journalentry/service/JournalEntryReadPlatformServiceImpl.java @@ -45,7 +45,7 @@ public class JournalEntryReadPlatformServiceImpl implements JournalEntryReadPlat + " journalEntry.office_id as officeId, office.name as officeName, " + " journalEntry.manual_entry as manualEntry,journalEntry.entry_date as transactionDate, " + " journalEntry.type_enum as entryType,journalEntry.amount as amount, journalEntry.transaction_id as transactionId," - + " journalEntry.entity_type as entityType, journalEntry.entity_id as entityId, creatingUser.id as createdByUserId, " + + " journalEntry.entity_type_enum as entityType, journalEntry.entity_id as entityId, creatingUser.id as createdByUserId, " + " creatingUser.username as createdByUserName, journalEntry.description as comments, " + " journalEntry.created_date as createdDate, journalEntry.reversed as reversed " + " from acc_gl_journal_entry journalEntry, acc_gl_account glAccount, m_office office, m_appuser creatingUser " @@ -70,7 +70,12 @@ public class JournalEntryReadPlatformServiceImpl implements JournalEntryReadPlat final int entryTypeId = JdbcSupport.getInteger(rs, "entryType"); final EnumOptionData entryType = AccountingEnumerations.journalEntryType(entryTypeId); final String transactionId = rs.getString("transactionId"); - final String entityType = rs.getString("entityType"); + final Integer entityTypeId = JdbcSupport.getInteger(rs, "entityType"); + EnumOptionData entityType = null; + if (entityTypeId != null) { + entityType = AccountingEnumerations.portfolioProductType(entityTypeId); + } + final Long entityId = JdbcSupport.getLong(rs, "entityId"); final Long createdByUserId = rs.getLong("createdByUserId"); final LocalDate createdDate = JdbcSupport.getLocalDate(rs, "createdDate"); @@ -79,14 +84,14 @@ public class JournalEntryReadPlatformServiceImpl implements JournalEntryReadPlat final Boolean reversed = rs.getBoolean("reversed"); return new JournalEntryData(journalEntryId, officeId, officeName, glAccountName, glAccountId, glCode, accountType, - transactionDate, entryType, amount, transactionId, manualEntry, entityType, entityId, createdByUserId, - createdDate, createdByUserName, comments, reversed); + transactionDate, entryType, amount, transactionId, manualEntry, entityType, entityId, createdByUserId, createdDate, + createdByUserName, comments, reversed); } } @Override - public List retrieveAllGLJournalEntries(final Long officeId, final Long glAccountId, - final Boolean onlyManualEntries, final Date fromDate, final Date toDate) { + public List retrieveAllGLJournalEntries(final Long officeId, final Long glAccountId, final Boolean onlyManualEntries, + final Date fromDate, final Date toDate) { final GLJournalEntryMapper rm = new GLJournalEntryMapper(); String sql = "select " + rm.schema(); @@ -133,7 +138,7 @@ public class JournalEntryReadPlatformServiceImpl implements JournalEntryReadPlat if (onlyManualEntries != null) { if (onlyManualEntries) { sql += " and journalEntry.manual_entry = 1"; - } + } } sql += " order by journalEntry.entry_date desc,journalEntry.id desc"; diff --git a/mifosng-provider/src/main/java/org/mifosplatform/accounting/journalentry/service/JournalEntryWritePlatformServiceJpaRepositoryImpl.java b/mifosng-provider/src/main/java/org/mifosplatform/accounting/journalentry/service/JournalEntryWritePlatformServiceJpaRepositoryImpl.java index 92fd10edc..8a6230eac 100755 --- a/mifosng-provider/src/main/java/org/mifosplatform/accounting/journalentry/service/JournalEntryWritePlatformServiceJpaRepositoryImpl.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/accounting/journalentry/service/JournalEntryWritePlatformServiceJpaRepositoryImpl.java @@ -196,7 +196,6 @@ public class JournalEntryWritePlatformServiceJpaRepositoryImpl implements Journa final GLClosure latestGLClosure = this.glClosureRepository.getLatestGLClosureByBranch(loanDTO.getOfficeId()); final Office office = this.officeRepository.findOne(loanDTO.getOfficeId()); final Long loanProductId = loanDTO.getLoanProductId(); - // TODO: Check for accounting type for (final LoanTransactionDTO loanTransactionDTO : loanDTO.getNewLoanTransactions()) { final Date transactionDate = loanTransactionDTO.getTransactionDate(); final String transactionId = loanTransactionDTO.getTransactionId(); @@ -262,10 +261,6 @@ public class JournalEntryWritePlatformServiceJpaRepositoryImpl implements Journa BigDecimal totalDebitAmount = new BigDecimal(0); - if (isContraTransaction) { - transactionId = "reversal-" + transactionId; - } - if (principalAmount != null && !(principalAmount.compareTo(BigDecimal.ZERO) == 0)) { totalDebitAmount = totalDebitAmount.add(principalAmount); @@ -328,15 +323,17 @@ public class JournalEntryWritePlatformServiceJpaRepositoryImpl implements Journa private void createCreditJournalEntryForLoanProduct(final Office office, final GLAccount account, final Long loanId, final String transactionId, final Date transactionDate, final BigDecimal amount) { - final JournalEntry journalEntry = JournalEntry.createNew(office, account, transactionId, true, transactionDate, - JournalEntryType.CREDIT, amount, null, PortfolioProductType.LOAN.toString(), loanId); + final boolean manualEntry = false; + final JournalEntry journalEntry = JournalEntry.createNew(office, account, transactionId, manualEntry, transactionDate, + JournalEntryType.CREDIT, amount, null, PortfolioProductType.LOAN.getValue(), loanId); this.glJournalEntryRepository.saveAndFlush(journalEntry); } private void createDebitJournalEntryForLoanProduct(final Office office, final GLAccount account, final Long loanId, final String transactionId, final Date transactionDate, final BigDecimal amount) { - final JournalEntry journalEntry = JournalEntry.createNew(office, account, transactionId, true, transactionDate, - JournalEntryType.DEBIT, amount, null, PortfolioProductType.LOAN.toString(), loanId); + final boolean manualEntry = false; + final JournalEntry journalEntry = JournalEntry.createNew(office, account, transactionId, manualEntry, transactionDate, + JournalEntryType.DEBIT, amount, null, PortfolioProductType.LOAN.getValue(), loanId); this.glJournalEntryRepository.saveAndFlush(journalEntry); }