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

/*
 * JFVerArqueos.java
 *
 * Created on 04-nov-2010, 12:02:52
 */

package vistas;

import java.util.List;
import javabbuva.*;
import javax.swing.DefaultListModel;

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

    Sucursal su;
    JFPrincipal p;

    /** Creates new form JFVerArqueos */
    public JFVerArqueos(Sucursal su, JFPrincipal p) {
        initComponents();
        this.su = su;
        this.p = p;
        this.p.setEnabled(false);
        jLSaldo1.setText(String.valueOf(su.getCajaActual().getSaldo()));
    }

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

        jLSaldo1 = new javax.swing.JLabel();
        jLabel7 = new javax.swing.JLabel();
        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        jScrollPane1 = new javax.swing.JScrollPane();
        jLempleados = new javax.swing.JList();
        jBseleccionar = new javax.swing.JButton();
        jBterminar = new javax.swing.JButton();
        jScrollPane2 = new javax.swing.JScrollPane();
        jTrealizados = new javax.swing.JTextArea();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        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);
            }
            public void windowOpened(java.awt.event.WindowEvent evt) {
                formWindowOpened(evt);
            }
        });

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

        jLabel7.setForeground(new java.awt.Color(102, 102, 102));
        jLabel7.setText("Saldo actual en caja:");

        jLabel1.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N
        jLabel1.setText("Visualizando arqueos realizados por ...");

        jLabel2.setText("Seleccione al empleado:");

        jScrollPane1.setViewportView(jLempleados);

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

        jBterminar.setText("Terminar");
        jBterminar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jBterminarActionPerformed(evt);
            }
        });

        jTrealizados.setColumns(20);
        jTrealizados.setEditable(false);
        jTrealizados.setFont(new java.awt.Font("Monospaced", 1, 13)); // NOI18N
        jTrealizados.setRows(5);
        jScrollPane2.setViewportView(jTrealizados);

        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()
                        .addComponent(jLabel1)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 241, Short.MAX_VALUE)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel7)
                            .addComponent(jLSaldo1, javax.swing.GroupLayout.PREFERRED_SIZE, 89, javax.swing.GroupLayout.PREFERRED_SIZE)))
                    .addComponent(jLabel2)
                    .addComponent(jBterminar)
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 157, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addGroup(layout.createSequentialGroup()
                                .addGap(26, 26, 26)
                                .addComponent(jBseleccionar)))
                        .addGap(38, 38, 38)
                        .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 359, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel7)
                    .addComponent(jLabel1))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jLSaldo1)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jLabel2)
                .addGap(28, 28, 28)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 111, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(jBseleccionar)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 27, Short.MAX_VALUE)
                        .addComponent(jBterminar))
                    .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 153, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap())
        );

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

    private void formWindowActivated(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_formWindowActivated
        // TODO add your handling code here:
    }//GEN-LAST:event_formWindowActivated

    private void formWindowOpened(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_formWindowOpened
        // TODO add your handling code here:
        DefaultListModel mod = new DefaultListModel();
        List<Empleado>empleados = su.getEmpleado();
        int i = 0;
        while(i<empleados.size()){
            mod.addElement(empleados.get(i).getApellidos()+" "+empleados.get(i).getNombre());
            i++;
        }
        jLempleados.setModel(mod);
    }//GEN-LAST:event_formWindowOpened

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

    private void jBterminarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jBterminarActionPerformed
        // TODO add your handling code here:
        this.dispose();
    }//GEN-LAST:event_jBterminarActionPerformed

    private void jBseleccionarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jBseleccionarActionPerformed
        // TODO add your handling code here:
        if(jLempleados.getSelectedIndex()==-1){

        }
        else{
            Empleado seleccionado = su.dameEmpleado(String.valueOf(jLempleados.getSelectedValue()));
            List<Arqueo>arqueos = seleccionado.getArqueos();
            int i = 0;
            String mostrar="";
            if(arqueos.size()==0){
                mostrar+="No ha realizado ningun arqueo";
            }
            while(i<arqueos.size()){
                mostrar+="Arqueo "+arqueos.get(i).getTipo()+" realizado en "+arqueos.get(i).getFecha()+"\nen la "+arqueos.get(i).getRealizado().getIdentificador()+" con saldo "+arqueos.get(i).getTipo()+" "+String.valueOf(arqueos.get(i).getSaldo())+" €\n\n";
                i++;
            }
            jTrealizados.setText(mostrar);
        }
    }//GEN-LAST:event_jBseleccionarActionPerformed

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

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jBseleccionar;
    private javax.swing.JButton jBterminar;
    private javax.swing.JLabel jLSaldo1;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JList jLempleados;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JTextArea jTrealizados;
    // End of variables declaration//GEN-END:variables

}
