update
This commit is contained in:
@@ -160,13 +160,31 @@ 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');
|
||||
|
||||
$lists = Logs::find()->andWhere(["OR", ["BETWEEN", 'time_in', $f, $t], ["BETWEEN", 'time_out', $f, $t]])->orderBy(['time_in' => SORT_ASC])->all();
|
||||
$logs = Logs::find()->andWhere(["OR", ["BETWEEN", 'time_in', $f, $t], ["BETWEEN", 'time_out', $f, $t]])->orderBy(['time_in' => SORT_ASC])->all();
|
||||
|
||||
$temp = [];
|
||||
foreach ($logs as $k => $v) {
|
||||
if ($v->time_out) {
|
||||
$temp[$v->id] = $v->time_out;
|
||||
} else {
|
||||
$temp[$v->id] = $v->time_in;
|
||||
}
|
||||
}
|
||||
arsort($temp);
|
||||
|
||||
$results = [];
|
||||
foreach ($temp as $k => $v) {
|
||||
foreach ($logs as $key => $value) {
|
||||
if ($value->id == $k)
|
||||
$results[] = $value;
|
||||
}
|
||||
}
|
||||
|
||||
$objPHPExcel = new \PHPExcel();
|
||||
$count = 1;
|
||||
$objPHPExcel->setActiveSheetIndex(0);
|
||||
$toExcelFile[] = [
|
||||
"STT",
|
||||
"Biến số",
|
||||
"Loại xe",
|
||||
"Tên công ty",
|
||||
"Lái xe",
|
||||
@@ -174,13 +192,15 @@ class LogsController extends Controller {
|
||||
"CMT",
|
||||
"Factory",
|
||||
"SEAL_NO",
|
||||
"Biến số",
|
||||
"Ảnh biển vào",
|
||||
"Thời gian vào",
|
||||
"Ảnh biển ra",
|
||||
"Thời gian ra",
|
||||
"Nội dung khác"
|
||||
];
|
||||
foreach ($lists as $k => $v) {
|
||||
foreach ($results as $k => $v) {
|
||||
$ExportData[] = $count++;
|
||||
$ExportData[] = $v->vehicle->plate;
|
||||
$ExportData[] = $v->vehicle->type;
|
||||
$ExportData[] = $v->vehicle->company;
|
||||
$ExportData[] = $v->vehicle->driver;
|
||||
@@ -188,32 +208,52 @@ class LogsController extends Controller {
|
||||
$ExportData[] = $v->vehicle->indentity_card;
|
||||
$ExportData[] = $v->factory;
|
||||
$ExportData[] = $v->seal_no;
|
||||
$ExportData[] = $v->vehicle->plate;
|
||||
$ExportData[] = "";
|
||||
$ExportData[] = $v->time_in == 0 ? "" : date("H:i:s d/m/Y", $v->time_in);
|
||||
$ExportData[] = "";
|
||||
$ExportData[] = $v->time_out == 0 ? "" : date("H:i:s d/m/Y", $v->time_out);
|
||||
$ExportData[] = $v->note;
|
||||
if ($v->time_in) {
|
||||
$objDrawing = new \PHPExcel_Worksheet_Drawing();
|
||||
$objDrawing->setPath("./data/uploads/" . $v->plate_image_in);
|
||||
$objDrawing->setWidth(105);
|
||||
$objDrawing->setCoordinates('J' . ($k + 3));
|
||||
$objDrawing->setWorksheet($objPHPExcel->getActiveSheet());
|
||||
}
|
||||
if ($v->time_out) {
|
||||
$objDrawing = new \PHPExcel_Worksheet_Drawing();
|
||||
$objDrawing->setPath("./data/uploads/" . $v->plate_image_out);
|
||||
$objDrawing->setWidth(105);
|
||||
$objDrawing->setCoordinates('L' . ($k + 3));
|
||||
$objDrawing->setWorksheet($objPHPExcel->getActiveSheet());
|
||||
}
|
||||
$toExcelFile[] = $ExportData;
|
||||
unset($ExportData);
|
||||
}
|
||||
$totals = count($lists) + 2;
|
||||
|
||||
$totals = count($results) + 2;
|
||||
$activeSheet = $objPHPExcel->getActiveSheet();
|
||||
$activeSheet->setCellValue("A1", "DANH SÁCH XE RA VÀO TỪ {$from} ĐẾN {$to}");
|
||||
$activeSheet->mergeCells('A1:L1');
|
||||
$activeSheet->mergeCells('A1:N1');
|
||||
$activeSheet->getRowDimension('1')->setRowHeight(50);
|
||||
$activeSheet->getStyle("A2:L2")->getFont()->setBold(true);
|
||||
$activeSheet->getStyle("A2:N2")->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->getStyle("A2:N" . $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('B')->setWidth(10);
|
||||
$activeSheet->getColumnDimension('C')->setWidth(30);
|
||||
$activeSheet->getColumnDimension('D')->setWidth(15);
|
||||
$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('G')->setWidth(12);
|
||||
$activeSheet->getColumnDimension('H')->setWidth(10);
|
||||
$activeSheet->getColumnDimension('I')->setWidth(12);
|
||||
$activeSheet->getColumnDimension('J')->setWidth(15);
|
||||
$activeSheet->getColumnDimension('K')->setWidth(15);
|
||||
$activeSheet->getColumnDimension('L')->setWidth(20);
|
||||
$activeSheet->getColumnDimension('L')->setWidth(15);
|
||||
$activeSheet->getColumnDimension('M')->setWidth(15);
|
||||
$activeSheet->getColumnDimension('N')->setWidth(20);
|
||||
$style = array(
|
||||
'alignment' => array(
|
||||
'horizontal' => \PHPExcel_Style_Alignment::HORIZONTAL_CENTER,
|
||||
@@ -221,8 +261,8 @@ class LogsController extends Controller {
|
||||
'wrap' => true
|
||||
)
|
||||
);
|
||||
$activeSheet->getStyle("A1:L2")->applyFromArray($style);
|
||||
$activeSheet->getStyle("A2:L2")->applyFromArray([
|
||||
$activeSheet->getStyle("A1:N2")->applyFromArray($style);
|
||||
$activeSheet->getStyle("A2:N2")->applyFromArray([
|
||||
'fill' => array(
|
||||
'type' => \PHPExcel_Style_Fill::FILL_SOLID,
|
||||
'color' => array('rgb' => '00c0ef')
|
||||
@@ -245,7 +285,7 @@ class LogsController extends Controller {
|
||||
$rowCount++;
|
||||
}
|
||||
|
||||
$activeSheet->getStyle("A2:L" . $totals)->applyFromArray([
|
||||
$activeSheet->getStyle("A2:N" . $totals)->applyFromArray([
|
||||
'alignment' => [
|
||||
'horizontal' => \PHPExcel_Style_Alignment::HORIZONTAL_CENTER,
|
||||
'vertical' => \PHPExcel_Style_Alignment::VERTICAL_CENTER,
|
||||
|
||||
Reference in New Issue
Block a user