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/controllers/SiteController.php b/backend/controllers/SiteController.php index b0aadb1..162051e 100644 --- a/backend/controllers/SiteController.php +++ b/backend/controllers/SiteController.php @@ -9,6 +9,7 @@ use yii\filters\VerbFilter; use backend\models\UploadForm; use common\components\Helper; use common\models\User; +use common\models\Log; /** * Site controller @@ -74,6 +75,16 @@ class SiteController extends Controller ]; if ($model->load(Yii::$app->request->post()) && $model->login()) { + $geoip = Helper::getGeoIp(); + + $user = User::findOne(\Yii::$app->user->id); + $message = "Bejelentkezés: " .$user->username. " Ip cím:". $geoip->ip . " Város: " . $geoip->city; + + Log::log([ + 'type' =>Log::$TYPE_LOGIN, + 'message' => $message + ]); + $this->sendLoginMail(); return $this->goBack(); diff --git a/backend/models/GiroKotegForm.php b/backend/models/GiroKotegForm.php index 4a2745c..0e103e6 100644 --- a/backend/models/GiroKotegForm.php +++ b/backend/models/GiroKotegForm.php @@ -142,11 +142,7 @@ class GiroKotegForm extends Model{ public static function transliterate($string) { -// if (static::hasIntl()) { -// return transliterator_transliterate(BaseInflector::$transliterator, $string); -// } else { return str_replace(array_keys(BaseInflector::$transliteration), BaseInflector::$transliteration, $string); -// } } /** 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 @@ + + +
+ + + + field($model, 'id_log')->textInput() ?> + + field($model, 'type')->textInput() ?> + + field($model, 'message')->textInput(['maxlength' => true]) ?> + + field($model, 'url')->textarea(['rows' => 6]) ?> + + field($model, 'app')->textInput(['maxlength' => true]) ?> + + field($model, 'id_user')->textInput() ?> + + field($model, 'id_transfer')->textInput() ?> + + field($model, 'id_money_movement')->textInput() ?> + + field($model, 'id_ticket')->textInput() ?> + + field($model, 'id_sale')->textInput() ?> + + field($model, 'id_customer')->textInput() ?> + + field($model, 'id_account')->textInput() ?> + + field($model, 'id_account_state')->textInput() ?> + + field($model, 'id_key')->textInput() ?> + + field($model, 'id_product')->textInput() ?> + + field($model, 'id_door_log')->textInput() ?> + + field($model, 'created_at')->textInput() ?> + + field($model, 'updated_at')->textInput() ?> + +
+ isNewRecord ? Yii::t('common/log', 'Create') : Yii::t('common/log', 'Update'), ['class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary']) ?> +
+ + + +
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 @@ + + + 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; +?> +
+ +

title) ?>

+ + 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; +?> +
+ +

title) ?>

+ render('_search', ['model' => $searchModel]); ?> + + + $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'); +?> +
+ +

title) ?>

+ + 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; +?> +
+ +

title) ?>

+ +

+ $model->id_log], ['class' => 'btn btn-primary']) ?> + $model->id_log], [ + 'class' => 'btn btn-danger', + 'data' => [ + 'confirm' => Yii::t('common/log', 'Are you sure you want to delete this item?'), + 'method' => 'post', + ], + ]) ?> +

+ + $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/components/giro/GiroBase.php b/common/components/giro/GiroBase.php index 60971c0..0e38a06 100644 --- a/common/components/giro/GiroBase.php +++ b/common/components/giro/GiroBase.php @@ -24,7 +24,7 @@ class GiroBase { $data = substr($data, 0, $hossz ); } $data = str_pad($data, $hossz, $pad_string, STR_PAD_RIGHT); - echo $data; + //echo $data; // echo strlen($data); return $data; } diff --git a/common/components/giro/GiroBeszed.php b/common/components/giro/GiroBeszed.php index a3e6681..bea78ad 100644 --- a/common/components/giro/GiroBeszed.php +++ b/common/components/giro/GiroBeszed.php @@ -71,7 +71,7 @@ class GiroBeszed extends GiroBase { $tetel->szamlaTulajdonosNeve = $customer->name; $tetel->kozlemeny = "Fitness berlet. Megbizas azon: " . $request->id_ticket_installment_request; - return $tetel->toString(); + return $tetel->toString(); } public static function createLab($requests) { diff --git a/common/components/giro/GiroBeszedTetel.php b/common/components/giro/GiroBeszedTetel.php index 002bee3..aab3250 100644 --- a/common/components/giro/GiroBeszedTetel.php +++ b/common/components/giro/GiroBeszedTetel.php @@ -2,6 +2,7 @@ namespace common\components\giro; use common\components\giro\GiroBase; +use yii\helpers\VarDumper; /** * @property common\components\giro\GiroUzenetsorszam $uzenetSorszam * @property common\components\giro\GiroBankszamla $kotelezettBankszamla 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/Customer.php b/common/models/Customer.php index ba2d763..c029d65 100644 --- a/common/models/Customer.php +++ b/common/models/Customer.php @@ -3,6 +3,7 @@ namespace common\models; use Yii; +use common\models\BaseFitnessActiveRecord; /** * This is the model class for table "customer". @@ -29,7 +30,7 @@ use Yii; * @property string $created_at * @property string $updated_at */ -class Customer extends \yii\db\ActiveRecord +class Customer extends BaseFitnessActiveRecord { const STATUS_DELETED = 0; @@ -49,6 +50,7 @@ class Customer extends \yii\db\ActiveRecord { return 'customer'; } + /** * @inheritdoc @@ -184,6 +186,12 @@ class Customer extends \yii\db\ActiveRecord } + public function afterSave($insert, $changedAttributes){ + if ( !$insert ){ + Card::updateCardFlagTicket($this->id_customer_card); + } + } + } diff --git a/common/models/DoorLog.php b/common/models/DoorLog.php index 1c334b2..52a0e6a 100644 --- a/common/models/DoorLog.php +++ b/common/models/DoorLog.php @@ -138,6 +138,9 @@ class DoorLog extends \yii\db\ActiveRecord 17 => "Bérlet érvényességi időn kívüli KI olvastatás (nem enged)", 19 => "Bérlet érvényességi időn kívüli BE olvastatás (nem enged)", + + 128 => "Vésznyitás", + 256 => "Kártya tiltva -> információ mező", ]; } diff --git a/common/models/Log.php b/common/models/Log.php new file mode 100644 index 0000000..aefa0c6 --- /dev/null +++ b/common/models/Log.php @@ -0,0 +1,101 @@ + 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', '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', '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' + ]; + } + + + public static function info($message ){ + self::log(['type' =>self::$TYPE_INFO, 'message' => $message]); + } + public static function log( $config ){ + \Yii::info( "Log :" . VarDumper::dump( $config) ) ; + $model = new Log($config); + $model->app = \Yii::$app->name; + $model->url = Url::canonical(); + $model->id_user = \Yii::$app->user->id; + $model->save(); + } + +} diff --git a/common/models/Ticket.php b/common/models/Ticket.php index f3c4cc0..2da5f06 100644 --- a/common/models/Ticket.php +++ b/common/models/Ticket.php @@ -37,18 +37,35 @@ 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 from ticket - where ticket.start <= CURDATE() and ticket.end >= curdate() and ticket.status = 10 ) 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 - WHERE c1.type <> 50"; + 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 + 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 from ticket - where ticket.start <= CURDATE() and ticket.end >= curdate() and ticket.status = 10 ) 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 - WHERE c1.type <> 50 and c1.id_card = :id"; + 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 = :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 + WHERE c1.type <> 50 and c1.id_card = :id"; /** diff --git a/console/migrations/m160316_063618_create__table__log.php b/console/migrations/m160316_063618_create__table__log.php new file mode 100644 index 0000000..3c0f159 --- /dev/null +++ b/console/migrations/m160316_063618_create__table__log.php @@ -0,0 +1,75 @@ +db->driverName === 'mysql') { + // http://stackoverflow.com/questions/766809/whats-the-difference-between-utf8-general-ci-and-utf8-unicode-ci + $tableOptions = 'CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE=InnoDB'; + } + + $this->createTable( '{{%log}}', [ + 'id_log' => $this->primaryKey(), + 'type' => $this->integer(11), + 'message' => $this->string(), + 'url' => $this->text(), + 'app' => $this->string(50), + 'id_user' => $this->integer(11), + 'id_transfer' => $this->integer(11), + 'id_money_movement' => $this->integer(11), + 'id_ticket' => $this->integer(11), + 'id_sale' => $this->integer(11), + 'id_customer' => $this->integer(11), + 'id_account' => $this->integer(11), + 'id_account_state' => $this->integer(11), + 'id_key' => $this->integer(11), + 'id_product' => $this->integer(11), + 'id_door_log' => $this->integer(11), + 'created_at' => $this->dateTime()->notNull(), + 'updated_at' => $this->dateTime()->notNull(), + ], $tableOptions ); + + } + + public function down() + { + $this->dropTable("{{%log}}"); + } + + /* + // Use safeUp/safeDown to run migration code within a transaction + public function safeUp() + { + } + + public function safeDown() + { + } + */ +} 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/controllers/AccountController.php b/frontend/controllers/AccountController.php index f1d44e9..6850191 100644 --- a/frontend/controllers/AccountController.php +++ b/frontend/controllers/AccountController.php @@ -10,6 +10,8 @@ use yii\web\Controller; use yii\web\NotFoundHttpException; use yii\filters\VerbFilter; use yii\base\Object; +use common\models\Log; +use common\models\User; /** * AccountController implements the CRUD actions for Account model. @@ -43,6 +45,12 @@ class AccountController extends Controller if ($model->load(Yii::$app->request->post()) && $model->writeToSession()) { Yii::$app->session->setFlash('success', Yii::t('frontend/ticket', 'Default account is set!') ); + + $user = User::findOne(\Yii::$app->user->id); + Log::log([ 'type' => Log::$TYPE_DEFAULT_ACCOUNT, + 'message' => "Alapértelmezett kassza - Felhasználó: " . $user->username . " - Kassza: " . Account::readDefaultObject()->name, + 'id_account' => Account::readDefault(), + ]); return $this->redirect(['product/sale']); } return $this->render('select', [ diff --git a/frontend/controllers/CustomerController.php b/frontend/controllers/CustomerController.php index db1c268..0d327a0 100644 --- a/frontend/controllers/CustomerController.php +++ b/frontend/controllers/CustomerController.php @@ -16,6 +16,7 @@ use frontend\models\CustomerCreate; use common\models\Image; use frontend\models\ContractForm; use yii\base\Exception; +use common\models\Log; /** * CustomerController implements the CRUD actions for Customer model. @@ -127,6 +128,13 @@ class CustomerController extends Controller if ($model->load(Yii::$app->request->post()) && $model->save()) { $this->saveBinaryImage($model); \Yii::$app->session->setFlash( 'success','Vendég létrehozva!' ); + + Log::log([ + 'type' =>Log::$TYPE_CREATE_CUSTOMER, + 'message' => 'Új vendég:' .$model->name, + 'id_customer' => $model->id_customer + ]); + return $this->redirect(['update', 'number' => $model->cardNumber]); } else { return $this->render('create', [ diff --git a/frontend/controllers/SiteController.php b/frontend/controllers/SiteController.php index 10b124a..6247449 100644 --- a/frontend/controllers/SiteController.php +++ b/frontend/controllers/SiteController.php @@ -14,6 +14,7 @@ use yii\filters\VerbFilter; use yii\filters\AccessControl; use common\models\User; use common\components\Helper; +use common\models\Log; /** * Site controller @@ -90,6 +91,17 @@ class SiteController extends Controller $model = new LoginForm(); if ($model->load(Yii::$app->request->post()) && $model->login()) { + + $geoip = Helper::getGeoIp(); + + $user = User::findOne(\Yii::$app->user->id); + $message = "Bejelentkezés: " .$user->username. " Ip cím:". $geoip->ip . " Város: " . $geoip->city; + + Log::log([ + 'type' =>Log::$TYPE_LOGIN, + 'message' => $message + ]); + $this->sendLoginIp(); // return $this->goBack(); diff --git a/frontend/models/ContractForm.php b/frontend/models/ContractForm.php index 156cf8c..791ac06 100644 --- a/frontend/models/ContractForm.php +++ b/frontend/models/ContractForm.php @@ -90,6 +90,12 @@ class ContractForm extends Model { 'string', 'max' => 24 ], + [ + [ + 'bank_account' + ], + 'validateBankAccount', + ], [ [ 'bank_name' @@ -132,6 +138,18 @@ class ContractForm extends Model { [[ 'started_at', ], 'date', 'format' =>Yii::$app->formatter->dateFormat , 'timestampAttribute' => 'timestampStart' ,'timestampAttributeFormat' => 'yyyy-MM-dd' ,'timeZone' => 'UTC' ], ]; } + + public function validateBankAccount($attribute, $params) { + if ( !is_numeric($this->bank_account)){ + $this->addError( $attribute, "A bankszámlaszám csak számokat tartalmazhat!"); + }else{ + if ( !( strlen($this->bank_account) == 16 || strlen($this->bank_account) == 24 ) ){ + $this->addError($attribute,"Bankszámlaszám 16 vagy 24 hosszú!"); + } + } + } + + public function validateTicketType($attribute, $params) { $this->ticketType = TicketType::findOne ( $this->ticket_type ); if (! isset ( $this->ticketType )) { 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); + } } diff --git a/frontend/views/contract/_make_contract.php b/frontend/views/contract/_make_contract.php index c157be7..0d45fba 100644 --- a/frontend/views/contract/_make_contract.php +++ b/frontend/views/contract/_make_contract.php @@ -9,6 +9,7 @@ use kartik\widgets\DatePicker; use common\models\Transfer; use common\models\Discount; use frontend\assets\ContractMakeAsset; +use yii\helpers\VarDumper; /* @var $this yii\web\View */ /* @var $model common\models\Contract */ @@ -38,6 +39,7 @@ use frontend\assets\ContractMakeAsset; $this->registerJs(' contract_make.init( '. json_encode($options) .' );'); + ?>

Szerződés létrehozása