Search in sources :

Example 31 with Company

use of com.axelor.apps.base.db.Company in project axelor-open-suite by axelor.

the class ExpenseController method showSubordinateExpenses.

public void showSubordinateExpenses(ActionRequest request, ActionResponse response) {
    User user = AuthUtils.getUser();
    Company activeCompany = user.getActiveCompany();
    ActionViewBuilder actionView = ActionView.define(I18n.get("Expenses to be Validated by your subordinates")).model(Expense.class.getName()).add("grid", "expense-grid").add("form", "expense-form").param("search-filters", "expense-filters");
    String domain = "self.user.employee.managerUser.employee.managerUser = :_user AND self.company = :_activeCompany AND self.statusSelect = 2";
    long nbExpenses = Query.of(Expense.class).filter(domain).bind("_user", user).bind("_activeCompany", activeCompany).count();
    if (nbExpenses == 0) {
        response.setNotify(I18n.get("No expense to be validated by your subordinates"));
    } else {
        response.setView(actionView.domain(domain).context("_user", user).context("_activeCompany", activeCompany).map());
    }
}
Also used : Company(com.axelor.apps.base.db.Company) User(com.axelor.auth.db.User) ActionViewBuilder(com.axelor.meta.schema.actions.ActionView.ActionViewBuilder)

Example 32 with Company

use of com.axelor.apps.base.db.Company in project axelor-open-suite by axelor.

the class LunchVoucherAdvanceController method checkOnNewAdvance.

public void checkOnNewAdvance(ActionRequest request, ActionResponse response) throws AxelorException {
    LunchVoucherAdvance lunchVoucherAdvance = EntityHelper.getEntity(request.getContext().asType(LunchVoucherAdvance.class));
    if (lunchVoucherAdvance.getEmployee().getMainEmploymentContract() == null) {
        response.setError(String.format(I18n.get(IExceptionMessage.EMPLOYEE_CONTRACT_OF_EMPLOYMENT), lunchVoucherAdvance.getEmployee().getName()));
        return;
    }
    Company company = lunchVoucherAdvance.getEmployee().getMainEmploymentContract().getPayCompany();
    HRConfig hrConfig = Beans.get(HRConfigService.class).getHRConfig(company);
    int stock = Beans.get(LunchVoucherMgtService.class).checkStock(company, lunchVoucherAdvance.getNbrLunchVouchers());
    if (stock <= 0) {
        response.setAlert(String.format(I18n.get(IExceptionMessage.LUNCH_VOUCHER_MIN_STOCK), company.getName(), hrConfig.getMinStockLunchVoucher(), hrConfig.getAvailableStockLunchVoucher(), TraceBackRepository.CATEGORY_INCONSISTENCY));
    }
}
Also used : LunchVoucherAdvance(com.axelor.apps.hr.db.LunchVoucherAdvance) Company(com.axelor.apps.base.db.Company) HRConfig(com.axelor.apps.hr.db.HRConfig) HRConfigService(com.axelor.apps.hr.service.config.HRConfigService) LunchVoucherMgtService(com.axelor.apps.hr.service.lunch.voucher.LunchVoucherMgtService)

Example 33 with Company

use of com.axelor.apps.base.db.Company in project axelor-open-suite by axelor.

the class TimesheetController method showSubordinateTimesheets.

public void showSubordinateTimesheets(ActionRequest request, ActionResponse response) {
    User user = AuthUtils.getUser();
    Company activeCompany = user.getActiveCompany();
    ActionViewBuilder actionView = ActionView.define(I18n.get("Timesheets to be Validated by your subordinates")).model(Timesheet.class.getName()).add("grid", "timesheet-grid").add("form", "timesheet-form").param("search-filters", "timesheet-filters");
    String domain = "self.user.employee.managerUser.employee.managerUser = :_user AND self.company = :_activeCompany AND self.statusSelect = 2";
    long nbTimesheets = Query.of(Timesheet.class).filter(domain).bind("_user", user).bind("_activeCompany", activeCompany).count();
    if (nbTimesheets == 0) {
        response.setNotify(I18n.get("No timesheet to be validated by your subordinates"));
    } else {
        response.setView(actionView.domain(domain).context("_user", user).context("_activeCompany", activeCompany).map());
    }
}
Also used : Company(com.axelor.apps.base.db.Company) User(com.axelor.auth.db.User) ActionViewBuilder(com.axelor.meta.schema.actions.ActionView.ActionViewBuilder)

Example 34 with Company

use of com.axelor.apps.base.db.Company in project axelor-open-suite by axelor.

the class TimesheetServiceImpl method createTimesheet.

@Override
public Timesheet createTimesheet(User user, LocalDate fromDate, LocalDate toDate) {
    Timesheet timesheet = new Timesheet();
    timesheet.setUser(user);
    Company company = null;
    Employee employee = user.getEmployee();
    if (employee != null && employee.getMainEmploymentContract() != null) {
        company = employee.getMainEmploymentContract().getPayCompany();
    } else {
        company = user.getActiveCompany();
    }
    String timeLoggingPreferenceSelect = employee == null ? null : employee.getTimeLoggingPreferenceSelect();
    timesheet.setTimeLoggingPreferenceSelect(timeLoggingPreferenceSelect);
    timesheet.setCompany(company);
    timesheet.setFromDate(fromDate);
    timesheet.setStatusSelect(TimesheetRepository.STATUS_DRAFT);
    timesheet.setFullName(computeFullName(timesheet));
    return timesheet;
}
Also used : Company(com.axelor.apps.base.db.Company) Employee(com.axelor.apps.hr.db.Employee) Timesheet(com.axelor.apps.hr.db.Timesheet) AppTimesheet(com.axelor.apps.base.db.AppTimesheet)

Example 35 with Company

use of com.axelor.apps.base.db.Company in project axelor-open-suite by axelor.

the class WeightedAveragePriceServiceImpl method computeAvgPriceForProduct.

@Override
@Transactional
public void computeAvgPriceForProduct(Product product) throws AxelorException {
    Boolean avgPriceHandledByCompany = false;
    Set<MetaField> companySpecificFields = appBaseService.getAppBase().getCompanySpecificProductFieldsSet();
    for (MetaField field : companySpecificFields) {
        if (field.getName().equals("avgPrice")) {
            avgPriceHandledByCompany = true;
            break;
        }
    }
    if (avgPriceHandledByCompany && product.getProductCompanyList() != null && !product.getProductCompanyList().isEmpty()) {
        for (ProductCompany productCompany : product.getProductCompanyList()) {
            Company company = productCompany.getCompany();
            BigDecimal productAvgPrice = this.computeAvgPriceForCompany(product, company);
            if (productAvgPrice.compareTo(BigDecimal.ZERO) == 0) {
                continue;
            }
            productCompanyService.set(product, "avgPrice", productAvgPrice, company);
            if ((Integer) productCompanyService.get(product, "costTypeSelect", company) == ProductRepository.COST_TYPE_AVERAGE_PRICE) {
                productCompanyService.set(product, "costPrice", productAvgPrice, company);
                if ((Boolean) productCompanyService.get(product, "autoUpdateSalePrice", company)) {
                    Beans.get(ProductService.class).updateSalePrice(product, company);
                }
            }
        }
    } else {
        BigDecimal productAvgPrice = this.computeAvgPriceForCompany(product, null);
        if (productAvgPrice.compareTo(BigDecimal.ZERO) == 0) {
            return;
        }
        product.setAvgPrice(productAvgPrice);
        if (product.getCostTypeSelect() == ProductRepository.COST_TYPE_AVERAGE_PRICE) {
            product.setCostPrice(productAvgPrice);
            if (product.getAutoUpdateSalePrice()) {
                Beans.get(ProductService.class).updateSalePrice(product, null);
            }
        }
    }
    productRepo.save(product);
}
Also used : Company(com.axelor.apps.base.db.Company) ProductCompany(com.axelor.apps.base.db.ProductCompany) MetaField(com.axelor.meta.db.MetaField) ProductService(com.axelor.apps.base.service.ProductService) ProductCompany(com.axelor.apps.base.db.ProductCompany) BigDecimal(java.math.BigDecimal) Transactional(com.google.inject.persist.Transactional)

Aggregations

Company (com.axelor.apps.base.db.Company)213 Transactional (com.google.inject.persist.Transactional)72 Partner (com.axelor.apps.base.db.Partner)68 AxelorException (com.axelor.exception.AxelorException)65 BigDecimal (java.math.BigDecimal)54 Move (com.axelor.apps.account.db.Move)35 MoveLine (com.axelor.apps.account.db.MoveLine)35 LocalDate (java.time.LocalDate)35 ArrayList (java.util.ArrayList)31 PaymentMode (com.axelor.apps.account.db.PaymentMode)28 AccountConfig (com.axelor.apps.account.db.AccountConfig)27 Journal (com.axelor.apps.account.db.Journal)26 Account (com.axelor.apps.account.db.Account)25 Invoice (com.axelor.apps.account.db.Invoice)25 BankDetails (com.axelor.apps.base.db.BankDetails)22 Currency (com.axelor.apps.base.db.Currency)19 Product (com.axelor.apps.base.db.Product)17 StockLocation (com.axelor.apps.stock.db.StockLocation)17 StockMove (com.axelor.apps.stock.db.StockMove)15 List (java.util.List)15