Exemplo n.º 1
0
    function fetchBalance($where=null) {
        $select = $this->getDbTable()->select();
        $select->from($this->getDbTable());
//        $select->join(array('R' => 'REGISTRO'), 'C.ID_CATEGORIA = R.ID_CATEGORIA');
        
//        $select->where("R.ESTADO_REGISTRO = ?", 0);
//        $select->group("R.ID_CATEGORIA", "R.ID_TIPO_REGISTRO");
//        $select->order("C.ID_CATEGORIA ASC");
        if ($where != null) {
            foreach ($where as $key => $val) {
                $select->where($key . ' = ?', $val);
            }
        }
//        $sql = $select->__toString();
//        echo "$sql\n";

//        SELECT C.ID_CATEGORIA, CATEGORIA, SUM(MONTO_REGISTRO) AS MONTO, R.ID_TIPO_REGISTRO
//        FROM CATEGORIA AS C INNER JOIN REGISTRO AS R
//        WHERE R.ID_CATEGORIA = C.ID_CATEGORIA
//            AND R.ID_USUARIO = 1
//            AND R.ESTADO_REGISTRO = 0
//        GROUP BY R.ID_CATEGORIA, R.ID_TIPO_REGISTRO
//        ORDER BY C.ID_CATEGORIA
        $resultSet = $this->getDbTable()->fetchAll($select);
        $regMP = new Application_Model_RegistroMP();
        $entries = array();
        foreach ($resultSet as $row) {
            $entry = new Application_Model_Categoria();
            $entry->setIdCategoria($row->ID_CATEGORIA);
            $entry->setIdProyecto($row->ID_PROYECTO);
            $entry->setCategoria($row->CATEGORIA);
            $entry->setColorCategoria($row->COLOR_CATEGORIA);
            $entry->setEstadoCategoria($row->ESTADO_CATEGORIA);
            $entry->setIngresos($regMP->fetchSumCat($row->ID_CATEGORIA, 1, $row->ID_PROYECTO));
            $entry->setEgresos($regMP->fetchSumCat($row->ID_CATEGORIA, 2, $row->ID_PROYECTO));
            $entries[] = $entry;
        }
        return $entries;
    }
Exemplo n.º 2
0
    public function categoriaAction() {
        $request = $this->getRequest();
        if ($this->getRequest()->isGet()) {
            $id = $request->getParam('id');
            $this->view->id = $id;
            Zend_View_Helper_PaginationControl::setDefaultViewPartial('controls.phtml');
            $regMP = new Application_Model_RegistroMP();
            $formReg = new Application_Form_Registro();
            $this->view->formReg = $formReg;
            $this->view->categoria = new stdClass();
            $this->view->categoria->ing = $regMP->fetchSumTipo(1, $this->me['id_usuario'], $id);
            $this->view->categoria->gas = $regMP->fetchSumTipo(2, $this->me['id_usuario'], $id);
            $this->view->categoria->bal = $this->view->categoria->ing - $this->view->categoria->gas;
            $where = array('ID_PROYECTO' => $this->me['id_usuario'], 'ID_CATEGORIA' => $id);
            $this->view->reg = $regMP->fetchAll(null, $where);
            $attr = array('ID_CATEGORIA', 'CATEGORIA');
            $where = array('ID_PROYECTO' => $this->me["id_usuario"]);
            $catMP = new Application_Model_CategoriaMP();
            $cat = $catMP->fetchAll($attr, $where);
            $this->view->cat = $cat;
            $catArr = array();
            foreach ($cat as $c) {
                $catArr[$c->getIdCategoria()] = $c->getCategoria();
            }
            $this->view->catArr = $catArr;
            $this->view->categoria->nombre = $catArr[$id];
            $paginator = Zend_Paginator::factory($this->view->reg);
            $paginator->setItemCountPerPage(20);
            $paginator->setCurrentPageNumber($this->_getParam('page', 1));
            $this->view->paginator = $paginator;

//            $catMP = new Application_Model_CategoriaMP();
//            $attr = array("ID_CATEGORIA", "CATEGORIA");
//            $where = array('ID_PROYECTO' => $this->me['id_usuario']);
//            $this->view->cat = $catMP->fetchAll($attr, $where);
//            print_r($this->view->cat);
        }
    }