Resolving compilation issues with Email Campaigns Feature and resolving 322.2 migration script issue

This commit is contained in:
Nazeer Hussain Shaik
2017-11-21 18:51:18 +05:30
parent 2614ffdb29
commit 4dbecc7f0e
8 changed files with 378 additions and 367 deletions
@@ -3039,7 +3039,8 @@ public class CommandWrapperBuilder {
this.entityId = adHocId;
this.href = "/adhocquery/" + adHocId;
this.json = "{}";
return this ;
}
public CommandWrapperBuilder createEmail() {
this.actionName = "CREATE";
this.entityName = "EMAIL";
@@ -29,9 +29,7 @@ import org.apache.fineract.infrastructure.core.serialization.DefaultToApiJsonSer
import org.apache.fineract.infrastructure.core.service.Page;
import org.apache.fineract.infrastructure.core.service.SearchParameters;
import org.apache.fineract.infrastructure.security.service.PlatformSecurityContext;
import org.apache.fineract.infrastructure.campaigns.email.data.EmailConfigurationData;
import org.apache.fineract.infrastructure.campaigns.email.data.EmailData;
import org.apache.fineract.infrastructure.campaigns.email.service.EmailConfigurationReadPlatformService;
import org.apache.fineract.infrastructure.campaigns.email.service.EmailReadPlatformService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
@@ -41,9 +39,9 @@ import javax.ws.rs.*;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.UriInfo;
import java.util.Collection;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
@Path("/email")
@Consumes({ MediaType.APPLICATION_JSON })
@@ -58,68 +56,58 @@ public class EmailApiResource {
private final DefaultToApiJsonSerializer<EmailData> toApiJsonSerializer;
private final ApiRequestParameterHelper apiRequestParameterHelper;
private final PortfolioCommandSourceWritePlatformService commandsSourceWritePlatformService;
private final EmailConfigurationReadPlatformService emailConfigurationReadPlatformService;
@Autowired
public EmailApiResource(final PlatformSecurityContext context, final EmailReadPlatformService readPlatformService,
final DefaultToApiJsonSerializer<EmailData> toApiJsonSerializer, final ApiRequestParameterHelper apiRequestParameterHelper,
final PortfolioCommandSourceWritePlatformService commandsSourceWritePlatformService,
EmailConfigurationReadPlatformService emailConfigurationReadPlatformService) {
final PortfolioCommandSourceWritePlatformService commandsSourceWritePlatformService) {
this.context = context;
this.readPlatformService = readPlatformService;
this.toApiJsonSerializer = toApiJsonSerializer;
this.apiRequestParameterHelper = apiRequestParameterHelper;
this.commandsSourceWritePlatformService = commandsSourceWritePlatformService;
this.emailConfigurationReadPlatformService = emailConfigurationReadPlatformService;
}
@GET
public String retrieveAllEmails(@Context final UriInfo uriInfo) {
this.context.authenticatedUser().validateHasReadPermission(this.resourceNameForPermissions);
final Collection<EmailData> emailMessages = this.readPlatformService.retrieveAll();
final ApiRequestJsonSerializationSettings settings = this.apiRequestParameterHelper.process(uriInfo.getQueryParameters());
return this.toApiJsonSerializer.serialize(settings, emailMessages);
}
@GET
@Path("pendingEmail")
public String retrievePendingEmail(@QueryParam("sqlSearch") final String sqlSearch,
@QueryParam("offset") final Integer offset, @QueryParam("limit") final Integer limit,
@QueryParam("orderBy") final String orderBy, @QueryParam("sortOrder") final String sortOrder, @Context final UriInfo uriInfo) {
public String retrievePendingEmail(@QueryParam("sqlSearch") final String sqlSearch, @QueryParam("offset") final Integer offset,
@QueryParam("limit") final Integer limit, @QueryParam("orderBy") final String orderBy,
@QueryParam("sortOrder") final String sortOrder, @Context final UriInfo uriInfo) {
this.context.authenticatedUser().validateHasReadPermission(this.resourceNameForPermissions);
final SearchParameters searchParameters = SearchParameters.forEmailCampaign(sqlSearch, offset, limit, orderBy, sortOrder);
Page<EmailData> emailMessages = this.readPlatformService.retrieveAllPending(searchParameters);
Collection<EmailData> emailMessages = this.readPlatformService.retrieveAllPending(searchParameters);
final ApiRequestJsonSerializationSettings settings = this.apiRequestParameterHelper.process(uriInfo.getQueryParameters());
return this.toApiJsonSerializer.serialize(settings, emailMessages);
}
@GET
@Path("sentEmail")
public String retrieveSentEmail(@QueryParam("sqlSearch") final String sqlSearch,
@QueryParam("offset") final Integer offset, @QueryParam("limit") final Integer limit,
@QueryParam("orderBy") final String orderBy, @QueryParam("sortOrder") final String sortOrder, @Context final UriInfo uriInfo) {
public String retrieveSentEmail(@QueryParam("sqlSearch") final String sqlSearch, @QueryParam("offset") final Integer offset,
@QueryParam("limit") final Integer limit, @QueryParam("orderBy") final String orderBy,
@QueryParam("sortOrder") final String sortOrder, @Context final UriInfo uriInfo) {
this.context.authenticatedUser().validateHasReadPermission(this.resourceNameForPermissions);
final SearchParameters searchParameters = SearchParameters.forEmailCampaign(sqlSearch, offset, limit, orderBy, sortOrder);
Page<EmailData> emailMessages = this.readPlatformService.retrieveAllSent(searchParameters);
Collection<EmailData> emailMessages = this.readPlatformService.retrieveAllSent(searchParameters);
final ApiRequestJsonSerializationSettings settings = this.apiRequestParameterHelper.process(uriInfo.getQueryParameters());
return this.toApiJsonSerializer.serialize(settings, emailMessages);
}
@GET
@Path("messageByStatus")
public String retrieveAllEmailByStatus(@QueryParam("sqlSearch") final String sqlSearch,
@QueryParam("offset") final Integer offset, @QueryParam("limit") final Integer limit,
@QueryParam("status") final Long status,
public String retrieveAllEmailByStatus(@QueryParam("sqlSearch") final String sqlSearch, @QueryParam("offset") final Integer offset,
@QueryParam("limit") final Integer limit, @QueryParam("status") final Integer status,
@QueryParam("orderBy") final String orderBy, @QueryParam("sortOrder") final String sortOrder,
@QueryParam("fromDate") final DateParam fromDateParam, @QueryParam("toDate") final DateParam toDateParam,
@QueryParam("locale") final String locale, @QueryParam("dateFormat") final String dateFormat, @Context final UriInfo uriInfo) {
@@ -133,30 +121,26 @@ public class EmailApiResource {
if (toDateParam != null) {
toDate = toDateParam.getDate("toDate", dateFormat, locale);
}
final SearchParameters searchParameters = SearchParameters.forEmailCampaign(sqlSearch, offset, limit, status, fromDate,toDate, orderBy, sortOrder);
Page<EmailData> emailMessages = this.readPlatformService.retrieveEmailByStatus(searchParameters);
Page<EmailData> emailMessages = this.readPlatformService.retrieveEmailByStatus(limit, status, fromDate, toDate);
final ApiRequestJsonSerializationSettings settings = this.apiRequestParameterHelper.process(uriInfo.getQueryParameters());
return this.toApiJsonSerializer.serialize(settings, emailMessages);
}
@GET
@Path("failedEmail")
public String retrieveFailedEmail(@QueryParam("sqlSearch") final String sqlSearch,
@QueryParam("offset") final Integer offset, @QueryParam("limit") final Integer limit,
@QueryParam("orderBy") final String orderBy, @QueryParam("sortOrder") final String sortOrder, @Context final UriInfo uriInfo) {
public String retrieveFailedEmail(@QueryParam("sqlSearch") final String sqlSearch, @QueryParam("offset") final Integer offset,
@QueryParam("limit") final Integer limit, @QueryParam("orderBy") final String orderBy,
@QueryParam("sortOrder") final String sortOrder, @Context final UriInfo uriInfo) {
this.context.authenticatedUser().validateHasReadPermission(this.resourceNameForPermissions);
final SearchParameters searchParameters = SearchParameters.forEmailCampaign(sqlSearch, offset, limit, orderBy, sortOrder);
Page<EmailData> emailMessages = this.readPlatformService.retrieveAllFailed(searchParameters);
Collection<EmailData> emailMessages = this.readPlatformService.retrieveAllFailed(searchParameters);
final ApiRequestJsonSerializationSettings settings = this.apiRequestParameterHelper.process(uriInfo.getQueryParameters());
return this.toApiJsonSerializer.serialize(settings, emailMessages);
}
@POST
public String create(final String apiRequestBodyAsJson) {
@@ -45,9 +45,6 @@ import org.apache.fineract.infrastructure.dataqueries.exception.ReportNotFoundEx
import org.apache.fineract.infrastructure.dataqueries.service.GenericDataService;
import org.apache.fineract.infrastructure.dataqueries.service.ReadReportingService;
import org.apache.fineract.infrastructure.documentmanagement.contentrepository.FileSystemContentRepository;
import org.apache.fineract.infrastructure.reportmailingjob.data.ReportMailingJobEmailData;
import org.apache.fineract.infrastructure.reportmailingjob.domain.ReportMailingJob;
import org.apache.fineract.infrastructure.reportmailingjob.domain.ReportMailingJobEmailAttachmentFileFormat;
import org.apache.fineract.infrastructure.reportmailingjob.helper.IPv4Helper;
import org.apache.fineract.infrastructure.campaigns.email.data.EmailMessageWithAttachmentData;
import org.apache.fineract.infrastructure.campaigns.email.domain.*;
@@ -57,22 +54,17 @@ import org.apache.fineract.infrastructure.campaigns.email.exception.EmailCampaig
import org.apache.fineract.infrastructure.jobs.annotation.CronTarget;
import org.apache.fineract.infrastructure.jobs.exception.JobExecutionException;
import org.apache.fineract.infrastructure.jobs.service.JobName;
import org.apache.fineract.infrastructure.jobs.service.SchedularWritePlatformService;
import org.apache.fineract.infrastructure.security.service.PlatformSecurityContext;
import org.apache.fineract.infrastructure.campaigns.email.data.PreviewCampaignMessage;
import org.apache.fineract.infrastructure.campaigns.email.data.EmailCampaignData;
import org.apache.fineract.infrastructure.campaigns.email.data.EmailCampaignValidator;
import org.apache.fineract.organisation.staff.domain.Staff;
import org.apache.fineract.portfolio.calendar.service.CalendarUtils;
import org.apache.fineract.portfolio.client.domain.Client;
import org.apache.fineract.portfolio.client.domain.ClientRepositoryWrapper;
import org.apache.fineract.portfolio.loanaccount.domain.Loan;
import org.apache.fineract.portfolio.loanaccount.domain.LoanRepository;
import org.apache.fineract.portfolio.loanaccount.service.LoanReadPlatformService;
import org.apache.fineract.portfolio.savings.domain.SavingsAccount;
import org.apache.fineract.portfolio.savings.domain.SavingsAccountRepository;
import org.apache.fineract.template.domain.TemplateRepository;
import org.apache.fineract.template.service.TemplateMergeService;
import org.apache.fineract.useradministration.domain.AppUser;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -89,7 +81,6 @@ import java.util.*;
@Service
public class EmailCampaignWritePlatformCommandHandlerImpl implements EmailCampaignWritePlatformService {
private final static Logger logger = LoggerFactory.getLogger(EmailCampaignWritePlatformCommandHandlerImpl.class);
private final PlatformSecurityContext context;
@@ -98,43 +89,33 @@ public class EmailCampaignWritePlatformCommandHandlerImpl implements EmailCampai
private final EmailCampaignValidator emailCampaignValidator;
private final EmailCampaignReadPlatformService emailCampaignReadPlatformService;
private final ReportRepository reportRepository;
private final TemplateRepository templateRepository;
private final TemplateMergeService templateMergeService;
private final EmailMessageRepository emailMessageRepository;
private final ClientRepositoryWrapper clientRepositoryWrapper;
private final SchedularWritePlatformService schedularWritePlatformService;
private final ReadReportingService readReportingService;
private final GenericDataService genericDataService;
private final FromJsonHelper fromJsonHelper;
private final ReportParameterUsageRepository reportParameterUsageRepository;
private final LoanRepository loanRepository;
private final SavingsAccountRepository savingsAccountRepository;
private final EmailMessageJobEmailService emailMessageJobEmailService;
@Autowired
public EmailCampaignWritePlatformCommandHandlerImpl(final PlatformSecurityContext context, final EmailCampaignRepository emailCampaignRepository,
final EmailCampaignValidator emailCampaignValidator,final EmailCampaignReadPlatformService emailCampaignReadPlatformService,final ReportParameterUsageRepository reportParameterUsageRepository,
final ReportRepository reportRepository,final TemplateRepository templateRepository, final TemplateMergeService templateMergeService,
final EmailMessageRepository emailMessageRepository,final ClientRepositoryWrapper clientRepositoryWrapper,final SchedularWritePlatformService schedularWritePlatformService,
final ReadReportingService readReportingService, final GenericDataService genericDataService,final FromJsonHelper fromJsonHelper,
final LoanRepository loanRepository,final SavingsAccountRepository savingsAccountRepository,final EmailMessageJobEmailService emailMessageJobEmailService) {
public EmailCampaignWritePlatformCommandHandlerImpl(final PlatformSecurityContext context,
final EmailCampaignRepository emailCampaignRepository, final EmailCampaignValidator emailCampaignValidator,
final EmailCampaignReadPlatformService emailCampaignReadPlatformService, final ReportRepository reportRepository,
final EmailMessageRepository emailMessageRepository, final ClientRepositoryWrapper clientRepositoryWrapper,
final ReadReportingService readReportingService, final GenericDataService genericDataService,
final FromJsonHelper fromJsonHelper, final LoanRepository loanRepository,
final SavingsAccountRepository savingsAccountRepository, final EmailMessageJobEmailService emailMessageJobEmailService) {
this.context = context;
this.emailCampaignRepository = emailCampaignRepository;
this.emailCampaignValidator = emailCampaignValidator;
this.emailCampaignReadPlatformService = emailCampaignReadPlatformService;
this.reportRepository = reportRepository;
this.templateRepository = templateRepository;
this.templateMergeService = templateMergeService;
this.emailMessageRepository = emailMessageRepository;
this.clientRepositoryWrapper = clientRepositoryWrapper;
this.schedularWritePlatformService = schedularWritePlatformService;
this.readReportingService = readReportingService;
this.genericDataService = genericDataService;
this.fromJsonHelper = fromJsonHelper;
this.reportParameterUsageRepository = reportParameterUsageRepository;
this.loanRepository = loanRepository;
this.savingsAccountRepository = savingsAccountRepository;
this.emailMessageJobEmailService = emailMessageJobEmailService;
@@ -151,16 +132,12 @@ public class EmailCampaignWritePlatformCommandHandlerImpl implements EmailCampai
final Long businessRuleId = command.longValueOfParameterNamed(EmailCampaignValidator.businessRuleId);
final Report businessRule = this.reportRepository.findOne(businessRuleId);
if(businessRule == null){
throw new ReportNotFoundException(businessRuleId);
}
if (businessRule == null) { throw new ReportNotFoundException(businessRuleId); }
final Long reportId = command.longValueOfParameterNamed(EmailCampaignValidator.stretchyReportId);
final Report report = this.reportRepository.findOne(reportId);
if(report == null){
throw new ReportNotFoundException(reportId);
}
if (report == null) { throw new ReportNotFoundException(reportId); }
// find all report parameters and store them as json string
final Set<ReportParameterUsage> reportParameterUsages = report.getReportParameterUsages();
final Map<String, String> stretchyReportParams = new HashMap<>();
@@ -171,7 +148,6 @@ public class EmailCampaignWritePlatformCommandHandlerImpl implements EmailCampai
}
}
EmailCampaign emailCampaign = EmailCampaign.instance(currentUser, businessRule, report, command);
emailCampaign.setStretchyReportParamMap(new Gson().toJson(stretchyReportParams));
@@ -182,12 +158,12 @@ public class EmailCampaignWritePlatformCommandHandlerImpl implements EmailCampai
.withEntityId(emailCampaign.getId()) //
.build();
}
@Transactional
@Override
public CommandProcessingResult update(final Long resourceId, final JsonCommand command) {
try {
final AppUser currentUser = this.context.authenticatedUser();
this.context.authenticatedUser();
this.emailCampaignValidator.validateForUpdate(command.json());
final EmailCampaign emailCampaign = this.emailCampaignRepository.findOne(resourceId);
@@ -217,18 +193,18 @@ public class EmailCampaignWritePlatformCommandHandlerImpl implements EmailCampai
}
}
@Transactional
@Override
public CommandProcessingResult delete(final Long resourceId) {
final AppUser currentUser = this.context.authenticatedUser();
this.context.authenticatedUser();
final EmailCampaign emailCampaign = this.emailCampaignRepository.findOne(resourceId);
if (emailCampaign == null) { throw new EmailCampaignNotFound(resourceId); }
if (emailCampaign.isActive()) { throw new EmailCampaignMustBeClosedToBeDeletedException(emailCampaign.getId()); }
/*
Do not delete but set a boolean is_visible to zero
* Do not delete but set a boolean is_visible to zero
*/
emailCampaign.delete();
this.emailCampaignRepository.saveAndFlush(emailCampaign);
@@ -239,15 +215,17 @@ public class EmailCampaignWritePlatformCommandHandlerImpl implements EmailCampai
}
private void insertDirectCampaignIntoEmailOutboundTable(final String emailParams, final String emailSubject,
final String messageTemplate, final String campaignName, final Long campaignId) {
try {
HashMap<String,String> campaignParams = new ObjectMapper().readValue(emailParams, new TypeReference<HashMap<String,String>>(){});
HashMap<String, String> campaignParams = new ObjectMapper().readValue(emailParams,
new TypeReference<HashMap<String, String>>() {});
HashMap<String,String> queryParamForRunReport = new ObjectMapper().readValue(emailParams, new TypeReference<HashMap<String,String>>(){});
HashMap<String, String> queryParamForRunReport = new ObjectMapper().readValue(emailParams,
new TypeReference<HashMap<String, String>>() {});
List<HashMap<String,Object>> runReportObject = this.getRunReportByServiceImpl(campaignParams.get("reportName"),queryParamForRunReport);
List<HashMap<String, Object>> runReportObject = this.getRunReportByServiceImpl(campaignParams.get("reportName"),
queryParamForRunReport);
if (runReportObject != null) {
for (HashMap<String, Object> entry : runReportObject) {
@@ -258,7 +236,8 @@ public class EmailCampaignWritePlatformCommandHandlerImpl implements EmailCampai
String emailAddress = client.emailAddress();
if (emailAddress != null && isValidEmail(emailAddress)) {
EmailMessage emailMessage = EmailMessage.pendingEmail(null,client,null,emailCampaign,emailSubject,message,emailAddress,campaignName);
EmailMessage emailMessage = EmailMessage.pendingEmail(null, client, null, emailCampaign, emailSubject, message,
emailAddress, campaignName);
this.emailMessageRepository.save(emailMessage);
}
}
@@ -288,7 +267,8 @@ public class EmailCampaignWritePlatformCommandHandlerImpl implements EmailCampai
@Override
@CronTarget(jobName = JobName.UPDATE_EMAIL_OUTBOUND_WITH_CAMPAIGN_MESSAGE)
public void storeTemplateMessageIntoEmailOutBoundTable() throws JobExecutionException {
final Collection<EmailCampaignData> emailCampaignDataCollection = this.emailCampaignReadPlatformService.retrieveAllScheduleActiveCampaign();
final Collection<EmailCampaignData> emailCampaignDataCollection = this.emailCampaignReadPlatformService
.retrieveAllScheduleActiveCampaign();
if (emailCampaignDataCollection != null) {
for (EmailCampaignData emailCampaignData : emailCampaignDataCollection) {
LocalDateTime tenantDateNow = tenantDateTime();
@@ -296,7 +276,8 @@ public class EmailCampaignWritePlatformCommandHandlerImpl implements EmailCampai
logger.info("tenant time " + tenantDateNow.toString() + " trigger time " + nextTriggerDate.toString());
if (nextTriggerDate.isBefore(tenantDateNow)) {
insertDirectCampaignIntoEmailOutboundTable(emailCampaignData.getParamValue(),emailCampaignData.getEmailSubject(), emailCampaignData.getMessage(),emailCampaignData.getCampaignName(),emailCampaignData.getId());
insertDirectCampaignIntoEmailOutboundTable(emailCampaignData.getParamValue(), emailCampaignData.getEmailSubject(),
emailCampaignData.getMessage(), emailCampaignData.getCampaignName(), emailCampaignData.getId());
this.updateTriggerDates(emailCampaignData.getId());
}
}
@@ -305,26 +286,36 @@ public class EmailCampaignWritePlatformCommandHandlerImpl implements EmailCampai
private void updateTriggerDates(Long campaignId) {
final EmailCampaign emailCampaign = this.emailCampaignRepository.findOne(campaignId);
if(emailCampaign == null){
throw new EmailCampaignNotFound(campaignId);
}
if (emailCampaign == null) { throw new EmailCampaignNotFound(campaignId); }
LocalDateTime nextTriggerDate = emailCampaign.getNextTriggerDate();
emailCampaign.setLastTriggerDate(nextTriggerDate.toDate());
// calculate new trigger date and insert into next trigger date
/**
* next run time has to be in the future if not calculate a new future date
* next run time has to be in the future if not calculate a new future
* date
*/
LocalDate nextRuntime = CalendarUtils.getNextRecurringDate(emailCampaign.getRecurrence(), emailCampaign.getNextTriggerDate().toLocalDate(), nextTriggerDate.toLocalDate()) ;
if(nextRuntime.isBefore(DateUtils.getLocalDateOfTenant())){ // means next run time is in the past calculate a new future date
nextRuntime = CalendarUtils.getNextRecurringDate(emailCampaign.getRecurrence(), emailCampaign.getNextTriggerDate().toLocalDate(),DateUtils.getLocalDateOfTenant()) ;
LocalDate nextRuntime = CalendarUtils.getNextRecurringDate(emailCampaign.getRecurrence(),
emailCampaign.getNextTriggerDate().toLocalDate(), nextTriggerDate.toLocalDate());
if (nextRuntime.isBefore(DateUtils.getLocalDateOfTenant())) { // means
// next
// run
// time is
// in the
// past
// calculate
// a new
// future
// date
nextRuntime = CalendarUtils.getNextRecurringDate(emailCampaign.getRecurrence(),
emailCampaign.getNextTriggerDate().toLocalDate(), DateUtils.getLocalDateOfTenant());
}
final LocalDateTime getTime = emailCampaign.getRecurrenceStartDateTime();
final String dateString = nextRuntime.toString() + " " + getTime.getHourOfDay()+":"+getTime.getMinuteOfHour()+":"+getTime.getSecondOfMinute();
final String dateString = nextRuntime.toString() + " " + getTime.getHourOfDay() + ":" + getTime.getMinuteOfHour() + ":"
+ getTime.getSecondOfMinute();
final DateTimeFormatter simpleDateFormat = DateTimeFormat.forPattern("yyyy-MM-dd HH:mm:ss");
final LocalDateTime newTriggerDateWithTime = LocalDateTime.parse(dateString, simpleDateFormat);
emailCampaign.setNextTriggerDate(newTriggerDateWithTime.toDate());
this.emailCampaignRepository.saveAndFlush(emailCampaign);
}
@@ -338,11 +329,7 @@ public class EmailCampaignWritePlatformCommandHandlerImpl implements EmailCampai
final EmailCampaign emailCampaign = this.emailCampaignRepository.findOne(campaignId);
if(emailCampaign == null){
throw new EmailCampaignNotFound(campaignId);
}
if (emailCampaign == null) { throw new EmailCampaignNotFound(campaignId); }
final Locale locale = command.extractLocale();
final DateTimeFormatter fmt = DateTimeFormat.forPattern(command.dateFormat()).withLocale(locale);
@@ -353,25 +340,28 @@ public class EmailCampaignWritePlatformCommandHandlerImpl implements EmailCampai
this.emailCampaignRepository.saveAndFlush(emailCampaign);
if (emailCampaign.isDirect()) {
insertDirectCampaignIntoEmailOutboundTable(emailCampaign.getParamValue(),emailCampaign.getEmailSubject(),emailCampaign.getEmailMessage(),emailCampaign.getCampaignName(), emailCampaign.getId());
insertDirectCampaignIntoEmailOutboundTable(emailCampaign.getParamValue(), emailCampaign.getEmailSubject(),
emailCampaign.getEmailMessage(), emailCampaign.getCampaignName(), emailCampaign.getId());
} else {
if (emailCampaign.isSchedule()) {
/**
* if recurrence start date is in the future calculate
* next trigger date if not use recurrence start date us next trigger
* if recurrence start date is in the future calculate next
* trigger date if not use recurrence start date us next trigger
* date when activating
*/
LocalDate nextTriggerDate = null;
if (emailCampaign.getRecurrenceStartDateTime().isBefore(tenantDateTime())) {
nextTriggerDate = CalendarUtils.getNextRecurringDate(emailCampaign.getRecurrence(), emailCampaign.getRecurrenceStartDate(), DateUtils.getLocalDateOfTenant());
nextTriggerDate = CalendarUtils.getNextRecurringDate(emailCampaign.getRecurrence(),
emailCampaign.getRecurrenceStartDate(), DateUtils.getLocalDateOfTenant());
} else {
nextTriggerDate = emailCampaign.getRecurrenceStartDate();
}
// to get time of tenant
final LocalDateTime getTime = emailCampaign.getRecurrenceStartDateTime();
final String dateString = nextTriggerDate.toString() + " " + getTime.getHourOfDay()+":"+getTime.getMinuteOfHour()+":"+getTime.getSecondOfMinute();
final String dateString = nextTriggerDate.toString() + " " + getTime.getHourOfDay() + ":" + getTime.getMinuteOfHour() + ":"
+ getTime.getSecondOfMinute();
final DateTimeFormatter simpleDateFormat = DateTimeFormat.forPattern("yyyy-MM-dd HH:mm:ss");
final LocalDateTime nextTriggerDateWithTime = LocalDateTime.parse(dateString, simpleDateFormat);
@@ -381,8 +371,8 @@ public class EmailCampaignWritePlatformCommandHandlerImpl implements EmailCampai
}
/*
if campaign is direct insert campaign message into email outbound table
else if its a schedule create a job process for it
* if campaign is direct insert campaign message into email outbound
* table else if its a schedule create a job process for it
*/
return new CommandProcessingResultBuilder() //
.withCommandId(command.commandId()) //
@@ -398,9 +388,7 @@ public class EmailCampaignWritePlatformCommandHandlerImpl implements EmailCampai
this.emailCampaignValidator.validateClosedDate(command.json());
final EmailCampaign emailCampaign = this.emailCampaignRepository.findOne(campaignId);
if(emailCampaign == null){
throw new EmailCampaignNotFound(campaignId);
}
if (emailCampaign == null) { throw new EmailCampaignNotFound(campaignId); }
final Locale locale = command.extractLocale();
final DateTimeFormatter fmt = DateTimeFormat.forPattern(command.dateFormat()).withLocale(locale);
@@ -416,7 +404,8 @@ public class EmailCampaignWritePlatformCommandHandlerImpl implements EmailCampai
.build();
}
private String compileEmailTemplate(final String textMessageTemplate,final String campaignName , final Map<String, Object> emailParams) {
private String compileEmailTemplate(final String textMessageTemplate, final String campaignName,
final Map<String, Object> emailParams) {
final MustacheFactory mf = new DefaultMustacheFactory();
final Mustache mustache = mf.compile(new StringReader(textMessageTemplate), campaignName);
@@ -426,12 +415,14 @@ public class EmailCampaignWritePlatformCommandHandlerImpl implements EmailCampai
return stringWriter.toString();
}
private List<HashMap<String,Object>> getRunReportByServiceImpl(final String reportName,final Map<String, String> queryParams) throws IOException {
@SuppressWarnings({ "unused", "rawtypes" })
private List<HashMap<String, Object>> getRunReportByServiceImpl(final String reportName, final Map<String, String> queryParams)
throws IOException {
final String reportType = "report";
List<HashMap<String, Object>> resultList = new ArrayList<HashMap<String, Object>>();
final GenericResultsetData results = this.readReportingService.retrieveGenericResultSetForSmsEmailCampaign(reportName,
reportType, queryParams);
final GenericResultsetData results = this.readReportingService.retrieveGenericResultSetForSmsEmailCampaign(reportName, reportType,
queryParams);
final String response = this.genericDataService.generateJsonFromGenericResultsetData(results);
resultList = new ObjectMapper().readValue(response, new TypeReference<List<HashMap<String, Object>>>() {});
// loop changes array date to string date
@@ -440,7 +431,8 @@ public class EmailCampaignWritePlatformCommandHandlerImpl implements EmailCampai
String key = map.getKey();
Object ob = map.getValue();
if (ob instanceof ArrayList && ((ArrayList) ob).size() == 3) {
String changeArrayDateToStringDate = ((ArrayList) ob).get(2).toString() +"-"+((ArrayList) ob).get(1).toString() +"-"+((ArrayList) ob).get(0).toString();
String changeArrayDateToStringDate = ((ArrayList) ob).get(2).toString() + "-" + ((ArrayList) ob).get(1).toString() + "-"
+ ((ArrayList) ob).get(0).toString();
entry.put(key, changeArrayDateToStringDate);
}
}
@@ -451,17 +443,20 @@ public class EmailCampaignWritePlatformCommandHandlerImpl implements EmailCampai
@Override
public PreviewCampaignMessage previewMessage(final JsonQuery query) {
PreviewCampaignMessage campaignMessage = null;
final AppUser currentUser = this.context.authenticatedUser();
this.context.authenticatedUser();
this.emailCampaignValidator.validatePreviewMessage(query.json());
final String emailParams = this.fromJsonHelper.extractStringNamed("paramValue", query.parsedJson());
final String textMessageTemplate = this.fromJsonHelper.extractStringNamed("emailMessage", query.parsedJson());
try {
HashMap<String,String> campaignParams = new ObjectMapper().readValue(emailParams, new TypeReference<HashMap<String,String>>(){});
HashMap<String, String> campaignParams = new ObjectMapper().readValue(emailParams,
new TypeReference<HashMap<String, String>>() {});
HashMap<String,String> queryParamForRunReport = new ObjectMapper().readValue(emailParams, new TypeReference<HashMap<String,String>>(){});
HashMap<String, String> queryParamForRunReport = new ObjectMapper().readValue(emailParams,
new TypeReference<HashMap<String, String>>() {});
List<HashMap<String,Object>> runReportObject = this.getRunReportByServiceImpl(campaignParams.get("reportName"),queryParamForRunReport);
List<HashMap<String, Object>> runReportObject = this.getRunReportByServiceImpl(campaignParams.get("reportName"),
queryParamForRunReport);
if (runReportObject != null) {
for (HashMap<String, Object> entry : runReportObject) {
@@ -481,6 +476,7 @@ public class EmailCampaignWritePlatformCommandHandlerImpl implements EmailCampai
return campaignMessage;
}
@Transactional
@Override
public CommandProcessingResult reactivateEmailCampaign(final Long campaignId, JsonCommand command) {
@@ -500,19 +496,22 @@ public class EmailCampaignWritePlatformCommandHandlerImpl implements EmailCampai
if (emailCampaign.isSchedule()) {
/**
* if recurrence start date is in the future calculate
* next trigger date if not use recurrence start date us next trigger date when activating
* if recurrence start date is in the future calculate next trigger
* date if not use recurrence start date us next trigger date when
* activating
*/
LocalDate nextTriggerDate = null;
if (emailCampaign.getRecurrenceStartDateTime().isBefore(tenantDateTime())) {
nextTriggerDate = CalendarUtils.getNextRecurringDate(emailCampaign.getRecurrence(), emailCampaign.getRecurrenceStartDate(), DateUtils.getLocalDateOfTenant());
nextTriggerDate = CalendarUtils.getNextRecurringDate(emailCampaign.getRecurrence(), emailCampaign.getRecurrenceStartDate(),
DateUtils.getLocalDateOfTenant());
} else {
nextTriggerDate = emailCampaign.getRecurrenceStartDate();
}
// to get time of tenant
final LocalDateTime getTime = emailCampaign.getRecurrenceStartDateTime();
final String dateString = nextTriggerDate.toString() + " " + getTime.getHourOfDay()+":"+getTime.getMinuteOfHour()+":"+getTime.getSecondOfMinute();
final String dateString = nextTriggerDate.toString() + " " + getTime.getHourOfDay() + ":" + getTime.getMinuteOfHour() + ":"
+ getTime.getSecondOfMinute();
final DateTimeFormatter simpleDateFormat = DateTimeFormat.forPattern("yyyy-MM-dd HH:mm:ss");
final LocalDateTime nextTriggerDateWithTime = LocalDateTime.parse(dateString, simpleDateFormat);
@@ -520,15 +519,14 @@ public class EmailCampaignWritePlatformCommandHandlerImpl implements EmailCampai
this.emailCampaignRepository.saveAndFlush(emailCampaign);
}
return new CommandProcessingResultBuilder() //
.withEntityId(emailCampaign.getId()) //
.build();
}
private void handleDataIntegrityIssues(@SuppressWarnings("unused") final JsonCommand command, final DataIntegrityViolationException dve) {
private void handleDataIntegrityIssues(@SuppressWarnings("unused") final JsonCommand command,
final DataIntegrityViolationException dve) {
final Throwable realCause = dve.getMostSpecificCause();
throw new PlatformDataIntegrityException("error.msg.email.campaign.unknown.data.integrity.issue",
@@ -551,44 +549,54 @@ public class EmailCampaignWritePlatformCommandHandlerImpl implements EmailCampai
@Override
@CronTarget(jobName = JobName.EXECUTE_EMAIL)
public void sendEmailMessage() throws JobExecutionException {
if (IPv4Helper.applicationIsNotRunningOnLocalMachine()){ //remove when testing locally
final List<EmailMessage> emailMessages = this.emailMessageRepository.findByStatusType(EmailMessageStatusType.PENDING.getValue()); //retrieve all pending message
if (IPv4Helper.applicationIsNotRunningOnLocalMachine()) { // remove when
// testing
// locally
final List<EmailMessage> emailMessages = this.emailMessageRepository
.findByStatusType(EmailMessageStatusType.PENDING.getValue()); // retrieve
// all
// pending
// message
for (final EmailMessage emailMessage : emailMessages) {
if (isValidEmail(emailMessage.getEmailAddress())) {
final EmailCampaign emailCampaign = this.emailCampaignRepository.findOne(emailMessage.getEmailCampaign().getId()); //
final ScheduledEmailAttachmentFileFormat emailAttachmentFileFormat = ScheduledEmailAttachmentFileFormat.instance(emailCampaign.getEmailAttachmentFileFormat());
final ScheduledEmailAttachmentFileFormat emailAttachmentFileFormat = ScheduledEmailAttachmentFileFormat
.instance(emailCampaign.getEmailAttachmentFileFormat());
final List<File> attachmentList = new ArrayList<>();
final StringBuilder errorLog = new StringBuilder();
// check if email attachment format exist
if (emailAttachmentFileFormat != null && Arrays.asList(ScheduledEmailAttachmentFileFormat.validValues()).
contains(emailAttachmentFileFormat.getId())) {
if (emailAttachmentFileFormat != null && Arrays.asList(ScheduledEmailAttachmentFileFormat.validValues())
.contains(emailAttachmentFileFormat.getId())) {
final Report stretchyReport = emailCampaign.getStretchyReport();
final String reportName = (stretchyReport != null) ? stretchyReport.getReportName() : null;
final HashMap<String, String> reportStretchyParams = this.validateStretchyReportParamMap(emailCampaign.getStretchyReportParamMap());
final HashMap<String, String> reportStretchyParams = this
.validateStretchyReportParamMap(emailCampaign.getStretchyReportParamMap());
// there is a probability that a client has one or more loans or savings therefore we need to send two or more attachments
// there is a probability that a client has one or more
// loans or savings therefore we need to send two or
// more attachments
if (reportStretchyParams.containsKey("selectLoan") || reportStretchyParams.containsKey("loanId")) {
// get all ids of the client loans
if (emailMessage.getClient() != null) {
final List<Loan> loans = this.loanRepository.findLoanByClientId(emailMessage.getClient().getId());
HashMap<String, String> reportParams = this.replaceStretchyParamsWithActualClientParams(reportStretchyParams, emailMessage.getClient());
HashMap<String, String> reportParams = this
.replaceStretchyParamsWithActualClientParams(reportStretchyParams, emailMessage.getClient());
for (final Loan loan : loans) {
if (loan.isOpen()) { // only send attachment for active loan
if (loan.isOpen()) { // only send attachment
// for active loan
if (reportStretchyParams.containsKey("selectLoan")) {
@@ -598,7 +606,8 @@ public class EmailCampaignWritePlatformCommandHandlerImpl implements EmailCampai
reportParams.put("loanId", loan.getId().toString());
}
File file = this.generateAttachments(emailCampaign, emailAttachmentFileFormat, reportParams, reportName, errorLog);
File file = this.generateAttachments(emailCampaign, emailAttachmentFileFormat, reportParams,
reportName, errorLog);
if (file != null) {
attachmentList.add(file);
@@ -612,9 +621,11 @@ public class EmailCampaignWritePlatformCommandHandlerImpl implements EmailCampai
} else if (reportStretchyParams.containsKey("savingId")) {
if (emailMessage.getClient() != null) {
final List<SavingsAccount> savingsAccounts = this.savingsAccountRepository.findSavingAccountByClientId(emailMessage.getClient().getId());
final List<SavingsAccount> savingsAccounts = this.savingsAccountRepository
.findSavingAccountByClientId(emailMessage.getClient().getId());
HashMap<String, String> reportParams = this.replaceStretchyParamsWithActualClientParams(reportStretchyParams, emailMessage.getClient());
HashMap<String, String> reportParams = this
.replaceStretchyParamsWithActualClientParams(reportStretchyParams, emailMessage.getClient());
for (final SavingsAccount savingsAccount : savingsAccounts) {
@@ -622,7 +633,8 @@ public class EmailCampaignWritePlatformCommandHandlerImpl implements EmailCampai
reportParams.put("savingId", savingsAccount.getId().toString());
File file = this.generateAttachments(emailCampaign, emailAttachmentFileFormat, reportParams, reportName, errorLog);
File file = this.generateAttachments(emailCampaign, emailAttachmentFileFormat, reportParams,
reportName, errorLog);
if (file != null) {
attachmentList.add(file);
@@ -635,9 +647,11 @@ public class EmailCampaignWritePlatformCommandHandlerImpl implements EmailCampai
} else {
if (emailMessage.getClient() != null) {
HashMap<String, String> reportParams = this.replaceStretchyParamsWithActualClientParams(reportStretchyParams, emailMessage.getClient());
HashMap<String, String> reportParams = this
.replaceStretchyParamsWithActualClientParams(reportStretchyParams, emailMessage.getClient());
File file = this.generateAttachments(emailCampaign, emailAttachmentFileFormat, reportParams, reportName, errorLog);
File file = this.generateAttachments(emailCampaign, emailAttachmentFileFormat, reportParams, reportName,
errorLog);
if (file != null) {
attachmentList.add(file);
@@ -649,10 +663,20 @@ public class EmailCampaignWritePlatformCommandHandlerImpl implements EmailCampai
}
final EmailMessageWithAttachmentData emailMessageWithAttachmentData = EmailMessageWithAttachmentData.createNew(emailMessage.getEmailAddress(), emailMessage.getMessage(),
emailMessage.getEmailSubject(), attachmentList);
final EmailMessageWithAttachmentData emailMessageWithAttachmentData = EmailMessageWithAttachmentData.createNew(
emailMessage.getEmailAddress(), emailMessage.getMessage(), emailMessage.getEmailSubject(), attachmentList);
if (!attachmentList.isEmpty() && attachmentList.size() > 0) { // only send email message if there is an attachment to it
if (!attachmentList.isEmpty() && attachmentList.size() > 0) { // only
// send
// email
// message
// if
// there
// is
// an
// attachment
// to
// it
this.emailMessageJobEmailService.sendEmailWithAttachment(emailMessageWithAttachmentData);
@@ -671,11 +695,12 @@ public class EmailCampaignWritePlatformCommandHandlerImpl implements EmailCampai
}
}
/**
* This generates the the report and converts it to a file by passing the parameters below
* This generates the the report and converts it to a file by passing the
* parameters below
*
* @param emailCampaign
* @param emailAttachmentFileFormat
* @param reportParams
@@ -700,8 +725,7 @@ public class EmailCampaignWritePlatformCommandHandlerImpl implements EmailCampai
if (byteArrayOutputStream.size() == 0) {
errorLog.append("Pentaho report processing failed, empty output stream created");
}
else if (errorLog.length() == 0 && (byteArrayOutputStream.size() > 0)) {
} else if (errorLog.length() == 0 && (byteArrayOutputStream.size() > 0)) {
final String fileName = fileNameWithoutExtension + "." + emailAttachmentFileFormat.getValue();
final File file = new File(fileName);
@@ -712,25 +736,29 @@ public class EmailCampaignWritePlatformCommandHandlerImpl implements EmailCampai
}
} catch (IOException | PlatformDataIntegrityException e) {
errorLog.append("The ReportMailingJobWritePlatformServiceImpl.executeReportMailingJobs threw an IOException "
+ "exception: " + e.getMessage() + " ---------- ");
errorLog.append("The ReportMailingJobWritePlatformServiceImpl.executeReportMailingJobs threw an IOException " + "exception: "
+ e.getMessage() + " ---------- ");
}
return null;
}
/**
* This matches the the actual values to the key in the report stretchy parameters map
* This matches the the actual values to the key in the report stretchy
* parameters map
*
* @param stretchyParams
* @param client
* @return
*/
private HashMap<String,String> replaceStretchyParamsWithActualClientParams(final HashMap<String,String> stretchyParams,final Client client){
private HashMap<String, String> replaceStretchyParamsWithActualClientParams(final HashMap<String, String> stretchyParams,
final Client client) {
HashMap<String, String> actualParams = new HashMap<>();
for (Map.Entry<String, String> entry : stretchyParams.entrySet()) {
if (entry.getKey().equals("selectOffice")) {
//most at times the reports are run by picking the office of the staff Id
// most at times the reports are run by picking the office of
// the staff Id
if (client.getStaff() != null) {
actualParams.put(entry.getKey(), client.getStaff().officeId().toString());
} else {
@@ -753,7 +781,6 @@ public class EmailCampaignWritePlatformCommandHandlerImpl implements EmailCampai
return actualParams;
}
private HashMap<String, String> validateStretchyReportParamMap(final String stretchyParams) {
HashMap<String, String> stretchyReportParamHashMap = new HashMap<>();
@@ -771,5 +798,4 @@ public class EmailCampaignWritePlatformCommandHandlerImpl implements EmailCampai
return stretchyReportParamHashMap;
}
}
@@ -19,6 +19,7 @@
package org.apache.fineract.infrastructure.campaigns.email.service;
import org.apache.fineract.infrastructure.core.service.Page;
import org.apache.fineract.infrastructure.core.service.SearchParameters;
import org.apache.fineract.infrastructure.campaigns.email.data.EmailData;
import java.util.Collection;
@@ -31,13 +32,13 @@ public interface EmailReadPlatformService {
EmailData retrieveOne(Long resourceId);
Collection<EmailData> retrieveAllPending(Integer limit);
Collection<EmailData> retrieveAllPending(final SearchParameters searchParameters);
Collection<EmailData> retrieveAllSent(Integer limit);
Collection<EmailData> retrieveAllSent(final SearchParameters searchParameters);
Collection<EmailData> retrieveAllDelivered(Integer limit);
Collection<EmailData> retrieveAllFailed(Integer limit);
Collection<EmailData> retrieveAllFailed(final SearchParameters searchParameters);
Page<EmailData> retrieveEmailByStatus(Integer limit, Integer status, Date dateFrom, Date dateTo);
@@ -24,6 +24,7 @@ import org.apache.fineract.infrastructure.core.domain.JdbcSupport;
import org.apache.fineract.infrastructure.core.service.Page;
import org.apache.fineract.infrastructure.core.service.PaginationHelper;
import org.apache.fineract.infrastructure.core.service.RoutingDataSource;
import org.apache.fineract.infrastructure.core.service.SearchParameters;
import org.apache.fineract.infrastructure.campaigns.email.exception.EmailNotFoundException;
import org.apache.fineract.infrastructure.campaigns.email.data.EmailData;
import org.apache.fineract.infrastructure.campaigns.email.domain.EmailMessageEnumerations;
@@ -129,8 +130,8 @@ public class EmailReadPlatformServiceImpl implements EmailReadPlatformService {
}
@Override
public Collection<EmailData> retrieveAllPending(final Integer limit) {
final String sqlPlusLimit = (limit > 0) ? " limit 0, " + limit : "";
public Collection<EmailData> retrieveAllPending(final SearchParameters searchParameters) {
final String sqlPlusLimit = (searchParameters.getLimit() > 0) ? " limit 0, " + searchParameters.getLimit() : "";
final String sql = "select " + this.emailRowMapper.schema() + " where emo.status_enum = "
+ EmailMessageStatusType.PENDING.getValue() + sqlPlusLimit;
@@ -138,8 +139,8 @@ public class EmailReadPlatformServiceImpl implements EmailReadPlatformService {
}
@Override
public Collection<EmailData> retrieveAllSent(final Integer limit) {
final String sqlPlusLimit = (limit > 0) ? " limit 0, " + limit : "";
public Collection<EmailData> retrieveAllSent(final SearchParameters searchParameters) {
final String sqlPlusLimit = (searchParameters.getLimit() > 0) ? " limit 0, " + searchParameters.getLimit() : "";
final String sql = "select " + this.emailRowMapper.schema() + " where emo.status_enum = "
+ EmailMessageStatusType.SENT.getValue() + sqlPlusLimit;
@@ -165,8 +166,8 @@ public class EmailReadPlatformServiceImpl implements EmailReadPlatformService {
}
@Override
public Collection<EmailData> retrieveAllFailed(final Integer limit) {
final String sqlPlusLimit = (limit > 0) ? " limit 0, " + limit : "";
public Collection<EmailData> retrieveAllFailed(final SearchParameters searchParameters) {
final String sqlPlusLimit = (searchParameters.getLimit() > 0) ? " limit 0, " + searchParameters.getLimit() : "";
final String sql = "select " + this.emailRowMapper.schema() + " where emo.status_enum = "
+ EmailMessageStatusType.FAILED.getValue() + sqlPlusLimit;
@@ -19,6 +19,7 @@
package org.apache.fineract.infrastructure.dataqueries.service;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.io.InputStream;
@@ -49,16 +50,6 @@ import org.apache.fineract.infrastructure.documentmanagement.contentrepository.F
import org.apache.fineract.infrastructure.report.provider.ReportingProcessServiceProvider;
import org.apache.fineract.infrastructure.security.service.PlatformSecurityContext;
import org.apache.fineract.useradministration.domain.AppUser;
import org.pentaho.reporting.engine.classic.core.DefaultReportEnvironment;
import org.pentaho.reporting.engine.classic.core.MasterReport;
import org.pentaho.reporting.engine.classic.core.ReportProcessingException;
import org.pentaho.reporting.engine.classic.core.modules.output.pageable.pdf.PdfReportUtil;
import org.pentaho.reporting.engine.classic.core.modules.output.table.csv.CSVReportUtil;
import org.pentaho.reporting.engine.classic.core.modules.output.table.html.HtmlReportUtil;
import org.pentaho.reporting.engine.classic.core.modules.output.table.xls.ExcelReportUtil;
import org.pentaho.reporting.libraries.resourceloader.Resource;
import org.pentaho.reporting.libraries.resourceloader.ResourceException;
import org.pentaho.reporting.libraries.resourceloader.ResourceManager;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
@@ -530,6 +521,8 @@ public class ReadReportingServiceImpl implements ReadReportingService {
@Override
public ByteArrayOutputStream generatePentahoReportAsOutputStream(final String reportName, final String outputTypeParam, final Map<String, String> queryParams,
final Locale locale, final AppUser runReportAsUser, final StringBuilder errorLog) {
//This complete implementation should be moved to Pentaho Report Service
/*
String outputType = "HTML";
if (StringUtils.isNotBlank(outputTypeParam)) {
outputType = outputTypeParam;
@@ -600,6 +593,9 @@ public class ReadReportingServiceImpl implements ReadReportingService {
errorLog.append("ReadReportingServiceImpl.generatePentahoReportAsOutputStream method threw a PlatformDataIntegrityException "
+ "exception: No matching Output Type: " + outputType + " ---------- ");
throw new PlatformDataIntegrityException("error.msg.invalid.outputType", "No matching Output Type: " + outputType);
*/
return null ;
}
}
@@ -57,7 +57,8 @@
org.apache.fineract.template.service.*,
org.apache.fineract.useradministration.*,
org.apache.fineract.batch,
org.apache.fineract.adhocquery.*">
org.apache.fineract.adhocquery.*,
org.apache.fineract.infrastructure.campaigns.**">
<context:exclude-filter expression="org.springframework.stereotype.Controller"
type="annotation" />
@@ -84,6 +85,8 @@
<jpa:repositories base-package="org.apache.fineract.infrastructure.campaigns.sms.domain" />
<jpa:repositories base-package="org.apache.fineract.adhocquery.domain" />
<jpa:repositories base-package="org.apache.fineract.notification.domain"/>
<jpa:repositories base-package="org.apache.fineract.infrastructure.campaigns.email.domain"/>
<import resource="infrastructure.xml" />
@@ -34,78 +34,77 @@ INSERT INTO `stretchy_report` (`report_name`, `report_type`, `report_subtype`, `
INSERT INTO `stretchy_report` (`report_name`, `report_type`, `report_subtype`, `report_sql`, `description`, `core_report`, `use_report`) VALUES ('Loan Approved - Email', 'Email', 'Triggered', 'SELECT mc.id, mc.firstname, mc.middlename as middlename, mc.lastname, mc.display_name as FullName, mc.email_address as EmailAddress, mc.group_name as GroupName,\n mo.name as officename, ifnull(od.phoneNumber,\'\') as officenummber, ml.id as loanId, ml.account_no as accountnumber, ml.principal_amount_proposed as loanamount, ml.annual_nominal_interest_rate as annualinterestrate\n FROM\n m_office mo\n JOIN m_office ounder ON ounder.hierarchy LIKE CONCAT(mo.hierarchy, \'%\')\n AND ounder.hierarchy like CONCAT(\'.\', \'%\')\n LEFT JOIN (\n select \n ml.id as loanId, \n ifnull(mc.id,mc2.id) as id, \n ifnull(mc.firstname,mc2.firstname) as firstname, \n ifnull(mc.middlename,ifnull(mc2.middlename,(\'\'))) as middlename, \n ifnull(mc.lastname,mc2.lastname) as lastname, \n ifnull(mc.display_name,mc2.display_name) as display_name, \n ifnull(mc.status_enum,mc2.status_enum) as status_enum,\n ifnull(mc.email_address,mc2.email_address) as email_address,\n ifnull(mg.office_id,mc2.office_id) as office_id,\n ifnull(mg.staff_id,mc2.staff_id) as staff_id,\n mg.id as group_id, \nmg.display_name as group_name\n from\n m_loan ml\n left join m_group mg on mg.id = ml.group_id\n left join m_group_client mgc on mgc.group_id = mg.id\n left join m_client mc on mc.id = mgc.client_id\n left join m_client mc2 on mc2.id = ml.client_id\n order by loanId\n ) mc on mc.office_id = ounder.id\n left join ml_office_details as od on od.office_id = mo.id\n left join m_loan ml on ml.id = mc.loanId\n WHERE mc.status_enum = 300 and mc.email_address is not null\n and (mo.id = ${officeId} or ${officeId} = -1)\n and (mc.staff_id = ${staffId} or ${staffId} = -1)\nand (ml.id = ${loanId} or ${loanId} = -1)\nand (mc.id = ${clientId} or ${clientId} = -1)\nand (mc.group_id = ${groupId} or ${groupId} = -1)\nand (ml.loan_type_enum = ${loanType} or ${loanType} = -1)', 'Loan and client data of approved loan', '0', '0');
INSERT INTO `stretchy_report` (`report_name`, `report_type`, `report_subtype`, `report_sql`, `description`, `core_report`, `use_report`) VALUES ('Loan Repayment - Email', 'Email', 'Triggered', 'select ml.id as loanId,mc.id, mc.firstname, ifnull(mc.middlename,\'\') as middlename, mc.lastname, mc.display_name as FullName, email_address as EmailAddress, mc.group_name as GroupName, round(ml.principal_amount, ml.currency_digits) as LoanAmount, round(ml.`total_outstanding_derived`, ml.currency_digits) as LoanOutstanding,\nifnull(od.phoneNumber,\'\') as officenummber,ml.`account_no` as LoanAccountId, round(mlt.amountPaid, ml.currency_digits) as repaymentAmount\nFROM m_office mo\nJOIN m_office ounder ON ounder.hierarchy LIKE CONCAT(mo.hierarchy, \'%\')\nAND ounder.hierarchy like CONCAT(\'.\', \'%\')\nLEFT JOIN (\n select \n ml.id as loanId, \n ifnull(mc.id,mc2.id) as id, \n ifnull(mc.firstname,mc2.firstname) as firstname, \n ifnull(mc.middlename,ifnull(mc2.middlename,(\'\'))) as middlename, \n ifnull(mc.lastname,mc2.lastname) as lastname, \n ifnull(mc.display_name,mc2.display_name) as display_name, \n ifnull(mc.status_enum,mc2.status_enum) as status_enum,\n ifnull(mc.email_address,mc2.email_address) as email_address,\n ifnull(mg.office_id,mc2.office_id) as office_id,\n ifnull(mg.staff_id,mc2.staff_id) as staff_id,\n mg.id as group_id, \nmg.display_name as group_name\n from\n m_loan ml\n left join m_group mg on mg.id = ml.group_id\n left join m_group_client mgc on mgc.group_id = mg.id\n left join m_client mc on mc.id = mgc.client_id\n left join m_client mc2 on mc2.id = ml.client_id\n order by loanId\n ) mc on mc.office_id = ounder.id\nleft join ml_office_details as od on od.office_id = mo.id\nright join m_loan as ml on mc.loanId = ml.id\nright join(\nselect mlt.amount as amountPaid,mlt.id,mlt.loan_id\nfrom m_loan_transaction mlt\nwhere mlt.is_reversed = 0 \ngroup by mlt.loan_id\n) as mlt on mlt.loan_id = ml.id\nright join m_loan_repayment_schedule as mls1 on ml.id = mls1.loan_id and mls1.`completed_derived` = 0\nand mls1.installment = (SELECT MIN(installment) from m_loan_repayment_schedule where loan_id = ml.id and duedate <= CURDATE() and completed_derived=0)\nwhere mc.status_enum = 300 and email_address is not null and ml.`loan_status_id` = 300\nand (mo.id = ${officeId} or ${officeId} = -1)\nand (mc.staff_id = ${staffId} or ${staffId} = -1)\nand (ml.loan_type_enum = ${loanType} or ${loanType} = -1)\nand ml.id in (select mla.loan_id from m_loan_arrears_aging mla)\ngroup by ml.id', 'Loan Repayment', '0', '0');
INSERT INTO `stretchy_report_parameter` (`report_id`, `parameter_id`, `report_parameter_name`)
VALUES
( (SELECT id from stretchy_report where report_name = 'Active Clients - Email'), (SELECT id from stretchy_parameter where parameter_name = 'OfficeIdSelectOne'), 'Office'),
( (SELECT id from stretchy_report where report_name = 'Active Clients - Email'), (SELECT id from stretchy_parameter where parameter_name = 'LoanOfficerSelectOneRec'), 'Loanofficer'),
( (SELECT id from stretchy_report where report_name = 'Active Clients - Email'), (SELECT id from stretchy_parameter where parameter_name = 'loanOfficerIdSelectAll'), 'Loanofficer'),
( (SELECT id from stretchy_report where report_name = 'Prospective Clients - Email'), (SELECT id from stretchy_parameter where parameter_name = 'OfficeIdSelectOne'), 'Office'),
( (SELECT id from stretchy_report where report_name = 'Prospective Clients - Email'), (SELECT id from stretchy_parameter where parameter_name = 'LoanOfficerSelectOneRec'), 'Loanofficer'),
( (SELECT id from stretchy_report where report_name = 'Prospective Clients - Email'), (SELECT id from stretchy_parameter where parameter_name = 'loanOfficerIdSelectAll'), 'Loanofficer'),
( (SELECT id from stretchy_report where report_name = 'Active Loan Clients - Email'), (SELECT id from stretchy_parameter where parameter_name = 'OfficeIdSelectOne'), 'Office'),
( (SELECT id from stretchy_report where report_name = 'Active Loan Clients - Email'), (SELECT id from stretchy_parameter where parameter_name = 'LoanOfficerSelectOneRec'), 'Loanofficer'),
( (SELECT id from stretchy_report where report_name = 'Active Loan Clients - Email'), (SELECT id from stretchy_parameter where parameter_name = 'cycleX'), 'Cycle X'),
( (SELECT id from stretchy_report where report_name = 'Active Loan Clients - Email'), (SELECT id from stretchy_parameter where parameter_name = 'cycleY'), 'Cycle Y'),
( (SELECT id from stretchy_report where report_name = 'Active Loan Clients - Email'), (SELECT id from stretchy_parameter where parameter_name = 'loanOfficerIdSelectAll'), 'Loanofficer'),
( (SELECT id from stretchy_report where report_name = 'Active Loan Clients - Email'), (SELECT id from stretchy_parameter where parameter_name = 'cycleXSelect'), 'Cycle X'),
( (SELECT id from stretchy_report where report_name = 'Active Loan Clients - Email'), (SELECT id from stretchy_parameter where parameter_name = 'cycleYSelect'), 'Cycle Y'),
( (SELECT id from stretchy_report where report_name = 'Loans in arrears - Email'), (SELECT id from stretchy_parameter where parameter_name = 'OfficeIdSelectOne'), 'Office'),
( (SELECT id from stretchy_report where report_name = 'Loans in arrears - Email'), (SELECT id from stretchy_parameter where parameter_name = 'LoanOfficerSelectOneRec'), 'Loanofficer'),
( (SELECT id from stretchy_report where report_name = 'Loans in arrears - Email'), (SELECT id from stretchy_parameter where parameter_name = 'fromX'), 'fromX'),
( (SELECT id from stretchy_report where report_name = 'Loans in arrears - Email'), (SELECT id from stretchy_parameter where parameter_name = 'toY'), 'toY'),
( (SELECT id from stretchy_report where report_name = 'Loans in arrears - Email'), (SELECT id from stretchy_parameter where parameter_name = 'loanOfficerIdSelectAll'), 'Loanofficer'),
( (SELECT id from stretchy_report where report_name = 'Loans in arrears - Email'), (SELECT id from stretchy_parameter where parameter_name = 'fromXSelect'), 'fromX'),
( (SELECT id from stretchy_report where report_name = 'Loans in arrears - Email'), (SELECT id from stretchy_parameter where parameter_name = 'toYSelect'), 'toY'),
( (SELECT id from stretchy_report where report_name = 'Loans disbursed to clients - Email'), (SELECT id from stretchy_parameter where parameter_name = 'OfficeIdSelectOne'), 'Office'),
( (SELECT id from stretchy_report where report_name = 'Loans disbursed to clients - Email'), (SELECT id from stretchy_parameter where parameter_name = 'LoanOfficerSelectOneRec'), 'Loanofficer'),
( (SELECT id from stretchy_report where report_name = 'Loans disbursed to clients - Email'), (SELECT id from stretchy_parameter where parameter_name = 'fromX'), 'fromX'),
( (SELECT id from stretchy_report where report_name = 'Loans disbursed to clients - Email'), (SELECT id from stretchy_parameter where parameter_name = 'toY'), 'toY'),
( (SELECT id from stretchy_report where report_name = 'Loans disbursed to clients - Email'), (SELECT id from stretchy_parameter where parameter_name = 'cycleX'), 'Cycle X'),
( (SELECT id from stretchy_report where report_name = 'Loans disbursed to clients - Email'), (SELECT id from stretchy_parameter where parameter_name = 'cycleY'), 'Cycle Y'),
( (SELECT id from stretchy_report where report_name = 'Loans disbursed to clients - Email'), (SELECT id from stretchy_parameter where parameter_name = 'loanOfficerIdSelectAll'), 'Loanofficer'),
( (SELECT id from stretchy_report where report_name = 'Loans disbursed to clients - Email'), (SELECT id from stretchy_parameter where parameter_name = 'fromXSelect'), 'fromX'),
( (SELECT id from stretchy_report where report_name = 'Loans disbursed to clients - Email'), (SELECT id from stretchy_parameter where parameter_name = 'toYSelect'), 'toY'),
( (SELECT id from stretchy_report where report_name = 'Loans disbursed to clients - Email'), (SELECT id from stretchy_parameter where parameter_name = 'cycleXSelect'), 'Cycle X'),
( (SELECT id from stretchy_report where report_name = 'Loans disbursed to clients - Email'), (SELECT id from stretchy_parameter where parameter_name = 'cycleYSelect'), 'Cycle Y'),
( (SELECT id from stretchy_report where report_name = 'Loan payments due - Email'), (SELECT id from stretchy_parameter where parameter_name = 'OfficeIdSelectOne'), 'Office'),
( (SELECT id from stretchy_report where report_name = 'Loan payments due - Email'), (SELECT id from stretchy_parameter where parameter_name = 'LoanOfficerSelectOneRec'), 'Loanofficer'),
( (SELECT id from stretchy_report where report_name = 'Loan payments due - Email'), (SELECT id from stretchy_parameter where parameter_name = 'fromX'), 'fromX'),
( (SELECT id from stretchy_report where report_name = 'Loan payments due - Email'), (SELECT id from stretchy_parameter where parameter_name = 'toY'), 'toY'),
( (SELECT id from stretchy_report where report_name = 'Loan payments due - Email'), (SELECT id from stretchy_parameter where parameter_name = 'loanOfficerIdSelectAll'), 'Loanofficer'),
( (SELECT id from stretchy_report where report_name = 'Loan payments due - Email'), (SELECT id from stretchy_parameter where parameter_name = 'fromXSelect'), 'fromX'),
( (SELECT id from stretchy_report where report_name = 'Loan payments due - Email'), (SELECT id from stretchy_parameter where parameter_name = 'toYSelect'), 'toY'),
( (SELECT id from stretchy_report where report_name = 'Dormant Prospects - Email'), (SELECT id from stretchy_parameter where parameter_name = 'OfficeIdSelectOne'), 'Office'),
( (SELECT id from stretchy_report where report_name = 'Dormant Prospects - Email'), (SELECT id from stretchy_parameter where parameter_name = 'LoanOfficerSelectOneRec'), 'Loanofficer'),
( (SELECT id from stretchy_report where report_name = 'Dormant Prospects - Email'), (SELECT id from stretchy_parameter where parameter_name = 'loanOfficerIdSelectAll'), 'Loanofficer'),
( (SELECT id from stretchy_report where report_name = 'Active Group Leaders - Email'), (SELECT id from stretchy_parameter where parameter_name = 'OfficeIdSelectOne'), 'Office'),
( (SELECT id from stretchy_report where report_name = 'Active Group Leaders - Email'), (SELECT id from stretchy_parameter where parameter_name = 'LoanOfficerSelectOneRec'), 'Loanofficer'),
( (SELECT id from stretchy_report where report_name = 'Active Group Leaders - Email'), (SELECT id from stretchy_parameter where parameter_name = 'loanOfficerIdSelectAll'), 'Loanofficer'),
( (SELECT id from stretchy_report where report_name = 'Loan Payments Due (Overdue Loans) - Email'), (SELECT id from stretchy_parameter where parameter_name = 'OfficeIdSelectOne'), 'Office'),
( (SELECT id from stretchy_report where report_name = 'Loan Payments Due (Overdue Loans) - Email'), (SELECT id from stretchy_parameter where parameter_name = 'LoanOfficerSelectOneRec'), 'Loanofficer'),
( (SELECT id from stretchy_report where report_name = 'Loan Payments Due (Overdue Loans) - Email'), (SELECT id from stretchy_parameter where parameter_name = 'fromX'), 'fromX'),
( (SELECT id from stretchy_report where report_name = 'Loan Payments Due (Overdue Loans) - Email'), (SELECT id from stretchy_parameter where parameter_name = 'toY'), 'toY'),
( (SELECT id from stretchy_report where report_name = 'Loan Payments Due (Overdue Loans) - Email'), (SELECT id from stretchy_parameter where parameter_name = 'overdueX'), 'overdueX'),
( (SELECT id from stretchy_report where report_name = 'Loan Payments Due (Overdue Loans) - Email'), (SELECT id from stretchy_parameter where parameter_name = 'overdueY'), 'overdueY'),
( (SELECT id from stretchy_report where report_name = 'Loan Payments Due (Overdue Loans) - Email'), (SELECT id from stretchy_parameter where parameter_name = 'loanOfficerIdSelectAll'), 'Loanofficer'),
( (SELECT id from stretchy_report where report_name = 'Loan Payments Due (Overdue Loans) - Email'), (SELECT id from stretchy_parameter where parameter_name = 'fromXSelect'), 'fromX'),
( (SELECT id from stretchy_report where report_name = 'Loan Payments Due (Overdue Loans) - Email'), (SELECT id from stretchy_parameter where parameter_name = 'toYSelect'), 'toY'),
( (SELECT id from stretchy_report where report_name = 'Loan Payments Due (Overdue Loans) - Email'), (SELECT id from stretchy_parameter where parameter_name = 'overdueXSelect'), 'overdueX'),
( (SELECT id from stretchy_report where report_name = 'Loan Payments Due (Overdue Loans) - Email'), (SELECT id from stretchy_parameter where parameter_name = 'overdueYSelect'), 'overdueY'),
( (SELECT id from stretchy_report where report_name = 'Loan Payments Received (Active Loans) - Email'), (SELECT id from stretchy_parameter where parameter_name = 'OfficeIdSelectOne'), 'Office'),
( (SELECT id from stretchy_report where report_name = 'Loan Payments Received (Active Loans) - Email'), (SELECT id from stretchy_parameter where parameter_name = 'LoanOfficerSelectOneRec'), 'Loanofficer'),
( (SELECT id from stretchy_report where report_name = 'Loan Payments Received (Active Loans) - Email'), (SELECT id from stretchy_parameter where parameter_name = 'fromX'), 'fromX'),
( (SELECT id from stretchy_report where report_name = 'Loan Payments Received (Active Loans) - Email'), (SELECT id from stretchy_parameter where parameter_name = 'toY'), 'toY'),
( (SELECT id from stretchy_report where report_name = 'Loan Payments Received (Active Loans) - Email'), (SELECT id from stretchy_parameter where parameter_name = 'loanOfficerIdSelectAll'), 'Loanofficer'),
( (SELECT id from stretchy_report where report_name = 'Loan Payments Received (Active Loans) - Email'), (SELECT id from stretchy_parameter where parameter_name = 'fromXSelect'), 'fromX'),
( (SELECT id from stretchy_report where report_name = 'Loan Payments Received (Active Loans) - Email'), (SELECT id from stretchy_parameter where parameter_name = 'toYSelect'), 'toY'),
( (SELECT id from stretchy_report where report_name = 'Loan Payments Received (Overdue Loans) - Email'), (SELECT id from stretchy_parameter where parameter_name = 'OfficeIdSelectOne'), 'Office'),
( (SELECT id from stretchy_report where report_name = 'Loan Payments Received (Overdue Loans) - Email'), (SELECT id from stretchy_parameter where parameter_name = 'LoanOfficerSelectOneRec'), 'Loanofficer'),
( (SELECT id from stretchy_report where report_name = 'Loan Payments Received (Overdue Loans) - Email'), (SELECT id from stretchy_parameter where parameter_name = 'fromX'), 'fromX'),
( (SELECT id from stretchy_report where report_name = 'Loan Payments Received (Overdue Loans) - Email'), (SELECT id from stretchy_parameter where parameter_name = 'toY'), 'toY'),
( (SELECT id from stretchy_report where report_name = 'Loan Payments Received (Overdue Loans) - Email'), (SELECT id from stretchy_parameter where parameter_name = 'overdueX'), 'overdueX'),
( (SELECT id from stretchy_report where report_name = 'Loan Payments Received (Overdue Loans) - Email'), (SELECT id from stretchy_parameter where parameter_name = 'overdueY'), 'overdueY'),
( (SELECT id from stretchy_report where report_name = 'Loan Payments Received (Overdue Loans) - Email'), (SELECT id from stretchy_parameter where parameter_name = 'loanOfficerIdSelectAll'), 'Loanofficer'),
( (SELECT id from stretchy_report where report_name = 'Loan Payments Received (Overdue Loans) - Email'), (SELECT id from stretchy_parameter where parameter_name = 'fromXSelect'), 'fromX'),
( (SELECT id from stretchy_report where report_name = 'Loan Payments Received (Overdue Loans) - Email'), (SELECT id from stretchy_parameter where parameter_name = 'toYSelect'), 'toY'),
( (SELECT id from stretchy_report where report_name = 'Loan Payments Received (Overdue Loans) - Email'), (SELECT id from stretchy_parameter where parameter_name = 'overdueXSelect'), 'overdueX'),
( (SELECT id from stretchy_report where report_name = 'Loan Payments Received (Overdue Loans) - Email'), (SELECT id from stretchy_parameter where parameter_name = 'overdueYSelect'), 'overdueY'),
( (SELECT id from stretchy_report where report_name = 'Happy Birthday - Email'), (SELECT id from stretchy_parameter where parameter_name = 'OfficeIdSelectOne'), 'Office'),
( (SELECT id from stretchy_report where report_name = 'Happy Birthday - Email'), (SELECT id from stretchy_parameter where parameter_name = 'LoanOfficerSelectOneRec'), 'Loanofficer'),
( (SELECT id from stretchy_report where report_name = 'Happy Birthday - Email'), (SELECT id from stretchy_parameter where parameter_name = 'loanOfficerIdSelectAll'), 'Loanofficer'),
( (SELECT id from stretchy_report where report_name = 'Loan Fully Repaid - Email'), (SELECT id from stretchy_parameter where parameter_name = 'OfficeIdSelectOne'), 'Office'),
( (SELECT id from stretchy_report where report_name = 'Loan Fully Repaid - Email'), (SELECT id from stretchy_parameter where parameter_name = 'LoanOfficerSelectOneRec'), 'Loanofficer'),
( (SELECT id from stretchy_report where report_name = 'Loan Fully Repaid - Email'), (SELECT id from stretchy_parameter where parameter_name = 'fromX'), 'fromX'),
( (SELECT id from stretchy_report where report_name = 'Loan Fully Repaid - Email'), (SELECT id from stretchy_parameter where parameter_name = 'toY'), 'toY'),
( (SELECT id from stretchy_report where report_name = 'Loan Fully Repaid - Email'), (SELECT id from stretchy_parameter where parameter_name = 'loanOfficerIdSelectAll'), 'Loanofficer'),
( (SELECT id from stretchy_report where report_name = 'Loan Fully Repaid - Email'), (SELECT id from stretchy_parameter where parameter_name = 'fromXSelect'), 'fromX'),
( (SELECT id from stretchy_report where report_name = 'Loan Fully Repaid - Email'), (SELECT id from stretchy_parameter where parameter_name = 'toYSelect'), 'toY'),
( (SELECT id from stretchy_report where report_name = 'Loans Outstanding after final instalment date - Email'), (SELECT id from stretchy_parameter where parameter_name = 'OfficeIdSelectOne'), 'Office'),
( (SELECT id from stretchy_report where report_name = 'Loans Outstanding after final instalment date - Email'), (SELECT id from stretchy_parameter where parameter_name = 'toY'), 'toY'),
( (SELECT id from stretchy_report where report_name = 'Loans Outstanding after final instalment date - Email'), (SELECT id from stretchy_parameter where parameter_name = 'fromX'), 'fromX'),
( (SELECT id from stretchy_report where report_name = 'Loans Outstanding after final instalment date - Email'), (SELECT id from stretchy_parameter where parameter_name = 'LoanOfficerSelectOneRec'), 'Loanofficer'),
( (SELECT id from stretchy_report where report_name = 'Loans Outstanding after final instalment date - Email'), (SELECT id from stretchy_parameter where parameter_name = 'toYSelect'), 'toY'),
( (SELECT id from stretchy_report where report_name = 'Loans Outstanding after final instalment date - Email'), (SELECT id from stretchy_parameter where parameter_name = 'fromXSelect'), 'fromX'),
( (SELECT id from stretchy_report where report_name = 'Loans Outstanding after final instalment date - Email'), (SELECT id from stretchy_parameter where parameter_name = 'loanOfficerIdSelectAll'), 'Loanofficer'),
( (SELECT id from stretchy_report where report_name = 'Loan Rejected - Email'), (SELECT id from stretchy_parameter where parameter_name = 'OfficeIdSelectOne'), 'Office'),
( (SELECT id from stretchy_report where report_name = 'Loan Rejected - Email'), (SELECT id from stretchy_parameter where parameter_name = 'LoanOfficerSelectOneRec'), 'Loanofficer'),
( (SELECT id from stretchy_report where report_name = 'Loan Rejected - Email'), (SELECT id from stretchy_parameter where parameter_name = 'loanOfficerIdSelectAll'), 'Loanofficer'),
( (SELECT id from stretchy_report where report_name = 'Loan Rejected - Email'), (SELECT id from stretchy_parameter where parameter_name = 'DefaultLoan'), 'loanId'),
( (SELECT id from stretchy_report where report_name = 'Loan Rejected - Email'), (SELECT id from stretchy_parameter where parameter_name = 'DefaultClient'), 'clientId'),
( (SELECT id from stretchy_report where report_name = 'Loan Rejected - Email'), (SELECT id from stretchy_parameter where parameter_name = 'DefaultGroup'), 'groupId'),
( (SELECT id from stretchy_report where report_name = 'Loan Rejected - Email'), (SELECT id from stretchy_parameter where parameter_name = 'SelectLoanType'), 'loanType'),
( (SELECT id from stretchy_report where report_name = 'Loan Approved - Email'), (SELECT id from stretchy_parameter where parameter_name = 'OfficeIdSelectOne'), 'Office'),
( (SELECT id from stretchy_report where report_name = 'Loan Approved - Email'), (SELECT id from stretchy_parameter where parameter_name = 'LoanOfficerSelectOneRec'), 'Loanofficer'),
( (SELECT id from stretchy_report where report_name = 'Loan Approved - Email'), (SELECT id from stretchy_parameter where parameter_name = 'loanOfficerIdSelectAll'), 'Loanofficer'),
( (SELECT id from stretchy_report where report_name = 'Loan Approved - Email'), (SELECT id from stretchy_parameter where parameter_name = 'DefaultLoan'), 'loanId'),
( (SELECT id from stretchy_report where report_name = 'Loan Approved - Email'), (SELECT id from stretchy_parameter where parameter_name = 'DefaultClient'), 'clientId'),
( (SELECT id from stretchy_report where report_name = 'Loan Approved - Email'), (SELECT id from stretchy_parameter where parameter_name = 'DefaultGroup'), 'groupId'),
( (SELECT id from stretchy_report where report_name = 'Loan Approved - Email'), (SELECT id from stretchy_parameter where parameter_name = 'SelectLoanType'), 'loanType'),
( (SELECT id from stretchy_report where report_name = 'Loan Repayment - Email'), (SELECT id from stretchy_parameter where parameter_name = 'OfficeIdSelectOne'), 'Office'),
( (SELECT id from stretchy_report where report_name = 'Loan Repayment - Email'), (SELECT id from stretchy_parameter where parameter_name = 'LoanOfficerSelectOneRec'), 'Loanofficer'),
( (SELECT id from stretchy_report where report_name = 'Loan Repayment - Email'), (SELECT id from stretchy_parameter where parameter_name = 'loanOfficerIdSelectAll'), 'Loanofficer'),
( (SELECT id from stretchy_report where report_name = 'Loan Repayment - Email'), (SELECT id from stretchy_parameter where parameter_name = 'SelectLoanType'), 'loanType');
INSERT INTO `m_permission` (`grouping`, `code`, `entity_name`, `action_name`, `can_maker_checker`)
VALUES
('report', 'READ_Active Clients - Email', 'Active Clients - Email', 'READ', 0),