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

/*
 * jfrmIngresos.java
 *
 * Created on 19-nov-2009, 21:52:10
 */

package dia4g3java;

import java.text.SimpleDateFormat;
import java.util.Date;

/**
 *
 * @author pelujl
 */
public class jfrmIngresos extends javax.swing.JFrame {

    Sucursal auxsuc = new Sucursal();
    Producto auxprod = new Producto();
    /** Creates new form jfrmIngresos */
    public jfrmIngresos(Sucursal suc) {
        auxsuc = suc;
        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() {

        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        lbl_concepto = new javax.swing.JLabel();
        txtNumCta = new javax.swing.JTextField();
        txt_titular = new javax.swing.JTextField();
        jSeparator1 = new javax.swing.JSeparator();
        btn_comprobar_cuenta = new javax.swing.JButton();
        lbl_datos_adicionales = new javax.swing.JLabel();
        lbl_nombre = new javax.swing.JLabel();
        lbl_importe = new javax.swing.JLabel();
        lbl_fecha = new javax.swing.JLabel();
        txt_fecha = new javax.swing.JTextField();
        txt_importe = new javax.swing.JTextField();
        jScrollPane1 = new javax.swing.JScrollPane();
        txt_concepto = new javax.swing.JTextArea();
        btn_ingresar = new javax.swing.JButton();
        txt_nota = new javax.swing.JLabel();
        txt_nota2 = new javax.swing.JLabel();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        jLabel1.setText("REALIZAR  INGRESO.");

        jLabel2.setText("Introduzca el número de cuenta:");

        lbl_concepto.setText("Concepto del ingreso:");
        lbl_concepto.setEnabled(false);
        lbl_concepto.setOpaque(true);

        txt_titular.setEnabled(false);

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

        lbl_datos_adicionales.setText("DATOS ADICIONALES:");
        lbl_datos_adicionales.setEnabled(false);
        lbl_datos_adicionales.setOpaque(true);

        lbl_nombre.setText("Nombre del titular:");
        lbl_nombre.setEnabled(false);
        lbl_nombre.setOpaque(true);

        lbl_importe.setText("Importe del ingreso:");
        lbl_importe.setEnabled(false);
        lbl_importe.setOpaque(true);

        lbl_fecha.setText("Fecha del ingreso:");
        lbl_fecha.setEnabled(false);
        lbl_fecha.setOpaque(true);

        txt_fecha.setEnabled(false);

        txt_importe.setEnabled(false);

        jScrollPane1.setEnabled(false);

        txt_concepto.setColumns(20);
        txt_concepto.setRows(5);
        txt_concepto.setEnabled(false);
        jScrollPane1.setViewportView(txt_concepto);

        btn_ingresar.setText("Realizar Ingreso");
        btn_ingresar.setEnabled(false);
        btn_ingresar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btn_ingresarActionPerformed(evt);
            }
        });

        txt_nota.setForeground(new java.awt.Color(255, 51, 51));

        txt_nota2.setForeground(new java.awt.Color(255, 51, 51));

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jSeparator1, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 978, Short.MAX_VALUE)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel1)
                .addContainerGap(864, Short.MAX_VALUE))
            .addGroup(layout.createSequentialGroup()
                .addGap(37, 37, 37)
                .addComponent(lbl_datos_adicionales)
                .addContainerGap(832, Short.MAX_VALUE))
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addGap(148, 148, 148)
                .addComponent(jLabel2, javax.swing.GroupLayout.DEFAULT_SIZE, 182, Short.MAX_VALUE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(txtNumCta, javax.swing.GroupLayout.PREFERRED_SIZE, 206, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addComponent(btn_comprobar_cuenta, javax.swing.GroupLayout.PREFERRED_SIZE, 163, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addComponent(txt_nota, javax.swing.GroupLayout.PREFERRED_SIZE, 153, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(86, 86, 86))
            .addGroup(layout.createSequentialGroup()
                .addGap(148, 148, 148)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.CENTER)
                    .addComponent(lbl_nombre, javax.swing.GroupLayout.DEFAULT_SIZE, 105, Short.MAX_VALUE)
                    .addComponent(lbl_fecha, javax.swing.GroupLayout.DEFAULT_SIZE, 105, Short.MAX_VALUE)
                    .addComponent(lbl_importe, javax.swing.GroupLayout.DEFAULT_SIZE, 105, Short.MAX_VALUE)
                    .addComponent(lbl_concepto, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(8, 8, 8)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(txt_titular, javax.swing.GroupLayout.PREFERRED_SIZE, 383, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                                .addComponent(txt_importe)
                                .addComponent(txt_fecha, javax.swing.GroupLayout.PREFERRED_SIZE, 194, javax.swing.GroupLayout.PREFERRED_SIZE))))
                    .addGroup(layout.createSequentialGroup()
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(jScrollPane1)))
                .addGap(334, 334, 334))
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap(250, Short.MAX_VALUE)
                .addComponent(txt_nota2, javax.swing.GroupLayout.PREFERRED_SIZE, 409, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(btn_ingresar)
                .addGap(204, 204, 204))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel1)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jSeparator1, javax.swing.GroupLayout.PREFERRED_SIZE, 10, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE, false)
                    .addComponent(jLabel2)
                    .addComponent(btn_comprobar_cuenta)
                    .addComponent(txtNumCta, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(txt_nota))
                .addGap(32, 32, 32)
                .addComponent(lbl_datos_adicionales)
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.CENTER)
                    .addComponent(lbl_fecha, javax.swing.GroupLayout.DEFAULT_SIZE, 20, Short.MAX_VALUE)
                    .addComponent(txt_fecha, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.CENTER)
                    .addComponent(lbl_importe, javax.swing.GroupLayout.DEFAULT_SIZE, 20, Short.MAX_VALUE)
                    .addComponent(txt_importe, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.CENTER)
                    .addComponent(txt_titular, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(lbl_nombre, javax.swing.GroupLayout.DEFAULT_SIZE, 20, Short.MAX_VALUE))
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18))
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(lbl_concepto, javax.swing.GroupLayout.DEFAULT_SIZE, 16, Short.MAX_VALUE)
                        .addGap(98, 98, 98)))
                .addGap(15, 15, 15)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(txt_nota2, javax.swing.GroupLayout.PREFERRED_SIZE, 21, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(btn_ingresar))
                .addGap(57, 57, 57))
        );

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

    private void btn_comprobar_cuentaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btn_comprobar_cuentaActionPerformed
        // buscamos la cuenta donde hay que realizar el ingreso
        String NumCta = new String();
        Producto prod = new Producto();
        NumCta = this.txtNumCta.getText();//obtenemos el numero de cuenta
        prod=auxsuc.devuelveProducto(NumCta);   //vemos si existe
        auxprod = prod;
        java.util.Date fecha_actual = new java.util.Date();
        // si existe la cuenta activa el resto de componentes del formulario para
        // continuar con el ingreso si no muestra un mensaje diciendo que no
        // existe la empresa.

        if (prod == null){
            txt_nota.setText("no existe la cuenta");
        }else{
            txt_nota.setText("");
            lbl_datos_adicionales.setEnabled(true);
            txt_fecha.setText(fecha_actual.toString());
            lbl_importe.setEnabled(true);
            txt_importe.setEnabled(true);
            lbl_fecha.setEnabled(true);
            lbl_nombre.setEnabled(true);
            lbl_concepto.setEnabled(true);
            txt_concepto.setEnabled(true);
            txt_titular.setText(prod.getNombreCliente());
            btn_ingresar.setEnabled(true);
        }

    }//GEN-LAST:event_btn_comprobar_cuentaActionPerformed

    private void btn_ingresarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btn_ingresarActionPerformed
        // funcion encargada de realizar el ingreso

        txt_nota.setText("");

        String cantidad = new String();
        cantidad = txt_importe.getText();
        Float money = Float.valueOf(cantidad);
        java.util.Date fecha_actual = new java.util.Date();
        Movimiento ingreso = new Movimiento();

        ingreso.setConcepto(txt_concepto.getText());
        ingreso.setFechaOperacion(fecha_actual);
        ingreso.setImporte(money);

        auxprod.insertaMovimientoenCuenta(ingreso);
        
        txt_fecha.setText("");
        txt_importe.setText("");
        txt_concepto.setText("");
        txt_titular.setText("");
        txtNumCta.setText("");
        txt_nota2.setText("Se han ingresado "+cantidad+" Euros en la cuenta "+ auxprod.getNumeroProducto()+".");


    }//GEN-LAST:event_btn_ingresarActionPerformed

    /**
    * @param args the command line arguments
    */
   

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btn_comprobar_cuenta;
    private javax.swing.JButton btn_ingresar;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JSeparator jSeparator1;
    private javax.swing.JLabel lbl_concepto;
    private javax.swing.JLabel lbl_datos_adicionales;
    private javax.swing.JLabel lbl_fecha;
    private javax.swing.JLabel lbl_importe;
    private javax.swing.JLabel lbl_nombre;
    private javax.swing.JTextField txtNumCta;
    private javax.swing.JTextArea txt_concepto;
    private javax.swing.JTextField txt_fecha;
    private javax.swing.JTextField txt_importe;
    private javax.swing.JLabel txt_nota;
    private javax.swing.JLabel txt_nota2;
    private javax.swing.JTextField txt_titular;
    // End of variables declaration//GEN-END:variables

}
