Advertisement
Guest User

Untitled

a guest
Mar 3rd, 2017
147
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.07 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. $sqlCreateDeadLineDates = "SELECT createDate, deadlineDate FROM fsharkc_efetasks.frk_item
  92. where itemId = $itemId";
  93.  
  94. $resultCreateDeadLineDates = mysqli_query($conn, $sqlCreateDeadLineDates);
  95.  
  96. if (mysqli_num_rows($resultCreateDeadLineDates) > 0) {
  97.  
  98. // output data of each row
  99. while($row = mysqli_fetch_assoc($resultCreateDeadLineDates)) {
  100. $createDate = $row["createDate"];
  101. $deadLineDate = $row["deadlineDate"];
  102. }
  103. } else {
  104. echo "0 results";
  105. }
  106. //=====================================SQL PARA PEGAR TODAS AS DATAS DO RANGE $createDate e $deadLineDate
  107. $sqlRangeDates = "select * from
  108. (select adddate('1970-01-01',t4*10000 + t3*1000 + t2*100 + t1*10 + t0) selected_date from
  109. (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,
  110. (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,
  111. (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,
  112. (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,
  113. (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
  114. where selected_date between \"".$createDate."\" and \"".$deadLineDate."\" ";
  115.  
  116. $resultRangeDates = mysqli_query($conn, $sqlRangeDates);
  117.  
  118. // Cria array
  119. $arrayRangeDt = array();
  120. $countDataPlanejamento;
  121.  
  122. // LÓGICA TRAZER TODAS AS DATAS DO RANGE
  123. if (mysqli_num_rows($resultRangeDates) > 0) {
  124.  
  125. // output data of each row
  126. while($row = mysqli_fetch_assoc($resultRangeDates)) {
  127.  
  128. // Insere no array
  129. $countDataPlanejamento++;
  130. array_push($arrayRangeDt, date("d-m-Y", strtotime($row["selected_date"])));
  131. }
  132. } else {
  133. echo "0 results";
  134. }
  135. // fecha conexão mysql
  136. mysqli_close($conn);
  137. //MySQL - FIM========================================================================================================================
  138.  
  139. if ($countDataPlanejamento > $countLancamento) {
  140.  
  141. $diferenca = ($countDataPlanejamento - $countLancamento);
  142.  
  143. $x = 1;
  144.  
  145. while($x <= $diferenca) {
  146. $horasFenix = "";
  147. $horasFenix->dataLancada = null;
  148. $horasFenix->horasTrabalhadas = null;
  149. array_push($arrayHF, $horasFenix);
  150. $x++;
  151. }
  152. }
  153.  
  154. // Objeto fenix
  155. $fenix->horasFenix = $arrayHF;
  156. $fenix->dataPlanejamento = $arrayRangeDt;
  157.  
  158. $myJSON = json_encode($fenix);
  159. echo $myJSON;
  160. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement