Search in sources :

Example 1 with WorkingAgreement

use of com.autentia.tnt.businessobject.WorkingAgreement in project TNTConcept by autentia.

the class UserBean method getAgreements.

/**
 * Get the list of all agreements
 *
 * @return the list of all agreements
 */
public List<SelectItem> getAgreements() {
    List<WorkingAgreement> refs = WorkingAgreementManager.getDefault().getAllEntities(null, new SortCriteria("name"));
    ArrayList<SelectItem> ret = new ArrayList<SelectItem>();
    for (WorkingAgreement ref : refs) {
        ret.add(new SelectItem(ref, ref.getName()));
    }
    return ret;
}
Also used : SortCriteria(com.autentia.tnt.dao.SortCriteria) SelectItem(javax.faces.model.SelectItem) ArrayList(java.util.ArrayList) WorkingAgreement(com.autentia.tnt.businessobject.WorkingAgreement)

Example 2 with WorkingAgreement

use of com.autentia.tnt.businessobject.WorkingAgreement in project TNTConcept by autentia.

the class UserHolidaysStateManager method calculateUserHolidaysState.

public UserHolidaysState calculateUserHolidaysState(User usuario, Date year) {
    UserHolidaysState uhs = new UserHolidaysState();
    uhs.setUser(usuario);
    // WorkingAgreement attribute is an HB proxy not initialized, we need to get it
    // from DB
    WorkingAgreementDAO workingAgreementDao = WorkingAgreementDAO.getDefault();
    WorkingAgreement agreement = workingAgreementDao.loadById(usuario.getAgreement().getId());
    // and refresh the user instance agreement attribute
    usuario.setAgreement(agreement);
    uhs.setTotalYear(agreement.getHolidays());
    int acceptedHolidays = 0;
    if (year != null) {
        HolidayManager fiestasManager = HolidayManager.getDefault();
        // We must take in account previous year holidays and next year holidays
        Date firstDayOfYear = com.autentia.tnt.util.DateUtils.getFirstDayOfYear(year);
        Date lastDayOfYear = com.autentia.tnt.util.DateUtils.getLastDayOfYear(year);
        Calendar calendarFirstDayOfYear = Calendar.getInstance();
        calendarFirstDayOfYear.setTime(firstDayOfYear);
        calendarFirstDayOfYear.add(Calendar.YEAR, -1);
        Calendar calendarLastDayOfYear = Calendar.getInstance();
        calendarLastDayOfYear.setTime(lastDayOfYear);
        calendarLastDayOfYear.add(Calendar.YEAR, 1);
        HolidaySearch fiestaSearch = new HolidaySearch();
        fiestaSearch.setStartDate(calendarFirstDayOfYear.getTime());
        fiestaSearch.setEndDate(calendarLastDayOfYear.getTime());
        List<Holiday> allFiestas = fiestasManager.getAllEntities(fiestaSearch, null);
        firstDayOfYear = com.autentia.tnt.util.DateUtils.getFirstDayOfYear(year);
        calendarFirstDayOfYear.setTime(firstDayOfYear);
        lastDayOfYear = com.autentia.tnt.util.DateUtils.getLastDayOfYear(year);
        calendarLastDayOfYear.setTime(lastDayOfYear);
        RequestHolidayManager holyManager = RequestHolidayManager.getDefault();
        RequestHolidaySearch holSearch = new RequestHolidaySearch();
        holSearch.setUserRequest(uhs.getUser());
        holSearch.setState(HolidayState.ACCEPT);
        holSearch.setStartChargeYear(calendarFirstDayOfYear.getTime());
        holSearch.setEndChargeYear(calendarLastDayOfYear.getTime());
        List<RequestHoliday> listH = holyManager.getAllEntities(holSearch, null);
        for (RequestHoliday rH : listH) {
            Calendar cActual = Calendar.getInstance();
            cActual.setTime(rH.getBeginDate());
            while (!cActual.getTime().after(rH.getFinalDate())) {
                if (cActual.get(Calendar.DAY_OF_WEEK) != Calendar.SATURDAY && cActual.get(Calendar.DAY_OF_WEEK) != Calendar.SUNDAY) {
                    boolean isFiesta = false;
                    for (Holiday fiest : allFiestas) {
                        Calendar cFiesta = Calendar.getInstance();
                        cFiesta.setTime(fiest.getDate());
                        if (cFiesta.get(Calendar.YEAR) == cActual.get(Calendar.YEAR) && cFiesta.get(Calendar.MONTH) == cActual.get(Calendar.MONTH) && cFiesta.get(Calendar.DAY_OF_MONTH) == cActual.get(Calendar.DAY_OF_MONTH)) {
                            isFiesta = true;
                        }
                    }
                    if (!isFiesta) {
                        acceptedHolidays++;
                    }
                }
                cActual.add(Calendar.DAY_OF_MONTH, 1);
            }
        }
        uhs.setTotalAccepted(acceptedHolidays);
        Calendar calAuxCont = Calendar.getInstance();
        calAuxCont.setTime(uhs.getUser().getStartDate());
        Calendar calAux = Calendar.getInstance();
        calAux.setTime(year);
        int yearCharge = calAux.get(Calendar.YEAR);
        int yearContract = calAuxCont.get(Calendar.YEAR);
        if (yearCharge == yearContract) {
            // Dividimos los días de cada usuario entre los dias del año.
            double ratio = uhs.getUser().getAgreement().getHolidays() / 360.0;
            int dayContract = calAuxCont.get(Calendar.DAY_OF_YEAR);
            int workedDays = (360 - dayContract);
            double holidayDays = workedDays * ratio;
            double aux = Math.round(holidayDays);
            uhs.setTotalYear((int) aux);
        }
    }
    return uhs;
}
Also used : Calendar(java.util.Calendar) UserHolidaysState(com.autentia.tnt.businessobject.UserHolidaysState) Date(java.util.Date) WorkingAgreementDAO(com.autentia.tnt.dao.hibernate.WorkingAgreementDAO) RequestHoliday(com.autentia.tnt.businessobject.RequestHoliday) Holiday(com.autentia.tnt.businessobject.Holiday) RequestHoliday(com.autentia.tnt.businessobject.RequestHoliday) HolidaySearch(com.autentia.tnt.dao.search.HolidaySearch) RequestHolidaySearch(com.autentia.tnt.dao.search.RequestHolidaySearch) RequestHolidaySearch(com.autentia.tnt.dao.search.RequestHolidaySearch) WorkingAgreement(com.autentia.tnt.businessobject.WorkingAgreement)

Example 3 with WorkingAgreement

use of com.autentia.tnt.businessobject.WorkingAgreement in project TNTConcept by autentia.

the class DuplicateOfferTest method insertInitialData.

/**
 * Metodo encargado de insertar datos muy generales pero que son necesarios
 * para generar facturas en base a ofertas
 */
private void insertInitialData() {
    final OfferDAO offerDAO = (OfferDAO) SpringUtilsForTesting.getSpringBean("daoOffer");
    final ProjectDAO projectDAO = (ProjectDAO) SpringUtilsForTesting.getSpringBean("daoProject");
    final OrganizationDAO organizationDAO = (OrganizationDAO) SpringUtilsForTesting.getSpringBean("daoOrganization");
    final ContactDAO contactDAO = (ContactDAO) SpringUtilsForTesting.getSpringBean("daoContact");
    final UserDAO userDAO = (UserDAO) SpringUtilsForTesting.getSpringBean("daoUser");
    final RoleDAO roleDAO = (RoleDAO) SpringUtilsForTesting.getSpringBean("daoRole");
    final UserCategoryDAO categoryDAO = (UserCategoryDAO) SpringUtilsForTesting.getSpringBean("daoUserCategory");
    final DepartmentDAO departmentDAO = (DepartmentDAO) SpringUtilsForTesting.getSpringBean("daoDepartment");
    final WorkingAgreementDAO workingAgreementDAO = (WorkingAgreementDAO) SpringUtilsForTesting.getSpringBean("daoWorkingAgreement");
    final Role role = new Role();
    roleDAO.insert(role);
    final Department department = new Department();
    department.setName("departamento");
    departmentDAO.insert(department);
    final UserCategory category = new UserCategory();
    categoryDAO.insert(category);
    final WorkingAgreement workingAgreement = new WorkingAgreement();
    workingAgreementDAO.insert(workingAgreement);
    contact.setName("Sergio Hermida");
    contactDAO.insert(contact);
    projectDAO.insert(project);
    organizationDAO.insert(organization);
    user.setRole(role);
    user.setCategory(category);
    user.setDepartment(department);
    user.setAgreement(workingAgreement);
    userDAO.insert(user);
    offer.setNumber(OFFER_NUMBER);
    offer.setOrganization(organization);
    offer.setContact(contact);
    offer.setTitle(OFFER_TITLE);
    offer.setDescription(OFFER_DESCRIPTION);
    offer.setOfferPotential(OfferPotential.MEDIUM);
    offer.setOfferState(OfferState.OPEN);
    offer.setCreationDate(new Date());
    offer.setMaturityDate(new Date());
    offerDAO.insert(offer);
}
Also used : UserCategory(com.autentia.tnt.businessobject.UserCategory) DepartmentDAO(com.autentia.tnt.dao.hibernate.DepartmentDAO) Date(java.util.Date) WorkingAgreementDAO(com.autentia.tnt.dao.hibernate.WorkingAgreementDAO) Role(com.autentia.tnt.businessobject.Role) OfferRole(com.autentia.tnt.businessobject.OfferRole) Department(com.autentia.tnt.businessobject.Department) UserCategoryDAO(com.autentia.tnt.dao.hibernate.UserCategoryDAO) UserDAO(com.autentia.tnt.dao.hibernate.UserDAO) ContactDAO(com.autentia.tnt.dao.hibernate.ContactDAO) RoleDAO(com.autentia.tnt.dao.hibernate.RoleDAO) OfferDAO(com.autentia.tnt.dao.hibernate.OfferDAO) OrganizationDAO(com.autentia.tnt.dao.hibernate.OrganizationDAO) ProjectDAO(com.autentia.tnt.dao.hibernate.ProjectDAO) WorkingAgreement(com.autentia.tnt.businessobject.WorkingAgreement)

Example 4 with WorkingAgreement

use of com.autentia.tnt.businessobject.WorkingAgreement in project TNTConcept by autentia.

the class SpringUtilsForTesting method createAgreementInContext.

private static WorkingAgreement createAgreementInContext() {
    final WorkingAgreement agreement = new WorkingAgreement();
    final WorkingAgreementDAO workingAgreementDAO = (WorkingAgreementDAO) appCtx.getBean("daoWorkingAgreement");
    workingAgreementDAO.insert(agreement);
    return agreement;
}
Also used : WorkingAgreement(com.autentia.tnt.businessobject.WorkingAgreement) WorkingAgreementDAO(com.autentia.tnt.dao.hibernate.WorkingAgreementDAO)

Example 5 with WorkingAgreement

use of com.autentia.tnt.businessobject.WorkingAgreement in project TNTConcept by autentia.

the class SpringUtilsForTesting method createAgreementInContext.

private static WorkingAgreement createAgreementInContext() {
    final WorkingAgreement agreement = new WorkingAgreement();
    agreement.setName("Test Agreement");
    final WorkingAgreementDAO workingAgreementDAO = (WorkingAgreementDAO) appCtx.getBean("daoWorkingAgreement");
    workingAgreementDAO.insert(agreement);
    return agreement;
}
Also used : WorkingAgreement(com.autentia.tnt.businessobject.WorkingAgreement) WorkingAgreementDAO(com.autentia.tnt.dao.hibernate.WorkingAgreementDAO)

Aggregations

WorkingAgreement (com.autentia.tnt.businessobject.WorkingAgreement)5 WorkingAgreementDAO (com.autentia.tnt.dao.hibernate.WorkingAgreementDAO)4 Date (java.util.Date)2 Department (com.autentia.tnt.businessobject.Department)1 Holiday (com.autentia.tnt.businessobject.Holiday)1 OfferRole (com.autentia.tnt.businessobject.OfferRole)1 RequestHoliday (com.autentia.tnt.businessobject.RequestHoliday)1 Role (com.autentia.tnt.businessobject.Role)1 UserCategory (com.autentia.tnt.businessobject.UserCategory)1 UserHolidaysState (com.autentia.tnt.businessobject.UserHolidaysState)1 SortCriteria (com.autentia.tnt.dao.SortCriteria)1 ContactDAO (com.autentia.tnt.dao.hibernate.ContactDAO)1 DepartmentDAO (com.autentia.tnt.dao.hibernate.DepartmentDAO)1 OfferDAO (com.autentia.tnt.dao.hibernate.OfferDAO)1 OrganizationDAO (com.autentia.tnt.dao.hibernate.OrganizationDAO)1 ProjectDAO (com.autentia.tnt.dao.hibernate.ProjectDAO)1 RoleDAO (com.autentia.tnt.dao.hibernate.RoleDAO)1 UserCategoryDAO (com.autentia.tnt.dao.hibernate.UserCategoryDAO)1 UserDAO (com.autentia.tnt.dao.hibernate.UserDAO)1 HolidaySearch (com.autentia.tnt.dao.search.HolidaySearch)1