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

/*
 * jfrmReintegros.java
 *
 * Created on 21-nov-2009, 19:17:27
 */

package dia4g3java;

/**
 *
 * @author pelujl
 */
public class jfrmReintegros extends javax.swing.JFrame {
    Sucursal auxSucursal = new Sucursal();
    Producto auxproducto = new Producto();
    /** Creates new form jfrmReintegros */
    public jfrmReintegros(Sucursal suc) {
        auxSucursal = suc;
        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() {

        jLabel1 = new javax.swing.JLabel();
        jSeparator1 = new javax.swing.JSeparator();
        jLabel2 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        txt_numcta = new javax.swing.JTextField();
        txt_nomtitular = new javax.swing.JTextField();
        jSeparator2 = new javax.swing.JSeparator();
        btn_identificacion = new javax.swing.JButton();
        jLabel4 = new javax.swing.JLabel();
        txt_info = new javax.swing.JLabel();
        lbl_adicional = new javax.swing.JLabel();
        lbl_fecha = new javax.swing.JLabel();
        lbl_importe = new javax.swing.JLabel();
        lbl_concepto = new javax.swing.JLabel();
        txt_fecha = new javax.swing.JTextField();
        txt_importe = new javax.swing.JTextField();
        txt_concepto = new javax.swing.JTextField();
        btn_reintegro = new javax.swing.JButton();
        txt_nota2 = new javax.swing.JLabel();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        jLabel1.setText("REALIZAR REINTEGRO.");

        jLabel2.setText("Introduzca el número de cuenta:");

        jLabel3.setText("Introduzca el nombre y apellidos del titular:");

        btn_identificacion.setText("Realizar Identificación");
        btn_identificacion.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btn_identificacionActionPerformed(evt);
            }
        });

        txt_info.setForeground(new java.awt.Color(255, 51, 51));

        lbl_adicional.setText("DATOS ADICIONALES DEL REINTEGRO");
        lbl_adicional.setEnabled(false);

        lbl_fecha.setText("Fecha del reintegro:");
        lbl_fecha.setEnabled(false);

        lbl_importe.setText("Importe del reintegro:");
        lbl_importe.setEnabled(false);

        lbl_concepto.setText("Concepto del reintegro:");
        lbl_concepto.setEnabled(false);

        txt_fecha.setEnabled(false);

        txt_importe.setEnabled(false);

        txt_concepto.setEnabled(false);

        btn_reintegro.setText("Realizar Reintegro");
        btn_reintegro.setEnabled(false);
        btn_reintegro.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btn_reintegroActionPerformed(evt);
            }
        });

        txt_nota2.setForeground(new java.awt.Color(255, 0, 51));

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel1)
                .addContainerGap(699, Short.MAX_VALUE))
            .addComponent(jSeparator1, javax.swing.GroupLayout.DEFAULT_SIZE, 823, Short.MAX_VALUE)
            .addGroup(layout.createSequentialGroup()
                .addGap(118, 118, 118)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jLabel3)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(txt_nomtitular))
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jLabel2)
                        .addGap(18, 18, 18)
                        .addComponent(txt_numcta, javax.swing.GroupLayout.PREFERRED_SIZE, 271, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 81, Short.MAX_VALUE)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(txt_info, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jLabel4, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(btn_identificacion, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addGap(41, 41, 41))
            .addComponent(jSeparator2, javax.swing.GroupLayout.DEFAULT_SIZE, 823, Short.MAX_VALUE)
            .addGroup(layout.createSequentialGroup()
                .addGap(28, 28, 28)
                .addComponent(lbl_adicional)
                .addContainerGap(608, Short.MAX_VALUE))
            .addGroup(layout.createSequentialGroup()
                .addGap(121, 121, 121)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(lbl_concepto)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(txt_concepto))
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(lbl_importe)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(txt_importe))
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(lbl_fecha)
                        .addGap(18, 18, 18)
                        .addComponent(txt_fecha, javax.swing.GroupLayout.PREFERRED_SIZE, 328, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addGap(79, 79, 79)
                .addComponent(btn_reintegro, javax.swing.GroupLayout.PREFERRED_SIZE, 146, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(34, Short.MAX_VALUE))
            .addGroup(layout.createSequentialGroup()
                .addGap(179, 179, 179)
                .addComponent(txt_nota2, javax.swing.GroupLayout.PREFERRED_SIZE, 435, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(209, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel1)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .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.LEADING)
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(jLabel2)
                        .addComponent(txt_numcta, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(txt_info))
                    .addComponent(jLabel4))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel3)
                    .addComponent(txt_nomtitular, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(btn_identificacion))
                .addGap(37, 37, 37)
                .addComponent(jSeparator2, javax.swing.GroupLayout.PREFERRED_SIZE, 10, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(lbl_adicional)
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(lbl_fecha)
                    .addComponent(txt_fecha, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(lbl_importe)
                    .addComponent(txt_importe, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(btn_reintegro))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(lbl_concepto)
                    .addComponent(txt_concepto, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 54, Short.MAX_VALUE)
                .addComponent(txt_nota2)
                .addGap(42, 42, 42))
        );

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

    private void btn_identificacionActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btn_identificacionActionPerformed
        // TODO add your handling code here:
        String auxNumCta = new String();
        String auxNombre = new String();

        auxNumCta = txt_numcta.getText();
        auxNombre = txt_nomtitular.getText();

        auxproducto=auxSucursal.devuelveProducto(auxNumCta);

        if(auxproducto == null){
            txt_info.setText("Datos incorrectos");
            lbl_adicional.setEnabled(false);
            lbl_fecha.setEnabled(false);
            lbl_concepto.setEnabled(false);
            lbl_importe.setEnabled(false);
            btn_reintegro.setEnabled(false);
        }else{

            String nomCtaSele = new String();
           // nomCtaSele = auxproducto.getNombreCliente();
            if(auxNombre.compareTo(nomCtaSele) == 0){
                txt_info.setText("");
                lbl_adicional.setEnabled(true);
                lbl_fecha.setEnabled(true);
                lbl_concepto.setEnabled(true);
                lbl_importe.setEnabled(true);
                btn_reintegro.setEnabled(true);
                txt_info.setText(auxproducto.calcularSaldoenCuenta().toString());
                txt_importe.setEnabled(true);
                txt_concepto.setEnabled(true);
                java.util.Date fecha_actual = new java.util.Date();
                txt_fecha.setText(fecha_actual.toString());

            }else{
                 lbl_adicional.setEnabled(false);
                lbl_fecha.setEnabled(false);
                lbl_concepto.setEnabled(false);
                lbl_importe.setEnabled(false);
                btn_reintegro.setEnabled(false);
                txt_info.setText("Datos incorrectos");
                }
            }

    }//GEN-LAST:event_btn_identificacionActionPerformed

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

        String cantidad = new String();
        cantidad = txt_importe.getText();
        Float money = Float.valueOf(cantidad);
        Float money_negativo = Float.valueOf(0);
        java.util.Date fecha_actual = new java.util.Date();
        Movimiento reintegro = new Movimiento();

        money_negativo = money_negativo - money;
        reintegro.setConcepto(txt_concepto.getText());
        reintegro.setFechaOperacion(fecha_actual);
        reintegro.setImporte(money_negativo);

        auxproducto.insertaMovimientoenCuenta(reintegro);

        txt_nota2.setText("Se han extraido "+money_negativo+" Euros de la cuenta "+ auxproducto.getNumeroProducto()+".");
        
        txt_importe.setText("");
        txt_fecha.setText("");
        txt_concepto.setText("");
        txt_numcta.setText("");
        txt_nomtitular.setText("");
        lbl_adicional.setEnabled(false);
        lbl_fecha.setEnabled(false);
        lbl_concepto.setEnabled(false);
        lbl_importe.setEnabled(false);
        btn_reintegro.setEnabled(false);
    }//GEN-LAST:event_btn_reintegroActionPerformed

    /**
    * @param args the command line arguments
    */

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btn_identificacion;
    private javax.swing.JButton btn_reintegro;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JSeparator jSeparator1;
    private javax.swing.JSeparator jSeparator2;
    private javax.swing.JLabel lbl_adicional;
    private javax.swing.JLabel lbl_concepto;
    private javax.swing.JLabel lbl_fecha;
    private javax.swing.JLabel lbl_importe;
    private javax.swing.JTextField txt_concepto;
    private javax.swing.JTextField txt_fecha;
    private javax.swing.JTextField txt_importe;
    private javax.swing.JLabel txt_info;
    private javax.swing.JTextField txt_nomtitular;
    private javax.swing.JLabel txt_nota2;
    private javax.swing.JTextField txt_numcta;
    // End of variables declaration//GEN-END:variables

}
