use of com.axelor.apps.hr.db.Expense in project axelor-open-suite by axelor.
the class BatchCreditTransferExpensePaymentHR method processExpenses.
/**
* Process expenses that need to be paid.
*
* @return
*/
protected List<Expense> processExpenses() {
List<Expense> doneList = new ArrayList<>();
// Can't pass an empty collection to the query
List<Long> anomalyList = Lists.newArrayList(0L);
AccountingBatch accountingBatch = batch.getAccountingBatch();
boolean manageMultiBanks = appAccountService.getAppBase().getManageMultiBanks();
String filter = "self.ventilated = true " + "AND self.paymentStatusSelect = :paymentStatusSelect " + "AND self.company = :company " + "AND self.user.partner.outPaymentMode = :paymentMode " + "AND self.id NOT IN (:anomalyList)";
if (manageMultiBanks) {
filter += " AND self.bankDetails IN (:bankDetailsSet)";
}
Query<Expense> query = expenseRepo.all().filter(filter).bind("paymentStatusSelect", InvoicePaymentRepository.STATUS_DRAFT).bind("company", accountingBatch.getCompany()).bind("paymentMode", accountingBatch.getPaymentMode()).bind("anomalyList", anomalyList);
if (manageMultiBanks) {
Set<BankDetails> bankDetailsSet = Sets.newHashSet(accountingBatch.getBankDetails());
if (accountingBatch.getIncludeOtherBankAccounts()) {
bankDetailsSet.addAll(accountingBatch.getCompany().getBankDetailsList());
}
query.bind("bankDetailsSet", bankDetailsSet);
}
for (List<Expense> expenseList; !(expenseList = query.fetch(FETCH_LIMIT)).isEmpty(); JPA.clear()) {
for (Expense expense : expenseList) {
try {
addPayment(expense, accountingBatch.getBankDetails());
doneList.add(expense);
incrementDone();
} catch (Exception ex) {
incrementAnomaly();
anomalyList.add(expense.getId());
query.bind("anomalyList", anomalyList);
TraceBackService.trace(ex, ExceptionOriginRepository.CREDIT_TRANSFER, batch.getId());
ex.printStackTrace();
log.error(String.format("Credit transfer batch for expense payment: anomaly for expense %s", expense.getExpenseSeq()));
break;
}
}
}
return doneList;
}
use of com.axelor.apps.hr.db.Expense in project axelor-open-suite by axelor.
the class BatchCreditTransferExpensePaymentHR method mergeBankOrders.
/**
* Merge bank orders.
*
* @param doneList
* @throws AxelorException
*/
@Transactional(rollbackOn = { Exception.class })
protected void mergeBankOrders(List<Expense> doneList) throws AxelorException {
List<Expense> expenseList = new ArrayList<>();
List<BankOrder> bankOrderList = new ArrayList<>();
for (Expense expense : doneList) {
BankOrder bankOrder = expense.getBankOrder();
if (bankOrder != null) {
expenseList.add(expense);
bankOrderList.add(bankOrder);
}
}
if (bankOrderList.size() > 1) {
BankOrder mergedBankOrder = bankOrderMergeService.mergeBankOrders(bankOrderList);
for (Expense expense : expenseList) {
expense.setBankOrder(mergedBankOrder);
}
}
}
use of com.axelor.apps.hr.db.Expense in project axelor-open-suite by axelor.
the class ExpenseServiceImpl method getListOfKilometricAllowParamVehicleFilter.
@Override
public List<KilometricAllowParam> getListOfKilometricAllowParamVehicleFilter(ExpenseLine expenseLine) throws AxelorException {
List<KilometricAllowParam> kilometricAllowParamList = new ArrayList<>();
Expense expense = expenseLine.getExpense();
if (expense == null) {
return kilometricAllowParamList;
}
if (expense.getId() != null) {
expense = expenseRepository.find(expense.getId());
}
LocalDate expenseDate = expenseLine.getExpenseDate();
if (expense.getUser() == null || expense.getUser().getEmployee() == null || expenseDate == null) {
return kilometricAllowParamList;
}
List<EmployeeVehicle> vehicleList = expense.getUser().getEmployee().getEmployeeVehicleList();
for (EmployeeVehicle vehicle : vehicleList) {
LocalDate startDate = vehicle.getStartDate();
LocalDate endDate = vehicle.getEndDate();
if (startDate == null) {
if (endDate == null || expenseDate.compareTo(endDate) <= 0) {
kilometricAllowParamList.add(vehicle.getKilometricAllowParam());
}
} else if (endDate == null) {
if (expenseDate.compareTo(startDate) >= 0) {
kilometricAllowParamList.add(vehicle.getKilometricAllowParam());
}
} else if (expenseDate.compareTo(startDate) >= 0 && expenseDate.compareTo(endDate) <= 0) {
kilometricAllowParamList.add(vehicle.getKilometricAllowParam());
}
}
return kilometricAllowParamList;
}
use of com.axelor.apps.hr.db.Expense in project axelor-open-suite by axelor.
the class ExpenseServiceImpl method getOrCreateExpense.
@Override
public Expense getOrCreateExpense(User user) {
Expense expense = Beans.get(ExpenseRepository.class).all().filter("self.statusSelect = ?1 AND self.user.id = ?2", ExpenseRepository.STATUS_DRAFT, user.getId()).order("-id").fetchOne();
if (expense == null) {
expense = new Expense();
expense.setUser(user);
Company company = null;
if (user.getEmployee() != null && user.getEmployee().getMainEmploymentContract() != null) {
company = user.getEmployee().getMainEmploymentContract().getPayCompany();
} else {
company = user.getActiveCompany();
}
Period period = Beans.get(PeriodRepository.class).all().filter("self.fromDate <= ?1 AND self.toDate >= ?1 AND self.allowExpenseCreation = true AND self.year.company = ?2 AND self.year.typeSelect = ?3", Beans.get(AppBaseService.class).getTodayDate(company), company, YearBaseRepository.STATUS_OPENED).fetchOne();
expense.setCompany(company);
expense.setPeriod(period);
expense.setStatusSelect(ExpenseRepository.STATUS_DRAFT);
}
return expense;
}
use of com.axelor.apps.hr.db.Expense in project axelor-open-suite by axelor.
the class ExpenseController method printExpense.
public void printExpense(ActionRequest request, ActionResponse response) throws AxelorException {
Expense expense = request.getContext().asType(Expense.class);
String name = I18n.get("Expense") + " " + expense.getFullName().replace("/", "-");
String fileLink = ReportFactory.createReport(IReport.EXPENSE, name).addParam("ExpenseId", expense.getId()).addParam("Timezone", expense.getCompany() != null ? expense.getCompany().getTimezone() : null).addParam("Locale", ReportSettings.getPrintingLocale(null)).toAttach(expense).generate().getFileLink();
logger.debug("Printing {}", name);
response.setView(ActionView.define(name).add("html", fileLink).map());
}
Aggregations