add coronavirus activate/inactivate

This commit is contained in:
2020-04-20 09:10:18 +02:00
parent e7e4183221
commit 5d847e2538
13 changed files with 628 additions and 10 deletions

View File

@@ -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
/////////////////////////////

View File

@@ -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

View File

@@ -0,0 +1,65 @@
<?php
namespace backend\models;
use common\models\Card;
use common\models\Ticket;
use Yii;
use yii\base\Model;
class CustomerActivateForm extends Model{
public $inactiveCardCount;
public $message ;
public function rules()
{
return [
];
}
public function loadActiveCardCount(){
$this->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{
Yii::$app->db->createCommand(Ticket::$SQL_UPDATE_TICKETS_END_DATE_ON_CARD_ACTIVATION )->execute();
Card::updateAll(
[
'status' => Card::STATUS_ACTIVE,
'end' => 'date_add( end, INTERVAL datediff(current_date, c.inactivated_at) DAY )'
],
[
'status' => Card::STATUS_INACTIVE
]
);
Card::updateFlagStatus();
$tx->commit();
}catch (\Exception $exception){
$tx->rollBack();
throw $exception;
}
$this->message = $this->inactiveCardCount ." kártya aktiválva" ;
return true;
}
}

View File

@@ -0,0 +1,56 @@
<?php
namespace backend\models;
use common\models\Card;
use yii\base\Model;
class CustomerInactivateForm extends Model{
public $inactivateDate;
public $timestampInactivate;
public $activeCardCount;
public $message ;
public function rules()
{
return [
[[ 'inactivateDate' ], 'required'],
[[ 'inactivateDate', ], 'date' , 'timestampAttribute' => '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;
}
}

View File

@@ -0,0 +1,46 @@
<?php
use backend\models\CustomerActivateForm;
use yii\widgets\ActiveForm;
use yii\helpers\Html;
/* @var $this yii\web\View */
/* @var $model CustomerActivateForm */
?>
<h1>Aktiválás</h1>
<?php if ( isset($model, $model->message) ) {?>
<div class="alert alert-success" role="alert">
<p>
<?= $model->message ?>
</p>
</div>
<?php }else { ?>
<div class="customer-form">
<?php $form = ActiveForm::begin(); ?>
<div class="form-group">
<p>
<?= $model->inactiveCardCount ?> kártya aktiválása
</p>
<div class="row">
<div class="col-md-3">
<?= Html::submitButton('Aktiválás',['class' => 'btn btn-success']) ?>
</div>
</div>
</div>
<?php ActiveForm::end(); ?>
</div>
<?php }?>

View File

@@ -0,0 +1,57 @@
<?php
use backend\models\CustomerInactivateForm;
use yii\widgets\ActiveForm;
use yii\helpers\Html;
/* @var $this yii\web\View */
/* @var $model CustomerInactivateForm */
?>
<h1>Inaktiválás</h1>
<?php if ( isset($model, $model->message) ) {?>
<div class="alert alert-success" role="alert">
<p>
<?= $model->message ?>
</p>
</div>
<?php }else { ?>
<div class="customer-form">
<?php $form = ActiveForm::begin(); ?>
<div class="form-group">
<p>
<?= $model->activeCardCount ?> kártya inaktiválása
</p>
<div class="row">
<div class="col-md-3">
<?= $form->field($model, 'inactivateDate') ->widget(\kartik\widgets\DatePicker::classname(), [
'pluginOptions' => [
'autoclose'=>true,
'format' => 'yyyy.mm.dd'
]
])->label("Inaktiválási dátum") ?>
</div>
</div>
<div class="row">
<div class="col-md-3">
<?= Html::submitButton('Inaktiválás',['class' => 'btn btn-danger']) ?>
</div>
</div>
</div>
<?php ActiveForm::end(); ?>
</div>
<?php }?>