diff --git a/backend/runtime/.gitignore b/backend/runtime/.gitignore index c96a04f..d6b7ef3 100644 --- a/backend/runtime/.gitignore +++ b/backend/runtime/.gitignore @@ -1,2 +1,2 @@ * -!.gitignore \ No newline at end of file +!.gitignore diff --git a/clean_runtime.sh b/clean_runtime.sh new file mode 100755 index 0000000..debdd61 --- /dev/null +++ b/clean_runtime.sh @@ -0,0 +1,32 @@ +#!/usr/bin/env bash + +FITNESS_HOME=$(pwd) + +echo ${FITNESS_HOME} + +cd ${FITNESS_HOME}/backend +rm -r runtime +mkdir runtime +cd runtime +cat > .gitignore < .gitignore < .gitignore <params ['ticket_create_price_editable'] == true ; } + public static function isKeyToggleDoorLogEnabled() { + return \Yii::$app->params ['key_toggle_door_log_enabled'] == true ; + } + public static function isReceptionTransferListToday(){ return \Yii::$app->params['reception_transfer_list_only_today']; } diff --git a/common/config/params.php b/common/config/params.php index 3817db6..d97d64a 100644 --- a/common/config/params.php +++ b/common/config/params.php @@ -54,6 +54,10 @@ return [ ] ], 'newsletter_from' => 'noreply@fitnessadmin.hu', - 'newsletter_enabled' => false - + 'newsletter_enabled' => false, + /** + * if true, key in/out events will generate doorlog events + */ + 'key_toggle_door_log_enabled' => false + ]; diff --git a/common/data/trigger/trigger.cutler.sql b/common/data/trigger/trigger.cutler.sql new file mode 100644 index 0000000..2411576 --- /dev/null +++ b/common/data/trigger/trigger.cutler.sql @@ -0,0 +1,119 @@ +DROP TRIGGER IF EXISTS trigger_inc_ticket_usage_count; +CREATE TRIGGER trigger_inc_ticket_usage_count +AFTER INSERT ON `door_log` FOR EACH ROW + begin + + DECLARE p_count_all Integer; + DECLARE p_count_all_2 Integer; + DECLARE p_from DATETIME; + DECLARE p_usage_count Integer; + DECLARE p_max_usage_count Integer; + DECLARE p_mo_ticket_id Integer; + DECLARE p_mo_ticket_max_usage_count Integer; + DECLARE p_allow_multiple_enter boolean; + DECLARE p_allow_enter boolean; + + delete from devlog; + + IF NEW.id_customer is not null and NEW.id_card is not null + THEN + + IF (NEW.direction = 7 or New.direction = 3 ) and NEW.id_ticket_current is not null + then + INSERT INTO devlog ( msg) values('belepes feldoglozas indit'); + + select count(*) into @p_count_all from door_log where created_at >= CURDATE() and id_ticket_current = New.id_ticket_current and ( direction = 7 or direction = 3); + INSERT INTO devlog ( msg) values( concat( 'count all' ,@p_count_all ) ); + + + IF @p_count_all = 1 + THEN + + select usage_count, max_usage_count into @p_usage_count ,@p_max_usage_count from ticket where id_ticket = NEW.id_ticket_current; + + + update ticket set usage_count = usage_count +1 where id_ticket = NEW.id_ticket_current; + + + INSERT INTO log (type,message, app, id_ticket, id_door_log,created_at, updated_at) + values( + 30, concat('Bérlet használat (elotte: ',@p_usage_count, ' > utana: ' , @p_usage_count +1 , ' max: ', @p_max_usage_count, ')' ), ' trigger_inc_ticket',New.id_ticket_current, New.id_door_log,now(),now()); + else + + select min(created_at) + INTERVAL (3 * FLOOR( ( ( HOUR( TIMEDIFF( min(created_at) , now() ) ) /3 ) ) ) ) hour as last_date + into @p_from + from door_log + where created_at > CURDATE() and id_customer is not null and id_ticket_current = NEW.id_ticket_current and ( direction = 7 or direction = 3); + + + select count(*) into @p_count_all_2 from door_log where created_at >= @p_from and id_ticket_current = New.id_ticket_current and ( direction = 7 or direction = 3); + + INSERT INTO devlog ( msg) values(CONCAT( 'Belépések száma az aktuális 3 órás intervalumban: ', @p_count_all_2) ); + + + IF @p_count_all_2 = 1 + THEN + INSERT INTO devlog ( msg) values( 'Az aktuális intervallumban ez az első belépés, usage_count növelése' ); + + select usage_count, max_usage_count into @p_usage_count ,@p_max_usage_count from ticket where id_ticket = NEW.id_ticket_current; + + update ticket set usage_count = usage_count +1 where id_ticket = New.id_ticket_current; + + INSERT INTO log (type,message, app, id_ticket, id_door_log,created_at, updated_at) + values( + 40, concat('Bérlet használat/egy nap tobbszori (elotte: ',@p_usage_count, ' > utana: ' , @p_usage_count +1 , ' max: ', @p_max_usage_count, ')' ), ' trigger_inc_ticket',New.id_ticket_current, New.id_door_log,now(),now()); + END IF; + END IF; + End IF; + + + IF NEW.direction = 5 or New.direction = 1 + then + INSERT INTO devlog ( msg) values('Kilépés van folyamatban, kilépések számának beállítása'); + update ticket set count_move_out = usage_count where id_ticket = NEW.id_ticket_current; + END IF; + + INSERT INTO devlog ( msg) values( 'Kártya validáció módosítása' ); + + UPDATE card as c1 + left JOIN ( select ticket.id_card as id_card , max(ticket.id_ticket) as id_ticket + from ticket + where ticket.start <= CURDATE() + and ticket.end >= curdate() + and ticket.status = 10 + and ticket.count_move_out < ticket.max_usage_count + and ticket.id_card = New.id_card + group by id_card + order by id_card desc ) as t + on t.id_card = c1.id_card + SET c1.validity = case when t.id_card is null then ( c1.validity | 1 << 0 ) else ( c1.validity & ~(1 << 0) ) end + , c1.flag = case when t.id_card is null then ( c1.flag | 1 << 0 ) else ( c1.flag & ~(1 << 0) ) end + , c1.id_ticket_current = case when t.id_ticket is null then null else t.id_ticket end + WHERE c1.type <> 50 and c1.id_card = New.id_card; + + IF NEW.direction = 5 or New.direction = 1 + then + select max(ticket.id_ticket) into @p_mo_ticket_id + from ticket + where ticket.start <= CURDATE() + and ticket.end >= curdate() + and ticket.status = 10 + and ticket.count_move_out < ticket.max_usage_count + and ticket.id_card = New.id_card + group by id_card + order by id_card desc; + set @p_allow_enter = true; + update card set + flag_out = ( flag_out | 1 << 1 ) , + flag = case when @p_allow_enter then ( flag & ~(1 << 1) ) else ( flag | 1 << 1 ) end + WHERE type <> 50 and id_card = New.id_card; + END IF; + IF (NEW.direction = 7 or New.direction = 3 ) and NEW.id_ticket_current is not null + THEN + update card set + flag_out = ( flag_out & ~(1 << 1 ) ) , + flag = ( flag | 1 << 1 ) + WHERE type <> 50 and id_card = New.id_card; + END IF; + END IF; + END \ No newline at end of file diff --git a/common/models/DoorLog.php b/common/models/DoorLog.php index 72d81dc..f0a535a 100644 --- a/common/models/DoorLog.php +++ b/common/models/DoorLog.php @@ -174,6 +174,10 @@ class DoorLog extends \yii\db\ActiveRecord public static function mkDoorLog($direction,$card,$customer = null,$key = null){ + if ( !Helper::isKeyToggleDoorLogEnabled() ){ + return; + } + $dlog = new DoorLog(); $dlog->id_card = $card->id_card; diff --git a/console/controllers/DoorlogController.php b/console/controllers/DoorlogController.php index a4c3f33..d6e73d1 100644 --- a/console/controllers/DoorlogController.php +++ b/console/controllers/DoorlogController.php @@ -1,39 +1,21 @@ 'ticket']; -// } - - - public function actionIn($ticket) { - $log = new DoorLog(); //5559 9719 - $log->id_card = 9719; $log->id_customer = 5559; $log->id_ticket_current = $ticket; @@ -44,9 +26,6 @@ class DoorlogController extends Controller{ $log->id_account = null; $log->card_flag = 0; $log->flag_out= 0; - - - $log->save(false); } @@ -92,12 +71,12 @@ class DoorlogController extends Controller{ public function actionFixmissing(){ $tickets = Ticket::find()->andWhere(['in','id_ticket_type' ,[54,55,56,57]])->all(); - - - - foreach ($tickets as $ticket){ + + + /** @var /common/models/Ticket $ticket */ + foreach ($tickets as $ticket){ $cache = []; - + $doorlogs = DoorLog::find()->andWhere( [ 'id_ticket_current' => $ticket->id_ticket, 'direction' => 7 ])->all(); @@ -129,23 +108,17 @@ class DoorlogController extends Controller{ } if ( count($cache) > 0 ){ - foreach ($cache as $item){ - echo $item['id']; echo "/"; echo $item['count']; echo "\r\n"; $t = Ticket::findOne($ticket->id_ticket); - - $elotte = $t->usage_count; $t->usage_count = $t->usage_count + 1; $t->count_move_out = $t->usage_count; - $t->save(false); - $log = new Log(); $log->type = 30; $log->id_ticket = $ticket->id_ticket; @@ -153,18 +126,17 @@ class DoorlogController extends Controller{ $log->id_door_log = $item['id']; $log->message = "FixMissing: Bérlet használat (elotte: " . $elotte ." > utana: " . $t->usage_count . " max: ". $t->max_usage_count .")"; $log->save(false); - } - } - - } - - - - } - + + + public function actionDeleteOld(){ + $sql = "DELETE FROM door_log WHERE created_at < DATE_SUB(NOW(), INTERVAL 3 MONTH);"; + $cmd = \Yii::$app->db->createCommand($sql); + $count = $cmd->execute(); + \Yii::info("Door logs deleted: " . $count ); + } } \ No newline at end of file diff --git a/console/runtime/.gitignore b/console/runtime/.gitignore index c96a04f..d6b7ef3 100644 --- a/console/runtime/.gitignore +++ b/console/runtime/.gitignore @@ -1,2 +1,2 @@ * -!.gitignore \ No newline at end of file +!.gitignore diff --git a/cutler_daily.sh b/cutler_daily.sh index eb2839a..edba5cb 100644 --- a/cutler_daily.sh +++ b/cutler_daily.sh @@ -1,4 +1,5 @@ #!/usr/bin/env bash php /var/www/virtual/fitnessadmin.hu/htdocs/cutler/yii ticket/index -php /var/www/virtual/fitnessadmin.hu/htdocs/cutler/yii ticket/daily \ No newline at end of file +php /var/www/virtual/fitnessadmin.hu/htdocs/cutler/yii ticket/daily +php /var/www/virtual/fitnessadmin.hu/htdocs/cutler/yii doorlog/delete-old \ No newline at end of file diff --git a/frontend/controllers/CustomerController.php b/frontend/controllers/CustomerController.php index 90f081d..b589e47 100644 --- a/frontend/controllers/CustomerController.php +++ b/frontend/controllers/CustomerController.php @@ -6,7 +6,6 @@ use frontend\models\TowelForm; use Yii; use common\models\Customer; use frontend\models\ReceptionForm; -use frontend\models\CustomerSearch; use yii\web\Controller; use yii\web\NotFoundHttpException; use yii\filters\VerbFilter; @@ -14,7 +13,6 @@ use common\models\Card; use frontend\models\CustomerUpdate; use frontend\models\CustomerCreate; use common\models\Image; -use yii\base\Exception; use common\models\Log; /** @@ -56,15 +54,13 @@ class CustomerController extends Controller $model->number = $number; $model->readCard(); - $model->mkDoorLog(); +// $model->mkDoorLog(); if ( $model->isFreeCard() ){ return $this->redirect([ 'create', 'number' => $model->card->number ]); }else if ( $model->isCardWithKey()){ return $this->redirect([ 'product/sale', 'number' => $model->card->number ]); }else if ( $model->isCustomerWithTicket()){ -// return $this->redirect([ 'product/sale', 'number' => $model->card->number ]); -// return $this->redirect([ 'customer/reception', 'number' => $model->card->number ]); }else if ( $model->isCardWithCustomer() ){ return $this->redirect([ 'ticket/create', 'number' => $model->card->number ]); } @@ -72,38 +68,6 @@ class CustomerController extends Controller return $this->render('reception',['model' => $model]); } - - - /** - * Lists all Customer models. - * @return mixed - */ - /* - public function actionIndex() - { - $searchModel = new CustomerSearch(); - $dataProvider = $searchModel->search(Yii::$app->request->queryParams); - - return $this->render('index', [ - 'searchModel' => $searchModel, - 'dataProvider' => $dataProvider, - ]); - } -*/ - /** - * Displays a single Customer model. - * @param null $number - * @return mixed - * @internal param int $id - */ - /* - public function actionView($id) - { - return $this->render('view', [ - 'model' => $this->findModel($id), - ]); - } -*/ public function actionTowel($number = null) { @@ -185,7 +149,9 @@ class CustomerController extends Controller if ( $number != null ){ $card = Card::readCard($number); if ( $card != null ){ - $model = CustomerUpdate::find()->innerJoin(Card::tableName(), "customer.id_customer_card = card.id_card")->andWhere( [ 'customer.id_customer_card' => $card->id_card ])->one(); + $model = CustomerUpdate::find() + ->innerJoin(Card::tableName(), "customer.id_customer_card = card.id_card") + ->andWhere( [ 'customer.id_customer_card' => $card->id_card ])->one(); } } @@ -239,25 +205,6 @@ class CustomerController extends Controller } } - - - -// s - - /** - * Deletes an existing Customer model. - * If deletion is successful, the browser will be redirected to the 'index' page. - * @param integer $id - * @return mixed - */ - /* - public function actionDelete($id) - { - $this->findModel($id)->delete(); - - return $this->redirect(['index']); - } -*/ /** * Finds the Customer model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. diff --git a/frontend/controllers/KeyController.php b/frontend/controllers/KeyController.php index a9eb5bf..eb7ddc1 100644 --- a/frontend/controllers/KeyController.php +++ b/frontend/controllers/KeyController.php @@ -103,11 +103,9 @@ class KeyController extends Controller if ( isset( $model->keyCard ) ){ return $this->redirect(['product/sale', 'number' => $model->keyCard->number ]); } - - - + return $this->redirect(['customer/reception', 'number' => $number ]); - + } diff --git a/frontend/models/ReceptionForm.php b/frontend/models/ReceptionForm.php index c24db87..9d79307 100644 --- a/frontend/models/ReceptionForm.php +++ b/frontend/models/ReceptionForm.php @@ -52,7 +52,37 @@ class ReceptionForm extends Model 'verifyCode' => 'Verification Code', ]; } - + + + public function preReadCard(){ + + $this->number = Helper::fixAsciiChars( $this->number ); + + $query = Card::find(); + $query->leftJoin("card_key_assignment", 'card.id_card = card_key_assignment.id_card'); + $query->leftJoin("key", 'key.id_key = card_key_assignment.id_key'); + + $query->andWhere(['or', + ['and',[ 'in','card.number' , [$this->number]],"trim(coalesce(card.number, '')) <>'' " ], + ['and', ['in','card.rfid_key' ,[ $this->number] ],"trim(coalesce(card.rfid_key, '')) <>'' "], + ['and',[ 'in','key.number' , [$this->number]],"trim(coalesce(key.number, '')) <>'' " ], + ['and', ['in','key.rfid_key' ,[ $this->number] ],"trim(coalesce(key.rfid_key, '')) <>'' "] + + ]); + + $this->card = $query->one(); + + if ( $this->card == null ){ + + } + + if ( $this->card != null ){ + $this->customer = $this->card->customer; + $this->readValidTickets(); + } + + } + public function readCard(){ $this->number = Helper::fixAsciiChars( $this->number ); @@ -71,10 +101,7 @@ class ReceptionForm extends Model $this->card = $query->one(); - if ( $this->card == null ){ - - } - + if ( $this->card != null ){ $this->customer = $this->card->customer; $this->readValidTickets(); diff --git a/frontend/runtime/.gitignore b/frontend/runtime/.gitignore index c96a04f..d6b7ef3 100644 --- a/frontend/runtime/.gitignore +++ b/frontend/runtime/.gitignore @@ -1,2 +1,2 @@ * -!.gitignore \ No newline at end of file +!.gitignore