diff --git a/controllers/DeviceController.php b/controllers/DeviceController.php index bd2bde54..cc81b6e3 100644 --- a/controllers/DeviceController.php +++ b/controllers/DeviceController.php @@ -541,4 +541,15 @@ class DeviceController extends Controller { } } + public function actionOpenDoor($id, $door) { + if (Yii::$app->request->isAjax) { + Yii::$app->response->format = "json"; + $model = $this->findModel($id); + return json_decode(common::requestToCardService("/ControlDevice", [ + "DeviceIP" => $model->ip_address, + "DoorID" => $door + ]), true); + } + } + } diff --git a/controllers/StaffController.php b/controllers/StaffController.php index e269fc75..8495399b 100644 --- a/controllers/StaffController.php +++ b/controllers/StaffController.php @@ -12,6 +12,7 @@ use yii\web\NotFoundHttpException; use yii\filters\VerbFilter; use yii\helpers\Html; use yii\helpers\Url; +use app\models\Device; /** * StaffController implements the CRUD actions for Staff model. @@ -79,7 +80,8 @@ class StaffController extends Controller { "model" => $model, "url" => Url::to(["create"]), "departmentArray" => Department::departmentArray(), - "genderArray" => Staff::$genderArray + "genderArray" => Staff::$genderArray, + "deviceArray" => Device::deviceArray() ]) ]; } @@ -125,7 +127,8 @@ class StaffController extends Controller { "model" => $model, "url" => Url::to(["update", "id" => $id]), "departmentArray" => Department::departmentArray(), - "genderArray" => Staff::$genderArray + "genderArray" => Staff::$genderArray, + "deviceArray" => Device::deviceArray() ]) ]; } @@ -302,4 +305,13 @@ class StaffController extends Controller { } } + public function actionGetRtlog() { + if (Yii::$app->request->post()) { + Yii::$app->response->format = "json"; + $device_id = Yii::$app->request->post("device"); + $device = Device::findOne($device_id); + return json_decode(common::requestToCardService("/GetRTLog", ["DeviceIP" => $device->ip_address]), true); + } + } + } diff --git a/helpers/DeviceGrid.php b/helpers/DeviceGrid.php index ed29d67b..a30f5426 100644 --- a/helpers/DeviceGrid.php +++ b/helpers/DeviceGrid.php @@ -2,6 +2,10 @@ namespace app\helpers; +use app\models\Door; +use yii\helpers\Html; +use yii\helpers\Url; + class DeviceGrid extends CommonGrid { public static function status($array) { @@ -30,4 +34,20 @@ class DeviceGrid extends CommonGrid { }; } + public static function openDoor() { + return function($model) { + $doors = Door::find()->andWhere(["device_id" => $model->id])->all(); + $html = ""; + foreach ($doors as $key => $value) { + $html .= Html::button($value->code, [ + 'class' => 'btn btn-info', + 'data' => ['toggle' => 'tooltip', 'href' => Url::to(['open-door', 'id' => $model->id, 'door' => $value->code])], + 'title' => \Yii::t('app', 'Mở cửa'), + 'onclick' => "openDoor(this);" + ]) . " "; + } + return $html; + }; + } + } diff --git a/views/device/index.tpl b/views/device/index.tpl index bba439e8..cb9bc07a 100644 --- a/views/device/index.tpl +++ b/views/device/index.tpl @@ -68,8 +68,14 @@ 'value' => \app\helpers\DeviceGrid::checkbox("device", false) ], 'name', - 'serial', - 'ip_address', + [ + 'attribute' => 'serial', + 'headerOptions' => ['style' => 'width:10%'] + ], + [ + 'attribute' => 'ip_address', + 'headerOptions' => ['style' => 'width:10%'] + ], 'subnet_mask', 'gateway', 'mac_address', @@ -80,7 +86,11 @@ 'contentOptions' => ['class' => 'text-center'], 'value' => \app\helpers\DeviceGrid::status($statusArray) ], - 'type', + [ + 'attribute' => 'type', + 'contentOptions' => ['class' => 'text-center'], + 'headerOptions' => ['style' => 'width:5%'] + ], [ 'attribute' => 'area_id', 'format' => 'raw', @@ -88,7 +98,12 @@ 'contentOptions' => ['class' => 'text-center'], 'value' => \app\helpers\DeviceGrid::area($areaArray) ], - 'version' + 'version', + [ + 'format' => 'raw', + 'headerOptions' => ['style' => 'width:10%'], + 'value' => \app\helpers\DeviceGrid::openDoor() + ] ] ])} {/Pjax} diff --git a/views/staff/form.tpl b/views/staff/form.tpl index 47bace96..452d02b8 100644 --- a/views/staff/form.tpl +++ b/views/staff/form.tpl @@ -81,9 +81,28 @@
Mã thẻ
+
+ +
+
Phòng ban
diff --git a/web/js/device.js b/web/js/device.js index 4edebde0..d73b82e6 100644 --- a/web/js/device.js +++ b/web/js/device.js @@ -478,3 +478,22 @@ function processProgress(ai) { $("#close-modal").attr("disabled", false); } } + +function openDoor(e) { + common.modalBlock(true); + $.ajax({ + url: $(e).attr('data-href'), + type: 'POST', + success: function (data) { + common.modalBlock(false); + if (data.ErrorCode === "0") + notification.success("Mở cửa thành công", 2000); + else + notification.error("Mở cửa thất bại, không có kết nối tới thiết bị", 2000); + }, + error: function (jqXHR, textStatus, errorThrown) { + common.modalBlock(false); + common.ajaxError(); + } + }); +} diff --git a/web/js/staff.js b/web/js/staff.js index b0436ccc..a62bb799 100644 --- a/web/js/staff.js +++ b/web/js/staff.js @@ -257,4 +257,39 @@ function btnImage() { } }).addInstance('AnhNhanVien'); } -; + +function formGetRTLog(e) { + var stt = $(e).attr("data-stt"); + if (stt === "true") { + $("#device-lists").removeClass("hidden"); + $(e).attr("data-stt", false); + } else { + $("#device-lists").addClass("hidden"); + $(e).attr("data-stt", true); + } +} + +function getRTLog(e) { + common.modalBlock(true); + $.ajax({ + url: $(e).attr('data-href'), + type: 'POST', + data: { + device: $("select[name='Device']").val() + }, + success: function (data) { + common.modalBlock(false); + if (data.ErrorCode === "1") { + $("input[name='CardNumber']").val(data.CardNumber); + $("#device-lists").addClass("hidden"); + $("#btn-get-rtlog").attr("data-stt", true); + } else { + alert("Không có tín hiệu thẻ"); + } + }, + error: function (jqXHR, textStatus, errorThrown) { + common.modalBlock(false); + alert("Không có tín hiệu thẻ"); + } + }); +}