restore flag_out logic, toggleKey logic

This commit is contained in:
rocho 2016-12-29 19:17:31 +01:00
parent c673c5f73d
commit 6de07dac93
8 changed files with 100 additions and 67 deletions

View File

@ -391,13 +391,13 @@ class CardController extends \backend\controllers\BackendController {
\Yii::info("Tickets updated: " . $result ); \Yii::info("Tickets updated: " . $result );
\Yii::$app->session->setFlash('success', 'Módosított bérletek száma: ' . $result); \Yii::$app->session->setFlash('success', 'Módosított bérletek száma: ' . $result);
// $command = $connection->createCommand( Card::$SQL_CLEARS_STATUS_DOOR ); $command = $connection->createCommand( Card::$SQL_CLEARS_STATUS_DOOR );
// $result = $command->execute(); $result = $command->execute();
// \Yii::info("Door flag cleared: " . $result ); \Yii::info("Door flag cleared: " . $result );
//
// $command = $connection->createCommand( Card::$SQL_FIX_KEY_STATUS ); $command = $connection->createCommand( Card::$SQL_FIX_KEY_STATUS );
// $result = $command->execute(); $result = $command->execute();
// \Yii::info("Key flag fixed: " . $result ); \Yii::info("Key flag fixed: " . $result );

View File

@ -1,3 +1,6 @@
-0.0.94
- restore flag_out logic
- add toggleKey changes
-0.0.93 -0.0.93
- add shebang line to botond_daily script - add shebang line to botond_daily script
-0.0.92 -0.0.92

View File

@ -5,7 +5,7 @@ return [
'supportEmail' => 'rocho02@gmail.com', 'supportEmail' => 'rocho02@gmail.com',
'infoEmail' => 'info@rocho-net.hu', 'infoEmail' => 'info@rocho-net.hu',
'user.passwordResetTokenExpire' => 3600, 'user.passwordResetTokenExpire' => 3600,
'version' => 'v0.0.93', 'version' => 'v0.0.94',
'company' => 'movar',//gyor 'company' => 'movar',//gyor
'company_name' => "Freimann Kft.", 'company_name' => "Freimann Kft.",
'product_visiblity' => 'account',// on reception which products to display. account or global 'product_visiblity' => 'account',// on reception which products to display. account or global

View File

@ -5,6 +5,8 @@ namespace common\models;
use Yii; use Yii;
use common\components\Helper; use common\components\Helper;
/** @noinspection PhpUnnecessaryFullyQualifiedNameInspection */
/** /**
* This is the model class for table "card". * This is the model class for table "card".
* *
@ -17,6 +19,7 @@ use common\components\Helper;
* @property string $updated_at * @property string $updated_at
* @property int flag_out * @property int flag_out
* @property \common\models\Customer $customer relation * @property \common\models\Customer $customer relation
* @property mixed validity
*/ */
class Card extends \common\models\BaseFitnessActiveRecord class Card extends \common\models\BaseFitnessActiveRecord
{ {
@ -86,6 +89,7 @@ class Card extends \common\models\BaseFitnessActiveRecord
*/ */
public function attributeLabels() public function attributeLabels()
{ {
/** @noinspection PhpUndefinedClassInspection */
return [ return [
'id_card' => Yii::t('common/card', 'Id Card'), 'id_card' => Yii::t('common/card', 'Id Card'),
'number' => Yii::t('common/card', 'Number'), 'number' => Yii::t('common/card', 'Number'),
@ -98,15 +102,18 @@ class Card extends \common\models\BaseFitnessActiveRecord
} }
public function validateAscii($attribute,$params){ public function validateAscii($attribute, /** @noinspection PhpUnusedParameterInspection */
$params){
if ( !$this->hasErrors($this->$attribute)){ if ( !$this->hasErrors($this->$attribute)){
$this->$attribute = Helper::fixAsciiChars($this->$attribute); $this->$attribute = Helper::fixAsciiChars($this->$attribute);
Yii::info(" $attribute converted to: " . $this->$attribute); /** @noinspection PhpUndefinedClassInspection */
Yii::info(" $attribute converted to: " . $this->$attribute);
} }
} }
static function statuses() { static function statuses() {
return [ /** @noinspection PhpUndefinedClassInspection */
return [
self::STATUS_ACTIVE => Yii::t('common/card', 'Active'), self::STATUS_ACTIVE => Yii::t('common/card', 'Active'),
self::STATUS_DELETED => Yii::t('common/card', 'Inactive'), self::STATUS_DELETED => Yii::t('common/card', 'Inactive'),
]; ];
@ -114,7 +121,7 @@ class Card extends \common\models\BaseFitnessActiveRecord
public function getStatusHuman(){ public function getStatusHuman(){
$result = null; $result = null;
$s = self::statuses($this->status); $s = self::statuses();
if ( array_key_exists($this->status, $s)){ if ( array_key_exists($this->status, $s)){
$result = $s[$this->status]; $result = $s[$this->status];
} }
@ -128,7 +135,8 @@ class Card extends \common\models\BaseFitnessActiveRecord
} }
static function types() { static function types() {
return [ /** @noinspection PhpUndefinedClassInspection */
return [
self::TYPE_RFID => Yii::t('common/card', 'RFID'), self::TYPE_RFID => Yii::t('common/card', 'RFID'),
self::TYPE_QRCODE => Yii::t('common/card', 'QRCODE'), self::TYPE_QRCODE => Yii::t('common/card', 'QRCODE'),
self::TYPE_BARCODE => Yii::t('common/card', 'BARCODE'), self::TYPE_BARCODE => Yii::t('common/card', 'BARCODE'),
@ -139,7 +147,7 @@ class Card extends \common\models\BaseFitnessActiveRecord
public function getTypeHuman(){ public function getTypeHuman(){
$result = null; $result = null;
$s = self::types($this->type); $s = self::types();
if ( array_key_exists($this->type, $s)){ if ( array_key_exists($this->type, $s)){
$result = $s[$this->type]; $result = $s[$this->type];
} }
@ -182,18 +190,24 @@ class Card extends \common\models\BaseFitnessActiveRecord
public function getCustomerName(){ public function getCustomerName(){
$name = null; $name = null;
$customer = $this->customer;
if ( $this->customer != null){ if ( $this->customer != null){
$name = $this->customer->name; $name = $this->customer->name;
} }
return $name; return $name;
} }
public static function addCardNumberCondition($query,$number, $field_number = "card.number",$field_rfid_key = "card.rfid_key"){ /** @noinspection PhpUndefinedClassInspection */
/**
* @param \yii\db\Query $query
* @param number $number
* @param string $field_number
* @param string $field_rfid_key
*/
public static function addCardNumberCondition($query, $number, $field_number = "card.number", $field_rfid_key = "card.rfid_key"){
$query->andWhere(['or', $query->andWhere(['or',
['and',[ 'in',$field_number , [$number]],"trim(coalesce(card.number, '')) <>'' " ], ['and',[ 'in',$field_number , [$number]],"trim(coalesce(card.number, '')) <>'' " ],
['and', ['in',$field_rfid_key ,[ $number ] ],"trim(coalesce(card.rfid_key, '')) <>'' "], ['and', ['in',$field_rfid_key ,[ $number ] ],"trim(coalesce(card.rfid_key, '')) <>'' "],
]); ]);
} }
@ -201,7 +215,8 @@ class Card extends \common\models\BaseFitnessActiveRecord
if ( !isset($id)){ if ( !isset($id)){
return ; return ;
} }
$db = \Yii::$app->db; /** @noinspection PhpUndefinedClassInspection */
$db = \Yii::$app->db;
$command = $db->createCommand(Ticket::$SQL_UPDATE_CARD,[':id' => $id]); $command = $db->createCommand(Ticket::$SQL_UPDATE_CARD,[':id' => $id]);
$command->execute(); $command->execute();
@ -224,11 +239,10 @@ class Card extends \common\models\BaseFitnessActiveRecord
} }
public function setFlagsHasKey($hasKey){ public function setFlagsHasKey($hasKey){
$this->flag = $hasKey ? ( $this->flag & ~(1 << Card::$FLAG_KEY) ) : ( $this->flag | 1 << Card::$FLAG_KEY );
$pos = Card::$FLAG_KEY; $this->flag_out = $hasKey ? ( $this->flag_out | 1 << Card::$FLAG_KEY ) : ( $this->flag_out & ~(1 << Card::$FLAG_KEY) );
// $this->flag = $hasKey ? ( $this->flag & ~(1 << $pos) ) : ( $this->flag | 1 << $pos ); /** @noinspection PhpUndefinedClassInspection */
// $this->flag_out = $hasKey ? ( $this->flag_out | 1 << $pos ) : ( $this->flag_out & ~(1 << $pos) ); \Yii::info("flag has key: ".$this->flag .";".$this->flag_out);
// \Yii::info("flag has key: ".$this->flag .";".$this->flag_out);
} }

View File

@ -111,7 +111,7 @@ class Log extends BaseFitnessActiveRecord
'type' =>Log::$TYPE_LOGIN, 'type' =>Log::$TYPE_LOGIN,
'message' => $message 'message' => $message
]); ]);
* @param unknown $config * @param array $config
*/ */
public static function log( $config ){ public static function log( $config ){
$model = new Log($config); $model = new Log($config);

View File

@ -28,10 +28,10 @@ class TicketController extends Controller {
$command = $connection->createCommand ( Ticket::$SQL_UPDATE ); $command = $connection->createCommand ( Ticket::$SQL_UPDATE );
$result = $command->execute (); $result = $command->execute ();
\Yii::info ( "Tickets updated: " . $result ); \Yii::info ( "Tickets updated: " . $result );
//
//
// $command = $connection->createCommand ( Card::$SQL_FIX_KEY_STATUS ); $command = $connection->createCommand ( Card::$SQL_FIX_KEY_STATUS );
// $result = $command->execute (); $result = $command->execute ();
} }
/** /**

View File

@ -4,19 +4,22 @@ namespace frontend\models;
use common\models\DoorLog; use common\models\DoorLog;
use common\models\Log; use common\models\Log;
use Yii; use /** @noinspection PhpUndefinedClassInspection */
use yii\base\Model; yii\base\Model;
use common\models\CardKeyAssignment; use common\models\CardKeyAssignment;
use common\models\Key; use common\models\Key;
use yii\helpers\ArrayHelper;
use common\components\Helper; use common\components\Helper;
use common\models\Card; use common\models\Card;
/** @noinspection PhpUndefinedClassInspection */
/** /**
* ContactForm is the model behind the contact form. * ContactForm is the model behind the contact form.
* *
* @property \common\models\Card $card * @property \common\models\Card $card
* @property \common\models\Key $key * @property \common\models\Key $key
* @property \common\models\Key $keyModel
* @property \common\models\Card $keyCard
* *
*/ */
class KeyToggleForm extends Model class KeyToggleForm extends Model
@ -49,11 +52,13 @@ class KeyToggleForm extends Model
]; ];
} }
/**
*
*/
public function toggleKey(){ public function toggleKey(){
$query= Key::find(); $query= Key::find();
$this->key = Helper::fixAsciiChars($this->key); $this->key = Helper::fixAsciiChars($this->key);
// add condition rfid key or number
$query->andWhere(['or', $query->andWhere(['or',
['and',[ 'in','key.number' , [$this->key]],"trim(coalesce(key.number, '')) <>'' " ], ['and',[ 'in','key.number' , [$this->key]],"trim(coalesce(key.number, '')) <>'' " ],
['and', ['in','key.rfid_key' ,[ $this->key ] ],"trim(coalesce(key.rfid_key, '')) <>'' "], ['and', ['in','key.rfid_key' ,[ $this->key ] ],"trim(coalesce(key.rfid_key, '')) <>'' "],
@ -61,29 +66,42 @@ class KeyToggleForm extends Model
]); ]);
$this->keyModel = $query->one(); $this->keyModel = $query->one();
//ha van ilyen kulcs
if ( isset($this->keyModel) ){ if ( isset($this->keyModel) ){
//find card - key assignments
/** @var /common/models/Card keyCard */
$this->keyCard = Card::find()->innerJoin('card_key_assignment','card.id_card = card_key_assignment.id_card')->andWhere('card_key_assignment.id_key = ' .$this->keyModel->id_key)->one(); $this->keyCard = Card::find()->innerJoin('card_key_assignment','card.id_card = card_key_assignment.id_card')->andWhere('card_key_assignment.id_key = ' .$this->keyModel->id_key)->one();
$assignments = CardKeyAssignment::find()->andWhere(['id_key' => $this->keyModel->id_key])->all(); $assignments = CardKeyAssignment::find()->andWhere(['id_key' => $this->keyModel->id_key])->all();
//if assignment found - we will unassign it
if ( count($assignments) > 0){ if ( count($assignments) > 0){
if ( isset( $this->keyCard ) ){
$this->unassign(); CardKeyAssignment::deleteAll(['id_key' => $this->keyModel->id_key]);
$this->action = 'unassign'; $this->keyCard->setFlagsHasKey(false);
$this->keyCard->save(false);
Log::log([ /** @noinspection PhpUndefinedClassInspection */
'type' =>Log::$TYPE_KEY_ASSIGN, \Yii::$app->session->setFlash ( 'success', 'Kulcs visszaadva!' );
'message' => 'Kulcs visszaadás - Kártya/Kulcs/Vendég:' .$this->keyCard->number ."/" .$this->keyModel->number . "/".$this->keyCard->customer->name, $this->action = 'unassign';
'id_key' => $this->card->id_card, Log::log([
'id_customer' => $this->keyCard->customer->id_customer 'type' =>Log::$TYPE_KEY_ASSIGN,
]); 'message' => 'Kulcs visszaadás - Kártya/Kulcs/Vendég:' .$this->keyCard->number ."/" .$this->keyModel->number . "/".$this->keyCard->customer->name,
'id_key' => $this->card->id_card,
DoorLog::mkDoorLog(-1,$this->keyCard,$this->keyCard->customer,$this->keyModel ); 'id_customer' => $this->keyCard->customer->id_customer
]);
DoorLog::mkDoorLog(-1,$this->keyCard,$this->keyCard->customer,$this->keyModel );
}else{
/** @noinspection PhpUndefinedClassInspection */
\Yii::error("Key for assignment not found");
/** @noinspection PhpUndefinedClassInspection */
\Yii::$app->session->setFlash ( 'danger', 'Kulcs visszaadás hiba: kulcs nem található!' );
}
}else{ }else{
// if there is no assignment - assign it to the customer
$this->assign(); $this->assign();
} }
}else{ }else{
\Yii::$app->session->setFlash ( 'danger', 'Kulcs nem található!' ); /** @noinspection PhpUndefinedClassInspection */
\Yii::$app->session->setFlash ( 'danger', 'Kulcs nem található!' );
} }
} }
@ -91,14 +109,17 @@ class KeyToggleForm extends Model
if ( isset($this->card) && isset($this->customer) ){ if ( isset($this->card) && isset($this->customer) ){
$assignments = CardKeyAssignment::find()->andWhere(['id_card' => $this->card->id_card])->all(); $assignments = CardKeyAssignment::find()->andWhere(['id_card' => $this->card->id_card])->all();
if ( count($assignments) > 0 ){ if ( count($assignments) > 0 ){
\Yii::$app->session->setFlash ( 'danger', 'A vendégnél egyszerre csak egy kulcs lehet' ); /** @noinspection PhpUndefinedClassInspection */
\Yii::$app->session->setFlash ( 'danger', 'A vendégnél egyszerre csak egy kulcs lehet' );
}else{ }else{
$assignment = new CardKeyAssignment(); $assignment = new CardKeyAssignment();
$assignment->id_card = $this->card->id_card; $assignment->id_card = $this->card->id_card;
$assignment->id_key = $this->keyModel->id_key; $assignment->id_key = $this->keyModel->id_key;
$assignment->id_user = \Yii::$app->user->id; /** @noinspection PhpUndefinedClassInspection */
$assignment->id_user = \Yii::$app->user->id;
$assignment->save(false); $assignment->save(false);
\Yii::$app->session->setFlash ( 'success', 'Kulcs kiadva!' ); /** @noinspection PhpUndefinedClassInspection */
\Yii::$app->session->setFlash ( 'success', 'Kulcs kiadva!' );
$this->card->setFlagsHasKey(true); $this->card->setFlagsHasKey(true);
$this->card->save(false); $this->card->save(false);
@ -113,15 +134,10 @@ class KeyToggleForm extends Model
DoorLog::mkDoorLog(-2,$this->card,$this->customer,$this->keyModel ); DoorLog::mkDoorLog(-2,$this->card,$this->customer,$this->keyModel );
} }
}else{ }else{
\Yii::$app->session->setFlash ( 'danger', 'Nincs vendég kiválasztva vagy érvénytelen kártya!' ); /** @noinspection PhpUndefinedClassInspection */
\Yii::$app->session->setFlash ( 'danger', 'Nincs vendég kiválasztva vagy érvénytelen kártya!' );
} }
} }
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!' );
}
} }

View File

@ -150,8 +150,8 @@ begin
END IF; END IF;
*/ */
INSERT INTO devlog ( msg) values( concat( 'Kilépés: Aktuális bérlet/belépések száma/többszire belépés on/belépés on: ' -- INSERT INTO devlog ( msg) values( concat( 'Kilépés: Aktuális bérlet/belépések száma/többszire belépés on/belépés on: '
, coalesce(@p_mo_ticket_id,''),'/', coalesce(@p_count_all,'') , '/', coalesce(@p_allow_multiple_enter,''),'/', coalesce(@p_allow_enter,'' ) ) ); -- , coalesce(@p_mo_ticket_id,''),'/', coalesce(@p_count_all,'') , '/', coalesce(@p_allow_multiple_enter,''),'/', coalesce(@p_allow_enter,'' ) ) );
update card set update card set
flag_out = ( flag_out | 1 << 1 ) , -- nem léphet ki ( 1. bit beállíátsa 1-re ) flag_out = ( flag_out | 1 << 1 ) , -- nem léphet ki ( 1. bit beállíátsa 1-re )
@ -163,7 +163,7 @@ begin
-- BELÉPÉS van folyamatban - kilépés flag_out bekapcsolása, belépés flag kikapcsolása -- BELÉPÉS van folyamatban - kilépés flag_out bekapcsolása, belépés flag kikapcsolása
IF (NEW.direction = 7 or New.direction = 3 ) and NEW.id_ticket_current is not null IF (NEW.direction = 7 or New.direction = 3 ) and NEW.id_ticket_current is not null
THEN THEN
INSERT INTO devlog ( msg) values( 'kilépés flag_out bekapcsolása, belépés flag kikapcsolása' ); -- INSERT INTO devlog ( msg) values( 'kilépés flag_out bekapcsolása, belépés flag kikapcsolása' );
update card set update card set
flag_out = ( flag_out & ~(1 << 1 ) ) , -- kilpés engedélyezése ( 1. bit beállítása 0-ra ) flag_out = ( flag_out & ~(1 << 1 ) ) , -- kilpés engedélyezése ( 1. bit beállítása 0-ra )
flag = ( flag | 1 << 1 ) -- belépés nem lehetséges ( 1.bit beállítsa 1-re ) flag = ( flag | 1 << 1 ) -- belépés nem lehetséges ( 1.bit beállítsa 1-re )