door manager extra logging + docu improvment
This commit is contained in:
@@ -22,7 +22,7 @@ class Helper {
|
||||
*/
|
||||
public static function calcStartDatimeDaysSinceToday($start, $format = "datetime" ){
|
||||
$now = time();
|
||||
|
||||
|
||||
if ( $format == "datetime"){
|
||||
$format = "Y-m-d H:i";
|
||||
}else if ( $format == "date") {
|
||||
@@ -30,10 +30,10 @@ class Helper {
|
||||
}else{
|
||||
//use format
|
||||
}
|
||||
|
||||
|
||||
$d = \DateTime::createFromFormat( $format , $start)->getTimeStamp();
|
||||
$days_between = ceil(abs( $now - $d) / 86400 );
|
||||
|
||||
|
||||
return $days_between;
|
||||
}
|
||||
|
||||
@@ -52,8 +52,8 @@ class Helper {
|
||||
*/
|
||||
public static function restrictIfNotAdminTheStartDate($query,$date, $fields = ['transfer.paid_at','transfer.created_at'], $format = 'datetime'){
|
||||
$result = null;
|
||||
|
||||
|
||||
|
||||
|
||||
$needFix = false;
|
||||
if ( !isset($date) || empty($date)){
|
||||
$needFix = true;
|
||||
@@ -63,19 +63,19 @@ class Helper {
|
||||
$needFix = true;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if ( $needFix == true ){
|
||||
$d = Helper::getReceptionVisibilityDays();
|
||||
|
||||
|
||||
$time = date( "Y-m-d H:i:s", strtotime("today -$d day") );
|
||||
|
||||
|
||||
$conditions = [];
|
||||
|
||||
|
||||
foreach ($fields as $f ){
|
||||
$conditions[] = ['>=', $f, $time];
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
if ( count($conditions) > 1 ){
|
||||
$andWhereCond = [];
|
||||
$andWhereCond[0] = "or";
|
||||
@@ -87,26 +87,26 @@ class Helper {
|
||||
}else if ( count($conditions) == 1 ){
|
||||
$andWhereCond = $conditions[0];
|
||||
}
|
||||
|
||||
|
||||
// $start_date_condition = ['or',[ '>=', 'transfer.created_at', $time ] ,[ '>=', 'transfer.paid_at', $time] ];
|
||||
if ( isset($andWhereCond)){
|
||||
if ( isset($andWhereCond)){
|
||||
$query->andWhere( $andWhereCond );
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
|
||||
public static function getDateTimeString( ){
|
||||
|
||||
|
||||
return date("Y-m-d H:i:s");
|
||||
}
|
||||
public static function getDateString( ){
|
||||
|
||||
|
||||
return date("Y-m-d");
|
||||
}
|
||||
|
||||
|
||||
public static function getArrayValue($arr,$key,$def){
|
||||
$result = $def;
|
||||
if ( array_key_exists($key, $arr)){
|
||||
@@ -114,8 +114,8 @@ class Helper {
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
public static function hufRound($m) {
|
||||
$result = round ( $m / 5, 0 ) * 5;
|
||||
return $result;
|
||||
@@ -128,18 +128,18 @@ class Helper {
|
||||
* @param $end
|
||||
*/
|
||||
public static function notInInterval($query, $field, $start, $end) {
|
||||
$query->andFilterWhere ( [
|
||||
$query->andFilterWhere ( [
|
||||
'or',
|
||||
[
|
||||
[
|
||||
'<',
|
||||
$field,
|
||||
isset ( $start ) ? $start : '1900-01-01'
|
||||
isset ( $start ) ? $start : '1900-01-01'
|
||||
],
|
||||
[
|
||||
[
|
||||
'>=',
|
||||
$field,
|
||||
isset ( $end ) ? $end : '3000-01-01'
|
||||
]
|
||||
isset ( $end ) ? $end : '3000-01-01'
|
||||
]
|
||||
] );
|
||||
}
|
||||
|
||||
@@ -150,21 +150,21 @@ class Helper {
|
||||
* @param string $end the end date
|
||||
*/
|
||||
public static function notPaid($query, $field, $start, $end) {
|
||||
$query->andFilterWhere ( [
|
||||
$query->andFilterWhere ( [
|
||||
'or',
|
||||
[
|
||||
[
|
||||
'<',
|
||||
$field,
|
||||
isset ( $start ) ? $start : '1900-01-01'
|
||||
isset ( $start ) ? $start : '1900-01-01'
|
||||
],
|
||||
[
|
||||
[
|
||||
'>=',
|
||||
$field,
|
||||
isset ( $end ) ? $end : '3000-01-01'
|
||||
isset ( $end ) ? $end : '3000-01-01'
|
||||
],
|
||||
[
|
||||
"transfer.status" => Transfer::STATUS_NOT_PAID
|
||||
]
|
||||
[
|
||||
"transfer.status" => Transfer::STATUS_NOT_PAID
|
||||
]
|
||||
] );
|
||||
}
|
||||
|
||||
@@ -175,15 +175,15 @@ class Helper {
|
||||
* @param string $end the end date
|
||||
*/
|
||||
public static function inInterval($query, $field, $start, $end) {
|
||||
$query->andFilterWhere ( [
|
||||
$query->andFilterWhere ( [
|
||||
'>=',
|
||||
$field,
|
||||
$start
|
||||
$start
|
||||
] );
|
||||
$query->andFilterWhere ( [
|
||||
$query->andFilterWhere ( [
|
||||
'<',
|
||||
$field,
|
||||
$end
|
||||
$end
|
||||
] );
|
||||
}
|
||||
|
||||
@@ -194,53 +194,53 @@ class Helper {
|
||||
* @return array the query 'in interval' rule
|
||||
*/
|
||||
public static function queryInIntervalRule($field, $start, $end) {
|
||||
return [
|
||||
return [
|
||||
'and',
|
||||
[
|
||||
[
|
||||
'>=',
|
||||
$field,
|
||||
$start
|
||||
$start
|
||||
],
|
||||
[
|
||||
[
|
||||
'<',
|
||||
$field,
|
||||
$end
|
||||
]
|
||||
$end
|
||||
]
|
||||
];
|
||||
}
|
||||
public static function queryExpireRule($field_start, $field_end, $start, $end) {
|
||||
return [
|
||||
return [
|
||||
'and',
|
||||
[
|
||||
[
|
||||
'<',
|
||||
$field_start,
|
||||
$end
|
||||
$end
|
||||
],
|
||||
[
|
||||
[
|
||||
'>=',
|
||||
$field_end,
|
||||
$start
|
||||
$start
|
||||
],
|
||||
[
|
||||
[
|
||||
'<=',
|
||||
$field_end,
|
||||
$end
|
||||
]
|
||||
$end
|
||||
]
|
||||
];
|
||||
}
|
||||
public static function queryValidRule($field_start, $field_end, $start, $end) {
|
||||
return [
|
||||
return [
|
||||
'and',
|
||||
[
|
||||
[
|
||||
'<',
|
||||
$field_start,
|
||||
$end
|
||||
$end
|
||||
],
|
||||
[
|
||||
[
|
||||
'>=',
|
||||
$field_end,
|
||||
$start
|
||||
]
|
||||
$start
|
||||
]
|
||||
];
|
||||
}
|
||||
public static function sqlInIntervalRule($field, $paramStart, $paramEnd) {
|
||||
@@ -270,35 +270,35 @@ class Helper {
|
||||
public static function queryAccountConstraint($query, $field) {
|
||||
if (! RoleDefinition::isAdmin ()) {
|
||||
$query->innerJoin ( "user_account_assignment", $field . ' = user_account_assignment.id_account' );
|
||||
$query->andWhere ( [
|
||||
'user_account_assignment.id_user' => Yii::$app->user->id
|
||||
$query->andWhere ( [
|
||||
'user_account_assignment.id_user' => Yii::$app->user->id
|
||||
] );
|
||||
}
|
||||
}
|
||||
public static function roleLabels() {
|
||||
return [
|
||||
return [
|
||||
'reception' => Yii::t ( 'common/role', 'Reception' ),
|
||||
'admin' => Yii::t ( 'common/role', 'Administrator' ),
|
||||
'employee' => Yii::t ( 'common/role', 'Alkalmazott' )
|
||||
'employee' => Yii::t ( 'common/role', 'Alkalmazott' )
|
||||
];
|
||||
}
|
||||
public static function roleDefinitions() {
|
||||
return [
|
||||
'employee' => [
|
||||
'canAllow' => [
|
||||
'employee'
|
||||
]
|
||||
return [
|
||||
'employee' => [
|
||||
'canAllow' => [
|
||||
'employee'
|
||||
]
|
||||
],
|
||||
'admin' => [
|
||||
'canAllow' => [
|
||||
'admin' => [
|
||||
'canAllow' => [
|
||||
'admin',
|
||||
'reception',
|
||||
'employee'
|
||||
]
|
||||
'employee'
|
||||
]
|
||||
],
|
||||
'reception' => [
|
||||
'canAllow' => [ ]
|
||||
]
|
||||
'reception' => [
|
||||
'canAllow' => [ ]
|
||||
]
|
||||
];
|
||||
}
|
||||
public static function flash($mode, $message) {
|
||||
@@ -322,26 +322,26 @@ class Helper {
|
||||
public static function isUserCartVisibilityAll() {
|
||||
return \Yii::$app->params ['user_cart_item_visibility'] == 'all';
|
||||
}
|
||||
|
||||
|
||||
public static function getBackendSkin() {
|
||||
return \Yii::$app->params ['backend_skin'] ;
|
||||
}
|
||||
|
||||
|
||||
public static function getCompany() {
|
||||
return \Yii::$app->params ['company'] ;
|
||||
}
|
||||
public static function getCompanyName() {
|
||||
return \Yii::$app->params ['company_name'] ;
|
||||
}
|
||||
|
||||
|
||||
public static function isCompanyMovar() {
|
||||
return \Yii::$app->params ['company'] == 'movar';
|
||||
}
|
||||
|
||||
|
||||
public static function isCompanyGyor() {
|
||||
return \Yii::$app->params ['company'] == 'gyor';
|
||||
}
|
||||
|
||||
|
||||
public static function isUserCartOn() {
|
||||
return \Yii::$app->params ['user_cart_on'] == true;
|
||||
}
|
||||
@@ -353,26 +353,26 @@ class Helper {
|
||||
public static function isTicketTypeDoorAllowedCheckOn() {
|
||||
return \Yii::$app->params ['ticket_type_door_allowed_check_on'] == true;
|
||||
}
|
||||
|
||||
|
||||
public static function getProductSaleDefaultFocus() {
|
||||
return \Yii::$app->params ['product_sale_default_focus'] ;
|
||||
}
|
||||
public static function isProductVisibilityAccount() {
|
||||
return \Yii::$app->params ['product_visiblity'] == 'account';
|
||||
}
|
||||
|
||||
|
||||
public static function isAccountStateClosePreloadMoney() {
|
||||
return \Yii::$app->params ['account_state_close_preload_money'] == true;
|
||||
}
|
||||
|
||||
|
||||
public static function isAccountStateOpenSendMail() {
|
||||
return \Yii::$app->params ['mail_account_state_open'] == true;
|
||||
}
|
||||
|
||||
|
||||
public static function isAccountStateCloseSendMail() {
|
||||
return \Yii::$app->params ['mail_account_state_close'] == true;
|
||||
}
|
||||
|
||||
|
||||
public static function getReceptionVisibilityDays() {
|
||||
return \Yii::$app->params ['reception_visibility_days'] ;
|
||||
}
|
||||
@@ -399,12 +399,12 @@ class Helper {
|
||||
public static function isReceptionTransferIndexEnabled(){
|
||||
return !Helper::isReceptionTransferListToday();
|
||||
}
|
||||
|
||||
|
||||
public static function getRealUserIp() {
|
||||
$client = @$_SERVER ['HTTP_CLIENT_IP'];
|
||||
$forward = @$_SERVER ['HTTP_X_FORWARDED_FOR'];
|
||||
$remote = $_SERVER ['REMOTE_ADDR'];
|
||||
|
||||
|
||||
if (filter_var ( $client, FILTER_VALIDATE_IP )) {
|
||||
$ip = $client;
|
||||
} elseif (filter_var ( $forward, FILTER_VALIDATE_IP )) {
|
||||
@@ -412,10 +412,10 @@ class Helper {
|
||||
} else {
|
||||
$ip = $remote;
|
||||
}
|
||||
|
||||
|
||||
return $ip;
|
||||
}
|
||||
|
||||
|
||||
public static function url_get_contents ($Url) {
|
||||
if (!function_exists('curl_init')){
|
||||
die('CURL is not installed!');
|
||||
@@ -427,14 +427,14 @@ class Helper {
|
||||
curl_close($ch);
|
||||
return $output;
|
||||
}
|
||||
|
||||
|
||||
public static function getGeoIp() {
|
||||
$ip = Helper::getRealUserIp ();
|
||||
$details = json_decode ( Helper::url_get_contents( "http://ipinfo.io/{$ip}/json" ) );
|
||||
return $details;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
public static function mkYiiSortItem($field, $column){
|
||||
return [
|
||||
$field => [
|
||||
@@ -454,7 +454,7 @@ class Helper {
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
|
||||
public static function setBit($val,$index,$bit_on){
|
||||
$flag = +$val;
|
||||
if ( $bit_on ){
|
||||
@@ -471,7 +471,7 @@ class Helper {
|
||||
return $result ;
|
||||
}
|
||||
|
||||
|
||||
|
||||
public static function generateRandomString($length = 6,$characters = '0123456789ABCDEFGHIJKLMNOPQRSTUVWX' ) {
|
||||
$charactersLength = strlen($characters);
|
||||
$randomString = '';
|
||||
@@ -480,7 +480,7 @@ class Helper {
|
||||
}
|
||||
return $randomString;
|
||||
}
|
||||
|
||||
|
||||
public static function getWebUrl(){
|
||||
if ( \Yii::$app->params['development'] == true ){
|
||||
return "http://localhost/fitness-web";
|
||||
@@ -529,5 +529,9 @@ class Helper {
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
|
||||
|
||||
public static function isRestAllowVerifyOnly() {
|
||||
return \Yii::$app->params ['rest_allow_verify_only'] == true;
|
||||
}
|
||||
}
|
||||
@@ -15,6 +15,8 @@ use common\models\Ticket;
|
||||
use common\models\VirtualKey;
|
||||
use frontend\models\KeyToggleForm;
|
||||
use yii\base\BaseObject;
|
||||
use yii\base\InvalidConfigException;
|
||||
use yii\db\Exception;
|
||||
use yii\web\BadRequestHttpException;
|
||||
use yii\web\ServerErrorHttpException;
|
||||
|
||||
@@ -42,11 +44,18 @@ class DoorManager extends BaseObject
|
||||
*/
|
||||
public function move($identifier, $device, $direction, $verifyOnly, $createdAt = null, $date = null)
|
||||
{
|
||||
$requestId = uniqid("",false);
|
||||
$stopWatch = new StopWatch();
|
||||
|
||||
\Yii::info("move with next parameers:" . ";identifier" . $identifier . ";device" . $device . ";direction" . $direction . ";verifyOnly" . $verifyOnly . ";createdAt" . print_r($createdAt,true) . ";date" . print_r($date,true));
|
||||
\Yii::info("move get request: " . print_r($_GET, true));
|
||||
\Yii::info("move post request: " . print_r($_GET, true));
|
||||
// for testing purposes
|
||||
if ( Helper::isRestAllowVerifyOnly() === false ){
|
||||
\Yii::info("$requestId: verifyonly not allowed");
|
||||
$verifyOnly = false;
|
||||
}
|
||||
|
||||
\Yii::info("$requestId: move with next parameers:" . ";identifier" . $identifier . ";device" . $device . ";direction" . $direction . ";verifyOnly" . $verifyOnly . ";createdAt" . print_r($createdAt,true) . ";date" . print_r($date,true));
|
||||
\Yii::info("$requestId: move get request: " . print_r($_GET, true));
|
||||
\Yii::info("$requestId: move post request: " . print_r($_GET, true));
|
||||
|
||||
if (isset($createdAt)) {
|
||||
$createdAt = DateUtil::parseDateTime($createdAt);
|
||||
@@ -61,7 +70,7 @@ class DoorManager extends BaseObject
|
||||
}
|
||||
|
||||
if ($device === 'E') {
|
||||
$this->moveEmergency($identifier, $device, $direction, $verifyOnly, $createdAt, $date);
|
||||
$this->moveEmergency($requestId,$identifier, $device, $direction, $verifyOnly, $createdAt, $date);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -76,7 +85,7 @@ class DoorManager extends BaseObject
|
||||
$direction = DoorLog::$DIRECTION_OUT;
|
||||
break;
|
||||
default:
|
||||
throw new BadRequestHttpException("Direction not supported: " . $direction);
|
||||
throw new BadRequestHttpException("$requestId: Direction not supported: " . $direction);
|
||||
}
|
||||
|
||||
// if device is qr code
|
||||
@@ -84,27 +93,27 @@ class DoorManager extends BaseObject
|
||||
// allow only virtual key
|
||||
$virtualKey = VirtualKey::findOne(['number' => $identifier]);
|
||||
if (!isset($virtualKey)) {
|
||||
throw new BadRequestHttpException("Virtual key not found: " . $identifier);
|
||||
throw new BadRequestHttpException("$requestId: Virtual key not found: " . $identifier);
|
||||
}
|
||||
$card = Card::findOne($virtualKey->id_card);
|
||||
if ($card != null) {
|
||||
$card = Card::readCard($card->number);
|
||||
}
|
||||
if ($card == null) {
|
||||
throw new BadRequestHttpException("Card not found by virtual key: " . $identifier . '/' . $virtualKey->id_card);
|
||||
throw new BadRequestHttpException("$requestId: Card not found by virtual key: " . $identifier . '/' . $virtualKey->id_card);
|
||||
}
|
||||
$cardNumber = $card->number;
|
||||
\Yii::info("virtual key and card loaded in sec " . $stopWatch->split());
|
||||
\Yii::info("$requestId: virtual key and card loaded in sec " . $stopWatch->split());
|
||||
} else {
|
||||
// load by rfid or card number
|
||||
$card = Card::readCard(Helper::fixAsciiChars($identifier));
|
||||
\Yii::info("Card loaded in sec " . $stopWatch->split());
|
||||
\Yii::info("$requestId: Card loaded in sec " . $stopWatch->split());
|
||||
if (!isset($card)) {
|
||||
throw new BadRequestHttpException('Card not found with number: ' . $identifier);
|
||||
throw new BadRequestHttpException("$requestId: Card not found with number: " . $identifier);
|
||||
}
|
||||
\Yii::info("card loaded in sec " . $stopWatch->split());
|
||||
\Yii::info("$requestId: card loaded in sec " . $stopWatch->split());
|
||||
$virtualKey = VirtualKey::findOne(['id_card' => $card->id_card]);
|
||||
\Yii::info("virtual key for card loaded in sec " . $stopWatch->split());
|
||||
\Yii::info("$requestId: virtual key for card loaded in sec " . $stopWatch->split());
|
||||
|
||||
}
|
||||
|
||||
@@ -113,13 +122,13 @@ class DoorManager extends BaseObject
|
||||
return;
|
||||
}
|
||||
|
||||
$this->moveCustomer($identifier, $device, $direction, $verifyOnly, $createdAt, $date, $card, $cardNumber, $virtualKey);
|
||||
$this->moveCustomer($requestId, $identifier, $device, $direction, $verifyOnly, $createdAt, $date, $card, $cardNumber, $virtualKey);
|
||||
|
||||
}
|
||||
|
||||
function moveEmergency($identifier, $device, $direction, $verifyOnly, $createdAt, $date)
|
||||
function moveEmergency($requestId,$identifier, $device, $direction, $verifyOnly, $createdAt, $date)
|
||||
{
|
||||
\Yii::info("emergency move");
|
||||
\Yii::info("$requestId: emergency move");
|
||||
try {
|
||||
$createdAtStr = DateUtil::formatDateTimeUtc($createdAt);
|
||||
\Yii::$app->db->beginTransaction();
|
||||
@@ -188,6 +197,7 @@ class DoorManager extends BaseObject
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $requestId
|
||||
* @param $identifier string virtual key id, card rfid or card number
|
||||
* @param $device string device
|
||||
* @param $direction number direction
|
||||
@@ -200,19 +210,17 @@ class DoorManager extends BaseObject
|
||||
* @return void
|
||||
* @throws BadRequestHttpException
|
||||
* @throws ServerErrorHttpException
|
||||
* @throws \Throwable
|
||||
* @throws \yii\base\InvalidConfigException
|
||||
* @throws \yii\db\Exception
|
||||
* @throws \yii\db\StaleObjectException
|
||||
* @throws InvalidConfigException
|
||||
* @throws Exception
|
||||
*/
|
||||
function moveCustomer($identifier, $device, $direction, $verifyOnly, $createdAt, $date, $card, $cardNumber, $virtualKey)
|
||||
function moveCustomer($requestId, $identifier, $device, $direction, $verifyOnly, $createdAt, $date, $card, $cardNumber, $virtualKey)
|
||||
{
|
||||
\Yii::info("move customer");
|
||||
\Yii::info("$requestId: move customer");
|
||||
$stopWatch = new StopWatch();
|
||||
|
||||
try {
|
||||
$createdAtStr = DateUtil::formatDateTimeUtc($createdAt);
|
||||
\Yii::info("crated at str: ". $createdAtStr);
|
||||
\Yii::info("$requestId: crated at str: ". $createdAtStr);
|
||||
\Yii::$app->db->beginTransaction();
|
||||
|
||||
$doorLog = new DoorLog();
|
||||
@@ -225,7 +233,7 @@ class DoorManager extends BaseObject
|
||||
|
||||
|
||||
$activeTickets = Ticket::readActive($card, clone $date);
|
||||
\Yii::info('active ticket count:' . count($activeTickets));
|
||||
\Yii::info("$requestId: active ticket count:" . count($activeTickets));
|
||||
/** @var Ticket $ticket */
|
||||
$ticket = null;
|
||||
if (isset($activeTickets) && count($activeTickets) > 0) {
|
||||
@@ -233,54 +241,54 @@ class DoorManager extends BaseObject
|
||||
}
|
||||
|
||||
if (!isset($ticket)) {
|
||||
throw new BadRequestHttpException("No active ticket found for:" . $card->number);
|
||||
throw new BadRequestHttpException("$requestId: No active ticket found for:" . $card->number);
|
||||
}
|
||||
|
||||
\Yii::info("ticket {$ticket->id_ticket} loaded in sec " . $stopWatch->split());
|
||||
\Yii::info("$requestId: ticket {$ticket->id_ticket} loaded in sec " . $stopWatch->split());
|
||||
|
||||
$doorLog->id_ticket_current = $ticket->id_ticket;
|
||||
|
||||
// customer is also required
|
||||
$customer = $card->customer;
|
||||
if (!isset($customer)) {
|
||||
throw new BadRequestHttpException("Customer not found for:" . $card->number);
|
||||
throw new BadRequestHttpException("$requestId: Customer not found for:" . $card->number);
|
||||
}
|
||||
|
||||
$doorLog->id_customer = $customer->id_customer;
|
||||
\Yii::info("customer {$customer->id_customer} loaded in sec " . $stopWatch->split());
|
||||
\Yii::info("$requestId: customer {$customer->id_customer} loaded in sec " . $stopWatch->split());
|
||||
|
||||
if (!$verifyOnly) {
|
||||
// save the door log
|
||||
$doorLog->save(false);
|
||||
}
|
||||
\Yii::info("door log {$doorLog->id_door_log} saved in sec " . $stopWatch->split());
|
||||
\Yii::info("$requestId: door log {$doorLog->id_door_log} saved in sec " . $stopWatch->split());
|
||||
|
||||
// if direction is in
|
||||
if ($direction == DoorLog::$DIRECTION_IN) {
|
||||
|
||||
if ($card->isFlagDoor()) {
|
||||
throw new BadRequestHttpException("Card already 'IN': " . $card->id_card);
|
||||
throw new BadRequestHttpException("$requestId: Card already 'IN': " . $card->id_card);
|
||||
}
|
||||
|
||||
if ($card->isFlagKey()) {
|
||||
throw new BadRequestHttpException("Key required: " . $card->id_card);
|
||||
throw new BadRequestHttpException("$requestId: Key required: " . $card->id_card);
|
||||
}
|
||||
|
||||
if ($card->isFlagStatus()) {
|
||||
throw new BadRequestHttpException("Card has no active status: " . $card->id_card);
|
||||
throw new BadRequestHttpException("$requestId: Card has no active status: " . $card->id_card);
|
||||
}
|
||||
|
||||
if (isset($virtualKey)) {
|
||||
|
||||
if (isset($virtualKey->direction_in_at)) {
|
||||
throw new BadRequestHttpException("Virtual key - already moved in: " . $identifier . '/' . $virtualKey->id_card);
|
||||
throw new BadRequestHttpException("$requestId: Virtual key - already moved in: " . $identifier . '/' . $virtualKey->id_card);
|
||||
}
|
||||
|
||||
$virtualKey->direction_in_at = Helper::getDateTimeString();
|
||||
\Yii::info("Setting virtual key direction_in_at");
|
||||
\Yii::info("$requestId: Setting virtual key direction_in_at");
|
||||
|
||||
if (!$verifyOnly) {
|
||||
\Yii::info("Updating virtual key");
|
||||
\Yii::info("$requestId: Updating virtual key");
|
||||
$virtualKey->save(false);
|
||||
}
|
||||
}
|
||||
@@ -289,13 +297,13 @@ class DoorManager extends BaseObject
|
||||
if (!$verifyOnly) {
|
||||
// if not verifyonly, check, if ticket usage count must be increased
|
||||
$countDoorLogsForTicketSince = $this->getCountDoorLogsForTicketSince($ticket->id_ticket, DateUtil::utcDate(clone $date));
|
||||
\Yii::info("getCountDoorLogsForTicketSince: " . $countDoorLogsForTicketSince);
|
||||
\Yii::info("$requestId: getCountDoorLogsForTicketSince: " . $countDoorLogsForTicketSince);
|
||||
|
||||
if (!isset($countDoorLogsForTicketSince)) {
|
||||
$countDoorLogsForTicketSince = 0;
|
||||
}
|
||||
|
||||
\Yii::info("count of door logs '{$countDoorLogsForTicketSince}' loaded in sec " . $stopWatch->split());
|
||||
\Yii::info("$requestId: count of door logs '{$countDoorLogsForTicketSince}' loaded in sec " . $stopWatch->split());
|
||||
|
||||
// if the current event is the first door log today
|
||||
if ($countDoorLogsForTicketSince == 1) {
|
||||
@@ -303,7 +311,7 @@ class DoorManager extends BaseObject
|
||||
$usageCount = $ticket->usage_count;
|
||||
$ticket->usage_count += 1;
|
||||
$ticket->save(false);
|
||||
\Yii::info("First ticket usage today, increasing usage count for card: " . $card->id_card);
|
||||
\Yii::info("$requestId: First ticket usage today, increasing usage count for card: " . $card->id_card);
|
||||
Log::log(
|
||||
[
|
||||
'type' => Log::$TYPE_TICKET_USAGE_FIRST,
|
||||
@@ -312,10 +320,10 @@ class DoorManager extends BaseObject
|
||||
'id_door_log' => $doorLog->id_door_log
|
||||
]
|
||||
);
|
||||
\Yii::info("Ticket usage count increased after first doorlog of day in sec " . $stopWatch->split());
|
||||
\Yii::info("$requestId: Ticket usage count increased after first doorlog of day in sec " . $stopWatch->split());
|
||||
|
||||
} else {
|
||||
\Yii::info("more then one door log today for card: " . $card->id_card);
|
||||
\Yii::info("$requestId: more then one door log today for card: " . $card->id_card);
|
||||
// we have already a door log for today, other than this
|
||||
// Now we split the day into 3hour intervalls, starting with the createdAt value of the first event.
|
||||
// If the actual event happens in an interval, in which still now doorlog event happend, we increase
|
||||
@@ -332,9 +340,9 @@ class DoorManager extends BaseObject
|
||||
->andWhere(['in', 'direction', [DoorLog::$DIRECTION_IN_WITHOUT_MOVE, DoorLog::$DIRECTION_IN]])
|
||||
->orderBy(['door_log.created_at' => SORT_ASC])
|
||||
->all();
|
||||
\Yii::info("All door logs for today loaded in sec " . $stopWatch->split());
|
||||
\Yii::info("$requestId: All door logs for today loaded in sec " . $stopWatch->split());
|
||||
|
||||
\Yii::info("allDoorLogToday", print_r($allDoorLogToday, true));
|
||||
\Yii::info("$requestId: allDoorLogToday", print_r($allDoorLogToday, true));
|
||||
|
||||
|
||||
if (isset($allDoorLogToday) && count($allDoorLogToday) > 0) {
|
||||
@@ -343,7 +351,7 @@ class DoorManager extends BaseObject
|
||||
|
||||
if (isset($firstInToday)) {
|
||||
|
||||
\Yii::info("first in today for card: " . $card->id_card . " was at " . $firstInToday->created_at);
|
||||
\Yii::info("$requestId: first in today for card: " . $card->id_card . " was at " . $firstInToday->created_at);
|
||||
|
||||
$firstEntryDateTimeToday = DateUtil::parseDateTime($firstInToday->created_at);
|
||||
|
||||
@@ -365,7 +373,7 @@ class DoorManager extends BaseObject
|
||||
|
||||
$activeInterval = $this->getActiveInterval($intervals, $createdAt);
|
||||
if (!isset($activeInterval)) {
|
||||
throw new ServerErrorHttpException("Active Interval not found");
|
||||
throw new ServerErrorHttpException("$requestId: Active Interval not found");
|
||||
}
|
||||
|
||||
$logCountInActiveInterval = count($activeInterval['logs']);
|
||||
@@ -373,7 +381,7 @@ class DoorManager extends BaseObject
|
||||
if ($logCountInActiveInterval == 1) {
|
||||
$ticket->usage_count = $ticket->usage_count + 1;
|
||||
$ticket->save(false);
|
||||
\Yii::info("Ticket usage count increased after first IN after first door_log in interval in sec " . $stopWatch->split());
|
||||
\Yii::info("$requestId: Ticket usage count increased after first IN after first door_log in interval in sec " . $stopWatch->split());
|
||||
|
||||
}
|
||||
}
|
||||
@@ -385,27 +393,27 @@ class DoorManager extends BaseObject
|
||||
if ($direction == DoorLog::$DIRECTION_OUT || $direction == DoorLog::$DIRECTION_OUT_WITHOUT_MOVE) {
|
||||
|
||||
if ($card->isFlagOutKey()) {
|
||||
throw new BadRequestHttpException("Can't exit with card has a key assigned");
|
||||
throw new BadRequestHttpException("$requestId: Can't exit with card has a key assigned");
|
||||
}
|
||||
|
||||
if ($card->isFlagStatus()) {
|
||||
throw new BadRequestHttpException("Can't exit with card has inactive status");
|
||||
throw new BadRequestHttpException("$requestId: Can't exit with card has inactive status");
|
||||
}
|
||||
|
||||
$keyAssigned = CardKeyAssignment::findOne(['id_card' => $card->id_card]);
|
||||
|
||||
if (isset($keyAssigned)) {
|
||||
throw new BadRequestHttpException("Can't exit with card has a key assigned");
|
||||
throw new BadRequestHttpException("$requestId: Can't exit with card has a key assigned");
|
||||
}
|
||||
|
||||
if (isset($virtualKey)) {
|
||||
|
||||
if (!isset($virtualKey->direction_in_at)) {
|
||||
throw new BadRequestHttpException("Virtual key: move out without move in");
|
||||
throw new BadRequestHttpException("$requestId: Virtual key: move out without move in");
|
||||
}
|
||||
|
||||
if (isset($virtualKey->direction_out_at)) {
|
||||
throw new BadRequestHttpException("Virtual key: already move out");
|
||||
throw new BadRequestHttpException("$requestId: Virtual key: already move out");
|
||||
}
|
||||
|
||||
$virtualKey->direction_out_at = Helper::getDateTimeString();
|
||||
@@ -419,12 +427,12 @@ class DoorManager extends BaseObject
|
||||
if (!$verifyOnly) {
|
||||
$ticket->save(false);
|
||||
}
|
||||
\Yii::info("direction_out: ticket count_move_out set after direction_out in sec " . $stopWatch->split());
|
||||
\Yii::info("$requestId: direction_out: ticket count_move_out set after direction_out in sec " . $stopWatch->split());
|
||||
}
|
||||
|
||||
if (!$verifyOnly) {
|
||||
Card::updateCardFlagTicket($ticket->id_ticket);
|
||||
\Yii::info("updateCardFlagTicket: card flag updated in sec " . $stopWatch->split());
|
||||
\Yii::info("$requestId: updateCardFlagTicket: card flag updated in sec " . $stopWatch->split());
|
||||
|
||||
// reload card after flag is set
|
||||
$card = Card::readCard($cardNumber);
|
||||
@@ -432,22 +440,22 @@ class DoorManager extends BaseObject
|
||||
$card->flag_out = Helper::setBit($card->flag_out, Card::$FLAG_DOOR, true);
|
||||
$card->flag = Helper::setBit($card->flag, Card::$FLAG_DOOR, false);
|
||||
$card->save(false);
|
||||
\Yii::info("direction_out: Door flag updated in sec " . $stopWatch->split());
|
||||
\Yii::info("$requestId: direction_out: Door flag updated in sec " . $stopWatch->split());
|
||||
|
||||
} else if ($direction == DoorLog::$DIRECTION_IN || $direction == DoorLog::$DIRECTION_IN_WITHOUT_MOVE) {
|
||||
$card->flag_out = Helper::setBit($card->flag_out, Card::$FLAG_DOOR, false);
|
||||
$card->flag = Helper::setBit($card->flag, Card::$FLAG_DOOR, true);
|
||||
$card->save(false);
|
||||
\Yii::info("direction_in: Card flag updated in sec " . $stopWatch->split());
|
||||
\Yii::info("$requestId: direction_in: Card flag updated in sec " . $stopWatch->split());
|
||||
}
|
||||
}
|
||||
$stopWatch->stop();
|
||||
\Yii::info("finished in sec " . $stopWatch->getTotal());
|
||||
\Yii::info("$requestId: finished in sec " . $stopWatch->getTotal());
|
||||
\Yii::$app->db->transaction->commit();
|
||||
\Yii::info("Commited");
|
||||
\Yii::info("$requestId: Commited");
|
||||
} catch (\Exception $e) {
|
||||
\Yii::$app->db->transaction->rollBack();
|
||||
\Yii::info("rollbacked");
|
||||
\Yii::info("$requestId: rollbacked");
|
||||
throw $e;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user