From 5d38cbe37638073e2eb172b1cfc8104b42ef90e7 Mon Sep 17 00:00:00 2001 From: Alexander Smirnov Date: Fri, 31 Jan 2025 12:15:01 +0300 Subject: [PATCH] =?utf8?q?[ERP-283]=20=D0=B4=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB?= =?utf8?q?=D0=B5=D0=BD=D1=8B=20=D1=84=D0=B8=D0=BB=D1=8C=D1=82=D1=80=D1=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- .../SalesWriteOffsPlanController.php | 66 +++++++++++++- erp24/views/category-plan/index.php | 4 +- erp24/views/sales-write-offs-plan/index.php | 89 +++++++++++++++++-- 3 files changed, 150 insertions(+), 9 deletions(-) diff --git a/erp24/controllers/SalesWriteOffsPlanController.php b/erp24/controllers/SalesWriteOffsPlanController.php index 8f693165..fc69a2e8 100644 --- a/erp24/controllers/SalesWriteOffsPlanController.php +++ b/erp24/controllers/SalesWriteOffsPlanController.php @@ -7,8 +7,10 @@ use yii\base\DynamicModel; use yii\helpers\Json; use yii\web\Controller; use yii_app\records\CityStore; +use yii_app\records\CityStoreParams; use yii_app\records\Sales; use yii_app\records\SalesWriteOffsPlan; +use yii_app\records\StoreDynamic; class SalesWriteOffsPlanController extends Controller { @@ -16,8 +18,15 @@ class SalesWriteOffsPlanController extends Controller $model = DynamicModel::validateData([ 'year' => date('Y'), 'month' => date('m'), + 'city_id' => null, + 'region_id' => null, + 'raion_id' => null, + 'store_type_id' => null, + 'territory_manager_id' => null, + 'kshf_id' => null, ], [ - [['year', 'month'], 'safe'] + [['year', 'month', 'city_id', 'region_id', 'raion_id', 'store_type_id', + 'territory_manager_id', 'kshf_id'], 'safe'] ]); $model->load(Yii::$app->request->get()); @@ -31,7 +40,6 @@ class SalesWriteOffsPlanController extends Controller $years [$year] = $year; } - $stores = CityStore::find()->andWhere(['visible' => '1'])->all(); $salesWriteOffsPlan = SalesWriteOffsPlan::find()->where(['year' => $model->year, 'month' => $model->month]) ->indexBy('store_id')->asArray()->all(); @@ -43,6 +51,60 @@ class SalesWriteOffsPlanController extends Controller ->indexBy('store_id') ->asArray()->all(); + $territorialManager = $model->territorial_manager_id ?? null; + $bushChefFlorist = $model->kshf_id ?? null; + + $query = CityStore::find() + ->andWhere(['visible' => CityStore::IS_VISIBLE]); + + if (!empty($model->city_id)) { + $query->andWhere(['id' => CityStoreParams::find() + ->andWhere(['address_city' => $model->city_id]) + ->select('store_id') + ->column()]); + } + + if (!empty($model->region_id)) { + $query->andWhere(['id' => CityStoreParams::find() + ->andWhere(['address_region' => $model->region_id]) + ->select('store_id') + ->column()]); + } + + if (!empty($model->raion_id)) { + $query->andWhere(['id' => CityStoreParams::find() + ->andWhere(['address_district' => $model->raion_id]) + ->select('store_id') + ->column()]); + } + + if (!empty($model->store_type_id)) { + $query->andWhere(['id' => CityStoreParams::find() + ->andWhere(['store_type' => $model->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 $this->render('index', compact('model', 'years', 'stores', 'salesWriteOffsPlan', 'sales')); } diff --git a/erp24/views/category-plan/index.php b/erp24/views/category-plan/index.php index 6f8453d8..d2818af8 100644 --- a/erp24/views/category-plan/index.php +++ b/erp24/views/category-plan/index.php @@ -28,6 +28,8 @@ $this->registerJsFile('/js/category-plan/index.js', ['position' => \yii\web\View
+

План по категориям

+ 'filter-form', 'method' => 'GET', @@ -117,7 +119,7 @@ $this->registerJsFile('/js/category-plan/index.js', ['position' => \yii\web\View
field($model, 'kshf_id')->widget(Select2::class, [ - 'data' => ArrayHelper::map(Admin::findAll(['group_id' => AdminGroup::GROUP_BUSH_CHEF_FLORIST]), 'id', 'name_full'), + 'data' => ArrayHelper::map(Admin::findAll(['group_id' => AdminGroup::GROUP_BUSH_CHEF_FLORIST]), 'id', 'name'), 'language' => 'ru', 'options' => ['placeholder' => 'кШФ...'], 'pluginOptions' => [ diff --git a/erp24/views/sales-write-offs-plan/index.php b/erp24/views/sales-write-offs-plan/index.php index aecdec0c..c15a9ebb 100644 --- a/erp24/views/sales-write-offs-plan/index.php +++ b/erp24/views/sales-write-offs-plan/index.php @@ -3,9 +3,15 @@ use yii\helpers\Html; use yii\base\DynamicModel; use yii\widgets\ActiveForm; +use yii\helpers\ArrayHelper; +use kartik\select2\Select2; use dosamigos\datetimepicker\DateTimePicker; +use yii_app\records\Admin; +use yii_app\records\AdminGroup; +use yii_app\records\StoreType; +use yii_app\records\StoreCityList; use yii_app\helpers\HtmlHelper; use yii_app\records\SalesWriteOffsPlan; @@ -47,13 +53,84 @@ function colorScheme2($p) { ]) ?>
-
- field($model, 'year')->dropDownList($years, ['onchange' => 'this.form.submit();'])->label(false) ?> +
+
+
+ field($model, 'year')->dropDownList($years)->label(false) ?> +
+
+ field($model, 'city_id')->widget(Select2::class, [ + 'data' => ArrayHelper::map(StoreCityList::findAll(['type' => StoreCityList::TYPE_CITY]), 'id', 'name'), + 'language' => 'ru', + 'options' => ['placeholder' => 'Города...'], + 'pluginOptions' => [ + 'allowClear' => true, + ] + ])->label(false) ?> +
+
+ field($model, 'store_type_id')->widget(Select2::class, [ + 'data' => ArrayHelper::map(StoreType::find()->all(), 'id', 'name'), + 'language' => 'ru', + 'options' => ['placeholder' => 'Тип магазина...'], + 'pluginOptions' => [ + 'allowClear' => true, + ] + ])->label(false) ?> +
+
+
+
+ field($model, 'month')->dropDownList(HtmlHelper::getMonthNames())->label(false) ?> +
+
+ field($model, 'region_id')->widget(Select2::class, [ + 'data' => ArrayHelper::map(StoreCityList::findAll(['type' => StoreCityList::TYPE_REGION]), 'id', 'name'), + 'language' => 'ru', + 'options' => ['placeholder' => 'Регион...'], + 'pluginOptions' => [ + 'allowClear' => true, + ] + ])->label(false) ?> +
+
+ field($model, 'territory_manager_id')->widget(Select2::class, [ + 'data' => ArrayHelper::map(Admin::findAll(['group_id' => AdminGroup::GROUP_BUSH_DIRECTOR]), 'id', 'name_full'), + 'language' => 'ru', + 'options' => ['placeholder' => 'Тер. Управляющий...'], + 'pluginOptions' => [ + 'allowClear' => true, + ] + ])->label(false) ?> +
+
+
+
+
+
+ field($model, 'raion_id')->widget(Select2::class, [ + 'data' => ArrayHelper::map(StoreCityList::findAll(['type' => StoreCityList::TYPE_DISTRICT]), 'id', 'name'), + 'language' => 'ru', + 'options' => ['placeholder' => 'Район...'], + 'pluginOptions' => [ + 'allowClear' => true, + ] + ])->label(false) ?> +
+
+ field($model, 'kshf_id')->widget(Select2::class, [ + 'data' => ArrayHelper::map(Admin::findAll(['group_id' => AdminGroup::GROUP_BUSH_CHEF_FLORIST]), 'id', 'name'), + 'language' => 'ru', + 'options' => ['placeholder' => 'кШФ...'], + 'pluginOptions' => [ + 'allowClear' => true, + ] + ])->label(false) ?> +
+
-
-
-
- field($model, 'month')->dropDownList(HtmlHelper::getMonthNames(), ['onchange' => 'this.form.submit();'])->label(false) ?> +
+ 'btn btn-secondary'])?>
-- 2.39.5