diff --git a/backend/components/AdminMenuStructure.php b/backend/components/AdminMenuStructure.php
index bf08e95..b04dd80 100644
--- a/backend/components/AdminMenuStructure.php
+++ b/backend/components/AdminMenuStructure.php
@@ -80,6 +80,7 @@ class AdminMenuStructure{
$items[] = ['label' => 'Statisztika', 'url' => ['/ticket/statistics' , 'TicketSearchStatisitcs[start]' =>$today,'TicketSearchStatisitcs[end]' => $tomorrow ] ];
$items[] = ['label' => 'Kártya létrehozás', 'url' => ['/card-package/index' , ] ];
$items[] = ['label' => 'Kártya csomag RFId hozzárendelés', 'url' => ['/card-package/import' , ] ];
+ $items[] = ['label' => 'Érvényességek újraszámolása', 'url' => ['/card/recalculate' , ] ];
$this->menuItems[] = ['label' => 'Bérletek/Vendégek', 'url' => $this->emptyUrl,
'items' => $items
];
@@ -133,6 +134,7 @@ class AdminMenuStructure{
/////////////////////////////
$items = [];
$items[] = ['label' => 'Kártya események', 'url' => ['/door-log/index' , 'DoorLogSearch[start]' =>$todayDatetime,'DoorLogSearch[end]' => $tomorrowDatetime ] ];
+ $items[] = ['label' => 'Esemény napló', 'url' => ['/log/index' , 'LogSearch[start]' =>$todayDatetime,'LogSearch[end]' => $tomorrowDatetime ] ];
// $items[] = ['label' => 'Részletek aktiválása', 'url' => ['/ugiro/parts' ] ];
// $items[] = ['label' => 'Bevétel', 'url' => ['/transfer/summary' , 'TransferSummarySearch[start]' =>$today,'TransferSummarySearch[end]' => $tomorrow ] ];
// $items[] = ['label' => 'Napi bevételek', 'url' => ['/transfer/list', 'TransferListSearch[start]' =>$todayDatetime,'TransferListSearch[end]' => $tomorrowDatetime ] ];
diff --git a/backend/controllers/LogController.php b/backend/controllers/LogController.php
new file mode 100644
index 0000000..d0a873c
--- /dev/null
+++ b/backend/controllers/LogController.php
@@ -0,0 +1,127 @@
+ [
+ 'class' => \yii\filters\AccessControl::className(),
+ 'rules' => [
+ // allow authenticated users
+ [
+ 'actions' => [ 'index' ],
+ 'allow' => true,
+ 'roles' => ['admin','employee','reception'],
+ ],
+ // everything else is denied
+ ],
+ ],
+ ];
+ }
+
+ /**
+ * Lists all Log models.
+ * @return mixed
+ */
+ public function actionIndex()
+ {
+ $searchModel = new LogSearch();
+ $dataProvider = $searchModel->search(Yii::$app->request->queryParams);
+
+ return $this->render('index', [
+ 'searchModel' => $searchModel,
+ 'dataProvider' => $dataProvider,
+ ]);
+ }
+
+ /**
+ * Displays a single Log model.
+ * @param integer $id
+ * @return mixed
+ */
+ public function actionView($id)
+ {
+ return $this->render('view', [
+ 'model' => $this->findModel($id),
+ ]);
+ }
+
+ /**
+ * Creates a new Log model.
+ * If creation is successful, the browser will be redirected to the 'view' page.
+ * @return mixed
+ */
+ public function actionCreate()
+ {
+ $model = new Log();
+
+ if ($model->load(Yii::$app->request->post()) && $model->save()) {
+ return $this->redirect(['view', 'id' => $model->id_log]);
+ } else {
+ return $this->render('create', [
+ 'model' => $model,
+ ]);
+ }
+ }
+
+ /**
+ * Updates an existing Log model.
+ * If update is successful, the browser will be redirected to the 'view' page.
+ * @param integer $id
+ * @return mixed
+ */
+ public function actionUpdate($id)
+ {
+ $model = $this->findModel($id);
+
+ if ($model->load(Yii::$app->request->post()) && $model->save()) {
+ return $this->redirect(['view', 'id' => $model->id_log]);
+ } else {
+ return $this->render('update', [
+ 'model' => $model,
+ ]);
+ }
+ }
+
+ /**
+ * Deletes an existing Log 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 Log model based on its primary key value.
+ * If the model is not found, a 404 HTTP exception will be thrown.
+ * @param integer $id
+ * @return Log the loaded model
+ * @throws NotFoundHttpException if the model cannot be found
+ */
+ protected function findModel($id)
+ {
+ if (($model = Log::findOne($id)) !== null) {
+ return $model;
+ } else {
+ throw new NotFoundHttpException('The requested page does not exist.');
+ }
+ }
+}
diff --git a/backend/models/LogSearch.php b/backend/models/LogSearch.php
new file mode 100644
index 0000000..2d5d049
--- /dev/null
+++ b/backend/models/LogSearch.php
@@ -0,0 +1,122 @@
+Yii::$app->formatter->datetimeFormat , 'timestampAttribute' => 'timestampStart' ,'timestampAttributeFormat' => 'yyyy-MM-dd HH:mm' ,'timeZone' => 'UTC' ],
+ [[ 'end' , ], 'date' ,'format' =>Yii::$app->formatter->datetimeFormat , 'timestampAttribute' => 'timestampEnd' ,'timestampAttributeFormat' => 'yyyy-MM-dd HH:mm' ,'timeZone' => 'UTC' ],
+ ];
+ }
+
+ /**
+ * @inheritdoc
+ */
+ public function scenarios()
+ {
+ // bypass scenarios() implementation in the parent class
+ return Model::scenarios();
+ }
+
+ /**
+ * Creates data provider instance with search query applied
+ *
+ * @param array $params
+ *
+ * @return ActiveDataProvider
+ */
+ public function search($params)
+ {
+ $query = new Query();
+ $query->select([
+ 'log.id_log as log_id_log',
+ 'log.created_at as log_created_at',
+ 'log.message as log_message',
+ 'log.app as log_app',
+ 'log.type as log_type',
+ 'user.username as user_username',
+ 'customer.name as customer_name',
+
+ ]);
+ $query->from("log");
+ $query->leftJoin("user"," user.id = log.id_user");
+ $query->leftJoin("customer"," customer.id_customer = log.id_customer");
+
+
+ $dataProvider = new ActiveDataProvider([
+ 'query' => $query,
+ 'sort' =>[
+ 'defaultOrder' => [ 'log_created_at' => SORT_DESC],
+ 'attributes' => Helper::mkYiiSortItems([
+ ['log_id_log'],
+ ['log_created_at'],
+ ['log_message'],
+ ['log_app'],
+ ['log_app'],
+ ['user_username'],
+ ['customer_name'],
+
+ ])
+
+ ]
+ ]);
+
+ $this->load($params);
+
+ if (!$this->validate()) {
+ // uncomment the following line if you do not want to return any records when validation fails
+ // $query->where('0=1');
+ return $dataProvider;
+ }
+
+ $query->andFilterWhere(['>=', 'log.created_at', $this->timestampStart]);
+ $query->andFilterWhere(['<', 'log.created_at', $this->timestampEnd]);
+
+ $query->andFilterWhere([
+ 'id_log' => $this->id_log,
+ 'type' => $this->type,
+ 'id_user' => $this->id_user,
+ 'id_transfer' => $this->id_transfer,
+ 'id_money_movement' => $this->id_money_movement,
+ 'id_ticket' => $this->id_ticket,
+ 'id_sale' => $this->id_sale,
+ 'id_customer' => $this->id_customer,
+ 'id_account' => $this->id_account,
+ 'id_account_state' => $this->id_account_state,
+ 'id_key' => $this->id_key,
+ 'id_product' => $this->id_product,
+ 'id_door_log' => $this->id_door_log,
+ 'created_at' => $this->created_at,
+ ]);
+
+ $query->andFilterWhere(['like', 'message', $this->message])
+ ->andFilterWhere(['like', 'url', $this->url])
+ ->andFilterWhere(['like', 'app', $this->app]);
+
+ return $dataProvider;
+ }
+}
diff --git a/backend/views/log/_form.php b/backend/views/log/_form.php
new file mode 100644
index 0000000..0a0e615
--- /dev/null
+++ b/backend/views/log/_form.php
@@ -0,0 +1,57 @@
+
+
+
diff --git a/backend/views/log/_search.php b/backend/views/log/_search.php
new file mode 100644
index 0000000..3d9f237
--- /dev/null
+++ b/backend/views/log/_search.php
@@ -0,0 +1,50 @@
+
+
+
+
+ ['index'],
+ 'method' => 'get',
+ ]); ?>
+
+
+
+
+
+ = $form->field($model, 'start')->widget(DateTimePicker::classname(), [
+ 'pluginOptions' => [
+ 'autoclose'=>true,
+ 'format' => 'yyyy.mm.dd hh:ii'
+ ]
+ ]) ?>
+
+
+
+ = $form->field($model, 'end') ->widget(DateTimePicker::classname(), [
+ 'pluginOptions' => [
+ 'autoclose'=>true,
+ 'format' => 'yyyy.mm.dd hh:ii'
+ ]
+ ]) ?>
+
+
+
+
+
+
+
+ = Html::submitButton(Yii::t('common/log', 'Keresés'), ['class' => 'btn btn-primary']) ?>
+
+
+
+
+
diff --git a/backend/views/log/create.php b/backend/views/log/create.php
new file mode 100644
index 0000000..6ca4e3b
--- /dev/null
+++ b/backend/views/log/create.php
@@ -0,0 +1,21 @@
+title = Yii::t('common/log', 'Create Log');
+$this->params['breadcrumbs'][] = ['label' => Yii::t('common/log', 'Logs'), 'url' => ['index']];
+$this->params['breadcrumbs'][] = $this->title;
+?>
+
+
+
= Html::encode($this->title) ?>
+
+ = $this->render('_form', [
+ 'model' => $model,
+ ]) ?>
+
+
diff --git a/backend/views/log/index.php b/backend/views/log/index.php
new file mode 100644
index 0000000..ea39a3c
--- /dev/null
+++ b/backend/views/log/index.php
@@ -0,0 +1,60 @@
+title = Yii::t('common/log', 'Logok');
+$this->params['breadcrumbs'][] = $this->title;
+?>
+
+
+
= Html::encode($this->title) ?>
+ render('_search', ['model' => $searchModel]); ?>
+
+
+ = GridView::widget([
+ 'dataProvider' => $dataProvider,
+ 'columns' => [
+
+ [
+ 'attribute' => "log_id_log",
+ 'label' => "Log azonosító",
+ ],
+ [
+ 'attribute' => "log_created_at",
+ 'label' => "Dátum idő",
+ ],
+ [
+ 'attribute' => "log_message",
+ 'label' => "Üzenet",
+ ],
+ [
+ 'attribute' => "log_app",
+ 'label' => "Alkalmazás",
+ ],
+ [
+ 'attribute' => "user_username",
+ 'label' => "Felhasználó",
+ ],
+ // 'id_user',
+ // 'id_transfer',
+ // 'id_money_movement',
+ // 'id_ticket',
+ // 'id_sale',
+ // 'id_customer',
+ // 'id_account',
+ // 'id_account_state',
+ // 'id_key',
+ // 'id_product',
+ // 'id_door_log',
+ // 'updated_at',
+
+// ['class' => 'yii\grid\ActionColumn'],
+ ],
+ ]); ?>
+
+
diff --git a/backend/views/log/update.php b/backend/views/log/update.php
new file mode 100644
index 0000000..a8e499a
--- /dev/null
+++ b/backend/views/log/update.php
@@ -0,0 +1,23 @@
+title = Yii::t('common/log', 'Update {modelClass}: ', [
+ 'modelClass' => 'Log',
+]) . ' ' . $model->id_log;
+$this->params['breadcrumbs'][] = ['label' => Yii::t('common/log', 'Logs'), 'url' => ['index']];
+$this->params['breadcrumbs'][] = ['label' => $model->id_log, 'url' => ['view', 'id' => $model->id_log]];
+$this->params['breadcrumbs'][] = Yii::t('common/log', 'Update');
+?>
+
+
+
= Html::encode($this->title) ?>
+
+ = $this->render('_form', [
+ 'model' => $model,
+ ]) ?>
+
+
diff --git a/backend/views/log/view.php b/backend/views/log/view.php
new file mode 100644
index 0000000..967b04f
--- /dev/null
+++ b/backend/views/log/view.php
@@ -0,0 +1,52 @@
+title = $model->id_log;
+$this->params['breadcrumbs'][] = ['label' => Yii::t('common/log', 'Logs'), 'url' => ['index']];
+$this->params['breadcrumbs'][] = $this->title;
+?>
+
+
+
= Html::encode($this->title) ?>
+
+
+ = Html::a(Yii::t('common/log', 'Update'), ['update', 'id' => $model->id_log], ['class' => 'btn btn-primary']) ?>
+ = Html::a(Yii::t('common/log', 'Delete'), ['delete', 'id' => $model->id_log], [
+ 'class' => 'btn btn-danger',
+ 'data' => [
+ 'confirm' => Yii::t('common/log', 'Are you sure you want to delete this item?'),
+ 'method' => 'post',
+ ],
+ ]) ?>
+
+
+ = DetailView::widget([
+ 'model' => $model,
+ 'attributes' => [
+ 'id_log',
+ 'type',
+ 'message',
+ 'url:ntext',
+ 'app',
+ 'id_user',
+ 'id_transfer',
+ 'id_money_movement',
+ 'id_ticket',
+ 'id_sale',
+ 'id_customer',
+ 'id_account',
+ 'id_account_state',
+ 'id_key',
+ 'id_product',
+ 'id_door_log',
+ 'created_at',
+ 'updated_at',
+ ],
+ ]) ?>
+
+
diff --git a/changelog.txt b/changelog.txt
index 4353605..d318fb0 100644
--- a/changelog.txt
+++ b/changelog.txt
@@ -1,3 +1,7 @@
+-0.0.54
+ - add ticket usage count increment trigger
+ - add log
+ - fix card flag update query
-0.0.53
- inventory changes
- add id_ticket_current to card and ticket table
diff --git a/common/components/Helper.php b/common/components/Helper.php
index 47f669b..0e2abe8 100644
--- a/common/components/Helper.php
+++ b/common/components/Helper.php
@@ -363,7 +363,11 @@ class Helper {
public static function mkYiiSortItems($config){
$result = [];
foreach ($config as $col ){
- $result = $result + Helper::mkYiiSortItem($col[0] ,$col[1]);
+ if ( count($col) == 1){
+ $result = $result + Helper::mkYiiSortItem($col[0] ,$col[0]);
+ }else{
+ $result = $result + Helper::mkYiiSortItem($col[0] ,$col[1]);
+ }
}
return $result;
}
diff --git a/common/config/params.php b/common/config/params.php
index 1d7fbad..2d8fcb0 100644
--- a/common/config/params.php
+++ b/common/config/params.php
@@ -4,7 +4,7 @@ return [
'supportEmail' => 'rocho02@gmail.com',
'infoEmail' => 'info@rocho-net.hu',
'user.passwordResetTokenExpire' => 3600,
- 'version' => 'v0.0.53',
+ 'version' => 'v0.0.54',
'company' => 'movar',//gyor
'company_name' => "Freimann Kft.",
'product_visiblity' => 'account',// on reception which products to display. account or global
diff --git a/common/models/Log.php b/common/models/Log.php
index 7d922fd..aefa0c6 100644
--- a/common/models/Log.php
+++ b/common/models/Log.php
@@ -62,24 +62,26 @@ class Log extends BaseFitnessActiveRecord
public function attributeLabels()
{
return [
- 'id_log' => Yii::t('common/log', 'Id Log'),
- 'type' => Yii::t('common/log', 'Type'),
- 'message' => Yii::t('common/log', 'Message'),
+ 'id_log' => Yii::t('common/log', 'Azonosító'),
+ 'type' => Yii::t('common/log', 'Típus'),
+ 'message' => Yii::t('common/log', 'Üzenet'),
'url' => Yii::t('common/log', 'Url'),
- 'app' => Yii::t('common/log', 'App'),
- 'id_user' => Yii::t('common/log', 'Id User'),
- 'id_transfer' => Yii::t('common/log', 'Id Transfer'),
- 'id_money_movement' => Yii::t('common/log', 'Id Money Movement'),
- 'id_ticket' => Yii::t('common/log', 'Id Ticket'),
- 'id_sale' => Yii::t('common/log', 'Id Sale'),
- 'id_customer' => Yii::t('common/log', 'Id Customer'),
- 'id_account' => Yii::t('common/log', 'Id Account'),
+ 'app' => Yii::t('common/log', 'Alkalmazás'),
+ 'id_user' => Yii::t('common/log', 'Felhasználó'),
+ 'id_transfer' => Yii::t('common/log', 'Tranzakció'),
+ 'id_money_movement' => Yii::t('common/log', 'Pénzmozgás'),
+ 'id_ticket' => Yii::t('common/log', 'Bérlet'),
+ 'id_sale' => Yii::t('common/log', 'Termékeladás'),
+ 'id_customer' => Yii::t('common/log', 'Vendég'),
+ 'id_account' => Yii::t('common/log', 'Kassza'),
'id_account_state' => Yii::t('common/log', 'Id Account State'),
- 'id_key' => Yii::t('common/log', 'Id Key'),
- 'id_product' => Yii::t('common/log', 'Id Product'),
- 'id_door_log' => Yii::t('common/log', 'Id Door Log'),
- 'created_at' => Yii::t('common/log', 'Created At'),
- 'updated_at' => Yii::t('common/log', 'Updated At'),
+ 'id_key' => Yii::t('common/log', 'Kulcs'),
+ 'id_product' => Yii::t('common/log', 'Termék'),
+ 'id_door_log' => Yii::t('common/log', 'Kapu log'),
+ 'created_at' => Yii::t('common/log', 'Dátum idő'),
+ 'updated_at' => Yii::t('common/log', 'Módosítás'),
+ 'start' => 'Időszak kezdete',
+ 'end' => 'Időszak vége'
];
}
diff --git a/common/models/Ticket.php b/common/models/Ticket.php
index b368598..2da5f06 100644
--- a/common/models/Ticket.php
+++ b/common/models/Ticket.php
@@ -37,22 +37,31 @@ class Ticket extends \common\models\BaseFitnessActiveRecord
const STATUS_INACTIVE = 20;
public static $SQL_UPDATE = "UPDATE card as c1
- left JOIN ( select distinct ticket.id_card as id_card ,ticket.id_ticket as id_ticket from ticket
+ 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.usage_count < ticket.max_usage_count
- order by id_ticket desc limit 1 ) as t
+ and ticket.end >= curdate()
+ and ticket.status = 10
+ and ticket.usage_count < ticket.max_usage_count
+ group by id_card
+ order by id_card desc
+ ) as t
on t.id_card = c1.id_card
SET 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";
public static $SQL_UPDATE_CARD = "UPDATE card as c1
- left JOIN ( select distinct ticket.id_card as id_card ,ticket.id_ticket as id_ticket from ticket
+ 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.end >= curdate()
+ and ticket.status = 10
and ticket.usage_count < ticket.max_usage_count
- order by id_ticket desc limit 1 ) as t
+ and ticket.id_card = :id
+ group by id_card
+ order by id_card desc
+ ) as t
on t.id_card = c1.id_card
SET 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
diff --git a/console/migrations/m160318_201703_add__trigger__inc_ticket_usage_count.php b/console/migrations/m160318_201703_add__trigger__inc_ticket_usage_count.php
new file mode 100644
index 0000000..c8dc305
--- /dev/null
+++ b/console/migrations/m160318_201703_add__trigger__inc_ticket_usage_count.php
@@ -0,0 +1,125 @@
+execute("
+
+ DROP TRIGGER IF EXISTS trigger_inc_ticket_usage_count;
+ DELIMITER $$
+ CREATE TRIGGER trigger_inc_ticket_usage_count
+ AFTER INSERT ON `door_log` FOR EACH ROW
+ begin
+ /*DECLARE p_usage_count Integer;*/
+ 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;
+
+ -- delete from devlog;
+ /** van vendég*/
+ IF NEW.id_customer is not null
+ /*van kártya*/
+ and NEW.id_card is not null
+ /**van bérlet*/
+ and NEW.id_ticket_current is not null
+ /**bemozgás volt*/
+ and NEW.direction = 7
+ then
+ insert into devlog ( msg) values('conditions ok');
+ select count(*) into @p_count_all from door_log where created_at >= CURDATE() and id_ticket_current = New.id_ticket_current and direction = 7;
+
+ 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
+ /**
+ Innentől kezdve biztos, hogy nem ez az első belépés az aktuális napon.
+ Ki kell számolnunk hányadik 3 órás intervallumban vagyunk az első belépéstől számítva.
+ Pl. ha 06:00 kor volt az első belépés, akkor 07: 30 még nem von le újabb használatot,
+ de a 09:00 már igen
+ */
+
+ 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;
+
+
+ /**
+
+ */
+ -- select count(*) into @p_count_all_2 from door_log where created_at >= p_from and id_ticket_current ;
+ 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;
+
+ -- insert into devlog ( msg) values(CONCAT( 'ticket count since last period begin: ', @p_count_all_2) );
+ /**
+ Ha az első belépéstől számítot aktuális 3 órás intervallumban ez az elős belépés, akkor növeljük a használatot
+ */
+ IF @p_count_all_2 = 1
+ THEN
+ -- insert into devlog ( msg) values( 'need to increase usage count multiple intervals ' );
+ 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 @p_count_all_2 = 1
+
+ END IF;
+
+ /**
+ Van e érvényes bérlet státusz frissítése a bérletkártyán
+ update card.flag and card.id_ticket_current
+
+ */
+ -- insert into devlog ( msg) values( 'updateing card state' );
+ UPDATE card as c1
+ left JOIN ( select distinct ticket.id_card as id_card ,ticket.id_ticket as id_ticket from ticket
+ where ticket.start <= CURDATE()
+ and ticket.end >= curdate() and ticket.status = 10
+ and ticket.usage_count < ticket.max_usage_count
+ order by id_ticket desc limit 1 ) as t
+ on t.id_card = c1.id_card
+ SET 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;
+
+
+ END IF;
+
+ END;
+ $$
+ DELIMITER ;
+ ");
+ }
+
+ public function down()
+ {
+ echo "m160318_201703_add__trigger__inc_ticket_usage_count cannot be reverted.\n";
+
+ return false;
+ }
+
+ /*
+ // Use safeUp/safeDown to run migration code within a transaction
+ public function safeUp()
+ {
+ }
+
+ public function safeDown()
+ {
+ }
+ */
+}
diff --git a/console/migrations/m160319_180510_update_ticket_count.php b/console/migrations/m160319_180510_update_ticket_count.php
new file mode 100644
index 0000000..242162a
--- /dev/null
+++ b/console/migrations/m160319_180510_update_ticket_count.php
@@ -0,0 +1,32 @@
+execute("update ticket_type set max_usage_count = 10000;");
+
+ $this->execute( "update ticket set max_usage_count = 10000 , usage_count = 0" );
+ }
+
+ public function down()
+ {
+ echo "m160319_180510_update_ticket_count cannot be reverted.\n";
+
+ return false;
+ }
+
+ /*
+ // Use safeUp/safeDown to run migration code within a transaction
+ public function safeUp()
+ {
+ }
+
+ public function safeDown()
+ {
+ }
+ */
+}
diff --git a/console/migrations/m160320_094046_change_auto_inc_ticket_usage_trigger.php b/console/migrations/m160320_094046_change_auto_inc_ticket_usage_trigger.php
new file mode 100644
index 0000000..0c5de47
--- /dev/null
+++ b/console/migrations/m160320_094046_change_auto_inc_ticket_usage_trigger.php
@@ -0,0 +1,128 @@
+execute("
+ DROP TRIGGER IF EXISTS trigger_inc_ticket_usage_count;
+DELIMITER $$
+CREATE TRIGGER trigger_inc_ticket_usage_count
+AFTER INSERT ON `door_log` FOR EACH ROW
+begin
+ /*DECLARE p_usage_count Integer;*/
+ 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;
+
+ -- delete from devlog;
+ /** van vendég*/
+ IF NEW.id_customer is not null
+ /*van kártya*/
+ and NEW.id_card is not null
+ /**van bérlet*/
+ and NEW.id_ticket_current is not null
+ /**bemozgás volt*/
+ and NEW.direction = 7
+ then
+ insert into devlog ( msg) values('conditions ok');
+ select count(*) into @p_count_all from door_log where created_at >= CURDATE() and id_ticket_current = New.id_ticket_current and direction = 7;
+
+ 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
+ /**
+ Innentől kezdve biztos, hogy nem ez az első belépés az aktuális napon.
+ Ki kell számolnunk hányadik 3 órás intervallumban vagyunk az első belépéstől számítva.
+ Pl. ha 06:00 kor volt az első belépés, akkor 07: 30 még nem von le újabb használatot,
+ de a 09:00 már igen
+ */
+
+ 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;
+
+
+ /**
+
+ */
+ -- select count(*) into @p_count_all_2 from door_log where created_at >= p_from and id_ticket_current ;
+ 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;
+
+ -- insert into devlog ( msg) values(CONCAT( 'ticket count since last period begin: ', @p_count_all_2) );
+ /**
+ Ha az első belépéstől számítot aktuális 3 órás intervallumban ez az elős belépés, akkor növeljük a használatot
+ */
+ IF @p_count_all_2 = 1
+ THEN
+ -- insert into devlog ( msg) values( 'need to increase usage count multiple intervals ' );
+ 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 @p_count_all_2 = 1
+
+ END IF;
+
+ /**
+ Van e érvényes bérlet státusz frissítése a bérletkártyán
+ update card.flag and card.id_ticket_current
+
+ */
+ -- insert into devlog ( msg) values( 'updateing card state' );
+ 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.usage_count < 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.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;
+
+
+ END IF;
+
+END;
+$$
+DELIMITER ;
+ ");
+ }
+
+ public function down()
+ {
+ echo "m160320_094046_change_auto_inc_ticket_usage_trigger cannot be reverted.\n";
+
+ return false;
+ }
+
+ /*
+ // Use safeUp/safeDown to run migration code within a transaction
+ public function safeUp()
+ {
+ }
+
+ public function safeDown()
+ {
+ }
+ */
+}
diff --git a/frontend/models/CustomerUpdate.php b/frontend/models/CustomerUpdate.php
index 89214fa..32d6418 100644
--- a/frontend/models/CustomerUpdate.php
+++ b/frontend/models/CustomerUpdate.php
@@ -164,6 +164,9 @@ class CustomerUpdate extends \common\models\Customer
if ( isset($this->replacementCard)){
Ticket::updateAll( ['id_card' => $this->replacementCard->id_card ], ['id_card' => $this->originalCard->id_card] );
}
+ if ( !$insert ){
+ Card::updateCardFlagTicket($this->id_customer_card);
+ }
}