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

/*
 * jfrmArqFinal.java
 *
 * Created on 04-ene-2010, 21:55:03
 */

package interfaz;

import daial.Arqueo;
import daial.Caja;
import daial.Movimiento;
import daial.OPBasica;
import daial.Sucursal;
import java.util.ArrayList;
import java.util.Date;
import javax.swing.JOptionPane;

/**
 *
 * @author Alberto
 */
public class jfrmArqFinal extends javax.swing.JFrame {
    private Sucursal s = new Sucursal();
    jfrmPrincipal p;
    private Caja caja_activa;
    Arqueo arq;

    /** Creates new form jfrmArqFinal */
    public jfrmArqFinal(Sucursal suc,jfrmPrincipal principal, Caja caj) {
        initComponents();
        this.setLocationRelativeTo(null);
        s = suc;
        p = new jfrmPrincipal(suc,caj);
        p = principal;
        caja_activa = caj;
        Date fecha = new Date();
        //arq = caja_activa.buscarArqueo(fecha);
        arq = caja_activa.getArqueo().get(caja_activa.getArqueo().size()-1);
        double diferencia;

        jTxt_saldo_ini.setText(String.valueOf(arq.getSaldo_inicial()));
        
        jTxt_saldo_fin.setText(String.valueOf(caja_activa.getSaldo()));

        diferencia = caja_activa.getSaldo() - arq.getSaldo_inicial();
        jTxt_diferencia.setText(String.valueOf(diferencia));
    }

    /** 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();
        jTxt_saldo_ini = new javax.swing.JTextField();
        jTxt_saldo_fin = new javax.swing.JTextField();
        jLabel2 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        jBtn_aceptar = new javax.swing.JButton();
        jPanel1 = new javax.swing.JPanel();
        jLabel4 = new javax.swing.JLabel();
        jTxt_diferencia = new javax.swing.JTextField();
        jBtn_Parte = new javax.swing.JButton();
        jTxt_incidencia = new javax.swing.JTextField();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setTitle("Arqueo Final");
        addWindowListener(new java.awt.event.WindowAdapter() {
            public void windowClosing(java.awt.event.WindowEvent evt) {
                formWindowClosing(evt);
            }
        });

        jLabel1.setFont(new java.awt.Font("Tahoma", 1, 18)); // NOI18N
        jLabel1.setText("Arqueo Final");

        jLabel2.setText("Saldo inicial: ");

        jLabel3.setText("Saldo final:");

        jBtn_aceptar.setText("Aceptar");
        jBtn_aceptar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jBtn_aceptarActionPerformed(evt);
            }
        });

        jPanel1.setBorder(javax.swing.BorderFactory.createEtchedBorder());

        jLabel4.setText("Diferencia:");

        jTxt_diferencia.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N

        jBtn_Parte.setText("Crear incidencia");
        jBtn_Parte.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jBtn_ParteActionPerformed(evt);
            }
        });

        jTxt_incidencia.setText("Introducir incidencia");
        jTxt_incidencia.setEnabled(false);

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGap(22, 22, 22)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                    .addComponent(jTxt_incidencia, javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(javax.swing.GroupLayout.Alignment.LEADING, jPanel1Layout.createSequentialGroup()
                        .addComponent(jLabel4)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jTxt_diferencia, javax.swing.GroupLayout.PREFERRED_SIZE, 158, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18)
                        .addComponent(jBtn_Parte)))
                .addContainerGap(26, Short.MAX_VALUE))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                .addContainerGap(12, Short.MAX_VALUE)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jTxt_diferencia, javax.swing.GroupLayout.PREFERRED_SIZE, 37, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel4)
                    .addComponent(jBtn_Parte))
                .addGap(18, 18, 18)
                .addComponent(jTxt_incidencia, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap(89, Short.MAX_VALUE)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel2)
                    .addComponent(jLabel3))
                .addGap(53, 53, 53)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(jTxt_saldo_fin)
                    .addComponent(jTxt_saldo_ini, javax.swing.GroupLayout.PREFERRED_SIZE, 159, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(93, 93, 93))
            .addGroup(layout.createSequentialGroup()
                .addGap(161, 161, 161)
                .addComponent(jLabel1)
                .addContainerGap(181, Short.MAX_VALUE))
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap(196, Short.MAX_VALUE)
                .addComponent(jBtn_aceptar)
                .addGap(188, 188, 188))
            .addGroup(layout.createSequentialGroup()
                .addGap(28, 28, 28)
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(34, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(22, 22, 22)
                .addComponent(jLabel1)
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jTxt_saldo_ini, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel2))
                .addGap(28, 28, 28)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jTxt_saldo_fin, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel3))
                .addGap(18, 18, 18)
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(11, 11, 11)
                .addComponent(jBtn_aceptar)
                .addGap(20, 20, 20))
        );

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

    private void jBtn_aceptarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jBtn_aceptarActionPerformed
        arq.setSaldo_final(caja_activa.getSaldo());

        if(!jTxt_incidencia.getText().equals("Introducir incidencia"))
            arq.setIncidencia(jTxt_incidencia.getText());

        JOptionPane dialogo = new JOptionPane();
        JOptionPane.showMessageDialog(rootPane, "Arqueo final realizado con éxito", "Aviso", JOptionPane.INFORMATION_MESSAGE);
        p.setEnabled(true);
        this.dispose();
    }//GEN-LAST:event_jBtn_aceptarActionPerformed

    private void jBtn_ParteActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jBtn_ParteActionPerformed
        jTxt_incidencia.enable(true);
    }//GEN-LAST:event_jBtn_ParteActionPerformed

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

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

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jBtn_Parte;
    private javax.swing.JButton jBtn_aceptar;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JTextField jTxt_diferencia;
    private javax.swing.JTextField jTxt_incidencia;
    private javax.swing.JTextField jTxt_saldo_fin;
    private javax.swing.JTextField jTxt_saldo_ini;
    // End of variables declaration//GEN-END:variables

}
