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 yii\web\Controller;
|
||||
use yii\filters\VerbFilter;
|
||||
use yii\helpers\Html;
|
||||
use yii\helpers\Url;
|
||||
use app\models\StaffSearch;
|
||||
|
||||
/**
|
||||
* DeviceController implements the CRUD actions for Device model.
|
||||
|
@ -53,10 +52,18 @@ class AssignController extends Controller {
|
|||
if (Yii::$app->request->isAjax) {
|
||||
$model = new Department();
|
||||
$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(),
|
||||
"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() {
|
||||
if (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(),
|
||||
"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 {
|
||||
|
||||
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) {
|
||||
return function($model) use ($array) {
|
||||
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;
|
||||
}
|
||||
|
||||
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_out' => "Thời gian ra",
|
||||
'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>
|
||||
.choose-staff-schedule{
|
||||
cursor: pointer;
|
||||
}
|
||||
.choose-staff-schedule:hover{
|
||||
background: #cecece;
|
||||
.pagination{
|
||||
margin: 0;
|
||||
}
|
||||
</style>
|
||||
<div>
|
||||
Danh sách có <b class="text-red">{count($staffs)}</b> nhân viên.
|
||||
</div>
|
||||
<table class="table table-bordered table-striped table-staff-schedule" style="background: #fff;">
|
||||
<thead>
|
||||
<tr class="info">
|
||||
<th style="width: 5%;" class="text-center">
|
||||
<input type='checkbox' value='0' class='checkbox-staff-schedule' id='checkall-staff-schedule'>
|
||||
</th>
|
||||
<th style="width: 20%;">Mã nhân viên</th>
|
||||
<th>Tên nhân viên</th>
|
||||
<th>Phòng ban</th>
|
||||
<th>Lịch trình</th>
|
||||
<th>Cửa</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{foreach from=$staffs item=s}
|
||||
<tr>
|
||||
<td class="text-center">
|
||||
<input type='checkbox' value='{$s->id}' name='checkbox-staff-schedule' class='checkbox-staff-schedule'>
|
||||
</td>
|
||||
<td>{$s->code}</td>
|
||||
<td class="choose-staff-schedule">
|
||||
{$s->name}
|
||||
</td>
|
||||
<td>{$departmentArray[$s->department_id]|default:""}</td>
|
||||
<td id="schedule-staff-results-{$s->id}">{$scheduleArray[$s->schedule_id]|default:""}</td>
|
||||
<td id="schedule-door-results-{$s->id}">{$s->doors}</td>
|
||||
</tr>
|
||||
{/foreach}
|
||||
</tbody>
|
||||
</table>
|
||||
{Pjax id="staff-list" enablePushState=false timeout=false enableReplaceState=false}
|
||||
{GridView::widget([
|
||||
'dataProvider' => $dataProvider,
|
||||
'filterModel' => null,
|
||||
'layout'=> \app\helpers\StaffGrid::getLayout(),
|
||||
'tableOptions' => [
|
||||
'class' => 'table table-striped table-bordered table-hover',
|
||||
'style' => 'background:#fff;min-width:700px;'
|
||||
],
|
||||
'rowOptions' => \app\helpers\CommonGrid::rows("staff", true),
|
||||
'columns' => [
|
||||
[
|
||||
'class' => 'yii\grid\SerialColumn',
|
||||
'contentOptions' => ['class' => 'text-center'],
|
||||
'headerOptions' => ['class' => 'text-center', 'style' => 'width:3%']
|
||||
],
|
||||
[
|
||||
'header' => "<input type='checkbox' value='0' class='checkbox-staff-schedule' id='checkall-staff-schedule'>",
|
||||
'format' => 'raw',
|
||||
'contentOptions' => ['class' => 'text-center'],
|
||||
'headerOptions' => ['class' => 'text-center', 'style' => 'width:3%'],
|
||||
'value' => \app\helpers\CommonGrid::checkbox("staff-schedule", false)
|
||||
],
|
||||
'code',
|
||||
'name',
|
||||
'card_number',
|
||||
[
|
||||
'attribute' => 'department_id',
|
||||
'value' => \app\helpers\StaffGrid::department($departmentArray)
|
||||
],
|
||||
[
|
||||
'attribute' => 'schedule',
|
||||
'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);
|
||||
$(".department-schedule").removeClass("department-schedule-active");
|
||||
$(e).addClass("department-schedule-active");
|
||||
$("#staff-list").on('pjax:success', function () {
|
||||
common.checkboxInit("staff-schedule");
|
||||
});
|
||||
common.checkboxInit("staff-schedule");
|
||||
},
|
||||
error: function (jqXHR, textStatus, errorThrown) {
|
||||
|
@ -80,9 +83,9 @@ schedule.setSchedule = function (e) {
|
|||
url: $(e).attr("data-href"),
|
||||
type: 'POST',
|
||||
data: {
|
||||
staffs: staffs,
|
||||
schedule: $("select[name='ScheduleLists']").val(),
|
||||
doors: doors,
|
||||
schedule: $("select[name='ScheduleLists']").val()
|
||||
staffs: staffs
|
||||
},
|
||||
success: function (data) {
|
||||
common.modalBlock(false);
|
||||
|
|
Loading…
Reference in New Issue
Block a user