public function addAction() {
        $request = $this->getRequest();
        $form = new Application_Form_Registro();

        if ($this->getRequest()->isPost()) {
            if ($form->isValid($request->getPost())) {
                $data = new Application_Model_Registro($form->getValues());
                $data->setIdUsuario($this->me['id_usuario']);
                $MP = new Application_Model_RegistroMP();
                $res = $MP->save($data);
                $data->setIdRegistro($res);
                
                $MPCat = new Application_Model_CategoriaMP();
                $cat = new Application_Model_Categoria();
                $MPCat->find($data->getIdCategoria(), $cat);
                
//                print_r($cat);
                
                $out["idRegistro"] = $data->getIdRegistro();
                $out["idCategoria"] = $cat->getIdCategoria();
                $out["nomCategoria"] = $cat->getCategoria();
                $out["idTipoRegistro"] = $data->getIdTipoRegistro();
                $out["montoRegistro"] = $data->getMontoRegistro();
                $out["fechaRegistro"] = $data->getFechaRegistro();
                $out["descRegistro"] = $this->view->escape($data->getDescRegistro());
//                $proyecto = array();
                if($out["idTipoRegistro"] == 1) {
                    $proyecto["ingresos"] = $this->view->proyecto->getIngresos() + $out["montoRegistro"];
                    $proyecto["balance"] = $this->view->proyecto->getBalance() + $out["montoRegistro"];
                    $proyecto["egresos"] = $this->view->proyecto->getEgresos();
                } else {
                    $proyecto["egresos"] = $this->view->proyecto->getEgresos() + $out["montoRegistro"];
                    $proyecto["balance"] = $this->view->proyecto->getBalance() - $out["montoRegistro"];
                    $proyecto["ingresos"] = $this->view->proyecto->getIngresos();
                }
                $proyecto["nombre"] = $this->view->proyecto->getNomProyecto();
                $this->view->pro = $proyecto;
                $this->view->res = $out;
            } else {
                $this->view->inn = $form->getValues();
                $this->view->res1 = "form no valido";
            }
        } else {
            $this->view->res2 = "no post";
        }

        $this->view->form = $form;
    }
Exemple #2
0
    public function fetchAll($attr = null, $where = null) {
        $select = $this->getDbTable()->select();
        if ($attr != null) {
            $select->from($this->getDbTable(), $attr);
        } else {
            $select->from($this->getDbTable());
        }
        if ($where != null) {
            foreach ($where as $key => $val) {
                $select->where($key . ' = ?', $val);
            }
        }
        $select->where("ESTADO_REGISTRO = ?", 0);
        $select->order("FECHA_REGISTRO DESC");
//        echo $select;
//        $select->limit(10,0);
        $resultSet = $this->getDbTable()->fetchAll($select);
        $entries = array();
        foreach ($resultSet as $row) {
            $entry = new Application_Model_Registro();
            if ($attr == null) {
                $entry->setIdRegistro($row->ID_REGISTRO);
                $entry->setIdTipoRegistro($row->ID_TIPO_REGISTRO);
                $entry->setIdCategoria($row->ID_CATEGORIA);
                $entry->setIdProyecto($row->ID_PROYECTO);
                $entry->setIdUsuario($row->ID_USUARIO);
                $entry->setMontoRegistro($row->MONTO_REGISTRO);
                $entry->setFechaRegistro($row->FECHA_REGISTRO);
                $entry->setDescRegistro($row->DESC_REGISTRO);
            } else {
                foreach($attr as $a) {
                    $ta = strtolower($a);
                    $ta = split("_", $ta);
                    $method = "set";
                    foreach($ta as $pa) {
                        $method .= ucfirst($pa);
                    }
                    $entry->$method($row->$a);
                }
            }
            $entries[] = $entry;
        }
        return $entries;
    }