use of com.axelor.apps.hr.db.Expense in project axelor-open-suite by axelor.
the class ExpenseController method editExpense.
public void editExpense(ActionRequest request, ActionResponse response) {
User user = AuthUtils.getUser();
Company activeCompany = user.getActiveCompany();
List<Expense> expenseList = Beans.get(ExpenseRepository.class).all().filter("self.user = ?1 AND self.company = ?2 AND self.statusSelect = 1 AND (self.multipleUsers is false OR self.multipleUsers is null)", user, activeCompany).fetch();
if (expenseList.isEmpty()) {
response.setView(ActionView.define(I18n.get("Expense")).model(Expense.class.getName()).add("form", "expense-form").context("_payCompany", Beans.get(UserHrService.class).getPayCompany(user)).map());
} else if (expenseList.size() == 1) {
response.setView(ActionView.define(I18n.get("Expense")).model(Expense.class.getName()).add("form", "expense-form").param("forceEdit", "true").context("_showRecord", String.valueOf(expenseList.get(0).getId())).map());
} else {
response.setView(ActionView.define(I18n.get("Expense")).model(Wizard.class.getName()).add("form", "popup-expense-form").param("forceEdit", "true").param("popup", "true").param("show-toolbar", "false").param("show-confirm", "false").param("forceEdit", "true").param("popup-save", "false").map());
}
}
use of com.axelor.apps.hr.db.Expense in project axelor-open-suite by axelor.
the class ExpenseController method cancelPayment.
/**
* Called on clicking cancelPaymentButton, call {@link ExpenseService#cancelPayment(Expense)}.
*
* @param request
* @param response
*/
public void cancelPayment(ActionRequest request, ActionResponse response) {
Expense expense = request.getContext().asType(Expense.class);
expense = Beans.get(ExpenseRepository.class).find(expense.getId());
try {
Beans.get(ExpenseService.class).cancelPayment(expense);
response.setReload(true);
} 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 computeKilometricExpense.
public void computeKilometricExpense(ActionRequest request, ActionResponse response) throws AxelorException {
ExpenseLine expenseLine = request.getContext().asType(ExpenseLine.class);
if (expenseLine.getKilometricAllowParam() == null || expenseLine.getDistance().compareTo(BigDecimal.ZERO) == 0 || expenseLine.getExpenseDate() == null) {
return;
}
String userId;
String userName;
if (expenseLine.getExpense() != null) {
setExpense(request, expenseLine);
}
Expense expense = expenseLine.getExpense();
if (expense != null && expenseLine.getUser() != null) {
userId = expense.getUser().getId().toString();
userName = expense.getUser().getFullName();
} else {
userId = request.getContext().getParent().asType(Expense.class).getUser().getId().toString();
userName = request.getContext().getParent().asType(Expense.class).getUser().getFullName();
}
Employee employee = Beans.get(EmployeeRepository.class).all().filter("self.user.id = ?1", userId).fetchOne();
if (employee == null) {
throw new AxelorException(TraceBackRepository.CATEGORY_CONFIGURATION_ERROR, I18n.get(IExceptionMessage.LEAVE_USER_EMPLOYEE), userName);
}
BigDecimal amount = BigDecimal.ZERO;
try {
amount = Beans.get(KilometricService.class).computeKilometricExpense(expenseLine, employee);
} catch (Exception e) {
TraceBackService.trace(response, e);
}
response.setValue("totalAmount", amount);
response.setValue("untaxedAmount", amount);
}
use of com.axelor.apps.hr.db.Expense in project axelor-open-suite by axelor.
the class ExpenseController method addPayment.
public void addPayment(ActionRequest request, ActionResponse response) {
Expense expense = request.getContext().asType(Expense.class);
expense = Beans.get(ExpenseRepository.class).find(expense.getId());
try {
Beans.get(ExpenseService.class).addPayment(expense);
response.setReload(true);
} 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 updateMoveDateAndPeriod.
public void updateMoveDateAndPeriod(ActionRequest request, ActionResponse response) {
Expense expense = request.getContext().asType(Expense.class);
expense = Beans.get(ExpenseService.class).updateMoveDateAndPeriod(expense);
response.setValue("moveDate", expense.getMoveDate());
response.setValue("period", expense.getPeriod());
}
Aggregations