update socket

This commit is contained in:
2020-02-10 10:23:13 +07:00
parent 6bee84075c
commit adadd350ba
15 changed files with 867 additions and 34 deletions

View File

@@ -0,0 +1,80 @@
<?php
namespace app\controllers;
use Yii;
use app\models\Logs;
use yii\web\Controller;
use yii\web\NotFoundHttpException;
use yii\filters\VerbFilter;
/**
* LogsController implements the CRUD actions for Logs model.
*/
class DashboardController 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'],
],
],
];
}
/**
* Lists all Logs models.
* @return mixed
*/
public function actionIndex() {
$this->view->title = "Bảng điều khiển";
$f = date_format(date_create_from_format('H:i d/m/Y', "00:00 " . date("d/m/Y")), 'U');
$t = date_format(date_create_from_format('H:i d/m/Y', "23:59 " . date("d/m/Y")), 'U');
$logs = Logs::find()->andWhere(["OR", ["BETWEEN", 'time_in', $f, $t], ["BETWEEN", 'time_out', $f, $t]])->orderBy(['time_in' => SORT_DESC, 'time_out' => SORT_DESC])->all();
$temp = [];
$in = 0;
$out = 0;
foreach ($logs as $k => $v) {
if ($v->time_out) {
$temp[$v->id] = $v->time_out;
} else {
$temp[$v->id] = $v->time_in;
}
if ($v->time_in)
$in++;
if ($v->time_out)
$out++;
}
arsort($temp);
$results = [];
foreach ($temp as $k => $v) {
foreach ($logs as $key => $value) {
if ($value->id == $k)
$results[] = $value;
}
}
return $this->render('index', [
"results" => $results,
"in" => $in,
"out" => $out,
"common" => new \app\models\common()
]);
}
}

View File

@@ -53,7 +53,6 @@ class LogsController extends Controller {
$f = date_format(date_create_from_format('H:i d/m/Y', $from), 'U');
$t = date_format(date_create_from_format('H:i d/m/Y', $to), 'U');
$dataProvider->query->andWhere(["OR", ["BETWEEN", 'time_in', $f, $t], ["BETWEEN", 'time_out', $f, $t]]);
return $this->render('index', [
'searchModel' => $searchModel,
'dataProvider' => $dataProvider,
@@ -138,4 +137,151 @@ class LogsController extends Controller {
throw new NotFoundHttpException('The requested page does not exist.');
}
public function actionSave() {
if (Yii::$app->request->post()) {
$post = Yii::$app->request->post();
$logs = Logs::findOne($post['id']);
$field = $post['field'];
if ($logs) {
$logs->$field = $post['value'];
$logs->save();
}
return "<div style='cursor:pointer;' onclick='openForm(this, \"{$field}\");' data-id='{$post['id']}' data-text='{$post['value']}'>{$post['value']}</div>";
}
}
public function actionExport($from = "", $to = "") {
if ($from === "") {
$from = "00:00 " . date("d/m/Y");
}
if ($to === "") {
$to = "23:59 " . date("d/m/Y");
}
$f = date_format(date_create_from_format('H:i d/m/Y', $from), 'U');
$t = date_format(date_create_from_format('H:i d/m/Y', $to), 'U');
$lists = Logs::find()->andWhere(["OR", ["BETWEEN", 'time_in', $f, $t], ["BETWEEN", 'time_out', $f, $t]])->orderBy(['time_in' => SORT_ASC])->all();
$objPHPExcel = new \PHPExcel();
$count = 1;
$objPHPExcel->setActiveSheetIndex(0);
$toExcelFile[] = [
"STT",
"Biến số",
"Loại xe",
"Tên công ty",
"Lái xe",
"Điện thoại",
"CMT",
"Factory",
"SEAL_NO",
"Thời gian vào",
"Thời gian ra",
"Nội dung khác"
];
foreach ($lists as $k => $v) {
$ExportData[] = $count++;
$ExportData[] = $v->vehicle->plate;
$ExportData[] = $v->vehicle->type;
$ExportData[] = $v->vehicle->company;
$ExportData[] = $v->vehicle->driver;
$ExportData[] = $v->vehicle->telephone;
$ExportData[] = $v->vehicle->indentity_card;
$ExportData[] = $v->factory;
$ExportData[] = $v->seal_no;
$ExportData[] = $v->time_in == 0 ? "" : date("H:i:s d/m/Y", $v->time_in);
$ExportData[] = $v->time_out == 0 ? "" : date("H:i:s d/m/Y", $v->time_out);
$ExportData[] = $v->note;
$toExcelFile[] = $ExportData;
unset($ExportData);
}
$totals = count($lists) + 2;
$activeSheet = $objPHPExcel->getActiveSheet();
$activeSheet->setCellValue("A1", "DANH SÁCH XE RA VÀO TỪ {$from} ĐẾN {$to}");
$activeSheet->mergeCells('A1:L1');
$activeSheet->getRowDimension('1')->setRowHeight(50);
$activeSheet->getStyle("A2:L2")->getFont()->setBold(true);
$activeSheet->getStyle("A1")->getFont()->setBold(true)->setName('Time New Roman')->setSize(13);
$activeSheet->getStyle("A2:L" . $totals)->getFont()->setName('Time New Roman')->setSize(10);
$activeSheet->getColumnDimension('A')->setWidth(5);
$activeSheet->getColumnDimension('B')->setWidth(12);
$activeSheet->getColumnDimension('C')->setWidth(10);
$activeSheet->getColumnDimension('D')->setWidth(30);
$activeSheet->getColumnDimension('E')->setWidth(15);
$activeSheet->getColumnDimension('F')->setWidth(15);
$activeSheet->getColumnDimension('G')->setWidth(15);
$activeSheet->getColumnDimension('H')->setWidth(12);
$activeSheet->getColumnDimension('I')->setWidth(10);
$activeSheet->getColumnDimension('J')->setWidth(15);
$activeSheet->getColumnDimension('K')->setWidth(15);
$activeSheet->getColumnDimension('L')->setWidth(20);
$style = array(
'alignment' => array(
'horizontal' => \PHPExcel_Style_Alignment::HORIZONTAL_CENTER,
'vertical' => \PHPExcel_Style_Alignment::VERTICAL_CENTER,
'wrap' => true
)
);
$activeSheet->getStyle("A1:L2")->applyFromArray($style);
$activeSheet->getStyle("A2:L2")->applyFromArray([
'fill' => array(
'type' => \PHPExcel_Style_Fill::FILL_SOLID,
'color' => array('rgb' => '00c0ef')
)
]);
$rowCount = 2;
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("A2:L" . $totals)->applyFromArray([
'alignment' => [
'horizontal' => \PHPExcel_Style_Alignment::HORIZONTAL_CENTER,
'vertical' => \PHPExcel_Style_Alignment::VERTICAL_CENTER,
'wrap' => true
],
'borders' => [
'allborders' => [
'style' => \PHPExcel_Style_Border::BORDER_THIN
]
]
]);
$activeSheet->getStyle("D3:D" . $totals)->applyFromArray([
'alignment' => [
'horizontal' => \PHPExcel_Style_Alignment::HORIZONTAL_LEFT,
'wrap' => true
]
]);
$activeSheet->setCellValue("B" . ($totals + 3), "Tổng số lượt xe vào:");
$activeSheet->setCellValue("B" . ($totals + 4), "Tổng số lượt xe ra:");
$activeSheet->mergeCells("B" . ($totals + 3) . ":C" . ($totals + 3));
$activeSheet->mergeCells("B" . ($totals + 4) . ":C" . ($totals + 4));
$activeSheet->setCellValue("D" . ($totals + 3), Logs::find()->andWhere(["BETWEEN", "time_in", $f, $t])->count());
$activeSheet->setCellValue("D" . ($totals + 4), Logs::find()->andWhere(["BETWEEN", "time_out", $f, $t])->count());
$activeSheet->getStyle("B" . ($totals + 3) . ":B" . ($totals + 5))->getFont()->setBold(true)->setItalic(true)->setName('Time New Roman')->setSize(11);
$activeSheet->getStyle("D" . ($totals + 3) . ":D" . ($totals + 5))->getFont()->setItalic(true)->setName('Time New Roman')->setSize(11);
$objWriter = \PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel2007');
ob_end_clean();
header('Content-type: application/vnd.ms-excel');
header('Content-Disposition: attachment; filename="bao-cao.xlsx"');
header('Cache-Control: max-age=0');
$objWriter->save('php://output');
exit();
}
}

View File

@@ -138,4 +138,151 @@ class LogsUnknowController extends Controller {
throw new NotFoundHttpException('The requested page does not exist.');
}
public function actionSave() {
if (Yii::$app->request->post()) {
$post = Yii::$app->request->post();
$logs = LogsUnknow::findOne($post['id']);
$field = $post['field'];
if ($logs) {
$logs->$field = $post['value'];
$logs->save();
}
return "<div style='cursor:pointer;' onclick='openForm(this, \"{$field}\");' data-id='{$post['id']}' data-text='{$post['value']}'>{$post['value']}</div>";
}
}
public function actionExport($from = "", $to = "") {
if ($from === "") {
$from = "00:00 " . date("d/m/Y");
}
if ($to === "") {
$to = "23:59 " . date("d/m/Y");
}
$f = date_format(date_create_from_format('H:i d/m/Y', $from), 'U');
$t = date_format(date_create_from_format('H:i d/m/Y', $to), 'U');
$lists = LogsUnknow::find()->andWhere(["OR", ["BETWEEN", 'time_in', $f, $t], ["BETWEEN", 'time_out', $f, $t]])->orderBy(['time_in' => SORT_ASC])->all();
$objPHPExcel = new \PHPExcel();
$count = 1;
$objPHPExcel->setActiveSheetIndex(0);
$toExcelFile[] = [
"STT",
"Biến số",
"Loại xe",
"Tên công ty",
"Lái xe",
"Điện thoại",
"CMT",
"Factory",
"SEAL_NO",
"Thời gian vào",
"Thời gian ra",
"Nội dung khác"
];
foreach ($lists as $k => $v) {
$ExportData[] = $count++;
$ExportData[] = $v->plate;
$ExportData[] = "";
$ExportData[] = "";
$ExportData[] = "";
$ExportData[] = "";
$ExportData[] = "";
$ExportData[] = $v->factory;
$ExportData[] = $v->seal_no;
$ExportData[] = $v->time_in == 0 ? "" : date("H:i:s d/m/Y", $v->time_in);
$ExportData[] = $v->time_out == 0 ? "" : date("H:i:s d/m/Y", $v->time_out);
$ExportData[] = $v->note;
$toExcelFile[] = $ExportData;
unset($ExportData);
}
$totals = count($lists) + 2;
$activeSheet = $objPHPExcel->getActiveSheet();
$activeSheet->setCellValue("A1", "DANH SÁCH XE KHÔNG RÕ NGUỒN GỐC RA VÀO TỪ {$from} ĐẾN {$to}");
$activeSheet->mergeCells('A1:L1');
$activeSheet->getRowDimension('1')->setRowHeight(50);
$activeSheet->getStyle("A2:L2")->getFont()->setBold(true);
$activeSheet->getStyle("A1")->getFont()->setBold(true)->setName('Time New Roman')->setSize(13);
$activeSheet->getStyle("A2:L" . $totals)->getFont()->setName('Time New Roman')->setSize(10);
$activeSheet->getColumnDimension('A')->setWidth(5);
$activeSheet->getColumnDimension('B')->setWidth(12);
$activeSheet->getColumnDimension('C')->setWidth(10);
$activeSheet->getColumnDimension('D')->setWidth(30);
$activeSheet->getColumnDimension('E')->setWidth(15);
$activeSheet->getColumnDimension('F')->setWidth(15);
$activeSheet->getColumnDimension('G')->setWidth(15);
$activeSheet->getColumnDimension('H')->setWidth(12);
$activeSheet->getColumnDimension('I')->setWidth(10);
$activeSheet->getColumnDimension('J')->setWidth(15);
$activeSheet->getColumnDimension('K')->setWidth(15);
$activeSheet->getColumnDimension('L')->setWidth(20);
$style = array(
'alignment' => array(
'horizontal' => \PHPExcel_Style_Alignment::HORIZONTAL_CENTER,
'vertical' => \PHPExcel_Style_Alignment::VERTICAL_CENTER,
'wrap' => true
)
);
$activeSheet->getStyle("A1:L2")->applyFromArray($style);
$activeSheet->getStyle("A2:L2")->applyFromArray([
'fill' => array(
'type' => \PHPExcel_Style_Fill::FILL_SOLID,
'color' => array('rgb' => '00c0ef')
)
]);
$rowCount = 2;
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("A2:L" . $totals)->applyFromArray([
'alignment' => [
'horizontal' => \PHPExcel_Style_Alignment::HORIZONTAL_CENTER,
'vertical' => \PHPExcel_Style_Alignment::VERTICAL_CENTER,
'wrap' => true
],
'borders' => [
'allborders' => [
'style' => \PHPExcel_Style_Border::BORDER_THIN
]
]
]);
$activeSheet->getStyle("D3:D" . $totals)->applyFromArray([
'alignment' => [
'horizontal' => \PHPExcel_Style_Alignment::HORIZONTAL_LEFT,
'wrap' => true
]
]);
$activeSheet->setCellValue("B" . ($totals + 3), "Tổng số lượt xe vào:");
$activeSheet->setCellValue("B" . ($totals + 4), "Tổng số lượt xe ra:");
$activeSheet->mergeCells("B" . ($totals + 3) . ":C" . ($totals + 3));
$activeSheet->mergeCells("B" . ($totals + 4) . ":C" . ($totals + 4));
$activeSheet->setCellValue("D" . ($totals + 3), LogsUnknow::find()->andWhere(["BETWEEN", "time_in", $f, $t])->count());
$activeSheet->setCellValue("D" . ($totals + 4), LogsUnknow::find()->andWhere(["BETWEEN", "time_out", $f, $t])->count());
$activeSheet->getStyle("B" . ($totals + 3) . ":B" . ($totals + 5))->getFont()->setBold(true)->setItalic(true)->setName('Time New Roman')->setSize(11);
$activeSheet->getStyle("D" . ($totals + 3) . ":D" . ($totals + 5))->getFont()->setItalic(true)->setName('Time New Roman')->setSize(11);
$objWriter = \PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel2007');
ob_end_clean();
header('Content-type: application/vnd.ms-excel');
header('Content-Disposition: attachment; filename="bao-cao.xlsx"');
header('Cache-Control: max-age=0');
$objWriter->save('php://output');
exit();
}
}

View File

@@ -154,7 +154,7 @@ class VehicleController extends Controller {
throw new NotFoundHttpException('The requested page does not exist.');
}
//
// public function actionImport() {
// $file_type = \PHPExcel_IOFactory::identify("data/data.xlsx");
// $objReader = \PHPExcel_IOFactory::createReader($file_type);
@@ -165,12 +165,12 @@ class VehicleController extends Controller {
// if ($k > 1) {
// $model = new Vehicle();
// $kq[] = $model->create([
// 'plate' => $this->formatPlate($row["B"]),
// 'plate' => $this->format($row["B"]),
// 'type' => $row["C"],
// 'company' => $row["D"],
// 'vehicle_type' => $row["E"],
// 'driver' => $row["F"],
// 'telephone' => $this->formatPlate($row["G"]),
// 'telephone' => $this->format($row["G"]),
// 'indentity_card' => strval($row["H"])
// ]);
// }
@@ -180,11 +180,77 @@ class VehicleController extends Controller {
// echo "</pre>";
// exit();
// }
//
public function format($plate) {
$p1 = str_replace("-", "", $plate);
$p2 = str_replace(".", "", $p1);
return str_replace(" ", "", $p2);
$p3 = str_replace("\n", "", $p2);
return str_replace(" ", "", $p3);
}
//
// public function actionExport() {
// set_time_limit(3600);
// $vehicles = Vehicle::find()->orderBy(['plate' => SORT_ASC])->all();
// $connection = Yii::$app->getDb();
// foreach ($vehicles as $k => $v) {
// $command = $connection->createCommand("SELECT * FROM `vehicle` WHERE `plate`<>'{$v->plate}' AND levenshtein('%{$v->plate}', `plate`) BETWEEN 0 AND 1");
// $result = $command->queryAll();
// $temp = [];
// foreach ($result as $key => $value) {
// $temp[] = $value['plate'];
// }
// $v->levenshtein_plate_2 = json_encode($temp);
// $v->save();
// }
// exit();
//
// $objPHPExcel = new \PHPExcel();
// $count = 1;
// $objPHPExcel->setActiveSheetIndex(0);
// $toExcelFile[] = [
// "STT",
// "Biển số",
// "Gần giống",
// "Công ty",
// "Lái xe"
// ];
// foreach ($vehicles as $k => $v) {
// $ExportData[] = $count++;
// $ExportData[] = $v->plate;
// $connection = Yii::$app->getDb();
// $command = $connection->createCommand("SELECT * FROM `vehicle` WHERE levenshtein(':plate_query', `plate`) BETWEEN 0 AND 2 AND `plate`<>':plate_query'", [':plate_query' => $v->plate]);
// $result = $command->queryAll();
// $ExportData[] = count($result);
// $ExportData[] = $v->company;
// $ExportData[] = $v->driver;
// $toExcelFile[] = $ExportData;
// unset($ExportData);
// }
// $activeSheet = $objPHPExcel->getActiveSheet();
// $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++;
// }
//
// $objWriter = \PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel2007');
// ob_end_clean();
// header('Content-type: application/vnd.ms-excel');
// header('Content-Disposition: attachment; filename="bao-cao.xlsx"');
// header('Cache-Control: max-age=0');
// $objWriter->save('php://output');
// exit();
// }
}