package org.salamanca.ui;
import java.awt.BorderLayout;
import javax.swing.JInternalFrame;
import javax.swing.JPanel;
import javax.swing.JLabel;
import java.awt.Font;
import javax.swing.JTextField;
import javax.swing.BorderFactory;
import javax.swing.JButton;
import componenteTabla.compomenteABMCList;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.WindowConstants;
import javax.swing.JOptionPane;
import org.salamanca.domain.ConfiguracionGeneral;
import org.salamanca.commands.recargo.SetRecargo;
import org.salamanca.commands.*;
import org.salamanca.broker.*;
import javax.jdo.Extent;
import java.util.Iterator;
import java.awt.event.ComponentEvent;
import java.awt.event.ComponentAdapter;
import java.awt.Dimension;
import componenteTabla.InsertarEvent;
import componenteTabla.InsertarListener;
import java.util.Date;
import org.salamanca.domain.Curso;
import java.text.ParseException;
import java.util.Vector;
import java.text.SimpleDateFormat;
import org.salamanca.commands.curso.InsertarCurso;
import org.salamanca.domain.Descuento;
import org.salamanca.domain.DescuentoSumaFija;
import org.salamanca.commands.descuento.InsertarDescuentoSumaFija;
import org.salamanca.domain.DescuentoPorcentual;
import org.salamanca.commands.descuento.InsertarDescuentoPorcentual;
import org.salamanca.domain.CuotaBasica;
import java.util.*;
import componenteTabla.EliminarEvent;
import componenteTabla.EliminarListener;
import org.salamanca.commands.cuota.EliminarCuota;
import org.jdoinstruments.runtime.discfilemodel.util.DirectOID;
import org.salamanca.commands.descuento.EliminarDescuentoSumaFija;
import org.salamanca.commands.descuento.EliminarDescuentoPorcentual;
import java.awt.Rectangle;
/**
* <p>Title: </p>
*
* <p>Description: </p>
*
* <p>Copyright: Copyright (c) 2006</p>
*
* <p>Company: </p>
*
* @author not attributable
* @version 1.0
*/
public class ConfiguracionGeneralFrame extends JInternalFrame {
BorderLayout borderLayout1 = new BorderLayout();
JPanel jPanel1 = new JPanel();
JPanel jPanel2 = new JPanel();
BorderLayout borderLayout2 = new BorderLayout();
BorderLayout borderLayout3 = new BorderLayout();
JPanel jPanel3 = new JPanel();
JPanel jPanel4 = new JPanel();
JPanel jPanel5 = new JPanel();
JPanel jPanel6 = new JPanel();
JLabel jLabel1 = new JLabel();
JLabel jLabel2 = new JLabel();
JButton jButton1 = new JButton();
JPanel jPanel7 = new JPanel();
BorderLayout borderLayout4 = new BorderLayout();
JPanel jPanel8 = new JPanel();
JLabel jLabel3 = new JLabel();
JLabel jLabel4 = new JLabel();
compomenteABMCList compomenteABMCListDescuentos = new
compomenteABMCList();
BorderLayout borderLayout5 = new BorderLayout();
JPanel jPanel9 = new JPanel();
JTextField jTextFieldRecargoCuotaBasica = new JTextField();
JTextField jTextFieldRecargoPagoExtra = new JTextField();
JLabel jLabel5 = new JLabel();
JTextField jTextFieldDiasDeshabilitaDescuento = new JTextField();
public ConfiguracionGeneralFrame() {
try {
jbInit();
} catch (Exception exception) {
exception.printStackTrace();
}
}
private void jbInit() throws Exception {
getContentPane().setLayout(borderLayout1);
jPanel1.setBorder(BorderFactory.createEtchedBorder());
jPanel4.setBorder(BorderFactory.createEtchedBorder());
jPanel4.setPreferredSize(new Dimension(479, 135));
jPanel4.setLayout(borderLayout4);
jLabel2.setFont(new java.awt.Font("Arial", Font.PLAIN, 11));
jLabel2.setToolTipText("Ej:0.1(es decir 0.1% sobre la cuota base)");
jLabel2.setText("Porcentaje recargo por dia Cuota Basica = ");
jLabel2.setBounds(new Rectangle(71, 33, 207, 14));
jButton1.setFont(new java.awt.Font("Arial", Font.PLAIN, 9));
jButton1.setText("Actualizar");
jButton1.addActionListener(new
ConfiguracionGeneralFrame_jButton1_actionAdapter(this));
jLabel3.setFont(new java.awt.Font("Arial", Font.PLAIN, 11));
jLabel3.setToolTipText("");
jLabel3.setText("Porcentaje recargo por dia Pagos Extra = ");
jLabel3.setBounds(new Rectangle(74, 8, 201, 14));
jPanel2.setBorder(BorderFactory.createEtchedBorder());
jLabel4.setFont(new java.awt.Font("Arial", Font.BOLD, 13));
jLabel4.setText("Descuentos");
jPanel6.setBorder(BorderFactory.createEtchedBorder());
jPanel6.setLayout(borderLayout5);
jTextFieldRecargoPagoExtra.setMinimumSize(new Dimension(61, 20));
jTextFieldRecargoPagoExtra.setPreferredSize(new Dimension(47, 20));
jTextFieldRecargoPagoExtra.setText("0");
jTextFieldRecargoPagoExtra.setBounds(new Rectangle(280, 5, 47, 20));
jTextFieldRecargoPagoExtra.addActionListener(new
ConfiguracionGeneralFrame_jTextFieldRecargoPagoExtra_actionAdapter(this));
jTextFieldRecargoCuotaBasica.setMinimumSize(new Dimension(61, 20));
jTextFieldRecargoCuotaBasica.setPreferredSize(new Dimension(47, 20));
jTextFieldRecargoCuotaBasica.setText("0");
jTextFieldRecargoCuotaBasica.setBounds(new Rectangle(283, 30, 47, 20));
jTextFieldRecargoCuotaBasica.addActionListener(new
ConfiguracionGeneralFrame_jTextFieldRecargoCuotaBasica_actionAdapter(this));
this.setDefaultCloseOperation(WindowConstants.HIDE_ON_CLOSE);
this.addComponentListener(new
ConfiguracionGeneralFrame_this_componentAdapter(this));
compomenteABMCListDescuentos.addInsertarListener(new
ConfiguracionGeneralFrame_compomenteABMCListDescuentos_insertarAdapter(this));
compomenteABMCListDescuentos.addEliminarListener(new
ConfiguracionGeneralFrame_compomenteABMCListDescuentos_eliminarAdapter(this));
jLabel5.setFont(new java.awt.Font("Arial", Font.PLAIN, 11));
jLabel5.setText(
"Periodo (dias luego del vencimiento) para deshabilitar descuentos");
jTextFieldDiasDeshabilitaDescuento.setFont(new java.awt.Font("Arial",
Font.PLAIN, 11));
jTextFieldDiasDeshabilitaDescuento.setMinimumSize(new Dimension(41, 20));
jTextFieldDiasDeshabilitaDescuento.setPreferredSize(new Dimension(41,
20));
jTextFieldDiasDeshabilitaDescuento.setText("0");
jPanel8.setLayout(null);
this.getContentPane().add(jPanel2, java.awt.BorderLayout.CENTER);
jPanel2.setLayout(borderLayout3);
jPanel1.setLayout(borderLayout2);
this.getContentPane().add(jPanel1, java.awt.BorderLayout.NORTH);
jLabel1.setFont(new java.awt.Font("Arial", Font.PLAIN, 18));
jLabel1.setText("Configuracion de recargos y descuentos");
jPanel1.add(jPanel4, java.awt.BorderLayout.CENTER);
jPanel1.add(jPanel3, java.awt.BorderLayout.NORTH);
jPanel3.add(jLabel1);
jPanel2.add(jPanel6, java.awt.BorderLayout.CENTER);
jPanel2.add(jPanel5, java.awt.BorderLayout.NORTH);
jPanel5.add(jLabel4);
jPanel4.add(jPanel8, java.awt.BorderLayout.CENTER);
jPanel8.add(jLabel3);
jPanel8.add(jTextFieldRecargoPagoExtra);
jPanel8.add(jLabel2);
jPanel8.add(jTextFieldRecargoCuotaBasica);
jPanel6.add(compomenteABMCListDescuentos, java.awt.BorderLayout.CENTER);
jPanel4.add(jPanel7, java.awt.BorderLayout.NORTH);
jPanel7.add(jLabel5);
jPanel7.add(jTextFieldDiasDeshabilitaDescuento);
jPanel4.add(jPanel9, java.awt.BorderLayout.SOUTH);
jPanel9.add(jButton1);
compomenteABMCListDescuentos.setVisibleCantidadRegistros(true);
compomenteABMCListDescuentos.setVisibleBuscar(true);
compomenteABMCListDescuentos.setInfoColumna(new String[][] { {"nombre",
"tipo", "editable", "editor",
"val.Combo", "Ancho Columna"}
, {"Nombre", "String", "true",
"comun", "", "120"}
, {"Suma fija", "Double",
"true", "comun", "", "130"}
, {"Porcentaje",
"Double", "true", "comun", "2",
"110"}, {"oid", "String",
"false", "comun", "", "1"}
});
compomenteABMCListDescuentos.setVisibleAgregar(true);
compomenteABMCListDescuentos.setVisibleOrdenar(false);
compomenteABMCListDescuentos.setVisibleModificar(false);
compomenteABMCListDescuentos.setVisibleImprimir(true);
compomenteABMCListDescuentos.setVisibleGuardarComo(false);
compomenteABMCListDescuentos.setVisibleHeaderTabla(true);
compomenteABMCListDescuentos.setVisibleFiltrar(false);
compomenteABMCListDescuentos.setVisibleEliminar(true);
compomenteABMCListDescuentos.setVisibleCopyclipboard(true);
compomenteABMCListDescuentos.setVisibleReportes(true);
compomenteABMCListDescuentos.setTituloImprimir("Descuentos");
}
public void jTextFieldRecargoPagoExtra_actionPerformed(ActionEvent e) {
}
/**
* loadRecargos
*/
private void loadRecargos() {
double recargoCuotaBasica = 0;
double recargoPagoExtra = 0;
int diasDeshabilitaDescuento=0;
Extent ext = BrokerServer.instance().getPMF().getPersistenceManager().
getExtent(ConfiguracionGeneral.class, true);
Iterator iter = ext.iterator();
if (iter.hasNext()) {
ConfiguracionGeneral conf = (ConfiguracionGeneral) iter.next();
recargoCuotaBasica = conf.getPorcentajeRecargoPorDiaCuotas();
recargoPagoExtra = conf.getPorcentajeRecargoPorDiaPagosExtra();
diasDeshabilitaDescuento=conf.getDiasLuegoVencimientoAnulaDescuento();
}
this.jTextFieldRecargoCuotaBasica.setText(String.valueOf(
recargoCuotaBasica));
this.jTextFieldRecargoPagoExtra.setText(String.valueOf(recargoPagoExtra));
this.jTextFieldDiasDeshabilitaDescuento.setText(String.valueOf(diasDeshabilitaDescuento));
}
/**
* jButton1_actionPerformed
*
* @param e ActionEvent
*/
public void jButton1_actionPerformed(ActionEvent e) {
double recargoCuotaBasica = 0;
double recargoPagoExtra = 0;
int diasDeshabilitaDescuento = 0;
try {
recargoCuotaBasica = Double.parseDouble(this.
jTextFieldRecargoCuotaBasica.getText());
recargoPagoExtra = Double.parseDouble(this.
jTextFieldRecargoPagoExtra.
getText());
diasDeshabilitaDescuento = Integer.parseInt(this.
jTextFieldDiasDeshabilitaDescuento.
getText());
} catch (Exception ex) {
JOptionPane.showMessageDialog(this,
"Solo se permiten valores numericos ");
loadRecargos();
return;
}
ICommand setRecargo = CommandFactory.createSetRecargo(
recargoCuotaBasica,
recargoPagoExtra, diasDeshabilitaDescuento);
try {
setRecargo.execute();
} catch (Exception ex1) {
JOptionPane.showMessageDialog(this, ex1.getMessage());
loadRecargos();
}
loadRecargos();
}
public void jTextFieldRecargoCuotaBasica_actionPerformed(ActionEvent e) {
}
public void this_componentShown(ComponentEvent e) {
loadRecargos();
loadDescuentos();
}
private void loadDescuentos() {
try {
compomenteABMCListDescuentos.clearDatos();
Extent ext = BrokerServer.instance().getPMF().
getPersistenceManager().getExtent(Descuento.class, true);
Vector v = new Vector();
Iterator iter = ext.iterator();
while (iter.hasNext()) {
Descuento descuento = (Descuento) iter.next();
v.add(descuento);
}
//cargo todos los descuentos
if ((v != null) && (v.size() > 0)) {
Object[][] trabajo = new Object[v.size()][5];
for (int i = 0; i < v.size(); i++) {
Descuento descuento = (Descuento) v.elementAt(i);
trabajo[i][0] = descuento.getNombre();
trabajo[i][1] = new Double(0);
trabajo[i][2] = new Double(0);
if (descuento instanceof DescuentoSumaFija) {
trabajo[i][1] = new Double(((DescuentoSumaFija)
descuento).getSumaFija());
}
if (descuento instanceof DescuentoPorcentual) {
trabajo[i][2] = new Double(((DescuentoPorcentual)
descuento).getPorcentaje());
}
trabajo[i][3] = javax.jdo.JDOHelper.
getObjectId(descuento).toString();
}
compomenteABMCListDescuentos.setDatos(trabajo);
compomenteABMCListDescuentos.setVisibleModificar(false);
}
}
catch (Exception ex) {
ex.printStackTrace();
}
}
/**
* compomenteABMCListDescuentos_Insercion
*
* @param e InsertarEvent
*/
public void compomenteABMCListDescuentos_Insercion(InsertarEvent e) {
String nombre = (String) ((Vector) e.getVector()).elementAt(0);
double sumafija = ((Double) ((Vector) e.getVector()).elementAt(1)).
doubleValue();
double porcentaje = ((Double) ((Vector) e.getVector()).elementAt(2)).
doubleValue();
if (sumafija == 0 && porcentaje == 0) {
JOptionPane.showMessageDialog(this,
"Debe establecer algun valor diferente de cero");
loadDescuentos();
return;
}
if (sumafija != 0 && porcentaje != 0) {
JOptionPane.showMessageDialog(this,
"Debe establecer solo uno de los dos descuento (porcentaje o suma fija)");
loadDescuentos();
return;
}
//si lleg� hasta ac� es que seleccion� solo una opcion
//-------------- SUMA FIJA
if (sumafija != 0) {
DescuentoSumaFija descuentoSumaFija = new DescuentoSumaFija();
descuentoSumaFija.setNombre(nombre);
descuentoSumaFija.setSumaFija(sumafija);
ICommand insertarDescuentoSumaFija = CommandFactory.
createInsertarDescuentoSumaFija(
descuentoSumaFija);
try {
insertarDescuentoSumaFija.execute();
} catch (Exception ex) {
JOptionPane.showMessageDialog(this, ex.getMessage());
loadDescuentos();
return;
}
}
//-------------- PORCENTUAL
if (porcentaje != 0) {
DescuentoPorcentual descuentoPorcentual = new DescuentoPorcentual();
descuentoPorcentual.setNombre(nombre);
descuentoPorcentual.setPorcentaje(porcentaje);
ICommand insertarDescuentoPorcentual = CommandFactory.
createInsertarDescuentoPorcentual(descuentoPorcentual);
try {
insertarDescuentoPorcentual.execute();
} catch (Exception ex) {
JOptionPane.showMessageDialog(this, ex.getMessage());
loadDescuentos();
return;
}
}
loadDescuentos();
}
public void compomenteABMCListDescuentos_Eliminacion(EliminarEvent e) {
String oidStr = ((String) ((Vector) e.getVector()).elementAt(3));
kodo.util.Id oid = new kodo.util.Id(oidStr);
Descuento descuento = (Descuento) BrokerServer.instance().getPMF().
getPersistenceManager().getObjectById(oid, true);
if (descuento instanceof DescuentoSumaFija) {
ICommand eliminarDescuentoSumaFija = CommandFactory.
createEliminarDescuentoSumaFija((
DescuentoSumaFija)
descuento);
try {
eliminarDescuentoSumaFija.execute();
} catch (Exception ex) {
JOptionPane.showMessageDialog(this, ex.getMessage());
}
}
if (descuento instanceof DescuentoPorcentual) {
ICommand eliminarDescuentoPorcentual = CommandFactory.
createEliminarDescuentoPorcentual((DescuentoPorcentual)
descuento);
try {
eliminarDescuentoPorcentual.execute();
} catch (Exception ex) {
JOptionPane.showMessageDialog(this, ex.getMessage());
}
}
this.loadDescuentos();
}
}
class ConfiguracionGeneralFrame_compomenteABMCListDescuentos_insertarAdapter implements
InsertarListener {
private ConfiguracionGeneralFrame adaptee;
ConfiguracionGeneralFrame_compomenteABMCListDescuentos_insertarAdapter(
ConfiguracionGeneralFrame adaptee) {
this.adaptee = adaptee;
}
public void Insercion(InsertarEvent e) {
adaptee.compomenteABMCListDescuentos_Insercion(e);
}
}
class ConfiguracionGeneralFrame_this_componentAdapter extends ComponentAdapter {
private ConfiguracionGeneralFrame adaptee;
ConfiguracionGeneralFrame_this_componentAdapter(ConfiguracionGeneralFrame
adaptee) {
this.adaptee = adaptee;
}
public void componentShown(ComponentEvent e) {
adaptee.this_componentShown(e);
}
}
class ConfiguracionGeneralFrame_compomenteABMCListDescuentos_eliminarAdapter implements
EliminarListener {
private ConfiguracionGeneralFrame adaptee;
ConfiguracionGeneralFrame_compomenteABMCListDescuentos_eliminarAdapter(
ConfiguracionGeneralFrame adaptee) {
this.adaptee = adaptee;
}
public void Eliminacion(EliminarEvent e) {
adaptee.compomenteABMCListDescuentos_Eliminacion(e);
}
}
class ConfiguracionGeneralFrame_jTextFieldRecargoCuotaBasica_actionAdapter implements
ActionListener {
private ConfiguracionGeneralFrame adaptee;
ConfiguracionGeneralFrame_jTextFieldRecargoCuotaBasica_actionAdapter(
ConfiguracionGeneralFrame adaptee) {
this.adaptee = adaptee;
}
public void actionPerformed(ActionEvent e) {
adaptee.jTextFieldRecargoCuotaBasica_actionPerformed(e);
}
}
class ConfiguracionGeneralFrame_jButton1_actionAdapter implements
ActionListener {
private ConfiguracionGeneralFrame adaptee;
ConfiguracionGeneralFrame_jButton1_actionAdapter(ConfiguracionGeneralFrame
adaptee) {
this.adaptee = adaptee;
}
public void actionPerformed(ActionEvent e) {
adaptee.jButton1_actionPerformed(e);
}
}
class ConfiguracionGeneralFrame_jTextFieldRecargoPagoExtra_actionAdapter implements
ActionListener {
private ConfiguracionGeneralFrame adaptee;
ConfiguracionGeneralFrame_jTextFieldRecargoPagoExtra_actionAdapter(
ConfiguracionGeneralFrame adaptee) {
this.adaptee = adaptee;
}
public void actionPerformed(ActionEvent e) {
adaptee.jTextFieldRecargoPagoExtra_actionPerformed(e);
}
}