new balance

This commit is contained in:
2019-06-25 12:37:09 +03:00
parent a783be26d1
commit 2f4f92bdec
16 changed files with 523 additions and 58 deletions

View File

@ -5,7 +5,10 @@ namespace backend\modules\balance\controllers;
use backend\modules\balance\models\Balance;
use backend\modules\balance\models\BalanceSearch;
use common\classes\Debug;
use common\models\FieldsValue;
use common\models\FieldsValueNew;
use Yii;
use yii\data\ActiveDataProvider;
use yii\web\Controller;
use yii\web\NotFoundHttpException;
use yii\db\Query;
@ -15,7 +18,7 @@ class BalanceController extends Controller
public function actionIndex()
{
$searchModel = new BalanceSearch();
$dataProvider = $searchModel->search();
$dataProvider = $searchModel->search(Yii::$app->request->queryParams);
return $this->render('index',[
'searchModel' => $searchModel,
@ -25,8 +28,18 @@ class BalanceController extends Controller
public function actionView($id)
{
$dataProviderF = new ActiveDataProvider([
'query' => FieldsValueNew::find()
->where(['item_id' => $id, 'item_type' => FieldsValueNew::TYPE_BALANCE])
->orderBy('order'),
'pagination' => [
'pageSize' => 200,
],
]);
return $this->render('view',[
'model' => $this->findModel($id),
'dataProviderF' => $dataProviderF
]);
}
@ -53,7 +66,9 @@ class BalanceController extends Controller
{
$model = $this->findModel($id);
if ($model->load(Yii::$app->request->post()) && $model->save()) {
if ($model->load(Yii::$app->request->post())) {
$model->dt_add = strtotime($model->dt_add);
$model->save();
return $this->redirect(['view', 'id' => $model->id]);
}

View File

@ -5,20 +5,23 @@ namespace backend\modules\balance\models;
use common\models\FieldsValue;
use common\models\FieldsValueNew;
use common\models\ProjectUser;
use yii\helpers\ArrayHelper;
class Balance extends \common\models\Balance
{
public $fields;
public function init()
{
parent::init();
$fieldValue = FieldsValue::find()
$fieldValue = FieldsValueNew::find()
->where(
[
'balance_id' => \Yii::$app->request->get('id'),
'card_id' => null,
'company_id' => null,
//'balance_id' => \Yii::$app->request->get('id'),
'item_id' => \Yii::$app->request->get('id'),
'item_type' => FieldsValueNew::TYPE_BALANCE,
])
->all();
$array = [];
@ -37,12 +40,12 @@ class Balance extends \common\models\Balance
];
}
$user = ArrayHelper::getColumn(ProjectUser::find()->where(['project_id' => \Yii::$app->request->get('id')])->all(),
'card_id');
if (!empty($user)) {
$this->user = $user;
}
// $user = ArrayHelper::getColumn(ProjectUser::find()->where(['project_id' => \Yii::$app->request->get('id')])->all(),
// 'card_id');
//
// if (!empty($user)) {
// $this->user = $user;
//
// }
}
}

View File

@ -1,30 +1,89 @@
<?php
namespace backend\modules\balance\models;
use common\classes\Debug;
use Yii;
use yii\base\Model;
use yii\data\ActiveDataProvider;
use backend\modules\balance\models\Balance;
/**
* BalanceSearch represents the model behind the search form of `backend\modules\balance\models\Balance`.
*/
class BalanceSearch extends Balance
{
public function scenarios()
public $summ_from;
public $summ_to;
public $dt_from;
public $dt_to;
/**
* {@inheritdoc}
*/
public function rules()
{
return Model::scenarios(); // TODO: Change the autogenerated stub
return [
[['id', 'type', 'summ', 'summ_from', 'summ_to'], 'integer'],
[['dt_from', 'dt_to', 'dt_add'], 'safe'],
];
}
public function search()
/**
* {@inheritdoc}
*/
public function scenarios()
{
// bypass scenarios() implementation in the parent class
return Model::scenarios();
}
/**
* Creates data provider instance with search query applied
*
* @param array $params
*
* @return ActiveDataProvider
*/
public function search($params)
{
$query = Balance::find();
// add conditions that should always apply here
$dataProvider = new ActiveDataProvider([
'query' => $query,
]);
if($this->validate())
{
$this->load($params);
if (!$this->validate()) {
// uncomment the following line if you do not want to return any records when validation fails
// $query->where('0=1');
return $dataProvider;
}
// grid filtering conditions
$query->andFilterWhere([
'id' => $this->id,
'type' => $this->type,
//'summ' => $this->summ,
'dt_add' => $this->dt_add,
]);
//Debug::dd($this);
if($this->dt_from && $this->dt_to){
$query->where(['between', 'dt_add', strtotime($this->$this->dt_from), strtotime($this->$this->dt_to)]);
}
if($this->dt_from){
$query->where(['>', 'dt_add', strtotime($this->$this->dt_from)]);
}
$summ_from = $this->summ_from ?: 0;
$summ_to = $this->summ_to ?: 9999999999;
$query->andFilterWhere(['between', 'summ', $summ_from, $summ_to]);
return $dataProvider;
}
}
}

View File

@ -17,12 +17,7 @@ use yii\widgets\ActiveForm;
<?php $form = ActiveForm::begin(); ?>
<?= $form->field($model, 'type')
->dropDownList(
[
'1' => 'активный',
'0' => 'пассивный',
]
)?>
->dropDownList(\common\models\Balance::getTypeList())?>
<?= $form->field($model, 'summ')->textInput(['maxlength' => 9]) ?>

View File

@ -0,0 +1,33 @@
<?php
use yii\helpers\Html;
use yii\widgets\ActiveForm;
/* @var $this yii\web\View */
/* @var $model backend\modules\balance\models\BalanceSearch */
/* @var $form yii\widgets\ActiveForm */
?>
<div class="balance-search">
<?php $form = ActiveForm::begin([
'action' => ['index'],
'method' => 'get',
]); ?>
<?= $form->field($model, 'id') ?>
<?= $form->field($model, 'type') ?>
<?= $form->field($model, 'summ') ?>
<?= $form->field($model, 'dt_add') ?>
<div class="form-group">
<?= Html::submitButton('Search', ['class' => 'btn btn-primary']) ?>
<?= Html::resetButton('Reset', ['class' => 'btn btn-default']) ?>
</div>
<?php ActiveForm::end(); ?>
</div>

View File

@ -1,5 +1,6 @@
<?php
use kartik\select2\Select2;
use yii\data\ActiveDataProvider;
use yii\helpers\Html;
use yii\grid\GridView;
@ -21,9 +22,34 @@ $this->params['breadcrumps'][] = $this->title;
'filterModel' => $searchModel,
'columns' => [
['class' => 'yii\grid\SerialColumn'],
'type',
'summ',
'dt_add',
[
'attribute' => 'type',
'value' => function ($model) {
return \common\models\Balance::getTypeName($model->type);
},
'filter' => kartik\select2\Select2::widget([
'model' => $searchModel,
'attribute' => 'type',
'data' => \common\models\Balance::getTypeList(),
'options' => ['placeholder' => 'Начните вводить...','class' => 'form-control'],
'pluginOptions' => [
'allowClear' => true
],
]),
],
[
'attribute' => 'summ',
'filter' => \backend\widgets\SummRangeWidget::widget([
'model' => $searchModel,
]),
],
[
'attribute' => 'dt_add',
'value' => 'dt_add',
'filter' => \yii\jui\DatePicker::widget(['language' => 'ru', 'dateFormat' => 'dd-MM-yyyy']),
'format' => 'html',
],
['class' => 'yii\grid\ActionColumn'],
],
]); ?>

View File

@ -1,9 +1,11 @@
<?php
use yii\grid\GridView;
use yii\helpers\Html;
use yii\widgets\DetailView;
/* @var $this yii\web\View */
/* @var $dataProviderF \yii\data\ActiveDataProvider
/* @var $model backend\modules\balance\models\Balance */
$this->title = 'Баланс №' . $model->id;
@ -12,8 +14,9 @@ $this->params['breadcrumbs'][] = $this->title;
?>
<div class="balance-view">
<p>
<?= Html::a('Update', ['update', 'id' => $model->id], ['class' => 'btn btn-primary']) ?>
<?= Html::a('Delete', ['delete', 'id' => $model->id], [
<?= Html::a('Список', ['index'], ['class' => 'btn btn-primary']) ?>
<?= Html::a('Редактировать', ['update', 'id' => $model->id], ['class' => 'btn btn-primary']) ?>
<?= Html::a('Удалить', ['delete', 'id' => $model->id], [
'class' => 'btn btn-danger',
'data' => [
'confirm' => 'Are you sure you want to delete this item?',
@ -25,11 +28,30 @@ $this->params['breadcrumbs'][] = $this->title;
<?= DetailView::widget([
'model' => $model,
'attributes' => [
'id',
'type',
//'id',
[
'attribute' => 'type',
'value' => function($model){
return \common\models\Balance::getTypeName($model->type);
}
],
'summ',
'dt_add',
],
]) ?>
<h2>Дополнительные сведения</h2>
<?= GridView::widget([
'dataProvider' => $dataProviderF,
'layout' => "{items}",
'columns' => [
'field.name:text:Поле',
[
'attribute' => 'value',
'label' => 'Значение'
],
],
]); ?>
</div>