templates\home\index.html.twig line 1

Open in your IDE?
  1. {% extends 'base.html.twig' %}
  2. {% block title %}Hello HomeController!{% endblock %}
  3. {% block body %}
  4. <style>
  5.     .example-wrapper { margin: 1em auto; max-width: 800px; width: 95%; font: 18px/1.5 sans-serif; }
  6.     .example-wrapper code { background: #F5F5F5; padding: 2px 6px; }
  7.     .synchroniser {
  8.         background-color: #4CAF50; /* Green */
  9.         border: none;
  10.         color: white;
  11.         padding: 15px 32px;
  12.         text-align: center;
  13.         text-decoration: none;
  14.         display: inline-block;
  15.         font-size: 16px;
  16.         position:   absolute;
  17.         top:40%;
  18.         left : 45%;
  19.     }
  20. </style>
  21. <button type="button" class="btn btn-primary synchroniser">synchroniser</button>
  22. <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.6.3/jquery.min.js" integrity="sha512-STof4xm1wgkfm7heWqFJVn58Hm3EtS31XFaagaa8VMReCXAkQnJZ+jEy8PCC/iT18dFy95WcExNHFTqLyp72eQ==" crossorigin="anonymous" referrerpolicy="no-referrer"></script>
  23. <script src="https://cdnjs.cloudflare.com/ajax/libs/axios/0.27.2/axios.min.js" integrity="sha512-odNmoc1XJy5x1TMVMdC7EMs3IVdItLPlCeL5vSUPN2llYKMJ2eByTTAIiiuqLg+GdNr9hF6z81p27DArRFKT7A==" crossorigin="anonymous" referrerpolicy="no-referrer"></script>
  24. <script>
  25.     const getCaFromUgouv = async () => {
  26.         try {
  27.             const request = await axios.post('/api/ugouv/cloud/vente');
  28.             let response = request.data
  29.             console.log("Total CA RECIEVED FROM UGOUV WAS: "+response);
  30.             getHmFromUgouv()
  31.             } catch (error) {
  32.                 console.log(error)
  33.                 const message = error.response.data;
  34.                 console.log('CA RECIEVED UGOUV HOSIX :'+ message)
  35.             }
  36.     }
  37.     const getHmFromUgouv = async () => {
  38.         
  39.             try {
  40.             const request = await axios.post('/api/ugouv/cloud/achat');
  41.             let response = request.data
  42.             console.log("Total HM RECIEVED FROM UGOUV WAS: "+response);
  43.             sendCaToAdonix();
  44.             } catch (error) {
  45.                 console.log(error)
  46.                 const message = error.response.data;
  47.                 console.log('HM RECIEVED FROM UGOUV :'+ message)
  48.             }
  49.     }
  50.     const sendCaToAdonix = async () => {
  51.             try {
  52.             const request = await axios.post('/api/ugouv/adonix/vente');
  53.             let response = request.data
  54.             console.log("Total CA SENT TO ADONIX WAS: "+response);
  55.             sendHmToAdonix();
  56.             } catch (error) {
  57.                 console.log(error)
  58.                 const message = error.response.data;
  59.                 console.log('CA SENT TO ADONIX :'+ message)
  60.             }
  61.         
  62.     }
  63.     const sendHmToAdonix = async () => {
  64.             try {
  65.             const request = await axios.post('/api/ugouv/adonix/achat');
  66.             let response = request.data
  67.             console.log("Total HM SENT TO ADONIX WAS: "+response);
  68.             } catch (error) {
  69.                 console.log(error)
  70.                 const message = error.response.data;
  71.                 console.log('HM SENT TO ADONIX :'+ message)
  72.             }
  73.     }
  74.     
  75.     // {# const functions = [getCaFromUgouv, getHmFromUgouv, sendCaToAdonix, sendHmToAdonix]; #}
  76.     // window.setInterval(function(){ // Set interval for checking
  77.     //       var date = new Date(); // Create a Date object to find out what time it is
  78.     //       if(date.getHours() === 4 && date.getMinutes() === 0){ // Check the time
  79.     //             getCaFromUgouv()
  80.     //       }
  81.     //       else{
  82.     //         console.log(date)
  83.     //       }
  84.     // }, 60000);
  85.     // {# alert('ziko'); #}
  86.     function checkServerStatus() {
  87.         $.ajax({
  88.             type: "POST", // HTTP method used for the request
  89.             url: '/insert/adonix', // The endpoint to which the request is sent
  90.             data: '', // Data sent with the request (empty in this case)
  91.             processData: false, // Indicates whether data should be processed (false here, meaning data is not processed)
  92.             contentType: false, // Indicates that content type should not be set (useful for uploading files)
  93.             success: function(result) { // Callback function executed if the request is successful
  94.                 if (result === 'ok') { // Check if the result is 'ok'
  95.                     console.log('Success received. Executing route again...');
  96.                     // Execute the route again
  97.                     checkServerStatus();
  98.                 } else {
  99.                     console.log('Response was not ok. Stopping.');
  100.                 }
  101.             },
  102.             error: function(jqXHR, textStatus, errorThrown) { // Callback function executed if the request fails
  103.                 console.log('Error occurred: ' + textStatus + ', ' + errorThrown);
  104.             },
  105.         });
  106.     }
  107.     // Initial call to execute the route
  108.     checkServerStatus();
  109.     // window.setInterval(function(){ // Set interval for checking
  110.     //     $.ajax({
  111.     //         type: "POST",
  112.     //         url: '/insert/adonix',
  113.     //         data: '',
  114.     //         processData: false,
  115.     //         contentType: false,
  116.     //         success: function(result) {
  117.     //             if(result == 'ok'){
  118.     //                  console.log('success');
  119.     //             }else{
  120.     //                 console.log('il y a un probleme');
  121.     //             }
  122.                 
  123.     //         },
  124.     //         error: function(jqXHR, textStatus, errorThrown) {
  125.     //                  console.log('erreur');
  126.     //         },
  127.     //     });
  128.     // }, 70000);
  129.     window.setInterval(function(){ // Set interval for checking
  130.         var date = new Date();
  131.         var days = ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"];
  132.         var fullDays = ["Saturday", "Sunday"];
  133.         var day = days[date.getDay()];
  134.         if(fullDays.includes(day)) {
  135.             // nhar kaml
  136.             {# $.ajax({
  137.                 type: "POST",
  138.                 url: '/insert/hosix/adonix',
  139.                 data: '',
  140.                 processData: false,
  141.                 contentType: false,
  142.                 success: function(result) {
  143.                     if(result == 'ok'){
  144.                         console.log('success');
  145.                     }else{
  146.                         console.log('il y a un probleme');
  147.                     }
  148.                     
  149.                 },
  150.                 error: function(jqXHR, textStatus, errorThrown) {
  151.                         console.log('erreur');
  152.                 },
  153.             }); #}
  154.         } else {
  155.             // mn 18 tal 08;
  156.             if(date.getHours() >= 18 || date.getHours() <= 8) {
  157.                 {# $.ajax({
  158.                     type: "POST",
  159.                     url: '/insert/hosix/adonix',
  160.                     data: '',
  161.                     processData: false,
  162.                     contentType: false,
  163.                     success: function(result) {
  164.                         if(result == 'ok'){
  165.                             console.log('success');
  166.                         }else{
  167.                             console.log('il y a un probleme');
  168.                         }
  169.                         
  170.                     },
  171.                     error: function(jqXHR, textStatus, errorThrown) {
  172.                             console.log('erreur');
  173.                     },
  174.                 }); #}
  175.             }
  176.         }
  177.         
  178.     }, 3600000);
  179. {# 300000 #}
  180.     $('.synchroniser').on('click', function() {
  181.         $.ajax({
  182.             type: "POST",
  183.             url: '/insert/adonix',
  184.             data: '',
  185.             processData: false,
  186.             contentType: false,
  187.             success: function(result) {
  188.                 if(result == 'ok'){
  189.                     $(".synchroniser").text("success");
  190.                 }
  191.                 
  192.             },
  193.             error: function(jqXHR, textStatus, errorThrown) {
  194.                     
  195.                     $(".synchroniser").text("error");
  196.                     $(".synchroniser").css("background-color", "red");
  197.             },
  198.         });
  199.     });
  200. </script>
  201. {% endblock %}