Search in sources :

Example 1 with AppBaseService

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;
}
Also used : StockMove(com.axelor.apps.stock.db.StockMove) AppBaseService(com.axelor.apps.base.service.app.AppBaseService) Transactional(com.google.inject.persist.Transactional)

Example 2 with AppBaseService

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());
    }
}
Also used : AxelorException(com.axelor.exception.AxelorException) LeaveReasonRepository(com.axelor.apps.hr.db.repo.LeaveReasonRepository) Company(com.axelor.apps.base.db.Company) User(com.axelor.auth.db.User) LeaveReason(com.axelor.apps.hr.db.LeaveReason) LeaveRequest(com.axelor.apps.hr.db.LeaveRequest) Employee(com.axelor.apps.hr.db.Employee) AppBaseService(com.axelor.apps.base.service.app.AppBaseService) LeaveLine(com.axelor.apps.hr.db.LeaveLine) LeaveLineRepository(com.axelor.apps.hr.db.repo.LeaveLineRepository) Transactional(com.google.inject.persist.Transactional)

Example 3 with AppBaseService

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);
}
Also used : AppBaseService(com.axelor.apps.base.service.app.AppBaseService) LocalDate(java.time.LocalDate)

Example 4 with AppBaseService

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);
}
Also used : Employee(com.axelor.apps.hr.db.Employee) AppBaseService(com.axelor.apps.base.service.app.AppBaseService) LocalDate(java.time.LocalDate)

Example 5 with AppBaseService

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;
}
Also used : AppBaseService(com.axelor.apps.base.service.app.AppBaseService) InvoiceLine(com.axelor.apps.account.db.InvoiceLine) InvoiceLineService(com.axelor.apps.account.service.invoice.InvoiceLineService) BigDecimal(java.math.BigDecimal)

Aggregations

AppBaseService (com.axelor.apps.base.service.app.AppBaseService)10 Transactional (com.google.inject.persist.Transactional)4 Company (com.axelor.apps.base.db.Company)3 Employee (com.axelor.apps.hr.db.Employee)3 LocalDate (java.time.LocalDate)3 StockMove (com.axelor.apps.stock.db.StockMove)2 User (com.axelor.auth.db.User)2 BigDecimal (java.math.BigDecimal)2 Account (com.axelor.apps.account.db.Account)1 AccountConfig (com.axelor.apps.account.db.AccountConfig)1 Invoice (com.axelor.apps.account.db.Invoice)1 InvoiceLine (com.axelor.apps.account.db.InvoiceLine)1 Journal (com.axelor.apps.account.db.Journal)1 Move (com.axelor.apps.account.db.Move)1 MoveLine (com.axelor.apps.account.db.MoveLine)1 MoveRepository (com.axelor.apps.account.db.repo.MoveRepository)1 AccountConfigService (com.axelor.apps.account.service.config.AccountConfigService)1 InvoiceLineService (com.axelor.apps.account.service.invoice.InvoiceLineService)1 MoveService (com.axelor.apps.account.service.move.MoveService)1 AppBase (com.axelor.apps.base.db.AppBase)1