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