Package org.salamanca.ui

Source Code of org.salamanca.ui.PagosFrame

package org.salamanca.ui;

import java.awt.BorderLayout;

import javax.swing.JInternalFrame;
import javax.swing.JLabel;
import javax.swing.*;
import javax.swing.BorderFactory;
import componenteTabla.compomenteABMCList;
import org.salamanca.domain.Alumno;
import org.salamanca.broker.BrokerServer;
import java.util.Vector;
import java.util.Iterator;
import java.util.*;
import org.salamanca.domain.Periodo;
import org.salamanca.domain.Curso;
import java.text.SimpleDateFormat;
import org.salamanca.domain.Persona;
import com.borland.jbcl.layout.VerticalFlowLayout;
import com.borland.jbcl.layout.PaneLayout;
import com.borland.jbcl.layout.*;
import java.awt.Rectangle;
import java.awt.FlowLayout;
import java.awt.GridLayout;
import java.awt.Font;
import componenteTabla.InsertarEvent;
import componenteTabla.InsertarListener;
import org.salamanca.commands.periodo.InsertarPeriodo;
import componenteTabla.ClickTableEvent;
import componenteTabla.ClickTableListener;
import org.jdoinstruments.runtime.discfilemodel.util.DirectOID;
import org.salamanca.commands.*;
import componenteTabla.ModificarEvent;
import componenteTabla.ModificarListener;
import org.salamanca.commands.periodo.ModificarPeriodo;
import componenteTabla.EliminarEvent;
import componenteTabla.EliminarListener;
import org.salamanca.commands.periodo.EliminarPeriodo;
import org.salamanca.domain.CuotaBasica;
import java.awt.Color;
import org.salamanca.domain.Pago;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.ComponentEvent;
import java.awt.event.ComponentAdapter;

/**
* <p>Title: </p>
*
* <p>Description: </p>
*
* <p>Copyright: Copyright (c) 2006</p>
*
* <p>Company: </p>
*
* @author not attributable
* @version 1.0
*/
public class PagosFrame extends JInternalFrame implements
        CursoSelectableI {

    BorderLayout borderLayout1 = new BorderLayout();
    JLabel jLabel1 = new JLabel();
    JPanel jPanel1 = new JPanel();
    compomenteABMCList compomenteABMCListCuotasBasicas = new
            compomenteABMCList();
    compomenteABMCList compomenteABMCListAlumnos = new
            compomenteABMCList();
    JPanel jPanel2 = new JPanel();
    BorderLayout borderLayout2 = new BorderLayout();
    BorderLayout borderLayout3 = new BorderLayout();
    JPanel jPanel3 = new JPanel();
    GridLayout gridLayout1 = new GridLayout();
    Curso curso;
    JPanel jPanel4 = new JPanel();
    FlowLayout flowLayout1 = new FlowLayout();
    JButton jButtonRealizarPago = new JButton();
    JButton jButtonAnularPAgo = new JButton();
    MainFrame mainFrame;
    public PagosFrame(MainFrame mainFrame) {
        this.mainFrame = mainFrame;
        try {
            jbInit();

        } catch (Exception exception) {
            exception.printStackTrace();
        }
    }

    public void setCurso(Curso curso) {
        this.curso = curso;
        this.jLabel1.setText("PAGOS ---- Curso : " + curso.getNombre());
        loadListAlumnoDeCurso();
    }


    private void jbInit() throws Exception {
        getContentPane().setLayout(borderLayout1);
        jLabel1.setFont(new java.awt.Font("Arial", Font.PLAIN, 22));
        jLabel1.setHorizontalAlignment(SwingConstants.CENTER);
        jLabel1.setText("PAGOS --- Curso xxxx");
        jPanel1.setLayout(borderLayout3);
        jPanel2.setLayout(borderLayout2);
        //------------------------ Coutas Basicas
        compomenteABMCListCuotasBasicas.setVisibleCantidadRegistros(false);
        compomenteABMCListCuotasBasicas.setVisibleBuscar(false);
        compomenteABMCListCuotasBasicas.setInfoColumna(new String[][] { {
                "nombre",
                "tipo", "editable", "editor",
                "val.Combo", "Ancho Columna"}

                , {"Fecha vencimiento",
                "String",
                "false",
                "comun", "", "130"}

                , {"FACTURADO",
                "Boolean",
                "false",
                "comun", "", "130"}

                , {"Concepto", "String",
                "false",
                "comun", "", "70"}

                , {"Importe", "Double", "false",
                "comun", "", "100"}

                , {"Es Pago extra", "Boolean",
                "false", "comun", "", "130"},

                {"Fecha Pago", "String",
                "false", "comun", "", "130"},

                {"N�mero factura", "String",
                "false", "comun", "", "130"},

                {"oid", "String",
                "false", "comun", "", "1"}

        });

        compomenteABMCListCuotasBasicas.setVisibleAgregar(false);
        compomenteABMCListCuotasBasicas.setVisibleOrdenar(false);
        compomenteABMCListCuotasBasicas.setVisibleModificar(false);
        compomenteABMCListCuotasBasicas.setVisibleImprimir(true);
        compomenteABMCListCuotasBasicas.setVisibleGuardarComo(false);
        compomenteABMCListCuotasBasicas.setVisibleHeaderTabla(true);
        compomenteABMCListCuotasBasicas.setVisibleFiltrar(false);
        compomenteABMCListCuotasBasicas.setVisibleEliminar(false);
        compomenteABMCListCuotasBasicas.setVisibleCopyclipboard(true);
        compomenteABMCListCuotasBasicas.setVisibleReportes(true);
        compomenteABMCListCuotasBasicas.setEditableBoolean(false);
        jPanel1.setBorder(null);
        this.setDefaultCloseOperation(WindowConstants.HIDE_ON_CLOSE);
        this.setMaximizable(true);
        this.addComponentListener(new PagosFrame_this_componentAdapter(this));
        compomenteABMCListAlumnos.addClickTableListener(new
                PagosFrame_compomenteABMCListAlumnos_clickTableAdapter(this));
        jPanel4.setLayout(flowLayout1);
        jButtonRealizarPago.setBackground(new Color(215, 255, 201));
        jButtonRealizarPago.setToolTipText("Registra el pago de una cuota");
        jButtonRealizarPago.setText("Realizar pago");
        jButtonRealizarPago.addActionListener(new
                                              PagosFrame_jButtonRealizarPago_actionAdapter(this));
        jButtonAnularPAgo.setBackground(new Color(255, 194, 208));
        jButtonAnularPAgo.setToolTipText(
                "Anula un pago ya realizado, una vez anulado no se puede deshacer");
        jButtonAnularPAgo.setText("Anular pago");
        jButtonAnularPAgo.addComponentListener(new
                                               PagosFrame_jButtonAnularPAgo_componentAdapter(this));
        jButtonAnularPAgo.addActionListener(new
                                            PagosFrame_jButtonAnularPAgo_actionAdapter(this));
        this.getContentPane().add(jPanel3, java.awt.BorderLayout.CENTER);
        jPanel3.setBorder(BorderFactory.createEtchedBorder());
        jPanel3.setLayout(gridLayout1);
        jPanel1.add(compomenteABMCListCuotasBasicas,
                    java.awt.BorderLayout.CENTER);
        jPanel3.add(jPanel2, null);
        jPanel2.add(compomenteABMCListAlumnos, java.awt.BorderLayout.CENTER);
        jPanel3.add(jPanel1, null);
        this.getContentPane().add(jLabel1, java.awt.BorderLayout.NORTH);
        this.getContentPane().add(jPanel4, java.awt.BorderLayout.SOUTH);
        jPanel4.add(jButtonRealizarPago);
        jPanel4.add(jButtonAnularPAgo);
        compomenteABMCListAlumnos.setVisibleCantidadRegistros(true);
        compomenteABMCListAlumnos.setVisibleBuscar(true);
        compomenteABMCListAlumnos.setInfoColumna(new String[][] { {"nombre",
                                                 "tipo", "editable", "editor",
                                                 "val.Combo", "Ancho Columna"}
                                                 , {"Nombre", "String", "true",
                                                 "comun", "", "90"}
                                                 , {"Apellido", "String",
                                                 "true",
                                                 "comun", "", "90"}
                                                 , {"DNI", "Long", "true",
                                                 "comun",
                                                 "", "50"}
                                                 , {"Masculino", "Boolean",
                                                 "false",
                                                 "comun", "", "60"}
                                                 , {"Domicilio", "String",
                                                 "true",
                                                 "comun", "", "50"}
                                                 , {"Localidad", "String",
                                                 "true",
                                                 "comun", "", "50"}
                                                 , {"Codigo Postal", "String",
                                                 "true", "comun", "", "70"}
                                                 , {"Telefono", "String",
                                                 "true",
                                                 "comun", "", "50"}
                                                 , {"Fecha de Nacimiento",
                                                 "String",
                                                 "true", "comun", "", "180"},
                                                 {"oid", "String", "false",
                                                 "comun", "", "1"}

        });
        compomenteABMCListAlumnos.setEditableBoolean(false);
        compomenteABMCListAlumnos.setVisibleAgregar(false);
        compomenteABMCListAlumnos.setVisibleOrdenar(false);
        compomenteABMCListAlumnos.setVisibleModificar(false);
        compomenteABMCListAlumnos.setVisibleImprimir(true);
        compomenteABMCListAlumnos.setVisibleGuardarComo(false);
        compomenteABMCListAlumnos.setVisibleHeaderTabla(true);
        compomenteABMCListAlumnos.setVisibleFiltrar(false);
        compomenteABMCListAlumnos.setVisibleEliminar(false);
        compomenteABMCListAlumnos.setVisibleCopyclipboard(true);
        compomenteABMCListAlumnos.setVisibleReportes(true);

        compomenteABMCListAlumnos.setTituloImprimir("Alumnos del Curso ");

    }


    /**
     * loadListAlumnoDeCurso
     *
     * @param curso Curso
     */
    private void loadListAlumnoDeCurso() {
        if (curso != null) {
            try {

                //actualizo el curso
                curso = (Curso) BrokerServer.instance().getPMF().
                        getPersistenceManager().getObjectById(javax.jdo.
                        JDOHelper.getObjectId(curso), true);

                Vector v = new Vector();
                Iterator iter = curso.getSetAlumnos().iterator();
                while (iter.hasNext()) {
                    Alumno itemAlumno = (Alumno) iter.next();

                    if (itemAlumno.isHabilitado()) { //solo se muestran los alumnos habilitados
                        v.add(itemAlumno);
                    }
                }

                compomenteABMCListAlumnos.clearDatos();
                if (v.size() > 0) {
                    Object[][] trabajo = new Object[v.size()][10];
                    for (int i = 0; i < v.size(); i++) {
                        Alumno alumno = (Alumno) v.elementAt(i);
                        Persona persona = alumno.getPersona();
                        trabajo[i][0] = persona.getNombre();
                        trabajo[i][1] = persona.getApellido();
                        trabajo[i][2] = new Long(persona.getDni());
                        trabajo[i][3] = new Boolean(persona.isMasculino());
                        trabajo[i][4] = persona.getDomicilio();
                        trabajo[i][5] = persona.getLocalidad();
                        trabajo[i][6] = persona.getCodigoPostal();
                        trabajo[i][7] = persona.getTelefono();
                        SimpleDateFormat dateFormatInicio = new
                                SimpleDateFormat(
                                        "d-M-yyyy");
                        trabajo[i][8] = dateFormatInicio.format(persona.
                                getFechaNacimiento());
                        trabajo[i][9] = javax.jdo.JDOHelper.
                                        getObjectId(alumno).toString(); ;
                    }
                    compomenteABMCListAlumnos.setDatos(trabajo);
                    this.compomenteABMCListCuotasBasicas.clearDatos();
                }
            }

            catch (Exception ex) {
                ex.printStackTrace();
            }
        }
    }


    /**
     * loadList
     */
    private void loadListCuotas(Alumno alumno) {
        compomenteABMCListCuotasBasicas.clearDatos();

        if (alumno != null) {
            //actualizo el objeto curso el cual puede que se le hayan insertado modificado o borrado objetos
            curso = (Curso) BrokerServer.instance().getPMF().
                    getPersistenceManager().getObjectById(javax.jdo.JDOHelper.
                    getObjectId(curso), true);
            Vector v = new Vector(curso.
                                  getSetCuotaBasica());
            if ((v != null) && (v.size() > 0)) {
                Object[][] trabajo = new Object[v.size()][8];
                for (int i = 0; i < v.size(); i++) {
                    CuotaBasica cuota = (CuotaBasica) v.elementAt(i);

                    SimpleDateFormat dateFormatInicio = new SimpleDateFormat(
                            "d-M-yyyy");
                    trabajo[i][0] = dateFormatInicio.format(cuota.
                            getFechaVencimiento());
                    trabajo[i][1] = Boolean.valueOf(isCuotaPaga(cuota, alumno));
                    trabajo[i][2] = cuota.getConcepto();
                    trabajo[i][3] = Double.valueOf(cuota.getImporte());
                    trabajo[i][4] = Boolean.valueOf(cuota.isPagoExtra());
                    trabajo[i][5] = getFechaPago(cuota, alumno);
                    trabajo[i][6] = getNumeroFactura(cuota, alumno);
                    trabajo[i][7] = javax.jdo.JDOHelper.
                                    getObjectId(cuota).toString();
                }
                compomenteABMCListCuotasBasicas.setDatos(trabajo);
            }
        }
    }


    private boolean isCuotaPaga(CuotaBasica cuota, Alumno alumno) {

        Iterator iter = alumno.getSetPagos().iterator();
        while (iter.hasNext()) {
            Pago itemPago = (Pago) iter.next();
            if (!itemPago.isAnulado() &&
                javax.jdo.JDOHelper.getObjectId(itemPago.getCuotaPagada()).
                equals(javax.jdo.JDOHelper.getObjectId(cuota))) {
                return true; //si alguno de sus pagos era sobre la cuota en cuestion
                //y no fue anulada
            }
        }
        return false;
    }

    private String getFechaPago(CuotaBasica cuota, Alumno alumno) {
        SimpleDateFormat dateFormat = new SimpleDateFormat("d-M-yyyy");
        Iterator iter = alumno.getSetPagos().iterator();
        while (iter.hasNext()) {
            Pago itemPago = (Pago) iter.next();
            if (!itemPago.isAnulado() &&
                javax.jdo.JDOHelper.getObjectId(itemPago.getCuotaPagada()).
                equals(javax.jdo.JDOHelper.getObjectId(cuota))) {
                String fecha = dateFormat.format(itemPago.getFechaPago());
                return fecha;
            }
        }
        return "";
    }


    private String getNumeroFactura(CuotaBasica cuota, Alumno alumno) {

        Iterator iter = alumno.getSetPagos().iterator();
        while (iter.hasNext()) {
            Pago itemPago = (Pago) iter.next();
            if (!itemPago.isAnulado() &&
                javax.jdo.JDOHelper.getObjectId(itemPago.getCuotaPagada()).
                equals(javax.jdo.JDOHelper.getObjectId(cuota))) {
                String numero = Long.toString(itemPago.getNumeroFactura());
                return numero;
            }
        }
        return "";
    }


    public void compomenteABMCListAlumnos_ClickTable(ClickTableEvent e) {
        if (compomenteABMCListAlumnos.getSelectedRow() != -1) {

            Alumno alumno = getUltimoAlumnoSeleccionado();
            this.loadListCuotas(alumno);

        }
    }

    public void refreshABCMListAlumnos() {
        Alumno alumno = getUltimoAlumnoSeleccionado();
        if (alumno != null) {
            this.loadListCuotas(alumno);
        }
    }

    private Alumno getUltimoAlumnoSeleccionado() {
        if (compomenteABMCListAlumnos.getSelectedRow() != -1) {
            String oidStr = ((String) compomenteABMCListAlumnos.
                             getSelectedRowData().
                             getValueAt(9));
            kodo.util.Id oid = new kodo.util.Id(oidStr);
            Alumno alumno = (Alumno) org.salamanca.broker.BrokerServer.instance().
                            getPMF().getPersistenceManager().getObjectById(oid, true);
            return alumno;

        }
        return null;
    }

    private CuotaBasica getUltimaCuotaBasicaSeleccionada() {
        if (this.compomenteABMCListCuotasBasicas.getSelectedRow() != -1) {
            String oidStr = ((String) compomenteABMCListCuotasBasicas.
                             getSelectedRowData().
                             getValueAt(7));
            kodo.util.Id oid = new kodo.util.Id(oidStr);
            CuotaBasica cuotaBasica = (CuotaBasica) org.salamanca.broker.
                                      BrokerServer.instance().
                                      getPMF().getPersistenceManager().
                                      getObjectById(oid, true);
            return cuotaBasica;

        }
        return null;
    }

    public void jButtonRealizarPago_actionPerformed(ActionEvent e) {
        if (getUltimoAlumnoSeleccionado() != null &&
            getUltimaCuotaBasicaSeleccionada() != null) {
            mainFrame.facturaFrame.setData(getUltimoAlumnoSeleccionado(),
                                           getUltimaCuotaBasicaSeleccionada());
            mainFrame.facturaFrame.show();
            this.setVisible(false);
        }
    }

    public void jButtonAnularPAgo_actionPerformed(ActionEvent e) {
        if (getUltimoAlumnoSeleccionado() != null &&
            getUltimaCuotaBasicaSeleccionada() != null) {
            ICommand insertarCurso = CommandFactory.createAnularPago(
                    getUltimaCuotaBasicaSeleccionada(),
                    getUltimoAlumnoSeleccionado());
            try {
                insertarCurso.execute();
            } catch (Exception ex) {
                JOptionPane.showMessageDialog(this, ex.getMessage());

            }
            refreshABCMListAlumnos(); //refeesco para que salga destildado
        }

    }

    public void jButtonAnularPAgo_componentShown(ComponentEvent e) {

    }

    public void this_componentShown(ComponentEvent e) {
        //cuando se de visualiza se debe refescar para que salga el tilde de que se pag�
        refreshABCMListAlumnos();
    }

    public void this_componentHidden(ComponentEvent e) {
       // this.mainFrame.selectPagosFrame.show();
    }


    class PagosFrame_compomenteABMCListAlumnos_clickTableAdapter implements
            ClickTableListener {
        private PagosFrame adaptee;
        PagosFrame_compomenteABMCListAlumnos_clickTableAdapter(
                PagosFrame adaptee) {
            this.adaptee = adaptee;
        }

        public void ClickTable(ClickTableEvent e) {
            adaptee.compomenteABMCListAlumnos_ClickTable(e);
        }
    }
}


class PagosFrame_jButtonAnularPAgo_actionAdapter implements ActionListener {
    private PagosFrame adaptee;
    PagosFrame_jButtonAnularPAgo_actionAdapter(PagosFrame adaptee) {
        this.adaptee = adaptee;
    }

    public void actionPerformed(ActionEvent e) {
        adaptee.jButtonAnularPAgo_actionPerformed(e);
    }
}


class PagosFrame_this_componentAdapter extends ComponentAdapter {
    private PagosFrame adaptee;
    PagosFrame_this_componentAdapter(PagosFrame adaptee) {
        this.adaptee = adaptee;
    }

    public void componentShown(ComponentEvent e) {
        adaptee.this_componentShown(e);
    }
     public void componentHidden(ComponentEvent e) {
        adaptee.this_componentHidden( e);
    }

}


class PagosFrame_jButtonAnularPAgo_componentAdapter extends ComponentAdapter {
    private PagosFrame adaptee;
    PagosFrame_jButtonAnularPAgo_componentAdapter(PagosFrame adaptee) {
        this.adaptee = adaptee;
    }

    public void componentShown(ComponentEvent e) {
        adaptee.jButtonAnularPAgo_componentShown(e);
    }
}


class PagosFrame_jButtonRealizarPago_actionAdapter implements ActionListener {
    private PagosFrame adaptee;
    PagosFrame_jButtonRealizarPago_actionAdapter(PagosFrame adaptee) {
        this.adaptee = adaptee;
    }

    public void actionPerformed(ActionEvent e) {
        adaptee.jButtonRealizarPago_actionPerformed(e);
    }
}
TOP

Related Classes of org.salamanca.ui.PagosFrame

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.