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

/*
 * jfrmArqueo.java
 *
 * Created on 08-ene-2010, 11:56:48
 */

package Vistas;

import Modelo.*;
import java.text.DecimalFormat;
import java.text.ParseException;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JFrame;

/**
 *
 * @author Administrador
 */
public class jfrmArqueo extends javax.swing.JFrame {

    JFrame auxJf;
    Sucursal sucAux = new Sucursal();

    /** Creates new form jfrmArqueo */
    public jfrmArqueo(Sucursal suc,JFrame jf) {
        auxJf=jf;
        initComponents();
        sucAux = suc;
        jtxtDocumentacion.setText(String.valueOf(sucAux.dameDNIEmpleado()));
        jtxtImpFinal.setText(String.valueOf(sucAux.saldoCaja(sucAux.dameDNIEmpleado())));
        jtxtImpCajaCentral.setText(String.valueOf(sucAux.saldoCajaCentral()));
        jbtnParteDiferencia.setVisible(false);
    }

    /** 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();
        jLabel1 = new javax.swing.JLabel();
        jlblDoc = new javax.swing.JLabel();
        jtxtDocumentacion = new javax.swing.JTextField();
        jLabel7 = new javax.swing.JLabel();
        jtxtImpFinal = new javax.swing.JTextField();
        jLabel8 = new javax.swing.JLabel();
        jtxtRecuento = new javax.swing.JTextField();
        jlblDescuadre = new javax.swing.JLabel();
        jtxtDescuadre = new javax.swing.JTextField();
        jSeparator1 = new javax.swing.JSeparator();
        jButton1 = new javax.swing.JButton();
        jLabel9 = new javax.swing.JLabel();
        jtxtImpCajaCentral = new javax.swing.JTextField();
        jlblInformacion = new javax.swing.JLabel();
        jbtnParteDiferencia = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        addWindowListener(new java.awt.event.WindowAdapter() {
            public void windowClosing(java.awt.event.WindowEvent evt) {
                formWindowClosing(evt);
            }
        });

        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");

        jLabel1.setFont(new java.awt.Font("Comic Sans MS", 1, 18));
        jLabel1.setText("Arqueo");

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

        jtxtDocumentacion.setEditable(false);
        jtxtDocumentacion.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jtxtDocumentacionActionPerformed(evt);
            }
        });

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

        jtxtImpFinal.setEditable(false);
        jtxtImpFinal.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jtxtImpFinalActionPerformed(evt);
            }
        });

        jLabel8.setFont(new java.awt.Font("Comic Sans MS", 0, 14));
        jLabel8.setText("Recuento:");

        jlblDescuadre.setFont(new java.awt.Font("Comic Sans MS", 0, 14));
        jlblDescuadre.setText("Descuadre:");

        jtxtDescuadre.setEditable(false);
        jtxtDescuadre.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jtxtDescuadreActionPerformed(evt);
            }
        });

        jButton1.setText("Confirmar");
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });

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

        jtxtImpCajaCentral.setEditable(false);

        jbtnParteDiferencia.setText("Parte de Diferencia");
        jbtnParteDiferencia.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jbtnParteDiferenciaActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(38, 38, 38)
                .addComponent(jLabel6)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(84, 84, 84)
                        .addComponent(label2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(193, 193, 193)
                        .addComponent(jLabel1)))
                .addContainerGap(124, Short.MAX_VALUE))
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
                        .addGap(89, 89, 89)
                        .addComponent(jlblInformacion, javax.swing.GroupLayout.DEFAULT_SIZE, 274, Short.MAX_VALUE)
                        .addGap(62, 62, 62)
                        .addComponent(jbtnParteDiferencia))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(108, 108, 108)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jlblDoc)
                            .addComponent(jLabel7)
                            .addComponent(jLabel8)
                            .addComponent(jlblDescuadre))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 50, Short.MAX_VALUE)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addComponent(jtxtDocumentacion, javax.swing.GroupLayout.PREFERRED_SIZE, 298, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addGroup(layout.createSequentialGroup()
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                                    .addComponent(jtxtDescuadre, javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(jSeparator1, javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(jtxtRecuento, javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(jtxtImpFinal, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 69, Short.MAX_VALUE))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(jButton1, javax.swing.GroupLayout.Alignment.TRAILING)
                                    .addGroup(layout.createSequentialGroup()
                                        .addGap(29, 29, 29)
                                        .addComponent(jLabel9)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                        .addComponent(jtxtImpCajaCentral)))))))
                .addGap(152, 152, 152))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(21, 21, 21)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(label2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(39, 39, 39)
                        .addComponent(jLabel1))
                    .addComponent(jLabel6))
                .addGap(31, 31, 31)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jlblDoc)
                    .addComponent(jtxtDocumentacion, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(jLabel7)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(jLabel8))
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(jtxtImpFinal, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(jtxtRecuento, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jSeparator1, javax.swing.GroupLayout.PREFERRED_SIZE, 12, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(jtxtImpCajaCentral, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(jLabel9)))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jtxtDescuadre, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jlblDescuadre)
                    .addComponent(jButton1))
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 27, Short.MAX_VALUE)
                        .addComponent(jlblInformacion, javax.swing.GroupLayout.PREFERRED_SIZE, 18, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addContainerGap())
                    .addGroup(layout.createSequentialGroup()
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(jbtnParteDiferencia)
                        .addContainerGap())))
        );

        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 jtxtDescuadreActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jtxtDescuadreActionPerformed
        // TODO add your handling code here:
}//GEN-LAST:event_jtxtDescuadreActionPerformed

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

        if((jtxtDocumentacion.getText().equals("")) || (jtxtRecuento.getText().equals("")) || (jtxtImpFinal.getText().equals("")) || (jtxtImpCajaCentral.getText().equals("")))
            {
                jlblInformacion.setText("Debe rellenar todos los campos");
            }

        else
        {

            DecimalFormat df = new DecimalFormat("#######,##");
            Number n = null;

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

            jtxtDescuadre.setText(String.valueOf(n.doubleValue() - sucAux.saldoCaja(jtxtDocumentacion.getText())));

            //double cantidad = Double.valueOf(jtxtImporteInicial.getText()).doubleValue();

            double dDescuadre = Double.valueOf(jtxtDescuadre.getText()).doubleValue();
            if(dDescuadre != 0)
            {
                jlblInformacion.setText("Descuadre de "+((sucAux.saldoCaja(jtxtDocumentacion.getText())-n.doubleValue()))*(-1)+" €");
                //sucAux.CerrarCajaOcupada(jtxtDocumentacion.getText());
                jbtnParteDiferencia.setVisible(true);
            }
            else
            {
             sucAux.CerrarCajaOcupada(jtxtDocumentacion.getText());

             jlblInformacion.setText("Arqueo realizado correctamente");
            }
        }
        
    }//GEN-LAST:event_jButton1ActionPerformed

    private void formWindowClosing(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_formWindowClosing
        auxJf.setEnabled(true);
    }//GEN-LAST:event_formWindowClosing

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

    private void jbtnParteDiferenciaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbtnParteDiferenciaActionPerformed
        sucAux.RegistraParteDiferencia(Double.valueOf(jtxtDescuadre.getText()).doubleValue());
        jlblInformacion.setText("Parte realizado correctamente");
        sucAux.CerrarCajaOcupada(jtxtDocumentacion.getText());
}//GEN-LAST:event_jbtnParteDiferenciaActionPerformed

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

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jButton1;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JSeparator jSeparator1;
    private javax.swing.JButton jbtnParteDiferencia;
    private javax.swing.JLabel jlblDescuadre;
    private javax.swing.JLabel jlblDoc;
    private javax.swing.JLabel jlblInformacion;
    private javax.swing.JTextField jtxtDescuadre;
    private javax.swing.JTextField jtxtDocumentacion;
    private javax.swing.JTextField jtxtImpCajaCentral;
    private javax.swing.JTextField jtxtImpFinal;
    private javax.swing.JTextField jtxtRecuento;
    private java.awt.Label label2;
    // End of variables declaration//GEN-END:variables

}
