From: Alexander Smirnov Date: Tue, 28 Jan 2025 18:43:38 +0000 (+0300) Subject: [ERP-283] очередная копипаста фильтра X-Git-Tag: 1.7~29^2 X-Git-Url: https://gitweb.erp-flowers.ru/?a=commitdiff_plain;h=8541fbd43c93157fe6f08cf43977737efe9e2f85;p=erp24_rep%2Fyii-erp24%2F.git [ERP-283] очередная копипаста фильтра --- diff --git a/erp24/controllers/CategoryPlanController.php b/erp24/controllers/CategoryPlanController.php index 29f3705d..57d9806f 100644 --- a/erp24/controllers/CategoryPlanController.php +++ b/erp24/controllers/CategoryPlanController.php @@ -8,9 +8,11 @@ use yii\helpers\ArrayHelper; use yii\web\Controller; use yii\web\Response; use yii_app\records\CityStore; +use yii_app\records\CityStoreParams; use yii_app\records\ExportImportTable; use yii_app\records\Sales; use yii_app\records\SalesWriteOffsPlan; +use yii_app\records\StoreDynamic; use yii_app\records\WriteOffs; use yii_app\records\WriteOffsErp; @@ -142,26 +144,62 @@ class CategoryPlanController extends Controller { public function actionGetStores() { Yii::$app->response->format = Response::FORMAT_JSON; - $cityId = Yii::$app->request->post('city_id'); - $regionId = Yii::$app->request->post('region_id'); - $raionId = Yii::$app->request->post('raion_id'); - $storeTypeId = Yii::$app->request->post('store_type_id'); -// $territoryManagerId = Yii::$app->request->post('territory_manager_id'); -// $kshfId = Yii::$app->request->post('kshf_id'); - - $stores = CityStore::find() - ->andFilterWhere([ - 'visible' => 1, - 'city' => $cityId, - 'region' => $regionId, - 'district' => $raionId, - 'type' => $storeTypeId, - ]) -// ->andFilterWhere(['in', 'id', $bushChefFloristStoreIds]) -// ->andFilterWhere(['in', 'id', $territorialManagerStoreIds]) - ->orderBy('id') - ->all(); + $data = Yii::$app->request->post(); + + $territorialManager = $data['territorial_manager_id'] ?? null; + $bushChefFlorist = $data['kshf_id'] ?? null; + + $query = CityStore::find() + ->andWhere(['visible' => CityStore::IS_VISIBLE]); + + if (!empty($data['city_id'])) { + $query->andWhere(['id' => CityStoreParams::find() + ->andWhere(['address_city' => $data['city_id']]) + ->select('store_id') + ->column()]); + } + + if (!empty($data['region_id'])) { + $query->andWhere(['id' => CityStoreParams::find() + ->andWhere(['address_region' => $data['region_id']]) + ->select('store_id') + ->column()]); + } + + if (!empty($data['raion_id'])) { + $query->andWhere(['id' => CityStoreParams::find() + ->andWhere(['address_district' => $data['raion_id']]) + ->select('store_id') + ->column()]); + } + + if (!empty($data['store_type_id'])) { + $query->andWhere(['id' => CityStoreParams::find() + ->andWhere(['store_type' => $data['store_type_id']]) + ->select('store_id') + ->column()]); + } + + if (!empty($territorialManager)) { + $territorialManagerStoreIds = StoreDynamic::find() + ->select('store_id') + ->where(['category' => 3, 'active' => 1, 'value_int' => $territorialManager]) + ->column(); + + $query->andWhere(['in', 'id', $territorialManagerStoreIds ?: [-1]]); + } + + if (!empty($bushChefFlorist)) { + $bushChefFloristStoreIds = StoreDynamic::find() + ->select('store_id') + ->where(['category' => 2, 'active' => 1, 'value_int' => $bushChefFlorist]) + ->column(); + + $query->andWhere(['in', 'id', $bushChefFloristStoreIds ?: [-1]]); + } + + $stores = $query->all(); return ArrayHelper::map($stores, 'id', 'name'); } diff --git a/erp24/views/category-plan/index.php b/erp24/views/category-plan/index.php index 40ee2c64..6f8453d8 100644 --- a/erp24/views/category-plan/index.php +++ b/erp24/views/category-plan/index.php @@ -9,6 +9,9 @@ use kartik\select2\Select2; use yii_app\helpers\HtmlHelper; use yii_app\records\SalesWriteOffsPlan; use yii_app\records\StoreCityList; +use yii_app\records\Admin; +use yii_app\records\AdminGroup; +use yii_app\records\StoreType; /* @var $model DynamicModel */ /* @var $years array */ @@ -49,7 +52,7 @@ $this->registerJsFile('/js/category-plan/index.js', ['position' => \yii\web\View
field($model, 'store_type_id')->widget(Select2::class, [ - 'data' => [0 => 'оффлайн', 1 => 'онлайн'], + 'data' => ArrayHelper::map(StoreType::find()->all(), 'id', 'name'), 'language' => 'ru', 'options' => ['placeholder' => 'Тип магазина...'], 'pluginOptions' => [ @@ -89,7 +92,7 @@ $this->registerJsFile('/js/category-plan/index.js', ['position' => \yii\web\View
field($model, 'territory_manager_id')->widget(Select2::class, [ - 'data' => [0 => 'Маша', 1 => 'Миша'], + 'data' => ArrayHelper::map(Admin::findAll(['group_id' => AdminGroup::GROUP_BUSH_DIRECTOR]), 'id', 'name_full'), 'language' => 'ru', 'options' => ['placeholder' => 'Тер. Управляющий...'], 'pluginOptions' => [ @@ -114,7 +117,7 @@ $this->registerJsFile('/js/category-plan/index.js', ['position' => \yii\web\View
field($model, 'kshf_id')->widget(Select2::class, [ - 'data' => [0 => 'Маша', 1 => 'Миша'], + 'data' => ArrayHelper::map(Admin::findAll(['group_id' => AdminGroup::GROUP_BUSH_CHEF_FLORIST]), 'id', 'name_full'), 'language' => 'ru', 'options' => ['placeholder' => 'кШФ...'], 'pluginOptions' => [