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

/*
 * JFDomiciliaciones.java
 *
 * Created on 13-oct-2010, 13:20:58
 */

package vistas;

import javabbuva.Producto;
import javabbuva.*;

/**
 *
 * @author Adrian
 */
public class JFDomiciliaciones extends javax.swing.JFrame {

    Sucursal su;
    JFPrincipal p;
    JFVerCuentas ver;

    /** Creates new form JFDomiciliaciones */
    public JFDomiciliaciones(Sucursal su, JFPrincipal p) {
        this.su = su;
        this.p = p;
        p.setEnabled(false);
        ver = new JFVerCuentas(su,p);
        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() {

        jLTitulo = new javax.swing.JLabel();
        jBTerminar = new javax.swing.JButton();
        jBSeleccionar = new javax.swing.JButton();
        jBver = new javax.swing.JButton();
        jLerror = new javax.swing.JLabel();
        jScrollPane1 = new javax.swing.JScrollPane();
        jTmostrar = new javax.swing.JTextArea();
        jLSaldo = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setResizable(false);
        addWindowListener(new java.awt.event.WindowAdapter() {
            public void windowActivated(java.awt.event.WindowEvent evt) {
                formWindowActivated(evt);
            }
            public void windowClosed(java.awt.event.WindowEvent evt) {
                formWindowClosed(evt);
            }
        });

        jLTitulo.setFont(new java.awt.Font("Tahoma", 1, 12));
        jLTitulo.setText("Ver domiciliaciones de una cuenta.");

        jBTerminar.setText("Terminar");
        jBTerminar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jBTerminarActionPerformed(evt);
            }
        });

        jBSeleccionar.setText("Seleccionar la cuenta");
        jBSeleccionar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jBSeleccionarActionPerformed(evt);
            }
        });

        jBver.setText("Ver domiciliaciones");
        jBver.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jBverActionPerformed(evt);
            }
        });

        jLerror.setFont(new java.awt.Font("Tahoma", 1, 12));
        jLerror.setForeground(new java.awt.Color(204, 0, 0));

        jScrollPane1.setEnabled(false);

        jTmostrar.setColumns(20);
        jTmostrar.setEditable(false);
        jTmostrar.setFont(new java.awt.Font("Monospaced", 3, 12));
        jTmostrar.setForeground(new java.awt.Color(0, 0, 51));
        jTmostrar.setRows(5);
        jScrollPane1.setViewportView(jTmostrar);

        jLSaldo.setFont(new java.awt.Font("Tahoma", 1, 14));
        jLSaldo.setForeground(new java.awt.Color(51, 51, 51));
        jLSaldo.setText("0");
        jLSaldo.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED));

        jLabel2.setForeground(new java.awt.Color(51, 51, 51));
        jLabel2.setText("Saldo actual en caja:");

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(jBTerminar))
                    .addGroup(layout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(jLTitulo))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(30, 30, 30)
                        .addComponent(jBSeleccionar)
                        .addGap(39, 39, 39)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLerror, javax.swing.GroupLayout.PREFERRED_SIZE, 236, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jBver)))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(19, 19, 19)
                        .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 492, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLSaldo, javax.swing.GroupLayout.PREFERRED_SIZE, 89, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel2))))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jLabel2)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(jLSaldo))
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jLTitulo)
                        .addGap(18, 18, 18)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jBSeleccionar)
                            .addComponent(jLerror, javax.swing.GroupLayout.PREFERRED_SIZE, 18, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(20, 20, 20)
                        .addComponent(jBver)
                        .addGap(20, 20, 20)
                        .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 115, Short.MAX_VALUE)
                        .addGap(18, 18, 18)
                        .addComponent(jBTerminar)))
                .addContainerGap())
        );

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

    private void jBTerminarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jBTerminarActionPerformed
        // TODO add your handling code here:
        this.dispose();
}//GEN-LAST:event_jBTerminarActionPerformed

    private void jBSeleccionarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jBSeleccionarActionPerformed
        // TODO add your handling code here:
        if(!ver.isVisible()){
            ver.show();
            ver.ingreso = true;
            jTmostrar.setText("");
        }
    }//GEN-LAST:event_jBSeleccionarActionPerformed

    private void formWindowClosed(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_formWindowClosed
        // TODO add your handling code here:
        p.setEnabled(true);
    }//GEN-LAST:event_formWindowClosed

    private void jBverActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jBverActionPerformed
        // TODO add your handling code here:
        jLerror.setText("");
        int i = 0;
        String añadir="";
        if(p.escogida==true){
            Producto cuentaprovisional = su.dameCuenta(p.auxiliar);
            if(cuentaprovisional.getMDomiciliaciones().size()==0)
                jLerror.setText("Esta cuenta no tiene domiciliaciones");
            while(i<cuentaprovisional.getMDomiciliaciones().size()){
                añadir+=cuentaprovisional.getMDomiciliaciones().get(i).getNombreD()+'\n';
                i++;
            }
            jTmostrar.setText(añadir);
        }
        else{
            jLerror.setText("Seleccione una cuenta primero");
        }
    }//GEN-LAST:event_jBverActionPerformed

    private void formWindowActivated(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_formWindowActivated
        // TODO add your handling code here:
        jLSaldo.setText(String.valueOf(su.getCajaActual().getSaldo()));
    }//GEN-LAST:event_formWindowActivated

    /**
    * @param args the command line arguments
    */
    /*public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new JFDomiciliaciones().setVisible(true);
            }
        });
    }*/

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jBSeleccionar;
    private javax.swing.JButton jBTerminar;
    private javax.swing.JButton jBver;
    private javax.swing.JLabel jLSaldo;
    private javax.swing.JLabel jLTitulo;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLerror;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JTextArea jTmostrar;
    // End of variables declaration//GEN-END:variables

}
