use of com.axelor.apps.base.service.app.AppBaseService in project axelor-open-suite by axelor.
the class StockCorrectionServiceImpl method validate.
@Override
@Transactional(rollbackOn = { Exception.class })
public boolean validate(StockCorrection stockCorrection) throws AxelorException {
AppBaseService baseService = Beans.get(AppBaseService.class);
StockMove stockMove = generateStockMove(stockCorrection);
if (stockMove != null) {
stockCorrection.setStatusSelect(StockCorrectionRepository.STATUS_VALIDATED);
stockCorrection.setValidationDateT(baseService.getTodayDateTime().toLocalDateTime());
return true;
}
return false;
}
use of com.axelor.apps.base.service.app.AppBaseService in project axelor-open-suite by axelor.
the class HumanResourceMobileController method insertLeave.
/*
* This method is used in mobile application.
* It was in LeaveServiceImpl
* @param request
* @param response
*
* POST /open-suite-webapp/ws/action/com.axelor.apps.hr.mobile.HumanResourceMobileController:insertLeave
* Content-Type: application/json
*
* URL: com.axelor.apps.hr.mobile.HumanResourceMobileController:insertLeave
* fields: leaveReason, fromDateT, startOn, toDateT, endOn, comment
*
* payload:
* { "data": {
* "action": "com.axelor.apps.hr.mobile.HumanResourceMobileController:insertLeave",
* "leaveReason": 10,
* "fromDateT": "2018-02-22T10:30:00",
* "startOn": 1,
* "toDateT": "2018-02-24T:19:30:00",
* "endOn": 1,
* "comment": "no"
* } }
*/
@Transactional(rollbackOn = { Exception.class })
public void insertLeave(ActionRequest request, ActionResponse response) throws AxelorException {
AppBaseService appBaseService = Beans.get(AppBaseService.class);
User user = AuthUtils.getUser();
Map<String, Object> requestData = request.getData();
LeaveReason leaveReason = Beans.get(LeaveReasonRepository.class).find(Long.valueOf(requestData.get("leaveReason").toString()));
Employee employee = user.getEmployee();
if (employee == null) {
throw new AxelorException(TraceBackRepository.CATEGORY_CONFIGURATION_ERROR, I18n.get(IExceptionMessage.LEAVE_USER_EMPLOYEE), user.getName());
}
if (leaveReason != null) {
LeaveRequest leave = new LeaveRequest();
leave.setUser(user);
Company company = null;
if (employee.getMainEmploymentContract() != null) {
company = employee.getMainEmploymentContract().getPayCompany();
}
leave.setCompany(company);
LeaveLine leaveLine = Beans.get(LeaveLineRepository.class).all().filter("self.employee = ?1 AND self.leaveReason = ?2", employee, leaveReason).fetchOne();
if (leaveLine == null) {
throw new AxelorException(TraceBackRepository.CATEGORY_CONFIGURATION_ERROR, I18n.get(IExceptionMessage.LEAVE_LINE), employee.getName(), leaveReason.getName());
}
leave.setLeaveReason(leaveReason);
leave.setRequestDate(appBaseService.getTodayDate(company));
if (requestData.get("fromDateT") != null) {
leave.setFromDateT(LocalDateTime.parse(requestData.get("fromDateT").toString(), DateTimeFormatter.ISO_LOCAL_DATE_TIME));
}
leave.setStartOnSelect(new Integer(requestData.get("startOn").toString()));
if (requestData.get("toDateT") != null) {
leave.setToDateT(LocalDateTime.parse(requestData.get("toDateT").toString(), DateTimeFormatter.ISO_LOCAL_DATE_TIME));
}
leave.setEndOnSelect(new Integer(requestData.get("endOn").toString()));
leave.setDuration(Beans.get(LeaveService.class).computeDuration(leave));
leave.setStatusSelect(LeaveRequestRepository.STATUS_AWAITING_VALIDATION);
if (requestData.get("comments") != null) {
leave.setComments(requestData.get("comments").toString());
}
leave = Beans.get(LeaveRequestRepository.class).save(leave);
response.setTotal(1);
response.setValue("id", leave.getId());
}
}
use of com.axelor.apps.base.service.app.AppBaseService in project axelor-open-suite by axelor.
the class EmployeeHRRepository method isEmployeeFormerNewOrArchived.
/**
* Return true if given employee is a New employee or a Former employee at the current date
* according to hire date and leaving date, or if given employee is archived.
*
* @param employee
* @return
*/
public static boolean isEmployeeFormerNewOrArchived(Employee employee) {
Objects.requireNonNull(employee);
AppBaseService appBaseService = Beans.get(AppBaseService.class);
LocalDate today = appBaseService.getTodayDate(employee.getUser() != null ? employee.getUser().getActiveCompany() : AuthUtils.getUser().getActiveCompany());
return isEmployeeFormerNewOrArchived(employee, today);
}
use of com.axelor.apps.base.service.app.AppBaseService in project axelor-open-suite by axelor.
the class EmployeeHRRepository method populate.
@Override
public Map<String, Object> populate(Map<String, Object> json, Map<String, Object> context) {
if (json != null && json.get("id") != null) {
Long id = (Long) json.get("id");
if (id != null) {
Employee employee = super.find(id);
AppBaseService appBaseService = Beans.get(AppBaseService.class);
LocalDate today = appBaseService.getTodayDate(employee.getUser() != null ? employee.getUser().getActiveCompany() : AuthUtils.getUser().getActiveCompany());
if (employee.getLeavingDate() == null && employee.getHireDate() != null && employee.getHireDate().compareTo(today.minusDays(30)) > 0) {
json.put("$employeeStatus", "new");
} else if (employee.getLeavingDate() != null && employee.getLeavingDate().compareTo(today) < 0) {
json.put("$employeeStatus", "former");
} else {
json.put("$employeeStatus", "active");
}
}
}
return super.populate(json, context);
}
use of com.axelor.apps.base.service.app.AppBaseService in project axelor-open-suite by axelor.
the class InvoiceLineController method updateQty.
public List<InvoiceLine> updateQty(List<InvoiceLine> invoiceLines, BigDecimal oldKitQty, BigDecimal newKitQty, Invoice invoice) throws AxelorException {
BigDecimal qty = BigDecimal.ZERO;
BigDecimal exTaxTotal = BigDecimal.ZERO;
BigDecimal companyExTaxTotal = BigDecimal.ZERO;
BigDecimal inTaxTotal = BigDecimal.ZERO;
BigDecimal companyInTaxTotal = BigDecimal.ZERO;
BigDecimal priceDiscounted = BigDecimal.ZERO;
BigDecimal taxRate = BigDecimal.ZERO;
AppBaseService appBaseService = Beans.get(AppBaseService.class);
InvoiceLineService invoiceLineService = Beans.get(InvoiceLineService.class);
int scale = appBaseService.getNbDecimalDigitForQty();
if (invoiceLines != null) {
if (newKitQty.compareTo(BigDecimal.ZERO) != 0) {
for (InvoiceLine line : invoiceLines) {
qty = (line.getQty().divide(oldKitQty, scale, RoundingMode.HALF_UP)).multiply(newKitQty).setScale(scale, RoundingMode.HALF_UP);
priceDiscounted = invoiceLineService.computeDiscount(line, invoice.getInAti());
if (line.getTaxLine() != null) {
taxRate = line.getTaxLine().getValue();
}
if (!invoice.getInAti()) {
exTaxTotal = InvoiceLineManagement.computeAmount(qty, priceDiscounted);
inTaxTotal = exTaxTotal.add(exTaxTotal.multiply(taxRate));
} else {
inTaxTotal = InvoiceLineManagement.computeAmount(qty, priceDiscounted);
exTaxTotal = inTaxTotal.divide(taxRate.add(BigDecimal.ONE), 2, BigDecimal.ROUND_HALF_UP);
}
companyExTaxTotal = invoiceLineService.getCompanyExTaxTotal(exTaxTotal, invoice);
companyInTaxTotal = invoiceLineService.getCompanyExTaxTotal(inTaxTotal, invoice);
line.setQty(qty);
line.setExTaxTotal(exTaxTotal);
line.setCompanyExTaxTotal(companyExTaxTotal);
line.setInTaxTotal(inTaxTotal);
line.setCompanyInTaxTotal(companyInTaxTotal);
line.setPriceDiscounted(priceDiscounted);
line.setTaxRate(taxRate);
}
} else {
for (InvoiceLine line : invoiceLines) {
line.setQty(qty);
}
}
}
return invoiceLines;
}
Aggregations