added new fcp statistics
This commit is contained in:
@@ -1076,20 +1076,73 @@ $pagination_entity_name = "Vorbestellungen";
|
||||
}
|
||||
|
||||
async function getFCPs(map) {
|
||||
var fcp = await $.get("<?=self::getUrl("Preorder", "Api")?>", {
|
||||
const fcpResponse = await $.get("<?=self::getUrl("Preorder", "Api")?>", {
|
||||
do: "getFCPsForCampaign",
|
||||
campaign_id: "<?=$campaign->id?>"
|
||||
});
|
||||
|
||||
if(fcp.status == "OK") {
|
||||
fcp.result.forEach((fcp) => {
|
||||
var icon = L.MakiMarkers.icon({icon: "viewpoint", color: "yellow", size: "m"});
|
||||
var marker = L.marker([fcp.lat, fcp.lng], {icon: icon}).addTo(map);
|
||||
var google_maps_link = "https://www.google.com/maps/search/?api=1&query=" + fcp.lat + "," + fcp.lng;
|
||||
var popup_content = "<a href='" + google_maps_link + "' target='_blank'>Google Maps</a><br />" + fcp.text;
|
||||
marker.bindPopup(popup_content);
|
||||
});
|
||||
}
|
||||
if (fcpResponse.status !== "OK" || !fcpResponse.result?.length) return;
|
||||
|
||||
const fcpIds = fcpResponse.result.map(fcp => fcp.real_id);
|
||||
const statsResponse = await $.ajax({
|
||||
url: "<?=self::getUrl("Preorder", "Api")?>?do=getRimoFcpStats",
|
||||
type: 'POST',
|
||||
contentType: 'application/json', // 1. Set the content type to JSON
|
||||
data: JSON.stringify({ fcp_ids: fcpIds }) // 2. Stringify the data object
|
||||
});
|
||||
const stats = statsResponse.status === "OK" ? statsResponse.result : [];
|
||||
|
||||
fcpResponse.result.forEach(fcp => {
|
||||
const icon = L.MakiMarkers.icon({ icon: "viewpoint", color: "yellow", size: "m" });
|
||||
const marker = L.marker([fcp.lat, fcp.lng], { icon }).addTo(map);
|
||||
const fcpStat = stats.find(s => parseInt(s.fcp_id) === parseInt(fcp.real_id));
|
||||
|
||||
const googleMapsLink = `https://www.google.com/maps/search/?api=1&query=${fcp.lat},${fcp.lng}`;
|
||||
|
||||
const statsHtml = !fcpStat ? `<p>Keine Statistiken gefunden.</p>` : `
|
||||
<div style="margin-bottom: 15px;">
|
||||
<strong style="display: block; margin-bottom: 5px; color: #555;">Zusammenfassung:</strong>
|
||||
<span>Hausnummern Gesamt: <b>${fcpStat.total_hausnummer_count}</b></span><br>
|
||||
<span>Wohneinheiten Gesamt: <b>${fcpStat.total_wohneinheit_count}</b></span><br>
|
||||
<span>Aktive Vorbestellungen: <b>${fcpStat.total_active_preorders}</b></span>
|
||||
</div>
|
||||
<strong style="display: block; margin-bottom: 5px; color: #555;">Details nach RIMO-Typ:</strong>
|
||||
<table style="width: 100%; border-collapse: collapse; font-size: 12px;">
|
||||
<thead>
|
||||
<tr style="background-color: #f2f2f2; text-align: left;">
|
||||
<th style="padding: 8px; border: 1px solid #ddd;">Typ</th>
|
||||
<th style="padding: 8px; border: 1px solid #ddd;">HN</th>
|
||||
<th style="padding: 8px; border: 1px solid #ddd;">WE</th>
|
||||
<th style="padding: 8px; border: 1px solid #ddd;">VB</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
${Object.entries(fcpStat.counts_by_rimo_type || {}).length ?
|
||||
Object.entries(fcpStat.counts_by_rimo_type).map(([type, counts], index) => `
|
||||
<tr style="${index % 2 === 0 ? 'background-color: #ffffff;' : 'background-color: #f9f9f9;'}">
|
||||
<td style="padding: 8px; border: 1px solid #ddd;">${type}</td>
|
||||
<td style="padding: 8px; border: 1px solid #ddd;">${counts.hausnummer_count}</td>
|
||||
<td style="padding: 8px; border: 1px solid #ddd;">${counts.wohneinheit_count}</td>
|
||||
<td style="padding: 8px; border: 1px solid #ddd;">${counts.preorder_count}</td>
|
||||
</tr>
|
||||
`).join('') :
|
||||
'<tr><td colspan="4" style="padding: 8px; text-align: center; border: 1px solid #ddd;">Keine detaillierten Statistiken verfügbar.</td></tr>'
|
||||
}
|
||||
</tbody>
|
||||
</table>
|
||||
`;
|
||||
|
||||
const popupContent = `
|
||||
<div style="font-family: Arial, sans-serif; width: 320px; padding: 5px;">
|
||||
<h3 style="margin-bottom: 10px; color: #333; border-bottom: 1px solid #ddd; padding-bottom: 5px;">
|
||||
${fcp.text}
|
||||
</h3>
|
||||
<a href='${googleMapsLink}' target='_blank' style="color: #007bff; text-decoration: none; margin-bottom: 15px; display: inline-block;">In Google Maps anzeigen</a>
|
||||
${statsHtml}
|
||||
</div>
|
||||
`;
|
||||
marker.bindPopup(popupContent);
|
||||
});
|
||||
}
|
||||
|
||||
function centerMap() {
|
||||
|
||||
Reference in New Issue
Block a user