// Factura // package Logica; import import import import java.sql.*; java.util.ArrayList; java.sql.CallableStatement; oracle.jdbc.*; public class Factura{ Connection con; Conexion conex = new Conexion(); CallableStatement cstm=null; public int idfactura; public int idEmpleado; public int idCliente; public String hora; public String fecha; public float subtotal; public float impuesto; public float total; public Factura(int idfactura,int idEmpleado,int idCliente, String hora, String fecha, float subtotal, float impuesto, float total) { this.idfactura = idfactura; this.idEmpleado = idEmpleado; this.idCliente = idCliente; this.hora = hora; this.fecha = fecha; this.subtotal = subtotal; this.impuesto = impuesto; this.total = total; } public Factura(int id){ this.idfactura =id; this.idEmpleado =0; this.idCliente = 0; this.hora = ""; this.fecha = ""; this.subtotal = 0; this.impuesto = 0; this.total = 0; } public Factura getFactura(String id) throws Exception{ conex.Conectarse(); con=conex.getConexion(); cstm = con.prepareCall("{call Factura_Paquete.Factura_consultarXid(?,?)}"); cstm.setInt(1,Integer.parseInt(id)); cstm.registerOutParameter(2,OracleTypes.CURSOR); cstm.execute(); ResultSet rs = ((OracleCallableStatement)cstm).getCursor(2); Factura fact=null; if(rs.next()){ fact = new Factura(rs.getInt(1),rs.getInt(2),rs.getInt(3),rs.getString(4),rs.getStri ng(5),rs.getFloat(6), rs.getFloat(7),rs.getFloat(8)); } cstm.close(); con.close(); return fact; } public void setIdCliente(int idCliente) { this.idCliente = idCliente; } public void setIdEmpleado(int idEmpleado) { this.idEmpleado = idEmpleado; } public int getIdCliente() { return idCliente; } public int getIdEmpleado() { return idEmpleado; } public void settotal(float total) { this.total = total; } public void setimpuesto(float impuesto) { this.impuesto = impuesto; } public void setFecha(String fecha) { this.fecha = fecha; } public void setHora(String hora) { this.hora = hora; } public void setIdFactura(int idfactura) { this.idfactura = idfactura; } public void setsubtotal(float subtotal) { this.subtotal = subtotal; } public float gettotal() { return total; } public float getimpuesto() { return impuesto; } public String getFecha() { return fecha; } public String getHora() { return hora; } public int getIdFactura() { return idfactura; } public float getsubtotal() { return subtotal; } public void insertar() throws Exception{ conex.Conectarse(); con=conex.getConexion(); cstm=con.prepareCall("{call Factura_Paquete.factura_insertar(?,?,?,?,?,?,?)}"); cstm.setInt(1,this.getIdEmpleado()); cstm.setInt(2,this.getIdCliente()); cstm.setString(3,this.getHora()); cstm.setString(4,this.getFecha()); cstm.setFloat(5,this.getsubtotal()); cstm.setFloat(6,this.getimpuesto()); cstm.setFloat(7,this.gettotal()); cstm.execute(); cstm.close(); con.close(); } public void actualizar() throws Exception{ conex.Conectarse(); con=conex.getConexion(); CallableStatement cstm3 = con.prepareCall("{call Factura_Paquete.factura_modificar(?,?,?,?,?,?,?,?)}"); cstm3.setInt(1,this.getIdFactura()); cstm3.setInt(2,this.getIdEmpleado()); cstm3.setInt(3,this.getIdCliente()); cstm3.setString(4,this.getHora()); cstm3.setString(5,this.getFecha()); cstm3.setFloat(6,this.getsubtotal()); cstm3.setFloat(7,this.getimpuesto()); cstm3.setFloat(8,this.gettotal()); cstm3.execute(); cstm3.close(); con.close(); } public ArrayList consultar() throws Exception{ ArrayList list=new ArrayList(); conex.Conectarse(); con=conex.getConexion(); Factura fact=new Factura(0); ResultSet rs=null; if(this.getIdFactura()>0){ cstm = con.prepareCall("{call Factura_Paquete.Factura_consultarXid(?,?)}"); cstm.setInt(1,this.getIdFactura()); cstm.registerOutParameter(2,OracleTypes.CURSOR); cstm.execute(); rs = ((OracleCallableStatement)cstm).getCursor(2); }else if(this.getIdCliente()>0){ cstm = con.prepareCall("{call Factura_Paquete.Factura_consultarXidCli(?,?)}"); cstm.setInt(1,this.getIdCliente()); cstm.registerOutParameter(2,OracleTypes.CURSOR); cstm.execute(); rs = ((OracleCallableStatement)cstm).getCursor(2); }else if(this.getIdEmpleado()>0){ cstm = con.prepareCall("{call Factura_Paquete.Factura_consultarXidEmp(?,?)}"); cstm.setInt(1,this.getIdEmpleado()); cstm.registerOutParameter(2,OracleTypes.CURSOR); cstm.execute(); rs = ((OracleCallableStatement)cstm).getCursor(2); } while(rs.next()){ fact = new Factura(rs.getInt(1),rs.getInt(2),rs.getInt(3),rs.getString(4),rs.getStri ng(5),rs.getFloat(6), rs.getFloat(7),rs.getFloat(8)); list.add(fact); } con.close(); return list; } public void eliminar() throws Exception{ conex.Conectarse(); con=conex.getConexion(); cstm = con.prepareCall("{call Factura_Paquete.factura_eliminar(?)}"); cstm.setInt(1,this.getIdFactura()); cstm.execute(); cstm.close(); con.close(); } public int getIdmax() throws Exception{ conex.Conectarse(); con=conex.getConexion(); int id=0; cstm = con.prepareCall("{call Factura_Paquete.factura_idMax(?)}"); cstm.registerOutParameter(1,OracleTypes.CURSOR); cstm.execute(); ResultSet rs = ((OracleCallableStatement)cstm).getCursor(1); while(rs.next()){ id = rs.getInt(1); } cstm.close(); con.close(); return id; } }