/**
  * Returns a new CategoriagastoQuery object.
  *
  * @param     string $modelAlias The alias of a model in the query
  * @param   CategoriagastoQuery|Criteria $criteria Optional Criteria to build the query from
  *
  * @return CategoriagastoQuery
  */
 public static function create($modelAlias = null, $criteria = null)
 {
     if ($criteria instanceof CategoriagastoQuery) {
         return $criteria;
     }
     $query = new CategoriagastoQuery(null, null, $modelAlias);
     if ($criteria instanceof Criteria) {
         $query->mergeWith($criteria);
     }
     return $query;
 }
 public function editarAction()
 {
     //ID ENTIDAD
     $id = $this->params()->fromRoute('id');
     $request = $this->getRequest();
     if ($request->isPost()) {
         $post_data = $request->getPost();
         //INSTANCIAMOS NUESTRA ENTIDAD
         $entity = \GastofacturacionQuery::create()->findPk($id);
         //SETIAMOS NUESTROS DATOS CON EXCEPCIONES
         foreach ($post_data as $key => $value) {
             if (\GastofacturacionPeer::getTableMap()->hasColumn($key)) {
                 $entity->setByName($key, $value, \BasePeer::TYPE_FIELDNAME);
             }
         }
         //SETIAMOS EL IVA
         $entity->setGastofacturacionIva($post_data['gastofacturacion_iva']);
         $entity->save();
         //Agregamos un mensaje
         $this->flashMessenger()->addSuccessMessage('Registro guardado exitosamente!');
         //REDIRECCIONAMOS A LA ENTIDAD QUE ACABAMOS DE CREAR
         return $this->redirect()->toRoute('admin/catalogo/gastos', array('action' => 'editar', 'id' => $entity->getIdgastofacturacion()));
     }
     $exist = \GastofacturacionQuery::create()->filterByIdgastofacturacion($id)->exists();
     if ($exist) {
         $entity = \GastofacturacionQuery::create()->findPk($id);
         //LE DAMOS FORMATO A LAS CATEGORIAS DE GASTOS
         $categorias_gastos = \CategoriagastoQuery::create()->find();
         $categorias_gastos_array = array();
         foreach ($categorias_gastos as $categoria_gasto) {
             $idcategoriagasto = $categoria_gasto->getIdcategoriagasto();
             $categorias_gastos_array[$idcategoriagasto] = $categoria_gasto->getCategoriagastoNombre();
         }
         //INSTANCIAMOS NUESTRO FORMULARIO
         $form = new \Catalogo\Form\GastoForm($categorias_gastos_array);
         $form->setData($entity->toArray(\BasePeer::TYPE_FIELDNAME));
         //RETORNAMOS A NUESTRA VISTA
         $view_model = new ViewModel();
         $view_model->setTemplate('admin/catalogo/gastos/editar');
         $view_model->setVariables(array('entity' => json_encode($entity->toArray(\BasePeer::TYPE_FIELDNAME)), 'successMessages' => json_encode($this->flashMessenger()->getSuccessMessages()), 'form' => $form));
         return $view_model;
     } else {
         return $this->redirect()->toRoute('admin/catalogo/gastos', array('action' => 'index'));
     }
 }
 /**
  * Removes this object from datastore and sets delete attribute.
  *
  * @param PropelPDO $con
  * @return void
  * @throws PropelException
  * @throws Exception
  * @see        BaseObject::setDeleted()
  * @see        BaseObject::isDeleted()
  */
 public function delete(PropelPDO $con = null)
 {
     if ($this->isDeleted()) {
         throw new PropelException("This object has already been deleted.");
     }
     if ($con === null) {
         $con = Propel::getConnection(CategoriagastoPeer::DATABASE_NAME, Propel::CONNECTION_WRITE);
     }
     $con->beginTransaction();
     try {
         $deleteQuery = CategoriagastoQuery::create()->filterByPrimaryKey($this->getPrimaryKey());
         $ret = $this->preDelete($con);
         if ($ret) {
             $deleteQuery->delete($con);
             $this->postDelete($con);
             $con->commit();
             $this->setDeleted(true);
         } else {
             $con->commit();
         }
     } catch (Exception $e) {
         $con->rollBack();
         throw $e;
     }
 }
 /**
  * Get the associated Categoriagasto object
  *
  * @param PropelPDO $con Optional Connection object.
  * @param $doQuery Executes a query to get the object if required
  * @return Categoriagasto The associated Categoriagasto object.
  * @throws PropelException
  */
 public function getCategoriagasto(PropelPDO $con = null, $doQuery = true)
 {
     if ($this->aCategoriagasto === null && $this->idcategoriagasto !== null && $doQuery) {
         $this->aCategoriagasto = CategoriagastoQuery::create()->findPk($this->idcategoriagasto, $con);
         /* The following can be used additionally to
               guarantee the related object contains a reference
               to this object.  This level of coupling may, however, be
               undesirable since it could result in an only partially populated collection
               in the referenced object.
               $this->aCategoriagasto->addGastofacturacions($this);
            */
     }
     return $this->aCategoriagasto;
 }
 public function eliminarAction()
 {
     $request = $this->getRequest();
     if ($request->isPost()) {
         $id = $request->getPost('id');
         $entity = \CategoriagastoQuery::create()->findPk($id);
         $entity->delete();
         //Agregamos un mensaje
         $this->flashMessenger()->addSuccessMessage('Registro eliminado exitosamente!');
         if ($entity->isDeleted()) {
             return $this->getResponse()->setContent(json_encode(true));
         }
     }
     $id = $this->params()->fromQuery('id');
     $viewModel = new ViewModel();
     $viewModel->setTerminal(true);
     $viewModel->setTemplate('admin/catalogo/categoriasgastos/eliminar');
     return $viewModel;
 }
 public function editarcargoAction()
 {
     $request = $this->getRequest();
     $idgasto = $this->params()->fromQuery('id');
     $entity = \ExpedientegastoQuery::create()->findPk($idgasto);
     if ($request->isPost()) {
         $post_data = $request->getPost();
         $post_files = $request->getFiles();
         $auth = new \Shared\Session\AouthSession();
         $auth = $auth->getData();
         $entity = \ExpedientegastoQuery::create()->findPk($post_data['idexpedientegasto']);
         foreach ($post_data as $key => $value) {
             if (\ExpedientegastoPeer::getTableMap()->hasColumn($key) && !empty($value) && $key != 'expedientegasto_fecha') {
                 $entity->setByName($key, $value, \BasePeer::TYPE_FIELDNAME);
             }
         }
         //LA FECHA
         $expedientegasto_fecha = \DateTime::createFromFormat('d/m/Y', $post_data['expedientegasto_fecha']);
         $entity->setExpedientegastoFecha($expedientegasto_fecha);
         $entity->setIdempleado($auth['idempleado']);
         $entity->save();
         //El comprobante
         if (!empty($post_files['expedientegasto_comprobante']['name'])) {
             $target_path = "/files/expedientesgastos/";
             $target_path = $target_path . $entity->getIdexpedientegasto() . '_' . basename($post_files['expedientegasto_comprobante']['name']);
             if (move_uploaded_file($_FILES['expedientegasto_comprobante']['tmp_name'], $_SERVER['DOCUMENT_ROOT'] . $target_path)) {
                 $entity->setExpedientegastoComprobante($target_path);
                 $entity->save();
             }
         }
         $this->flashMessenger()->addSuccessMessage('Registro guardado exitosamente!');
         //REDIRECCIONAMOS A LA ENTIDAD QUE ACABAMOS DE CREAR
         return $this->redirect()->toUrl('/clientes/ver/' . $entity->getExpediente()->getIdcliente() . '/expedientes/ver/' . $entity->getIdexpediente());
     }
     //LAS CATEGORIAS DE NUESTROS GASTOS
     $categoriasgasto = \CategoriagastoQuery::create()->find();
     $categoriasgasto_array = array();
     foreach ($categoriasgasto as $categoriagastos) {
         $id = $categoriagastos->getIdcategoriagasto();
         $categoriasgasto_array[$id] = $categoriagastos->getCategoriagastoNombre();
     }
     //LOS PROVEEDORES
     $proveedores = \ProveedoritradeQuery::create()->filterByIdproveedoritrade(1, \Criteria::NOT_EQUAL)->find();
     $proveedores_array = array();
     foreach ($proveedores as $proveedor) {
         $id = $proveedor->getIdproveedoritrade();
         $proveedores_array[$id] = $proveedor->getProveedoritradeNombre();
     }
     //gastos de facturacion
     $gastos_facturacion = \GastofacturacionQuery::create()->filterByIdcategoriagasto($entity->getGastofacturacion()->getIdcategoriagasto())->find();
     $gastos_facturacion_array = array();
     foreach ($gastos_facturacion as $gasto_facturacion) {
         $id = $gasto_facturacion->getIdgastofacturacion();
         $gastos_facturacion_array[$id] = $gasto_facturacion->getGastofacturacionNombre();
     }
     //INSTANCIAMOS NUESTRO FORMULARIO
     $form = new \Admin\Clientes\Form\ExpedientegastoForm($entity->getIdexpediente(), $categoriasgasto_array, $proveedores_array, $entity->getExpedientegastoMoneda(), $gastos_facturacion_array);
     //Ponemos nuetros datos al formulario....
     $form->setData($entity->toArray(\BasePeer::TYPE_FIELDNAME));
     $form->get('expedientegasto_fecha')->setValue($entity->getExpedientegastoFecha('d/m/Y'));
     $form->get('idcategoriagasto')->setValue($entity->getGastofacturacion()->getIdcategoriagasto());
     $form->get('idgastofacturacion')->setValue($entity->getIdgastofacturacion());
     $form->get('idgastofacturacion')->setAttribute('disabled', false);
     //Enviamos a la vista
     $view_model = new ViewModel();
     $view_model->setTerminal(true)->setVariable('form', $form)->setVariable('entity', $entity)->setTemplate('/clientes/expedientes/modal/editarcargo');
     return $view_model;
 }