$model->load(Yii::$app->request->get());
+ $stores = ArrayHelper::map($this->getStores([
+ 'territorial_manager_id' => $model->territory_manager_id,
+ 'kshf_id' => $model->kshf_id,
+ 'city_id' => $model->city_id,
+ 'region_id' => $model->region_id,
+ 'raion_id' => $model->raion_id,
+ 'store_type_id' => $model->store_type_id,
+ ]), 'id', 'name');
+
+ $exist = false;
+ foreach ($stores as $storeId => $storeName) {
+ if ($model->store_id == $storeId) {
+ $exist = true;
+ break;
+ }
+ }
+ if (!$exist) {
+ $model->store_id = null;
+ }
///////////////////////////////////////////
$total = 0;
$matrixTypes = MatrixType::find()->orderBy(['id' => SORT_ASC])->all();
$year = date("Y") - $i;
$years [$year] = $year;
}
- $stores = ArrayHelper::map(CityStore::find()->andWhere(['visible' => '1'])->all(), 'id', 'name');
-
return $this->render('index', compact('model', 'years', 'stores', 'total',
'withoutMatrix', 'withOnlyMatrix', 'saleCountPlan', 'matrixTypes'));
}
- public function actionGetStores() {
- Yii::$app->response->format = Response::FORMAT_JSON;
-
- $data = Yii::$app->request->post();
-
+ public function getStores($data) {
$territorialManager = $data['territorial_manager_id'] ?? null;
$bushChefFlorist = $data['kshf_id'] ?? null;
$stores = $query->all();
+ return $stores;
+ }
+
+ public function actionGetStores() {
+ Yii::$app->response->format = Response::FORMAT_JSON;
+
+ $data = Yii::$app->request->post();
+
+ $stores = $this->getStores($data);
+
return ArrayHelper::map($stores, 'id', 'name');
}
}