From ad30699a52c2f2e74abb8a42bd52bba419d59799 Mon Sep 17 00:00:00 2001 From: dongpd Date: Tue, 20 Oct 2020 10:15:03 +0700 Subject: [PATCH] =?UTF-8?q?ph=C3=A2n=20trang=20t=C3=ACm=20ki=E1=BA=BFm=20n?= =?UTF-8?q?h=C3=A2n=20vi=C3=AAn=20=C4=91=E1=BB=83=20g=C3=A1n=20l=E1=BB=8Bc?= =?UTF-8?q?h=20tr=C3=ACnh?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- controllers/AssignController.php | 26 +++++++--- helpers/StaffGrid.php | 24 +++++++++ models/Door.php | 9 ++++ models/Staff.php | 4 +- views/assign/staff.tpl | 85 ++++++++++++++++++-------------- web/js/assign.js | 7 ++- 6 files changed, 108 insertions(+), 47 deletions(-) diff --git a/controllers/AssignController.php b/controllers/AssignController.php index c33758b2..df710600 100644 --- a/controllers/AssignController.php +++ b/controllers/AssignController.php @@ -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() ]); } } diff --git a/helpers/StaffGrid.php b/helpers/StaffGrid.php index 4e3c5579..76a11a82 100644 --- a/helpers/StaffGrid.php +++ b/helpers/StaffGrid.php @@ -6,6 +6,10 @@ use app\models\Logs; class StaffGrid extends CommonGrid { + public static function getLayout() { + return "
{summary}
{pager}
{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("
", $doors); + }; + } + } diff --git a/models/Door.php b/models/Door.php index 2ce47780..32a3fedd 100644 --- a/models/Door.php +++ b/models/Door.php @@ -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; + } + } diff --git a/models/Staff.php b/models/Staff.php index cd5dc248..cc01c633 100644 --- a/models/Staff.php +++ b/models/Staff.php @@ -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" ]; } diff --git a/views/assign/staff.tpl b/views/assign/staff.tpl index e1c37210..6d3fd6fd 100644 --- a/views/assign/staff.tpl +++ b/views/assign/staff.tpl @@ -1,41 +1,50 @@ +{use class="yii\grid\GridView"} +{use class="yii\widgets\Pjax" type="block"} -
- Danh sách có {count($staffs)} nhân viên. -
- - - - - - - - - - - - - {foreach from=$staffs item=s} - - - - - - - - - {/foreach} - -
- - Mã nhân viênTên nhân viênPhòng banLịch trìnhCửa
- - {$s->code} - {$s->name} - {$departmentArray[$s->department_id]|default:""}{$scheduleArray[$s->schedule_id]|default:""}{$s->doors}
\ No newline at end of file +{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' => "", + '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} \ No newline at end of file diff --git a/web/js/assign.js b/web/js/assign.js index ae72a3b3..9754e4c9 100644 --- a/web/js/assign.js +++ b/web/js/assign.js @@ -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);