From 8541fbd43c93157fe6f08cf43977737efe9e2f85 Mon Sep 17 00:00:00 2001 From: Alexander Smirnov Date: Tue, 28 Jan 2025 21:43:38 +0300 Subject: [PATCH] =?utf8?q?[ERP-283]=20=D0=BE=D1=87=D0=B5=D1=80=D0=B5=D0=B4?= =?utf8?q?=D0=BD=D0=B0=D1=8F=20=D0=BA=D0=BE=D0=BF=D0=B8=D0=BF=D0=B0=D1=81?= =?utf8?q?=D1=82=D0=B0=20=D1=84=D0=B8=D0=BB=D1=8C=D1=82=D1=80=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- erp24/controllers/CategoryPlanController.php | 76 +++++++++++++++----- erp24/views/category-plan/index.php | 9 ++- 2 files changed, 63 insertions(+), 22 deletions(-) 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' => [ -- 2.39.5