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());
}
}
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));
}
}
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());
}
}
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;
}
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);
}
Aggregations