Search in sources :

Example 1 with Caja

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

the class AbrirCajaGUI method construirCaja.

private Caja construirCaja(double monto) {
    Caja caja = new Caja();
    caja.setEstado(EstadoCaja.ABIERTA);
    caja.setObservacion("Apertura De Caja");
    caja.setEmpresa(EmpresaActiva.getInstance().getEmpresa());
    Calendar corte = Calendar.getInstance();
    corte.set(Calendar.HOUR_OF_DAY, (int) spinner_Hora.getValue());
    corte.set(Calendar.MINUTE, (int) spinner_Minutos.getValue());
    caja.setFechaCorteInforme(corte.getTime());
    caja.setSaldoInicial(monto);
    caja.setSaldoFinal(monto);
    caja.setSaldoReal(0);
    caja.setUsuarioAbreCaja(UsuarioActivo.getInstance().getUsuario());
    return caja;
}
Also used : Calendar(java.util.Calendar) Caja(sic.modelo.Caja) EstadoCaja(sic.modelo.EstadoCaja)

Example 2 with Caja

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

the class CajasGUI method cargarResultadosAlTable.

private void cargarResultadosAlTable() {
    double totalFinal = 0.0;
    double totalCierre = 0.0;
    for (Caja caja : cajas) {
        Object[] fila = new Object[8];
        fila[0] = caja.getEstado();
        fila[1] = caja.getFechaApertura();
        fila[2] = (new FormatterFechaHora(FormatterFechaHora.FORMATO_HORA_INTERNACIONAL)).format(caja.getFechaCorteInforme());
        if (caja.getFechaCierre() != null) {
            fila[3] = caja.getFechaCierre();
        }
        fila[4] = (caja.getUsuarioCierraCaja() != null ? caja.getUsuarioCierraCaja() : "");
        fila[5] = caja.getSaldoInicial();
        fila[6] = caja.getSaldoFinal();
        fila[7] = (caja.getEstado().equals(EstadoCaja.CERRADA) ? caja.getSaldoReal() : 0.0);
        totalFinal += caja.getSaldoFinal();
        totalCierre += caja.getSaldoReal();
        modeloTablaCajas.addRow(fila);
    }
    tbl_Cajas.setModel(modeloTablaCajas);
    tbl_Cajas.getColumnModel().getColumn(0).setCellRenderer(new ColoresEstadosRenderer());
    ftxt_TotalFinal.setValue(totalFinal);
    ftxt_TotalCierre.setValue(totalCierre);
    lbl_cantidadMostrar.setText(cajas.size() + " Cajas encontradas");
}
Also used : FormatterFechaHora(sic.util.FormatterFechaHora) ColoresEstadosRenderer(sic.util.ColoresEstadosRenderer) Caja(sic.modelo.Caja) EstadoCaja(sic.modelo.EstadoCaja)

Example 3 with Caja

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

the class CajasGUI method buscar.

private void buscar() {
    cambiarEstadoEnabled(false);
    pb_barra.setIndeterminate(true);
    SwingWorker<List<Caja>, Void> worker = new SwingWorker<List<Caja>, Void>() {

        @Override
        protected List<Caja> doInBackground() throws Exception {
            String criteria = "/cajas/busqueda/criteria?";
            if (chk_Fecha.isSelected()) {
                criteria += "desde=" + dc_FechaDesde.getDate().getTime() + "&hasta=" + dc_FechaHasta.getDate().getTime();
            }
            if (chk_Usuario.isSelected()) {
                criteria += "&idUsuario=" + ((Usuario) cmb_Usuarios.getSelectedItem()).getId_Usuario();
            }
            criteria += "&idEmpresa=" + EmpresaActiva.getInstance().getEmpresa().getId_Empresa();
            cajas = new ArrayList(Arrays.asList(RestClient.getRestTemplate().getForObject(criteria, Caja[].class)));
            cargarResultadosAlTable();
            cambiarEstadoEnabled(true);
            return cajas;
        }

        @Override
        protected void done() {
            pb_barra.setIndeterminate(false);
            try {
                if (get().isEmpty()) {
                    JOptionPane.showInternalMessageDialog(getParent(), ResourceBundle.getBundle("Mensajes").getString("mensaje_busqueda_sin_resultados"), "Aviso", JOptionPane.INFORMATION_MESSAGE);
                }
            } catch (InterruptedException ex) {
                String msjError = "La tarea que se estaba realizando fue interrumpida. Intente nuevamente.";
                LOGGER.error(msjError + " - " + ex.getMessage());
                JOptionPane.showInternalMessageDialog(getParent(), msjError, "Error", JOptionPane.ERROR_MESSAGE);
            } catch (ExecutionException ex) {
                if (ex.getCause() instanceof RestClientResponseException) {
                    JOptionPane.showMessageDialog(getParent(), ex.getMessage(), "Error", JOptionPane.ERROR_MESSAGE);
                } else if (ex.getCause() instanceof ResourceAccessException) {
                    LOGGER.error(ex.getMessage());
                    JOptionPane.showMessageDialog(getParent(), ResourceBundle.getBundle("Mensajes").getString("mensaje_error_conexion"), "Error", JOptionPane.ERROR_MESSAGE);
                } else {
                    String msjError = "Se produjo un error en la ejecución de la tarea solicitada. Intente nuevamente.";
                    LOGGER.error(msjError + " - " + ex.getMessage());
                    JOptionPane.showInternalMessageDialog(getParent(), msjError, "Error", JOptionPane.ERROR_MESSAGE);
                }
                cambiarEstadoEnabled(true);
            }
        }
    };
    worker.execute();
}
Also used : Usuario(sic.modelo.Usuario) ArrayList(java.util.ArrayList) SwingWorker(javax.swing.SwingWorker) Caja(sic.modelo.Caja) EstadoCaja(sic.modelo.EstadoCaja) ArrayList(java.util.ArrayList) List(java.util.List) RestClientResponseException(org.springframework.web.client.RestClientResponseException) ExecutionException(java.util.concurrent.ExecutionException) ResourceAccessException(org.springframework.web.client.ResourceAccessException)

Example 4 with Caja

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

the class CajaServiceImpl method getTotalMovimientosPorFormaDePago.

private double getTotalMovimientosPorFormaDePago(Caja caja, FormaDePago fdp) {
    double pagosVentasTotal = 0.0;
    double pagosComprasTotal = 0.0;
    double gastosTotal = 0.0;
    LocalDateTime ldt = caja.getFechaApertura().toInstant().atZone(ZoneId.systemDefault()).toLocalDateTime();
    if (caja.getFechaCierre() == null) {
        ldt = ldt.withHour(23);
        ldt = ldt.withMinute(59);
        ldt = ldt.withSecond(59);
    } else {
        ldt = caja.getFechaCierre().toInstant().atZone(ZoneId.systemDefault()).toLocalDateTime();
    }
    List<Pago> pagos = pagoService.getPagosEntreFechasYFormaDePago(caja.getEmpresa().getId_Empresa(), fdp.getId_FormaDePago(), caja.getFechaApertura(), Date.from(ldt.atZone(ZoneId.systemDefault()).toInstant()));
    List<Gasto> gastos = gastoService.getGastosEntreFechasYFormaDePago(caja.getEmpresa().getId_Empresa(), fdp.getId_FormaDePago(), caja.getFechaApertura(), Date.from(ldt.atZone(ZoneId.systemDefault()).toInstant()));
    for (Pago pago : pagos) {
        if (pago.getFactura() instanceof FacturaVenta) {
            pagosVentasTotal += pago.getMonto();
        } else if (pago.getFactura() instanceof FacturaCompra) {
            pagosComprasTotal += pago.getMonto();
        }
    }
    gastosTotal = gastos.stream().map((gasto) -> gasto.getMonto()).reduce(gastosTotal, (accumulator, _item) -> accumulator + _item);
    return pagosVentasTotal - pagosComprasTotal - gastosTotal;
}
Also used : LocalDateTime(java.time.LocalDateTime) Caja(sic.modelo.Caja) Pago(sic.modelo.Pago) FormaDePago(sic.modelo.FormaDePago) Date(java.util.Date) QCaja(sic.modelo.QCaja) CajaRepository(sic.repository.CajaRepository) LocalDateTime(java.time.LocalDateTime) Autowired(org.springframework.beans.factory.annotation.Autowired) BooleanBuilder(com.querydsl.core.BooleanBuilder) HashMap(java.util.HashMap) Scheduled(org.springframework.scheduling.annotation.Scheduled) Rol(sic.modelo.Rol) ArrayList(java.util.ArrayList) Logger(org.apache.log4j.Logger) ICajaService(sic.service.ICajaService) Calendar(java.util.Calendar) ResourceBundle(java.util.ResourceBundle) Service(org.springframework.stereotype.Service) Empresa(sic.modelo.Empresa) Map(java.util.Map) Gasto(sic.modelo.Gasto) IFormaDePagoService(sic.service.IFormaDePagoService) EntityNotFoundException(javax.persistence.EntityNotFoundException) Sort(org.springframework.data.domain.Sort) Validator(sic.util.Validator) GregorianCalendar(java.util.GregorianCalendar) FormatterFechaHora(sic.util.FormatterFechaHora) DateExpression(com.querydsl.core.types.dsl.DateExpression) FacturaVenta(sic.modelo.FacturaVenta) BusinessServiceException(sic.service.BusinessServiceException) EstadoCaja(sic.modelo.EstadoCaja) ZoneId(java.time.ZoneId) IUsuarioService(sic.service.IUsuarioService) IPagoService(sic.service.IPagoService) BusquedaCajaCriteria(sic.modelo.BusquedaCajaCriteria) List(java.util.List) IGastoService(sic.service.IGastoService) Expressions(com.querydsl.core.types.dsl.Expressions) LocalDate(java.time.LocalDate) FacturaCompra(sic.modelo.FacturaCompra) IEmpresaService(sic.service.IEmpresaService) Transactional(org.springframework.transaction.annotation.Transactional) FacturaVenta(sic.modelo.FacturaVenta) Gasto(sic.modelo.Gasto) Pago(sic.modelo.Pago) FormaDePago(sic.modelo.FormaDePago) FacturaCompra(sic.modelo.FacturaCompra)

Example 5 with Caja

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

the class CajaServiceImpl method cerrarCaja.

@Override
@Transactional
public Caja cerrarCaja(long idCaja, double monto, Long idUsuario, boolean scheduling) {
    Caja cajaACerrar = this.getCajaPorId(idCaja);
    cajaACerrar.setSaldoFinal(this.getTotalCaja(cajaACerrar, false));
    cajaACerrar.setSaldoReal(monto);
    if (scheduling) {
        LocalDateTime fechaCierre = LocalDateTime.ofInstant(cajaACerrar.getFechaApertura().toInstant(), ZoneId.systemDefault());
        fechaCierre = fechaCierre.withHour(23);
        fechaCierre = fechaCierre.withMinute(59);
        fechaCierre = fechaCierre.withSecond(59);
        cajaACerrar.setFechaCierre(Date.from(fechaCierre.atZone(ZoneId.systemDefault()).toInstant()));
    } else {
        cajaACerrar.setFechaCierre(new Date());
    }
    if (idUsuario != null) {
        cajaACerrar.setUsuarioCierraCaja(usuarioService.getUsuarioPorId(idUsuario));
    }
    cajaACerrar.setEstado(EstadoCaja.CERRADA);
    this.actualizar(cajaACerrar);
    LOGGER.warn("La Caja " + cajaACerrar + " se cerró correctamente.");
    return cajaACerrar;
}
Also used : LocalDateTime(java.time.LocalDateTime) Caja(sic.modelo.Caja) QCaja(sic.modelo.QCaja) EstadoCaja(sic.modelo.EstadoCaja) Date(java.util.Date) LocalDate(java.time.LocalDate) Transactional(org.springframework.transaction.annotation.Transactional)

Aggregations

Caja (sic.modelo.Caja)9 EstadoCaja (sic.modelo.EstadoCaja)9 QCaja (sic.modelo.QCaja)6 LocalDate (java.time.LocalDate)4 Calendar (java.util.Calendar)4 EntityNotFoundException (javax.persistence.EntityNotFoundException)4 ArrayList (java.util.ArrayList)3 Date (java.util.Date)3 GregorianCalendar (java.util.GregorianCalendar)3 Transactional (org.springframework.transaction.annotation.Transactional)3 FormatterFechaHora (sic.util.FormatterFechaHora)3 BooleanBuilder (com.querydsl.core.BooleanBuilder)2 LocalDateTime (java.time.LocalDateTime)2 List (java.util.List)2 Sort (org.springframework.data.domain.Sort)2 Scheduled (org.springframework.scheduling.annotation.Scheduled)2 Empresa (sic.modelo.Empresa)2 BusinessServiceException (sic.service.BusinessServiceException)2 DateExpression (com.querydsl.core.types.dsl.DateExpression)1 Expressions (com.querydsl.core.types.dsl.Expressions)1