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

/*
 * jfrmLoginArqueo.java
 *
 * Created on 08-ene-2010, 12:19:54
 */

package Vistas;

import Modelo.Sucursal;
import java.text.DecimalFormat;
import java.text.ParseException;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author Administrador
 */
public class jfrmLoginArqueo extends javax.swing.JFrame {
    Sucursal sucAux = new Sucursal();
    
        /** Creates new form jfrmLoginArqueo */
    public jfrmLoginArqueo(Sucursal suc) {
        initComponents();
        sucAux=suc;
    }

    /** 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() {

        jLabel6 = new javax.swing.JLabel();
        label2 = new java.awt.Label();
        jlblDoc = new javax.swing.JLabel();
        jLabel5 = new javax.swing.JLabel();
        jtxtDocumentacion = new javax.swing.JTextField();
        jtxtImporteInicial = new javax.swing.JTextField();
        jbtAceptar = new javax.swing.JButton();
        jlblInformacion = new javax.swing.JLabel();
        jLabel7 = new javax.swing.JLabel();
        jtxtCaja = new javax.swing.JTextField();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);

        jLabel6.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Vistas/EstafadorLogo2.JPG"))); // NOI18N

        label2.setFont(new java.awt.Font("Comic Sans MS", 1, 48));
        label2.setText("SwindlerBank");

        jlblDoc.setFont(new java.awt.Font("Comic Sans MS", 0, 14));
        jlblDoc.setText("DNI/NIF:");

        jLabel5.setFont(new java.awt.Font("Comic Sans MS", 0, 14));
        jLabel5.setText("Importe Inicial:");

        jtxtDocumentacion.setText("12345678A");
        jtxtDocumentacion.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jtxtDocumentacionActionPerformed(evt);
            }
        });

        jtxtImporteInicial.setText("2000");

        jbtAceptar.setText("Aceptar");
        jbtAceptar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jbtAceptarActionPerformed(evt);
            }
        });

        jLabel7.setFont(new java.awt.Font("Comic Sans MS", 0, 14));
        jLabel7.setText("Caja");

        jtxtCaja.setText("1");

        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.TRAILING)
                    .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
                        .addGap(62, 62, 62)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jlblDoc)
                            .addComponent(jLabel5)
                            .addComponent(jLabel7))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 22, Short.MAX_VALUE)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(jtxtDocumentacion, javax.swing.GroupLayout.PREFERRED_SIZE, 298, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(106, 106, 106))
                            .addGroup(layout.createSequentialGroup()
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(jtxtImporteInicial, javax.swing.GroupLayout.PREFERRED_SIZE, 97, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addComponent(jtxtCaja, javax.swing.GroupLayout.PREFERRED_SIZE, 97, javax.swing.GroupLayout.PREFERRED_SIZE))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 198, Short.MAX_VALUE)
                                .addComponent(jbtAceptar)
                                .addGap(38, 38, 38))))
                    .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
                        .addGap(38, 38, 38)
                        .addComponent(jLabel6)
                        .addGap(84, 84, 84)
                        .addComponent(label2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap(21, javax.swing.GroupLayout.PREFERRED_SIZE))
            .addGroup(layout.createSequentialGroup()
                .addGap(120, 120, 120)
                .addComponent(jlblInformacion, javax.swing.GroupLayout.PREFERRED_SIZE, 251, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(242, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(19, 19, 19)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(label2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel6))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 32, Short.MAX_VALUE)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jlblDoc)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(jLabel5)
                        .addGap(1, 1, 1))
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jtxtDocumentacion, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(jtxtImporteInicial, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addGap(8, 8, 8)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel7)
                    .addComponent(jtxtCaja, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jlblInformacion, javax.swing.GroupLayout.PREFERRED_SIZE, 15, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(24, 24, 24))
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap(258, Short.MAX_VALUE)
                .addComponent(jbtAceptar)
                .addGap(61, 61, 61))
        );

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

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

    private void jbtAceptarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbtAceptarActionPerformed

        if(sucAux.busquedaEmpleadosSucursal(jtxtDocumentacion.getText()))
        {
            //jlblInformacion.setText("Login correcto");
            //double cantidad = Double.valueOf(jtxtImporteInicial.getText()).doubleValue();

            if(jtxtImporteInicial.getText().equals(""))
            {jlblInformacion.setText("Introduzca importe");}
            
            else
            {
               
                DecimalFormat df = new DecimalFormat("#######,##");

                Number n = null;

                try {
                    n = df.parse(jtxtImporteInicial.getText());
                } catch (ParseException ex) {
                    Logger.getLogger(jfrmIngreso.class.getName()).log(Level.SEVERE, null, ex);
                }
                    
                    

                    if(jtxtCaja.getText().equals(""))
                    {
                        jlblInformacion.setText("Seleccione Caja");
                    }

                    else
                    {
                        double idcaja = Double.valueOf(jtxtCaja.getText()).doubleValue();

                        if(sucAux.bbusquedaCajaSucursal(idcaja))
                        {
                            if(sucAux.CajaOcupada(idcaja))
                            {
                                jlblInformacion.setText("Caja seleccionada ocupada");
                            }

                            else
                            {
                                sucAux.inicializaSaldo(n.doubleValue(),idcaja,jtxtDocumentacion.getText());


                                new jfrmPrincipal(sucAux,this).setVisible(true);
                                this.setEnabled(false);
                                this.setVisible(false);
                            }
                        }
                        else
                        {
                            jlblInformacion.setText("Caja seleccionada NO EXISTE");
                        }
                    
                    }
            }
        }

        else {
            jlblInformacion.setText("Login incorrecto");
        }
}//GEN-LAST:event_jbtAceptarActionPerformed

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

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JButton jbtAceptar;
    private javax.swing.JLabel jlblDoc;
    private javax.swing.JLabel jlblInformacion;
    private javax.swing.JTextField jtxtCaja;
    private javax.swing.JTextField jtxtDocumentacion;
    private javax.swing.JTextField jtxtImporteInicial;
    private java.awt.Label label2;
    // End of variables declaration//GEN-END:variables

}
