{% extends 'base.html.twig' %}
{% block title %}Hello HomeController!{% endblock %}
{% block body %}
<style>
.example-wrapper { margin: 1em auto; max-width: 800px; width: 95%; font: 18px/1.5 sans-serif; }
.example-wrapper code { background: #F5F5F5; padding: 2px 6px; }
.synchroniser {
background-color: #4CAF50; /* Green */
border: none;
color: white;
padding: 15px 32px;
text-align: center;
text-decoration: none;
display: inline-block;
font-size: 16px;
position: absolute;
top:40%;
left : 45%;
}
</style>
<button type="button" class="btn btn-primary synchroniser">synchroniser</button>
<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>
<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>
<script>
const getCaFromUgouv = async () => {
try {
const request = await axios.post('/api/ugouv/cloud/vente');
let response = request.data
console.log("Total CA RECIEVED FROM UGOUV WAS: "+response);
getHmFromUgouv()
} catch (error) {
console.log(error)
const message = error.response.data;
console.log('CA RECIEVED UGOUV HOSIX :'+ message)
}
}
const getHmFromUgouv = async () => {
try {
const request = await axios.post('/api/ugouv/cloud/achat');
let response = request.data
console.log("Total HM RECIEVED FROM UGOUV WAS: "+response);
sendCaToAdonix();
} catch (error) {
console.log(error)
const message = error.response.data;
console.log('HM RECIEVED FROM UGOUV :'+ message)
}
}
const sendCaToAdonix = async () => {
try {
const request = await axios.post('/api/ugouv/adonix/vente');
let response = request.data
console.log("Total CA SENT TO ADONIX WAS: "+response);
sendHmToAdonix();
} catch (error) {
console.log(error)
const message = error.response.data;
console.log('CA SENT TO ADONIX :'+ message)
}
}
const sendHmToAdonix = async () => {
try {
const request = await axios.post('/api/ugouv/adonix/achat');
let response = request.data
console.log("Total HM SENT TO ADONIX WAS: "+response);
} catch (error) {
console.log(error)
const message = error.response.data;
console.log('HM SENT TO ADONIX :'+ message)
}
}
// {# const functions = [getCaFromUgouv, getHmFromUgouv, sendCaToAdonix, sendHmToAdonix]; #}
// window.setInterval(function(){ // Set interval for checking
// var date = new Date(); // Create a Date object to find out what time it is
// if(date.getHours() === 4 && date.getMinutes() === 0){ // Check the time
// getCaFromUgouv()
// }
// else{
// console.log(date)
// }
// }, 60000);
// {# alert('ziko'); #}
function checkServerStatus() {
$.ajax({
type: "POST", // HTTP method used for the request
url: '/insert/adonix', // The endpoint to which the request is sent
data: '', // Data sent with the request (empty in this case)
processData: false, // Indicates whether data should be processed (false here, meaning data is not processed)
contentType: false, // Indicates that content type should not be set (useful for uploading files)
success: function(result) { // Callback function executed if the request is successful
if (result === 'ok') { // Check if the result is 'ok'
console.log('Success received. Executing route again...');
// Execute the route again
checkServerStatus();
} else {
console.log('Response was not ok. Stopping.');
}
},
error: function(jqXHR, textStatus, errorThrown) { // Callback function executed if the request fails
console.log('Error occurred: ' + textStatus + ', ' + errorThrown);
},
});
}
// Initial call to execute the route
checkServerStatus();
// window.setInterval(function(){ // Set interval for checking
// $.ajax({
// type: "POST",
// url: '/insert/adonix',
// data: '',
// processData: false,
// contentType: false,
// success: function(result) {
// if(result == 'ok'){
// console.log('success');
// }else{
// console.log('il y a un probleme');
// }
// },
// error: function(jqXHR, textStatus, errorThrown) {
// console.log('erreur');
// },
// });
// }, 70000);
window.setInterval(function(){ // Set interval for checking
var date = new Date();
var days = ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"];
var fullDays = ["Saturday", "Sunday"];
var day = days[date.getDay()];
if(fullDays.includes(day)) {
// nhar kaml
{# $.ajax({
type: "POST",
url: '/insert/hosix/adonix',
data: '',
processData: false,
contentType: false,
success: function(result) {
if(result == 'ok'){
console.log('success');
}else{
console.log('il y a un probleme');
}
},
error: function(jqXHR, textStatus, errorThrown) {
console.log('erreur');
},
}); #}
} else {
// mn 18 tal 08;
if(date.getHours() >= 18 || date.getHours() <= 8) {
{# $.ajax({
type: "POST",
url: '/insert/hosix/adonix',
data: '',
processData: false,
contentType: false,
success: function(result) {
if(result == 'ok'){
console.log('success');
}else{
console.log('il y a un probleme');
}
},
error: function(jqXHR, textStatus, errorThrown) {
console.log('erreur');
},
}); #}
}
}
}, 3600000);
{# 300000 #}
$('.synchroniser').on('click', function() {
$.ajax({
type: "POST",
url: '/insert/adonix',
data: '',
processData: false,
contentType: false,
success: function(result) {
if(result == 'ok'){
$(".synchroniser").text("success");
}
},
error: function(jqXHR, textStatus, errorThrown) {
$(".synchroniser").text("error");
$(".synchroniser").css("background-color", "red");
},
});
});
</script>
{% endblock %}