use of com.axelor.apps.hr.db.ExpenseLine in project axelor-open-suite by axelor.
the class ExpenseController method computeAnalyticDistribution.
public void computeAnalyticDistribution(ActionRequest request, ActionResponse response) throws AxelorException {
ExpenseLine expenseLine = request.getContext().asType(ExpenseLine.class);
Expense expense = expenseLine.getExpense();
if (expense == null) {
setExpense(request, expenseLine);
}
if (Beans.get(AppAccountService.class).getAppAccount().getManageAnalyticAccounting()) {
expenseLine = Beans.get(ExpenseService.class).computeAnalyticDistribution(expenseLine);
response.setValue("analyticMoveLineList", expenseLine.getAnalyticMoveLineList());
}
}
use of com.axelor.apps.hr.db.ExpenseLine in project axelor-open-suite by axelor.
the class ExpenseController method validateAndCompute.
public void validateAndCompute(ActionRequest request, ActionResponse response) {
Expense expense = request.getContext().asType(Expense.class);
ExpenseService expenseService = Beans.get(ExpenseService.class);
List<Integer> expenseLineListId = new ArrayList<>();
int compt = 0;
for (ExpenseLine expenseLine : expenseService.getExpenseLineList(expense)) {
compt++;
if (expenseLine.getExpenseDate().isAfter(Beans.get(AppBaseService.class).getTodayDate(expense.getCompany()))) {
expenseLineListId.add(compt);
}
}
try {
if (!expenseLineListId.isEmpty()) {
throw new AxelorException(TraceBackRepository.CATEGORY_CONFIGURATION_ERROR, I18n.get("Date can't be in the future for line(s) : %s"), expenseLineListId.stream().map(id -> id.toString()).collect(Collectors.joining(",")));
}
} catch (AxelorException e) {
TraceBackService.trace(response, e, ResponseMessageType.ERROR);
}
response.setValue("personalExpenseAmount", expenseService.computePersonalExpenseAmount(expense));
response.setValue("advanceAmount", expenseService.computeAdvanceAmount(expense));
if (expense.getKilometricExpenseLineList() != null && !expense.getKilometricExpenseLineList().isEmpty()) {
response.setValue("kilometricExpenseLineList", expense.getKilometricExpenseLineList());
}
compute(request, response);
}
use of com.axelor.apps.hr.db.ExpenseLine in project axelor-open-suite by axelor.
the class ExpenseController method computeDistanceAndKilometricExpense.
public void computeDistanceAndKilometricExpense(ActionRequest request, ActionResponse response) throws AxelorException {
// Compute distance.
try {
if (!Beans.get(AppHumanResourceService.class).getAppExpense().getComputeDistanceWithWebService()) {
return;
}
Context context = request.getContext();
ExpenseLine expenseLine = context.asType(ExpenseLine.class);
if (Strings.isNullOrEmpty(expenseLine.getFromCity()) || Strings.isNullOrEmpty(expenseLine.getToCity())) {
return;
}
KilometricService kilometricService = Beans.get(KilometricService.class);
BigDecimal distance = kilometricService.computeDistance(expenseLine);
expenseLine.setDistance(distance);
response.setValue("distance", distance);
if (expenseLine.getKilometricAllowParam() == null || expenseLine.getExpenseDate() == null || expenseLine.getKilometricTypeSelect() == 0) {
return;
}
Expense expense = expenseLine.getExpense();
if (expense == null) {
expense = context.getParent().asType(Expense.class);
}
Employee employee = expense.getUser().getEmployee();
if (employee == null) {
throw new AxelorException(TraceBackRepository.CATEGORY_CONFIGURATION_ERROR, I18n.get(IExceptionMessage.LEAVE_USER_EMPLOYEE), expense.getUser().getName());
}
BigDecimal amount = kilometricService.computeKilometricExpense(expenseLine, employee);
response.setValue("totalAmount", amount);
response.setValue("untaxedAmount", amount);
} catch (Exception e) {
TraceBackService.trace(response, e);
}
}
use of com.axelor.apps.hr.db.ExpenseLine in project axelor-open-suite by axelor.
the class ExpenseController method createAnalyticDistributionWithTemplate.
public void createAnalyticDistributionWithTemplate(ActionRequest request, ActionResponse response) throws AxelorException {
ExpenseLine expenseLine = request.getContext().asType(ExpenseLine.class);
expenseLine = Beans.get(ExpenseService.class).createAnalyticDistributionWithTemplate(expenseLine);
response.setValue("analyticMoveLineList", expenseLine.getAnalyticMoveLineList());
}
use of com.axelor.apps.hr.db.ExpenseLine in project axelor-open-suite by axelor.
the class ExpenseServiceImpl method validate.
@Override
@Transactional(rollbackOn = { Exception.class })
public void validate(Expense expense) throws AxelorException {
Employee employee = expense.getUser().getEmployee();
if (employee == null) {
throw new AxelorException(expense, TraceBackRepository.CATEGORY_CONFIGURATION_ERROR, I18n.get(IExceptionMessage.LEAVE_USER_EMPLOYEE), expense.getUser().getFullName());
}
if (expense.getPeriod() == null) {
throw new AxelorException(expense, TraceBackRepository.CATEGORY_MISSING_FIELD, I18n.get(IExceptionMessage.EXPENSE_MISSING_PERIOD));
}
List<ExpenseLine> kilometricExpenseLineList = expense.getKilometricExpenseLineList();
KilometricService kilometricService = Beans.get(KilometricService.class);
if (ObjectUtils.notEmpty(kilometricExpenseLineList)) {
for (ExpenseLine line : kilometricExpenseLineList) {
BigDecimal amount = kilometricService.computeKilometricExpense(line, employee);
line.setTotalAmount(amount);
line.setUntaxedAmount(amount);
kilometricService.updateKilometricLog(line, employee);
}
compute(expense);
}
Beans.get(EmployeeAdvanceService.class).fillExpenseWithAdvances(expense);
expense.setStatusSelect(ExpenseRepository.STATUS_VALIDATED);
expense.setValidatedBy(AuthUtils.getUser());
expense.setValidationDate(appAccountService.getTodayDate(expense.getCompany()));
if (expense.getUser().getPartner() != null) {
PaymentMode paymentMode = expense.getUser().getPartner().getOutPaymentMode();
expense.setPaymentMode(paymentMode);
}
expenseRepository.save(expense);
}
Aggregations