123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432 |
- <?php
- defined('YII_DEBUG') or define('YII_DEBUG', true);
- defined('YII_ENV') or define('YII_ENV', 'dev');
- require __DIR__ . '/api/vendor/autoload.php';
- require __DIR__ . '/api/vendor/yiisoft/yii2/Yii.php';
- $config = require __DIR__ . '/api/config/web.php';
- (new yii\web\Application($config));
- $res = new \app\models\AnalyticsModel();
- $arrTasks = $res->getTasks();
- $arrProjecttypes = $res->getProjecttypes();
- $arrTaskstypes = $res->getTaskstypes();
- $arrAccounts = $res->getAccounts();
- $arrJobtypes = $res->getJobtypes();
- $arrJobtypesAccounts = $res->getJobtypesAccounts();
- $arrSections = $res->getSections();
- /*
- foreach($arrTasks as $ar){
-
- var_dump($ar->project->id); echo "<br>";
- var_dump($ar->accounts->name); echo "<br>";
- }
- exit;
- */
- require_once('PHPExcel-1.8.2/Classes/PHPExcel.php');
- // Подключаем класс для вывода данных в формате excel
- require_once('PHPExcel-1.8.2/Classes/PHPExcel/Writer/Excel5.php');
-
- // Создаем объект класса PHPExcel
- $xls = new PHPExcel();
- // Устанавливаем индекс активного листа
- $xls->setActiveSheetIndex(0);
- // Получаем активный лист
- $sheet = $xls->getActiveSheet();
- // Подписываем лист
- $sheet->setTitle('Команды');
-
- // Вставляем текст в ячейку A1
- $sheet->setCellValue("A1", 'action');
- $sheet->setCellValue("B1", 'loco_type');
- $sheet->setCellValue("C1", 'status');
- $sheet->setCellValue("D1", 'loco_number');
- $sheet->setCellValue("E1", 'depo');
- $sheet->setCellValue("F1", 'depo_service');
- $sheet->setCellValue("G1", 'created');
- $sheet->setCellValue("H1", 'section_id');
- $sheet->setCellValue("I1", 'id_project');
- $sheet->setCellValue("J1", 'task_created');
- $sheet->setCellValue("K1", 'finished_time');
- $sheet->setCellValue("L1", 'accepted_time');
- $sheet->setCellValue("M1", 'expires');
- $sheet->setCellValue("N1", 'type');
- $sheet->setCellValue("O1", 'account_id');
- $sheet->setCellValue("P1", 'account_name');
- $sheet->setCellValue("Q1", 'task_status');
- $sheet->setCellValue("R1", 'task_id');
- //$sheet->setCellValue("O1", 'input_id');
- $sheet->getStyle('A1')->getFill()->setFillType(
- PHPExcel_Style_Fill::FILL_SOLID);
- $sheet->getStyle('A1')->getFill()->getStartColor()->setRGB('EEEEEE');
-
- // Объединяем ячейки
- //$sheet->mergeCells('A1:H1');
-
- // Выравнивание текста
- $sheet->getStyle('A1')->getAlignment()->setHorizontal(
- PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
-
- for ($i = 2; $i < 20; $i++) {
- $j = 2;
- foreach($arrTasks as $task){
-
-
- switch ($i) {
- case 2:
- $value = $task->project->action;
- break;
- case 3:
- $value = $task->project->loco_type;
- break;
- case 4:
- $value = $task->project->status;
- break;
- case 5:
- $value = $task->project->loco_number;
- break;
-
- case 6:
- $value = $task->project->depo;
- break;
- case 7:
- $value = $task->project->depo_service;
- break;
-
- case 8:
- $value = $task->project->created;
- break;
- case 9:
- $value = $task->project->section_id;
- break;
- case 10:
- $value = $task->project->id;
- break;
- case 11:
- $value = $task->created;
- break;
- case 12:
- $value = $task->finished_time;
- break;
- case 13:
- $value = $task->accepted_time;
- break;
- case 14:
- $value = $task->expires;
- break;
- case 15:
- $value = $task->type;
- break;
- case 16:
- $value = $task->accounts->id;
- break;
- case 17:
- $value = $task->accounts->name;
- break;
- case 18:
- $value = $task->status;
- break;
- case 19:
- $value = $task->id;
- break;
- case 20:
- $value = '';
- break;
- }
- $sheet->setCellValueByColumnAndRow(
- $i - 2,
- $j,
- ($value));
-
- // Применяем выравнивание
- $sheet->getStyleByColumnAndRow($i - 2, $j)->getAlignment()->
- setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
- $j++;
- }
- }
- $xls->createSheet();
- $xls->setActiveSheetIndex(1);
- // Получаем активный лист
- $sheet = $xls->getActiveSheet();
- // Подписываем лист
- $sheet->setTitle('Типы проектов');
- $sheet->setCellValue("A1", 'id');
- $sheet->setCellValue("B1", 'name');
- $sheet->setCellValue("C1", 'company');
- for ($i = 2; $i < 5; $i++) {
- $j = 2;
- foreach($arrProjecttypes as $projecttype){
-
-
- switch ($i) {
- case 2:
- $value = $projecttype->id;
- break;
- case 3:
- $value = $projecttype->name;
- break;
- case 4:
- $value = $projecttype->company;
- break;
- }
- $sheet->setCellValueByColumnAndRow(
- $i - 2,
- $j,
- ($value));
-
- // Применяем выравнивание
- $sheet->getStyleByColumnAndRow($i - 2, $j)->getAlignment()->
- setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
- $j++;
- }
- }
- $xls->createSheet();
- $xls->setActiveSheetIndex(2);
- // Получаем активный лист
- $sheet = $xls->getActiveSheet();
- // Подписываем лист
- $sheet->setTitle('Типы задач');
- $sheet->setCellValue("A1", 'id');
- $sheet->setCellValue("B1", 'name');
- $sheet->setCellValue("C1", 'company');
- $sheet->setCellValue("D1", 'main_task');
- $sheet->setCellValue("E1", 'time_to_complete_minutes');
- $sheet->setCellValue("F1", 'object_name');
- for ($i = 2; $i < 8; $i++) {
- $j = 2;
- foreach($arrTaskstypes as $taskstype){
-
-
- switch ($i) {
- case 2:
- $value = $taskstype->id;
- break;
- case 3:
- $value = $taskstype->name;
- break;
- case 4:
- $value = $taskstype->company;
- break;
- case 5:
- $value = $taskstype->main_task;
- break;
- case 6:
- $value = $taskstype->time_to_complete_minutes;
- break;
- case 7:
- $value = $taskstype->object_name;
- break;
- }
-
- $sheet->setCellValueByColumnAndRow(
- $i - 2,
- $j,
- ($value));
-
- // Применяем выравнивание
- $sheet->getStyleByColumnAndRow($i - 2, $j)->getAlignment()->
- setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
- $j++;
- }
- }
- $xls->createSheet();
- $xls->setActiveSheetIndex(3);
- // Получаем активный лист
- $sheet = $xls->getActiveSheet();
- // Подписываем лист
- $sheet->setTitle('Аккаунты');
- $sheet->setCellValue("A1", 'id');
- $sheet->setCellValue("B1", 'name');
- $sheet->setCellValue("C1", 'company');
- $sheet->setCellValue("D1", 'position');
- $sheet->setCellValue("E1", 'repair_site');
- for ($i = 2; $i < 7; $i++) {
- $j = 2;
- foreach($arrAccounts as $accounts){
-
-
- switch ($i) {
- case 2:
- $value = $accounts->id;
- break;
- case 3:
- $value = $accounts->name;
- break;
- case 4:
- $value = $accounts->company;
- break;
- case 5:
- $value = $accounts->position;
- break;
- case 6:
- $value = $accounts->repair_site;
- break;
- }
- $sheet->setCellValueByColumnAndRow(
- $i - 2,
- $j,
- ($value));
-
- // Применяем выравнивание
- $sheet->getStyleByColumnAndRow($i - 2, $j)->getAlignment()->
- setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
- $j++;
- }
- }
- $xls->createSheet();
- $xls->setActiveSheetIndex(4);
- // Получаем активный лист
- $sheet = $xls->getActiveSheet();
- // Подписываем лист
- $sheet->setTitle('Должности');
- $sheet->setCellValue("A1", 'id');
- $sheet->setCellValue("B1", 'name');
- $sheet->setCellValue("C1", 'company');
- for ($i = 2; $i < 5; $i++) {
- $j = 2;
- foreach($arrJobtypes as $jobtype){
-
-
- switch ($i) {
- case 2:
- $value = $jobtype->id;
- break;
- case 3:
- $value = $jobtype->name;
- break;
- case 4:
- $value = $jobtype->company;
- break;
- }
- $sheet->setCellValueByColumnAndRow(
- $i - 2,
- $j,
- ($value));
-
- // Применяем выравнивание
- $sheet->getStyleByColumnAndRow($i - 2, $j)->getAlignment()->
- setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
- $j++;
- }
- }
- $xls->createSheet();
- $xls->setActiveSheetIndex(5);
- // Получаем активный лист
- $sheet = $xls->getActiveSheet();
- // Подписываем лист
- $sheet->setTitle('Промежуточная таблица');
- $sheet->setCellValue("A1", 'account_id');
- $sheet->setCellValue("B1", 'jobtype_id');
- for ($i = 2; $i < 4; $i++) {
- $j = 2;
- foreach($arrJobtypesAccounts as $jobtypeAccount){
-
-
- switch ($i) {
- case 2:
- $value = $jobtypeAccount->account_id;
- break;
- case 3:
- $value = $jobtypeAccount->jobtype_id;
- break;
-
- }
- $sheet->setCellValueByColumnAndRow(
- $i - 2,
- $j,
- ($value));
-
- // Применяем выравнивание
- $sheet->getStyleByColumnAndRow($i - 2, $j)->getAlignment()->
- setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
- $j++;
- }
- }
- $xls->createSheet();
- $xls->setActiveSheetIndex(6);
- // Получаем активный лист
- $sheet = $xls->getActiveSheet();
- // Подписываем лист
- $sheet->setTitle('Секции');
- $sheet->setCellValue("A1", 'id');
- $sheet->setCellValue("B1", 'locomotive_series');
- $sheet->setCellValue("C1", 'section_number');
- $sheet->setCellValue("D1", 'section_subnumber');
- for ($i = 2; $i < 6; $i++) {
- $j = 2;
- foreach($arrSections as $section){
-
-
- switch ($i) {
- case 2:
- $value = $section->id;
- break;
- case 3:
- $value = $section->locomotive_series;
- break;
- case 4:
- $value = $section->section_number;
- break;
- case 5:
- $value = $section->section_subnumber;
- break;
-
- }
- $sheet->setCellValueByColumnAndRow(
- $i - 2,
- $j,
- ($value));
-
- // Применяем выравнивание
- $sheet->getStyleByColumnAndRow($i - 2, $j)->getAlignment()->
- setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
- $j++;
- }
- }
- $xls->setActiveSheetIndex(0);
- // Выводим HTTP-заголовки
- header ( "Expires: Mon, 1 Apr 1974 05:00:00 GMT" );
- header ( "Last-Modified: " . gmdate("D,d M YH:i:s") . " GMT" );
- header ( "Cache-Control: no-cache, must-revalidate" );
- header ( "Pragma: no-cache" );
- header ( "Content-type: application/vnd.ms-excel" );
- header ( "Content-Disposition: attachment; filename=smopp.xls" );
-
- // Выводим содержимое файла
- $objWriter = new PHPExcel_Writer_Excel5($xls);
- $objWriter->save('php://output');
-
|