Added accounting entries for allocate and settle transactions
This commit is contained in:
+3
-1
@@ -221,7 +221,9 @@ public class AccountingConstants {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static enum FINANCIAL_ACTIVITY {
|
public static enum FINANCIAL_ACTIVITY {
|
||||||
ASSET_TRANSFER(100, "assetTransfer", GLAccountType.ASSET), LIABILITY_TRANSFER(200, "liabilityTransfer", GLAccountType.LIABILITY);
|
ASSET_TRANSFER(100, "assetTransfer", GLAccountType.ASSET), LIABILITY_TRANSFER(200, "liabilityTransfer", GLAccountType.LIABILITY),
|
||||||
|
CASH_AT_MAINVAULT (300, "cashAtMainVault", GLAccountType.ASSET),
|
||||||
|
CASH_AT_TELLER (400, "cashAtTeller", GLAccountType.ASSET);
|
||||||
|
|
||||||
private final Integer value;
|
private final Integer value;
|
||||||
private final String code;
|
private final String code;
|
||||||
|
|||||||
+2
-1
@@ -53,7 +53,8 @@ public final class FinancialActivityAccountDataValidator {
|
|||||||
|
|
||||||
final Integer financialActivityId = this.fromApiJsonHelper.extractIntegerSansLocaleNamed(paramNameForFinancialActivity, element);
|
final Integer financialActivityId = this.fromApiJsonHelper.extractIntegerSansLocaleNamed(paramNameForFinancialActivity, element);
|
||||||
baseDataValidator.reset().parameter(paramNameForFinancialActivity).value(financialActivityId).notNull()
|
baseDataValidator.reset().parameter(paramNameForFinancialActivity).value(financialActivityId).notNull()
|
||||||
.isOneOfTheseValues(FINANCIAL_ACTIVITY.ASSET_TRANSFER.getValue(), FINANCIAL_ACTIVITY.LIABILITY_TRANSFER.getValue());
|
.isOneOfTheseValues(FINANCIAL_ACTIVITY.ASSET_TRANSFER.getValue(), FINANCIAL_ACTIVITY.LIABILITY_TRANSFER.getValue(),
|
||||||
|
FINANCIAL_ACTIVITY.CASH_AT_MAINVAULT.getValue(), FINANCIAL_ACTIVITY.CASH_AT_TELLER.getValue());
|
||||||
|
|
||||||
final Long glAccountId = this.fromApiJsonHelper.extractLongNamed(paramNameForGLAccount, element);
|
final Long glAccountId = this.fromApiJsonHelper.extractLongNamed(paramNameForGLAccount, element);
|
||||||
baseDataValidator.reset().parameter(paramNameForGLAccount).value(glAccountId).notNull().integerGreaterThanZero();
|
baseDataValidator.reset().parameter(paramNameForGLAccount).value(glAccountId).notNull().integerGreaterThanZero();
|
||||||
|
|||||||
+4
@@ -240,6 +240,10 @@ public class CashierTransaction extends AbstractPersistable<Long> {
|
|||||||
return txnNote;
|
return txnNote;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public BigDecimal getTxnAmount() {
|
||||||
|
return txnAmount;
|
||||||
|
}
|
||||||
|
|
||||||
public void setTxnNote (String txnNote) {
|
public void setTxnNote (String txnNote) {
|
||||||
this.txnNote = txnNote;
|
this.txnNote = txnNote;
|
||||||
}
|
}
|
||||||
|
|||||||
+61
-5
@@ -2,6 +2,13 @@ package org.mifosplatform.organisation.teller.service;
|
|||||||
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
|
import org.mifosplatform.accounting.common.AccountingConstants.FINANCIAL_ACTIVITY;
|
||||||
|
import org.mifosplatform.accounting.financialactivityaccount.domain.FinancialActivityAccount;
|
||||||
|
import org.mifosplatform.accounting.financialactivityaccount.domain.FinancialActivityAccountRepositoryWrapper;
|
||||||
|
import org.mifosplatform.accounting.glaccount.domain.GLAccount;
|
||||||
|
import org.mifosplatform.accounting.journalentry.domain.JournalEntry;
|
||||||
|
import org.mifosplatform.accounting.journalentry.domain.JournalEntryType;
|
||||||
|
import org.mifosplatform.accounting.journalentry.domain.JournalEntryRepository;
|
||||||
import org.mifosplatform.infrastructure.core.api.JsonCommand;
|
import org.mifosplatform.infrastructure.core.api.JsonCommand;
|
||||||
import org.mifosplatform.infrastructure.core.data.CommandProcessingResult;
|
import org.mifosplatform.infrastructure.core.data.CommandProcessingResult;
|
||||||
import org.mifosplatform.infrastructure.core.data.CommandProcessingResultBuilder;
|
import org.mifosplatform.infrastructure.core.data.CommandProcessingResultBuilder;
|
||||||
@@ -44,13 +51,19 @@ public class TellerWritePlatformServiceJpaImpl implements TellerWritePlatformSer
|
|||||||
private final StaffRepository staffRepository;
|
private final StaffRepository staffRepository;
|
||||||
private final CashierRepository cashierRepository;
|
private final CashierRepository cashierRepository;
|
||||||
private final CashierTransactionRepository cashierTxnRepository;
|
private final CashierTransactionRepository cashierTxnRepository;
|
||||||
|
private final JournalEntryRepository glJournalEntryRepository;
|
||||||
|
private final FinancialActivityAccountRepositoryWrapper financialActivityAccountRepositoryWrapper;
|
||||||
|
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
public TellerWritePlatformServiceJpaImpl (final PlatformSecurityContext context,
|
public TellerWritePlatformServiceJpaImpl (final PlatformSecurityContext context,
|
||||||
final TellerCommandFromApiJsonDeserializer fromApiJsonDeserializer,
|
final TellerCommandFromApiJsonDeserializer fromApiJsonDeserializer,
|
||||||
final TellerRepository tellerRepository, final OfficeRepository officeRepository,
|
final TellerRepository tellerRepository, final OfficeRepository officeRepository,
|
||||||
final StaffRepository staffRepository, CashierRepository cashierRepository,
|
final StaffRepository staffRepository, CashierRepository cashierRepository,
|
||||||
CashierTransactionRepository cashierTxnRepository) {
|
CashierTransactionRepository cashierTxnRepository,
|
||||||
|
JournalEntryRepository glJournalEntryRepository,
|
||||||
|
FinancialActivityAccountRepositoryWrapper financialActivityAccountRepositoryWrapper
|
||||||
|
) {
|
||||||
this.context = context;
|
this.context = context;
|
||||||
this.fromApiJsonDeserializer = fromApiJsonDeserializer;
|
this.fromApiJsonDeserializer = fromApiJsonDeserializer;
|
||||||
this.tellerRepository = tellerRepository;
|
this.tellerRepository = tellerRepository;
|
||||||
@@ -58,6 +71,8 @@ public class TellerWritePlatformServiceJpaImpl implements TellerWritePlatformSer
|
|||||||
this.staffRepository = staffRepository;
|
this.staffRepository = staffRepository;
|
||||||
this.cashierRepository = cashierRepository;
|
this.cashierRepository = cashierRepository;
|
||||||
this.cashierTxnRepository = cashierTxnRepository;
|
this.cashierTxnRepository = cashierTxnRepository;
|
||||||
|
this.glJournalEntryRepository = glJournalEntryRepository;
|
||||||
|
this.financialActivityAccountRepositoryWrapper = financialActivityAccountRepositoryWrapper;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -65,7 +80,7 @@ public class TellerWritePlatformServiceJpaImpl implements TellerWritePlatformSer
|
|||||||
@Transactional
|
@Transactional
|
||||||
public CommandProcessingResult createTeller(JsonCommand command) {
|
public CommandProcessingResult createTeller(JsonCommand command) {
|
||||||
try {
|
try {
|
||||||
final AppUser currentUser = this.context.authenticatedUser();
|
this.context.authenticatedUser();
|
||||||
|
|
||||||
final Long officeId = command.longValueOfParameterNamed("officeId");
|
final Long officeId = command.longValueOfParameterNamed("officeId");
|
||||||
|
|
||||||
@@ -176,7 +191,7 @@ public class TellerWritePlatformServiceJpaImpl implements TellerWritePlatformSer
|
|||||||
@Override
|
@Override
|
||||||
public CommandProcessingResult allocateCashierToTeller(final Long tellerId, JsonCommand command) {
|
public CommandProcessingResult allocateCashierToTeller(final Long tellerId, JsonCommand command) {
|
||||||
try {
|
try {
|
||||||
final AppUser currentUser = this.context.authenticatedUser();
|
this.context.authenticatedUser();
|
||||||
|
|
||||||
// final Office parent = validateUserPriviledgeOnOfficeAndRetrieve(currentUser, officeId);
|
// final Office parent = validateUserPriviledgeOnOfficeAndRetrieve(currentUser, officeId);
|
||||||
final Teller teller = this.tellerRepository.findOne(tellerId);
|
final Teller teller = this.tellerRepository.findOne(tellerId);
|
||||||
@@ -194,7 +209,6 @@ public class TellerWritePlatformServiceJpaImpl implements TellerWritePlatformSer
|
|||||||
final Cashier cashier = Cashier.fromJson(tellerOffice, teller, staff,
|
final Cashier cashier = Cashier.fromJson(tellerOffice, teller, staff,
|
||||||
command);
|
command);
|
||||||
|
|
||||||
// pre save to generate id for use in office hierarchy
|
|
||||||
this.cashierRepository.save(cashier);
|
this.cashierRepository.save(cashier);
|
||||||
|
|
||||||
return new CommandProcessingResultBuilder() //
|
return new CommandProcessingResultBuilder() //
|
||||||
@@ -327,9 +341,51 @@ public class TellerWritePlatformServiceJpaImpl implements TellerWritePlatformSer
|
|||||||
final CashierTransaction cashierTxn = CashierTransaction.fromJson(cashier, command);
|
final CashierTransaction cashierTxn = CashierTransaction.fromJson(cashier, command);
|
||||||
cashierTxn.setTxnType(txnType.getId());
|
cashierTxn.setTxnType(txnType.getId());
|
||||||
|
|
||||||
// pre save to generate id for use in office hierarchy
|
|
||||||
this.cashierTxnRepository.save(cashierTxn);
|
this.cashierTxnRepository.save(cashierTxn);
|
||||||
|
|
||||||
|
// Pass the journal entries
|
||||||
|
FinancialActivityAccount mainVaultFinancialActivityAccount = this.financialActivityAccountRepositoryWrapper.
|
||||||
|
findByFinancialActivityTypeWithNotFoundDetection(
|
||||||
|
FINANCIAL_ACTIVITY.CASH_AT_MAINVAULT.getValue());
|
||||||
|
FinancialActivityAccount tellerCashFinancialActivityAccount = this.financialActivityAccountRepositoryWrapper.
|
||||||
|
findByFinancialActivityTypeWithNotFoundDetection(
|
||||||
|
FINANCIAL_ACTIVITY.CASH_AT_TELLER.getValue());
|
||||||
|
GLAccount creditAccount = null;
|
||||||
|
GLAccount debitAccount = null;
|
||||||
|
if (txnType.equals(CashierTxnType.ALLOCATE) ) {
|
||||||
|
debitAccount = tellerCashFinancialActivityAccount.getGlAccount();
|
||||||
|
creditAccount = mainVaultFinancialActivityAccount.getGlAccount();
|
||||||
|
} else if (txnType.equals(CashierTxnType.SETTLE) ) {
|
||||||
|
debitAccount = mainVaultFinancialActivityAccount.getGlAccount();
|
||||||
|
creditAccount = tellerCashFinancialActivityAccount.getGlAccount();
|
||||||
|
}
|
||||||
|
|
||||||
|
final Office cashierOffice = cashier.getTeller().getOffice();
|
||||||
|
|
||||||
|
final Long time = System.currentTimeMillis();
|
||||||
|
final String uniqueVal = String.valueOf(time) + currentUser.getId() + cashierOffice.getId();
|
||||||
|
final String transactionId = Long.toHexString(Long.parseLong(uniqueVal));
|
||||||
|
|
||||||
|
final JournalEntry debitJournalEntry = JournalEntry.createNew(
|
||||||
|
cashierOffice, null, // payment detail
|
||||||
|
debitAccount, "USD", // FIXME: Take currency code from the transaction
|
||||||
|
transactionId, false, // manual entry
|
||||||
|
cashierTxn.getTxnDate(), JournalEntryType.DEBIT, cashierTxn.getTxnAmount(),
|
||||||
|
cashierTxn.getTxnNote(), // Description
|
||||||
|
null, null, null, // entity Type, entityId, reference number
|
||||||
|
null, null); // Loan and Savings Txn
|
||||||
|
final JournalEntry creditJournalEntry = JournalEntry.createNew(
|
||||||
|
cashierOffice, null, // payment detail
|
||||||
|
creditAccount, "USD", // FIXME: Take currency code from the transaction
|
||||||
|
transactionId, false, // manual entry
|
||||||
|
cashierTxn.getTxnDate(), JournalEntryType.CREDIT, cashierTxn.getTxnAmount(),
|
||||||
|
cashierTxn.getTxnNote(), // Description
|
||||||
|
null, null, null, // entity Type, entityId, reference number
|
||||||
|
null, null); // Loan and Savings Txn
|
||||||
|
|
||||||
|
this.glJournalEntryRepository.saveAndFlush(debitJournalEntry);
|
||||||
|
this.glJournalEntryRepository.saveAndFlush(creditJournalEntry);
|
||||||
|
|
||||||
return new CommandProcessingResultBuilder() //
|
return new CommandProcessingResultBuilder() //
|
||||||
.withCommandId(command.commandId()) //
|
.withCommandId(command.commandId()) //
|
||||||
.withEntityId(cashier.getId()) //
|
.withEntityId(cashier.getId()) //
|
||||||
|
|||||||
Reference in New Issue
Block a user