add log key assign

This commit is contained in:
Roland Schneider 2016-08-25 19:18:13 +02:00
parent 2a59952b2d
commit 9d0d0199c7
3 changed files with 59 additions and 3 deletions

View File

@ -134,6 +134,8 @@ class DoorLog extends \yii\db\ActiveRecord
public static function getDirectionTypes( ){ public static function getDirectionTypes( ){
return [ return [
-2 => "Kézi olvasás/Kulcs ki",
-1 => "Kézi olvasás/Kulcs vissza",
0 => "Kézi olvasás", 0 => "Kézi olvasás",
1 => "KI olvastatás mozgás nélkül", 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", 0 => "Kártya érvényes bérlettel",
1 => "Nincs érvényes bérlet", 1 => "Nincs érvényes bérlet",
2 => "Kártya inaktív/É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);
}
} }

View File

@ -49,6 +49,8 @@ class Log extends BaseFitnessActiveRecord
public static $TYPE_TICKET_EXPIRE_SENT = 140; public static $TYPE_TICKET_EXPIRE_SENT = 140;
public static $TYPE_NEWSLETTER_SEND_START = 150; public static $TYPE_NEWSLETTER_SEND_START = 150;
public static $TYPE_NEWSLETTER_SEND_END = 160; public static $TYPE_NEWSLETTER_SEND_END = 160;
public static $TYPE_KEY_ASSIGN = 170;
public static $TYPE_KEY_UNASSIGN = 180;
/** /**
* @inheritdoc * @inheritdoc

View File

@ -2,6 +2,8 @@
namespace frontend\models; namespace frontend\models;
use common\models\DoorLog;
use common\models\Log;
use Yii; use Yii;
use yii\base\Model; use yii\base\Model;
use common\models\CardKeyAssignment; use common\models\CardKeyAssignment;
@ -12,6 +14,7 @@ use common\models\Card;
/** /**
* ContactForm is the model behind the contact form. * ContactForm is the model behind the contact form.
*
*/ */
class KeyToggleForm extends Model class KeyToggleForm extends Model
{ {
@ -20,6 +23,7 @@ class KeyToggleForm extends Model
public $customer; public $customer;
public $keyModel; public $keyModel;
public $action; public $action;
public $keyCard; 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(); $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 ( count($assignments) > 0){ if ( count($assignments) > 0){
$this->unassign(); $this->unassign();
$this->action = '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{ }else{
$this->assign(); $this->assign();
} }
@ -81,6 +96,15 @@ class KeyToggleForm extends Model
$assignment->id_user = \Yii::$app->user->id; $assignment->id_user = \Yii::$app->user->id;
$assignment->save(false); $assignment->save(false);
\Yii::$app->session->setFlash ( 'success', 'Kulcs kiadva!' ); \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{ }else{
\Yii::$app->session->setFlash ( 'danger', 'Nincs vendég kiválasztva vagy érvénytelen kártya!' ); \Yii::$app->session->setFlash ( 'danger', 'Nincs vendég kiválasztva vagy érvénytelen kártya!' );