add display money to account state close, delete ticket on customer tickets

This commit is contained in:
Roland Schneider 2016-01-10 15:25:25 +01:00
parent 5a98d128bc
commit 7c584a0779
21 changed files with 291 additions and 19 deletions

View File

@ -9,6 +9,7 @@ use common\models\Account;
use common\models\MoneyMovement;
use common\components\RoleDefinition;
use common\models\AccountState;
/**
* TransferListSearch represents the model behind the search form about `common\models\Transfer`.
*/
@ -108,6 +109,14 @@ class DailyListing
public $id_user;
public $type;
public $totalWithCassa;
public $cassaOpen;
public $showWithCassaOpen = false;// if easy total should be displayed with cassa open money
public $accountState; //the cassa object for we load the data
public function readTotalEasy(){
$this->readTicketMoney();
@ -141,6 +150,7 @@ class DailyListing
public function loadAccountState($accountState){
$this->mode = 'accountstate';
$this->accountState = $accountState;
$this->start = $accountState->start_date;
$this->end = $accountState->created_at;
$this->timestampStart = $accountState->start_date;
@ -149,13 +159,26 @@ class DailyListing
$this->id_user = $accountState->id_user;
}
public function readModeAccountState(){
$this->readTotalEasy ();
$this->readTotalDetailed ();
$this->readTotalMedium ();
$this->readCassaOpen();
$this->calcTotalWithCassaOpen();
$this->showWithCassaOpen = true;
}
public function isModeAdmin(){
return $this->mode == 'admin';
}
public function isModeAccountState(){
return $this->mode == 'accountstate';
}
public function isModeReception(){
return $this->mode == 'reception';
}
public function calcTotal(){
$this->total = 0;
@ -170,6 +193,22 @@ class DailyListing
$this->totalNetto += $this->moneyMovementMoneis;
}
protected function readCassaOpen(){
if ( isset($this->accountState) && $this->accountState->isTypeClose() && isset($this->accountState->prev_state) ){
$this->cassaOpen = AccountState::findOne(['id_account_state' => $this->accountState->prev_state]);
}
}
protected function calcTotalWithCassaOpen(){
$this->totalWithCassa = 0;
$this->totalWithCassa += $this->total;
if ( isset($this->cassaOpen ) ){
$this->totalWithCassa += $this->cassaOpen->money;
}
}
public function addAccountConstraint($query){
@ -513,7 +552,7 @@ class DailyListing
public function readMoneyMovements(){
$query = (new \yii\db\Query());
$query->select([ 'user.username as user_name','account.name as account_name', 'transfer.direction as transfer_direction' ,'money_movement.type as money_movement_type', 'transfer.money AS money_movement_money', 'money_movement.name as money_movement_name','transfer.created_at as money_movement_created_at', ]);
$query->select([ 'user.username as user_name','account.name as account_name', 'transfer.direction as transfer_direction' ,'money_movement.type as money_movement_type', 'transfer.money AS money_movement_money', 'money_movement.name as money_movement_name','transfer.created_at as money_movement_created_at', 'money_movement.comment as money_movement_comment' ]);
$query->from('transfer');
$query->andWhere(['transfer.type' => Transfer::TYPE_MONEY_MOVEMENT_OUT]);
$query->innerJoin("money_movement", "money_movement.id_money_movement = transfer.id_object");

View File

@ -161,6 +161,9 @@ class Helper {
public static function isProductVisibilityAccount() {
return \Yii::$app->params ['product_visiblity'] == 'account';
}
public static function isAccountStateClosePreloadMoney() {
return \Yii::$app->params ['account_state_close_preload_money'] == true;
}
public static function getRealUserIp() {
$client = @$_SERVER ['HTTP_CLIENT_IP'];
$forward = @$_SERVER ['HTTP_X_FORWARDED_FOR'];

View File

@ -42,9 +42,11 @@ class AccountStateMail extends Object {
$this->details = new DailyListing();
$this->details->loadAccountState ( $this->model );
$this->details->readTotalEasy ();
$this->details->readTotalDetailed ();
$this->details->readTotalMedium ();
$this->details->readModeAccountState();
// $this->details->readTotalEasy ();
// $this->details->readTotalDetailed ();
// $this->details->readTotalMedium ();
}
}
@ -61,7 +63,7 @@ class AccountStateMail extends Object {
$this->attachPdf();
$this->message->setFrom('noreplay@fitnessadmin.hu')
$this->message->setFrom(\Yii::$app->params['infoEmail'])
->setTo( \Yii::$app->params['notify_mail'] )
->setSubject($subject )
->send();

View File

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

View File

@ -12,5 +12,6 @@ return [
'mail_account_state_open' => true,
'login_reception_email' => true, //if reception login should send email
'login_admin_email' => true, //if admin login should send email
'account_state_close_preload_money' => 'true',//preload money wnen show account state close page
];

View File

@ -13,6 +13,7 @@ use common\components\total\TotalDifferenceWidget;
use common\models\AccountState;
use yii\helpers\Url;
use common\components\accountstate\AccountStateWidget;
use common\components\total\TotalCassaOpenInfoWidget;
/* @var $this yii\web\View */
/* @var $model common\models\AccountState */
@ -72,6 +73,8 @@ if ( $model ->type == AccountState::TYPE_OPEN ){
<?php if ( $model ->type == AccountState::TYPE_CLOSE ){?>
<?php echo TotalEasyWidget::widget(['dailyListing' => $details]);?>
<?php echo TotalCassaOpenInfoWidget::widget(['dailyListing' => $details]);?>
<h2>Közepes összesítés</h2>
<h3>Bérletek típus szerint</h3>
<?php echo TotalMediumTicketsWidget::widget(['dailyListing' => $details]);?>

View File

@ -34,7 +34,7 @@ return [
'Id Account' => 'Kassza',
'Id Account State' => 'Kassza művelet',
'Id User' => 'Felhasználó',
'Money' => 'Összeg',
'Money' => 'Kasszában lévő összeg',
'Type' => 'Típus',
'Updated At' => 'Módosítás ideje',
];

View File

@ -3,8 +3,8 @@
namespace common\models;
use Yii;
use yii\db\QueryBuilder;
use yii\helpers\ArrayHelper;
use yii\behaviors\TimestampBehavior;
/**
* This is the model class for table "account_state".
@ -38,6 +38,17 @@ class AccountState extends \common\models\BaseFitnessActiveRecord
public $start_date;
/**
* @inheritdoc
*/
// public function behaviors()
// {
// return [[
// 'class' => TimestampBehavior::className(),
// 'value' => function(){ return date('Y-m-d H:i' ); }
// ] ];
// }
/**
* @inheritdoc
*/

View File

@ -14,6 +14,7 @@ use common\models\Account;
use yii\helpers\ArrayHelper;
use common\models\MoneyMovement;
use common\components\RoleDefinition;
use common\components\Helper;
/**
* TransferListSearch represents the model behind the search form about `common\models\Transfer`.
*/
@ -29,7 +30,10 @@ class TransferListSearch extends Transfer
public $timestampEnd;
public $includeCassaOpen = false;
public $totalWithCassa;
public $cassaOpen;
// public $totalsCreatedAt = ['total' => 0, 'accounts' =>[] ];
// public $totalsCreatedAtNotPaid= ['total' => 0, 'accounts' =>[]];
// public $totalsCreatedAtPaid= ['total' => 0, 'accounts' =>[]];
@ -124,6 +128,9 @@ class TransferListSearch extends Transfer
public function isModeAdmin(){
return $this->mode == 'admin';
}
public function isModeReception(){
return $this->mode == 'reception';
}
/**
* Creates data provider instance with search query applied
@ -149,11 +156,20 @@ class TransferListSearch extends Transfer
}
$this->readTicketMoney();
$this->readProductsMoney();
$this->readMoneyMovementMoney();
$this->calcTotal();
if ( $this->isModeReception()){
if ( Helper::isAccountStateClosePreloadMoney()){
$this->readCassaOpen();
$this->calcTotalWithCassaOpen();
}
}
$this->readProductsByCategory();
$this->readProductsByCategoryDetailed();
$this->readTicketStas();
@ -179,12 +195,24 @@ class TransferListSearch extends Transfer
}
protected function readCassaOpen(){
$this->cassaOpen = AccountState::readLast(AccountState::TYPE_OPEN,null,Account::readDefault());
}
protected function calcTotal(){
$this->total = 0;
$this->total += $this->ticketMoney;
$this->total += $this->productMoney;
$this->total += $this->moneyMovementMoneis;
}
protected function calcTotalWithCassaOpen(){
$this->totalWithCassa = 0;
$this->totalWithCassa += $this->total;
if ( isset($this->cassaOpen ) ){
$this->totalWithCassa += $this->cassaOpen->money;
}
}
protected function calcTotalNetto(){
$this->totalNetto = 0;
$this->totalNetto += $this->ticketMoney;
@ -437,7 +465,7 @@ class TransferListSearch extends Transfer
protected function readMoneyMovements(){
$query = (new \yii\db\Query());
$query->select([ 'user.username as user_name','account.name as account_name', 'transfer.direction as transfer_direction' ,'money_movement.type as money_movement_type', 'transfer.money AS money_movement_money', 'money_movement.name as money_movement_name','transfer.created_at as money_movement_created_at', ]);
$query->select([ 'user.username as user_name','account.name as account_name', 'transfer.direction as transfer_direction' ,'money_movement.type as money_movement_type', 'transfer.money AS money_movement_money', 'money_movement.name as money_movement_name','transfer.created_at as money_movement_created_at', 'money_movement.comment as money_movement_comment' ]);
$query->from('transfer');
$query->andWhere(['transfer.type' => Transfer::TYPE_MONEY_MOVEMENT_OUT]);
$query->innerJoin("money_movement", "money_movement.id_money_movement = transfer.id_object");

View File

@ -63,6 +63,9 @@ if ( $model ->type == AccountState::TYPE_OPEN ){
echo AccountStateWidget::widget(['model' => $model]);
?>
<?php if ( $model->hasDifferenceToPrevState() ){
?>
<h2>Különbözet</h2>

View File

@ -0,0 +1,31 @@
<?php
use common\components\DailyListing;
/** @var $model common\components\DailyListing */
?>
<?php if ( $model->showWithCassaOpen && isset($model->cassaOpen) ){?>
<h2>Aktuális záró összeg</h2>
<table class="table table-bordered table-striped table-summary">
<tbody>
<tr>
<th>Kasszanyitás </th>
<td ><span style=' '><?php echo ( $model->cassaOpen->user->username ) ?> </span></td>
</tr>
<tr>
<th>Kasszanyitás ideje</th>
<td ><span style=' '><?php echo ( $model->cassaOpen->created_at ) ?> </span></td>
</tr>
<tr>
<th>Kasszanyitás összege</th>
<td class="money"><span style=' '><?php echo isset($model->cassaOpen) ? \Yii::$app->formatter->asInteger( $model->cassaOpen->money ) : ""?> FT</span></td>
</tr>
<tr>
<th>Végösszeg</th>
<td class="money"><span style=' '><?php echo \Yii::$app->formatter->asInteger($model->total)?> FT</span></td>
</tr>
<tr>
<th>Kasszában lévő összeg</th>
<td class="money"><span style='border-bottom: 1px solid black'><?php echo \Yii::$app->formatter->asInteger( $model->totalWithCassa ) ?> FT</span></td>
</tr>
</tbody>
</table>
<?php }?>

View File

@ -8,6 +8,7 @@
<th>Név</th>
<th>Típus</th>
<th>Összeg</th>
<th>Megjegyzés</th>
</tr>
</thead>
<tbody>
@ -19,6 +20,7 @@
<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>
<td><?php echo $p['money_movement_comment'] ?></td>
</tr>
<?php } ?>

View File

@ -12,6 +12,8 @@ use common\models\Account;
use common\components\DailyListing;
use common\models\User;
use common\components\accountstate\AccountStateMail;
use common\models\Transfer;
use common\components\Helper;
/**
* AccountStateController implements the CRUD actions for AccountState model.
@ -111,6 +113,17 @@ class AccountStateController extends Controller {
$model->type = AccountState::TYPE_CLOSE;
$model->id_user = Yii::$app->user->id;
$model->id_account = Account::readDefault ();
$lastCassaState = AccountState::readLast(null,null, Account::readDefault());
if ( Helper::isAccountStateClosePreloadMoney()){
$model->money = $this->readCassaClose();
}
if ($model->load ( Yii::$app->request->post () ) && $model->save ()) {
@ -128,11 +141,22 @@ class AccountStateController extends Controller {
return $this->render ( 'close', [
'model' => $model,
'accounts' => $accounts,
'lastStates' => $lastStates
'lastStates' => $lastStates ,
'lastCassaState' => $lastCassaState,
] );
}
}
protected function readCassaClose(){
$total = 0;
$cassaOpen = AccountState::readLast(AccountState::TYPE_OPEN,null, Account::readDefault());
if ( isset($cassaOpen )){
$total += $cassaOpen->money;
}
$total += Transfer::readPaid($cassaOpen->created_at, date('Y-d-m h:i:s'), \Yii::$app->user->id);
return $total;
}
/**
* Finds the AccountState model based on its primary key value.
* If the model is not found, a 404 HTTP exception will be thrown.

View File

@ -127,4 +127,53 @@ class TicketController extends FrontendController
]);
}
/**
* Deletes an existing Transfer model.
* If deletion is successful, the browser will be redirected to the 'index' page.
* @param integer $id
* @return mixed
*/
public function actionDelete($id)
{
$ticket = $this->findModel($id);
$transfer = Transfer::find()->andWhere(['transfer.type' => Transfer::TYPE_TICKET])
->andWhere(['transfer.id_object' => $ticket->id_ticket])
->one();
$connection = \Yii::$app->db;
$transaction = $connection->beginTransaction();
try {
ShoppingCart::deleteAll([ 'id_transfer' => $transfer->id_transfer]);
UserSoldItem::deleteAll([ 'id_transfer' => $transfer->id_transfer]);
if ( $transfer->delete() ){
\Yii::$app->session->setFlash( 'success','Bérlet törölve' );
$transaction->commit();
}else{
throw new \Exception("Failed to save");
}
} catch(Exception $e) {
$transaction->rollback();
\Yii::$app->session->setFlash( 'danger','Bérlet törlése nem sikerült' );
}
return $this->redirect(Yii::$app->request->referrer);
}
/**
* Finds the Ticket model based on its primary key value.
* If the model is not found, a 404 HTTP exception will be thrown.
* @param integer $id
* @return Ticket the loaded model
* @throws NotFoundHttpException if the model cannot be found
*/
protected function findModel($id)
{
if (($model = Ticket::findOne($id)) !== null) {
return $model;
} else {
throw new NotFoundHttpException('The requested page does not exist.');
}
}
}

View File

@ -9,6 +9,7 @@ use common\models\Customer;
use common\models\Ticket;
use common\models\Account;
use common\models\CardSearch;
use common\models\AccountState;
/**
* ContactForm is the model behind the contact form.
@ -21,6 +22,7 @@ class ReceptionForm extends Model
public $tickets;
public $defaultAccount;
public $cardSearchModel;
public $lastCassaState;
/**
* @inheritdoc
@ -58,10 +60,33 @@ class ReceptionForm extends Model
$this->defaultAccount = Account::findOne($defaultAccount);
}
$this->readLastCassaState();
$this->cardSearchModel = new CardSearch();
}
public function readLastCassaState(){
$a = Account::readDefault();
if ( isset($a)){
$this->lastCassaState = AccountState::find()->andWhere(['account_state.id_account' => $a])
->andWhere(['account_state.id_user' => \Yii::$app->user->id] )
->orderBy(['account_state.created_at' => SORT_DESC])
->limit(1)
->one();
}
}
public function hasCassa(){
return isset($this->lastCassaState) ;
}
public function isCassaOpen(){
return ( isset($this->lastCassaState) && $this->lastCassaState->isTypeOpen());
}
public function isCassaClose(){
return ( isset($this->lastCassaState) && $this->lastCassaState->isTypeClose());
}
public function getDefaultAccountName(){
$result = "";
if ( $this->defaultAccount ){

View File

@ -7,6 +7,7 @@ use frontend\components\HtmlHelper;
/* @var $this yii\web\View */
/* @var $model common\models\AccountState */
/* @var $form yii\widgets\ActiveForm */
/* @var $lastCassaState common\models\AccountState */
?>
@ -57,7 +58,6 @@ use frontend\components\HtmlHelper;
<div class="form-group">
<?= Html::submitButton( Yii::t('frontend/account-state', 'Close account'), ['class' => 'btn btn-primary']) ?>
</div>
<?php ActiveForm::end(); ?>
</div>

View File

@ -22,6 +22,7 @@ $this->registerJs ( 'new AccountState( '. json_encode($options).');' );
<?= $this->render('_form_close', [
'model' => $model,
'accounts' => $accounts,
'lastCassaState' => $lastCassaState,
]) ?>
</div>

View File

@ -8,11 +8,25 @@ use frontend\components\ReceptionTicketWidget;
use frontend\components\ReceptionCustomerWidget;
use yii\widgets\ActiveForm;
use yii\helpers\Html;
/** @var $model frontend\models\ReceptionForm */
?>
<?php
$alertClass = "info";
$cassaMessage = "Nyitva";
if ( $model->isCassaClose() ){
$alertClass = "danger";
$cassaMessage = "Zárva";
}else if ( !$model->hasCassa() ){
$alertClass = "danger";
$cassaMessage = "Nincs kassza kiválasztva";
}
?>
<div class='row'>
<div class='col-md-4'>
<div class="alert alert-info">
Aktuális kassza: <?php echo $model->getDefaultAccountName();?>
<div class="alert alert-<?php echo $alertClass;?>">
Aktuális kassza: <?php echo $model->getDefaultAccountName();?> -
<?php echo $cassaMessage;?>
</div>
</div>
<?php $form = ActiveForm::begin([

View File

@ -32,6 +32,10 @@ $this->params['breadcrumbs'][] = $this->title;
'name',
'money',
'created_at:datetime',
[
'attribute' => 'comment',
'format' => 'html'
],
['class' => 'yii\grid\ActionColumn',
'template' => '{view}'

View File

@ -59,11 +59,9 @@ $this->params['breadcrumbs'][] = $this->title;
*/
'price_brutto',
'created_at:datetime',
/*
['class' => 'yii\grid\ActionColumn',
'template' =>'{view} {update}',
'template' =>'{delete}',
],
*/
],
]); ?>

View File

@ -3,9 +3,11 @@ use yii\helpers\Html;
use yii\grid\GridView;
use yii\widgets\ListView;
use yii\base\Widget;
use yii\helpers\Url;
use common\components\Helper;
/* @var $this yii\web\View */
/* @var $searchModel common\models\TransferSearch */
/* @var $searchModel common\models\TransferListSearch */
/* @var $dataProvider yii\data\ActiveDataProvider */
$this->title = Yii::t ( 'frontend/transfer', 'Daily transfers' );
@ -82,10 +84,31 @@ td.name{
</tr>
<tr>
<th>Végösszeg</th>
<td class="money"><span style='border-bottom: 1px solid black'><?php echo $searchModel->total?> FT</span></td>
<td class="money"><span style='border-bottom: 1px solid black'><?php echo \Yii::$app->formatter->asInteger($searchModel->total)?> FT</span></td>
</tr>
</tbody>
</table>
<?php if ( $searchModel->isModeReception() && Helper::isAccountStateClosePreloadMoney()){?>
<h2>Aktuális záró összeg</h2>
<table class="table table-bordered table-striped table-summary">
<tbody>
<tr>
<th>Kasszanyitás</th>
<td class="money"><span style=' '><?php echo isset($searchModel->cassaOpen) ? \Yii::$app->formatter->asInteger( $searchModel->cassaOpen->money ) : ""?> FT</span></td>
</tr>
<tr>
<th>Végösszeg</th>
<td class="money"><span style=' '><?php echo \Yii::$app->formatter->asInteger($searchModel->total)?> FT</span></td>
</tr>
<tr>
<th>Kasszában lévő összeg</th>
<td class="money"><span style='border-bottom: 1px solid black'><?php echo \Yii::$app->formatter->asInteger( $searchModel->totalWithCassa ) ?> FT</span></td>
</tr>
</tbody>
</table>
<?php echo Html::a("Ugrás kassza zárásra",Url::toRoute([ 'account-state/close', 'money' => $searchModel->totalWithCassa ]), ['class' =>'btn btn-primary'])?>
<?php }?>
</div>
<div role="tabpanel" class="tab-pane" id="medium">
<h2>Közepes összesítés</h2>
@ -351,6 +374,7 @@ td.name{
<th>Név</th>
<th>Típus</th>
<th>Összeg</th>
<th>Megjegyzés</th>
</tr>
</thead>
<tbody>
@ -362,6 +386,7 @@ td.name{
<td><?php echo $p['money_movement_name'] ?></td>
<td><?php echo $p['money_movement_type_name'] ?></td>
<td class='money'><?php echo $p['signed_money']?> Ft</td>
<td><?php echo $p['money_movement_comment'] ?></td>
</tr>
<?php } ?>