
import java.text.ParseException;
import java.util.logging.Level;
import java.util.logging.Logger;

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

/*
 * JframeIngreso.java
 *
 * Created on 19-nov-2009, 12:46:47
 */

/**
 *
 */
public class JframeIRREM extends javax.swing.JFrame {
        Sucursal auxS= new Sucursal();
    /** Creates new form JframeIngreso */
        public JframeIRREM(Sucursal s) {

    /** Creates new form jfrmRemesaCargos */
        auxS=s;
        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() {

        jTabbedPane1 = new javax.swing.JTabbedPane();
        jPanel1 = new javax.swing.JPanel();
        jbtnvalidar = new javax.swing.JButton();
        jlblingresar = new javax.swing.JLabel();
        jlbcantidad = new javax.swing.JLabel();
        jlblcuenta = new javax.swing.JLabel();
        jtxtcuenta = new javax.swing.JTextField();
        jtxtImporte = new javax.swing.JTextField();
        jlblsaldo = new javax.swing.JLabel();
        jlblsaldotot = new javax.swing.JLabel();
        jlblerr = new javax.swing.JLabel();
        jPanel2 = new javax.swing.JPanel();
        jlblremesa = new javax.swing.JLabel();
        jlblfichero = new javax.swing.JLabel();
        jtxtPathFicheroRemesa = new javax.swing.JTextField();
        jbtnImportar = new javax.swing.JButton();
        jarea = new javax.swing.JScrollPane();
        jtxaVerRemesa = new javax.swing.JTextArea();
        jbtnValidar = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        jbtnvalidar.setText("Validar");
        jbtnvalidar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jbtnvalidarActionPerformed(evt);
            }
        });

        jlblingresar.setText("INGRESO / REINTEGRO");

        jlbcantidad.setText("Introduzca cantidad:");

        jlblcuenta.setText("Introduzca nº cuenta:");

        jtxtcuenta.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jtxtcuentaActionPerformed(evt);
            }
        });

        jtxtImporte.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jtxtImporteActionPerformed(evt);
            }
        });

        jlblsaldo.setText("Saldo actual: ");

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGap(163, 163, 163)
                        .addComponent(jbtnvalidar))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jlbcantidad)
                            .addComponent(jlblcuenta)
                            .addComponent(jlblsaldo))
                        .addGap(30, 30, 30)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jlblsaldotot)
                            .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                .addComponent(jtxtImporte, javax.swing.GroupLayout.DEFAULT_SIZE, 211, Short.MAX_VALUE)
                                .addComponent(jlblingresar, javax.swing.GroupLayout.PREFERRED_SIZE, 134, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addComponent(jtxtcuenta))
                            .addComponent(jlblerr))))
                .addContainerGap(228, Short.MAX_VALUE))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addComponent(jlblingresar, javax.swing.GroupLayout.PREFERRED_SIZE, 34, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(15, 15, 15)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jtxtcuenta, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jlblcuenta))
                .addGap(18, 18, 18)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jtxtImporte, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jlbcantidad))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jbtnvalidar)
                .addGap(40, 40, 40)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jlblsaldo)
                    .addComponent(jlblsaldotot))
                .addGap(51, 51, 51)
                .addComponent(jlblerr)
                .addContainerGap(76, Short.MAX_VALUE))
        );

        jTabbedPane1.addTab("Ingreso/Reintegro", jPanel1);

        jlblremesa.setText("Tratamiento remesa de cargos");

        jlblfichero.setText("Fichero a tratar:");

        jtxtPathFicheroRemesa.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jtxtPathFicheroRemesaActionPerformed(evt);
            }
        });

        jbtnImportar.setText("Importar");
        jbtnImportar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jbtnImportarActionPerformed(evt);
            }
        });

        jtxaVerRemesa.setColumns(20);
        jtxaVerRemesa.setRows(5);
        jarea.setViewportView(jtxaVerRemesa);

        jbtnValidar.setText("Validar");
        jbtnValidar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jbtnValidarActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addGap(21, 21, 21)
                        .addComponent(jlblfichero)
                        .addGap(75, 75, 75)
                        .addComponent(jtxtPathFicheroRemesa, javax.swing.GroupLayout.PREFERRED_SIZE, 232, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(jarea, javax.swing.GroupLayout.DEFAULT_SIZE, 565, Short.MAX_VALUE))
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addGap(167, 167, 167)
                        .addComponent(jlblremesa))
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addGap(210, 210, 210)
                        .addComponent(jbtnImportar))
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addGap(211, 211, 211)
                        .addComponent(jbtnValidar)))
                .addContainerGap())
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jlblremesa)
                .addGap(41, 41, 41)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jlblfichero)
                    .addComponent(jtxtPathFicheroRemesa, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jbtnImportar)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jarea, javax.swing.GroupLayout.PREFERRED_SIZE, 143, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 19, Short.MAX_VALUE)
                .addComponent(jbtnValidar)
                .addContainerGap())
        );

        jTabbedPane1.addTab("Remesa", jPanel2);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jTabbedPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 590, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jTabbedPane1, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 345, Short.MAX_VALUE)
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents
    private void jtxtImporteActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jtxtImporteActionPerformed
        // TOD add your handling code here:
    }//GEN-LAST:event_jtxtImporteActionPerformed

    private void jbtnvalidarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbtnvalidarActionPerformed
        // TODO add your handling code here:
        jlblerr.setText("");
        Float f=Float.valueOf(jtxtImporte.getText());
        if(auxS.devuelveProducto(jtxtcuenta.getText())==null) {
                   jlblerr.setText("La cuenta no existe.");
                                                            }
        
        else if(auxS.devuelveProducto(jtxtcuenta.getText()).getSaldo()+f <0 && f<0){
            jlblerr.setText("Está en números rojos, no puede sacar dinero.");
                                                                                    }
        else{
        auxS.modificarsaldo(jtxtcuenta.getText(),jtxtImporte.getText());
        String mensaje=String.valueOf(auxS.devuelveProducto(jtxtcuenta.getText()).getSaldo());
        jlblsaldotot.setText(mensaje);
        }
    }//GEN-LAST:event_jbtnvalidarActionPerformed

    private void jtxtcuentaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jtxtcuentaActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_jtxtcuentaActionPerformed

    private void jtxtPathFicheroRemesaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jtxtPathFicheroRemesaActionPerformed
        // TODO add your handling code here:
}//GEN-LAST:event_jtxtPathFicheroRemesaActionPerformed

    private void jbtnImportarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbtnImportarActionPerformed
        String mensaje=auxS.verRemesa(jtxtPathFicheroRemesa.getText());
        jtxaVerRemesa.setText(mensaje);
}//GEN-LAST:event_jbtnImportarActionPerformed

    private void jbtnValidarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbtnValidarActionPerformed
        try {
            auxS.incorporarRemesa(jtxtPathFicheroRemesa.getText());
        } catch (ParseException ex) {
            Logger.getLogger(JframeIRREM.class.getName()).log(Level.SEVERE, null, ex);
        }
}//GEN-LAST:event_jbtnValidarActionPerformed

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

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JTabbedPane jTabbedPane1;
    private javax.swing.JScrollPane jarea;
    private javax.swing.JButton jbtnImportar;
    private javax.swing.JButton jbtnValidar;
    private javax.swing.JButton jbtnvalidar;
    private javax.swing.JLabel jlbcantidad;
    private javax.swing.JLabel jlblcuenta;
    private javax.swing.JLabel jlblerr;
    private javax.swing.JLabel jlblfichero;
    private javax.swing.JLabel jlblingresar;
    private javax.swing.JLabel jlblremesa;
    private javax.swing.JLabel jlblsaldo;
    private javax.swing.JLabel jlblsaldotot;
    private javax.swing.JTextArea jtxaVerRemesa;
    private javax.swing.JTextField jtxtImporte;
    private javax.swing.JTextField jtxtPathFicheroRemesa;
    private javax.swing.JTextField jtxtcuenta;
    // End of variables declaration//GEN-END:variables

}
