public function getComerciosOrdenados()
 {
     $rutaDiariaComercios = $this->getRutaDiariaComercios()->orderBy('orden')->all();
     $comerciosOrdenados = [];
     $i = 0;
     foreach ($rutaDiariaComercios as $rutaDiariaComercio) {
         $comercio = Comercio::find()->where(['id' => $rutaDiariaComercio->id_comercio])->one();
         $comerciosOrdenados[$i] = $comercio;
         $i++;
     }
     return $comerciosOrdenados;
 }
    <?php 
$form = ActiveForm::begin();
?>

    <?php 
echo $form->field($model, 'fecha')->textInput(['label' => Yii::t('core', 'Date')]);
?>

    <?php 
echo $form->field($model, 'vendidos')->textInput(['label' => Yii::t('core', 'Sold')]);
?>

    <?php 
$comercio = array(Comercio::find()->all());
$listData = ArrayHelper::map(Comercio::find()->all(), 'id', 'nombre');
echo $form->field($model, 'id_comercio')->dropDownList($listData, ['prompt' => Yii::t('core', 'Select...')]);
?>

    <?php 
//$comercio=array(Comercio::find()->all());
$listData = ArrayHelper::map(Producto::find()->all(), 'id', 'nombre');
echo $form->field($model, 'id_producto')->dropDownList($listData, ['prompt' => Yii::t('core', 'Select...')]);
?>

    <div class="form-group">
        <?php 
echo Html::submitButton($model->isNewRecord ? Yii::t('core', 'Create') : Yii::t('core', 'Update'), ['class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary']);
?>
    </div>
 public function chargeStoreArray()
 {
     $comercios = Comercio::find()->all();
     return $comercios;
 }
 /**
  * Updates an existing Ruta model.
  * If update is successful, the browser will be redirected to the 'view' page.
  * @param integer $id
  * @return mixed
  */
 public function actionUpdate($id)
 {
     $model = $this->findModel($id);
     if ($model->load(Yii::$app->request->post())) {
         $validar = $model->validar();
         if ($validar == 'OK' && $model->save()) {
             return $this->redirect(['view', 'id' => $model->id]);
         } else {
             Yii::$app->getSession()->setFlash('danger', $validar);
             return $this->redirect(['update', 'id' => $model->id]);
         }
     } else {
         if ($model->getOrdenComercios()->count() != 0) {
             $ordenComercios = $model->getOrdenComercios()->all();
             $usuario = User::findOne($model->id_usuario);
             $comercios = [];
             $i = 0;
             foreach ($ordenComercios as $ordenComercio) {
                 $comercios[$i] = Comercio::find()->where(['id' => $ordenComercio->id_comercio])->one();
                 $i++;
             }
             $requestRuta = json_encode(sysconfigs::getRutaRequestParaMostrar($usuario, $comercios));
             return $this->render('update', ['model' => $this->findModel($id), 'tieneRecorrido' => true, 'requestRuta' => $requestRuta]);
         } else {
             return $this->render('update', ['model' => $model]);
         }
     }
 }
 public function comerciosPorDiaSinRutasActivas($dia)
 {
     //ruta: las rutas creadas
     //orden_comercio
     //comercio
     //Devuelve todas las rutas activas
     //$query = new Query();
     $query = Ruta::find()->select('id')->where(['esActivo' => "1"]);
     //Devuelve los comercios en rutas activas
     //$query2 = new Query();
     $query2 = OrdenComercio::find()->select('id_comercio')->where(['in', 'id_ruta', $query]);
     //Devuelve los comercios sin rutas activas
     //$comercios = [];
     $comercios = Comercio::find()->where(['not in', 'id', $query2])->andWhere(['dia' => $dia])->andWhere(['esActivo' => '1'])->all();
     return $comercios;
 }
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = Comercio::find();
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     $this->load($params);
     if (!$this->validate()) {
         // uncomment the following line if you do not want to return any records when validation fails
         // $query->where('0=1');
         return $dataProvider;
     }
     $query->andFilterWhere(['id' => $this->id, 'latitud' => $this->latitud, 'longitud' => $this->longitud, 'direccion' => $this->direccion]);
     if (strtolower($this->esActivo) == strtolower(Yii::t('core', 'Yes'))) {
         $query->andFilterWhere(['esActivo' => $this->esActivo == 0]);
     } else {
         if (strtolower($this->esActivo) == strtolower(Yii::t('core', 'No'))) {
             $query->andFilterWhere(['esActivo' => $this->esActivo == 1]);
         }
     }
     if (strtolower($this->dia) == strtolower(Yii::t('core', 'Monday'))) {
         $query->andFilterWhere(['dia' => 1]);
     } else {
         if (strtolower($this->dia) == strtolower(Yii::t('core', 'Tuesday'))) {
             $query->andFilterWhere(['dia' => 2]);
         } else {
             if (strtolower($this->dia) == strtolower(Yii::t('core', 'Wednesday'))) {
                 $query->andFilterWhere(['dia' => 3]);
             } else {
                 if (strtolower($this->dia) == strtolower(Yii::t('core', 'Thursday'))) {
                     $query->andFilterWhere(['dia' => 4]);
                 } else {
                     if (strtolower($this->dia) == strtolower(Yii::t('core', 'Friday'))) {
                         $query->andFilterWhere(['dia' => 5]);
                     } else {
                         if (strtolower($this->dia) == strtolower(Yii::t('core', 'Saturday'))) {
                             $query->andFilterWhere(['dia' => 6]);
                         } else {
                             if (strtolower($this->dia) == strtolower(Yii::t('core', 'Sunday'))) {
                                 $query->andFilterWhere(['dia' => 7]);
                             }
                         }
                     }
                 }
             }
         }
     }
     if (strtolower($this->prioridad) == strtolower(Yii::t('core', 'Very High'))) {
         $query->andFilterWhere(['prioridad' => 1]);
     } else {
         if (strtolower($this->prioridad) == strtolower(Yii::t('core', 'High'))) {
             $query->andFilterWhere(['prioridad' => 2]);
         } else {
             if (strtolower($this->prioridad) == strtolower(Yii::t('core', 'Normal'))) {
                 $query->andFilterWhere(['prioridad' => 3]);
             } else {
                 if (strtolower($this->prioridad) == strtolower(Yii::t('core', 'Low'))) {
                     $query->andFilterWhere(['prioridad' => 4]);
                 } else {
                     if (strtolower($this->prioridad) == strtolower(Yii::t('core', 'Very Low'))) {
                         $query->andFilterWhere(['prioridad' => 5]);
                     }
                 }
             }
         }
     }
     $query->andFilterWhere(['like', 'nombre', $this->nombre]);
     return $dataProvider;
 }