update export excel
This commit is contained in:
@@ -5,14 +5,6 @@ namespace app\controllers;
|
||||
use Yii;
|
||||
use yii\web\Controller;
|
||||
use yii\filters\VerbFilter;
|
||||
use yii\helpers\FileHelper;
|
||||
use app\models\User;
|
||||
use app\models\Gate;
|
||||
use app\models\Camera;
|
||||
use app\models\Card;
|
||||
use app\models\CardGroup;
|
||||
use app\models\Logs;
|
||||
use app\models\Config;
|
||||
|
||||
/**
|
||||
* CardController implements the CRUD actions for Card model.
|
||||
@@ -33,10 +25,13 @@ class ApiController extends Controller {
|
||||
];
|
||||
}
|
||||
|
||||
public function actionLogin() {
|
||||
public function actionSaveLogs() {
|
||||
if (Yii::$app->request->post()) {
|
||||
$post = Yii::$app->request->bodyParams;
|
||||
|
||||
$model = new \app\models\FaceLogs();
|
||||
$model->create($post);
|
||||
Yii::$app->response->format = "json";
|
||||
return ["stt" => true];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -3,8 +3,8 @@
|
||||
namespace app\controllers;
|
||||
|
||||
use Yii;
|
||||
use app\models\Logs;
|
||||
use app\models\LogsSearch;
|
||||
use app\models\FaceLogs;
|
||||
use app\models\FaceLogsSearch;
|
||||
use yii\web\Controller;
|
||||
use yii\filters\VerbFilter;
|
||||
use yii\helpers\Url;
|
||||
@@ -41,9 +41,109 @@ class DashboardController extends Controller {
|
||||
*/
|
||||
public function actionIndex() {
|
||||
$this->view->title = "Bảng tổng hợp";
|
||||
$searchModel = new FaceLogsSearch();
|
||||
$dataProvider = $searchModel->search(Yii::$app->request->queryParams);
|
||||
|
||||
return $this->render('index', [
|
||||
'searchModel' => $searchModel,
|
||||
'dataProvider' => $dataProvider,
|
||||
]);
|
||||
}
|
||||
|
||||
public function actionExport() {
|
||||
$lists = FaceLogs::find()->all();
|
||||
$objPHPExcel = new \PHPExcel();
|
||||
$count = 1;
|
||||
$objPHPExcel->setActiveSheetIndex(0);
|
||||
$toExcelFile[] = [
|
||||
"STT",
|
||||
"camera_id",
|
||||
"confidence",
|
||||
"frametime",
|
||||
"face_id",
|
||||
"name",
|
||||
"stt",
|
||||
"timezone"
|
||||
];
|
||||
foreach ($lists as $k => $v) {
|
||||
$ExportData[] = $count++;
|
||||
$ExportData[] = $v->camera_id;
|
||||
$ExportData[] = $v->confidence;
|
||||
$ExportData[] = $v->frametime;
|
||||
$ExportData[] = $v->face_id;
|
||||
$ExportData[] = $v->name;
|
||||
$ExportData[] = $v->stt;
|
||||
$ExportData[] = $v->timezone;
|
||||
$toExcelFile[] = $ExportData;
|
||||
unset($ExportData);
|
||||
}
|
||||
$totals = count($lists) + 2;
|
||||
$maxCol = "H";
|
||||
$activeSheet = $objPHPExcel->getActiveSheet();
|
||||
$activeSheet->setCellValue("A1", "DANH SÁCH CHẤM CÔNG");
|
||||
$activeSheet->mergeCells('A1:' . $maxCol . '1');
|
||||
$activeSheet->getRowDimension('1')->setRowHeight(50);
|
||||
$activeSheet->getStyle("A2:" . $maxCol . "2")->getFont()->setBold(true);
|
||||
$activeSheet->getStyle("A1")->getFont()->setBold(true)->setName('Time New Roman')->setSize(13);
|
||||
$activeSheet->getStyle("A2:" . $maxCol . $totals)->getFont()->setName('Time New Roman')->setSize(10);
|
||||
$activeSheet->getColumnDimension('A')->setWidth(5);
|
||||
$activeSheet->getColumnDimension('B')->setWidth(15);
|
||||
$activeSheet->getColumnDimension('C')->setWidth(15);
|
||||
$activeSheet->getColumnDimension('D')->setWidth(25);
|
||||
$activeSheet->getColumnDimension('E')->setWidth(10);
|
||||
$activeSheet->getColumnDimension('F')->setWidth(20);
|
||||
$activeSheet->getColumnDimension('G')->setWidth(10);
|
||||
$activeSheet->getColumnDimension('H')->setWidth(15);
|
||||
$style = array(
|
||||
'alignment' => array(
|
||||
'horizontal' => \PHPExcel_Style_Alignment::HORIZONTAL_CENTER,
|
||||
'vertical' => \PHPExcel_Style_Alignment::VERTICAL_CENTER,
|
||||
'wrap' => true
|
||||
)
|
||||
);
|
||||
$activeSheet->getStyle("A1:" . $maxCol . "2")->applyFromArray($style);
|
||||
$activeSheet->getStyle("A2:" . $maxCol . "2")->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:" . $maxCol . $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
|
||||
]
|
||||
]
|
||||
]);
|
||||
$objWriter = \PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel2007');
|
||||
ob_end_clean();
|
||||
header('Content-type: application/vnd.ms-excel');
|
||||
header('Content-Disposition: attachment; filename="du-lieu.xlsx"');
|
||||
header('Cache-Control: max-age=0');
|
||||
$objWriter->save('php://output');
|
||||
exit();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user