Package org.salamanca.ui

Source Code of org.salamanca.ui.FacturaFrame_jButtonAplicarDescuentoPorcentual_actionAdapter

package org.salamanca.ui;

import java.awt.BorderLayout;

import javax.swing.JInternalFrame;
import javax.swing.JLabel;
import java.awt.Rectangle;
import java.awt.Font;
import javax.swing.JPanel;
import javax.swing.BorderFactory;
import javax.swing.JComboBox;
import javax.swing.JButton;
import org.salamanca.domain.*;
import java.text.SimpleDateFormat;
import org.salamanca.broker.BrokerServer;
import java.util.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.text.NumberFormat;
import java.text.DecimalFormat;
import javax.swing.WindowConstants;
import javax.jdo.Extent;
import org.salamanca.commands.CommandFactory;
import org.salamanca.commands.ICommand;
import java.text.ParseException;
import javax.swing.JOptionPane;
import org.salamanca.reportes.factura.Factura;
import javax.swing.JTextField;
import javax.swing.JFormattedTextField;
import java.beans.*;
import java.util.prefs.Preferences;
import javax.swing.JCheckBox;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;
import java.awt.event.ComponentEvent;
import java.awt.event.ComponentAdapter;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;

/**
* <p>Title: </p>
*
* <p>Description: </p>
*
* <p>Copyright: Copyright (c) 2006</p>
*
* <p>Company: </p>
*
* @author not attributable
* @version 1.0
*/
public class FacturaFrame extends JInternalFrame implements
        PropertyChangeListener {
    public final static String NUMERO_FACTURA = "org.salamanca.NumeroFactura";

    final int DESCUENTO_NADA = 0;
    final int DESCUENTO_PROCENTUAL = 1;
    final int DESCUENTO_SUMAFIJA = 2;
    private int tipoDescuento = DESCUENTO_NADA;
    double descuento = 0;
    double recargoMoroso = 0;
    double importeAPagar = 0;
    double porcentajeRecargoFormaDePago = 0;

    JLabel jLabel1 = new JLabel();
    JLabel jLabelImporteCuotaBasica = new JLabel();
    JPanel jPanel1 = new JPanel();
    JPanel jPanel2 = new JPanel();
    JComboBox jComboBoxDescuentoPorcentual = new JComboBox();
    JComboBox jComboBoxDescuentoSumaFija = new JComboBox();
    JLabel jLabel2 = new JLabel();
    JLabel jLabel3 = new JLabel();
    JPanel jPanel3 = new JPanel();
    JPanel jPanel4 = new JPanel();
    JButton jButtonAplicarDescuentoPorcentual = new JButton();
    JButton jButtonAnularDescuentoPorcentual = new JButton();
    JButton jButtonAplicarDescuentoSumafija = new JButton();
    JButton jButtonAnularDescuentoSumafija = new JButton();
    JLabel jLabel4 = new JLabel();
    JLabel jLabelDscuentoPorcentual = new JLabel();
    JLabel jLabel5 = new JLabel();
    JLabel jLabel6 = new JLabel();
    JLabel jLabel7 = new JLabel();
    JLabel jLabel9 = new JLabel();
    JLabel jLabelPorcentaje = new JLabel();
    JLabel jLabelConceptoDescuentoPorcentual = new JLabel();
    JLabel jLabelDescuentoSumaFija = new JLabel();
    JLabel jLabelConceptoDescuentoSumaFija = new JLabel();
    JLabel jLabel10 = new JLabel();
    JLabel jLabel11 = new JLabel();
    JLabel jLabel12 = new JLabel();
    JLabel jLabel13 = new JLabel();
    JLabel jLabelAlumno = new JLabel();
    JLabel jLabelCurso = new JLabel();
    JLabel jLabelConcepto = new JLabel();
    JLabel jLabelTotalAPagar = new JLabel();
    Alumno alumno;
    CuotaBasica cuotaBasica;
    JPanel jPanel5 = new JPanel();
    JLabel jLabel14 = new JLabel();
    JLabel jLabel15 = new JLabel();
    JLabel jLabelVencimiento = new JLabel();
    JLabel jLabelRecargo = new JLabel();
    JButton jButtonImprimir = new JButton();
    static final String CONSTANT_NO = "NO";
    JLabel jLabel8 = new JLabel();
    JLabel jLabelRecargoFormaPago = new JLabel();
    JComboBox jComboBoxRecargoFormaDePago = new JComboBox();
    MainFrame mainFrame;
    JLabel jLabel16 = new JLabel();
    JFormattedTextField jFormattedTextFieldFacturaNumero = new
            JFormattedTextField(new DecimalFormat("##########"));
    JCheckBox jCheckBox1 = new JCheckBox();
    JCheckBox jCheckBoxAplicarRecargo = new JCheckBox();
    public FacturaFrame(MainFrame mainFrame) {
        this.mainFrame = mainFrame;
        try {
            jbInit();
        } catch (Exception exception) {
            exception.printStackTrace();
        }
    }

    /**
     * setData
     *
     * @param alumno Alumno
     * @param cuotaBasica CuotaBasica
     */
    public void setData(Alumno alumno, CuotaBasica cuotaBasica) {
        this.alumno = alumno;
        this.cuotaBasica = cuotaBasica;

        update();
        this.jCheckBox1.setSelected(true);
        this.jCheckBoxAplicarRecargo.setSelected(true);
        this.loadComboDescuentoPorcentual();
        this.loadComboDescuentoSumaFija();
        this.loadComboRecargoFormaDePago();

        this.anularDescuentoPorcentual(); //tengo que cerear los descuentos
        // para que no coloque los del anterior cobro
        this.anularDescuentoSumaFija();
        //cada vez que se setea l adata es una factura nueva por eso actualizo el numero
        actualizarNumeroFactura();

    }


    private void actualizarNumeroFactura() {
        Preferences prefs =
                Preferences.userNodeForPackage(org.salamanca.ui.FacturaFrame.class);
        String str = prefs.get(NUMERO_FACTURA, "0");

        long contador = Long.valueOf(str).longValue();
        contador++;
        this.jFormattedTextFieldFacturaNumero.setValue(new Long(contador));
    }

    private void updateNumeroFactura(Long numero) {
        Preferences prefs =
                Preferences.userNodeForPackage(org.salamanca.ui.FacturaFrame.class);

        prefs.put(NUMERO_FACTURA, numero.toString());

    }


    /**
     * getRecargo
     *
     * @return double
     */
    private double updateRecargo() {
        GregorianCalendar vencimiento = new GregorianCalendar();
        GregorianCalendar hoy = new GregorianCalendar();
        vencimiento.setTime(cuotaBasica.getFechaVencimiento());
        hoy.setTime(new Date());

        if (hoy.after(vencimiento)) { // si se pas� del vencimiento
            int dias = calculateDifference(new Date(),
                                           cuotaBasica.getFechaVencimiento());
            if (this.cuotaBasica.isPagoExtra()) { // para pagos extras

                double recargoDiario = cuotaBasica.getImporte() / 100 *
                                       getRecargoPagoExtra();
                double recargoTotal = recargoDiario * dias;
                return recargoTotal;

            } else { //para cuotas comunes
                double recargoDiario = cuotaBasica.getImporte() / 100 *
                                       getRecargoCuotaBasica();
                double recargoTotal = recargoDiario * dias;
                return recargoTotal;
            }
        }
        return 0; // si no hay recargo es cero
    }


    private boolean isAvisarFueraPeriodoDedescuentos() {
        GregorianCalendar vencimiento = new GregorianCalendar();
        GregorianCalendar hoy = new GregorianCalendar();
        vencimiento.setTime(cuotaBasica.getFechaVencimiento());
        hoy.setTime(new Date());

        if (hoy.after(vencimiento)) { // si se pas� del vencimiento
            int dias = calculateDifference(new Date(),
                                           cuotaBasica.getFechaVencimiento());
            if (dias > getDiasLimiteDescuento()) {
                return true;
            }
        }
        return false; // si no hay recargo es cero
    }


    /**
     * getRecargoCuotaBasica
     *
     * @return double
     */
    private double getRecargoCuotaBasica() {
        double recargoCuotaBasica = 0;
        Vector v = BrokerServer.instance().getAll(ConfiguracionGeneral.class);
        Enumeration enumer = v.elements();
        while (enumer.hasMoreElements()) {
            ConfiguracionGeneral conf = (ConfiguracionGeneral) enumer.
                                        nextElement();
            recargoCuotaBasica = conf.getPorcentajeRecargoPorDiaCuotas();
        }
        return recargoCuotaBasica;
    }


    /**
     * getDiasLimiteDescuento
     *
     * @return int
     */
    private int getDiasLimiteDescuento() {
        int dias = 0;

        Extent ext = BrokerServer.instance().getPMF().getPersistenceManager().
                     getExtent(ConfiguracionGeneral.class, true);
        Iterator iter = ext.iterator();
        if (iter.hasNext()) {
            ConfiguracionGeneral conf = (ConfiguracionGeneral) iter.next();
            dias = conf.getDiasLuegoVencimientoAnulaDescuento();
        }
        return dias;
    }


    /**
     * getRecargoPagoExtra
     *
     * @return double
     */
    private double getRecargoPagoExtra() {
        double recargoPagoExtra = 0;
        Extent ext = BrokerServer.instance().getPMF().getPersistenceManager().
                     getExtent(ConfiguracionGeneral.class, true);
        Iterator iter = ext.iterator();
        if (iter.hasNext()) {
            ConfiguracionGeneral conf = (ConfiguracionGeneral) iter.next();
            recargoPagoExtra = conf.getPorcentajeRecargoPorDiaPagosExtra();
        }
        return recargoPagoExtra;
    }


    /**
     * calculateDifference
     *
     * @param a Date
     * @param b Date
     * @return int
     */
    public static int calculateDifference(Date a, Date b) {
        int tempDifference = 0;
        int difference = 0;
        Calendar earlier = Calendar.getInstance();
        Calendar later = Calendar.getInstance();

        if (a.compareTo(b) < 0) {
            earlier.setTime(a);
            later.setTime(b);
        } else {
            earlier.setTime(b);
            later.setTime(a);
        }

        while (earlier.get(Calendar.YEAR) != later.get(Calendar.YEAR)) {
            tempDifference = 365 *
                             (later.get(Calendar.YEAR) -
                              earlier.get(Calendar.YEAR));
            difference += tempDifference;

            earlier.add(Calendar.DAY_OF_YEAR, tempDifference);
        }

        if (earlier.get(Calendar.DAY_OF_YEAR) != later.get(Calendar.DAY_OF_YEAR)) {
            tempDifference = later.get(Calendar.DAY_OF_YEAR) -
                             earlier.get(Calendar.DAY_OF_YEAR);
            difference += tempDifference;

            earlier.add(Calendar.DAY_OF_YEAR, tempDifference);
        }

        return difference;
    }


    /**
     * update
     */
    private void update() {
        this.jLabelAlumno.setText(this.alumno.getPersona().getApellido() +
                                  ", " +
                                  this.alumno.getPersona().getNombre());
        this.jLabelCurso.setText(cuotaBasica.getCurso().getNombre());
        this.jLabelConcepto.setText(cuotaBasica.getConcepto());
        this.jLabelImporteCuotaBasica.setText(String.valueOf(cuotaBasica.
                getImporte()));
        SimpleDateFormat dateFormatInicio = new SimpleDateFormat(
                "d-M-yyyy");

        this.jLabelVencimiento.setText(dateFormatInicio.format(
                cuotaBasica.
                getFechaVencimiento()));

        DecimalFormat decFormat = new DecimalFormat();
        decFormat.setMaximumFractionDigits(2);
        decFormat.setMinimumFractionDigits(2);

        recargoMoroso = updateRecargo();
        this.jLabelRecargo.setText("$ " + decFormat.format(recargoMoroso));

        updateImporteAPagar();
    }

    /**
     * loadComboDescuentoPorcentual
     */
    private void loadComboDescuentoPorcentual() {
        this.jComboBoxDescuentoPorcentual.removeAllItems();
        Vector v = new Vector();
        Iterator iter = this.alumno.getPersona().getSetDescuento().iterator();
        while (iter.hasNext()) {
            Descuento itemDescuento = (Descuento) iter.next();
            if (itemDescuento instanceof DescuentoPorcentual) {
                v.add(itemDescuento);
            }
        }

        Enumeration enumer = v.elements();
        while (enumer.hasMoreElements()) {
            DescuentoPorcentual itemDescuentoPorcentual = (
                    DescuentoPorcentual)
                    enumer.nextElement();
            this.jComboBoxDescuentoPorcentual.addItem(
                    itemDescuentoPorcentual);
        }

    }

//este metodo carga todos los descuentos que existen para que el operador los pueda usar
    //se activa al destildar el checkbox de restringir descuentos
    private void loadComboTodosLosDescuentosPorcentual() {
        this.jComboBoxDescuentoPorcentual.removeAllItems();

        Vector v = BrokerServer.instance().getAll(DescuentoPorcentual.class);

        Enumeration enumer = v.elements();
        while (enumer.hasMoreElements()) {
            DescuentoPorcentual itemDescuentoPorcentual = (
                    DescuentoPorcentual)
                    enumer.nextElement();
            this.jComboBoxDescuentoPorcentual.addItem(
                    itemDescuentoPorcentual);
        }

    }


    /**
     * loadComboDescuentoSumaFija
     */
    private void loadComboDescuentoSumaFija() {
        this.jComboBoxDescuentoSumaFija.removeAllItems();
        Vector v = new Vector();
        Iterator iter = this.alumno.getPersona().getSetDescuento().iterator();
        while (iter.hasNext()) {
            Descuento itemDescuento = (Descuento) iter.next();
            if (itemDescuento instanceof DescuentoSumaFija) {
                v.add(itemDescuento);
            }
        }

        Enumeration enumer = v.elements();
        while (enumer.hasMoreElements()) {
            DescuentoSumaFija itemDescuentoSumaFija = (DescuentoSumaFija)
                    enumer.nextElement();
            this.jComboBoxDescuentoSumaFija.addItem(itemDescuentoSumaFija);
        }

    }

    /**
     * loadComboRecargoFormaDePago
     */
    private void loadComboRecargoFormaDePago() {
        this.jComboBoxRecargoFormaDePago.removeAllItems();
        Vector v = BrokerServer.instance().getAll(Recargo.class);

        Vector vOrdenado = new Vector();
        Enumeration enumer = v.elements();
        while (enumer.hasMoreElements()) {
            Recargo recargo = (Recargo)
                              enumer.nextElement();
            vOrdenado.add(recargo.getConcepto());

        }

        java.util.Collections.sort(vOrdenado);
        Enumeration enumer2 = vOrdenado.elements();
        while (enumer2.hasMoreElements()) {
            String item = (String) enumer2.nextElement();
            this.jComboBoxRecargoFormaDePago.addItem(item);
        }

        setearRecargoFormaDePago();
    }


    private void jbInit() throws Exception {
        getContentPane().setLayout(null);
        jLabel1.setFont(new java.awt.Font("Arial", Font.PLAIN, 11));
        jLabel1.setText("Importe cuota:");
        jLabel1.setBounds(new Rectangle(7, 70, 70, 15));
        jPanel1.setBorder(BorderFactory.createEtchedBorder());
        jPanel1.setBounds(new Rectangle(6, 9, 429, 115));
        jPanel1.setLayout(null);
        jPanel2.setBorder(BorderFactory.createEtchedBorder());
        jPanel2.setBounds(new Rectangle(6, 129, 429, 181));
        jPanel2.setLayout(null);
        jComboBoxDescuentoPorcentual.setFont(new java.awt.Font("Arial",
                Font.PLAIN, 11));
        jComboBoxDescuentoPorcentual.setBounds(new Rectangle(7, 33, 182, 20));
        jComboBoxDescuentoSumaFija.setFont(new java.awt.Font("Arial",
                Font.PLAIN, 11));
        jComboBoxDescuentoSumaFija.setBounds(new Rectangle(9, 33, 182, 20));
        jLabel2.setFont(new java.awt.Font("Arial", Font.PLAIN, 11));
        jLabel2.setText("Descuento porcentual");
        jLabel2.setBounds(new Rectangle(34, 6, 128, 23));
        jLabel3.setFont(new java.awt.Font("Arial", Font.PLAIN, 11));
        jLabel3.setText("Descuento suma fija");
        jLabel3.setBounds(new Rectangle(38, 11, 122, 15));
        jPanel3.setBorder(BorderFactory.createEtchedBorder());
        jPanel3.setBounds(new Rectangle(6, 5, 207, 170));
        jPanel3.setLayout(null);
        jPanel4.setBorder(BorderFactory.createEtchedBorder());
        jPanel4.setBounds(new Rectangle(218, 5, 206, 170));
        jPanel4.setLayout(null);
        jButtonAplicarDescuentoPorcentual.setBounds(new Rectangle(9, 82, 79, 20));
        jButtonAplicarDescuentoPorcentual.setFont(new java.awt.Font("Arial",
                Font.PLAIN, 11));
        jButtonAplicarDescuentoPorcentual.setText("Aplicar");
        jButtonAplicarDescuentoPorcentual.addActionListener(new
                FacturaFrame_jButtonAplicarDescuentoPorcentual_actionAdapter(this));
        jButtonAnularDescuentoPorcentual.setBounds(new Rectangle(107, 82, 79,
                20));
        jButtonAnularDescuentoPorcentual.setFont(new java.awt.Font("Arial",
                Font.PLAIN, 11));
        jButtonAnularDescuentoPorcentual.setText("Anular");
        jButtonAnularDescuentoPorcentual.addActionListener(new
                FacturaFrame_jButtonAnularDescuentoPorcentual_actionAdapter(this));
        jButtonAplicarDescuentoSumafija.setBounds(new Rectangle(12, 81, 79, 20));
        jButtonAplicarDescuentoSumafija.setFont(new java.awt.Font("Arial",
                Font.PLAIN, 11));
        jButtonAplicarDescuentoSumafija.setText("Aplicar");
        jButtonAplicarDescuentoSumafija.addActionListener(new
                FacturaFrame_jButtonAplicarDescuentoSumafija_actionAdapter(this));
        jButtonAnularDescuentoSumafija.setBounds(new Rectangle(110, 81, 79, 20));
        jButtonAnularDescuentoSumafija.setFont(new java.awt.Font("Arial",
                Font.PLAIN, 11));
        jButtonAnularDescuentoSumafija.setText("Anular");
        jButtonAnularDescuentoSumafija.addActionListener(new
                FacturaFrame_jButtonAnularDescuentoSumafija_actionAdapter(this));
        jLabelImporteCuotaBasica.setFont(new java.awt.Font("Arial",
                Font.PLAIN,
                11));
        jLabel4.setFont(new java.awt.Font("Arial", Font.PLAIN, 11));
        jLabel4.setText("Descuento = ");
        jLabel4.setBounds(new Rectangle(6, 145, 68, 16));
        jLabelDscuentoPorcentual.setFont(new java.awt.Font("Arial",
                Font.PLAIN,
                11));
        jLabelDscuentoPorcentual.setText(CONSTANT_NO);
        jLabelDscuentoPorcentual.setBounds(new Rectangle(74, 144, 63, 16));
        jLabel5.setFont(new java.awt.Font("Arial", Font.PLAIN, 11));
        jLabel5.setText("Concepto = ");
        jLabel5.setBounds(new Rectangle(6, 110, 61, 16));
        jLabel6.setFont(new java.awt.Font("Arial", Font.PLAIN, 11));
        jLabel6.setText("Porcentaje = ");
        jLabel6.setBounds(new Rectangle(6, 128, 67, 16));
        jLabel7.setFont(new java.awt.Font("Arial", Font.PLAIN, 11));
        jLabel7.setText("Concepto = ");
        jLabel7.setBounds(new Rectangle(12, 117, 61, 15));
        jLabel9.setFont(new java.awt.Font("Arial", Font.PLAIN, 11));
        jLabel9.setText("Descuento = ");
        jLabel9.setBounds(new Rectangle(12, 133, 67, 15));
        jLabelPorcentaje.setFont(new java.awt.Font("Arial", Font.PLAIN, 11));
        jLabelPorcentaje.setText(CONSTANT_NO);
        jLabelPorcentaje.setBounds(new Rectangle(74, 127, 35, 16));
        jLabelConceptoDescuentoPorcentual.setFont(new java.awt.Font("Arial",
                Font.PLAIN, 11));
        jLabelConceptoDescuentoPorcentual.setText(CONSTANT_NO);
        jLabelConceptoDescuentoPorcentual.setBounds(new Rectangle(74, 111,
                123,
                15));
        jLabelDescuentoSumaFija.setFont(new java.awt.Font("Arial",
                Font.PLAIN,
                11));
        jLabelDescuentoSumaFija.setText(CONSTANT_NO);
        jLabelDescuentoSumaFija.setBounds(new Rectangle(76, 134, 54, 15));
        jLabelConceptoDescuentoSumaFija.setFont(new java.awt.Font("Arial",
                Font.PLAIN, 11));
        jLabelConceptoDescuentoSumaFija.setText(CONSTANT_NO);
        jLabelConceptoDescuentoSumaFija.setBounds(new Rectangle(76, 114,
                117,
                18));
        jLabel10.setFont(new java.awt.Font("Arial", Font.PLAIN, 14));
        jLabel10.setText("Total a pagar :");
        jLabel10.setBounds(new Rectangle(11, 383, 100, 15));
        jLabel11.setFont(new java.awt.Font("Arial", Font.PLAIN, 11));
        jLabel11.setText("Concepto:");
        jLabel11.setBounds(new Rectangle(7, 50, 62, 15));
        jLabel12.setFont(new java.awt.Font("Arial", Font.PLAIN, 11));
        jLabel12.setText("Alumno:");
        jLabel12.setBounds(new Rectangle(7, 10, 40, 15));
        jLabel13.setFont(new java.awt.Font("Arial", Font.PLAIN, 11));
        jLabel13.setText("Curso:");
        jLabel13.setBounds(new Rectangle(7, 30, 40, 15));
        jLabelAlumno.setFont(new java.awt.Font("Arial", Font.PLAIN, 11));
        jLabelAlumno.setText("...");
        jLabelAlumno.setBounds(new Rectangle(52, 9, 220, 15));
        jLabelCurso.setFont(new java.awt.Font("Arial", Font.PLAIN, 11));
        jLabelCurso.setText("...");
        jLabelCurso.setBounds(new Rectangle(43, 29, 277, 15));
        jLabelConcepto.setFont(new java.awt.Font("Arial", Font.PLAIN, 11));
        jLabelConcepto.setText("...");
        jLabelConcepto.setBounds(new Rectangle(58, 49, 300, 15));
        jLabelTotalAPagar.setFont(new java.awt.Font("Arial", Font.PLAIN, 14));
        jLabelTotalAPagar.setText("...");
        jLabelTotalAPagar.setBounds(new Rectangle(112, 383, 67, 15));
        jPanel5.setBorder(BorderFactory.createEtchedBorder());
        jPanel5.setBounds(new Rectangle(6, 315, 429, 62));
        jPanel5.setLayout(null);
        jLabel14.setFont(new java.awt.Font("Arial", Font.PLAIN, 11));
        jLabel14.setText("Recargo por pago fuera de t�rmino:");
        jLabel14.setBounds(new Rectangle(12, 6, 183, 15));
        jLabel15.setFont(new java.awt.Font("Arial", Font.PLAIN, 11));
        jLabel15.setText("Vencimiento:");
        jLabel15.setBounds(new Rectangle(7, 90, 69, 15));
        jLabelVencimiento.setFont(new java.awt.Font("Arial", Font.PLAIN, 11));
        jLabelVencimiento.setText("...");
        jLabelVencimiento.setBounds(new Rectangle(70, 89, 276, 15));
        jLabelRecargo.setFont(new java.awt.Font("Arial", Font.PLAIN, 11));
        jLabelRecargo.setText("...");
        jLabelRecargo.setBounds(new Rectangle(199, 6, 38, 15));
        jButtonImprimir.setBounds(new Rectangle(246, 379, 151, 23));
        jButtonImprimir.setFont(new java.awt.Font("Arial", Font.PLAIN, 11));
        jButtonImprimir.setText("Guardar e Imprimir");
        jButtonImprimir.addActionListener(new
                                          FacturaFrame_jButtonImprimir_actionAdapter(this));
        this.setDefaultCloseOperation(WindowConstants.HIDE_ON_CLOSE);
        this.addComponentListener(new FacturaFrame_this_componentAdapter(this));
        jLabel8.setFont(new java.awt.Font("Arial", Font.PLAIN, 11));
        jLabel8.setText("Recargo por forma de pago :");
        jLabel8.setBounds(new Rectangle(12, 30, 143, 18));
        jLabelRecargoFormaPago.setFont(new java.awt.Font("Arial", Font.PLAIN,
                11));
        jLabelRecargoFormaPago.setText("...");
        jLabelRecargoFormaPago.setBounds(new Rectangle(154, 31, 42, 17));
        jComboBoxRecargoFormaDePago.setBounds(new Rectangle(196, 30, 158, 18));
        jComboBoxRecargoFormaDePago.addActionListener(new
                FacturaFrame_jComboBoxRecargoFormaDePago_actionAdapter(this));
        jLabel16.setFont(new java.awt.Font("Arial", Font.PLAIN, 11));
        jLabel16.setText("Factura Nro.");
        jLabel16.setBounds(new Rectangle(45, 406, 65, 12));
        jFormattedTextFieldFacturaNumero.setFont(new java.awt.Font("Arial",
                Font.PLAIN, 12));
        jFormattedTextFieldFacturaNumero.setInputVerifier(null);
        jFormattedTextFieldFacturaNumero.setText("0");
        jFormattedTextFieldFacturaNumero.setBounds(new Rectangle(119, 405, 87,
                15));
        jCheckBox1.setFont(new java.awt.Font("Arial", Font.PLAIN, 11));
        jCheckBox1.setToolTipText(
                "Si est� tildado solo aparecen en la lista los descuentos permitidos " +
                "para ese alumno, destildado aparecen absolutamente todos los descuentos ");
        jCheckBox1.setSelected(true);
        jCheckBox1.setText("Restringir descuentos");
        jCheckBox1.setBounds(new Rectangle(11, 54, 163, 23));
        jCheckBox1.addItemListener(new FacturaFrame_jCheckBox1_itemAdapter(this));
        jCheckBoxAplicarRecargo.setFont(new java.awt.Font("Arial", Font.PLAIN,
                11));
        jCheckBoxAplicarRecargo.setSelected(true);
        jCheckBoxAplicarRecargo.setText("Aplicar recargo");
        jCheckBoxAplicarRecargo.setBounds(new Rectangle(238, 2, 129, 23));
        jCheckBoxAplicarRecargo.addChangeListener(new
                                                  FacturaFrame_jCheckBoxAplicarRecargo_changeAdapter(this));
        jPanel1.add(jLabel13);
        jPanel1.add(jLabel12);
        jPanel1.add(jLabel11);
        jPanel1.add(jLabel1);
        jPanel1.add(jLabelAlumno);
        jPanel1.add(jLabel15);
        jPanel1.add(jLabelConcepto);
        jPanel1.add(jLabelCurso);
        jPanel1.add(jLabelVencimiento);
        jPanel1.add(jLabelImporteCuotaBasica);
        this.getContentPane().add(jButtonImprimir);
        this.getContentPane().add(jLabel10);
        this.getContentPane().add(jLabelTotalAPagar);
        this.getContentPane().add(jPanel5);
        jPanel5.add(jLabel14);
        jPanel5.add(jLabelRecargo);
        jPanel5.add(jLabel8);
        jPanel5.add(jComboBoxRecargoFormaDePago);
        jPanel5.add(jLabelRecargoFormaPago);
        jPanel5.add(jCheckBoxAplicarRecargo);
        this.getContentPane().add(jPanel2);
        jPanel4.add(jComboBoxDescuentoSumaFija);
        jPanel4.add(jLabel3);
        jPanel4.add(jLabel9);
        jPanel4.add(jLabelDescuentoSumaFija);
        jPanel4.add(jLabel7);
        jPanel4.add(jLabelConceptoDescuentoSumaFija);
        jPanel4.add(jButtonAplicarDescuentoSumafija);
        jPanel4.add(jButtonAnularDescuentoSumafija);
        jPanel2.add(jPanel3);
        jPanel3.add(jLabel2);
        jPanel3.add(jLabel5);
        jPanel3.add(jLabel4);
        jPanel3.add(jLabel6);
        jPanel3.add(jComboBoxDescuentoPorcentual);
        jPanel3.add(jLabelPorcentaje);
        jPanel3.add(jLabelDscuentoPorcentual);
        jPanel3.add(jLabelConceptoDescuentoPorcentual);
        jPanel3.add(jCheckBox1);
        jPanel3.add(jButtonAplicarDescuentoPorcentual);
        jPanel3.add(jButtonAnularDescuentoPorcentual);
        jPanel2.add(jPanel4);
        this.getContentPane().add(jPanel1);
        this.getContentPane().add(jLabel16);
        this.getContentPane().add(jFormattedTextFieldFacturaNumero);
        jLabelImporteCuotaBasica.setText("...");
        jLabelImporteCuotaBasica.setBounds(new Rectangle(79, 70, 42, 15));
        // JFormattedtextfield
        jFormattedTextFieldFacturaNumero.setColumns(10);
        jFormattedTextFieldFacturaNumero.addPropertyChangeListener("value", this);
    }

    /**
     * jButtonAplicarDescuentoPorcentual_actionPerformed
     *
     * @param e ActionEvent
     */
    public void jButtonAplicarDescuentoPorcentual_actionPerformed(
            ActionEvent e) {

        if (isAvisarFueraPeriodoDedescuentos()) {
            JOptionPane.showMessageDialog(this, "EL pago de esta cuota est� fuera del periodo en el que se pueden aplicar descuentos");
        }

        Object o = jComboBoxDescuentoPorcentual.getSelectedItem();

        if (o != null) {
            this.setLabelDescuentoPorcentual();
            DescuentoPorcentual descuentoPorcentual = (DescuentoPorcentual)
                    o;
            this.jLabelConceptoDescuentoPorcentual.setText(
                    descuentoPorcentual.
                    getNombre());
            this.jLabelPorcentaje.setText(String.valueOf(
                    descuentoPorcentual.getPorcentaje()) + "%");

            DecimalFormat decFormat = new DecimalFormat();
            decFormat.setMaximumFractionDigits(2);
            decFormat.setMinimumFractionDigits(2);

            double descuentoEnPlataPorcentual = getDescuentoPorcentual(
                    descuentoPorcentual.
                    getPorcentaje());

            this.jLabelDscuentoPorcentual.setText("$ " +
                                                  decFormat.format(
                    descuentoEnPlataPorcentual));
            actualizarDescuento(descuentoEnPlataPorcentual); //usa un metodo porque debe ademas hacer la
            // llamada para actualizar el importe total a pagar
        }
    }

    /**
     * jButtonAplicarDescuentoSumafija_actionPerformed
     *
     * @param e ActionEvent
     */
    public void jButtonAplicarDescuentoSumafija_actionPerformed(ActionEvent
            e) {
        if (isAvisarFueraPeriodoDedescuentos()) {
            JOptionPane.showMessageDialog(this, "EL pago de esta cuota est� fuera del periodo en el que se pueden aplicar descuentos");
        }

        Object o = jComboBoxDescuentoSumaFija.getSelectedItem();
        if (o != null) {
            this.setLabelDescuentoSumaFija();
            DescuentoSumaFija descuentoSumaFija = (DescuentoSumaFija) o;
            this.jLabelConceptoDescuentoSumaFija.setText(descuentoSumaFija.
                    getNombre());
            this.jLabelDescuentoSumaFija.setText("$ " + String.valueOf(
                    descuentoSumaFija.getSumaFija()));
            actualizarDescuento(descuentoSumaFija.getSumaFija()); //usa un metodo porque debe ademas hacer la
            // llamada para actualizar el importe total a pagar
        }
    }

    /**
     * clearLabelDescuentoPorcentual
     */
    private void setLabelDescuentoPorcentual() {
        clearDescuentoSumaFija();
        tipoDescuento = this.DESCUENTO_PROCENTUAL;
    }

    /**
     * clearLabelDescuentoSumaFija
     */
    private void setLabelDescuentoSumaFija() {
        clearDescuentoPorcentual();
        tipoDescuento = this.DESCUENTO_SUMAFIJA;
    }

    /**
     * anularDescuentoPorcentual
     */
    private void clearDescuentoPorcentual() {
        this.jLabelConceptoDescuentoPorcentual.setText(CONSTANT_NO);
        this.jLabelPorcentaje.setText(CONSTANT_NO);
        this.jLabelDscuentoPorcentual.setText(CONSTANT_NO);
    }

    /**
     * anularDescuentoSumaFija
     */
    private void clearDescuentoSumaFija() {
        this.jLabelConceptoDescuentoSumaFija.setText(CONSTANT_NO);
        this.jLabelDescuentoSumaFija.setText(CONSTANT_NO);
    }

    /**
     * anularDescuentoPorcentual
     */
    private void anularDescuentoPorcentual() {
        clearDescuentoPorcentual();
        if (this.tipoDescuento == this.DESCUENTO_PROCENTUAL) { // si es del mismo tipo que
            //el activo queda sin ningun tipo de descuentos
            this.tipoDescuento = this.DESCUENTO_NADA;
            actualizarDescuento(0); //usa un metodo porque debe ademas hacer la
            // llamada para actualizar el importe total a pagar
        }
    }

    /**
     * anularDescuentoSumaFija
     */
    private void anularDescuentoSumaFija() {
        clearDescuentoSumaFija();
        if (this.tipoDescuento == this.DESCUENTO_SUMAFIJA) { // si es del mismo tipo que
            //el activo queda sin ningun tipo de descuentos
            this.tipoDescuento = this.DESCUENTO_NADA;
            actualizarDescuento(0); //usa un metodo porque debe ademas hacer la
            // llamada para actualizar el importe total a pagar
        }
    }

    /**
     * setearRecargoFormaDePago
     */
    private void setearRecargoFormaDePago() {

        String strRecargoFormaPago = (String)this.jComboBoxRecargoFormaDePago.
                                     getSelectedItem();
        if (strRecargoFormaPago != null) {
            Vector v = BrokerServer.instance().query(Recargo.class,
                    "concepto==\"" +
                    strRecargoFormaPago +
                    "\"");
            Recargo recargo = (Recargo) v.firstElement();
            this.porcentajeRecargoFormaDePago = recargo.getPorcentaje();

            updateImporteAPagar();
        }
    }

    /**
     * getDescuentoPorcentual
     *
     * @param porcentaje double
     * @return double
     */
    private double getDescuentoPorcentual(double porcentaje) {
        return this.cuotaBasica.getImporte() / 100 * porcentaje;
    }


    /**
     * actualizarDescuento
     *
     * @param descuento double
     */
    private void actualizarDescuento(double descuento) {
        this.descuento = descuento;
        updateImporteAPagar();

    }


    /**
     * updateImporteAPagar
     */
    private void updateImporteAPagar() {

        this.importeAPagar = this.cuotaBasica.getImporte() - this.descuento +
                             this.recargoMoroso;

        double recargoFormaPagoFinal = (this.importeAPagar *
                                        this.porcentajeRecargoFormaDePago) /
                                       100;
        this.importeAPagar = this.importeAPagar + recargoFormaPagoFinal;
        DecimalFormat decFormat = new DecimalFormat();
        decFormat.setMaximumFractionDigits(2);
        decFormat.setMinimumFractionDigits(2);

        this.jLabelRecargoFormaPago.setText(decFormat.format(
                recargoFormaPagoFinal));
        updateLabelImporteAPagar();
    }

    /**
     * updateLabelImporteAPagar
     */
    private void updateLabelImporteAPagar() {
        DecimalFormat decFormat = new DecimalFormat();
        decFormat.setMaximumFractionDigits(2);
        decFormat.setMinimumFractionDigits(2);
        this.jLabelTotalAPagar.setText("$ " +
                                       decFormat.format(this.importeAPagar));
    }

    /**
     * jButtonAnularDescuentoPorcentual_actionPerformed
     *
     * @param e ActionEvent
     */
    public void jButtonAnularDescuentoPorcentual_actionPerformed(
            ActionEvent e) {
        anularDescuentoPorcentual();
    }

    /**
     * jButtonAnularDescuentoSumafija_actionPerformed
     *
     * @param e ActionEvent
     */
    public void jButtonAnularDescuentoSumafija_actionPerformed(ActionEvent
            e) {
        anularDescuentoSumaFija();
    }

    public void jButtonImprimir_actionPerformed(ActionEvent e) {
        Pago pago = new Pago();
        Number num = (Number)this.jFormattedTextFieldFacturaNumero.getValue();
        pago.setNumeroFactura(num.longValue());

        pago.setFechaPago(new Date());
        pago.setImportePagado(this.importeAPagar);
        String conceptodescuento = "";
        String importedescuento = "";

        if (!this.jLabelConceptoDescuentoPorcentual.getText().equals(
                CONSTANT_NO)) {
            pago.setNombreDescuento(this.jLabelConceptoDescuentoPorcentual.
                                    getText());
            conceptodescuento = pago.getNombreDescuento();

            importedescuento = this.jLabelDscuentoPorcentual.getText();
        }
        if (!this.jLabelConceptoDescuentoSumaFija.getText().equals(CONSTANT_NO)) {
            pago.setNombreDescuento(this.jLabelConceptoDescuentoSumaFija.
                                    getText());
            conceptodescuento = pago.getNombreDescuento();
            importedescuento = this.jLabelDescuentoSumaFija.getText();
        }

        ICommand insertarCurso = CommandFactory.createInsertarPago(pago,
                cuotaBasica, alumno);
        try {
            insertarCurso.execute();
        } catch (Exception ex) {
            JOptionPane.showMessageDialog(this, ex.getMessage());

        }

//actualizo el contador de numero de factura
        updateNumeroFactura((Long)this.jFormattedTextFieldFacturaNumero.
                            getValue());

        Date date = new Date();
        SimpleDateFormat dateFormatInicio = new SimpleDateFormat(
                "d-M-yyyy");
        String fecha = dateFormatInicio.format(date);
        String strRecargoFormaPago = (String)this.jComboBoxRecargoFormaDePago.
                                     getSelectedItem();
        if (strRecargoFormaPago == null) {
            strRecargoFormaPago = "";
        }
        String importeCuota = "$" + String.valueOf(cuotaBasica.getImporte());

        String recargopagofueradetermino = this.jLabelRecargo.getText();

        String recargoFormaPago = "$" + this.jLabelRecargoFormaPago.getText();
        String totalapagar = this.jLabelTotalAPagar.getText();

        Factura factura = new Factura(fecha,
                                      alumno.getApellido() + "," +
                                      alumno.getNombre(),
                                      alumno.getDomicilio(),
                                      strRecargoFormaPago,
                                      cuotaBasica.getCurso().getNombre(),
                                      cuotaBasica.getConcepto(), importeCuota,
                                      conceptodescuento, "-" + importedescuento,
                                      recargopagofueradetermino,
                                      recargoFormaPago, totalapagar,alumno.getDni());

        factura.display();
        this.setVisible(false);

    }

    public void jComboBoxRecargoFormaDePago_actionPerformed(ActionEvent e) {
        setearRecargoFormaDePago();
    }


    /** Called when a field's "value" property changes. */
    public void propertyChange(PropertyChangeEvent e) {
        Object source = e.getSource();
        if (source == jFormattedTextFieldFacturaNumero) {
            /*   jFormattedTextFieldFacturaNumero.setValue(new Integer(((Number)
             jFormattedTextFieldFacturaNumero.getValue()).intValue()));
             */
        }

    }

    public void jCheckBox1_itemStateChanged(ItemEvent e) {
        if (jCheckBox1.isSelected()) { //si est� seleccionado significa que debe restringir
            //los descuentos a solo los que esa persona tiene asociados
            this.loadComboDescuentoPorcentual();
        } else {
            loadComboTodosLosDescuentosPorcentual(); //si no carga todos los descuentos
        }
    }

    public void this_componentHidden(ComponentEvent e) {
        mainFrame.pagosFrame.show();
    }

    /**
     * jCheckBoxAplicarRecargo_stateChanged
     *
     * @param e ChangeEvent
     */
    public void jCheckBoxAplicarRecargo_stateChanged(ChangeEvent e) {
        if (this.jCheckBoxAplicarRecargo.isSelected()) {
            DecimalFormat decFormat = new DecimalFormat();
            decFormat.setMaximumFractionDigits(2);
            decFormat.setMinimumFractionDigits(2);

            recargoMoroso = updateRecargo();
            this.jLabelRecargo.setText("$ " + decFormat.format(recargoMoroso));
        } else {
            recargoMoroso = 0;
            this.jLabelRecargo.setText("$ " + recargoMoroso);
        }
        updateImporteAPagar();
    }
}


class FacturaFrame_jCheckBoxAplicarRecargo_changeAdapter implements
        ChangeListener {
    private FacturaFrame adaptee;
    FacturaFrame_jCheckBoxAplicarRecargo_changeAdapter(FacturaFrame adaptee) {
        this.adaptee = adaptee;
    }

    public void stateChanged(ChangeEvent e) {
        adaptee.jCheckBoxAplicarRecargo_stateChanged(e);
    }
}


class FacturaFrame_this_componentAdapter extends ComponentAdapter {
    private FacturaFrame adaptee;
    FacturaFrame_this_componentAdapter(FacturaFrame adaptee) {
        this.adaptee = adaptee;
    }

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


class FacturaFrame_jCheckBox1_itemAdapter implements ItemListener {
    private FacturaFrame adaptee;
    FacturaFrame_jCheckBox1_itemAdapter(FacturaFrame adaptee) {
        this.adaptee = adaptee;
    }

    public void itemStateChanged(ItemEvent e) {
        adaptee.jCheckBox1_itemStateChanged(e);
    }
}


class FacturaFrame_jComboBoxRecargoFormaDePago_actionAdapter implements
        ActionListener {
    private FacturaFrame adaptee;
    FacturaFrame_jComboBoxRecargoFormaDePago_actionAdapter(FacturaFrame adaptee) {
        this.adaptee = adaptee;
    }

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


class FacturaFrame_jButtonImprimir_actionAdapter implements ActionListener {
    private FacturaFrame adaptee;
    FacturaFrame_jButtonImprimir_actionAdapter(FacturaFrame adaptee) {
        this.adaptee = adaptee;
    }

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


class FacturaFrame_jButtonAnularDescuentoSumafija_actionAdapter implements
        ActionListener {
    private FacturaFrame adaptee;
    FacturaFrame_jButtonAnularDescuentoSumafija_actionAdapter(FacturaFrame
            adaptee) {
        this.adaptee = adaptee;
    }

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


class FacturaFrame_jButtonAnularDescuentoPorcentual_actionAdapter implements
        ActionListener {
    private FacturaFrame adaptee;
    FacturaFrame_jButtonAnularDescuentoPorcentual_actionAdapter(
            FacturaFrame
            adaptee) {
        this.adaptee = adaptee;
    }

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


class FacturaFrame_jButtonAplicarDescuentoSumafija_actionAdapter implements
        ActionListener {
    private FacturaFrame adaptee;
    FacturaFrame_jButtonAplicarDescuentoSumafija_actionAdapter(FacturaFrame
            adaptee) {
        this.adaptee = adaptee;
    }

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


class FacturaFrame_jButtonAplicarDescuentoPorcentual_actionAdapter implements
        ActionListener {
    private FacturaFrame adaptee;
    FacturaFrame_jButtonAplicarDescuentoPorcentual_actionAdapter(
            FacturaFrame
            adaptee) {
        this.adaptee = adaptee;
    }

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

Related Classes of org.salamanca.ui.FacturaFrame_jButtonAplicarDescuentoPorcentual_actionAdapter

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.