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

/*
 * JFParteDiferencia.java
 *
 * Created on 22-oct-2010, 13:42:09
 */

package vistas;

import javabbuva.*;

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

    Sucursal su;
    boolean inicial;

    /** Creates new form JFParteDiferencia */
    public JFParteDiferencia(Sucursal su, boolean aux) {
        this.su = su;
        initComponents();
        inicial = aux;
    }

    /** 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();
        jTcantidad = new javax.swing.JTextField();
        jBcrear = new javax.swing.JButton();
        jLerror = new javax.swing.JLabel();
        jCfalta = new javax.swing.JCheckBox();
        jLabel3 = new javax.swing.JLabel();
        jCsobra = new javax.swing.JCheckBox();
        jBver = new javax.swing.JButton();
        jLSaldo1 = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();

        setDefaultCloseOperation(javax.swing.WindowConstants.DO_NOTHING_ON_CLOSE);
        addWindowListener(new java.awt.event.WindowAdapter() {
            public void windowActivated(java.awt.event.WindowEvent evt) {
                formWindowActivated(evt);
            }
            public void windowOpened(java.awt.event.WindowEvent evt) {
                formWindowOpened(evt);
            }
        });

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

        jLabel2.setText("Introduzca la cantidad de dinero que sobra o falta en la caja:");

        jBcrear.setText("Crear parte");
        jBcrear.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jBcrearActionPerformed(evt);
            }
        });

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

        jCfalta.setText("FALTA");

        jLabel3.setText("Pinche donde corresponda:");

        jCsobra.setText("SOBRA");

        jBver.setText("Crear y ver");
        jBver.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jBverActionPerformed(evt);
            }
        });

        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));

        jLabel4.setForeground(new java.awt.Color(51, 51, 51));
        jLabel4.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(jBcrear)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 319, Short.MAX_VALUE)
                        .addComponent(jBver))
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jLabel1)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 221, 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(jLabel4))))
                .addContainerGap())
            .addGroup(layout.createSequentialGroup()
                .addGap(31, 31, 31)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jLerror, javax.swing.GroupLayout.PREFERRED_SIZE, 268, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addContainerGap())
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addGroup(layout.createSequentialGroup()
                            .addComponent(jLabel3, javax.swing.GroupLayout.DEFAULT_SIZE, 255, Short.MAX_VALUE)
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                            .addComponent(jCfalta)
                            .addGap(32, 32, 32)
                            .addComponent(jCsobra)
                            .addGap(81, 81, 81))
                        .addGroup(layout.createSequentialGroup()
                            .addComponent(jTcantidad, javax.swing.GroupLayout.PREFERRED_SIZE, 125, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addContainerGap())
                        .addGroup(layout.createSequentialGroup()
                            .addComponent(jLabel2, javax.swing.GroupLayout.DEFAULT_SIZE, 386, Short.MAX_VALUE)
                            .addGap(98, 98, 98)))))
        );
        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(jLabel4)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(jLSaldo1))
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jLabel1)
                        .addGap(25, 25, 25)
                        .addComponent(jLabel2)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(jTcantidad, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel3)
                            .addComponent(jCsobra)
                            .addComponent(jCfalta))
                        .addGap(30, 30, 30)
                        .addComponent(jLerror, javax.swing.GroupLayout.PREFERRED_SIZE, 19, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 27, Short.MAX_VALUE)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jBcrear)
                            .addComponent(jBver))))
                .addContainerGap())
        );

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

    private void jBcrearActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jBcrearActionPerformed
        // TODO add your handling code here:
        if(jTcantidad.getText().compareTo("")==0){
            jLerror.setText("Introduzca la cantidad que corresponda.");
        }
        else{
            if(jCfalta.isSelected() && jCsobra.isSelected())
                jLerror.setText("Seleccione una unica opcion.");
            else if(!jCfalta.isSelected() && !jCsobra.isSelected())
                jLerror.setText("Seleccione alguna opcion.");
            else{
                if(jCfalta.isSelected())
                    su.crearParteDiferencia(Double.parseDouble(jTcantidad.getText()),"faltaron");
                else
                    su.crearParteDiferencia(Double.parseDouble(jTcantidad.getText()),"sobraron");
                if(inicial == true){
                    new JFPrincipal(su).setVisible(true);
                    this.dispose();
                }
                else{
                    su.guardar();
                    this.dispose();
                }
            }
        }
}//GEN-LAST:event_jBcrearActionPerformed

    private void formWindowOpened(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_formWindowOpened
        // TODO add your handling code here:
        if(inicial == false){
            jBver.setVisible(true);
        }
        else{
           jBver.setVisible(false);
        }
    }//GEN-LAST:event_formWindowOpened

    private void jBverActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jBverActionPerformed
        // TODO add your handling code here:
         if(jTcantidad.getText().compareTo("")==0){
            jLerror.setText("Introduzca la cantidad que corresponda.");
        }
        else{
            if(jCfalta.isSelected() && jCsobra.isSelected())
                jLerror.setText("Seleccione una unica opcion.");
            else if(!jCfalta.isSelected() && !jCsobra.isSelected())
                jLerror.setText("Seleccione alguna opcion.");
            else{
                if(jCfalta.isSelected())
                    su.crearParteDiferencia(Double.parseDouble(jTcantidad.getText()),"faltaron");
                else
                    su.crearParteDiferencia(Double.parseDouble(jTcantidad.getText()),"sobraron");
             JFPrincipal p = new JFPrincipal(su);
             new JFVerPartes(su, p, true).setVisible(true);
             this.dispose();
            }
        }
    }//GEN-LAST:event_jBverActionPerformed

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

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jBcrear;
    private javax.swing.JButton jBver;
    private javax.swing.JCheckBox jCfalta;
    private javax.swing.JCheckBox jCsobra;
    private javax.swing.JLabel jLSaldo1;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLerror;
    private javax.swing.JTextField jTcantidad;
    // End of variables declaration//GEN-END:variables

}
