/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package adgsyncms.service;

import adgsyncms.repository.Servers;
import adgsyncms.repository.db;
import static adgsyncms.repository.db._SQLQuery;
import static adgsyncms.repository.db._connection;
import static adgsyncms.repository.db.openConnection;

import static adgsyncms.repository.db_express._ex_SQLQuery;
import static adgsyncms.repository.db_express._ex_connection;
import static adgsyncms.repository.db_express.ex_openConnection;
import static adgsyncms.repository.db_express._ex_Host;
import static adgsyncms.repository.db_express._ex_Database;
import static adgsyncms.repository.db_express._ex_Port;
import static adgsyncms.repository.db_express._ex_User;
import static adgsyncms.repository.db_express._ex_Password;

import adgsyncms.repository.message;
import adgsyncms.repository.repository;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Iterator;
import javax.swing.JLabel;
import javax.swing.JTextArea;

/**
 *
 * @author amartinez
 */
public class Entidades extends db {

    protected String Cajas = "", Compania = "", tabla = "", Campos = "", Condicion = "", Cambios = "", Valores = "";

    protected boolean b_QueryResult = true;
    JTextArea jtext1;
    JLabel lblTransaccion;
    PreparedStatement ps_Condicion, ps_Cambios, ps_Valores;
    repository repo1;

    public void getServers() {
        repo1 = new repository();
        repo1.readSetting();
    }

    public boolean ActualizarCentrosCostos() {
        PreparedStatement ps_stmt, ps_ex;
        ResultSet rscentroscostos;

        tabla = "cntrecen";
        Campos = "cia_codigo,  numecen,  desccen,  encacen,  fcrecen,  estacen,  centro_logo, "
                + "centro_direccion,  centro_slogan,  centro_telefonos";
        getServers();
        if (openConnection()) {

            Iterator<Servers> servidores = repo1.lstservidores.iterator();
            while (servidores.hasNext()) {
                Servers servidor = servidores.next();
                this.SetSlaveConnection(servidor.host_name, servidor.database_name, servidor.port_number, servidor.user_name, servidor.user_pwd);
                getCajasLocales();
                try {

                    _SQLQuery = "select b.numecen, b.desccen, b.encacen, b.fcrecen, b.estacen, b.centro_logo,"
                            + "  b.centro_direccion, b.centro_slogan, b.centro_telefonos , c.caja_ip,a.cia_codigo , a.numcen ,a.borrado "
                            + "  from vtas.centros_cajas a inner join inv_cajas c on(a.caja_cod = c.caja_cod) "
                            + "  left join cntrecen b on (a.cia_codigo = b.cia_codigo and a.numcen = b.numecen)"
                            + "  where a.cia_codigo = ? and a.sincronizado is false and c.caja_cod in (" + Cajas + " )"
                            + "  order by a.borrado desc";
                    ps_stmt = _connection.prepareStatement(_SQLQuery);
                    ps_stmt.setString(1, repo1.Company);
                    rscentroscostos = ps_stmt.executeQuery();

                    while (rscentroscostos.next()) {
                        this.SetCaja(servidor.cajas, repo1.Company);
                        message.setCaption(lblTransaccion, "Caja: " + this.Cajas + " Actualizando centro de costo : " + rscentroscostos.getString("desccen"));

                        if (ex_openConnection()) {
                            if (rscentroscostos.getBoolean("borrado") == true) {
                                _ex_SQLQuery = "delete from cntrecen where cia_codigo = ?::varchar "
                                        + " and numecen = ?::varchar ";
                                ps_ex = _ex_connection.prepareStatement(_ex_SQLQuery);
                                ps_ex.setString(1, rscentroscostos.getString("cia_codigo"));
                                ps_ex.setString(2, rscentroscostos.getString("numcen"));
                                ps_ex.execute();
                            } else {
                                Condicion = "cia_codigo = ?::varchar and numecen = ?::varchar ";
                                ps_Condicion = _ex_connection.prepareStatement(Condicion);
                                ps_Condicion.setString(1, rscentroscostos.getString("cia_codigo"));
                                ps_Condicion.setString(2, rscentroscostos.getString("numecen"));

                                Cambios = "desccen = ?::varchar, encacen = ?::varchar, fcrecen = ?::date,"
                                        + "estacen = ?::varchar, centro_logo = ?::varchar,"
                                        + "centro_direccion = ?::varchar, centro_slogan = ?::varchar, centro_telefonos = ?::varchar";
                                ps_Cambios = _ex_connection.prepareStatement(Cambios);
                                ps_Cambios.setString(1, rscentroscostos.getString("desccen"));
                                ps_Cambios.setString(2, rscentroscostos.getString("encacen"));
                                ps_Cambios.setDate(3, rscentroscostos.getDate("fcrecen"));
                                ps_Cambios.setString(4, rscentroscostos.getString("estacen"));
                                ps_Cambios.setString(5, rscentroscostos.getString("centro_logo"));
                                ps_Cambios.setString(6, rscentroscostos.getString("centro_direccion"));
                                ps_Cambios.setString(7, rscentroscostos.getString("centro_slogan"));
                                ps_Cambios.setString(8, rscentroscostos.getString("centro_telefonos"));

                                Valores = "?::varchar, ?::varchar,"
                                        + "?::varchar, ?::varchar, ?::date,"
                                        + "?::varchar, ?::varchar,"
                                        + "?::varchar, ?::varchar, ?::varchar";
                                ps_Valores = _ex_connection.prepareStatement(Valores);
                                ps_Valores.setString(1, rscentroscostos.getString("cia_codigo"));
                                ps_Valores.setString(2, rscentroscostos.getString("numecen"));
                                ps_Valores.setString(3, rscentroscostos.getString("desccen"));
                                ps_Valores.setString(4, rscentroscostos.getString("encacen"));
                                ps_Valores.setDate(5, rscentroscostos.getDate("fcrecen"));
                                ps_Valores.setString(6, rscentroscostos.getString("estacen"));
                                ps_Valores.setString(7, rscentroscostos.getString("centro_logo"));
                                ps_Valores.setString(8, rscentroscostos.getString("centro_direccion"));
                                ps_Valores.setString(9, rscentroscostos.getString("centro_slogan"));
                                ps_Valores.setString(10, rscentroscostos.getString("centro_telefonos"));

                                _ex_SQLQuery = "SELECT * FROM public.fn_editar(?::varchar, ?::varchar, ?::varchar, ?::varchar, ?::varchar, ?::varchar, ?::varchar, ?::varchar, ?::varchar);";
                                ps_ex = _ex_connection.prepareStatement(_ex_SQLQuery);
                                ps_ex.setString(1, tabla);
                                ps_ex.setString(2, ps_Cambios.toString());
                                ps_ex.setString(3, "");
                                ps_ex.setString(4, "");
                                ps_ex.setString(5, ps_Condicion.toString());
                                ps_ex.setString(6, Campos);
                                ps_ex.setString(7, ps_Valores.toString());
                                ps_ex.setString(8, "");
                                ps_ex.setString(9, "");
                                ps_ex.executeQuery();

                            }
                            _SQLQuery = "update vtas.centros_cajas set sincronizado = true where cia_codigo = ?::varchar "
                                    + " and numcen = ?::varchar and caja_cod in(" + this.Cajas + ") ";
                            ps_stmt = _connection.prepareStatement(_SQLQuery);
                            ps_stmt.setString(1, rscentroscostos.getString("cia_codigo"));
                            ps_stmt.setString(2, rscentroscostos.getString("numcen"));
                            ps_stmt.execute();
                            _ex_connection.commit();
                            _connection.commit();
                            _ex_connection.close();
                        }
                    }

                } catch (SQLException ex) {
                    message.setMessage(jtext1, "Caja: " + this.Cajas + " Ocurrio el siguiente error al actualizar los centros de costos: " + ex.getMessage());
                    this.b_QueryResult = false;
                    CerrarConexiones();
                    return this.b_QueryResult;
                }
            }
        }
        CerrarConexiones();

        return this.b_QueryResult;
    }

    public boolean ActualizarSupervisores() {
        PreparedStatement ps_stmt, ps_ex;
        ResultSet rssupervisores;
        tabla = "inv_supervisores";
        Campos = " cia_codigo,  spv_codigo,  spv_nombre,  spv_clave,  spv_borraritem,  spv_modifact,  spv_anularfact,"
                + "  spv_descuento,  spv_cambprecio,  spv_porcientodesc,  spv_ventasinexistencia,  spv_borrarfactespera,"
                + "  spv_precio_bajominimo,  spv_precio_bajocosto,  spv_f1_puntoventa,  spv_cambiar_cantidad,"
                + "  spv_reimpfactura,  spv_regimen_especial, spv_autorizar_egresos,  spv_cancelar_factura,"
                + "  spv_dias_expiracion_pwd,spv_password_expira,spv_anular_voucher,spv_devolver_voucher";
        getServers();
        if (openConnection()) {

            Iterator<Servers> servidor = repo1.lstservidores.iterator();

            while (servidor.hasNext()) {
                Servers caja = servidor.next();
                this.SetSlaveConnection(caja.host_name, caja.database_name, caja.port_number, caja.user_name, caja.user_pwd);
                getCajasLocales();
                try {

                    _SQLQuery = "select b.spv_nombre,  b.spv_clave,  b.spv_borraritem,  b.spv_modifact,  b.spv_anularfact,"
                            + "  b.spv_descuento,  b.spv_cambprecio,  b.spv_porcientodesc,  b.spv_ventasinexistencia,  b.spv_borrarfactespera,"
                            + "  b.spv_precio_bajominimo,  b.spv_precio_bajocosto,  b.spv_f1_puntoventa,  b.spv_cambiar_cantidad,"
                            + "  b.spv_reimpfactura,  b.spv_regimen_especial,  b.spv_autorizar_egresos,"
                            + "  b.spv_cancelar_factura , b.spv_dias_expiracion_pwd,b.spv_password_expira,b.spv_anular_voucher,b.spv_devolver_voucher,"
                            + " c.caja_ip,a.cia_codigo , a.spv_codigo ,a.borrado "
                            + " from vtas.supervisores_cajas a inner join inv_cajas c on(a.caja_cod = c.caja_cod) "
                            + " left join inv_supervisores b on (a.cia_codigo = b.cia_codigo and a.spv_codigo = b.spv_codigo) "
                            + " where a.sincronizado is false and b.cia_codigo = ? and c.caja_cod  in (" + Cajas + ")"
                            + " order by a.borrado desc";
                    ps_stmt = _connection.prepareStatement(_SQLQuery);
                    ps_stmt.setString(1, repo1.Company);
                    rssupervisores = ps_stmt.executeQuery();

                    if (ex_openConnection()) {
                        while (rssupervisores.next()) {
                            this.SetCaja(caja.cajas, repo1.Company);

                            message.setCaption(lblTransaccion, "Caja: " + this.Cajas + " Actualizando supervisor : " + rssupervisores.getString("spv_codigo"));

                            if (rssupervisores.getBoolean("borrado") == true) {
                                _ex_SQLQuery = "delete from inv_supervisores where cia_codigo = ?::varchar "
                                        + " and spv_codigo = ?::varchar ";
                                ps_ex = _ex_connection.prepareStatement(_ex_SQLQuery);
                                ps_ex.setString(1, rssupervisores.getString("cia_codigo"));
                                ps_ex.setString(2, rssupervisores.getString("spv_codigo"));
                                ps_ex.execute();
                            } else {
                                Condicion = "cia_codigo = ?::varchar and spv_codigo = ?::varchar";
                                ps_Condicion = _ex_connection.prepareStatement(Condicion);
                                ps_Condicion.setString(1, rssupervisores.getString("cia_codigo"));
                                ps_Condicion.setString(2, rssupervisores.getString("spv_codigo"));

                                Cambios = "spv_nombre = ?::varchar,  spv_clave = ?::varchar,  spv_borraritem = ?::boolean,"
                                        + " spv_modifact = ?::boolean,  spv_anularfact = ?::boolean,  spv_descuento = ?::boolean,"
                                        + " spv_cambprecio = ?::boolean,  spv_porcientodesc = ?::numeric,  spv_ventasinexistencia = ?::boolean,"
                                        + " spv_borrarfactespera = ?::boolean,spv_precio_bajominimo = ?::boolean,  spv_precio_bajocosto = ?::boolean,"
                                        + " spv_f1_puntoventa  = ?::boolean,  spv_cambiar_cantidad  = ?::boolean,"
                                        + " spv_reimpfactura = ?::boolean,  spv_regimen_especial = ?::boolean, spv_autorizar_egresos = ?::boolean,"
                                        + " spv_cancelar_factura = ?::boolean,"
                                        + " spv_dias_expiracion_pwd = ? ,spv_password_expira = ?,spv_anular_voucher = ?,spv_devolver_voucher = ?";
                                ps_Cambios = _ex_connection.prepareStatement(Cambios);
                                ps_Cambios.setString(1, rssupervisores.getString("spv_nombre"));
                                ps_Cambios.setString(2, rssupervisores.getString("spv_clave"));
                                ps_Cambios.setBoolean(3, rssupervisores.getBoolean("spv_borraritem"));
                                ps_Cambios.setBoolean(4, rssupervisores.getBoolean("spv_modifact"));
                                ps_Cambios.setBoolean(5, rssupervisores.getBoolean("spv_anularfact"));
                                ps_Cambios.setBoolean(6, rssupervisores.getBoolean("spv_descuento"));
                                ps_Cambios.setBoolean(7, rssupervisores.getBoolean("spv_cambprecio"));
                                ps_Cambios.setDouble(8, rssupervisores.getDouble("spv_porcientodesc"));
                                ps_Cambios.setBoolean(9, rssupervisores.getBoolean("spv_ventasinexistencia"));
                                ps_Cambios.setBoolean(10, rssupervisores.getBoolean("spv_borrarfactespera"));
                                ps_Cambios.setBoolean(11, rssupervisores.getBoolean("spv_precio_bajominimo"));
                                ps_Cambios.setBoolean(12, rssupervisores.getBoolean("spv_precio_bajocosto"));
                                ps_Cambios.setBoolean(13, rssupervisores.getBoolean("spv_f1_puntoventa"));
                                ps_Cambios.setBoolean(14, rssupervisores.getBoolean("spv_cambiar_cantidad"));
                                ps_Cambios.setBoolean(15, rssupervisores.getBoolean("spv_reimpfactura"));
                                ps_Cambios.setBoolean(16, rssupervisores.getBoolean("spv_regimen_especial"));
                                ps_Cambios.setBoolean(17, rssupervisores.getBoolean("spv_autorizar_egresos"));
                                ps_Cambios.setBoolean(18, rssupervisores.getBoolean("spv_cancelar_factura"));
                                ps_Cambios.setInt(19, rssupervisores.getInt("spv_dias_expiracion_pwd"));
                                ps_Cambios.setInt(20, rssupervisores.getInt("spv_password_expira"));
                                ps_Cambios.setBoolean(21, rssupervisores.getBoolean("spv_anular_voucher"));
                                ps_Cambios.setBoolean(22, rssupervisores.getBoolean("spv_devolver_voucher"));

                                Valores = "?::varchar,  ?::varchar,"
                                        + "?::varchar,  ?::varchar, ?::boolean,"
                                        + " ?::boolean, ?::boolean, ?::boolean,"
                                        + " ?::boolean, ?::numeric, ?::boolean,"
                                        + " ?::boolean, ?::boolean, ?::boolean,"
                                        + " ?::boolean, ?::boolean,"
                                        + " ?::boolean, ?::boolean, ?::boolean,"
                                        + " ?::boolean, "
                                        + " ?, ?, ?, ?";
                                ps_Valores = _ex_connection.prepareStatement(Valores);
                                ps_Valores.setString(1, rssupervisores.getString("cia_codigo"));
                                ps_Valores.setString(2, rssupervisores.getString("spv_codigo"));
                                ps_Valores.setString(3, rssupervisores.getString("spv_nombre"));
                                ps_Valores.setString(4, rssupervisores.getString("spv_clave"));
                                ps_Valores.setBoolean(5, rssupervisores.getBoolean("spv_borraritem"));
                                ps_Valores.setBoolean(6, rssupervisores.getBoolean("spv_modifact"));
                                ps_Valores.setBoolean(7, rssupervisores.getBoolean("spv_anularfact"));
                                ps_Valores.setBoolean(8, rssupervisores.getBoolean("spv_descuento"));
                                ps_Valores.setBoolean(9, rssupervisores.getBoolean("spv_cambprecio"));
                                ps_Valores.setDouble(10, rssupervisores.getDouble("spv_porcientodesc"));
                                ps_Valores.setBoolean(11, rssupervisores.getBoolean("spv_ventasinexistencia"));
                                ps_Valores.setBoolean(12, rssupervisores.getBoolean("spv_borrarfactespera"));
                                ps_Valores.setBoolean(13, rssupervisores.getBoolean("spv_precio_bajominimo"));
                                ps_Valores.setBoolean(14, rssupervisores.getBoolean("spv_precio_bajocosto"));
                                ps_Valores.setBoolean(15, rssupervisores.getBoolean("spv_f1_puntoventa"));
                                ps_Valores.setBoolean(16, rssupervisores.getBoolean("spv_cambiar_cantidad"));
                                ps_Valores.setBoolean(17, rssupervisores.getBoolean("spv_reimpfactura"));
                                ps_Valores.setBoolean(18, rssupervisores.getBoolean("spv_regimen_especial"));
                                ps_Valores.setBoolean(19, rssupervisores.getBoolean("spv_autorizar_egresos"));
                                ps_Valores.setBoolean(20, rssupervisores.getBoolean("spv_cancelar_factura"));
                                ps_Valores.setInt(21, rssupervisores.getInt("spv_dias_expiracion_pwd"));
                                ps_Valores.setInt(22, rssupervisores.getInt("spv_password_expira"));
                                ps_Valores.setBoolean(23, rssupervisores.getBoolean("spv_anular_voucher"));
                                ps_Valores.setBoolean(24, rssupervisores.getBoolean("spv_devolver_voucher"));

                                _ex_SQLQuery = "SELECT * FROM public.fn_editar(?::varchar, ?::varchar, ?::varchar, ?::varchar, ?::varchar, ?::varchar, ?::varchar, ?::varchar, ?::varchar);";
                                ps_ex = _ex_connection.prepareStatement(_ex_SQLQuery);
                                ps_ex.setString(1, tabla);
                                ps_ex.setString(2, ps_Cambios.toString());
                                ps_ex.setString(3, "");
                                ps_ex.setString(4, "");
                                ps_ex.setString(5, ps_Condicion.toString());
                                ps_ex.setString(6, Campos);
                                ps_ex.setString(7, ps_Valores.toString());
                                ps_ex.setString(8, "");
                                ps_ex.setString(9, "");
                                ps_ex.executeQuery();
                            }

                            //Marcando la transaccion como sincronizada en la caja 
                            _SQLQuery = "update vtas.supervisores_cajas set sincronizado = true where cia_codigo = ?::varchar"
                                    + " and spv_codigo = ?::varchar and caja_cod in (" + this.Cajas + ")";
                            ps_stmt = _connection.prepareStatement(_SQLQuery);
                            ps_stmt.setString(1, rssupervisores.getString("cia_codigo"));
                            ps_stmt.setString(2, rssupervisores.getString("spv_codigo"));

                            ps_stmt.execute();

                        }
                        _ex_connection.commit();
                        _connection.commit();
                        _ex_connection.close();
                    }

                } catch (SQLException e) {
                    message.setMessage(jtext1, "Caja: " + this.Cajas + " Ocurrio el siguiente error al actualizar los supervisores: " + e.getMessage());
                    this.b_QueryResult = false;
                    try {
                        _connection.rollback();
                    } catch (SQLException ex) {
                        message.setMessage(jtext1, "Caja: " + this.Cajas + " Ocurrio el siguiente error al guardar los supervisores: " + ex.getMessage());
                        this.b_QueryResult = false;
                        CerrarConexiones();
                    }
                    return this.b_QueryResult;
                }
            }
        }

        CerrarConexiones();
        return this.b_QueryResult;
    }

    public boolean ActualizarCajeros() {
        PreparedStatement ps_stmt, ps_ex;
        ResultSet rsCajeros;

        tabla = "inv_cajeros";
        Campos = "cia_codigo,  caje_codigo,  caje_nombre,  caje_hora1,  caje_hora2,  caje_fondos,  caje_status,"
                + "caje_fecha,  sec_ventas,  sec_cuadre,  caje_maxpordesc,  caje_solclaveqprodpv,  caje_solclavedev,  caje_ponerfactespera,"
                + "caje_quitarfactespera,  caje_borrarfactespera,  caje_f1_puntoventa,  caje_cambiar_cantidad,  caje_abrir_cajon,  caje_reimpfactura,"
                + "caje_egreso_caja,caje_cambiar_precio,cajero_status";
        getServers();
        if (openConnection()) {

            Iterator<Servers> servidor = repo1.lstservidores.iterator();

            while (servidor.hasNext()) {
                Servers caja = servidor.next();
                this.SetSlaveConnection(caja.host_name, caja.database_name, caja.port_number, caja.user_name, caja.user_pwd);
                getCajasLocales();
                try {

                    _SQLQuery = "select  b.caje_nombre,  b.caje_hora1,  b.caje_hora2,  b.caje_fondos,  b.caje_status,"
                            + "b.caje_fecha,  b.sec_ventas,  b.sec_cuadre,  b.caje_maxpordesc,  b.caje_solclaveqprodpv,"
                            + "b.caje_solclavedev,  b.caje_ponerfactespera,  b.caje_quitarfactespera,  b.caje_borrarfactespera,"
                            + "b.caje_f1_puntoventa,  b.caje_cambiar_cantidad,  b.caje_abrir_cajon,  b.caje_reimpfactura,  b.caje_egreso_caja,"
                            + "b.caje_cambiar_precio,b.cajero_status,"
                            + "c.caja_ip,a.cia_codigo , a.caje_codigo ,a.borrado "
                            + "  from vtas.cajeros_cajas a inner join inv_cajas c on(a.caja_cod = c.caja_cod) "
                            + "  left join inv_cajeros b on (a.cia_codigo = b.cia_codigo and a.caje_codigo = b.caje_codigo)"
                            + "  where a.cia_codigo = ? and a.sincronizado is false and c.caja_cod in (" + Cajas + ")"
                            + "  order by a.borrado desc";
                    ps_stmt = _connection.prepareStatement(_SQLQuery);
                    ps_stmt.setString(1, repo1.Company);
                    rsCajeros = ps_stmt.executeQuery();

                    while (rsCajeros.next()) {
                        //this.SetCaja(caja.cajas, rsCajeros.getString("cia_codigo"));
                        message.setCaption(lblTransaccion, "Caja: " + this.Cajas + " Actualizando cajero : " + rsCajeros.getString("caje_nombre"));

                        if (ex_openConnection()) {
                            if (rsCajeros.getBoolean("borrado") == true) {
                                _ex_SQLQuery = "delete from inv_cajeros where cia_codigo = ?::varchar "
                                        + " and caje_codigo = ?::varchar ";
                                ps_ex = _ex_connection.prepareStatement(_ex_SQLQuery);
                                ps_ex.setString(1, rsCajeros.getString("cia_codigo"));
                                ps_ex.setString(2, rsCajeros.getString("caje_codigo"));
                                ps_ex.execute();
                            } else {
                                Condicion = "cia_codigo = ?::varchar and caje_codigo = ?::varchar ";
                                ps_Condicion = _ex_connection.prepareStatement(Condicion);
                                ps_Condicion.setString(1, rsCajeros.getString("cia_codigo"));
                                ps_Condicion.setString(2, rsCajeros.getString("caje_codigo"));

                                Cambios = "caje_nombre = ?::varchar,  caje_hora1 = ?::varchar, caje_hora2 = ?::varchar,"
                                        + "caje_fondos = ?::numeric,  caje_status = ?::varchar, caje_fecha = ?::date,  sec_ventas = ?::numeric,"
                                        + "sec_cuadre = ?::numeric,  caje_maxpordesc = ?::numeric,  caje_solclaveqprodpv = ?::smallint,  caje_solclavedev = ?::smallint,"
                                        + "caje_ponerfactespera = ?::boolean,  caje_quitarfactespera = ?::boolean,  caje_borrarfactespera = ?::boolean,  caje_f1_puntoventa = ?::boolean,"
                                        + "caje_cambiar_cantidad = ?::boolean,  caje_abrir_cajon = ?::boolean,  caje_reimpfactura = ?::boolean,  caje_egreso_caja = ?::boolean,"
                                        + "caje_cambiar_precio = ? ,cajero_status = ?";

                                ps_Cambios = _ex_connection.prepareStatement(Cambios);
                                ps_Cambios.setString(1, rsCajeros.getString("caje_nombre"));
                                ps_Cambios.setString(2, rsCajeros.getString("caje_hora1"));
                                ps_Cambios.setString(3, rsCajeros.getString("caje_hora2"));
                                ps_Cambios.setDouble(4, rsCajeros.getDouble("caje_fondos"));
                                ps_Cambios.setString(5, rsCajeros.getString("caje_status"));
                                ps_Cambios.setDate(6, rsCajeros.getDate("caje_fecha"));
                                ps_Cambios.setDouble(7, rsCajeros.getDouble("sec_ventas"));
                                ps_Cambios.setDouble(8, rsCajeros.getDouble("sec_cuadre"));
                                ps_Cambios.setDouble(9, rsCajeros.getDouble("caje_maxpordesc"));
                                ps_Cambios.setInt(10, rsCajeros.getInt("caje_solclaveqprodpv"));
                                ps_Cambios.setInt(11, rsCajeros.getInt("caje_solclavedev"));
                                ps_Cambios.setBoolean(12, rsCajeros.getBoolean("caje_ponerfactespera"));
                                ps_Cambios.setBoolean(13, rsCajeros.getBoolean("caje_quitarfactespera"));
                                ps_Cambios.setBoolean(14, rsCajeros.getBoolean("caje_borrarfactespera"));
                                ps_Cambios.setBoolean(15, rsCajeros.getBoolean("caje_f1_puntoventa"));
                                ps_Cambios.setBoolean(16, rsCajeros.getBoolean("caje_cambiar_cantidad"));
                                ps_Cambios.setBoolean(17, rsCajeros.getBoolean("caje_abrir_cajon"));
                                ps_Cambios.setBoolean(18, rsCajeros.getBoolean("caje_reimpfactura"));
                                ps_Cambios.setBoolean(19, rsCajeros.getBoolean("caje_egreso_caja"));
                                ps_Cambios.setBoolean(20, rsCajeros.getBoolean("caje_cambiar_precio"));
                                ps_Cambios.setString(21, rsCajeros.getString("cajero_status"));

                                Valores = "?::varchar,  ?::varchar,"
                                        + "?::varchar,  ?::varchar,  ?::varchar,"
                                        + "?::numeric,  ?::varchar,  ?::date,  ?::numeric,"
                                        + "?::numeric,  ?::numeric,  ?::smallint,  ?::smallint,"
                                        + "?::boolean,  ?::boolean,  ?::boolean,  ?::boolean,"
                                        + "?::boolean,  ?::boolean,  ?::boolean,  ?::boolean, ? , ?";
                                ps_Valores = _ex_connection.prepareStatement(Valores);
                                ps_Valores.setString(1, rsCajeros.getString("cia_codigo"));
                                ps_Valores.setString(2, rsCajeros.getString("caje_codigo"));
                                ps_Valores.setString(3, rsCajeros.getString("caje_nombre"));
                                ps_Valores.setString(4, rsCajeros.getString("caje_hora1"));
                                ps_Valores.setString(5, rsCajeros.getString("caje_hora2"));
                                ps_Valores.setDouble(6, rsCajeros.getDouble("caje_fondos"));
                                ps_Valores.setString(7, rsCajeros.getString("caje_status"));
                                ps_Valores.setDate(8, rsCajeros.getDate("caje_fecha"));
                                ps_Valores.setDouble(9, rsCajeros.getDouble("sec_ventas"));
                                ps_Valores.setDouble(10, rsCajeros.getDouble("sec_cuadre"));
                                ps_Valores.setDouble(11, rsCajeros.getDouble("caje_maxpordesc"));
                                ps_Valores.setInt(12, rsCajeros.getInt("caje_solclaveqprodpv"));
                                ps_Valores.setInt(13, rsCajeros.getInt("caje_solclavedev"));
                                ps_Valores.setBoolean(14, rsCajeros.getBoolean("caje_ponerfactespera"));
                                ps_Valores.setBoolean(15, rsCajeros.getBoolean("caje_quitarfactespera"));
                                ps_Valores.setBoolean(16, rsCajeros.getBoolean("caje_borrarfactespera"));
                                ps_Valores.setBoolean(17, rsCajeros.getBoolean("caje_f1_puntoventa"));
                                ps_Valores.setBoolean(18, rsCajeros.getBoolean("caje_cambiar_cantidad"));
                                ps_Valores.setBoolean(19, rsCajeros.getBoolean("caje_abrir_cajon"));
                                ps_Valores.setBoolean(20, rsCajeros.getBoolean("caje_reimpfactura"));
                                ps_Valores.setBoolean(21, rsCajeros.getBoolean("caje_egreso_caja"));
                                ps_Valores.setBoolean(22, rsCajeros.getBoolean("caje_cambiar_precio"));
                                ps_Valores.setString(23, rsCajeros.getString("cajero_status"));

                                _ex_SQLQuery = "SELECT * FROM public.fn_editar(?::varchar, ?::varchar, ?::varchar, ?::varchar, ?::varchar, ?::varchar, ?::varchar, ?::varchar, ?::varchar);";
                                ps_ex = _ex_connection.prepareStatement(_ex_SQLQuery);
                                ps_ex.setString(1, tabla);
                                ps_ex.setString(2, ps_Cambios.toString());
                                ps_ex.setString(3, "");
                                ps_ex.setString(4, "");
                                ps_ex.setString(5, ps_Condicion.toString());
                                ps_ex.setString(6, Campos);
                                ps_ex.setString(7, ps_Valores.toString());
                                ps_ex.setString(8, "");
                                ps_ex.setString(9, "");
                                ps_ex.executeQuery();

                            }
                            _SQLQuery = "update vtas.cajeros_cajas set sincronizado = true where cia_codigo = ?::varchar "
                                    + " and caje_codigo = ?::varchar and caja_cod in (" + Cajas + ")";
                            ps_stmt = _connection.prepareStatement(_SQLQuery);
                            ps_stmt.setString(1, rsCajeros.getString("cia_codigo"));
                            ps_stmt.setString(2, rsCajeros.getString("caje_codigo"));
                            ps_stmt.execute();
                            _ex_connection.commit();
                            _ex_connection.close();
                            _connection.commit();
                        }
                    }

                } catch (SQLException ex) {
                    message.setMessage(jtext1, "Caja: " + this.Cajas + " Ocurrio el siguiente error al actualizar los cajeros: " + ex.getMessage());
                    this.b_QueryResult = false;
                    CerrarConexiones();
                    return this.b_QueryResult;
                }
            }
        }
        CerrarConexiones();

        return this.b_QueryResult;
    }

    public boolean ActualizarCajas() {
        PreparedStatement ps_stmt, ps_ex;
        ResultSet rstmp, rsCajas;

        tabla = "inv_cajas";
        Campos = "cia_codigo,caja_cod, caja_nom, caja_fecha, caja_act, impresora, caja_setcajon, caja_imprimefcr, caja_imprimefco,"
                + "caja_formapago, caja_copiasfcr, caja_copiasfco, caja_confncf, caja_codusancf, caja_imprimencf, caja_tiponcfdefault, caja_confnotapie,"
                + "caja_codusanota, caja_confsecft, caja_codusasec, caja_confimpresion, caja_maxventaespera, caja_almacen, caja_tipoprinter, caja_fiscal,"
                + "inv_precioventaexpress, caja_clientecontado, numcen, caja_usadoslineas, caja_formatoimp, caja_usapartado, caja_colshojarollo, cuecue,"
                + "caja_cajon_conexion, caja_puertoserie, codigo, caja_importe_neto, caja_formato_tirilla, caja_puertofiscal, caja_balanzaelectronica,"
                + "caja_logofiscal, caja_porcientosi, caja_marcaimpresora,formato_factura_cr,formato_factura_co,"
                + "impresora_factura_cr,impresora_factura_co,caja_pos_conectado,caja_imprimir_voucher_pos,caja_formato_voucher,"
                + "caja_pos_conectado_azul,caja_copias_voucher,caja_pago_efectivo,caja_pago_tarjeta,caja_pago_cheque,caja_pago_bono,caja_pago_documentos,"
                + "caja_pos_conectado_visanet,caja_usardev_dev_bono";
        getServers();
        if (openConnection()) {

            Iterator<Servers> servidor = repo1.lstservidores.iterator();

            while (servidor.hasNext()) {
                Servers caja = servidor.next();
                this.SetSlaveConnection(caja.host_name, caja.database_name, caja.port_number, caja.user_name, caja.user_pwd);
                getCajasLocales();
                _SQLQuery = "select a.caja_cod , c.caja_ip from vtas.cajas_cajas a inner join inv_cajas c on(a.caja_cod = c.caja_cod) "
                        + " where a.sincronizado is false and c.caja_cod in (" + Cajas + ") group by a.caja_cod , c.caja_ip ";
                try {
                    ps_stmt = _connection.prepareStatement(_SQLQuery);
                    rstmp = ps_stmt.executeQuery();
                    while (rstmp.next()) {
                        _SQLQuery = "select b.caja_cod,b.caja_nom,b.caja_fecha,b.caja_act,b.impresora,b.caja_setcajon,b.caja_imprimefcr,"
                                + "b.caja_imprimefco,b.caja_formapago,b.caja_copiasfcr,b.caja_copiasfco,b.caja_confncf,"
                                + "b.caja_codusancf,b.caja_imprimencf,b.caja_tiponcfdefault,b.caja_confnotapie,b.caja_codusanota,"
                                + "b.caja_confsecft,b.caja_codusasec,b.caja_confimpresion,b.caja_maxventaespera,b.caja_almacen,"
                                + "b.caja_tipoprinter,b.caja_fiscal,b.inv_precioventaexpress,b.caja_clientecontado,b.numcen,"
                                + "b.caja_usadoslineas,b.caja_formatoimp,b.caja_usapartado,b.caja_colshojarollo,b.cuecue,"
                                + "b.caja_cajon_conexion,b.caja_puertoserie,b.codigo,b.caja_importe_neto,b.caja_formato_tirilla,"
                                + "b.caja_puertofiscal,b.caja_balanzaelectronica,b.caja_logofiscal,b.caja_porcientosi,"
                                + "b.caja_marcaimpresora,b.caja_ip,b.ip, "
                                + "b.caja_ip,b.cia_codigo , a.caja_cod, "
                                + "b.formato_factura_cr,b.formato_factura_co,"
                                + "b.impresora_factura_cr,b.impresora_factura_co,b.caja_pos_conectado,b.caja_imprimir_voucher_pos,b.caja_formato_voucher,"
                                + "b.caja_pos_conectado_azul,b.caja_copias_voucher,"
                                + "b.caja_pago_efectivo,b.caja_pago_tarjeta,b.caja_pago_cheque,b.caja_pago_bono,b.caja_pago_documentos,"
                                + "b.caja_pos_conectado_visanet,b.caja_usardev_dev_bono"
                                + " from vtas.cajas_cajas a inner join inv_cajas b on(a.codigo = b.codigo) "
                                + " where a.sincronizado is false and a.caja_cod = ?::varchar";
                        ps_stmt = _connection.prepareStatement(_SQLQuery);
                        ps_stmt.setString(1, rstmp.getString("caja_cod"));
                        rsCajas = ps_stmt.executeQuery();

                        //this.SetSlaveConnection(rstmp.getString("caja_ip"));
                        while (rsCajas.next()) {
                            this.SetCaja(rstmp.getString("caja_cod"), rsCajas.getString("cia_codigo"));
                            message.setCaption(lblTransaccion, "Caja: " + this.Cajas + " Actualizando caja : " + rsCajas.getString("caja_cod"));

                            if (ex_openConnection()) {

                                Condicion = " cia_codigo = ?::varchar and caja_cod = ?::varchar ";
                                ps_Condicion = _ex_connection.prepareStatement(Condicion);
                                ps_Condicion.setString(1, rsCajas.getString("cia_codigo"));
                                ps_Condicion.setString(2, rsCajas.getString("caja_cod"));

                                Cambios = "caja_nom = ?::varchar,  caja_fecha = ?::date,  caja_act = ?::varchar,  impresora= ?::varchar,"
                                        + "caja_setcajon = ?::smallint,  caja_imprimefcr =?::smallint,caja_imprimefco = ?::smallint, "
                                        + "caja_formapago = ?::smallint,  caja_copiasfcr = ?::smallint,  caja_copiasfco = ?::smallint,"
                                        + "caja_confncf = ?::smallint,  caja_codusancf = ?::varchar, caja_imprimencf = ?::smallint, "
                                        + "caja_tiponcfdefault = ?::smallint,  caja_confnotapie = ?::integer,  caja_codusanota = ?::varchar,"
                                        + "caja_confsecft = ?::smallint,caja_codusasec = ?::varchar,  caja_confimpresion = ?::smallint,"
                                        + "caja_maxventaespera = ?::numeric,  caja_almacen = ?::varchar,  caja_tipoprinter = ?::smallint,"
                                        + "caja_fiscal = ?::smallint,  inv_precioventaexpress = ?::varchar,  caja_clientecontado = ?::varchar,  numcen = ?::varchar,"
                                        + "caja_usadoslineas = ?::smallint,  caja_formatoimp = ?::varchar,caja_usapartado = ?::smallint,  caja_colshojarollo = ?::smallint,"
                                        + "cuecue = ?::varchar,  caja_cajon_conexion = ?::smallint,  caja_puertoserie = ?::smallint,"
                                        + "caja_importe_neto = ?::smallint,  caja_formato_tirilla= ?::smallint,  caja_puertofiscal= ?::smallint,  caja_balanzaelectronica= ?::smallint,"
                                        + "caja_logofiscal= ?::smallint,  caja_porcientosi= ?::smallint,  caja_marcaimpresora= ?::smallint,  caja_ip = ?::varchar,"
                                        + "formato_factura_cr = ?,formato_factura_co = ?,"
                                        + "impresora_factura_cr = ?,impresora_factura_co = ?,caja_pos_conectado = ?,caja_imprimir_voucher_pos = ?,"
                                        + "caja_formato_voucher = ?, caja_pos_conectado_azul = ?,"
                                        + "caja_copias_voucher = ?,"
                                        + "caja_pago_efectivo = ?,caja_pago_tarjeta = ?,caja_pago_cheque = ?,caja_pago_bono = ?,caja_pago_documentos = ?,"
                                        + "caja_pos_conectado_visanet = ?,caja_usardev_dev_bono = ?";

                                ps_Cambios = _ex_connection.prepareStatement(Cambios);
                                ps_Cambios.setString(1, rsCajas.getString("caja_nom"));
                                ps_Cambios.setDate(2, rsCajas.getDate("caja_fecha"));
                                ps_Cambios.setString(3, rsCajas.getString("caja_act"));
                                ps_Cambios.setString(4, rsCajas.getString("impresora"));
                                ps_Cambios.setInt(5, rsCajas.getInt("caja_setcajon"));
                                ps_Cambios.setInt(6, rsCajas.getInt("caja_imprimefcr"));
                                ps_Cambios.setInt(7, rsCajas.getInt("caja_imprimefco"));
                                ps_Cambios.setInt(8, rsCajas.getInt("caja_formapago"));
                                ps_Cambios.setInt(9, rsCajas.getInt("caja_copiasfcr"));
                                ps_Cambios.setInt(10, rsCajas.getInt("caja_copiasfco"));
                                ps_Cambios.setInt(11, rsCajas.getInt("caja_confncf"));
                                ps_Cambios.setString(12, rsCajas.getString("caja_codusancf"));
                                ps_Cambios.setInt(13, rsCajas.getInt("caja_imprimencf"));
                                ps_Cambios.setInt(14, rsCajas.getInt("caja_tiponcfdefault"));
                                ps_Cambios.setInt(15, rsCajas.getInt("caja_confnotapie"));
                                ps_Cambios.setString(16, rsCajas.getString("caja_codusanota"));
                                ps_Cambios.setInt(17, rsCajas.getInt("caja_confsecft"));
                                ps_Cambios.setString(18, rsCajas.getString("caja_codusasec"));
                                ps_Cambios.setInt(19, rsCajas.getInt("caja_confimpresion"));
                                ps_Cambios.setInt(20, rsCajas.getInt("caja_maxventaespera"));
                                ps_Cambios.setString(21, rsCajas.getString("caja_almacen"));
                                ps_Cambios.setInt(22, rsCajas.getInt("caja_tipoprinter"));
                                ps_Cambios.setInt(23, rsCajas.getInt("caja_fiscal"));
                                ps_Cambios.setString(24, rsCajas.getString("inv_precioventaexpress"));
                                ps_Cambios.setString(25, rsCajas.getString("caja_clientecontado"));
                                ps_Cambios.setString(26, rsCajas.getString("numcen"));
                                ps_Cambios.setInt(27, rsCajas.getInt("caja_usadoslineas"));
                                ps_Cambios.setString(28, rsCajas.getString("caja_formatoimp"));
                                ps_Cambios.setInt(29, rsCajas.getInt("caja_usapartado"));
                                ps_Cambios.setInt(30, rsCajas.getInt("caja_colshojarollo"));
                                ps_Cambios.setString(31, rsCajas.getString("cuecue"));
                                ps_Cambios.setInt(32, rsCajas.getInt("caja_cajon_conexion"));
                                ps_Cambios.setInt(33, rsCajas.getInt("caja_puertoserie"));
                                ps_Cambios.setInt(34, rsCajas.getInt("caja_importe_neto"));
                                ps_Cambios.setInt(35, rsCajas.getInt("caja_formato_tirilla"));
                                ps_Cambios.setInt(36, rsCajas.getInt("caja_puertofiscal"));
                                ps_Cambios.setInt(37, rsCajas.getInt("caja_balanzaelectronica"));
                                ps_Cambios.setInt(38, rsCajas.getInt("caja_logofiscal"));
                                ps_Cambios.setInt(39, rsCajas.getInt("caja_porcientosi"));
                                ps_Cambios.setInt(40, rsCajas.getInt("caja_marcaimpresora"));
                                ps_Cambios.setString(41, rsCajas.getString("caja_ip"));
                                ps_Cambios.setString(42, rsCajas.getString("formato_factura_cr"));
                                ps_Cambios.setString(43, rsCajas.getString("formato_factura_co"));
                                ps_Cambios.setString(44, rsCajas.getString("impresora_factura_cr"));
                                ps_Cambios.setString(45, rsCajas.getString("impresora_factura_co"));
                                ps_Cambios.setBoolean(46, rsCajas.getBoolean("caja_pos_conectado"));
                                ps_Cambios.setBoolean(47, rsCajas.getBoolean("caja_imprimir_voucher_pos"));
                                ps_Cambios.setString(48, rsCajas.getString("caja_formato_voucher"));
                                ps_Cambios.setBoolean(49, rsCajas.getBoolean("caja_pos_conectado_azul"));
                                ps_Cambios.setInt(50, rsCajas.getInt("caja_copias_voucher"));
                                ps_Cambios.setBoolean(51, rsCajas.getBoolean("caja_pago_efectivo"));
                                ps_Cambios.setBoolean(52, rsCajas.getBoolean("caja_pago_tarjeta"));
                                ps_Cambios.setBoolean(53, rsCajas.getBoolean("caja_pago_cheque"));
                                ps_Cambios.setBoolean(54, rsCajas.getBoolean("caja_pago_bono"));
                                ps_Cambios.setBoolean(55, rsCajas.getBoolean("caja_pago_documentos"));
                                ps_Cambios.setBoolean(56, rsCajas.getBoolean("caja_pos_conectado_visanet"));
                                ps_Cambios.setInt(57, rsCajas.getInt("caja_usardev_dev_bono"));

                                Valores = "?::VARCHAR,?::VARCHAR,?::VARCHAR,?::DATE,?::VARCHAR,"
                                        + "?::VARCHAR,?::SMALLINT,?::SMALLINT,?::SMALLINT,?::SMALLINT,"
                                        + "?::SMALLINT,?::SMALLINT,?::SMALLINT,?::VARCHAR,"
                                        + "?::SMALLINT,?::SMALLINT,?::SMALLINT,?::VARCHAR,"
                                        + "?::SMALLINT,?::VARCHAR,?::SMALLINT,?::NUMERIC,?::VARCHAR,"
                                        + "?::SMALLINT,?::SMALLINT,?::VARCHAR,?::VARCHAR,?::VARCHAR,"
                                        + "?::SMALLINT,?::VARCHAR,?::SMALLINT,?::SMALLINT,?::VARCHAR,"
                                        + "?::SMALLINT,?::SMALLINT,?::INTEGER,?::SMALLINT,?::SMALLINT,"
                                        + "?::SMALLINT,?::SMALLINT,?::SMALLINT,?::SMALLINT,?::INTEGER,"
                                        + "?::VARCHAR,?::VARCHAR,?::VARCHAR,?::VARCHAR,?::BOOLEAN,?::BOOLEAN,"
                                        + "?::VARCHAR,?::BOOLEAN,?::INTEGER,"
                                        + "?, ?, ?, ?, ?, ?, ? ";

                                ps_Valores = _ex_connection.prepareStatement(Valores);
                                ps_Valores.setString(1, rsCajas.getString("cia_codigo"));
                                ps_Valores.setString(2, rsCajas.getString("caja_cod"));
                                ps_Valores.setString(3, rsCajas.getString("caja_nom"));
                                ps_Valores.setDate(4, rsCajas.getDate("caja_fecha"));
                                ps_Valores.setString(5, rsCajas.getString("caja_act"));
                                ps_Valores.setString(6, rsCajas.getString("impresora"));
                                ps_Valores.setInt(7, rsCajas.getInt("caja_setcajon"));
                                ps_Valores.setInt(8, rsCajas.getInt("caja_imprimefcr"));
                                ps_Valores.setInt(9, rsCajas.getInt("caja_imprimefco"));
                                ps_Valores.setInt(10, rsCajas.getInt("caja_formapago"));
                                ps_Valores.setInt(11, rsCajas.getInt("caja_copiasfcr"));
                                ps_Valores.setInt(12, rsCajas.getInt("caja_copiasfco"));
                                ps_Valores.setInt(13, rsCajas.getInt("caja_confncf"));
                                ps_Valores.setString(14, rsCajas.getString("caja_codusancf"));
                                ps_Valores.setInt(15, rsCajas.getInt("caja_imprimencf"));
                                ps_Valores.setInt(16, rsCajas.getInt("caja_tiponcfdefault"));
                                ps_Valores.setInt(17, rsCajas.getInt("caja_confnotapie"));
                                ps_Valores.setString(18, rsCajas.getString("caja_codusanota"));
                                ps_Valores.setInt(19, rsCajas.getInt("caja_confsecft"));
                                ps_Valores.setString(20, rsCajas.getString("caja_codusasec"));
                                ps_Valores.setInt(21, rsCajas.getInt("caja_confimpresion"));
                                ps_Valores.setInt(22, rsCajas.getInt("caja_maxventaespera"));
                                ps_Valores.setString(23, rsCajas.getString("caja_almacen"));
                                ps_Valores.setInt(24, rsCajas.getInt("caja_tipoprinter"));
                                ps_Valores.setInt(25, rsCajas.getInt("caja_fiscal"));
                                ps_Valores.setString(26, rsCajas.getString("inv_precioventaexpress"));
                                ps_Valores.setString(27, rsCajas.getString("caja_clientecontado"));
                                ps_Valores.setString(28, rsCajas.getString("numcen"));
                                ps_Valores.setInt(29, rsCajas.getInt("caja_usadoslineas"));
                                ps_Valores.setString(30, rsCajas.getString("caja_formatoimp"));
                                ps_Valores.setInt(31, rsCajas.getInt("caja_usapartado"));
                                ps_Valores.setInt(32, rsCajas.getInt("caja_colshojarollo"));
                                ps_Valores.setString(33, rsCajas.getString("cuecue"));
                                ps_Valores.setInt(34, rsCajas.getInt("caja_cajon_conexion"));
                                ps_Valores.setInt(35, rsCajas.getInt("caja_puertoserie"));
                                ps_Valores.setInt(36, rsCajas.getInt("codigo"));
                                ps_Valores.setInt(37, rsCajas.getInt("caja_importe_neto"));
                                ps_Valores.setInt(38, rsCajas.getInt("caja_formato_tirilla"));
                                ps_Valores.setInt(39, rsCajas.getInt("caja_puertofiscal"));
                                ps_Valores.setInt(40, rsCajas.getInt("caja_balanzaelectronica"));
                                ps_Valores.setInt(41, rsCajas.getInt("caja_logofiscal"));
                                ps_Valores.setInt(42, rsCajas.getInt("caja_porcientosi"));
                                ps_Valores.setInt(43, rsCajas.getInt("caja_marcaimpresora"));
                                ps_Valores.setString(44, rsCajas.getString("formato_factura_cr"));
                                ps_Valores.setString(45, rsCajas.getString("formato_factura_co"));
                                ps_Valores.setString(46, rsCajas.getString("impresora_factura_cr"));
                                ps_Valores.setString(47, rsCajas.getString("impresora_factura_co"));
                                ps_Valores.setBoolean(48, rsCajas.getBoolean("caja_pos_conectado"));
                                ps_Valores.setBoolean(49, rsCajas.getBoolean("caja_imprimir_voucher_pos"));
                                ps_Valores.setString(50, rsCajas.getString("caja_formato_voucher"));
                                ps_Valores.setBoolean(51, rsCajas.getBoolean("caja_pos_conectado_azul"));
                                ps_Valores.setInt(52, rsCajas.getInt("caja_copias_voucher"));
                                ps_Valores.setBoolean(53, rsCajas.getBoolean("caja_pago_efectivo"));
                                ps_Valores.setBoolean(54, rsCajas.getBoolean("caja_pago_tarjeta"));
                                ps_Valores.setBoolean(55, rsCajas.getBoolean("caja_pago_cheque"));
                                ps_Valores.setBoolean(56, rsCajas.getBoolean("caja_pago_bono"));
                                ps_Valores.setBoolean(57, rsCajas.getBoolean("caja_pago_documentos"));
                                ps_Valores.setBoolean(58, rsCajas.getBoolean("caja_pos_conectado_visanet"));
                                ps_Valores.setInt(59, rsCajas.getInt("caja_usardev_dev_bono"));

                                _ex_SQLQuery = "SELECT * FROM public.fn_editar(?::varchar, ?::varchar, ?::varchar, ?::varchar, ?::varchar, ?::varchar, ?::varchar, ?::varchar, ?::varchar);";
                                ps_ex = _ex_connection.prepareStatement(_ex_SQLQuery);
                                ps_ex.setString(1, tabla);
                                ps_ex.setString(2, ps_Cambios.toString());
                                ps_ex.setString(3, "");
                                ps_ex.setString(4, "");
                                ps_ex.setString(5, ps_Condicion.toString());
                                ps_ex.setString(6, Campos);
                                ps_ex.setString(7, ps_Valores.toString());
                                ps_ex.setString(8, "");
                                ps_ex.setString(9, "");
                                ps_ex.executeQuery();

                                _SQLQuery = "update vtas.cajas_cajas set sincronizado = true where codigo = ?::integer "
                                        + " and caja_cod = ?::varchar ";
                                ps_stmt = _connection.prepareStatement(_SQLQuery);
                                ps_stmt.setInt(1, rsCajas.getInt("codigo"));
                                ps_stmt.setString(2, rstmp.getString("caja_cod"));
                                ps_stmt.execute();

                                _ex_connection.commit();
                                _connection.commit();
                                _ex_connection.close();
                            }
                        }

                    }
                } catch (SQLException ex) {
                    message.setMessage(jtext1, "Caja: " + this.Cajas + " Ocurrio el siguiente error al actualizar las cajas: " + ex.getMessage());
                    this.b_QueryResult = false;
                    CerrarConexiones();
                    return this.b_QueryResult;
                }
            }
        }
        CerrarConexiones();

        return this.b_QueryResult;
    }

    public boolean ActualizarSetGeneral() {
        PreparedStatement ps_stmt, ps_ex;
        ResultSet rssetgeneral;
        getServers();
        if (openConnection()) {

            Iterator<Servers> servidor = repo1.lstservidores.iterator();

            try {

                while (servidor.hasNext()) {
                    Servers caja = servidor.next();
                    this.SetSlaveConnection(caja.host_name, caja.database_name, caja.port_number, caja.user_name, caja.user_pwd);
                    getCajasLocales();

                    _SQLQuery = "select b.* , c.caja_ip,a.cia_codigo "
                            + "  from vtas.setgeneral_cajas a inner join inv_cajas c on(a.caja_cod = c.caja_cod) "
                            + "  left join inv_setgeneral b on (a.cia_codigo = b.cia_codigo)"
                            + "  where a.cia_codigo = ? and a.sincronizado is false and c.caja_cod in (" + Cajas + ")";
                    ps_stmt = _connection.prepareStatement(_SQLQuery);
                    ps_stmt.setString(1, repo1.Company);
                    rssetgeneral = ps_stmt.executeQuery();

                    while (rssetgeneral.next()) {
                        this.SetCaja(caja.cajas, rssetgeneral.getString("cia_codigo"));
                        message.setCaption(lblTransaccion, "Caja: " + this.Cajas + " Actualizando configuracion general : " + rssetgeneral.getString("cia_codigo"));

                        if (ex_openConnection()) {

                            _ex_SQLQuery = "update inv_setgeneral set "
                                    + "set_fecha= ?,set_pedido= ?,set_pagos= ?,"
                                    + "set_vencaj= ?,set_copias= ?,set_caja= ?,"
                                    + "set_vendef= ?,set_forimp= ?,set_pagina= ?,"
                                    + "set_slogan= ?,set_pregim= ?,set_tasa= ?,"
                                    + "set_mora= ?,ben1b= ?,ben1n= ?,"
                                    + "ben2b= ?,ben2n= ?,set_f1supl= ?,"
                                    + "set_dias= ?,printermay= ?,generalx= ?,"
                                    + "feccxp= ?::DATE,set_an= ?,set_ncf= ?,"
                                    + "set_modvtapag= ?,set_modcompag= ?,set_cxcgeneral= ?,"
                                    + "set_autbonotarpref= ?,set_activar_oferta= ?,set_margen_beneficio= ?,"
                                    + "cant_sindecimales= ?,set_estadopedidos= ?,set_secuenciatrans= ?,"
                                    + "autorizar_transferencias= ?,set_fondoexpress= ?,set_carruselpv= ?,"
                                    + "set_validavendpvexpress= ?,reservar_apartado= ?,set_fecha_devolucion= ?,"
                                    + "desc_fact_proddesc= ?,reservar_soltransf= ?,set_existencia= ?,"
                                    + "set_cosproditbis= ?,set_entrada_difrecepcion= ?,set_referencia_clientepref= ?,"
                                    + "set_desc_producto= ?,set_buscar_prodexpress= ?,set_buscar_prodexpresspor= ?,"
                                    + "set_estados_ordenescomp= ?,set_cambios_apartados= ?,set_tipori_ptoventa= ?,"
                                    + "set_abono_factcredito= ?,set_almexistencia_ini= ?,set_cambiarcostoprod= ?,"
                                    + "set_control_existencia= ?,set_imprimirnotaped_fact= ?,set_cxcdesc_prontopag= ?,"
                                    + "set_orden_artifact= ?,set_usarcodbarraprod= ?,set_autorizargiftcard= ?,"
                                    + "set_uso_teclaf9= ?,set_tipo_tarjetasolidaridad= ?,set_facturarsincliente= ?,"
                                    + "set_depositocierrecaja= ?,set_fechaservidor= ?,set_novistapreviafact= ?,"
                                    + "set_nolimpiarcantidad= ?,set_noautorizarfacturasant= ?,set_pedirclave_configuraciones= ?,"
                                    + "set_recargo_productos= ?,set_imprimenomciarollo= ?,set_novistapreviarecibos= ?,"
                                    + "set_notascredito_saldofavor= ?,set_recibosingresos_saldofavor= ?,set_asterisco_consultaprod= ?,"
                                    + "set_mostrar_ultprecios= ?,set_mostrar_ultfacturas= ?,set_asterisco_consultaclientes= ?,"
                                    + "set_agregar_detalle_consultaprod= ?,set_agregar_detalle_conenter= ?,set_foconuevocliente= ?,"
                                    + "set_usar_ncfcliente_pventa= ?,set_guardar_ultconsprod= ?,set_porc_aumento_fact_tarj= ?,"
                                    + "set_cliente_cedula_obligatoria= ?,set_cliente_cedula_unica= ?,set_seleccionar_producto= ?,"
                                    + "set_noactprecios_compras= ?,set_cantidad_fact_1= ?,set_mostrar_liquid_preciofact= ?,"
                                    + "set_valida_cant_char_ced_rnc= ?,set_valida_propietario= ?,set_valida_direcciones= ?,"
                                    + "set_valida_borrar_cliente= ?,set_esc_limpiar_fact= ?,set_liquidar_precios_compra= ?,"
                                    + "set_mostrar_ultcostosycompras= ?,set_cambiarunidad_compra= ?,set_fact_validarutadia= ?,"
                                    + "set_recibos_facturas_descuento= ?,set_imprimir_kit= ?,set_no_nota_recibosingresos= ?,"
                                    + "set_attachment_path= ?,set_sumaritems_ptoventa= ?,set_usar_unidades_puntoventa= ?,"
                                    + "set_validar_monto_compra= ?,set_precios_otras_unidades= ?,set_controlaperturaturnoscajero= ?,"
                                    + "set_nocambiar_costocif= ?,set_nocargar_fpago= ?,set_valida_fact_pendientes= ?,"
                                    + "buscar_rncced_dgii= ?,set_valida_grupo_cuentas= ?,set_tip_salida_conteo_fisico= ?,"
                                    + "set_tip_entrada_conteo_fisico= ?,set_noentregasin_numero= ?,set_solentrega_obligatoria= ?,"
                                    + "set_rutaimagen_clasificacion= ?,set_rutaimagen_productos= ?,set_no_usartecla_mas= ?,"
                                    + "set_borrar_prod_bonificacion= ?,set_dias_control_fecha_cuadre= ?,set_controlar_fecha_cuadre= ?,"
                                    + "set_depositos_consolidados= ?,set_cuenta_caja_deposito= ?,set_no_porciento_fact_sincnt= ?,"
                                    + "set_usar_und_conteofisico= ?,set_controlar_prod_kitcombo= ?,set_costo_formular_produccion= ?,"
                                    + "no_reimprimir_boletas= ?,set_pedir_vend_ptoventa= ?,set_solo_devol_completas= ?,"
                                    + "set_tipori_movil= ?,set_imagen_factnormal= ?,set_avisar_anticipos_pend= ?,"
                                    + "set_autorizar_bonos_dev= ?,set_usar_bonoempresarial= ?,set_prod_bonos_empresariales= ?,"
                                    + "set_clasificar_cuadres= ?,set_bloquear_consumidor_final= ?,set_abrircaj_credito= ?,"
                                    + "set_autoriza_regespecial= ?,set_pedir_nombre_fact_espera= ?,set_novistapreviadev= ?,"
                                    + "set_nofiltrar_fact_espera= ?,set_act_suplidor_producto= ?,set_desactivar_prodexistencia= ?,"
                                    + "set_modcosto_transalmacen= ?,set_valcantidad_fraccion= ?,set_retener_itbis_compras= ?,"
                                    + "set_recalcular_balance= ?,set_guardar_comprobante_recibo= ?,set_usa_fecharimobiles= ?,"
                                    + "vtas_hasta= ?,set_combusa_compania= ?,set_pedirmotivo_cancelventa= ?,"
                                    + "set_permitir_modpreciodev= ?,set_impcopiari= ?,set_elegir_und_ptoventa = ? "
                                    + " where cia_codigo = ? ";

                            ps_ex = _ex_connection.prepareStatement(_ex_SQLQuery);
                            ps_ex.setString(1, rssetgeneral.getString("set_fecha"));
                            ps_ex.setString(2, rssetgeneral.getString("set_pedido"));
                            ps_ex.setDouble(3, rssetgeneral.getDouble("set_pagos"));
                            ps_ex.setString(4, rssetgeneral.getString("set_vencaj"));
                            ps_ex.setDouble(5, rssetgeneral.getDouble("set_copias"));
                            ps_ex.setString(6, rssetgeneral.getString("set_caja"));
                            ps_ex.setDouble(7, rssetgeneral.getDouble("set_vendef"));
                            ps_ex.setDouble(8, rssetgeneral.getDouble("set_forimp"));
                            ps_ex.setDouble(9, rssetgeneral.getDouble("set_pagina"));
                            ps_ex.setString(10, rssetgeneral.getString("set_slogan"));
                            ps_ex.setString(11, rssetgeneral.getString("set_pregim"));
                            ps_ex.setDouble(12, rssetgeneral.getDouble("set_tasa"));
                            ps_ex.setDouble(13, rssetgeneral.getDouble("set_mora"));
                            ps_ex.setDouble(14, rssetgeneral.getDouble("ben1b"));
                            ps_ex.setDouble(15, rssetgeneral.getDouble("ben1n"));
                            ps_ex.setDouble(16, rssetgeneral.getDouble("ben2b"));
                            ps_ex.setDouble(17, rssetgeneral.getDouble("ben2n"));
                            ps_ex.setInt(18, rssetgeneral.getInt("set_f1supl"));
                            ps_ex.setInt(19, rssetgeneral.getInt("set_dias"));
                            ps_ex.setInt(20, rssetgeneral.getInt("printermay"));
                            ps_ex.setString(21, rssetgeneral.getString("generalx"));
                            ps_ex.setDate(22, rssetgeneral.getDate("feccxp"));
                            ps_ex.setDouble(23, rssetgeneral.getDouble("set_an"));
                            ps_ex.setInt(24, rssetgeneral.getInt("set_ncf"));
                            ps_ex.setInt(25, rssetgeneral.getInt("set_modvtapag"));
                            ps_ex.setInt(26, rssetgeneral.getInt("set_modcompag"));
                            ps_ex.setInt(27, rssetgeneral.getInt("set_cxcgeneral"));
                            ps_ex.setBoolean(28, rssetgeneral.getBoolean("set_autbonotarpref"));
                            ps_ex.setBoolean(29, rssetgeneral.getBoolean("set_activar_oferta"));
                            ps_ex.setInt(30, rssetgeneral.getInt("set_margen_beneficio"));
                            ps_ex.setString(31, rssetgeneral.getString("cant_sindecimales"));
                            ps_ex.setBoolean(32, rssetgeneral.getBoolean("set_estadopedidos"));
                            ps_ex.setInt(33, rssetgeneral.getInt("set_secuenciatrans"));
                            ps_ex.setBoolean(34, rssetgeneral.getBoolean("autorizar_transferencias"));
                            ps_ex.setString(35, rssetgeneral.getString("set_fondoexpress"));
                            ps_ex.setString(36, rssetgeneral.getString("set_carruselpv"));
                            ps_ex.setInt(37, rssetgeneral.getInt("set_validavendpvexpress"));
                            ps_ex.setBoolean(38, rssetgeneral.getBoolean("reservar_apartado"));
                            ps_ex.setInt(39, rssetgeneral.getInt("set_fecha_devolucion"));
                            ps_ex.setBoolean(40, rssetgeneral.getBoolean("desc_fact_proddesc"));
                            ps_ex.setBoolean(41, rssetgeneral.getBoolean("reservar_soltransf"));
                            ps_ex.setInt(42, rssetgeneral.getInt("set_existencia"));
                            ps_ex.setInt(43, rssetgeneral.getInt("set_cosproditbis"));
                            ps_ex.setString(44, rssetgeneral.getString("set_entrada_difrecepcion"));
                            ps_ex.setBoolean(45, rssetgeneral.getBoolean("set_referencia_clientepref"));
                            ps_ex.setBoolean(46, rssetgeneral.getBoolean("set_desc_producto"));
                            ps_ex.setInt(47, rssetgeneral.getInt("set_buscar_prodexpress"));
                            ps_ex.setInt(48, rssetgeneral.getInt("set_buscar_prodexpresspor"));
                            ps_ex.setBoolean(49, rssetgeneral.getBoolean("set_estados_ordenescomp"));
                            ps_ex.setBoolean(50, rssetgeneral.getBoolean("set_cambios_apartados"));
                            ps_ex.setString(51, rssetgeneral.getString("set_tipori_ptoventa"));
                            ps_ex.setBoolean(52, rssetgeneral.getBoolean("set_abono_factcredito"));
                            ps_ex.setString(53, rssetgeneral.getString("set_almexistencia_ini"));
                            ps_ex.setBoolean(54, rssetgeneral.getBoolean("set_cambiarcostoprod"));
                            ps_ex.setInt(55, rssetgeneral.getInt("set_control_existencia"));
                            ps_ex.setBoolean(56, rssetgeneral.getBoolean("set_imprimirnotaped_fact"));
                            ps_ex.setBoolean(57, rssetgeneral.getBoolean("set_cxcdesc_prontopag"));
                            ps_ex.setInt(58, rssetgeneral.getInt("set_orden_artifact"));
                            ps_ex.setBoolean(59, rssetgeneral.getBoolean("set_usarcodbarraprod"));
                            ps_ex.setBoolean(60, rssetgeneral.getBoolean("set_autorizargiftcard"));
                            ps_ex.setInt(61, rssetgeneral.getInt("set_uso_teclaf9"));
                            ps_ex.setInt(62, rssetgeneral.getInt("set_tipo_tarjetasolidaridad"));
                            ps_ex.setBoolean(63, rssetgeneral.getBoolean("set_facturarsincliente"));
                            ps_ex.setBoolean(64, rssetgeneral.getBoolean("set_depositocierrecaja"));
                            ps_ex.setBoolean(65, rssetgeneral.getBoolean("set_fechaservidor"));
                            ps_ex.setBoolean(66, rssetgeneral.getBoolean("set_novistapreviafact"));
                            ps_ex.setBoolean(67, rssetgeneral.getBoolean("set_nolimpiarcantidad"));
                            ps_ex.setBoolean(68, rssetgeneral.getBoolean("set_noautorizarfacturasant"));
                            ps_ex.setBoolean(69, rssetgeneral.getBoolean("set_pedirclave_configuraciones"));
                            ps_ex.setBoolean(70, rssetgeneral.getBoolean("set_recargo_productos"));
                            ps_ex.setBoolean(71, rssetgeneral.getBoolean("set_imprimenomciarollo"));
                            ps_ex.setBoolean(72, rssetgeneral.getBoolean("set_novistapreviarecibos"));
                            ps_ex.setBoolean(73, rssetgeneral.getBoolean("set_notascredito_saldofavor"));
                            ps_ex.setBoolean(74, rssetgeneral.getBoolean("set_recibosingresos_saldofavor"));
                            ps_ex.setBoolean(75, rssetgeneral.getBoolean("set_asterisco_consultaprod"));
                            ps_ex.setBoolean(76, rssetgeneral.getBoolean("set_mostrar_ultprecios"));
                            ps_ex.setBoolean(77, rssetgeneral.getBoolean("set_mostrar_ultfacturas"));
                            ps_ex.setBoolean(78, rssetgeneral.getBoolean("set_asterisco_consultaclientes"));
                            ps_ex.setBoolean(79, rssetgeneral.getBoolean("set_agregar_detalle_consultaprod"));
                            ps_ex.setBoolean(80, rssetgeneral.getBoolean("set_agregar_detalle_conenter"));
                            ps_ex.setInt(81, rssetgeneral.getInt("set_foconuevocliente"));
                            ps_ex.setBoolean(82, rssetgeneral.getBoolean("set_usar_ncfcliente_pventa"));
                            ps_ex.setBoolean(83, rssetgeneral.getBoolean("set_guardar_ultconsprod"));
                            ps_ex.setDouble(84, rssetgeneral.getDouble("set_porc_aumento_fact_tarj"));
                            ps_ex.setBoolean(85, rssetgeneral.getBoolean("set_cliente_cedula_obligatoria"));
                            ps_ex.setBoolean(86, rssetgeneral.getBoolean("set_cliente_cedula_unica"));
                            ps_ex.setBoolean(87, rssetgeneral.getBoolean("set_seleccionar_producto"));
                            ps_ex.setBoolean(88, rssetgeneral.getBoolean("set_noactprecios_compras"));
                            ps_ex.setBoolean(89, rssetgeneral.getBoolean("set_cantidad_fact_1"));
                            ps_ex.setBoolean(90, rssetgeneral.getBoolean("set_mostrar_liquid_preciofact"));
                            ps_ex.setBoolean(91, rssetgeneral.getBoolean("set_valida_cant_char_ced_rnc"));
                            ps_ex.setBoolean(92, rssetgeneral.getBoolean("set_valida_propietario"));
                            ps_ex.setBoolean(93, rssetgeneral.getBoolean("set_valida_direcciones"));
                            ps_ex.setBoolean(94, rssetgeneral.getBoolean("set_valida_borrar_cliente"));
                            ps_ex.setBoolean(95, rssetgeneral.getBoolean("set_esc_limpiar_fact"));
                            ps_ex.setBoolean(96, rssetgeneral.getBoolean("set_liquidar_precios_compra"));
                            ps_ex.setBoolean(97, rssetgeneral.getBoolean("set_mostrar_ultcostosycompras"));
                            ps_ex.setBoolean(98, rssetgeneral.getBoolean("set_cambiarunidad_compra"));
                            ps_ex.setBoolean(99, rssetgeneral.getBoolean("set_fact_validarutadia"));
                            ps_ex.setBoolean(100, rssetgeneral.getBoolean("set_recibos_facturas_descuento"));
                            ps_ex.setBoolean(101, rssetgeneral.getBoolean("set_imprimir_kit"));
                            ps_ex.setBoolean(102, rssetgeneral.getBoolean("set_no_nota_recibosingresos"));
                            ps_ex.setString(103, rssetgeneral.getString("set_attachment_path"));
                            ps_ex.setBoolean(104, rssetgeneral.getBoolean("set_sumaritems_ptoventa"));
                            ps_ex.setBoolean(105, rssetgeneral.getBoolean("set_usar_unidades_puntoventa"));
                            ps_ex.setBoolean(106, rssetgeneral.getBoolean("set_validar_monto_compra"));
                            ps_ex.setBoolean(107, rssetgeneral.getBoolean("set_precios_otras_unidades"));
                            ps_ex.setBoolean(108, rssetgeneral.getBoolean("set_controlaperturaturnoscajero"));
                            ps_ex.setBoolean(109, rssetgeneral.getBoolean("set_nocambiar_costocif"));
                            ps_ex.setBoolean(110, rssetgeneral.getBoolean("set_nocargar_fpago"));
                            ps_ex.setBoolean(111, rssetgeneral.getBoolean("set_valida_fact_pendientes"));
                            ps_ex.setBoolean(112, rssetgeneral.getBoolean("buscar_rncced_dgii"));
                            ps_ex.setBoolean(113, rssetgeneral.getBoolean("set_valida_grupo_cuentas"));
                            ps_ex.setString(114, rssetgeneral.getString("set_tip_salida_conteo_fisico"));
                            ps_ex.setString(115, rssetgeneral.getString("set_tip_entrada_conteo_fisico"));
                            ps_ex.setBoolean(116, rssetgeneral.getBoolean("set_noentregasin_numero"));
                            ps_ex.setBoolean(117, rssetgeneral.getBoolean("set_solentrega_obligatoria"));
                            ps_ex.setString(118, rssetgeneral.getString("set_rutaimagen_clasificacion"));
                            ps_ex.setString(119, rssetgeneral.getString("set_rutaimagen_productos"));
                            ps_ex.setBoolean(120, rssetgeneral.getBoolean("set_no_usartecla_mas"));
                            ps_ex.setBoolean(121, rssetgeneral.getBoolean("set_borrar_prod_bonificacion"));
                            ps_ex.setInt(122, rssetgeneral.getInt("set_dias_control_fecha_cuadre"));
                            ps_ex.setBoolean(123, rssetgeneral.getBoolean("set_controlar_fecha_cuadre"));
                            ps_ex.setBoolean(124, rssetgeneral.getBoolean("set_depositos_consolidados"));
                            ps_ex.setString(125, rssetgeneral.getString("set_cuenta_caja_deposito"));
                            ps_ex.setBoolean(126, rssetgeneral.getBoolean("set_no_porciento_fact_sincnt"));
                            ps_ex.setBoolean(127, rssetgeneral.getBoolean("set_usar_und_conteofisico"));
                            ps_ex.setBoolean(128, rssetgeneral.getBoolean("set_controlar_prod_kitcombo"));
                            ps_ex.setInt(129, rssetgeneral.getInt("set_costo_formular_produccion"));
                            ps_ex.setBoolean(130, rssetgeneral.getBoolean("no_reimprimir_boletas"));
                            ps_ex.setBoolean(131, rssetgeneral.getBoolean("set_pedir_vend_ptoventa"));
                            ps_ex.setBoolean(132, rssetgeneral.getBoolean("set_solo_devol_completas"));
                            ps_ex.setString(133, rssetgeneral.getString("set_tipori_movil"));
                            ps_ex.setBoolean(134, rssetgeneral.getBoolean("set_imagen_factnormal"));
                            ps_ex.setBoolean(135, rssetgeneral.getBoolean("set_avisar_anticipos_pend"));
                            ps_ex.setBoolean(136, rssetgeneral.getBoolean("set_autorizar_bonos_dev"));
                            ps_ex.setBoolean(137, rssetgeneral.getBoolean("set_usar_bonoempresarial"));
                            ps_ex.setString(138, rssetgeneral.getString("set_prod_bonos_empresariales"));
                            ps_ex.setBoolean(139, rssetgeneral.getBoolean("set_clasificar_cuadres"));
                            ps_ex.setBoolean(140, rssetgeneral.getBoolean("set_bloquear_consumidor_final"));
                            ps_ex.setBoolean(141, rssetgeneral.getBoolean("set_abrircaj_credito"));
                            ps_ex.setBoolean(142, rssetgeneral.getBoolean("set_autoriza_regespecial"));
                            ps_ex.setBoolean(143, rssetgeneral.getBoolean("set_pedir_nombre_fact_espera"));
                            ps_ex.setBoolean(144, rssetgeneral.getBoolean("set_novistapreviadev"));
                            ps_ex.setBoolean(145, rssetgeneral.getBoolean("set_nofiltrar_fact_espera"));
                            ps_ex.setBoolean(146, rssetgeneral.getBoolean("set_act_suplidor_producto"));
                            ps_ex.setBoolean(147, rssetgeneral.getBoolean("set_desactivar_prodexistencia"));
                            ps_ex.setBoolean(148, rssetgeneral.getBoolean("set_modcosto_transalmacen"));
                            ps_ex.setBoolean(149, rssetgeneral.getBoolean("set_valcantidad_fraccion"));
                            ps_ex.setBoolean(150, rssetgeneral.getBoolean("set_retener_itbis_compras"));
                            ps_ex.setBoolean(151, rssetgeneral.getBoolean("set_recalcular_balance"));
                            ps_ex.setBoolean(152, rssetgeneral.getBoolean("set_guardar_comprobante_recibo"));
                            ps_ex.setBoolean(153, rssetgeneral.getBoolean("set_usa_fecharimobiles"));
                            ps_ex.setDouble(154, rssetgeneral.getDouble("vtas_hasta"));
                            ps_ex.setBoolean(155, rssetgeneral.getBoolean("set_combusa_compania"));
                            ps_ex.setBoolean(156, rssetgeneral.getBoolean("set_pedirmotivo_cancelventa"));
                            ps_ex.setBoolean(157, rssetgeneral.getBoolean("set_permitir_modpreciodev"));
                            ps_ex.setBoolean(158, rssetgeneral.getBoolean("set_impcopiari"));
                            ps_ex.setBoolean(159, rssetgeneral.getBoolean("set_elegir_und_ptoventa"));
                            ps_ex.setString(160, rssetgeneral.getString("cia_codigo"));
                            ps_ex.execute();

                            _SQLQuery = "update vtas.setgeneral_cajas set sincronizado = true where cia_codigo = ?::varchar "
                                    + " and caja_cod in (" + this.Cajas + ")";
                            ps_stmt = _connection.prepareStatement(_SQLQuery);
                            ps_stmt.setString(1, rssetgeneral.getString("cia_codigo"));
                            ps_stmt.execute();

                            _ex_connection.commit();
                            _connection.commit();
                            _ex_connection.close();
                        }
                    }

                }
            } catch (SQLException ex) {
                message.setMessage(jtext1, "Caja: " + this.Cajas + " Ocurrio el siguiente error al actualizar la configuracion general: " + ex.getMessage());
                this.b_QueryResult = false;
                CerrarConexiones();
                return this.b_QueryResult;
            }

        }
        CerrarConexiones();

        return this.b_QueryResult;
    }

    public boolean ActualizarCiaSetup() {
        PreparedStatement ps_stmt, ps_ex;
        ResultSet rsciasetup;
        getServers();
        if (openConnection()) {
            Iterator<Servers> servidor = repo1.lstservidores.iterator();

            try {
                while (servidor.hasNext()) {
                    Servers caja = servidor.next();
                    this.SetSlaveConnection(caja.host_name, caja.database_name, caja.port_number, caja.user_name, caja.user_pwd);
                    getCajasLocales();
                    _SQLQuery = "select b.* , c.caja_ip,a.cia_codigo "
                            + "  from vtas.ciasetup_cajas a inner join inv_cajas c on(a.caja_cod = c.caja_cod) "
                            + "  left join cia_setup b on (a.cia_codigo = b.cia_codigo)"
                            + "  where a.cia_codigo = ? and a.sincronizado is false and c.caja_cod in (" + Cajas + ")";
                    ps_stmt = _connection.prepareStatement(_SQLQuery);
                    ps_stmt.setString(1, repo1.Company);
                    rsciasetup = ps_stmt.executeQuery();

                    while (rsciasetup.next()) {
                        this.SetCaja(caja.cajas, rsciasetup.getString("cia_codigo"));
                        message.setCaption(lblTransaccion, "Caja: " + this.Cajas + " Actualizando configuracion general : " + rsciasetup.getString("cia_codigo"));

                        if (ex_openConnection()) {

                            _ex_SQLQuery = "UPDATE cia_setup "
                                    + "SET inv_negativo=?, inv_pordebajo=?, inv_ventassi=?, "
                                    + "inv_ventasno=?, sis_nota1=?, sis_nota2=?, sis_nota3=?, sis_nota4=?, "
                                    + "sis_nota5=?, sis_nota6=?, inv_diasgracia=?, inv_almacen=?, inv_almacen1=?, "
                                    + "inv_almacen2=?, inv_almacen3=?, inv_almacen4=?, inv_almacen5=?, "
                                    + "inv_almacen6=?, inv_almacen7=?, inv_almacen8=?, inv_almacen9=?, "
                                    + "cxc_ringresosi=?, inv_pedidosi=?, inv_cotizacioni=?, inv_facturasi=?, "
                                    + "inv_alm=?, sis_dias=?, cia_reportes=?, sis_nota7=?, sis_nota8=?, "
                                    + "dev_tiponc=?, inv_almventaexpress=?, inv_precioventaexpress=?, "
                                    + "inv_usapesoelectronico=?, inv_identpesoe=?, inv_longlibpesoe=?, "
                                    + "inv_longcodpeso=?, inv_longdecpeso=?, inv_eliminaultcero=?, sis_manejoturnos=?, "
                                    + "sis_autorizaingresos=?, inv_segofertas=?, inv_tipo_salida_automatica=?, "
                                    + "inv_preciofact=?, tipo_doc_ck=?, inv_formatoimpmat=?, inv_porbenmaxpre=?,"
                                    + "cxc_muestrackf_estcl=?, inv_ver_precioconitbis=?, inv_confirmarcompra=?, "
                                    + "sis_cambioautofechacaja=?, inv_cuadftcontado=?, inv_cuadftredito=?, "
                                    + "inv_cuaddevoluciones=?, inv_cuadckdevueltos=?, inv_cuadringresos=?, "
                                    + "inv_cuadranticipos=?, inv_cuadrotroscobros=?, inv_cuadcobfuturos=?, "
                                    + "inv_cuadndebitos=?, inv_cuadncreditos=?, inv_cuadegresos=?, sis_usarpropietario=?, "
                                    + "inv_tipodev_oblig=?, cxc_aplicar_ckf=?, cxc_formato_adelantos=?, "
                                    + "cxc_formato_nc=?, cxc_formato_nd=?, cxc_formato_otros=?, cxc_formato_recibo=?, "
                                    + "inv_cambiaprecioped=?, inv_tipcompgdcxc=?, inv_usabonosdevcont=?, "
                                    + "inv_usarsecvtacredito=?, inv_cambiapreciofac=?, inv_cursor_facturacion=?, "
                                    + "inv_tipo_venta=?, inv_tipo_entxproduccion=?, inv_tipo_salxproduccion=?, "
                                    + "cia_titulo_reporte=?, cxc_ri_caja_banco=?, inv_tipo_entxprodmat=?, "
                                    + "inv_tipo_salxprodmat=?, inv_referenciaprodmat=?, inv_rptfact_credito=?, "
                                    + "sis_opt_anular=?, cuad_presentainfocierre=?, inv_porciento_apartado=?, "
                                    + "url_apache_server=?, dir_php_file=?, inv_genantcxpdevcompras=?, "
                                    + "comp_actualizar_cospromed=?, cxp_aplicar_ant_auto=?, set_referenciare=?, "
                                    + "cxp_impgastoscomp=?, inv_usaformatolaserlabels=?, inv_quitarcerosinicialespeso=?, "
                                    + "via_recarga_defecto=?, cxc_descpropag=?, cxc_pordescppa=?, cxc_diapdesv=?, "
                                    + "cxc_pordescsitb=?, prod_impuestoplaca=?, inv_controlaperturaturnosusuarios=?, "
                                    + "fac_imprimirlabel=?, com_usarpreliquidacion=?, fac_exoneraitbisregesp =? "
                                    + "WHERE cia_codigo = ? ;";

                            ps_ex = _ex_connection.prepareStatement(_ex_SQLQuery);
                            ps_ex.setDouble(1, rsciasetup.getDouble("inv_negativo"));
                            ps_ex.setDouble(2, rsciasetup.getDouble("inv_pordebajo"));
                            ps_ex.setDouble(3, rsciasetup.getDouble("inv_ventassi"));
                            ps_ex.setDouble(4, rsciasetup.getDouble("inv_ventasno"));
                            ps_ex.setString(5, rsciasetup.getString("sis_nota1"));
                            ps_ex.setString(6, rsciasetup.getString("sis_nota2"));
                            ps_ex.setString(7, rsciasetup.getString("sis_nota3"));
                            ps_ex.setString(8, rsciasetup.getString("sis_nota4"));
                            ps_ex.setString(9, rsciasetup.getString("sis_nota5"));
                            ps_ex.setString(10, rsciasetup.getString("sis_nota6"));
                            ps_ex.setDouble(11, rsciasetup.getDouble("inv_diasgracia"));
                            ps_ex.setDouble(12, rsciasetup.getDouble("inv_almacen"));
                            ps_ex.setString(13, rsciasetup.getString("inv_almacen1"));
                            ps_ex.setString(14, rsciasetup.getString("inv_almacen2"));
                            ps_ex.setString(15, rsciasetup.getString("inv_almacen3"));
                            ps_ex.setString(16, rsciasetup.getString("inv_almacen4"));
                            ps_ex.setString(17, rsciasetup.getString("inv_almacen5"));
                            ps_ex.setString(18, rsciasetup.getString("inv_almacen6"));
                            ps_ex.setString(19, rsciasetup.getString("inv_almacen7"));
                            ps_ex.setString(20, rsciasetup.getString("inv_almacen8"));
                            ps_ex.setString(21, rsciasetup.getString("inv_almacen9"));
                            ps_ex.setDouble(22, rsciasetup.getDouble("cxc_ringresosi"));
                            ps_ex.setDouble(23, rsciasetup.getDouble("inv_pedidosi"));
                            ps_ex.setDouble(24, rsciasetup.getDouble("inv_cotizacioni"));
                            ps_ex.setDouble(25, rsciasetup.getDouble("inv_facturasi"));
                            ps_ex.setInt(26, rsciasetup.getInt("inv_alm"));
                            ps_ex.setInt(27, rsciasetup.getInt("sis_dias"));
                            ps_ex.setInt(28, rsciasetup.getInt("cia_reportes"));
                            ps_ex.setString(29, rsciasetup.getString("sis_nota7"));
                            ps_ex.setString(30, rsciasetup.getString("sis_nota8"));
                            ps_ex.setString(31, rsciasetup.getString("dev_tiponc"));
                            ps_ex.setString(32, rsciasetup.getString("inv_almventaexpress"));
                            ps_ex.setString(33, rsciasetup.getString("inv_precioventaexpress"));
                            ps_ex.setInt(34, rsciasetup.getInt("inv_usapesoelectronico"));
                            ps_ex.setString(35, rsciasetup.getString("inv_identpesoe"));
                            ps_ex.setInt(36, rsciasetup.getInt("inv_longlibpesoe"));
                            ps_ex.setInt(37, rsciasetup.getInt("inv_longcodpeso"));
                            ps_ex.setInt(38, rsciasetup.getInt("inv_longdecpeso"));
                            ps_ex.setInt(39, rsciasetup.getInt("inv_eliminaultcero"));
                            ps_ex.setInt(40, rsciasetup.getInt("sis_manejoturnos"));
                            ps_ex.setInt(41, rsciasetup.getInt("sis_autorizaingresos"));
                            ps_ex.setInt(42, rsciasetup.getInt("inv_segofertas"));
                            ps_ex.setString(43, rsciasetup.getString("inv_tipo_salida_automatica"));
                            ps_ex.setString(44, rsciasetup.getString("inv_preciofact"));
                            ps_ex.setString(45, rsciasetup.getString("tipo_doc_ck"));
                            ps_ex.setInt(46, rsciasetup.getInt("inv_formatoimpmat"));
                            ps_ex.setDouble(47, rsciasetup.getDouble("inv_porbenmaxpre"));
                            ps_ex.setInt(48, rsciasetup.getInt("cxc_muestrackf_estcl"));
                            ps_ex.setInt(49, rsciasetup.getInt("inv_ver_precioconitbis"));
                            ps_ex.setInt(50, rsciasetup.getInt("inv_confirmarcompra"));
                            ps_ex.setInt(51, rsciasetup.getInt("sis_cambioautofechacaja"));
                            ps_ex.setInt(52, rsciasetup.getInt("inv_cuadftcontado"));
                            ps_ex.setInt(53, rsciasetup.getInt("inv_cuadftredito"));
                            ps_ex.setInt(54, rsciasetup.getInt("inv_cuaddevoluciones"));
                            ps_ex.setInt(55, rsciasetup.getInt("inv_cuadckdevueltos"));
                            ps_ex.setInt(56, rsciasetup.getInt("inv_cuadringresos"));
                            ps_ex.setInt(57, rsciasetup.getInt("inv_cuadranticipos"));
                            ps_ex.setInt(58, rsciasetup.getInt("inv_cuadrotroscobros"));
                            ps_ex.setInt(59, rsciasetup.getInt("inv_cuadcobfuturos"));
                            ps_ex.setInt(60, rsciasetup.getInt("inv_cuadndebitos"));
                            ps_ex.setInt(61, rsciasetup.getInt("inv_cuadncreditos"));
                            ps_ex.setInt(62, rsciasetup.getInt("inv_cuadegresos"));
                            ps_ex.setInt(63, rsciasetup.getInt("sis_usarpropietario"));
                            ps_ex.setBoolean(64, rsciasetup.getBoolean("inv_tipodev_oblig"));
                            ps_ex.setInt(65, rsciasetup.getInt("cxc_aplicar_ckf"));
                            ps_ex.setInt(66, rsciasetup.getInt("cxc_formato_adelantos"));
                            ps_ex.setInt(67, rsciasetup.getInt("cxc_formato_nc"));
                            ps_ex.setInt(68, rsciasetup.getInt("cxc_formato_nd"));
                            ps_ex.setInt(69, rsciasetup.getInt("cxc_formato_otros"));
                            ps_ex.setInt(70, rsciasetup.getInt("cxc_formato_recibo"));
                            ps_ex.setInt(71, rsciasetup.getInt("inv_cambiaprecioped"));
                            ps_ex.setString(72, rsciasetup.getString("inv_tipcompgdcxc"));
                            ps_ex.setInt(73, rsciasetup.getInt("inv_usabonosdevcont"));
                            ps_ex.setInt(74, rsciasetup.getInt("inv_usarsecvtacredito"));
                            ps_ex.setInt(75, rsciasetup.getInt("inv_cambiapreciofac"));
                            ps_ex.setInt(76, rsciasetup.getInt("inv_cursor_facturacion"));
                            ps_ex.setInt(77, rsciasetup.getInt("inv_tipo_venta"));
                            ps_ex.setString(78, rsciasetup.getString("inv_tipo_entxproduccion"));
                            ps_ex.setString(79, rsciasetup.getString("inv_tipo_salxproduccion"));
                            ps_ex.setInt(80, rsciasetup.getInt("cia_titulo_reporte"));
                            ps_ex.setInt(81, rsciasetup.getInt("cxc_ri_caja_banco"));
                            ps_ex.setString(82, rsciasetup.getString("inv_tipo_entxprodmat"));
                            ps_ex.setString(83, rsciasetup.getString("inv_tipo_salxprodmat"));
                            ps_ex.setString(84, rsciasetup.getString("inv_referenciaprodmat"));
                            ps_ex.setString(85, rsciasetup.getString("inv_rptfact_credito"));
                            ps_ex.setInt(86, rsciasetup.getInt("sis_opt_anular"));
                            ps_ex.setInt(87, rsciasetup.getInt("cuad_presentainfocierre"));
                            ps_ex.setDouble(88, rsciasetup.getDouble("inv_porciento_apartado"));
                            ps_ex.setString(89, rsciasetup.getString("url_apache_server"));
                            ps_ex.setString(90, rsciasetup.getString("dir_php_file"));
                            ps_ex.setInt(91, rsciasetup.getInt("inv_genantcxpdevcompras"));
                            ps_ex.setInt(92, rsciasetup.getInt("comp_actualizar_cospromed"));
                            ps_ex.setInt(93, rsciasetup.getInt("cxp_aplicar_ant_auto"));
                            ps_ex.setString(94, rsciasetup.getString("set_referenciare"));
                            ps_ex.setBoolean(95, rsciasetup.getBoolean("cxp_impgastoscomp"));
                            ps_ex.setBoolean(96, rsciasetup.getBoolean("inv_usaformatolaserlabels"));
                            ps_ex.setInt(97, rsciasetup.getInt("inv_quitarcerosinicialespeso"));
                            ps_ex.setInt(98, rsciasetup.getInt("via_recarga_defecto"));
                            ps_ex.setDouble(99, rsciasetup.getDouble("cxc_descpropag"));
                            ps_ex.setDouble(100, rsciasetup.getDouble("cxc_pordescppa"));
                            ps_ex.setDouble(101, rsciasetup.getDouble("cxc_diapdesv"));
                            ps_ex.setDouble(102, rsciasetup.getDouble("cxc_pordescsitb"));
                            ps_ex.setString(103, rsciasetup.getString("prod_impuestoplaca"));
                            ps_ex.setBoolean(104, rsciasetup.getBoolean("inv_controlaperturaturnosusuarios"));
                            ps_ex.setBoolean(105, rsciasetup.getBoolean("fac_imprimirlabel"));
                            ps_ex.setBoolean(106, rsciasetup.getBoolean("com_usarpreliquidacion"));
                            ps_ex.setBoolean(107, rsciasetup.getBoolean("fac_exoneraitbisregesp"));
                            ps_ex.setString(108, rsciasetup.getString("cia_codigo"));

                            ps_ex.execute();

                            _SQLQuery = "update vtas.ciasetup_cajas set sincronizado = true where cia_codigo = ?::varchar "
                                    + " and caja_cod in (" + this.Cajas + ") ";
                            ps_stmt = _connection.prepareStatement(_SQLQuery);
                            ps_stmt.setString(1, rsciasetup.getString("cia_codigo"));
                            ps_stmt.execute();

                            _ex_connection.commit();
                            _connection.commit();
                            _ex_connection.close();
                        }
                    }

                }
            } catch (SQLException ex) {
                message.setMessage(jtext1, "Caja: " + this.Cajas + " Ocurrio el siguiente error al actualizar la configuracion general: " + ex.getMessage());
                this.b_QueryResult = false;
                CerrarConexiones();
                return this.b_QueryResult;
            }

        }
        CerrarConexiones();

        return this.b_QueryResult;
    }

    public boolean ActualizarConfiguracionTarPref() {
        PreparedStatement ps_stmt, ps_ex;
        ResultSet rsConfiguracionTP;

        tabla = "cxc_config_tarpref";
        Campos = "cia_codigo, generar_puntos, generar_descuento, ptos_x_monto, "
                + "ptos_x_producto, equivalencia_ptos, cantidad_minima, fecha_disp, "
                + "vencimiento_ptos, acumular_vencidos, penalizacionxdevol, porc_penalizacion, "
                + "periodo_vencimiento, desc_fijo, porc_descfijo, desc_subclas, "
                + "montofactura, puntos_generados, monto_brutoneto, disponibilidad_en_dias, "
                + "disponibilidad_monacum, codigo_tiptar, bonos_nogeneran_ptos, "
                + "desc_x_subcategoria, diasvenc_bonos, letras_iniciales, ptos_pagos_saldo, "
                + "ptos_x_subcategoria, usar_total_bono, puntos_o_porc, porciento, "
                + "cant_digitos_id, devolucion_facturas, ptos_boletas, boletas_generadas";
        getServers();
        if (openConnection()) {
            Iterator<Servers> servidor = repo1.lstservidores.iterator();

            try {
                while (servidor.hasNext()) {
                    Servers caja = servidor.next();
                    this.SetSlaveConnection(caja.host_name, caja.database_name, caja.port_number, caja.user_name, caja.user_pwd);
                    getCajasLocales();

                    _SQLQuery = "select  b.*,c.caja_ip,a.cia_codigo "
                            + "  from vtas.configtarpref_cajas a inner join inv_cajas c on(a.caja_cod = c.caja_cod) "
                            + "  left join cxc_config_tarpref b on (a.cia_codigo = b.cia_codigo )"
                            + "  where a.cia_codigo = ? and a.sincronizado is false and c.caja_cod in (" + Cajas + ")";
                    ps_stmt = _connection.prepareStatement(_SQLQuery);
                    ps_stmt.setString(1, repo1.Company);
                    rsConfiguracionTP = ps_stmt.executeQuery();

                    while (rsConfiguracionTP.next()) {
                        this.SetCaja(caja.cajas, rsConfiguracionTP.getString("cia_codigo"));
                        message.setCaption(lblTransaccion, "Caja: " + this.Cajas + " Actualizando configuracion de tarjetas preferenciales : " + rsConfiguracionTP.getString("cia_codigo"));

                        if (ex_openConnection()) {

                            Condicion = "cia_codigo = ?::varchar ";
                            ps_Condicion = _ex_connection.prepareStatement(Condicion);
                            ps_Condicion.setString(1, rsConfiguracionTP.getString("cia_codigo"));

                            Cambios = "generar_puntos=?, generar_descuento=?, ptos_x_monto=?, "
                                    + "ptos_x_producto=?, equivalencia_ptos=?, cantidad_minima=?, fecha_disp=?,  "
                                    + "vencimiento_ptos=?, acumular_vencidos=?, penalizacionxdevol=?,  "
                                    + "porc_penalizacion=?, periodo_vencimiento=?, desc_fijo=?, porc_descfijo=?,  "
                                    + "desc_subclas=?, montofactura=?, puntos_generados=?, monto_brutoneto=?,  "
                                    + "disponibilidad_en_dias=?, disponibilidad_monacum=?, codigo_tiptar=?,  "
                                    + "bonos_nogeneran_ptos=?, desc_x_subcategoria=?, diasvenc_bonos=?,  "
                                    + "letras_iniciales=?, ptos_pagos_saldo=?, ptos_x_subcategoria=?,  "
                                    + "usar_total_bono=?, puntos_o_porc=?, porciento=?, cant_digitos_id=?,  "
                                    + "devolucion_facturas=?, ptos_boletas=?, boletas_generadas=? ";

                            ps_Cambios = _ex_connection.prepareStatement(Cambios);
                            ps_Cambios.setBoolean(1, rsConfiguracionTP.getBoolean("generar_puntos"));
                            ps_Cambios.setBoolean(2, rsConfiguracionTP.getBoolean("generar_descuento"));
                            ps_Cambios.setBoolean(3, rsConfiguracionTP.getBoolean("ptos_x_monto"));
                            ps_Cambios.setBoolean(4, rsConfiguracionTP.getBoolean("ptos_x_producto"));
                            ps_Cambios.setInt(5, rsConfiguracionTP.getInt("equivalencia_ptos"));
                            ps_Cambios.setInt(6, rsConfiguracionTP.getInt("cantidad_minima"));
                            ps_Cambios.setInt(7, rsConfiguracionTP.getInt("fecha_disp"));
                            ps_Cambios.setInt(8, rsConfiguracionTP.getInt("vencimiento_ptos"));
                            ps_Cambios.setBoolean(9, rsConfiguracionTP.getBoolean("acumular_vencidos"));
                            ps_Cambios.setBoolean(10, rsConfiguracionTP.getBoolean("penalizacionxdevol"));
                            ps_Cambios.setDouble(11, rsConfiguracionTP.getDouble("porc_penalizacion"));
                            ps_Cambios.setInt(12, rsConfiguracionTP.getInt("periodo_vencimiento"));
                            ps_Cambios.setBoolean(13, rsConfiguracionTP.getBoolean("desc_fijo"));
                            ps_Cambios.setDouble(14, rsConfiguracionTP.getDouble("porc_descfijo"));
                            ps_Cambios.setBoolean(15, rsConfiguracionTP.getBoolean("desc_subclas"));
                            ps_Cambios.setDouble(16, rsConfiguracionTP.getDouble("montofactura"));
                            ps_Cambios.setInt(17, rsConfiguracionTP.getInt("puntos_generados"));
                            ps_Cambios.setInt(18, rsConfiguracionTP.getInt("monto_brutoneto"));
                            ps_Cambios.setBoolean(19, rsConfiguracionTP.getBoolean("disponibilidad_en_dias"));
                            ps_Cambios.setBoolean(20, rsConfiguracionTP.getBoolean("disponibilidad_monacum"));
                            ps_Cambios.setInt(21, rsConfiguracionTP.getInt("codigo_tiptar"));
                            ps_Cambios.setBoolean(22, rsConfiguracionTP.getBoolean("bonos_nogeneran_ptos"));
                            ps_Cambios.setBoolean(23, rsConfiguracionTP.getBoolean("desc_x_subcategoria"));
                            ps_Cambios.setInt(24, rsConfiguracionTP.getInt("diasvenc_bonos"));
                            ps_Cambios.setString(25, rsConfiguracionTP.getString("letras_iniciales"));
                            ps_Cambios.setInt(26, rsConfiguracionTP.getInt("ptos_pagos_saldo"));
                            ps_Cambios.setBoolean(27, rsConfiguracionTP.getBoolean("ptos_x_subcategoria"));
                            ps_Cambios.setBoolean(28, rsConfiguracionTP.getBoolean("usar_total_bono"));
                            ps_Cambios.setInt(29, rsConfiguracionTP.getInt("puntos_o_porc"));
                            ps_Cambios.setDouble(30, rsConfiguracionTP.getDouble("porciento"));
                            ps_Cambios.setInt(31, rsConfiguracionTP.getInt("cant_digitos_id"));
                            ps_Cambios.setInt(32, rsConfiguracionTP.getInt("devolucion_facturas"));
                            ps_Cambios.setInt(33, rsConfiguracionTP.getInt("ptos_boletas"));
                            ps_Cambios.setInt(34, rsConfiguracionTP.getInt("boletas_generadas"));

                            Valores = "?, ?, ?, ?,"
                                    + "?, ?, ?, ?, "
                                    + "?, ?, ?, ?, "
                                    + "?, ?, ?, ?,  "
                                    + "?, ?, ?, ?,  "
                                    + "?, ?, ?,  "
                                    + "?, ?, ?, ?, "
                                    + "?, ?, ?, ?,  "
                                    + "?, ?, ?, ?";
                            ps_Valores = _ex_connection.prepareStatement(Valores);
                            ps_Valores.setString(1, rsConfiguracionTP.getString("cia_codigo"));
                            ps_Valores.setBoolean(2, rsConfiguracionTP.getBoolean("generar_puntos"));
                            ps_Valores.setBoolean(3, rsConfiguracionTP.getBoolean("generar_descuento"));
                            ps_Valores.setBoolean(4, rsConfiguracionTP.getBoolean("ptos_x_monto"));
                            ps_Valores.setBoolean(5, rsConfiguracionTP.getBoolean("ptos_x_producto"));
                            ps_Valores.setInt(6, rsConfiguracionTP.getInt("equivalencia_ptos"));
                            ps_Valores.setInt(7, rsConfiguracionTP.getInt("cantidad_minima"));
                            ps_Valores.setInt(8, rsConfiguracionTP.getInt("fecha_disp"));
                            ps_Valores.setInt(9, rsConfiguracionTP.getInt("vencimiento_ptos"));
                            ps_Valores.setBoolean(10, rsConfiguracionTP.getBoolean("acumular_vencidos"));
                            ps_Valores.setBoolean(11, rsConfiguracionTP.getBoolean("penalizacionxdevol"));
                            ps_Valores.setDouble(12, rsConfiguracionTP.getDouble("porc_penalizacion"));
                            ps_Valores.setInt(13, rsConfiguracionTP.getInt("periodo_vencimiento"));
                            ps_Valores.setBoolean(14, rsConfiguracionTP.getBoolean("desc_fijo"));
                            ps_Valores.setDouble(15, rsConfiguracionTP.getDouble("porc_descfijo"));
                            ps_Valores.setBoolean(16, rsConfiguracionTP.getBoolean("desc_subclas"));
                            ps_Valores.setDouble(17, rsConfiguracionTP.getDouble("montofactura"));
                            ps_Valores.setInt(18, rsConfiguracionTP.getInt("puntos_generados"));
                            ps_Valores.setInt(19, rsConfiguracionTP.getInt("monto_brutoneto"));
                            ps_Valores.setBoolean(20, rsConfiguracionTP.getBoolean("disponibilidad_en_dias"));
                            ps_Valores.setBoolean(21, rsConfiguracionTP.getBoolean("disponibilidad_monacum"));
                            ps_Valores.setInt(22, rsConfiguracionTP.getInt("codigo_tiptar"));
                            ps_Valores.setBoolean(23, rsConfiguracionTP.getBoolean("bonos_nogeneran_ptos"));
                            ps_Valores.setBoolean(24, rsConfiguracionTP.getBoolean("desc_x_subcategoria"));
                            ps_Valores.setInt(25, rsConfiguracionTP.getInt("diasvenc_bonos"));
                            ps_Valores.setString(26, rsConfiguracionTP.getString("letras_iniciales"));
                            ps_Valores.setInt(27, rsConfiguracionTP.getInt("ptos_pagos_saldo"));
                            ps_Valores.setBoolean(28, rsConfiguracionTP.getBoolean("ptos_x_subcategoria"));
                            ps_Valores.setBoolean(29, rsConfiguracionTP.getBoolean("usar_total_bono"));
                            ps_Valores.setInt(30, rsConfiguracionTP.getInt("puntos_o_porc"));
                            ps_Valores.setDouble(31, rsConfiguracionTP.getDouble("porciento"));
                            ps_Valores.setInt(32, rsConfiguracionTP.getInt("cant_digitos_id"));
                            ps_Valores.setInt(33, rsConfiguracionTP.getInt("devolucion_facturas"));
                            ps_Valores.setInt(34, rsConfiguracionTP.getInt("ptos_boletas"));
                            ps_Valores.setInt(35, rsConfiguracionTP.getInt("boletas_generadas"));

                            _ex_SQLQuery = "SELECT * FROM public.fn_editar(?::varchar, ?::varchar, ?::varchar, ?::varchar, ?::varchar, ?::varchar, ?::varchar, ?::varchar, ?::varchar);";
                            ps_ex = _ex_connection.prepareStatement(_ex_SQLQuery);
                            ps_ex.setString(1, tabla);
                            ps_ex.setString(2, ps_Cambios.toString());
                            ps_ex.setString(3, "");
                            ps_ex.setString(4, "");
                            ps_ex.setString(5, ps_Condicion.toString());
                            ps_ex.setString(6, Campos);
                            ps_ex.setString(7, ps_Valores.toString());
                            ps_ex.setString(8, "");
                            ps_ex.setString(9, "");
                            ps_ex.executeQuery();

                            _SQLQuery = "update vtas.configtarpref_cajas set sincronizado = true where cia_codigo = ?::varchar "
                                    + " and caja_cod in (" + this.Cajas + ")";
                            ps_stmt = _connection.prepareStatement(_SQLQuery);
                            ps_stmt.setString(1, rsConfiguracionTP.getString("cia_codigo"));
                            ps_stmt.execute();
                            _ex_connection.commit();
                            _connection.commit();
                            _ex_connection.close();
                        }
                    }

                }
            } catch (SQLException ex) {
                message.setMessage(jtext1, "Caja: " + this.Cajas + " Ocurrio el siguiente error al actualizar la configuracion de tarjetas preferenciales: " + ex.getMessage());
                this.b_QueryResult = false;
                CerrarConexiones();
                return this.b_QueryResult;
            }

        }
        CerrarConexiones();

        return this.b_QueryResult;
    }

    public boolean ActualizarTiposTarPref() {
        PreparedStatement ps_stmt, ps_ex;
        ResultSet rstipostarpref;

        tabla = "cxc_tipos_tarpref";
        Campos = "codigo, cia_codigo, tip_codigo, tip_nombre, tip_estado";
        getServers();
        if (openConnection()) {
            Iterator<Servers> servidor = repo1.lstservidores.iterator();

            try {
                while (servidor.hasNext()) {
                    Servers caja = servidor.next();
                    this.SetSlaveConnection(caja.host_name, caja.database_name, caja.port_number, caja.user_name, caja.user_pwd);
                    getCajasLocales();

                    _SQLQuery = "select b.cia_codigo, b.tip_codigo, b.tip_nombre, b.tip_estado , c.caja_ip, a.codigo ,a.borrado "
                            + "  from vtas.tipotarpref_cajas a inner join inv_cajas c on(a.caja_cod = c.caja_cod) "
                            + "  left join cxc_tipos_tarpref b on (a.codigo = b.codigo )"
                            + "  where b.cia_codigo = ? and a.sincronizado is false and c.caja_cod in (" + Cajas + ")"
                            + "  order by a.borrado desc";
                    ps_stmt = _connection.prepareStatement(_SQLQuery);
                    ps_stmt.setString(1, repo1.Company);
                    rstipostarpref = ps_stmt.executeQuery();

                    while (rstipostarpref.next()) {
                        this.SetCaja(caja.cajas, rstipostarpref.getString("cia_codigo"));
                        message.setCaption(lblTransaccion, "Caja: " + this.Cajas + " Actualizando tipo de tarjeta preferencial : " + rstipostarpref.getString("tip_nombre"));

                        if (ex_openConnection()) {
                            if (rstipostarpref.getBoolean("borrado") == true) {
                                _ex_SQLQuery = "delete from cxc_tipos_tarpref where codigo = ?::integer ";
                                ps_ex = _ex_connection.prepareStatement(_ex_SQLQuery);
                                ps_ex.setInt(1, rstipostarpref.getInt("codigo"));
                                ps_ex.execute();
                            } else {
                                Condicion = "codigo = ?::integer ";
                                ps_Condicion = _ex_connection.prepareStatement(Condicion);
                                ps_Condicion.setInt(1, rstipostarpref.getInt("codigo"));

                                Cambios = "tip_nombre = ?, tip_estado = ?";
                                ps_Cambios = _ex_connection.prepareStatement(Cambios);
                                ps_Cambios.setString(1, rstipostarpref.getString("tip_nombre"));
                                ps_Cambios.setString(2, rstipostarpref.getString("tip_estado"));

                                Valores = "?, ?, ?, ?, ?";
                                ps_Valores = _ex_connection.prepareStatement(Valores);
                                ps_Valores.setInt(1, rstipostarpref.getInt("codigo"));
                                ps_Valores.setString(2, rstipostarpref.getString("cia_codigo"));
                                ps_Valores.setString(3, rstipostarpref.getString("tip_codigo"));
                                ps_Valores.setString(4, rstipostarpref.getString("tip_nombre"));
                                ps_Valores.setString(5, rstipostarpref.getString("tip_estado"));

                                _ex_SQLQuery = "SELECT * FROM public.fn_editar(?::varchar, ?::varchar, ?::varchar, ?::varchar, ?::varchar, ?::varchar, ?::varchar, ?::varchar, ?::varchar);";
                                ps_ex = _ex_connection.prepareStatement(_ex_SQLQuery);
                                ps_ex.setString(1, tabla);
                                ps_ex.setString(2, ps_Cambios.toString());
                                ps_ex.setString(3, "");
                                ps_ex.setString(4, "");
                                ps_ex.setString(5, ps_Condicion.toString());
                                ps_ex.setString(6, Campos);
                                ps_ex.setString(7, ps_Valores.toString());
                                ps_ex.setString(8, "");
                                ps_ex.setString(9, "");
                                ps_ex.executeQuery();

                            }
                            _SQLQuery = "update vtas.tipotarpref_cajas set sincronizado = true where codigo = ?::integer "
                                    + " and caja_cod in (" + this.Cajas + ") ";
                            ps_stmt = _connection.prepareStatement(_SQLQuery);
                            ps_stmt.setInt(1, rstipostarpref.getInt("codigo"));
                            ps_stmt.execute();
                            _ex_connection.commit();
                            _connection.commit();
                            _ex_connection.close();
                        }
                    }

                }
            } catch (SQLException ex) {
                message.setMessage(jtext1, "Caja: " + this.Cajas + " Ocurrio el siguiente error al actualizar los tipos de tarjeta preferenciales: " + ex.getMessage());
                this.b_QueryResult = false;
                CerrarConexiones();
                return this.b_QueryResult;
            }

        }
        CerrarConexiones();

        return this.b_QueryResult;
    }

    public boolean ActualizarTarjetasPref() {
        PreparedStatement ps_stmt, ps_ex;
        ResultSet rstarpref;

        tabla = "cxc_tarjeta_pref";
        Campos = "codigo, cia_codigo, id_tarjeta, fecha_asignacion, estado, balance, codigo_tiptar, clie_codigo, codigo_recepcion";
        getServers();
        if (openConnection()) {

            Iterator<Servers> servidor = repo1.lstservidores.iterator();
            try {
                while (servidor.hasNext()) {
                    Servers caja = servidor.next();
                    this.SetSlaveConnection(caja.host_name, caja.database_name, caja.port_number, caja.user_name, caja.user_pwd);
                    getCajasLocales();
                    _SQLQuery = "select b.cia_codigo, b.id_tarjeta, b.fecha_asignacion, b.estado, b.balance, b.codigo_tiptar, "
                            + " b.clie_codigo, b.codigo_recepcion, c.caja_ip, a.codigo ,a.borrado "
                            + "  from vtas.tarjetapref_cajas a inner join inv_cajas c on(a.caja_cod = c.caja_cod) "
                            + "  left join cxc_tarjeta_pref b on (a.codigo = b.codigo )"
                            + "  where b.cia_codigo = ? and a.sincronizado is false and c.caja_cod in (" + Cajas + ")"
                            + "  order by a.borrado desc";
                    ps_stmt = _connection.prepareStatement(_SQLQuery);
                    ps_stmt.setString(1, repo1.Company);
                    rstarpref = ps_stmt.executeQuery();

                    while (rstarpref.next()) {
                        this.SetCaja(caja.cajas, rstarpref.getString("cia_codigo"));
                        message.setCaption(lblTransaccion, "Caja: " + this.Cajas + " Actualizando Tarjeta preferencial : " + rstarpref.getString("id_tarjeta"));

                        if (ex_openConnection()) {
                            if (rstarpref.getBoolean("borrado") == true) {
                                _ex_SQLQuery = "delete from cxc_tarjeta_pref where codigo = ?::integer ";
                                ps_ex = _ex_connection.prepareStatement(_ex_SQLQuery);
                                ps_ex.setInt(1, rstarpref.getInt("codigo"));
                                ps_ex.execute();
                            } else {
                                Condicion = "codigo = ?::integer ";
                                ps_Condicion = _ex_connection.prepareStatement(Condicion);
                                ps_Condicion.setInt(1, rstarpref.getInt("codigo"));

                                Cambios = "fecha_asignacion = ?, estado = ?, balance = ?, codigo_tiptar = ?, clie_codigo = ?";
                                ps_Cambios = _ex_connection.prepareStatement(Cambios);
                                ps_Cambios.setDate(1, rstarpref.getDate("fecha_asignacion"));
                                ps_Cambios.setString(2, rstarpref.getString("estado"));
                                ps_Cambios.setDouble(3, rstarpref.getDouble("balance"));
                                ps_Cambios.setInt(4, rstarpref.getInt("codigo_tiptar"));
                                ps_Cambios.setString(5, rstarpref.getString("clie_codigo"));

                                Valores = "?, ?, ?, ?, ?, "
                                        + "?, ?, ?, ?";
                                ps_Valores = _ex_connection.prepareStatement(Valores);
                                ps_Valores.setInt(1, rstarpref.getInt("codigo"));
                                ps_Valores.setString(2, rstarpref.getString("cia_codigo"));
                                ps_Valores.setString(3, rstarpref.getString("id_tarjeta"));
                                ps_Valores.setDate(4, rstarpref.getDate("fecha_asignacion"));
                                ps_Valores.setString(5, rstarpref.getString("estado"));
                                ps_Valores.setDouble(6, rstarpref.getDouble("balance"));
                                ps_Valores.setInt(7, rstarpref.getInt("codigo_tiptar"));
                                ps_Valores.setString(8, rstarpref.getString("clie_codigo"));
                                ps_Valores.setInt(9, rstarpref.getInt("codigo_recepcion"));

                                _ex_SQLQuery = "SELECT * FROM public.fn_editar(?::varchar, ?::varchar, ?::varchar, ?::varchar, ?::varchar, ?::varchar, ?::varchar, ?::varchar, ?::varchar);";
                                ps_ex = _ex_connection.prepareStatement(_ex_SQLQuery);
                                ps_ex.setString(1, tabla);
                                ps_ex.setString(2, ps_Cambios.toString());
                                ps_ex.setString(3, "");
                                ps_ex.setString(4, "");
                                ps_ex.setString(5, ps_Condicion.toString());
                                ps_ex.setString(6, Campos);
                                ps_ex.setString(7, ps_Valores.toString());
                                ps_ex.setString(8, "");
                                ps_ex.setString(9, "");
                                ps_ex.executeQuery();

                            }
                            _SQLQuery = "update vtas.tarjetapref_cajas set sincronizado = true where codigo = ?::integer "
                                    + " and caja_cod in (" + this.Cajas + ")";
                            ps_stmt = _connection.prepareStatement(_SQLQuery);
                            ps_stmt.setInt(1, rstarpref.getInt("codigo"));
                            ps_stmt.execute();
                            _ex_connection.commit();
                            _connection.commit();
                            _ex_connection.close();
                        }
                    }

                }
            } catch (SQLException ex) {
                message.setMessage(jtext1, "Caja: " + this.Cajas + " Ocurrio el siguiente error al actualizar las tarjetas preferenciales: " + ex.getMessage());
                this.b_QueryResult = false;
                CerrarConexiones();
                return this.b_QueryResult;
            }

        }
        CerrarConexiones();

        return this.b_QueryResult;
    }

    public boolean ActualizarClasifImpuestos() {
        PreparedStatement ps_stmt, ps_ex;
        ResultSet rsclasifimpuestos, rsdetalle;

        tabla = "inv_clasificacion_impuesto";
        Campos = "id_clasificacion, descripcion, identificador";

        if (openConnection()) {
            getServers();
            Iterator<Servers> servidor = repo1.lstservidores.iterator();

            while (servidor.hasNext()) {
                Servers caja = servidor.next();
                try {
                    this.SetSlaveConnection(caja.host_name, caja.database_name, caja.port_number, caja.user_name, caja.user_pwd);
                    getCajasLocales();

                    _SQLQuery = "select b.* , c.caja_ip, a.codigo ,a.borrado "
                            + "  from vtas.clasifimpuestos_cajas a inner join inv_cajas c on(a.caja_cod = c.caja_cod) "
                            + "  left join inv_clasificacion_impuesto b on (a.codigo = b.id_clasificacion )"
                            + "  where a.sincronizado is false and c.caja_cod in (" + Cajas + ")"
                            + "  order by a.borrado desc";
                    ps_stmt = _connection.prepareStatement(_SQLQuery);
                    rsclasifimpuestos = ps_stmt.executeQuery();

                    while (rsclasifimpuestos.next()) {
                        this.SetCaja(caja.cajas, "");
                        message.setCaption(lblTransaccion, "Caja: " + this.Cajas + " Actualizando clasificacion de impuestos : " + rsclasifimpuestos.getString("descripcion"));

                        if (ex_openConnection()) {
                            if (rsclasifimpuestos.getBoolean("borrado") == true) {
                                _ex_SQLQuery = "delete from inv_clasificacion_impuesto where id_clasificacion = ?::integer ;"
                                        + "delete from inv_clasifimpuesto_rango where id_clasificacion = ?::integer ;";
                                ps_ex = _ex_connection.prepareStatement(_ex_SQLQuery);
                                ps_ex.setInt(1, rsclasifimpuestos.getInt("codigo"));
                                ps_ex.setInt(2, rsclasifimpuestos.getInt("codigo"));
                                ps_ex.execute();
                            } else {
                                Condicion = "id_clasificacion = ?::integer ";
                                ps_Condicion = _ex_connection.prepareStatement(Condicion);
                                ps_Condicion.setInt(1, rsclasifimpuestos.getInt("codigo"));

                                Cambios = "descripcion = ?, identificador = ?";
                                ps_Cambios = _ex_connection.prepareStatement(Cambios);
                                ps_Cambios.setString(1, rsclasifimpuestos.getString("descripcion"));
                                ps_Cambios.setString(2, rsclasifimpuestos.getString("identificador"));

                                Valores = "?, ?, ?";
                                ps_Valores = _ex_connection.prepareStatement(Valores);
                                ps_Valores.setInt(1, rsclasifimpuestos.getInt("codigo"));
                                ps_Valores.setString(2, rsclasifimpuestos.getString("descripcion"));
                                ps_Valores.setString(3, rsclasifimpuestos.getString("identificador"));

                                _ex_SQLQuery = "SELECT * FROM public.fn_editar(?::varchar, ?::varchar, ?::varchar, ?::varchar, ?::varchar, ?::varchar, ?::varchar, ?::varchar, ?::varchar);";
                                ps_ex = _ex_connection.prepareStatement(_ex_SQLQuery);
                                ps_ex.setString(1, tabla);
                                ps_ex.setString(2, ps_Cambios.toString());
                                ps_ex.setString(3, "");
                                ps_ex.setString(4, "");
                                ps_ex.setString(5, ps_Condicion.toString());
                                ps_ex.setString(6, Campos);
                                ps_ex.setString(7, ps_Valores.toString());
                                ps_ex.setString(8, "");
                                ps_ex.setString(9, "");
                                ps_ex.executeQuery();

                                _ex_SQLQuery = "delete from inv_clasifimpuesto_rango where id_clasificacion = ?::integer ;";
                                ps_ex = _ex_connection.prepareStatement(_ex_SQLQuery);
                                ps_ex.setInt(1, rsclasifimpuestos.getInt("codigo"));
                                ps_ex.execute();

                                _SQLQuery = "select * from inv_clasifimpuesto_rango where id_clasificacion = ?::integer";
                                ps_stmt = _connection.prepareStatement(_SQLQuery);
                                ps_stmt.setInt(1, rsclasifimpuestos.getInt("codigo"));

                                rsdetalle = ps_stmt.executeQuery();
                                while (rsdetalle.next()) {
                                    _ex_SQLQuery = "INSERT INTO inv_clasifimpuesto_rango(id_clasificacion, fecha_desde, fecha_hasta, itb_xitbis, itb_yitbis)"
                                            + " VALUES (?, ?, ?, ?, ?);";
                                    ps_ex = _ex_connection.prepareStatement(_ex_SQLQuery);
                                    ps_ex.setInt(1, rsclasifimpuestos.getInt("codigo"));
                                    ps_ex.setDate(2, rsdetalle.getDate("fecha_desde"));
                                    ps_ex.setDate(3, rsdetalle.getDate("fecha_hasta"));
                                    ps_ex.setDouble(4, rsdetalle.getDouble("itb_xitbis"));
                                    ps_ex.setDouble(5, rsdetalle.getDouble("itb_yitbis"));
                                    ps_ex.execute();
                                }

                            }
                            _SQLQuery = "update vtas.clasifimpuestos_cajas set sincronizado = true where codigo = ?::integer "
                                    + " and caja_cod in ( " + this.Cajas + ")";
                            ps_stmt = _connection.prepareStatement(_SQLQuery);
                            ps_stmt.setInt(1, rsclasifimpuestos.getInt("codigo"));
                            ps_stmt.execute();
                            _ex_connection.commit();
                            _connection.commit();
                            _ex_connection.close();
                        }
                    }

                } catch (SQLException ex) {
                    message.setMessage(jtext1, "Caja: " + this.Cajas + " Ocurrio el siguiente error al actualizar los impuestos: " + ex.getMessage());
                    this.b_QueryResult = false;
                    CerrarConexiones();
                    return this.b_QueryResult;
                }
            }
        }
        CerrarConexiones();

        return this.b_QueryResult;
    }

    public boolean ActualizarDepartamentos() {
        PreparedStatement ps_stmt, ps_ex;
        ResultSet rsdepartamentos;

        tabla = "inv_departamentos";
        Campos = " cia_codigo, depa_codigo, depa_nombre, depa_bene1, depa_bene2, "
                + "depa_bene3, depar, nomdep, depa_cueinv, depa_cuevcr, depa_cuevco,  "
                + "depa_cuedvcrmay, depa_cuedvcomen, depa_cuedescmen, depa_cuecoscr,  "
                + "depa_cuecosco, depa_cuebonif, depa_cuedvcrmen, depa_cuedvcomay,  "
                + "depa_cuedescmay, depa_cuedvcr, depa_cuedvco, depa_cuecosdvcr,  "
                + "depa_cuecosdvco, depa_cuedesc, depa_secuencia, cuen_vtagravadascr,  "
                + "cuen_vtagravadasco, cuen_vtaexentascr, cuen_vtaexentasco, cuen_devvtagravadascr,  "
                + "cuen_devvtagravadasco, cuen_devvtaexentascr, cuen_devvtaexentasco,  "
                + "cuen_cosvtagravadascr, cuen_cosvtagravadasco, cuen_cosvtaexentascr,  "
                + "cuen_cosvtaexentasco, cuen_fleteventas, cuen_cosdevvtagravadascr,  "
                + "cuen_cosdevvtagravadasco, cuen_cosdevvtaexentascr, cuen_cosdevvtaexentasco,  "
                + "depa_ajusteprecio, depa_tipoajuste, cuen_descventascredito, cuen_fletecompras,  "
                + "cuen_desccompras, cuen_devcompras, cuen_anticipocompras,  "
                + "cuen_bonostarjpreferenciales, depa_tarjetasolidaridad, depa_decimalesprecio,  "
                + "cuen_montoley, depa_no_bar_restaurant, depa_no_sis_ordenes, depa_imagen,  "
                + "cuen_itbiscontado, incuir_itt,codigo";

        if (openConnection()) {
            getServers();
            try {
                Iterator<Servers> servidor = repo1.lstservidores.iterator();

                while (servidor.hasNext()) {
                    Servers caja = servidor.next();
                    this.SetSlaveConnection(caja.host_name, caja.database_name, caja.port_number, caja.user_name, caja.user_pwd);
                    getCajasLocales();
                    _SQLQuery = "select b.* , c.caja_ip, a.codigo ,a.borrado "
                            + "  from vtas.departamentos_cajas a inner join inv_cajas c on(a.caja_cod = c.caja_cod) "
                            + "  left join inv_departamentos b on (a.codigo = b.codigo )"
                            + "  where b.cia_codigo = ? and a.sincronizado is false and c.caja_cod in (" + Cajas + ")"
                            + "  order by a.borrado desc";
                    ps_stmt = _connection.prepareStatement(_SQLQuery);
                    ps_stmt.setString(1, repo1.Company);
                    rsdepartamentos = ps_stmt.executeQuery();

                    this.SetSlaveConnection(caja.host_name, caja.database_name, caja.port_number, caja.user_name, caja.user_pwd);
                    while (rsdepartamentos.next()) {
                        this.SetCaja(caja.cajas, rsdepartamentos.getString("cia_codigo"));
                        message.setCaption(lblTransaccion, "Caja: " + this.Cajas + " Actualizando departamento : " + rsdepartamentos.getString("depa_nombre"));

                        if (ex_openConnection()) {
                            if (rsdepartamentos.getBoolean("borrado") == true) {
                                _ex_SQLQuery = "delete from inv_departamentos where codigo = ?::integer ";
                                ps_ex = _ex_connection.prepareStatement(_ex_SQLQuery);
                                ps_ex.setInt(1, rsdepartamentos.getInt("codigo"));
                                ps_ex.execute();
                            } else {
                                Condicion = "codigo = ?::integer ";
                                ps_Condicion = _ex_connection.prepareStatement(Condicion);
                                ps_Condicion.setInt(1, rsdepartamentos.getInt("codigo"));

                                Cambios = "depa_codigo=?, depa_nombre=?, depa_bene1=?, depa_bene2=?, "
                                        + " depa_bene3=?, depar=?, nomdep=?, depa_cueinv=?, depa_cuevcr=?, "
                                        + "depa_cuevco=?, depa_cuedvcrmay=?, depa_cuedvcomen=?, depa_cuedescmen=?, "
                                        + "depa_cuecoscr=?, depa_cuecosco=?, depa_cuebonif=?, depa_cuedvcrmen=?, "
                                        + "depa_cuedvcomay=?, depa_cuedescmay=?, depa_cuedvcr=?, depa_cuedvco=?, "
                                        + "depa_cuecosdvcr=?, depa_cuecosdvco=?, depa_cuedesc=?, depa_secuencia=?,"
                                        + "cuen_vtagravadascr=?, cuen_vtagravadasco=?, cuen_vtaexentascr=?, "
                                        + "cuen_vtaexentasco=?, cuen_devvtagravadascr=?, cuen_devvtagravadasco=?, "
                                        + "cuen_devvtaexentascr=?, cuen_devvtaexentasco=?, cuen_cosvtagravadascr=?, "
                                        + "cuen_cosvtagravadasco=?, cuen_cosvtaexentascr=?, cuen_cosvtaexentasco=?, "
                                        + "cuen_fleteventas=?, cuen_cosdevvtagravadascr=?, cuen_cosdevvtagravadasco=?, "
                                        + "cuen_cosdevvtaexentascr=?, cuen_cosdevvtaexentasco=?, depa_ajusteprecio=?, "
                                        + "depa_tipoajuste=?, cuen_descventascredito=?, cuen_fletecompras=?, "
                                        + "cuen_desccompras=?, cuen_devcompras=?, cuen_anticipocompras=?, "
                                        + "cuen_bonostarjpreferenciales=?, depa_tarjetasolidaridad=?, depa_decimalesprecio=?, "
                                        + "cuen_montoley=?, depa_no_bar_restaurant=?, depa_no_sis_ordenes=?, "
                                        + "depa_imagen=?, cuen_itbiscontado=?, incuir_itt=?";
                                ps_Cambios = _ex_connection.prepareStatement(Cambios);
                                ps_Cambios.setString(1, rsdepartamentos.getString("depa_codigo"));
                                ps_Cambios.setString(2, rsdepartamentos.getString("depa_nombre"));
                                ps_Cambios.setDouble(3, rsdepartamentos.getDouble("depa_bene1"));
                                ps_Cambios.setDouble(4, rsdepartamentos.getDouble("depa_bene2"));
                                ps_Cambios.setDouble(5, rsdepartamentos.getDouble("depa_bene3"));
                                ps_Cambios.setDouble(6, rsdepartamentos.getDouble("depar"));
                                ps_Cambios.setString(7, rsdepartamentos.getString("nomdep"));
                                ps_Cambios.setString(8, rsdepartamentos.getString("depa_cueinv"));
                                ps_Cambios.setString(9, rsdepartamentos.getString("depa_cuevcr"));
                                ps_Cambios.setString(10, rsdepartamentos.getString("depa_cuevco"));
                                ps_Cambios.setString(11, rsdepartamentos.getString("depa_cuedvcrmay"));
                                ps_Cambios.setString(12, rsdepartamentos.getString("depa_cuedvcomen"));
                                ps_Cambios.setString(13, rsdepartamentos.getString("depa_cuedescmen"));
                                ps_Cambios.setString(14, rsdepartamentos.getString("depa_cuecoscr"));
                                ps_Cambios.setString(15, rsdepartamentos.getString("depa_cuecosco"));
                                ps_Cambios.setString(16, rsdepartamentos.getString("depa_cuebonif"));
                                ps_Cambios.setString(17, rsdepartamentos.getString("depa_cuedvcrmen"));
                                ps_Cambios.setString(18, rsdepartamentos.getString("depa_cuedvcomay"));
                                ps_Cambios.setString(19, rsdepartamentos.getString("depa_cuedescmay"));
                                ps_Cambios.setString(20, rsdepartamentos.getString("depa_cuedvcr"));
                                ps_Cambios.setString(21, rsdepartamentos.getString("depa_cuedvco"));
                                ps_Cambios.setString(22, rsdepartamentos.getString("depa_cuecosdvcr"));
                                ps_Cambios.setString(23, rsdepartamentos.getString("depa_cuecosdvco"));
                                ps_Cambios.setString(24, rsdepartamentos.getString("depa_cuedesc"));
                                ps_Cambios.setInt(25, rsdepartamentos.getInt("depa_secuencia"));
                                ps_Cambios.setString(26, rsdepartamentos.getString("cuen_vtagravadascr"));
                                ps_Cambios.setString(27, rsdepartamentos.getString("cuen_vtagravadasco"));
                                ps_Cambios.setString(28, rsdepartamentos.getString("cuen_vtaexentascr"));
                                ps_Cambios.setString(29, rsdepartamentos.getString("cuen_vtaexentasco"));
                                ps_Cambios.setString(30, rsdepartamentos.getString("cuen_devvtagravadascr"));
                                ps_Cambios.setString(31, rsdepartamentos.getString("cuen_devvtagravadasco"));
                                ps_Cambios.setString(32, rsdepartamentos.getString("cuen_devvtaexentascr"));
                                ps_Cambios.setString(33, rsdepartamentos.getString("cuen_devvtaexentasco"));
                                ps_Cambios.setString(34, rsdepartamentos.getString("cuen_cosvtagravadascr"));
                                ps_Cambios.setString(35, rsdepartamentos.getString("cuen_cosvtagravadasco"));
                                ps_Cambios.setString(36, rsdepartamentos.getString("cuen_cosvtaexentascr"));
                                ps_Cambios.setString(37, rsdepartamentos.getString("cuen_cosvtaexentasco"));
                                ps_Cambios.setString(38, rsdepartamentos.getString("cuen_fleteventas"));
                                ps_Cambios.setString(39, rsdepartamentos.getString("cuen_cosdevvtagravadascr"));
                                ps_Cambios.setString(40, rsdepartamentos.getString("cuen_cosdevvtagravadasco"));
                                ps_Cambios.setString(41, rsdepartamentos.getString("cuen_cosdevvtaexentascr"));
                                ps_Cambios.setString(42, rsdepartamentos.getString("cuen_cosdevvtaexentasco"));
                                ps_Cambios.setInt(43, rsdepartamentos.getInt("depa_ajusteprecio"));
                                ps_Cambios.setInt(44, rsdepartamentos.getInt("depa_tipoajuste"));
                                ps_Cambios.setString(45, rsdepartamentos.getString("cuen_descventascredito"));
                                ps_Cambios.setString(46, rsdepartamentos.getString("cuen_fletecompras"));
                                ps_Cambios.setString(47, rsdepartamentos.getString("cuen_desccompras"));
                                ps_Cambios.setString(48, rsdepartamentos.getString("cuen_devcompras"));
                                ps_Cambios.setString(49, rsdepartamentos.getString("cuen_anticipocompras"));
                                ps_Cambios.setString(50, rsdepartamentos.getString("cuen_bonostarjpreferenciales"));
                                ps_Cambios.setBoolean(51, rsdepartamentos.getBoolean("depa_tarjetasolidaridad"));
                                ps_Cambios.setInt(52, rsdepartamentos.getInt("depa_decimalesprecio"));
                                ps_Cambios.setString(53, rsdepartamentos.getString("cuen_montoley"));
                                ps_Cambios.setBoolean(54, rsdepartamentos.getBoolean("depa_no_bar_restaurant"));
                                ps_Cambios.setBoolean(55, rsdepartamentos.getBoolean("depa_no_sis_ordenes"));
                                ps_Cambios.setString(56, rsdepartamentos.getString("depa_imagen"));
                                ps_Cambios.setString(57, rsdepartamentos.getString("cuen_itbiscontado"));
                                ps_Cambios.setBoolean(58, rsdepartamentos.getBoolean("incuir_itt"));

                                Valores = " ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?,"
                                        + " ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?,"
                                        + " ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?,"
                                        + " ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?,"
                                        + " ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?,"
                                        + " ?, ?, ?, ?, ?";
                                ps_Valores = _ex_connection.prepareStatement(Valores);
                                ps_Valores.setString(1, rsdepartamentos.getString("cia_codigo"));
                                ps_Valores.setString(2, rsdepartamentos.getString("depa_codigo"));
                                ps_Valores.setString(3, rsdepartamentos.getString("depa_nombre"));
                                ps_Valores.setDouble(4, rsdepartamentos.getDouble("depa_bene1"));
                                ps_Valores.setDouble(5, rsdepartamentos.getDouble("depa_bene2"));
                                ps_Valores.setDouble(6, rsdepartamentos.getDouble("depa_bene3"));
                                ps_Valores.setDouble(7, rsdepartamentos.getDouble("depar"));
                                ps_Valores.setString(8, rsdepartamentos.getString("nomdep"));
                                ps_Valores.setString(9, rsdepartamentos.getString("depa_cueinv"));
                                ps_Valores.setString(10, rsdepartamentos.getString("depa_cuevcr"));
                                ps_Valores.setString(11, rsdepartamentos.getString("depa_cuevco"));
                                ps_Valores.setString(12, rsdepartamentos.getString("depa_cuedvcrmay"));
                                ps_Valores.setString(13, rsdepartamentos.getString("depa_cuedvcomen"));
                                ps_Valores.setString(14, rsdepartamentos.getString("depa_cuedescmen"));
                                ps_Valores.setString(15, rsdepartamentos.getString("depa_cuecoscr"));
                                ps_Valores.setString(16, rsdepartamentos.getString("depa_cuecosco"));
                                ps_Valores.setString(17, rsdepartamentos.getString("depa_cuebonif"));
                                ps_Valores.setString(18, rsdepartamentos.getString("depa_cuedvcrmen"));
                                ps_Valores.setString(19, rsdepartamentos.getString("depa_cuedvcomay"));
                                ps_Valores.setString(20, rsdepartamentos.getString("depa_cuedescmay"));
                                ps_Valores.setString(21, rsdepartamentos.getString("depa_cuedvcr"));
                                ps_Valores.setString(22, rsdepartamentos.getString("depa_cuedvco"));
                                ps_Valores.setString(23, rsdepartamentos.getString("depa_cuecosdvcr"));
                                ps_Valores.setString(24, rsdepartamentos.getString("depa_cuecosdvco"));
                                ps_Valores.setString(25, rsdepartamentos.getString("depa_cuedesc"));
                                ps_Valores.setInt(26, rsdepartamentos.getInt("depa_secuencia"));
                                ps_Valores.setString(27, rsdepartamentos.getString("cuen_vtagravadascr"));
                                ps_Valores.setString(28, rsdepartamentos.getString("cuen_vtagravadasco"));
                                ps_Valores.setString(29, rsdepartamentos.getString("cuen_vtaexentascr"));
                                ps_Valores.setString(30, rsdepartamentos.getString("cuen_vtaexentasco"));
                                ps_Valores.setString(31, rsdepartamentos.getString("cuen_devvtagravadascr"));
                                ps_Valores.setString(32, rsdepartamentos.getString("cuen_devvtagravadasco"));
                                ps_Valores.setString(33, rsdepartamentos.getString("cuen_devvtaexentascr"));
                                ps_Valores.setString(34, rsdepartamentos.getString("cuen_devvtaexentasco"));
                                ps_Valores.setString(35, rsdepartamentos.getString("cuen_cosvtagravadascr"));
                                ps_Valores.setString(36, rsdepartamentos.getString("cuen_cosvtagravadasco"));
                                ps_Valores.setString(37, rsdepartamentos.getString("cuen_cosvtaexentascr"));
                                ps_Valores.setString(38, rsdepartamentos.getString("cuen_cosvtaexentasco"));
                                ps_Valores.setString(39, rsdepartamentos.getString("cuen_fleteventas"));
                                ps_Valores.setString(40, rsdepartamentos.getString("cuen_cosdevvtagravadascr"));
                                ps_Valores.setString(41, rsdepartamentos.getString("cuen_cosdevvtagravadasco"));
                                ps_Valores.setString(42, rsdepartamentos.getString("cuen_cosdevvtaexentascr"));
                                ps_Valores.setString(43, rsdepartamentos.getString("cuen_cosdevvtaexentasco"));
                                ps_Valores.setInt(44, rsdepartamentos.getInt("depa_ajusteprecio"));
                                ps_Valores.setInt(45, rsdepartamentos.getInt("depa_tipoajuste"));
                                ps_Valores.setString(46, rsdepartamentos.getString("cuen_descventascredito"));
                                ps_Valores.setString(47, rsdepartamentos.getString("cuen_fletecompras"));
                                ps_Valores.setString(48, rsdepartamentos.getString("cuen_desccompras"));
                                ps_Valores.setString(49, rsdepartamentos.getString("cuen_devcompras"));
                                ps_Valores.setString(50, rsdepartamentos.getString("cuen_anticipocompras"));
                                ps_Valores.setString(51, rsdepartamentos.getString("cuen_bonostarjpreferenciales"));
                                ps_Valores.setBoolean(52, rsdepartamentos.getBoolean("depa_tarjetasolidaridad"));
                                ps_Valores.setInt(53, rsdepartamentos.getInt("depa_decimalesprecio"));
                                ps_Valores.setString(54, rsdepartamentos.getString("cuen_montoley"));
                                ps_Valores.setBoolean(55, rsdepartamentos.getBoolean("depa_no_bar_restaurant"));
                                ps_Valores.setBoolean(56, rsdepartamentos.getBoolean("depa_no_sis_ordenes"));
                                ps_Valores.setString(57, rsdepartamentos.getString("depa_imagen"));
                                ps_Valores.setString(58, rsdepartamentos.getString("cuen_itbiscontado"));
                                ps_Valores.setBoolean(59, rsdepartamentos.getBoolean("incuir_itt"));
                                ps_Valores.setInt(60, rsdepartamentos.getInt("codigo"));

                                _ex_SQLQuery = "SELECT * FROM public.fn_editar(?::varchar, ?::varchar, ?::varchar, ?::varchar, ?::varchar, ?::varchar, ?::varchar, ?::varchar, ?::varchar);";
                                ps_ex = _ex_connection.prepareStatement(_ex_SQLQuery);
                                ps_ex.setString(1, tabla);
                                ps_ex.setString(2, ps_Cambios.toString());
                                ps_ex.setString(3, "");
                                ps_ex.setString(4, "");
                                ps_ex.setString(5, ps_Condicion.toString());
                                ps_ex.setString(6, Campos);
                                ps_ex.setString(7, ps_Valores.toString());
                                ps_ex.setString(8, "");
                                ps_ex.setString(9, "");
                                ps_ex.executeQuery();

                            }
                            _SQLQuery = "update vtas.departamentos_cajas set sincronizado = true where codigo = ?::integer "
                                    + " and caja_cod in ( " + this.Cajas + ")";
                            ps_stmt = _connection.prepareStatement(_SQLQuery);
                            ps_stmt.setInt(1, rsdepartamentos.getInt("codigo"));
                            ps_stmt.execute();
                            _ex_connection.commit();
                            _connection.commit();
                            _ex_connection.close();
                        }
                    }

                }
            } catch (SQLException ex) {
                message.setMessage(jtext1, "Caja: " + this.Cajas + " Ocurrio el siguiente error al actualizar los departamentos: " + ex.getMessage());
                this.b_QueryResult = false;
                CerrarConexiones();
                return this.b_QueryResult;
            }

        }
        CerrarConexiones();

        return this.b_QueryResult;
    }

    public boolean ActualizarSubDepartamentos() {
        PreparedStatement ps_stmt, ps_ex;
        ResultSet rssubdepartamentos;

        tabla = "inv_sub_departamentos";
        Campos = "cia_codigo, depa_codigo, sdepa_codigo, sdepa_bene1, sdepa_bene2, "
                + "sdepa_bene3, sdepa_nombre, sdepa_cueinv, sdepa_cuevcr, sdepa_cuevco, "
                + "sdepa_cuedvcr, sdepa_cuedvco, sdepa_cuedesc, sdepa_cuecoscr,  "
                + "sdepa_cuecosco, sdepa_status, depar, sdepar, nomsdep, marg1,  "
                + "marg2, marg3, sdepa_bene4, descuento, ptos_tarpref, sdepa_secuencia, codigo";
        getServers();
        if (openConnection()) {

            try {
                Iterator<Servers> servidor = repo1.lstservidores.iterator();

                while (servidor.hasNext()) {
                    Servers caja = servidor.next();
                    this.SetSlaveConnection(caja.host_name, caja.database_name, caja.port_number, caja.user_name, caja.user_pwd);
                    getCajasLocales();
                    _SQLQuery = "select b.* , c.caja_ip, a.codigo as codigo_subdepa ,a.borrado "
                            + "  from vtas.subdepartamentos_cajas a inner join inv_cajas c on(a.caja_cod = c.caja_cod) "
                            + "  left join inv_sub_departamentos b on (a.codigo = b.codigo )"
                            + "  where b.cia_codigo = ? and a.sincronizado is false and c.caja_cod in (" + Cajas + ")"
                            + "  order by a.borrado desc";
                    ps_stmt = _connection.prepareStatement(_SQLQuery);
                    ps_stmt.setString(1, repo1.Company);
                    rssubdepartamentos = ps_stmt.executeQuery();

                    while (rssubdepartamentos.next()) {
                        this.SetCaja(caja.cajas, rssubdepartamentos.getString("cia_codigo"));
                        message.setCaption(lblTransaccion, "Caja: " + this.Cajas + " Actualizando sub-departamento : " + rssubdepartamentos.getString("sdepa_nombre"));

                        if (ex_openConnection()) {
                            if (rssubdepartamentos.getBoolean("borrado") == true) {
                                _ex_SQLQuery = "delete from inv_sub_departamentos where codigo = ?::integer ";
                                ps_ex = _ex_connection.prepareStatement(_ex_SQLQuery);
                                ps_ex.setInt(1, rssubdepartamentos.getInt("codigo_subdepa"));
                                ps_ex.execute();
                            } else {
                                Condicion = "codigo = ?::integer ";
                                ps_Condicion = _ex_connection.prepareStatement(Condicion);
                                ps_Condicion.setInt(1, rssubdepartamentos.getInt("codigo_subdepa"));

                                Cambios = "sdepa_bene1=?, sdepa_bene2=?, "
                                        + "sdepa_bene3=?, sdepa_nombre=?, sdepa_cueinv=?, sdepa_cuevcr=?,  "
                                        + "sdepa_cuevco=?, sdepa_cuedvcr=?, sdepa_cuedvco=?, sdepa_cuedesc=?,  "
                                        + "sdepa_cuecoscr=?, sdepa_cuecosco=?, sdepa_status=?, depar=?,  "
                                        + "sdepar=?, nomsdep=?, marg1=?, marg2=?, marg3=?, sdepa_bene4=?,  "
                                        + "descuento=?, ptos_tarpref=?, sdepa_secuencia=?";

                                ps_Cambios = _ex_connection.prepareStatement(Cambios);
                                ps_Cambios.setDouble(1, rssubdepartamentos.getDouble("sdepa_bene1"));
                                ps_Cambios.setDouble(2, rssubdepartamentos.getDouble("sdepa_bene2"));
                                ps_Cambios.setDouble(3, rssubdepartamentos.getDouble("sdepa_bene3"));
                                ps_Cambios.setString(4, rssubdepartamentos.getString("sdepa_nombre"));
                                ps_Cambios.setString(5, rssubdepartamentos.getString("sdepa_cueinv"));
                                ps_Cambios.setString(6, rssubdepartamentos.getString("sdepa_cuevcr"));
                                ps_Cambios.setString(7, rssubdepartamentos.getString("sdepa_cuevco"));
                                ps_Cambios.setString(8, rssubdepartamentos.getString("sdepa_cuedvcr"));
                                ps_Cambios.setString(9, rssubdepartamentos.getString("sdepa_cuedvco"));
                                ps_Cambios.setString(10, rssubdepartamentos.getString("sdepa_cuedesc"));
                                ps_Cambios.setString(11, rssubdepartamentos.getString("sdepa_cuecoscr"));
                                ps_Cambios.setString(12, rssubdepartamentos.getString("sdepa_cuecosco"));
                                ps_Cambios.setString(13, rssubdepartamentos.getString("sdepa_status"));
                                ps_Cambios.setDouble(14, rssubdepartamentos.getDouble("depar"));
                                ps_Cambios.setDouble(15, rssubdepartamentos.getDouble("sdepar"));
                                ps_Cambios.setString(16, rssubdepartamentos.getString("nomsdep"));
                                ps_Cambios.setDouble(17, rssubdepartamentos.getDouble("marg1"));
                                ps_Cambios.setDouble(18, rssubdepartamentos.getDouble("marg2"));
                                ps_Cambios.setDouble(19, rssubdepartamentos.getDouble("marg3"));
                                ps_Cambios.setDouble(20, rssubdepartamentos.getDouble("sdepa_bene4"));
                                ps_Cambios.setDouble(21, rssubdepartamentos.getDouble("descuento"));
                                ps_Cambios.setInt(22, rssubdepartamentos.getInt("ptos_tarpref"));
                                ps_Cambios.setInt(23, rssubdepartamentos.getInt("sdepa_secuencia"));

                                Valores = " ?, ?, ?, ?, ?, "
                                        + " ?, ?, ?, ?, ?, "
                                        + " ?, ?, ?, ?, "
                                        + " ?, ?, ?, ?, ?, ?, "
                                        + " ?, ?, ?, ?, ?, ?, "
                                        + " ?";
                                ps_Valores = _ex_connection.prepareStatement(Valores);
                                ps_Valores.setString(1, rssubdepartamentos.getString("cia_codigo"));
                                ps_Valores.setString(2, rssubdepartamentos.getString("depa_codigo"));
                                ps_Valores.setString(3, rssubdepartamentos.getString("sdepa_codigo"));
                                ps_Valores.setDouble(4, rssubdepartamentos.getDouble("sdepa_bene1"));
                                ps_Valores.setDouble(5, rssubdepartamentos.getDouble("sdepa_bene2"));
                                ps_Valores.setDouble(6, rssubdepartamentos.getDouble("sdepa_bene3"));
                                ps_Valores.setString(7, rssubdepartamentos.getString("sdepa_nombre"));
                                ps_Valores.setString(8, rssubdepartamentos.getString("sdepa_cueinv"));
                                ps_Valores.setString(9, rssubdepartamentos.getString("sdepa_cuevcr"));
                                ps_Valores.setString(10, rssubdepartamentos.getString("sdepa_cuevco"));
                                ps_Valores.setString(11, rssubdepartamentos.getString("sdepa_cuedvcr"));
                                ps_Valores.setString(12, rssubdepartamentos.getString("sdepa_cuedvco"));
                                ps_Valores.setString(13, rssubdepartamentos.getString("sdepa_cuedesc"));
                                ps_Valores.setString(14, rssubdepartamentos.getString("sdepa_cuecoscr"));
                                ps_Valores.setString(15, rssubdepartamentos.getString("sdepa_cuecosco"));
                                ps_Valores.setString(16, rssubdepartamentos.getString("sdepa_status"));
                                ps_Valores.setDouble(17, rssubdepartamentos.getDouble("depar"));
                                ps_Valores.setDouble(18, rssubdepartamentos.getDouble("sdepar"));
                                ps_Valores.setString(19, rssubdepartamentos.getString("nomsdep"));
                                ps_Valores.setDouble(20, rssubdepartamentos.getDouble("marg1"));
                                ps_Valores.setDouble(21, rssubdepartamentos.getDouble("marg2"));
                                ps_Valores.setDouble(22, rssubdepartamentos.getDouble("marg3"));
                                ps_Valores.setDouble(23, rssubdepartamentos.getDouble("sdepa_bene4"));
                                ps_Valores.setDouble(24, rssubdepartamentos.getDouble("descuento"));
                                ps_Valores.setInt(25, rssubdepartamentos.getInt("ptos_tarpref"));
                                ps_Valores.setInt(26, rssubdepartamentos.getInt("sdepa_secuencia"));
                                ps_Valores.setInt(27, rssubdepartamentos.getInt("codigo"));

                                _ex_SQLQuery = "SELECT * FROM public.fn_editar(?::varchar, ?::varchar, ?::varchar, ?::varchar, ?::varchar, ?::varchar, ?::varchar, ?::varchar, ?::varchar);";
                                ps_ex = _ex_connection.prepareStatement(_ex_SQLQuery);
                                ps_ex.setString(1, tabla);
                                ps_ex.setString(2, ps_Cambios.toString());
                                ps_ex.setString(3, "");
                                ps_ex.setString(4, "");
                                ps_ex.setString(5, ps_Condicion.toString());
                                ps_ex.setString(6, Campos);
                                ps_ex.setString(7, ps_Valores.toString());
                                ps_ex.setString(8, "");
                                ps_ex.setString(9, "");
                                ps_ex.executeQuery();

                            }
                            _SQLQuery = "update vtas.subdepartamentos_cajas set sincronizado = true where codigo = ?::integer "
                                    + " and caja_cod in (" + this.Cajas + ")";
                            ps_stmt = _connection.prepareStatement(_SQLQuery);
                            ps_stmt.setInt(1, rssubdepartamentos.getInt("codigo_subdepa"));
                            ps_stmt.execute();
                            _ex_connection.commit();
                            _connection.commit();
                            _ex_connection.close();
                        }
                    }

                }
            } catch (SQLException ex) {
                message.setMessage(jtext1, "Caja: " + this.Cajas + " Ocurrio el siguiente error al actualizar los sub-departamentos: " + ex.getMessage());
                this.b_QueryResult = false;
                CerrarConexiones();
                return this.b_QueryResult;
            }

        }
        CerrarConexiones();

        return this.b_QueryResult;
    }

    public boolean ActualizarFamilias() {
        PreparedStatement ps_stmt, ps_ex;
        ResultSet rsfamilias;

        tabla = "inv_claves";
        Campos = "cia_codigo, clave_codigo, clave_nombre, clave_marca, local_p1,"
                + "local_p2, local_p3, local_p4, impor_p1, impor_p2, impor_p3, impor_p4,"
                + "clave_secuencia, cuen_vtagravadascr, cuen_vtagravadasco, cuen_vtaexentascr, "
                + "cuen_vtaexentasco, cuen_devvtagravadascr, cuen_devvtagravadasco, "
                + "cuen_devvtaexentascr, cuen_devvtaexentasco, cuen_cosvtagravadascr, "
                + "cuen_cosvtagravadasco, cuen_cosvtaexentascr, cuen_cosvtaexentasco, "
                + "cuen_fleteventas, cuen_descventas, cuen_invproductos, clave_cuenbonif, "
                + "cuen_cosdevvtagravadascr, cuen_cosdevvtagravadasco, cuen_cosdevvtaexentascr, "
                + "cuen_cosdevvtaexentasco, cuen_descventascredito, cuen_fletecompras, "
                + "cuen_desccompras, cuen_devcompras, cuen_anticipocompras, "
                + "cuen_bonostarjpreferenciales, cuen_montoley, clave_no_puntos, "
                + "cuen_itbiscontado, codigo";
        getServers();
        if (openConnection()) {

            try {
                Iterator<Servers> servidor = repo1.lstservidores.iterator();

                while (servidor.hasNext()) {
                    Servers caja = servidor.next();
                    this.SetSlaveConnection(caja.host_name, caja.database_name, caja.port_number, caja.user_name, caja.user_pwd);
                    getCajasLocales();
                    _SQLQuery = "select b.* , c.caja_ip, a.codigo as codigo_familia ,a.borrado "
                            + "  from vtas.familias_cajas a inner join inv_cajas c on(a.caja_cod = c.caja_cod) "
                            + "  left join inv_claves b on (a.codigo = b.codigo )"
                            + "  where b.cia_codigo = ? and a.sincronizado is false and c.caja_cod in(" + Cajas + ")"
                            + "  order by a.borrado desc";
                    ps_stmt = _connection.prepareStatement(_SQLQuery);
                    ps_stmt.setString(1, repo1.Company);
                    rsfamilias = ps_stmt.executeQuery();

                    while (rsfamilias.next()) {
                        this.SetCaja(caja.cajas, rsfamilias.getString("cia_codigo"));
                        message.setCaption(lblTransaccion, "Caja: " + this.Cajas + " Actualizando familia : " + rsfamilias.getString("clave_nombre"));

                        if (ex_openConnection()) {
                            if (rsfamilias.getBoolean("borrado") == true) {
                                _ex_SQLQuery = "delete from inv_claves where codigo = ?::integer ";
                                ps_ex = _ex_connection.prepareStatement(_ex_SQLQuery);
                                ps_ex.setInt(1, rsfamilias.getInt("codigo_familia"));
                                ps_ex.execute();
                            } else {
                                Condicion = "codigo = ?::integer ";
                                ps_Condicion = _ex_connection.prepareStatement(Condicion);
                                ps_Condicion.setInt(1, rsfamilias.getInt("codigo"));

                                Cambios = "clave_nombre=?, clave_marca=?, "
                                        + "local_p1=?, local_p2=?, local_p3=?, local_p4=?, impor_p1=?, impor_p2=?, "
                                        + "impor_p3=?, impor_p4=?, clave_secuencia=?, cuen_vtagravadascr=?, "
                                        + "cuen_vtagravadasco=?, cuen_vtaexentascr=?, cuen_vtaexentasco=?, "
                                        + "cuen_devvtagravadascr=?, cuen_devvtagravadasco=?, cuen_devvtaexentascr=?, "
                                        + "cuen_devvtaexentasco=?, cuen_cosvtagravadascr=?, cuen_cosvtagravadasco=?, "
                                        + "cuen_cosvtaexentascr=?, cuen_cosvtaexentasco=?, cuen_fleteventas=?, "
                                        + "cuen_descventas=?, cuen_invproductos=?, clave_cuenbonif=?, cuen_cosdevvtagravadascr=?, "
                                        + "cuen_cosdevvtagravadasco=?, cuen_cosdevvtaexentascr=?, cuen_cosdevvtaexentasco=?, "
                                        + "cuen_descventascredito=?, cuen_fletecompras=?, cuen_desccompras=?, "
                                        + "cuen_devcompras=?, cuen_anticipocompras=?, cuen_bonostarjpreferenciales=?, "
                                        + "cuen_montoley=?, clave_no_puntos=?, cuen_itbiscontado=?";

                                ps_Cambios = _ex_connection.prepareStatement(Cambios);
                                ps_Cambios.setString(1, rsfamilias.getString("clave_nombre"));
                                ps_Cambios.setString(2, rsfamilias.getString("clave_marca"));
                                ps_Cambios.setDouble(3, rsfamilias.getDouble("local_p1"));
                                ps_Cambios.setDouble(4, rsfamilias.getDouble("local_p2"));
                                ps_Cambios.setDouble(5, rsfamilias.getDouble("local_p3"));
                                ps_Cambios.setDouble(6, rsfamilias.getDouble("local_p4"));
                                ps_Cambios.setDouble(7, rsfamilias.getDouble("impor_p1"));
                                ps_Cambios.setDouble(8, rsfamilias.getDouble("impor_p2"));
                                ps_Cambios.setDouble(9, rsfamilias.getDouble("impor_p3"));
                                ps_Cambios.setDouble(10, rsfamilias.getDouble("impor_p4"));
                                ps_Cambios.setInt(11, rsfamilias.getInt("clave_secuencia"));
                                ps_Cambios.setString(12, rsfamilias.getString("cuen_vtagravadascr"));
                                ps_Cambios.setString(13, rsfamilias.getString("cuen_vtagravadasco"));
                                ps_Cambios.setString(14, rsfamilias.getString("cuen_vtaexentascr"));
                                ps_Cambios.setString(15, rsfamilias.getString("cuen_vtaexentasco"));
                                ps_Cambios.setString(16, rsfamilias.getString("cuen_devvtagravadascr"));
                                ps_Cambios.setString(17, rsfamilias.getString("cuen_devvtagravadasco"));
                                ps_Cambios.setString(18, rsfamilias.getString("cuen_devvtaexentascr"));
                                ps_Cambios.setString(19, rsfamilias.getString("cuen_devvtaexentasco"));
                                ps_Cambios.setString(20, rsfamilias.getString("cuen_cosvtagravadascr"));
                                ps_Cambios.setString(21, rsfamilias.getString("cuen_cosvtagravadasco"));
                                ps_Cambios.setString(22, rsfamilias.getString("cuen_cosvtaexentascr"));
                                ps_Cambios.setString(23, rsfamilias.getString("cuen_cosvtaexentasco"));
                                ps_Cambios.setString(24, rsfamilias.getString("cuen_fleteventas"));
                                ps_Cambios.setString(25, rsfamilias.getString("cuen_descventas"));
                                ps_Cambios.setString(26, rsfamilias.getString("cuen_invproductos"));
                                ps_Cambios.setString(27, rsfamilias.getString("clave_cuenbonif"));
                                ps_Cambios.setString(28, rsfamilias.getString("cuen_cosdevvtagravadascr"));
                                ps_Cambios.setString(29, rsfamilias.getString("cuen_cosdevvtagravadasco"));
                                ps_Cambios.setString(30, rsfamilias.getString("cuen_cosdevvtaexentascr"));
                                ps_Cambios.setString(31, rsfamilias.getString("cuen_cosdevvtaexentasco"));
                                ps_Cambios.setString(32, rsfamilias.getString("cuen_descventascredito"));
                                ps_Cambios.setString(33, rsfamilias.getString("cuen_fletecompras"));
                                ps_Cambios.setString(34, rsfamilias.getString("cuen_desccompras"));
                                ps_Cambios.setString(35, rsfamilias.getString("cuen_devcompras"));
                                ps_Cambios.setString(36, rsfamilias.getString("cuen_anticipocompras"));
                                ps_Cambios.setString(37, rsfamilias.getString("cuen_bonostarjpreferenciales"));
                                ps_Cambios.setString(38, rsfamilias.getString("cuen_montoley"));
                                ps_Cambios.setBoolean(39, rsfamilias.getBoolean("clave_no_puntos"));
                                ps_Cambios.setString(40, rsfamilias.getString("cuen_itbiscontado"));

                                Valores = "?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?,"
                                        + "?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, "
                                        + "?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?,"
                                        + "?, ?, ?, ?, ?, ?,?";
                                ps_Valores = _ex_connection.prepareStatement(Valores);
                                ps_Valores.setString(1, rsfamilias.getString("cia_codigo"));
                                ps_Valores.setString(2, rsfamilias.getString("clave_codigo"));
                                ps_Valores.setString(3, rsfamilias.getString("clave_nombre"));
                                ps_Valores.setString(4, rsfamilias.getString("clave_marca"));
                                ps_Valores.setDouble(5, rsfamilias.getDouble("local_p1"));
                                ps_Valores.setDouble(6, rsfamilias.getDouble("local_p2"));
                                ps_Valores.setDouble(7, rsfamilias.getDouble("local_p3"));
                                ps_Valores.setDouble(8, rsfamilias.getDouble("local_p4"));
                                ps_Valores.setDouble(9, rsfamilias.getDouble("impor_p1"));
                                ps_Valores.setDouble(10, rsfamilias.getDouble("impor_p2"));
                                ps_Valores.setDouble(11, rsfamilias.getDouble("impor_p3"));
                                ps_Valores.setDouble(12, rsfamilias.getDouble("impor_p4"));
                                ps_Valores.setInt(13, rsfamilias.getInt("clave_secuencia"));
                                ps_Valores.setString(14, rsfamilias.getString("cuen_vtagravadascr"));
                                ps_Valores.setString(15, rsfamilias.getString("cuen_vtagravadasco"));
                                ps_Valores.setString(16, rsfamilias.getString("cuen_vtaexentascr"));
                                ps_Valores.setString(17, rsfamilias.getString("cuen_vtaexentasco"));
                                ps_Valores.setString(18, rsfamilias.getString("cuen_devvtagravadascr"));
                                ps_Valores.setString(19, rsfamilias.getString("cuen_devvtagravadasco"));
                                ps_Valores.setString(20, rsfamilias.getString("cuen_devvtaexentascr"));
                                ps_Valores.setString(21, rsfamilias.getString("cuen_devvtaexentasco"));
                                ps_Valores.setString(22, rsfamilias.getString("cuen_cosvtagravadascr"));
                                ps_Valores.setString(23, rsfamilias.getString("cuen_cosvtagravadasco"));
                                ps_Valores.setString(24, rsfamilias.getString("cuen_cosvtaexentascr"));
                                ps_Valores.setString(25, rsfamilias.getString("cuen_cosvtaexentasco"));
                                ps_Valores.setString(26, rsfamilias.getString("cuen_fleteventas"));
                                ps_Valores.setString(27, rsfamilias.getString("cuen_descventas"));
                                ps_Valores.setString(28, rsfamilias.getString("cuen_invproductos"));
                                ps_Valores.setString(29, rsfamilias.getString("clave_cuenbonif"));
                                ps_Valores.setString(30, rsfamilias.getString("cuen_cosdevvtagravadascr"));
                                ps_Valores.setString(31, rsfamilias.getString("cuen_cosdevvtagravadasco"));
                                ps_Valores.setString(32, rsfamilias.getString("cuen_cosdevvtaexentascr"));
                                ps_Valores.setString(33, rsfamilias.getString("cuen_cosdevvtaexentasco"));
                                ps_Valores.setString(34, rsfamilias.getString("cuen_descventascredito"));
                                ps_Valores.setString(35, rsfamilias.getString("cuen_fletecompras"));
                                ps_Valores.setString(36, rsfamilias.getString("cuen_desccompras"));
                                ps_Valores.setString(37, rsfamilias.getString("cuen_devcompras"));
                                ps_Valores.setString(38, rsfamilias.getString("cuen_anticipocompras"));
                                ps_Valores.setString(39, rsfamilias.getString("cuen_bonostarjpreferenciales"));
                                ps_Valores.setString(40, rsfamilias.getString("cuen_montoley"));
                                ps_Valores.setBoolean(41, rsfamilias.getBoolean("clave_no_puntos"));
                                ps_Valores.setString(42, rsfamilias.getString("cuen_itbiscontado"));
                                ps_Valores.setInt(43, rsfamilias.getInt("codigo"));

                                _ex_SQLQuery = "SELECT * FROM public.fn_editar(?::varchar, ?::varchar, ?::varchar, ?::varchar, ?::varchar, ?::varchar, ?::varchar, ?::varchar, ?::varchar);";
                                ps_ex = _ex_connection.prepareStatement(_ex_SQLQuery);
                                ps_ex.setString(1, tabla);
                                ps_ex.setString(2, ps_Cambios.toString());
                                ps_ex.setString(3, "");
                                ps_ex.setString(4, "");
                                ps_ex.setString(5, ps_Condicion.toString());
                                ps_ex.setString(6, Campos);
                                ps_ex.setString(7, ps_Valores.toString());
                                ps_ex.setString(8, "");
                                ps_ex.setString(9, "");
                                ps_ex.executeQuery();

                            }
                            _SQLQuery = "update vtas.familias_cajas set sincronizado = true where codigo = ?::integer "
                                    + " and caja_cod in(" + this.Cajas + ") ";
                            ps_stmt = _connection.prepareStatement(_SQLQuery);
                            ps_stmt.setInt(1, rsfamilias.getInt("codigo_familia"));
                            ps_stmt.execute();
                            _ex_connection.commit();
                            _connection.commit();
                            _ex_connection.close();
                        }
                    }

                }
            } catch (SQLException ex) {
                message.setMessage(jtext1, "Caja: " + this.Cajas + " Ocurrio el siguiente error al actualizar las familias: " + ex.getMessage());
                this.b_QueryResult = false;
                CerrarConexiones();
                return this.b_QueryResult;
            }

        }
        CerrarConexiones();

        return this.b_QueryResult;
    }

    public boolean ActualizarTiposProductos() {
        PreparedStatement ps_stmt, ps_ex;
        ResultSet rstiposproductos;

        tabla = "inv_tipos_productos";
        Campos = "cia_codigo, tipo_prod_codigo, tipo_prod_nombre, tipo_monto_boletas, tipo_cantidad_boletas, codigo";
        getServers();
        if (openConnection()) {

            try {
                Iterator<Servers> servidor = repo1.lstservidores.iterator();

                while (servidor.hasNext()) {
                    Servers caja = servidor.next();
                    this.SetSlaveConnection(caja.host_name, caja.database_name, caja.port_number, caja.user_name, caja.user_pwd);
                    getCajasLocales();
                    _SQLQuery = "select b.* , c.caja_ip, a.codigo as codigo_tipoproducto ,a.borrado "
                            + "  from vtas.tiposproductos_cajas a inner join inv_cajas c on(a.caja_cod = c.caja_cod) "
                            + "  left join inv_tipos_productos b on (a.codigo = b.codigo )"
                            + "  where b.cia_codigo = ? and a.sincronizado is false and c.caja_cod in (" + Cajas + ")"
                            + "  order by a.borrado desc";
                    ps_stmt = _connection.prepareStatement(_SQLQuery);
                    ps_stmt.setString(1, repo1.Company);
                    rstiposproductos = ps_stmt.executeQuery();

                    while (rstiposproductos.next()) {
                        this.SetCaja(caja.cajas, rstiposproductos.getString("cia_codigo"));
                        message.setCaption(lblTransaccion, "Caja: " + this.Cajas + " Actualizando tipo de producto : " + rstiposproductos.getString("tipo_prod_nombre"));

                        if (ex_openConnection()) {
                            if (rstiposproductos.getBoolean("borrado") == true) {
                                _ex_SQLQuery = "delete from inv_tipos_productos where codigo = ?::integer ";
                                ps_ex = _ex_connection.prepareStatement(_ex_SQLQuery);
                                ps_ex.setInt(1, rstiposproductos.getInt("codigo_tipoproducto"));
                                ps_ex.execute();
                            } else {
                                Condicion = "codigo = ?::integer ";
                                ps_Condicion = _ex_connection.prepareStatement(Condicion);
                                ps_Condicion.setInt(1, rstiposproductos.getInt("codigo"));

                                Cambios = "tipo_prod_nombre=?, tipo_monto_boletas=?, tipo_cantidad_boletas=?";

                                ps_Cambios = _ex_connection.prepareStatement(Cambios);
                                ps_Cambios.setString(1, rstiposproductos.getString("tipo_prod_nombre"));
                                ps_Cambios.setDouble(2, rstiposproductos.getDouble("tipo_monto_boletas"));
                                ps_Cambios.setInt(3, rstiposproductos.getInt("tipo_cantidad_boletas"));

                                Valores = "?, ?, ?, ?, ?, ?";
                                ps_Valores = _ex_connection.prepareStatement(Valores);
                                ps_Valores.setString(1, rstiposproductos.getString("cia_codigo"));
                                ps_Valores.setString(2, rstiposproductos.getString("tipo_prod_codigo"));
                                ps_Valores.setString(3, rstiposproductos.getString("tipo_prod_nombre"));
                                ps_Valores.setDouble(4, rstiposproductos.getDouble("tipo_monto_boletas"));
                                ps_Valores.setDouble(5, rstiposproductos.getInt("tipo_cantidad_boletas"));
                                ps_Valores.setDouble(6, rstiposproductos.getInt("codigo"));

                                _ex_SQLQuery = "SELECT * FROM public.fn_editar(?::varchar, ?::varchar, ?::varchar, ?::varchar, ?::varchar, ?::varchar, ?::varchar, ?::varchar, ?::varchar);";
                                ps_ex = _ex_connection.prepareStatement(_ex_SQLQuery);
                                ps_ex.setString(1, tabla);
                                ps_ex.setString(2, ps_Cambios.toString());
                                ps_ex.setString(3, "");
                                ps_ex.setString(4, "");
                                ps_ex.setString(5, ps_Condicion.toString());
                                ps_ex.setString(6, Campos);
                                ps_ex.setString(7, ps_Valores.toString());
                                ps_ex.setString(8, "");
                                ps_ex.setString(9, "");
                                ps_ex.executeQuery();

                            }
                            _SQLQuery = "update vtas.tiposproductos_cajas set sincronizado = true where codigo = ?::integer "
                                    + " and caja_cod in (" + this.Cajas + ") ";
                            ps_stmt = _connection.prepareStatement(_SQLQuery);
                            ps_stmt.setInt(1, rstiposproductos.getInt("codigo_tipoproducto"));
                            ps_stmt.execute();
                            _ex_connection.commit();
                            _connection.commit();
                            _ex_connection.close();
                        }
                    }

                }
            } catch (SQLException ex) {
                message.setMessage(jtext1, "Caja: " + this.Cajas + " Ocurrio el siguiente error al actualizar los tipos de producto: " + ex.getMessage());
                this.b_QueryResult = false;
                CerrarConexiones();
                return this.b_QueryResult;
            }

        }
        CerrarConexiones();

        return this.b_QueryResult;
    }

    public boolean ActualizarTiposClientes() {
        PreparedStatement ps_stmt, ps_ex;
        ResultSet rstiposclientes;

        tabla = "cxc_tipos_clientes";
        Campos = "cia_codigo,id_tipo_cliente,tipo_clie_nombre,codigo";
        getServers();
        if (openConnection()) {

            try {
                Iterator<Servers> servidor = repo1.lstservidores.iterator();

                while (servidor.hasNext()) {
                    Servers caja = servidor.next();
                    this.SetSlaveConnection(caja.host_name, caja.database_name, caja.port_number, caja.user_name, caja.user_pwd);
                    getCajasLocales();
                    _SQLQuery = "select b.* , c.caja_ip, a.codigo as codigo_tipocliente ,a.borrado "
                            + "  from vtas.tiposclientes_cajas a inner join inv_cajas c on(a.caja_cod = c.caja_cod) "
                            + "  left join cxc_tipos_clientes b on (a.codigo = b.codigo )"
                            + "  where b.cia_codigo = ? and a.sincronizado is false and c.caja_cod in (" + Cajas + ")"
                            + "  order by a.borrado desc";
                    ps_stmt = _connection.prepareStatement(_SQLQuery);
                    ps_stmt.setString(1, repo1.Company);
                    rstiposclientes = ps_stmt.executeQuery();

                    while (rstiposclientes.next()) {
                        this.SetCaja(caja.cajas, rstiposclientes.getString("cia_codigo"));
                        message.setCaption(lblTransaccion, "Caja: " + this.Cajas + " Actualizando tipo de cliente : " + rstiposclientes.getString("tipo_clie_nombre"));

                        if (ex_openConnection()) {
                            if (rstiposclientes.getBoolean("borrado") == true) {
                                _ex_SQLQuery = "delete from cxc_tipos_clientes where codigo = ?::integer ";
                                ps_ex = _ex_connection.prepareStatement(_ex_SQLQuery);
                                ps_ex.setInt(1, rstiposclientes.getInt("codigo_tipocliente"));
                                ps_ex.execute();
                            } else {
                                Condicion = "codigo = ?::integer ";
                                ps_Condicion = _ex_connection.prepareStatement(Condicion);
                                ps_Condicion.setInt(1, rstiposclientes.getInt("codigo"));

                                Cambios = "tipo_clie_nombre=?";

                                ps_Cambios = _ex_connection.prepareStatement(Cambios);
                                ps_Cambios.setString(1, rstiposclientes.getString("tipo_clie_nombre"));

                                Valores = "?, ?, ?, ?";
                                ps_Valores = _ex_connection.prepareStatement(Valores);
                                ps_Valores.setString(1, rstiposclientes.getString("cia_codigo"));
                                ps_Valores.setString(2, rstiposclientes.getString("id_tipo_cliente"));
                                ps_Valores.setString(3, rstiposclientes.getString("tipo_clie_nombre"));
                                ps_Valores.setDouble(4, rstiposclientes.getInt("codigo"));

                                _ex_SQLQuery = "SELECT * FROM public.fn_editar(?::varchar, ?::varchar, ?::varchar, ?::varchar, ?::varchar, ?::varchar, ?::varchar, ?::varchar, ?::varchar);";
                                ps_ex = _ex_connection.prepareStatement(_ex_SQLQuery);
                                ps_ex.setString(1, tabla);
                                ps_ex.setString(2, ps_Cambios.toString());
                                ps_ex.setString(3, "");
                                ps_ex.setString(4, "");
                                ps_ex.setString(5, ps_Condicion.toString());
                                ps_ex.setString(6, Campos);
                                ps_ex.setString(7, ps_Valores.toString());
                                ps_ex.setString(8, "");
                                ps_ex.setString(9, "");
                                ps_ex.executeQuery();

                            }
                            _SQLQuery = "update vtas.tiposclientes_cajas set sincronizado = true where codigo = ?::integer "
                                    + " and caja_cod in (" + this.Cajas + ")";
                            ps_stmt = _connection.prepareStatement(_SQLQuery);
                            ps_stmt.setInt(1, rstiposclientes.getInt("codigo_tipocliente"));
                            ps_stmt.execute();
                            _ex_connection.commit();
                            _connection.commit();
                            _ex_connection.close();
                        }
                    }

                }
            } catch (SQLException ex) {
                message.setMessage(jtext1, "Caja: " + this.Cajas + " Ocurrio el siguiente error al actualizar los tipos de cliente: " + ex.getMessage());
                this.b_QueryResult = false;
                CerrarConexiones();
                return this.b_QueryResult;
            }

        }
        CerrarConexiones();

        return this.b_QueryResult;
    }

    public boolean ActualizarTiposCxc() {
        PreparedStatement ps_stmt, ps_ex;
        ResultSet rstiposcxc;

        tabla = "cxc_tipos_cxc";
        Campos = "cia_codigo, tipo_codigo, tipo_nombre, tipo_cuecue, codigo";

        getServers();
        if (openConnection()) {
            Iterator<Servers> servidor = repo1.lstservidores.iterator();

            try {
                while (servidor.hasNext()) {
                    Servers caja = servidor.next();
                    this.SetSlaveConnection(caja.host_name, caja.database_name, caja.port_number, caja.user_name, caja.user_pwd);
                    getCajasLocales();
                    _SQLQuery = "select b.* , c.caja_ip, a.codigo as codigo_tipocxc ,a.borrado "
                            + "  from vtas.tiposcxc_cajas a inner join inv_cajas c on(a.caja_cod = c.caja_cod) "
                            + "  left join cxc_tipos_cxc b on (a.codigo = b.codigo )"
                            + "  where b.cia_codigo = ? and a.sincronizado is false and c.caja_cod in (" + Cajas + ")"
                            + "  order by a.borrado desc";
                    ps_stmt = _connection.prepareStatement(_SQLQuery);
                    ps_stmt.setString(1, repo1.Company);
                    rstiposcxc = ps_stmt.executeQuery();

                    while (rstiposcxc.next()) {
                        this.SetCaja(caja.cajas, rstiposcxc.getString("cia_codigo"));
                        message.setCaption(lblTransaccion, "Caja: " + this.Cajas + " Actualizando tipo de cxc : " + rstiposcxc.getString("tipo_nombre"));

                        if (ex_openConnection()) {
                            if (rstiposcxc.getBoolean("borrado") == true) {
                                _ex_SQLQuery = "delete from cxc_tipos_cxc where codigo = ?::integer ";
                                ps_ex = _ex_connection.prepareStatement(_ex_SQLQuery);
                                ps_ex.setInt(1, rstiposcxc.getInt("codigo_tipocxc"));
                                ps_ex.execute();
                            } else {
                                Condicion = "codigo = ?::integer ";
                                ps_Condicion = _ex_connection.prepareStatement(Condicion);
                                ps_Condicion.setInt(1, rstiposcxc.getInt("codigo"));

                                Cambios = "tipo_nombre=?, tipo_cuecue =?";

                                ps_Cambios = _ex_connection.prepareStatement(Cambios);
                                ps_Cambios.setString(1, rstiposcxc.getString("tipo_nombre"));
                                ps_Cambios.setString(2, rstiposcxc.getString("tipo_cuecue"));

                                Valores = "?, ?, ?, ?, ?";
                                ps_Valores = _ex_connection.prepareStatement(Valores);
                                ps_Valores.setString(1, rstiposcxc.getString("cia_codigo"));
                                ps_Valores.setString(2, rstiposcxc.getString("tipo_codigo"));
                                ps_Valores.setString(3, rstiposcxc.getString("tipo_nombre"));
                                ps_Valores.setString(4, rstiposcxc.getString("tipo_cuecue"));
                                ps_Valores.setDouble(5, rstiposcxc.getInt("codigo"));

                                _ex_SQLQuery = "SELECT * FROM public.fn_editar(?::varchar, ?::varchar, ?::varchar, ?::varchar, ?::varchar, ?::varchar, ?::varchar, ?::varchar, ?::varchar);";
                                ps_ex = _ex_connection.prepareStatement(_ex_SQLQuery);
                                ps_ex.setString(1, tabla);
                                ps_ex.setString(2, ps_Cambios.toString());
                                ps_ex.setString(3, "");
                                ps_ex.setString(4, "");
                                ps_ex.setString(5, ps_Condicion.toString());
                                ps_ex.setString(6, Campos);
                                ps_ex.setString(7, ps_Valores.toString());
                                ps_ex.setString(8, "");
                                ps_ex.setString(9, "");
                                ps_ex.executeQuery();

                            }
                            _SQLQuery = "update vtas.tiposcxc_cajas set sincronizado = true where codigo = ?::integer "
                                    + " and caja_cod in (" + this.Cajas + ") ";
                            ps_stmt = _connection.prepareStatement(_SQLQuery);
                            ps_stmt.setInt(1, rstiposcxc.getInt("codigo_tipocxc"));
                            ps_stmt.execute();
                            _ex_connection.commit();
                            _connection.commit();
                        }
                    }

                }
            } catch (SQLException ex) {
                message.setMessage(jtext1, "Caja: " + this.Cajas + " Ocurrio el siguiente error al actualizar los tipos de cxc: " + ex.getMessage());
                this.b_QueryResult = false;
                CerrarConexiones();
                return this.b_QueryResult;
            }

        }
        CerrarConexiones();

        return this.b_QueryResult;
    }

    public boolean ActualizarCategoriaClientes() {
        PreparedStatement ps_stmt, ps_ex;
        ResultSet rscategorias;

        tabla = "cxc_categoria_clientes";
        Campos = "cia_codigo, id_categoria, categoria_nombre, codigo";

        getServers();
        if (openConnection()) {

            Iterator<Servers> servidor = repo1.lstservidores.iterator();

            while (servidor.hasNext()) {
                Servers caja = servidor.next();
                try {
                    this.SetSlaveConnection(caja.host_name, caja.database_name, caja.port_number, caja.user_name, caja.user_pwd);
                    getCajasLocales();
                    _SQLQuery = "select b.* , c.caja_ip, a.codigo as codigo_categoria ,a.borrado "
                            + "  from vtas.categoriacliente_cajas a inner join inv_cajas c on(a.caja_cod = c.caja_cod) "
                            + "  left join cxc_categoria_clientes b on (a.codigo = b.codigo )"
                            + "  where b.cia_codigo = ? and a.sincronizado is false and c.caja_cod in (" + Cajas + ")"
                            + "  order by a.borrado desc";
                    ps_stmt = _connection.prepareStatement(_SQLQuery);
                    ps_stmt.setString(1, repo1.Company);
                    rscategorias = ps_stmt.executeQuery();

                    while (rscategorias.next()) {
                        this.SetCaja(caja.cajas, rscategorias.getString("cia_codigo"));
                        message.setCaption(lblTransaccion, "Caja: " + this.Cajas + " Actualizando tipo de cxc : " + rscategorias.getString("categoria_nombre"));

                        if (ex_openConnection()) {
                            if (rscategorias.getBoolean("borrado") == true) {
                                _ex_SQLQuery = "delete from cxc_categoria_clientes where codigo = ?::integer ";
                                ps_ex = _ex_connection.prepareStatement(_ex_SQLQuery);
                                ps_ex.setInt(1, rscategorias.getInt("codigo_categoria"));
                                ps_ex.execute();
                            } else {
                                Condicion = "codigo = ?::integer ";
                                ps_Condicion = _ex_connection.prepareStatement(Condicion);
                                ps_Condicion.setInt(1, rscategorias.getInt("codigo"));

                                Cambios = "categoria_nombre=?";

                                ps_Cambios = _ex_connection.prepareStatement(Cambios);
                                ps_Cambios.setString(1, rscategorias.getString("categoria_nombre"));

                                Valores = "?, ?, ?, ?";
                                ps_Valores = _ex_connection.prepareStatement(Valores);
                                ps_Valores.setString(1, rscategorias.getString("cia_codigo"));
                                ps_Valores.setString(2, rscategorias.getString("id_categoria"));
                                ps_Valores.setString(3, rscategorias.getString("categoria_nombre"));
                                ps_Valores.setDouble(4, rscategorias.getInt("codigo"));

                                _ex_SQLQuery = "SELECT * FROM public.fn_editar(?::varchar, ?::varchar, ?::varchar, ?::varchar, ?::varchar, ?::varchar, ?::varchar, ?::varchar, ?::varchar);";
                                ps_ex = _ex_connection.prepareStatement(_ex_SQLQuery);
                                ps_ex.setString(1, tabla);
                                ps_ex.setString(2, ps_Cambios.toString());
                                ps_ex.setString(3, "");
                                ps_ex.setString(4, "");
                                ps_ex.setString(5, ps_Condicion.toString());
                                ps_ex.setString(6, Campos);
                                ps_ex.setString(7, ps_Valores.toString());
                                ps_ex.setString(8, "");
                                ps_ex.setString(9, "");
                                ps_ex.executeQuery();

                            }
                            _SQLQuery = "update vtas.categoriacliente_cajas set sincronizado = true where codigo = ?::integer "
                                    + " and caja_cod in ( " + this.Cajas + ")";
                            ps_stmt = _connection.prepareStatement(_SQLQuery);
                            ps_stmt.setInt(1, rscategorias.getInt("codigo_categoria"));
                            ps_stmt.execute();
                            _ex_connection.commit();
                            _connection.commit();
                            _ex_connection.close();
                        }
                    }

                } catch (SQLException ex) {
                    message.setMessage(jtext1, "Caja: " + this.Cajas + " Ocurrio el siguiente error al actualizar las categorias de cliente: " + ex.getMessage());
                    this.b_QueryResult = false;
                    CerrarConexiones();
                    return this.b_QueryResult;
                }
            }
        }
        CerrarConexiones();

        return this.b_QueryResult;
    }

    public boolean ActualizarUnidades() {
        PreparedStatement ps_stmt, ps_ex;
        ResultSet rsunidades;

        tabla = "inv_unidades";
        Campos = "id_unidad, unid_nombre";

        getServers();
        if (openConnection()) {

            Iterator<Servers> servidor = repo1.lstservidores.iterator();
            while (servidor.hasNext()) {
                Servers caja = servidor.next();
                this.SetSlaveConnection(caja.host_name, caja.database_name, caja.port_number, caja.user_name, caja.user_pwd);
                getCajasLocales();
                try {
                    _SQLQuery = "select b.* , c.caja_ip, a.codigo as codigo_unidad ,a.borrado "
                            + "  from vtas.unidades_cajas a inner join inv_cajas c on(a.caja_cod = c.caja_cod) "
                            + "  left join inv_unidades b on (a.codigo = b.id_unidad )"
                            + "  where a.sincronizado is false and c.caja_cod in (" + Cajas + ")"
                            + "  order by a.borrado desc";
                    ps_stmt = _connection.prepareStatement(_SQLQuery);
                    rsunidades = ps_stmt.executeQuery();

                    while (rsunidades.next()) {
                        this.SetCaja(caja.cajas, "");
                        message.setCaption(lblTransaccion, "Caja: " + this.Cajas + " Actualizando unidades : " + rsunidades.getString("unid_nombre"));

                        if (ex_openConnection()) {
                            if (rsunidades.getBoolean("borrado") == true) {
                                _ex_SQLQuery = "delete from inv_unidades where id_unidad = ?::integer ";
                                ps_ex = _ex_connection.prepareStatement(_ex_SQLQuery);
                                ps_ex.setInt(1, rsunidades.getInt("codigo_unidad"));
                                ps_ex.execute();
                            } else {
                                Condicion = "id_unidad = ?::integer ";
                                ps_Condicion = _ex_connection.prepareStatement(Condicion);
                                ps_Condicion.setInt(1, rsunidades.getInt("id_unidad"));

                                Cambios = "unid_nombre=?";

                                ps_Cambios = _ex_connection.prepareStatement(Cambios);
                                ps_Cambios.setString(1, rsunidades.getString("unid_nombre"));

                                Valores = "?, ?";
                                ps_Valores = _ex_connection.prepareStatement(Valores);
                                ps_Valores.setDouble(1, rsunidades.getInt("id_unidad"));
                                ps_Valores.setString(2, rsunidades.getString("unid_nombre"));

                                _ex_SQLQuery = "SELECT * FROM public.fn_editar(?::varchar, ?::varchar, ?::varchar, ?::varchar, ?::varchar, ?::varchar, ?::varchar, ?::varchar, ?::varchar);";
                                ps_ex = _ex_connection.prepareStatement(_ex_SQLQuery);
                                ps_ex.setString(1, tabla);
                                ps_ex.setString(2, ps_Cambios.toString());
                                ps_ex.setString(3, "");
                                ps_ex.setString(4, "");
                                ps_ex.setString(5, ps_Condicion.toString());
                                ps_ex.setString(6, Campos);
                                ps_ex.setString(7, ps_Valores.toString());
                                ps_ex.setString(8, "");
                                ps_ex.setString(9, "");
                                ps_ex.executeQuery();

                            }
                            _SQLQuery = "update vtas.unidades_cajas set sincronizado = true where codigo = ?::integer "
                                    + " and caja_cod in ( " + this.Cajas + ")";
                            ps_stmt = _connection.prepareStatement(_SQLQuery);
                            ps_stmt.setInt(1, rsunidades.getInt("codigo_unidad"));
                            ps_stmt.execute();
                            _ex_connection.commit();
                            _connection.commit();
                            _ex_connection.close();
                        }
                    }

                } catch (SQLException ex) {
                    message.setMessage(jtext1, "Caja: " + this.Cajas + " Ocurrio el siguiente error al actualizar las unidades: " + ex.getMessage());
                    this.b_QueryResult = false;
                    CerrarConexiones();
                    return this.b_QueryResult;
                }
            }
        }
        CerrarConexiones();

        return this.b_QueryResult;
    }

    public boolean ActualizarKit() {
        PreparedStatement ps_stmt, ps_ex;
        ResultSet rsKitHead, rsKitItem;

        tabla = "inv_kit_head";
        Campos = "cia_codigo, kit_codigo, kit_nombre, kit_fecha, kit_precio, kit_costo, "
                + "kit_modificable, kit_detalleprecio, kit_imprim";

        getServers();
        if (openConnection()) {
            Iterator<Servers> servidor = repo1.lstservidores.iterator();

            try {
                while (servidor.hasNext()) {
                    Servers caja = servidor.next();
                    this.SetSlaveConnection(caja.host_name, caja.database_name, caja.port_number, caja.user_name, caja.user_pwd);
                    getCajasLocales();
                    _SQLQuery = "select  b.*,c.caja_ip,a.cia_codigo , a.kit_codigo ,a.borrado "
                            + "  from vtas.kit_cajas a inner join inv_cajas c on(a.caja_cod = c.caja_cod) "
                            + "  left join inv_kit_head b on (a.cia_codigo = b.cia_codigo and a.kit_codigo = b.kit_codigo)"
                            + "  where a.cia_codigo = ? and a.sincronizado is false and c.caja_cod in (" + Cajas + ")"
                            + "  order by a.borrado desc";
                    ps_stmt = _connection.prepareStatement(_SQLQuery);
                    ps_stmt.setString(1, repo1.Company);
                    rsKitHead = ps_stmt.executeQuery();

                    while (rsKitHead.next()) {
                        this.SetCaja(caja.cajas, rsKitHead.getString("cia_codigo"));
                        message.setCaption(lblTransaccion, "Caja: " + this.Cajas + " Actualizando Kit : " + rsKitHead.getString("kit_nombre"));

                        if (ex_openConnection()) {
                            if (rsKitHead.getBoolean("borrado") == true) {
                                _ex_SQLQuery = "delete from inv_kit_head where cia_codigo = ?::varchar "
                                        + " and kit_codigo = ?::varchar ";
                                ps_ex = _ex_connection.prepareStatement(_ex_SQLQuery);
                                ps_ex.setString(1, rsKitHead.getString("cia_codigo"));
                                ps_ex.setString(2, rsKitHead.getString("kit_codigo"));
                                ps_ex.execute();
                            } else {
                                Condicion = "cia_codigo = ?::varchar and kit_codigo = ?::varchar ";
                                ps_Condicion = _ex_connection.prepareStatement(Condicion);
                                ps_Condicion.setString(1, rsKitHead.getString("cia_codigo"));
                                ps_Condicion.setString(2, rsKitHead.getString("kit_codigo"));

                                Cambios = "kit_nombre=?, kit_fecha=?, kit_precio=?, "
                                        + "kit_costo=?, kit_modificable=?, kit_detalleprecio=?, kit_imprim=?";

                                ps_Cambios = _ex_connection.prepareStatement(Cambios);
                                ps_Cambios.setString(1, rsKitHead.getString("kit_nombre"));
                                ps_Cambios.setDate(2, rsKitHead.getDate("kit_fecha"));
                                ps_Cambios.setDouble(3, rsKitHead.getDouble("kit_precio"));
                                ps_Cambios.setDouble(4, rsKitHead.getDouble("kit_costo"));
                                ps_Cambios.setInt(5, rsKitHead.getInt("kit_modificable"));
                                ps_Cambios.setInt(6, rsKitHead.getInt("kit_detalleprecio"));
                                ps_Cambios.setInt(7, rsKitHead.getInt("kit_imprim"));

                                Valores = "?, ?, ?, ?, ?, ?, ?, ?, ?";
                                ps_Valores = _ex_connection.prepareStatement(Valores);
                                ps_Valores.setString(1, rsKitHead.getString("cia_codigo"));
                                ps_Valores.setString(2, rsKitHead.getString("kit_codigo"));
                                ps_Valores.setString(3, rsKitHead.getString("kit_nombre"));
                                ps_Valores.setDate(4, rsKitHead.getDate("kit_fecha"));
                                ps_Valores.setDouble(5, rsKitHead.getDouble("kit_precio"));
                                ps_Valores.setDouble(6, rsKitHead.getDouble("kit_costo"));
                                ps_Valores.setInt(7, rsKitHead.getInt("kit_modificable"));
                                ps_Valores.setInt(8, rsKitHead.getInt("kit_detalleprecio"));
                                ps_Valores.setInt(9, rsKitHead.getInt("kit_imprim"));

                                _ex_SQLQuery = "SELECT * FROM public.fn_editar(?::varchar, ?::varchar, ?::varchar, ?::varchar, ?::varchar, ?::varchar, ?::varchar, ?::varchar, ?::varchar);";
                                ps_ex = _ex_connection.prepareStatement(_ex_SQLQuery);
                                ps_ex.setString(1, tabla);
                                ps_ex.setString(2, ps_Cambios.toString());
                                ps_ex.setString(3, "");
                                ps_ex.setString(4, "");
                                ps_ex.setString(5, ps_Condicion.toString());
                                ps_ex.setString(6, Campos);
                                ps_ex.setString(7, ps_Valores.toString());
                                ps_ex.setString(8, "");
                                ps_ex.setString(9, "");
                                ps_ex.executeQuery();

                                _SQLQuery = "select * from inv_kit_item where cia_codigo = ? and kit_codigo = ? ";
                                ps_stmt = _connection.prepareStatement(_SQLQuery);
                                ps_stmt.setString(1, rsKitHead.getString("cia_codigo"));
                                ps_stmt.setString(2, rsKitHead.getString("kit_codigo"));

                                rsKitItem = ps_stmt.executeQuery();

                                _ex_SQLQuery = " delete from inv_kit_item where cia_codigo = ? and kit_codigo = ? ";
                                ps_ex = _ex_connection.prepareStatement(_ex_SQLQuery);
                                ps_ex.setString(1, rsKitHead.getString("cia_codigo"));
                                ps_ex.setString(2, rsKitHead.getString("kit_codigo"));
                                ps_ex.execute();

                                while (rsKitItem.next()) {
                                    _ex_SQLQuery = " insert into inv_kit_item"
                                            + " (cia_codigo, kit_codigo, prod_referencia, prod_nombre, prod_unidad,"
                                            + "prod_cantidad, prod_marca, prod_precio, prod_costo, prod_preciov, kit_secuencia)"
                                            + " VALUES (?, ?, ?, ?, ?,  ?, ?, ?, ?, ?, ?)";
                                    ps_ex = _ex_connection.prepareStatement(_ex_SQLQuery);
                                    ps_ex.setString(1, rsKitItem.getString("cia_codigo"));
                                    ps_ex.setString(2, rsKitItem.getString("kit_codigo"));
                                    ps_ex.setString(3, rsKitItem.getString("prod_referencia"));
                                    ps_ex.setString(4, rsKitItem.getString("prod_nombre"));
                                    ps_ex.setString(5, rsKitItem.getString("prod_unidad"));
                                    ps_ex.setDouble(6, rsKitItem.getDouble("prod_cantidad"));
                                    ps_ex.setString(7, rsKitItem.getString("prod_marca"));
                                    ps_ex.setDouble(8, rsKitItem.getDouble("prod_precio"));
                                    ps_ex.setDouble(9, rsKitItem.getDouble("prod_costo"));
                                    ps_ex.setDouble(10, rsKitItem.getDouble("prod_preciov"));
                                    ps_ex.setInt(11, rsKitItem.getInt("kit_secuencia"));
                                    ps_ex.execute();

                                }

                            }
                            _SQLQuery = "update vtas.kit_cajas set sincronizado = true where cia_codigo = ?::varchar "
                                    + " and kit_codigo = ?::varchar and caja_cod in (" + this.Cajas + ") ";
                            ps_stmt = _connection.prepareStatement(_SQLQuery);
                            ps_stmt.setString(1, rsKitHead.getString("cia_codigo"));
                            ps_stmt.setString(2, rsKitHead.getString("kit_codigo"));
                            ps_stmt.execute();
                            _ex_connection.commit();
                            _connection.commit();
                            _ex_connection.close();
                        }
                    }

                }
            } catch (SQLException ex) {
                message.setMessage(jtext1, "Caja: " + this.Cajas + " Ocurrio el siguiente error al actualizar los kits: " + ex.getMessage());
                this.b_QueryResult = false;
                CerrarConexiones();
                return this.b_QueryResult;
            }

        }
        CerrarConexiones();

        return this.b_QueryResult;
    }

    public boolean ActualizarGiftCard() {
        PreparedStatement ps_stmt, ps_ex;
        ResultSet rsgiftcard;

        tabla = "cxc_giftcard";
        Campos = "codigo_giftcard,cia_codigo,numero_giftcard,estado_giftcard";

        getServers();
        if (openConnection()) {
            Iterator<Servers> servidor = repo1.lstservidores.iterator();

            try {
                while (servidor.hasNext()) {
                    Servers caja = servidor.next();
                    this.SetSlaveConnection(caja.host_name, caja.database_name, caja.port_number, caja.user_name, caja.user_pwd);
                    getCajasLocales();
                    _SQLQuery = "select b.* , c.caja_ip, a.codigo ,a.borrado "
                            + "  from vtas.giftcard_cajas a inner join inv_cajas c on(a.caja_cod = c.caja_cod) "
                            + "  left join cxc_giftcard b on (a.codigo = b.codigo_giftcard )"
                            + "  where b.cia_codigo = ? and a.sincronizado is false and c.caja_cod in (" + Cajas + ")"
                            + "  order by a.borrado desc";
                    ps_stmt = _connection.prepareStatement(_SQLQuery);
                    ps_stmt.setString(1, repo1.Company);
                    rsgiftcard = ps_stmt.executeQuery();

                    while (rsgiftcard.next()) {
                        this.SetCaja(caja.cajas, rsgiftcard.getString("cia_codigo"));
                        message.setCaption(lblTransaccion, "Caja: " + this.Cajas + " Actualizando Gift Card : " + rsgiftcard.getString("numero_giftcard"));

                        if (ex_openConnection()) {
                            if (rsgiftcard.getBoolean("borrado") == true) {
                                _ex_SQLQuery = "delete from cxc_giftcard where codigo_giftcard = ?::integer ";
                                ps_ex = _ex_connection.prepareStatement(_ex_SQLQuery);
                                ps_ex.setInt(1, rsgiftcard.getInt("codigo"));
                                ps_ex.execute();
                            } else {
                                Condicion = "codigo_giftcard = ?::integer ";
                                ps_Condicion = _ex_connection.prepareStatement(Condicion);
                                ps_Condicion.setInt(1, rsgiftcard.getInt("codigo"));

                                Cambios = "estado_giftcard = ?";
                                ps_Cambios = _ex_connection.prepareStatement(Cambios);
                                ps_Cambios.setString(1, rsgiftcard.getString("estado_giftcard"));

                                Valores = "?, ?, ?, ?";
                                ps_Valores = _ex_connection.prepareStatement(Valores);
                                ps_Valores.setInt(1, rsgiftcard.getInt("codigo"));
                                ps_Valores.setString(2, rsgiftcard.getString("cia_codigo"));
                                ps_Valores.setString(3, rsgiftcard.getString("numero_giftcard"));
                                ps_Valores.setString(4, rsgiftcard.getString("estado_giftcard"));

                                _ex_SQLQuery = "SELECT * FROM public.fn_editar(?::varchar, ?::varchar, ?::varchar, ?::varchar, ?::varchar, ?::varchar, ?::varchar, ?::varchar, ?::varchar);";
                                ps_ex = _ex_connection.prepareStatement(_ex_SQLQuery);
                                ps_ex.setString(1, tabla);
                                ps_ex.setString(2, ps_Cambios.toString());
                                ps_ex.setString(3, "");
                                ps_ex.setString(4, "");
                                ps_ex.setString(5, ps_Condicion.toString());
                                ps_ex.setString(6, Campos);
                                ps_ex.setString(7, ps_Valores.toString());
                                ps_ex.setString(8, "");
                                ps_ex.setString(9, "");
                                ps_ex.executeQuery();

                            }
                            _SQLQuery = "update vtas.giftcard_cajas set sincronizado = true where codigo = ?::integer "
                                    + " and caja_cod in (" + this.Cajas + ")";
                            ps_stmt = _connection.prepareStatement(_SQLQuery);
                            ps_stmt.setInt(1, rsgiftcard.getInt("codigo"));
                            ps_stmt.execute();
                            _ex_connection.commit();
                            _connection.commit();
                            _ex_connection.close();
                        }
                    }

                }
            } catch (SQLException ex) {
                message.setMessage(jtext1, "Caja: " + this.Cajas + " Ocurrio el siguiente error al actualizar las Gift Card: " + ex.getMessage());
                this.b_QueryResult = false;
                CerrarConexiones();
                return this.b_QueryResult;
            }

        }
        CerrarConexiones();

        return this.b_QueryResult;
    }

    public boolean ActualizarCajasPos() {
        PreparedStatement ps_stmt, ps_ex;
        ResultSet rscajasvspos;

        tabla = "cajavspos";
        Campos = "caja_cod,descripcion,cia_codigo";

        getServers();
        if (openConnection()) {
            Iterator<Servers> servidor = repo1.lstservidores.iterator();

            try {
                while (servidor.hasNext()) {
                    Servers caja = servidor.next();
                    this.SetSlaveConnection(caja.host_name, caja.database_name, caja.port_number, caja.user_name, caja.user_pwd);
                    getCajasLocales();
                    _SQLQuery = "select c.cia_codigo,c.caja_ip, a.caja_cod,a.descripcion ,a.borrado "
                            + "  from vtas.cajavspos_cajas a inner join inv_cajas c on(a.caja_cod = c.caja_cod) "
                            + "  where c.cia_codigo = ? and a.sincronizado is false and c.caja_cod in (" + Cajas + ")"
                            + "  order by a.borrado desc";
                    ps_stmt = _connection.prepareStatement(_SQLQuery);
                    ps_stmt.setString(1, repo1.Company);
                    rscajasvspos = ps_stmt.executeQuery();

                    while (rscajasvspos.next()) {
                        this.SetCaja(caja.cajas, "");
                        message.setCaption(lblTransaccion, "Caja: " + this.Cajas + " Actualizando Operaciones de POS por cajas : " + rscajasvspos.getString("descripcion"));

                        if (ex_openConnection()) {
                            if (rscajasvspos.getBoolean("borrado") == true) {
                                _ex_SQLQuery = "delete from cajavspos where caja_cod = ? and descripcion = ? ";
                                ps_ex = _ex_connection.prepareStatement(_ex_SQLQuery);
                                ps_ex.setString(1, rscajasvspos.getString("caja_cod"));
                                ps_ex.setString(2, rscajasvspos.getString("descripcion"));
                                ps_ex.execute();
                            } else {
                                Condicion = "caja_cod = ? and descripcion = ? and cia_codigo = ?";
                                ps_Condicion = _ex_connection.prepareStatement(Condicion);
                                ps_Condicion.setString(1, rscajasvspos.getString("caja_cod"));
                                ps_Condicion.setString(2, rscajasvspos.getString("descripcion"));
                                ps_Condicion.setString(3, rscajasvspos.getString("cia_codigo"));

                                Cambios = "descripcion = ?";

                                ps_Cambios = _ex_connection.prepareStatement(Cambios);
                                ps_Cambios.setString(1, rscajasvspos.getString("descripcion"));

                                Valores = "?, ?, ?";
                                ps_Valores = _ex_connection.prepareStatement(Valores);
                                ps_Valores.setString(1, rscajasvspos.getString("caja_cod"));
                                ps_Valores.setString(2, rscajasvspos.getString("descripcion"));
                                ps_Valores.setString(3, rscajasvspos.getString("cia_codigo"));

                                _ex_SQLQuery = "SELECT * FROM public.fn_editar(?::varchar, ?::varchar, ?::varchar, ?::varchar, ?::varchar, ?::varchar, ?::varchar, ?::varchar, ?::varchar);";
                                ps_ex = _ex_connection.prepareStatement(_ex_SQLQuery);
                                ps_ex.setString(1, tabla);
                                ps_ex.setString(2, ps_Cambios.toString());
                                ps_ex.setString(3, "");
                                ps_ex.setString(4, "");
                                ps_ex.setString(5, ps_Condicion.toString());
                                ps_ex.setString(6, Campos);
                                ps_ex.setString(7, ps_Valores.toString());
                                ps_ex.setString(8, "");
                                ps_ex.setString(9, "");
                                ps_ex.executeQuery();

                            }
                            _SQLQuery = "update vtas.cajavspos_cajas set sincronizado = true where descripcion = ?"
                                    + " and caja_cod in (" + this.Cajas + ") ";
                            ps_stmt = _connection.prepareStatement(_SQLQuery);
                            ps_stmt.setString(1, rscajasvspos.getString("descripcion"));
                            ps_stmt.execute();
                            _ex_connection.commit();
                            _connection.commit();
                            _ex_connection.close();
                        }
                    }

                }
            } catch (SQLException ex) {
                message.setMessage(jtext1, "Caja: " + this.Cajas + " Ocurrio el siguiente error al actualizar las Operaciones de POS: " + ex.getMessage());
                this.b_QueryResult = false;
                CerrarConexiones();
                return this.b_QueryResult;
            }

        }
        CerrarConexiones();

        return this.b_QueryResult;
    }

    public boolean ActualizarFormatosImpresionPos() {
        PreparedStatement ps_stmt, ps_ex;
        ResultSet rsformatosimppos;

        tabla = "formatos_impresion_pos";
        Campos = "codigo,reporte_nombre,tipo,descripcion,codigo_proveedor";

        getServers();
        if (openConnection()) {
            Iterator<Servers> servidor = repo1.lstservidores.iterator();

            try {
                while (servidor.hasNext()) {
                    Servers caja = servidor.next();
                    this.SetSlaveConnection(caja.host_name, caja.database_name, caja.port_number, caja.user_name, caja.user_pwd);
                    getCajasLocales();
                    _SQLQuery = "select c.caja_ip, a.caja_cod,a.borrado,b.codigo,b.reporte_nombre,b.tipo,b.descripcion,b.codigo_proveedor "
                            + "  from vtas.formatos_impresion_pos_cajas a inner join inv_cajas c on(a.caja_cod = c.caja_cod) "
                            + " left join formatos_impresion_pos b on (b.codigo = a.codigo)"
                            + "  where c.cia_codigo = ? and a.sincronizado is false and c.caja_cod in (" + Cajas + ")"
                            + "  order by a.borrado desc";
                    ps_stmt = _connection.prepareStatement(_SQLQuery);
                    ps_stmt.setString(1, repo1.Company);
                    rsformatosimppos = ps_stmt.executeQuery();

                    while (rsformatosimppos.next()) {
                        this.SetCaja(caja.cajas, "");
                        message.setCaption(lblTransaccion, "Caja: " + this.Cajas + " Actualizando Formatos Impresion POS por cajas : " + rsformatosimppos.getString("descripcion"));

                        if (ex_openConnection()) {
                            if (rsformatosimppos.getBoolean("borrado") == true) {
                                _ex_SQLQuery = "delete from formatos_impresion_pos where codigo = ? ";
                                ps_ex = _ex_connection.prepareStatement(_ex_SQLQuery);
                                ps_ex.setInt(1, rsformatosimppos.getInt("codigo"));
                                ps_ex.execute();
                            } else {
                                Condicion = "codigo = ?";
                                ps_Condicion = _ex_connection.prepareStatement(Condicion);
                                ps_Condicion.setInt(1, rsformatosimppos.getInt("codigo"));

                                Cambios = "reporte_nombre = ?, tipo = ?, descripcion = ?, codigo_proveedor = ? ";

                                ps_Cambios = _ex_connection.prepareStatement(Cambios);
                                ps_Cambios.setString(1, rsformatosimppos.getString("reporte_nombre"));
                                ps_Cambios.setInt(2, rsformatosimppos.getInt("tipo"));
                                ps_Cambios.setString(3, rsformatosimppos.getString("descripcion"));
                                ps_Cambios.setInt(4, rsformatosimppos.getInt("codigo_proveedor"));

                                Valores = "?, ?, ?, ?";
                                ps_Valores = _ex_connection.prepareStatement(Valores);
                                ps_Valores.setInt(1, rsformatosimppos.getInt("codigo"));
                                ps_Valores.setString(2, rsformatosimppos.getString("reporte_nombre"));
                                ps_Valores.setInt(3, rsformatosimppos.getInt("tipo"));
                                ps_Valores.setString(4, rsformatosimppos.getString("descripcion"));
                                ps_Valores.setInt(5, rsformatosimppos.getInt("codigo_proveedor"));

                                _ex_SQLQuery = "SELECT * FROM public.fn_editar(?::varchar, ?::varchar, ?::varchar, ?::varchar, ?::varchar, ?::varchar, ?::varchar, ?::varchar, ?::varchar);";
                                ps_ex = _ex_connection.prepareStatement(_ex_SQLQuery);
                                ps_ex.setString(1, tabla);
                                ps_ex.setString(2, ps_Cambios.toString());
                                ps_ex.setString(3, "");
                                ps_ex.setString(4, "");
                                ps_ex.setString(5, ps_Condicion.toString());
                                ps_ex.setString(6, Campos);
                                ps_ex.setString(7, ps_Valores.toString());
                                ps_ex.setString(8, "");
                                ps_ex.setString(9, "");
                                ps_ex.executeQuery();

                            }
                            _SQLQuery = "update vtas.formatos_impresion_pos_cajas set sincronizado = true where codigo = ?"
                                    + " and caja_cod in (" + this.Cajas + ") ";
                            ps_stmt = _connection.prepareStatement(_SQLQuery);
                            ps_stmt.setInt(1, rsformatosimppos.getInt("codigo"));
                            ps_stmt.execute();
                            _ex_connection.commit();
                            _connection.commit();
                            _ex_connection.close();
                        }
                    }

                }
            } catch (SQLException ex) {
                message.setMessage(jtext1, "Caja: " + this.Cajas + " Ocurrio el siguiente error al actualizar los Formatos de Impresion de POS: " + ex.getMessage());
                this.b_QueryResult = false;
                CerrarConexiones();
                return this.b_QueryResult;
            }

        }
        CerrarConexiones();

        return this.b_QueryResult;
    }

    public boolean ActualizarVouchersProveedores() {
        PreparedStatement ps_stmt, ps_ex;
        ResultSet rsproveedores;

        tabla = "proveedores_vouchers";
        Campos = "codigo, nombre";
        getServers();
        if (openConnection()) {
            Iterator<Servers> servidor = repo1.lstservidores.iterator();

            try {

                while (servidor.hasNext()) {
                    Servers caja = servidor.next();
                    this.SetSlaveConnection(caja.host_name, caja.database_name, caja.port_number, caja.user_name, caja.user_pwd);
                    getCajasLocales();
                    _SQLQuery = "select b.* , c.caja_ip, a.id ,a.borrado "
                            + "  from vtas.vouchers_proveedores_cajas a inner join inv_cajas c on(a.caja_cod = c.caja_cod) "
                            + "  left join proveedores_vouchers b on (a.id = b.codigo )"
                            + "  where c.cia_codigo = ? and a.sincronizado is false and c.caja_cod in (" + Cajas + ")"
                            + "  order by a.borrado desc";
                    ps_stmt = _connection.prepareStatement(_SQLQuery);
                    ps_stmt.setString(1, repo1.Company);
                    rsproveedores = ps_stmt.executeQuery();

                    while (rsproveedores.next()) {
                        this.SetCaja(caja.cajas, "");
                        message.setCaption(lblTransaccion, "Caja: " + this.Cajas + " Actualizando Proveedores de Vouchers : " + rsproveedores.getString("nombre"));

                        if (ex_openConnection()) {
                            if (rsproveedores.getBoolean("borrado") == true) {
                                _ex_SQLQuery = "delete from proveedores_vouchers where codigo = ?::integer ";
                                ps_ex = _ex_connection.prepareStatement(_ex_SQLQuery);
                                ps_ex.setInt(1, rsproveedores.getInt("id"));
                                ps_ex.execute();
                            } else {
                                Condicion = "codigo = ?::integer ";
                                ps_Condicion = _ex_connection.prepareStatement(Condicion);
                                ps_Condicion.setInt(1, rsproveedores.getInt("id"));

                                Cambios = "nombre = ?";

                                ps_Cambios = _ex_connection.prepareStatement(Cambios);
                                ps_Cambios.setString(1, rsproveedores.getString("nombre"));

                                Valores = "?, ?";
                                ps_Valores = _ex_connection.prepareStatement(Valores);
                                ps_Valores.setDouble(1, rsproveedores.getInt("id"));
                                ps_Valores.setString(2, rsproveedores.getString("nombre"));

                                _ex_SQLQuery = "SELECT * FROM public.fn_editar(?::varchar, ?::varchar, ?::varchar, ?::varchar, ?::varchar, ?::varchar, ?::varchar, ?::varchar, ?::varchar);";
                                ps_ex = _ex_connection.prepareStatement(_ex_SQLQuery);
                                ps_ex.setString(1, tabla);
                                ps_ex.setString(2, ps_Cambios.toString());
                                ps_ex.setString(3, "");
                                ps_ex.setString(4, "");
                                ps_ex.setString(5, ps_Condicion.toString());
                                ps_ex.setString(6, Campos);
                                ps_ex.setString(7, ps_Valores.toString());
                                ps_ex.setString(8, "");
                                ps_ex.setString(9, "");
                                ps_ex.executeQuery();

                            }
                            _SQLQuery = "update vtas.vouchers_proveedores_cajas set sincronizado = true where id = ?::integer "
                                    + " and caja_cod in (" + this.Cajas + ") ";
                            ps_stmt = _connection.prepareStatement(_SQLQuery);
                            ps_stmt.setInt(1, rsproveedores.getInt("id"));
                            ps_stmt.execute();
                            _ex_connection.commit();
                            _connection.commit();
                            _ex_connection.close();
                        }
                    }

                }
            } catch (SQLException ex) {
                message.setMessage(jtext1, "Caja: " + this.Cajas + " Ocurrio el siguiente error al actualizar los proveedores de vouchers: " + ex.getMessage());
                this.b_QueryResult = false;
                CerrarConexiones();
                return this.b_QueryResult;
            }

        }
        CerrarConexiones();

        return this.b_QueryResult;
    }

    public boolean ActualizarNCFCajas() {
        PreparedStatement ps_stmt, ps_ex;
        ResultSet rstmp, rsCajas, rsSecuenciasNCF, rsNCFTipos;
        getServers();
        if (openConnection()) {
            Iterator<Servers> servidor = repo1.lstservidores.iterator();

            while (servidor.hasNext()) {
                Servers caja = servidor.next();
                this.SetSlaveConnection(caja.host_name, caja.database_name, caja.port_number, caja.user_name, caja.user_pwd);
                getCajasLocales();
                //Consultando las cajas configuradas como independientes
                _SQLQuery = "select c.cia_codigo, c.caja_cod , c.caja_ip from inv_cajas c where c.caja_cod IN (" + Cajas + ") order by c.caja_cod ";
                try {
                    ps_stmt = _connection.prepareStatement(_SQLQuery);
                    rsCajas = ps_stmt.executeQuery();
                    while (rsCajas.next()) {

                        //Consultando las secuencias de NCF configuradas en el servidor
                        _SQLQuery = "select * from dgii.h_secuenciancf where distribuir_por_caja is true order by id";
                        ps_stmt = _connection.prepareStatement(_SQLQuery);
                        rstmp = ps_stmt.executeQuery();

//                    this.SetSlaveConnection(rsCajas.getString("caja_ip"));
                        while (rstmp.next()) {
                            this.SetCaja(rsCajas.getString("caja_cod"), rsCajas.getString("cia_codigo"));
                            message.setCaption(lblTransaccion, "Caja: " + this.Cajas + " Actualizando NCF en caja : " + rsCajas.getString("caja_cod"));

                            if (ex_openConnection()) {
                                //Guardando el header de la secuencia de NCF
                                tabla = "dgii.h_secuenciancf";
                                Campos = "id, cia_codigo, fecha_emision, fecha_vencimiento, numero_solicitud, distribuir_por_caja";
                                Condicion = " id = ?";
                                Cambios = "fecha_emision = ?, fecha_vencimiento = ?";
                                Valores = "?, ?, ?, ?, ?, ? ";
                                ps_Condicion = _ex_connection.prepareStatement(Condicion);
                                ps_Condicion.setLong(1, rstmp.getLong("id"));

                                ps_Cambios = _ex_connection.prepareStatement(Cambios);
                                ps_Cambios.setDate(1, rstmp.getDate("fecha_emision"));
                                ps_Cambios.setDate(2, rstmp.getDate("fecha_vencimiento"));

                                ps_Valores = _ex_connection.prepareStatement(Valores);
                                ps_Valores.setLong(1, rstmp.getLong("id"));
                                ps_Valores.setString(2, rstmp.getString("cia_codigo"));
                                ps_Valores.setDate(3, rstmp.getDate("fecha_emision"));

                                ps_Valores.setDate(4, rstmp.getDate("fecha_vencimiento"));
                                ps_Valores.setLong(5, rstmp.getLong("numero_solicitud"));
                                ps_Valores.setBoolean(6, rstmp.getBoolean("distribuir_por_caja"));

                                //Guardando el encabezado de la secuencia de NCF
                                _ex_SQLQuery = "SELECT * FROM public.fn_editar(?::varchar, ?::varchar, ?::varchar, ?::varchar, ?::varchar, ?::varchar, ?::varchar, ?::varchar, ?::varchar);";
                                ps_ex = _ex_connection.prepareStatement(_ex_SQLQuery);
                                ps_ex.setString(1, tabla);
                                ps_ex.setString(2, ps_Cambios.toString());
                                ps_ex.setString(3, "");
                                ps_ex.setString(4, "");
                                ps_ex.setString(5, ps_Condicion.toString());
                                ps_ex.setString(6, Campos);
                                ps_ex.setString(7, ps_Valores.toString());
                                ps_ex.setString(8, "");
                                ps_ex.setString(9, "");
                                ps_ex.executeQuery();

                                String aTiposNCF[] = {"01", "02", "03", "04", "11", "12", "13", "14", "15"};
                                int i_index = 0;
                                //Guardando las secuencias de los NCF por tipos
                                for (i_index = 0; i_index < aTiposNCF.length; i_index++) {
                                    _SQLQuery = "select * from dgii.d_secuenciancf_" + aTiposNCF[i_index].trim();
                                    ps_stmt = _connection.prepareStatement(_SQLQuery);
                                    rsNCFTipos = ps_stmt.executeQuery();
                                    while (rsNCFTipos.next()) {
                                        tabla = "dgii.d_secuenciancf_" + aTiposNCF[i_index].trim();
                                        Campos = "id, cia_codigo, serie, secuencia_inicial, secuencia_final, secuencia_actual, secuencia_aviso";
                                        Condicion = "id = ? and cia_codigo = ? and serie = ?";
                                        Cambios = "secuencia_inicial = ?,secuencia_final=?,secuencia_aviso = ?";
                                        Valores = "?, ?, ?, ?, ?, ?, ?";
                                        ps_Condicion = _ex_connection.prepareStatement(Condicion);

                                        ps_Condicion.setLong(1, rstmp.getLong("id"));
                                        ps_Condicion.setString(2, rstmp.getString("cia_codigo"));
                                        ps_Condicion.setString(3, rsNCFTipos.getString("serie"));

                                        ps_Cambios = _ex_connection.prepareStatement(Cambios);
                                        ps_Cambios.setLong(1, rsNCFTipos.getLong("secuencia_inicial"));
                                        ps_Cambios.setLong(2, rsNCFTipos.getLong("secuencia_final"));
                                        ps_Cambios.setLong(3, rsNCFTipos.getLong("secuencia_aviso"));

                                        ps_Valores = _ex_connection.prepareStatement(Valores);
                                        ps_Valores.setLong(1, rstmp.getLong("id"));
                                        ps_Valores.setString(2, rstmp.getString("cia_codigo"));
                                        ps_Valores.setString(3, rsNCFTipos.getString("serie"));

                                        ps_Valores.setLong(4, rsNCFTipos.getLong("secuencia_inicial"));
                                        ps_Valores.setLong(5, rsNCFTipos.getLong("secuencia_final"));
                                        ps_Valores.setLong(6, rsNCFTipos.getLong("secuencia_actual"));
                                        ps_Valores.setLong(7, rsNCFTipos.getLong("secuencia_aviso"));

                                        //Guardando el encabezado de la secuencia de NCF
                                        _ex_SQLQuery = "SELECT * FROM public.fn_editar(?::varchar, ?::varchar, ?::varchar, ?::varchar, ?::varchar, ?::varchar, ?::varchar, ?::varchar, ?::varchar);";
                                        ps_ex = _ex_connection.prepareStatement(_ex_SQLQuery);
                                        ps_ex.setString(1, tabla);
                                        ps_ex.setString(2, ps_Cambios.toString());
                                        ps_ex.setString(3, "");
                                        ps_ex.setString(4, "");
                                        ps_ex.setString(5, ps_Condicion.toString());
                                        ps_ex.setString(6, Campos);
                                        ps_ex.setString(7, ps_Valores.toString());
                                        ps_ex.setString(8, "");
                                        ps_ex.setString(9, "");
                                        ps_ex.executeQuery();
                                    }
                                }
                                //Buscando el detalle de la solicitud de los NCF
                                _SQLQuery = "select * from dgii.d_secuenciancf_caja_" + this.Cajas + " where id = ? ";
                                ps_stmt = _connection.prepareStatement(_SQLQuery);
                                ps_stmt.setInt(1, rstmp.getInt("id"));
                                rsSecuenciasNCF = ps_stmt.executeQuery();
                                while (rsSecuenciasNCF.next()) {
                                    tabla = "dgii.d_secuenciancf_caja_" + this.Cajas;
                                    Campos = "id,cia_codigo,tipo_ncf,secuencia_inicial,secuencia_final,secuencia_aviso,secuencia_actual";
                                    Condicion = "id = ? and cia_codigo = ? and tipo_ncf = ?";
                                    Cambios = "secuencia_inicial = ?,secuencia_final=?,secuencia_aviso = ?";
                                    Valores = "?, ?, ?, ?, ?, ?, ?";
                                    ps_Condicion = _ex_connection.prepareStatement(Condicion);
                                    ps_Condicion.setLong(1, rstmp.getLong("id"));
                                    ps_Condicion.setString(2, rsSecuenciasNCF.getString("cia_codigo"));
                                    ps_Condicion.setString(3, rsSecuenciasNCF.getString("tipo_ncf"));

                                    ps_Cambios = _ex_connection.prepareStatement(Cambios);
                                    ps_Cambios.setLong(1, rsSecuenciasNCF.getLong("secuencia_inicial"));
                                    ps_Cambios.setLong(2, rsSecuenciasNCF.getLong("secuencia_final"));
                                    ps_Cambios.setLong(3, rsSecuenciasNCF.getLong("secuencia_aviso"));

                                    ps_Valores = _ex_connection.prepareStatement(Valores);
                                    ps_Valores.setLong(1, rstmp.getLong("id"));
                                    ps_Valores.setString(2, rsSecuenciasNCF.getString("cia_codigo"));
                                    ps_Valores.setString(3, rsSecuenciasNCF.getString("tipo_ncf"));

                                    ps_Valores.setLong(4, rsSecuenciasNCF.getLong("secuencia_inicial"));
                                    ps_Valores.setLong(5, rsSecuenciasNCF.getLong("secuencia_final"));
                                    ps_Valores.setLong(6, rsSecuenciasNCF.getLong("secuencia_aviso"));
                                    ps_Valores.setLong(7, rsSecuenciasNCF.getLong("secuencia_actual"));

                                    //Guardando el encabezado de la secuencia de NCF
                                    _ex_SQLQuery = "SELECT * FROM public.fn_editar(?::varchar, ?::varchar, ?::varchar, ?::varchar, ?::varchar, ?::varchar, ?::varchar, ?::varchar, ?::varchar);";
                                    ps_ex = _ex_connection.prepareStatement(_ex_SQLQuery);
                                    ps_ex.setString(1, tabla);
                                    ps_ex.setString(2, ps_Cambios.toString());
                                    ps_ex.setString(3, "");
                                    ps_ex.setString(4, "");
                                    ps_ex.setString(5, ps_Condicion.toString());
                                    ps_ex.setString(6, Campos);
                                    ps_ex.setString(7, ps_Valores.toString());
                                    ps_ex.setString(8, "");
                                    ps_ex.setString(9, "");
                                    ps_ex.executeQuery();
                                }
                                _ex_connection.commit();
                                _connection.commit();
                                _ex_connection.close();
                            }
                        }

                    }
                } catch (SQLException ex) {
                    message.setMessage(jtext1, "Caja: " + this.Cajas + " Ocurrio el siguiente error al actualizar las cajas: " + ex.getMessage());
                    this.b_QueryResult = false;
                    CerrarConexiones();
                    return this.b_QueryResult;
                }
            }
        }
        CerrarConexiones();

        return this.b_QueryResult;
    }
    
    public boolean ActualizarAlmacenes() {
        PreparedStatement ps_stmt, ps_ex;
        ResultSet rscentroscostos;

        tabla = "inv_almacenes";
        Campos = "cia_codigo, alma_codigo, alma_nombre, alma_direccion, alma_telefono, alma_encargado, alma_apertura,"
                + " alma_status, alma_ventas, alma_compras, alma_transferencia, alma_nocontrolar, numcen, alm_usarubicaciones";
        getServers();
        if (openConnection()) {

            Iterator<Servers> servidores = repo1.lstservidores.iterator();
            while (servidores.hasNext()) {
                Servers servidor = servidores.next();
                this.SetSlaveConnection(servidor.host_name, servidor.database_name, servidor.port_number, servidor.user_name, servidor.user_pwd);
                getCajasLocales();
                try {

                    _SQLQuery = "select b.alma_codigo, b.alma_nombre, b.alma_direccion, b.alma_telefono, b.alma_encargado, b.alma_apertura, b.alma_status,"
                                + " b.alma_ventas, b.alma_compras, b.alma_transferencia, b.alma_nocontrolar, b.numcen, b.alm_usarubicaciones,"
                                + " c.caja_ip, a.cia_codigo, a.borrado"
                            + " from vtas.almacenes_cajas a"
                            + " inner join inv_cajas c on(a.caja_cod = c.caja_cod)"
                            + " left join inv_almacenes b on (a.cia_codigo = b.cia_codigo and a.alma_codigo = b.alma_codigo)"
                            + " where a.cia_codigo = ? and a.sincronizado is false and c.caja_cod in (" + Cajas + ")"
                            + " order by a.borrado desc";
                    
                    ps_stmt = _connection.prepareStatement(_SQLQuery);
                    ps_stmt.setString(1, repo1.Company);
                    rscentroscostos = ps_stmt.executeQuery();

                    while (rscentroscostos.next()) {
                        this.SetCaja(servidor.cajas, repo1.Company);
                        message.setCaption(lblTransaccion, "Caja: " + this.Cajas + " Actualizando almacenes : " + rscentroscostos.getString("alma_nombre"));

                        if (ex_openConnection()) {
                            if (rscentroscostos.getBoolean("borrado") == true) {
                                _ex_SQLQuery = "delete from inv_almacenes where cia_codigo = ?::varchar "
                                        + " and alma_codigo = ?::varchar ";
                                ps_ex = _ex_connection.prepareStatement(_ex_SQLQuery);
                                ps_ex.setString(1, rscentroscostos.getString("cia_codigo"));
                                ps_ex.setString(2, rscentroscostos.getString("alma_codigo"));
                                ps_ex.execute();
                            } else {
                                Condicion = "cia_codigo = ?::varchar and alma_codigo = ?::varchar ";
                                ps_Condicion = _ex_connection.prepareStatement(Condicion);
                                ps_Condicion.setString(1, rscentroscostos.getString("cia_codigo"));
                                ps_Condicion.setString(2, rscentroscostos.getString("alma_codigo"));
                                
                                Cambios = "alma_codigo = ?::varchar, alma_nombre = ?::varchar, alma_direccion = ?::varchar,"
                                        + " alma_telefono = ?::varchar, alma_encargado = ?::varchar, alma_apertura = ?::date,"
                                        + " alma_status = ?::varchar, alma_ventas = ?::smallint, alma_compras = ?::smallint,"
                                        + " alma_transferencia = ?::smallint, alma_nocontrolar = ?::boolean,"
                                        + " numcen = ?::varchar, alm_usarubicaciones = ?::boolean";
                                ps_Cambios = _ex_connection.prepareStatement(Cambios);
                                ps_Cambios.setString(1, rscentroscostos.getString("alma_codigo"));
                                ps_Cambios.setString(2, rscentroscostos.getString("alma_nombre"));
                                ps_Cambios.setString(3, rscentroscostos.getString("alma_direccion"));
                                ps_Cambios.setString(4, rscentroscostos.getString("alma_telefono"));
                                ps_Cambios.setString(5, rscentroscostos.getString("alma_encargado"));
                                ps_Cambios.setDate(6, rscentroscostos.getDate("alma_apertura"));
                                ps_Cambios.setString(7, rscentroscostos.getString("alma_status"));
                                ps_Cambios.setInt(8, rscentroscostos.getInt("alma_ventas"));
                                ps_Cambios.setInt(9, rscentroscostos.getInt("alma_compras"));
                                ps_Cambios.setInt(10, rscentroscostos.getInt("alma_transferencia"));
                                ps_Cambios.setBoolean(11, rscentroscostos.getBoolean("alma_nocontrolar"));
                                ps_Cambios.setString(12, rscentroscostos.getString("numcen"));
                                ps_Cambios.setBoolean(13, rscentroscostos.getBoolean("alm_usarubicaciones"));
                                
                                Valores = "?::varchar, ?::varchar, ?::varchar, ?::varchar, ?::varchar, ?::varchar,"
                                        + " ?::date, ?::varchar, ?::smallint, ?::smallint, ?::smallint,"
                                        + " ?::boolean, ?::varchar, ?::boolean";
                                ps_Valores = _ex_connection.prepareStatement(Valores);
                                ps_Valores.setString(1, rscentroscostos.getString("cia_codigo"));
                                ps_Valores.setString(2, rscentroscostos.getString("alma_codigo"));
                                ps_Valores.setString(3, rscentroscostos.getString("alma_nombre"));
                                ps_Valores.setString(4, rscentroscostos.getString("alma_direccion"));
                                ps_Valores.setString(5, rscentroscostos.getString("alma_telefono"));
                                ps_Valores.setString(6, rscentroscostos.getString("alma_encargado"));
                                ps_Valores.setDate(7, rscentroscostos.getDate("alma_apertura"));
                                ps_Valores.setString(8, rscentroscostos.getString("alma_status"));
                                ps_Valores.setInt(9, rscentroscostos.getInt("alma_ventas"));
                                ps_Valores.setInt(10, rscentroscostos.getInt("alma_compras"));
                                ps_Valores.setInt(11, rscentroscostos.getInt("alma_transferencia"));
                                ps_Valores.setBoolean(12, rscentroscostos.getBoolean("alma_nocontrolar"));
                                ps_Valores.setString(13, rscentroscostos.getString("numcen"));
                                ps_Valores.setBoolean(14, rscentroscostos.getBoolean("alm_usarubicaciones"));

                                _ex_SQLQuery = "SELECT * FROM public.fn_editar(?::varchar, ?::varchar, ?::varchar, ?::varchar, ?::varchar, ?::varchar, ?::varchar, ?::varchar, ?::varchar);";
                                ps_ex = _ex_connection.prepareStatement(_ex_SQLQuery);
                                ps_ex.setString(1, tabla);
                                ps_ex.setString(2, ps_Cambios.toString());
                                ps_ex.setString(3, "");
                                ps_ex.setString(4, "");
                                ps_ex.setString(5, ps_Condicion.toString());
                                ps_ex.setString(6, Campos);
                                ps_ex.setString(7, ps_Valores.toString());
                                ps_ex.setString(8, "");
                                ps_ex.setString(9, "");
                                ps_ex.executeQuery();

                            }
                            _SQLQuery = "update vtas.almacenes_cajas set sincronizado = true where cia_codigo = ?::varchar "
                                    + " and alma_codigo = ?::varchar and caja_cod in(" + this.Cajas + ") ";
                            ps_stmt = _connection.prepareStatement(_SQLQuery);
                            ps_stmt.setString(1, rscentroscostos.getString("cia_codigo"));
                            ps_stmt.setString(2, rscentroscostos.getString("alma_codigo"));
                            ps_stmt.execute();
                            _ex_connection.commit();
                            _connection.commit();
                            _ex_connection.close();
                        }
                    }

                } catch (SQLException ex) {
                    message.setMessage(jtext1, "Caja: " + this.Cajas + " Ocurrio el siguiente error al actualizar los almacenes: " + ex.getMessage());
                    this.b_QueryResult = false;
                    CerrarConexiones();
                    return this.b_QueryResult;
                }
            }
        }
        CerrarConexiones();

        return this.b_QueryResult;
    }

    public void SetCaja(String CodigoCaja, String codigocompania) {
        //this.Cajas = CodigoCaja;
        this.Compania = codigocompania;

    }

    public void SetSlaveConnection(String host, String database, String portnumber, String username, String password) {
        _ex_Host = host;
        _ex_Database = database;
        _ex_User = username;
        _ex_Port = portnumber;
        _ex_Password = password;

    }

    private void CerrarConexiones() {
        try {
            if (_connection != null && !_connection.isClosed()) {
                _connection.close();
            }
        } catch (SQLException ex) {
            message.setMessage(jtext1, "Ocurrio el siguiente error al cerrar las conexiones: " + ex.getMessage());
        }

        try {
            if (_ex_connection != null && !_ex_connection.isClosed()) {
                _ex_connection.close();
            }
        } catch (SQLException ex) {
            message.setMessage(jtext1, "Ocurrio el siguiente error al cerrar las conexiones: " + ex.getMessage());
        }
    }

    private boolean getCajasLocales() {
        ResultSet rsCaja;
        PreparedStatement ps;
        try {
            Cajas = "";
//Consultando las cajas del servidor local
            if (ex_openConnection()) {
                _ex_SQLQuery = "SELECT caja_cod FROM inv_cajas WHERE cia_codigo = ? ORDER BY caja_cod";
                ps = _ex_connection.prepareStatement(_ex_SQLQuery);
                ps.setString(1, repo1.Company);
                rsCaja = ps.executeQuery();
                _ex_connection.close();
                Cajas = "";
                while (rsCaja.next()) {
                    Cajas = Cajas + (!Cajas.isEmpty() ? "," : " ") + ("'" + rsCaja.getString("caja_cod") + "'");
                }
            }
        } catch (SQLException e) {

        }
        return true;
    }
}
