123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869 |
- <?
- header("Expires: 0");
- session_start();
- require_once 'PHPExcel-1.8.2/Classes/PHPExcel.php';
- include 'auth.php';
- include 'functions.php';
- require_once "doctrine/bootstrap.php";
- include 'CheckPoint.php';
- include 'CheckPointType.php';
- use CheckPoints\CheckPoint;
- use CheckPointTypes\CheckPointType;
- $arResult = [];
- $res = explode(',',$_REQUEST['type']);
- $ids = explode(',',$_REQUEST['id']);
- $arrIds = [];
- foreach($res as $key => $r){
- $arrIds[$ids[$key]] = $r;
- }
- foreach($arrIds as $key => $r){
- $tenpArray = [];
- $type = Tasktype::Find($r);
- $tenpArray['name'] = $type->name;
- $arResult[$key] = $tenpArray;
- }
- //echo '<pre><h3>Шаг 1.</h3><br/>'; var_dump($arResult); echo '<pre>'; die();
- foreach($arResult as $key => $id){
- $notes = FindTaskNotes($key);
- $tenpArray = [];
- foreach ($notes as $note) {
- $tenpArray[] = explode(', TWX',$note['text'])[0];
- }
- $arResult[$key]['notes'] = $tenpArray;
- }
- //echo '<pre><h3>Шаг 2.</h3><br/>'; var_dump($arResult); echo '<pre>'; die();
- foreach($arResult as $key => $id){
- $cps = CheckPoint::FindAllByTask($key);
- $tenpArray = [];
- foreach ($cps as $cp) {
- $temArray = [];
- $tenpArray['name'] = $cp->name;
-
- if ($cp->value != null){
- //echo $cp->value;
- $temArray[] = $cp->value;
- } else {
- $children = $cp->childrenCheckpoints;
-
- foreach ($children as $child) {
-
- if ( 1 == $child->state) {
-
- $temArray[]= $child->name;
- }
- //$temArray[] = $child->name;
- //echo "$child->name: $child->value $child->state<br>";
- }
-
- }
- $tenpArray['value'] = implode(',',$temArray);
- //var_dump($tenpArray); echo "<br>";
- if (!empty($tenpArray['value']) && '' != $tenpArray['value']){
- $arResult[$key]['maps'][] = $tenpArray;
- }
- }
-
- }
- //echo '<pre><h3>Шаг 3.</h3><br/>'; var_dump($arResult); echo '<pre>'; die();
- $rrr = [];
- foreach($arResult as $res){
- $temp = [];
- foreach($res['notes'] as $r){
- $temp['name'] = $res['name'];
- $temp['desc'] = $r;
- $rrr[] = $temp;
- }
- $temp = [];
- foreach($res['maps'] as $b){
- /*$temp['name'] = $b['name'];
- $temp['desc'] = $b['value'];/**/
- $temp['name'] = $res['name'];
- $temp['desc'] = $b['name'].': '.$b['value'];
- $rrr[] = $temp;
- }
-
- }
- $arResult = $rrr;
- //echo '<pre><h3>Шаг 4.</h3><br/>'; var_dump($arResult); echo '<pre>'; die();
- /*
- echo "<pre>";
- var_dump($rrr);
- echo "</pre>";
- exit;
- */
- function cellColor($cells,$color){
- global $objPHPExcel;
- $objPHPExcel->getActiveSheet()->getStyle($cells)->getFill()->applyFromArray(array(
- 'type' => PHPExcel_Style_Fill::FILL_SOLID,
- 'startcolor' => array(
- 'rgb' => $color
- )
- ));
- }
- $styleBorder = array(
- 'borders' => array(
- 'allborders' => array(
- 'style' => PHPExcel_Style_Border::BORDER_THIN
- )
- )
- );
- foreach (array_keys($_REQUEST) as $var)
- {
- ${$var}=$_REQUEST[$var];
- //echo "<b>$var:</b> ${$var} <br>";
- }
- $array_children = $_SESSION['array_children'];
- $array_parent = $_SESSION['array_parent'];
- $activeid = $_SESSION['actid'];
- $res_parent = $array_parent[$activeid];
- foreach($res_parent as $key => $r) {
- if ('type' == $key){
- $res_parent_type = $r;
- }
- if ('input_id' == $key){
- $res_parent_input_id = $r;
- }
- if ( 'created' == $key) {
- $res_parent_created = $r;
- }
- }
- //var_dump($res_parent_created);echo "<br>";
- //exit;
- $namedesc = GetTaskNameAndDesc($res_parent_type);
- //$namedesc = GetTaskNameAndDesc($res_parent['type']);
- $proj = GetProject($res_parent_input_id);
- //$proj = GetProject($res_parent['input_id']);
- $depo = $proj['depo'];
- $depo_service = $proj['depo_service'];
- $project_finished = $res_parent_created;
- //echo '<pre><h3>Шаг 1.</h3><br/>'; var_dump($finished); echo '<pre>'; die();
- //$finished = $res_parent['created'];
- // Create new PHPExcel object
- $objPHPExcel = new PHPExcel();
- // Set document properties
- $objPHPExcel->getProperties()->setCreator("Maarten Balliauw")
- ->setLastModifiedBy("Maarten Balliauw")
- ->setTitle("Office 2007 XLSX Report Document")
- ->setSubject("Office 2007 XLSX Report Document")
- ->setDescription("Test document for Office 2007 XLSX, generated using PHP classes.")
- ->setKeywords("office 2007 openxml php")
- ->setCategory("Report result file");
- $style = array(
- 'alignment' => array(
- 'horizontal' => PHPExcel_Style_Alignment::HORIZONTAL_CENTER,
- )
- );
- $style1 = array(
- 'alignment' => array(
- 'horizontal' => PHPExcel_Style_Alignment::HORIZONTAL_RIGHT,
- )
- );
- $style2 = array(
- 'alignment' => array(
- 'vertical' => PHPExcel_Style_Alignment::VERTICAL_CENTER,
- )
- );
- $sheet = $objPHPExcel->getActiveSheet();
- $sheet->getDefaultStyle()->getFont()->setName('Times New Roman')->setSize(11);
- //$sheet->getStyle("A2:A9")->applyFromArray($style);
- //$sheet->getStyle("B1")->applyFromArray($style);
- $sheet->getStyle("C3")->applyFromArray($style);
- //$sheet->getStyle("B10")->applyFromArray($style);
- //$sheet->getStyle("A7:A9")->applyFromArray($style1);
- //$sheet->getDefaultStyle()->applyFromArray($style);
- // $sheet->getStyle('B11:D11')->getBorders()->getAllBorders()->setBorderStyle(PHPExcel_Style_Border::BORDER_THIN);
- $objPHPExcel->getActiveSheet()->getStyle('B11:D11')->applyFromArray($styleBorder);
- cellColor('B11:D11', 'f2f2f2');
- $sheet->getRowDimension('1')->setRowHeight(31.5);
- $sheet->getRowDimension('3')->setRowHeight(31.5);
- $sheet->getRowDimension('4')->setRowHeight(31.5);
- $sheet->getRowDimension('5')->setRowHeight(31.5);
- $sheet->getRowDimension('6')->setRowHeight(31.5);
- $sheet->getRowDimension('7')->setRowHeight(31.5);
- //$sheet->getRowDimension('1')->setRowHeight(31.5);
- $objPHPExcel->setActiveSheetIndex(0)->setCellValue('D1', 'Приложение №10 к Регламенту (Приложение №4)');
- //$objPHPExcel->setActiveSheetIndex(0)->setCellValue('D2', 'Проект №'.$proj['id']);
- //cellColor('A1:J1', '8DB4E2');
- $sheet->getStyle('C3:C4')->getFont()->setBold(TRUE);
- $sheet->getStyle('B11:D11')->getFont()->setBold(TRUE);
- //$sheet->getStyle('B3:B6')->getFont()->setBold(TRUE);
- $sheet->setCellValue('B11', '№ п/п');
- $i=12;
- $k=1;
- foreach($arResult as $item){
- $sheet->setCellValue('B'.$i, $k);
- $sheet->setCellValue('C'.$i, $item['name']);
- $sheet->setCellValue('D'.$i, $item['desc']);
- $i++;
- $k++;
- }
- $sheet->setCellValue('C11', 'Наименование работ');
- //$sheet->setCellValue('C11', 'Дата создания задачи');
- //$sheet->setCellValue('D11', 'Дата начала исполнения');
- //$sheet->setCellValue('C11', 'Описание');
- //$sheet->setCellValue('D11', 'Необходимые запасные части');
- $sheet->setCellValue('D11', 'Замечания');
- // $sheet->setCellValue('D11', 'Дата завершения');
- // $sheet->setCellValue('E11', "Исполнитель");
- //$sheet->setCellValue('D11', 'Замечания');
- //$sheet->setCellValue('E11', "Замечания");
- // $sheet->setCellValue('F11', 'Замечания');
- // $sheet->setCellValue('G11', 'Замечания');
- // $sheet->setCellValue('H11', 'Замечания');
- // $sheet->setCellValue('I11', 'Замечания');
- // $sheet->setCellValue('J11', 'Замечания');
- //$sheet->setCellValue('K11', 'Замечания');
- //$sheet->setCellValue('L11', 'Замечания');
- //cellColor('A10:L11', 'EEEEEE');
- //$sheet->getStyle('A10:L11')->getBorders()->getAllBorders()->setBorderStyle(PHPExcel_Style_Border::BORDER_THIN);
- $sheet->getStyle('A10:L11')->getFont()->setBold(TRUE);
- //$sheet->setCellValue('A2', '№');
- //$sheet->setCellValue('A3', '1');
- //$sheet->setCellValue('A4', '2'); //имя глобала
- //$sheet->setCellValue('A5', '3'); //Депо сервисного обслуживания: Братское
- //$sheet->setCellValue('A6', '4'); //Настоящий акт подверждает, что 2018-12-12T00:00:00 на
- //$sheet->setCellValue('A7', '5'); //Локомотиве серии номер
- //$sheet->setCellValue('A8', '6'); //приписки локомотивного депо
- //$sheet->setCellValue('A9', '7'); //В ходе приемки, испытания, осмотра и ремонта Локомотива необходимо проведение следующих работ:
- //$sheet->setCellValue('B2', 'Наименование');
- $objPHPExcel->getActiveSheet()->getStyle("C3:C4")->getFont()->setSize(18);
- //$objPHPExcel->getActiveSheet()->getStyle("C3:C4")->getFont()->setSize(18);
- $sheet->setCellValue('C3', 'Акт №');
- //$sheet->setCellValue('C4', $namedesc[0]);
- $sheet->setCellValue('C4', $namedesc[0]);
- $sheet->setCellValue('C5', "Депо сервисного обслуживания: ".$depo_service);
- $sheet->setCellValue('C6', 'Настоящий акт подверждает, что '.$project_finished->date);
- $sheet->setCellValue('C7', "На локомотиве серии ".$proj['loco_type']." номер ".$proj['loco_number']);
- $sheet->setCellValue('C8', "Приписки локомотивного депо: $depo");
- $sheet->setCellValue('C9', 'В ходе приемки, испытания, осмотра и ремонта Локомотива необходимо проведение следующих работ:');
- //$sheet->getStyle('C9')->getFont()->setBold(TRUE);
- //$sheet->setCellValue('C2', 'Значение');
- //cellColor('A10:L10', '8DB4E2');
- $sheet->getStyle('B11')->getFont()->setBold(TRUE);
- $sheet->getStyle('B10')->getFont()->getColor()->setRGB('FFFFFF');
- //$i=12;
- $finished = [];
- $assignee_names = [];
- //echo '<pre><h3>Шаг 2.</h3><br/>'; var_dump($array_children); echo '<pre>'; die();
- foreach ($array_children as $parent_id => $children)
- {
- //echo '<pre><h3>Шаг 2.</h3><br/>'; var_dump($children); echo '<pre>'; die();
- if ($activeid != $parent_id)
- {
- continue;
- }
- foreach ($children as $res1) {
- foreach ($res1 as $key => $res)
- {
- switch ($key)
- {
- case 'accepted_time':
- $finished[] = $res;
- break;
- case 'account':
- foreach ($res as $acckey => $accval)
- {
- if ($acckey == 'name')
- {
- $assignee_names[] = $accval;
- break;
- }
- }
- break;
- }
- }
- $taskid = $res1->id;
- $type = $res1->type;
- $created = $res1->created;
- //$accepted = $res1->accepted_time;
- //$finished[] = $res1->finished_time;
- //$finished[] = $res1->accepted_time->date;
- //$assignee = $res1->assignees_arr;
- //$assignee_names[] = $res1->name;//GetAccount($assignee)['name'];
- //if ($finished == '')
- // $finished = 'не завершена';
- //if ($accepted == '')
- // $accepted = 'не принята';
- $namedesc = GetTaskNameAndDesc($type);
- // $sheet->setCellValueByColumnAndRow(0, $i, $taskid);
- // $sheet->setCellValueByColumnAndRow(1, $i, $namedesc[0]);
- // $sheet->setCellValueByColumnAndRow(2, $i, $namedesc[1]);
- // $sheet->setCellValueByColumnAndRow(3, $i, $finished);
- // $sheet->setCellValueByColumnAndRow(4, $i, $assignee_names);
- // $sheet->setCellValueByColumnAndRow(5, $i, $namedesc[1]);
- // $sheet->setCellValueByColumnAndRow(6, $i, $assignee_names);
- $notes = FindTaskNotes($taskid);
- if (sizeof($notes) > 0) {
- $nn = 2;
- $num = 0;
- $notestext = "$taskid. \n";
- foreach ($notes as $note) {
- $num++;
- // if ($num == 3)
- // break;
- $notedate = $note['date'];
- $noteid = $note['id'];
- $notetext = $note['text'];
- //$sheet->setCellValueByColumnAndRow($nn, $i, $noteid." [".$notedate."] ".$notetext);
- $sheet->getStyle('C'.$i)->getAlignment()->setWrapText(true);
- $sheet->getStyle('D'.$i)->getAlignment()->setWrapText(true);
- $sheet->getStyle('E'.$i)->getAlignment()->setWrapText(true);
- $sheet->getStyle('F'.$i)->getAlignment()->setWrapText(true);
- $sheet->getStyle('G'.$i)->getAlignment()->setWrapText(true);
- $notestext .= $num.". ".$notetext."\n";
- //$nn++;
- }
- $sheet->setCellValueByColumnAndRow($nn, $i, $notestext);
- $i++;
- }
- }
- }
- $i--;
- $sheet->getStyle("B12:D".$i)->applyFromArray($styleBorder);
- $i+=2;
- $sheet->getRowDimension($i)->setRowHeight(25);
- rsort($finished);
- $finished_datetime = $finished[0];
- //echo '<pre><h3>Шаг 2.</h3><br/>'; var_dump($finished_datetime); echo '<pre>'; die();
- if (empty($finished_datetime))
- $sheet->setCellValueByColumnAndRow(2, $i, 'Дата окончания осмотра: не завершена');
- else
- $sheet->setCellValueByColumnAndRow(2, $i, 'Дата окончания осмотра: '.date('Y-m-d H:i:s', strtotime($finished_datetime->date)));
- $i+=2;
- $sheet->getRowDimension($i)->setRowHeight(30);
- $assignee_names = array_unique($assignee_names);
- //echo '<pre><h3>Шаг 2.</h3><br/>'; var_dump($assignee_names); echo '<pre>'; die();
- $sheet->setCellValueByColumnAndRow(2, $i, 'Исполнитель: '.implode(',', $assignee_names));
- // Rename worksheet
- $sheet->setTitle('Report');
-
-
- // Set active sheet index to the first sheet, so Excel opens this as the first sheet
- $objPHPExcel->setActiveSheetIndex(0);
- $sheet->getColumnDimension('A')->setWidth(17.57);
- $sheet->getColumnDimension('B')->setWidth(7.14);
- $sheet->getColumnDimension('C')->setWidth(51.29);
- $sheet->getColumnDimension('D')->setWidth(51.29);
- $sheet->getColumnDimension('E')->setWidth(51.29);
- $sheet->getColumnDimension('F')->setWidth(51.29);
- $sheet->getColumnDimension('G')->setWidth(51.29);
- $sheet->getColumnDimension('H')->setAutoSize(true);
- $sheet->getColumnDimension('I')->setAutoSize(true);
- $sheet->getColumnDimension('J')->setAutoSize(true);
- $sheet->getColumnDimension('K')->setAutoSize(true);
- $sheet->getColumnDimension('L')->setAutoSize(true);
- $sheet->getColumnDimension('M')->setAutoSize(true);
- $objPHPExcel->getActiveSheet()->getStyle('E11')->getAlignment()->setWrapText(true);
-
- $sheet->getStyle("A10:M10")->applyFromArray($style2);
-
- $styleBorder = array('font' => array('bold' => true));
- $sheet->getStyle('B1:F1')->applyFromArray($styleBorder);
- $sheet->getStyle('A1')->getFont()->setBold(TRUE);
- //$sheet->getStyle('B1')->getFont()->getColor()->setRGB('FFFFFF');
- //$_SESSION['array_children'] = [];
- //$_SESSION['array_parent'] = [];
- //$_SESSION['actid'] = [];
-
- // Redirect output to a client’s web browser (Excel5)
- header('Content-Type: application/vnd.ms-excel');
- $date1 = date('Y.m.d-H.i', strtotime($project_finished->date));
- header('Content-Disposition: attachment;filename="'.$date1.'-'.$proj['loco_type'].'-'.$proj['loco_number'].'.xls"');
- header('Cache-Control: max-age=0');
- // If you're serving to IE 9, then the following may be needed
- header('Cache-Control: max-age=1');
-
- // If you're serving to IE over SSL, then the following may be needed
- header ('Expires: Mon, 26 Jul 1997 05:00:00 GMT'); // Date in the past
- header ('Last-Modified: '.gmdate('D, d M Y H:i:s').' GMT'); // always modified
- header ('Cache-Control: cache, must-revalidate'); // HTTP/1.1
- header ('Pragma: public'); // HTTP/1.0
-
- $objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5');
- //$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel2007');
- $objWriter->save('php://output');
- ?>
|