use of com.axelor.apps.crm.db.Target in project axelor-open-suite by axelor.
the class TargetService method createsTargets.
public void createsTargets(TargetConfiguration targetConfiguration) throws AxelorException {
if (targetConfiguration.getPeriodTypeSelect() == TargetConfigurationRepository.PERIOD_TYPE_NONE) {
Target target = this.createTarget(targetConfiguration, targetConfiguration.getFromDate(), targetConfiguration.getToDate());
this.update(target);
} else {
LocalDate oldDate = targetConfiguration.getFromDate();
LocalDate date = oldDate;
while (date.isBefore(targetConfiguration.getToDate()) || date.isEqual(targetConfiguration.getToDate())) {
date = this.getNextDate(targetConfiguration.getPeriodTypeSelect(), date);
Target target2 = targetRepo.all().filter("self.user = ?1 AND self.team = ?2 AND self.periodTypeSelect = ?3 AND self.fromDate >= ?4 AND self.toDate <= ?5 AND " + "((self.callEmittedNumberTarget > 0 AND ?6 > 0) OR (self.meetingNumberTarget > 0 AND ?7 > 0) OR " + "(self.opportunityAmountWonTarget > 0.00 AND ?8 > 0.00) OR (self.opportunityCreatedNumberTarget > 0 AND ?9 > 0) OR (self.opportunityCreatedWonTarget > 0 AND ?10 > 0))", targetConfiguration.getUser(), targetConfiguration.getTeam(), targetConfiguration.getPeriodTypeSelect(), targetConfiguration.getFromDate(), targetConfiguration.getToDate(), targetConfiguration.getCallEmittedNumber(), targetConfiguration.getMeetingNumber(), targetConfiguration.getOpportunityAmountWon().doubleValue(), targetConfiguration.getOpportunityCreatedNumber(), targetConfiguration.getOpportunityCreatedWon()).fetchOne();
if (target2 == null) {
Target target = this.createTarget(targetConfiguration, oldDate, (date.isBefore(targetConfiguration.getToDate())) ? date.minusDays(1) : targetConfiguration.getToDate());
this.update(target);
oldDate = date;
} else {
throw new AxelorException(targetConfiguration, TraceBackRepository.CATEGORY_CONFIGURATION_ERROR, I18n.get(IExceptionMessage.TARGET_1), target2.getCode(), targetConfiguration.getCode());
}
}
}
}
use of com.axelor.apps.crm.db.Target in project axelor-open-suite by axelor.
the class TargetService method createTarget.
@Transactional
public Target createTarget(TargetConfiguration targetConfiguration, LocalDate fromDate, LocalDate toDate) {
Target target = new Target();
target.setCallEmittedNumberTarget(targetConfiguration.getCallEmittedNumber());
target.setMeetingNumberTarget(targetConfiguration.getMeetingNumber());
target.setOpportunityAmountWonTarget(targetConfiguration.getOpportunityAmountWon());
target.setOpportunityCreatedNumberTarget(targetConfiguration.getOpportunityCreatedNumber());
target.setOpportunityCreatedWonTarget(targetConfiguration.getOpportunityCreatedWon());
// target.setSaleOrderAmountWonTarget(targetConfiguration.getSaleOrderAmountWon());
// target.setSaleOrderCreatedNumberTarget(targetConfiguration.getSaleOrderCreatedNumber());
// target.setSaleOrderCreatedWonTarget(targetConfiguration.getSaleOrderCreatedWon());
target.setPeriodTypeSelect(targetConfiguration.getPeriodTypeSelect());
target.setFromDate(fromDate);
target.setToDate(toDate);
target.setUser(targetConfiguration.getUser());
target.setTeam(targetConfiguration.getTeam());
target.setName(targetConfiguration.getName());
target.setCode(targetConfiguration.getCode());
return targetRepo.save(target);
}
use of com.axelor.apps.crm.db.Target in project axelor-open-suite by axelor.
the class TargetController method update.
public void update(ActionRequest request, ActionResponse response) {
Target target = request.getContext().asType(Target.class);
try {
Beans.get(TargetService.class).update(Beans.get(TargetRepository.class).find(target.getId()));
response.setValue("opportunityAmountWon", target.getOpportunityAmountWon());
response.setValue("opportunityCreatedNumber", target.getOpportunityCreatedNumber());
response.setValue("opportunityCreatedWon", target.getOpportunityCreatedWon());
response.setValue("callEmittedNumber", target.getCallEmittedNumber());
response.setValue("meetingNumber", target.getMeetingNumber());
} catch (Exception e) {
TraceBackService.trace(response, e);
}
}
Aggregations