Add door log changes, direction types, and manual reading event

This commit is contained in:
2016-02-16 18:37:16 +01:00
parent f81af9e5bb
commit 769b5d16de
8 changed files with 230 additions and 43 deletions

View File

@@ -14,6 +14,8 @@ use common\models\Key;
use common\models\CardKeyAssignment;
use common\models\Contract;
use yii\db\Expression;
use common\components\Helper;
use common\models\DoorLog;
/**
* ContactForm is the model behind the contact form.
@@ -52,7 +54,7 @@ class ReceptionForm extends Model
public function readCard(){
$this->number = str_replace("ö", "0", $this->number);
$this->number = Helper::fixAsciiChars( $this->number );
$query = Card::find();
$query->leftJoin("card_key_assignment", 'card.id_card = card_key_assignment.id_card');
@@ -89,6 +91,32 @@ class ReceptionForm extends Model
}
public function mkDoorLog(){
if ( !isset($this->card)){
return;
}
$dlog = new DoorLog();
$dlog->id_card = $this->card->id_card;
if ( isset($this->customer)){
$dlog->id_customer = $this->customer->id_customer;
}
$key = $this->getFirstKey();
if ( isset($key)){
$dlog->id_key = $key->id_key;
}
$dlog->direction = 0;
$dlog->type = $this->card->type;
$dlog->source_app = DoorLog::$SOURCE_APP_FITNESS_ADMIN;
$dlog->created_at = date('Y-m-d H:i:s');
$dlog->save(false);
}
public function readAssignedKeys(){
$query = Key::find();
$query->join( 'INNER JOIN', CardKeyAssignment::tableName() , Key::tableName().".id_key = " . CardKeyAssignment::tableName() . ".id_key");
@@ -97,6 +125,14 @@ class ReceptionForm extends Model
}
public function getFirstKey(){
$result = null;
if ( isset($this->keys) && is_array($this->keys) && count($this->keys) > 0 ){
$esut = $this->keys[0];
}
return $result;
}
public function readLastCassaState(){
$a = Account::readDefault();
if ( isset($a)){