/* * eGov suite of products aim to improve the internal efficiency,transparency, * accountability and the service delivery of the government organizations. * * Copyright (C) <2015> eGovernments Foundation * * The updated version of eGov suite of products as by eGovernments Foundation * is available at http://www.egovernments.org * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see http://www.gnu.org/licenses/ or * http://www.gnu.org/licenses/gpl.html . * * In addition to the terms of the GPL license to be adhered to in using this * program, the following additional terms are to be complied with: * * 1) All versions of this program, verbatim or modified must carry this * Legal Notice. * * 2) Any misrepresentation of the origin of the material is prohibited. It * is required that all modified versions of this material be marked in * reasonable ways as different from the original version. * * 3) This license does not grant any rights to any user of the program * with regards to rights under trademark law for use of the trade names * or trademarks of eGovernments Foundation. * * In case of any queries, you can reach eGovernments Foundation at contact@egovernments.org. */ package org.egov.collection.web.actions.receipts; import java.math.BigInteger; import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; import java.util.Date; import java.util.HashMap; import java.util.List; import java.util.Locale; import java.util.TreeMap; import org.apache.commons.lang3.StringUtils; import org.apache.log4j.Logger; import org.apache.struts2.convention.annotation.Action; import org.apache.struts2.convention.annotation.ParentPackage; import org.apache.struts2.convention.annotation.Result; import org.apache.struts2.convention.annotation.Results; import org.apache.struts2.interceptor.validation.SkipValidation; import org.egov.collection.constants.CollectionConstants; import org.egov.collection.entity.CollectionBankRemittanceReport; import org.egov.collection.entity.ReceiptHeader; import org.egov.collection.service.ReceiptHeaderService; import org.egov.collection.service.RemittanceServiceImpl; import org.egov.collection.utils.CollectionsUtil; import org.egov.commons.Bankaccount; import org.egov.commons.CFinancialYear; import org.egov.commons.dao.BankaccountHibernateDAO; import org.egov.commons.dao.FinancialYearDAO; import org.egov.eis.entity.Employee; import org.egov.eis.entity.Jurisdiction; import org.egov.eis.service.EmployeeService; import org.egov.infra.admin.master.entity.Boundary; import org.egov.infra.admin.master.entity.User; import org.egov.infra.exception.ApplicationRuntimeException; import org.egov.infra.validation.exception.ValidationError; import org.egov.infra.validation.exception.ValidationException; import org.egov.infra.web.struts.actions.BaseFormAction; import org.egov.infra.web.struts.annotation.ValidationErrorPage; import org.hibernate.Query; import org.springframework.beans.factory.annotation.Autowired; @Results({ @Result(name = BankRemittanceAction.NEW, location = "bankRemittance-new.jsp"), @Result(name = BankRemittanceAction.PRINT_BANK_CHALLAN, type = "redirectAction", location = "remittanceStatementReport-printBankChallan.action", params = { "namespace", "/reports", "totalCashAmount", "${totalCashAmount}", "totalChequeAmount", "${totalChequeAmount}", "bank", "${bank}", "bankAccount", "${bankAccount}", "remittanceDate", "${remittanceDate}" }), @Result(name = BankRemittanceAction.INDEX, location = "bankRemittance-index.jsp") }) @ParentPackage("egov") public class BankRemittanceAction extends BaseFormAction { private static final long serialVersionUID = 1L; private static final Logger LOGGER = Logger.getLogger(BankRemittanceAction.class); private List<HashMap<String, Object>> paramList = null; private final ReceiptHeader receiptHeaderIntsance = new ReceiptHeader(); private List<ReceiptHeader> voucherHeaderValues = new ArrayList<ReceiptHeader>(0); private String[] serviceNameArray; private String[] totalCashAmountArray; private String[] totalChequeAmountArray; private String[] totalCardAmountArray; private String[] receiptDateArray; private String[] receiptNumberArray; private String[] fundCodeArray; private String[] departmentCodeArray; private Integer accountNumberId; private CollectionsUtil collectionsUtil; private Integer branchId; private static final String ACCOUNT_NUMBER_LIST = "accountNumberList"; private Boolean isListData = false; // Added for Manual Work Flow private Integer positionUser; private Integer designationId; private Date remittanceDate; @Autowired private FinancialYearDAO financialYearDAO; @Autowired private EmployeeService employeeService; @Autowired private BankaccountHibernateDAO bankaccountHibernateDAO; protected static final String PRINT_BANK_CHALLAN = "printBankChallan"; private Double totalCashAmount; private Double totalChequeAmount; private List<CollectionBankRemittanceReport> bankRemittanceList; private String bank; private String bankAccount; private Boolean showCardAndOnlineColumn = false; private Boolean showRemittanceDate = false; private Long finYearId; private RemittanceServiceImpl remittanceService; private String voucherNumber; private TreeMap<String, String> paymentModesMap = new TreeMap<String, String>(); private String paymentMode; private Date fromDate; private Date toDate; private Integer pageSize; /** * @param collectionsUtil * the collectionsUtil to set */ public void setCollectionsUtil(final CollectionsUtil collectionsUtil) { this.collectionsUtil = collectionsUtil; } @Action(value = "/receipts/bankRemittance-newform") @SkipValidation public String newform() { populateRemittanceList(); return NEW; } private void populateRemittanceList() { final AjaxBankRemittanceAction ajaxBankRemittanceAction = new AjaxBankRemittanceAction(); ajaxBankRemittanceAction.setPersistenceService(getPersistenceService()); ajaxBankRemittanceAction.bankBranchListOfService(); addDropdownData("bankBranchList", ajaxBankRemittanceAction.getBankBranchArrayList()); if (branchId != null) { ajaxBankRemittanceAction.setBranchId(branchId); ajaxBankRemittanceAction.accountListOfService(); addDropdownData(ACCOUNT_NUMBER_LIST, ajaxBankRemittanceAction.getBankAccountArrayList()); } else addDropdownData(ACCOUNT_NUMBER_LIST, Collections.EMPTY_LIST); addDropdownData("financialYearList", financialYearDAO.getAllPriorFinancialYears(new Date())); final TreeMap<String, String> paymentModes = new TreeMap<String, String>() { { put(CollectionConstants.INSTRUMENTTYPE_CASH, CollectionConstants.INSTRUMENTTYPE_CASH); put(CollectionConstants.INSTRUMENTTYPE_CHEQUEORDD, CollectionConstants.INSTRUMENTTYPE_CHEQUEORDD); } }; paymentModesMap.putAll(paymentModes); } public String getJurisdictionBoundary() { final User user = collectionsUtil.getLoggedInUser(); final Employee employee = employeeService.getEmployeeById(user.getId()); final StringBuilder jurValuesId = new StringBuilder(); for (final Jurisdiction element : employee.getJurisdictions()) { if (jurValuesId.length() > 0) jurValuesId.append(','); jurValuesId.append(element.getBoundary().getId()); for (final Boundary boundary : element.getBoundary().getChildren()) { jurValuesId.append(','); jurValuesId.append(boundary.getId()); } } return jurValuesId.toString(); } @Action(value = "/receipts/bankRemittance-listData") @SkipValidation public String listData() { isListData = true; populateRemittanceList(); if (fromDate != null && fromDate.before(financialYearDAO.getFinancialYearByDate(new Date()).getStartingDate())) addActionError(getText("bankremittance.error.fromdate.lessthan.financialyear")); if (toDate != null && toDate.before(financialYearDAO.getFinancialYearByDate(new Date()).getStartingDate())) addActionError(getText("bankremittance.error.todate.lessthan.financialyear")); if (fromDate != null && toDate != null && toDate.before(fromDate)) addActionError(getText("bankremittance.before.fromdate")); if (!hasErrors()) { final String serviceFundQueryStr = "select distinct sd.code as servicecode,fd.code as fundcode from BANKACCOUNT ba," + "EGCL_BANKACCOUNTSERVICEMAPPING asm,EGCL_SERVICEDETAILS sd,FUND fd where asm.BANKACCOUNT=ba.ID and asm.servicedetails=sd.ID and fd.ID=ba.FUNDID and " + "ba.id=" + accountNumberId; final Query serviceFundQuery = persistenceService.getSession().createSQLQuery(serviceFundQueryStr); final List<Object[]> queryResults = serviceFundQuery.list(); final List serviceCodeList = new ArrayList<String>(0); final List fundCodeList = new ArrayList<String>(0); for (int i = 0; i < queryResults.size(); i++) { final Object[] arrayObjectInitialIndex = queryResults.get(i); serviceCodeList.add(arrayObjectInitialIndex[0].toString()); fundCodeList.add(arrayObjectInitialIndex[1].toString()); } final CFinancialYear financialYear = financialYearDAO.getFinancialYearById(finYearId); paramList = remittanceService.findAllRemittanceDetailsForServiceAndFund(getJurisdictionBoundary(), "'" + StringUtils.join(serviceCodeList, "','") + "'", "'" + StringUtils.join(fundCodeList, "','") + "'", fromDate == null ? financialYear.getStartingDate() : fromDate, toDate == null ? financialYear.getEndingDate() : toDate, paymentMode); if (fromDate != null && toDate != null) pageSize = paramList.size(); else pageSize = CollectionConstants.DEFAULT_PAGE_SIZE; } return NEW; } @Action(value = "/receipts/bankRemittance-printBankChallan") @SkipValidation public String printBankChallan() { return PRINT_BANK_CHALLAN; } public String edit() { return EDIT; } public String save() { return SUCCESS; } @Override public void prepare() { super.prepare(); final String showColumn = collectionsUtil.getAppConfigValue(CollectionConstants.MODULE_NAME_COLLECTIONS_CONFIG, CollectionConstants.APPCONFIG_VALUE_COLLECTION_BANKREMITTANCE_SHOWCOLUMNSCARDONLINE); if (!showColumn.isEmpty() && showColumn.equals(CollectionConstants.YES)) showCardAndOnlineColumn = true; final String showRemitDate = collectionsUtil.getAppConfigValue( CollectionConstants.MODULE_NAME_COLLECTIONS_CONFIG, CollectionConstants.APPCONFIG_VALUE_COLLECTION_BANKREMITTANCE_SHOWREMITDATE); if (!showRemitDate.isEmpty() && showRemitDate.equals(CollectionConstants.YES)) showRemittanceDate = true; addDropdownData("bankBranchList", Collections.EMPTY_LIST); addDropdownData("accountNumberList", Collections.EMPTY_LIST); } @Action(value = "/receipts/bankRemittance-create") @ValidationErrorPage(value = NEW) public String create() throws InstantiationException, IllegalAccessException { final long startTimeMillis = System.currentTimeMillis(); BigInteger accountNumber = null; String serviceName = ""; String fundCode = ""; for (int i = 0; i < getServiceNameArray().length; i++) if (getServiceNameArray() != null && !getServiceNameArray()[i].isEmpty()) { serviceName = getServiceNameArray()[i]; fundCode = getFundCodeArray()[i]; break; } final String bankAccountStr = "select distinct asm.BANKACCOUNT from BANKACCOUNT ba," + "EGCL_BANKACCOUNTSERVICEMAPPING asm,EGCL_SERVICEDETAILS sd,FUND fd where asm.BANKACCOUNT=ba.ID and asm.servicedetails=sd.ID and fd.ID=ba.FUNDID and " + "sd.name= '" + serviceName + "' and fd.code='" + fundCode + "'"; final Query bankAccountQry = persistenceService.getSession().createSQLQuery(bankAccountStr); if (bankAccountQry.list().size() > 1) throw new ValidationException(Arrays.asList(new ValidationError( "Mulitple Bank Accounts for the same Service and Fund is mapped. Please correct the data", "bankremittance.error.multiplebankaccounterror"))); final Object queryResults = bankAccountQry.uniqueResult(); accountNumber = (BigInteger) queryResults; accountNumberId = accountNumber != null ? accountNumber.intValue() : accountNumberId; if (accountNumber == null || accountNumber.equals(-1) || accountNumber != null && accountNumber.intValue() != accountNumberId) throw new ValidationException(Arrays.asList(new ValidationError( "Bank Account for the Service and Fund is not mapped", "bankremittance.error.bankaccounterror"))); voucherHeaderValues = remittanceService.createBankRemittance(getServiceNameArray(), getTotalCashAmountArray(), getTotalChequeAmountArray(), getTotalCardAmountArray(), getReceiptDateArray(), getFundCodeArray(), getDepartmentCodeArray(), accountNumberId, positionUser, getReceiptNumberArray(), remittanceDate); final long elapsedTimeMillis = System.currentTimeMillis() - startTimeMillis; LOGGER.info("$$$$$$ Time taken to persist the remittance list (ms) = " + elapsedTimeMillis); bankRemittanceList = remittanceService.prepareBankRemittanceReport(voucherHeaderValues); if (getSession().get("REMITTANCE_LIST") != null) getSession().remove("REMITTANCE_LIST"); getSession().put("REMITTANCE_LIST", bankRemittanceList); final Bankaccount bankAcc = bankaccountHibernateDAO.findById(Long.valueOf(accountNumberId), false); bankAccount = bankAcc.getAccountnumber(); bank = bankAcc.getBankbranch().getBank().getName(); totalCashAmount = getSum(getTotalCashAmountArray()); totalChequeAmount = getSum(getTotalChequeAmountArray()); return INDEX; } private Double getSum(final String[] array) { Double sum = 0.0; for (final String num : array) if (!num.isEmpty()) sum = sum + Double.valueOf(num); return sum; } @Override public void validate() { super.validate(); populateRemittanceList(); listData(); final SimpleDateFormat dateFomatter = new SimpleDateFormat("yyyy-MM-dd", Locale.getDefault()); if (receiptDateArray != null) { final String[] filterReceiptDateArray = removeNullValue(receiptDateArray); final String receiptEndDate = filterReceiptDateArray[filterReceiptDateArray.length - 1]; if (!receiptEndDate.isEmpty()) try { if (remittanceDate != null && remittanceDate.before(dateFomatter.parse(receiptEndDate))) addActionError(getText("bankremittance.before.receiptdate")); } catch (final ParseException e) { LOGGER.debug("Exception in parsing date " + receiptEndDate + " - " + e.getMessage()); throw new ApplicationRuntimeException("Exception while parsing receiptEndDate date", e); } } } private String[] removeNullValue(String[] receiptDateArray) { final List<String> list = new ArrayList<String>(); for (final String s : receiptDateArray) if (s != null && s.length() > 0) list.add(s); receiptDateArray = list.toArray(new String[list.size()]); return receiptDateArray; } @Override public Object getModel() { return receiptHeaderIntsance; } public void setReceiptHeaderService(final ReceiptHeaderService receiptHeaderService) { } /** * @return the paramList */ public List<HashMap<String, Object>> getParamList() { return paramList; } /** * @param paramList * the paramList to set */ public void setParamList(final List<HashMap<String, Object>> paramList) { this.paramList = paramList; } /** * @return the serviceName */ public String[] getServiceNameArray() { return serviceNameArray; } /** * @param serviceName * the serviceName to set */ public void setServiceNameArray(final String[] serviceNameArray) { this.serviceNameArray = serviceNameArray; } /** * @return the totalCashAmount */ public String[] getTotalCashAmountArray() { return totalCashAmountArray; } /** * @param totalCashAmount * the totalCashAmount to set */ public void setTotalCashAmountArray(final String[] totalCashAmountArray) { this.totalCashAmountArray = totalCashAmountArray; } /** * @return the totalChequeAmount */ public String[] getTotalChequeAmountArray() { return totalChequeAmountArray; } /** * @param totalChequeAmount * the totalChequeAmount to set */ public void setTotalChequeAmountArray(final String[] totalChequeAmountArray) { this.totalChequeAmountArray = totalChequeAmountArray; } /** * @return the receiptDate */ public String[] getReceiptDateArray() { return receiptDateArray; } /** * @param receiptDate * the receiptDate to set */ public void setReceiptDateArray(final String[] receiptDateArray) { this.receiptDateArray = receiptDateArray; } /** * @return the voucherHeaderValues */ public List<ReceiptHeader> getVoucherHeaderValues() { return voucherHeaderValues; } /** * @param voucherHeaderValues * the voucherHeaderValues to set */ public void setVoucherHeaderValues(final List<ReceiptHeader> voucherHeaderValues) { this.voucherHeaderValues = voucherHeaderValues; } /** * @return the fundCodeArray */ public String[] getFundCodeArray() { return fundCodeArray; } /** * @param fundCodeArray * the fundCodeArray to set */ public void setFundCodeArray(final String[] fundCodeArray) { this.fundCodeArray = fundCodeArray; } /** * @return the departmentCodeArray */ public String[] getDepartmentCodeArray() { return departmentCodeArray; } /** * @param departmentCodeArray * the departmentCodeArray to set */ public void setDepartmentCodeArray(final String[] departmentCodeArray) { this.departmentCodeArray = departmentCodeArray; } /** * @return the totalCardAmountArray */ public String[] getTotalCardAmountArray() { return totalCardAmountArray; } /** * @param totalCardAmountArray * the totalCardAmountArray to set */ public void setTotalCardAmountArray(final String[] totalCardAmountArray) { this.totalCardAmountArray = totalCardAmountArray; } /** * @return the positionUser */ public Integer getPositionUser() { return positionUser; } /** * @param positionUser * the positionUser to set */ public void setPositionUser(final Integer positionUser) { this.positionUser = positionUser; } /** * @return the designationId */ public Integer getDesignationId() { return designationId; } /** * @param designationId * the designationId to set */ public void setDesignationId(final Integer designationId) { this.designationId = designationId; } public String[] getReceiptNumberArray() { return receiptNumberArray; } public void setReceiptNumberArray(final String[] receiptNumberArray) { this.receiptNumberArray = receiptNumberArray; } public Integer getBranchId() { return branchId; } public void setBranchId(final Integer branchId) { this.branchId = branchId; } public Integer getAccountNumberId() { return accountNumberId; } public void setAccountNumberId(final Integer accountNumberId) { this.accountNumberId = accountNumberId; } public Boolean getIsListData() { return isListData; } public void setIsListData(final Boolean isListData) { this.isListData = isListData; } public Double getTotalCashAmount() { return totalCashAmount; } public void setTotalCashAmount(final Double totalCashAmount) { this.totalCashAmount = totalCashAmount; } public Double getTotalChequeAmount() { return totalChequeAmount; } public void setTotalChequeAmount(final Double totalChequeAmount) { this.totalChequeAmount = totalChequeAmount; } public List<CollectionBankRemittanceReport> getBankRemittanceList() { return bankRemittanceList; } public void setBankRemittanceList(final List<CollectionBankRemittanceReport> bankRemittanceList) { this.bankRemittanceList = bankRemittanceList; } public String getBank() { return bank; } public void setBank(final String bank) { this.bank = bank; } public String getBankAccount() { return bankAccount; } public void setBankAccount(final String bankAccount) { this.bankAccount = bankAccount; } public Boolean getShowCardAndOnlineColumn() { return showCardAndOnlineColumn; } public void setShowCardAndOnlineColumn(final Boolean showCardAndOnlineColumn) { this.showCardAndOnlineColumn = showCardAndOnlineColumn; } public Boolean getShowRemittanceDate() { return showRemittanceDate; } public void setShowRemittanceDate(final Boolean showRemittanceDate) { this.showRemittanceDate = showRemittanceDate; } public Date getRemittanceDate() { return remittanceDate; } public void setRemittanceDate(final Date remittanceDate) { this.remittanceDate = remittanceDate; } public Long getFinYearId() { return finYearId; } public void setFinYearId(final Long finYearId) { this.finYearId = finYearId; } public void setRemittanceService(final RemittanceServiceImpl remittanceService) { this.remittanceService = remittanceService; } public String getVoucherNumber() { return voucherNumber; } public void setVoucherNumber(final String voucherNumber) { this.voucherNumber = voucherNumber; } public TreeMap<String, String> getPaymentModesMap() { return paymentModesMap; } public void setPaymentModesMap(final TreeMap<String, String> paymentModesMap) { this.paymentModesMap = paymentModesMap; } public String getPaymentMode() { return paymentMode; } public void setPaymentMode(final String paymentMode) { this.paymentMode = paymentMode; } public Date getFromDate() { return fromDate; } public void setFromDate(Date fromDate) { this.fromDate = fromDate; } public Date getToDate() { return toDate; } public void setToDate(Date toDate) { this.toDate = toDate; } public Integer getPageSize() { return pageSize; } public void setPageSize(Integer pageSize) { this.pageSize = pageSize; } }