diff --git a/changelog.txt b/changelog.txt index ffd66e7..4137da8 100644 --- a/changelog.txt +++ b/changelog.txt @@ -1,3 +1,5 @@ +-0.0.85 + - add key assign/unassign log -0.0.84 - add faster inventory item edit -0.0.83 diff --git a/common/config/params.php b/common/config/params.php index 9e5736b..1fdaa81 100644 --- a/common/config/params.php +++ b/common/config/params.php @@ -5,7 +5,7 @@ return [ 'supportEmail' => 'rocho02@gmail.com', 'infoEmail' => 'info@rocho-net.hu', 'user.passwordResetTokenExpire' => 3600, - 'version' => 'v0.0.84', + 'version' => 'v0.0.85', 'company' => 'movar',//gyor 'company_name' => "Freimann Kft.", 'product_visiblity' => 'account',// on reception which products to display. account or global 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!' );