Search in sources :

Example 1 with Pedido

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

the class PedidoServiceImpl method buscarConCriteria.

@Override
public List<Pedido> buscarConCriteria(BusquedaPedidoCriteria criteria) {
    //Fecha
    if (criteria.isBuscaPorFecha() == true & (criteria.getFechaDesde() == null | criteria.getFechaHasta() == null)) {
        throw new BusinessServiceException(ResourceBundle.getBundle("Mensajes").getString("mensaje_pedido_fechas_busqueda_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());
    }
    //Empresa
    if (criteria.getEmpresa() == null) {
        throw new EntityNotFoundException(ResourceBundle.getBundle("Mensajes").getString("mensaje_empresa_no_existente"));
    }
    //Cliente
    if (criteria.isBuscaCliente() == true && criteria.getCliente() == null) {
        throw new BusinessServiceException(ResourceBundle.getBundle("Mensajes").getString("mensaje_cliente_vacio_razonSocial"));
    }
    //Usuario
    if (criteria.isBuscaUsuario() == true && criteria.getUsuario() == null) {
        throw new BusinessServiceException(ResourceBundle.getBundle("Mensajes").getString("mensaje_usuario_vacio_nombre"));
    }
    QPedido qpedido = QPedido.pedido;
    BooleanBuilder builder = new BooleanBuilder();
    builder.and(qpedido.empresa.eq(criteria.getEmpresa()).and(qpedido.eliminado.eq(false)));
    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(qpedido.fecha.between(fDesde, fHasta));
    }
    if (criteria.isBuscaCliente() == true) {
        builder.and(qpedido.cliente.eq(criteria.getCliente()));
    }
    if (criteria.isBuscaUsuario() == true) {
        builder.and(qpedido.usuario.eq(criteria.getUsuario()));
    }
    if (criteria.isBuscaPorNroPedido() == true) {
        builder.and(qpedido.nroPedido.eq(criteria.getNroPedido()));
    }
    List<Pedido> pedidos = new ArrayList<>();
    pedidoRepository.findAll(builder, new Sort(Sort.Direction.DESC, "fecha")).iterator().forEachRemaining(pedidos::add);
    return this.calcularTotalActualDePedidos(pedidos);
}
Also used : FormatterFechaHora(sic.util.FormatterFechaHora) Calendar(java.util.Calendar) GregorianCalendar(java.util.GregorianCalendar) RenglonPedido(sic.modelo.RenglonPedido) QPedido(sic.modelo.QPedido) Pedido(sic.modelo.Pedido) EstadoPedido(sic.modelo.EstadoPedido) GregorianCalendar(java.util.GregorianCalendar) ArrayList(java.util.ArrayList) EntityNotFoundException(javax.persistence.EntityNotFoundException) QPedido(sic.modelo.QPedido) Date(java.util.Date) BusinessServiceException(sic.service.BusinessServiceException) BooleanBuilder(com.querydsl.core.BooleanBuilder) Sort(org.springframework.data.domain.Sort)

Example 2 with Pedido

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

the class PedidoServiceImpl method eliminar.

@Override
@Transactional
public boolean eliminar(long idPedido) {
    Pedido pedido = this.getPedidoPorId(idPedido);
    if (pedido == null) {
        throw new EntityNotFoundException(ResourceBundle.getBundle("Mensajes").getString("mensaje_pedido_no_existente"));
    }
    if (pedido.getEstado() == EstadoPedido.ABIERTO) {
        pedido.setEliminado(true);
        pedidoRepository.save(pedido);
    }
    return pedido.isEliminado();
}
Also used : RenglonPedido(sic.modelo.RenglonPedido) QPedido(sic.modelo.QPedido) Pedido(sic.modelo.Pedido) EstadoPedido(sic.modelo.EstadoPedido) EntityNotFoundException(javax.persistence.EntityNotFoundException) Transactional(org.springframework.transaction.annotation.Transactional)

Example 3 with Pedido

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

the class PedidoBuilder method build.

public Pedido build() {
    if (renglones == null) {
        RenglonPedido renglon1 = new RenglonPedidoBuilder().build();
        RenglonPedido renglon2 = new RenglonPedidoBuilder().withCantidad(1).withIdRenglonPedido(90L).withProducto(new ProductoBuilder().withId_Producto(77L).withDescripcion("Pack 6 Vasos").withEmpresa(new EmpresaBuilder().build()).build()).build();
        List<RenglonPedido> renglonesPedido = new ArrayList<>();
        renglonesPedido.add(renglon1);
        renglonesPedido.add(renglon2);
        this.renglones = renglonesPedido;
    }
    return new Pedido(id_Pedido, nroPedido, fecha, fechaVencimiento, observaciones, empresa, eliminado, cliente, usuario, facturas, renglones, totalEstimado, totalActual, estado);
}
Also used : RenglonPedido(sic.modelo.RenglonPedido) RenglonPedido(sic.modelo.RenglonPedido) Pedido(sic.modelo.Pedido) EstadoPedido(sic.modelo.EstadoPedido) ArrayList(java.util.ArrayList)

Example 4 with Pedido

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

the class PedidosGUI method bnt_modificaPedidoActionPerformed.

//GEN-LAST:event_btn_imprimirPedidoActionPerformed
private void bnt_modificaPedidoActionPerformed(java.awt.event.ActionEvent evt) {
    //GEN-FIRST:event_bnt_modificaPedidoActionPerformed
    try {
        if (tbl_Pedidos.getSelectedRow() != -1) {
            long nroPedido = (long) tbl_Pedidos.getValueAt(tbl_Pedidos.getSelectedRow(), 2);
            Pedido pedido = Arrays.asList(RestClient.getRestTemplate().getForObject("/pedidos/busqueda/criteria?nroPedido=" + nroPedido + "&idEmpresa=" + EmpresaActiva.getInstance().getEmpresa().getId_Empresa(), Pedido[].class)).get(0);
            if (pedido.getEstado() == EstadoPedido.CERRADO) {
                JOptionPane.showInternalMessageDialog(this, ResourceBundle.getBundle("Mensajes").getString("mensaje_pedido_facturado"), "Error", JOptionPane.ERROR_MESSAGE);
            } else if (pedido.getEstado() == EstadoPedido.ACTIVO) {
                JOptionPane.showInternalMessageDialog(this, ResourceBundle.getBundle("Mensajes").getString("mensaje_pedido_procesado"), "Error", JOptionPane.ERROR_MESSAGE);
            } else if (this.existeClienteDisponible()) {
                PuntoDeVentaGUI gui_puntoDeVenta = new PuntoDeVentaGUI();
                gui_puntoDeVenta.setPedido(pedido);
                gui_puntoDeVenta.setModificarPedido(true);
                gui_puntoDeVenta.setModal(true);
                gui_puntoDeVenta.setLocationRelativeTo(this);
                gui_puntoDeVenta.setVisible(true);
                this.buscar();
            } else {
                String mensaje = ResourceBundle.getBundle("Mensajes").getString("mensaje_sin_cliente");
                JOptionPane.showInternalMessageDialog(this, mensaje, "Error", JOptionPane.ERROR_MESSAGE);
            }
        }
    } catch (RestClientResponseException ex) {
        JOptionPane.showMessageDialog(this, ex.getMessage(), "Error", JOptionPane.ERROR_MESSAGE);
    } catch (ResourceAccessException ex) {
        LOGGER.error(ex.getMessage());
        JOptionPane.showMessageDialog(this, ResourceBundle.getBundle("Mensajes").getString("mensaje_error_conexion"), "Error", JOptionPane.ERROR_MESSAGE);
    }
}
Also used : RenglonPedido(sic.modelo.RenglonPedido) Pedido(sic.modelo.Pedido) EstadoPedido(sic.modelo.EstadoPedido) RestClientResponseException(org.springframework.web.client.RestClientResponseException) ResourceAccessException(org.springframework.web.client.ResourceAccessException)

Example 5 with Pedido

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

the class PedidosGUI method btn_FacturarActionPerformed.

//GEN-LAST:event_btn_NuevoPedidoActionPerformed
private void btn_FacturarActionPerformed(java.awt.event.ActionEvent evt) {
    //GEN-FIRST:event_btn_FacturarActionPerformed
    try {
        if (tbl_Pedidos.getSelectedRow() != -1) {
            long nroPedido = (long) tbl_Pedidos.getValueAt(tbl_Pedidos.getSelectedRow(), 2);
            Pedido pedido = Arrays.asList(RestClient.getRestTemplate().getForObject("/pedidos/busqueda/criteria?nroPedido=" + nroPedido + "&idEmpresa=" + EmpresaActiva.getInstance().getEmpresa().getId_Empresa(), Pedido[].class)).get(0);
            if (pedido.getEstado() == EstadoPedido.CERRADO) {
                JOptionPane.showInternalMessageDialog(this, ResourceBundle.getBundle("Mensajes").getString("mensaje_pedido_facturado"), "Error", JOptionPane.ERROR_MESSAGE);
            } else if (this.existeClienteDisponible()) {
                PuntoDeVentaGUI gui_puntoDeVenta = new PuntoDeVentaGUI();
                gui_puntoDeVenta.setPedido(pedido);
                gui_puntoDeVenta.setModal(true);
                gui_puntoDeVenta.setLocationRelativeTo(this);
                gui_puntoDeVenta.setVisible(true);
                this.buscar();
            } else {
                String mensaje = ResourceBundle.getBundle("Mensajes").getString("mensaje_sin_cliente");
                JOptionPane.showInternalMessageDialog(this, mensaje, "Error", JOptionPane.ERROR_MESSAGE);
            }
        }
    } catch (RestClientResponseException ex) {
        JOptionPane.showMessageDialog(this, ex.getMessage(), "Error", JOptionPane.ERROR_MESSAGE);
    } catch (ResourceAccessException ex) {
        LOGGER.error(ex.getMessage());
        JOptionPane.showMessageDialog(this, ResourceBundle.getBundle("Mensajes").getString("mensaje_error_conexion"), "Error", JOptionPane.ERROR_MESSAGE);
    }
}
Also used : RenglonPedido(sic.modelo.RenglonPedido) Pedido(sic.modelo.Pedido) EstadoPedido(sic.modelo.EstadoPedido) RestClientResponseException(org.springframework.web.client.RestClientResponseException) ResourceAccessException(org.springframework.web.client.ResourceAccessException)

Aggregations

Pedido (sic.modelo.Pedido)14 EstadoPedido (sic.modelo.EstadoPedido)13 RenglonPedido (sic.modelo.RenglonPedido)13 ResourceAccessException (org.springframework.web.client.ResourceAccessException)9 RestClientResponseException (org.springframework.web.client.RestClientResponseException)9 ArrayList (java.util.ArrayList)8 RenglonFactura (sic.modelo.RenglonFactura)5 Date (java.util.Date)3 Cliente (sic.modelo.Cliente)3 Usuario (sic.modelo.Usuario)3 Point (java.awt.Point)2 List (java.util.List)2 ExecutionException (java.util.concurrent.ExecutionException)2 EntityNotFoundException (javax.persistence.EntityNotFoundException)2 SwingWorker (javax.swing.SwingWorker)2 Transactional (org.springframework.transaction.annotation.Transactional)2 Factura (sic.modelo.Factura)2 QPedido (sic.modelo.QPedido)2 BooleanBuilder (com.querydsl.core.BooleanBuilder)1 Desktop (java.awt.Desktop)1