restore flag_out logic, toggleKey logic
This commit is contained in:
parent
c673c5f73d
commit
6de07dac93
@ -391,13 +391,13 @@ class CardController extends \backend\controllers\BackendController {
|
||||
\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 );
|
||||
$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 );
|
||||
|
||||
|
||||
|
||||
|
||||
@ -1,3 +1,6 @@
|
||||
-0.0.94
|
||||
- restore flag_out logic
|
||||
- add toggleKey changes
|
||||
-0.0.93
|
||||
- add shebang line to botond_daily script
|
||||
-0.0.92
|
||||
|
||||
@ -5,7 +5,7 @@ return [
|
||||
'supportEmail' => 'rocho02@gmail.com',
|
||||
'infoEmail' => 'info@rocho-net.hu',
|
||||
'user.passwordResetTokenExpire' => 3600,
|
||||
'version' => 'v0.0.93',
|
||||
'version' => 'v0.0.94',
|
||||
'company' => 'movar',//gyor
|
||||
'company_name' => "Freimann Kft.",
|
||||
'product_visiblity' => 'account',// on reception which products to display. account or global
|
||||
|
||||
@ -5,6 +5,8 @@ namespace common\models;
|
||||
use Yii;
|
||||
use common\components\Helper;
|
||||
|
||||
/** @noinspection PhpUnnecessaryFullyQualifiedNameInspection */
|
||||
|
||||
/**
|
||||
* This is the model class for table "card".
|
||||
*
|
||||
@ -17,6 +19,7 @@ use common\components\Helper;
|
||||
* @property string $updated_at
|
||||
* @property int flag_out
|
||||
* @property \common\models\Customer $customer relation
|
||||
* @property mixed validity
|
||||
*/
|
||||
class Card extends \common\models\BaseFitnessActiveRecord
|
||||
{
|
||||
@ -86,6 +89,7 @@ class Card extends \common\models\BaseFitnessActiveRecord
|
||||
*/
|
||||
public function attributeLabels()
|
||||
{
|
||||
/** @noinspection PhpUndefinedClassInspection */
|
||||
return [
|
||||
'id_card' => Yii::t('common/card', 'Id Card'),
|
||||
'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)){
|
||||
$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() {
|
||||
return [
|
||||
/** @noinspection PhpUndefinedClassInspection */
|
||||
return [
|
||||
self::STATUS_ACTIVE => Yii::t('common/card', 'Active'),
|
||||
self::STATUS_DELETED => Yii::t('common/card', 'Inactive'),
|
||||
];
|
||||
@ -114,7 +121,7 @@ class Card extends \common\models\BaseFitnessActiveRecord
|
||||
|
||||
public function getStatusHuman(){
|
||||
$result = null;
|
||||
$s = self::statuses($this->status);
|
||||
$s = self::statuses();
|
||||
if ( array_key_exists($this->status, $s)){
|
||||
$result = $s[$this->status];
|
||||
}
|
||||
@ -128,7 +135,8 @@ class Card extends \common\models\BaseFitnessActiveRecord
|
||||
}
|
||||
|
||||
static function types() {
|
||||
return [
|
||||
/** @noinspection PhpUndefinedClassInspection */
|
||||
return [
|
||||
self::TYPE_RFID => Yii::t('common/card', 'RFID'),
|
||||
self::TYPE_QRCODE => Yii::t('common/card', 'QRCODE'),
|
||||
self::TYPE_BARCODE => Yii::t('common/card', 'BARCODE'),
|
||||
@ -139,7 +147,7 @@ class Card extends \common\models\BaseFitnessActiveRecord
|
||||
|
||||
public function getTypeHuman(){
|
||||
$result = null;
|
||||
$s = self::types($this->type);
|
||||
$s = self::types();
|
||||
if ( array_key_exists($this->type, $s)){
|
||||
$result = $s[$this->type];
|
||||
}
|
||||
@ -182,18 +190,24 @@ class Card extends \common\models\BaseFitnessActiveRecord
|
||||
|
||||
public function getCustomerName(){
|
||||
$name = null;
|
||||
$customer = $this->customer;
|
||||
if ( $this->customer != null){
|
||||
$name = $this->customer->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',
|
||||
['and',[ 'in',$field_number , [$number]],"trim(coalesce(card.number, '')) <>'' " ],
|
||||
['and', ['in',$field_rfid_key ,[ $number ] ],"trim(coalesce(card.rfid_key, '')) <>'' "],
|
||||
|
||||
]);
|
||||
}
|
||||
|
||||
@ -201,7 +215,8 @@ class Card extends \common\models\BaseFitnessActiveRecord
|
||||
if ( !isset($id)){
|
||||
return ;
|
||||
}
|
||||
$db = \Yii::$app->db;
|
||||
/** @noinspection PhpUndefinedClassInspection */
|
||||
$db = \Yii::$app->db;
|
||||
|
||||
$command = $db->createCommand(Ticket::$SQL_UPDATE_CARD,[':id' => $id]);
|
||||
$command->execute();
|
||||
@ -224,11 +239,10 @@ class Card extends \common\models\BaseFitnessActiveRecord
|
||||
}
|
||||
|
||||
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);
|
||||
$this->flag = $hasKey ? ( $this->flag & ~(1 << Card::$FLAG_KEY) ) : ( $this->flag | 1 << Card::$FLAG_KEY );
|
||||
$this->flag_out = $hasKey ? ( $this->flag_out | 1 << Card::$FLAG_KEY ) : ( $this->flag_out & ~(1 << Card::$FLAG_KEY) );
|
||||
/** @noinspection PhpUndefinedClassInspection */
|
||||
\Yii::info("flag has key: ".$this->flag .";".$this->flag_out);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@ -111,7 +111,7 @@ class Log extends BaseFitnessActiveRecord
|
||||
'type' =>Log::$TYPE_LOGIN,
|
||||
'message' => $message
|
||||
]);
|
||||
* @param unknown $config
|
||||
* @param array $config
|
||||
*/
|
||||
public static function log( $config ){
|
||||
$model = new Log($config);
|
||||
|
||||
@ -28,10 +28,10 @@ class TicketController extends Controller {
|
||||
$command = $connection->createCommand ( Ticket::$SQL_UPDATE );
|
||||
$result = $command->execute ();
|
||||
\Yii::info ( "Tickets updated: " . $result );
|
||||
//
|
||||
//
|
||||
// $command = $connection->createCommand ( Card::$SQL_FIX_KEY_STATUS );
|
||||
// $result = $command->execute ();
|
||||
|
||||
|
||||
$command = $connection->createCommand ( Card::$SQL_FIX_KEY_STATUS );
|
||||
$result = $command->execute ();
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@ -4,19 +4,22 @@ namespace frontend\models;
|
||||
|
||||
use common\models\DoorLog;
|
||||
use common\models\Log;
|
||||
use Yii;
|
||||
use yii\base\Model;
|
||||
use /** @noinspection PhpUndefinedClassInspection */
|
||||
yii\base\Model;
|
||||
use common\models\CardKeyAssignment;
|
||||
use common\models\Key;
|
||||
use yii\helpers\ArrayHelper;
|
||||
use common\components\Helper;
|
||||
use common\models\Card;
|
||||
|
||||
/** @noinspection PhpUndefinedClassInspection */
|
||||
|
||||
/**
|
||||
* ContactForm is the model behind the contact form.
|
||||
*
|
||||
* @property \common\models\Card $card
|
||||
* @property \common\models\Key $key
|
||||
* @property \common\models\Key $keyModel
|
||||
* @property \common\models\Card $keyCard
|
||||
*
|
||||
*/
|
||||
class KeyToggleForm extends Model
|
||||
@ -48,42 +51,57 @@ class KeyToggleForm extends Model
|
||||
return [
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public function toggleKey(){
|
||||
$query= Key::find();
|
||||
|
||||
$this->key = Helper::fixAsciiChars($this->key);
|
||||
|
||||
// add condition rfid key or number
|
||||
$query->andWhere(['or',
|
||||
['and',[ 'in','key.number' , [$this->key]],"trim(coalesce(key.number, '')) <>'' " ],
|
||||
['and', ['in','key.rfid_key' ,[ $this->key ] ],"trim(coalesce(key.rfid_key, '')) <>'' "],
|
||||
|
||||
|
||||
]);
|
||||
|
||||
|
||||
$this->keyModel = $query->one();
|
||||
|
||||
if ( isset($this->keyModel) ){
|
||||
//ha van ilyen kulcs
|
||||
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();
|
||||
$assignments = CardKeyAssignment::find()->andWhere(['id_key' => $this->keyModel->id_key])->all();
|
||||
//if assignment found - we will unassign it
|
||||
if ( count($assignments) > 0){
|
||||
if ( isset( $this->keyCard ) ){
|
||||
|
||||
$this->unassign();
|
||||
$this->action = 'unassign';
|
||||
|
||||
Log::log([
|
||||
'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,
|
||||
'id_customer' => $this->keyCard->customer->id_customer
|
||||
]);
|
||||
|
||||
DoorLog::mkDoorLog(-1,$this->keyCard,$this->keyCard->customer,$this->keyModel );
|
||||
|
||||
CardKeyAssignment::deleteAll(['id_key' => $this->keyModel->id_key]);
|
||||
$this->keyCard->setFlagsHasKey(false);
|
||||
$this->keyCard->save(false);
|
||||
/** @noinspection PhpUndefinedClassInspection */
|
||||
\Yii::$app->session->setFlash ( 'success', 'Kulcs visszaadva!' );
|
||||
$this->action = 'unassign';
|
||||
Log::log([
|
||||
'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,
|
||||
'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{
|
||||
// if there is no assignment - assign it to the customer
|
||||
$this->assign();
|
||||
}
|
||||
}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) ){
|
||||
$assignments = CardKeyAssignment::find()->andWhere(['id_card' => $this->card->id_card])->all();
|
||||
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{
|
||||
$assignment = new CardKeyAssignment();
|
||||
$assignment->id_card = $this->card->id_card;
|
||||
$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);
|
||||
\Yii::$app->session->setFlash ( 'success', 'Kulcs kiadva!' );
|
||||
/** @noinspection PhpUndefinedClassInspection */
|
||||
\Yii::$app->session->setFlash ( 'success', 'Kulcs kiadva!' );
|
||||
|
||||
$this->card->setFlagsHasKey(true);
|
||||
$this->card->save(false);
|
||||
@ -113,15 +134,10 @@ class KeyToggleForm extends Model
|
||||
DoorLog::mkDoorLog(-2,$this->card,$this->customer,$this->keyModel );
|
||||
}
|
||||
}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!' );
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@ -74,7 +74,7 @@ begin
|
||||
END IF; -- end @p_count_all_2 = 1
|
||||
END IF; -- @p_count_all > 1
|
||||
End IF; -- vége bemozgás érvényes bérlettel end type == 7 or 3 ( move in )
|
||||
|
||||
|
||||
-- KILÉPÉS -- count_move_out beállítása usage_count-ra
|
||||
IF NEW.direction = 5 or New.direction = 1 -- type move out
|
||||
then
|
||||
@ -150,8 +150,8 @@ begin
|
||||
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: '
|
||||
, coalesce(@p_mo_ticket_id,''),'/', coalesce(@p_count_all,'') , '/', coalesce(@p_allow_multiple_enter,''),'/', coalesce(@p_allow_enter,'' ) ) );
|
||||
-- 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,'' ) ) );
|
||||
|
||||
update card set
|
||||
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
|
||||
IF (NEW.direction = 7 or New.direction = 3 ) and NEW.id_ticket_current is not null
|
||||
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
|
||||
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 )
|
||||
|
||||
Loading…
Reference in New Issue
Block a user