use of com.axelor.team.db.Team in project axelor-open-suite by axelor.
the class TargetService method update.
@Transactional
public void update(Target target) {
User user = target.getUser();
Team team = target.getTeam();
LocalDate fromDate = target.getFromDate();
LocalDate toDate = target.getToDate();
LocalDateTime fromDateTime = fromDate.atStartOfDay();
LocalDateTime toDateTime = toDate.atTime(23, 59);
if (user != null) {
Query q = JPA.em().createQuery("select SUM(op.amount) FROM Opportunity as op WHERE op.user = ?1 AND op.salesStageSelect = ?2 AND op.createdOn >= ?3 AND op.createdOn <= ?4 ");
q.setParameter(1, user);
q.setParameter(2, OpportunityRepository.SALES_STAGE_CLOSED_WON);
q.setParameter(3, fromDateTime);
q.setParameter(4, toDateTime);
BigDecimal opportunityAmountWon = (BigDecimal) q.getSingleResult();
Long callEmittedNumber = eventRepo.all().filter("self.typeSelect = ?1 AND self.user = ?2 AND self.startDateTime >= ?3 AND self.endDateTime <= ?4 AND self.callTypeSelect = 2", EventRepository.TYPE_CALL, user, fromDateTime, toDateTime).count();
target.setCallEmittedNumber(callEmittedNumber.intValue());
Long meetingNumber = eventRepo.all().filter("self.typeSelect = ?1 AND self.user = ?2 AND self.startDateTime >= ?3 AND self.endDateTime <= ?4", EventRepository.TYPE_MEETING, user, fromDateTime, toDateTime).count();
target.setMeetingNumber(meetingNumber.intValue());
target.setOpportunityAmountWon(opportunityAmountWon);
Long opportunityCreatedNumber = opportunityRepo.all().filter("self.user = ?1 AND self.createdOn >= ?2 AND self.createdOn <= ?3", user, fromDateTime, toDateTime).count();
target.setOpportunityCreatedNumber(opportunityCreatedNumber.intValue());
Long opportunityCreatedWon = opportunityRepo.all().filter("self.user = ?1 AND self.createdOn >= ?2 AND self.createdOn <= ?3 AND self.salesStageSelect = ?4", user, fromDateTime, toDateTime, OpportunityRepository.SALES_STAGE_CLOSED_WON).count();
target.setOpportunityCreatedWon(opportunityCreatedWon.intValue());
} else if (team != null) {
Query q = JPA.em().createQuery("select SUM(op.amount) FROM Opportunity as op WHERE op.team = ?1 AND op.salesStageSelect = ?2 AND op.createdOn >= ?3 AND op.createdOn <= ?4 ");
q.setParameter(1, team);
q.setParameter(2, OpportunityRepository.SALES_STAGE_CLOSED_WON);
q.setParameter(3, fromDateTime);
q.setParameter(4, toDateTime);
BigDecimal opportunityAmountWon = (BigDecimal) q.getSingleResult();
Long callEmittedNumber = eventRepo.all().filter("self.typeSelect = ?1 AND self.team = ?2 AND self.startDateTime >= ?3 AND self.endDateTime <= ?4 AND self.callTypeSelect = 2", EventRepository.TYPE_CALL, team, fromDateTime, toDateTime).count();
target.setCallEmittedNumber(callEmittedNumber.intValue());
Long meetingNumber = eventRepo.all().filter("self.typeSelect = ?1 AND self.team = ?2 AND self.startDateTime >= ?3 AND self.endDateTime <= ?4", EventRepository.TYPE_MEETING, team, fromDateTime, toDateTime).count();
target.setMeetingNumber(meetingNumber.intValue());
target.setOpportunityAmountWon(opportunityAmountWon);
Long opportunityCreatedNumber = opportunityRepo.all().filter("self.team = ?1 AND self.createdOn >= ?2 AND self.createdOn <= ?3", team, fromDateTime, toDateTime).count();
target.setOpportunityCreatedNumber(opportunityCreatedNumber.intValue());
Long opportunityCreatedWon = opportunityRepo.all().filter("self.team = ?1 AND self.createdOn >= ?2 AND self.createdOn <= ?3 AND self.salesStageSelect = ?4", team, fromDateTime, toDateTime, OpportunityRepository.SALES_STAGE_CLOSED_WON).count();
target.setOpportunityCreatedWon(opportunityCreatedWon.intValue());
}
targetRepo.save(target);
}
use of com.axelor.team.db.Team in project axelor-open-suite by axelor.
the class SaleOrderController method mergeSaleOrder.
@SuppressWarnings({ "rawtypes", "unchecked" })
public void mergeSaleOrder(ActionRequest request, ActionResponse response) {
List<SaleOrder> saleOrderList = new ArrayList<>();
List<Long> saleOrderIdList = new ArrayList<>();
boolean fromPopup = false;
String lineToMerge;
if (request.getContext().get("saleQuotationToMerge") != null) {
lineToMerge = "saleQuotationToMerge";
} else {
lineToMerge = "saleOrderToMerge";
}
if (request.getContext().get(lineToMerge) != null) {
if (request.getContext().get(lineToMerge) instanceof List) {
// No confirmation popup, sale orders are content in a parameter list
List<Map> saleOrderMap = (List<Map>) request.getContext().get(lineToMerge);
for (Map map : saleOrderMap) {
saleOrderIdList.add(new Long((Integer) map.get("id")));
}
} else {
// After confirmation popup, sale order's id are in a string separated by ","
String saleOrderIdListStr = (String) request.getContext().get(lineToMerge);
for (String saleOrderId : saleOrderIdListStr.split(",")) {
saleOrderIdList.add(new Long(saleOrderId));
}
fromPopup = true;
}
}
// Check if currency, clientPartner and company are the same for all selected
// sale orders
Currency commonCurrency = null;
Partner commonClientPartner = null;
Company commonCompany = null;
Partner commonContactPartner = null;
Team commonTeam = null;
// Useful to determine if a difference exists between teams of all sale orders
boolean existTeamDiff = false;
// Useful to determine if a difference exists between contact partners of all
// sale orders
boolean existContactPartnerDiff = false;
PriceList commonPriceList = null;
// Useful to determine if a difference exists between price lists of all sale
// orders
boolean existPriceListDiff = false;
StockLocation commonLocation = null;
// Useful to determine if a difference exists between stock locations of all
// sale orders
boolean existLocationDiff = false;
SaleOrder saleOrderTemp;
int count = 1;
for (Long saleOrderId : saleOrderIdList) {
saleOrderTemp = JPA.em().find(SaleOrder.class, saleOrderId);
saleOrderList.add(saleOrderTemp);
if (count == 1) {
commonCurrency = saleOrderTemp.getCurrency();
commonClientPartner = saleOrderTemp.getClientPartner();
commonCompany = saleOrderTemp.getCompany();
commonContactPartner = saleOrderTemp.getContactPartner();
commonTeam = saleOrderTemp.getTeam();
commonPriceList = saleOrderTemp.getPriceList();
commonLocation = saleOrderTemp.getStockLocation();
} else {
if (commonCurrency != null && !commonCurrency.equals(saleOrderTemp.getCurrency())) {
commonCurrency = null;
}
if (commonClientPartner != null && !commonClientPartner.equals(saleOrderTemp.getClientPartner())) {
commonClientPartner = null;
}
if (commonCompany != null && !commonCompany.equals(saleOrderTemp.getCompany())) {
commonCompany = null;
}
if (commonContactPartner != null && !commonContactPartner.equals(saleOrderTemp.getContactPartner())) {
commonContactPartner = null;
existContactPartnerDiff = true;
}
if (commonTeam != null && !commonTeam.equals(saleOrderTemp.getTeam())) {
commonTeam = null;
existTeamDiff = true;
}
if (commonPriceList != null && !commonPriceList.equals(saleOrderTemp.getPriceList())) {
commonPriceList = null;
existPriceListDiff = true;
}
if (commonLocation != null && !commonLocation.equals(saleOrderTemp.getStockLocation())) {
commonLocation = null;
existLocationDiff = true;
}
}
count++;
}
StringBuilder fieldErrors = new StringBuilder();
if (commonCurrency == null) {
fieldErrors.append(I18n.get(com.axelor.apps.sale.exception.IExceptionMessage.SALE_ORDER_MERGE_ERROR_CURRENCY));
}
if (commonClientPartner == null) {
if (fieldErrors.length() > 0) {
fieldErrors.append("<br/>");
}
fieldErrors.append(I18n.get(com.axelor.apps.sale.exception.IExceptionMessage.SALE_ORDER_MERGE_ERROR_CLIENT_PARTNER));
}
if (commonCompany == null) {
if (fieldErrors.length() > 0) {
fieldErrors.append("<br/>");
}
fieldErrors.append(I18n.get(com.axelor.apps.sale.exception.IExceptionMessage.SALE_ORDER_MERGE_ERROR_COMPANY));
}
if (fieldErrors.length() > 0) {
response.setFlash(fieldErrors.toString());
return;
}
// Check if priceList or contactPartner are content in parameters
if (request.getContext().get("priceList") != null) {
commonPriceList = JPA.em().find(PriceList.class, new Long((Integer) ((Map) request.getContext().get("priceList")).get("id")));
}
if (request.getContext().get("contactPartner") != null) {
commonContactPartner = JPA.em().find(Partner.class, new Long((Integer) ((Map) request.getContext().get("contactPartner")).get("id")));
}
if (request.getContext().get("team") != null) {
commonTeam = JPA.em().find(Team.class, new Long((Integer) ((Map) request.getContext().get("team")).get("id")));
}
if (request.getContext().get("stockLocation") != null) {
commonLocation = JPA.em().find(StockLocation.class, new Long((Integer) ((Map) request.getContext().get("stockLocation")).get("id")));
}
if (!fromPopup && (existContactPartnerDiff || existPriceListDiff || existTeamDiff)) {
// Need to display intermediate screen to select some values
ActionViewBuilder confirmView = ActionView.define("Confirm merge sale order").model(Wizard.class.getName()).add("form", "sale-order-merge-confirm-form").param("popup", "true").param("show-toolbar", "false").param("show-confirm", "false").param("popup-save", "false").param("forceEdit", "true");
if (existPriceListDiff) {
confirmView.context("contextPriceListToCheck", "true");
}
if (existContactPartnerDiff) {
confirmView.context("contextContactPartnerToCheck", "true");
confirmView.context("contextPartnerId", commonClientPartner.getId().toString());
}
if (existTeamDiff) {
confirmView.context("contextTeamToCheck", "true");
}
if (existLocationDiff) {
confirmView.context("contextLocationToCheck", "true");
}
confirmView.context(lineToMerge, Joiner.on(",").join(saleOrderIdList));
response.setView(confirmView.map());
return;
}
try {
SaleOrder saleOrder = Beans.get(SaleOrderCreateServiceSupplychainImpl.class).mergeSaleOrders(saleOrderList, commonCurrency, commonClientPartner, commonCompany, commonLocation, commonContactPartner, commonPriceList, commonTeam);
if (saleOrder != null) {
// Open the generated sale order in a new tab
response.setView(ActionView.define("Sale order").model(SaleOrder.class.getName()).add("grid", "sale-order-grid").add("form", "sale-order-form").param("search-filters", "sale-order-filters").param("forceEdit", "true").context("_showRecord", String.valueOf(saleOrder.getId())).map());
response.setCanClose(true);
}
} catch (Exception e) {
response.setFlash(e.getLocalizedMessage());
}
}
use of com.axelor.team.db.Team in project axelor-open-suite by axelor.
the class ProjectManagementRepository method save.
@Override
public Project save(Project project) {
ProjectManagementRepository.setAllProjectMembersUserSet(project);
if (project.getSynchronize()) {
Team team = project.getTeam();
if (team != null) {
team.clearMembers();
project.getMembersUserSet().forEach(team::addMember);
}
}
try {
AppProject appProject = Beans.get(AppProjectService.class).getAppProject();
if (Strings.isNullOrEmpty(project.getCode()) && appProject.getGenerateProjectSequence()) {
Company company = project.getCompany();
String seq = Beans.get(SequenceService.class).getSequenceNumber(SequenceRepository.PROJECT_SEQUENCE, company);
if (seq == null) {
throw new AxelorException(company, TraceBackRepository.CATEGORY_CONFIGURATION_ERROR, I18n.get(IExceptionMessage.PROJECT_SEQUENCE_ERROR), company.getName());
}
project.setCode(seq);
}
} catch (AxelorException e) {
TraceBackService.traceExceptionFromSaveMethod(e);
throw new PersistenceException(e.getMessage(), e);
}
setAllProjectFullName(project);
project.setEstimatedTimeHrs(project.getEstimatedTimeDays().multiply(Beans.get(AppBaseService.class).getAppBase().getDailyWorkHours()));
return super.save(project);
}
use of com.axelor.team.db.Team in project axelor-open-suite by axelor.
the class SaleOrderController method mergeSaleOrder.
@SuppressWarnings({ "rawtypes", "unchecked" })
public void mergeSaleOrder(ActionRequest request, ActionResponse response) {
List<SaleOrder> saleOrderList = new ArrayList<SaleOrder>();
List<Long> saleOrderIdList = new ArrayList<Long>();
boolean fromPopup = false;
String lineToMerge;
if (request.getContext().get("saleQuotationToMerge") != null) {
lineToMerge = "saleQuotationToMerge";
} else {
lineToMerge = "saleOrderToMerge";
}
if (request.getContext().get(lineToMerge) != null) {
if (request.getContext().get(lineToMerge) instanceof List) {
// No confirmation popup, sale orders are content in a parameter list
List<Map> saleOrderMap = (List<Map>) request.getContext().get(lineToMerge);
for (Map map : saleOrderMap) {
saleOrderIdList.add(new Long((Integer) map.get("id")));
}
} else {
// After confirmation popup, sale order's id are in a string separated by ","
String saleOrderIdListStr = (String) request.getContext().get(lineToMerge);
for (String saleOrderId : saleOrderIdListStr.split(",")) {
saleOrderIdList.add(new Long(saleOrderId));
}
fromPopup = true;
}
}
// Check if currency, clientPartner and company are the same for all selected sale orders
Currency commonCurrency = null;
Partner commonClientPartner = null;
Company commonCompany = null;
Partner commonContactPartner = null;
Team commonTeam = null;
// Useful to determine if a difference exists between teams of all sale orders
boolean existTeamDiff = false;
// Useful to determine if a difference exists between contact partners of all sale orders
boolean existContactPartnerDiff = false;
PriceList commonPriceList = null;
// Useful to determine if a difference exists between price lists of all sale orders
boolean existPriceListDiff = false;
SaleOrder saleOrderTemp;
int count = 1;
for (Long saleOrderId : saleOrderIdList) {
saleOrderTemp = JPA.em().find(SaleOrder.class, saleOrderId);
saleOrderList.add(saleOrderTemp);
if (count == 1) {
commonCurrency = saleOrderTemp.getCurrency();
commonClientPartner = saleOrderTemp.getClientPartner();
commonCompany = saleOrderTemp.getCompany();
commonContactPartner = saleOrderTemp.getContactPartner();
commonTeam = saleOrderTemp.getTeam();
commonPriceList = saleOrderTemp.getPriceList();
} else {
if (commonCurrency != null && !commonCurrency.equals(saleOrderTemp.getCurrency())) {
commonCurrency = null;
}
if (commonClientPartner != null && !commonClientPartner.equals(saleOrderTemp.getClientPartner())) {
commonClientPartner = null;
}
if (commonCompany != null && !commonCompany.equals(saleOrderTemp.getCompany())) {
commonCompany = null;
}
if (commonContactPartner != null && !commonContactPartner.equals(saleOrderTemp.getContactPartner())) {
commonContactPartner = null;
existContactPartnerDiff = true;
}
if (commonTeam != null && !commonTeam.equals(saleOrderTemp.getTeam())) {
commonTeam = null;
existTeamDiff = true;
}
if (commonPriceList != null && !commonPriceList.equals(saleOrderTemp.getPriceList())) {
commonPriceList = null;
existPriceListDiff = true;
}
}
count++;
}
StringBuilder fieldErrors = new StringBuilder();
if (commonCurrency == null) {
fieldErrors.append(I18n.get(IExceptionMessage.SALE_ORDER_MERGE_ERROR_CURRENCY));
}
if (commonClientPartner == null) {
if (fieldErrors.length() > 0) {
fieldErrors.append("<br/>");
}
fieldErrors.append(I18n.get(IExceptionMessage.SALE_ORDER_MERGE_ERROR_CLIENT_PARTNER));
}
if (commonCompany == null) {
if (fieldErrors.length() > 0) {
fieldErrors.append("<br/>");
}
fieldErrors.append(I18n.get(IExceptionMessage.SALE_ORDER_MERGE_ERROR_COMPANY));
}
if (fieldErrors.length() > 0) {
response.setFlash(fieldErrors.toString());
return;
}
// Check if priceList or contactPartner are content in parameters
if (request.getContext().get("priceList") != null) {
commonPriceList = JPA.em().find(PriceList.class, new Long((Integer) ((Map) request.getContext().get("priceList")).get("id")));
}
if (request.getContext().get("contactPartner") != null) {
commonContactPartner = JPA.em().find(Partner.class, new Long((Integer) ((Map) request.getContext().get("contactPartner")).get("id")));
}
if (request.getContext().get("team") != null) {
commonTeam = JPA.em().find(Team.class, new Long((Integer) ((Map) request.getContext().get("team")).get("id")));
}
if (!fromPopup && (existContactPartnerDiff || existPriceListDiff || existTeamDiff)) {
// Need to display intermediate screen to select some values
ActionViewBuilder confirmView = ActionView.define("Confirm merge sale order").model(Wizard.class.getName()).add("form", "sale-order-merge-confirm-form").param("popup", "true").param("show-toolbar", "false").param("show-confirm", "false").param("popup-save", "false").param("forceEdit", "true");
if (existPriceListDiff) {
confirmView.context("contextPriceListToCheck", "true");
}
if (existContactPartnerDiff) {
confirmView.context("contextContactPartnerToCheck", "true");
confirmView.context("contextPartnerId", commonClientPartner.getId().toString());
}
if (existTeamDiff) {
confirmView.context("contextTeamToCheck", "true");
}
confirmView.context(lineToMerge, Joiner.on(",").join(saleOrderIdList));
response.setView(confirmView.map());
return;
}
try {
SaleOrder saleOrder = Beans.get(SaleOrderCreateService.class).mergeSaleOrders(saleOrderList, commonCurrency, commonClientPartner, commonCompany, commonContactPartner, commonPriceList, commonTeam);
if (saleOrder != null) {
// Open the generated sale order in a new tab
response.setView(ActionView.define("Sale order").model(SaleOrder.class.getName()).add("grid", "sale-order-grid").add("form", "sale-order-form").param("search-filters", "sale-order-filters").param("forceEdit", "true").context("_showRecord", String.valueOf(saleOrder.getId())).map());
response.setCanClose(true);
}
} catch (Exception e) {
response.setFlash(e.getLocalizedMessage());
}
}
use of com.axelor.team.db.Team in project axelor-open-suite by axelor.
the class CalendarService method showSharedCalendars.
public List<Long> showSharedCalendars(User user) {
Team team = user.getActiveTeam();
Set<User> followedUsers = user.getFollowersCalUserSet();
List<Long> calendarIdlist = new ArrayList<Long>();
for (User userIt : followedUsers) {
for (CalendarManagement calendarManagement : userIt.getCalendarManagementList()) {
if ((user.equals(calendarManagement.getUser())) || (team != null && team.equals(calendarManagement.getTeam()))) {
List<ICalendar> icalList = icalRepo.all().filter("self.user.id = ?1", userIt.getId()).fetch();
calendarIdlist.addAll(Lists.transform(icalList, it -> it.getId()));
}
}
}
List<ICalendar> icalList = icalRepo.all().filter("self.user.id = ?1", user.getId()).fetch();
calendarIdlist.addAll(Lists.transform(icalList, it -> it.getId()));
return calendarIdlist;
}
Aggregations