use of com.axelor.auth.db.User in project axelor-open-suite by axelor.
the class IrrecoverableService method createIrrecoverableReportLineList.
/**
* Fonction permettant de créer une liste de ligne de reporting pour une ligne Echéance rejetée
*
* @param iil Une ligne Echéance rejetée
* @param invoice Une échéance rejetée
* @param prorataRate Un taux de restant à payer d'une échéance rejetée
* @return
* @throws AxelorException
*/
public List<IrrecoverableReportLine> createIrrecoverableReportLineList(IrrecoverablePaymentScheduleLineLine ipsll, PaymentScheduleLine paymentScheduleLine, Tax tax) throws AxelorException {
List<IrrecoverableReportLine> irlList = new ArrayList<IrrecoverableReportLine>();
BigDecimal taxRate = taxService.getTaxRate(tax, appAccountService.getTodayDate(paymentScheduleLine.getPaymentSchedule() != null ? paymentScheduleLine.getPaymentSchedule().getCompany() : Optional.ofNullable(AuthUtils.getUser()).map(User::getActiveCompany).orElse(null)));
BigDecimal amount = paymentScheduleLine.getInTaxAmount();
BigDecimal divid = taxRate.add(BigDecimal.ONE);
// Montant hors-Taxe
BigDecimal irrecoverableAmount = amount.divide(divid, 6, RoundingMode.HALF_UP).setScale(AppBaseService.DEFAULT_NB_DECIMAL_DIGITS, RoundingMode.HALF_UP);
// Montant Tax
BigDecimal taxAmount = amount.subtract(irrecoverableAmount);
irlList.add(this.createIrrecoverableReportLine(ipsll, "HT", irrecoverableAmount, 1));
irlList.add(this.createIrrecoverableReportLine(ipsll, tax.getName(), taxAmount, 2));
return irlList;
}
use of com.axelor.auth.db.User in project axelor-open-suite by axelor.
the class AdvancedExportServiceImpl method getAdvancedExportQuery.
/**
* This method split and join the all fields/columns which are selected by user and create the
* query.
*
* @param advancedExport
* @param criteria
* @return
* @throws AxelorException
* @throws ClassNotFoundException
*/
@Override
public Query getAdvancedExportQuery(AdvancedExport advancedExport, List<Long> recordIds) throws AxelorException {
StringBuilder selectFieldBuilder = new StringBuilder();
StringBuilder orderByFieldBuilder = new StringBuilder();
joinFieldSet.clear();
selectionJoinFieldSet.clear();
isNormalField = true;
selectField = "";
msi = 0;
mt = 0;
int col = 0;
language = Optional.ofNullable(AuthUtils.getUser()).map(User::getLanguage).orElse(null);
try {
if (language == null) {
throw new AxelorException(TraceBackRepository.CATEGORY_MISSING_FIELD, I18n.get("Please select a language on user form."));
}
for (AdvancedExportLine advancedExportLine : advancedExport.getAdvancedExportLineList()) {
String[] splitField = advancedExportLine.getTargetField().split("\\.");
String alias = "Col_" + col;
createQueryParts(splitField, 0, advancedExport.getMetaModel());
selectFieldBuilder.append(aliasName + selectField + " AS " + alias + ",");
if (advancedExportLine.getOrderBy()) {
orderByFieldBuilder.append(alias + " " + advancedExportLine.getOrderByType() + ",");
}
selectField = "";
aliasName = "";
col++;
}
if (StringUtils.notEmpty(orderByFieldBuilder)) {
orderByFieldBuilder.append("self.id asc,");
}
} catch (ClassNotFoundException e) {
TraceBackService.trace(e);
throw new AxelorException(e, TraceBackRepository.CATEGORY_CONFIGURATION_ERROR);
}
return createQuery(createQueryBuilder(advancedExport, selectFieldBuilder, recordIds, orderByFieldBuilder));
}
use of com.axelor.auth.db.User in project axelor-open-suite by axelor.
the class AppBaseServiceImpl method getTodayDateTime.
public ZonedDateTime getTodayDateTime(Company company) {
ZonedDateTime todayDateTime = ZonedDateTime.now();
if (company != null) {
todayDateTime = DateTool.getTodayDateTime(company.getTimezone());
}
String applicationMode = AppSettings.get().get("application.mode", "prod");
if ("dev".equals(applicationMode)) {
User user = AuthUtils.getUser();
if (user != null && user.getToday() != null) {
todayDateTime = user.getToday();
} else {
AppBase appBase = getAppBase();
if (appBase != null && appBase.getToday() != null) {
return appBase.getToday();
}
}
}
return todayDateTime;
}
use of com.axelor.auth.db.User in project axelor-open-suite by axelor.
the class CalendarController method showMyEvents.
public void showMyEvents(ActionRequest request, ActionResponse response) {
User user = AuthUtils.getUser();
response.setView(ActionView.define(I18n.get("My.Calendar.CRM")).model(Event.class.getName()).add("calendar", "event-calendar-color-by-calendar").add("grid", "event-grid").add("form", "event-form").param("search-filters", "event-filters").context("_typeSelect", 2).domain("self.user.id = :_userId or self.calendar.user.id = :_userId or :_userId IN (SELECT attendee.user FROM self.attendees attendee) or self.organizer.user.id = :_userId").context("_userId", user.getId()).map());
}
use of com.axelor.auth.db.User 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);
}
Aggregations