add transaction/summary, fix transaction/index, add reception product typeahead
This commit is contained in:
@@ -89,6 +89,7 @@ class AdminMenuStructure{
|
||||
/////////////////////////////
|
||||
$items = [];
|
||||
$items[] = ['label' => 'Tranzakciók', 'url' => ['/transfer/index' , 'TransferSearch[start]' =>$today,'TransferSearch[end]' => $tomorrow ] ];
|
||||
$items[] = ['label' => 'Bevétel', 'url' => ['/transfer/summary' , 'TransferSummarySearch[start]' =>$today,'TransferSummarySearch[end]' => $tomorrow ] ];
|
||||
$items[] = ['label' => 'Kassza müveletek', 'url' => ['/account-state/index'] ];
|
||||
$items[] = ['label' => 'Zárások', 'url' => ['/collection/index' , 'CollectionSearch[start]' =>$todayDatetime,'CollectionSearch[end]' => $tomorrowDatetime ] ];
|
||||
$this->menuItems[] = ['label' => 'Pénzügy', 'url' => $this->emptyUrl,
|
||||
|
||||
@@ -9,6 +9,7 @@ use yii\web\NotFoundHttpException;
|
||||
use yii\filters\VerbFilter;
|
||||
use common\models\Account;
|
||||
use common\models\User;
|
||||
use backend\models\TransferSummarySearch;
|
||||
|
||||
/**
|
||||
* TransferController implements the CRUD actions for Transfer model.
|
||||
@@ -23,7 +24,7 @@ class TransferController extends \backend\controllers\BackendController
|
||||
'rules' => [
|
||||
// allow authenticated users
|
||||
[
|
||||
'actions' => [ 'index','view' ],
|
||||
'actions' => [ 'index','view','summary' ],
|
||||
'allow' => true,
|
||||
'roles' => ['admin','employee','reception'],
|
||||
],
|
||||
@@ -57,6 +58,29 @@ class TransferController extends \backend\controllers\BackendController
|
||||
]);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Lists all Transfer models.
|
||||
* @return mixed
|
||||
*/
|
||||
public function actionSummary()
|
||||
{
|
||||
$searchModel = new TransferSummarySearch();
|
||||
$dataProvider = $searchModel->search(Yii::$app->request->queryParams);
|
||||
|
||||
$accounts = Account::read();
|
||||
|
||||
$users = User::read();
|
||||
|
||||
return $this->render('summary', [
|
||||
'searchModel' => $searchModel,
|
||||
'dataProvider' => $dataProvider,
|
||||
'accounts' => $accounts,
|
||||
'users' => $users,
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Displays a single Transfer model.
|
||||
* @param integer $id
|
||||
|
||||
@@ -114,8 +114,9 @@ class TransferSearch extends Transfer
|
||||
|
||||
$accounts = Account::read();
|
||||
$accountMap = ArrayHelper::map( $accounts ,'id_account','name' );
|
||||
$idUser = Yii::$app->user->id;
|
||||
$idUser = $this->id_user;
|
||||
|
||||
|
||||
$this->totals = Transfer::mkTotals($this->timestampStart, $this->timestampEnd, $idUser, $this->types, $this->id_account, $accounts, $accountMap);
|
||||
|
||||
|
||||
|
||||
180
backend/models/TransferSummarySearch.php
Normal file
180
backend/models/TransferSummarySearch.php
Normal file
@@ -0,0 +1,180 @@
|
||||
<?php
|
||||
|
||||
namespace backend\models;
|
||||
|
||||
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;
|
||||
use common\components\Helper;
|
||||
use common\components\RoleDefinition;
|
||||
|
||||
/**
|
||||
* TransferSearch represents the model behind the search form about `common\models\Transfer`.
|
||||
*/
|
||||
class TransferSummarySearch extends Transfer
|
||||
{
|
||||
public $searchObjectName;
|
||||
public $searchTypeName;
|
||||
public $searchUserName;
|
||||
public $start;
|
||||
public $end;
|
||||
|
||||
public $timestampStart;
|
||||
public $timestampEnd;
|
||||
|
||||
|
||||
public $types;
|
||||
|
||||
/**
|
||||
* all money gained with ticket sell
|
||||
* */
|
||||
public $ticketMoney;
|
||||
/**
|
||||
* all money gained with product sell grouped by category
|
||||
* */
|
||||
public $productMoneies;
|
||||
/**
|
||||
* all money lost by money movement
|
||||
* */
|
||||
public $moneyMovementMoneis;
|
||||
/**
|
||||
* total gained money
|
||||
* */
|
||||
public $total;
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function rules()
|
||||
{
|
||||
return [
|
||||
[[ 'id_account','id_user', 'type'], 'integer'],
|
||||
// [[ 'searchObjectName' ], 'string'],
|
||||
[[ 'start', ], 'date' , 'timestampAttribute' => 'timestampStart' ,'timestampAttributeFormat' => 'yyyy-MM-dd' ],
|
||||
[[ 'end' , ], 'date' , 'timestampAttribute' => 'timestampEnd' ,'timestampAttributeFormat' => 'yyyy-MM-dd' ],
|
||||
['types', 'each', 'rule' => ['integer']],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @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)
|
||||
{
|
||||
|
||||
|
||||
|
||||
$this->load($params);
|
||||
|
||||
if (!$this->validate()) {
|
||||
// $query->where('0=1');
|
||||
// return $dataProvider;
|
||||
}
|
||||
|
||||
|
||||
$this->readTicketMoney();
|
||||
$this->readProductsByCategory();
|
||||
$this->readMoneyMovements();
|
||||
$this->calcTotal();
|
||||
}
|
||||
|
||||
protected function calcTotal(){
|
||||
$this->total = 0;
|
||||
$this->total += $this->ticketMoney;
|
||||
$this->total -= $this->moneyMovementMoneis['money_movement_money'];
|
||||
foreach ($this->productMoneies as $pm ){
|
||||
$this->total += $pm['product_money'];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
protected function addQueryFilters($query){
|
||||
if ( !RoleDefinition::isAdmin() ){
|
||||
$query->innerJoin("user_account_assignment",'transfer.id_account = user_account_assignment.id_account' );
|
||||
$query->andWhere(['user_account_assignment.id_user' => Yii::$app->user->id ]);
|
||||
}
|
||||
|
||||
$query->andFilterWhere([
|
||||
'transfer.id_account' => $this->id_account,
|
||||
'transfer.type' => $this->type,
|
||||
'transfer.id_user' => $this->id_user,
|
||||
]);
|
||||
|
||||
$created_condition = ['and',[ '>=', 'transfer.created_at', $this->timestampStart ] ,[ '<', 'transfer.created_at', $this->timestampEnd ] ];
|
||||
$paid_condition = ['and',[ '>=', 'transfer.paid_at', $this->timestampStart ] ,[ '<', 'transfer.paid_at', $this->timestampEnd ] ];
|
||||
|
||||
|
||||
$query->andFilterWhere(['or' , $created_condition , $paid_condition]);
|
||||
|
||||
$query->andWhere(['transfer.status' => Transfer::STATUS_PAID]);
|
||||
|
||||
}
|
||||
|
||||
|
||||
protected function readTicketMoney(){
|
||||
|
||||
$query = (new \yii\db\Query());
|
||||
$query->select([' coalesce(sum(abs(transfer.money)),0) AS ticket_money']);
|
||||
$query->from('transfer');
|
||||
$query->andWhere(['transfer.type' => Transfer::TYPE_TICKET]);
|
||||
$query->innerJoin("ticket", "ticket.id_ticket = transfer.id_object");
|
||||
$this->addQueryFilters($query);
|
||||
|
||||
// $query = Transfer::find();
|
||||
// $query->andWhere(['type' => Transfer::TYPE_TICKET]);
|
||||
// $this->addQueryFilters($query);
|
||||
$this->ticketMoney = $query->scalar();
|
||||
print_r($this->ticketMoney);
|
||||
}
|
||||
|
||||
protected function readProductsByCategory(){
|
||||
|
||||
|
||||
$query = (new \yii\db\Query());
|
||||
$query->select(['coalesce(sum(transfer.money),0) AS product_money', 'product_category.name as category_name']);
|
||||
$query->from('transfer');
|
||||
$query->groupBy(['product_category.id_product_category','product_category.name']);
|
||||
$query->andWhere(['transfer.type' => Transfer::TYPE_PRODUCT]);
|
||||
$query->innerJoin("sale", "sale.id_sale = transfer.id_object");
|
||||
$query->innerJoin("product", "sale.id_product = product.id_product");
|
||||
$query->innerJoin("product_category", "product.id_product_category = product_category.id_product_category");
|
||||
$this->addQueryFilters($query);
|
||||
|
||||
$this->productMoneies = $query->all();
|
||||
|
||||
}
|
||||
|
||||
|
||||
protected function readMoneyMovements(){
|
||||
$query = (new \yii\db\Query());
|
||||
$query->select([' coalesce(sum(abs(transfer.money)),0) AS money_movement_money']);
|
||||
$query->from('transfer');
|
||||
$query->andWhere(['transfer.type' => Transfer::TYPE_MONEY_MOVEMENT_OUT]);
|
||||
$query->innerJoin("money_movement", "money_movement.id_money_movement = transfer.id_object");
|
||||
$this->addQueryFilters($query);
|
||||
|
||||
$this->moneyMovementMoneis = $query->one();
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
58
backend/views/transfer/_search_summary.php
Normal file
58
backend/views/transfer/_search_summary.php
Normal file
@@ -0,0 +1,58 @@
|
||||
<?php
|
||||
|
||||
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' => ['summary'],
|
||||
'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, 'id_user')->dropDownList( ['' => Yii::t('common/transfer', 'All')] +ArrayHelper::map($users,'id' , 'username') ) ?>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="row">
|
||||
<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>
|
||||
|
||||
<div class="form-group">
|
||||
<?= Html::submitButton(Yii::t('frontend/transfer', 'Search'), ['class' => 'btn btn-primary']) ?>
|
||||
</div>
|
||||
|
||||
<?php ActiveForm::end(); ?>
|
||||
|
||||
</div>
|
||||
@@ -43,6 +43,10 @@ $this->params['breadcrumbs'][] = $this->title;
|
||||
'dataProvider' => $dataProvider,
|
||||
'columns' => [
|
||||
|
||||
[
|
||||
'attribute' => 'id_transfer',
|
||||
'value' => 'id_transfer'
|
||||
],
|
||||
[
|
||||
'attribute' => 'type',
|
||||
'value' => 'transferTypeName'
|
||||
@@ -72,6 +76,7 @@ $this->params['breadcrumbs'][] = $this->title;
|
||||
'value' => 'signedMoney'
|
||||
],
|
||||
'created_at:datetime',
|
||||
'paid_at:datetime',
|
||||
|
||||
['class' => 'yii\grid\ActionColumn',
|
||||
'template' => '{view}'
|
||||
|
||||
73
backend/views/transfer/summary.php
Normal file
73
backend/views/transfer/summary.php
Normal file
@@ -0,0 +1,73 @@
|
||||
<?php
|
||||
|
||||
use yii\helpers\Html;
|
||||
|
||||
|
||||
/* @var $this yii\web\View */
|
||||
/* @var $searchModel backend\models\TransferSearch */
|
||||
/* @var $dataProvider yii\data\ActiveDataProvider */
|
||||
|
||||
$this->title = Yii::t('frontend/transfer', 'Transfers Summary');
|
||||
$this->params['breadcrumbs'][] = $this->title;
|
||||
?>
|
||||
<style>
|
||||
.table-summary th
|
||||
{
|
||||
width: 200px;
|
||||
}
|
||||
</style>
|
||||
|
||||
<div class="transfer-index">
|
||||
|
||||
<h1><?= Html::encode($this->title) ?></h1>
|
||||
<?php echo $this->render('_search_summary', ['model' => $searchModel, 'accounts' => $accounts,'users' => $users,]); ?>
|
||||
|
||||
|
||||
|
||||
<h2>Bérletek összesen</h2>
|
||||
<table class="table-bordered table-striped table-summary">
|
||||
<tbody>
|
||||
<tr>
|
||||
<th >Bérletek</th>
|
||||
<td><?php echo $searchModel->ticketMoney?> FT</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
<h2>Termékek összesen</h2>
|
||||
<table class="table-bordered table-striped table-summary">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Termék kategória</th>
|
||||
<th>Összeg</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr>
|
||||
<?php
|
||||
foreach ($searchModel->productMoneies as $pm ){
|
||||
?>
|
||||
<th ><?php echo $pm['category_name'] ?></th>
|
||||
<td><?php echo $pm['product_money']?> FT</td>
|
||||
<?php } ?>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
<h2>Pénzmozgások összesen</h2>
|
||||
<table class="table-bordered table-striped table-summary">
|
||||
<tbody>
|
||||
<tr>
|
||||
<th >Pénzmozgások</th>
|
||||
<td><?php echo $searchModel->moneyMovementMoneis['money_movement_money']?> FT</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
<h2>Bevétel összesen</h2>
|
||||
<table class="table-bordered table-striped table-summary">
|
||||
<tbody>
|
||||
<tr>
|
||||
<th >Bérletek</th>
|
||||
<td><span style='border-bottom: 1px solid black'><?php echo $searchModel->total?> FT</span></td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
@@ -41,6 +41,7 @@ $this->params['breadcrumbs'][] = $this->title;
|
||||
'money',
|
||||
'comment',
|
||||
'created_at',
|
||||
'paid_at',
|
||||
],
|
||||
]) ?>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user