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