Search in sources :

Example 56 with Employee

use of com.axelor.apps.hr.db.Employee in project axelor-open-suite by axelor.

the class BatchTimesheetValidationReminder method generateAllEmailTemplate.

public void generateAllEmailTemplate() {
    Template template = batch.getMailBatch().getTemplate();
    String model = template.getMetaModel().getFullName();
    String tag = template.getMetaModel().getName();
    List<Employee> employeeList = Beans.get(EmployeeRepository.class).all().filter("self.timesheetReminder = true").fetch();
    for (Employee employee : employeeList) {
        if (employee == null || EmployeeHRRepository.isEmployeeFormerNewOrArchived(employee)) {
            continue;
        }
        try {
            Message message = templateMessageService.generateMessage(employee.getId(), model, tag, template);
            messageService.sendByEmail(message);
            incrementDone();
        } catch (Exception e) {
            incrementAnomaly();
            TraceBackService.trace(new Exception(e), ExceptionOriginRepository.REMINDER, batch.getId());
        }
    }
}
Also used : EmployeeRepository(com.axelor.apps.hr.db.repo.EmployeeRepository) Employee(com.axelor.apps.hr.db.Employee) Message(com.axelor.apps.message.db.Message) MessagingException(javax.mail.MessagingException) AxelorException(com.axelor.exception.AxelorException) IOException(java.io.IOException) Template(com.axelor.apps.message.db.Template)

Example 57 with Employee

use of com.axelor.apps.hr.db.Employee in project axelor-open-suite by axelor.

the class BatchTimesheetValidationReminder method generateEmailTemplate.

public void generateEmailTemplate() {
    Company company = batch.getMailBatch().getCompany();
    Template template = batch.getMailBatch().getTemplate();
    List<Timesheet> timesheetList = null;
    if (Beans.get(CompanyRepository.class).all().count() > 1) {
        timesheetList = Beans.get(TimesheetRepository.class).all().filter("self.company.id = ?1 AND self.statusSelect = 1 AND self.user.employee.timesheetReminder = true", company.getId()).fetch();
    } else {
        timesheetList = Beans.get(TimesheetRepository.class).all().filter("self.statusSelect = 1 AND self.user.employee.timesheetReminder = true").fetch();
    }
    String model = template.getMetaModel().getFullName();
    String tag = template.getMetaModel().getName();
    for (Timesheet timesheet : timesheetList) {
        try {
            Employee employee = timesheet.getUser().getEmployee();
            if (employee == null || EmployeeHRRepository.isEmployeeFormerNewOrArchived(employee)) {
                continue;
            }
            Message message = templateMessageService.generateMessage(employee.getId(), model, tag, template);
            messageService.sendByEmail(message);
            incrementDone();
        } catch (Exception e) {
            incrementAnomaly();
            TraceBackService.trace(new Exception(e), ExceptionOriginRepository.REMINDER, batch.getId());
        }
    }
}
Also used : Company(com.axelor.apps.base.db.Company) CompanyRepository(com.axelor.apps.base.db.repo.CompanyRepository) Employee(com.axelor.apps.hr.db.Employee) Message(com.axelor.apps.message.db.Message) Timesheet(com.axelor.apps.hr.db.Timesheet) MessagingException(javax.mail.MessagingException) AxelorException(com.axelor.exception.AxelorException) IOException(java.io.IOException) Template(com.axelor.apps.message.db.Template)

Example 58 with Employee

use of com.axelor.apps.hr.db.Employee in project axelor-open-suite by axelor.

the class EmployeeController method setEmployeeSocialNetworkUrl.

public void setEmployeeSocialNetworkUrl(ActionRequest request, ActionResponse response) {
    Employee employee = request.getContext().asType(Employee.class);
    if (employee.getContactPartner() != null) {
        Map<String, String> urlMap = Beans.get(EmployeeService.class).getSocialNetworkUrl(employee.getContactPartner().getName(), employee.getContactPartner().getFirstName());
        response.setAttr("contactPartner.facebookLabel", "title", urlMap.get("facebook"));
        response.setAttr("contactPartner.twitterLabel", "title", urlMap.get("twitter"));
        response.setAttr("contactPartner.linkedinLabel", "title", urlMap.get("linkedin"));
        response.setAttr("contactPartner.youtubeLabel", "title", urlMap.get("youtube"));
    }
}
Also used : Employee(com.axelor.apps.hr.db.Employee) EmployeeService(com.axelor.apps.hr.service.employee.EmployeeService)

Example 59 with Employee

use of com.axelor.apps.hr.db.Employee in project axelor-open-suite by axelor.

the class HumanResourceMobileController method insertKMExpenses.

/**
 * This method is used in mobile application. It was in ExpenseController
 *
 * @param request
 * @param response
 * @throws AxelorException
 *     <p>POST
 *     /open-suite-webapp/ws/action/com.axelor.apps.hr.mobile.HumanResourceMobileController:insertKMExpenses
 *     Content-Type: application/json
 *     <p>URL: com.axelor.apps.hr.mobile.HumanResourceMobileController:insertKMExpenses fields:
 *     kmNumber, locationFrom, locationTo, allowanceTypeSelect, comments, date, projectTask,
 *     kilometricAllowParam
 *     <p>payload: { "data": { "action":
 *     "com.axelor.apps.hr.mobile.HumanResourceMobileController:insertKMExpenses", "kmNumber":
 *     350.00, "locationFrom": "Paris", "locationTo": "Marseille", "allowanceTypeSelect": 1,
 *     "comments": "no", "date": "2018-02-22", "expenseProduct": 43 } }
 */
@Transactional(rollbackOn = { Exception.class })
public void insertKMExpenses(ActionRequest request, ActionResponse response) throws AxelorException {
    User user = AuthUtils.getUser();
    if (user != null) {
        ExpenseService expenseService = Beans.get(ExpenseService.class);
        Expense expense = expenseService.getOrCreateExpense(user);
        ExpenseLine expenseLine = new ExpenseLine();
        expenseLine.setDistance(new BigDecimal(request.getData().get("kmNumber").toString()));
        expenseLine.setFromCity(request.getData().get("locationFrom").toString());
        expenseLine.setToCity(request.getData().get("locationTo").toString());
        expenseLine.setKilometricTypeSelect(new Integer(request.getData().get("allowanceTypeSelect").toString()));
        expenseLine.setComments(request.getData().get("comments").toString());
        expenseLine.setExpenseDate(LocalDate.parse(request.getData().get("date").toString()));
        expenseLine.setProject(Beans.get(ProjectRepository.class).find(Long.valueOf(request.getData().get("projectTask").toString())));
        HRConfigService hrConfigService = Beans.get(HRConfigService.class);
        HRConfig hrConfig = hrConfigService.getHRConfig(expense.getCompany());
        Product expenseProduct = hrConfigService.getKilometricExpenseProduct(hrConfig);
        expenseLine.setExpenseProduct(expenseProduct);
        Employee employee = user.getEmployee();
        if (employee != null && !EmployeeHRRepository.isEmployeeFormerNewOrArchived(employee)) {
            KilometricAllowParamRepository kilometricAllowParamRepo = Beans.get(KilometricAllowParamRepository.class);
            expenseLine.setKilometricAllowParam(kilometricAllowParamRepo.find(Long.valueOf(request.getData().get("kilometricAllowParam").toString())));
            expenseLine.setTotalAmount(Beans.get(KilometricService.class).computeKilometricExpense(expenseLine, employee));
            expenseLine.setUntaxedAmount(expenseLine.getTotalAmount());
        }
        expense.addKilometricExpenseLineListItem(expenseLine);
        Beans.get(ExpenseRepository.class).save(expense);
        response.setValue("id", expenseLine.getId());
    }
}
Also used : User(com.axelor.auth.db.User) Employee(com.axelor.apps.hr.db.Employee) HRConfig(com.axelor.apps.hr.db.HRConfig) Expense(com.axelor.apps.hr.db.Expense) KilometricAllowParamRepository(com.axelor.apps.hr.db.repo.KilometricAllowParamRepository) ExpenseRepository(com.axelor.apps.hr.db.repo.ExpenseRepository) ExpenseService(com.axelor.apps.hr.service.expense.ExpenseService) HRConfigService(com.axelor.apps.hr.service.config.HRConfigService) Product(com.axelor.apps.base.db.Product) ExpenseLine(com.axelor.apps.hr.db.ExpenseLine) BigDecimal(java.math.BigDecimal) Transactional(com.google.inject.persist.Transactional)

Example 60 with Employee

use of com.axelor.apps.hr.db.Employee in project axelor-open-suite by axelor.

the class EmployeeAdvanceService method fillExpenseWithAdvances.

@Transactional
public void fillExpenseWithAdvances(Expense expense) {
    Employee employee = Beans.get(EmployeeRepository.class).find(expense.getUser().getEmployee().getId());
    if (EmployeeHRRepository.isEmployeeFormerNewOrArchived(employee)) {
        return;
    }
    List<EmployeeAdvance> advanceList = employeeAdvanceRepository.all().filter("self.employee.id = ?1 AND self.remainingAmount > 0 AND self.date < ?2 AND self.statusSelect = ?3 AND self.typeSelect = ?4", employee.getId(), expense.getPeriod().getToDate(), EmployeeAdvanceRepository.STATUS_VALIDATED, EmployeeAdvanceRepository.TYPE_OCCASIONAL).fetch();
    if (advanceList != null && !advanceList.isEmpty()) {
        BigDecimal currentAmountToRefund = expense.getInTaxTotal().subtract(expense.getPersonalExpenseAmount()).subtract(expense.getWithdrawnCash());
        for (EmployeeAdvance advance : advanceList) {
            if (currentAmountToRefund.signum() == 0) {
                break;
            }
            currentAmountToRefund = withdrawFromAdvance(advance, expense, currentAmountToRefund);
            employeeAdvanceRepository.save(advance);
        }
        expense.setAdvanceAmount(expense.getInTaxTotal().subtract(currentAmountToRefund).subtract(expense.getPersonalExpenseAmount()).subtract(expense.getWithdrawnCash()));
    }
}
Also used : EmployeeRepository(com.axelor.apps.hr.db.repo.EmployeeRepository) Employee(com.axelor.apps.hr.db.Employee) EmployeeAdvance(com.axelor.apps.hr.db.EmployeeAdvance) BigDecimal(java.math.BigDecimal) Transactional(com.google.inject.persist.Transactional)

Aggregations

Employee (com.axelor.apps.hr.db.Employee)71 AxelorException (com.axelor.exception.AxelorException)34 User (com.axelor.auth.db.User)28 Transactional (com.google.inject.persist.Transactional)21 BigDecimal (java.math.BigDecimal)18 ActionViewBuilder (com.axelor.meta.schema.actions.ActionView.ActionViewBuilder)14 LocalDate (java.time.LocalDate)13 TimesheetLine (com.axelor.apps.hr.db.TimesheetLine)9 EmployeeRepository (com.axelor.apps.hr.db.repo.EmployeeRepository)9 WeeklyPlanning (com.axelor.apps.base.db.WeeklyPlanning)8 Message (com.axelor.apps.message.db.Message)8 LeaveRequest (com.axelor.apps.hr.db.LeaveRequest)7 ArrayList (java.util.ArrayList)7 HashSet (java.util.HashSet)7 DayPlanning (com.axelor.apps.base.db.DayPlanning)6 LeaveLine (com.axelor.apps.hr.db.LeaveLine)6 LeaveService (com.axelor.apps.hr.service.leave.LeaveService)6 HashMap (java.util.HashMap)6 Map (java.util.Map)6 Company (com.axelor.apps.base.db.Company)5