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

/*
 * jfrmIngresoCentral.java
 *
 * Created on 10-ene-2010, 1:30:49
 */

package Vistas;

import Hito4.*;
import java.util.Observable;
import java.util.Observer;
import javax.swing.JFrame;

/**
 *
 * @author Ro
 */
public class jfrmIngresoCentral extends javax.swing.JFrame  implements Observer {
    Sucursal auxsuc;
    JFrame auxjf;
    Caja auxca;
    /** Creates new form jfrmIngresoCentral */
    public jfrmIngresoCentral(Sucursal suc, Caja ca, JFrame ppal) {
        auxsuc=suc;
        auxjf=ppal;
        auxca=ca;
        initComponents();
        jlblSaldoCaja.setText(String.valueOf(auxca.getSaldoFinal()));
    }

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

        buttonGroup2 = new javax.swing.ButtonGroup();
        jLabel3 = new javax.swing.JLabel();
        jLabel1 = new javax.swing.JLabel();
        jtxtImporte = new javax.swing.JTextField();
        jbtnValida = new javax.swing.JButton();
        jbtnSalir = new javax.swing.JButton();
        jlblError = new javax.swing.JLabel();
        jLabel7 = new javax.swing.JLabel();
        jlblSaldoCaja = new javax.swing.JLabel();
        jrbIngreso = new javax.swing.JRadioButton();
        jrbReintegro = new javax.swing.JRadioButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.DO_NOTHING_ON_CLOSE);

        jLabel3.setFont(new java.awt.Font("Papyrus", 1, 24)); // NOI18N
        jLabel3.setForeground(new java.awt.Color(0, 0, 102));
        jLabel3.setText("Banco ALROMA");

        jLabel1.setText("Importe");

        jbtnValida.setText("Valida");
        jbtnValida.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jbtnValidaActionPerformed(evt);
            }
        });

        jbtnSalir.setText("Salir");
        jbtnSalir.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jbtnSalirActionPerformed(evt);
            }
        });

        jLabel7.setFont(new java.awt.Font("Papyrus", 0, 14));
        jLabel7.setText("Saldo en Caja");

        jlblSaldoCaja.setFont(new java.awt.Font("Papyrus", 1, 18));
        jlblSaldoCaja.setForeground(new java.awt.Color(0, 153, 51));

        buttonGroup2.add(jrbIngreso);
        jrbIngreso.setText("Ingreso");

        buttonGroup2.add(jrbReintegro);
        jrbReintegro.setText("Reintegro");

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(jLabel7)
                        .addGap(114, 114, 114))
                    .addGroup(layout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(jlblSaldoCaja, javax.swing.GroupLayout.PREFERRED_SIZE, 80, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)))
                .addGap(304, 304, 304))
            .addGroup(layout.createSequentialGroup()
                .addGap(148, 148, 148)
                .addComponent(jLabel3)
                .addContainerGap(57, Short.MAX_VALUE))
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jlblError, javax.swing.GroupLayout.PREFERRED_SIZE, 253, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jLabel1)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(jtxtImporte, javax.swing.GroupLayout.DEFAULT_SIZE, 205, Short.MAX_VALUE))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                        .addGap(68, 68, 68)
                        .addComponent(jbtnValida)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 38, Short.MAX_VALUE)
                        .addComponent(jbtnSalir)
                        .addGap(33, 33, 33)))
                .addGap(64, 64, 64)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jrbIngreso)
                    .addComponent(jrbReintegro))
                .addGap(121, 121, 121))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel1)
                    .addComponent(jtxtImporte, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jrbIngreso))
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(18, 18, 18)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jbtnSalir)
                            .addComponent(jbtnValida))
                        .addGap(17, 17, 17)
                        .addComponent(jlblError, javax.swing.GroupLayout.PREFERRED_SIZE, 31, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(5, 5, 5)
                        .addComponent(jrbReintegro)))
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(layout.createSequentialGroup()
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jLabel7)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jlblSaldoCaja, javax.swing.GroupLayout.PREFERRED_SIZE, 23, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addContainerGap(22, Short.MAX_VALUE))
                    .addGroup(layout.createSequentialGroup()
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jLabel3, javax.swing.GroupLayout.PREFERRED_SIZE, 56, javax.swing.GroupLayout.PREFERRED_SIZE))))
        );

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

    private void jbtnValidaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbtnValidaActionPerformed
        Arqueo a=new Arqueo();
        Double importe = null;
        if(jrbIngreso.isSelected()){
            importe=Double.parseDouble(jtxtImporte.getText());
        }else if(jrbReintegro.isSelected()){
                importe=Double.parseDouble(jtxtImporte.getText())-Double.parseDouble(jtxtImporte.getText())*2;}

        if(a.IngresoCentral(auxsuc,auxca,importe)){
            if(jrbIngreso.isSelected()){
                jlblError.setText("Ingreso Realizado con Éxito.");}
            else if(jrbReintegro.isSelected()){
                jlblError.setText("Reintegro Realizado con Éxito.");}
        }
        else{jlblError.setText("ERROR. Ingreso No Realizado.");}
    }//GEN-LAST:event_jbtnValidaActionPerformed

    private void jbtnSalirActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbtnSalirActionPerformed
        auxjf.setEnabled(true);
        this.dispose();
    }//GEN-LAST:event_jbtnSalirActionPerformed

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

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.ButtonGroup buttonGroup2;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JButton jbtnSalir;
    private javax.swing.JButton jbtnValida;
    private javax.swing.JLabel jlblError;
    private javax.swing.JLabel jlblSaldoCaja;
    private javax.swing.JRadioButton jrbIngreso;
    private javax.swing.JRadioButton jrbReintegro;
    private javax.swing.JTextField jtxtImporte;
    // End of variables declaration//GEN-END:variables

    public void update(Observable o, Object arg) {
        jlblSaldoCaja.setText(String.valueOf(auxca.getSaldoFinal()));}
}
