2026-04-02 08:29:44 +02:00
|
|
|
var oAppEnablementCommonInstance = new comGkSoftwareGkrAppEnablementApi.Common();
|
|
|
|
|
var oAppEnablementPosInstance = new comGkSoftwareGkrAppEnablementApi.Pos();
|
|
|
|
|
var oAppEnablementPosEXTInstance = new comGkSoftwareGkrAppEnablementApi.Pos_EXT();
|
|
|
|
|
|
2026-03-31 22:07:11 +02:00
|
|
|
async function searchCompany() {
|
|
|
|
|
const country = document.getElementById("country").value;
|
|
|
|
|
const vatNumber = document.getElementById("vat_number").value.trim();
|
|
|
|
|
const status = document.getElementById("status");
|
|
|
|
|
|
|
|
|
|
if (!country || !vatNumber) {
|
|
|
|
|
status.textContent = "Please enter a country and VAT number.";
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
status.textContent = "Searching...";
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
const response = await fetch(
|
|
|
|
|
`/api/company_lookup?country=${encodeURIComponent(country)}&vat_number=${encodeURIComponent(vatNumber)}`
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
const data = await response.json();
|
|
|
|
|
|
|
|
|
|
if (!response.ok) {
|
|
|
|
|
status.textContent = data.error || "Lookup failed.";
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
document.getElementById("company_name").value = data.name || "";
|
|
|
|
|
document.getElementById("street").value = data.street || "";
|
|
|
|
|
document.getElementById("zip").value = data.zip || "";
|
|
|
|
|
document.getElementById("city").value = data.city || "";
|
|
|
|
|
|
2026-04-01 09:35:40 +02:00
|
|
|
let message = data.found ? `Found via ${data.source}.` : "No company found. Search different or enter manually";
|
2026-03-31 22:07:11 +02:00
|
|
|
|
|
|
|
|
if (data.warning) {
|
|
|
|
|
message += `\nWarning: ${data.warning}`;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (data.fallback_error) {
|
|
|
|
|
message += `\nFallback error: ${data.fallback_error}`;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
status.textContent = message;
|
|
|
|
|
} catch (error) {
|
|
|
|
|
status.textContent = "Request failed: " + error;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function saveData() {
|
|
|
|
|
const payload = {
|
|
|
|
|
country: document.getElementById("country").value,
|
|
|
|
|
vat_number: document.getElementById("vat_number").value.trim(),
|
|
|
|
|
company_name: document.getElementById("company_name").value.trim(),
|
|
|
|
|
street: document.getElementById("street").value.trim(),
|
|
|
|
|
zip: document.getElementById("zip").value.trim(),
|
|
|
|
|
city: document.getElementById("city").value.trim(),
|
|
|
|
|
email: document.getElementById("email").value.trim(),
|
|
|
|
|
phone: document.getElementById("phone").value.trim()
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
alert(JSON.stringify(payload, null, 2));
|
2026-04-02 08:29:44 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
var customer = {
|
|
|
|
|
"customerId":"17600703312990"
|
|
|
|
|
}
|
|
|
|
|
var oRegisterCustomerRequest = JSON.stringify(customer)
|
|
|
|
|
oAppEnablementPosInstance.registerCustomer('registerDataOk', 'registerDataFailed', oRegisterCustomerRequest);
|
|
|
|
|
|
2026-03-31 22:07:11 +02:00
|
|
|
}
|
2026-04-01 09:35:40 +02:00
|
|
|
|
|
|
|
|
function clearForm() {
|
|
|
|
|
document.getElementById("vat_number").value = "";
|
|
|
|
|
document.getElementById("company_name").value = "";
|
|
|
|
|
document.getElementById("street").value = "";
|
|
|
|
|
document.getElementById("zip").value = "";
|
|
|
|
|
document.getElementById("city").value = "";
|
|
|
|
|
document.getElementById("email").value = "";
|
|
|
|
|
document.getElementById("phone").value = "";
|
|
|
|
|
|
|
|
|
|
document.getElementById("status").textContent = "Cleared.";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function updateVatPlaceholder() {
|
|
|
|
|
const country = document.getElementById("country").value;
|
|
|
|
|
const vatInput = document.getElementById("vat_number");
|
|
|
|
|
|
|
|
|
|
if (country === "HR") {
|
|
|
|
|
vatInput.placeholder = "VAT number (11 digits)";
|
|
|
|
|
} else {
|
|
|
|
|
vatInput.placeholder = "VAT number (10 digits)";
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2026-04-02 08:29:44 +02:00
|
|
|
function closeBrowser() {
|
|
|
|
|
oAppEnablementCommonInstance.closeBrowser();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// customer registration - uses standard Pos
|
|
|
|
|
|
|
|
|
|
function registerLoyaltyCall(customerId) {
|
|
|
|
|
var request = JSON.stringify({
|
|
|
|
|
"customerId": customerId,
|
|
|
|
|
"customerServiceTypeCode": null,
|
|
|
|
|
"preferredReceiptPrintoutTypeCode": null
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
oAppEnablementPosInstance.registerCustomer(
|
|
|
|
|
'onSuccess',
|
|
|
|
|
'onError',
|
|
|
|
|
request
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Callback functions
|
|
|
|
|
function onSuccess(result) {
|
|
|
|
|
document.getElementById("status").textContent = "Thank you.";
|
|
|
|
|
closeBrowser();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function onError(error) {
|
|
|
|
|
document.getElementById("status").textContent = "Company registration in receipt failed. Please try again.";
|
|
|
|
|
}
|
|
|
|
|
|
2026-04-01 09:35:40 +02:00
|
|
|
document.getElementById("country").addEventListener("change", updateVatPlaceholder);
|
|
|
|
|
window.addEventListener("DOMContentLoaded", updateVatPlaceholder);
|