bakance_filter

This commit is contained in:
SoHardKI
2019-06-26 14:03:42 +03:00
parent b2312730c3
commit 91e3608c47
7 changed files with 76 additions and 12 deletions

View File

@ -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,
]);
}

View File

@ -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
{

View File

@ -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;
}

View File

@ -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'],
],