use of com.axelor.exception.AxelorException in project axelor-open-suite by axelor.
the class TimesheetServiceImpl method validateDates.
/**
* Checks validity of dates related to the timesheet.
*
* @param timesheet
* @throws AxelorException if
* <ul>
* <li>fromDate of the timesheet is null
* <li>toDate of the timesheet is null
* <li>timesheetLineList of the timesheet is null or empty
* <li>date of a timesheet line is null
* <li>date of a timesheet line is before fromDate or after toDate of the timesheet
* </ul>
*/
protected void validateDates(Timesheet timesheet) throws AxelorException {
List<TimesheetLine> timesheetLineList = timesheet.getTimesheetLineList();
LocalDate fromDate = timesheet.getFromDate();
LocalDate toDate = timesheet.getToDate();
if (fromDate == null) {
throw new AxelorException(timesheet, TraceBackRepository.CATEGORY_MISSING_FIELD, I18n.get(IExceptionMessage.TIMESHEET_NULL_FROM_DATE));
} else if (toDate == null) {
throw new AxelorException(timesheet, TraceBackRepository.CATEGORY_MISSING_FIELD, I18n.get(IExceptionMessage.TIMESHEET_NULL_TO_DATE));
} else if (ObjectUtils.isEmpty(timesheetLineList)) {
throw new AxelorException(timesheet, TraceBackRepository.CATEGORY_NO_VALUE, I18n.get(IExceptionMessage.TIMESHEET_TIMESHEET_LINE_LIST_IS_EMPTY));
} else {
for (TimesheetLine timesheetLine : timesheetLineList) {
LocalDate timesheetLineDate = timesheetLine.getDate();
if (timesheetLineDate == null) {
throw new AxelorException(timesheetLine, TraceBackRepository.CATEGORY_MISSING_FIELD, I18n.get(IExceptionMessage.TIMESHEET_LINE_NULL_DATE), timesheetLineList.indexOf(timesheetLine) + 1);
}
}
}
}
use of com.axelor.exception.AxelorException in project axelor-open-suite by axelor.
the class TimesheetServiceImpl method createInvoiceLine.
@Override
public List<InvoiceLine> createInvoiceLine(Invoice invoice, Product product, User user, String date, BigDecimal hoursDuration, int priority, PriceList priceList) throws AxelorException {
int discountMethodTypeSelect = PriceListLineRepository.TYPE_DISCOUNT;
int discountTypeSelect = PriceListLineRepository.AMOUNT_TYPE_NONE;
if (product == null) {
throw new AxelorException(TraceBackRepository.CATEGORY_CONFIGURATION_ERROR, I18n.get(IExceptionMessage.TIMESHEET_PRODUCT));
}
BigDecimal price = (BigDecimal) productCompanyService.get(product, "salePrice", invoice.getCompany());
BigDecimal discountAmount = BigDecimal.ZERO;
BigDecimal priceDiscounted = price;
BigDecimal qtyConverted = Beans.get(UnitConversionService.class).convert(appHumanResourceService.getAppBase().getUnitHours(), (Unit) productCompanyService.get(product, "unit", invoice.getCompany()), hoursDuration, AppBaseService.DEFAULT_NB_DECIMAL_DIGITS, product);
if (priceList != null) {
PriceListLine priceListLine = priceListService.getPriceListLine(product, qtyConverted, priceList, price);
if (priceListLine != null) {
discountMethodTypeSelect = priceListLine.getTypeSelect();
}
Map<String, Object> discounts = priceListService.getDiscounts(priceList, priceListLine, price);
if (discounts != null) {
discountAmount = (BigDecimal) discounts.get("discountAmount");
discountTypeSelect = (int) discounts.get("discountTypeSelect");
priceDiscounted = priceListService.computeDiscount(price, discountTypeSelect, discountAmount);
}
if ((appHumanResourceService.getAppBase().getComputeMethodDiscountSelect() == AppBaseRepository.INCLUDE_DISCOUNT_REPLACE_ONLY && discountMethodTypeSelect == PriceListLineRepository.TYPE_REPLACE) || appHumanResourceService.getAppBase().getComputeMethodDiscountSelect() == AppBaseRepository.INCLUDE_DISCOUNT) {
discountTypeSelect = PriceListLineRepository.AMOUNT_TYPE_NONE;
price = priceDiscounted;
}
}
String description = user.getFullName();
String productName = (String) productCompanyService.get(product, "name", invoice.getCompany());
if (date != null) {
productName += " " + "(" + date + ")";
}
InvoiceLineGenerator invoiceLineGenerator = new InvoiceLineGenerator(invoice, product, productName, price, price, priceDiscounted, description, qtyConverted, (Unit) productCompanyService.get(product, "unit", invoice.getCompany()), null, priority, discountAmount, discountTypeSelect, price.multiply(qtyConverted), null, false) {
@Override
public List<InvoiceLine> creates() throws AxelorException {
InvoiceLine invoiceLine = this.createInvoiceLine();
List<InvoiceLine> invoiceLines = new ArrayList<>();
invoiceLines.add(invoiceLine);
return invoiceLines;
}
};
return invoiceLineGenerator.creates();
}
use of com.axelor.exception.AxelorException in project axelor-open-suite by axelor.
the class EmployeeController method generateNewDPAE.
public void generateNewDPAE(ActionRequest request, ActionResponse response) {
Employee employee = request.getContext().asType(Employee.class);
employee = Beans.get(EmployeeRepository.class).find(employee.getId());
try {
Long dpaeId = Beans.get(EmployeeService.class).generateNewDPAE(employee);
ActionViewBuilder builder = ActionView.define(I18n.get("DPAE")).model(DPAE.class.getName()).add("grid", "dpae-grid").add("form", "dpae-form").param("search-filters", "dpae-filters").context("_showRecord", dpaeId);
response.setView(builder.map());
} catch (AxelorException e) {
TraceBackService.trace(response, e);
}
response.setReload(true);
}
use of com.axelor.exception.AxelorException 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.exception.AxelorException 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);
}
}
Aggregations