phân trang tìm kiếm nhân viên để gán lịch trình
This commit is contained in:
parent
adffab016c
commit
ad30699a52
|
@ -10,8 +10,7 @@ use app\models\Door;
|
||||||
use app\models\Device;
|
use app\models\Device;
|
||||||
use yii\web\Controller;
|
use yii\web\Controller;
|
||||||
use yii\filters\VerbFilter;
|
use yii\filters\VerbFilter;
|
||||||
use yii\helpers\Html;
|
use app\models\StaffSearch;
|
||||||
use yii\helpers\Url;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* DeviceController implements the CRUD actions for Device model.
|
* DeviceController implements the CRUD actions for Device model.
|
||||||
|
@ -53,10 +52,18 @@ class AssignController extends Controller {
|
||||||
if (Yii::$app->request->isAjax) {
|
if (Yii::$app->request->isAjax) {
|
||||||
$model = new Department();
|
$model = new Department();
|
||||||
$lsDepartment = $model->departmentChilds(intval($id));
|
$lsDepartment = $model->departmentChilds(intval($id));
|
||||||
return $this->renderPartial("staff", [
|
|
||||||
|
$searchModel = new StaffSearch();
|
||||||
|
$dataProvider = $searchModel->search(Yii::$app->request->queryParams);
|
||||||
|
$dataProvider->query->andFilterWhere(['IN', 'department_id', $lsDepartment]);
|
||||||
|
$dataProvider->pagination->pageSize = 200;
|
||||||
|
|
||||||
|
return $this->renderAjax("staff", [
|
||||||
|
'searchModel' => $searchModel,
|
||||||
|
'dataProvider' => $dataProvider,
|
||||||
"departmentArray" => Department::departmentArray(),
|
"departmentArray" => Department::departmentArray(),
|
||||||
"scheduleArray" => Schedule::scheduleArray(),
|
"scheduleArray" => Schedule::scheduleArray(),
|
||||||
"staffs" => Staff::find()->andWhere(['IN', 'department_id', $lsDepartment])->all()
|
"doorsArray" => Door::doorsArray()
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -64,10 +71,17 @@ class AssignController extends Controller {
|
||||||
public function actionSearchStaff() {
|
public function actionSearchStaff() {
|
||||||
if (Yii::$app->request->post()) {
|
if (Yii::$app->request->post()) {
|
||||||
$post = Yii::$app->request->post();
|
$post = Yii::$app->request->post();
|
||||||
return $this->renderPartial("staff", [
|
$searchModel = new StaffSearch();
|
||||||
|
$dataProvider = $searchModel->search(Yii::$app->request->queryParams);
|
||||||
|
$dataProvider->query->andFilterWhere(['OR', ["LIKE", "name", $post['key']], ["LIKE", "code", $post['key']]]);
|
||||||
|
$dataProvider->pagination->pageSize = 200;
|
||||||
|
|
||||||
|
return $this->renderAjax("staff", [
|
||||||
|
'searchModel' => $searchModel,
|
||||||
|
'dataProvider' => $dataProvider,
|
||||||
"departmentArray" => Department::departmentArray(),
|
"departmentArray" => Department::departmentArray(),
|
||||||
"scheduleArray" => Schedule::scheduleArray(),
|
"scheduleArray" => Schedule::scheduleArray(),
|
||||||
"staffs" => Staff::find()->andWhere(['OR', ["LIKE", "name", $post['key']], ["LIKE", "code", $post['key']]])->all()
|
"doorsArray" => Door::doorsArray()
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,6 +6,10 @@ use app\models\Logs;
|
||||||
|
|
||||||
class StaffGrid extends CommonGrid {
|
class StaffGrid extends CommonGrid {
|
||||||
|
|
||||||
|
public static function getLayout() {
|
||||||
|
return "<div class='row'><div class='col-md-4' style='padding-top: 10px;padding-bottom:10px;'>{summary}</div><div class='col-md-8 text-right'>{pager}</div></div>{items}";
|
||||||
|
}
|
||||||
|
|
||||||
public static function department($array) {
|
public static function department($array) {
|
||||||
return function($model) use ($array) {
|
return function($model) use ($array) {
|
||||||
return isset($array[$model->department_id]) ? $array[$model->department_id] : "";
|
return isset($array[$model->department_id]) ? $array[$model->department_id] : "";
|
||||||
|
@ -73,4 +77,24 @@ class StaffGrid extends CommonGrid {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static function schedule($array) {
|
||||||
|
return function($model) use ($array) {
|
||||||
|
return isset($array[$model->schedule_id]) ? $array[$model->schedule_id] : "";
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function doors($array) {
|
||||||
|
return function($model) use ($array) {
|
||||||
|
$doors = [];
|
||||||
|
if ($model->door_access) {
|
||||||
|
$ls = json_decode($model->door_access, true);
|
||||||
|
foreach ($ls as $key => $value) {
|
||||||
|
if (isset($array[$value]))
|
||||||
|
$doors[] = $array[$value];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return implode("<br>", $doors);
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -54,4 +54,13 @@ class Door extends \yii\db\ActiveRecord {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static function doorsArray() {
|
||||||
|
$lists = self::find()->all();
|
||||||
|
$results = [];
|
||||||
|
foreach ($lists as $key => $value) {
|
||||||
|
$results[$value->id] = $value->name;
|
||||||
|
}
|
||||||
|
return $results;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -69,7 +69,9 @@ class Staff extends \yii\db\ActiveRecord {
|
||||||
'time_in' => "Thời gian vào",
|
'time_in' => "Thời gian vào",
|
||||||
'time_out' => "Thời gian ra",
|
'time_out' => "Thời gian ra",
|
||||||
'man_hour' => "Giờ công",
|
'man_hour' => "Giờ công",
|
||||||
'man_day' => "Ngày công"
|
'man_day' => "Ngày công",
|
||||||
|
'schedule' => "Lịch trình",
|
||||||
|
'doors' => "Cửa"
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,41 +1,50 @@
|
||||||
|
{use class="yii\grid\GridView"}
|
||||||
|
{use class="yii\widgets\Pjax" type="block"}
|
||||||
<style>
|
<style>
|
||||||
.choose-staff-schedule{
|
.pagination{
|
||||||
cursor: pointer;
|
margin: 0;
|
||||||
}
|
|
||||||
.choose-staff-schedule:hover{
|
|
||||||
background: #cecece;
|
|
||||||
}
|
}
|
||||||
</style>
|
</style>
|
||||||
<div>
|
{Pjax id="staff-list" enablePushState=false timeout=false enableReplaceState=false}
|
||||||
Danh sách có <b class="text-red">{count($staffs)}</b> nhân viên.
|
{GridView::widget([
|
||||||
</div>
|
'dataProvider' => $dataProvider,
|
||||||
<table class="table table-bordered table-striped table-staff-schedule" style="background: #fff;">
|
'filterModel' => null,
|
||||||
<thead>
|
'layout'=> \app\helpers\StaffGrid::getLayout(),
|
||||||
<tr class="info">
|
'tableOptions' => [
|
||||||
<th style="width: 5%;" class="text-center">
|
'class' => 'table table-striped table-bordered table-hover',
|
||||||
<input type='checkbox' value='0' class='checkbox-staff-schedule' id='checkall-staff-schedule'>
|
'style' => 'background:#fff;min-width:700px;'
|
||||||
</th>
|
],
|
||||||
<th style="width: 20%;">Mã nhân viên</th>
|
'rowOptions' => \app\helpers\CommonGrid::rows("staff", true),
|
||||||
<th>Tên nhân viên</th>
|
'columns' => [
|
||||||
<th>Phòng ban</th>
|
[
|
||||||
<th>Lịch trình</th>
|
'class' => 'yii\grid\SerialColumn',
|
||||||
<th>Cửa</th>
|
'contentOptions' => ['class' => 'text-center'],
|
||||||
</tr>
|
'headerOptions' => ['class' => 'text-center', 'style' => 'width:3%']
|
||||||
</thead>
|
],
|
||||||
<tbody>
|
[
|
||||||
{foreach from=$staffs item=s}
|
'header' => "<input type='checkbox' value='0' class='checkbox-staff-schedule' id='checkall-staff-schedule'>",
|
||||||
<tr>
|
'format' => 'raw',
|
||||||
<td class="text-center">
|
'contentOptions' => ['class' => 'text-center'],
|
||||||
<input type='checkbox' value='{$s->id}' name='checkbox-staff-schedule' class='checkbox-staff-schedule'>
|
'headerOptions' => ['class' => 'text-center', 'style' => 'width:3%'],
|
||||||
</td>
|
'value' => \app\helpers\CommonGrid::checkbox("staff-schedule", false)
|
||||||
<td>{$s->code}</td>
|
],
|
||||||
<td class="choose-staff-schedule">
|
'code',
|
||||||
{$s->name}
|
'name',
|
||||||
</td>
|
'card_number',
|
||||||
<td>{$departmentArray[$s->department_id]|default:""}</td>
|
[
|
||||||
<td id="schedule-staff-results-{$s->id}">{$scheduleArray[$s->schedule_id]|default:""}</td>
|
'attribute' => 'department_id',
|
||||||
<td id="schedule-door-results-{$s->id}">{$s->doors}</td>
|
'value' => \app\helpers\StaffGrid::department($departmentArray)
|
||||||
</tr>
|
],
|
||||||
{/foreach}
|
[
|
||||||
</tbody>
|
'attribute' => 'schedule',
|
||||||
</table>
|
'value' => \app\helpers\StaffGrid::schedule($scheduleArray)
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'attribute' => 'doors',
|
||||||
|
'format' => 'raw',
|
||||||
|
'headerOptions' => ['style' => 'width:15%'],
|
||||||
|
'value' => \app\helpers\StaffGrid::doors($doorsArray)
|
||||||
|
]
|
||||||
|
]
|
||||||
|
])}
|
||||||
|
{/Pjax}
|
|
@ -25,6 +25,9 @@ schedule.chooseDepartment = function (e) {
|
||||||
$("#schedule-search-staff").html(data);
|
$("#schedule-search-staff").html(data);
|
||||||
$(".department-schedule").removeClass("department-schedule-active");
|
$(".department-schedule").removeClass("department-schedule-active");
|
||||||
$(e).addClass("department-schedule-active");
|
$(e).addClass("department-schedule-active");
|
||||||
|
$("#staff-list").on('pjax:success', function () {
|
||||||
|
common.checkboxInit("staff-schedule");
|
||||||
|
});
|
||||||
common.checkboxInit("staff-schedule");
|
common.checkboxInit("staff-schedule");
|
||||||
},
|
},
|
||||||
error: function (jqXHR, textStatus, errorThrown) {
|
error: function (jqXHR, textStatus, errorThrown) {
|
||||||
|
@ -80,9 +83,9 @@ schedule.setSchedule = function (e) {
|
||||||
url: $(e).attr("data-href"),
|
url: $(e).attr("data-href"),
|
||||||
type: 'POST',
|
type: 'POST',
|
||||||
data: {
|
data: {
|
||||||
staffs: staffs,
|
schedule: $("select[name='ScheduleLists']").val(),
|
||||||
doors: doors,
|
doors: doors,
|
||||||
schedule: $("select[name='ScheduleLists']").val()
|
staffs: staffs
|
||||||
},
|
},
|
||||||
success: function (data) {
|
success: function (data) {
|
||||||
common.modalBlock(false);
|
common.modalBlock(false);
|
||||||
|
|
Loading…
Reference in New Issue
Block a user