add coronavirus activate/inactivate
This commit is contained in:
parent
e7e4183221
commit
5d847e2538
@ -152,6 +152,18 @@ class AdminMenuStructure{
|
|||||||
$this->menuItems[] = ['label' => 'Hírlevél', 'url' => $this->emptyUrl,
|
$this->menuItems[] = ['label' => 'Hírlevél', 'url' => $this->emptyUrl,
|
||||||
'items' => $items
|
'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
|
// Development
|
||||||
/////////////////////////////
|
/////////////////////////////
|
||||||
|
|||||||
@ -2,10 +2,13 @@
|
|||||||
|
|
||||||
namespace backend\controllers;
|
namespace backend\controllers;
|
||||||
|
|
||||||
|
use backend\models\CustomerActivateForm;
|
||||||
|
use backend\models\CustomerInactivateForm;
|
||||||
use Yii;
|
use Yii;
|
||||||
use common\models\Customer;
|
use common\models\Customer;
|
||||||
use backend\models\CustomerSearch;
|
use backend\models\CustomerSearch;
|
||||||
use backend\models\CustomerCreate;
|
use backend\models\CustomerCreate;
|
||||||
|
use yii\filters\AccessControl;
|
||||||
use yii\web\Controller;
|
use yii\web\Controller;
|
||||||
use yii\web\NotFoundHttpException;
|
use yii\web\NotFoundHttpException;
|
||||||
use yii\filters\VerbFilter;
|
use yii\filters\VerbFilter;
|
||||||
@ -27,13 +30,18 @@ class CustomerController extends \backend\controllers\BackendController
|
|||||||
{
|
{
|
||||||
return [
|
return [
|
||||||
'access' => [
|
'access' => [
|
||||||
'class' => \yii\filters\AccessControl::className(),
|
'class' => AccessControl::className(),
|
||||||
'rules' => [
|
'rules' => [
|
||||||
// allow authenticated users
|
// allow authenticated users
|
||||||
[
|
[
|
||||||
'actions' => ['create','index','view','update','mail' ],
|
'actions' => ['create','index','view','update','mail' ],
|
||||||
'allow' => true,
|
'allow' => true,
|
||||||
'roles' => ['admin','employee','reception'],
|
'roles' => ['admin','employee','reception'],
|
||||||
|
],// allow authenticated users
|
||||||
|
[
|
||||||
|
'actions' => ['inactivate','activate'],
|
||||||
|
'allow' => true,
|
||||||
|
'roles' => ['admin','employee'],
|
||||||
],
|
],
|
||||||
// everything else is denied
|
// everything else is denied
|
||||||
],
|
],
|
||||||
@ -42,6 +50,51 @@ class CustomerController extends \backend\controllers\BackendController
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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.
|
* Lists all Customer models.
|
||||||
* @return mixed
|
* @return mixed
|
||||||
|
|||||||
65
backend/models/CustomerActivateForm.php
Normal file
65
backend/models/CustomerActivateForm.php
Normal 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;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
56
backend/models/CustomerInactivateForm.php
Normal file
56
backend/models/CustomerInactivateForm.php
Normal 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;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
46
backend/views/customer/activate.php
Normal file
46
backend/views/customer/activate.php
Normal 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 }?>
|
||||||
|
|
||||||
|
|
||||||
57
backend/views/customer/inactivate.php
Normal file
57
backend/views/customer/inactivate.php
Normal 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 }?>
|
||||||
|
|
||||||
|
|
||||||
@ -20,12 +20,14 @@ use common\components\Helper;
|
|||||||
* @property int flag_out
|
* @property int flag_out
|
||||||
* @property \common\models\Customer $customer relation
|
* @property \common\models\Customer $customer relation
|
||||||
* @property mixed validity
|
* @property mixed validity
|
||||||
|
* @property string inactivated_at
|
||||||
*/
|
*/
|
||||||
class Card extends \common\models\BaseFitnessActiveRecord
|
class Card extends \common\models\BaseFitnessActiveRecord
|
||||||
{
|
{
|
||||||
|
|
||||||
const STATUS_DELETED = 0;
|
const STATUS_DELETED = 0;
|
||||||
const STATUS_ACTIVE = 10;
|
const STATUS_ACTIVE = 10;
|
||||||
|
const STATUS_INACTIVE = 20;
|
||||||
|
|
||||||
const TYPE_RFID = 10;
|
const TYPE_RFID = 10;
|
||||||
const TYPE_QRCODE = 20;
|
const TYPE_QRCODE = 20;
|
||||||
@ -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
|
* @inheritdoc
|
||||||
*/
|
*/
|
||||||
@ -128,8 +135,9 @@ class Card extends \common\models\BaseFitnessActiveRecord
|
|||||||
static function statuses() {
|
static function statuses() {
|
||||||
/** @noinspection PhpUndefinedClassInspection */
|
/** @noinspection PhpUndefinedClassInspection */
|
||||||
return [
|
return [
|
||||||
self::STATUS_ACTIVE => Yii::t('common/card', 'Active'),
|
self::STATUS_ACTIVE => 'Aktív',
|
||||||
self::STATUS_DELETED => Yii::t('common/card', 'Inactive'),
|
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);
|
return Helper::isBitOn($this->flag,Card::$FLAG_DOOR_ALLOWED);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static function updateFlagStatus(){
|
||||||
|
\Yii::$app->db->createCommand(self::$SQL_UPDATE_FLAG_STATUS_ACTIVE)->execute();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -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 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'
|
-- 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.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
|
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
|
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
|
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.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.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(){
|
public static function SQL_UPDATE_DOOR_ALLOWED_FLAG(){
|
||||||
return "
|
return "
|
||||||
UPDATE card c
|
UPDATE card c
|
||||||
|
|||||||
43
console/migrations/m200418_053358_add_active_fields.php
Normal file
43
console/migrations/m200418_053358_add_active_fields.php
Normal file
@ -0,0 +1,43 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
use yii\db\Migration;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Class m200418_053358_add_active_fields
|
||||||
|
*/
|
||||||
|
class m200418_053358_add_active_fields extends Migration
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* {@inheritdoc}
|
||||||
|
*/
|
||||||
|
public function safeUp()
|
||||||
|
{
|
||||||
|
// add
|
||||||
|
$this->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;
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
}
|
||||||
@ -2,6 +2,8 @@
|
|||||||
|
|
||||||
namespace frontend\controllers;
|
namespace frontend\controllers;
|
||||||
|
|
||||||
|
use backend\models\CustomerActivateForm;
|
||||||
|
use frontend\models\SingleCustomerActivateForm;
|
||||||
use frontend\models\TowelForm;
|
use frontend\models\TowelForm;
|
||||||
use Yii;
|
use Yii;
|
||||||
use common\models\Customer;
|
use common\models\Customer;
|
||||||
@ -35,7 +37,7 @@ class CustomerController extends Controller
|
|||||||
],
|
],
|
||||||
'access' => [
|
'access' => [
|
||||||
'class' => \yii\filters\AccessControl::className(),
|
'class' => \yii\filters\AccessControl::className(),
|
||||||
'only' => ['create', 'update','reception','contract','towel'],
|
'only' => ['create', 'update','reception','contract','towel','activate'],
|
||||||
'rules' => [
|
'rules' => [
|
||||||
// allow authenticated users
|
// 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 = ""){
|
public function actionReception($number = ""){
|
||||||
$model = new ReceptionForm();
|
$model = new ReceptionForm();
|
||||||
|
|
||||||
|
|||||||
134
frontend/models/SingleCustomerActivateForm.php
Normal file
134
frontend/models/SingleCustomerActivateForm.php
Normal file
@ -0,0 +1,134 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
|
||||||
|
namespace frontend\models;
|
||||||
|
|
||||||
|
|
||||||
|
use common\models\Card;
|
||||||
|
use common\models\Ticket;
|
||||||
|
use Yii;
|
||||||
|
use yii\base\Model;
|
||||||
|
use yii\data\ArrayDataProvider;
|
||||||
|
use yii\db\Query;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Class SingleCustomerActivateForm
|
||||||
|
* @package backend\models
|
||||||
|
*
|
||||||
|
* @property Card $card
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
class SingleCustomerActivateForm extends Model{
|
||||||
|
|
||||||
|
public $message ;
|
||||||
|
public $number ;
|
||||||
|
public $card;
|
||||||
|
public $tickets;
|
||||||
|
public $daysPassed;
|
||||||
|
|
||||||
|
|
||||||
|
public function rules()
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
[['number'], 'required'],
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public function loadTicketsToActivate(){
|
||||||
|
$this->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();
|
||||||
|
$tx->commit();
|
||||||
|
} catch (\Exception $exception) {
|
||||||
|
$tx->rollBack();
|
||||||
|
throw $exception;
|
||||||
|
}
|
||||||
|
Yii::$app->session->setFlash('success', 'Kártya aktiválva');
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@ -17,6 +17,17 @@ if (count($model->tickets) > 0) {
|
|||||||
$ticket = $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->card)) {
|
||||||
if (isset($model->customer)) {
|
if (isset($model->customer)) {
|
||||||
if ($model->card->validity == 0) {
|
if ($model->card->validity == 0) {
|
||||||
|
|||||||
101
frontend/views/customer/activate.php
Normal file
101
frontend/views/customer/activate.php
Normal file
@ -0,0 +1,101 @@
|
|||||||
|
<h1>Recepció</h1>
|
||||||
|
<?php
|
||||||
|
|
||||||
|
use common\models\Card;
|
||||||
|
use frontend\components\ReceptionWidget;
|
||||||
|
|
||||||
|
use yii\grid\GridView;
|
||||||
|
use yii\widgets\ActiveForm;
|
||||||
|
use yii\helpers\Html;
|
||||||
|
|
||||||
|
?>
|
||||||
|
<?php echo ReceptionWidget::widget(['form' => $model, 'route' => ['customer/reception']]) ?>
|
||||||
|
<h2>Aktiválás</h2>
|
||||||
|
|
||||||
|
|
||||||
|
<?php if ($formModel->card->status == Card::STATUS_INACTIVE) { ?>
|
||||||
|
<div class="customer-form">
|
||||||
|
|
||||||
|
<?php $form = ActiveForm::begin(); ?>
|
||||||
|
|
||||||
|
<div class="form-group">
|
||||||
|
|
||||||
|
<div class="row">
|
||||||
|
<div class="col-md-3">
|
||||||
|
Inaktiválási dátum:
|
||||||
|
</div>
|
||||||
|
<div class="col-md-3">
|
||||||
|
<?= \Yii::$app->formatter->asDate($formModel->card->inactivated_at) ?>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
</div>
|
||||||
|
<div class="row">
|
||||||
|
<div class="col-md-3">
|
||||||
|
Eltelt napok:
|
||||||
|
</div>
|
||||||
|
<div class="col-md-3">
|
||||||
|
<?= $formModel->daysPassed ?>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<?= GridView::widget([
|
||||||
|
'dataProvider' => $ticketsDataProvider,
|
||||||
|
'columns' => [
|
||||||
|
|
||||||
|
[
|
||||||
|
'attribute' => 'id_ticket',
|
||||||
|
'label' => 'Bérlet Azonosító'
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'attribute' => 'created_at',
|
||||||
|
'label' => 'Vásárlás ideje',
|
||||||
|
'format' => 'datetime'
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'attribute' => 'start',
|
||||||
|
'label' => 'Érvényesség kezdete',
|
||||||
|
'format' => 'date'
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'attribute' => 'end',
|
||||||
|
'label' => 'Érvényesség vége',
|
||||||
|
'format' => 'date'
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'attribute' => 'max_usage_count',
|
||||||
|
'label' => 'Max alkalmak'
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'attribute' => 'usage_count',
|
||||||
|
'label' => 'Felhasznált alkalmak'
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'attribute' => 'end2',
|
||||||
|
'label' => 'Új Érvényesség vége',
|
||||||
|
'format' => 'date'
|
||||||
|
],
|
||||||
|
|
||||||
|
],
|
||||||
|
]); ?>
|
||||||
|
|
||||||
|
|
||||||
|
<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 } else { ?>
|
||||||
|
|
||||||
|
<div class="alert alert-success" role="alert">
|
||||||
|
<p>
|
||||||
|
A kártya aktív
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
<?php } ?>
|
||||||
Loading…
Reference in New Issue
Block a user