update thống kê

This commit is contained in:
dongpd 2020-10-16 11:35:29 +07:00
parent 53de75104e
commit 4ba094ab24
16 changed files with 526 additions and 80 deletions

View File

@ -3,7 +3,7 @@
-- https://www.phpmyadmin.net/ -- https://www.phpmyadmin.net/
-- --
-- Host: 127.0.0.1 -- Host: 127.0.0.1
-- Generation Time: Oct 14, 2020 at 11:53 AM -- Generation Time: Oct 16, 2020 at 06:34 AM
-- Server version: 10.4.8-MariaDB -- Server version: 10.4.8-MariaDB
-- PHP Version: 7.1.33 -- PHP Version: 7.1.33
@ -218,7 +218,7 @@ CREATE TABLE `device` (
INSERT INTO `device` (`id`, `name`, `serial`, `ip_address`, `subnet_mask`, `gateway`, `mac_address`, `status`, `type`, `version`, `area_id`, `created_at`, `modified_at`) VALUES INSERT INTO `device` (`id`, `name`, `serial`, `ip_address`, `subnet_mask`, `gateway`, `mac_address`, `status`, `type`, `version`, `area_id`, `created_at`, `modified_at`) VALUES
(4, 'Thiết bị 1', 'AJNV193560605', '192.168.1.200', '255.255.252.0', '192.168.0.1', '00:17:61:C9:6B:A4', 1, 'C3-200', 'AC Ver 4.3.4 Jan 5 2019', 1, 1602563228, 1602563228), (4, 'Thiết bị 1', 'AJNV193560605', '192.168.1.200', '255.255.252.0', '192.168.0.1', '00:17:61:C9:6B:A4', 1, 'C3-200', 'AC Ver 4.3.4 Jan 5 2019', 1, 1602563228, 1602563228),
(5, '192.168.1.202', 'AJNV200860076', '192.168.1.202', '255.255.252.0', '192.168.0.1', '00:17:61:CA:8D:F6', 1, 'C3-200', 'AC Ver 4.3.4 Jan 5 2019', 1, 1602659429, 1602659429); (5, '192.168.1.205', 'AJNV200860076', '192.168.1.205', '255.255.255.255', '192.168.0.1', '00:17:61:CA:8D:F6', 1, 'C3-200', 'AC Ver 4.3.4 Jan 5 2019', 1, 1602659429, 1602659429);
-- -------------------------------------------------------- -- --------------------------------------------------------
@ -247,6 +247,55 @@ INSERT INTO `door` (`id`, `device_id`, `name`, `code`, `created_at`, `modified_a
-- -------------------------------------------------------- -- --------------------------------------------------------
--
-- Table structure for table `event_type`
--
CREATE TABLE `event_type` (
`id` int(11) NOT NULL,
`code` int(11) NOT NULL,
`name` varchar(200) NOT NULL,
`description` text NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
--
-- Dumping data for table `event_type`
--
INSERT INTO `event_type` (`id`, `code`, `name`, `description`) VALUES
(1, 0, 'Normal Punch Open', 'In [Card Only] verification mode, the person has open door permission punch the card and triggers this normal event of open the door.'),
(2, 27, 'Unregistered Card', 'Refers to the current card is not registered in the system, trigger this abnormal event.');
-- --------------------------------------------------------
--
-- Table structure for table `logs`
--
CREATE TABLE `logs` (
`id` int(11) NOT NULL,
`staff_id` int(11) NOT NULL DEFAULT 0,
`card_number` int(11) NOT NULL,
`device_id` int(11) NOT NULL,
`door_id` int(11) NOT NULL,
`in_out_state` int(11) NOT NULL,
`time` int(11) NOT NULL,
`event_type` int(11) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
--
-- Dumping data for table `logs`
--
INSERT INTO `logs` (`id`, `staff_id`, `card_number`, `device_id`, `door_id`, `in_out_state`, `time`, `event_type`) VALUES
(6, 2, 16672726, 4, 2, 1, 1602819028, 0),
(7, 2, 16672726, 4, 1, 1, 1602819033, 0),
(8, 2, 16672726, 4, 1, 0, 1602819356, 0),
(9, 3, 2430805, 4, 2, 1, 1602819665, 0),
(10, 0, 16673826, 4, 2, 1, 1602819669, 27);
-- --------------------------------------------------------
-- --
-- Table structure for table `schedule` -- Table structure for table `schedule`
-- --
@ -2437,6 +2486,18 @@ ALTER TABLE `device`
ALTER TABLE `door` ALTER TABLE `door`
ADD PRIMARY KEY (`id`); ADD PRIMARY KEY (`id`);
--
-- Indexes for table `event_type`
--
ALTER TABLE `event_type`
ADD PRIMARY KEY (`id`);
--
-- Indexes for table `logs`
--
ALTER TABLE `logs`
ADD PRIMARY KEY (`id`);
-- --
-- Indexes for table `schedule` -- Indexes for table `schedule`
-- --
@ -2490,6 +2551,18 @@ ALTER TABLE `device`
ALTER TABLE `door` ALTER TABLE `door`
MODIFY `id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=11; MODIFY `id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=11;
--
-- AUTO_INCREMENT for table `event_type`
--
ALTER TABLE `event_type`
MODIFY `id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=3;
--
-- AUTO_INCREMENT for table `logs`
--
ALTER TABLE `logs`
MODIFY `id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=11;
-- --
-- AUTO_INCREMENT for table `schedule` -- AUTO_INCREMENT for table `schedule`
-- --
@ -2512,7 +2585,7 @@ ALTER TABLE `system_logs`
-- AUTO_INCREMENT for table `user` -- AUTO_INCREMENT for table `user`
-- --
ALTER TABLE `user` ALTER TABLE `user`
MODIFY `id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=202; MODIFY `id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=203;
-- --
-- Constraints for dumped tables -- Constraints for dumped tables

23
assets/LogsAsset.php Normal file
View File

@ -0,0 +1,23 @@
<?php
namespace app\assets;
use yii\web\AssetBundle;
class LogsAsset extends AssetBundle {
public $basePath = '@webroot';
public $baseUrl = '@web';
public $css = [
];
public $js = [
'js/logs.js'
];
public $depends = [
'yii\web\YiiAsset',
'app\assets\AppAsset',
// 'yii\jui\JuiAsset',
'yii\bootstrap\BootstrapAsset',
];
}

View File

@ -7,9 +7,9 @@ $db = require __DIR__ . '/db.php';
$config = [ $config = [
'id' => 'basic', 'id' => 'basic',
'homeUrl' => ['/dashboard'], 'homeUrl' => ['/staff'],
'name' => 'AIParking Traffic', 'name' => 'Access Control',
'defaultRoute' => 'dashboard', 'defaultRoute' => 'staff',
'basePath' => dirname(__DIR__), 'basePath' => dirname(__DIR__),
'bootstrap' => ['log'], 'bootstrap' => ['log'],
'timeZone' => 'Asia/Ho_Chi_Minh', 'timeZone' => 'Asia/Ho_Chi_Minh',

View File

@ -8,6 +8,10 @@ use app\models\LogsSearch;
use yii\web\Controller; use yii\web\Controller;
use yii\web\NotFoundHttpException; use yii\web\NotFoundHttpException;
use yii\filters\VerbFilter; use yii\filters\VerbFilter;
use app\models\Device;
use app\models\EventType;
use app\models\Department;
use app\models\common;
/** /**
* LogsController implements the CRUD actions for Logs model. * LogsController implements the CRUD actions for Logs model.
@ -34,17 +38,132 @@ class LogsController extends Controller {
]; ];
} }
public function actionIndex() { public function actionIndex($type = "today", $from = "", $to = "") {
$this->view->title = 'Sự kiện hôm nay'; $f = $t = 0;
$this->view->title = 'Tất cả sự kiện';
if ($type === "today" && $from === "" && $to === "") {
$f = date_format(date_create_from_format('H:i:s d/m/Y', "00:00:00 " . date("d/m/Y")), 'U');
$t = date_format(date_create_from_format('H:i:s d/m/Y', "23:59:59 " . date("d/m/Y")), 'U');
$this->view->title = 'Sự kiện hôm nay';
}
if ($type === "3days" && $from === "" && $to === "") {
$f = date_format(date_create_from_format('H:i:s d/m/Y', "00:00:00 " . date("d/m/Y")), 'U');
$f = $f - 60 * 60 * 24 * 2;
$t = date_format(date_create_from_format('H:i:s d/m/Y', "23:59:59 " . date("d/m/Y")), 'U');
$this->view->title = 'Sự kiện 3 ngày gần đây';
}
if ($type === "thisWeek" && $from === "" && $to === "") {
$dayOfWeek = date("w");
$f = date_format(date_create_from_format('H:i:s d/m/Y', "00:00:00 " . date("d/m/Y")), 'U');
$f = $f - 60 * 60 * 24 * ($dayOfWeek - 1);
$t = date_format(date_create_from_format('H:i:s d/m/Y', "23:59:59 " . date("d/m/Y")), 'U');
$t = $t + 60 * 60 * 24 * (7 - $dayOfWeek);
$this->view->title = 'Sự kiện tuần này';
}
if ($type === "lastWeek" && $from === "" && $to === "") {
$dayOfWeek = date("w");
$f = date_format(date_create_from_format('H:i:s d/m/Y', "00:00:00 " . date("d/m/Y")), 'U');
$f = $f - 60 * 60 * 24 * ($dayOfWeek - 1) - 60 * 60 * 24 * 7;
$t = date_format(date_create_from_format('H:i:s d/m/Y', "23:59:59 " . date("d/m/Y")), 'U');
$t = $t + 60 * 60 * 24 * (7 - $dayOfWeek) - 60 * 60 * 24 * 7;
$this->view->title = 'Sự kiện tuần trước';
}
if ($from !== "" && $to !== "") {
$f = date_format(date_create_from_format('H:i:s d/m/Y', $from), 'U');
$t = date_format(date_create_from_format('H:i:s d/m/Y', $to), 'U');
}
$searchModel = new LogsSearch(); $searchModel = new LogsSearch();
$dataProvider = $searchModel->search(Yii::$app->request->queryParams); $dataProvider = $searchModel->search(Yii::$app->request->queryParams);
if ($f != 0 && $t != 0) {
$dataProvider->query->andWhere(["BETWEEN", 'time', $f, $t]);
}
$dataProvider->query->orderBy(["time" => SORT_DESC]);
return $this->render('index', [ return $this->render('index', [
'searchModel' => $searchModel, 'searchModel' => $searchModel,
'dataProvider' => $dataProvider, 'dataProvider' => $dataProvider,
'deviceArray' => Device::deviceArray(),
'stateArray' => Logs::$stateArray,
'eventTypeArray' => EventType::eventTypeArray(),
'departmentArray' => Department::departmentArray(),
'f' => $f,
't' => $t
]); ]);
} }
public function actionExport($from = "", $to = "") {
$f = date_format(date_create_from_format('H:i:s d/m/Y', $from), 'U');
$t = date_format(date_create_from_format('H:i:s d/m/Y', $to), 'U');
$objPHPExcel = new \PHPExcel();
$objPHPExcel->setActiveSheetIndex(0);
$toExcelFile[] = ["Thời gian", "Mã nhân viên", "Tên nhân viên", "Phòng ban", "Mã thẻ", "Thiết bị", "Cửa", "Trạng thái vào/ra", "Mô tả sự kiện"];
$query = Logs::find();
$query->andWhere(["BETWEEN", 'time', $f, $t]);
$query->orderBy(["time" => SORT_DESC]);
$logs = $query->all();
$departmentArray = Department::departmentArray();
$deviceArray = Device::deviceArray();
$stateArray = Logs::$stateArray;
$eventTypeArray = EventType::eventTypeArray();
foreach ($logs as $k => $v) {
$staff = $v->staff;
$ExportData[] = date("H:i:s d/m/Y", $v->time);
$ExportData[] = $staff ? $staff->code : "";
$ExportData[] = $staff ? $staff->name : "";
$ExportData[] = $staff && isset($departmentArray[$staff->department_id]) ? $departmentArray[$staff->department_id] : "";
$ExportData[] = $v->card_number;
$ExportData[] = isset($deviceArray[$v->device_id]) ? $deviceArray[$v->device_id] : "";
$ExportData[] = isset($deviceArray[$v->device_id]) ? $deviceArray[$v->device_id] . "-" . $v->door_id : "";
$ExportData[] = isset($stateArray[$v->in_out_state]) ? $stateArray[$v->in_out_state] : "";
$ExportData[] = isset($eventTypeArray[$v->event_type]) ? $eventTypeArray[$v->event_type] : "";
$toExcelFile[] = $ExportData;
unset($ExportData);
}
$totals = count($logs) + 1;
$activeSheet = $objPHPExcel->getActiveSheet();
$activeSheet->getStyle("A1:I" . $totals)->getFont()->setName('Time New Roman')->setSize(10);
$activeSheet->getStyle("A1:I1")->applyFromArray([
'fill' => array(
'type' => \PHPExcel_Style_Fill::FILL_SOLID,
'color' => array('rgb' => '7ac3ec')
)
]);
$rowCount = 1;
for ($i = 0; $i < count($toExcelFile); $i++) {
$column = 'A';
$row = $toExcelFile[$i];
for ($j = 0; $j < count($row); $j++) {
if (!isset($row[$j]))
$value = NULL;
elseif ($row[$j] != "")
$value = strip_tags($row[$j]);
else
$value = "";
$activeSheet->setCellValue($column . $rowCount, $value);
$column = chr(ord($column) + 1);
}
$rowCount++;
}
$activeSheet->getStyle("A1:I" . $totals)->applyFromArray([
'alignment' => [
'vertical' => \PHPExcel_Style_Alignment::VERTICAL_CENTER,
],
'borders' => [
'allborders' => [
'style' => \PHPExcel_Style_Border::BORDER_THIN
]
]
]);
$objWriter = \PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel2007');
ob_end_clean();
header('Content-type: application/vnd.ms-excel');
header('Content-Disposition: attachment; filename="logs_' . date("YmdHis") . '.xlsx"');
header('Cache-Control: max-age=0');
common::SaveViaTempFile($objWriter);
exit();
}
protected function findModel($id) { protected function findModel($id) {
if (($model = Logs::findOne($id)) !== null) { if (($model = Logs::findOne($id)) !== null) {
return $model; return $model;

View File

@ -73,7 +73,7 @@ class SiteController extends Controller {
$model = new LoginForm(); $model = new LoginForm();
if ($model->load(Yii::$app->request->post()) && $model->login()) { if ($model->load(Yii::$app->request->post()) && $model->login()) {
return $this->redirect(["/dashboard"]); return $this->redirect(["/staff"]);
} }
$model->password = ''; $model->password = '';

View File

@ -42,9 +42,6 @@ class UserController extends Controller {
throw new \yii\web\HttpException(403, 'Bạn không có quyền truy cập nội dung này'); throw new \yii\web\HttpException(403, 'Bạn không có quyền truy cập nội dung này');
$this->view->title = 'Người dùng'; $this->view->title = 'Người dùng';
$this->view->params['breadcrumbs'][] = 'Hệ thống';
$this->view->params['breadcrumbs'][] = $this->view->title;
$searchModel = new UserSearch(); $searchModel = new UserSearch();
$dataProvider = $searchModel->search(Yii::$app->request->queryParams); $dataProvider = $searchModel->search(Yii::$app->request->queryParams);

62
helpers/LogsGrid.php Normal file
View File

@ -0,0 +1,62 @@
<?php
namespace app\helpers;
class LogsGrid extends CommonGrid {
public static function time() {
return function($model) {
return date("H:i:s d/m/Y", $model->time);
};
}
public static function device($array) {
return function($model) use ($array) {
return isset($array[$model->device_id]) ? $array[$model->device_id] : "";
};
}
public static function door($array) {
return function($model) use ($array) {
return isset($array[$model->device_id]) ? $array[$model->device_id] . "-" . $model->door_id : "";
};
}
public static function state($array) {
return function($model) use ($array) {
return isset($array[$model->in_out_state]) ? $array[$model->in_out_state] : "";
};
}
public static function eventType($array) {
return function($model) use ($array) {
return isset($array[$model->event_type]) ? $array[$model->event_type] : "";
};
}
public static function name() {
return function($model) {
$staff = $model->staff;
return $staff ? $staff->name : "";
};
}
public static function department($array) {
return function($model) use ($array) {
$staff = $model->staff;
if ($staff)
return isset($array[$staff->department_id]) ? $array[$staff->department_id] : "";
return "";
};
}
public static function rowsColor() {
return function($model, $index, $widget, $grid) {
$color = "orange";
if ($model->event_type == 0)
$color = "green";
return ["class" => "text-" . $color];
};
}
}

57
models/EventType.php Normal file
View File

@ -0,0 +1,57 @@
<?php
namespace app\models;
use Yii;
/**
* This is the model class for table "event_type".
*
* @property int $id
* @property int $code
* @property string $name
* @property string $description
*/
class EventType extends \yii\db\ActiveRecord {
/**
* {@inheritdoc}
*/
public static function tableName() {
return 'event_type';
}
/**
* {@inheritdoc}
*/
public function rules() {
return [
[['code', 'name', 'description'], 'required'],
[['code'], 'integer'],
[['description'], 'string'],
[['name'], 'string', 'max' => 200],
];
}
/**
* {@inheritdoc}
*/
public function attributeLabels() {
return [
'id' => 'ID',
'code' => 'Code',
'name' => 'Name',
'description' => 'Description',
];
}
public static function eventTypeArray() {
$lists = self::find()->all();
$results = [];
foreach ($lists as $key => $value) {
$results[$value->code] = $value->name;
}
return $results;
}
}

View File

@ -41,22 +41,33 @@ class Logs extends \yii\db\ActiveRecord {
public function attributeLabels() { public function attributeLabels() {
return [ return [
'id' => 'ID', 'id' => 'ID',
'staff_id' => 'Staff ID', 'staff_id' => 'Mã nhân viên',
'card_number' => 'card_number', 'card_number' => 'Mã thẻ',
'device_id' => 'Device ID', 'device_id' => 'Thiết bị',
'door_id' => 'Door ID', 'door_id' => 'Cửa',
'in_out_state' => 'In Out State', 'in_out_state' => 'Trạng thái vào/ra',
'time' => 'Time', 'time' => 'Thời gian',
'event_type' => 'Event Type', 'event_type' => 'Mô tả sự kiện',
'staff_name' => 'Tên nhân viên',
'staff_department' => 'Phòng ban',
]; ];
} }
public static $stateArray = [
0 => "Vào",
1 => "Ra"
];
public function multiCreate($datas) { public function multiCreate($datas) {
$field = ['staff_id', 'card_number', 'device_id', 'door_id', 'in_out_state', 'time', 'event_type']; $field = ['staff_id', 'card_number', 'device_id', 'door_id', 'in_out_state', 'time', 'event_type'];
static::getDb()->createCommand()->batchInsert($this->tableName(), $field, $datas)->execute(); static::getDb()->createCommand()->batchInsert($this->tableName(), $field, $datas)->execute();
return true; return true;
} }
public function getStaff() {
return $this->hasOne(Staff::className(), ["id" => "staff_id"]);
}
public static function parseTime($time) { public static function parseTime($time) {
$temp = intval($time); $temp = intval($time);
$second = $temp % 60; $second = $temp % 60;

View File

@ -10,23 +10,25 @@ use app\models\Logs;
/** /**
* LogsSearch represents the model behind the search form of `app\models\Logs`. * LogsSearch represents the model behind the search form of `app\models\Logs`.
*/ */
class LogsSearch extends Logs class LogsSearch extends Logs {
{
public $staff_name;
public $staff_department;
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
public function rules() public function rules() {
{
return [ return [
[['id', 'staff_id', 'device_id', 'door_id', 'in_out_state', 'time', 'event_type'], 'integer'], [['id', 'staff_id', 'device_id', 'in_out_state', 'event_type', 'card_number', 'staff_department'], 'integer'],
[['staff_name'], 'safe'],
]; ];
} }
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
public function scenarios() public function scenarios() {
{
// bypass scenarios() implementation in the parent class // bypass scenarios() implementation in the parent class
return Model::scenarios(); return Model::scenarios();
} }
@ -38,9 +40,9 @@ class LogsSearch extends Logs
* *
* @return ActiveDataProvider * @return ActiveDataProvider
*/ */
public function search($params) public function search($params) {
{
$query = Logs::find(); $query = Logs::find();
$query->joinWith("staff");
// add conditions that should always apply here // add conditions that should always apply here
@ -56,6 +58,11 @@ class LogsSearch extends Logs
return $dataProvider; return $dataProvider;
} }
if ($this->staff_name)
$query->andFilterWhere(['LIKE', 'name', $this->staff_name]);
if ($this->staff_department)
$query->andFilterWhere(['department_id' => $this->staff_department]);
// grid filtering conditions // grid filtering conditions
$query->andFilterWhere([ $query->andFilterWhere([
'id' => $this->id, 'id' => $this->id,
@ -69,4 +76,5 @@ class LogsSearch extends Logs
return $dataProvider; return $dataProvider;
} }
} }

View File

@ -40,8 +40,8 @@ use yii\widgets\ActiveForm;
Báo cáo Báo cáo
</a> </a>
</li> </li>
<li> <li class="<?php if (in_array($this->context->id, ['user'])) echo "active"; ?>">
<a href="#"> <a href="<?php echo \yii\helpers\Url::to(['/user']); ?>">
Hệ thống Hệ thống
</a> </a>
</li> </li>

View File

@ -33,13 +33,18 @@
['label' => 'Cấp quyền truy cập', 'url' => ['/assign'], 'icon' => 'cogs'] ['label' => 'Cấp quyền truy cập', 'url' => ['/assign'], 'icon' => 'cogs']
]; ];
} }
if (in_array($this->context->id, ['user'])) {
$items = [
['label' => 'Người dùng', 'url' => ['/user'], 'icon' => 'users']
];
}
if (in_array($this->context->id, ['logs'])) { if (in_array($this->context->id, ['logs'])) {
$items = [ $items = [
['label' => 'Sự kiện hôm nay', 'url' => ['/logs'], 'icon' => 'clock-o'], ['label' => 'Sự kiện hôm nay', 'url' => ['/logs', 'type' => 'today'], 'icon' => 'clock-o'],
['label' => 'Sự kiện 3 ngày gần đây', 'url' => ['/logs/3-days'], 'icon' => 'calendar'], ['label' => 'Sự kiện 3 ngày gần đây', 'url' => ['/logs', 'type' => '3days'], 'icon' => 'calendar'],
['label' => 'Sự kiện tuần này', 'url' => ['/logs/this-week'], 'icon' => 'calendar'], ['label' => 'Sự kiện tuần này', 'url' => ['/logs', 'type' => 'thisWeek'], 'icon' => 'calendar'],
['label' => 'Sự kiện tuần trước', 'url' => ['/logs/last-week'], 'icon' => 'calendar'], ['label' => 'Sự kiện tuần trước', 'url' => ['/logs', 'type' => 'lastWeek'], 'icon' => 'calendar'],
['label' => 'Tất cả', 'url' => ['/logs/all'], 'icon' => 'calendar'] ['label' => 'Tất cả', 'url' => ['/logs', 'type' => 'all'], 'icon' => 'calendar']
]; ];
} }
?> ?>

View File

@ -2,17 +2,42 @@
{use class="yii\helpers\Url"} {use class="yii\helpers\Url"}
{use class="yii\grid\GridView"} {use class="yii\grid\GridView"}
{use class="yii\widgets\Pjax" type="block"} {use class="yii\widgets\Pjax" type="block"}
{use class="app\assets\DepartmentAsset"} {use class="app\assets\LogsAsset"}
{DepartmentAsset::register($this)|void} {LogsAsset::register($this)|void}
{block name='content'} {block name='content'}
<style>
.form-group{
margin-bottom: 0;
}
</style>
<div class="logs-index"> <div class="logs-index">
<div class="" style="font-size: 15px;"> <div class="row" style="font-size: 15px;">
<label class="action-button" onclick="common.form(this, '');" data-href="{Url::to(['tree'])}"> <div class="col-md-6">
<i class="fa fa-sitemap fa-1-5x"></i> Cây thư mục <label class="action-button" onclick="_export(this);" data-href="{Url::to(['export'])}">
</label> <i class="fa fa-download fa-1-5x"></i> Xuất
<label class="action-button" onclick="_logs(this);" data-href="{Url::to(['logs'])}"> </label>
<i class="fa fa-file fa-1-5x"></i> Ghi nhận hệ thống </div>
</label> <div class="col-md-6" style="padding-top: 5px;">
<div class="row">
<div class="form-group col-md-4 col-md-push-2">
<div class="input-group">
<div class="input-group-addon">Từ</div>
<input type='text' value="{$f|date_format:"%H:%M:%S %d/%m/%Y"}" class="form-control time-picker" name='FromTime' readonly="">
</div>
</div>
<div class="form-group col-md-4 col-md-push-2">
<div class="input-group">
<div class="input-group-addon">Đến</div>
<input type='text' value="{$t|date_format:"%H:%M:%S %d/%m/%Y"}" class="form-control time-picker" name='ToTime' readonly="">
</div>
</div>
<div class="col-md-2 col-md-push-2">
<button class="btn btn-primary btn-block" onclick="search(this);" data-href='{Url::to(['index'])}'>
<i class="fa fa-bar-chart"></i> Thống kê
</button>
</div>
</div>
</div>
</div> </div>
{Pjax id="department-list"} {Pjax id="department-list"}
{GridView::widget([ {GridView::widget([
@ -23,14 +48,64 @@
'class' => 'table table-striped table-bordered table-hover', 'class' => 'table table-striped table-bordered table-hover',
'style' => 'background:#fff;min-width:700px;' 'style' => 'background:#fff;min-width:700px;'
], ],
'rowOptions' => \app\helpers\LogsGrid::rowsColor(),
'columns' => [ 'columns' => [
[ [
'class' => 'yii\grid\SerialColumn', 'class' => 'yii\grid\SerialColumn',
'contentOptions' => ['class' => 'text-center'], 'contentOptions' => ['class' => 'text-center'],
'headerOptions' => ['class' => 'text-center', 'style' => 'width:3%'] 'headerOptions' => ['class' => 'text-center', 'style' => 'width:3%']
], ],
'time', [
'staff_id' 'attribute' => 'time',
'format' => 'raw',
'headerOptions' => ['style' => 'width:10%'],
'value' => \app\helpers\LogsGrid::time()
],
[
'attribute' => 'staff_id',
'contentOptions' => ['class' => 'text-center'],
'headerOptions' => ['style' => 'width:5%']
],
[
'attribute' => 'staff_name',
'format' => 'raw',
'value' => \app\helpers\LogsGrid::name()
],
[
'attribute' => 'staff_department',
'filter' => $departmentArray,
'format' => 'raw',
'value' => \app\helpers\LogsGrid::department($departmentArray)
],
'card_number',
[
'attribute' => 'device_id',
'format' => 'raw',
'filter' => $deviceArray,
'headerOptions' => ['style' => 'width:10%'],
'value' => \app\helpers\LogsGrid::device($deviceArray)
],
[
'attribute' => 'door_id',
'format' => 'raw',
'filter' => $deviceArray,
'headerOptions' => ['style' => 'width:10%'],
'value' => \app\helpers\LogsGrid::door($deviceArray)
],
[
'attribute' => 'in_out_state',
'format' => 'raw',
'filter' => $stateArray,
'headerOptions' => ['style' => 'width:8%'],
'contentOptions' => ['class' => 'text-center'],
'value' => \app\helpers\LogsGrid::state($stateArray)
],
[
'attribute' => 'event_type',
'format' => 'raw',
'filter' => $eventTypeArray,
'value' => \app\helpers\LogsGrid::eventType($eventTypeArray)
]
] ]
])} ])}
{/Pjax} {/Pjax}

View File

@ -4,41 +4,42 @@
{use class="app\assets\UserAsset"} {use class="app\assets\UserAsset"}
{UserAsset::register($this)|void} {UserAsset::register($this)|void}
{block name='content'} {block name='content'}
<div class="text-left"> <div class="logs-index">
<button class="btn btn-primary" onclick="common.form(this, 'user');" data-href="{Url::to(['create'])}"> <div class="" style="font-size: 15px;">
<i class="fa fa-plus"></i> Thêm mới <label class="action-button" onclick="common.form(this, 'user');" data-href="{Url::to(['create'])}">
</button> <i class="fa fa-plus-square fa-1-5x"></i> Thêm
</div> </label>
<br> </div>
{GridView::widget([ {GridView::widget([
'dataProvider' => $dataProvider, 'dataProvider' => $dataProvider,
'filterModel' => $searchModel, 'filterModel' => $searchModel,
'layout'=> \app\helpers\UserGrid::getLayout(), 'layout'=> \app\helpers\UserGrid::getLayout(),
'tableOptions' => [ 'tableOptions' => [
'class' => 'table table-striped table-bordered', 'class' => 'table table-striped table-bordered',
'style' => 'background:#fff;min-width:700px;' 'style' => 'background:#fff;min-width:700px;'
],
'columns' => [
['class' => 'yii\grid\SerialColumn'],
'username',
'first_name',
[
'attribute' => 'roleName',
'format' => 'raw',
'value' => \app\helpers\UserGrid::roles()
], ],
'phone_number', 'columns' => [
'email', ['class' => 'yii\grid\SerialColumn'],
[ 'username',
'template'=> \app\helpers\UserGrid::actionTemplate(), 'first_name',
'class' => 'yii\grid\ActionColumn', [
'contentOptions' => ['class' => 'text-center'], 'attribute' => 'roleName',
'headerOptions' => ['style' => 'width:10%'], 'format' => 'raw',
'buttons' => [ 'value' => \app\helpers\UserGrid::roles()
'update' => \app\helpers\UserGrid::update('user'), ],
'delete' => \app\helpers\UserGrid::delete('Bạn có chắc chắn muốn xóa người dùng này không?') 'phone_number',
'email',
[
'template'=> \app\helpers\UserGrid::actionTemplate(),
'class' => 'yii\grid\ActionColumn',
'contentOptions' => ['class' => 'text-center'],
'headerOptions' => ['style' => 'width:10%'],
'buttons' => [
'update' => \app\helpers\UserGrid::update('user'),
'delete' => \app\helpers\UserGrid::delete('Bạn có chắc chắn muốn xóa người dùng này không?')
]
] ]
] ]
] ])}
])} </div>
{/block} {/block}

View File

@ -186,6 +186,7 @@ common.dateTimePickerByClass = function (cls, format) {
$('.' + cls).datetimepicker({ $('.' + cls).datetimepicker({
locale: 'vi', locale: 'vi',
ignoreReadonly: true, ignoreReadonly: true,
sideBySide: true,
format: format format: format
}); });
}; };
@ -251,6 +252,9 @@ common.form = function (e, obj, bigSize) {
if (obj === 'schedule') { if (obj === 'schedule') {
common.dateTimePickerByClass("select-picker", "HH:mm"); common.dateTimePickerByClass("select-picker", "HH:mm");
} }
if (obj === 'user') {
$('#role').select2({tags: true, tokenSeparators: [',']});
}
}, },
error: function (jqXHR, textStatus, errorThrown) { error: function (jqXHR, textStatus, errorThrown) {
common.modalBlock(false); common.modalBlock(false);

11
web/js/logs.js Normal file
View File

@ -0,0 +1,11 @@
$(function () {
common.dateTimePickerByClass("time-picker", "HH:mm:ss DD/MM/YYYY");
});
function _export(e) {
window.location = $(e).attr("data-href") + "?from=" + $("input[name='FromTime']").val() + "&to=" + $("input[name='ToTime']").val();
}
function search(e) {
window.location = $(e).attr("data-href") + "?type=all" + "&from=" + $("input[name='FromTime']").val() + "&to=" + $("input[name='ToTime']").val();
}