public Map<String, Object> update(final JsonCommand command) { final Map<String, Object> actualChanges = new LinkedHashMap<String, Object>(9); if (command.isChangeInIntegerParameterNamed( GroupingTypesApiConstants.statusParamName, this.status)) { final Integer newValue = command.integerValueOfParameterNamed(GroupingTypesApiConstants.statusParamName); actualChanges.put( GroupingTypesApiConstants.statusParamName, GroupingTypeEnumerations.status(newValue)); this.status = GroupingTypeStatus.fromInt(newValue).getValue(); } if (command.isChangeInStringParameterNamed( GroupingTypesApiConstants.externalIdParamName, this.externalId)) { final String newValue = command.stringValueOfParameterNamed(GroupingTypesApiConstants.externalIdParamName); actualChanges.put(GroupingTypesApiConstants.externalIdParamName, newValue); this.externalId = StringUtils.defaultIfEmpty(newValue, null); } if (command.isChangeInLongParameterNamed( GroupingTypesApiConstants.officeIdParamName, this.office.getId())) { final Long newValue = command.longValueOfParameterNamed(GroupingTypesApiConstants.officeIdParamName); actualChanges.put(GroupingTypesApiConstants.officeIdParamName, newValue); } if (command.isChangeInLongParameterNamed( GroupingTypesApiConstants.staffIdParamName, staffId())) { final Long newValue = command.longValueOfParameterNamed(GroupingTypesApiConstants.staffIdParamName); actualChanges.put(GroupingTypesApiConstants.staffIdParamName, newValue); } if (command.isChangeInStringParameterNamed( GroupingTypesApiConstants.nameParamName, this.name)) { final String newValue = command.stringValueOfParameterNamed(GroupingTypesApiConstants.nameParamName); actualChanges.put(GroupingTypesApiConstants.nameParamName, newValue); this.name = StringUtils.defaultIfEmpty(newValue, null); } final String dateFormatAsInput = command.dateFormat(); final String localeAsInput = command.locale(); if (command.isChangeInLocalDateParameterNamed( GroupingTypesApiConstants.activationDateParamName, getActivationLocalDate())) { final String valueAsInput = command.stringValueOfParameterNamed(GroupingTypesApiConstants.activationDateParamName); actualChanges.put(GroupingTypesApiConstants.activationDateParamName, valueAsInput); actualChanges.put(GroupingTypesApiConstants.dateFormatParamName, dateFormatAsInput); actualChanges.put(GroupingTypesApiConstants.localeParamName, localeAsInput); final LocalDate newValue = command.localDateValueOfParameterNamed(GroupingTypesApiConstants.activationDateParamName); this.activationDate = newValue.toDate(); } return actualChanges; }
@Transactional @Override public CommandProcessingResult activate(final Long savingsId, final JsonCommand command) { this.context.authenticatedUser(); this.savingsAccountTransactionDataValidator.validateActivation(command); final SavingsAccount account = this.savingAccountRepository.findOneWithNotFoundDetection(savingsId); final Locale locale = command.extractLocale(); final DateTimeFormatter fmt = DateTimeFormat.forPattern(command.dateFormat()).withLocale(locale); final LocalDate activationDate = command.localDateValueOfParameterNamed("activationDate"); final List<Long> existingTransactionIds = new ArrayList<Long>(); final List<Long> existingReversedTransactionIds = new ArrayList<Long>(); account.activate( fmt, activationDate, existingReversedTransactionIds, existingReversedTransactionIds); this.savingAccountRepository.save(account); postJournalEntries(account, existingTransactionIds, existingReversedTransactionIds); return new CommandProcessingResultBuilder() // .withEntityId(savingsId) // .withOfficeId(account.officeId()) // .withClientId(account.clientId()) // .withGroupId(account.groupId()) // .withSavingsId(savingsId) // .build(); }
@Transactional @Override public CommandProcessingResult deposit(final Long savingsId, final JsonCommand command) { this.context.authenticatedUser(); this.savingsAccountTransactionDataValidator.validate(command); final SavingsAccount account = this.savingAccountRepository.findOneWithNotFoundDetection(savingsId); final Locale locale = command.extractLocale(); final DateTimeFormatter fmt = DateTimeFormat.forPattern(command.dateFormat()).withLocale(locale); final LocalDate transactionDate = command.localDateValueOfParameterNamed("transactionDate"); final BigDecimal transactionAmount = command.bigDecimalValueOfParameterNamed("transactionAmount"); final List<Long> existingTransactionIds = new ArrayList<Long>(); final List<Long> existingReversedTransactionIds = new ArrayList<Long>(); final Map<String, Object> changes = new LinkedHashMap<String, Object>(); PaymentDetail paymentDetail = paymentDetailWritePlatformService.createAndPersistPaymentDetail(command, changes); final SavingsAccountTransaction deposit = account.deposit( fmt, transactionDate, transactionAmount, existingTransactionIds, existingReversedTransactionIds, paymentDetail); final Long transactionId = saveTransactionToGenerateTransactionId(deposit); this.savingAccountRepository.save(account); postJournalEntries(account, existingTransactionIds, existingReversedTransactionIds); return new CommandProcessingResultBuilder() // .withEntityId(transactionId) // .withOfficeId(account.officeId()) // .withClientId(account.clientId()) // .withGroupId(account.groupId()) // .withSavingsId(savingsId) // .with(changes) // .build(); }
@Transactional @Override public CommandProcessingResult create(final JsonCommand command) { this.accountTransfersDataValidator.validate(command); final LocalDate transactionDate = command.localDateValueOfParameterNamed(transferDateParamName); final BigDecimal transactionAmount = command.bigDecimalValueOfParameterNamed(transferAmountParamName); final Locale locale = command.extractLocale(); final DateTimeFormatter fmt = DateTimeFormat.forPattern(command.dateFormat()).withLocale(locale); final Integer fromAccountTypeId = command.integerValueSansLocaleOfParameterNamed(fromAccountTypeParamName); final PortfolioAccountType fromAccountType = PortfolioAccountType.fromInt(fromAccountTypeId); final Integer toAccountTypeId = command.integerValueSansLocaleOfParameterNamed(toAccountTypeParamName); final PortfolioAccountType toAccountType = PortfolioAccountType.fromInt(toAccountTypeId); final PaymentDetail paymentDetail = null; Long fromSavingsAccountId = null; Long transferTransactionId = null; if (isSavingsToSavingsAccountTransfer(fromAccountType, toAccountType)) { fromSavingsAccountId = command.longValueOfParameterNamed(fromAccountIdParamName); final SavingsAccount fromSavingsAccount = this.savingsAccountAssembler.assembleFrom(fromSavingsAccountId); final SavingsAccountTransaction withdrawal = this.savingsAccountDomainService.handleWithdrawal( fromSavingsAccount, fmt, transactionDate, transactionAmount, paymentDetail, fromSavingsAccount.isWithdrawalFeeApplicableForTransfer()); final Long toSavingsId = command.longValueOfParameterNamed(toAccountIdParamName); final SavingsAccount toSavingsAccount = this.savingsAccountAssembler.assembleFrom(toSavingsId); final SavingsAccountTransaction deposit = this.savingsAccountDomainService.handleDeposit( toSavingsAccount, fmt, transactionDate, transactionAmount, paymentDetail); final AccountTransfer transferTransaction = this.accountTransferAssembler.assembleSavingsToSavingsTransfer( command, withdrawal, deposit); this.accountTransferRepository.saveAndFlush(transferTransaction); transferTransactionId = transferTransaction.getId(); } else if (isSavingsToLoanAccountTransfer(fromAccountType, toAccountType)) { // fromSavingsAccountId = command.longValueOfParameterNamed(fromAccountIdParamName); final SavingsAccount fromSavingsAccount = this.savingsAccountAssembler.assembleFrom(fromSavingsAccountId); final SavingsAccountTransaction withdrawal = this.savingsAccountDomainService.handleWithdrawal( fromSavingsAccount, fmt, transactionDate, transactionAmount, paymentDetail, fromSavingsAccount.isWithdrawalFeeApplicableForTransfer()); final Long toLoanAccountId = command.longValueOfParameterNamed(toAccountIdParamName); final Loan toLoanAccount = this.loanAccountAssembler.assembleFrom(toLoanAccountId); final LoanTransaction loanRepaymentTransaction = this.loanAccountDomainService.makeRepayment( toLoanAccount, new CommandProcessingResultBuilder(), transactionDate, transactionAmount, paymentDetail, null, null); final AccountTransfer transferTransaction = this.accountTransferAssembler.assembleSavingsToLoanTransfer( command, fromSavingsAccount, toLoanAccount, withdrawal, loanRepaymentTransaction); this.accountTransferRepository.saveAndFlush(transferTransaction); transferTransactionId = transferTransaction.getId(); } else if (isLoanToSavingsAccountTransfer(fromAccountType, toAccountType)) { // FIXME - kw - ADD overpaid loan to savings account transfer // support. // final Long fromLoanAccountId = command.longValueOfParameterNamed(fromAccountIdParamName); final Loan fromLoanAccount = this.loanAccountAssembler.assembleFrom(fromLoanAccountId); final LoanTransaction loanRefundTransaction = this.loanAccountDomainService.makeRefund( fromLoanAccountId, new CommandProcessingResultBuilder(), transactionDate, transactionAmount, paymentDetail, null, null); final Long toSavingsAccountId = command.longValueOfParameterNamed(toAccountIdParamName); final SavingsAccount toSavingsAccount = this.savingsAccountAssembler.assembleFrom(toSavingsAccountId); final SavingsAccountTransaction deposit = this.savingsAccountDomainService.handleDeposit( toSavingsAccount, fmt, transactionDate, transactionAmount, paymentDetail); final AccountTransfer transferTransaction = this.accountTransferAssembler.assembleLoanToSavingsTransfer( command, fromLoanAccount, toSavingsAccount, deposit, loanRefundTransaction); this.accountTransferRepository.saveAndFlush(transferTransaction); transferTransactionId = transferTransaction.getId(); } else { } final CommandProcessingResultBuilder builder = new CommandProcessingResultBuilder().withEntityId(transferTransactionId); if (fromAccountType.isSavingsAccount()) { builder.withSavingsId(fromSavingsAccountId); } return builder.build(); }
public Map<String, Object> update(final JsonCommand command, final BigDecimal amount) { final Map<String, Object> actualChanges = new LinkedHashMap<>(7); final String dateFormatAsInput = command.dateFormat(); final String localeAsInput = command.locale(); final String dueDateParamName = "dueDate"; if (command.isChangeInLocalDateParameterNamed(dueDateParamName, getDueLocalDate())) { final String valueAsInput = command.stringValueOfParameterNamed(dueDateParamName); actualChanges.put(dueDateParamName, valueAsInput); actualChanges.put("dateFormat", dateFormatAsInput); actualChanges.put("locale", localeAsInput); final LocalDate newValue = command.localDateValueOfParameterNamed(dueDateParamName); this.dueDate = newValue.toDate(); } final String amountParamName = "amount"; if (command.isChangeInBigDecimalParameterNamed(amountParamName, this.amount)) { final BigDecimal newValue = command.bigDecimalValueOfParameterNamed(amountParamName); actualChanges.put(amountParamName, newValue); actualChanges.put("locale", localeAsInput); switch (ChargeCalculationType.fromInt(this.chargeCalculation)) { case INVALID: break; case FLAT: if (isInstalmentFee()) { this.amount = newValue.multiply( BigDecimal.valueOf( this.loan.repaymentScheduleDetail().getNumberOfRepayments())); } else { this.amount = newValue; } this.amountOutstanding = calculateOutstanding(); break; case PERCENT_OF_AMOUNT: case PERCENT_OF_AMOUNT_AND_INTEREST: case PERCENT_OF_INTEREST: this.percentage = newValue; this.amountPercentageAppliedTo = amount; BigDecimal loanCharge = BigDecimal.ZERO; if (isInstalmentFee()) { loanCharge = this.loan.calculatePerInstallmentChargeAmount( ChargeCalculationType.fromInt(this.chargeCalculation), this.percentage); } if (loanCharge.compareTo(BigDecimal.ZERO) == 0) { loanCharge = percentageOf(this.amountPercentageAppliedTo); } this.amount = minimumAndMaximumCap(loanCharge); this.amountOutstanding = calculateOutstanding(); break; } this.amountOrPercentage = newValue; if (isInstalmentFee()) { final Set<LoanInstallmentCharge> chargePerInstallments = this.loan.generateInstallmentLoanCharges(this); if (this.loanInstallmentCharge.isEmpty()) { this.loanInstallmentCharge.addAll(chargePerInstallments); } else { int index = 0; final LoanInstallmentCharge[] loanChargePerInstallments = new LoanInstallmentCharge[chargePerInstallments.size()]; final LoanInstallmentCharge[] loanChargePerInstallmentArray = chargePerInstallments.toArray(loanChargePerInstallments); for (final LoanInstallmentCharge chargePerInstallment : this.loanInstallmentCharge) { chargePerInstallment.copyFrom(loanChargePerInstallmentArray[index++]); } } } } return actualChanges; }