bakance_filter
This commit is contained in:
parent
b2312730c3
commit
91e3608c47
@ -24,6 +24,11 @@ class BalanceController extends Controller
|
||||
$searchModel->dt_from = date('Y-m-01');
|
||||
$searchModel->dt_to = date('Y-m-t');
|
||||
}
|
||||
if(\Yii::$app->request->get('previous_month'))
|
||||
{
|
||||
$searchModel->dt_from = date('Y-m-d', strtotime('first day of previous month'));
|
||||
$searchModel->dt_to = date('Y-m-d', strtotime('last day of previous month'));
|
||||
}
|
||||
$dataProvider = $searchModel->search(Yii::$app->request->queryParams);
|
||||
|
||||
return $this->render('index',[
|
||||
@ -34,10 +39,6 @@ class BalanceController extends Controller
|
||||
|
||||
public function actionView($id)
|
||||
{
|
||||
$model = Balance::find()
|
||||
->where(['id' => $id])
|
||||
->with('fieldsValues')
|
||||
->one();
|
||||
$dataProviderF = new ActiveDataProvider([
|
||||
'query' => FieldsValueNew::find()
|
||||
->where(['item_id' => $id, 'item_type' => FieldsValueNew::TYPE_BALANCE])
|
||||
@ -73,7 +74,7 @@ class BalanceController extends Controller
|
||||
|
||||
public function actionUpdate($id)
|
||||
{
|
||||
$model = $this->findModel($id);
|
||||
$model = $this->findModel($id);
|
||||
|
||||
if ($model->load(Yii::$app->request->post())) {
|
||||
$model->dt_add = strtotime($model->dt_add);
|
||||
@ -81,7 +82,7 @@ class BalanceController extends Controller
|
||||
return $this->redirect(['view', 'id' => $model->id]);
|
||||
}
|
||||
|
||||
return $this->render('update',[
|
||||
return $this->render('update', [
|
||||
'model' => $model,
|
||||
]);
|
||||
}
|
||||
|
@ -10,6 +10,14 @@ use common\models\FieldsValueNew;
|
||||
use common\models\ProjectUser;
|
||||
use yii\helpers\ArrayHelper;
|
||||
|
||||
/**
|
||||
* This is the model class for table "company".
|
||||
*
|
||||
* @property int $id
|
||||
* @property int $type
|
||||
* @property int $summ
|
||||
* @property int $dt_add
|
||||
*/
|
||||
class Balance extends \common\models\Balance
|
||||
{
|
||||
|
||||
|
@ -19,14 +19,17 @@ class BalanceSearch extends Balance
|
||||
public $summ_to;
|
||||
public $dt_from;
|
||||
public $dt_to;
|
||||
public $field_name;
|
||||
public $field_value;
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function rules()
|
||||
{
|
||||
return [
|
||||
[['id', 'type', 'summ', 'summ_from', 'summ_to'], 'integer'],
|
||||
[['id', 'type', 'summ', 'summ_from', 'field_name', 'summ_to'], 'integer'],
|
||||
[['dt_from', 'dt_to', 'dt_add'], 'safe'],
|
||||
[['field_value'], 'string']
|
||||
];
|
||||
}
|
||||
|
||||
@ -49,7 +52,7 @@ class BalanceSearch extends Balance
|
||||
public function search($params)
|
||||
{
|
||||
$query = Balance::find();
|
||||
|
||||
$query->leftJoin('fields_value_new','fields_value_new.item_id=balance.id AND fields_value_new.item_type=3');
|
||||
// add conditions that should always apply here
|
||||
$dataProvider = new ActiveDataProvider([
|
||||
'query' => $query,
|
||||
@ -63,6 +66,7 @@ class BalanceSearch extends Balance
|
||||
return $dataProvider;
|
||||
}
|
||||
|
||||
|
||||
// grid filtering conditions
|
||||
$query->andFilterWhere([
|
||||
'id' => $this->id,
|
||||
@ -76,6 +80,10 @@ class BalanceSearch extends Balance
|
||||
|
||||
|
||||
$query->andFilterWhere(['between', 'summ', $this->summ_from ?: 0, $this->summ_to ?: 9999999999]);
|
||||
$query->andFilterWhere(['fields_value_new.field_id'=>$this->field_name]);
|
||||
$query->andFilterWhere(['LIKE', 'fields_value_new.value', $this->field_value]);
|
||||
|
||||
$query->orderBy('balance.dt_add DESC');
|
||||
|
||||
return $dataProvider;
|
||||
}
|
||||
|
@ -19,8 +19,10 @@ $this->params['breadcrumps'][] = $this->title;
|
||||
<?= Html::a('Добавить', ['create'], ['class' => 'btn btn-success']) ?>
|
||||
</p>
|
||||
<p>
|
||||
<?= Html::a('Показать за прошлый месяц', ['index', 'previous_month' => true], ['class' => 'btn btn-primary']) ?>
|
||||
<?= Html::a('Показать за текущий месяц', ['index', 'month' => true], ['class' => 'btn btn-primary']) ?>
|
||||
</p>
|
||||
<!-- --><?php //\common\classes\Debug::dd($searchModel->fields); ?>
|
||||
<?= GridView::widget([
|
||||
'dataProvider' => $dataProvider,
|
||||
'filterModel' => $searchModel,
|
||||
@ -72,6 +74,7 @@ $this->params['breadcrumps'][] = $this->title;
|
||||
|
||||
]);
|
||||
},
|
||||
'filter' => \backend\widgets\AdditionalFieldsFilterWidget::widget(['model' => $searchModel]),
|
||||
'headerOptions' => ['width' => '300'],
|
||||
|
||||
],
|
||||
|
18
backend/widgets/AdditionalFieldsFilterWidget.php
Normal file
18
backend/widgets/AdditionalFieldsFilterWidget.php
Normal file
@ -0,0 +1,18 @@
|
||||
<?php
|
||||
|
||||
|
||||
namespace backend\widgets;
|
||||
|
||||
|
||||
use yii\base\Widget;
|
||||
|
||||
class AdditionalFieldsFilterWidget extends Widget
|
||||
{
|
||||
public $model;
|
||||
|
||||
public function run()
|
||||
{
|
||||
return $this->render('additional_fields_filter', ['model' => $this->model]);
|
||||
}
|
||||
|
||||
}
|
19
backend/widgets/views/additional_fields_filter.php
Normal file
19
backend/widgets/views/additional_fields_filter.php
Normal file
@ -0,0 +1,19 @@
|
||||
<?php
|
||||
/**
|
||||
* @var $model \yii\db\ActiveRecord
|
||||
*/
|
||||
|
||||
echo \kartik\select2\Select2::widget(
|
||||
[
|
||||
'model' => $model,
|
||||
'attribute' => 'field_name',
|
||||
'data' => \common\models\Balance::getNameList(),
|
||||
'options' => ['placeholder' => 'Выбрать параметр','class' => 'form-control'],
|
||||
'pluginOptions' => [
|
||||
'allowClear' => true
|
||||
],
|
||||
]);
|
||||
|
||||
echo \yii\helpers\Html::activeTextInput($model, 'field_value', [
|
||||
'placeholder' => 'Значение параметра'
|
||||
]);
|
@ -4,6 +4,9 @@
|
||||
namespace common\models;
|
||||
|
||||
use common\classes\Debug;
|
||||
use PHPUnit\Framework\MockObject\Matcher\DeferredError;
|
||||
use yii\db\Query;
|
||||
use yii\helpers\ArrayHelper;
|
||||
|
||||
/**
|
||||
* This is the model class for table "company".
|
||||
@ -26,14 +29,12 @@ class Balance extends \yii\db\ActiveRecord
|
||||
$fieldValue = FieldsValueNew::find()
|
||||
->where(
|
||||
[
|
||||
//'balance_id' => \Yii::$app->request->get('id'),
|
||||
'item_id' => $this->id,
|
||||
'item_id' => \Yii::$app->request->get('id'),
|
||||
// 'item_id' => $this->id,
|
||||
'item_type' => FieldsValueNew::TYPE_BALANCE,
|
||||
])
|
||||
->with('field')
|
||||
->all();
|
||||
// Debug::dd($fieldValue[0]->field->name);
|
||||
|
||||
$array = [];
|
||||
if (!empty($fieldValue)) {
|
||||
foreach ($fieldValue as $item) {
|
||||
@ -76,6 +77,11 @@ class Balance extends \yii\db\ActiveRecord
|
||||
];
|
||||
}
|
||||
|
||||
public static function getNameList()
|
||||
{
|
||||
return ArrayHelper::map(AdditionalFields::find()->all(),'id','name');
|
||||
}
|
||||
|
||||
public static function tableName()
|
||||
{
|
||||
return 'balance';
|
||||
@ -95,6 +101,7 @@ class Balance extends \yii\db\ActiveRecord
|
||||
'type' => 'Тип',
|
||||
'summ' => 'Сумма',
|
||||
'dt_add' => 'Дата добавления',
|
||||
'value' => 'Значение',
|
||||
];
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user