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

/*
 * jfrmReintegroCajaCentral.java
 *
 * Created on 14-ene-2010, 10:24:33
 */

package Vistas;

import Modelo.Caja;
import Modelo.Op_Basica;
import Modelo.Sucursal;
import java.text.DecimalFormat;
import java.text.ParseException;
import java.util.Date;
import java.util.Observable;
import java.util.Observer;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JFrame;

/**
 *
 * @author Administrador
 */
public class jfrmReintegroCajaCentral extends javax.swing.JFrame implements Observer{
    JFrame auxJf;
    Sucursal sucAux = new Sucursal();
    /** Creates new form jfrmReintegroCajaCentral */
    public jfrmReintegroCajaCentral(Sucursal suc,JFrame jf) {
        auxJf=jf;
        initComponents();
        sucAux = suc;
        
        jtxtSaldoActualCaja.setText(String.valueOf(sucAux.saldoCaja(sucAux.dameDNIEmpleado())));
        Caja c = sucAux.busquedaCajaSucursal(sucAux.dameIdCaja());
        c.addObserver(this);
    }

    /** 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();
        jLabel1 = new javax.swing.JLabel();
        label2 = new java.awt.Label();
        jLabel3 = new javax.swing.JLabel();
        jbtAceptarReintegroCajaCentral = new javax.swing.JButton();
        jtxtImporteIngreso = new javax.swing.JTextField();
        jlblInformacion = new javax.swing.JLabel();
        jtxtSaldoActualCaja = new javax.swing.JTextField();
        jlblDoc1 = new javax.swing.JLabel();

        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

        jLabel1.setFont(new java.awt.Font("Comic Sans MS", 1, 18));
        jLabel1.setText("Reintegro de Caja Central");

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

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

        jbtAceptarReintegroCajaCentral.setFont(new java.awt.Font("Comic Sans MS", 0, 12));
        jbtAceptarReintegroCajaCentral.setText("Aceptar");
        jbtAceptarReintegroCajaCentral.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jbtAceptarReintegroCajaCentralActionPerformed(evt);
            }
        });

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

        jlblDoc1.setFont(new java.awt.Font("Comic Sans MS", 0, 10)); // NOI18N
        jlblDoc1.setText("Saldo 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()
                .addContainerGap()
                .addComponent(jLabel6)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                        .addComponent(jLabel1)
                        .addGap(69, 69, 69))
                    .addComponent(label2, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap())
            .addGroup(layout.createSequentialGroup()
                .addGap(21, 21, 21)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jLabel3)
                        .addGap(53, 53, 53))
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jlblInformacion, javax.swing.GroupLayout.PREFERRED_SIZE, 233, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)))
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jbtAceptarReintegroCajaCentral)
                    .addComponent(jtxtImporteIngreso, javax.swing.GroupLayout.PREFERRED_SIZE, 63, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 48, Short.MAX_VALUE)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jtxtSaldoActualCaja, javax.swing.GroupLayout.PREFERRED_SIZE, 64, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jlblDoc1))
                .addGap(33, 33, 33))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(18, 18, 18)
                        .addComponent(label2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jLabel1))
                    .addComponent(jLabel6))
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(18, 18, 18)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel3)
                            .addComponent(jtxtImporteIngreso, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 41, Short.MAX_VALUE)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(jbtAceptarReintegroCajaCentral)
                                .addGap(24, 24, 24))
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(jlblInformacion, javax.swing.GroupLayout.PREFERRED_SIZE, 18, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addContainerGap())))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(1, 1, 1)
                        .addComponent(jlblDoc1)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(jtxtSaldoActualCaja, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addContainerGap())))
        );

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

    private void jbtAceptarReintegroCajaCentralActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbtAceptarReintegroCajaCentralActionPerformed
        // TODO add your handling code here:
        if (jtxtImporteIngreso.getText().equals(""))
        { jlblInformacion.setText("Debe introducir el importe");}
        else
        {
            Op_Basica op = new Op_Basica();
            String stImporte = jtxtImporteIngreso.getText();
            DecimalFormat df = new DecimalFormat("#######,##");
            Number n = null;

            try {
                n = df.parse(stImporte);
            } catch (ParseException ex) {
                Logger.getLogger(jfrmIngreso.class.getName()).log(Level.SEVERE, null, ex);
            }
            op.setDImporte(n.doubleValue());
            Date d = new Date();
            op.setDatOpe(d);

            if(sucAux.saldoCajaCentral()<n.doubleValue())
                {jlblInformacion.setText("ERROR. Importe mayor que Caja Central");}
                else
                {
                    sucAux.decrementoCaja(n.doubleValue(),0);
                    sucAux.incrementoCaja(n.doubleValue(),sucAux.dameIdCaja());
                    jlblInformacion.setText("Reintegro realizado");
                }
        }
}//GEN-LAST:event_jbtAceptarReintegroCajaCentralActionPerformed

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

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

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

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JButton jbtAceptarReintegroCajaCentral;
    private javax.swing.JLabel jlblDoc1;
    private javax.swing.JLabel jlblInformacion;
    private javax.swing.JTextField jtxtImporteIngreso;
    private javax.swing.JTextField jtxtSaldoActualCaja;
    private java.awt.Label label2;
    // End of variables declaration//GEN-END:variables

    public void update(Observable o, Object arg) {
        jtxtSaldoActualCaja.setText(String.valueOf(sucAux.saldoCaja(sucAux.dameDNIEmpleado())));
    }

}
