update Staff full CRUD
This commit is contained in:
parent
6272bec1b7
commit
2a8b009c12
|
@ -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 10, 2020 at 07:36 AM
|
-- Generation Time: Oct 10, 2020 at 11:10 AM
|
||||||
-- Server version: 10.4.8-MariaDB
|
-- Server version: 10.4.8-MariaDB
|
||||||
-- PHP Version: 7.1.33
|
-- PHP Version: 7.1.33
|
||||||
|
|
||||||
|
@ -158,6 +158,37 @@ CREATE TABLE `device` (
|
||||||
|
|
||||||
-- --------------------------------------------------------
|
-- --------------------------------------------------------
|
||||||
|
|
||||||
|
--
|
||||||
|
-- Table structure for table `staff`
|
||||||
|
--
|
||||||
|
|
||||||
|
CREATE TABLE `staff` (
|
||||||
|
`id` int(11) NOT NULL,
|
||||||
|
`code` int(11) NOT NULL,
|
||||||
|
`name` varchar(100) NOT NULL,
|
||||||
|
`card_number` int(11) NOT NULL DEFAULT 0,
|
||||||
|
`department_id` int(11) NOT NULL DEFAULT 0,
|
||||||
|
`gender` varchar(10) NOT NULL,
|
||||||
|
`birthday` int(11) NOT NULL DEFAULT 0,
|
||||||
|
`email` varchar(100) DEFAULT NULL,
|
||||||
|
`phone` varchar(20) DEFAULT NULL,
|
||||||
|
`date_in` int(11) NOT NULL DEFAULT 0,
|
||||||
|
`address` text DEFAULT NULL,
|
||||||
|
`created_at` int(11) NOT NULL DEFAULT 0,
|
||||||
|
`modified_at` int(11) NOT NULL DEFAULT 0
|
||||||
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
|
||||||
|
|
||||||
|
--
|
||||||
|
-- Dumping data for table `staff`
|
||||||
|
--
|
||||||
|
|
||||||
|
INSERT INTO `staff` (`id`, `code`, `name`, `card_number`, `department_id`, `gender`, `birthday`, `email`, `phone`, `date_in`, `address`, `created_at`, `modified_at`) VALUES
|
||||||
|
(1, 1, 'Phạm Đức Đông', 1000001, 1, 'M', 691231867, '', '', 1602319867, '', 1602319867, 1602319867),
|
||||||
|
(2, 2, 'Ngô Văn Dũng', 10000002, 1, 'M', 608719882, '', '', 1602319882, '', 1602319882, 1602319882),
|
||||||
|
(3, 3, 'Hoàng Hồng Sơn', 10000003, 1, 'M', 622544932, NULL, NULL, 1602320932, NULL, 1602320932, 1602320932);
|
||||||
|
|
||||||
|
-- --------------------------------------------------------
|
||||||
|
|
||||||
--
|
--
|
||||||
-- Table structure for table `system_logs`
|
-- Table structure for table `system_logs`
|
||||||
--
|
--
|
||||||
|
@ -190,7 +221,15 @@ INSERT INTO `system_logs` (`id`, `user_id`, `time`, `action`, `description`, `ty
|
||||||
(12, 1, 1602226793, 'delete', 'Xóa khu vực: Khu vực 1', 'area'),
|
(12, 1, 1602226793, 'delete', 'Xóa khu vực: Khu vực 1', 'area'),
|
||||||
(13, 1, 1602226793, 'delete', 'Xóa khu vực: Khu vực 2', 'area'),
|
(13, 1, 1602226793, 'delete', 'Xóa khu vực: Khu vực 2', 'area'),
|
||||||
(14, 1, 1602227006, 'insert', 'Thêm mới khu vực: Khu vực 2', 'area'),
|
(14, 1, 1602227006, 'insert', 'Thêm mới khu vực: Khu vực 2', 'area'),
|
||||||
(15, 1, 1602227907, 'insert', 'Thêm mới khu vực: Khu vực 1', 'area');
|
(15, 1, 1602227907, 'insert', 'Thêm mới khu vực: Khu vực 1', 'area'),
|
||||||
|
(16, 1, 1602316450, 'insert', 'Thêm mới nhân viên: Phạm Đức Đông', 'staff'),
|
||||||
|
(17, 1, 1602317528, 'update', 'Chỉnh sửa nhân viên: Phạm Đức Đông', 'staff'),
|
||||||
|
(18, 1, 1602318491, 'update', 'Chỉnh sửa nhân viên: Phạm Đức Đông', 'staff'),
|
||||||
|
(19, 1, 1602318858, 'insert', 'Thêm mới nhân viên: Ngô Văn Dũng', 'staff'),
|
||||||
|
(20, 1, 1602318893, 'delete', 'Xóa 2 nhân viên', 'staff'),
|
||||||
|
(21, 1, 1602319867, 'insert', 'Thêm mới nhân viên: Phạm Đức Đông', 'staff'),
|
||||||
|
(22, 1, 1602319882, 'insert', 'Thêm mới nhân viên: Ngô Văn Dũng', 'staff'),
|
||||||
|
(23, 1, 1602320932, 'import', 'Nhập dữ liệu: 1 nhân viên mới', 'staff');
|
||||||
|
|
||||||
-- --------------------------------------------------------
|
-- --------------------------------------------------------
|
||||||
|
|
||||||
|
@ -269,6 +308,12 @@ ALTER TABLE `department`
|
||||||
ALTER TABLE `device`
|
ALTER TABLE `device`
|
||||||
ADD PRIMARY KEY (`id`);
|
ADD PRIMARY KEY (`id`);
|
||||||
|
|
||||||
|
--
|
||||||
|
-- Indexes for table `staff`
|
||||||
|
--
|
||||||
|
ALTER TABLE `staff`
|
||||||
|
ADD PRIMARY KEY (`id`);
|
||||||
|
|
||||||
--
|
--
|
||||||
-- Indexes for table `system_logs`
|
-- Indexes for table `system_logs`
|
||||||
--
|
--
|
||||||
|
@ -304,11 +349,17 @@ ALTER TABLE `department`
|
||||||
ALTER TABLE `device`
|
ALTER TABLE `device`
|
||||||
MODIFY `id` int(11) NOT NULL AUTO_INCREMENT;
|
MODIFY `id` int(11) NOT NULL AUTO_INCREMENT;
|
||||||
|
|
||||||
|
--
|
||||||
|
-- AUTO_INCREMENT for table `staff`
|
||||||
|
--
|
||||||
|
ALTER TABLE `staff`
|
||||||
|
MODIFY `id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=4;
|
||||||
|
|
||||||
--
|
--
|
||||||
-- AUTO_INCREMENT for table `system_logs`
|
-- AUTO_INCREMENT for table `system_logs`
|
||||||
--
|
--
|
||||||
ALTER TABLE `system_logs`
|
ALTER TABLE `system_logs`
|
||||||
MODIFY `id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=16;
|
MODIFY `id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=24;
|
||||||
|
|
||||||
--
|
--
|
||||||
-- AUTO_INCREMENT for table `user`
|
-- AUTO_INCREMENT for table `user`
|
||||||
|
|
23
assets/StaffAsset.php
Normal file
23
assets/StaffAsset.php
Normal file
|
@ -0,0 +1,23 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace app\assets;
|
||||||
|
|
||||||
|
use yii\web\AssetBundle;
|
||||||
|
|
||||||
|
class StaffAsset extends AssetBundle {
|
||||||
|
|
||||||
|
public $basePath = '@webroot';
|
||||||
|
public $baseUrl = '@web';
|
||||||
|
public $css = [
|
||||||
|
];
|
||||||
|
public $js = [
|
||||||
|
'js/staff.js'
|
||||||
|
];
|
||||||
|
public $depends = [
|
||||||
|
'yii\web\YiiAsset',
|
||||||
|
'app\assets\AppAsset',
|
||||||
|
// 'yii\jui\JuiAsset',
|
||||||
|
'yii\bootstrap\BootstrapAsset',
|
||||||
|
];
|
||||||
|
|
||||||
|
}
|
262
controllers/StaffController.php
Normal file
262
controllers/StaffController.php
Normal file
|
@ -0,0 +1,262 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace app\controllers;
|
||||||
|
|
||||||
|
use Yii;
|
||||||
|
use app\models\Staff;
|
||||||
|
use app\models\StaffSearch;
|
||||||
|
use app\models\Department;
|
||||||
|
use app\models\common;
|
||||||
|
use yii\web\Controller;
|
||||||
|
use yii\web\NotFoundHttpException;
|
||||||
|
use yii\filters\VerbFilter;
|
||||||
|
use yii\helpers\Html;
|
||||||
|
use yii\helpers\Url;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* StaffController implements the CRUD actions for Staff model.
|
||||||
|
*/
|
||||||
|
class StaffController extends Controller {
|
||||||
|
|
||||||
|
public function init() {
|
||||||
|
parent::init();
|
||||||
|
if (Yii::$app->user->isGuest)
|
||||||
|
return $this->redirect(['/site/login']);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritdoc}
|
||||||
|
*/
|
||||||
|
public function behaviors() {
|
||||||
|
return [
|
||||||
|
'verbs' => [
|
||||||
|
'class' => VerbFilter::className(),
|
||||||
|
'actions' => [
|
||||||
|
'delete' => ['POST'],
|
||||||
|
],
|
||||||
|
],
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
public function actionIndex() {
|
||||||
|
$this->view->title = 'Nhân viên';
|
||||||
|
$searchModel = new StaffSearch();
|
||||||
|
$dataProvider = $searchModel->search(Yii::$app->request->queryParams);
|
||||||
|
|
||||||
|
return $this->render('index', [
|
||||||
|
'searchModel' => $searchModel,
|
||||||
|
'dataProvider' => $dataProvider,
|
||||||
|
"departmentArray" => Department::departmentArray(),
|
||||||
|
"genderArray" => Staff::$genderArray
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function actionCreate() {
|
||||||
|
$model = new Staff();
|
||||||
|
Yii::$app->response->format = "json";
|
||||||
|
if (Yii::$app->request->post()) {
|
||||||
|
$data = Yii::$app->request->post();
|
||||||
|
$check = Staff::findOne(['code' => $data['Code']]);
|
||||||
|
if ($check)
|
||||||
|
return ["status" => false, "type" => "code"];
|
||||||
|
$check = Staff::findOne(['card_number' => $data['CardNumber']]);
|
||||||
|
if ($check)
|
||||||
|
return ["status" => false, "type" => "card"];
|
||||||
|
if ($model->create($data)) {
|
||||||
|
common::insertSystemLogs(["action" => "insert", "description" => "Thêm mới nhân viên: " . $data["Name"], "type" => Yii::$app->controller->id]);
|
||||||
|
return ["status" => true];
|
||||||
|
} else
|
||||||
|
return ["status" => false, "type" => "error"];
|
||||||
|
} else {
|
||||||
|
return [
|
||||||
|
"title" => Html::tag("i", "", ["class" => "fa fa-plus-square"]) . " Thêm",
|
||||||
|
"form" => $this->renderPartial("form", [
|
||||||
|
"model" => $model,
|
||||||
|
"url" => Url::to(["create"]),
|
||||||
|
"departmentArray" => Department::departmentArray(),
|
||||||
|
"genderArray" => Staff::$genderArray
|
||||||
|
])
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function actionUpdate($id) {
|
||||||
|
$model = $this->findModel($id);
|
||||||
|
Yii::$app->response->format = "json";
|
||||||
|
if (Yii::$app->request->post()) {
|
||||||
|
$data = Yii::$app->request->post();
|
||||||
|
$check = Staff::findOne(['code' => $data['Code']]);
|
||||||
|
if ($check && $check->id != $id)
|
||||||
|
return ["status" => false, "type" => "code"];
|
||||||
|
$check = Staff::findOne(['card_number' => $data['CardNumber']]);
|
||||||
|
if ($check && $check->id != $id)
|
||||||
|
return ["status" => false, "type" => "card"];
|
||||||
|
$model->name = $data["Name"];
|
||||||
|
$model->code = $data["Code"];
|
||||||
|
$model->card_number = $data["CardNumber"] != "" ? $data["CardNumber"] : 0;
|
||||||
|
$model->department_id = $data["Department"];
|
||||||
|
$model->gender = $data["Gender"];
|
||||||
|
$model->birthday = date_format(date_create_from_format('d/m/Y', $data["BirthDay"]), 'U');
|
||||||
|
$model->email = $data["Email"];
|
||||||
|
$model->phone = $data["Phone"];
|
||||||
|
$model->date_in = date_format(date_create_from_format('d/m/Y', $data["DateIn"]), 'U');
|
||||||
|
$model->address = $data["Address"];
|
||||||
|
$model->modified_at = time();
|
||||||
|
if ($model->save()) {
|
||||||
|
common::insertSystemLogs(["action" => "update", "description" => "Chỉnh sửa nhân viên: " . $data["Name"], "type" => Yii::$app->controller->id]);
|
||||||
|
return ["status" => true];
|
||||||
|
} else
|
||||||
|
return ["status" => false, "type" => "error"];
|
||||||
|
} else {
|
||||||
|
return [
|
||||||
|
"title" => Html::tag("i", "", ["class" => "fa fa-edit"]) . " Tùy chỉnh",
|
||||||
|
"form" => $this->renderPartial("form", [
|
||||||
|
"model" => $model,
|
||||||
|
"url" => Url::to(["update", "id" => $id]),
|
||||||
|
"departmentArray" => Department::departmentArray(),
|
||||||
|
"genderArray" => Staff::$genderArray
|
||||||
|
])
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function actionDelete() {
|
||||||
|
if (Yii::$app->request->post()) {
|
||||||
|
$lists = Yii::$app->request->post("lists");
|
||||||
|
Staff::deleteAll(["IN", "id", $lists]);
|
||||||
|
common::insertSystemLogs(["action" => "delete", "description" => "Xóa " . count($lists) . " nhân viên", "type" => Yii::$app->controller->id]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function findModel($id) {
|
||||||
|
if (($model = Staff::findOne($id)) !== null) {
|
||||||
|
return $model;
|
||||||
|
}
|
||||||
|
|
||||||
|
throw new NotFoundHttpException('The requested page does not exist.');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function actionExport() {
|
||||||
|
$objPHPExcel = new \PHPExcel();
|
||||||
|
$objPHPExcel->setActiveSheetIndex(0);
|
||||||
|
$toExcelFile[] = ["Mã nhân viên", "Tên nhân viên", "Số thẻ", "Phòng ban", "Giới tính", "Ngày sinh", "Email", "Điện thoại", "Ngày bắt đầu làm việc", "Địa chỉ"];
|
||||||
|
$staffs = Staff::find()->all();
|
||||||
|
$departmentArray = Department::departmentArray();
|
||||||
|
foreach ($staffs as $k => $v) {
|
||||||
|
$ExportData[] = $v->code;
|
||||||
|
$ExportData[] = $v->name;
|
||||||
|
$ExportData[] = $v->card_number;
|
||||||
|
$ExportData[] = isset($departmentArray[$v->department_id]) ? $departmentArray[$v->department_id] : "";
|
||||||
|
$ExportData[] = $v->gender;
|
||||||
|
$ExportData[] = date("d/m/Y", $v->birthday);
|
||||||
|
$ExportData[] = $v->email;
|
||||||
|
$ExportData[] = $v->phone;
|
||||||
|
$ExportData[] = date("d/m/Y", $v->date_in);
|
||||||
|
$ExportData[] = $v->address;
|
||||||
|
$toExcelFile[] = $ExportData;
|
||||||
|
unset($ExportData);
|
||||||
|
}
|
||||||
|
$totals = count($staffs) + 1;
|
||||||
|
$activeSheet = $objPHPExcel->getActiveSheet();
|
||||||
|
$activeSheet->getStyle("A1:J" . $totals)->getFont()->setName('Time New Roman')->setSize(10);
|
||||||
|
$activeSheet->getStyle("A1:J1")->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:J" . $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="staff_' . date("YmdHis") . '.xlsx"');
|
||||||
|
header('Cache-Control: max-age=0');
|
||||||
|
common::SaveViaTempFile($objWriter);
|
||||||
|
exit();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function actionUpload() {
|
||||||
|
if (Yii::$app->request->post()) {
|
||||||
|
$common = new common();
|
||||||
|
$fileUploads = $common->UploadFile("file", ["XLS", "XLSX"], "excel");
|
||||||
|
$file_type = \PHPExcel_IOFactory::identify($fileUploads);
|
||||||
|
$objReader = \PHPExcel_IOFactory::createReader($file_type);
|
||||||
|
$objPHPExcel = $objReader->load($fileUploads);
|
||||||
|
$sheet_data = $objPHPExcel->getActiveSheet()->toArray(null, true, true, true);
|
||||||
|
Yii::$app->response->format = 'json';
|
||||||
|
return [
|
||||||
|
"title" => Html::tag("i", "", ["class" => "fa fa-upload"]) . " Nhập",
|
||||||
|
"form" => $this->renderPartial("import", [
|
||||||
|
"data" => $sheet_data,
|
||||||
|
"model" => new Staff()
|
||||||
|
])
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function actionImport() {
|
||||||
|
if (Yii::$app->request->post()) {
|
||||||
|
$post = Yii::$app->request->post("lists");
|
||||||
|
$datas = [];
|
||||||
|
foreach ($post as $key => $value) {
|
||||||
|
$val = json_decode($value, true);
|
||||||
|
$parent = Department::findOne(["name" => $val["D"]]);
|
||||||
|
$datas[] = [
|
||||||
|
$val["A"],
|
||||||
|
$val["B"],
|
||||||
|
$val["C"],
|
||||||
|
$parent ? $parent->code : 1,
|
||||||
|
in_array($val["E"], ["M", "F"]) ? $val["E"] : "M",
|
||||||
|
$val["F"] !== "" ? date_format(date_create_from_format('d/m/Y', $val["F"]), 'U') : 0,
|
||||||
|
$val["G"],
|
||||||
|
$val["H"],
|
||||||
|
$val["I"] !== "" ? date_format(date_create_from_format('d/m/Y', $val["I"]), 'U') : 0,
|
||||||
|
$val["J"],
|
||||||
|
time(),
|
||||||
|
time()
|
||||||
|
];
|
||||||
|
}
|
||||||
|
$model = new Staff();
|
||||||
|
$model->multiCreate($datas);
|
||||||
|
common::insertSystemLogs(["action" => "import", "description" => "Nhập dữ liệu: " . count($post) . " nhân viên mới", "type" => Yii::$app->controller->id]);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function actionLogs() {
|
||||||
|
if (Yii::$app->request->isAjax) {
|
||||||
|
Yii::$app->response->format = "json";
|
||||||
|
return [
|
||||||
|
"title" => Html::tag("i", "", ["class" => "fa fa-file"]) . " Ghi nhận hệ thống",
|
||||||
|
"form" => \app\widgets\SystemLogsView::widget(['type' => Yii::$app->controller->id])
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -62,18 +62,18 @@ class CommonGrid {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function checkbox($type) {
|
public static function checkbox($type, $haveRoot = true) {
|
||||||
return function($model) use ($type) {
|
return function($model) use ($type, $haveRoot) {
|
||||||
if ($model->id == 1)
|
if ($model->id == 1 && $haveRoot)
|
||||||
return "";
|
return "";
|
||||||
return "<input type='checkbox' value='{$model->id}' name='checkbox-{$type}' class='checkbox-{$type}'>";
|
return "<input type='checkbox' value='{$model->id}' name='checkbox-{$type}' class='checkbox-{$type}'>";
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function rows($type) {
|
public static function rows($type, $bigSize = false) {
|
||||||
return function($model, $index, $widget, $grid) use ($type) {
|
return function($model, $index, $widget, $grid) use ($type, $bigSize) {
|
||||||
return [
|
return [
|
||||||
"ondblclick" => "common.form(this, '{$type}');",
|
"ondblclick" => "common.form(this, '{$type}', {$bigSize});",
|
||||||
"style" => "cursor: pointer;",
|
"style" => "cursor: pointer;",
|
||||||
"data" => [
|
"data" => [
|
||||||
"href" => Url::to(["update", "id" => $model->id])
|
"href" => Url::to(["update", "id" => $model->id])
|
||||||
|
|
31
helpers/StaffGrid.php
Normal file
31
helpers/StaffGrid.php
Normal file
|
@ -0,0 +1,31 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace app\helpers;
|
||||||
|
|
||||||
|
class StaffGrid extends CommonGrid {
|
||||||
|
|
||||||
|
public static function department($array) {
|
||||||
|
return function($model) use ($array) {
|
||||||
|
return isset($array[$model->department_id]) ? $array[$model->department_id] : "";
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function gender($array) {
|
||||||
|
return function($model) use ($array) {
|
||||||
|
return isset($array[$model->gender]) ? $array[$model->gender] : "";
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function birthday() {
|
||||||
|
return function($model) {
|
||||||
|
return date("d/m/Y", $model->birthday);
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function dateIn() {
|
||||||
|
return function($model) {
|
||||||
|
return date("d/m/Y", $model->date_in);
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
111
models/Staff.php
Normal file
111
models/Staff.php
Normal file
|
@ -0,0 +1,111 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace app\models;
|
||||||
|
|
||||||
|
use Yii;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This is the model class for table "staff".
|
||||||
|
*
|
||||||
|
* @property int $id
|
||||||
|
* @property int $code
|
||||||
|
* @property string $name
|
||||||
|
* @property int $card_number
|
||||||
|
* @property int $department_id
|
||||||
|
* @property string $gender
|
||||||
|
* @property int $birthday
|
||||||
|
* @property string $email
|
||||||
|
* @property string $phone
|
||||||
|
* @property int $date_in
|
||||||
|
* @property string $address
|
||||||
|
* @property int $created_at
|
||||||
|
* @property int $modified_at
|
||||||
|
*/
|
||||||
|
class Staff extends \yii\db\ActiveRecord {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritdoc}
|
||||||
|
*/
|
||||||
|
public static function tableName() {
|
||||||
|
return 'staff';
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritdoc}
|
||||||
|
*/
|
||||||
|
public function rules() {
|
||||||
|
return [
|
||||||
|
[['code', 'name', 'gender'], 'required'],
|
||||||
|
[['code', 'card_number', 'department_id', 'birthday', 'date_in', 'created_at', 'modified_at'], 'integer'],
|
||||||
|
[['address'], 'string'],
|
||||||
|
[['name', 'email'], 'string', 'max' => 100],
|
||||||
|
[['gender'], 'string', 'max' => 10],
|
||||||
|
[['phone'], 'string', 'max' => 20],
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritdoc}
|
||||||
|
*/
|
||||||
|
public function attributeLabels() {
|
||||||
|
return [
|
||||||
|
'id' => 'ID',
|
||||||
|
'code' => 'Mã nhân viên',
|
||||||
|
'name' => 'Tên nhân viên',
|
||||||
|
'card_number' => 'Số thẻ',
|
||||||
|
'department_id' => 'Phòng ban',
|
||||||
|
'gender' => 'Giới tính',
|
||||||
|
'birthday' => 'Ngày sinh',
|
||||||
|
'email' => 'Email',
|
||||||
|
'phone' => 'Điện thoại',
|
||||||
|
'date_in' => 'Ngày bắt đầu làm việc',
|
||||||
|
'address' => 'Địa chỉ',
|
||||||
|
'created_at' => 'Thời gian tạo',
|
||||||
|
'modified_at' => 'Thời gian sửa',
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
public static $genderArray = ["M" => "Nam", "F" => "Nữ"];
|
||||||
|
|
||||||
|
public function create($data) {
|
||||||
|
$r = $this->load([
|
||||||
|
"code" => $data["Code"],
|
||||||
|
"name" => $data["Name"],
|
||||||
|
"card_number" => $data["CardNumber"] != "" ? $data["CardNumber"] : 0,
|
||||||
|
"department_id" => $data["Department"],
|
||||||
|
"gender" => $data["Gender"],
|
||||||
|
"birthday" => date_format(date_create_from_format('d/m/Y', $data["BirthDay"]), 'U'),
|
||||||
|
"email" => $data["Email"],
|
||||||
|
"phone" => $data["Phone"],
|
||||||
|
"date_in" => date_format(date_create_from_format('d/m/Y', $data["DateIn"]), 'U'),
|
||||||
|
"address" => $data["Address"],
|
||||||
|
"created_at" => time(),
|
||||||
|
"modified_at" => time()
|
||||||
|
], '');
|
||||||
|
if ($r) {
|
||||||
|
try {
|
||||||
|
$this->save();
|
||||||
|
return $this->id;
|
||||||
|
} catch (\Exception $ex) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function multiCreate($datas) {
|
||||||
|
$field = ['code', 'name', 'card_number', 'department_id', 'gender', 'birthday', 'email', 'phone', 'date_in', 'address', 'created_at', 'modified_at'];
|
||||||
|
static::getDb()->createCommand()->batchInsert($this->tableName(), $field, $datas)->execute();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function checkStatusImport($data) {
|
||||||
|
if ($this->findOne(["code" => $data["A"]]))
|
||||||
|
return ["status" => false, "description" => "Mã nhân viên đã tồn tại"];
|
||||||
|
if ($this->findOne(["card_number" => $data["C"]]))
|
||||||
|
return ["status" => false, "description" => "Số thẻ đã tồn tại"];
|
||||||
|
if (!Department::findOne(["name" => $data["D"]]))
|
||||||
|
return ["status" => true, "description" => "Phòng ban không tồn tại"];
|
||||||
|
return ["status" => true, "description" => ""];
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
78
models/StaffSearch.php
Normal file
78
models/StaffSearch.php
Normal file
|
@ -0,0 +1,78 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace app\models;
|
||||||
|
|
||||||
|
use Yii;
|
||||||
|
use yii\base\Model;
|
||||||
|
use yii\data\ActiveDataProvider;
|
||||||
|
use app\models\Staff;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* StaffSearch represents the model behind the search form of `app\models\Staff`.
|
||||||
|
*/
|
||||||
|
class StaffSearch extends Staff {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritdoc}
|
||||||
|
*/
|
||||||
|
public function rules() {
|
||||||
|
return [
|
||||||
|
[['id', 'code', 'card_number', 'department_id'], 'integer'],
|
||||||
|
[['name', 'gender', 'email', 'phone', 'address'], 'safe'],
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritdoc}
|
||||||
|
*/
|
||||||
|
public function scenarios() {
|
||||||
|
// bypass scenarios() implementation in the parent class
|
||||||
|
return Model::scenarios();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates data provider instance with search query applied
|
||||||
|
*
|
||||||
|
* @param array $params
|
||||||
|
*
|
||||||
|
* @return ActiveDataProvider
|
||||||
|
*/
|
||||||
|
public function search($params) {
|
||||||
|
$query = Staff::find();
|
||||||
|
|
||||||
|
// add conditions that should always apply here
|
||||||
|
|
||||||
|
$dataProvider = new ActiveDataProvider([
|
||||||
|
'query' => $query,
|
||||||
|
]);
|
||||||
|
|
||||||
|
$this->load($params);
|
||||||
|
|
||||||
|
if (!$this->validate()) {
|
||||||
|
// uncomment the following line if you do not want to return any records when validation fails
|
||||||
|
// $query->where('0=1');
|
||||||
|
return $dataProvider;
|
||||||
|
}
|
||||||
|
|
||||||
|
// grid filtering conditions
|
||||||
|
$query->andFilterWhere([
|
||||||
|
'id' => $this->id,
|
||||||
|
'code' => $this->code,
|
||||||
|
'card_number' => $this->card_number,
|
||||||
|
'department_id' => $this->department_id,
|
||||||
|
'birthday' => $this->birthday,
|
||||||
|
'date_in' => $this->date_in,
|
||||||
|
'created_at' => $this->created_at,
|
||||||
|
'modified_at' => $this->modified_at,
|
||||||
|
]);
|
||||||
|
|
||||||
|
$query->andFilterWhere(['like', 'name', $this->name])
|
||||||
|
->andFilterWhere(['like', 'gender', $this->gender])
|
||||||
|
->andFilterWhere(['like', 'email', $this->email])
|
||||||
|
->andFilterWhere(['like', 'phone', $this->phone])
|
||||||
|
->andFilterWhere(['like', 'address', $this->address]);
|
||||||
|
|
||||||
|
return $dataProvider;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -20,7 +20,7 @@ use yii\widgets\ActiveForm;
|
||||||
<nav class="navbar navbar-static-top" role="navigation">
|
<nav class="navbar navbar-static-top" role="navigation">
|
||||||
<div class="collapse navbar-collapse pull-left" id="navbar-collapse">
|
<div class="collapse navbar-collapse pull-left" id="navbar-collapse">
|
||||||
<ul class="nav navbar-nav" style="font-size: 20px;">
|
<ul class="nav navbar-nav" style="font-size: 20px;">
|
||||||
<li class="<?php if (in_array($this->context->id, ['department'])) echo "active"; ?>">
|
<li class="<?php if (in_array($this->context->id, ['department', 'staff'])) echo "active"; ?>">
|
||||||
<a href="<?php echo \yii\helpers\Url::to(['/department']); ?>">
|
<a href="<?php echo \yii\helpers\Url::to(['/department']); ?>">
|
||||||
Nhân sự
|
Nhân sự
|
||||||
</a>
|
</a>
|
||||||
|
|
|
@ -13,10 +13,10 @@
|
||||||
],
|
],
|
||||||
['label' => 'Login', 'url' => ['site/login'], 'visible' => Yii::$app->user->isGuest],
|
['label' => 'Login', 'url' => ['site/login'], 'visible' => Yii::$app->user->isGuest],
|
||||||
];
|
];
|
||||||
if (in_array($this->context->id, ['department'])) {
|
if (in_array($this->context->id, ['department', 'staff'])) {
|
||||||
$items = [
|
$items = [
|
||||||
['label' => 'Phòng ban', 'url' => ['/department'], 'icon' => 'building'],
|
['label' => 'Phòng ban', 'url' => ['/department'], 'icon' => 'building'],
|
||||||
['label' => 'Nhân viên', 'url' => ['/dashboard'], 'icon' => 'users'],
|
['label' => 'Nhân viên', 'url' => ['/staff'], 'icon' => 'users'],
|
||||||
['label' => 'Đăng ký thẻ', 'url' => ['/dashboard'], 'icon' => 'credit-card']
|
['label' => 'Đăng ký thẻ', 'url' => ['/dashboard'], 'icon' => 'credit-card']
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
95
views/staff/form.tpl
Normal file
95
views/staff/form.tpl
Normal file
|
@ -0,0 +1,95 @@
|
||||||
|
<style>
|
||||||
|
.input-group-addon{
|
||||||
|
width: 140px;
|
||||||
|
text-align: left;
|
||||||
|
}
|
||||||
|
.input-group{
|
||||||
|
width: 100%;
|
||||||
|
}
|
||||||
|
.select2{
|
||||||
|
width: 100% !important;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
<div class="row">
|
||||||
|
<div class="col-md-6">
|
||||||
|
<div class="form-group" id="code">
|
||||||
|
<div class="input-group">
|
||||||
|
<div class="input-group-addon">Mã nhân viên <i class="text-red">*</i></div>
|
||||||
|
<input type="number" class="form-control" value="{$model->code|default:""}" name="Code">
|
||||||
|
</div>
|
||||||
|
<span class="help-block hidden"></span>
|
||||||
|
</div>
|
||||||
|
<div class="form-group" id="name">
|
||||||
|
<div class="input-group">
|
||||||
|
<div class="input-group-addon">Tên nhân viên <i class="text-red">*</i></div>
|
||||||
|
<input type="text" class="form-control" value="{$model->name|default:""}" name="Name">
|
||||||
|
</div>
|
||||||
|
<span class="help-block hidden"></span>
|
||||||
|
</div>
|
||||||
|
<div class="form-group">
|
||||||
|
<div class="input-group">
|
||||||
|
<div class="input-group-addon">Giới tính <i class="text-red">*</i></div>
|
||||||
|
<select class="form-control" name="Gender">
|
||||||
|
{html_options options=$genderArray selected=$model->gender|default:"M"}
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="form-group">
|
||||||
|
<div class="input-group">
|
||||||
|
<div class="input-group-addon">Ngày sinh</div>
|
||||||
|
<input type="text" class="form-control DatePicker" value="{$model->birthday|date_format:"%d/%m/%Y"}" name="BirthDay">
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="form-group" id="email">
|
||||||
|
<div class="input-group">
|
||||||
|
<div class="input-group-addon">Email</div>
|
||||||
|
<input type="text" class="form-control" value="{$model->email}" name="Email">
|
||||||
|
</div>
|
||||||
|
<span class="help-block hidden"></span>
|
||||||
|
</div>
|
||||||
|
<div class="form-group" id="phone">
|
||||||
|
<div class="input-group">
|
||||||
|
<div class="input-group-addon">Điện thoại</div>
|
||||||
|
<input type="text" class="form-control" value="{$model->phone}" name="Phone">
|
||||||
|
</div>
|
||||||
|
<span class="help-block hidden"></span>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="col-md-6">
|
||||||
|
<div class="form-group" id="card_number">
|
||||||
|
<div class="input-group">
|
||||||
|
<div class="input-group-addon">Mã thẻ</div>
|
||||||
|
<input type="number" class="form-control" value="{$model->card_number|default:""}" name="CardNumber">
|
||||||
|
</div>
|
||||||
|
<span class="help-block hidden"></span>
|
||||||
|
</div>
|
||||||
|
<div class="form-group">
|
||||||
|
<div class="input-group">
|
||||||
|
<div class="input-group-addon">Phòng ban</div>
|
||||||
|
<select class="form-control" name="Department" id="Department">
|
||||||
|
{html_options options=$departmentArray selected=$model->department_id|default:0}
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="form-group">
|
||||||
|
<div class="input-group">
|
||||||
|
<div class="input-group-addon">Ngày bắt đầu làm việc</div>
|
||||||
|
<input type="text" class="form-control DatePicker" value="{$model->date_in|date_format:"%d/%m/%Y"}" name="DateIn">
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="form-group">
|
||||||
|
<div class="input-group">
|
||||||
|
<div class="input-group-addon">Địa chỉ</div>
|
||||||
|
<textarea class="form-control" rows="6" name="Address">{$model->address}</textarea>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="text-right">
|
||||||
|
<button class="btn btn-primary" onclick="save(this);" data-href="{$url}">
|
||||||
|
<i class="fa fa-floppy-o"></i> Lưu
|
||||||
|
</button>
|
||||||
|
<button class="btn btn-default" data-dismiss="modal">
|
||||||
|
<span class="fa fa-remove"></span> Hủy
|
||||||
|
</button>
|
||||||
|
</div>
|
55
views/staff/import.tpl
Normal file
55
views/staff/import.tpl
Normal file
|
@ -0,0 +1,55 @@
|
||||||
|
<table class="table table-bordered table-striped table-hover">
|
||||||
|
<thead>
|
||||||
|
<tr>
|
||||||
|
<th style="width: 3%;">#</th>
|
||||||
|
<th style="width: 3%;" class="text-center">
|
||||||
|
<input type='checkbox' value='0' class='checkbox-staff-import' checked="" id='checkall-staff-import'>
|
||||||
|
</th>
|
||||||
|
<th>Mã nhân viên</th>
|
||||||
|
<th>Tên nhân viên</th>
|
||||||
|
<th>Số thẻ</th>
|
||||||
|
<th>Phòng ban</th>
|
||||||
|
<th>Giới tính</th>
|
||||||
|
<th>Ngày sinh</th>
|
||||||
|
<th>Email</th>
|
||||||
|
<th>Điện thoại</th>
|
||||||
|
<th>Ngày bắt đầu làm việc</th>
|
||||||
|
<th>Địa chỉ</th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody>
|
||||||
|
{$count=1}
|
||||||
|
{foreach from=$data item=d key=k}
|
||||||
|
{if $k>1}
|
||||||
|
{$status=$model->checkStatusImport($d)}
|
||||||
|
<tr {if !$status.status}class="warning"{/if}>
|
||||||
|
<td>{$count++}</td>
|
||||||
|
<td class="text-center">
|
||||||
|
{if $status.status}
|
||||||
|
<input type='checkbox' value='{json_encode($d)}' checked="" name='checkbox-staff-import' class='checkbox-staff-import'>
|
||||||
|
{/if}
|
||||||
|
</td>
|
||||||
|
<td>{$d.A}</td>
|
||||||
|
<td>{$d.B}</td>
|
||||||
|
<td>{$d.C}</td>
|
||||||
|
<td>{$d.D}</td>
|
||||||
|
<td>{$d.E}</td>
|
||||||
|
<td>{$d.F}</td>
|
||||||
|
<td>{$d.G}</td>
|
||||||
|
<td>{$d.H}</td>
|
||||||
|
<td>{$d.I}</td>
|
||||||
|
<td>{$d.J}</td>
|
||||||
|
<td><i class="text-red">{$status.description}</i></td>
|
||||||
|
</tr>
|
||||||
|
{/if}
|
||||||
|
{/foreach}
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
<div class="text-right">
|
||||||
|
<button class="btn btn-primary" onclick="_import(this);" data-href="{yii\helpers\Url::to(["import"])}">
|
||||||
|
<i class="fa fa-floppy-o"></i> Lưu
|
||||||
|
</button>
|
||||||
|
<button class="btn btn-default" data-dismiss="modal">
|
||||||
|
<span class="fa fa-remove"></span> Hủy
|
||||||
|
</button>
|
||||||
|
</div>
|
84
views/staff/index.tpl
Normal file
84
views/staff/index.tpl
Normal file
|
@ -0,0 +1,84 @@
|
||||||
|
{extends file=$smarty.current_dir|cat:'/../extends.tpl'}
|
||||||
|
{use class="yii\helpers\Url"}
|
||||||
|
{use class="yii\grid\GridView"}
|
||||||
|
{use class="yii\widgets\Pjax" type="block"}
|
||||||
|
{use class="app\assets\StaffAsset"}
|
||||||
|
{StaffAsset::register($this)|void}
|
||||||
|
{block name='content'}
|
||||||
|
<div class="staff-index">
|
||||||
|
<div class="" style="font-size: 15px;">
|
||||||
|
<label class="action-button" onclick="common.form(this, 'staff', true);" data-href="{Url::to(['create'])}">
|
||||||
|
<i class="fa fa-plus-square fa-1-5x"></i> Thêm
|
||||||
|
</label>
|
||||||
|
<label class="action-button" onclick="_form(this);" data-href="{Url::to(['update'])}">
|
||||||
|
<i class="fa fa-edit fa-1-5x"></i> Tùy chỉnh
|
||||||
|
</label>
|
||||||
|
<label class="action-button" onclick="_delete(this);" data-href="{Url::to(['delete'])}">
|
||||||
|
<i class="fa fa-trash fa-1-5x"></i> Xóa
|
||||||
|
</label>
|
||||||
|
<label class="action-button" onclick="$('#file').trigger('click');">
|
||||||
|
<i class="fa fa-upload fa-1-5x"></i> Nhập
|
||||||
|
</label>
|
||||||
|
<label class="action-button" onclick="_export(this);" data-href="{Url::to(['export'])}">
|
||||||
|
<i class="fa fa-download fa-1-5x"></i> Xuất
|
||||||
|
</label>
|
||||||
|
<label class="action-button" onclick="_logs(this);" data-href="{Url::to(['logs'])}">
|
||||||
|
<i class="fa fa-file fa-1-5x"></i> Ghi nhận hệ thống
|
||||||
|
</label>
|
||||||
|
</div>
|
||||||
|
<div class="hidden">
|
||||||
|
<input type="file" name="file" id="file">
|
||||||
|
<input type="hidden" value="{Url::to(['upload'])}" name="upload_file_url">
|
||||||
|
</div>
|
||||||
|
{Pjax id="staff-list"}
|
||||||
|
{GridView::widget([
|
||||||
|
'dataProvider' => $dataProvider,
|
||||||
|
'filterModel' => $searchModel,
|
||||||
|
'layout'=> \app\helpers\CommonGrid::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' id='checkall-staff'>",
|
||||||
|
'format' => 'raw',
|
||||||
|
'contentOptions' => ['class' => 'text-center'],
|
||||||
|
'headerOptions' => ['class' => 'text-center', 'style' => 'width:3%'],
|
||||||
|
'value' => \app\helpers\CommonGrid::checkbox("staff", false)
|
||||||
|
],
|
||||||
|
'code',
|
||||||
|
'name',
|
||||||
|
'card_number',
|
||||||
|
[
|
||||||
|
'attribute' => 'department_id',
|
||||||
|
'filter' => $departmentArray,
|
||||||
|
'value' => \app\helpers\StaffGrid::department($departmentArray)
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'attribute' => 'gender',
|
||||||
|
'filter' => $genderArray,
|
||||||
|
'value' => \app\helpers\StaffGrid::gender($genderArray)
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'attribute' => 'birthday',
|
||||||
|
'value' => \app\helpers\StaffGrid::birthday()
|
||||||
|
],
|
||||||
|
'email',
|
||||||
|
'phone',
|
||||||
|
[
|
||||||
|
'attribute' => 'date_in',
|
||||||
|
'value' => \app\helpers\StaffGrid::dateIn()
|
||||||
|
],
|
||||||
|
'address'
|
||||||
|
]
|
||||||
|
])}
|
||||||
|
{/Pjax}
|
||||||
|
</div>
|
||||||
|
{/block}
|
BIN
web/data/excel/1602319719_staff_20201010154609.xlsx
Normal file
BIN
web/data/excel/1602319719_staff_20201010154609.xlsx
Normal file
Binary file not shown.
BIN
web/data/excel/1602320488_staff_20201010155211.xlsx
Normal file
BIN
web/data/excel/1602320488_staff_20201010155211.xlsx
Normal file
Binary file not shown.
BIN
web/data/excel/1602320930_staff_20201010155211.xlsx
Normal file
BIN
web/data/excel/1602320930_staff_20201010155211.xlsx
Normal file
Binary file not shown.
BIN
web/data/excel/1602320972_staff_20201010155211.xlsx
Normal file
BIN
web/data/excel/1602320972_staff_20201010155211.xlsx
Normal file
Binary file not shown.
|
@ -224,16 +224,21 @@ common.success = function (id) {
|
||||||
$("#" + id).addClass("has-success").removeClass("has-error");
|
$("#" + id).addClass("has-success").removeClass("has-error");
|
||||||
$("#" + id).find(".help-block").addClass("hidden");
|
$("#" + id).find(".help-block").addClass("hidden");
|
||||||
};
|
};
|
||||||
common.form = function (e, obj) {
|
common.form = function (e, obj, bigSize) {
|
||||||
|
var size = bigSize | false;
|
||||||
common.modalBlock(true);
|
common.modalBlock(true);
|
||||||
$.ajax({
|
$.ajax({
|
||||||
url: $(e).attr('data-href'),
|
url: $(e).attr('data-href'),
|
||||||
type: 'POST',
|
type: 'POST',
|
||||||
success: function (data) {
|
success: function (data) {
|
||||||
common.modalBlock(false);
|
common.modalBlock(false);
|
||||||
common.modalOpen(data.form, false, data.title);
|
common.modalOpen(data.form, size, data.title);
|
||||||
if (obj === 'department')
|
if (obj === 'department')
|
||||||
$('#Pid').select2();
|
$('#Pid').select2();
|
||||||
|
if (obj === 'staff') {
|
||||||
|
$('#Department').select2();
|
||||||
|
common.dateTimePickerByClass("DatePicker", "DD/MM/YYYY");
|
||||||
|
}
|
||||||
},
|
},
|
||||||
error: function (jqXHR, textStatus, errorThrown) {
|
error: function (jqXHR, textStatus, errorThrown) {
|
||||||
common.modalBlock(false);
|
common.modalBlock(false);
|
||||||
|
@ -263,6 +268,22 @@ common.tree = function (e) {
|
||||||
$("#sub-tree-" + $(e).attr("data")).removeClass("hidden");
|
$("#sub-tree-" + $(e).attr("data")).removeClass("hidden");
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
common.validatePhone = function (PhoneNumber) {
|
||||||
|
var pattern = /^[0-9]{10,11}$/;
|
||||||
|
if (pattern.test(PhoneNumber)) {
|
||||||
|
return true;
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
common.validateEmail = function (Email) {
|
||||||
|
var pattern = /^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}$/;
|
||||||
|
if (pattern.test(Email)) {
|
||||||
|
return true;
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* =========================
|
* =========================
|
||||||
|
|
225
web/js/staff.js
Normal file
225
web/js/staff.js
Normal file
|
@ -0,0 +1,225 @@
|
||||||
|
$(function () {
|
||||||
|
common.checkboxInit("staff");
|
||||||
|
btnUpload($("input[name='upload_file_url']").val(), "", '.xls,.xlsx', 3500);
|
||||||
|
});
|
||||||
|
|
||||||
|
function validate() {
|
||||||
|
var error = 0;
|
||||||
|
var Name = $("input[name='Name']").val();
|
||||||
|
if (Name === "") {
|
||||||
|
common.error("name", "Tên nhân viên không được để trống");
|
||||||
|
error++;
|
||||||
|
} else {
|
||||||
|
common.success("name");
|
||||||
|
}
|
||||||
|
|
||||||
|
var Code = $("input[name='Code']").val();
|
||||||
|
if (Code === "") {
|
||||||
|
common.error("code", "Mã nhân viên không được để trống");
|
||||||
|
error++;
|
||||||
|
} else {
|
||||||
|
common.success("code");
|
||||||
|
}
|
||||||
|
|
||||||
|
var Email = $("input[name='Email']").val();
|
||||||
|
if (Email !== "") {
|
||||||
|
if (common.validateEmail(Email) == false) {
|
||||||
|
common.error("email", "Định dạng email không đúng");
|
||||||
|
error++;
|
||||||
|
} else {
|
||||||
|
common.success("email");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
var Phone = $("input[name='Phone']").val();
|
||||||
|
if (Phone !== "") {
|
||||||
|
if (common.validatePhone(Phone) == false) {
|
||||||
|
common.error("phone", "Định dạng số điện thoại không đúng");
|
||||||
|
error++;
|
||||||
|
} else {
|
||||||
|
common.success("phone");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return error == 0 ? true : false;
|
||||||
|
}
|
||||||
|
|
||||||
|
function save(e) {
|
||||||
|
if (validate()) {
|
||||||
|
common.modalBlock(true);
|
||||||
|
$.ajax({
|
||||||
|
url: $(e).attr('data-href'),
|
||||||
|
type: 'POST',
|
||||||
|
data: {
|
||||||
|
Name: $("input[name='Name']").val(),
|
||||||
|
Code: $("input[name='Code']").val(),
|
||||||
|
Gender: $("select[name='Gender']").val(),
|
||||||
|
BirthDay: $("input[name='BirthDay']").val(),
|
||||||
|
Email: $("input[name='Email']").val(),
|
||||||
|
Phone: $("input[name='Phone']").val(),
|
||||||
|
CardNumber: $("input[name='CardNumber']").val(),
|
||||||
|
Department: $("select[name='Department']").val(),
|
||||||
|
DateIn: $("input[name='DateIn']").val(),
|
||||||
|
Address: $("textarea[name='Address']").val()
|
||||||
|
},
|
||||||
|
success: function (data) {
|
||||||
|
common.modalBlock(false);
|
||||||
|
if (data.status) {
|
||||||
|
notification.success("Đã lưu thông tin", 1000);
|
||||||
|
$.pjax.reload({container: '#staff-list'});
|
||||||
|
$("#staff-list").on('pjax:success', function () {
|
||||||
|
common.checkboxInit("staff");
|
||||||
|
});
|
||||||
|
$("#myModal").modal("hide");
|
||||||
|
} else {
|
||||||
|
if (data.type === "code") {
|
||||||
|
common.error("code", "Mã nhân viên đã tồn tại");
|
||||||
|
} else if (data.type === "card") {
|
||||||
|
common.error("card_number", "Số thẻ đã tồn tại");
|
||||||
|
} else {
|
||||||
|
notification.danger("Có lỗi xảy ra, không lưu được dữ liệu!", 1000);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
error: function (jqXHR, textStatus, errorThrown) {
|
||||||
|
common.modalBlock(false);
|
||||||
|
common.ajaxError();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function _form(e) {
|
||||||
|
var lists = [];
|
||||||
|
$.each($("input[name='checkbox-staff']:checked"), function () {
|
||||||
|
lists.push($(this).val());
|
||||||
|
});
|
||||||
|
if (lists.length == 0) {
|
||||||
|
alert("Vui lòng lựa chọn đối tượng để thay đổi!");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (lists.length > 1) {
|
||||||
|
alert("Tác vụ này không thể lựa chọn nhiều hơn một đối tượng!");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
common.modalBlock(true);
|
||||||
|
$.ajax({
|
||||||
|
url: $(e).attr('data-href') + "?id=" + lists[0],
|
||||||
|
type: 'POST',
|
||||||
|
success: function (data) {
|
||||||
|
common.modalBlock(false);
|
||||||
|
common.modalOpen(data.form, true, data.title);
|
||||||
|
$('#Department').select2();
|
||||||
|
common.dateTimePickerByClass("DatePicker", "DD/MM/YYYY");
|
||||||
|
},
|
||||||
|
error: function (jqXHR, textStatus, errorThrown) {
|
||||||
|
common.modalBlock(false);
|
||||||
|
common.ajaxError();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
function _delete(e) {
|
||||||
|
var lists = [];
|
||||||
|
$.each($("input[name='checkbox-staff']:checked"), function () {
|
||||||
|
lists.push($(this).val());
|
||||||
|
});
|
||||||
|
if (lists.length == 0) {
|
||||||
|
alert("Vui lòng lựa chọn đối tượng để xóa!");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (confirm("Bạn có chắc chắn muốn xóa các đối tượng đã lựa chọn không?")) {
|
||||||
|
common.modalBlock(true);
|
||||||
|
$.ajax({
|
||||||
|
url: $(e).attr('data-href'),
|
||||||
|
type: 'POST',
|
||||||
|
data: {
|
||||||
|
lists: lists
|
||||||
|
},
|
||||||
|
success: function (data) {
|
||||||
|
common.modalBlock(false);
|
||||||
|
notification.danger("Đã xóa dữ liệu", 1000);
|
||||||
|
$.pjax.reload({container: '#staff-list'});
|
||||||
|
$("#staff-list").on('pjax:success', function () {
|
||||||
|
common.checkboxInit("staff");
|
||||||
|
});
|
||||||
|
},
|
||||||
|
error: function (jqXHR, textStatus, errorThrown) {
|
||||||
|
common.modalBlock(false);
|
||||||
|
common.ajaxError();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function _export(e) {
|
||||||
|
window.location = $(e).attr("data-href");
|
||||||
|
}
|
||||||
|
|
||||||
|
function btnUpload(mUrl, className, extension, fileSize) {
|
||||||
|
var fData = {
|
||||||
|
UploadFile: true,
|
||||||
|
Name: className
|
||||||
|
};
|
||||||
|
fData[common.csrfParam] = common.csrf;
|
||||||
|
new afuButton({
|
||||||
|
uploadURI: mUrl,
|
||||||
|
formData: fData,
|
||||||
|
wrap: {
|
||||||
|
tagName: 'div',
|
||||||
|
classes: ''
|
||||||
|
},
|
||||||
|
fileExtension: extension,
|
||||||
|
fileSizeLimit: fileSize,
|
||||||
|
classes: 'btn btn-default file-paperclip-' + className,
|
||||||
|
fakeInputContent: '<span class=\'fa fa-upload\'></span> Nhập dữ liệu',
|
||||||
|
onUploaded: function (data) {
|
||||||
|
data = JSON.parse(data);
|
||||||
|
common.modalOpenFullScreen(data.form, data.title);
|
||||||
|
common.uploadBlock(false);
|
||||||
|
common.checkboxInit("staff-import");
|
||||||
|
}
|
||||||
|
}).addInstance('file' + className);
|
||||||
|
$(".file-paperclip-" + className).closest("div").attr("style", "display:inline-block;");
|
||||||
|
}
|
||||||
|
|
||||||
|
function _import(e) {
|
||||||
|
var lists = [];
|
||||||
|
$.each($("input[name='checkbox-staff-import']:checked"), function () {
|
||||||
|
lists.push($(this).val());
|
||||||
|
});
|
||||||
|
if (lists.length == 0) {
|
||||||
|
alert("Vui lòng lựa chọn đối tượng để nhập!");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
common.modalBlock(true);
|
||||||
|
$.ajax({
|
||||||
|
url: $(e).attr('data-href'),
|
||||||
|
type: 'POST',
|
||||||
|
data: {
|
||||||
|
lists: lists
|
||||||
|
},
|
||||||
|
success: function (data) {
|
||||||
|
common.modalBlock(false);
|
||||||
|
window.location.reload(true);
|
||||||
|
},
|
||||||
|
error: function (jqXHR, textStatus, errorThrown) {
|
||||||
|
common.modalBlock(false);
|
||||||
|
common.ajaxError();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
function _logs(e) {
|
||||||
|
common.modalBlock(true);
|
||||||
|
$.ajax({
|
||||||
|
url: $(e).attr('data-href'),
|
||||||
|
type: 'POST',
|
||||||
|
success: function (data) {
|
||||||
|
common.modalBlock(false);
|
||||||
|
common.modalOpen(data.form, true, data.title);
|
||||||
|
},
|
||||||
|
error: function (jqXHR, textStatus, errorThrown) {
|
||||||
|
common.modalBlock(false);
|
||||||
|
common.ajaxError();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user