Search in sources :

Example 66 with AxelorException

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);
            }
        }
    }
}
Also used : AxelorException(com.axelor.exception.AxelorException) TimesheetLine(com.axelor.apps.hr.db.TimesheetLine) LocalDate(java.time.LocalDate)

Example 67 with AxelorException

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();
}
Also used : AxelorException(com.axelor.exception.AxelorException) UnitConversionService(com.axelor.apps.base.service.UnitConversionService) InvoiceLine(com.axelor.apps.account.db.InvoiceLine) PriceListLine(com.axelor.apps.base.db.PriceListLine) ArrayList(java.util.ArrayList) InvoiceLineGenerator(com.axelor.apps.account.service.invoice.generator.InvoiceLineGenerator) BigDecimal(java.math.BigDecimal)

Example 68 with AxelorException

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);
}
Also used : DPAE(com.axelor.apps.hr.db.DPAE) AxelorException(com.axelor.exception.AxelorException) Employee(com.axelor.apps.hr.db.Employee) EmployeeService(com.axelor.apps.hr.service.employee.EmployeeService) ActionViewBuilder(com.axelor.meta.schema.actions.ActionView.ActionViewBuilder)

Example 69 with AxelorException

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);
    }
}
Also used : IExceptionMessage(com.axelor.apps.hr.exception.IExceptionMessage) Message(com.axelor.apps.message.db.Message) Expense(com.axelor.apps.hr.db.Expense) MessageServiceBaseImpl(com.axelor.apps.base.service.message.MessageServiceBaseImpl) ExpenseService(com.axelor.apps.hr.service.expense.ExpenseService) AxelorException(com.axelor.exception.AxelorException)

Example 70 with AxelorException

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);
    }
}
Also used : IExceptionMessage(com.axelor.apps.hr.exception.IExceptionMessage) Message(com.axelor.apps.message.db.Message) Expense(com.axelor.apps.hr.db.Expense) MessageServiceBaseImpl(com.axelor.apps.base.service.message.MessageServiceBaseImpl) ExpenseService(com.axelor.apps.hr.service.expense.ExpenseService) AxelorException(com.axelor.exception.AxelorException)

Aggregations

AxelorException (com.axelor.exception.AxelorException)546 Transactional (com.google.inject.persist.Transactional)126 BigDecimal (java.math.BigDecimal)118 ArrayList (java.util.ArrayList)84 IOException (java.io.IOException)73 Product (com.axelor.apps.base.db.Product)64 Company (com.axelor.apps.base.db.Company)63 LocalDate (java.time.LocalDate)58 Partner (com.axelor.apps.base.db.Partner)48 List (java.util.List)45 StockMoveLine (com.axelor.apps.stock.db.StockMoveLine)40 HashMap (java.util.HashMap)38 Invoice (com.axelor.apps.account.db.Invoice)33 StockMove (com.axelor.apps.stock.db.StockMove)32 Map (java.util.Map)31 Beans (com.axelor.inject.Beans)30 I18n (com.axelor.i18n.I18n)28 Inject (com.google.inject.Inject)28 MoveLine (com.axelor.apps.account.db.MoveLine)27 Context (com.axelor.rpc.Context)27