XLSList.php 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869
  1. <?
  2. header("Expires: 0");
  3. session_start();
  4. require_once 'PHPExcel-1.8.2/Classes/PHPExcel.php';
  5. include 'auth.php';
  6. include 'functions.php';
  7. require_once "doctrine/bootstrap.php";
  8. include 'CheckPoint.php';
  9. include 'CheckPointType.php';
  10. use CheckPoints\CheckPoint;
  11. use CheckPointTypes\CheckPointType;
  12. $arResult = [];
  13. $res = explode(',',$_REQUEST['type']);
  14. $ids = explode(',',$_REQUEST['id']);
  15. $arrIds = [];
  16. foreach($res as $key => $r){
  17. $arrIds[$ids[$key]] = $r;
  18. }
  19. foreach($arrIds as $key => $r){
  20. $tenpArray = [];
  21. $type = Tasktype::Find($r);
  22. $tenpArray['name'] = $type->name;
  23. $arResult[$key] = $tenpArray;
  24. }
  25. //echo '<pre><h3>Шаг 1.</h3><br/>'; var_dump($arResult); echo '<pre>'; die();
  26. foreach($arResult as $key => $id){
  27. $notes = FindTaskNotes($key);
  28. $tenpArray = [];
  29. foreach ($notes as $note) {
  30. $tenpArray[] = explode(', TWX',$note['text'])[0];
  31. }
  32. $arResult[$key]['notes'] = $tenpArray;
  33. }
  34. //echo '<pre><h3>Шаг 2.</h3><br/>'; var_dump($arResult); echo '<pre>'; die();
  35. foreach($arResult as $key => $id){
  36. $cps = CheckPoint::FindAllByTask($key);
  37. $tenpArray = [];
  38. foreach ($cps as $cp) {
  39. $temArray = [];
  40. $tenpArray['name'] = $cp->name;
  41. if ($cp->value != null){
  42. //echo $cp->value;
  43. $temArray[] = $cp->value;
  44. } else {
  45. $children = $cp->childrenCheckpoints;
  46. foreach ($children as $child) {
  47. if ( 1 == $child->state) {
  48. $temArray[]= $child->name;
  49. }
  50. //$temArray[] = $child->name;
  51. //echo "$child->name: $child->value $child->state<br>";
  52. }
  53. }
  54. $tenpArray['value'] = implode(',',$temArray);
  55. //var_dump($tenpArray); echo "<br>";
  56. if (!empty($tenpArray['value']) && '' != $tenpArray['value']){
  57. $arResult[$key]['maps'][] = $tenpArray;
  58. }
  59. }
  60. }
  61. //echo '<pre><h3>Шаг 3.</h3><br/>'; var_dump($arResult); echo '<pre>'; die();
  62. $rrr = [];
  63. foreach($arResult as $res){
  64. $temp = [];
  65. foreach($res['notes'] as $r){
  66. $temp['name'] = $res['name'];
  67. $temp['desc'] = $r;
  68. $rrr[] = $temp;
  69. }
  70. $temp = [];
  71. foreach($res['maps'] as $b){
  72. /*$temp['name'] = $b['name'];
  73. $temp['desc'] = $b['value'];/**/
  74. $temp['name'] = $res['name'];
  75. $temp['desc'] = $b['name'].': '.$b['value'];
  76. $rrr[] = $temp;
  77. }
  78. }
  79. $arResult = $rrr;
  80. //echo '<pre><h3>Шаг 4.</h3><br/>'; var_dump($arResult); echo '<pre>'; die();
  81. /*
  82. echo "<pre>";
  83. var_dump($rrr);
  84. echo "</pre>";
  85. exit;
  86. */
  87. function cellColor($cells,$color){
  88. global $objPHPExcel;
  89. $objPHPExcel->getActiveSheet()->getStyle($cells)->getFill()->applyFromArray(array(
  90. 'type' => PHPExcel_Style_Fill::FILL_SOLID,
  91. 'startcolor' => array(
  92. 'rgb' => $color
  93. )
  94. ));
  95. }
  96. $styleBorder = array(
  97. 'borders' => array(
  98. 'allborders' => array(
  99. 'style' => PHPExcel_Style_Border::BORDER_THIN
  100. )
  101. )
  102. );
  103. foreach (array_keys($_REQUEST) as $var)
  104. {
  105. ${$var}=$_REQUEST[$var];
  106. //echo "<b>$var:</b> ${$var} <br>";
  107. }
  108. $array_children = $_SESSION['array_children'];
  109. $array_parent = $_SESSION['array_parent'];
  110. $activeid = $_SESSION['actid'];
  111. $res_parent = $array_parent[$activeid];
  112. foreach($res_parent as $key => $r) {
  113. if ('type' == $key){
  114. $res_parent_type = $r;
  115. }
  116. if ('input_id' == $key){
  117. $res_parent_input_id = $r;
  118. }
  119. if ( 'created' == $key) {
  120. $res_parent_created = $r;
  121. }
  122. }
  123. //var_dump($res_parent_created);echo "<br>";
  124. //exit;
  125. $namedesc = GetTaskNameAndDesc($res_parent_type);
  126. //$namedesc = GetTaskNameAndDesc($res_parent['type']);
  127. $proj = GetProject($res_parent_input_id);
  128. //$proj = GetProject($res_parent['input_id']);
  129. $depo = $proj['depo'];
  130. $depo_service = $proj['depo_service'];
  131. $project_finished = $res_parent_created;
  132. //echo '<pre><h3>Шаг 1.</h3><br/>'; var_dump($finished); echo '<pre>'; die();
  133. //$finished = $res_parent['created'];
  134. // Create new PHPExcel object
  135. $objPHPExcel = new PHPExcel();
  136. // Set document properties
  137. $objPHPExcel->getProperties()->setCreator("Maarten Balliauw")
  138. ->setLastModifiedBy("Maarten Balliauw")
  139. ->setTitle("Office 2007 XLSX Report Document")
  140. ->setSubject("Office 2007 XLSX Report Document")
  141. ->setDescription("Test document for Office 2007 XLSX, generated using PHP classes.")
  142. ->setKeywords("office 2007 openxml php")
  143. ->setCategory("Report result file");
  144. $style = array(
  145. 'alignment' => array(
  146. 'horizontal' => PHPExcel_Style_Alignment::HORIZONTAL_CENTER,
  147. )
  148. );
  149. $style1 = array(
  150. 'alignment' => array(
  151. 'horizontal' => PHPExcel_Style_Alignment::HORIZONTAL_RIGHT,
  152. )
  153. );
  154. $style2 = array(
  155. 'alignment' => array(
  156. 'vertical' => PHPExcel_Style_Alignment::VERTICAL_CENTER,
  157. )
  158. );
  159. $sheet = $objPHPExcel->getActiveSheet();
  160. $sheet->getDefaultStyle()->getFont()->setName('Times New Roman')->setSize(11);
  161. //$sheet->getStyle("A2:A9")->applyFromArray($style);
  162. //$sheet->getStyle("B1")->applyFromArray($style);
  163. $sheet->getStyle("C3")->applyFromArray($style);
  164. //$sheet->getStyle("B10")->applyFromArray($style);
  165. //$sheet->getStyle("A7:A9")->applyFromArray($style1);
  166. //$sheet->getDefaultStyle()->applyFromArray($style);
  167. // $sheet->getStyle('B11:D11')->getBorders()->getAllBorders()->setBorderStyle(PHPExcel_Style_Border::BORDER_THIN);
  168. $objPHPExcel->getActiveSheet()->getStyle('B11:D11')->applyFromArray($styleBorder);
  169. cellColor('B11:D11', 'f2f2f2');
  170. $sheet->getRowDimension('1')->setRowHeight(31.5);
  171. $sheet->getRowDimension('3')->setRowHeight(31.5);
  172. $sheet->getRowDimension('4')->setRowHeight(31.5);
  173. $sheet->getRowDimension('5')->setRowHeight(31.5);
  174. $sheet->getRowDimension('6')->setRowHeight(31.5);
  175. $sheet->getRowDimension('7')->setRowHeight(31.5);
  176. //$sheet->getRowDimension('1')->setRowHeight(31.5);
  177. $objPHPExcel->setActiveSheetIndex(0)->setCellValue('D1', 'Приложение №10 к Регламенту (Приложение №4)');
  178. //$objPHPExcel->setActiveSheetIndex(0)->setCellValue('D2', 'Проект №'.$proj['id']);
  179. //cellColor('A1:J1', '8DB4E2');
  180. $sheet->getStyle('C3:C4')->getFont()->setBold(TRUE);
  181. $sheet->getStyle('B11:D11')->getFont()->setBold(TRUE);
  182. //$sheet->getStyle('B3:B6')->getFont()->setBold(TRUE);
  183. $sheet->setCellValue('B11', '№ п/п');
  184. $i=12;
  185. $k=1;
  186. foreach($arResult as $item){
  187. $sheet->setCellValue('B'.$i, $k);
  188. $sheet->setCellValue('C'.$i, $item['name']);
  189. $sheet->setCellValue('D'.$i, $item['desc']);
  190. $i++;
  191. $k++;
  192. }
  193. $sheet->setCellValue('C11', 'Наименование работ');
  194. //$sheet->setCellValue('C11', 'Дата создания задачи');
  195. //$sheet->setCellValue('D11', 'Дата начала исполнения');
  196. //$sheet->setCellValue('C11', 'Описание');
  197. //$sheet->setCellValue('D11', 'Необходимые запасные части');
  198. $sheet->setCellValue('D11', 'Замечания');
  199. // $sheet->setCellValue('D11', 'Дата завершения');
  200. // $sheet->setCellValue('E11', "Исполнитель");
  201. //$sheet->setCellValue('D11', 'Замечания');
  202. //$sheet->setCellValue('E11', "Замечания");
  203. // $sheet->setCellValue('F11', 'Замечания');
  204. // $sheet->setCellValue('G11', 'Замечания');
  205. // $sheet->setCellValue('H11', 'Замечания');
  206. // $sheet->setCellValue('I11', 'Замечания');
  207. // $sheet->setCellValue('J11', 'Замечания');
  208. //$sheet->setCellValue('K11', 'Замечания');
  209. //$sheet->setCellValue('L11', 'Замечания');
  210. //cellColor('A10:L11', 'EEEEEE');
  211. //$sheet->getStyle('A10:L11')->getBorders()->getAllBorders()->setBorderStyle(PHPExcel_Style_Border::BORDER_THIN);
  212. $sheet->getStyle('A10:L11')->getFont()->setBold(TRUE);
  213. //$sheet->setCellValue('A2', '№');
  214. //$sheet->setCellValue('A3', '1');
  215. //$sheet->setCellValue('A4', '2'); //имя глобала
  216. //$sheet->setCellValue('A5', '3'); //Депо сервисного обслуживания: Братское
  217. //$sheet->setCellValue('A6', '4'); //Настоящий акт подверждает, что 2018-12-12T00:00:00 на
  218. //$sheet->setCellValue('A7', '5'); //Локомотиве серии номер
  219. //$sheet->setCellValue('A8', '6'); //приписки локомотивного депо
  220. //$sheet->setCellValue('A9', '7'); //В ходе приемки, испытания, осмотра и ремонта Локомотива необходимо проведение следующих работ:
  221. //$sheet->setCellValue('B2', 'Наименование');
  222. $objPHPExcel->getActiveSheet()->getStyle("C3:C4")->getFont()->setSize(18);
  223. //$objPHPExcel->getActiveSheet()->getStyle("C3:C4")->getFont()->setSize(18);
  224. $sheet->setCellValue('C3', 'Акт №');
  225. //$sheet->setCellValue('C4', $namedesc[0]);
  226. $sheet->setCellValue('C4', $namedesc[0]);
  227. $sheet->setCellValue('C5', "Депо сервисного обслуживания: ".$depo_service);
  228. $sheet->setCellValue('C6', 'Настоящий акт подверждает, что '.$project_finished->date);
  229. $sheet->setCellValue('C7', "На локомотиве серии ".$proj['loco_type']." номер ".$proj['loco_number']);
  230. $sheet->setCellValue('C8', "Приписки локомотивного депо: $depo");
  231. $sheet->setCellValue('C9', 'В ходе приемки, испытания, осмотра и ремонта Локомотива необходимо проведение следующих работ:');
  232. //$sheet->getStyle('C9')->getFont()->setBold(TRUE);
  233. //$sheet->setCellValue('C2', 'Значение');
  234. //cellColor('A10:L10', '8DB4E2');
  235. $sheet->getStyle('B11')->getFont()->setBold(TRUE);
  236. $sheet->getStyle('B10')->getFont()->getColor()->setRGB('FFFFFF');
  237. //$i=12;
  238. $finished = [];
  239. $assignee_names = [];
  240. //echo '<pre><h3>Шаг 2.</h3><br/>'; var_dump($array_children); echo '<pre>'; die();
  241. foreach ($array_children as $parent_id => $children)
  242. {
  243. //echo '<pre><h3>Шаг 2.</h3><br/>'; var_dump($children); echo '<pre>'; die();
  244. if ($activeid != $parent_id)
  245. {
  246. continue;
  247. }
  248. foreach ($children as $res1) {
  249. foreach ($res1 as $key => $res)
  250. {
  251. switch ($key)
  252. {
  253. case 'accepted_time':
  254. $finished[] = $res;
  255. break;
  256. case 'account':
  257. foreach ($res as $acckey => $accval)
  258. {
  259. if ($acckey == 'name')
  260. {
  261. $assignee_names[] = $accval;
  262. break;
  263. }
  264. }
  265. break;
  266. }
  267. }
  268. $taskid = $res1->id;
  269. $type = $res1->type;
  270. $created = $res1->created;
  271. //$accepted = $res1->accepted_time;
  272. //$finished[] = $res1->finished_time;
  273. //$finished[] = $res1->accepted_time->date;
  274. //$assignee = $res1->assignees_arr;
  275. //$assignee_names[] = $res1->name;//GetAccount($assignee)['name'];
  276. //if ($finished == '')
  277. // $finished = 'не завершена';
  278. //if ($accepted == '')
  279. // $accepted = 'не принята';
  280. $namedesc = GetTaskNameAndDesc($type);
  281. // $sheet->setCellValueByColumnAndRow(0, $i, $taskid);
  282. // $sheet->setCellValueByColumnAndRow(1, $i, $namedesc[0]);
  283. // $sheet->setCellValueByColumnAndRow(2, $i, $namedesc[1]);
  284. // $sheet->setCellValueByColumnAndRow(3, $i, $finished);
  285. // $sheet->setCellValueByColumnAndRow(4, $i, $assignee_names);
  286. // $sheet->setCellValueByColumnAndRow(5, $i, $namedesc[1]);
  287. // $sheet->setCellValueByColumnAndRow(6, $i, $assignee_names);
  288. $notes = FindTaskNotes($taskid);
  289. if (sizeof($notes) > 0) {
  290. $nn = 2;
  291. $num = 0;
  292. $notestext = "$taskid. \n";
  293. foreach ($notes as $note) {
  294. $num++;
  295. // if ($num == 3)
  296. // break;
  297. $notedate = $note['date'];
  298. $noteid = $note['id'];
  299. $notetext = $note['text'];
  300. //$sheet->setCellValueByColumnAndRow($nn, $i, $noteid." [".$notedate."] ".$notetext);
  301. $sheet->getStyle('C'.$i)->getAlignment()->setWrapText(true);
  302. $sheet->getStyle('D'.$i)->getAlignment()->setWrapText(true);
  303. $sheet->getStyle('E'.$i)->getAlignment()->setWrapText(true);
  304. $sheet->getStyle('F'.$i)->getAlignment()->setWrapText(true);
  305. $sheet->getStyle('G'.$i)->getAlignment()->setWrapText(true);
  306. $notestext .= $num.". ".$notetext."\n";
  307. //$nn++;
  308. }
  309. $sheet->setCellValueByColumnAndRow($nn, $i, $notestext);
  310. $i++;
  311. }
  312. }
  313. }
  314. $i--;
  315. $sheet->getStyle("B12:D".$i)->applyFromArray($styleBorder);
  316. $i+=2;
  317. $sheet->getRowDimension($i)->setRowHeight(25);
  318. rsort($finished);
  319. $finished_datetime = $finished[0];
  320. //echo '<pre><h3>Шаг 2.</h3><br/>'; var_dump($finished_datetime); echo '<pre>'; die();
  321. if (empty($finished_datetime))
  322. $sheet->setCellValueByColumnAndRow(2, $i, 'Дата окончания осмотра: не завершена');
  323. else
  324. $sheet->setCellValueByColumnAndRow(2, $i, 'Дата окончания осмотра: '.date('Y-m-d H:i:s', strtotime($finished_datetime->date)));
  325. $i+=2;
  326. $sheet->getRowDimension($i)->setRowHeight(30);
  327. $assignee_names = array_unique($assignee_names);
  328. //echo '<pre><h3>Шаг 2.</h3><br/>'; var_dump($assignee_names); echo '<pre>'; die();
  329. $sheet->setCellValueByColumnAndRow(2, $i, 'Исполнитель: '.implode(',', $assignee_names));
  330. // Rename worksheet
  331. $sheet->setTitle('Report');
  332. // Set active sheet index to the first sheet, so Excel opens this as the first sheet
  333. $objPHPExcel->setActiveSheetIndex(0);
  334. $sheet->getColumnDimension('A')->setWidth(17.57);
  335. $sheet->getColumnDimension('B')->setWidth(7.14);
  336. $sheet->getColumnDimension('C')->setWidth(51.29);
  337. $sheet->getColumnDimension('D')->setWidth(51.29);
  338. $sheet->getColumnDimension('E')->setWidth(51.29);
  339. $sheet->getColumnDimension('F')->setWidth(51.29);
  340. $sheet->getColumnDimension('G')->setWidth(51.29);
  341. $sheet->getColumnDimension('H')->setAutoSize(true);
  342. $sheet->getColumnDimension('I')->setAutoSize(true);
  343. $sheet->getColumnDimension('J')->setAutoSize(true);
  344. $sheet->getColumnDimension('K')->setAutoSize(true);
  345. $sheet->getColumnDimension('L')->setAutoSize(true);
  346. $sheet->getColumnDimension('M')->setAutoSize(true);
  347. $objPHPExcel->getActiveSheet()->getStyle('E11')->getAlignment()->setWrapText(true);
  348. $sheet->getStyle("A10:M10")->applyFromArray($style2);
  349. $styleBorder = array('font' => array('bold' => true));
  350. $sheet->getStyle('B1:F1')->applyFromArray($styleBorder);
  351. $sheet->getStyle('A1')->getFont()->setBold(TRUE);
  352. //$sheet->getStyle('B1')->getFont()->getColor()->setRGB('FFFFFF');
  353. //$_SESSION['array_children'] = [];
  354. //$_SESSION['array_parent'] = [];
  355. //$_SESSION['actid'] = [];
  356. // Redirect output to a client’s web browser (Excel5)
  357. header('Content-Type: application/vnd.ms-excel');
  358. $date1 = date('Y.m.d-H.i', strtotime($project_finished->date));
  359. header('Content-Disposition: attachment;filename="'.$date1.'-'.$proj['loco_type'].'-'.$proj['loco_number'].'.xls"');
  360. header('Cache-Control: max-age=0');
  361. // If you're serving to IE 9, then the following may be needed
  362. header('Cache-Control: max-age=1');
  363. // If you're serving to IE over SSL, then the following may be needed
  364. header ('Expires: Mon, 26 Jul 1997 05:00:00 GMT'); // Date in the past
  365. header ('Last-Modified: '.gmdate('D, d M Y H:i:s').' GMT'); // always modified
  366. header ('Cache-Control: cache, must-revalidate'); // HTTP/1.1
  367. header ('Pragma: public'); // HTTP/1.0
  368. $objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5');
  369. //$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel2007');
  370. $objWriter->save('php://output');
  371. ?>