Skip to content

Instantly share code, notes, and snippets.

@wjurkowlaniec
Created April 4, 2022 12:55
Show Gist options
  • Save wjurkowlaniec/c3c3bdb378198e01194313a73d5c0c46 to your computer and use it in GitHub Desktop.
Save wjurkowlaniec/c3c3bdb378198e01194313a73d5c0c46 to your computer and use it in GitHub Desktop.
<!DOCTYPE html>
<head>
<meta charset="UTF-8">
</head>
<body>
<h1>Generowanie offline PIN Enko</h1>
<h2>Wprowadź numer wozaka</h2>
<input type="text" placeholder="Numer ID wozaka " id="pin_input">
<div> Wynik: <span id="result"></span></div>
<script type="text/javascript">
document.getElementById("pin_input").oninput = function (ev) {
var driver_id = document.getElementById("pin_input").value;
driver_id = Number.isInteger(parseInt(driver_id)) ? parseInt(driver_id) : -1;
if (driver_id > 999 || driver_id < 1) {
document.getElementById('result').textContent = "ID wozaka powinna być liczbą z zakresu 1-999";
return;
}
document.getElementById('result').textContent = generate_offline_mode_enko_pin(driver_id);
};
function generate_offline_mode_enko_pin(driver_enko_rfid) {
var month_day = ("00" + new Date().getDate()).slice(-2);
var driver_id = ("000" + driver_enko_rfid).slice(-3);
var pin = driver_id + month_day;
var checksum = (parseInt(pin[0]) * 3 + parseInt(pin[1]) * 2 + parseInt(pin[2]) * 4 + parseInt(pin[3]) * 6 + parseInt(pin[4]) * 5) % 10;
return pin + checksum;
}
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment