diff --git a/flask_company_data.py b/flask_company_data.py index b5ea829..dd042c4 100644 --- a/flask_company_data.py +++ b/flask_company_data.py @@ -21,7 +21,7 @@ def get_vies_client(): def normalize_vat(country_code: str, vat_number: str): country_code = (country_code or "").strip().upper() - vat_number = (vat_number or "").strip().replace(" ", "") + vat_number = (vat_number or "").strip().replace(" ", "").replace(".", "").replace("-", "") if vat_number.upper().startswith(country_code): vat_number = vat_number[len(country_code):] @@ -48,9 +48,9 @@ def parse_polish_working_address(address: str): def parse_vies_address(address: str): """ Assumption for VIES address: - - address is comma-separated + - address is comma-separated or line separated - first part = street - - last part = ZIP + CITY + - last part = ZIP + CITY or middlepart is city Examples: "Main Street 12, Some Region, 1000 Brussels" @@ -59,8 +59,11 @@ def parse_vies_address(address: str): """ if not address: return "", "", "" - + parts = [part.strip() for part in address.split(",") if part.strip()] + if "\n" in address: + parts = [part.strip() for part in address.split("\n") if part.strip()] + if not parts: return "", "", "" @@ -119,7 +122,7 @@ def check_polish_wl(nip: str): if not subject: return { - "source": "polish_wl", + "source": "mf.gov.pl", "found": False, "country": "PL", "vat_number": nip, @@ -131,11 +134,11 @@ def check_polish_wl(nip: str): } name = (subject.get("name") or "").strip() - working_address = (subject.get("workingAddress") or "").strip() + working_address = (subject.get("workingAddress")or subject.get("residenceAddress") or "").strip() street, zip_code, city = parse_polish_working_address(working_address) return { - "source": "polish_wl", + "source": "mf.gov.pl", "found": True, "country": "PL", "vat_number": nip, @@ -149,7 +152,7 @@ def check_polish_wl(nip: str): @app.get("/") def index(): - return render_template("index.html") + return render_template("company_data.html") @app.get("/api/company_lookup") @@ -166,7 +169,7 @@ def company_lookup(): vies_result = check_vies(country, vat_number) except Exception as exc: vies_result = { - "source": "vies", + "source": "ec.europa.eu", "found": False, "country": country, "vat_number": vat_number, @@ -175,7 +178,7 @@ def company_lookup(): "zip": "", "city": "", "raw_address": "", - "warning": f"VIES lookup failed: {exc}", + "warning": f"ec.europa.eu lookup failed: {exc}", } if vies_result.get("found"): @@ -190,7 +193,7 @@ def company_lookup(): except Exception as exc: return jsonify( { - "source": "polish_wl", + "source": "mf.gov.pl", "found": False, "country": country, "vat_number": vat_number, @@ -200,7 +203,7 @@ def company_lookup(): "city": "", "raw_address": "", "warning": vies_result.get("warning"), - "fallback_error": f"Polish WL lookup failed: {exc}", + "fallback_error": f"mf.gov.pl lookup failed: {exc}", } ) diff --git a/static/company_data.css b/static/company_data.css index 4c6ed83..d3ddb59 100644 --- a/static/company_data.css +++ b/static/company_data.css @@ -133,6 +133,10 @@ button:active { border: 1px solid rgba(77, 143, 219, 0.18); } +.span-2 { + grid-column: span 2; +} + .span-3 { grid-column: span 3; } @@ -165,7 +169,16 @@ button:active { font-size: 18px; } - .span-3 { - grid-column: span 1; + .span-4 { + grid-column: span 4; + } + + .secondary { + background: linear-gradient(135deg, #9bbce5, #6fa6e8); + box-shadow: none; + } + + .secondary:hover { + background: linear-gradient(135deg, #7fa9da, #4d8fdb); } } diff --git a/static/comany_data.js b/static/company_data.js similarity index 67% rename from static/comany_data.js rename to static/company_data.js index f82f1ef..9f5fe59 100644 --- a/static/comany_data.js +++ b/static/company_data.js @@ -27,7 +27,7 @@ async function searchCompany() { document.getElementById("zip").value = data.zip || ""; document.getElementById("city").value = data.city || ""; - let message = data.found ? `Found via ${data.source}.` : "No company found."; + let message = data.found ? `Found via ${data.source}.` : "No company found. Search different or enter manually"; if (data.warning) { message += `\nWarning: ${data.warning}`; @@ -57,3 +57,29 @@ function saveData() { alert(JSON.stringify(payload, null, 2)); } + +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)"; + } +} + +document.getElementById("country").addEventListener("change", updateVatPlaceholder); +window.addEventListener("DOMContentLoaded", updateVatPlaceholder); diff --git a/templates/company_data.html b/templates/company_data.html index 7fd0c0c..d40dab9 100644 --- a/templates/company_data.html +++ b/templates/company_data.html @@ -4,7 +4,8 @@