/**
  * Store a newly created resource in storage.
  *
  * @return Response
  */
 public function store()
 {
     // var_dump(Input::All());
     // die;
     //
     // 'categorias_id' => 'exists:rubros,id'
     $rules = ['articulo' => 'required', 'copete' => 'required', 'texto' => 'required'];
     if (!Articulo::isValid(Input::all(), $rules)) {
         return Redirect::back()->withInput()->withErrors(Articulo::$errors);
     }
     $articulo = new Articulo();
     $articulo->users_id = Sentry::getUser()->id;
     $articulo->articulo = Input::get('articulo');
     $articulo->copete = Input::get('copete');
     $articulo->texto = Input::get('texto');
     $articulo->tipo = Input::get('tipo');
     $articulo->categorias_id = Input::get('categorias_id');
     $url_seo = Input::get('articulo');
     $articulo->estado = 'nuevo';
     //$url_seo = $this->url_slug($url_seo) . implode("-",getdate());
     $url_seo = $this->url_slug($url_seo) . date('ljSFY');
     $articulo->url_seo = $url_seo;
     $articulo->save();
     return Redirect::to('/articulos/ver');
 }
예제 #2
0
 /**
  * Performs the work of inserting or updating the row in the database.
  *
  * If the object is new, it inserts it; otherwise an update is performed.
  * All related objects are also updated in this method.
  *
  * @param PropelPDO $con
  * @return int             The number of rows affected by this insert/update and any referring fk objects' save() operations.
  * @throws PropelException
  * @see        save()
  */
 protected function doSave(PropelPDO $con)
 {
     $affectedRows = 0;
     // initialize var to track total num of affected rows
     if (!$this->alreadyInSave) {
         $this->alreadyInSave = true;
         // We call the save method on the following object(s) if they
         // were passed to this object by their corresponding set
         // method.  This object relates to these object(s) by a
         // foreign key reference.
         if ($this->aArticulo !== null) {
             if ($this->aArticulo->isModified() || $this->aArticulo->isNew()) {
                 $affectedRows += $this->aArticulo->save($con);
             }
             $this->setArticulo($this->aArticulo);
         }
         if ($this->isNew() || $this->isModified()) {
             // persist changes
             if ($this->isNew()) {
                 $this->doInsert($con);
             } else {
                 $this->doUpdate($con);
             }
             $affectedRows += 1;
             $this->resetModified();
         }
         if ($this->articulovariantevalorsScheduledForDeletion !== null) {
             if (!$this->articulovariantevalorsScheduledForDeletion->isEmpty()) {
                 ArticulovariantevalorQuery::create()->filterByPrimaryKeys($this->articulovariantevalorsScheduledForDeletion->getPrimaryKeys(false))->delete($con);
                 $this->articulovariantevalorsScheduledForDeletion = null;
             }
         }
         if ($this->collArticulovariantevalors !== null) {
             foreach ($this->collArticulovariantevalors as $referrerFK) {
                 if (!$referrerFK->isDeleted() && ($referrerFK->isNew() || $referrerFK->isModified())) {
                     $affectedRows += $referrerFK->save($con);
                 }
             }
         }
         if ($this->propiedadvalorsScheduledForDeletion !== null) {
             if (!$this->propiedadvalorsScheduledForDeletion->isEmpty()) {
                 PropiedadvalorQuery::create()->filterByPrimaryKeys($this->propiedadvalorsScheduledForDeletion->getPrimaryKeys(false))->delete($con);
                 $this->propiedadvalorsScheduledForDeletion = null;
             }
         }
         if ($this->collPropiedadvalors !== null) {
             foreach ($this->collPropiedadvalors as $referrerFK) {
                 if (!$referrerFK->isDeleted() && ($referrerFK->isNew() || $referrerFK->isModified())) {
                     $affectedRows += $referrerFK->save($con);
                 }
             }
         }
         $this->alreadyInSave = false;
     }
     return $affectedRows;
 }
예제 #3
0
 /**
  * Performs the work of inserting or updating the row in the database.
  *
  * If the object is new, it inserts it; otherwise an update is performed.
  * All related objects are also updated in this method.
  *
  * @param PropelPDO $con
  * @return int             The number of rows affected by this insert/update and any referring fk objects' save() operations.
  * @throws PropelException
  * @see        save()
  */
 protected function doSave(PropelPDO $con)
 {
     $affectedRows = 0;
     // initialize var to track total num of affected rows
     if (!$this->alreadyInSave) {
         $this->alreadyInSave = true;
         // We call the save method on the following object(s) if they
         // were passed to this object by their corresponding set
         // method.  This object relates to these object(s) by a
         // foreign key reference.
         if ($this->aArticulo !== null) {
             if ($this->aArticulo->isModified() || $this->aArticulo->isNew()) {
                 $affectedRows += $this->aArticulo->save($con);
             }
             $this->setArticulo($this->aArticulo);
         }
         if ($this->aArticulovariante !== null) {
             if ($this->aArticulovariante->isModified() || $this->aArticulovariante->isNew()) {
                 $affectedRows += $this->aArticulovariante->save($con);
             }
             $this->setArticulovariante($this->aArticulovariante);
         }
         if ($this->aPropiedad !== null) {
             if ($this->aPropiedad->isModified() || $this->aPropiedad->isNew()) {
                 $affectedRows += $this->aPropiedad->save($con);
             }
             $this->setPropiedad($this->aPropiedad);
         }
         if ($this->aPropiedadvalor !== null) {
             if ($this->aPropiedadvalor->isModified() || $this->aPropiedadvalor->isNew()) {
                 $affectedRows += $this->aPropiedadvalor->save($con);
             }
             $this->setPropiedadvalor($this->aPropiedadvalor);
         }
         if ($this->isNew() || $this->isModified()) {
             // persist changes
             if ($this->isNew()) {
                 $this->doInsert($con);
             } else {
                 $this->doUpdate($con);
             }
             $affectedRows += 1;
             $this->resetModified();
         }
         $this->alreadyInSave = false;
     }
     return $affectedRows;
 }
예제 #4
0
 public function store()
 {
     $data = Input::all();
     $rules = array('req_id' => 'required|numeric', 'articulo' => 'required', 'cantidad' => 'required|numeric', 'unidad' => 'required');
     $validator = Validator::make($data, $rules);
     if ($validator->passes()) {
         $articulo = new Articulo();
         $articulo->req_id = Input::get('req_id');
         $articulo->articulo = Input::get('articulo');
         $articulo->cantidad = Input::get('cantidad');
         $articulo->unidad = Input::get('unidad');
         $articulo->save();
         return Redirect::action('RequisicionController@show', array(Input::get('req_id')));
     } else {
         return Redirect::action('ArticulosController@create', array(Input::get('req_id')))->withErrors($validator)->withInput();
     }
 }
예제 #5
0
 public function importarOcNuevas()
 {
     $oc_externas = $this->consultarOcExternas();
     if (count($oc_externas) > 0) {
         foreach ($oc_externas as $oc_nueva) {
             $proveedor = new ProveedorController();
             $proveedor_id = $proveedor->getProveedorId($oc_nueva->benef_id);
             if ($proveedor_id !== false) {
                 $oc = new Oc();
                 $oc->oc = $oc_nueva->oc;
                 $oc->fecha_oc = $oc_nueva->fecha_oc;
                 $oc->req = $oc_nueva->req;
                 $oc->db_origen = 'sgf14';
                 $oc->proveedor_id = $proveedor_id;
                 $oc->urg_id = '';
                 $oc->estatus = '';
                 $oc->save();
                 //Insetar artículos @articulos
                 $articulosExternos = $this->getArticulosExternos($oc_nueva->oc);
                 foreach ($articulosExternos as $articuloExterno) {
                     $articulo = new Articulo();
                     $articulo->articulo = $articuloExterno->art . ' ' . $articuloExterno->esp;
                     $articulo->unidad = $articuloExterno->unidad;
                     $articulo->rubro_id = 0;
                     $articulo->save();
                     //Insertar artículos @oc_articulos
                     $oc_art = new OcArticulo();
                     $oc_art->oc()->associate($oc);
                     $oc_art->articulo()->associate($articulo);
                     $oc_art->art_count = $articuloExterno->art_count;
                     $oc_art->esp = $articuloExterno->art . ' ' . $articuloExterno->esp;
                     $oc_art->cantidad = $articuloExterno->cantidad;
                     $oc_art->costo = $articuloExterno->costo;
                     $oc_art->impuesto = $articuloExterno->impuesto;
                     $oc_art->unidad = $articuloExterno->unidad;
                     $oc_art->save();
                 }
             }
         }
     }
 }
예제 #6
0
 public function post_nuevo()
 {
     $inputs = Input::all();
     $reglas = array('nombre' => 'required|max:50', 'descripcion' => 'required|max:50', 'alto' => 'required', 'largo' => 'required', 'ancho_prof' => 'required', 'rubro' => 'required|integer', 'sucursal' => 'required', 'stock' => 'required|integer', 'prec_compra' => 'required', 'proveedor' => 'required');
     $mensajes = array('required' => 'Campo Obligatorio');
     $validar = Validator::make($inputs, $reglas);
     if ($validar->fails()) {
         Input::flash();
         return Redirect::back()->withInput()->withErrors($validar);
     } else {
         try {
             DB::beginTransaction();
             $articulo = new Articulo();
             $articulo->nombre = Input::get('nombre');
             $articulo->descripcion = Input::get('descripcion');
             $articulo->alto = Input::get('alto');
             $articulo->largo = Input::get('largo');
             $articulo->ancho_prof = Input::get('ancho_prof');
             $articulo->id_rubro = Input::get('rubro');
             $articulo->precio_compra = Input::get('prec_compra');
             $articulo->id_proveedor = Input::get('proveedor');
             $articulo->save();
             $insertedId = $articulo->id_articulo;
             $stock = new Stock();
             $stock->id_articulo = $insertedId;
             $stock->id_sucursal = Input::get('sucursal');
             $stock->cantidad = Input::get('stock');
             $stock->save();
             DB::commit();
             $articulos = DB::table('articulos')->join('rubros', 'articulos.id_rubro', '=', 'rubros.id_rubro')->join('proveedores', 'articulos.id_proveedor', '=', 'proveedores.id_proveedor')->join('stock', 'articulos.id_articulo', '=', 'stock.id_articulo')->join('sucursales', 'stock.id_sucursal', '=', 'sucursales.id_sucursal')->select('articulos.id_articulo', 'rubros.rubro', 'articulos.nombre', 'articulos.descripcion', 'articulos.alto', 'articulos.largo', 'articulos.ancho_prof', 'articulos.precio_compra', 'rubros.id_rubro', 'proveedores.nom_raz', 'stock.cantidad', 'sucursales.nombre as sucursal')->orderby('articulos.nombre', 'asc')->paginate(100);
             return View::make('lista_articulos')->with('articulos', $articulos)->with('error', 'El Artículo ha sido cargado con Éxito');
         } catch (Exception $ex) {
             DB::rollBack();
             echo $ex->getMessage();
         }
     }
 }