From adffab016cea8772cdf263b5e54d0d95ead9a36a Mon Sep 17 00:00:00 2001 From: dongpd Date: Tue, 20 Oct 2020 09:18:48 +0700 Subject: [PATCH] =?UTF-8?q?fix=20bug=20import=20danh=20s=C3=A1ch=20nh?= =?UTF-8?q?=C3=A2n=20vi=C3=AAn=20v=E1=BB=9Bi=20d=E1=BB=AF=20li=E1=BB=87u?= =?UTF-8?q?=20l=E1=BB=9Bn?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- controllers/StaffController.php | 40 ++++++++++++++++++++++++++------- web/js/staff.js | 10 +++++---- 2 files changed, 38 insertions(+), 12 deletions(-) diff --git a/controllers/StaffController.php b/controllers/StaffController.php index acd9d7da..c52c9d6b 100644 --- a/controllers/StaffController.php +++ b/controllers/StaffController.php @@ -216,14 +216,38 @@ class StaffController extends Controller { $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() - ]) - ]; + foreach ($sheet_data as $key => $val) { + if ($key > 1) { + $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(), + time() + ]; + } + } + $model = new Staff(); + $model->multiCreate($datas); + common::insertSystemLogs(["action" => "import", "description" => "Nhập dữ liệu: " . count($datas) . " nhân viên mới", "type" => Yii::$app->controller->id]); + return 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() +// ]) +// ]; } } diff --git a/web/js/staff.js b/web/js/staff.js index fc1c9af5..c2d14adf 100644 --- a/web/js/staff.js +++ b/web/js/staff.js @@ -175,10 +175,11 @@ function btnUpload(mUrl, className, extension, fileSize) { classes: 'btn btn-default file-paperclip-' + className, fakeInputContent: ' 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"); + window.location.reload(true); +// 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;"); @@ -205,6 +206,7 @@ function _import(e) { window.location.reload(true); }, error: function (jqXHR, textStatus, errorThrown) { + console.log(errorThrown); common.modalBlock(false); common.ajaxError(); }