]> gitweb.erp-flowers.ru Git - erp24_rep/yii-erp24/.git/commitdiff
добавлен контроллер и представление с фильтрами
authorJoySystem_v <fvv2011@gmail.com>
Tue, 27 Aug 2024 13:43:09 +0000 (16:43 +0300)
committerJoySystem_v <fvv2011@gmail.com>
Tue, 27 Aug 2024 13:43:09 +0000 (16:43 +0300)
erp24/controllers/SelfCostProductController.php [new file with mode: 0644]
erp24/records/SelfCostProductSearch.php [new file with mode: 0644]
erp24/views/crud/employee-payment/_search.php
erp24/views/self-cost-product/index.php [new file with mode: 0644]

diff --git a/erp24/controllers/SelfCostProductController.php b/erp24/controllers/SelfCostProductController.php
new file mode 100644 (file)
index 0000000..356acae
--- /dev/null
@@ -0,0 +1,38 @@
+<?php
+
+namespace app\controllers;
+
+use Yii;
+use yii\helpers\ArrayHelper;
+use yii_app\records\CityStore;
+use yii_app\records\SelfCostProduct;
+use yii_app\records\SelfCostProductSearch;
+use yii\web\Controller;
+use yii\web\NotFoundHttpException;
+
+class SelfCostProductController extends Controller
+{
+    public function actionIndex()
+    {
+        $searchModel = new SelfCostProductSearch();
+        $dataProvider = $searchModel->search(Yii::$app->request->queryParams);
+
+        $stores = ArrayHelper::map(CityStore::find()->all(), 'id', 'name');
+
+
+        return $this->render('index', [
+            'searchModel' => $searchModel,
+            'dataProvider' => $dataProvider,
+            'stores' => $stores
+        ]);
+    }
+
+    protected function findModel($id)
+    {
+        if (($model = SelfCostProduct::findOne($id)) !== null) {
+            return $model;
+        }
+
+        throw new NotFoundHttpException('The requested page does not exist.');
+    }
+}
\ No newline at end of file
diff --git a/erp24/records/SelfCostProductSearch.php b/erp24/records/SelfCostProductSearch.php
new file mode 100644 (file)
index 0000000..63d00b1
--- /dev/null
@@ -0,0 +1,56 @@
+<?php
+
+namespace yii_app\records;
+
+use yii\base\Model;
+use yii\data\ActiveDataProvider;
+use yii_app\records\SelfCostProduct;
+
+class SelfCostProductSearch extends SelfCostProduct
+{
+    public function rules()
+    {
+        return [
+            [['id', 'store_id'], 'integer'],
+            [['date', 'product_guid', 'updated_at'], 'safe'],
+            [['price'], 'number'],
+        ];
+    }
+
+    public function search($params)
+    {
+        $query = SelfCostProduct::find();
+
+        $dataProvider = new ActiveDataProvider([
+            'query' => $query,
+            'pagination' => [
+                'pageSize' => 20,
+            ],
+            'sort' => [
+                'defaultOrder' => [
+                    'date' => SORT_DESC,
+                ]
+            ],
+        ]);
+
+        $this->load($params);
+
+        if (!$this->validate()) {
+            // если валидация не удалась, не возвращаем записи
+            $query->where('0=1');
+            return $dataProvider;
+        }
+
+        // Фильтрация по параметрам
+        $query->andFilterWhere([
+            'id' => $this->id,
+            'store_id' => $this->store_id,
+            'price' => $this->price,
+            'date' => $this->date,
+        ]);
+
+        $query->andFilterWhere(['like', 'product_guid', $this->product_guid]);
+
+        return $dataProvider;
+    }
+}
\ No newline at end of file
index ac3f00cd3cd8716b0008a54a4dab58f4c1513ca8..33da5db61cc5f415ed44c9ad7690fb28e8816494 100755 (executable)
@@ -65,7 +65,7 @@ use yii\widgets\ActiveForm;
 
     <div class="form-group">
         <?= Html::submitButton('Найти', ['class' => 'btn btn-primary']) ?>
-        <?= Html::resetButton('Сбросить фильтры', ['class' => 'btn btn-outline-secondary']) ?>
+        <?= Html::a('Сброс', ['index'], ['class' => 'btn btn-outline-secondary']) ?>
     </div>
 
     <?php ActiveForm::end(); ?>
diff --git a/erp24/views/self-cost-product/index.php b/erp24/views/self-cost-product/index.php
new file mode 100644 (file)
index 0000000..bca9b39
--- /dev/null
@@ -0,0 +1,73 @@
+<?php
+
+use kartik\select2\Select2;
+use yii\helpers\Html;
+use yii\grid\GridView;
+use yii\widgets\ActiveForm;
+
+/* @var $this yii\web\View */
+/* @var $searchModel yii_app\records\SelfCostProductSearch */
+/* @var $dataProvider yii\data\ActiveDataProvider */
+/** @var $stores array */
+
+$this->title = 'Себестоимость товаров';
+$this->params['breadcrumbs'][] = $this->title;
+?>
+<div class="self-cost-product-index p-4">
+
+    <h1><?= Html::encode($this->title) ?></h1>
+
+    <div class="self-cost-product-search">
+        <?php $form = ActiveForm::begin([
+            'action' => ['index'],
+            'method' => 'get',
+        ]); ?>
+
+        <div class="row">
+
+            <div class="col-3"><?= $form->field($searchModel, 'date', [])->input('date')->label('Дата') ?></div>
+            <div class="col-3">
+
+                <?= $form->field($searchModel, 'store_id')->widget(Select2::class, [
+                    'data' => $stores,
+                    'language' => 'ru',
+                    'options' => ['placeholder' => 'Магазин...'],
+                    'pluginOptions' => [
+                        'allowClear' => true
+                    ],
+                ])->label('Магазин ID') ?>
+            </div>
+            <div class="col-3"> <?= $form->field($searchModel, 'product_guid')->label('Товар GUID') ?></div>
+            <div class="col-3"><?= $form->field($searchModel, 'price')->label('Цена') ?></div>
+        </div>
+
+
+
+
+
+        <div class="form-group">
+            <?= Html::submitButton('Искать', ['class' => 'btn btn-primary']) ?>
+            <?= Html::a('Сброс', ['index'], ['class' => 'btn btn-outline-secondary']) ?>
+        </div>
+
+        <?php ActiveForm::end(); ?>
+    </div>
+
+    <?= GridView::widget([
+        'dataProvider' => $dataProvider,
+        'filterModel' => $searchModel,
+        'columns' => [
+            ['class' => 'yii\grid\SerialColumn'],
+
+            'id',
+            'date:text:Дата',
+            'store_id:text:Магазин',
+            'product_guid:text:GUID товара',
+            'price:text:Цена',
+            'updated_at:text:Обновлено',
+
+
+        ],
+    ]); ?>
+
+</div>