use of com.axelor.apps.hr.db.Expense 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.Expense in project axelor-open-suite by axelor.
the class ExpenseController method refuse.
// refusing expense and sending mail to applicant
public void refuse(ActionRequest request, ActionResponse response) throws AxelorException {
try {
Expense expense = request.getContext().asType(Expense.class);
expense = Beans.get(ExpenseRepository.class).find(expense.getId());
ExpenseService expenseService = Beans.get(ExpenseService.class);
expenseService.refuse(expense);
Message message = expenseService.sendRefusalEmail(expense);
if (message != null && message.getStatusSelect() == MessageRepository.STATUS_SENT) {
response.setFlash(String.format(I18n.get("Email sent to %s"), Beans.get(MessageServiceBaseImpl.class).getToRecipients(message)));
}
} catch (Exception e) {
TraceBackService.trace(response, e);
} finally {
response.setReload(true);
}
}
use of com.axelor.apps.hr.db.Expense in project axelor-open-suite by axelor.
the class ExpenseController method send.
// sending expense and sending mail to manager
public void send(ActionRequest request, ActionResponse response) throws AxelorException {
try {
Expense expense = request.getContext().asType(Expense.class);
expense = Beans.get(ExpenseRepository.class).find(expense.getId());
ExpenseService expenseService = Beans.get(ExpenseService.class);
expenseService.confirm(expense);
Message message = expenseService.sendConfirmationEmail(expense);
if (message != null && message.getStatusSelect() == MessageRepository.STATUS_SENT) {
response.setFlash(String.format(I18n.get("Email sent to %s"), Beans.get(MessageServiceBaseImpl.class).getToRecipients(message)));
}
} catch (Exception e) {
TraceBackService.trace(response, e);
} finally {
response.setReload(true);
}
}
use of com.axelor.apps.hr.db.Expense in project axelor-open-suite by axelor.
the class ExpenseController method valid.
// validating expense and sending mail to applicant
public void valid(ActionRequest request, ActionResponse response) throws AxelorException {
try {
Expense expense = request.getContext().asType(Expense.class);
expense = Beans.get(ExpenseRepository.class).find(expense.getId());
ExpenseService expenseService = Beans.get(ExpenseService.class);
expenseService.validate(expense);
Message message = expenseService.sendValidationEmail(expense);
if (message != null && message.getStatusSelect() == MessageRepository.STATUS_SENT) {
response.setFlash(String.format(I18n.get("Email sent to %s"), Beans.get(MessageServiceBaseImpl.class).getToRecipients(message)));
}
} catch (Exception e) {
TraceBackService.trace(response, e);
} finally {
response.setReload(true);
}
}
use of com.axelor.apps.hr.db.Expense in project axelor-open-suite by axelor.
the class BankOrderServiceHRImpl method validatePayment.
@Override
@Transactional(rollbackOn = { Exception.class })
public void validatePayment(BankOrder bankOrder) throws AxelorException {
super.validatePayment(bankOrder);
if (!Beans.get(AppService.class).isApp("employee")) {
return;
}
List<Expense> expenseList = Beans.get(ExpenseRepository.class).all().filter("self.bankOrder.id = ?", bankOrder.getId()).fetch();
for (Expense expense : expenseList) {
if (expense != null && expense.getStatusSelect() != ExpenseRepository.STATUS_REIMBURSED) {
expense.setStatusSelect(ExpenseRepository.STATUS_REIMBURSED);
expense.setPaymentStatusSelect(InvoicePaymentRepository.STATUS_VALIDATED);
expenseService.createMoveForExpensePayment(expense);
}
}
}
Aggregations