Search in sources :

Example 1 with QCaja

use of sic.modelo.QCaja in project sic by belluccifranco.

the class CajaServiceImpl method getCajasCriteria.

@Override
public Page<Caja> getCajasCriteria(BusquedaCajaCriteria criteria) {
    // Empresa
    if (criteria.getEmpresa() == null) {
        throw new EntityNotFoundException(ResourceBundle.getBundle("Mensajes").getString("mensaje_empresa_no_existente"));
    }
    // Fecha
    if (criteria.isBuscaPorFecha() == true && (criteria.getFechaDesde() == null || criteria.getFechaHasta() == null)) {
        throw new BusinessServiceException(ResourceBundle.getBundle("Mensajes").getString("mensaje_caja_fechas_invalidas"));
    }
    if (criteria.isBuscaPorFecha() == true) {
        Calendar cal = new GregorianCalendar();
        cal.setTime(criteria.getFechaDesde());
        cal.set(Calendar.HOUR_OF_DAY, 0);
        cal.set(Calendar.MINUTE, 0);
        cal.set(Calendar.SECOND, 0);
        criteria.setFechaDesde(cal.getTime());
        cal.setTime(criteria.getFechaHasta());
        cal.set(Calendar.HOUR_OF_DAY, 23);
        cal.set(Calendar.MINUTE, 59);
        cal.set(Calendar.SECOND, 59);
        criteria.setFechaHasta(cal.getTime());
    }
    if (criteria.getEmpresa() == null) {
        throw new EntityNotFoundException(ResourceBundle.getBundle("Mensajes").getString("mensaje_empresa_no_existente"));
    }
    QCaja qcaja = QCaja.caja;
    BooleanBuilder builder = new BooleanBuilder();
    builder.and(qcaja.empresa.eq(criteria.getEmpresa()).and(qcaja.eliminada.eq(false)));
    if (criteria.isBuscaPorUsuario() == true) {
        builder.and(qcaja.usuarioCierraCaja.eq(criteria.getUsuario()));
    }
    if (criteria.isBuscaPorFecha() == true) {
        FormatterFechaHora formateadorFecha = new FormatterFechaHora(FormatterFechaHora.FORMATO_FECHAHORA_INTERNACIONAL);
        DateExpression<Date> fDesde = Expressions.dateTemplate(Date.class, "convert({0}, datetime)", formateadorFecha.format(criteria.getFechaDesde()));
        DateExpression<Date> fHasta = Expressions.dateTemplate(Date.class, "convert({0}, datetime)", formateadorFecha.format(criteria.getFechaHasta()));
        builder.and(qcaja.fechaApertura.between(fDesde, fHasta));
    }
    int pageNumber = 0;
    int pageSize = Integer.MAX_VALUE;
    Sort sorting = new Sort(Sort.Direction.DESC, "fechaApertura");
    if (criteria.getPageable() != null) {
        pageNumber = criteria.getPageable().getPageNumber();
        pageSize = criteria.getPageable().getPageSize();
        sorting = criteria.getPageable().getSort();
    }
    Pageable pageable = new PageRequest(pageNumber, pageSize, sorting);
    return cajaRepository.findAll(builder, pageable);
}
Also used : FormatterFechaHora(sic.util.FormatterFechaHora) Calendar(java.util.Calendar) GregorianCalendar(java.util.GregorianCalendar) GregorianCalendar(java.util.GregorianCalendar) EntityNotFoundException(javax.persistence.EntityNotFoundException) Date(java.util.Date) LocalDate(java.time.LocalDate) PageRequest(org.springframework.data.domain.PageRequest) BusinessServiceException(sic.service.BusinessServiceException) QCaja(sic.modelo.QCaja) Pageable(org.springframework.data.domain.Pageable) BooleanBuilder(com.querydsl.core.BooleanBuilder) Sort(org.springframework.data.domain.Sort)

Aggregations

BooleanBuilder (com.querydsl.core.BooleanBuilder)1 LocalDate (java.time.LocalDate)1 Calendar (java.util.Calendar)1 Date (java.util.Date)1 GregorianCalendar (java.util.GregorianCalendar)1 EntityNotFoundException (javax.persistence.EntityNotFoundException)1 PageRequest (org.springframework.data.domain.PageRequest)1 Pageable (org.springframework.data.domain.Pageable)1 Sort (org.springframework.data.domain.Sort)1 QCaja (sic.modelo.QCaja)1 BusinessServiceException (sic.service.BusinessServiceException)1 FormatterFechaHora (sic.util.FormatterFechaHora)1