Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 0 additions & 21 deletions csf_tz/csf_tz/bank_reconciliation.js

This file was deleted.

1 change: 1 addition & 0 deletions csf_tz/csf_tz/bom_addittional_costs.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
frappe.ui.form.on("BOM", {
refresh: function (frm) {
if (!frm.fields_dict.additional_costs) return;
frm.set_query("expense_account", "additional_costs", function () {
return {
filters: {
Expand Down
116 changes: 32 additions & 84 deletions csf_tz/csf_tz/page/scan_qrcode/scan_qrcode.html
Original file line number Diff line number Diff line change
@@ -1,84 +1,32 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<script src="https://unpkg.com/html5-qrcode"></script>
<title>QR Code Reader</title>
<style>
#toast {
visibility: hidden;
max-width: 50%;
margin: auto;
background-color: #333;
text-align: center;
border-radius: 2px;
padding: 16px;
position: absolute;
z-index: 1;
left: 50%;
transform: translate(-50%, 0);
font-size: 17px;
}

#toast.show {
visibility: visible;
-webkit-animation: fadein 0.5s, fadeout 0.5s 2.5s;
animation: fadein 0.5s, fadeout 0.5s 2.5s;
}

@-webkit-keyframes fadein {
from {
top: 0;
opacity: 0;
}
to {
top: 30px;
opacity: 1;
}
}

@keyframes fadein {
from {
top: 0;
opacity: 0;
}
to {
top: 30px;
opacity: 1;
}
}

@-webkit-keyframes fadeout {
from {
top: 30px;
opacity: 1;
}
to {
top: 0;
opacity: 0;
}
}

@keyframes fadeout {
from {
top: 30px;
opacity: 1;
}
to {
top: 0;
opacity: 0;
}
}
</style>
</head>
<body>
<div id="qr-reader" style="width: 500px"></div>
<div id="qr-reader-results"></div>
<div id="toast"></div>
<div id="reader" style="width: 300px; height: 300px"></div>
<!-- <button onclick="startScanner()">Start Scanner</button>
<button onclick="stopScanner()">Stop Scanner</button> -->
<script src="script.js"></script>
</body>
</html>
<style>
#toast {
visibility: hidden;
max-width: 50%;
margin: auto;
background-color: #333;
color: #fff;
text-align: center;
border-radius: 2px;
padding: 16px;
position: absolute;
z-index: 1;
left: 50%;
transform: translate(-50%, 0);
font-size: 17px;
}
#toast.show {
visibility: visible;
animation: fadein 0.5s, fadeout 0.5s 2.5s;
}
@keyframes fadein {
from { top: 0; opacity: 0; }
to { top: 30px; opacity: 1; }
}
@keyframes fadeout {
from { top: 30px; opacity: 1; }
to { top: 0; opacity: 0; }
}
</style>
<div id="qr-reader" style="width: 500px"></div>
<div id="qr-reader-results"></div>
<div id="toast"></div>
56 changes: 28 additions & 28 deletions csf_tz/csf_tz/page/scan_qrcode/scan_qrcode.js
Original file line number Diff line number Diff line change
@@ -1,46 +1,46 @@
const SCANNER_LIBRARY_URL = "https://unpkg.com/html5-qrcode";

frappe.pages["scan-qrcode"].on_page_load = function (wrapper) {
var page = frappe.ui.make_app_page({
const page = frappe.ui.make_app_page({
parent: wrapper,
title: "Scan QRCode",
single_column: true,
});
page.main.html(frappe.render_template("scan_qrcode", {}));
setTimeout(function () {
startScanner();
}, 1000);
loadScannerLibrary()
.then(startScanner)
.catch(() =>
frappe.msgprint(__("Could not load the QR scanner library (html5-qrcode). Check the internet connection."))
);
};

var lastResult,
countResults = 0;

function startScanner() {
var resultContainer = document.getElementById("qr-reader-results");
let lastResult;

var html5QrcodeScanner = new Html5QrcodeScanner("qr-reader", {
fps: 10,
qrbox: 250,
function loadScannerLibrary() {
if (window.Html5QrcodeScanner) {
return Promise.resolve();
}
return new Promise((resolve, reject) => {
const script = document.createElement("script");
script.src = SCANNER_LIBRARY_URL;
script.onload = resolve;
script.onerror = reject;
document.head.appendChild(script);
});
html5QrcodeScanner.render(onScanSuccess);
}

function onScanSuccess(decodedText, decodedResult) {
if (decodedText !== lastResult) {
++countResults;
lastResult = decodedText;
// Handle on success condition with the decoded message.
console.log(`Scan result ${decodedText}`, decodedResult);
sendApiCall(decodedText);
}
function startScanner() {
const scanner = new Html5QrcodeScanner("qr-reader", { fps: 10, qrbox: 250 });
scanner.render(onScanSuccess);
}

function sendApiCall(decodedText) {
function onScanSuccess(decodedText) {
if (decodedText === lastResult) {
return;
}
lastResult = decodedText;
frappe.call({
method: "csf_tz.csf_tz.page.scan_qrcode.scan_qrcode.add_biometric_log",
args: {
data: decodedText,
},
callback: function (r) {
console.log(r);
},
args: { data: decodedText },
});
}
Loading
Loading