updated rimotype map
This commit is contained in:
@@ -1229,14 +1229,12 @@ class PreorderController extends mfBaseController {
|
||||
);
|
||||
}
|
||||
|
||||
public function getRimoFcpStatsApi() {
|
||||
$this->postData = json_decode(file_get_contents("php://input"));
|
||||
$stats = ADBRimoFcp::getRimoFcpStatistics();
|
||||
public function getRimoFcpStatsApi()
|
||||
{
|
||||
$this->postData = json_decode(file_get_contents("php://input"), true);
|
||||
$fcpIds = $this->postData['fcp_ids'] ?? [];
|
||||
$stats = ADBRimoFcp::getRimoFcpStatistics($fcpIds);
|
||||
|
||||
if (!empty($this->postData->fcp_ids)) {
|
||||
$fcpIds = (array) $this->postData->fcp_ids;
|
||||
$stats = array_filter($stats, fn($item) => in_array($item['fcp_id'], $fcpIds));
|
||||
}
|
||||
|
||||
foreach ($stats as &$item)
|
||||
if (isset($item['counts_by_rimo_type']) && is_string($item['counts_by_rimo_type']))
|
||||
@@ -1797,7 +1795,11 @@ class PreorderController extends mfBaseController {
|
||||
$this->redirect("Preorder", "Index");
|
||||
}
|
||||
|
||||
Helper::renderVue($this, "PreorderRimoTypeMap", "PreorderRimoTypeMap", ["MAPBOX_KEY" => TT_MAPBOX_TILE_API_TOKEN]);
|
||||
Helper::renderVue($this, "PreorderRimoTypeMap", "PreorderRimoTypeMap", [
|
||||
"MAPBOX_KEY" => TT_MAPBOX_TILE_API_TOKEN,
|
||||
"USER_ID" => $this->me->id,
|
||||
"ALL_USERS" => array_map(fn($u) => ["id" => $u->id, "name" => $u->name], UserModel::getAll())
|
||||
]);
|
||||
}
|
||||
|
||||
public function RimoTypeMapDataAction() {
|
||||
@@ -1810,4 +1812,130 @@ class PreorderController extends mfBaseController {
|
||||
$data = PreorderModel::getPreorderRimoTypeData($campaignId);
|
||||
self::returnJson(['success' => true, 'data' => $data]);
|
||||
}
|
||||
|
||||
public function RimoTypeMapSaveFaultsAction() {
|
||||
$input = json_decode(file_get_contents('php://input'), true);
|
||||
$campaignId = $input['campaignId'] ?? null;
|
||||
$faults = $input['faults'] ?? [];
|
||||
$allowedCampaigns = Helper::getPreorderCampaignFromUser($this->me);
|
||||
|
||||
if (!$campaignId || !in_array($campaignId, $allowedCampaigns)) self::sendError('Ungültige oder keine Kampagne ausgewählt.');
|
||||
if (!is_array($faults) || !count($faults)) self::sendError('Keine Fehlerdaten übermittelt.');
|
||||
|
||||
$campaign = new Preordercampaign($campaignId);
|
||||
if (!$campaign->id) self::sendError('Kampagne nicht gefunden.');
|
||||
|
||||
$campaign->rimo_type_map_faults = json_encode($faults);
|
||||
if (!$campaign->save()) self::sendError('Fehler beim Speichern der Fehlerdaten.');
|
||||
|
||||
self::returnJson(['success' => true, 'message' => 'Fehlerdaten erfolgreich gespeichert.']);
|
||||
}
|
||||
|
||||
public function RimoTypeMapGetFaultsAction() {
|
||||
$campaignId = $this->request->preordercampaign_id ?? null;
|
||||
$allowedCampaigns = Helper::getPreorderCampaignFromUser($this->me);
|
||||
|
||||
if (!$campaignId || !in_array($campaignId, $allowedCampaigns)) self::sendError('Ungültige oder keine Kampagne ausgewählt.');
|
||||
|
||||
$campaign = new Preordercampaign($campaignId);
|
||||
if (!$campaign->id) self::sendError('Kampagne nicht gefunden.');
|
||||
|
||||
$faults = $campaign->rimo_type_map_faults ? json_decode($campaign->rimo_type_map_faults, true) : [];
|
||||
self::returnJson(['success' => true, 'faults' => $faults]);
|
||||
}
|
||||
|
||||
protected function generateTemplate(string $templateName, array $replacements): string {
|
||||
$path = BASEDIR . "/Layout/default/{$templateName}.html";
|
||||
if (!file_exists($path)) self::sendError("Template nicht gefunden: {$templateName}");
|
||||
|
||||
$content = file_get_contents($path);
|
||||
foreach ($replacements as $key => $value) $content = str_replace("{{ {$key} }}", $value ?? '', $content);
|
||||
|
||||
return $content;
|
||||
}
|
||||
|
||||
public function RimoTypeMapFaultsPDFAction() {
|
||||
if (empty($this->request->preordercampaign_id)) self::sendError('Kampagnen-ID fehlt.');
|
||||
$campaignId = $this->request->preordercampaign_id;
|
||||
|
||||
if (!in_array($campaignId, Helper::getPreorderCampaignFromUser($this->me))) self::sendError('Zugriff auf diese Kampagne verweigert.');
|
||||
|
||||
$campaign = new Preordercampaign($campaignId);
|
||||
if (!$campaign->id) self::sendError('Kampagne nicht gefunden.');
|
||||
|
||||
$faults = json_decode($campaign->rimo_type_map_faults, true) ?? [];
|
||||
$allAddressesById = array_column(PreorderModel::getPreorderRimoFaultsData((int)$campaignId), null, 'hausnummer_id');
|
||||
|
||||
$faultReasonMap = [
|
||||
'building_type' => 'Gebäudetyp falsch',
|
||||
'home_count' => 'Homeanzahl falsch',
|
||||
'not_existent' => 'Gebäude nicht existent',
|
||||
'other' => 'Sonstiges',
|
||||
'graz_umgebung' => 'Ort/Gemeinde nicht existent'
|
||||
];
|
||||
|
||||
$faultyEntriesData = [];
|
||||
|
||||
foreach ($faults as $hausnummerId => $faultData) {
|
||||
if (!isset($allAddressesById[$hausnummerId])) continue;
|
||||
if (!empty($faultData['done']) && ($faultData['done'] === true || $faultData['done'] === 1 || $faultData['done'] === 'true')) continue;
|
||||
|
||||
$addressInfo = $allAddressesById[$hausnummerId];
|
||||
$reasons = array_map(fn($key) => $faultReasonMap[$key] ?? $key, $faultData['reasons'] ?? []);
|
||||
|
||||
$faultyEntriesData[$hausnummerId] = [
|
||||
'address' => $addressInfo,
|
||||
'faults' => [
|
||||
'reasons' => $reasons,
|
||||
'other' => htmlspecialchars($faultData['other'] ?? '')
|
||||
]
|
||||
];
|
||||
}
|
||||
|
||||
$faultyEntries = [];
|
||||
foreach ($faultyEntriesData as $hausnummerId => $data) {
|
||||
$addressInfo = $allAddressesById[$hausnummerId];
|
||||
$faultyEntries[] = [
|
||||
'address' => $addressInfo,
|
||||
'faults' => $data['faults'],
|
||||
'addressDbLink' => "https://thetool.xinon.at/AddressDB/View?id={$hausnummerId}",
|
||||
'googleMapsLink' => "https://maps.google.com/?q={$addressInfo['gps_lat']},{$addressInfo['gps_long']}"
|
||||
];
|
||||
}
|
||||
|
||||
$tempDir = BASEDIR . "/var/temp";
|
||||
is_dir($tempDir) || mkdir($tempDir, 0775, true);
|
||||
|
||||
$replacements = [
|
||||
'basedir' => BASEDIR,
|
||||
'campaignName' => htmlspecialchars($campaign->name),
|
||||
'creationDate' => date("d.m.Y"),
|
||||
];
|
||||
|
||||
$headerFile = tempnam($tempDir, 'pdf_header_') . '.html';
|
||||
$footerFile = tempnam($tempDir, 'pdf_footer_') . '.html';
|
||||
file_put_contents($headerFile, $this->generateTemplate('Preorder/PDF_HEADER', $replacements));
|
||||
file_put_contents($footerFile, $this->generateTemplate('Preorder/PDF_FOOTER', $replacements));
|
||||
|
||||
$pdf = new PdfForm("Preorder/PDF_MAIN", [
|
||||
"campaignName" => $campaign->name,
|
||||
"faultyEntries" => $faultyEntries,
|
||||
]);
|
||||
|
||||
$options = "--header-html {$headerFile} --footer-html {$footerFile} --margin-top 35 --margin-bottom 25";
|
||||
$filename = $pdf->render($options);
|
||||
|
||||
unlink($headerFile);
|
||||
unlink($footerFile);
|
||||
|
||||
if (!file_exists($filename)) self::sendError('Generierte PDF-Datei nicht gefunden.');
|
||||
|
||||
$outputFilename = "Fehlerprotokoll_" . preg_replace('/[^a-zA-Z0-9_-]/', '_', $campaign->name) . ".pdf";
|
||||
header('Content-Type: application/pdf');
|
||||
header('Content-Disposition: inline; filename="' . $outputFilename . '"');
|
||||
header('Content-Length: ' . filesize($filename));
|
||||
readfile($filename);
|
||||
unlink($filename);
|
||||
exit;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user