XLStu162table.php 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410
  1. <?
  2. defined('YII_DEBUG') or define('YII_DEBUG', true);
  3. defined('YII_ENV') or define('YII_ENV', 'dev');
  4. require __DIR__ . '/api/vendor/autoload.php';
  5. require __DIR__ . '/api/vendor/yiisoft/yii2/Yii.php';
  6. $config = require __DIR__ . '/api/config/web.php';
  7. (new yii\web\Application($config));
  8. header("Expires: 0");
  9. session_start();
  10. require_once 'PHPExcel-1.8.2/Classes/PHPExcel.php';
  11. include 'auth.php';
  12. include 'functions.php';
  13. require_once "doctrine/bootstrap.php";
  14. include 'CheckPoint.php';
  15. include 'CheckPointType.php';
  16. use CheckPoints\CheckPoint;
  17. use CheckPointTypes\CheckPointType;
  18. global $companyID;
  19. //global $link;
  20. $companyID = $_SESSION['company'];
  21. $sort = $_SESSION['proj_sort'];
  22. $activeid = (int)$_GET['activeid'];
  23. /*
  24. $parents = $entityManager->getRepository('Task')->findBy(array('input_id' => $activeid , 'parent_id' => 0), array('id' => 'DESC'));
  25. $tasktypes = GrabTasktypes();
  26. $tasktypesIds = GrabTasktypesIDs();
  27. //var_dump($_SESSION['array_tasksid']);
  28. //exit;
  29. $arrayMain = [];
  30. $query = mysqli_query($link, "SELECT write_to_twx,name FROM checkpoint_types");
  31. $arrayTwx = [];
  32. while ($checkpoint_arr = mysqli_fetch_array($query))
  33. {
  34. $arrayTwx[$checkpoint_arr['name']] = $checkpoint_arr['write_to_twx'];
  35. }
  36. foreach($_SESSION['array_tasksid'] as $activeid) {
  37. foreach ($parents as $parent) {
  38. if (!in_array(intval($parent->type), $tasktypesIds)){
  39. continue;
  40. }
  41. $status = GetTaskStatus($parent->id);
  42. if ($status == intval($sort)) {
  43. $array_parent[$parent->id] = $parent;
  44. $children = $entityManager->getRepository('Task')->findBy(array('parent_id' => $parent->id));
  45. $array_children[$parent->id] = $children;
  46. }
  47. }
  48. $array_type = [];
  49. $array_id = [];
  50. foreach ($array_children as $parent_id => $children) {
  51. if ($activeid == $parent_id) {
  52. foreach ($children as $res1) {
  53. //EchoTask2($res1, $activeid, false);
  54. $array_type[] = $res1->type;
  55. $array_id[] = $res1->id;
  56. }
  57. }
  58. }
  59. $arResult = [];
  60. //$res = explode(',',$array_type);
  61. //$ids = explode(',',$array_id);
  62. $res = $array_type;
  63. $ids = $array_id;
  64. $arrIds = [];
  65. foreach($res as $key => $r){
  66. $arrIds[$ids[$key]] = $r;
  67. }
  68. foreach($arrIds as $key => $r){
  69. $tenpArray = [];
  70. $type = Tasktype::Find($r);
  71. $tenpArray['name'] = $type->name;
  72. $arResult[$key] = $tenpArray;
  73. }
  74. //echo '<pre><h3>Шаг 1.</h3><br/>'; var_dump($arResult); echo '<pre>'; die();
  75. foreach($arResult as $key => $id){
  76. $notes = FindTaskNotes($key);
  77. $tenpArray = [];
  78. foreach ($notes as $note) {
  79. $tenpArray[] = explode(', TWX',$note['text'])[0];
  80. }
  81. $arResult[$key]['notes'] = $tenpArray;
  82. }
  83. //echo '<pre><h3>Шаг 2.</h3><br/>'; var_dump($arResult); echo '<pre>'; die();
  84. foreach($arResult as $key => $id){
  85. $cps = CheckPoint::FindAllByTask($key);
  86. $tenpArray = [];
  87. foreach ($cps as $cp) {
  88. // var_dump($cp->name);echo "<br>";
  89. $textnotes = $entityManager->getRepository('Tasknote')->findBy(array('checkpoint_id' => $cp->id));
  90. $noteType = '';
  91. if ( 0 != count($textnotes)) {
  92. $noteType = 'Замечание: ';
  93. }
  94. foreach ($textnotes as $tn)
  95. {
  96. $noteType .= $tn->text.', ';
  97. }
  98. $noteType = substr_replace($noteType, ' ', -2);
  99. $temArray = [];
  100. $tenpArray['name'] = $cp->name;
  101. $tenpArray['notesType'] = $noteType;
  102. if ($cp->value != null){
  103. //echo $cp->value;
  104. $temArray[] = $cp->value;
  105. } else {
  106. $children = $cp->childrenCheckpoints;
  107. foreach ($children as $child) {
  108. if ( 1 == $child->state) {
  109. $temArray[]= $child->name;
  110. //var_dump($arrayTwx[$child->name]);
  111. }
  112. //$temArray[] = $child->name;
  113. //echo "$child->name: $child->value $child->state<br>";
  114. }
  115. }
  116. $tenpArray['value'] = implode(',',$temArray);
  117. if ( 1 != $arrayTwx[$tenpArray['value']] ) {
  118. $tenpArray['grey'] = 1;
  119. } else {
  120. $tenpArray['grey'] = 0;
  121. }
  122. if (!empty($tenpArray['value']) && '' != $tenpArray['value']){
  123. $arResult[$key]['maps'][] = $tenpArray;
  124. }
  125. }
  126. }
  127. //echo '<pre><h3>Шаг 3.</h3><br/>'; var_dump($arResult); echo '<pre>'; die();
  128. $rrr = [];
  129. foreach($arResult as $res){
  130. $temp = [];
  131. foreach($res['notes'] as $r){
  132. $temp['name'] = $res['name'];
  133. $temp['desc'] = $r;
  134. $rrr[] = $temp;
  135. }
  136. $temp = [];
  137. foreach($res['maps'] as $b){
  138. $temp['color'] = $b['grey'];
  139. $temp['name'] = $res['name'];
  140. $temp['desc'] = $b['name'].': '.$b['value'].'. '. $b['notesType'];
  141. $rrr[] = $temp;
  142. }
  143. }
  144. $arResult = $rrr;
  145. $arResult['namedesc'] = GetTaskNameAndDesc($array_parent[$activeid]->type)[0];
  146. $finished = [];
  147. foreach ($array_children as $parent_id => $children) {
  148. if ($activeid != $parent_id)
  149. {
  150. continue;
  151. }
  152. foreach ($children as $res1) {
  153. foreach ($res1 as $key => $res) {
  154. switch ($key) {
  155. case 'accepted_time':
  156. $finished[] = $res;
  157. break;
  158. case 'account':
  159. foreach ($res as $acckey => $accval) {
  160. if ($acckey == 'name') {
  161. $assignee_names[] = $accval;
  162. break;
  163. }
  164. }
  165. break;
  166. }
  167. }
  168. }
  169. }
  170. rsort($finished);
  171. $finished_datetime = $finished[0];
  172. foreach($finished_datetime as $key => $res){
  173. if ( 'date' == $key ) {
  174. $finished_datetime = $res;
  175. }
  176. }
  177. $arResult['finished'] = date('Y-m-d H:i:s', strtotime($finished_datetime));
  178. $arrayMain[] = $arResult;
  179. // break;
  180. }
  181. //exit;
  182. //echo "<pre>";
  183. //var_dump($arrayMain);
  184. //echo "</pre>";
  185. //var_dump($_SESSION['array_tasksid']);
  186. //exit;
  187. function cellColor($cells,$color){
  188. global $objPHPExcel;
  189. $objPHPExcel->getActiveSheet()->getStyle($cells)->getFill()->applyFromArray(array(
  190. 'type' => PHPExcel_Style_Fill::FILL_SOLID,
  191. 'startcolor' => array(
  192. 'rgb' => $color
  193. )
  194. ));
  195. }
  196. $styleBorder = array(
  197. 'borders' => array(
  198. 'allborders' => array(
  199. 'style' => PHPExcel_Style_Border::BORDER_THIN
  200. )
  201. )
  202. );
  203. foreach (array_keys($_REQUEST) as $var)
  204. {
  205. ${$var}=$_REQUEST[$var];
  206. //echo "<b>$var:</b> ${$var} <br>";
  207. }
  208. $array_children = $_SESSION['array_children'];
  209. $array_parent = $_SESSION['array_parent'];
  210. $activeid = $_SESSION['actid'];
  211. $lastActiveId = array_pop($_SESSION['array_tasksid']);
  212. //$res_parent = $array_parent[$activeid];
  213. $res_parent = $array_parent[$lastActiveId];
  214. foreach($res_parent as $key => $r) {
  215. if ('type' == $key){
  216. $res_parent_type = $r;
  217. }
  218. if ('input_id' == $key){
  219. $res_parent_input_id = $r;
  220. }
  221. if ( 'created' == $key) {
  222. $res_parent_created = $r;
  223. }
  224. }
  225. */
  226. //echo "<pre>";
  227. //var_dump($activeid);echo "<br>";
  228. //var_dump($array_children);echo "<br>";
  229. //echo "</pre>";
  230. //exit;
  231. $namedesc = GetTaskNameAndDesc($res_parent_type);
  232. //$namedesc = GetTaskNameAndDesc($res_parent['type']);
  233. $proj = GetProject($res_parent_input_id);
  234. $sections = \app\models\entity\Sections::findAll(['section_number' => $proj['loco_number']]);
  235. //$proj = GetProject($res_parent['input_id']);
  236. $depo = $proj['depo'];
  237. $depo_service = $proj['depo_service'];
  238. $project_finished = $res_parent_created;
  239. //echo '<pre><h3>Шаг 1.</h3><br/>'; var_dump($finished); echo '<pre>'; die();
  240. //$finished = $res_parent['created'];
  241. $query = 'select spl.value,tt.name from (select t.parent_id as id, ch.value from `checkpoints` as `ch`
  242. LEFT JOIN `tasks` AS `t` ON ch.parent_task_id = t.id
  243. LEFT JOIN `projects_locotech` AS `pl` ON t.input_id = pl.id
  244. WHERE pl.id = '.$proj['id'].' and ch.type = 310 ) as `spl`
  245. LEFT JOIN `tasks` AS `ts` ON spl.id = ts.id
  246. LEFT JOIN `tasktypes` AS `tt` ON ts.type = tt.id';
  247. $queryRes = mysqli_query($link, $query);
  248. while ($checkpoint_arr = mysqli_fetch_array($queryRes))
  249. {
  250. var_dump($checkpoint_arr);
  251. }
  252. $query = 'select ch.text,ch.value from `projects_locotech` AS `pl`
  253. LEFT JOIN `tasks` as `t` ON pl.id = t.input_id
  254. LEFT JOIN `checkpoints` as `ch` ON t.id = ch.parent_task_id
  255. WHERE pl.id = '.$proj['id'].' and t.type = 741 ';
  256. $queryRes = mysqli_query($link, $query);
  257. $invArray = [];
  258. $k = 32;
  259. while ($checkpoint_arr = mysqli_fetch_assoc($queryRes))
  260. {
  261. $invArray[$k] = $checkpoint_arr['value'];
  262. $k++;
  263. }
  264. $k = 32;
  265. foreach($invArray as $inv){
  266. $sheet->setCellValue('AI'.$k, ($inv[$k])? $inv[$k] : '-' );
  267. $k++;
  268. }
  269. //exit;
  270. $objPHPExcel = PHPExcel_IOFactory::load($_SERVER['DOCUMENT_ROOT'].'/uploads/xls/tu162.xlsx');
  271. $sheet = $objPHPExcel->getActiveSheet(0);
  272. $k = 8;
  273. $arrForSecondTableHeader = [];
  274. foreach($sections as $section){
  275. $sheet->setCellValue('B'.$k, $section->locomotive_series);
  276. $sheet->setCellValue('I'.$k, $section->section_subnumber);
  277. $sheet->setCellValue('P'.$k, $section->section_number.$section->letter);
  278. $sheet->setCellValue('X'.$k, ($depo)?$depo: 'пусто');
  279. $arrForSecondTableHeader[] = $section->section_number.$section->letter.'/'.$section->section_subnumber;
  280. $k++;
  281. }
  282. $arrSecondTbl = [1 => 'AB20',2 => 'AL20', 3 => 'AT20',4 => 'DB29'];
  283. $k = 1;
  284. foreach( $arrForSecondTableHeader as $header) {
  285. $sheet->setCellValue($arrSecondTbl[$k],$header );
  286. $k++;
  287. }
  288. $sheet->setCellValue('B3', 'АКТ № ' . $proj['id']);
  289. //"Локомотив серия ".$proj['loco_type']." номер ".$proj['loco_number']
  290. //var_dump($proj);
  291. //exit;
  292. $sheet->setCellValue('AJ32', 22);
  293. // Redirect output to a client’s web browser (Excel5)
  294. header('Content-Type: application/vnd.ms-excel');
  295. $date1 = date('Y.m.d-H.i', strtotime($project_finished->date));
  296. header('Content-Disposition: attachment;filename="'.$date1.'-'.$proj['loco_type'].'-'.$proj['loco_number'].'.xls"');
  297. header('Cache-Control: max-age=0');
  298. // If you're serving to IE 9, then the following may be needed
  299. header('Cache-Control: max-age=1');
  300. // If you're serving to IE over SSL, then the following may be needed
  301. header ('Expires: Mon, 26 Jul 1997 05:00:00 GMT'); // Date in the past
  302. header ('Last-Modified: '.gmdate('D, d M Y H:i:s').' GMT'); // always modified
  303. header ('Cache-Control: cache, must-revalidate'); // HTTP/1.1
  304. header ('Pragma: public'); // HTTP/1.0
  305. $objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5');
  306. //$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel2007');
  307. $objWriter->save('php://output');
  308. ?>