No Description

ordenes.html 14KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340
  1. {% extends 'header.html' %}
  2. {% block css %}
  3. <link rel='stylesheet' href='/static/css/tienda.css'>
  4. {% endblock %}
  5. {% block body %}
  6. <br>
  7. <br>
  8. <div class='container-fluid'>
  9. <div class='row' id='ElQueue'>
  10. </div>
  11. </div>
  12. <script>
  13. var ordenes = jQuery.parseJSON('{{ ordenes | tojson | safe}}');
  14. var cantidadDeOrdenesPendientes = 0;
  15. var queue = [];
  16. $(document).ready(function () {
  17. for (orden in ordenes) {
  18. var modal = '<div class="modal fade" id="Modal' + orden + '">' +
  19. '<div class="modal-dialog" role="document">' +
  20. '<div class="modal-content">' +
  21. '<div class="modal-header">' +
  22. '<h5 class="modal-title">Orden #' + orden + '</h5>' +
  23. '<button type="button" class="close" data-dismiss="modal" aria-label="Close">' +
  24. '<span aria-hidden="true">&times;</span>' +
  25. '</button>' +
  26. '</div>' + '<div class="modal-body">';
  27. var comida = '';
  28. var bebida = '';
  29. var total = 0;
  30. for (var i = 0; i < ordenes[orden].ordenCompleta.length; i++) {
  31. if (ordenes[orden].ordenCompleta[i].comida_bebida == 0) {
  32. comida += '<h6 style ="padding-left: 4em">' + ordenes[orden].ordenCompleta[i].nombre + ': $' + ordenes[orden].ordenCompleta[i].precio.toFixed(2) + '</h6>';
  33. comida += '<p style ="padding-left: 8em">' + ordenes[orden].ordenCompleta[i].peticion + '</p>';
  34. }
  35. else {
  36. bebida += '<h6 style ="padding-left: 4em">' + ordenes[orden].ordenCompleta[i].nombre + ': $' + ordenes[orden].ordenCompleta[i].precio.toFixed(2) + '</h6>';
  37. bebida += '<p style ="padding-left: 8em">' + ordenes[orden].ordenCompleta[i].peticion + '</p>';
  38. }
  39. total += ordenes[orden].ordenCompleta[i].precio
  40. }
  41. if (comida != '') {
  42. modal += '<h4>Comida: </h4>' + comida;
  43. }
  44. if (bebida != '') {
  45. modal += '<h4>Bebida: </h4>' + bebida;
  46. }
  47. modal += '<h6 style="text-align: right">Precio : $' + total.toFixed(2) + '</h6>' +
  48. '</div>' +
  49. '<div class="modal-footer">' +
  50. '<button type ="button" class ="btn btn-primary" onclick= "deleteOrder(' + orden + ')">' +
  51. 'Orden terminada</button>' +
  52. '</div>' +
  53. '</div>' +
  54. '</div>' +
  55. '</div>';
  56. var card = '<div class="col-auto" id ="order' + orden + '"><div class="card" style =" width: 18rem; height: 20rem; background-color: rgba(219, 226,230, 0.6)">' +
  57. '<div class="card-body">' +
  58. '<p class="card-title"><strong>Orden #' + orden + '</strong></p>' +
  59. '<p class="card-text" ><strong>Precio :' + total.toFixed(2) +
  60. '</strong></p>' +
  61. '<p class="card-text" ><strong>Nombre :' + ordenes[orden].nombre +
  62. '</strong></p>' +
  63. '<p class="card-text" ><strong>Teléfono :' + ordenes[orden].num_celular +
  64. '</strong></p>' +
  65. '</div>' +
  66. '<div class="card-footer">' +
  67. '<button type="button" class="btn btn-warning" data-toggle="modal" data-target="#Modal' + orden + '">' +
  68. 'Ver detalles</button>' +
  69. '<button type="button" class="btn btn-primary" onclick=" deleteOrder(' + orden + ')">' +
  70. 'Terminada </button>' + '</div>' + '</div></div>';
  71. $('#ElQueue').append(card);
  72. $('#ElQueue').append(modal);
  73. cantidadDeOrdenesPendientes += 1;
  74. if (cantidadDeOrdenesPendientes >= 7) {
  75. addToQueue(ordenes);
  76. break;
  77. }
  78. }
  79. });
  80. $(document).ready(function () {
  81. setInterval(function () {
  82. let url = "/papelonDeComida";
  83. // Get
  84. $.get(url, function (d) { // jquery function that 'does' the GET request
  85. if (cantidadDeOrdenesPendientes >= 7) {
  86. addToQueue(d);
  87. return;
  88. }
  89. for (orden in d) {
  90. var modal = '<div class="modal fade" id="Modal' + orden + '">' +
  91. '<div class="modal-dialog" role="document">' +
  92. '<div class="modal-content">' +
  93. '<div class="modal-header">' +
  94. '<h5 class="modal-title">Orden #' + orden + '</h5>' +
  95. '<button type="button" class="close" data-dismiss="modal" aria-label="Close">' +
  96. '<span aria-hidden="true">&times;</span>' +
  97. '</button>' +
  98. '</div>' + '<div class="modal-body">';
  99. var comida = '';
  100. var bebida = '';
  101. var total = 0;
  102. for (var i = 0; i < d[orden].ordenCompleta.length; i++) {
  103. if (d[orden].ordenCompleta[i].comida_bebida == 0) {
  104. comida += '<h6 style ="padding-left: 4em">' + d[orden].ordenCompleta[i].nombre + ': $' + d[orden].ordenCompleta[i].precio.toFixed(2) + '</h6>';
  105. comida += '<p style ="padding-left: 8em">' + d[orden].ordenCompleta[i].peticion + '</p>';
  106. }
  107. else {
  108. bebida += '<h6 style ="padding-left: 4em">' + d[orden].ordenCompleta[i].nombre + ': $' + d[orden].ordenCompleta[i].precio.toFixed(2) + '</h6>';
  109. bebida += '<p style ="padding-left: 8em">' + d[orden].ordenCompleta[i].peticion + '</p>';
  110. }
  111. total += d[orden].ordenCompleta[i].precio
  112. }
  113. if (comida != '') {
  114. modal += '<h4>Comida: </h4>' + comida;
  115. }
  116. if (bebida != '') {
  117. modal += '<h4>Bebida: </h4>' + bebida;
  118. }
  119. modal += '<h6 style="text-align: right">Precio : $' + total.toFixed(2) + '</h6>' +
  120. '</div>' +
  121. '<div class="modal-footer">' +
  122. '<button type ="button" class ="btn btn-primary" onclick= "deleteOrder(' + orden + ')">' +
  123. 'Orden terminada</button>' +
  124. '</div>' +
  125. '</div>' +
  126. '</div>' +
  127. '</div>';
  128. var card = '<div class="col-auto" id ="order' + orden + '"><div class="card" style =" width: 18rem; height: 20rem; background-color: rgba(219, 226,230, 0.6)">' +
  129. '<div class="card-body">' +
  130. '<p class="card-title"><strong>Orden #' + orden + '</strong></p>' +
  131. '<p class="card-text" ><strong>Precio :' + total.toFixed(2) +
  132. '</strong></p>' +
  133. '<p class="card-text" ><strong>Nombre :' + d[orden].nombre +
  134. '</strong></p>' +
  135. '<p class="card-text" ><strong>Teléfono :' + d[orden].num_celular +
  136. '</strong></p>' +
  137. '</div>' +
  138. '<div class="card-footer">' +
  139. '<button type="button" class="btn btn-warning" data-toggle="modal" data-target="#Modal' + orden + '">' +
  140. 'Ver detalles</button>' +
  141. '<button type="button" class="btn btn-primary" onclick=" deleteOrder(' + orden + ')">' +
  142. 'Terminada </button>' + '</div>' + '</div></div>';
  143. $('#ElQueue').append(card);
  144. $('#ElQueue').append(modal);
  145. cantidadDeOrdenesPendientes += 1;
  146. }
  147. });
  148. }, 30000); // here we have set 1s (1000 ms)
  149. });
  150. function addToQueue(CualquierOrden) {
  151. for (order in CualquierOrden) {
  152. if ($('#order' + order).length || queue.includes(order)) {
  153. continue;
  154. }
  155. else {
  156. sig_orden = {};
  157. sig_orden[order] = CualquierOrden[order];
  158. queue.push(sig_orden);
  159. cantidadDeOrdenesPendientes += 1;
  160. }
  161. }
  162. var card = '<div class="col-auto" id ="ordenPendiente"><div class="card" style =" width: 18rem; height: 20rem; background-color: rgba(219, 226,230, 0.6)">' +
  163. '<div class="card-body">' +
  164. '<p class="card-title"><strong>Ordenes PENDIENTES SIN VER</strong></p>' +
  165. '<p class="card-text" ><strong>' + (cantidadDeOrdenesPendientes - 7).toString() +
  166. '</strong></p>' +
  167. '<p class="card-text" ><strong> AVANCEN LES GOOO' +
  168. '</strong></p>' +
  169. '</div>' +
  170. '<div class="card-footer">' +
  171. '</div>' + '</div></div>';
  172. $('#ordenPendiente').remove()
  173. $('#ElQueue').append(card);
  174. }
  175. function deleteOrder(orderId) {
  176. var order = orderId;
  177. var xhr = new XMLHttpRequest();
  178. xhr.open("POST", '/ordenes', true);
  179. xhr.setRequestHeader('Content-Type', 'application/json');
  180. xhr.send(JSON.stringify(
  181. {
  182. 'order': orderId
  183. }
  184. ));
  185. xhr.onload = function () {
  186. if (xhr.status != 200) { // analyze HTTP status of the response
  187. alert(`Error ${xhr.status}: ${xhr.statusText}`); // e.g. 404: Not Found
  188. } else { // show the result
  189. $('#order' + orderId.toString()).remove();
  190. $('#ordenPendiente').remove();
  191. cantidadDeOrdenesPendientes -= 1;
  192. todaOrden = queue.shift();
  193. for (orden in todaOrden) {
  194. var modal = '<div class="modal fade" id="Modal' + orden + '">' +
  195. '<div class="modal-dialog" role="document">' +
  196. '<div class="modal-content">' +
  197. '<div class="modal-header">' +
  198. '<h5 class="modal-title">Orden #' + orden + '</h5>' +
  199. '<button type="button" class="close" data-dismiss="modal" aria-label="Close">' +
  200. '<span aria-hidden="true">&times;</span>' +
  201. '</button>' +
  202. '</div>' + '<div class="modal-body">';
  203. var comida = '';
  204. var bebida = '';
  205. var total = 0;
  206. for (var i = 0; i < todaOrden[orden].ordenCompleta.length; i++) {
  207. if (todaOrden[orden].ordenCompleta[i].comida_bebida == 0) {
  208. comida += '<h6 style ="padding-left: 4em">' + todaOrden[orden].ordenCompleta[i].nombre + ': $' + todaOrden[orden].ordenCompleta[i].precio.toFixed(2) + '</h6>';
  209. comida += '<p style ="padding-left: 8em">' + todaOrden[orden].ordenCompleta[i].peticion + '</p>';
  210. }
  211. else {
  212. bebida += '<h6 style ="padding-left: 4em">' + todaOrden[orden].ordenCompleta[i].nombre + ': $' + todaOrden[orden].ordenCompleta[i].precio.toFixed(2) + '</h6>';
  213. bebida += '<p style ="padding-left: 8em">' + todaOrden[orden].ordenCompleta[i].peticion + '</p>';
  214. }
  215. total += todaOrden[orden].ordenCompleta[i].precio
  216. }
  217. if (comida != '') {
  218. modal += '<h4>Comida: </h4>' + comida;
  219. }
  220. if (bebida != '') {
  221. modal += '<h4>Bebida: </h4>' + bebida;
  222. }
  223. modal += '<h6 style="text-align: right">Precio : $' + total.toFixed(2) + '</h6>' +
  224. '</div>' +
  225. '<div class="modal-footer">' +
  226. '<button type ="button" class ="btn btn-primary" onclick= "deleteOrder(' + orden + ')">' +
  227. 'Orden terminada</button>' +
  228. '</div>' +
  229. '</div>' +
  230. '</div>' +
  231. '</div>';
  232. var card = '<div class="col-auto" id ="order' + orden + '"><div class="card" style =" width: 18rem; height: 20rem; background-color: rgba(219, 226,230, 0.6)">' +
  233. '<div class="card-body">' +
  234. '<p class="card-title"><strong>Orden #' + orden + '</strong></p>' +
  235. '<p class="card-text" ><strong>Precio :' + total.toFixed(2) +
  236. '</strong></p>' +
  237. '<p class="card-text" ><strong>Nombre :' + todaOrden[orden].nombre +
  238. '</strong></p>' +
  239. '<p class="card-text" ><strong>Teléfono :' + todaOrden[orden].num_celular +
  240. '</strong></p>' +
  241. '</div>' +
  242. '<div class="card-footer">' +
  243. '<button type="button" class="btn btn-warning" data-toggle="modal" data-target="#Modal' + orden + '">' +
  244. 'Ver detalles</button>' +
  245. '<button type="button" class="btn btn-primary" onclick="deleteOrder(' + orden + ')">' +
  246. 'Terminada </button>' + '</div>' + '</div></div>';
  247. $('#ElQueue').append(card);
  248. $('#ElQueue').append(modal);
  249. if (cantidadDeOrdenesPendientes >= 7) {
  250. addToQueue(todaOrden);
  251. break;
  252. }
  253. }
  254. }
  255. };
  256. }
  257. </script>
  258. {% endblock %}