/**
  * 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(ProveedoritradePeer::DATABASE_NAME, Propel::CONNECTION_WRITE);
     }
     $con->beginTransaction();
     try {
         $deleteQuery = ProveedoritradeQuery::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 Proveedoritrade object
  *
  * @param PropelPDO $con Optional Connection object.
  * @param $doQuery Executes a query to get the object if required
  * @return Proveedoritrade The associated Proveedoritrade object.
  * @throws PropelException
  */
 public function getProveedoritrade(PropelPDO $con = null, $doQuery = true)
 {
     if ($this->aProveedoritrade === null && $this->idproveedoritrade !== null && $doQuery) {
         $this->aProveedoritrade = ProveedoritradeQuery::create()->findPk($this->idproveedoritrade, $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->aProveedoritrade->addProveedoritradearchivos($this);
            */
     }
     return $this->aProveedoritrade;
 }
 /**
  * Returns a new ProveedoritradeQuery object.
  *
  * @param     string $modelAlias The alias of a model in the query
  * @param   ProveedoritradeQuery|Criteria $criteria Optional Criteria to build the query from
  *
  * @return ProveedoritradeQuery
  */
 public static function create($modelAlias = null, $criteria = null)
 {
     if ($criteria instanceof ProveedoritradeQuery) {
         return $criteria;
     }
     $query = new ProveedoritradeQuery(null, null, $modelAlias);
     if ($criteria instanceof Criteria) {
         $query->mergeWith($criteria);
     }
     return $query;
 }
 public function serversideAction()
 {
     $request = $this->getRequest();
     if ($request->isPost()) {
         //EL MAPEO DE NUESTRA TABALA
         $table_map = array(0 => 'proveedoritrade_nombre', 1 => 'proveedor_nombrecontacto', 2 => 'proveedoritrade_telefono');
         $post_data = $request->getPost();
         //NUESTRA QUERY
         $query = new \ProveedoritradeQuery();
         $query->filterByIdproveedoritrade(1, \Criteria::NOT_EQUAL);
         //ORDER
         if (isset($post_data['order'])) {
             $order = $table_map[$post_data['order'][0]['column']];
             $dir = $post_data['order'][0]['dir'];
             $query->orderBy($order, $dir);
         } else {
             $query->orderByIdproveedoritrade(\Criteria::DESC);
         }
         if (!empty($post_data['search']['value'])) {
             $search = $post_data['search']['value'];
             $c = new \Criteria();
             $c1 = $c->getNewCriterion('proveedoritrade.proveedoritrade_nombre', '%' . $search . '%', \Criteria::LIKE);
             $c2 = $c->getNewCriterion('proveedoritrade.proveedoritrade_nombrecontacto', '%' . $search . '%', \Criteria::LIKE);
             $c3 = $c->getNewCriterion('proveedoritrade.proveedoritrade_telefono', '%' . $search . '%', \Criteria::LIKE);
             $c1->addOr($c2)->addOr($c3);
             $query->addAnd($c1);
         }
         //EL TOTAL DE LA BUSQUEDA
         $recordsFiltered = $query->count();
         //LIMIT
         $query->setOffset((int) $post_data['start']);
         $query->setLimit((int) $post_data['length']);
         //DAMOS EL FORMATO CORRECTO
         $data = array();
         $value = new \Proveedoritrade();
         foreach ($query->find() as $value) {
             $tmp['DT_RowId'] = $value->getIdproveedoritrade();
             $tmp['proveedoritrade_nombre'] = $value->getProveedoritradeNombre();
             $tmp['proveedor_nombrecontacto'] = $value->getProveedoritradeNombrecontacto();
             $tmp['proveedoritrade_telefono'] = $value->getProveedoritradeTelefono();
             $tmp['empleado_options'] = '<a data-toggle="tooltip" data-placement="left" title="Editar" href="/catalogo/proveedores/editar/' . $value->getIdproveedoritrade() . '"><i class="fa fa-pencil"></i></a><a class="delete" data-toggle="tooltip" data-placement="left" title="Eliminar" href="javascript:void(0)"><i class="fa fa-trash-o"></i></a>';
             $data[] = $tmp;
         }
         //El arreglo que regresamos
         $json_data = array("draw" => (int) $post_data['draw'], "recordsFiltered" => $recordsFiltered, "data" => $data, "page" => $post_data['url_params']['page']);
         return $this->getResponse()->setContent(json_encode($json_data));
     }
 }
 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;
 }