From f538a82def845f1bc5672534a71bec4b8dc35997 Mon Sep 17 00:00:00 2001 From: Roland Schneider Date: Sat, 17 Jun 2017 22:01:11 +0200 Subject: [PATCH] add mover cutler door --- backend/controllers/CardController.php | 12 ++++ backend/views/ticket-type/_form.php | 6 +- backend/views/ticket-type/index.php | 64 ++++++++++++--------- backend/views/ticket-type/view.php | 5 ++ common/components/Helper.php | 4 ++ common/config/params.php | 3 +- common/models/Card.php | 34 +++++++++-- common/models/Ticket.php | 23 ++++++-- common/models/TicketType.php | 17 ++++++ console/controllers/TicketController.php | 12 ++++ frontend/models/ReceptionForm.php | 2 + frontend/views/card/info.php | 13 +++++ frontend/views/common/_reception_ticket.php | 24 +++++--- 13 files changed, 175 insertions(+), 44 deletions(-) diff --git a/backend/controllers/CardController.php b/backend/controllers/CardController.php index 717359b..3fa1b25 100644 --- a/backend/controllers/CardController.php +++ b/backend/controllers/CardController.php @@ -405,6 +405,18 @@ class CardController extends \backend\controllers\BackendController { $result = $command->execute(); \Yii::info("Clearing flag key ready: " . $result ); } + + if ( Helper::isTicketTypeDoorAllowedCheckOn()){ + \Yii::info ( "updating door allowed flag" ); + $command = $connection->createCommand ( Ticket::SQL_UPDATE_DOOR_ALLOWED_FLAG() ); + $result = $command->execute (); + \Yii::info ( "Door allowed flag updated: ". $result ); + }else{ + \Yii::info ( "clearing door allowed flag" ); + $command = $connection->createCommand ( Card::SQL_CLEAR_STATUS_DOOR_ALLOWED_FLAG() ); + $result = $command->execute (); + \Yii::info ( "Door allowed flag cleared: ". $result ); + } } return $this->render("recalculate"); } diff --git a/backend/views/ticket-type/_form.php b/backend/views/ticket-type/_form.php index 3c3ff86..ea80d2d 100644 --- a/backend/views/ticket-type/_form.php +++ b/backend/views/ticket-type/_form.php @@ -56,13 +56,17 @@ use yii\helpers\ArrayHelper; field($model, 'status')->checkbox( ['value' => 10, 'label' => Yii::t('common/ticket_type', "Active") ]) ?> field($model, 'flag_student')->checkbox( ['value' => 1, 'label' => Yii::t('common/ticket_type', "Student") ]) ?> - + field($model, 'installment_enabled')->checkbox( ['value' => 1, 'label' => Yii::t('common/ticket_type', "Csoportos beszedéses a bruttó áron felül") ]) ?>

A részletek havonta kerülnek beszedésre

field($model, 'installment_money')->textInput() ?> field($model, 'installment_count')->textInput() ?> + + field($model, 'door_allowed')->checkbox( ['value' => 1, 'label' => 'Forgóvilla engedi' ]) ?> + +
isNewRecord ? Yii::t('common/ticket_type', 'Create') : Yii::t('common/ticket_type', 'Update'), ['class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary']) ?>
diff --git a/backend/views/ticket-type/index.php b/backend/views/ticket-type/index.php index 96abced..382ebc2 100644 --- a/backend/views/ticket-type/index.php +++ b/backend/views/ticket-type/index.php @@ -21,42 +21,54 @@ $this->params['breadcrumbs'][] = $this->title;

- $dataProvider, - 'columns' => [ + + 'time_unit_type', - 'value' =>'timeUnitHuman', - ], [ - 'attribute' => 'id_account', - 'value' => 'accountName', - ], - [ - 'attribute' =>'flag_student', - 'value' =>function($model, $key, $index, $column){ - return $model->isStudent() ? Yii::t('common', "Yes") : Yii::t('common', "No") ; - }, - ], - [ - 'attribute' =>'status', - 'value' =>'statusHuman', - ], + 'attribute' =>'time_unit_type', + 'value' =>'timeUnitHuman', + ], + [ + 'attribute' => 'id_account', + 'value' => 'accountName', + ], + [ + 'attribute' =>'flag_student', + 'value' =>function($model, $key, $index, $column){ + return $model->isStudent() ? Yii::t('common', "Yes") : Yii::t('common', "No") ; + }, + + ], + [ + 'attribute' =>'door_allowed', + 'value' =>function($model, $key, $index, $column){ + return $model->isDoor() ? Yii::t('common', "Yes") : Yii::t('common', "No") ; + }, + 'visible' => \common\components\Helper::isTicketTypeDoorAllowedCheckOn() + + ], + [ + 'attribute' =>'status', + 'value' =>'statusHuman', + ], 'created_at:datetime', 'updated_at:datetime', [ - 'class' => 'yii\grid\ActionColumn', - 'template' => RoleDefinition::getRoleTemplate( ['admin' => '{view} {update}','employee' => '{view}' , 'reception' => '{view}']), - - ], - ], + 'class' => 'yii\grid\ActionColumn', + 'template' => RoleDefinition::getRoleTemplate( ['admin' => '{view} {update}','employee' => '{view}' , 'reception' => '{view}']), + + ], + ]; + ?> + $dataProvider, + 'columns' => $columns ]); ?> diff --git a/backend/views/ticket-type/view.php b/backend/views/ticket-type/view.php index 3396d34..02fc174 100644 --- a/backend/views/ticket-type/view.php +++ b/backend/views/ticket-type/view.php @@ -50,6 +50,11 @@ $this->params['breadcrumbs'][] = $this->title; 'attribute' => 'status', 'value' => $model->statusHuman ], + [ + 'attribute' => 'door_allowed', + 'value' => ( $model->isDoor() ? Yii::t('common', 'Yes' ) : Yii::t('common', 'No' ) ), + //'visible' => \common\components\Helper::isTicketTypeDoorAllowedCheckOn() + ], 'created_at:datetime', 'updated_at:datetime', [ diff --git a/common/components/Helper.php b/common/components/Helper.php index 54fc469..8e98063 100644 --- a/common/components/Helper.php +++ b/common/components/Helper.php @@ -348,6 +348,10 @@ class Helper { public static function isKeyRequired() { return \Yii::$app->params ['key_required'] == true; } + + public static function isTicketTypeDoorAllowedCheckOn() { + return \Yii::$app->params ['ticket_type_door_allowed_check_on'] == true; + } public static function getProductSaleDefaultFocus() { return \Yii::$app->params ['product_sale_default_focus'] ; diff --git a/common/config/params.php b/common/config/params.php index 574ad51..982f022 100644 --- a/common/config/params.php +++ b/common/config/params.php @@ -60,5 +60,6 @@ return [ */ 'key_toggle_door_log_enabled' => false, //if key required for entry trough the door - 'key_required' => true + 'key_required' => true, + 'ticket_type_door_allowed_check_on' => false ]; diff --git a/common/models/Card.php b/common/models/Card.php index 9286ba3..90020af 100644 --- a/common/models/Card.php +++ b/common/models/Card.php @@ -34,10 +34,11 @@ class Card extends \common\models\BaseFitnessActiveRecord const TYPE_EMPLOYEE = 50; - public static $FLAG_TICKET = 0; - public static $FLAG_DOOR = 1; - public static $FLAG_KEY = 2; - public static $FLAG_STATUS = 3; + public static $FLAG_TICKET = 0; //has valid ticket + public static $FLAG_DOOR = 1; //door in/out order + public static $FLAG_KEY = 2; //key status + public static $FLAG_STATUS = 3; //allowed/disabled + public static $FLAG_DOOR_ALLOWED = 4; //ticket type allows door /** * This script is used in daily scripts, to clear the flag door log status @@ -65,6 +66,15 @@ class Card extends \common\models\BaseFitnessActiveRecord UPDATE card set flag = ( flag & ~(1 << 1 ) ) WHERE card.type <> 50 and card.id_card = :id "; + public static function SQL_CLEAR_STATUS_DOOR_ALLOWED_FLAG(){ + return "UPDATE card set flag = ( flag & ~(1 << " . Card::$FLAG_DOOR_ALLOWED. " ) ) WHERE card.type <> 50 "; + } + + public static function SQL_CLEAR_STATUS_DOOR_ALLOWED_FLAG_FOR_CARD(){ + return Card::SQL_CLEAR_STATUS_DOOR_ALLOWED_FLAG() . " and card.id_card = :id "; + } + + /** * @inheritdoc */ @@ -227,6 +237,15 @@ class Card extends \common\models\BaseFitnessActiveRecord $command = $db->createCommand(Card::$SQL_CLEARS_STATUS_DOOR_IN,[':id' => $id]); $command->execute(); + + if ( Helper::isTicketTypeDoorAllowedCheckOn()) { + $command = $db->createCommand(Ticket::SQL_UPDATE_DOOR_ALLOWED_FLAG_FOR_CARD(), [':id' => $id]); + $command->execute(); + }else{ + $command = $db->createCommand(Card::SQL_CLEAR_STATUS_DOOR_ALLOWED_FLAG_FOR_CARD(), [':id' => $id]); + $command->execute(); + } + } public function beforeSave($insert) { @@ -279,6 +298,11 @@ class Card extends \common\models\BaseFitnessActiveRecord return Helper::isBitOn($this->flag_out,Card::$FLAG_KEY); } - + /** + * if flag is on, door entry is not allowed. + */ + public function isFlagDoorAllowed(){ + return Helper::isBitOn($this->flag,Card::$FLAG_DOOR_ALLOWED); + } } diff --git a/common/models/Ticket.php b/common/models/Ticket.php index 19a8f0c..9894739 100644 --- a/common/models/Ticket.php +++ b/common/models/Ticket.php @@ -73,8 +73,25 @@ class Ticket extends \common\models\BaseFitnessActiveRecord ,c1.flag = case when t.id_card is null then ( c1.flag | 1 << 0 ) else ( c1.flag & ~(1 << 0) ) end , c1.id_ticket_current = case when t.id_ticket is null then null else t.id_ticket end WHERE c1.type <> 50 and c1.id_card = :id"; - - + + + + public static function SQL_UPDATE_DOOR_ALLOWED_FLAG(){ + return " + UPDATE card c + LEFT JOIN ticket t on c.id_ticket_current = t.id_ticket + LEFT JOIN ticket_type tt on t.id_ticket_type = tt.id_ticket_type + set + c.flag = case when tt.door_allowed <> 1 then ( c.flag | 1 << 4 ) else ( c.flag & ~(1 << 4) ) end + WHERE c.type <> 50 + "; + } + + public static function SQL_UPDATE_DOOR_ALLOWED_FLAG_FOR_CARD(){ + return Ticket::SQL_UPDATE_DOOR_ALLOWED_FLAG() . " and c.id_card = :id"; + } + + /** * @inheritdoc */ @@ -395,6 +412,4 @@ class Ticket extends \common\models\BaseFitnessActiveRecord Card::updateCardFlagTicket($this->id_card);; } - - } diff --git a/common/models/TicketType.php b/common/models/TicketType.php index 2a03a4c..a424676 100644 --- a/common/models/TicketType.php +++ b/common/models/TicketType.php @@ -21,6 +21,7 @@ use yii\helpers\ArrayHelper; * @property integer installment_enabled * @property integer installment_count * @property integer installment_money + * @property integer door_allowed * @property string $created_at * @property string $updated_at */ @@ -38,6 +39,9 @@ class TicketType extends \common\models\BaseFitnessActiveRecord { const INSTALLMENT_OFF = 0; const INSTALLMENT_ON = 1; + + const FLAG_DOOR_ALLOWED_OFF = 0; + const FLAG_DOOR_ALLOWED_ON = 1; /** * @inheritdoc @@ -104,6 +108,13 @@ class TicketType extends \common\models\BaseFitnessActiveRecord { [['installment_money',], 'integer'], [['installment_count',], 'integer'], + + //////////////// + //door_allowed + //////////////// + [['door_allowed',], 'integer'], + [['door_allowed',], 'in', 'range' => [ self::FLAG_DOOR_ALLOWED_OFF, self::FLAG_DOOR_ALLOWED_ON ]], + ]; } @@ -128,6 +139,7 @@ class TicketType extends \common\models\BaseFitnessActiveRecord { 'installment_enabled' => Yii::t('common/ticket_type', 'Részlet fizetés a brutto áron felül'), 'installment_count' => Yii::t('common/ticket_type', 'Havi részletek száma'), 'installment_money' => Yii::t('common/ticket_type', 'Havi részlet összege'), + 'door_allowed' => Yii::t('common/ticket_type', 'Forgóvilla'), ]; } @@ -188,6 +200,11 @@ class TicketType extends \common\models\BaseFitnessActiveRecord { public function isStudent(){ return $this->flag_student == ( self::FLAG_STUDENT_ON); } + + public function isDoor(){ + return $this->door_allowed == ( self::FLAG_STUDENT_ON); + } + public function isInstallment(){ return $this->installment_enabled == ( self::INSTALLMENT_ON); } diff --git a/console/controllers/TicketController.php b/console/controllers/TicketController.php index cfe81ec..dc60595 100644 --- a/console/controllers/TicketController.php +++ b/console/controllers/TicketController.php @@ -40,6 +40,18 @@ class TicketController extends Controller { $result = $command->execute (); \Yii::info ( "Clearing key status updated: ". $result ); } + + if ( Helper::isTicketTypeDoorAllowedCheckOn()){ + \Yii::info ( "updating door allowed flag" ); + $command = $connection->createCommand ( Ticket::SQL_UPDATE_DOOR_ALLOWED_FLAG() ); + $result = $command->execute (); + \Yii::info ( "Door allowed flag updated: ". $result ); + }else{ + \Yii::info ( "clearing door allowed flag" ); + $command = $connection->createCommand ( Card::SQL_CLEAR_STATUS_DOOR_ALLOWED_FLAG() ); + $result = $command->execute (); + \Yii::info ( "Door allowed flag cleared: ". $result ); + } } /** diff --git a/frontend/models/ReceptionForm.php b/frontend/models/ReceptionForm.php index 9d79307..d08e277 100644 --- a/frontend/models/ReceptionForm.php +++ b/frontend/models/ReceptionForm.php @@ -19,6 +19,8 @@ use common\models\DoorLog; /** * ContactForm is the model behind the contact form. + * + * @property \common\models\Card $card */ class ReceptionForm extends Model { diff --git a/frontend/views/card/info.php b/frontend/views/card/info.php index 94b39ef..edc2ead 100644 --- a/frontend/views/card/info.php +++ b/frontend/views/card/info.php @@ -48,6 +48,19 @@ $this->params['breadcrumbs'][] = $this->title; echo Html::tag("span", "Kártya nincs tiltva - OK", ['class' => 'text-success']); } ?> + +
  • Bérlet beléphet a forgókapun: + isFlagDoorAllowed()) { + echo Html::tag("span", "Beléphet - Nem", ['class' => 'text-danger']); + } else { + echo Html::tag("span", "Beléphet - Igen", ['class' => 'text-success']); + } ?> +
  • +

    Kilépés jelző

    diff --git a/frontend/views/common/_reception_ticket.php b/frontend/views/common/_reception_ticket.php index d60a594..70fd006 100644 --- a/frontend/views/common/_reception_ticket.php +++ b/frontend/views/common/_reception_ticket.php @@ -1,13 +1,8 @@ card)){ echo " - "; echo Yii::$app->formatter->asDate($ticket->end); echo Html::endTag("div"); + + }else{ echo Html::beginTag("div",['class'=>"alert alert-danger", "role"=>"alert"]); echo Html::beginTag("strong",[ ]); @@ -72,6 +69,19 @@ if ( isset($model->card)){ echo Html::endTag("div"); } +if (Helper::isTicketTypeDoorAllowedCheckOn()) { + if (isset($model->card) && isset($ticket) ) { + $alert = "alert " . ($model->card->isFlagDoorAllowed() ? "alert-warning" : "alert-success"); + $text = "Kapun beléphet: " .($model->card->isFlagDoorAllowed() ? "nem" : "igen"); + + echo Html::beginTag("div",['class' => $alert ,"role"=>"alert"]); + echo Html::beginTag("strong",[ ]); + echo $text; + echo Html::endTag("strong"); + echo Html::endTag("div"); + + } +} if ( isset($model->contract)){ /** @var common\models\Contract $contract*/