Exemplo n.º 1
0
 /**
  * Finds the Registro model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param integer $id
  * @return Registro the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = Registro::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }
Exemplo n.º 2
0
 public function afterSave()
 {
     $registros = Registro::find()->where(['categoria_id' => $this->id])->all();
     foreach ($registros as $r) {
         $r->categoria = $this->titulo;
         $r->save();
     }
 }
Exemplo n.º 3
0
 public function afterSave()
 {
     $registros = Registro::find()->where(['almacen_id' => $this->id])->all();
     foreach ($registros as $r) {
         $r->almacen = $r->cadenaR->titulo . ' ' . $this->identificador;
         $r->save();
     }
 }
 /**
  * This command echoes what you have entered as the message.
  * @param string $message the message to be echoed.
  */
 public function actionStart()
 {
     $registros = Registro::find()->all();
     foreach ($registros as $r) {
         //La cadena es la primera palabra
         $words = explode(' ', $r->almacen);
         $regcadena = $words[0];
         $cadena = Cadena::find()->where(['titulo' => $regcadena])->one();
         if (!$cadena) {
             $cadena = new Cadena();
             $cadena->titulo = $regcadena;
             $cadena->detachBehavior('blameable');
             $cadena->created_by = 1;
             $cadena->save();
         }
         $regalmacen = "";
         if (count($words) > 1) {
             $regalmacen = implode(' ', array_slice($words, 1, count($words) - 1));
             $almacen = Almacen::find()->where(['identificador' => $regalmacen, 'cadena_id' => $cadena->id])->one();
         } else {
             $almacen = null;
         }
         if (!$almacen) {
             $almacen = new Almacen();
             $almacen->cadena_id = $cadena->id;
             $almacen->identificador = $regalmacen;
             $almacen->detachBehavior('blameable');
             $almacen->created_by = 1;
             $almacen->save();
         }
         $regcategoria = $r->categoria;
         $categoria = Categoria::find()->where(['titulo' => $r->categoria])->one();
         if (!$categoria) {
             $categoria = new Categoria();
             $categoria->titulo = $regcategoria;
             $categoria->descripcion = $r->elemento;
             $categoria->detachBehavior('blameable');
             $categoria->created_by = 1;
             $categoria->save();
         } elseif (strpos($categoria->descripcion, $r->elemento) === false) {
             $o = explode(', ', $categoria->descripcion);
             $o[] = $r->elemento;
             $categoria->descripcion = implode(', ', $o);
             $categoria->save();
         }
         $r->cadena_id = $cadena->id;
         $r->almacen_id = $almacen->id;
         $r->categoria_id = $categoria->id;
         $r->save();
     }
 }
Exemplo n.º 5
0
 public function searchOrderByAlmacen($params)
 {
     $query = Registro::find()->orderBy('almacen, fecha desc');
     return $this->search($params, $query, false);
 }
Exemplo n.º 6
0
 public function beforeSave($insert)
 {
     if (parent::beforeSave($insert)) {
         $this->precio_unitario = $this->precio / $this->cantidad;
         if (!$this->fecha) {
             $this->fecha = date('Y-m-d');
         }
         if (!$this->triggered) {
             $old = Registro::find()->where(['almacen_id' => $this->almacen_id, 'categoria_id' => $this->categoria_id, 'elemento' => $this->elemento, 'marca' => $this->marca, 'descripcion' => $this->descripcion, 'status' => 'active']);
             if (isset($this->id)) {
                 $old = $old->andWhere(['<>', 'id', $this->id]);
             }
             $old = $old->all();
             //echo '<pre>';var_dump($old);die;
             if (is_array($old) && count($old) > 0) {
                 $maxFecha = $old[0]->fecha;
                 foreach ($old as $o) {
                     if ($o->fecha > $maxFecha) {
                         $maxFecha = $o->fecha;
                     }
                     if ($o->fecha <= $this->fecha) {
                         $o->status = 'inactive';
                         $o->triggered = true;
                         $o->save();
                     }
                 }
                 if ($maxFecha > $this->fecha) {
                     $this->status = 'inactive';
                 }
             }
             $this->almacen = $this->cadenaR->titulo . ' ' . $this->almacenR->identificador;
             $this->categoria = $this->categoriaR->titulo;
         }
         return true;
     } else {
         return false;
     }
 }