add backend transfer list changes

This commit is contained in:
2015-10-13 09:27:56 +02:00
parent fda450b801
commit b04cbda645
20 changed files with 677 additions and 222 deletions

View File

@@ -8,6 +8,8 @@ use backend\models\TransferSearch;
use yii\web\Controller;
use yii\web\NotFoundHttpException;
use yii\filters\VerbFilter;
use common\models\Account;
use common\models\User;
/**
* TransferController implements the CRUD actions for Transfer model.
@@ -34,10 +36,20 @@ class TransferController extends Controller
{
$searchModel = new TransferSearch();
$dataProvider = $searchModel->search(Yii::$app->request->queryParams);
$accounts = Account::readAccounts();
$users = User::read();
$searchModel->totals(Yii::$app->request->queryParams);
return $this->render('index', [
'searchModel' => $searchModel,
'dataProvider' => $dataProvider,
'accounts' => $accounts,
'users' => $users,
// 'totals' =>$totals
]);
}

View File

@@ -77,7 +77,7 @@ class ProcurementSearch extends Procurement
'id_product' => $this->id_product,
]);
$query->andFilterWhere([ '>=', 'created_at', $this->date_start ] );
$query->andFilterWhere([ '>=', 'created_at', $this->timestampStart ] );
$query->andFilterWhere([ '<', 'created_at', $this->timestampEnd ] );

View File

@@ -6,20 +6,39 @@ use Yii;
use yii\base\Model;
use yii\data\ActiveDataProvider;
use common\models\Transfer;
use yii\db\Expression;
use yii\base\Object;
use yii\db\Query;
use yii\helpers\ArrayHelper;
use common\models\Account;
/**
* TransferSearch represents the model behind the search form about `common\models\Transfer`.
*/
class TransferSearch extends Transfer
{
public $searchObjectName;
public $searchTypeName;
public $searchUserName;
public $start;
public $end;
public $timestampStart;
public $timestampEnd;
public $accountTotals;
public $fullTotal;
/**
* @inheritdoc
*/
public function rules()
{
return [
[['id_transfer', 'id_discount', 'id_currency', 'id_object', 'status', 'type', 'item_price', 'count', 'money', 'money_currency', 'rate', 'id_user'], 'integer'],
[['comment', 'created_at', 'updated_at'], 'safe'],
[[ 'id_account','id_user', 'type'], 'integer'],
[[ 'searchObjectName' ], 'string'],
[[ 'start', ], 'date' , 'timestampAttribute' => 'timestampStart' ,'timestampAttributeFormat' => 'yyyy-MM-dd' ],
[[ 'end' , ], 'date' , 'timestampAttribute' => 'timestampEnd' ,'timestampAttributeFormat' => 'yyyy-MM-dd' ],
];
}
@@ -47,33 +66,108 @@ class TransferSearch extends Transfer
'query' => $query,
]);
$selectObjectName = "";
$selectObjectName .= " case when transfer.type = " .self::TYPE_PRODUCT ." then product.name else ticket_type.name end as object_name";
$query->addSelect( ['*', new Expression($selectObjectName) ]);
$query->joinWith('ticket');
$query->joinWith('ticketType');
$query->joinWith('product');
$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');
$query->where('0=1');
return $dataProvider;
}
$query->andFilterWhere([
'id_transfer' => $this->id_transfer,
'id_discount' => $this->id_discount,
'id_currency' => $this->id_currency,
'id_object' => $this->id_object,
'status' => $this->status,
'type' => $this->type,
'item_price' => $this->item_price,
'count' => $this->count,
'money' => $this->money,
'money_currency' => $this->money_currency,
'rate' => $this->rate,
'id_user' => $this->id_user,
'created_at' => $this->created_at,
'updated_at' => $this->updated_at,
'transfer.id_account' => $this->id_account,
'transfer.type' => $this->type,
'transfer.id_user' => $this->id_user,
]);
$query->andFilterWhere([ '>=', 'transfer.created_at', $this->timestampStart ] );
$query->andFilterWhere([ '<', 'transfer.created_at', $this->timestampEnd ] );
$query->andFilterWhere(['like', 'comment', $this->comment]);
if ( isset($this->searchObjectName))
$query->andWhere( new Expression(" case when transfer.type = " .self::TYPE_PRODUCT ." then product.name else ticket_type.name end like '%" . $this->searchObjectName ."%'"));
return $dataProvider;
}
public function totals($params){
$query = new Query();
$result = [ ];
$accountTotals = [];
$fullTotal = [
'label' => Yii::t('common/transfer', 'Total'),
'money' => 0
];
$query->addSelect( [ new Expression( 'transfer.id_account as account'), new Expression( ' COALESCE(sum( transfer.money ),0) as money' )]);
$query->from('transfer');
$query->leftJoin('ticket', 'transfer.type = ' .self::TYPE_TICKET .' and transfer.id_object = ticket.id_ticket ' );
$query->leftJoin('ticket_type', 'ticket.id_ticket_type = ticket_type.id_ticket_type ' );
$query->leftJoin('product', 'product.id_product = ' .self::TYPE_TICKET .' and transfer.id_object = ticket.id_ticket ' );
$this->load($params);
if (!$this->validate()) {
return ;
}
$query->andFilterWhere([
'transfer.id_account' => $this->id_account,
'transfer.type' => $this->type,
'transfer.id_user' => $this->id_user,
]);
$query->andFilterWhere([ '>=', 'transfer.created_at', $this->timestampStart ] );
$query->andFilterWhere([ '<', 'transfer.created_at', $this->timestampEnd ] );
if ( isset($this->searchObjectName) && !empty($this->searchObjectName)){
$query->andWhere( new Expression(" case when transfer.type = " .self::TYPE_PRODUCT ." then product.name else ticket_type.name end like '%" . $this->searchObjectName ."%'"));
}
$query->groupBy('transfer.id_account');
$command = $query->createCommand();
// $command->sql returns the actual SQL
$result = $command->queryAll();
$accounts = Account::find()->orderBy("name asc")->all();
$accountMap = ArrayHelper::map( $accounts ,'id_account','name' );
foreach ($result as $item){
$account = "";
if ( array_key_exists($item['account'], $accountMap)){
$account = $accountMap[$item['account']];
}
$accountTotal = [
'label' => $account,
'money' => $item['money']
];
$accountTotals[] = $accountTotal;
$fullTotal['money'] += $item['money'];
}
$this->accountTotals = $accountTotals;
$this->fullTotal = $fullTotal;
// return $result;
}
}

View File

@@ -2,52 +2,68 @@
use yii\helpers\Html;
use yii\widgets\ActiveForm;
use frontend\components\HtmlHelper;
use yii\helpers\ArrayHelper;
use common\models\Transfer;
use kartik\widgets\DatePicker;
/* @var $this yii\web\View */
/* @var $model backend\models\TransferSearch */
/* @var $form yii\widgets\ActiveForm */
?>
<?php
?>
<div class="transfer-search">
<?php $form = ActiveForm::begin([
'action' => ['index'],
'method' => 'get',
]); ?>
<div class='row'>
<div class='col-md-4'>
<?= $form->field($model, 'id_account')->dropDownList( ['' => Yii::t('common/transfer', 'All')] +HtmlHelper::mkAccountOptions($accounts) ) ?>
</div>
<div class='col-md-4'>
<?= $form->field($model, 'type')->dropDownList( ['' => Yii::t('common/transfer', 'All')] + Transfer::types() ) ?>
</div>
<div class='col-md-4'>
<?= $form->field($model, 'id_user')->dropDownList( ['' => Yii::t('common/transfer', 'All')] +ArrayHelper::map($users,'id' , 'username') ) ?>
</div>
</div>
<?= $form->field($model, 'id_transfer') ?>
<?= $form->field($model, 'id_discount') ?>
<?= $form->field($model, 'id_currency') ?>
<?= $form->field($model, 'id_object') ?>
<?= $form->field($model, 'status') ?>
<div class="row">
<div class='col-md-4'>
<?php echo $form->field($model, 'searchObjectName') ?>
</div>
<div class="col-md-4">
<?= $form->field($model, 'start')->widget(DatePicker::classname(), [
'pluginOptions' => [
'autoclose'=>true,
'format' => 'yyyy.mm.dd'
]
]) ?>
</div>
<div class="col-md-4">
<?= $form->field($model, 'end') ->widget(DatePicker::classname(), [
'pluginOptions' => [
'autoclose'=>true,
'format' => 'yyyy.mm.dd'
]
]) ?>
</div>
</div>
<?php // echo $form->field($model, 'type') ?>
<?php // echo $form->field($model, 'item_price') ?>
<?php // echo $form->field($model, 'count') ?>
<?php // echo $form->field($model, 'money') ?>
<?php // echo $form->field($model, 'money_currency') ?>
<?php // echo $form->field($model, 'rate') ?>
<?php // echo $form->field($model, 'id_user') ?>
<?php // echo $form->field($model, 'comment') ?>
<?php // echo $form->field($model, 'created_at') ?>
<?php // echo $form->field($model, 'updated_at') ?>
<div class="form-group">
<?= Html::submitButton(Yii::t('frontend/transfer', 'Search'), ['class' => 'btn btn-primary']) ?>
<?= Html::resetButton(Yii::t('frontend/transfer', 'Reset'), ['class' => 'btn btn-default']) ?>
</div>
<?php ActiveForm::end(); ?>

View File

@@ -2,6 +2,10 @@
use yii\helpers\Html;
use yii\grid\GridView;
use yii\widgets\DetailView;
use yii\base\Widget;
use yii\base\Object;
use yii\data\ArrayDataProvider;
/* @var $this yii\web\View */
/* @var $searchModel backend\models\TransferSearch */
@@ -13,30 +17,68 @@ $this->params['breadcrumbs'][] = $this->title;
<div class="transfer-index">
<h1><?= Html::encode($this->title) ?></h1>
<?php // echo $this->render('_search', ['model' => $searchModel]); ?>
<p>
<?= Html::a(Yii::t('frontend/transfer', 'Create Transfer'), ['create'], ['class' => 'btn btn-success']) ?>
</p>
<?php echo $this->render('_search', ['model' => $searchModel, 'accounts' => $accounts,'users' => $users,]); ?>
<?php
?>
<h2>Összesen</h2>
<?php
echo DetailView::widget([
'model' => $searchModel->fullTotal,
'attributes' => [
[
'value' => $searchModel->fullTotal['money'],
'label' => $searchModel->fullTotal['label'],
],
]
])
?>
<h2>Kasszák összesen</h2>
<?php
echo GridView::widget([
'dataProvider' => new ArrayDataProvider([
'allModels' => $searchModel->accountTotals,
'sort' => false,
'pagination' => false,
]) ,
'columns' => [
[
'label' => Yii::t('common/transfer','Account'),
'value' => 'label'
],
[
'label' => Yii::t('common/transfer','Money total'),
'value' => 'money'
],
]
]
);
?>
<h2>Pénzmozgások</h2>
<?= GridView::widget([
'dataProvider' => $dataProvider,
'columns' => [
'id_discount',
'id_currency',
'id_object',
'status',
// 'type',
// 'item_price',
// 'count',
// 'money',
// 'money_currency',
// 'rate',
// 'id_user',
// 'comment',
[
'attribute' => 'type',
'value' => 'transferTypeName'
],
[
'attribute' => 'id_object',
'value' => 'objectName'
],
[
'attribute' => 'id_user',
'value' => 'userName'
],
[
'attribute' => 'id_account',
'value' => 'accountName'
],
'item_price',
'count',
'money',
'created_at:datetime',
'updated_at:datetime',
['class' => 'yii\grid\ActionColumn',
'template' => '{view}'

View File

@@ -14,35 +14,33 @@ $this->params['breadcrumbs'][] = $this->title;
<h1><?= Html::encode($this->title) ?></h1>
<p>
<?= Html::a(Yii::t('frontend/transfer', 'Update'), ['update', 'id' => $model->id_transfer], ['class' => 'btn btn-primary']) ?>
<?= Html::a(Yii::t('frontend/transfer', 'Delete'), ['delete', 'id' => $model->id_transfer], [
'class' => 'btn btn-danger',
'data' => [
'confirm' => Yii::t('frontend/transfer', 'Are you sure you want to delete this item?'),
'method' => 'post',
],
]) ?>
</p>
<?= DetailView::widget([
'model' => $model,
'attributes' => [
'id_transfer',
'id_discount',
'id_currency',
'id_object',
'status',
'type',
[
'attribute' => 'id_transfer',
],
[
'attribute' => 'id_account',
'value' => $model->accountName
],
[
'attribute' => 'type',
'value' => $model->transferTypeName,
],
[
'attribute' => 'id_object',
'value' => $model->objectName,
],
[
'attribute' => 'id_user',
'value' => $model->userName,
],
'item_price',
'count',
'money',
'money_currency',
'rate',
'id_user',
'comment',
'created_at',
'updated_at',
],
]) ?>