Advertisement
Guest User

Untitled

a guest
Mar 6th, 2017
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.39 KB | None | 0 0
  1. <?php
  2. $servername = "localhost:3306";
  3. $username = "root";
  4. $password = "root";
  5. $dbname = "fsharkc_efetasks";
  6.  
  7. $itemId = $_REQUEST['itemId'];
  8.  
  9. //Classes
  10. class HorasFenix {
  11. public $dataLancada= '';
  12. public $horasTrabalhadas= '';
  13. }
  14.  
  15. class Fenix {
  16. public $horasFenix = '';
  17. public $etc = '';
  18. }
  19.  
  20. class DataPlanejamento {
  21. public $data = '';
  22. }
  23. //Classes - FIM
  24.  
  25. // Instâncicas
  26. $fenix = new Fenix;
  27. $horasFenix = new HorasFenix;
  28. $dataPlanejamento = new DataPlanejamento;
  29.  
  30. // Variaveis
  31. $createDate = '';
  32. $deadLineDate = '';
  33.  
  34. //MySQL==============================================================================================================================
  35. $conn = mysqli_connect($servername, $username, $password, $dbname);
  36. // Check connection
  37. if (!$conn) {
  38. die("Connection failed: " . mysqli_connect_error());
  39. }
  40.  
  41. //=====================================SQL PARA PEGAR INFORMAÇÕES DA TABELA everis_hours_fenix
  42. $sqlEverisHours = "SELECT itemId,date,incurred,etc FROM everis_hours_fenix WHERE itemId = $itemId";
  43.  
  44. //=====================================SQL PARA PEGAR O ETC DA DATA MAIS RECENTE
  45. $sqlMaxEtc = "SELECT etc
  46. FROM everis_hours_fenix AS a
  47. WHERE date = (
  48. SELECT MAX(date)
  49. FROM everis_hours_fenix AS b
  50. WHERE a.itemId = $itemId
  51. )";
  52.  
  53. $resultEverisHours = mysqli_query($conn, $sqlEverisHours);
  54. $resultMaxEtc = mysqli_query($conn, $sqlMaxEtc);
  55.  
  56. // Cria array
  57. $arrayHF = array();
  58. $countLancamento;
  59.  
  60. // LÓGICA EVERIS HOURS
  61. if (mysqli_num_rows($resultEverisHours) > 0) {
  62.  
  63. // output data of each row
  64. while($row = mysqli_fetch_assoc($resultEverisHours)) {
  65.  
  66. // Objeto horasFenix
  67. $horasFenix = "";
  68. $horasFenix->dataLancada = date("d-m-Y", strtotime($row["date"]));
  69. $horasFenix->horasTrabalhadas = $row["incurred"];
  70.  
  71. // Insere no array
  72. $countLancamento++;
  73. array_push($arrayHF, $horasFenix);
  74. }
  75. } else {
  76. //echo "0 results - SELECT EVERIS HOURS";
  77. }
  78.  
  79. // LÓGICA MAX DATE ETC
  80. if (mysqli_num_rows($resultMaxEtc) > 0) {
  81.  
  82. // output data of each row
  83. while($row = mysqli_fetch_assoc($resultMaxEtc)) {
  84.  
  85. $fenix->etc = $row["etc"];
  86. }
  87. } else {
  88. //echo "0 results - SELECT MAX DATE ETC";
  89. }
  90. //=====================================SQL PARA PEGAR createDate e deadLineDate
  91. $sqlCreateDeadLineDate = "SELECT a.deadlineDate, b.statusDate
  92. FROM fsharkc_efetasks.frk_item a,
  93. fsharkc_efetasks.frk_itemstatus b
  94. where a.itemId = b.itemId
  95. and a.itemId = $itemId
  96. and b.statusKey = 0";
  97.  
  98. $resultCreateDeadLineDates = mysqli_query($conn, $sqlCreateDeadLineDate);
  99.  
  100. if (mysqli_num_rows($resultCreateDeadLineDates) > 0) {
  101.  
  102. // output data of each row
  103. while($row = mysqli_fetch_assoc($resultCreateDeadLineDates)) {
  104. $deadLineDate = $row["deadlineDate"];
  105. $createDate = date("Y-m-d", strtotime($row["statusDate"]));
  106. }
  107.  
  108. if ($deadLineDate == '9999-00-00') {
  109. $dt = new DateTime();
  110. $dtFmt = $dt->format('Y-m-d');
  111. $deadLineDate = date('Y-m-d',strtotime($dtFmt . "+1 days"));
  112. }
  113. } else {
  114. //echo "0 results";
  115. }
  116.  
  117. //=====================================SQL PARA PEGAR TODAS AS DATAS DO RANGE $createDate e $deadLineDate
  118. $sqlRangeDates = "select * from
  119. (select adddate('1970-01-01',t4*10000 + t3*1000 + t2*100 + t1*10 + t0) selected_date from
  120. (select 0 t0 union select 1 union select 2 union select 3 union select 4 union select 5 union select 6 union select 7 union select 8 union select 9) t0,
  121. (select 0 t1 union select 1 union select 2 union select 3 union select 4 union select 5 union select 6 union select 7 union select 8 union select 9) t1,
  122. (select 0 t2 union select 1 union select 2 union select 3 union select 4 union select 5 union select 6 union select 7 union select 8 union select 9) t2,
  123. (select 0 t3 union select 1 union select 2 union select 3 union select 4 union select 5 union select 6 union select 7 union select 8 union select 9) t3,
  124. (select 0 t4 union select 1 union select 2 union select 3 union select 4 union select 5 union select 6 union select 7 union select 8 union select 9) t4) v
  125. where selected_date between \"".$createDate."\" and \"".$deadLineDate."\" ";
  126.  
  127. $resultRangeDates = mysqli_query($conn, $sqlRangeDates);
  128.  
  129. // Cria array
  130. $arrayRangeDt = array();
  131. $countDataPlanejamento;
  132.  
  133. // LÓGICA TRAZER TODAS AS DATAS DO RANGE
  134. if (mysqli_num_rows($resultRangeDates) > 0) {
  135.  
  136. // output data of each row
  137. while($row = mysqli_fetch_assoc($resultRangeDates)) {
  138.  
  139. // Insere no array
  140. $countDataPlanejamento++;
  141. array_push($arrayRangeDt, date("d-m-Y", strtotime($row["selected_date"])));
  142. }
  143. } else {
  144. //echo "0 results";
  145. }
  146. // fecha conexão mysql
  147. mysqli_close($conn);
  148. //MySQL - FIM========================================================================================================================
  149.  
  150. if ($countDataPlanejamento > $countLancamento) {
  151.  
  152. $diferenca = ($countDataPlanejamento - $countLancamento);
  153.  
  154. $x = 1;
  155.  
  156. while($x <= $diferenca) {
  157. $horasFenix = "";
  158. $horasFenix->dataLancada = "";
  159. $horasFenix->horasTrabalhadas = "";
  160. array_push($arrayHF, $horasFenix);
  161. $x++;
  162. }
  163. }
  164.  
  165. // Objeto fenix
  166. $fenix->horasFenix = $arrayHF;
  167. $fenix->dataPlanejamento = $arrayRangeDt;
  168.  
  169. $myJSON = json_encode($fenix);
  170. echo $myJSON;
  171. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement