package Vistas;


import Modelo.Caja;
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;

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

/*
 * jfrmPrestamoHipotecario.java
 *
 * Created on 09-dic-2009, 18:16:28
 */

/**
 *
 * @author acc_local
 */
public class jfrmPrestamoHipotecario extends javax.swing.JFrame implements Observer{
    Sucursal sucAux = new Sucursal();
    JFrame auxJf;
    /** Creates new form jfrmPrestamoHipotecario */
    public jfrmPrestamoHipotecario(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();
        label2 = new java.awt.Label();
        jLabel1 = new javax.swing.JLabel();
        jLabel7 = new javax.swing.JLabel();
        jtxtCCOrigen = new javax.swing.JTextField();
        jbtnSOrigen = new javax.swing.JButton();
        jLabel3 = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        jtxtImporte = new javax.swing.JTextField();
        jtxtConcepto = new javax.swing.JTextField();
        jLabel5 = new javax.swing.JLabel();
        jtxtAnos = new javax.swing.JTextField();
        jbtCrearCC = new javax.swing.JButton();
        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

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

        jLabel1.setFont(new java.awt.Font("Comic Sans MS", 1, 18)); // NOI18N
        jLabel1.setText("Prestamo Hipotecario");

        jLabel7.setFont(new java.awt.Font("Comic Sans MS", 0, 14));
        jLabel7.setText("Nº Cuenta:");

        jbtnSOrigen.setText("...");
        jbtnSOrigen.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jbtnSOrigenActionPerformed(evt);
            }
        });

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

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

        jtxtConcepto.setText("Prestamo Hipotecario");

        jLabel5.setFont(new java.awt.Font("Comic Sans MS", 0, 14));
        jLabel5.setText("NºAños:");

        jbtCrearCC.setText("Crear");
        jbtCrearCC.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jbtCrearCCActionPerformed(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()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel3, javax.swing.GroupLayout.Alignment.TRAILING)
                            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                .addComponent(jLabel5)
                                .addComponent(jLabel4)))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED))
                    .addComponent(jLabel7, javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jLabel6, javax.swing.GroupLayout.Alignment.TRAILING))
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addGroup(layout.createSequentialGroup()
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 20, Short.MAX_VALUE)
                            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                .addGroup(layout.createSequentialGroup()
                                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                                        .addComponent(jtxtConcepto, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.PREFERRED_SIZE, 298, javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addComponent(jtxtImporte, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.PREFERRED_SIZE, 63, javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addComponent(jtxtCCOrigen, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.PREFERRED_SIZE, 298, javax.swing.GroupLayout.PREFERRED_SIZE))
                                    .addGap(18, 18, 18)
                                    .addComponent(jbtnSOrigen))
                                .addComponent(jtxtAnos, javax.swing.GroupLayout.PREFERRED_SIZE, 49, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addContainerGap())
                        .addGroup(layout.createSequentialGroup()
                            .addGap(84, 84, 84)
                            .addComponent(jLabel1)
                            .addGap(31, 31, 31)
                            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                .addComponent(jtxtSaldoActualCaja, javax.swing.GroupLayout.PREFERRED_SIZE, 64, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addComponent(jlblDoc1))
                            .addGap(27, 27, 27)))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(40, 40, 40)
                        .addComponent(label2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addContainerGap())))
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addGap(25, 25, 25)
                .addComponent(jlblInformacion, javax.swing.GroupLayout.PREFERRED_SIZE, 233, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 31, Short.MAX_VALUE)
                .addComponent(jbtCrearCC)
                .addGap(202, 202, 202))
        );
        layout.setVerticalGroup(
            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(label2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(layout.createSequentialGroup()
                                .addGap(28, 28, 28)
                                .addComponent(jLabel1))
                            .addGroup(layout.createSequentialGroup()
                                .addGap(20, 20, 20)
                                .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))))
                    .addComponent(jLabel6))
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(jtxtCCOrigen, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(jLabel7))
                    .addComponent(jbtnSOrigen))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jtxtImporte, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel3))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel4)
                    .addComponent(jtxtConcepto, 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.BASELINE)
                    .addComponent(jtxtAnos, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel5))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 19, Short.MAX_VALUE)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jbtCrearCC)
                    .addComponent(jlblInformacion, javax.swing.GroupLayout.PREFERRED_SIZE, 18, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap())
        );

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

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

    private void jbtnSOrigenActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbtnSOrigenActionPerformed
        new jfrmSeleccionarCuentaCliente(sucAux,this,jtxtCCOrigen,true).setVisible(true);
        this.setEnabled(false);
}//GEN-LAST:event_jbtnSOrigenActionPerformed

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


        if((jtxtCCOrigen.getText().equals("")) || (jtxtImporte.getText().equals("")) || (jtxtConcepto.getText().equals("")) || (jtxtAnos.getText().equals("")))
        {
            jlblInformacion.setText("Debe rellenar todos los campos");
        }
        else
        {
            DecimalFormat df = new DecimalFormat("#######,##");
            Number n = null;

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

            DecimalFormat df2 = new DecimalFormat("#####");
            Number n2 = null;

            try {
                n2 = df2.parse(jtxtAnos.getText());
            } catch (ParseException ex) {
                Logger.getLogger(jfrmIngreso.class.getName()).log(Level.SEVERE, null, ex);
            }



            sucAux.crearPH(jtxtCCOrigen.getText(),n.doubleValue(),jtxtConcepto.getText(),n2.intValue());
            jlblInformacion.setText("Prestamo Hipotecario creado");
        }
        
        
}//GEN-LAST:event_jbtCrearCCActionPerformed

    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 jfrmPrestamoHipotecario().setVisible(true);
            }
        });
    }*/

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JButton jbtCrearCC;
    private javax.swing.JButton jbtnSOrigen;
    private javax.swing.JLabel jlblDoc1;
    private javax.swing.JLabel jlblInformacion;
    private javax.swing.JTextField jtxtAnos;
    private javax.swing.JTextField jtxtCCOrigen;
    private javax.swing.JTextField jtxtConcepto;
    private javax.swing.JTextField jtxtImporte;
    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())));
    }

}
