Grupos.java
Code: Select all
public class Grupos implements Serializable{
private static final long serialVersionUID = 1L;
private Integer id;
private String descripcion;
private Integer plantillaId;
private String estado;
private List<SubGrupos> subGrupos;
//constructor, geters and setters
}
Code: Select all
public class SubGrupos implements Serializable{
private static final long serialVersionUID = 1L;
private Integer id;
private String descripcion;
private Integer grupoId;
private String estado;
private List<Items> items;
//constructor, geters and setters
}
Code: Select all
public class Items implements Serializable{
private static final long serialVersionUID = 1L;
private long numDocPe;
private int lineaPed;
private String codItem;
private Float desRecLin;
private Float porDesGlo;
private Float porRecGlo;
private BigDecimal precio;
private BigDecimal cantPed;
private BigDecimal cantDes;
private String codana2;
private BigDecimal factor;
private String uniMed;
private BigDecimal cantidadMedAlter;
private BigDecimal precioMedAlter;
private String motivoNoDesp;
private String observacion;
private String descripItem;
private BigDecimal vmDescGlo;
private BigDecimal vmRecGlo;
private BigDecimal vmDescRecLin;
private String cbmCodigo;
private BigDecimal cantidadSolicitada;
private String codmotivo;
private String tipoCotiz;
private Long numCotiz;
private Integer lineaCotiz;
private BigDecimal precioFinal;
private BigDecimal totalLineal;
private BigDecimal saldo;
//constructor, getters and setters
}
Code: Select all
public class GruposDao implements Serializable{
public List<Grupos> searchGrupos(Integer plantilla, String codLis, String codBod) throws SQLException{
List<Grupos> ret = new ArrayList<Grupos>();
String sql;
sql = "SELECT * FROM WWW_PLANTILLAS_PEDIDOS_GRUPOS WHERE plantilla_id = ?";
PreparedStatement ps = conn.prepareStatement(sql);
ps.setInt(1, plantilla);
Grupos grupo;
SubGrupos subGrupo;
Items item;
List<SubGrupos> subGrupos;
List<Items> items;
ResultSet rs1 = ps.executeQuery();
while(rs1.next()){
grupo = new Grupos();
grupo.setId(rs1.getInt("id"));
grupo.setDescripcion(rs1.getString("descripcion"));
grupo.setPlantillaId(rs1.getInt("plantilla_id"));
grupo.setEstado(rs1.getString("estado"));
sql = "SELECT * FROM WWW_PLANTILLAS_PEDIDOS_SUBGRUPOS WHERE grupo_id = ?";
ps = conn.prepareStatement(sql);
ps.setInt(1, grupo.getId());
ResultSet rs2 = ps.executeQuery();
subGrupos = new ArrayList<SubGrupos>();
while(rs2.next()){
subGrupo = new SubGrupos();
subGrupo.setId(rs2.getInt("id"));
subGrupo.setDescripcion(rs2.getString("descripcion"));
subGrupo.setGrupoId(rs2.getInt("grupo_id"));
subGrupo.setEstado(rs2.getString("estado"));
sql = "SELECT items.cod_item, items.descrip_res, item_precio.precio, stock.saldo, items.uni_med ";
sql += "FROM items inner join WWW_PLANTILLAS_PEDIDOS_ITEMS on items.cod_item = WWW_PLANTILLAS_PEDIDOS_ITEMS.cod_item ";
sql += "INNER JOIN item_precio ON item_precio.cod_item = items.cod_item INNER JOIN stock ON items.cod_item = stock.cod_item ";
sql += "INNER JOIN WWW_PLANTILLAS_PEDIDOS_SUBGRUPOS ON WWW_PLANTILLAS_PEDIDOS_SUBGRUPOS.id = WWW_PLANTILLAS_PEDIDOS_ITEMS.subgrupo_id ";
sql += "INNER JOIN WWW_PLANTILLAS_PEDIDOS_GRUPOS ON WWW_PLANTILLAS_PEDIDOS_GRUPOS.id = WWW_PLANTILLAS_PEDIDOS_SUBGRUPOS.grupo_id ";
sql += "INNER JOIN WWW_PLANTILLAS_PEDIDOS ON WWW_PLANTILLAS_PEDIDOS.id = WWW_PLANTILLAS_PEDIDOS_GRUPOS.plantilla_id ";
sql += "WHERE WWW_PLANTILLAS_PEDIDOS_ITEMS.subgrupo_id = ? AND item_precio.codlis = ? AND stock.cod_bod = ?";
ps = conn.prepareStatement(sql);
ps.setInt(1, subGrupo.getId());
ps.setString(2, codLis);
ps.setString(3, codBod);
ResultSet rs3 = ps.executeQuery();
items = new ArrayList<Items>();
while(rs3.next()){
item = new Items();
item.setCodItem(rs3.getString("cod_item"));
item.setDescripItem(rs3.getString("descrip_res"));
item.setPrecio(rs3.getBigDecimal("precio"));
item.setSaldo(rs3.getBigDecimal("saldo"));
item.setUniMed(rs3.getString("uni_med"));
items.add(item);
}//fin de while de items
subGrupo.setItems(items);
rs3.close();
subGrupos.add(subGrupo);
}//fin de while de subgrupos
grupo.setSubGrupos(subGrupos);
rs2.close();
ret.add(grupo);
}//fin de while de grupos
rs1.close();
ps.close();
return ret;
}
}
Code: Select all
@ManagedBean
@ViewScoped
public class PlantillasController implements Serializable{
private static final long serialVersionUID = 1L;
private List<Grupos> grupos;
GruposBo service = new GruposBo();
public PlantillasController() {
grupos = service.searchGrupos(1, "02", "GYE");
}
public List<Grupos> getGrupos() {
return grupos;
}
public void setGrupos(List<Grupos> grupos) {
this.grupos = grupos;
}
}
Code: Select all
<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:p="http://primefaces.org/ui"
xmlns:f="http://java.sun.com/jsf/core">
<h:head>
<title>Página de Prueba</title>
</h:head>
<h:body>
<h:form id="form">
<p:growl id="growl"/>
<p:dataTable value="#{plantillasController.grupos}" var="grupo">
<f:facet name="header">#{grupos.descripcion}</f:facet>
<p:subTable value="#{grupo}" var="subgrupo">
<f:facet name="header">#{subgrupo.descripcion}</f:facet>
<p:subTable value="#{subgrupo}" var="items">
<p:column>#{items.codItem}</p:column>
<p:column>#{items.descripItem}</p:column>
</p:subTable>
</p:subTable>
</p:dataTable>
</h:form>
</h:body>
</html>