From 7c584a077982c5c343c1490be91e4a52c0b3e3b4 Mon Sep 17 00:00:00 2001 From: Roland Schneider Date: Sun, 10 Jan 2016 15:25:25 +0100 Subject: [PATCH] add display money to account state close, delete ticket on customer tickets --- common/components/DailyListing.php | 45 +++++++++++++++-- common/components/Helper.php | 3 ++ .../accountstate/AccountStateMail.php | 10 ++-- .../total/TotalCassaOpenInfoWidget.php | 9 ++++ common/config/params.php | 1 + common/mail/account_state.php | 3 ++ common/messages/hu/common/account_state.php | 2 +- common/models/AccountState.php | 13 ++++- common/models/TransferListSearch.php | 30 +++++++++++- .../views/account-state/account_state_pdf.php | 3 ++ common/views/total/total_cassa_open.php | 31 ++++++++++++ .../total/total_detailed_money_movement.php | 2 + .../controllers/AccountStateController.php | 26 +++++++++- frontend/controllers/TicketController.php | 49 +++++++++++++++++++ frontend/models/ReceptionForm.php | 25 ++++++++++ frontend/views/account-state/_form_close.php | 2 +- frontend/views/account-state/close.php | 1 + frontend/views/common/_reception.php | 18 ++++++- frontend/views/money-movement/index.php | 4 ++ frontend/views/ticket/index.php | 4 +- frontend/views/transfer/list.php | 29 ++++++++++- 21 files changed, 291 insertions(+), 19 deletions(-) create mode 100644 common/components/total/TotalCassaOpenInfoWidget.php create mode 100644 common/views/total/total_cassa_open.php diff --git a/common/components/DailyListing.php b/common/components/DailyListing.php index 7fad687..85340f0 100644 --- a/common/components/DailyListing.php +++ b/common/components/DailyListing.php @@ -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,7 +109,15 @@ 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(); $this->readProductsMoney(); @@ -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"); diff --git a/common/components/Helper.php b/common/components/Helper.php index 607aa37..d8b3a75 100644 --- a/common/components/Helper.php +++ b/common/components/Helper.php @@ -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']; diff --git a/common/components/accountstate/AccountStateMail.php b/common/components/accountstate/AccountStateMail.php index 105ab3f..089d02c 100644 --- a/common/components/accountstate/AccountStateMail.php +++ b/common/components/accountstate/AccountStateMail.php @@ -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(); diff --git a/common/components/total/TotalCassaOpenInfoWidget.php b/common/components/total/TotalCassaOpenInfoWidget.php new file mode 100644 index 0000000..cd049cb --- /dev/null +++ b/common/components/total/TotalCassaOpenInfoWidget.php @@ -0,0 +1,9 @@ + 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 ]; diff --git a/common/mail/account_state.php b/common/mail/account_state.php index 925643e..feee931 100644 --- a/common/mail/account_state.php +++ b/common/mail/account_state.php @@ -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 ){ type == AccountState::TYPE_CLOSE ){?> $details]);?> + + $details]);?>

Közepes összesítés

Bérletek típus szerint

$details]);?> diff --git a/common/messages/hu/common/account_state.php b/common/messages/hu/common/account_state.php index 1bc3391..e28833d 100644 --- a/common/messages/hu/common/account_state.php +++ b/common/messages/hu/common/account_state.php @@ -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', ]; diff --git a/common/models/AccountState.php b/common/models/AccountState.php index 4251258..197c0b7 100644 --- a/common/models/AccountState.php +++ b/common/models/AccountState.php @@ -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 */ diff --git a/common/models/TransferListSearch.php b/common/models/TransferListSearch.php index e920419..efd3997 100644 --- a/common/models/TransferListSearch.php +++ b/common/models/TransferListSearch.php @@ -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"); diff --git a/common/views/account-state/account_state_pdf.php b/common/views/account-state/account_state_pdf.php index 6c3df5c..ca3ab93 100644 --- a/common/views/account-state/account_state_pdf.php +++ b/common/views/account-state/account_state_pdf.php @@ -62,6 +62,9 @@ if ( $model ->type == AccountState::TYPE_OPEN ){ $model]); ?> + + + hasDifferenceToPrevState() ){ ?> diff --git a/common/views/total/total_cassa_open.php b/common/views/total/total_cassa_open.php new file mode 100644 index 0000000..734e98f --- /dev/null +++ b/common/views/total/total_cassa_open.php @@ -0,0 +1,31 @@ + +showWithCassaOpen && isset($model->cassaOpen) ){?> +

Aktuális záró összeg

+ + + + + + + + + + + + + + + + + + + + + + + +
Kasszanyitás cassaOpen->user->username ) ?>
Kasszanyitás idejecassaOpen->created_at ) ?>
Kasszanyitás összegecassaOpen) ? \Yii::$app->formatter->asInteger( $model->cassaOpen->money ) : ""?> FT
Végösszegformatter->asInteger($model->total)?> FT
Kasszában lévő összegformatter->asInteger( $model->totalWithCassa ) ?> FT
+ \ No newline at end of file diff --git a/common/views/total/total_detailed_money_movement.php b/common/views/total/total_detailed_money_movement.php index 140fe2f..8b22905 100644 --- a/common/views/total/total_detailed_money_movement.php +++ b/common/views/total/total_detailed_money_movement.php @@ -8,6 +8,7 @@ Név Típus Összeg + Megjegyzés @@ -19,6 +20,7 @@ formatter->asInteger( $p['signed_money'])?> Ft + diff --git a/frontend/controllers/AccountStateController.php b/frontend/controllers/AccountStateController.php index 86d8d4e..a02c764 100644 --- a/frontend/controllers/AccountStateController.php +++ b/frontend/controllers/AccountStateController.php @@ -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. diff --git a/frontend/controllers/TicketController.php b/frontend/controllers/TicketController.php index 9306887..ad3253e 100644 --- a/frontend/controllers/TicketController.php +++ b/frontend/controllers/TicketController.php @@ -126,5 +126,54 @@ class TicketController extends FrontendController 'receptionForm' => $receptionForm, ]); } + + /** + * 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.'); + } + } + } diff --git a/frontend/models/ReceptionForm.php b/frontend/models/ReceptionForm.php index 5d4159e..814a5ab 100644 --- a/frontend/models/ReceptionForm.php +++ b/frontend/models/ReceptionForm.php @@ -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 ){ diff --git a/frontend/views/account-state/_form_close.php b/frontend/views/account-state/_form_close.php index 11839c0..a023ef5 100644 --- a/frontend/views/account-state/_form_close.php +++ b/frontend/views/account-state/_form_close.php @@ -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;
'btn btn-primary']) ?>
- diff --git a/frontend/views/account-state/close.php b/frontend/views/account-state/close.php index 2378870..8bbaa43 100644 --- a/frontend/views/account-state/close.php +++ b/frontend/views/account-state/close.php @@ -22,6 +22,7 @@ $this->registerJs ( 'new AccountState( '. json_encode($options).');' ); render('_form_close', [ 'model' => $model, 'accounts' => $accounts, + 'lastCassaState' => $lastCassaState, ]) ?> diff --git a/frontend/views/common/_reception.php b/frontend/views/common/_reception.php index 1f9d128..8a39fc6 100644 --- a/frontend/views/common/_reception.php +++ b/frontend/views/common/_reception.php @@ -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 */ +?> +isCassaClose() ){ + $alertClass = "danger"; + $cassaMessage = "Zárva"; + }else if ( !$model->hasCassa() ){ + $alertClass = "danger"; + $cassaMessage = "Nincs kassza kiválasztva"; + } ?>
-
- Aktuális kassza: getDefaultAccountName();?> +
+ Aktuális kassza: getDefaultAccountName();?> - +
params['breadcrumbs'][] = $this->title; 'name', 'money', 'created_at:datetime', + [ + 'attribute' => 'comment', + 'format' => 'html' + ], ['class' => 'yii\grid\ActionColumn', 'template' => '{view}' diff --git a/frontend/views/ticket/index.php b/frontend/views/ticket/index.php index 1d9b78d..3386bba 100644 --- a/frontend/views/ticket/index.php +++ b/frontend/views/ticket/index.php @@ -59,11 +59,9 @@ $this->params['breadcrumbs'][] = $this->title; */ 'price_brutto', 'created_at:datetime', - /* ['class' => 'yii\grid\ActionColumn', - 'template' =>'{view} {update}', + 'template' =>'{delete}', ], - */ ], ]); ?> diff --git a/frontend/views/transfer/list.php b/frontend/views/transfer/list.php index 4015789..f8f00b0 100644 --- a/frontend/views/transfer/list.php +++ b/frontend/views/transfer/list.php @@ -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{ Végösszeg - total?> FT + formatter->asInteger($searchModel->total)?> FT + isModeReception() && Helper::isAccountStateClosePreloadMoney()){?> +

Aktuális záró összeg

+ + + + + + + + + + + + + + + +
KasszanyitáscassaOpen) ? \Yii::$app->formatter->asInteger( $searchModel->cassaOpen->money ) : ""?> FT
Végösszegformatter->asInteger($searchModel->total)?> FT
Kasszában lévő összegformatter->asInteger( $searchModel->totalWithCassa ) ?> FT
+ $searchModel->totalWithCassa ]), ['class' =>'btn btn-primary'])?> + +

Közepes összesítés

@@ -351,6 +374,7 @@ td.name{ Név Típus Összeg + Megjegyzés @@ -362,6 +386,7 @@ td.name{ Ft +