domingo, 28 de febrero de 2010

Proyecto Mejoramiento - Correccion en las Paginas y la Clase de Balances

Se ha corregido los querys en la clase balance para que estos funcionen con la nueva base, a continuación el código modificado:

public ArrayList bIngresosAdmin(String id) {

        ArrayList bIngresosAdminList=null;
        int idpersona=Integer.parseInt(id);
        ArrayList nueva = new ArrayList();
        Balance bia;
        try {
            Session sesion = HibernateUtil.getSessionFactory().getCurrentSession();
            sesion.beginTransaction();
            Query q = sesion.createSQLQuery("select  p.nombre, p.apellido, sum(m.valor), monthname(m.fecha), year(m.fecha) from persona p, movimiento m where p.id_persona=m.fk_id_persona and p.id_persona="+idpersona+" and m.tipo='Ingreso' group by(p.nombre), monthname(m.fecha), year(m.fecha)");
            bIngresosAdminList = (ArrayList)q.list();
            Iterator it=bIngresosAdminList.iterator();
            while (it.hasNext()) {
                Object[] result=(Object[])it.next();
                bia=new Balance();
                bia.setNombre((String) result[0]);
                bia.setApellido((String) result[1]);
                bia.setTotal((Double) result[2]);
                bia.setMes((String) result[3]);
                bia.setAnio((Integer) result[4]);
                nueva.add(bia);

            }
        } catch (Exception e) {
            e.printStackTrace();
        }

        return nueva;

    }

    public ArrayList bEgresosAdmin(String id) {

        ArrayList bEgresosAdminList=null;
        int idpersona=Integer.parseInt(id);
        ArrayList nueva = new ArrayList();
        Balance bea;
        try {
            Session sesion = HibernateUtil.getSessionFactory().getCurrentSession();
            sesion.beginTransaction();
            Query q = sesion.createSQLQuery("select  p.nombre, p.apellido, sum(m.valor), monthname(m.fecha), year(m.fecha) from persona p, movimiento m where p.id_persona=m.fk_id_persona and p.id_persona="+idpersona+" and m.tipo='Egreso' group by(p.nombre), monthname(m.fecha), year(m.fecha)");
            bEgresosAdminList = (ArrayList)q.list();
            Iterator it=bEgresosAdminList.iterator();
            while (it.hasNext()) {
                Object[] result=(Object[])it.next();
                bea=new Balance();
                bea.setNombre((String) result[0]);
                bea.setApellido((String) result[1]);
                bea.setTotal((Double) result[2]);
                bea.setMes((String) result[3]);
                bea.setAnio((Integer) result[4]);
                nueva.add(bea);

            }
        } catch (Exception e) {
            e.printStackTrace();
        }

        return nueva;

    }

    public ArrayList bIngresosEmp(String id) {

        ArrayList bIngresosEmpList=null;
        int idpersona=Integer.parseInt(id);
        ArrayList nueva = new ArrayList();
        Balance bie;
        try {
            Session sesion = HibernateUtil.getSessionFactory().getCurrentSession();
            sesion.beginTransaction();
            Query q = sesion.createSQLQuery("select  p.nombre, p.apellido, sum(m.valor), monthname(m.fecha), year(m.fecha) from persona p, movimiento m where p.id_persona=m.fk_id_persona and p.id_persona="+idpersona+" and m.tipo='Ingreso' group by(p.nombre), monthname(m.fecha), year(m.fecha)");
            bIngresosEmpList = (ArrayList)q.list();
            Iterator it=bIngresosEmpList.iterator();
            while (it.hasNext()) {
                Object[] result=(Object[])it.next();
                bie=new Balance();
                bie.setNombre((String) result[0]);
                bie.setApellido((String) result[1]);
                bie.setTotal((Double) result[2]);
                bie.setMes((String) result[3]);
                bie.setAnio((Integer) result[4]);
                nueva.add(bie);

            }
        } catch (Exception e) {
            e.printStackTrace();
        }

        return nueva;

    }

    public ArrayList bEgresosEmp(String id) {

        ArrayList bEgresosEmpList=null;
        int idpersona=Integer.parseInt(id);
        ArrayList nueva = new ArrayList();
        Balance bee;
        try {
            Session sesion = HibernateUtil.getSessionFactory().getCurrentSession();
            sesion.beginTransaction();
            Query q = sesion.createSQLQuery("select  p.nombre, p.apellido, sum(m.valor), monthname(m.fecha), year(m.fecha) from persona p, movimiento m where p.id_persona=m.fk_id_persona and p.id_persona="+idpersona+" and m.tipo='Egreso' group by(p.nombre), monthname(m.fecha), year(m.fecha)");
            bEgresosEmpList = (ArrayList)q.list();
            Iterator it=bEgresosEmpList.iterator();
            while (it.hasNext()) {
                Object[] result=(Object[])it.next();
                bee=new Balance();
                bee.setNombre((String) result[0]);
                bee.setApellido((String) result[1]);
                bee.setTotal((Double) result[2]);
                bee.setMes((String) result[3]);
                bee.setAnio((Integer) result[4]);
                nueva.add(bee);

            }
        } catch (Exception e) {
            e.printStackTrace();
        }

        return nueva;

    }

No hay comentarios:

Publicar un comentario