Files
MYSOPHAL/front/inventaire.php
2025-08-07 13:15:31 +01:00

210 lines
6.0 KiB
PHP

<?php
use Glpi\Event;
include ('../model_controller/articles.list.php');
Session::checkLoginUser();
if (Session::getCurrentInterface() == "helpdesk") {
Html::helpHeader("DRH", '', $_SESSION["glpiname"]);
} else {
Html::header("DRH", '', "", "");
}
//die;
if(isset($_POST['valider'])) {
$currentdate = date('Y-m-d h:i:s', time());
$currentuser = $_SESSION["glpiname"];
$qtcompt1 = '';
$qtcompt2 = '';
$qtcontrole = '';
$usercomp1 = '';
$datecomp1 = '';
$usercomp2 = '';
$datecomp2 = '';
$usercontrole = '';
$datecontrole = '';
if($_POST['comptage'] == "comptage1") {
$qtcompt1 = $_POST['quantity'];
$usercomp1 = $currentuser;
$datecomp1 = $currentdate;
}
if($_POST['comptage'] == "comptage2") {
$qtcompt2 = $_POST['quantity'];
$usercomp2 = $currentuser;
$datecomp2 = $currentdate;
}
if($_POST['comptage'] == "comptage3") {
$qtcontrole = $_POST['quantity'];
$usercontrole = $currentuser;
$datecontrole = $currentdate;
}
saveInventaire($_POST['depot'], $_POST['qr-label'], $_POST['numlot'], 'emplacement', $_POST['qtreel'], $qtcompt1, $qtcompt2, $qtcontrole, $usercomp1, $datecomp1, $usercomp2, $datecomp2, $usercontrole, $datecontrole);
//Html::redirect("central.php");
}
$all = 1;
$depots = getDepots();
$a=array();
//array_push($a,$depots[0],$depots[1],$depots[2],$depots[3],$depots[9],$depots[10],$depots[11],$depots[12]
// ,$depots[14],$depots[15],$depots[17],$depots[18],$depots[21]);
//array_push($a,$depots[13]);
$depots = $a;
$results = getStocks($all);
$msg = "Confirmez-vous l\'enregistrement ?";
$checkbtn = '';
//if($_SESSION["glpiname"] == 'itapplications')
$checkbtn = '<label id="btncheck"">check</label>';
echo '<div>
<form method="post" id="formulaire" name="formulaire" autocomplete="off">
<input type="hidden" id="_glpi_csrf_token" name="_glpi_csrf_token" value="'.Session::getNewCSRFToken().'">
<label>Depot</label>
<select id="depot" name="depot" required style="height:25px">';
echo '<option value=""></option>';
foreach($depots as $row) {
echo '<option value="'.$row['DEP_CODE'].'">'.$row['DEP_NOM'].'</option>';
}
echo '</select>
<br><br>
<div>
<input type="radio" id="comptage1" name="comptage" value="comptage1" checked>
<label>Comptage 1</label>
</div>
<br>
<div>
<input type="radio" id="comptage2" name="comptage" value="comptage2">
<label>Comptage 2</label>
</div>
<br>
<div>
<input type="radio" id="comptage3" name="comptage" value="comptage3">
<label>Controle</label>
</div>
<br><br>
<label>Article</label>
<input type="text" id="qr-label" name="qr-label" required><lable id="article-label"></lable>
<img id="img-scan" src="../pics/scanimg.jpg" style="vertical-align:bottom;width:26px;height:18px"/>
<div id="qr-reader" style="width: 300px"></div>
<div id="placeHolder" style="width: 300px"></div>
<br><br>
<label>Numero Lot</label>
<select id="numlot" name="numlot"><option value=""></option></select>
<br><br>
<label>Quantité</label>
<input type="number" step="any" id="quantity" name="quantity" required>
<input type="text" id="qtreel" name="qtreel" hidden>
<br><br>
<input type="submit" name="valider" id="valider" value="Envoyer" class="vsubmit" onclick="return(confirm(\''.$msg.'\'));">
</form>
</div>
<div> <video hidden style="max-width:500px" id="qr-video"></video> </div>
<div id="show-region" style="max-width:500px; display:none"></div>
'.$checkbtn;
Html::footer();
?>
<script src="https://unpkg.com/html5-qrcode" type="text/javascript"></script>
<script type="module">
let alreadyup = false;
let alreadyscanned = false;
document.getElementById('img-scan').addEventListener('click', (e) => {
if(!alreadyup){
document.getElementById("placeHolder").innerHTML =
'<div id="qr-reader" style="width: 600px"></div>'
var html5QrcodeScanner = new Html5QrcodeScanner(
"qr-reader", {
fps: 30,
qrbox: 150
});
html5QrcodeScanner.render(onScanSuccess);
alreadyup = true;
}
});
function onScanSuccess(decodedText, decodedResult) {
document.getElementById('qr-label').value = decodedText
if (!alreadyscanned){
check();
alreadyscanned = true;
}
}
var stocks = <?php echo json_encode($results); ?>;
var found = false;
$(document).ready(function(){
$("#c_ssmenu2").html('<ul>'+
'<li class="breadcrumb_item"><a href="central.php" title="Accueil">Accueil</a></li>'+
'<li class="breadcrumb_item"><a href="" title="">Inventaire</a></li>'+
'</ul>');
});
function numlotchange() {
var selectedDepot = document.getElementById('depot').value;
var article = document.getElementById('qr-label').value;
var res = stocks.filter(a => a.DEP_CODE.toUpperCase().includes(selectedDepot.toUpperCase()));
let e = document.querySelector('#numlot');
res = res.filter(a => a.ART_CODE.toUpperCase().includes(article.toUpperCase()));
res = res.filter(a => a.STK_NUMLOT.toUpperCase().includes(e.value.toUpperCase()));
var a = res[0];
document.getElementById('qtreel').value = a['STK_REEL'];
}
function check(e) {
var te = document.getElementById('qr-label').value;
found = false;
setLabel(te);
}
function setLabel(text) {
if(!found) {
document.getElementById('qr-label').value = text;
var resart = stocks.filter(a => a.ART_CODE == text);
document.getElementById('article-label').innerHTML = resart[0]['ART_LIB'];
var selectedDepot = document.getElementById('depot').value;
var res = stocks.filter(a => a.DEP_CODE.toUpperCase().includes(selectedDepot.toUpperCase()));
res = res.filter(a => a.ART_CODE.toUpperCase() == text.toUpperCase());
var numlot = document.getElementById('numlot');
res.forEach(a => {
var lotnum = a['STK_NUMLOT'];
if(lotnum != '') {
var opt = document.createElement('option');
opt.value = lotnum;
opt.innerHTML = lotnum;
numlot.appendChild(opt);
}
document.getElementById('qtreel').value = a['STK_REEL'];
});
found = true;
}
}
document.getElementById('btncheck').addEventListener("click", check, false);
document.getElementById('numlot').addEventListener("change", numlotchange);
</script>