/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * jfrmVerDomiciliacion.java
 *
 * Created on 11-dic-2009, 19:36:31
 */

package dia4g3java;

import java.util.ArrayList;
import java.util.Iterator;
import javax.swing.DefaultListModel;
import javax.swing.ListSelectionModel;

/**
 *
 * @author pelujl
 */
public class jfrmVerDomiciliacion extends javax.swing.JFrame {
    Sucursal AuxSuc;
    javax.swing.JFrame auxjf;

    /** Creates new form jfrmVerDomiciliacion */
    public jfrmVerDomiciliacion(Sucursal suc, javax.swing.JFrame jf) {
        AuxSuc = suc;
        auxjf=jf;
        initComponents();
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jSeparator1 = new javax.swing.JSeparator();
        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        jrbNombre = new javax.swing.JRadioButton();
        jScrollPane2 = new javax.swing.JScrollPane();
        jlistamovimientos = new javax.swing.JList();
        jScrollPane1 = new javax.swing.JScrollPane();
        jlstCuentas = new javax.swing.JList();
        jbtnSeleccionar = new javax.swing.JButton();
        jLabel3 = new javax.swing.JLabel();
        jbtnBuscar = new javax.swing.JButton();
        jrbDniCif = new javax.swing.JRadioButton();
        jtxtCadenaBusqueda = new javax.swing.JTextField();
        jbtnSalir = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        jLabel1.setText("Ultimos movimientos de cuenta.");

        jLabel2.setText("Realizar busqueda por:");

        jrbNombre.setText("por Nombre");

        jScrollPane2.setViewportView(jlistamovimientos);

        jScrollPane1.setViewportView(jlstCuentas);

        jbtnSeleccionar.setText("Seleccionar");
        jbtnSeleccionar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jbtnSeleccionarActionPerformed(evt);
            }
        });

        jLabel3.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
        jLabel3.setText("Domiciliaciones de la cuenta");

        jbtnBuscar.setText("Buscar");
        jbtnBuscar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jbtnBuscarActionPerformed(evt);
            }
        });

        jrbDniCif.setText("por NIF/CIF");

        jbtnSalir.setText("Salir");
        jbtnSalir.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jbtnSalirActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 669, Short.MAX_VALUE)
            .addComponent(jSeparator1, javax.swing.GroupLayout.DEFAULT_SIZE, 669, Short.MAX_VALUE)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel1)
                .addContainerGap(508, Short.MAX_VALUE))
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(layout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(jbtnSeleccionar))
                    .addGroup(layout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(jbtnBuscar, javax.swing.GroupLayout.PREFERRED_SIZE, 147, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
                        .addGap(31, 31, 31)
                        .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 276, Short.MAX_VALUE))
                    .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
                        .addGap(26, 26, 26)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jtxtCadenaBusqueda, javax.swing.GroupLayout.DEFAULT_SIZE, 281, Short.MAX_VALUE)
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(jLabel2)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addComponent(jrbNombre)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(jrbDniCif)))))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 346, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jbtnSalir, javax.swing.GroupLayout.PREFERRED_SIZE, 89, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addContainerGap())
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jLabel3, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addGap(24, 24, 24))))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 331, Short.MAX_VALUE)
            .addGroup(layout.createSequentialGroup()
                .addGap(11, 11, 11)
                .addComponent(jLabel1)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jSeparator1, javax.swing.GroupLayout.PREFERRED_SIZE, 10, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel2)
                    .addComponent(jrbNombre)
                    .addComponent(jrbDniCif)
                    .addComponent(jLabel3))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jtxtCadenaBusqueda, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18)
                        .addComponent(jbtnBuscar)
                        .addGap(11, 11, 11)
                        .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 141, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addComponent(jScrollPane2))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jbtnSeleccionar)
                    .addComponent(jbtnSalir))
                .addContainerGap())
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jbtnSeleccionarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbtnSeleccionarActionPerformed
        // TODO add your handling code here:

        String cta = new String();
        String cadena=(String) jlstCuentas.getSelectedValue();
        cta = cadena.substring(0,20);
        System.out.println(cta);

        Producto p = AuxSuc.devuelveProducto(cta);

        ArrayList<Movimiento> m = p.getMovimiento();

        Iterator iterador = m.listIterator();
        
        DefaultListModel dlm = new DefaultListModel();
        jlistamovimientos.setModel(dlm);


        while(iterador.hasNext()){
            Movimiento mov = (Movimiento) iterador.next();
            if ((mov.getConcepto().compareTo("INGRESO")!=0) && (mov.getConcepto().compareTo("REINTEGRO")!=0)){
            dlm.addElement(mov.getConcepto()+"  -    "+mov.getFechaOperacion()+"    -      "+mov.getImporte());
            }
        }

        /*
        ArrayList<Producto> a = AuxSuc.busquedaProductosCliente(jtxtCadenaBusqueda.getText(), tipoBusqueda);
        DefaultListModel dlm = new DefaultListModel();
        jlstCuentas.setModel(dlm);
        jlstCuentas.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
        Iterator iterador = a.listIterator();

        while (iterador.hasNext()){
            Producto p = (Producto) iterador.next();
            dlm.addElement(p.getNumeroProducto()+"  "+p.getSaldo());
        }
         */

    }//GEN-LAST:event_jbtnSeleccionarActionPerformed

    private void jbtnBuscarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbtnBuscarActionPerformed
        // TODO add your handling code here:
        int tipoBusqueda=0;
        if(jrbDniCif.isSelected()){
            tipoBusqueda=1;
        }else{
            if(jrbNombre.isSelected()){
                tipoBusqueda=2;
            }
        }
        ArrayList<Producto> a = AuxSuc.busquedaProductosCliente(jtxtCadenaBusqueda.getText(), tipoBusqueda);
        DefaultListModel dlm = new DefaultListModel();
        jlstCuentas.setModel(dlm);
        jlstCuentas.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
        Iterator iterador = a.listIterator();

        while (iterador.hasNext()){
            Producto p = (Producto) iterador.next();
            dlm.addElement(p.getNumeroProducto()+"  "+p.getSaldo());
        }






    }//GEN-LAST:event_jbtnBuscarActionPerformed

    private void jbtnSalirActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbtnSalirActionPerformed
        // TODO add your handling code here:
        auxjf.setEnabled(true);
        this.dispose();
}//GEN-LAST:event_jbtnSalirActionPerformed

    /**
    * @param args the command line arguments
    */
 /*   public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new jfrmVerDomiciliacion().setVisible(true);
            }
        });
    }
*/
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JSeparator jSeparator1;
    private javax.swing.JButton jbtnBuscar;
    private javax.swing.JButton jbtnSalir;
    private javax.swing.JButton jbtnSeleccionar;
    private javax.swing.JList jlistamovimientos;
    private javax.swing.JList jlstCuentas;
    private javax.swing.JRadioButton jrbDniCif;
    private javax.swing.JRadioButton jrbNombre;
    private javax.swing.JTextField jtxtCadenaBusqueda;
    // End of variables declaration//GEN-END:variables

}
