add reception account state view and pdf export

This commit is contained in:
2016-01-08 14:06:55 +01:00
parent da29702a79
commit e8df61f123
30 changed files with 1190 additions and 288 deletions

View File

@@ -15,7 +15,8 @@ use common\components\RoleDefinition;
class DailyListing
{
public $mode = "reception";//reception or admin
public $mode = "reception";//reception or admin or accountstate
/**
* string start date , inclusive
* */
@@ -108,6 +109,25 @@ class DailyListing
public $type;
public function readTotalEasy(){
$this->readTicketMoney();
$this->readProductsMoney();
$this->readMoneyMovementMoney();
$this->calcTotal();
}
public function readTotalDetailed(){
$this->readTickets();
$this->readProducts();
$this->readMoneyMovements();
}
public function readTotalMedium(){
$this->readProductsByCategory();
$this->readProductsByCategoryDetailed();
$this->readTicketStas();
$this->readMoneyMovementsStats();
}
public function loadFilters($transfer){
$this->start = $transfer->start;
$this->end = $transfer->end;
@@ -119,9 +139,22 @@ class DailyListing
$this->timestampEnd = $transfer->timestampEnd;
}
public function loadAccountState($accountState){
$this->mode = 'accountstate';
$this->start = $accountState->start_date;
$this->end = $accountState->created_at;
$this->timestampStart = $accountState->start_date;
$this->timestampEnd =$accountState->created_at;
$this->id_account = $accountState->id_account;
$this->id_user = $accountState->id_user;
}
public function isModeAdmin(){
return $this->mode == 'admin';
}
public function isModeAccountState(){
return $this->mode == 'accountstate';
}
public function calcTotal(){
@@ -139,11 +172,15 @@ class DailyListing
public function addAccountConstraint($query){
if (!$this->isModeAdmin() || !RoleDefinition::isAdmin() ){
if ( $this->isModeAccountState() ){
$query->andWhere(['account.type' => Account::TYPE_ALL ]);
}else if (!$this->isModeAdmin() || !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 ]);
if ( RoleDefinition::isReception() || !$this->isModeAdmin()){
if ( RoleDefinition::isReception() || !$this->isModeAdmin()){
$query->andWhere(['transfer.id_user' => Yii::$app->user->id ]);
}

View File

@@ -0,0 +1,84 @@
<?php
namespace common\components\accountstate;
use yii\base\Widget;
use common\models\AccountState;
use yii\data\ArrayDataProvider;
use yii\grid\GridView;
use yii\helpers\Html;
use yii\widgets\DetailView;
/**
* This is the model class for widget display bank notes.
*
* @property common\models\AccountState $model
* */
class AccountStateWidget extends Widget{
public $model;
public function init(){
parent::init();
}
public function run(){
if ($this->model->isTypeOpen() ){
$attributes = [
[
'attribute' =>'account.name',
'label' => 'Kassza'
],
[
'attribute' =>'typeName',
'label' => 'Típus'
],
[
'attribute' =>'money',
'value' => \Yii::$app->formatter->asInteger($this->model->money) ." Ft",
],
'user.username',
[
'attribute' => 'created_at',
'label' => 'Nyitás ideje'
],
];
}else{
$attributes = [
[
'attribute' =>'account.name',
'label' => 'Kassza'
],
[
'attribute' =>'typeName',
'label' => 'Típus'
],
[
'attribute' =>'money',
'value' => \Yii::$app->formatter->asInteger($this->model->money) ." Ft",
],
'user.username',
[
'attribute' => 'start_date',
'label' => 'Előző nyitás ideje'
],
[
'attribute' => 'created_at',
'label' => 'Zárás ideje'
],
];
}
echo DetailView::widget([
'model' => $this->model,
'attributes' =>$attributes,
]) ;
}
}

View File

@@ -0,0 +1,96 @@
<?php
namespace common\components\accountstate;
use yii\base\Widget;
use common\models\AccountState;
use yii\data\ArrayDataProvider;
use yii\grid\GridView;
use yii\helpers\Html;
/**
* This is the model class for widget display bank notes.
*
* @property common\models\AccountState $model
* */
class BankNotesWidget extends Widget{
public $model;
public function init(){
parent::init();
}
public function run(){
echo $this->generateNotes();
}
protected function generateNotes(){
$s = "";
$s .= Html::beginTag("div", ['class' => 'row', 'style' => 'margin-top: 6px;']);
$s .= Html::beginTag("div", ['class' => 'col-md-4']);
$s .= $this->generateBanknoteGrid( [ 'banknote_5_ft','banknote_10_ft','banknote_20_ft','banknote_50_ft' ]);
$s .= Html::endTag("div");
$s .= Html::beginTag("div", ['class' => 'col-md-4']);
$s .= $this->generateBanknoteGrid( [ 'banknote_100_ft','banknote_200_ft','banknote_500_ft','banknote_1000_ft' ]);
$s .= Html::endTag("div");
$s .= Html::beginTag("div", ['class' => 'col-md-4']);
$s .= $this->generateBanknoteGrid( [ 'banknote_2000_ft','banknote_5000_ft','banknote_10000_ft','banknote_20000_ft' ]);
$s .= Html::endTag("div");
$s .= Html::endTag("div");
return $s;
}
protected function generateBanknoteGrid($attributes){
return $this->generateBanknoteColumn( $this->mkColumnData($attributes));
}
protected function mkColumnData( $attributes){
$values = AccountState::banknoteValues();
$items = [];
foreach ($attributes as $note){
$value = $values[$note];
$count = $this->model->$note;
if ( !isset($count) || empty($count)){
$count = 0;
}
$value = \Yii::$app->formatter->asInteger($value);
$item = [
'note' => $value . " Ft",
'count' => $count
];
$items[] = $item;
}
return $items;
}
protected function generateBanknoteColumn($data){
$dp = new ArrayDataProvider(
[
'allModels' => $data,
'sort' => false,
'pagination' => false
]
);
$s = GridView::widget([
'dataProvider' => $dp,
'layout' => '{items}',
'options' => ['class' => 'grid-view notes-view'],
'columns' =>[
[
'contentOptions' => ['class' => 'note-name'],
'value' => 'note',
'label' => 'Címlet'
],
[
'value' => 'count',
'label' => 'Db'
],
]
]);
return $s;
}
}

View File

@@ -0,0 +1,21 @@
<?php
namespace common\components\total;
use yii\base\Widget;
class TotalBaseWidget extends Widget{
public $dailyListing;
public $viewPath = '@common/views/total';
public $viewFile = 'totaleasy.php';
public $view;
public function init(){
$this->view = $this->viewPath . "/" . $this->viewFile;
}
public function run(){
echo $this->render($this->view,[ 'model' => $this->dailyListing ]);
}
}

View File

@@ -0,0 +1,9 @@
<?php
namespace common\components\total;
class TotalDetailedMoneyMovementWidget extends TotalBaseWidget{
public $viewFile = 'total_detailed_money_movement.php';
}

View File

@@ -0,0 +1,9 @@
<?php
namespace common\components\total;
class TotalDetailedProductsWidget extends TotalBaseWidget{
public $viewFile = 'total_detailed_product.php';
}

View File

@@ -0,0 +1,9 @@
<?php
namespace common\components\total;
class TotalDetailedTicketsWidget extends TotalBaseWidget{
public $viewFile = 'total_detailed_ticket.php';
}

View File

@@ -0,0 +1,68 @@
<?php
namespace common\components\total;
use yii\base\Widget;
use yii\widgets\DetailView;
/**
* Display account state difference information widget
*
*
* @property common\models\AccountState $model
*
* */
class TotalDifferenceWidget extends Widget{
public $model;
public function run(){
return $this->generateDifference();
}
protected function generateDifference(){
$s = "";
if ( $this->model->hasDifferenceToPrevState()){
$ft = " Ft";
$s .= DetailView::widget([
'model' => $this->model,
'template' =>"<tr><th>{label}</th><td style='text-align: right;'>{value} </td></tr>",
'attributes' => [
[
'label' => "Előző nyitás ideje",
'value' => $this->model->prevObject ? \Yii::$app->formatter->asDatetime( $this->model->prevObject->created_at) : "-",
],
[
'label' => "Előzőleg nyitott",
'value' => $this->model->prevObject ? $this->model->user->username : "-",
],
[
'label' => "Előző nyitás összege",
'value' => $this->model->prev_money.$ft
],
[
'label' => "Bevételek összesen előző nyitás óta",
'value' => $this->model->collection_money .$ft
],
[
'label' => "Zárás összege",
'value' => $this->model->money.$ft
],
[
'label' => "Várt összeg",
'value' => $this->model->expected.$ft
],
[
'label' => "Különbözet",
'value' => $this->model->signedDiff.$ft
],
]
]);
}
return $s;
}
}

View File

@@ -0,0 +1,22 @@
<?php
namespace common\components\total;
use yii\base\Widget;
class TotalEasyWidget extends Widget{
public $dailyListing;
public $viewPath = '@common/views/total';
public $viewFile = 'totaleasy.php';
public $view;
public function init(){
$this->view = $this->viewPath . "/" . $this->viewFile;
}
public function run(){
echo $this->render($this->view,[ 'model' => $this->dailyListing ]);
}
}

View File

@@ -0,0 +1,9 @@
<?php
namespace common\components\total;
class TotalMediumMoneyMovementsWidget extends TotalBaseWidget{
public $viewFile = 'total_medium_money_movement.php';
}

View File

@@ -0,0 +1,9 @@
<?php
namespace common\components\total;
class TotalMediumProductsWidget extends TotalBaseWidget{
public $viewFile = 'total_medium_product.php';
}

View File

@@ -0,0 +1,9 @@
<?php
namespace common\components\total;
class TotalMediumTicketsWidget extends TotalBaseWidget{
public $viewFile = 'total_medium_ticket.php';
}

View File

@@ -36,6 +36,8 @@ class AccountState extends \common\models\BaseFitnessActiveRecord
const TYPE_OPEN = 10;
const TYPE_CLOSE = 20;
public $start_date;
/**
* @inheritdoc
*/
@@ -94,6 +96,13 @@ class AccountState extends \common\models\BaseFitnessActiveRecord
}
public function isTypeOpen(){
return $this->type == AccountState::TYPE_OPEN;
}
public function isTypeClose(){
return $this->type == AccountState::TYPE_CLOSE;
}
public static function banknoteValues()
{
return [

View File

@@ -712,6 +712,7 @@ class Transfer extends \common\models\BaseFitnessActiveRecord
$query = (new \yii\db\Query());
$query->select(['coalesce(sum( case when transfer.direction = ' . Transfer::DIRECTION_IN. ' then transfer.money else -1 * transfer.money end ),0) AS transfer_money']);
$query->from('transfer');
$query->innerJoin("account","account.id_account = transfer.id_account");
$query->andWhere(['transfer.id_user' => $idUser ]);
$created_condition = ['and',[ '>=', 'transfer.created_at', $start ] ,[ '<', 'transfer.created_at', $end ] ];
@@ -719,6 +720,7 @@ class Transfer extends \common\models\BaseFitnessActiveRecord
$query->andFilterWhere(['or' , $created_condition , $paid_condition]);
$query->andWhere(['transfer.status' => Transfer::STATUS_PAID]);
$query->andWhere(['account.type' => Account::TYPE_ALL]);
return $query->scalar();
}

View File

@@ -0,0 +1,102 @@
<?php
use yii\helpers\Html;
use yii\widgets\DetailView;
use common\components\total\TotalEasyWidget;
use common\components\total\TotalDetailedProductsWidget;
use common\components\total\TotalDetailedTicketsWidget;
use common\components\total\TotalDetailedMoneyMovementWidget;
use common\components\accountstate\BankNotesWidget;
use common\components\total\TotalMediumTicketsWidget;
use common\components\total\TotalMediumProductsWidget;
use common\components\total\TotalMediumMoneyMovementsWidget;
use common\components\total\TotalDifferenceWidget;
use common\models\AccountState;
use common\components\accountstate\AccountStateWidget;
use yii\base\Widget;
/* @var $this yii\web\View */
/* @var $model common\models\AccountState */
if ( $model ->type == AccountState::TYPE_OPEN ){
$this->title = "Kassza nyitás";
}else{
$this->title = "Kassza zárás";
}
?>
<link rel='stylesheet' href='<?php echo \Yii::getAlias('@vendor'.'/bower/bootstrap/dist/css/bootstrap.css')?>'>
<style>
td,th{
padding: 3px;
}
td.note-name{
width: 50%;
}
td.money{
text-align: right;
}
</style>
<div class="account-state-view">
<h1><?= Html::encode($this->title) ?></h1>
<?php
if ( $model->hasDifferenceToPrevState() ){
if ( $model->hasMinus()){
?>
<div class="alert alert-danger" role="alert">Negatív különbözet</div>
<?php
}else{
?>
<div class="alert alert-success" role="alert">Pozitív különbözet</div>
<?php
}
}
?>
<?php
echo AccountStateWidget::widget(['model' => $model]);
?>
<?php if ( $model->hasDifferenceToPrevState() ){
?>
<h2>Különbözet</h2>
<?php
echo TotalDifferenceWidget::widget(['model' => $model] );
}
?>
<?php if ( $model ->type == AccountState::TYPE_CLOSE ){?>
<pagebreak />
<?php echo TotalEasyWidget::widget(['dailyListing' => $details]);?>
<pagebreak />
<h2>Közepes összesítés</h2>
<h3>Bérletek típus szerint</h3>
<?php echo TotalMediumTicketsWidget::widget(['dailyListing' => $details]);?>
<h3>Termékek név szerint</h3>
<?php echo TotalMediumProductsWidget::widget(['dailyListing' => $details]);?>
<h3>Pénzmozgások típus szerint</h3>
<?php echo TotalMediumMoneyMovementsWidget::widget(['dailyListing' => $details]);?>
<pagebreak />
<h2>Részletek</h2>
<?php echo TotalDetailedTicketsWidget::widget(['dailyListing' => $details]);?>
<?php echo TotalDetailedProductsWidget::widget(['dailyListing' => $details]);?>
<?php echo TotalDetailedMoneyMovementWidget::widget(['dailyListing' => $details]);?>
<pagebreak />
<h2>Címletek</h2>
<?php echo BankNotesWidget::widget(['model' => $model]);?>
</div>
<?php }else{?>
<pagebreak />
<h2>Címletek</h2>
<?php echo BankNotesWidget::widget(['model' => $model]);?>
<?php }?>
</div>

View File

@@ -0,0 +1,41 @@
<h3>Pénzmozgások</h3>
<table class="table table-bordered table-striped table-summary">
<thead>
<tr>
<th>Dátum</th>
<th>Kassza</th>
<th>Felhasználó</th>
<th>Név</th>
<th>Típus</th>
<th>Összeg</th>
</tr>
</thead>
<tbody>
<?php foreach ($model->moneyMovements as $p ){?>
<tr>
<td><?php echo $p['money_movement_created_at']?> </td>
<td><?php echo $p['account_name']?> </td>
<td><?php echo $p['user_name']?> </td>
<td><?php echo $p['money_movement_name'] ?></td>
<td><?php echo $p['money_movement_type_name'] ?></td>
<td class='money'><?php echo \Yii::$app->formatter->asInteger( $p['signed_money'])?> Ft</td>
</tr>
<?php } ?>
</tbody>
</table>
<?php if ( count($model->moneyMovements ) == 0 ) {
?>
Nincs találat
<?php
}else{?>
<div class="row">
<div class="col-md-12 text-right" style="text-decoration: underline;">
Összesen: <?php echo \Yii::$app->formatter->asInteger( $model->moneyMovementMoneis); ?> Ft
</div>
</div>
<?php
}
?>

View File

@@ -0,0 +1,51 @@
<?php
//////////////////////////
// Termék eladás
////////////////////////
?>
<h3>Termék eladások</h3>
<table class="table table-bordered table-striped table-summary">
<thead>
<tr>
<th>Kiadva</th>
<th>Fizetve</th>
<th>Kassza</th>
<th>Felhasználó</th>
<th>Kategória</th>
<th>Termék</th>
<th>Egység ár</th>
<th>Mennyiség</th>
<th>Összeg</th>
</tr>
</thead>
<tbody>
<?php foreach ($model->products as $p ){?>
<tr>
<td><?php echo $p['product_created_at']?> </td>
<td><?php echo $p['product_paid_at']?> </td>
<td><?php echo $p['account_name']?> </td>
<td><?php echo $p['user_name']?> </td>
<td><?php echo $p['product_category_name'] ?></td>
<td><?php echo $p['product_name'] ?></td>
<td class='money'><?php echo $p['product_item_price']?> Ft</td>
<td class='count'><?php echo $p['product_count']?> Db</td>
<td class='money'><?php echo \Yii::$app->formatter->asInteger( $p['product_money'])?> FT</td>
</tr>
<?php } ?>
</tbody>
</table>
<?php if ( count($model->products ) == 0 ) {
?>
Nincs találat
<?php
}else{?>
<div class="row">
<div class="col-md-12 text-right" style="text-decoration: underline;">
Összesen: <?php echo \Yii::$app->formatter->asInteger( $model->productMoney); ?> Ft
</div>
</div>
<?php
}
?>

View File

@@ -0,0 +1,46 @@
<h3>Bérletek</h3>
<table class="table table-bordered table-striped table-summary">
<thead>
<tr>
<th>Kiadva</th>
<th>Fizetve</th>
<th>Kassza</th>
<th>Felhasználó</th>
<th>Bérlet típus</th>
<th>Egység ár</th>
<th>Mennyiség</th>
<th>Összeg</th>
</tr>
</thead>
<tbody>
<?php foreach ($model->tickets as $t ){?>
<tr>
<td><?php echo $t['ticket_created_at']?> </td>
<td><?php echo $t['ticket_paid_at']?> </td>
<td><?php echo $t['account_name']?> </td>
<td><?php echo $t['user_name']?> </td>
<td><?php echo $t['ticket_type_name'] ?></td>
<td class='money'><?php echo $t['ticket_item_price']?> Ft</td>
<td class='count'><?php echo $t['ticket_count']?> Db</td>
<td class='money'><?php echo \Yii::$app->formatter->asInteger( $t['ticket_money'])?> FT</td>
</tr>
<?php } ?>
</tbody>
</table>
<?php if ( count($model->tickets ) == 0 ) {
?>
Nincs találat
<?php
}else{?>
<div class="row">
<div class="col-md-12 text-right" style="text-decoration: underline;">
Összesen: <?php echo \Yii::$app->formatter->asInteger( $model->ticketMoney); ?> Ft
</div>
</div>
<?php
}
?>
<?php

View File

@@ -0,0 +1 @@
<?php

View File

@@ -0,0 +1,26 @@
<table class="table table-bordered table-striped table-summary">
<thead>
<tr>
<th>Pénzmozgás típus</th>
<th>Mennyiség</th>
<th>Összeg</th>
</tr>
</thead>
<tbody>
<?php
foreach ( $model->moneyMovementsByType as $mmStat ) {
?>
<tr>
<td class="name"><?php echo $mmStat['name'] ?></td>
<td class="count"><?php echo $mmStat['money_movement_count']?> Db</td>
<td class="money"><?php echo \Yii::$app->formatter->asInteger( $mmStat['money_movement_money'])?> FT</td>
</tr>
<?php } ?>
</tbody>
</table>
<div class="row">
<div class="col-md-12 text-right" style="text-decoration: underline;">
Összesen: <?php echo \Yii::$app->formatter->asInteger( $model->moneyMovementMoneis); ?> Ft
</div>
</div>

View File

@@ -0,0 +1,45 @@
<?php
foreach ( $model->productsByCategory ['categories'] as $categoryHolder ) {
$products = $categoryHolder ['products'];
?>
<h4><?php echo $categoryHolder['category']['name']?></h4>
<table
class="table table-bordered table-striped table-summary table-category-product">
<thead>
<tr>
<th>Termék</th>
<th>Mennyiség</th>
<th>Összeg</th>
</tr>
</thead>
<tbody>
<?php foreach ( $products as $p){?>
<tr>
<td class='name'><?php echo $p['product_name'] ?></td>
<td class='count'><?php echo $p['product_count'] ?> Db</td>
<td class='money'><?php echo \Yii::$app->formatter->asInteger( $p['product_money'])?> FT</td>
</tr>
<?php }?>
<tr class="warning">
<td><?php echo "Összesen" ?></td>
<td><?php ?></td>
<td class='money'><?php echo \Yii::$app->formatter->asInteger( $categoryHolder['total'])?> FT</td>
</tr>
</tbody>
</table>
<?php
}
?>
<div class="row">
<div class="col-md-12 text-right" style="text-decoration: underline;">
Összesen:
<?php
echo \Yii::$app->formatter->asInteger( $model->productsByCategory ['total']);
?> Ft
</div>
</div>

View File

@@ -0,0 +1,27 @@
<table class="table table-bordered table-striped table-summary">
<thead>
<tr>
<th>Bérlet típus</th>
<th>Mennyiség</th>
<th>Összeg</th>
</tr>
</thead>
<tbody>
<?php
foreach ( $model->ticketStats as $ticketStat ) {
?>
<tr>
<td class="name"><?php echo $ticketStat['ticket_type_name'] ?></td>
<td class="count"><?php echo $ticketStat['ticket_count']?> Db</td>
<td class="money"><?php echo \Yii::$app->formatter->asInteger( $ticketStat['ticket_money'])?> FT</td>
</tr>
<?php } ?>
</tbody>
</table>
<div class="row">
<div class="col-md-12 text-right" style="text-decoration: underline;">
Összesen: <?php echo \Yii::$app->formatter->asInteger( $model->ticketMoney); ?> Ft
</div>
</div>

View File

@@ -0,0 +1,46 @@
<?php
use common\components\RoleDefinition;
use yii\helpers\Html;
use yii\helpers\Url;
?>
<?php
//echo $this->render('_list_pdf_head',[ 'searchModel' =>$model, 'label' => 'Napi bevételek - Egyszerű','type' =>'easy']);
?>
<h2>Egyszerű összesítés</h2>
<?php
// if ( !isset($model->output) ){
// $pdfUrl = Url::current([ Html::getInputName($model, 'output') => 'pdf']);
// echo Html::a("Teljes PDF letöltése", $pdfUrl,['class' => 'btn btn-primary btn-all' ]);
// $pdfUrl = Url::current([ Html::getInputName($model, 'output') => 'pdf', Html::getInputName($model, 'outputView') => 'easy']);
// echo Html::a("Egyszerű összesítő Pdf", $pdfUrl,['class' => 'btn btn-primary' ]);
// }
?>
<h3>Bruttó</h3>
<table class="table table-bordered table-striped table-summary">
<tbody>
<tr>
<th>Bérletek</th>
<td class="money"><?php echo \Yii::$app->formatter->asInteger( $model->ticketMoney)?> FT</td>
</tr>
<tr>
<th>Termékek</th>
<td class="money"><?php echo \Yii::$app->formatter->asInteger( $model->productMoney)?> FT</td>
</tr>
<tr>
<th>Pénzmozgások</th>
<td class="money"><?php echo \Yii::$app->formatter->asInteger( $model->moneyMovementMoneis)?> FT</td>
</tr>
<tr>
<th>Végösszeg bruttó</th>
<td class="money"><span style='border-bottom: 1px solid black'><?php echo \Yii::$app->formatter->asInteger( $model->total)?> FT</span></td>
</tr>
</tbody>
</table>