public ArrayList<ListaAlquiler> get_alquiler_byclientefecha(String condicion) { Connection cnn = null; CallableStatement cstmt = null; ArrayList<ListaAlquiler> listAlquiler = new ArrayList<ListaAlquiler>(); try { cnn = BD.getConnection(); String sql = "select * from get_alquiler_byclientefecha where " + condicion; cstmt = cnn.prepareCall(sql); ResultSet rs = cstmt.executeQuery(); while (rs.next()) { ListaAlquiler a = new ListaAlquiler(); a.setIdCliente(rs.getInt("int_id")); a.setVar_nombre_cliente(rs.getString("var_nombre_cliente")); a.setVar_apepaterno(rs.getString("var_apepaterno")); a.setVar_apematerno(rs.getString("var_apematerno")); a.setVar_nombre_material(rs.getString("var_nombre_material")); a.setDat_fechinicio(rs.getTimestamp("dat_fechinicio")); a.setDat_fechfin(rs.getTimestamp("dat_fechfin")); a.setInt_cantidad(rs.getInt("int_cantidad")); a.setDec_monto(rs.getDouble("dec_monto")); a.setDat_fechaRegistro(rs.getTimestamp("dat_fechaRegistro")); a.setVar_numero(rs.getString("var_numero")); listAlquiler.add(a); } cstmt.close(); cnn.close(); } catch (SQLException a) { System.out.println("" + a); } return listAlquiler; }
public boolean insertarAlquiler( int idtrabajador, int idCliente, ArrayList<Detalle_Alquiler> lista_detalle, int identificador) { boolean resultado = false; Connection cnn = null; CallableStatement cstmt = null; CallableStatement cstm1 = null; CallableStatement cstm2 = null; int id_alquiler = 0; try { cnn = BD.getConnection(); cnn.setAutoCommit(false); String sql = "call spI_Alquiler (?,?,?,?);"; cstmt = cnn.prepareCall(sql); cstmt.setInt(1, 2); cstmt.setInt(2, idCliente); cstmt.setInt(3, idtrabajador); cstmt.setInt(4, identificador); ResultSet rs = cstmt.executeQuery(); if (rs.next()) { id_alquiler = rs.getInt("int_id"); } for (int i = 0; i < lista_detalle.size(); i++) { String sql1 = "call spI_DetalleAlquiler(?,?,?,?,?,?,?);"; cstm1 = cnn.prepareCall(sql1); cstm1.setInt(1, id_alquiler); cstm1.setInt(2, lista_detalle.get(i).getMaterial_id()); cstm1.setInt(3, lista_detalle.get(i).getInt_cantidad()); cstm1.setDouble(4, lista_detalle.get(i).getDec_monto()); cstm1.setTimestamp(5, lista_detalle.get(i).getDat_fechfin()); cstm1.setTimestamp(6, lista_detalle.get(i).getDat_fechinicio()); cstm1.setInt(7, lista_detalle.get(i).getInt_horas()); cstm1.execute(); } // Registrar Pagos String sql2 = "call spI_Pagos_ByAlquiler(?,?);"; cstm2 = cnn.prepareCall(sql2); cstm2.setInt(1, 1); // es el codigo del usuario cambiar despues cstm2.setInt(2, id_alquiler); cstm2.execute(); cnn.commit(); resultado = true; } catch (SQLException s) { try { cnn.rollback(); } catch (SQLException b) { } System.out.println("aquí es :/ " + s); } finally { try { cstmt.close(); cnn.close(); } catch (SQLException ex) { } } return resultado; }
public String cantproducto(int codigo) { String total = ""; try { Connection con = BD.getConnection(); Statement stmt = con.createStatement(); ResultSet rs = stmt.executeQuery( "select SUM(nTraCantidad) total from transaccion where nVenCodigo=" + codigo); while (rs.next()) { total = rs.getString("total"); } rs.close(); stmt.close(); con.close(); } catch (SQLException error) { System.out.println(); } return total; }
public ArrayList<ListaMovimiento> get_reporte_movimiento(String condicion) { Connection cnn = null; CallableStatement cstmt = null; ArrayList<ListaMovimiento> lista_material = new ArrayList<ListaMovimiento>(); try { cnn = BD.getConnection(); String sql = "select * from get_reporte_movimiento " + condicion; cstmt = cnn.prepareCall(sql); ResultSet rs = cstmt.executeQuery(); int cont = 0; double ingreso = 0.0, egreso = 0.0, total = 0.0; while (rs.next()) { ListaMovimiento lm = new ListaMovimiento(); ingreso = rs.getDouble("dec_ingreso"); egreso = rs.getDouble("dec_egreso"); lm.setDat_fecregistro(rs.getDate("dat_fecregistro")); lm.setTipoComprobante(rs.getString("TipoComprobante")); lm.setInt_tipoOperacion(rs.getInt("int_tipoOperacion")); lm.setVar_numeroComprobante(rs.getString("var_numeroComprobante")); lm.setInt_proveedor(rs.getInt("int_proveedor")); lm.setDec_cantidad(rs.getDouble("dec_cantidad")); lm.setVar_concepto(rs.getString("var_concepto")); lm.setUsuario_id(rs.getInt("usuario_id")); lm.setTipo(rs.getInt("tipo")); lm.setDec_ingreso(new BigDecimal(String.valueOf(ingreso))); lm.setDec_egreso(new BigDecimal(String.valueOf(egreso))); if (cont == 0) { total = ingreso + egreso; } else { total = ingreso == 0.0 ? (egreso + total) : (ingreso + total); } lm.setDec_saldo(new BigDecimal(String.valueOf(total))); lista_material.add(lm); cont++; } cstmt.close(); cnn.close(); } catch (SQLException a) { System.out.println("" + a); } return lista_material; }
public double obtenerMonto() { double monto = 0.0; try { Connection con = BD.getConnection(); Statement stmt = con.createStatement(); ResultSet rs = stmt.executeQuery( "select SUM(nCPagoRecibido) MontoEsperado from cronogramapago where nVenCodigo=" + getCodigoVenta()); while (rs.next()) { monto = rs.getDouble(1); } rs.close(); stmt.close(); con.close(); } catch (SQLException error) { System.out.println(error); } return monto; }
public boolean insertarMovimiento(Movimiento m) { boolean resultado = true; Connection cnn = null; CallableStatement cstmt = null; try { cnn = BD.getConnection(); cnn.setAutoCommit(false); String sql = "call spI_Movimiento(?,?,?,?,?,?,?,?,?);"; cstmt = cnn.prepareCall(sql); cstmt.setInt(1, m.getUsuario_id()); cstmt.setString(2, m.getVar_concepto()); cstmt.setDouble(3, m.getDec_monto()); cstmt.setInt(4, m.getInt_tipoOperacion()); cstmt.setTimestamp(5, m.getDat_fecregistro()); cstmt.setInt(6, m.getInt_tipoComprobante()); cstmt.setString(7, m.getVar_numeroComprobante()); cstmt.setDouble(8, m.getDec_cantidad()); cstmt.setInt(9, m.getInt_proveedor()); cstmt.execute(); cnn.commit(); } catch (SQLException a) { try { cnn.rollback(); } catch (SQLException b) { System.out.println("" + b.toString()); } finally { resultado = false; } System.out.println("error al registrar movimiento " + a.toString()); } finally { try { cstmt.close(); cnn.close(); } catch (SQLException ex) { System.out.println("" + ex.getMessage()); } } return resultado; }