--- /dev/null
+<?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
--- /dev/null
+<?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
<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(); ?>
--- /dev/null
+<?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>