From 9d0d0199c73efab08bdfc1d8a6e2319ab303748a Mon Sep 17 00:00:00 2001 From: Roland Schneider Date: Thu, 25 Aug 2016 19:18:13 +0200 Subject: [PATCH] add log key assign --- common/models/DoorLog.php | 34 +++++++++++++++++++++++++++++-- common/models/Log.php | 4 +++- frontend/models/KeyToggleForm.php | 24 ++++++++++++++++++++++ 3 files changed, 59 insertions(+), 3 deletions(-) diff --git a/common/models/DoorLog.php b/common/models/DoorLog.php index 069d23a..9c473db 100644 --- a/common/models/DoorLog.php +++ b/common/models/DoorLog.php @@ -134,6 +134,8 @@ class DoorLog extends \yii\db\ActiveRecord public static function getDirectionTypes( ){ return [ + -2 => "Kézi olvasás/Kulcs ki", + -1 => "Kézi olvasás/Kulcs vissza", 0 => "Kézi olvasás", 1 => "KI olvastatás mozgás nélkül", @@ -162,9 +164,37 @@ class DoorLog extends \yii\db\ActiveRecord 0 => "Kártya érvényes bérlettel", 1 => "Nincs érvényes bérlet", 2 => "Kártya inaktív/Érvényes bérlet", - 3 => "Kártya inaktív/Nincs érvényes bérlet", - + 3 => "Kártya inaktív/Nincs érvényes bérlet" + ]; } + + public static function mkDoorLog($direction,$card,$customer = null,$key = null){ + + $dlog = new DoorLog(); + $dlog->id_card = $card->id_card; + + if ( isset($customer)){ + $dlog->id_customer = $customer->id_customer; + } + + if ( isset($key)){ + $dlog->id_key = $key->id_key; + } + $dlog->direction = $direction; + $dlog->type = $card->type; + $dlog->source_app = DoorLog::$SOURCE_APP_FITNESS_ADMIN; + + $dlog->id_account = Account::readDefault(); + + if ( $dlog->direction == 0){ + $dlog->card_flag = $card->flag; + }else{ + $dlog->card_flag = -1; + } + + $dlog->created_at = date('Y-m-d H:i:s'); + $dlog->save(false); + } } diff --git a/common/models/Log.php b/common/models/Log.php index 6f1cfca..ba10419 100644 --- a/common/models/Log.php +++ b/common/models/Log.php @@ -49,7 +49,9 @@ class Log extends BaseFitnessActiveRecord public static $TYPE_TICKET_EXPIRE_SENT = 140; public static $TYPE_NEWSLETTER_SEND_START = 150; public static $TYPE_NEWSLETTER_SEND_END = 160; - + public static $TYPE_KEY_ASSIGN = 170; + public static $TYPE_KEY_UNASSIGN = 180; + /** * @inheritdoc */ diff --git a/frontend/models/KeyToggleForm.php b/frontend/models/KeyToggleForm.php index 6e7d59b..5b87abe 100644 --- a/frontend/models/KeyToggleForm.php +++ b/frontend/models/KeyToggleForm.php @@ -2,6 +2,8 @@ namespace frontend\models; +use common\models\DoorLog; +use common\models\Log; use Yii; use yii\base\Model; use common\models\CardKeyAssignment; @@ -12,6 +14,7 @@ use common\models\Card; /** * ContactForm is the model behind the contact form. + * */ class KeyToggleForm extends Model { @@ -20,6 +23,7 @@ class KeyToggleForm extends Model public $customer; public $keyModel; public $action; + public $keyCard; @@ -59,8 +63,19 @@ class KeyToggleForm extends Model $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 ( count($assignments) > 0){ + $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 ); + }else{ $this->assign(); } @@ -81,6 +96,15 @@ class KeyToggleForm extends Model $assignment->id_user = \Yii::$app->user->id; $assignment->save(false); \Yii::$app->session->setFlash ( 'success', 'Kulcs kiadva!' ); + + 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, + 'id_key' => $this->card->id_card, + 'id_customer' => $this->customer->id_customer + ]); + + 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!' );