diff --git a/backend/components/AdminMenuStructure.php b/backend/components/AdminMenuStructure.php
index df3b8e2..cc46a7c 100644
--- a/backend/components/AdminMenuStructure.php
+++ b/backend/components/AdminMenuStructure.php
@@ -152,6 +152,18 @@ class AdminMenuStructure{
$this->menuItems[] = ['label' => 'Hírlevél', 'url' => $this->emptyUrl,
'items' => $items
];
+
+
+ /////////////////////////////
+ // Korona vírus
+ /////////////////////////////
+ $items = [];
+ $items[] = ['label' => 'Inaktiválás', 'url' => ['/customer/inactivate' ] ];
+ $items[] = ['label' => 'Aktiválás', 'url' => ['/customer/activate' ] ];
+ $this->menuItems[] = ['label' => 'Koronavírus', 'url' => $this->emptyUrl,
+ 'items' => $items
+ ];
+
/////////////////////////////
// Development
/////////////////////////////
diff --git a/backend/controllers/CustomerController.php b/backend/controllers/CustomerController.php
index 53d524a..5ad6930 100644
--- a/backend/controllers/CustomerController.php
+++ b/backend/controllers/CustomerController.php
@@ -2,10 +2,13 @@
namespace backend\controllers;
+use backend\models\CustomerActivateForm;
+use backend\models\CustomerInactivateForm;
use Yii;
use common\models\Customer;
use backend\models\CustomerSearch;
use backend\models\CustomerCreate;
+use yii\filters\AccessControl;
use yii\web\Controller;
use yii\web\NotFoundHttpException;
use yii\filters\VerbFilter;
@@ -27,21 +30,71 @@ class CustomerController extends \backend\controllers\BackendController
{
return [
'access' => [
- 'class' => \yii\filters\AccessControl::className(),
+ 'class' => AccessControl::className(),
'rules' => [
// allow authenticated users
[
- 'actions' => ['create','index','view','update','mail'],
+ 'actions' => ['create','index','view','update','mail' ],
'allow' => true,
'roles' => ['admin','employee','reception'],
+ ],// allow authenticated users
+ [
+ 'actions' => ['inactivate','activate'],
+ 'allow' => true,
+ 'roles' => ['admin','employee'],
],
// everything else is denied
],
],
];
}
-
-
+
+
+ /**
+ * Inactivate all card:
+ * set card.status to 20 and update card.flag
+ * @return string
+ */
+ public function actionInactivate(){
+
+ $form = new CustomerInactivateForm();
+
+ $form->loadActiveCardCount();
+
+ $form->inactivateDate = date('Y.m.d');
+
+
+ if ( $form->load(Yii::$app->request->post()) && $form->inactivate() ){
+ // redirect ?
+ }
+
+ return $this->render('inactivate', [
+ 'model' => $form
+ ]);
+ }
+
+ /**
+ * Activate all inactive cards.
+ * Set
+ * ticket.end
+ * card.status and card.flag
+ *
+ * @return string
+ */
+ public function actionActivate(){
+
+ $form = new CustomerActivateForm();
+
+ $form->loadActiveCardCount();
+ if ( Yii::$app->request->isPost && $form->activate()){
+ // redirect
+ }
+
+ return $this->render('activate', [
+ 'model' => $form
+ ]);
+ }
+
/**
* Lists all Customer models.
* @return mixed
diff --git a/backend/models/CustomerActivateForm.php b/backend/models/CustomerActivateForm.php
new file mode 100644
index 0000000..c888315
--- /dev/null
+++ b/backend/models/CustomerActivateForm.php
@@ -0,0 +1,61 @@
+inactiveCardCount = Card::find()->andWhere(
+ ['status' => Card::STATUS_INACTIVE]
+ )->count();
+ }
+
+ /**
+ * @return bool
+ * @throws \Exception
+ */
+ public function activate(){
+ if (!$this->validate()) {
+ return false;
+ }
+
+ $tx = \Yii::$app->db->beginTransaction();
+ assert(isset($tx));
+ try {
+ // update ticket end dates
+ Yii::$app->db->createCommand(Ticket::$SQL_UPDATE_TICKETS_END_DATE_ON_CARD_ACTIVATION)->execute();
+ // update card.status
+ Card::updateAll([ 'status' => Card::STATUS_ACTIVE, ], [ 'status' => Card::STATUS_INACTIVE ] );
+ // update card.flag
+ Card::updateFlagStatus();
+ // update ticket
+ \Yii::$app->db->createCommand(Ticket::$SQL_UPDATE)->execute();
+
+ $tx->commit();
+ } catch (\Exception $exception) {
+ $tx->rollBack();
+ throw $exception;
+ }
+ $this->message = $this->inactiveCardCount . " kártya aktiválva";
+ return true;
+ }
+
+}
diff --git a/backend/models/CustomerInactivateForm.php b/backend/models/CustomerInactivateForm.php
new file mode 100644
index 0000000..6fe6053
--- /dev/null
+++ b/backend/models/CustomerInactivateForm.php
@@ -0,0 +1,56 @@
+ 'timestampInactivate' ,'timestampAttributeFormat' => 'yyyy-MM-dd' ],
+
+ ];
+ }
+
+
+ public function loadActiveCardCount(){
+ $this->activeCardCount = Card::find()->andWhere(
+ ['status' => Card::STATUS_ACTIVE]
+ )->count();
+ }
+
+ public function inactivate(){
+ if ( !$this->validate()){
+ return false;
+ }
+ Card::updateAll(
+ [
+ 'status' => Card::STATUS_INACTIVE,
+ 'inactivated_at' => $this->timestampInactivate
+ ],
+ [
+ 'status' => Card::STATUS_ACTIVE
+ ]
+ );
+ Card::updateFlagStatus();
+ \Yii::$app->session->setFlash ( 'success', 'Kártyák inaktiválva' );
+ $this->message = $this->activeCardCount ." kártya inkatválva a köveztekző dátummal: " . $this->inactivateDate ;
+ return true;
+ }
+
+}
diff --git a/backend/views/customer/activate.php b/backend/views/customer/activate.php
new file mode 100644
index 0000000..e159246
--- /dev/null
+++ b/backend/views/customer/activate.php
@@ -0,0 +1,46 @@
+
+
+
Aktiválás
+
+
+message) ) {?>
+
+
+ = $model->message ?>
+
+
+
+
+
+
+
+
diff --git a/backend/views/customer/inactivate.php b/backend/views/customer/inactivate.php
new file mode 100644
index 0000000..bd04839
--- /dev/null
+++ b/backend/views/customer/inactivate.php
@@ -0,0 +1,57 @@
+
+
+Inaktiválás
+
+
+message) ) {?>
+
+
+ = $model->message ?>
+
+
+
+
+
+
+
+
diff --git a/common/models/Card.php b/common/models/Card.php
index 9484821..03c2ca9 100644
--- a/common/models/Card.php
+++ b/common/models/Card.php
@@ -20,13 +20,15 @@ use common\components\Helper;
* @property int flag_out
* @property \common\models\Customer $customer relation
* @property mixed validity
+ * @property string inactivated_at
*/
class Card extends \common\models\BaseFitnessActiveRecord
{
const STATUS_DELETED = 0;
const STATUS_ACTIVE = 10;
-
+ const STATUS_INACTIVE = 20;
+
const TYPE_RFID = 10;
const TYPE_QRCODE = 20;
const TYPE_BARCODE = 30;
@@ -75,6 +77,11 @@ class Card extends \common\models\BaseFitnessActiveRecord
}
+ public static $SQL_UPDATE_FLAG_STATUS_ACTIVE = '
+ update card set flag = CASE WHEN status = 20 then (flag | 1 << 3) else ( flag & ~(1 << 3 ) ) end
+';
+
+
/**
* @inheritdoc
*/
@@ -128,8 +135,9 @@ class Card extends \common\models\BaseFitnessActiveRecord
static function statuses() {
/** @noinspection PhpUndefinedClassInspection */
return [
- self::STATUS_ACTIVE => Yii::t('common/card', 'Active'),
- self::STATUS_DELETED => Yii::t('common/card', 'Inactive'),
+ self::STATUS_ACTIVE => 'Aktív',
+ self::STATUS_DELETED => 'Törölve',
+ self::STATUS_INACTIVE => 'Inaktív',
];
}
@@ -305,4 +313,8 @@ class Card extends \common\models\BaseFitnessActiveRecord
return Helper::isBitOn($this->flag,Card::$FLAG_DOOR_ALLOWED);
}
+ public static function updateFlagStatus(){
+ \Yii::$app->db->createCommand(self::$SQL_UPDATE_FLAG_STATUS_ACTIVE)->execute();
+ }
+
}
diff --git a/common/models/Ticket.php b/common/models/Ticket.php
index c655af8..3ea89c0 100644
--- a/common/models/Ticket.php
+++ b/common/models/Ticket.php
@@ -62,7 +62,8 @@ class Ticket extends \common\models\BaseFitnessActiveRecord
-- first bit is 0 when there is a ticket or 'employee' card 0000 0000
-- first bit is 1 when there is no ticket and card type is not 'employee'
, c1.flag = case when c1.type = 50 then ( c1.flag & ~(1 << 0) ) 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";
+ , c1.id_ticket_current = case when t.id_ticket is null then null else t.id_ticket end
+ where c1.status = 10";
public static $SQL_UPDATE_CARD = "UPDATE card as c1
left JOIN ( select ticket.id_card as id_card , max(ticket.id_ticket) as id_ticket
@@ -79,10 +80,18 @@ class Ticket extends \common\models\BaseFitnessActiveRecord
SET c1.validity = case when c1.type = 50 then ( c1.validity & ~(1 << 0) ) when t.id_card is null then ( c1.validity | 1 << 0 ) else ( c1.validity & ~(1 << 0) ) end
,c1.flag = case when c1.type = 50 then ( c1.flag & ~(1 << 0) ) 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.id_card = :id";
+ WHERE c1.status = 10 and c1.id_card = :id";
+ public static $SQL_UPDATE_TICKETS_END_DATE_ON_CARD_ACTIVATION = "UPDATE ticket t
+ inner join card c on t.id_card = c.id_card
+ SET end = date_add( end, INTERVAL datediff(current_date, c.inactivated_at) DAY )
+ where
+ c.status = 20
+ and c.inactivated_at is not null
+ and ((t.start <= c.inactivated_at and t.end >= c.inactivated_at) or (t.start >= c.inactivated_at)) ;";
+
public static function SQL_UPDATE_DOOR_ALLOWED_FLAG(){
return "
UPDATE card c
diff --git a/console/migrations/m200418_053358_add_active_fields.php b/console/migrations/m200418_053358_add_active_fields.php
new file mode 100644
index 0000000..c46797c
--- /dev/null
+++ b/console/migrations/m200418_053358_add_active_fields.php
@@ -0,0 +1,43 @@
+addColumn('card', 'inactivated_at',$this->date() );
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function safeDown()
+ {
+ echo "m200418_053358_add_active_fields cannot be reverted.\n";
+
+ return false;
+ }
+
+ /*
+ // Use up()/down() to run migration code without a transaction.
+ public function up()
+ {
+
+ }
+
+ public function down()
+ {
+ echo "m200418_053358_add_active_fields cannot be reverted.\n";
+
+ return false;
+ }
+ */
+}
diff --git a/frontend/controllers/CustomerController.php b/frontend/controllers/CustomerController.php
index 8605438..89f5663 100644
--- a/frontend/controllers/CustomerController.php
+++ b/frontend/controllers/CustomerController.php
@@ -2,6 +2,8 @@
namespace frontend\controllers;
+use backend\models\CustomerActivateForm;
+use frontend\models\SingleCustomerActivateForm;
use frontend\models\TowelForm;
use Yii;
use common\models\Customer;
@@ -35,7 +37,7 @@ class CustomerController extends Controller
],
'access' => [
'class' => \yii\filters\AccessControl::className(),
- 'only' => ['create', 'update','reception','contract','towel'],
+ 'only' => ['create', 'update','reception','contract','towel','activate'],
'rules' => [
// allow authenticated users
[
@@ -49,6 +51,23 @@ class CustomerController extends Controller
];
}
+ public function actionActivate($number = "")
+ {
+ $model = new ReceptionForm();
+ $model->number = $number;
+ $model->readCard();
+
+ $form = new SingleCustomerActivateForm( );
+ $form->number = $number;
+ $form->validate();
+ $ticketsDataProvider = $form->loadTicketsDataProvider();
+
+ if (\Yii::$app->request->isPost && $form->activate()) {
+ return $this->redirect(['customer/activate', 'number' => $number]);
+ }
+ return $this->render('activate', ['model' => $model, 'formModel' => $form, 'ticketsDataProvider' => $ticketsDataProvider]);
+ }
+
public function actionReception($number = ""){
$model = new ReceptionForm();
diff --git a/frontend/models/SingleCustomerActivateForm.php b/frontend/models/SingleCustomerActivateForm.php
new file mode 100644
index 0000000..0b623f2
--- /dev/null
+++ b/frontend/models/SingleCustomerActivateForm.php
@@ -0,0 +1,138 @@
+card = Card::readCard($this->number);
+
+ $query = new Query();
+
+ $this->daysPassed = $query
+ ->select(
+ [
+ 'datediff(current_date, card.inactivated_at ) '
+ ]
+ )
+ ->from(Card::tableName())
+ ->andWhere(['id_card' => $this->card->id_card])
+ ->scalar();
+
+ $query = new Query();
+ $this->tickets = $query
+ ->select(
+ [
+ 'ticket.id_ticket as id_ticket',
+ 'ticket.start as start',
+ 'ticket.end as end',
+ 'ticket.created_at as created_at',
+ 'ticket.usage_count as usage_count',
+ 'ticket.max_usage_count as max_usage_count',
+ 'date_add( ticket.end, INTERVAL datediff(current_date, card.inactivated_at) DAY ) as end2'
+ ]
+ )
+ ->from(Ticket::tableName())
+ ->innerJoin(Card::tableName(), 'card.id_card = ticket.id_card')
+ ->andWhere(['ticket.id_card' => $this->card->id_card])
+ ->andWhere(
+ ['or',
+ ['and',
+ ['<=','ticket.start',$this->card->inactivated_at ],
+ ['>=','ticket.end',$this->card->inactivated_at ]
+ ],
+ ['>=','ticket.start',$this->card->inactivated_at ],
+ ]
+ )
+ ->orderBy(
+ [
+ 'ticket.start' => SORT_DESC
+ ]
+ )
+ ->all();
+
+ }
+
+ public function loadTicketsDataProvider()
+ {
+ $this->loadTicketsToActivate();
+ return new ArrayDataProvider(
+ [
+ 'allModels' => $this->tickets,
+ 'sort' => false,
+ 'pagination' => false
+ ]
+ );
+ }
+
+ /**
+ * @return bool
+ * @throws Exception
+ */
+ public function activate()
+ {
+ if (!$this->validate()) {
+ return false;
+ }
+
+ $tx = Yii::$app->db->beginTransaction();
+ assert(isset($tx));
+ try {
+
+ Yii::$app->db->createCommand(Ticket::$SQL_UPDATE_TICKETS_END_DATE_ON_CARD_ACTIVATION
+ . " AND id_card = '" . $this->card->id_card . "'")->execute();
+ Card::updateAll(
+ [
+ 'status' => Card::STATUS_ACTIVE,
+ ],
+ [
+ 'status' => Card::STATUS_INACTIVE,
+ 'id_card' => $this->card->id_card
+ ]
+ );
+ Card::updateFlagStatus();
+
+ Card::updateCardFlagTicket( $this->card->id_card);
+
+ $tx->commit();
+ } catch (Exception $exception) {
+ $tx->rollBack();
+ throw $exception;
+ }
+ Yii::$app->session->setFlash('success', 'Kártya aktiválva');
+ return true;
+ }
+
+}
diff --git a/frontend/views/common/_reception_ticket.php b/frontend/views/common/_reception_ticket.php
index ce53b97..b6f260e 100644
--- a/frontend/views/common/_reception_ticket.php
+++ b/frontend/views/common/_reception_ticket.php
@@ -17,6 +17,17 @@ if (count($model->tickets) > 0) {
$ticket = $model->tickets[0];
}
+if ( isset($model,$model->card)){
+ if ( $model->card->status == \common\models\Card::STATUS_INACTIVE ){
+ echo Html::beginTag("div", ['class' => "alert alert-danger", "role" => "alert"]);
+ echo Html::beginTag("strong", []);
+ echo "A vendég inaktív!";
+ echo Html::a("Aktiválás", ["customer/activate",'number' => $model->card->number ]);
+ echo Html::endTag("strong");
+ echo Html::endTag("div");
+ }
+}
+
if (isset($model->card)) {
if (isset($model->customer)) {
if ($model->card->validity == 0) {
diff --git a/frontend/views/customer/activate.php b/frontend/views/customer/activate.php
new file mode 100644
index 0000000..90b5e32
--- /dev/null
+++ b/frontend/views/customer/activate.php
@@ -0,0 +1,101 @@
+Recepció
+
+ $model, 'route' => ['customer/reception']]) ?>
+Aktiválás
+
+
+card->status == Card::STATUS_INACTIVE) { ?>
+
+
+
+
+