diff --git a/backend/controllers/CardController.php b/backend/controllers/CardController.php index 2aff649..78b57de 100644 --- a/backend/controllers/CardController.php +++ b/backend/controllers/CardController.php @@ -389,10 +389,18 @@ class CardController extends \backend\controllers\BackendController { $command = $connection->createCommand( Ticket::$SQL_UPDATE ); $result = $command->execute(); \Yii::info("Tickets updated: " . $result ); - - \Yii::$app->session->setFlash('success', 'Módosított bérletek száma: ' . $result); - + + $command = $connection->createCommand( Card::$SQL_CLEARS_STATUS_DOOR ); + $result = $command->execute(); + \Yii::info("Door flag cleared: " . $result ); + + $command = $connection->createCommand( Card::$SQL_FIX_KEY_STATUS ); + $result = $command->execute(); + \Yii::info("Key flag fixed: " . $result ); + + + } return $this->render("recalculate"); diff --git a/backend/controllers/ContractController.php b/backend/controllers/ContractController.php index 73d8248..6e41790 100644 --- a/backend/controllers/ContractController.php +++ b/backend/controllers/ContractController.php @@ -137,13 +137,17 @@ class ContractController extends Controller { ] ); } } - + /** * Deletes an existing Contract model. * If deletion is successful, the browser will be redirected to the 'index' page. - * - * @param integer $id + * + * @param integer $id * @return mixed + * @throws Exception + * @throws NotFoundHttpException + * @throws \Exception + * @throws \yii\db\Exception */ public function actionDelete($id) { $model = $this->findModel ( $id ); diff --git a/backend/models/CardSearch.php b/backend/models/CardSearch.php index 19e8035..5972894 100644 --- a/backend/models/CardSearch.php +++ b/backend/models/CardSearch.php @@ -63,7 +63,7 @@ class CardSearch extends Card 'customer.name as customer_name' , 'customer.id_customer as customer_id_customer', 'key.number as key_number', - 'card.flag as card_flag', + 'card.validity as card_validity', ]); @@ -107,7 +107,7 @@ class CardSearch extends Card 'asc' => ['key.number' => SORT_ASC ], 'desc' => ['key.number' => SORT_DESC], ], - 'card_flag' => [ + 'card_validity' => [ 'asc' => ['card.flag' => SORT_ASC ], 'desc' => ['card.flag' => SORT_DESC], ], diff --git a/backend/views/card/index.php b/backend/views/card/index.php index 3c9f955..2c8632f 100644 --- a/backend/views/card/index.php +++ b/backend/views/card/index.php @@ -69,10 +69,10 @@ $this->params['breadcrumbs'][] = $this->title; 'label' => 'Kulcs száma' ], [ - 'attribute' => 'card_flag', + 'attribute' => 'card_validity', 'label' => 'Info', 'value' => function ($model, $key, $index, $column){ - return Helper::getArrayValue(DoorLog::getCardFlagTexts(), $model['card_flag'], "Ismeretlen ok"); + return Helper::getArrayValue(DoorLog::getCardFlagTexts(), $model['card_validity'], "Ismeretlen ok"); } ], diff --git a/common/components/Helper.php b/common/components/Helper.php index 8d4d8bf..4d6f2b9 100644 --- a/common/components/Helper.php +++ b/common/components/Helper.php @@ -396,7 +396,13 @@ class Helper { } return $flag; } - + + public static function isBitOn($flag,$n){ + $result = +$flag & (1 << +$n) ; + $result = $result > 0; + return $result ; + } + public static function generateRandomString($length = 6,$characters = '0123456789ABCDEFGHIJKLMNOPQRSTUVWX' ) { $charactersLength = strlen($characters); diff --git a/common/models/Card.php b/common/models/Card.php index f6160ea..7b87adc 100644 --- a/common/models/Card.php +++ b/common/models/Card.php @@ -15,6 +15,7 @@ use common\components\Helper; * @property integer $flag * @property string $created_at * @property string $updated_at + * @property int flag_out */ class Card extends \common\models\BaseFitnessActiveRecord { @@ -30,7 +31,32 @@ class Card extends \common\models\BaseFitnessActiveRecord public static $FLAG_TICKET = 0; - public static $FLAG_STATUS = 1; + public static $FLAG_DOOR = 1; + public static $FLAG_KEY = 2; + public static $FLAG_STATUS = 3; + + /** + * This script is used in daily scripts, to clear the flag door log status + * + * @var string + */ + public static $SQL_CLEARS_STATUS_DOOR = " + UPDATE card set flag = ( flag & ~(1 << 1 ) ), flag_out= ( flag_out & ~(1 << 1 ) ) where card.type <> 50 + "; + + public static $SQL_FIX_KEY_STATUS = " + update card as c1 + left join card_key_assignment k + on k.id_card = c1.id_card + set flag = CASE WHEN k.id_key is null then (c1.flag | 1 << 2) else ( c1.flag & ~(1 << 2 ) ) end, + flag_out = CASE WHEN k.id_key is null then ( c1.flag_out & ~(1 << 2 )) else (c1.flag_out | 1 << 2 ) end + WHERE c1.type <> 50 + "; + + public static $SQL_CLEARS_STATUS_DOOR_IN = " + UPDATE card set flag = ( flag & ~(1 << 1 ) ) WHERE card.type <> 50 and card.id_card = :id + "; + /** * @inheritdoc */ @@ -175,13 +201,17 @@ class Card extends \common\models\BaseFitnessActiveRecord return ; } $db = \Yii::$app->db; + $command = $db->createCommand(Ticket::$SQL_UPDATE_CARD,[':id' => $id]); $command->execute(); + + $command = $db->createCommand(Card::$SQL_CLEARS_STATUS_DOOR_IN,[':id' => $id]); + $command->execute(); } public function beforeSave($insert) { if (parent::beforeSave($insert)){ - $this->flag = Helper::setBit($this->flag, Card::$FLAG_STATUS, ( $this->status != Card::STATUS_ACTIVE)); + $this->flag = Helper::setBit( $this->flag , Card::$FLAG_STATUS, ( $this->status != Card::STATUS_ACTIVE ) ); return true; } return false; @@ -189,7 +219,42 @@ class Card extends \common\models\BaseFitnessActiveRecord public function getFlagText(){ - return Helper::getArrayValue(DoorLog::getCardFlagTexts(), $this->flag, "Ismeretlen"); + return Helper::getArrayValue(DoorLog::getCardFlagTexts(), $this->validity, "Ismeretlen"); } - + + public function setFlagsHasKey($hasKey){ + + $pos = Card::$FLAG_KEY; + $this->flag = $hasKey ? ( $this->flag & ~(1 << $pos) ) : ( $this->flag | 1 << $pos ); + $this->flag_out = $hasKey ? ( $this->flag_out | 1 << $pos ) : ( $this->flag_out & ~(1 << $pos) ); + \Yii::info("flag has key: ".$this->flag .";".$this->flag_out); + } + + + public function isFlagValidity(){ + return Helper::isBitOn($this->flag,Card::$FLAG_TICKET); + } + + public function isFlagDoor(){ + return Helper::isBitOn($this->flag,Card::$FLAG_DOOR); + } + + public function isFlagKey(){ + return Helper::isBitOn($this->flag,Card::$FLAG_KEY); + } + + public function isFlagStatus(){ + return Helper::isBitOn($this->flag,Card::$FLAG_STATUS); + } + + public function isFlagOutDoor(){ + return Helper::isBitOn($this->flag_out,Card::$FLAG_DOOR); + } + + public function isFlagOutKey(){ + return Helper::isBitOn($this->flag_out,Card::$FLAG_KEY); + } + + + } diff --git a/common/models/DoorLog.php b/common/models/DoorLog.php index 9c473db..c4dc53a 100644 --- a/common/models/DoorLog.php +++ b/common/models/DoorLog.php @@ -188,7 +188,7 @@ class DoorLog extends \yii\db\ActiveRecord $dlog->id_account = Account::readDefault(); if ( $dlog->direction == 0){ - $dlog->card_flag = $card->flag; + $dlog->card_flag = $card->validity; }else{ $dlog->card_flag = -1; } diff --git a/common/models/Ticket.php b/common/models/Ticket.php index 81635f1..8f9dd1e 100644 --- a/common/models/Ticket.php +++ b/common/models/Ticket.php @@ -47,7 +47,8 @@ class Ticket extends \common\models\BaseFitnessActiveRecord order by id_card desc ) as t on t.id_card = c1.id_card - SET c1.flag = case when t.id_card is null then ( c1.flag | 1 << 0 ) else ( c1.flag & ~(1 << 0) ) end + SET c1.validity = case when t.id_card is null then ( c1.validity | 1 << 0 ) else ( c1.validity & ~(1 << 0) ) end + , 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"; @@ -63,7 +64,8 @@ class Ticket extends \common\models\BaseFitnessActiveRecord order by id_card desc ) as t on t.id_card = c1.id_card - SET c1.flag = case when t.id_card is null then ( c1.flag | 1 << 0 ) else ( c1.flag & ~(1 << 0) ) end + SET c1.validity = case when t.id_card is null then ( c1.validity | 1 << 0 ) else ( c1.validity & ~(1 << 0) ) end + ,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"; diff --git a/console/controllers/DoorlogController.php b/console/controllers/DoorlogController.php index fd58b0e..c6d2b76 100644 --- a/console/controllers/DoorlogController.php +++ b/console/controllers/DoorlogController.php @@ -75,7 +75,7 @@ class DoorlogController extends Controller{ $card = $subject->card; - echo "in:" . $subject->usage_count. " | out:" . $subject->count_move_out . " | max: " .$subject->max_usage_count. " | card flag: " . $card->flag ."\n"; + echo "in:" . $subject->usage_count. " | out:" . $subject->count_move_out . " | max: " .$subject->max_usage_count. " | card validity: " . $card->validity ."\n"; } diff --git a/console/controllers/ProductConsoleController.php b/console/controllers/ProductConsoleController.php new file mode 100644 index 0000000..658645f --- /dev/null +++ b/console/controllers/ProductConsoleController.php @@ -0,0 +1,25 @@ +db; - $command = $connection->createCommand ( Ticket::$SQL_UPDATE ); + + $command = $connection->createCommand ( Card::$SQL_CLEARS_STATUS_DOOR ); + $result = $command->execute (); + \Yii::info ( "Tickets updated flag door: " . $result ); + + $command = $connection->createCommand ( Ticket::$SQL_UPDATE ); $result = $command->execute (); \Yii::info ( "Tickets updated: " . $result ); - echo "Tickets updated: " . $result; + + + $command = $connection->createCommand ( Card::$SQL_FIX_KEY_STATUS ); + $result = $command->execute (); } /** diff --git a/console/migrations/m160919_061627_alter__table__card__add__column__validity.php b/console/migrations/m160919_061627_alter__table__card__add__column__validity.php new file mode 100644 index 0000000..f32c848 --- /dev/null +++ b/console/migrations/m160919_061627_alter__table__card__add__column__validity.php @@ -0,0 +1,30 @@ +addColumn("card", "validity", "int default 0"); + } + + public function down() + { + echo "m160919_061627_alter__table__card__add__column__validity cannot be reverted.\n"; + + return false; + } + + /* + // Use safeUp/safeDown to run migration code within a transaction + public function safeUp() + { + } + + public function safeDown() + { + } + */ +} diff --git a/cutler_daily.sh b/cutler_daily.sh index a28c4aa..eb2839a 100644 --- a/cutler_daily.sh +++ b/cutler_daily.sh @@ -1,3 +1,4 @@ +#!/usr/bin/env bash php /var/www/virtual/fitnessadmin.hu/htdocs/cutler/yii ticket/index php /var/www/virtual/fitnessadmin.hu/htdocs/cutler/yii ticket/daily \ No newline at end of file diff --git a/frontend/controllers/CardController.php b/frontend/controllers/CardController.php index e370207..6eab957 100644 --- a/frontend/controllers/CardController.php +++ b/frontend/controllers/CardController.php @@ -90,6 +90,14 @@ class CardController extends Controller 'dataProvider' => $dataProvider, ]); } + + public function actionInfo($id_card){ + + $card = $this->findModel($id_card); + + + return $this->render("info",['card' => $card]); + } diff --git a/frontend/controllers/CustomerController.php b/frontend/controllers/CustomerController.php index 15e384e..19cbcdb 100644 --- a/frontend/controllers/CustomerController.php +++ b/frontend/controllers/CustomerController.php @@ -143,12 +143,14 @@ class CustomerController extends Controller } } -/** - * Updates an existing Customer model. - * If update is successful, the browser will be redirected to the 'view' page. - * @param integer $id - * @return mixed - */ + /** + * Updates an existing Customer model. + * If update is successful, the browser will be redirected to the 'view' page. + * @param null $number + * @return mixed + * @throws NotFoundHttpException + * @internal param int $id + */ public function actionUpdate($number = null) { $card = null; diff --git a/frontend/models/KeyToggleForm.php b/frontend/models/KeyToggleForm.php index 5b87abe..9e97cf3 100644 --- a/frontend/models/KeyToggleForm.php +++ b/frontend/models/KeyToggleForm.php @@ -15,6 +15,9 @@ use common\models\Card; /** * ContactForm is the model behind the contact form. * + * @property \common\models\Card $card + * @property \common\models\Key $key + * */ class KeyToggleForm extends Model { @@ -97,6 +100,9 @@ class KeyToggleForm extends Model $assignment->save(false); \Yii::$app->session->setFlash ( 'success', 'Kulcs kiadva!' ); + $this->card->setFlagsHasKey(true); + $this->card->save(false); + Log::log([ 'type' =>Log::$TYPE_KEY_ASSIGN, 'message' => 'Kulcs kiadás - Kártya/Kulcs/Vendég:' .$this->card->number ."/" .$this->keyModel->number . "/".$this->customer->name, @@ -113,6 +119,8 @@ class KeyToggleForm extends Model public function unassign(){ CardKeyAssignment::deleteAll(['id_key' => $this->keyModel->id_key]); + $this->card->setFlagsHasKey(false); + $this->card->save(false); \Yii::$app->session->setFlash ( 'success', 'Kulcs visszaadva!' ); } diff --git a/frontend/models/ReceptionForm.php b/frontend/models/ReceptionForm.php index 30a9f66..c24db87 100644 --- a/frontend/models/ReceptionForm.php +++ b/frontend/models/ReceptionForm.php @@ -117,7 +117,7 @@ class ReceptionForm extends Model $dlog->id_account = Account::readDefault(); - $dlog->card_flag = $this->card->flag; + $dlog->card_flag = $this->card->validity; $dlog->created_at = date('Y-m-d H:i:s'); $dlog->save(false); diff --git a/frontend/views/card/info.php b/frontend/views/card/info.php new file mode 100644 index 0000000..94b39ef --- /dev/null +++ b/frontend/views/card/info.php @@ -0,0 +1,69 @@ +title = "Kártya info"; +$this->params['breadcrumbs'][] = $this->title; +?> + + $card]) ?> + + +
Ez az adat jelzi, hogy a vendég az adott napon már belépett -e a terembe vagy sem.
+ Ha a vendégnek pl 10 alkalmas bérlete van, akkor egy nap többször is beléphet.
+ Viszont ha korlátlan belépési számú bérlete van (pl: havi bérlet ), akkor naponta csak egyszer léphet be.
+