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

/*
 * JFTransferenciaI.java
 *
 * Created on 13-oct-2010, 19:44:58
 */

package vistas;

import javabbuva.Producto;
import javabbuva.*;

/**
 *
 * @author Adrian
 */
public class JFTransferenciaI extends javax.swing.JFrame {

    Sucursal su;
    JFPrincipal p;

    /** Creates new form JFTransferenciaI */
    public JFTransferenciaI(Sucursal su, JFPrincipal p) {
        this.su = su;
        this.p = p;
        p.setEnabled(false);
        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() {

        jLTitulo = new javax.swing.JLabel();
        jBSeleccionar = new javax.swing.JButton();
        jLabel1 = new javax.swing.JLabel();
        jLSaldo = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        jTcantidad = new javax.swing.JTextField();
        jBAceptar = new javax.swing.JButton();
        jBCancelar = new javax.swing.JButton();
        jBdestino = new javax.swing.JButton();
        jLerror = new javax.swing.JLabel();
        jLSaldo1 = new javax.swing.JLabel();
        jLabel5 = new javax.swing.JLabel();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setResizable(false);
        addWindowListener(new java.awt.event.WindowAdapter() {
            public void windowActivated(java.awt.event.WindowEvent evt) {
                formWindowActivated(evt);
            }
            public void windowClosed(java.awt.event.WindowEvent evt) {
                formWindowClosed(evt);
            }
        });

        jLTitulo.setFont(new java.awt.Font("Tahoma", 1, 12));
        jLTitulo.setText("Realizando transferencia interna.");

        jBSeleccionar.setText("Seleccionar cuenta origen");
        jBSeleccionar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jBSeleccionarActionPerformed(evt);
            }
        });

        jLabel1.setText("Saldo cuenta origen:");

        jLabel3.setText("Cantidad a transferir:");

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

        jBCancelar.setText("Cancelar");
        jBCancelar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jBCancelarActionPerformed(evt);
            }
        });

        jBdestino.setText("Seleccionar cuenta destino");
        jBdestino.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jBdestinoActionPerformed(evt);
            }
        });

        jLerror.setFont(new java.awt.Font("Tahoma", 1, 12));
        jLerror.setForeground(new java.awt.Color(204, 0, 0));

        jLSaldo1.setFont(new java.awt.Font("Tahoma", 1, 14));
        jLSaldo1.setForeground(new java.awt.Color(51, 51, 51));
        jLSaldo1.setText("0");
        jLSaldo1.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED));

        jLabel5.setForeground(new java.awt.Color(51, 51, 51));
        jLabel5.setText("Saldo actual en 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()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(21, 21, 21)
                        .addComponent(jBAceptar)
                        .addGap(104, 104, 104)
                        .addComponent(jBCancelar))
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(layout.createSequentialGroup()
                                .addGap(30, 30, 30)
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addGroup(layout.createSequentialGroup()
                                        .addComponent(jLabel1)
                                        .addGap(67, 67, 67)
                                        .addComponent(jLSaldo, javax.swing.GroupLayout.PREFERRED_SIZE, 118, javax.swing.GroupLayout.PREFERRED_SIZE))
                                    .addGroup(layout.createSequentialGroup()
                                        .addGap(166, 166, 166)
                                        .addComponent(jTcantidad, javax.swing.GroupLayout.PREFERRED_SIZE, 83, javax.swing.GroupLayout.PREFERRED_SIZE))
                                    .addComponent(jLabel3)))
                            .addGroup(layout.createSequentialGroup()
                                .addContainerGap()
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                        .addComponent(jBSeleccionar)
                                        .addComponent(jBdestino))
                                    .addComponent(jLTitulo))
                                .addGap(50, 50, 50)
                                .addComponent(jLerror, javax.swing.GroupLayout.PREFERRED_SIZE, 171, javax.swing.GroupLayout.PREFERRED_SIZE)))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLSaldo1, javax.swing.GroupLayout.PREFERRED_SIZE, 89, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel5))))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jLabel5)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(jLSaldo1)
                        .addContainerGap())
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jLTitulo)
                        .addGap(29, 29, 29)
                        .addComponent(jBSeleccionar)
                        .addGap(18, 18, 18)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jBdestino)
                            .addComponent(jLerror, javax.swing.GroupLayout.PREFERRED_SIZE, 15, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(31, 31, 31)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel1)
                            .addComponent(jLSaldo, javax.swing.GroupLayout.PREFERRED_SIZE, 14, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(18, 18, 18)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel3)
                            .addComponent(jTcantidad, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 31, Short.MAX_VALUE)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jBAceptar)
                            .addComponent(jBCancelar))
                        .addGap(21, 21, 21))))
        );

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

    private void jBCancelarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jBCancelarActionPerformed
        // TODO add your handling code here:
        this.dispose();
        p.setEnabled(true);
        jLerror.setText("");
}//GEN-LAST:event_jBCancelarActionPerformed

    private void jBdestinoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jBdestinoActionPerformed
        // TODO add your handling code here:
        jLerror.setText("");
        if(p.escogida == false){
            jLerror.setText("Escoja primero el origen");
        }
        else{
        JFVerCuentas vc = new JFVerCuentas(su,p);
        vc.transferencia2 = true;
        vc.show();
        Producto pr = su.dameCuenta(p.auxiliar);
        jLSaldo.setText(String.valueOf(pr.getDinero()));
        }
    }//GEN-LAST:event_jBdestinoActionPerformed

    private void jBSeleccionarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jBSeleccionarActionPerformed
        // TODO add your handling code here:
        JFVerCuentas vc = new JFVerCuentas(su,p);
        vc.show();
        vc.transferencia = true;
    }//GEN-LAST:event_jBSeleccionarActionPerformed

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

    private void jBAceptarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jBAceptarActionPerformed
        // TODO add your handling code here:
        if(p.escogida == false || p.escogidades == false){
        jLerror.setText("Escoja las cuentas");
        }
        else{
            float cantidad = Float.parseFloat(jTcantidad.getText());
            float saldo = Float.parseFloat(jLSaldo.getText());
            if(saldo<cantidad || 0>=cantidad){
                jLerror.setText("Error en cantidades");
            }
            else{
                su.realizarTranferenciaI(cantidad, p.auxiliar, p.auxiliardes);
                this.dispose();
            }
        }
    }//GEN-LAST:event_jBAceptarActionPerformed

    private void formWindowActivated(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_formWindowActivated
        // TODO add your handling code here:
        jLSaldo1.setText(String.valueOf(su.getCajaActual().getSaldo()));
    }//GEN-LAST:event_formWindowActivated

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

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jBAceptar;
    private javax.swing.JButton jBCancelar;
    private javax.swing.JButton jBSeleccionar;
    private javax.swing.JButton jBdestino;
    private javax.swing.JLabel jLSaldo;
    private javax.swing.JLabel jLSaldo1;
    private javax.swing.JLabel jLTitulo;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLerror;
    private javax.swing.JTextField jTcantidad;
    // End of variables declaration//GEN-END:variables

}
