Site du proximo, utilisé pour gérer le stock.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

scan_article.php 1.0KB

1234567891011121314151617181920212223242526272829303132333435
  1. <?php
  2. $rest_json = file_get_contents("php://input");
  3. $_POST = json_decode($rest_json, true);
  4. // Must have a code and password field
  5. $fp = fopen('.htpassajax', 'r');
  6. $password = trim(fread($fp, filesize('.htpassajax')));
  7. fclose($fp);
  8. if ($_POST["password"] != $password)
  9. die("Wrong Password");
  10. // open the file and get the stock
  11. $file = '../data/stock.json';
  12. $fp = fopen($file, 'r');
  13. $result = json_decode(fread($fp, filesize($file)));
  14. fclose($fp);
  15. $returnVal = 'N/A';
  16. // Get the price from the given code and remove 1 in quantity. Do not get the price if quantity is at 0
  17. foreach ($result->articles as $articleObject) {
  18. if ($articleObject->code === $_POST["code"] && intval($articleObject->quantity) > 0) {
  19. $returnVal = $articleObject->name . "\n". $articleObject->price . "€";
  20. $articleObject->quantity = strval(intval($articleObject->quantity) - 1);
  21. }
  22. }
  23. // open the file and write the updated stock
  24. $fp = fopen('../data/stock.json', 'w');
  25. fwrite($fp, json_encode($result));
  26. fclose($fp);
  27. echo $returnVal;