update thống kê

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

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() {
return [
'id' => 'ID',
'staff_id' => 'Staff ID',
'card_number' => 'card_number',
'device_id' => 'Device ID',
'door_id' => 'Door ID',
'in_out_state' => 'In Out State',
'time' => 'Time',
'event_type' => 'Event Type',
'staff_id' => 'Mã nhân viên',
'card_number' => 'Mã thẻ',
'device_id' => 'Thiết bị',
'door_id' => 'Cửa',
'in_out_state' => 'Trạng thái vào/ra',
'time' => 'Thời gian',
'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) {
$field = ['staff_id', 'card_number', 'device_id', 'door_id', 'in_out_state', 'time', 'event_type'];
static::getDb()->createCommand()->batchInsert($this->tableName(), $field, $datas)->execute();
return true;
}
public function getStaff() {
return $this->hasOne(Staff::className(), ["id" => "staff_id"]);
}
public static function parseTime($time) {
$temp = intval($time);
$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`.
*/
class LogsSearch extends Logs
{
class LogsSearch extends Logs {
public $staff_name;
public $staff_department;
/**
* {@inheritdoc}
*/
public function rules()
{
public function rules() {
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}
*/
public function scenarios()
{
public function scenarios() {
// bypass scenarios() implementation in the parent class
return Model::scenarios();
}
@@ -38,9 +40,9 @@ class LogsSearch extends Logs
*
* @return ActiveDataProvider
*/
public function search($params)
{
public function search($params) {
$query = Logs::find();
$query->joinWith("staff");
// add conditions that should always apply here
@@ -56,6 +58,11 @@ class LogsSearch extends Logs
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
$query->andFilterWhere([
'id' => $this->id,
@@ -69,4 +76,5 @@ class LogsSearch extends Logs
return $dataProvider;
}
}