First commit (wating to add alerts in budget)
This commit is contained in:
@@ -60,9 +60,8 @@ public interface IExceptionMessage {
|
||||
|
||||
static final String EVENT_MEETING_INVITATION_1 = /*$$(*/
|
||||
"No PERSON IS INVITED TO THIS MEETING" /*)*/;
|
||||
|
||||
static final String USER_EMAIL_1 = /*$$(*/
|
||||
"No email address associated to %s" /*)*/;
|
||||
|
||||
static final String USER_EMAIL_1 = /*$$(*/ "No email address associated to %s" /*)*/;
|
||||
|
||||
/** Lead controller */
|
||||
static final String LEAD_1 = /*$$(*/ "Please select the Lead(s) to print." /*)*/;
|
||||
|
||||
@@ -17,15 +17,14 @@
|
||||
*/
|
||||
package com.axelor.apps.crm.service;
|
||||
|
||||
|
||||
import com.axelor.apps.base.db.AppBase;
|
||||
import com.axelor.apps.base.service.app.AppBaseService;
|
||||
import com.axelor.apps.base.db.Address;
|
||||
import com.axelor.apps.base.db.AppBase;
|
||||
import com.axelor.apps.base.db.ICalendarUser;
|
||||
import com.axelor.apps.base.db.Partner;
|
||||
import com.axelor.apps.base.db.repo.PartnerRepository;
|
||||
import com.axelor.apps.base.ical.ICalendarService;
|
||||
import com.axelor.apps.base.service.PartnerService;
|
||||
import com.axelor.apps.base.service.app.AppBaseService;
|
||||
import com.axelor.apps.crm.db.Event;
|
||||
import com.axelor.apps.crm.db.Lead;
|
||||
import com.axelor.apps.crm.db.RecurrenceConfiguration;
|
||||
@@ -34,14 +33,12 @@ import com.axelor.apps.crm.db.repo.LeadRepository;
|
||||
import com.axelor.apps.crm.db.repo.RecurrenceConfigurationRepository;
|
||||
import com.axelor.apps.crm.exception.IExceptionMessage;
|
||||
import com.axelor.apps.message.db.EmailAddress;
|
||||
import com.axelor.apps.message.db.Template;
|
||||
import com.axelor.apps.message.db.repo.EmailAddressRepository;
|
||||
import com.axelor.apps.message.service.MessageService;
|
||||
import com.axelor.apps.message.service.TemplateMessageService;
|
||||
import com.axelor.apps.message.db.Template;
|
||||
import com.axelor.auth.db.User;
|
||||
import com.axelor.exception.AxelorException;
|
||||
import javax.mail.MessagingException;
|
||||
import java.io.IOException;
|
||||
import com.axelor.exception.db.repo.TraceBackRepository;
|
||||
import com.axelor.i18n.I18n;
|
||||
import com.axelor.inject.Beans;
|
||||
@@ -52,6 +49,7 @@ import com.axelor.mail.db.repo.MailFollowerRepository;
|
||||
import com.google.common.base.Strings;
|
||||
import com.google.inject.Inject;
|
||||
import com.google.inject.persist.Transactional;
|
||||
import java.io.IOException;
|
||||
import java.time.DayOfWeek;
|
||||
import java.time.Duration;
|
||||
import java.time.LocalDate;
|
||||
@@ -60,11 +58,12 @@ import java.time.format.DateTimeFormatter;
|
||||
import java.time.temporal.TemporalAdjusters;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.function.BiFunction;
|
||||
import java.util.function.Function;
|
||||
import java.util.stream.Collectors;
|
||||
import javax.mail.MessagingException;
|
||||
import org.apache.commons.math3.exception.TooManyIterationsException;
|
||||
|
||||
public class EventServiceImpl implements EventService {
|
||||
@@ -664,30 +663,28 @@ public class EventServiceImpl implements EventService {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendEmailMeetingInvitation(Event event, Set<User> users) throws ClassNotFoundException, InstantiationException, IllegalAccessException,
|
||||
public void sendEmailMeetingInvitation(Event event, Set<User> users)
|
||||
throws ClassNotFoundException, InstantiationException, IllegalAccessException,
|
||||
MessagingException, IOException, AxelorException {
|
||||
AppBase appBase = Beans.get(AppBaseService.class).getAppBase();
|
||||
Template template = appBase.getSendMailToInvitedPersonInMeetingTemplate();
|
||||
AppBase appBase = Beans.get(AppBaseService.class).getAppBase();
|
||||
Template template = appBase.getSendMailToInvitedPersonInMeetingTemplate();
|
||||
|
||||
if (template == null) {
|
||||
throw new AxelorException(
|
||||
appBase,
|
||||
TraceBackRepository.CATEGORY_NO_VALUE,
|
||||
I18n.get("Template for sending meeting invitation is missing.")
|
||||
);
|
||||
}
|
||||
if (template == null) {
|
||||
throw new AxelorException(
|
||||
appBase,
|
||||
TraceBackRepository.CATEGORY_NO_VALUE,
|
||||
I18n.get("Template for sending meeting invitation is missing."));
|
||||
}
|
||||
|
||||
TemplateMessageService templateMessageService = Beans.get(TemplateMessageService.class);
|
||||
|
||||
try {
|
||||
templateMessageService.generateAndSendMessageToBulkUsers(event, template, users);
|
||||
} catch (MessagingException e) {
|
||||
throw new AxelorException(
|
||||
TraceBackRepository.CATEGORY_NO_VALUE,
|
||||
I18n.get("Failed to send meeting invitation email."),
|
||||
e
|
||||
);
|
||||
}
|
||||
TemplateMessageService templateMessageService = Beans.get(TemplateMessageService.class);
|
||||
|
||||
try {
|
||||
templateMessageService.generateAndSendMessageToBulkUsers(event, template, users);
|
||||
} catch (MessagingException e) {
|
||||
throw new AxelorException(
|
||||
TraceBackRepository.CATEGORY_NO_VALUE,
|
||||
I18n.get("Failed to send meeting invitation email."),
|
||||
e);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -63,10 +63,8 @@ import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.Map;
|
||||
|
||||
import org.apache.commons.math3.ode.events.EventState;
|
||||
import java.util.Set;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
@@ -75,7 +73,6 @@ public class EventController {
|
||||
|
||||
@Inject ImportationFolderRepository importationFolderRepository;
|
||||
|
||||
|
||||
private static final Logger LOG = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
|
||||
|
||||
public void computeFromStartDateTime(ActionRequest request, ActionResponse response) {
|
||||
@@ -557,10 +554,23 @@ public class EventController {
|
||||
public void setImportationFolderEvent(ActionRequest request, ActionResponse response) {
|
||||
Event event = new Event();
|
||||
|
||||
final ArrayList<String> importationSequences = new ArrayList(Arrays.asList("PREPARATION","ENTAME","VALIDATION COA/FICHE TECHNIQUE","LOGISTIQUE","TRANSIT","DEDOUANEMENT","RECEPTION"));
|
||||
final ArrayList<String> importationSequences =
|
||||
new ArrayList(
|
||||
Arrays.asList(
|
||||
"PREPARATION",
|
||||
"ENTAME",
|
||||
"VALIDATION COA/FICHE TECHNIQUE",
|
||||
"LOGISTIQUE",
|
||||
"TRANSIT",
|
||||
"DEDOUANEMENT",
|
||||
"RECEPTION"));
|
||||
|
||||
ImportationFolder importationFolder = Beans.get(ImportationFolderRepository.class).find(request.getContext().asType(ImportationFolder.class).getId());
|
||||
event.setSubject(importationSequences.get(Integer.parseInt(request.getContext().get("statusSelect").toString())));
|
||||
ImportationFolder importationFolder =
|
||||
Beans.get(ImportationFolderRepository.class)
|
||||
.find(request.getContext().asType(ImportationFolder.class).getId());
|
||||
event.setSubject(
|
||||
importationSequences.get(
|
||||
Integer.parseInt(request.getContext().get("statusSelect").toString())));
|
||||
event.setStatusSelect(1);
|
||||
event.setStartDateTime(LocalDateTime.now());
|
||||
event.setEndDateTime(LocalDateTime.now().plusDays(10));
|
||||
@@ -572,22 +582,19 @@ public class EventController {
|
||||
response.setReload(true);
|
||||
}
|
||||
|
||||
|
||||
public void openRoqApplication(ActionRequest request, ActionResponse response) {
|
||||
|
||||
|
||||
String uri = Beans.get(AppBaseService.class).getAppBase().getRoqURL();
|
||||
|
||||
LOG.debug("link {}",uri+AuthUtils.getUser().getId());
|
||||
LOG.debug("link {}", uri + AuthUtils.getUser().getId());
|
||||
|
||||
response.setView(
|
||||
ActionView.define(I18n.get("ROQ"))
|
||||
.model("")
|
||||
.add("html", uri +AuthUtils.getUser().getId())
|
||||
.map());
|
||||
response.setView(
|
||||
ActionView.define(I18n.get("ROQ"))
|
||||
.model("")
|
||||
.add("html", uri + AuthUtils.getUser().getId())
|
||||
.map());
|
||||
}
|
||||
|
||||
|
||||
public void printMeeting(ActionRequest request, ActionResponse response) throws AxelorException {
|
||||
Event event = request.getContext().asType(Event.class);
|
||||
event = Beans.get(EventRepository.class).find(event.getId());
|
||||
@@ -601,41 +608,41 @@ public class EventController {
|
||||
.generate()
|
||||
.getFileLink();
|
||||
|
||||
|
||||
response.setView(ActionView.define(eventName).add("html", fileLink).map());
|
||||
}
|
||||
|
||||
public void sendMailToGuests(ActionRequest request, ActionResponse response) throws AxelorException {
|
||||
public void sendMailToGuests(ActionRequest request, ActionResponse response)
|
||||
throws AxelorException {
|
||||
|
||||
Event event = request.getContext().asType(Event.class);
|
||||
event = Beans.get(EventRepository.class).find(event.getId());
|
||||
Event event = request.getContext().asType(Event.class);
|
||||
event = Beans.get(EventRepository.class).find(event.getId());
|
||||
|
||||
Set<User> users = event.getGuestList();
|
||||
if (event.getUser() != null)
|
||||
users.add(event.getUser());
|
||||
users.add(event.getCreatedBy());
|
||||
Set<User> users = event.getGuestList();
|
||||
if (event.getUser() != null) users.add(event.getUser());
|
||||
users.add(event.getCreatedBy());
|
||||
|
||||
if (!users.isEmpty()) {
|
||||
// Check if all users have an email address
|
||||
for (User user : users) {
|
||||
if (user.getEmail() == null) {
|
||||
response.setFlash(I18n.get(String.format(IExceptionMessage.USER_EMAIL_1, user.getName())));
|
||||
return; // Exit the method if any user lacks an email
|
||||
}
|
||||
}
|
||||
|
||||
// All users have emails; proceed to send emails
|
||||
try {
|
||||
Beans.get(EventService.class).sendEmailMeetingInvitation(event,users);
|
||||
} catch (Exception e) {
|
||||
LOG.error(e.getMessage());
|
||||
return; // Exit if any email fails to send
|
||||
}
|
||||
|
||||
response.setFlash(I18n.get("Emails successfully sent to all guests."));
|
||||
|
||||
} else {
|
||||
response.setFlash(I18n.get(IExceptionMessage.EVENT_MEETING_INVITATION_1));
|
||||
if (!users.isEmpty()) {
|
||||
// Check if all users have an email address
|
||||
for (User user : users) {
|
||||
if (user.getEmail() == null) {
|
||||
response.setFlash(
|
||||
I18n.get(String.format(IExceptionMessage.USER_EMAIL_1, user.getName())));
|
||||
return; // Exit the method if any user lacks an email
|
||||
}
|
||||
}
|
||||
|
||||
// All users have emails; proceed to send emails
|
||||
try {
|
||||
Beans.get(EventService.class).sendEmailMeetingInvitation(event, users);
|
||||
} catch (Exception e) {
|
||||
LOG.error(e.getMessage());
|
||||
return; // Exit if any email fails to send
|
||||
}
|
||||
|
||||
response.setFlash(I18n.get("Emails successfully sent to all guests."));
|
||||
|
||||
} else {
|
||||
response.setFlash(I18n.get(IExceptionMessage.EVENT_MEETING_INVITATION_1));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user