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

/*
 * JFVerPartes.java
 *
 * Created on 28-oct-2010, 12:43:17
 */

package vistas;

import java.util.ArrayList;
import java.util.ArrayList;
import java.util.List;
import javabbuva.*;

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

    Sucursal su;
    JFPrincipal p;
    boolean cerrar;

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

        jLabel1 = new javax.swing.JLabel();
        jBterminar = new javax.swing.JButton();
        jScrollPane1 = new javax.swing.JScrollPane();
        jTpartes = new javax.swing.JTextArea();
        jLSaldo1 = new javax.swing.JLabel();
        jLabel5 = new javax.swing.JLabel();

        setDefaultCloseOperation(javax.swing.WindowConstants.DO_NOTHING_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);
            }
            public void windowOpened(java.awt.event.WindowEvent evt) {
                formWindowOpened(evt);
            }
        });
        addPropertyChangeListener(new java.beans.PropertyChangeListener() {
            public void propertyChange(java.beans.PropertyChangeEvent evt) {
                formPropertyChange(evt);
            }
        });

        jLabel1.setFont(new java.awt.Font("Tahoma", 1, 12));
        jLabel1.setText("Visualizando partes de diferencia.");

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

        jTpartes.setColumns(20);
        jTpartes.setFont(new java.awt.Font("Monospaced", 3, 12));
        jTpartes.setForeground(new java.awt.Color(0, 0, 102));
        jTpartes.setRows(5);
        jTpartes.setEnabled(false);
        jScrollPane1.setViewportView(jTpartes);

        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()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jLabel1)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 273, 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(28, Short.MAX_VALUE))
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jBterminar)
                        .addContainerGap(530, Short.MAX_VALUE))
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 577, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addContainerGap(28, Short.MAX_VALUE))))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel1)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jLabel5)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(jLSaldo1)))
                .addGap(18, 18, 18)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 143, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 32, Short.MAX_VALUE)
                .addComponent(jBterminar)
                .addContainerGap())
        );

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

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

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

    private void formWindowOpened(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_formWindowOpened
        // TODO add your handling code here:
        List<PardeDiferencia> parte = new ArrayList();
        int i = 0;
        String mostrar="";
        parte = su.getMPartes();
        if(parte.size()==0){
            jTpartes.setText("NO EXISTEN PARTES DE DIFERENCIA");
        }
        else{
            while(i<parte.size()){
                mostrar += "En fecha " + String.valueOf(parte.get(i).getFecha()) + " " + parte.get(i).getConcepto() + " " + String.valueOf(parte.get(i).getDiferencia()) + " € en la " + parte.get(i).getCaja().getIdentificador() + ", creado por el empleado " + parte.get(i).getEmpleado().getNombre() + '\n';
                i++;
            }
            jTpartes.setText(mostrar);
        }
    }//GEN-LAST:event_formWindowOpened

    private void formPropertyChange(java.beans.PropertyChangeEvent evt) {//GEN-FIRST:event_formPropertyChange
        // TODO add your handling code here:
    }//GEN-LAST:event_formPropertyChange

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

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jBterminar;
    private javax.swing.JLabel jLSaldo1;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JTextArea jTpartes;
    // End of variables declaration//GEN-END:variables

}
