Example #1
0
 public function actionStock()
 {
     $debug = '';
     $model = new DynamicModel(['vins', 'diller']);
     $model->addRule('vins', 'string')->addRule('diller', 'integer')->addRule(['diller', 'vins'], 'required');
     $list = ArrayHelper::map(Mod\cats\Stock::find()->all(), 'id', 'name');
     $prompt = Yii::t('app', 'Select stock');
     $arrError = [];
     if ($model->load(Yii::$app->request->post()) && $model->validate()) {
         $arrvin = explode("\n", $model->vins);
         foreach ($arrvin as $vin) {
             if ($car = Mod\Car::findOne(['vin' => trim($vin)])) {
                 $status = Mod\CarStatus::findOne(['car_id' => $car->id]);
                 $status->stock_id = $model->diller;
                 $status->save();
             } else {
                 $arrError[] = $vin . ' не найден VIN';
             }
         }
         //			$debug = print_r($arrError, true);
         $debug = implode('<br>', $arrError);
         return $this->render('finish', ['debug' => $debug]);
     }
     $arrVars = ['model' => $model, 'list' => $list, 'prompt' => $prompt, 'selLabel' => 'Склад', 'title' => 'Пакетное перемещение'];
     return $this->render('index', $arrVars);
 }
Example #2
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getStock()
 {
     return $this->hasOne(cats\Stock::className(), ['id' => 'stock_id']);
 }