add_additional_fields
This commit is contained in:
parent
fe56d217c8
commit
b2312730c3
@ -7,6 +7,7 @@ use backend\modules\balance\models\BalanceSearch;
|
|||||||
use common\classes\Debug;
|
use common\classes\Debug;
|
||||||
use common\models\FieldsValue;
|
use common\models\FieldsValue;
|
||||||
use common\models\FieldsValueNew;
|
use common\models\FieldsValueNew;
|
||||||
|
use DateTime;
|
||||||
use Yii;
|
use Yii;
|
||||||
use yii\data\ActiveDataProvider;
|
use yii\data\ActiveDataProvider;
|
||||||
use yii\web\Controller;
|
use yii\web\Controller;
|
||||||
@ -18,6 +19,11 @@ class BalanceController extends Controller
|
|||||||
public function actionIndex()
|
public function actionIndex()
|
||||||
{
|
{
|
||||||
$searchModel = new BalanceSearch();
|
$searchModel = new BalanceSearch();
|
||||||
|
if(\Yii::$app->request->get('month'))
|
||||||
|
{
|
||||||
|
$searchModel->dt_from = date('Y-m-01');
|
||||||
|
$searchModel->dt_to = date('Y-m-t');
|
||||||
|
}
|
||||||
$dataProvider = $searchModel->search(Yii::$app->request->queryParams);
|
$dataProvider = $searchModel->search(Yii::$app->request->queryParams);
|
||||||
|
|
||||||
return $this->render('index',[
|
return $this->render('index',[
|
||||||
@ -28,6 +34,10 @@ class BalanceController extends Controller
|
|||||||
|
|
||||||
public function actionView($id)
|
public function actionView($id)
|
||||||
{
|
{
|
||||||
|
$model = Balance::find()
|
||||||
|
->where(['id' => $id])
|
||||||
|
->with('fieldsValues')
|
||||||
|
->one();
|
||||||
$dataProviderF = new ActiveDataProvider([
|
$dataProviderF = new ActiveDataProvider([
|
||||||
'query' => FieldsValueNew::find()
|
'query' => FieldsValueNew::find()
|
||||||
->where(['item_id' => $id, 'item_type' => FieldsValueNew::TYPE_BALANCE])
|
->where(['item_id' => $id, 'item_type' => FieldsValueNew::TYPE_BALANCE])
|
||||||
@ -50,7 +60,6 @@ class BalanceController extends Controller
|
|||||||
if ($model->load(Yii::$app->request->post())) {
|
if ($model->load(Yii::$app->request->post())) {
|
||||||
$model->dt_add = strtotime($model->dt_add);
|
$model->dt_add = strtotime($model->dt_add);
|
||||||
$model->save();
|
$model->save();
|
||||||
// Debug::dd($model);
|
|
||||||
|
|
||||||
Yii::$app->session->addFlash('success', 'Баланса добавлен');
|
Yii::$app->session->addFlash('success', 'Баланса добавлен');
|
||||||
|
|
||||||
@ -92,4 +101,5 @@ class BalanceController extends Controller
|
|||||||
|
|
||||||
throw new NotFoundHttpException('The requested page does not exist.');
|
throw new NotFoundHttpException('The requested page does not exist.');
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
@ -4,6 +4,7 @@
|
|||||||
namespace backend\modules\balance\models;
|
namespace backend\modules\balance\models;
|
||||||
|
|
||||||
|
|
||||||
|
use common\classes\Debug;
|
||||||
use common\models\FieldsValue;
|
use common\models\FieldsValue;
|
||||||
use common\models\FieldsValueNew;
|
use common\models\FieldsValueNew;
|
||||||
use common\models\ProjectUser;
|
use common\models\ProjectUser;
|
||||||
@ -11,41 +12,5 @@ use yii\helpers\ArrayHelper;
|
|||||||
|
|
||||||
class Balance extends \common\models\Balance
|
class Balance extends \common\models\Balance
|
||||||
{
|
{
|
||||||
public $fields;
|
|
||||||
|
|
||||||
public function init()
|
|
||||||
{
|
|
||||||
parent::init();
|
|
||||||
$fieldValue = FieldsValueNew::find()
|
|
||||||
->where(
|
|
||||||
[
|
|
||||||
//'balance_id' => \Yii::$app->request->get('id'),
|
|
||||||
'item_id' => \Yii::$app->request->get('id'),
|
|
||||||
'item_type' => FieldsValueNew::TYPE_BALANCE,
|
|
||||||
])
|
|
||||||
->all();
|
|
||||||
$array = [];
|
|
||||||
if (!empty($fieldValue)) {
|
|
||||||
foreach ($fieldValue as $item) {
|
|
||||||
array_push($array, ['field_id' => $item->field_id, 'value' => $item->value, 'order' => $item->order]);
|
|
||||||
}
|
|
||||||
$this->fields = $array;
|
|
||||||
} else {
|
|
||||||
$this->fields = [
|
|
||||||
[
|
|
||||||
'field_id' => null,
|
|
||||||
'value' => null,
|
|
||||||
'order' => null,
|
|
||||||
],
|
|
||||||
];
|
|
||||||
}
|
|
||||||
|
|
||||||
// $user = ArrayHelper::getColumn(ProjectUser::find()->where(['project_id' => \Yii::$app->request->get('id')])->all(),
|
|
||||||
// 'card_id');
|
|
||||||
//
|
|
||||||
// if (!empty($user)) {
|
|
||||||
// $this->user = $user;
|
|
||||||
//
|
|
||||||
// }
|
|
||||||
}
|
|
||||||
}
|
}
|
@ -3,6 +3,8 @@
|
|||||||
namespace backend\modules\balance\models;
|
namespace backend\modules\balance\models;
|
||||||
|
|
||||||
use common\classes\Debug;
|
use common\classes\Debug;
|
||||||
|
use common\models\FieldsValueNew;
|
||||||
|
use DateTime;
|
||||||
use Yii;
|
use Yii;
|
||||||
use yii\base\Model;
|
use yii\base\Model;
|
||||||
use yii\data\ActiveDataProvider;
|
use yii\data\ActiveDataProvider;
|
||||||
@ -49,7 +51,6 @@ class BalanceSearch extends Balance
|
|||||||
$query = Balance::find();
|
$query = Balance::find();
|
||||||
|
|
||||||
// add conditions that should always apply here
|
// add conditions that should always apply here
|
||||||
|
|
||||||
$dataProvider = new ActiveDataProvider([
|
$dataProvider = new ActiveDataProvider([
|
||||||
'query' => $query,
|
'query' => $query,
|
||||||
]);
|
]);
|
||||||
@ -70,19 +71,11 @@ class BalanceSearch extends Balance
|
|||||||
'dt_add' => $this->dt_add,
|
'dt_add' => $this->dt_add,
|
||||||
]);
|
]);
|
||||||
|
|
||||||
//Debug::dd($this);
|
$query->andFilterWhere(['>=','dt_add', strtotime($this->dt_from) ?: null]);
|
||||||
|
$query->andFilterWhere(['<=','dt_add', strtotime($this->dt_to) ?: null]);
|
||||||
|
|
||||||
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;
|
$query->andFilterWhere(['between', 'summ', $this->summ_from ?: 0, $this->summ_to ?: 9999999999]);
|
||||||
$summ_to = $this->summ_to ?: 9999999999;
|
|
||||||
|
|
||||||
$query->andFilterWhere(['between', 'summ', $summ_from, $summ_to]);
|
|
||||||
|
|
||||||
return $dataProvider;
|
return $dataProvider;
|
||||||
}
|
}
|
||||||
|
2
backend/modules/balance/views/balance/_additional.php
Normal file
2
backend/modules/balance/views/balance/_additional.php
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
<?= $model->field->name;?> -
|
||||||
|
<?= $model->value;?>
|
@ -5,6 +5,7 @@ use yii\data\ActiveDataProvider;
|
|||||||
use yii\helpers\Html;
|
use yii\helpers\Html;
|
||||||
use yii\grid\GridView;
|
use yii\grid\GridView;
|
||||||
use yii\web\View;
|
use yii\web\View;
|
||||||
|
use yii\widgets\ListView;
|
||||||
|
|
||||||
/* @var $this yii\web\View */
|
/* @var $this yii\web\View */
|
||||||
/* @var $searchModel backend\modules\company\models\BalanceSearch */
|
/* @var $searchModel backend\modules\company\models\BalanceSearch */
|
||||||
@ -17,6 +18,9 @@ $this->params['breadcrumps'][] = $this->title;
|
|||||||
<p>
|
<p>
|
||||||
<?= Html::a('Добавить', ['create'], ['class' => 'btn btn-success']) ?>
|
<?= Html::a('Добавить', ['create'], ['class' => 'btn btn-success']) ?>
|
||||||
</p>
|
</p>
|
||||||
|
<p>
|
||||||
|
<?= Html::a('Показать за текущий месяц', ['index', 'month' => true], ['class' => 'btn btn-primary']) ?>
|
||||||
|
</p>
|
||||||
<?= GridView::widget([
|
<?= GridView::widget([
|
||||||
'dataProvider' => $dataProvider,
|
'dataProvider' => $dataProvider,
|
||||||
'filterModel' => $searchModel,
|
'filterModel' => $searchModel,
|
||||||
@ -47,9 +51,30 @@ $this->params['breadcrumps'][] = $this->title;
|
|||||||
[
|
[
|
||||||
'attribute' => 'dt_add',
|
'attribute' => 'dt_add',
|
||||||
'value' => 'dt_add',
|
'value' => 'dt_add',
|
||||||
'filter' => \yii\jui\DatePicker::widget(['language' => 'ru', 'dateFormat' => 'dd-MM-yyyy']),
|
'filter' => \backend\widgets\DateRangeWidget::widget([
|
||||||
|
// 'language' => 'ru',
|
||||||
|
// 'dateFormat' => 'dd-MM-yyyy'
|
||||||
|
'model' => $searchModel,
|
||||||
|
]),
|
||||||
'format' => 'html',
|
'format' => 'html',
|
||||||
],
|
],
|
||||||
|
[
|
||||||
|
'label' => 'Доп. информация',
|
||||||
|
'format' => 'raw',
|
||||||
|
'value' => function ($model) {
|
||||||
|
$dataProvider = new ActiveDataProvider([
|
||||||
|
'query' => $model->getFieldsValues(),
|
||||||
|
]);
|
||||||
|
return ListView::widget([
|
||||||
|
'dataProvider' => $dataProvider,
|
||||||
|
'itemView' => '_additional',
|
||||||
|
'layout' => "{items}",
|
||||||
|
|
||||||
|
]);
|
||||||
|
},
|
||||||
|
'headerOptions' => ['width' => '300'],
|
||||||
|
|
||||||
|
],
|
||||||
['class' => 'yii\grid\ActionColumn'],
|
['class' => 'yii\grid\ActionColumn'],
|
||||||
],
|
],
|
||||||
]); ?>
|
]); ?>
|
||||||
|
@ -4,11 +4,13 @@
|
|||||||
namespace backend\widgets;
|
namespace backend\widgets;
|
||||||
|
|
||||||
|
|
||||||
|
use common\classes\Debug;
|
||||||
use yii\base\Widget;
|
use yii\base\Widget;
|
||||||
|
|
||||||
class DateRangeWidget extends Widget
|
class DateRangeWidget extends Widget
|
||||||
{
|
{
|
||||||
public $model;
|
public $model;
|
||||||
|
public $range_attribute;
|
||||||
|
|
||||||
public function run()
|
public function run()
|
||||||
{
|
{
|
||||||
|
@ -4,6 +4,7 @@
|
|||||||
namespace backend\widgets;
|
namespace backend\widgets;
|
||||||
|
|
||||||
|
|
||||||
|
use common\classes\Debug;
|
||||||
use yii\base\Widget;
|
use yii\base\Widget;
|
||||||
|
|
||||||
class SummRangeWidget extends Widget
|
class SummRangeWidget extends Widget
|
||||||
|
@ -9,6 +9,7 @@ echo DatePicker::widget([
|
|||||||
'attribute' => 'dt_from',
|
'attribute' => 'dt_from',
|
||||||
'language' => 'ru',
|
'language' => 'ru',
|
||||||
'dateFormat' => 'dd-MM-yyyy',
|
'dateFormat' => 'dd-MM-yyyy',
|
||||||
|
'options' => ['placeholder' => 'Выберите дату (От)'],
|
||||||
]);
|
]);
|
||||||
|
|
||||||
echo " - ";
|
echo " - ";
|
||||||
@ -18,4 +19,5 @@ echo DatePicker::widget([
|
|||||||
'attribute' => 'dt_to',
|
'attribute' => 'dt_to',
|
||||||
'language' => 'ru',
|
'language' => 'ru',
|
||||||
'dateFormat' => 'dd-MM-yyyy',
|
'dateFormat' => 'dd-MM-yyyy',
|
||||||
|
'options' => ['placeholder' => 'Выберите дату (До)'],
|
||||||
]);
|
]);
|
@ -18,6 +18,51 @@ class Balance extends \yii\db\ActiveRecord
|
|||||||
const TYPE_ACTIVE = 1;
|
const TYPE_ACTIVE = 1;
|
||||||
const TYPE_PASSIVE = 0;
|
const TYPE_PASSIVE = 0;
|
||||||
|
|
||||||
|
public $fields;
|
||||||
|
|
||||||
|
public function init()
|
||||||
|
{
|
||||||
|
parent::init();
|
||||||
|
$fieldValue = FieldsValueNew::find()
|
||||||
|
->where(
|
||||||
|
[
|
||||||
|
//'balance_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) {
|
||||||
|
array_push($array,
|
||||||
|
['field_id' => $item->field_id,
|
||||||
|
'value' => $item->value,
|
||||||
|
'order' => $item->order,
|
||||||
|
'field_name' => $item->field->name]);
|
||||||
|
}
|
||||||
|
$this->fields = $array;
|
||||||
|
} else {
|
||||||
|
$this->fields = [
|
||||||
|
[
|
||||||
|
'field_id' => null,
|
||||||
|
'value' => null,
|
||||||
|
'order' => null,
|
||||||
|
'field_name' => null,
|
||||||
|
],
|
||||||
|
];
|
||||||
|
}
|
||||||
|
// $user = ArrayHelper::getColumn(ProjectUser::find()->where(['project_id' => \Yii::$app->request->get('id')])->all(),
|
||||||
|
// 'card_id');
|
||||||
|
//
|
||||||
|
// if (!empty($user)) {
|
||||||
|
// $this->user = $user;
|
||||||
|
//
|
||||||
|
// }
|
||||||
|
}
|
||||||
|
|
||||||
public static function getTypeName($id)
|
public static function getTypeName($id)
|
||||||
{
|
{
|
||||||
return self::getTypeList()[$id];
|
return self::getTypeList()[$id];
|
||||||
@ -64,7 +109,7 @@ class Balance extends \yii\db\ActiveRecord
|
|||||||
*/
|
*/
|
||||||
public function getFieldsValues()
|
public function getFieldsValues()
|
||||||
{
|
{
|
||||||
return $this->hasMany(FieldsValueNew::class, ['item_id' => 'id', 'item_type' => FieldsValueNew::TYPE_BALANCE]);
|
return $this->hasMany(FieldsValueNew::class, ['item_id' => 'id'])->where(['item_type' => FieldsValueNew::TYPE_BALANCE])->with('field');
|
||||||
}
|
}
|
||||||
|
|
||||||
public function afterSave($insert, $changedAttributes)
|
public function afterSave($insert, $changedAttributes)
|
||||||
|
@ -62,4 +62,9 @@ class FieldsValueNew extends \yii\db\ActiveRecord
|
|||||||
{
|
{
|
||||||
return $this->hasOne(AdditionalFields::class, ['id' => 'field_id']);
|
return $this->hasOne(AdditionalFields::class, ['id' => 'field_id']);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// public function getadditional_fields()
|
||||||
|
// {
|
||||||
|
//
|
||||||
|
// }
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user