added pipework history job

This commit is contained in:
Luca Haid
2025-04-14 13:12:45 +02:00
parent 3b4200de52
commit 1563c8922e
2 changed files with 84 additions and 7 deletions

View File

@@ -115,7 +115,6 @@ class BuildingModel {
LEFT JOIN Buildingstatus ON (Buildingstatus.id = Building.status_id)
WHERE $where
ORDER BY network_id, pop_id, street, zip, city";
mfLoghandler::singleton()->debug($sql);
if(is_array($limit) && count($limit)) {
if(is_numeric($limit['start']) && is_numeric($limit['count'])) {
@@ -270,6 +269,13 @@ class BuildingModel {
$where .= " AND city like '$city'";
}
}
if(array_key_exists(">create", $filter)) {
$create = FronkDB::singleton()->escape($filter[">create"]);
if($create) {
$where .= " AND Building.`create` > $create";
}
}
//var_dump($filter, $where);exit;
return $where;
@@ -283,6 +289,7 @@ class BuildingModel {
wi.id AS item_id,
wi.name AS item_name,
wi.num AS item_num,
wi.object_type AS item_object_type,
wi.label AS item_label,
wi.type AS item_type,
wv.id AS value_id,
@@ -294,7 +301,7 @@ class BuildingModel {
FROM Workflowvalue wv
JOIN Workflowitem wi ON wv.item_id = wi.id
JOIN Building b ON wv.object_id = b.id";
$where = ["wi.object_type = 'Building'", "wi.name NOT LIKE '%delimiter%'"];
$where = ["wi.name NOT LIKE '%delimiter%'"];
if ($from !== null && $to !== null) {
$where[] = "(wv.changed >= " . intval($from) . " AND wv.changed <= " . intval($to) . ")";

View File

@@ -29,6 +29,8 @@ $allNetworkData = [];
$from = strtotime("-1 week"); // Simpler timestamp generation
$to = time();
$newBuildings = [];
foreach ($networkIDs as $networkID) {
try {
$network = new Network($networkID); // Assuming Network class is loaded
@@ -39,6 +41,28 @@ foreach ($networkIDs as $networkID) {
// Optional: Log or handle cases where a Network object couldn't be created
error_log("Could not load Network with ID: " . $networkID);
}
// fetch new buildings
$newBuildingsNetwork = BuildingModel::search([
'network_id' => $networkID,
'>create' => $from,
]);
if ($newBuildingsNetwork) {
foreach ($newBuildingsNetwork as $building) {
if (!isset($newBuildings[$network->name])) {
$newBuildings[$network->name] = [];
}
$newBuildings[$network->name][] = [
'network_id' => $networkID,
'network_name' => $network->name,
'building_id' => $building->id,
'street' => $building->street,
'zip' => $building->zip,
'city' => $building->city,
];
}
}
} catch (Exception $e) {
// Optional: Log or handle exceptions during data fetching for a specific network
error_log("Error fetching data for Network ID " . $networkID . ": " . $e->getMessage());
@@ -129,6 +153,32 @@ HTML;
<h2 style="font-size: 1.25rem; font-weight: 600; color: #00558c; margin: 0 0 16px 0;">Netzwerk: {$networkNameHtml}</h2>
HTML;
// Check if there are new buildings and show them
if (!empty($newBuildings[$networkName])) {
$html .= <<<HTML
<h3 style="font-size: 1rem; font-weight: 600; color: #374151; margin: 0 0 16px 0;">Neue Gebäude:</h3>
<ul style="list-style-type: none; padding: 0;">
HTML;
foreach ($newBuildings[$networkName] as $building) {
$buildingStreet = htmlspecialchars($building['street']);
$buildingZip = htmlspecialchars($building['zip']);
$buildingCity = htmlspecialchars($building['city']);
$html .= <<<HTML
<li style="padding: 5px 0; color: #4b5563; border-bottom: 1px solid #e5e7eb; font-size: 0.875rem; line-height: 1.5rem; font-weight: 500; margin: 0;">{$buildingStreet}, {$buildingZip} {$buildingCity}</li>
HTML;
}
$html .= <<<HTML
</ul>
HTML;
} else {
$noNewBuildingsMsg = htmlspecialchars("Keine neuen Gebäude für dieses Netzwerk.");
$html .= <<<HTML
<p style="background-color: #fef3c7; color: #92400e; padding: 10px 15px; border-radius: 6px; font-size: 0.875rem; margin: 0 0 15px;">{$noNewBuildingsMsg}</p>
HTML;
}
if (empty($networkData)) {
$noChangesMsg = htmlspecialchars("Keine Änderungen im Tiefbau für diesen Zeitraum.");
$html .= <<<HTML
@@ -139,6 +189,7 @@ HTML;
<table role="presentation" style="width: 100%; border-collapse: collapse; font-size: 0.875rem;">
<thead>
<tr style="background-color: #f3f4f6;">
<th style="padding: 10px; border-bottom: 1px solid #d1d5db; color: #374151; font-weight: 600;">Art</th>
<th style="padding: 10px; border-bottom: 1px solid #d1d5db; color: #374151; font-weight: 600;">Straße</th>
<th style="padding: 10px; border-bottom: 1px solid #d1d5db; color: #374151; font-weight: 600;">Ort</th>
<th style="padding: 10px; border-bottom: 1px solid #d1d5db; color: #374151; font-weight: 600;">Feld</th>
@@ -185,11 +236,32 @@ HTML;
$street = htmlspecialchars($item->building_street ?? 'N/A');
$city = htmlspecialchars($item->building_city ?? 'N/A');
$label = htmlspecialchars($item->item_label ?? 'N/A');
if (strpos($label, 'Tiefbau abgeschlossen') !== false) {
$label = 'Tiefbau angeschlossen';
}
if (strpos($label, 'Leitungsbau abgeschlossen') !== false) {
$label = 'Leitungsbau angeschlossen';
}
$editedAt = date("d.m.Y H:i", $item->last_edited_at); // Shortened format for space
$type = intval($item->item_num) > 150 ? 'Ist-Zustand' : 'Planung';
if ($item->item_object_type == 'Building') {
$type = intval($item->item_num) > 150 ? 'Ist-Zustand' : 'Planung';
$type2 = 'Tiefbau';
} else if ($item->item_object_type == 'Termination') {
if (intval($item->item_num) > 0 && intval($item->item_num) < 1005) $type = 'Planung';
else if (intval($item->item_num) > 1005 && intval($item->item_num) < 2005) $type = 'Ist-Zustand';
else $type = 'Zusätzlich';
$type2 = 'Leitungsbau';
} else {
$type = 'Unbekannt';
$type2 = 'Unbekannt';
}
$html .= <<<HTML
<tr style="border-bottom: 1px solid #e5e7eb;">
<td style="padding: 10px; color: #4b5563;">{$type2}</td>
<td style="padding: 10px; color: #4b5563;">{$street}</td>
<td style="padding: 10px; color: #4b5563;">{$city}</td>
<td style="padding: 10px; color: #4b5563;">{$label}</td>
@@ -256,7 +328,7 @@ try {
// Recipients
$mail->setFrom('thetool@xinon.at', 'XINON TheTool'); // Use sender address from config if available
$mail->addAddress('mark.zaff@xinon.eu', 'Mark Zaff');
// $mail->addAddress('mark.zaff@xinon.eu', 'Mark Zaff');
$mail->addAddress('luca.haid@xinon.eu', 'Luca Haid');
// Content
@@ -277,6 +349,4 @@ try {
error_log("E-Mail konnte nicht gesendet werden. Mailer Error: {$mail->ErrorInfo}");
// Output a user-friendly message
echo "E-Mail konnte nicht gesendet werden. Fehlerdetails wurden protokolliert. Mailer Error: {$mail->ErrorInfo}" . PHP_EOL; // German output
}
?>
}?>