diff --git a/ajax/scan_article.php b/ajax/scan_article.php new file mode 100644 index 0000000..58532dd --- /dev/null +++ b/ajax/scan_article.php @@ -0,0 +1,35 @@ +articles as $articleObject) { + if ($articleObject->code === $_POST["code"] && intval($articleObject->quantity) > 0) { + $price = $articleObject->price; + $articleObject->quantity = strval(intval($articleObject->quantity) - 1); + } +} + +// open the file and write the updated stock +$fp = fopen('../data/stock.json', 'w'); +fwrite($fp, json_encode($result)); +fclose($fp); + +echo $price; + diff --git a/assets/js/stock.js b/assets/js/stock.js index eb4a0a9..dfcf776 100644 --- a/assets/js/stock.js +++ b/assets/js/stock.js @@ -205,3 +205,23 @@ function saveDataset() { }, }); } + + + +function scanArticle(code) { + let data = { + password: 'coucou', + code : code, + }; + $.ajax({ + type: "POST", + url: "../ajax/scan_article.php", + data: JSON.stringify(data), + dataType: "json", + contentType: "application/json; charset=utf-8", + complete: function (data) { + // alert(data.responseText); + console.log(data.responseText); + }, + }); +}