Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/FBR-339: Implement Print Cheques #235

Merged
merged 2 commits into from
Oct 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions fineract-provider/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -223,11 +223,12 @@ bootRun {
dependencies {
implementation 'org.mariadb.jdbc:mariadb-java-client:2.7.6'
implementation 'org.postgresql:postgresql:42.4.0'
implementation 'org.openjdk.nashorn:nashorn-core:15.1'
implementation 'org.codehaus.groovy:groovy-all:3.0.8'
implementation 'org.apache.poi:poi:4.1.2'
implementation 'org.apache.poi:poi-ooxml:4.1.2'
implementation 'org.apache.poi:poi-ooxml-schemas:4.1.2'
implementation 'org.openjdk.nashorn:nashorn-core:15.1'
implementation 'org.apache.poi:poi:5.2.3'
implementation 'org.apache.poi:poi-ooxml:5.2.3'
implementation 'org.apache.poi:poi-ooxml-full:5.2.3'

}
}

Expand Down
6 changes: 6 additions & 0 deletions fineract-provider/pentahoReports/Print Bank Cheque.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
title.bank.cheque=THE FRIENDSHIP BRIDGE SUCURSAL CHIMALTENANGO
label.date.and.residential.place=LUGAR Y FECHA:
label.cheque.pay.to.order=PAGO A LA ORDEN DE:
label.cheque.sum.of=SUM DE:
label.cheque.signature=FIRMA
label.bank.account.number=A/C
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -3951,6 +3951,14 @@ public CommandWrapperBuilder payGuaranteesByCheques() {
return this;
}

public CommandWrapperBuilder printCheques() {
this.entityName = BankChequeApiConstants.BANK_CHECK_RESOURCE_NAME;
this.actionName = BankChequeApiConstants.CHECK_ACTION_PRINT;
this.entityId = null;
this.href = "/bankcheques";
return this;
}

public CommandWrapperBuilder createCommittee() {
this.actionName = "CREATE";
this.entityName = "COMMITTEE";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,8 @@ public class OAuth2SecurityConfig extends WebSecurityConfigurerAdapter {
protected void configure(HttpSecurity http) throws Exception {

http //
.csrf().disable() // NOSONAR only creating a service that is used by non-browser clients
.headers().frameOptions().disable().and().csrf().disable() // NOSONAR only creating a service that is
// used by non-browser clients
.antMatcher("/api/**").authorizeRequests() //
.antMatchers(HttpMethod.OPTIONS, "/api/**").permitAll() //
.antMatchers(HttpMethod.POST, "/api/*/echo").permitAll() //
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,8 @@ public class SecurityConfig extends WebSecurityConfigurerAdapter {
@Override
protected void configure(HttpSecurity http) throws Exception {
http //
.csrf().disable() // NOSONAR only creating a service that is used by non-browser clients
.headers().frameOptions().disable().and().csrf().disable() // NOSONAR only creating a service that is
// used by non-browser clients
.antMatcher("/api/**").authorizeRequests() //
.antMatchers(HttpMethod.OPTIONS, "/api/**").permitAll() //
.antMatchers(HttpMethod.POST, "/api/*/echo").permitAll() //
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ public class BankChequeApiConstants {
public static final String CHECK_ACTION_AUTHORIZE_ISSUANCE = "AUTHORIZEISSUANCE";
public static final String CHECK_ACTION_PAY_GUARANTEE_BY_CHEQUE = "PAYGUARANTEEBYCHEQUE";
public static final String CHECK_ACTION_DISBURSEBYCHEQUES = "DISBURSEBYCHEQUES";
public static final String CHECK_ACTION_PRINT = "PRINT";
public static String ID_PARAM_NAME = "id";
public static String BATCH_NO = "batchNo";
public static String AGENCY = "agency";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,11 +113,14 @@ public String chequeRequests(@Parameter(hidden = true) final String apiRequestBo
} else if (is(commandParam, "payguaranteesbycheques")) {
commandRequest = builder.payGuaranteesByCheques().build();
result = this.commandsSourceWritePlatformService.logCommandSource(commandRequest);
} else if (is(commandParam, "printcheques")) {
commandRequest = builder.printCheques().build();
result = this.commandsSourceWritePlatformService.logCommandSource(commandRequest);
}

if (result == null) {
throw new UnrecognizedQueryParamException("command", commandParam, "reassigncheque", "authorizereassignment", "createbatch",
"voidcheque", "authorizevoidance", "approveissuance", "payguaranteesbycheques");
"voidcheque", "authorizevoidance", "approveissuance", "payguaranteesbycheques", "printcheques");
}
return this.toApiJsonSerializer.serialize(result);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.apache.fineract.organisation.bankcheque.command;

import lombok.Builder;
import lombok.Data;

@Builder
@Data
public class PrintChequeCommand {

private Long chequeId;
private String description;
}
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ public class ChequeData {
private String groupName;
private String groupNo;
private String loanAccNo;
private Long loanAccId;
private String caseId;
private Long guaranteeId;
private BigDecimal chequeAmount;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.apache.fineract.organisation.bankcheque.handler;

import javax.persistence.PersistenceException;
import lombok.RequiredArgsConstructor;
import org.apache.commons.lang3.exception.ExceptionUtils;
import org.apache.fineract.commands.annotation.CommandType;
import org.apache.fineract.commands.handler.NewCommandSourceHandler;
import org.apache.fineract.infrastructure.DataIntegrityErrorHandler;
import org.apache.fineract.infrastructure.core.api.JsonCommand;
import org.apache.fineract.infrastructure.core.data.CommandProcessingResult;
import org.apache.fineract.organisation.bankcheque.api.BankChequeApiConstants;
import org.apache.fineract.organisation.bankcheque.service.ChequeWritePlatformService;
import org.springframework.dao.DataIntegrityViolationException;
import org.springframework.orm.jpa.JpaSystemException;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service
@CommandType(entity = BankChequeApiConstants.BANK_CHECK_RESOURCE_NAME, action = BankChequeApiConstants.CHECK_ACTION_PRINT)
@RequiredArgsConstructor
public class PrintChequeCommandHandler implements NewCommandSourceHandler {

private final ChequeWritePlatformService chequeWritePlatformService;
private final DataIntegrityErrorHandler dataIntegrityErrorHandler;

@Transactional
@Override
public CommandProcessingResult processCommand(JsonCommand command) {
try {
return this.chequeWritePlatformService.printCheques(command);
} catch (final JpaSystemException | DataIntegrityViolationException dve) {
dataIntegrityErrorHandler.handleDataIntegrityIssues(command, dve.getMostSpecificCause(), dve, "bankcheques", "print cheques");
return CommandProcessingResult.empty();
} catch (final PersistenceException dve) {
Throwable throwable = ExceptionUtils.getRootCause(dve.getCause());
dataIntegrityErrorHandler.handleDataIntegrityIssues(command, throwable, dve, "bankcheques", "prints");
return CommandProcessingResult.empty();
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.apache.fineract.organisation.bankcheque.serialization;

import com.google.gson.JsonArray;
import com.google.gson.JsonElement;
import java.util.ArrayList;
import java.util.List;
import lombok.RequiredArgsConstructor;
import org.apache.fineract.infrastructure.core.data.ApiParameterError;
import org.apache.fineract.infrastructure.core.data.DataValidatorBuilder;
import org.apache.fineract.infrastructure.core.exception.PlatformApiDataValidationException;
import org.apache.fineract.infrastructure.core.serialization.AbstractFromApiJsonDeserializer;
import org.apache.fineract.infrastructure.core.serialization.FromJsonHelper;
import org.apache.fineract.organisation.bankcheque.command.PrintChequeCommand;
import org.apache.fineract.portfolio.loanaccount.api.LoanApiConstants;
import org.springframework.stereotype.Component;

@Component
@RequiredArgsConstructor
public class PrintChequeCommandFromApiJsonDeserializer extends AbstractFromApiJsonDeserializer<List<PrintChequeCommand>> {

private final FromJsonHelper fromApiJsonHelper;

@Override
public List<PrintChequeCommand> commandFromApiJson(String json) {
final JsonElement jsonElement = this.fromApiJsonHelper.parse(json);
JsonArray jsonArray = jsonElement.getAsJsonObject().getAsJsonArray("selectedCheques");
List<PrintChequeCommand> printChequeCommandList = new ArrayList<>();
final List<ApiParameterError> dataValidationErrors = new ArrayList<>();
final DataValidatorBuilder baseDataValidator = new DataValidatorBuilder(dataValidationErrors).resource("loan");
for (int i = 0; i < jsonArray.size(); i++) {
final JsonElement element = jsonArray.get(i);
final Long chequeId = this.fromApiJsonHelper.extractLongNamed(LoanApiConstants.CHEQUE_ID, element);
baseDataValidator.reset().parameter(LoanApiConstants.CHEQUE_ID).value(chequeId).notBlank();
final String description = this.fromApiJsonHelper.extractStringNamed(LoanApiConstants.CHEQUE_DESCRIPTION, element);
baseDataValidator.reset().parameter(LoanApiConstants.CHEQUE_DESCRIPTION).value(description).ignoreIfNull()
.notExceedingLengthOf(1000);
final PrintChequeCommand printChequeCommand = PrintChequeCommand.builder().chequeId(chequeId).description(description).build();
printChequeCommandList.add(printChequeCommand);
}
throwExceptionIfValidationWarningsExist(dataValidationErrors);
return printChequeCommandList;
}

private void throwExceptionIfValidationWarningsExist(final List<ApiParameterError> dataValidationErrors) {
if (!dataValidationErrors.isEmpty()) {
throw new PlatformApiDataValidationException(dataValidationErrors);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ SELECT IFNULL(MAX(mbc.check_no), 0) AS maxChequeNo
.groupOptions(groupOptions).centerOptions(centerOptions).facilitatorOptions(facilitatorOptions).build();
}

private static final class ChequeMapper implements RowMapper<ChequeData> {
static final class ChequeMapper implements RowMapper<ChequeData> {

private final String schema;

Expand All @@ -154,6 +154,7 @@ private static final class ChequeMapper implements RowMapper<ChequeData> {
mg.display_name AS groupName,
mg.account_no AS groupNo,
ml.account_no AS loanAccNo,
ml.id AS loanAccId,
mpb.batch_no AS batchNo,
mba.account_number AS bankAccNo,
mba.id AS bankAccId,
Expand Down Expand Up @@ -225,6 +226,7 @@ public ChequeData mapRow(final ResultSet rs, final int rowNum) throws SQLExcepti
final String clientNo = rs.getString("clientNo");
final String groupName = rs.getString("groupName");
final String loanAccNo = rs.getString("loanAccNo");
final Long loanAccId = JdbcSupport.getLong(rs, "loanAccId");
final String groupNo = rs.getString("groupNo");
final BigDecimal loanAmount = JdbcSupport.getBigDecimalDefaultToZeroIfNull(rs, "loanAmount");
final BigDecimal guaranteeAmount = JdbcSupport.getBigDecimalDefaultToZeroIfNull(rs, "guaranteeAmount");
Expand All @@ -236,7 +238,7 @@ public ChequeData mapRow(final ResultSet rs, final int rowNum) throws SQLExcepti
.printedByUsername(printedByUsername).voidAuthorizedByUsername(voidAuthorizedByUsername)
.lastModifiedByUsername(lastModifiedByUsername).clientName(clientName).clientNo(clientNo).groupName(groupName)
.loanAccNo(loanAccNo).loanAmount(loanAmount).guaranteeAmount(guaranteeAmount).groupNo(groupNo).guaranteeId(guaranteeId)
.caseId(caseId).chequeAmount(chequeAmount).agencyId(agencyId).build();
.caseId(caseId).chequeAmount(chequeAmount).agencyId(agencyId).loanAccId(loanAccId).build();

}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ public interface ChequeWritePlatformService {

CommandProcessingResult authorizeChequeIssuance(final JsonCommand command);

CommandProcessingResult printCheques(final JsonCommand command);

CommandProcessingResult payGuaranteeByCheque(final JsonCommand command);

}
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,11 @@
import org.apache.fineract.organisation.bankcheque.command.AuthorizeChequeIssuanceCommand;
import org.apache.fineract.organisation.bankcheque.command.CreateChequeCommand;
import org.apache.fineract.organisation.bankcheque.command.PayGuaranteeByChequeCommand;
import org.apache.fineract.organisation.bankcheque.command.PrintChequeCommand;
import org.apache.fineract.organisation.bankcheque.command.ReassignChequeCommand;
import org.apache.fineract.organisation.bankcheque.command.UpdateChequeCommand;
import org.apache.fineract.organisation.bankcheque.command.VoidChequeCommand;
import org.apache.fineract.organisation.bankcheque.data.ChequeData;
import org.apache.fineract.organisation.bankcheque.domain.BankChequeStatus;
import org.apache.fineract.organisation.bankcheque.domain.Batch;
import org.apache.fineract.organisation.bankcheque.domain.Cheque;
Expand All @@ -52,9 +54,11 @@
import org.apache.fineract.organisation.bankcheque.serialization.AuthorizeChequeIssuanceCommandFromApiJsonDeserializer;
import org.apache.fineract.organisation.bankcheque.serialization.CreateChequeCommandFromApiJsonDeserializer;
import org.apache.fineract.organisation.bankcheque.serialization.PayGuaranteeByChequeCommandFromApiJsonDeserializer;
import org.apache.fineract.organisation.bankcheque.serialization.PrintChequeCommandFromApiJsonDeserializer;
import org.apache.fineract.organisation.bankcheque.serialization.ReassignChequeCommandFromApiJsonDeserializer;
import org.apache.fineract.organisation.bankcheque.serialization.UpdateChequeCommandFromApiJsonDeserializer;
import org.apache.fineract.organisation.bankcheque.serialization.VoidChequeCommandFromApiJsonDeserializer;
import org.apache.fineract.portfolio.loanaccount.service.LoanWritePlatformService;
import org.apache.fineract.useradministration.domain.AppUser;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Service;
Expand All @@ -77,6 +81,9 @@ public class ChequeWritePlatformServiceImpl implements ChequeWritePlatformServic
private final ApproveChequeIssuanceCommandFromApiJsonDeserializer approveChequeIssuanceCommandFromApiJsonDeserializer;
private final AuthorizeChequeIssuanceCommandFromApiJsonDeserializer authorizeChequeIssuanceCommandFromApiJsonDeserializer;
private final PayGuaranteeByChequeCommandFromApiJsonDeserializer payGuaranteeByChequeCommandFromApiJsonDeserializer;
private final PrintChequeCommandFromApiJsonDeserializer printChequeCommandFromApiJsonDeserializer;
private final ChequeReadPlatformServiceImpl.ChequeMapper chequeMapper = new ChequeReadPlatformServiceImpl.ChequeMapper();
private final LoanWritePlatformService loanWritePlatformService;

@Override
public CommandProcessingResult createBatch(JsonCommand command) {
Expand Down Expand Up @@ -305,4 +312,35 @@ public CommandProcessingResult payGuaranteeByCheque(JsonCommand command) {
}
return new CommandProcessingResultBuilder().withCommandId(command.commandId()).build();
}

@Override
@Transactional
public CommandProcessingResult printCheques(JsonCommand command) {
final AppUser currentUser = this.context.authenticatedUser();
List<PrintChequeCommand> printChequeCommandList = this.printChequeCommandFromApiJsonDeserializer.commandFromApiJson(command.json());
for (final PrintChequeCommand printChequeCommand : printChequeCommandList) {
final Cheque cheque = this.chequeBatchRepositoryWrapper.findOneChequeWithNotFoundDetection(printChequeCommand.getChequeId());
if (!BankChequeStatus.READY_TO_BE_PRINTED.getValue().equals(cheque.getStatus())) {
throw new BankChequeException("status", "invalid.loan.status.for.cheque.print");
}
final String query = "SELECT " + this.chequeMapper.schema() + " WHERE mbc.id = ? ";
ChequeData chequeData = this.jdbcTemplate.queryForObject(query, this.chequeMapper, cheque.getId());
final Long loanAccId = chequeData.getLoanAccId();
if (loanAccId != null && chequeData.getLoanAmount() != null) {
CommandProcessingResult result = this.loanWritePlatformService.disburseLoan(loanAccId, command, false);
if (result.getLoanId() == null) {
throw new BankChequeException("print.cheques", "failed.to.disburse.loan " + loanAccId);
}
}
cheque.setStatus(BankChequeStatus.ISSUED.getValue());
final LocalDateTime localDateTime = DateUtils.getLocalDateTimeOfSystem();
LocalDate localDate = DateUtils.getBusinessLocalDate();
final Long currentUserId = currentUser.getId();
cheque.stampAudit(currentUserId, localDateTime);
cheque.setPrintedBy(currentUser);
cheque.setPrintedDate(localDate);
this.chequeBatchRepositoryWrapper.updateCheque(cheque);
}
return new CommandProcessingResultBuilder().withCommandId(command.commandId()).build();
}
}
Loading
Loading