company frontend finished

This commit is contained in:
2026-04-01 09:35:40 +02:00
parent 2f34b9b8be
commit 1d7f31eb96
4 changed files with 69 additions and 29 deletions
+15 -12
View File
@@ -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}",
}
)
+15 -2
View File
@@ -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);
}
}
@@ -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);
+12 -14
View File
@@ -4,7 +4,8 @@
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>VAT Company Lookup</title>
<link rel="stylesheet" href="{{ url_for('static', filename='style.css') }}">
<link rel="stylesheet" href="{{ url_for('static', filename='company_data.css') }}">
</head>
<body>
<div class="container">
@@ -12,7 +13,6 @@
<div class="form-grid">
<div class="row">
<label for="country">Country / VAT</label>
<select id="country">
<option value="BE">Belgium</option>
<option value="HR">Croatia</option>
@@ -23,40 +23,38 @@
</div>
<div class="row">
<label for="company_name">Company</label>
<input id="company_name" type="text" class="span-3">
<input id="company_name" type="text" placeholder="Company" class="span-3">
</div>
<div class="row">
<label for="street">Street</label>
<input id="street" type="text" class="span-3">
<input id="street" type="text" placeholder="Street" class="span-3">
</div>
<div class="row">
<label for="zip">ZIP / City</label>
<input id="zip" type="text" placeholder="ZIP">
<input id="city" type="text" placeholder="City">
<div></div>
<input id="city" type="text" placeholder="City" class="span-2">
</div>
<div class="row">
<label for="email">Email</label>
<input id="email" type="email" placeholder="example@company.com" class="span-3">
</div>
<div class="row">
<label for="phone">Phone</label>
<input id="phone" type="text" placeholder="+32 123 45 67 89" class="span-3">
</div>
</div>
<div class="button-row">
<button type="button" onclick="saveData()">Save</button>
<button type="button" onclick="saveData()">Add to Receipt</button>
<button type="button" onclick="clearForm()">Clear</button>
<button type="button" onclick="saveData()">Cancel</button>
</div>
<div id="status" class="status">Ready.</div>
</div>
<script src="{{ url_for('static', filename='app.js') }}"></script>
<script src="{{ url_for('static', filename='company_data.js') }}"></script>
</body>
</html>