implement mobile devices in reception

This commit is contained in:
2022-02-19 14:51:58 +01:00
parent 9fb0485066
commit 34fca82e7d
13 changed files with 834 additions and 185 deletions

View File

@@ -1,6 +1,7 @@
<?php
namespace frontend\components;
use common\models\MobileDevice;
use yii\base\Widget;
/**
* This is the model class for table "customer".
@@ -15,8 +16,13 @@ class ReceptionCustomerWidget extends Widget{
public $model;
public function run(){
echo $this->render($this->viewFile,[ 'model' => $this->model ]);
$showLinkDevices = MobileDevice::find()
->andWhere(['status' => MobileDevice::STATUS_INACTIVE])
->count() > 0;
echo $this->render($this->viewFile,[ 'model' => $this->model,
'showLinkDevices' => $showLinkDevices
]);
}
}
}

View File

@@ -0,0 +1,108 @@
<?php
namespace frontend\controllers;
use common\models\Card;
use common\models\MobileDevice;
use frontend\models\MobileDeviceSearch;
use frontend\models\MobileStatusForm;
use Yii;
use common\models\City;
use backend\models\CitySearch;
use yii\web\Controller;
use yii\web\NotFoundHttpException;
use yii\filters\VerbFilter;
use yii\base\Object;
use yii\db\Query;
use yii\helpers\Json;
/**
* CityController implements the CRUD actions for City model.
*/
class MobileDeviceController extends Controller
{
public function behaviors()
{
return [
'verbs' => [
'class' => VerbFilter::className(),
'actions' => [
'delete' => ['post'],
],
],
];
}
/**
* Lists all City models.
* @return mixed
*/
public function actionIndex($id_card)
{
$card = $this->findModel($id_card);
$searchModel = new MobileDeviceSearch();
$searchModel->id_card = $card->id_card;
$dataProvider = $searchModel->search(Yii::$app->request->queryParams);
return $this->render('index', [
'searchModel' => $searchModel,
'dataProvider' => $dataProvider,
'card' => $card
]);
}
public function actionStatus($id_device, $status)
{
$device = $this->findDevice($id_device);
\Yii::info(print_r($device,true));
if ( $device == null ){
throw new NotFoundHttpException();
}
if (\Yii::$app->request->isPost) {
$form = new MobileStatusForm();
$form->status = $status;
$form->id_device = $id_device;
if ($form->validate()) {
$form->save();
return $this->redirect(['mobile-device/index', 'id_card' => $device->id_card]);
}
}
return $this->render( 'mobile-device/index',[ 'id_card' => $device->id_card]);
}
/**
* Finds the Card model based on its primary key value.
* If the model is not found, a 404 HTTP exception will be thrown.
* @param integer $id
* @return Card the loaded model
* @throws NotFoundHttpException if the model cannot be found
*/
protected function findModel($id)
{
if (($model = Card::findOne($id)) !== null) {
return $model;
} else {
throw new NotFoundHttpException('The requested page does not exist.');
}
}
/**
* @param $id
* @return MobileDevice|null
* @throws NotFoundHttpException
*/
protected function findDevice($id)
{
if (($model = MobileDevice::findOne($id)) !== null) {
return $model;
} else {
throw new NotFoundHttpException('The requested page does not exist.');
}
}
}

View File

@@ -0,0 +1,89 @@
<?php
namespace frontend\models;
use common\components\Helper;
use common\models\MobileDevice;
use Yii;
use yii\base\Model;
use yii\data\ActiveDataProvider;
use yii\db\Query;
/**
* EventSearch represents the model behind the search form about `common\models\Event`.
*/
class MobileDeviceSearch extends MobileDevice
{
/**
* @inheritdoc
*/
public function rules()
{
return [
];
}
/**
* @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([
'card.id_card as card_id',
'card.number as card_number',
'mobile_device.id as device_id',
'mobile_device.device_name as device_name',
'mobile_device.status as device_status',
'mobile_device.created_at as device_created_at',
]);
$query->from("mobile_device");
$query->innerJoin('customer', 'customer.id_customer_card = mobile_device.id_card');
$query->innerJoin('card', 'card.id_card = mobile_device.id_card');
$query->andWhere(['card.id_card' => $this->id_card]);
$dataProvider = new ActiveDataProvider([
'query' => $query,
'sort' => [
'defaultOrder' => [
'device_created_at' => SORT_DESC
],
'attributes' => Helper::mkYiiSortItems([
['device_created_at'],
['device_status'],
]),
]
]);
$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([
// 'event.id' => $this->id,
// ]);
return $dataProvider;
}
}

View File

@@ -0,0 +1,96 @@
<?php
namespace frontend\models;
use common\components\Helper;
use common\models\Card;
use common\models\Customer;
use common\models\Log;
use common\models\MobileDevice;
use Yii;
use yii\base\Model;
use yii\web\BadRequestHttpException;
use yii\web\NotFoundHttpException;
/**
* ContactForm is the model behind the contact form.
*/
class MobileStatusForm extends Model
{
public $id_device;
public $status;
/**
* @inheritdoc
*/
public function rules()
{
return [
[['id_device', 'status'], 'required'],
];
}
public function save()
{
$tx = null;
try {
$tx = \Yii::$app->db->beginTransaction();
$device = MobileDevice::findOne(['id' => $this->id_device]);
if ($device === null) {
throw new NotFoundHttpException();
}
$card = Card::findOne(['id_card' => $device->id_card]);
if ($card === null) {
throw new NotFoundHttpException();
}
\Yii::info("MobileStatusForm: changing status from $device->status to $this->status");
$origStatus = $device->status;
$device->status = $this->status;
if ( $this->status === MobileDevice::STATUS_ACTIVE ){
// only one card can be active at the same time
MobileDevice::updateAll([
'activated_at' => null,
'status' => MobileDevice::STATUS_DELETED_SYSTEM
],
[
'id_card' => $device->id_card
]
);
}
if ($this->status === MobileDevice::STATUS_ACTIVE) {
if (!isset($device->activated_at)) {
$device->activated_at = Helper::getDateTimeString();
}
} else {
$device->activated_at = null;
}
$device->save(false);
$customer = Customer::find()->andWhere(['id_customer_card' => $device->id_card])->one();
Log::log([
'type' => Log::$TYPE_MOBILE_DEVICE_STATUS,
'message' => "Eszkösz $device->id; Kártya: $card->number; előző státusz: $origStatus; új státusz: $this->status",
'id_customer' => $customer->id_customer
]);
$tx->commit();
}catch ( \Exception $e){
\Yii::error("Failed to save status for device $this->id_device :".$e->getMessage());
if ( $tx != null ){
$tx->rollBack();
}
throw $e;
}
}
}

View File

@@ -1,57 +1,85 @@
<?php
use yii\helpers\Url;
?>
<?php
$route = Yii::$app->controller->id .'/'. Yii::$app->controller->action->id;
$route = Yii::$app->controller->id . '/' . Yii::$app->controller->action->id;
/** @noinspection PhpUnhandledExceptionInspection */
$todayDateTime = Yii::$app->formatter->asDatetime(strtotime('today UTC'));
$items = [
[ 'Recepció', ['customer/reception', 'number' => $card->number ]],
[ 'Termék eladás', ['product/sale', 'number' => $card->number ]],
[ 'Adatlap', ['customer/update', 'number' => $card->number ]],
[ 'Befizetések', ['ticket/index', 'number' => $card->number] ],
[ 'Kulcsok', ['key/index', 'id_card' => $card->id_card] ],
[ 'Szerződések', ['contract/index', 'id_card' => $card->id_card ]],
[ 'Kosár', ['transfer/customer-cart', 'id_card' => $card->id_card ]],
[ 'Kártya', ['card/info', 'id_card' => $card->id_card ]],
[ 'Törölköző Bérlés', ['log/towel', 'id_card' => $card->id_card , 'LogSearch[start]' => $todayDateTime ]],
[ 'Ujjlenyomat', ['fingerprint/index', 'FingerprintSearch[id_card]' => $card->id_card ]],
[ 'Jelszó küldése', ['customer/password-change', 'id_card' => $card->id_card ]],
['Recepció', ['customer/reception', 'number' => $card->number]],
['Termék eladás', ['product/sale', 'number' => $card->number]],
['Adatlap', ['customer/update', 'number' => $card->number]],
['Befizetések', ['ticket/index', 'number' => $card->number]],
['Kulcsok', ['key/index', 'id_card' => $card->id_card]],
['Szerződések', ['contract/index', 'id_card' => $card->id_card]],
['Kosár', ['transfer/customer-cart', 'id_card' => $card->id_card]],
['Kártya', ['card/info', 'id_card' => $card->id_card]],
['Törölköző Bérlés', ['log/towel', 'id_card' => $card->id_card, 'LogSearch[start]' => $todayDateTime]],
['Ujjlenyomat', ['fingerprint/index', 'FingerprintSearch[id_card]' => $card->id_card]],
['Jelszó küldése', ['customer/password-change', 'id_card' => $card->id_card]],
['Mobil Eszközök', ['mobile-device/index', 'id_card' => $card->id_card]],
];
?>
<style>
.fitness-nav {
}
.fitness-nav-item.active a, .fitness-nav-item a:hover {
background: #0b93d5;
}
.fitness-nav-item > a {
padding: 8px 16px;
display: block;
margin-bottom: 8px;
background: #204d74;
color: #ffffff;
border-radius: 4px;
text-align: center;
}
.fitness-nav-container{
background: #e2e2e2;
padding: 8px 8px 0 8px;
border-radius: 4px;
}
</style>
<div class="fitness-nav-container">
<ul class="nav nav-tabs">
<?php foreach ($items as $item){?>
<?php
if ( empty($title)){
if ( $item[1][0] == $route) {
$title = $item[0];
}
}
?>
<li role="presentation" class="<?php echo $item[1][0] == $route ? 'active' : '' ?>"><a href="<?php echo Url::toRoute($item[1])?>"><?php echo $item[0] ?></a></li>
<?php }?>
</ul>
<div class="row fitness-nav">
<?php foreach ($items as $item) { ?>
<?php
if (empty($title)) {
if ($item[1][0] == $route) {
$title = $item[0];
}
}
?>
<div role="presentation"
class="col-lg-2 fitness-nav-item <?php echo $item[1][0] == $route ? 'active' : '' ?>"><a
href="<?php echo Url::toRoute($item[1]) ?>"><?php echo $item[0] ?></a></div>
<?php } ?>
</div>
</div>
<?php if ( !empty($title)) {?>
<h1><?php echo $title?></h1>
<?php if (!empty($title)) { ?>
<h1><?php echo $title ?></h1>
<p>Vendég: <?php echo $card->customer->name ?></p>
<p>Kártyaszám: <?php echo $card->number ?></p>
<?php }?>
<?php } ?>

View File

@@ -13,57 +13,69 @@ use yii\helpers\Url;
<?php
if ( $model->isCardWithCustomer() ){
$attributes = [
[
'label' => 'Kártyaszám',
'value' => $model->card->number
],
[
'label' => 'Vendég',
'value' => $model->customer->name
],
[
'label' => 'E-Mail',
'value' => $model->customer->email
],
[
'label' => 'Telefon',
'value' => $model->customer->phone
],
[
'label' => 'Kiadott törölközők',
'value' => $model->customer->towel_count
],
[
'label' => 'Kulcsok',
'value' =>
empty($model->keysText) ? '' : (
"<form method='POST' action='". Url::toRoute(['key/toggle', "number" => $model->card->number])."'>"
.$model->keysText
.Html::hiddenInput("KeyToggleForm[key]", $model->keysText)
.Html::submitButton("Visszaad", [ 'style' => 'float: right;', 'class' => 'btn btn-primary btn-xs'])
."</form>")
,
'format' => 'raw'
],
[
'label' => 'Fénykép',
'value' => $model->customer->image1 ? Html::img( Url::base( ) . Image::thumb( $model->customer->image1->path,160,120 )) : 'Nincs kép',
'format' => 'raw'
],
];
?>
<div class="row">
<div class="col-md-12">
<?php
echo DetailView::widget([
'model' => $model,
'attributes' =>[
[
'label' => 'Kártyaszám',
'value' => $model->card->number
],
[
'label' => 'Vendég',
'value' => $model->customer->name
],
[
'label' => 'E-Mail',
'value' => $model->customer->email
],
[
'label' => 'Telefon',
'value' => $model->customer->phone
],
[
'label' => 'Kiadott törölközők',
'value' => $model->customer->towel_count
],
[
'label' => 'Kulcsok',
'value' =>
empty($model->keysText) ? '' : (
"<form method='POST' action='". Url::toRoute(['key/toggle', "number" => $model->card->number])."'>"
.$model->keysText
.Html::hiddenInput("KeyToggleForm[key]", $model->keysText)
.Html::submitButton("Visszaad", [ 'style' => 'float: right;', 'class' => 'btn btn-primary btn-xs'])
."</form>")
,
'format' => 'raw'
],
[
'label' => 'Fénykép',
'value' => $model->customer->image1 ? Html::img( Url::base( ) . Image::thumb( $model->customer->image1->path,160,120 )) : 'Nincs kép',
'format' => 'raw'
],
]
'attributes' => $attributes
])
?>
<div>
<?php
echo Html::a('Menü',['customer/update', 'number' => $model->card->number],['class' => 'btn btn-success me-3']);
if ( isset($showLinkDevices) && $showLinkDevices === true ) {
echo Html::a('Eszköz aktiválása', ['mobile-device/index', 'id_card' => $model->card->id_card], ['class' => 'btn btn-success']);
}?>
</div>
</div>
</div>
<?php
}
?>
?>

View File

@@ -0,0 +1,86 @@
<?php
use yii\helpers\Html;
use yii\grid\GridView;
use yii\helpers\Url;
use common\models\MobileDevice;
/* @var $this yii\web\View */
/* @var $searchModel frontend\models\CollectionSearch */
/* @var $card \common\models\Card */
/* @var $dataProvider \frontend\controllers\MobileDeviceController */
$this->title = "Vendég - mobil eszközök";
$this->params['breadcrumbs'][] = "Vendég";
$this->params['breadcrumbs'][] = "Mobil eszközök";
echo \frontend\components\CustomerTabWidget::widget(['card' => $card]);
echo GridView::widget([
'dataProvider' => $dataProvider,
'columns' => [
[
'attribute' => 'card_number',
'label' => 'Kártyaszám',
],
[
'attribute' => 'device_name',
'label' => 'Eszköz neve',
],
[
'attribute' => 'device_created_at',
'label' => 'Létrehozva',
'format' => 'datetime'
],
[
'attribute' => 'device_status',
'label' => 'Státusz',
'value' => function ($model, $key, $index, $column) {
return MobileDevice::toStatusHumanReadable($model['device_status']);
}
],
['class' => 'yii\grid\ActionColumn',
'header' => 'Műveletek',
'template' => '{activate} {delete}',
'buttons' => [
'activate' => function ($url, $model, $key) {
$status = $model['device_status'];
if ($status == MobileDevice::STATUS_ACTIVE) {
return null;
}
$options = [
'title' => 'Az aktuális eszköz aktiválása',
'data-confirm' => "Biztosan aktiválni szerenté ezt az eszközt?",
'data-method' => 'post',
'class' => 'btn btn-xs btn-success'
];
return Html::a('Aktivál', $url, $options);
},
'delete' => function ($url, $model, $key) {
$status = $model['device_status'];
if ($status !== MobileDevice::STATUS_ACTIVE) {
return null;
}
$options = [
'title' => 'Az aktuális eszköz törlése',
'data-confirm' => "Biztosan törölni szerenté ezt az eszközt?",
'data-method' => 'post',
'class' => 'btn btn-xs btn-danger'
];
return Html::a('Töröl', $url, $options);
},
],
'urlCreator' => function ($action, $model, $key, $index) {
$status = MobileDevice::STATUS_DELETED_MANUAL;
if ($action === 'activate') {
$status = MobileDevice::STATUS_ACTIVE;
}
$url = Url::to(['mobile-device/status', 'id_device' => $model['device_id'], 'status' => $status]);
return $url;
}
],
],
]); ?>

View File

@@ -96,3 +96,138 @@ a.desc:after {
background-color: #dc500b;
border-color: #faebcc;
}
:root{
--spacer-1: 0.25rem;
--spacer-2: 0.5rem;
--spacer-3: 1rem;
--spacer-4: 1.5rem;
--spacer-5: 3rem;
}
.px-1{
padding-left: var(--spacer-1);
padding-right: var(--spacer-1);
}
.px-2{
padding-left: var(--spacer-2);
padding-right: var(--spacer-2);
}
.px-3{
padding-left: var(--spacer-3);
padding-right: var(--spacer-3);
}
.px-4{
padding-left: var(--spacer-4);
padding-right: var(--spacer-4);
}
.py-1{
padding-top: var(--spacer-1);
padding-bottom: var(--spacer-1);
}
.py-2{
padding-top: var(--spacer-2);
padding-bottom: var(--spacer-2);
}
.py-3{
padding-top: var(--spacer-3);
padding-bottom: var(--spacer-3);
}
.py-4{
padding-top: var(--spacer-4);
padding-bottom: var(--spacer-4);
}
.ps-1{
padding-left: var(--spacer-1);
}
.ps-2{
padding-left: var(--spacer-2);
}
.ps-3{
padding-left: var(--spacer-3);
}
.ps-4{
padding-left: var(--spacer-4);
}
.pe-1{
padding-right: var(--spacer-1);
}
.pe-2{
padding-right: var(--spacer-2);
}
.pe-3{
padding-right: var(--spacer-3);
}
.pe-4{
padding-right: var(--spacer-4);
}
/**
margins
*/
.mx-1{
margin-left: var(--spacer-1);
margin-right: var(--spacer-1);
}
.mx-2{
margin-left: var(--spacer-2);
margin-right: var(--spacer-2);
}
.mx-3{
margin-left: var(--spacer-3);
margin-right: var(--spacer-3);
}
.mx-4{
margin-left: var(--spacer-4);
margin-right: var(--spacer-4);
}
.my-1{
margin-top: var(--spacer-1);
margin-bottom: var(--spacer-1);
}
.my-2{
margin-top: var(--spacer-2);
margin-bottom: var(--spacer-2);
}
.my-3{
margin-top: var(--spacer-3);
margin-bottom: var(--spacer-3);
}
.my-4{
margin-top: var(--spacer-4);
margin-bottom: var(--spacer-4);
}
.ms-1{
margin-left: var(--spacer-1);
}
.ms-2{
margin-left: var(--spacer-2);
}
.ms-3{
margin-left: var(--spacer-3);
}
.ms-4{
margin-left: var(--spacer-4);
}
.me-1{
margin-right: var(--spacer-1);
}
.me-2{
margin-right: var(--spacer-2);
}
.me-3{
margin-right: var(--spacer-3);
}
.me-4{
margin-right: var(--spacer-4);
}