{
const [loading, setLoading] = useState
(false);
const [contacts, setContacts] = useState(undefined);
+ const [municipalities, setMunicipalities] = useState(undefined);
const abortControllerRef = useRef(null);
@@ -136,8 +138,8 @@ const Report: NextPage = ({ fietsenstallingen }: any) => {
useEffect(() => {
const go = async () => {
- const response = await fetch(`/api/contacts`);
- setContacts(await response.json());
+ const response = await getMunicipalities();
+ setContacts(response);
};
go();
@@ -164,7 +166,7 @@ const Report: NextPage = ({ fietsenstallingen }: any) => {
return createFixBadDataReport(filtered, contacts, showData);
});
break;
- case 'stallingtegoed':
+ case 'stallingstegoed':
launchReport((filtered: any): Promise => {
return createStallingtegoedReport(filtered, contacts, showData);
});
@@ -228,7 +230,7 @@ const Report: NextPage = ({ fietsenstallingen }: any) => {
-
+
{/* Add more options as needed */}
diff --git a/src/utils/parkings.tsx b/src/utils/parkings.tsx
index d1ffbff..0783315 100644
--- a/src/utils/parkings.tsx
+++ b/src/utils/parkings.tsx
@@ -228,21 +228,12 @@ export const createVeiligstallenOrgOpwaardeerLink = (parkingdata: ParkingDetails
return visible ? `https://veiligstallen.nl/${municipality}/stallingstegoed` : '';
}
-export const createVeiligstallenOrgOpwaardeerLinkForMunicipality = (municipality: string, fietsenstallingen: fietsenstallingen[], contacts: contacts[]): string => {
- const thecontact = contacts.find((contact: contacts) => {
- if (contact.Gemeentecode !== null) {
- return `GM${contact.Gemeentecode.toString().padStart(4, '0')}` === municipality;
- } else {
- return false
- }
- })
-
- if (thecontact === undefined) { return '' }
+export const createVeiligstallenOrgOpwaardeerLinkForMunicipality = (municipality: contacts, fietsenstallingen: fietsenstallingen[]): string => {
+ if (municipality === undefined) { return '' }
// check if there are any parkings for this SiteID and BerekentStallingskosten === false -> yes? create URL
- const others = fietsenstallingen.filter((fs) => (thecontact.ID === fs.SiteID) && (fs.BerekentStallingskosten === false));
+ const others = fietsenstallingen.filter((fs) => (municipality.ID === fs.SiteID) && (fs.BerekentStallingskosten === false));
+ const visible = others.length > 0
- const visible = others.length > 0 && municipality !== ""
-
- return visible ? `https://veiligstallen.nl/${municipality}/stallingstegoed` : '';
+ return visible ? `https://veiligstallen.nl/${municipality.UrlName}/stallingstegoed` : '';
}
\ No newline at end of file
diff --git a/src/utils/reports/stallingtegoed.tsx b/src/utils/reports/stallingtegoed.tsx
index 034250c..e296e23 100644
--- a/src/utils/reports/stallingtegoed.tsx
+++ b/src/utils/reports/stallingtegoed.tsx
@@ -1,7 +1,7 @@
import type { fietsenstallingen, contacts } from "@prisma/client";
import { ReportContent } from "./types";
import { ParkingDetailsType } from "~/types";
-import { createVeiligstallenOrgOpwaardeerLink, createVeiligstallenOrgLink } from "~/utils/parkings";
+import { createVeiligstallenOrgOpwaardeerLinkForMunicipality, createVeiligstallenOrgLink } from "~/utils/parkings";
export const createStallingtegoedReport = async (fietsenstallingen: fietsenstallingen[], contacts: contacts[], showData: boolean): Promise => {
const alwaysvisibleColumns = [
@@ -15,6 +15,7 @@ export const createStallingtegoedReport = async (fietsenstallingen: fietsenstall
const allColumns = [
...alwaysvisibleColumns,
"link_url",
+ "UrlName",
"BerekentStallingskosten",
];
@@ -109,7 +110,9 @@ export const createStallingtegoedReport = async (fietsenstallingen: fietsenstall
const parkingdata = fietsenstalling as any as ParkingDetailsType;
const isNS = parkingdata.EditorCreated === "NS-connector"
- const url = createVeiligstallenOrgOpwaardeerLink(parkingdata, fietsenstallingen, contacts);
+
+ const municipality: contacts = contacts.find((c: contacts) => c.ID === parkingdata.SiteID) as any as contacts;
+ let url = municipality ? createVeiligstallenOrgOpwaardeerLinkForMunicipality(municipality, fietsenstallingen) : "";
const toonOpwaarderen = url !== "";
report.data.records.push({
@@ -120,6 +123,7 @@ export const createStallingtegoedReport = async (fietsenstallingen: fietsenstall
"isNs": isNS ? "NS" : "",
"button_opwaarderen": toonOpwaarderen ? getOpwaarderenButton(parkingdata.ID, url) : null,
"link_url": toonOpwaarderen ? url : "",
+ "UrlName": municipality ? municipality.UrlName : "",
"BerekentStallingskosten": parkingdata.BerekentStallingskosten ? "Stalling berekent kosten stallingstransacties" : "FMS berekent kosten stallingstransacties",
});
};