Advertisement
Guest User

Untitled

a guest
Jan 23rd, 2019
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 10.59 KB | None | 0 0
  1. /**Imprimir Cronograma */
  2. function obtemMapaCronoImpressao() {
  3. var linhas = {};
  4. /* Para cada dia */
  5. var diasMesmaHora = [];
  6. var divisaoHorasArray = [];
  7.  
  8. $.each(dadosAcao.eventos, function (dia, events) {
  9. var current = new Date(parseInt(dia) * 1000);
  10. current.setHours(13 - (current.getTimezoneOffset() / 60), 0, 0, 0);
  11. diasMesmaHora.push(parseInt(current.getTime() / 1000));
  12. /* Ordenar eventos por hora */
  13. events.sort(function (obj1, obj2) {
  14. return comparaHoras(obj1.horade, obj2.horade);
  15. });
  16. $.each(events, function (index, evento) {
  17. var de = horaParaMinutos(evento.horade);
  18. var ate = horaParaMinutos(evento.horaate);
  19. //Vou ver se o de começa na hora certa
  20. var hours = Math.floor(de / 60);
  21. var horaInicialEmMinutos = hours * 60;
  22.  
  23. for (var horainicial = horaInicialEmMinutos; horainicial < ate; horainicial = horainicial + 60) {
  24. var object = $.extend({}, evento);
  25. object.hInicial = horainicial;
  26. object.hFinal = horainicial + 60;
  27. if (object.hInicial < de)
  28. object.hInicial = de;
  29. if (object.hFinal > ate)
  30. object.hFinal = ate;
  31. object.hDuracao = object.hFinal - object.hInicial;
  32. var a = Math.floor(object.hInicial / 60);
  33. var b = object.hInicial % 60;
  34. object.horasssInicial = '' + a + ':' + b;
  35. var a = Math.floor(object.hFinal / 60);
  36. var b = object.hFinal % 60;
  37. object.horasssFinal = '' + a + ':' + b;
  38.  
  39. if (linhas[horainicial] === undefined) {
  40. linhas[horainicial] = {};
  41. }
  42. if (linhas[horainicial][parseInt(current.getTime() / 1000)] === undefined) {
  43. linhas[horainicial][parseInt(current.getTime() / 1000)] = {};
  44. }
  45. var tamanho = Object.keys(linhas[horainicial][parseInt(current.getTime() / 1000)]).length;
  46. linhas[horainicial][parseInt(current.getTime() / 1000)][tamanho] = object;
  47. }
  48.  
  49. });
  50. });
  51.  
  52. diasMesmaHora = uniqueArray(diasMesmaHora).sort();
  53.  
  54. var rows = '';
  55. var acumulados = {};
  56. $.each(linhas, function (hora, linha) {
  57. var horaInicial = 0;
  58. var auxInicio = 1440;
  59. var auxFinal = 0;
  60. //Vou buscar o inicio mais cedo e o fim mais tarde
  61. $.each(diasMesmaHora, function (j, dia) {
  62. $.each(linha[dia], function (indexEvento, evento) {
  63. if (evento.hInicial < auxInicio) {
  64. auxInicio = evento.hInicial;
  65. }
  66. if (evento.hFinal > auxFinal) {
  67. auxFinal = evento.hFinal;
  68. }
  69. });
  70. });
  71. rows = rows + '<tr>';
  72.  
  73. var hours = Math.floor(parseInt(auxInicio) / 60);
  74. var minutes = 0;
  75. horaInicial = horaParaMinutos(pad(hours, 2) + ':' + pad(minutes, 2));
  76. rows = rows + '<td class="headcol">' + pad(hours, 2) + ':' + pad(minutes, 2) + '</td>';
  77. hours = Math.ceil(parseInt(auxFinal) / 60);
  78. minutes = 0;
  79. rows = rows + '<td class="headcol">' + pad(hours, 2) + ':' + pad(minutes, 2) + '</td>';
  80. var mesAnterior = null;
  81. var anoAnterior = null;
  82. $.each(diasMesmaHora, function (j, dia) {
  83. border = '';
  84. var mesDate = new Date(dia * 1000);
  85. var mes = mesDate.getMonth();
  86. var ano = mesDate.getFullYear();
  87. if (mesAnterior != mes || anoAnterior != ano) {
  88. border = 'border-left:1px solid #000000';
  89. }
  90. mesAnterior = mes;
  91. anoAnterior = ano;
  92.  
  93.  
  94.  
  95.  
  96.  
  97. if (acumulados[dia] === undefined) {
  98. acumulados[dia] = {};
  99. }
  100. if (linha[dia] === undefined) {
  101. rows = rows + '<td style="' + border + '"></td>';
  102. } else {
  103. //não sei se é preciso ordenar os eventos no mesmo dia e dentro da mesma hora
  104. // (linha[dia]).sort(function (obj1, obj2) {
  105. // return comparaHoras(obj1.horade, obj2.horade);
  106. // });
  107. var texto = '';
  108. var background = '';
  109.  
  110. var spots = {};
  111.  
  112. $.each(linha[dia], function (indexEvento, evento) {
  113.  
  114. divisaoHorasArray.push(parseInt(evento.divisaoHoras));
  115. if (acumulados[dia][evento.divisaoHoras] === undefined) {
  116. acumulados[dia][evento.divisaoHoras] = 0;
  117. }
  118. acumulados[dia][evento.divisaoHoras] += evento.hDuracao;
  119. if (evento.hDuracao < 58) {
  120. //var deAux = horaParaMinutos(evento.horade);
  121. var auxMinutos = Math.abs(evento.hInicial - horaInicial);
  122. //Quando começa o spot
  123. var inicioSpot = Math.round((auxMinutos % 60) / 15);
  124. var numeroSpots = Math.round(evento.hDuracao / 15);
  125. for (var i = 0; i < numeroSpots; i++) {
  126. spots[inicioSpot + i] = {
  127. cor: evento.cor,
  128. texto: $('input[name=divisaoHoras][value=' + evento.divisaoHoras + ']', '#acao_cronograma').closest('label').find('.codnome').text()
  129. };
  130. }
  131. } else {
  132. //Só tem 1 evento
  133. for (var i = 0; i < 4; i++) {
  134. spots[i] = {
  135. cor: evento.cor,
  136. texto: $('input[name=divisaoHoras][value=' + evento.divisaoHoras + ']', '#acao_cronograma').closest('label').find('.codnome').text()
  137. };
  138. }
  139. }
  140.  
  141. });
  142.  
  143. //Vou encher spots em branco
  144. var auxColor = '';
  145. var auxTexto = '';
  146. var auxPercent = 0;
  147. var cor = 'transparent';
  148. var t = '';
  149. for (var i = 0; i < 4; i++) {
  150. t = '';
  151. cor = 'transparent';
  152. if (spots[i] != undefined) {
  153. cor = spots[i].cor;
  154. t = spots[i].texto;
  155. }
  156. if ((auxColor != cor || auxTexto != t) && auxColor !== '') {
  157. texto = texto + '<span style="text-align:center;width: ' + auxPercent + '%;display: inline-block;color:' + darkOrLight(auxColor) + '!important;">' + auxTexto + '</span>';
  158. auxPercent = 0;
  159. }
  160. spots[i] = cor + ' ' + (i * 25) + '%, ' + cor + ' ' + ((i + 1) * 25) + '%';
  161. auxPercent = auxPercent + 25;
  162. auxColor = cor;
  163. auxTexto = t;
  164. }
  165. texto = texto + '<span style="text-align:center;width: ' + auxPercent + '%;display: inline-block;color:' + darkOrLight(auxColor) + '!important;">' + auxTexto + '</span>';
  166.  
  167. var s = "";
  168. for (var i in spots) {
  169. s += spots[i] + ", ";
  170. }
  171. s = s.substring(0, s.length - 2);
  172. background = 'background:linear-gradient(to right,' + s + ')!important;';
  173. rows = rows + '<td style="' + background + border + '">' + texto + '</td>';
  174. }
  175. });
  176. rows = rows + '<td class="headcolFim"></td></tr>';
  177. });
  178.  
  179.  
  180.  
  181. /* ACULUMADOS */
  182. var divisaoHorasFiltrado = uniqueArray(divisaoHorasArray).sort();
  183. var primeira = true;
  184. var totalDia = {};
  185. console.log(divisaoHorasFiltrado,'divisaoHorasFiltrado');
  186. $.each(divisaoHorasFiltrado, function (i, divisaoHoras) {
  187. rows = rows + '<tr>';
  188. if (primeira) {
  189. rows = rows + '<td rowspan="' + (divisaoHorasFiltrado.length + 3) + '" class="headcol" style="height:' + (((divisaoHorasFiltrado.length) * 32) - 8) + 'px">Nº Horas</td>';
  190. primeira = false;
  191. }
  192. rows = rows + '<td class="headcol paddingLeft" title="' + $('input[name=divisaoHoras][value=' + divisaoHoras + ']', '#acao_cronograma').closest('label').find('.nome').attr('title') + '">' + $('input[name=divisaoHoras][value=' + divisaoHoras + ']', '#acao_cronograma').closest('label').find('.codnome').html() + '</td>';
  193. var totalTipo = 0;
  194. var mesAnterior = null;
  195. var anoAnterior = null;
  196. $.each(diasMesmaHora, function (j, dia) {
  197. border = '';
  198. var mesDate = new Date(dia * 1000);
  199. var mes = mesDate.getMonth();
  200. var ano = mesDate.getFullYear();
  201. if (mesAnterior != mes || anoAnterior != ano) {
  202. border = 'border-left:1px solid #000000';
  203. }
  204. mesAnterior = mes;
  205. anoAnterior = ano;
  206.  
  207.  
  208. if (acumulados[dia][divisaoHoras] === undefined) {
  209. rows = rows + '<td style="' + border + '">0</td>';
  210. } else {
  211. var aux = Math.round((acumulados[dia][divisaoHoras] / 60) * 4) / 4;
  212. rows = rows + '<td style="' + border + '">' + (aux) + '</td>';
  213. totalTipo = totalTipo + (aux);
  214. if (totalDia[dia] === undefined) {
  215. totalDia[dia] = 0;
  216. }
  217. totalDia[dia] = totalDia[dia] + (aux);
  218. }
  219.  
  220. });
  221. rows = rows + '<td class="headcolFim">' + totalTipo + '</td>';
  222. rows = rows + '</tr>';
  223. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement