Files
thetool/Layout/default/Preorder/include/preorder-detail.php
Frank Schubert 90e40567b1 Merge branch 'fronkdev' into 'master'
PreorderstatusJournal & preorder flags -> ADBHausnummer flags sync

See merge request fronk/thetool!1739
2025-09-10 15:41:55 +00:00

1135 lines
69 KiB
PHP

<div class="card">
<div class="card-body" id="preorder-<?=$preorder->id?>-body">
<div class="row justify-content-center mt-2">
<div class="col-12">
<ul class="nav nav-tabs order-tab">
<li class="nav-item"><a class="nav-link active" href="#preorder-detail-<?=$preorder->id?>-detail" data-toggle="tab" aria-expanded="false">Bestellung</a></li>
<li class="nav-item"><a class="nav-link" href="#preorder-detail-<?=$preorder->id?>-address" data-toggle="tab" aria-expanded="false">Adressdetails</a></li>
<li class="nav-item"><a class="nav-link" href="#preorder-detail-<?=$preorder->id?>-flags" data-toggle="tab" aria-expanded="false">Status</a></li>
<?php if($preorder->campaign->fulfillment != "citycom_oan"): ?>
<li class="nav-item"><a class="nav-link" href="#preorder-detail-<?=$preorder->id?>-rimo" data-toggle="tab" aria-expanded="false">RIMO</a></li>
<?php else: ?>
<li class="nav-item"><a class="nav-link" href="#preorder-detail-<?=$preorder->id?>-citycom-oan" data-toggle="tab" aria-expanded="false">Citycom OAN</a></li>
<?php endif; ?>
<?php if($preorder->adb_hausnummer->borderpoint_lat && $preorder->adb_hausnummer->borderpoint_long): ?>
<li class="nav-item"><a class="nav-link" href="#preorder-detail-<?=$preorder->id?>-map" data-toggle="tab" aria-expanded="false" onclick="loadBorderpointMap(<?=$preorder->id?>)">Übergabepunkt</a></li>
<?php endif; ?>
<li class="nav-item"><a class="nav-link" href="#preorder-detail-<?=$preorder->id?>-history" data-toggle="tab" aria-expanded="false">History</a></li>
<li class="nav-item"><a class="nav-link" href="#preorder-detail-<?=$preorder->id?>-emails" data-toggle="tab" aria-expanded="false">E-Mails</a></li>
</ul>
</div>
</div>
<div class="tab-content pt-0">
<div id="preorder-detail-<?=$preorder->id?>-detail" class="tab-pane show active">
<div class="row justify-content-center">
<div class="col-12">
<div class="card">
<div class="card-body">
<div class="card-header bg-info text-white pl-2 pr-2 pt-1 pb-1">Details</div>
<div class="row">
<div class="col-8">
<div class="loader-big hidden" ><img src="<?=self::getResourcePath()?>assets/images/loader-big.gif" /></div>
<h3>Allgemein</h3>
<table class="table table-sm table-striped">
<tr>
<th>ID:</th>
<td class="text-monospace"><?=$preorder->id?></td>
</tr><tr>
<th>Bestellcode:</th>
<td class="text-monospace"><?=$preorder->ucode?></td>
</tr><th>Kampagne:</th>
<td><?=$preorder->campaign->name?></td>
</tr><tr>
<th>Status:</th>
<td class="text-monospace">
<span id="preorder-detail-status-<?=$preorder->id?>-text" data-status-id="<?=$preorder->status_id?>"><span id="preorder-detail-status-<?=$preorder->id?>-statustext"><?=$preorder->status->code?> - <?=$preorder->status->name?></span> <a href="#" onclick="return toggleStatusControl(<?=$preorder->id?>)"><i class="fas fa-fw fa-edit"></i></a></span>
<div class="input-group" id="preorder-detail-status-<?=$preorder->id?>-input" style="display:none">
<select class="form-control">
<?php foreach(PreorderstatusModel::getAll() as $status): ?>
<option value="<?=$status->id?>" <?=($preorder->status_id == $status->id) ? "selected='selected'" : ""?>><?=$status->code?> - <?=$status->name?></option>
<?php endforeach; ?>
</select>
<div class="input-group-append">
<button type="button" class="btn btn-primary" title="Speichern" onclick="savePreorderStatusControl(<?=$preorder->id?>, 'email')"><i class="fas fa-check"></i></button>
<button type="button" class="btn btn-secondary" title="Abbrechen" onclick="toggleStatusControl(<?=$preorder->id?>, 'email')"><i class="fas fa-times"></i></button>
</div>
</div>
</td>
</tr><tr>
<th>OAID:</th>
<td class="text-monospace text-pink"><?=$preorder->oaid?></td>
</tr><tr>
<th>Bestelltyp:</th>
<td><?=__($preorder->type, "preorder")?></td>
</tr><tr>
<th>Anschlusstyp:</th>
<td><?=__($preorder->connection_type, "preorder")?></td>
</tr><tr>
<th>Ist Zusatzbestellung:</th>
<td><?=($preorder->is_additional_order) ? "Ja" : "Nein"?></td>
</tr><tr>
<th>Partner:</th>
<td><?=$preorder->partner->getCompanyOrName()?></td>
</tr><tr>
<th>Bestelldatum:</th>
<td>
<span id="preorder-detail-orderdate-<?=$preorder->id?>-text" data-orderdate="<?=$preorder->order_date?>"><span id="preorder-detail-orderdate-<?=$preorder->id?>-textpart"><?=($preorder->order_date) ? date("d.m.Y",$preorder->order_date) : ""?></span> <a href="#" onclick="return toggleOrderdateControl(<?=$preorder->id?>)"><i class="fas fa-fw fa-edit"></i></a></span>
<div class="input-group" id="preorder-detail-orderdate-<?=$preorder->id?>-input" style="display:none">
<input type="text" class="form-control datepicker" value="<?=($preorder->order_date) ? date("d.m.Y",$preorder->order_date) : ""?>" />
<div class="input-group-append">
<button type="button" class="btn btn-primary" title="Speichern" onclick="savePreorderOrderdateControl(<?=$preorder->id?>)"><i class="fas fa-check"></i></button>
<button type="button" class="btn btn-secondary" title="Abbrechen" onclick="toggleOrderdateControl(<?=$preorder->id?>)"><i class="fas fa-times"></i></button>
</div>
</div>
</td>
</tr><tr>
<th>Aktivierungsdatum (Status 500):</th>
<td>
<?php if($preorder->getStatuschangeTo(500)): ?>
<span id="preorder-detail-activationdate-<?=$preorder->id?>-text" data-activationdate="<?=($preorder->getStatuschangeTo(500)) ? (new DateTime("@".$preorder->getStatuschangeTo(500)))->format("d.m.Y") : ""?>"><span id="preorder-detail-activationdate-<?=$preorder->id?>-textpart"><?=($preorder->getStatuschangeTo(500)) ? (new DateTime("@".$preorder->getStatuschangeTo(500)))->format("d.m.Y") : ""?></span> <span id="preorder-detail-activationdate-<?=$preorder->id?>-activation-billing-part"><?=($preorder->activation_billing) ? "(Billing ab Aktivierung)" : ""?></span> <a href="#" onclick="return toggleActivationdateControl(<?=$preorder->id?>)"><i class="fas fa-fw fa-edit"></i></a></span>
<div class="input-group" id="preorder-detail-activationdate-<?=$preorder->id?>-input" style="display:none">
<input type="text" class="form-control datepicker" value="<?=($preorder->getStatuschangeTo(500)) ? (new DateTime("@".$preorder->getStatuschangeTo(500)))->format("d.m.Y") : ""?>" />
<div class="input-group-append">
<button type="button" class="btn btn-primary" title="Speichern" onclick="savePreorderActivationdateControl(<?=$preorder->id?>)"><i class="fas fa-check"></i></button>
<button type="button" class="btn btn-secondary" title="Abbrechen" onclick="toggleActivationdateControl(<?=$preorder->id?>)"><i class="fas fa-times"></i></button>
</div>
</div>
<div id="preorder-detail-activation-billing-<?=$preorder->id?>" class="mt-1 hidden">
<label><input type="checkbox" name="activation_billing" value="1" <?=($preorder->activation_billing) ? "checked='checked'" : "" ?> /> Verrechnung ab Aktivierungsdatum (Wenn vor globalem Verrechnungsstart)</label><br />
</div>
<?php endif; ?>
</td>
</tr>
<!-- add new checkbox field here called "Verrechnet" and if $preorder->billed is not null or 0 show the unix date, also only show this when
preordercampaign -> network_id -> network -> owner_id === 209
then show billed = timestamp (no input as the checkbox is the only thing that can be changed)
also show billed_by
-->
<?php if($preorder->campaign->network->owner_id === "209"): ?>
<tr>
<th>Verrechnet:</th>
<td>
<div class="flex items-center space-x-2">
<input
type="checkbox"
id="preorder-detail-billed-<?=$preorder->id?>"
class="form-checkbox h-5 w-5 text-blue-600 rounded focus:ring-blue-500"
<?=($preorder->billed) ? 'checked' : ''?>
onchange="updatePreorderBilled(<?=$preorder->id?>, this.checked)"
/>
<label for="preorder-detail-billed-<?=$preorder->id?>" class="text-gray-700 mb-0">Verrechnet</label>
</div>
<?php if($preorder->billed_by && $preorder->billed): ?>
<div class="mt-2 text-sm text-gray-600" id="billed_text">Verrechnet durch: <?=(new User($preorder->billed_by))->name?> am <?=date("d.m.Y H:i", $preorder->billed)?> Uhr</div>
<?php endif; ?>
</td>
<script>
// console log if changed
function updatePreorderBilled(preorderId, isChecked) {
console.log("Updating billed status for preorder " + preorderId + ": " + (isChecked ? "checked" : "unchecked"));
$.ajax({
url: '<?=self::getUrl("Preorder", "Api")?>?do=updateBilled',
type: 'POST',
data: {
do: 'updateBilled',
id: preorderId,
billed: isChecked ? 1 : 0
},
success: function(response) {
console.log("Update successful:", response);
if (isChecked) {
$("#billed_text").html(`Verrechnet durch: ${response.result.billed_by_name} am ${response.result.billed_date} Uhr`);
window.notify("success", "Preorder wurde als verrechnet markiert.");
} else {
$("#billed_text").html("");
window.notify("success", "Preorder wurde als nicht verrechnet markiert.");
}
},
error: function(xhr, status, error) {
console.error("Update failed:", error);
window.notify("error", "Fehler beim Aktualisieren des Verrechnungsstatus: " + error);
}
});
}
</script>
</tr>
<?php endif; ?>
<tr>
<th>Erstellt:</th>
<td class="text-monospace"><?=date("d.m.Y H:i",$preorder->create)?> (<?=$preorder->creator->name?>)</td>
</tr><tr>
<th>Zuletzt bearbeitet:</th>
<td class="text-monospace"><?=date("d.m.Y H:i",$preorder->edit)?> (<?=$preorder->editor->name?>)</td>
</tr>
</table>
</div>
<div class="col-4">
<div class="row">
<div class="col">
<h3>Zustimmungen</h3>
<table class="table table-sm table-striped">
<tr>
<th>Zustimmung AGB:</th>
<td><?=($preorder->accept_agb) ? '<i class="fas fa-fw fa-check text-success"></i>' : '<i class="fas fa-fw fa-xmark text-danger"></i>'?></td>
</tr><tr>
<th>Zustimmung DSGVO:</th>
<td><?=($preorder->accept_dsgvo) ? '<i class="fas fa-fw fa-check text-success"></i>' : '<i class="fas fa-fw fa-xmark text-danger"></i>'?></td>
</tr><tr>
<th>Zustimmung Rücktrittsrecht:</th>
<td><?=($preorder->accept_withdrawal) ? '<i class="fas fa-fw fa-check text-success"></i>' : '<i class="fas fa-fw fa-xmark text-danger"></i>'?></td>
</tr><tr>
<th>Zustimmung Datenweitergabe:</th>
<td><?=($preorder->accept_marketing) ? '<i class="fas fa-fw fa-check text-success"></i>' : '<i class="fas fa-fw fa-xmark text-danger"></i>'?></td>
</tr><tr>
<th>Zustimmung Grabungsarbeiten:</th>
<td><?=($preorder->accept_digging) ? '<i class="fas fa-fw fa-check text-success"></i>' : '<i class="fas fa-fw fa-xmark text-danger"></i>'?></td>
</tr>
</table>
</div>
</div>
<div class="row">
<div class="col">
<h3>Starterpaket</h3>
<table class="table table-sm table-striped">
<tr>
<th>CIF Token:</th>
<td class="text-monospace" id="preorder-detail-ciftoken-<?=$preorder->id?>"><?=$preorder->ciftoken?></td>
</tr><tr>
<th>CIF Kabelnachbestell-Url:</th>
<td class="text-monospace" id="preorder-detail-cifcableurl-<?=$preorder->id?>"><?=$preorder->cifcableurl?></td>
</tr><tr>
<th>Starterpaket versandt:</th>
<td class="text-monospace"><?=($preorder->logistics && $preorder->logistics->sent) ? '<i class="fas fa-fw fa-check text-success"></i> '.date("d.m.Y H:i", $preorder->logistics->sent) : '<i class="fas fa-fw fa-xmark text-danger"></i>'?></td>
</tr>
</table>
</div>
</div>
</div>
</div>
<div class="row">
<div class="col-6">
<h3>Bestelldaten</h3>
<table class="table table-sm table-striped">
<tr>
<th>Extref:</th>
<td class="text-monospace"><?=htmlentities($preorder->extref)?></td>
</tr><tr>
<th>Adressinfo:</th>
<td><?=nl2br(htmlentities($preorder->address_info))?></td>
</tr><tr>
<th>Versand an:</th>
<td><?=($preorder->address_info == "address") ? "Anschlussadresse" : "Kontaktadresse"?></td>
</tr>
</table>
<?php if($preorder->discounts): ?>
<h3>Gutscheincodes</h3>
<table class="table table-sm table-striped">
<tr>
<th>Code</th>
<th>Zugewiesen</th>
<th>Info</th>
</tr>
<?php foreach($preorder->discounts as $discount): ?>
<tr>
<td class="text-monospace"><?=$discount->code?></td>
<td class="text-monospace"><?=date("d.m.Y H:i", $discount->assigned)?></td>
<td><?=htmlentities($discount->info)?></td>
</tr>
<?php endforeach; ?>
</tr>
</table>
<?php endif; ?>
</div>
<div class="col-6">
<?php if($preorder->ordered_services): ?>
<h3>Bestellte Zusatzdienste</h3>
<table class="table table-sm table-striped">
<tr>
<th>Dienst</th>
<th>Bestellt</th>
<th>Daten</th>
</tr>
<?php foreach($preorder->ordered_services as $service): ?>
<tr>
<td><?=$service->service?></td>
<td><?=($service->ordered == true || $service->ordered == 1) ? "Ja" : "Nein"?></td>
<td class="text-monospace">
<?php if($service->data): ?>
<?php foreach($service->data as $data): ?>
<?=$data->name?>: <?=$data->value?><br />
<?php endforeach; ?>
<?php endif; ?>
</td>
</tr>
<?php endforeach; ?>
</table>
<?php endif; ?>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<div id="preorder-detail-<?=$preorder->id?>-address" class="tab-pane">
<div class="row justify-content-center">
<div class="col-12">
<div class="card">
<div class="card-body">
<div class="card-header bg-info text-white pl-2 pr-2 pt-1 pb-1">Addressdetails</div>
<div class="row">
<div class="col-6">
<h3>Anschlussadresse</h3>
<table class="table table-sm table-striped">
<tr>
<th>ID</th>
<td class="text-monospace"><?=$preorder->adb_hausnummer_id?></td>
</tr><tr>
<th>OAID</th>
<td class="text-monospace text-pink"><?=$preorder->adb_hausnummer->oaid?></td>
</tr><tr>
<th>Status</th>
<td id="preorder-detail-building-status-<?=$preorder->id?>" class="text-monospace"><?=$preorder->adb_hausnummer->status->code?> - <?=$preorder->adb_hausnummer->status->name?></td>
</tr><tr>
<th>Statusflags</th>
<td>
<table class="table table-sm table-bordered table-striped bg-white">
<tr>
<th></th>
<th>Code</th>
<th>Text</th>
</tr>
<?php foreach($preorder->adb_hausnummer->statusflags as $flag): ?>
<tr>
<td class="text-center"><?=($flag->value->value) ? "<i class='fas fa-check text-success'></i>" : ""?></td>
<td><?=$flag->code?></td>
<td><?=$flag->name?></td>
</tr>
<?php endforeach; ?>
</table>
</td>
</tr><tr>
<th>Extref</th>
<td class="text-monospace"><?=$preorder->adb_hausnummer->extref?></td>
</tr><tr>
<th>Straße/Hausnummer</th>
<td><?=$preorder->adb_hausnummer->strasse->name?> <?=$preorder->adb_hausnummer->hausnummer?></td>
</tr><tr>
<th>PLZ Ort</th>
<td><?=$preorder->adb_hausnummer->plz->plz?> <?=$preorder->adb_hausnummer->ortschaft->name?></td>
</tr><tr>
<th>Gemeinde</th>
<td><?=$preorder->adb_hausnummer->strasse->gemeinde->name?></td>
</tr><tr>
<th>Anzahl Wohneinheiten</th>
<td><?=(is_array($preorder->adb_hausnummer->wohneinheiten) && count($preorder->adb_hausnummer->wohneinheiten)) ? count($preorder->adb_hausnummer->wohneinheiten) : "0"?></td>
</tr>
</table>
<h3>Nutzungseinheit</h3>
<table class="table table-sm table-striped">
<tr>
<th>ID</th>
<td class="text-monospace"><?=($preorder->adb_wohneinheit_id) ? $preorder->adb_wohneinheit_id : ""?></td>
</tr><tr>
<th>Status</th>
<td id="preorder-detail-unit-status-<?=$preorder->id?>" class="text-monospace"><?=$preorder->adb_wohneinheit->status->code?> - <?=$preorder->adb_wohneinheit->status->name?></td>
</tr><tr>
<th>OAID</th>
<td class="text-monospace text-pink"><?=$preorder->adb_wohneinheit->oaid?></td>
</tr><tr>
<th>Extref</th>
<td class="text-monospace"><?=$preorder->adb_wohneinheit->extref?></td>
</tr><tr>
<th>Block</th>
<td><?=$preorder->adb_wohneinheit->block?></td>
</tr><tr>
<th>Stiege</th>
<td><?=$preorder->adb_wohneinheit->stiege?></td>
</tr><tr>
<th>Stock</th>
<td><?=$preorder->adb_wohneinheit->stock?></td>
</tr><tr>
<th>Tür</th>
<td><?=$preorder->adb_wohneinheit->tuer?></td>
</tr><tr>
<th>Zusatz</th>
<td><?=$preorder->adb_wohneinheit->zusatz?></td>
</tr><tr>
<th>Bezeichner</th>
<td><?=$preorder->adb_wohneinheit->bezeichner?></td>
</tr>
</table>
</div>
<div class="col-6">
<h3>Kontaktadresse</h3>
<table class="table table-sm table-striped">
<tr>
<th>Firma</th>
<td><?=$preorder->company?></td>
</tr><tr>
<th>UID</th>
<td><?=$preorder->uidy?></td>
</tr><tr>
<th>Vorname</th>
<td><?=$preorder->firstname?></td>
</tr><tr>
<th>Nachname</th>
<td><?=$preorder->lastname?></td>
</tr><tr>
<th>Straße</th>
<td>
<?=$preorder->street?> <?=$preorder->housenumber?>
<?=($preorder->block) ? "/".$preorder->block : ""?>
<?=($preorder->stiege) ? "/".$preorder->stiege : ""?>
<?=($preorder->stock) ? "/".$preorder->stock : ""?>
<?=($preorder->tuer) ? "/".$preorder->tuer : ""?>
</td>
</tr><tr>
<th>PLZ</th>
<td><?=$preorder->zip?></td>
</tr><tr>
<th>Ort</th>
<td><?=$preorder->city?></td>
</tr><tr>
<th>Telefon</th>
<td><?=$preorder->phone?></td>
</tr><tr>
<th>Email</th>
<td><?=$preorder->email?></td>
</tr>
</table>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<?php if($preorder->campaign->fulfillment != "citycom_oan"): ?>
<div id="preorder-detail-<?=$preorder->id?>-rimo" class="tab-pane">
<div class="row justify-content-center">
<div class="col-12">
<div class="card">
<div class="card-body">
<div class="card-header bg-info text-white pl-2 pr-2 pt-1 pb-1">RIMO</div>
<div class="row">
<div class="col-6">
<div class="row col">
<h3>Metadaten</h3>
<table class="table table-sm table-striped">
<tr>
<th>Building Name:</th>
<td class="text-monospace"><?=$preorder->adb_hausnummer->extref?>
</tr><tr>
<th>Building External ID:</th>
<td class="text-monospace"><?=$preorder->adb_hausnummer->rimo_id?>
</tr><tr>
<th>Building Execution State:</th>
<td class="text-monospace"><?=$preorder->adb_hausnummer->rimo_ex_state?>
</tr><tr>
<th>Building Operational State:</th>
<td class="text-monospace"><?=($preorder->adb_hausnummer->rimo_op_state != "Undefined") ? $preorder->adb_hausnummer->rimo_op_state : ""?>
</tr><tr>
<th>Home External ID:</th>
<td class="text-monospace"><?=$preorder->adb_wohneinheit->extref?>
</tr><tr>
<th>Home Execution State:</th>
<td class="text-monospace"><?=$preorder->adb_wohneinheit->rimo_ex_state?>
</tr><tr>
<th>Home Operational State:</th>
<td class="text-monospace"><?=($preorder->adb_wohneinheit->rimo_op_state != "Undefined") ? $preorder->adb_wohneinheit->rimo_op_state : ""?>
</tr>
</table>
</div>
<div class="row">
<div class="col workorder-container">
<h3>Workorder</h3>
<?php if($preorder->adb_wohneinheit_id && is_array($preorder->adb_wohneinheit->rimo_workorders) && count($preorder->adb_wohneinheit->rimo_workorders)): ?>
<?php foreach($preorder->adb_wohneinheit->rimo_workorders as $wo): ?>
<h4>
<?=$wo->rimo_name?>
<a href="<?=self::getUrl("RimoWorkorder", "downloadAh", ["id" => $wo->id])?>" onclick="event.preventDefault(); downloadWorkorderAha(<?=$wo->id?>);"><i class="fas fa-fw fa-file-download ml-2"></i> AHA Blatt</a>
</h4>
<small id="preorder-detail-<?=$preorder->id?>-workorder-<?=$wo->id?>-del"><a href="#" onclick="if(confirm('Achtung: Löscht die Workorder in thetool, aber NICHT in RIMO!')) return deleteWorkorder(<?=$preorder->id?>, <?=$wo->id?>)" class="text-danger"><i class="far fa-times-circle"></i> Workorder löschen</a></small>
<table class="table table-sm table-striped" id="preorder-detail-<?=$preorder->id?>-workorder-<?=$wo->id?>">
<tr>
<th>Name</th>
<td class="text-monospace"><?=$wo->rimo_name?></td>
</tr><tr>
<th>External ID</th>
<td class="text-monospace"><?=$wo->rimo_id?></td>
</tr><tr>
<th>Status</th>
<td><?=$wo->rimo_status?></td>
</tr>
<?php if($wo->rimo_team_name): ?>
<tr>
<th>Zugewiesen an:</th>
<td><?=$wo->rimo_team_name?></td>
</tr>
<?php endif; ?>
<tr>
<th>Erstellt</th>
<td class="text-monospace"><?=date("d.m.Y H:i:s", $wo->create)?></td>
</tr>
<tr>
<th>Bemerkung</th>
<td id="wo-remark-<?=$preorder->id?>-<?=$wo->id?>">
<div class="input-group mb-2">
<input type="text" class="form-control" name="new_remark" placeholder="Bemerkung hinzufügen" />
<div class="input-group-append">
<button class="btn btn-primary" type="button" id="button-addon2" onclick="saveRemark(<?=$preorder->id?>, <?=$wo->id?>)">Hinzufügen</button>
</div>
</div>
<div class="remark-text border p-1 text-monospace" id="preorder-detail-<?=$preorder->id?>-workorder-<?=$wo->id?>-remarks">
<?=nl2br(htmlentities($wo->remarks))?>
</div>
</td>
</tr>
</table>
<?php endforeach; ?>
<?php elseif($preorder->status->code != "20"): ?>
<button type="button" class="btn btn-outline-primary create-workorder" onclick="createWorkorder(<?=$preorder->id?>)"><i class="fas fa-fw fa-plus"></i> <i class="fas fa-r"></i><i class="fas fa-fw fa-gears"></i> Wokorder erstellen</button>
<?php elseif($preorder->status->code == "20"): ?>
<div class="alert alert-info mt-2" role="alert">
<i class="fas fa-info-circle"></i> Diese Preorder ist auf Hold gesetzt. Es kann keine Workorder erstellt werden.
</div>
<?php endif; ?>
</div>
</div>
</div>
<div class="col-6">
<div class="row col">
<h3>FTU</h3>
<table class="table table-sm table-striped">
<tr>
<th>FTU Name:</th>
<td class="text-monospace"><?=$preorder->adb_wohneinheit->ftu_data["name"]?>
</tr><tr>
<th>FTU External ID:</th>
<td class="text-monospace"><?=$preorder->adb_wohneinheit->ftu_data["id"]?>
</tr>
</table>
</div>
<div class="col row">
<h3 >FCP</h3>
<?php
if($preorder->fcp): ?>
<table class="table table-sm table-striped">
<tr>
<th>FCP Name:</th>
<td class="text-monospace"><?=$preorder->fcp->name?>
</tr><tr>
<th>FCP External ID:</th>
<td class="text-monospace"><?=$preorder->fcp->rimo_id?>
</tr>
<tr>
<th>FCP Execution State:</th>
<td class="text-monospace"><?=$preorder->fcp->rimo_ex_state?>
</tr><tr>
<th>FCP Operational State:</th>
<td class="text-monospace"><?=($preorder->fcp->rimo_op_state != "Undefined") ? $preorder->fcp->rimo_op_state : ""?>
</tr><tr>
<th>FCP Building Type:</th>
<td class="text-monospace"><?=$preorder->fcp->building_type?>
</tr>
</table>
<?php else: ?>
<div class="col-12 p-0">
<div class="alert alert-info mt-2" role="alert">
<i class="fas fa-info-circle"></i> Kein FCP zugewiesen/importert.
</div>
</div>
<?php endif; ?>
</div>
<div class="row col">
<h3>
Patchposition
<?php if($preorder->adb_wohneinheit_id): ?>
<small id="preorder-detail-<?=$preorder->id?>-patchposition-edit"><a href="#" onclick="togglePortdata(<?=$preorder->id?>); return false;"><i class="fas fa-pencil"></i> Bearbeiten</a></small>
<span id="preorder-detail-<?=$preorder->id?>-patchposition-controls" class="hidden">
<button type="button" class="btn btn-sm btn-primary" onclick="savePortdata(<?=$preorder->id?>)"><i class="fas fa-check"></i></button>
<button type="button" class="btn btn-sm btn-secondary" onclick="togglePortdata(<?=$preorder->id?>)"><i class="fas fa-times"></i></button>
</span>
<?php endif; ?>
</h3>
<table class="table table-sm table-striped" id="preorder-detail-<?=$preorder->id?>-patchposition">
<tr>
<th>Equipment Name:</th>
<td>
<span id="preorder-detail-<?=$preorder->id?>-patchposition-string"><?=$preorder->adb_wohneinheit->getPatchEqString()?></span>
<table class="row hidden" id="preorder-detail-<?=$preorder->id?>-patchposition-data-form">
<tr>
<th>Cluster:</th>
<td><input type="text" class="form-control" name="patch_cluster"
data-default="<?=($preorder->adb_wohneinheit->patch_cluster) ? $preorder->adb_wohneinheit->patch_cluster : $preorder->adb_hausnummer->netzgebiet->extref?>"
/></td>
</tr><tr>
<th>Shelf:</th>
<td><input type="text" class="form-control" name="patch_shelf"
data-default="<?=$preorder->adb_wohneinheit->patch_shelf?>"
/></td>
</tr><tr>
<th>Module:</th>
<td><input type="text" class="form-control" name="patch_module"
data-default="<?=$preorder->adb_wohneinheit->patch_module?>"
/></td>
</tr>
</table>
</td>
</tr>
<tr>
<th>Equipment Port:</th>
<td>
<span id="preorder-detail-<?=$preorder->id?>-patchposition-port"><?=$preorder->adb_wohneinheit->patch_port?></span>
<table class="row hidden" id="preorder-detail-<?=$preorder->id?>-patchposition-port-form">
<tr>
<th>Port:</th>
<td><input type="text" class="form-control" name="patch_port" data-default="<?=$preorder->adb_wohneinheit->patch_port?>" /></td>
</tr>
</table>
</td>
</tr>
</table>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<?php endif; ?>
<?php if($preorder->campaign->fulfillment == "citycom_oan"): ?>
<div id="preorder-detail-<?=$preorder->id?>-citycom-oan" class="tab-pane">
<div class="row justify-content-center">
<div class="col-12">
<div class="card">
<div class="card-body">
<div class="card-header bg-info text-white pl-2 pr-2 pt-1 pb-1">Citycom OAN</div>
<div class="row">
<div class="col-6">
<div class="row">
<div class="col">
<h3>Services</h3>
<table class="table table-sm table-striped">
<tr>
<th>stag</th>
<th>ctag</th>
<th>Typ</th>
<th>External ID</th>
<th>External State</th>
</tr>
<?php if(is_array($preorder->ctags) && count($preorder->ctags)): ?>
<?php foreach($preorder->ctags as $ctag): ?>
<tr>
<td class="text-monospace"><?=$ctag->stag?></td>
<td class="text-monospace"><?=$ctag->ctag?></td>
<td class="text-monospace"><?=$ctag->service_type?></td>
<td class="text-monospace"><?=htmlentities($ctag->ext_id)?></td>
<td class="text-monospace"><?=htmlentities($ctag->ext_status)?></td>
</tr>
<?php endforeach; ?>
<?php endif; ?>
</table>
</div>
</div>
<div class="row">
<div class="col-6">
<h3>ONT</h3>
<table class="table table-sm table-striped">
<tr>
<th class="text-right">S/N</th>
<td class="text-monospace"><?=($preorder->citycomoan) ? $preorder->citycomoan->ont_sn : ""?></td>
</tr><tr>
<th class="text-right">FSAN</th>
<td class="text-monospace"><?=($preorder->citycomoan) ? $preorder->citycomoan->ont_gpid : ""?></td>
</tr>
</table>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<?php endif; ?>
<div id="preorder-detail-<?=$preorder->id?>-flags" class="tab-pane">
<div class="row justify-content-center">
<div class="col-12">
<div class="card">
<div class="card-body">
<div class="card-header bg-info text-white pl-2 pr-2 pt-1 pb-1">Status</div>
<div class="row">
<div class="col-6">
<div class="row">
<div class="col">
<h3>Bestellstatus</h3>
<table class="table table-sm table-striped">
<tr>
<th>Status Code</th>
<td class="text-monospace"><?=$preorder->status->code?></td>
</tr><tr>
<th>Status Text</th>
<td class="text-monospace"><?=$preorder->status->name?></td>
</tr>
</table>
</div>
</div>
<div class="row">
<div class="col">
<h3>Borderpoint Status</h3>
<div class="row">
<div class="col-3 text-center">
<label>
<input type="radio" class="form-control" name="borderpoint_status_<?=$preorder->id?>" id="borderpoint_need_measurement" value="need_measurement" <?=($preorder->borderpoint_status == "need_measurement") ? "checked='checked'" : ""?> />
Messung erforderlich
</label>
</div>
<div class="col-3 text-center">
<label>
<input type="radio" class="form-control" name="borderpoint_status_<?=$preorder->id?>" id="borderpoint_informed" value="informed" <?=($preorder->borderpoint_status == "informed") ? "checked='checked'" : ""?> />
Beauskunftet
</label>
</div>
<div class="col-3 text-center">
<label>
<input type="radio" class="form-control" name="borderpoint_status_<?=$preorder->id?>" id="borderpoint_need_digging" value="need_digging" <?=($preorder->borderpoint_status == "need_digging") ? "checked='checked'" : ""?> />
Grabung ausständig
</label>
</div>
</div>
</div>
</div>
<div class="row mt-2" id="preorder-<?=$preorder->id?>-status-journal">
<div class="col">
<h3>Journal</h3>
<div class="input-group mb-3">
<div class="input-group-prepend">
<span class="input-group-text">Neuer Journaleintrag:</span>
</div>
<input type="text" class="form-control preorder-status-journal-input" id="preorder-<?=$preorder->id?>-status-journal-input" />
<div class="input-group-append">
<button type="button" class="btn btn-primary" onclick="submitStatusJournal(<?=$preorder->id?>)">Speichern</button>
</div>
</div>
<table class="table table-sm table-striped" id="preorder-<?=$preorder->id?>-status-journal-list">
<?php foreach(array_reverse($preorder->statusjournals) as $journal): ?>
<tr>
<td class="text-monospace"><small style="white-space: nowrap"><i class="fas fa-clock fa-fw"></i> <?=date("d.m.Y H:i", $journal->create)?></small> <span style="white-space: nowrap">(<?=htmlentities($journal->creator->name)?>)<span></span></td>
<td class="text-left"><?=htmlentities($journal->text)?></td>
</tr>
<?php endforeach; ?>
</table>
</div>
</div>
</div>
<div class="col-6">
<h3>Statusflags</h3>
<table class="table table-sm table-striped">
<?php foreach(PreorderStatusflagModel::getAll() as $flag): ?>
<tr>
<th class="text-right">
<input type="checkbox" class="form-control preorder-statusflag"
id="preorder-<?=$preorder->id?>-statusflag-<?=$flag->code?>"
data-preorder_id="<?=$preorder->id?>"
data-flag_id="<?=$flag->id?>"
data-flag_code="<?=$flag->code?>"
<?=(array_key_exists($flag->id, $preorder->statusflags) && $preorder->statusflags[$flag->id]->value && $preorder->statusflags[$flag->id]->value->value) ? "checked='checked'" : ""?>
/>
</th>
<td class="text-monospace align-middle" id="preorder-<?=$preorder->id?>-statusflag-<?=$flag->id?>-text"><?=$preorder->statusflags[$flag->id]->name?></td>
</tr>
<?php endforeach; ?>
</table>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<div id="preorder-detail-<?=$preorder->id?>-history" class="tab-pane">
<div class="row justify-content-center">
<div class="col-12">
<div class="card">
<div class="card-body">
<div class="card-header bg-info text-white pl-2 pr-2 pt-1 pb-1">History</div>
<div class="row">
<div class="col-12">
<h3>Status Historie</h3>
<table class="table table-sm table-striped">
<tr>
<th>Zeitpunkt</th>
<th>Benutzer</th>
<th>Alter Status</th>
<th>Neuer Status</th>
</tr>
<?php foreach($preorder->history as $history): ?>
<?php if($history->key != "status_id") continue; ?>
<tr>
<td class="text-monospace"><?=date("d.m.Y H:i:s", $history->changed)?></td>
<td><?=$history->creator->name?></td>
<td><?=$history->old->code?> - <?=$history->old->name?></td>
<td><?=$history->new->code?> - <?=$history->new->name?></td>
</tr>
<?php endforeach; ?>
</table>
<h3>Gesamte Historie</h3>
<table class="table table-sm table-striped">
<tr>
<th>Zeitpunkt</th>
<th>Benutzer</th>
<th>Feld</th>
<th>Alter Wert</th>
<th>Neuer Wert</th>
</tr>
<?php foreach($preorder->history as $history): ?>
<tr>
<td class="text-monospace"><?=date("d.m.Y H:i:s", $history->create)?></td>
<td><?=$history->creator->name?></td>
<td><?=$history->getKey()?></td>
<td><?=$history->getText("old")?></td>
<td><?=$history->getText("new")?></td>
</tr>
<?php endforeach; ?>
</table>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<div id="preorder-detail-<?=$preorder->id?>-emails" class="tab-pane preorder-emails-view">
<?php
$email_logs = EmailLog::search(["object_type" => "preorder", "object_id" => $preorder->id]);
$allPreorderEmails = PreordernotificationLogModel::search(["preorder_id" => $preorder->id]);
$allStatusFlagEmails = PreorderStatusnotificationLog::search(["preorder_id" => $preorder->id]);
?>
<div class="container-fluid">
<div class="row">
<div class="col-12">
<h5 class="mb-3">
<i class="fas fa-envelope mr-2 text-muted"></i>
E-Mail Benachrichtigungen
</h5>
<!-- Preorder Notification Emails -->
<?php if (!empty($allPreorderEmails)): ?>
<div class="card mb-3">
<div class="card-header bg-light border-bottom">
<h6 class="mb-0 text-secondary">
<i class="fas fa-bell mr-2"></i>
Vorbestellungs-Benachrichtigungen
<span class="badge badge-secondary ml-2"><?= count($allPreorderEmails) ?></span>
</h6>
</div>
<div class="card-body p-0">
<div class="table-responsive">
<table class="table table-sm table-hover mb-0">
<thead class="thead-light">
<tr>
<th class="border-0 py-2">
<i class="fas fa-envelope-open mr-1 text-muted"></i>
Betreff
</th>
<th class="border-0 py-2">
<i class="fas fa-at mr-1 text-muted"></i>
E-Mail
</th>
<th class="border-0 py-2">
<i class="fas fa-clock mr-1 text-muted"></i>
Gesendet
</th>
<th class="border-0 py-2">
<i class="fas fa-hashtag mr-1 text-muted"></i>
ID
</th>
</tr>
</thead>
<tbody>
<?php foreach ($allPreorderEmails as $emailLog): ?>
<?php
$notification = PreordernotificationModel::getOne($emailLog->data->preordernotification_id);
$sentDate = date('Y-m-d H:i:s', $emailLog->data->sent);
$sentDateFormatted = date('M j, Y \a\t g:i A', $emailLog->data->sent);
?>
<tr>
<td class="py-2">
<div class="font-weight-medium text-dark small">
<?= htmlspecialchars($notification->subject ?? 'Kein Betreff') ?>
</div>
</td>
<td class="py-2">
<span class="badge badge-light text-muted px-2 py-1">
<?= htmlspecialchars($emailLog->data->email) ?>
</span>
</td>
<td class="py-2">
<div class="text-muted small">
<?= $sentDateFormatted ?>
</div>
</td>
<td class="py-2">
<span class="badge badge-secondary">
#<?= $emailLog->data->preordernotification_id ?>
</span>
</td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
</div>
</div>
</div>
<?php endif; ?>
<!-- Status Notification Emails -->
<?php if (!empty($allStatusFlagEmails)): ?>
<div class="card mb-3">
<div class="card-header bg-light border-bottom">
<h6 class="mb-0 text-secondary">
<i class="fas fa-flag mr-2"></i>
Status-Benachrichtigungen
<span class="badge badge-secondary ml-2"><?= count($allStatusFlagEmails) ?></span>
</h6>
</div>
<div class="card-body p-0">
<div class="table-responsive">
<table class="table table-sm table-hover mb-0">
<thead class="thead-light">
<tr>
<th class="border-0 py-2">
<i class="fas fa-flag mr-1 text-muted"></i>
Status
</th>
<th class="border-0 py-2">
<i class="fas fa-at mr-1 text-muted"></i>
E-Mail
</th>
<th class="border-0 py-2">
<i class="fas fa-clock mr-1 text-muted"></i>
Erstellt
</th>
<th class="border-0 py-2">
<i class="fas fa-user mr-1 text-muted"></i>
Benutzer
</th>
</tr>
</thead>
<tbody>
<?php foreach ($allStatusFlagEmails as $statusLog): ?>
<?php
$createdDate = date('Y-m-d H:i:s', $statusLog->create);
$createdDateFormatted = date('M j, Y \a\t g:i A', $statusLog->create);
// Status code color mapping - muted colors
$statusBadgeClass = 'badge-light text-muted';
switch($statusLog->data->status_code) {
case '100': $statusBadgeClass = 'badge-light text-info'; break;
case '110': $statusBadgeClass = 'badge-light text-warning'; break;
case '120': $statusBadgeClass = 'badge-light text-secondary'; break;
case '130': $statusBadgeClass = 'badge-light text-success'; break;
case '140': $statusBadgeClass = 'badge-light text-danger'; break;
}
?>
<tr>
<td class="py-2">
<span class="badge <?= $statusBadgeClass ?> px-2 py-1">
<?= !empty($statusLog->data->status_code) ? $statusLog->data->status_code : $statusLog->data->email_type?>
</span>
</td>
<td class="py-2">
<span class="badge badge-light text-muted px-2 py-1">
<?= htmlspecialchars($statusLog->data->email) ?>
</span>
</td>
<td class="py-2">
<div class="text-muted small">
<?= $createdDateFormatted ?>
</div>
</td>
<td class="py-2">
<span class="badge badge-light text-muted">
#<?= $statusLog->data->create_by ?>
</span>
</td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
</div>
</div>
</div>
<?php endif; ?>
<?php if($email_logs): ?>
<h5>Alle ausgehenden Emails <small>(ab 25.08.2025)</small></h5>
<table class="table table-sm table-striped mb-3">
<tr>
<th>Von</th>
<th>An</th>
<th>Betreff</th>
<th>Anhänge</th>
<th>Gesendet</th>
<th></th>
</tr>
<?php foreach($email_logs as $email): ?>
<tr>
<td><?=$email->from?></td>
<td><?=$email->to?></td>
<td><?=htmlentities($email->subject)?></td>
<td><?=(is_array($email->attachments)) ? count($email->attachments) : 0?></td>
<td><?=date("d.m.Y H:i",$email->create)?></td>
<td><i class="fas fa-eye text-primary pointer" onclick="displayEmailLogEmail(<?=$preorder->id?>,<?=$email->id?>); return false;"></i></td>
</tr>
<?php endforeach; ?>
</table>
<?php endif; ?>
<!-- Empty State -->
<?php if (empty($email_logs) && empty($allPreorderEmails) && empty($allStatusFlagEmails)): ?>
<div class="card border-0">
<div class="card-body text-center py-4">
<div class="mb-3">
<i class="fas fa-envelope-open-text fa-3x text-muted"></i>
</div>
<h6 class="text-muted mb-2">Keine E-Mail-Benachrichtigungen</h6>
<p class="text-muted small mb-0">
Für diese Vorbestellung wurden noch keine E-Mail-Benachrichtigungen versendet.
</p>
</div>
</div>
<?php endif; ?>
</div>
</div>
</div>
<style>
.preorder-emails-view .badge-light {
background-color: #f8f9fa;
border: 1px solid #e9ecef;
}
.preorder-emails-view .table td {
vertical-align: middle;
border-top: 1px solid #e9ecef;
}
.preorder-emails-view .table tbody tr:hover {
background-color: #f8f9fa;
}
.preorder-emails-view .card {
border: 1px solid #e9ecef;
border-radius: 0.375rem;
}
.preorder-emails-view .card-header {
background-color: #f8f9fa;
border-bottom: 1px solid #e9ecef;
}
.preorder-emails-view .text-info { color: #17a2b8 !important; }
.preorder-emails-view .text-warning { color: #ffc107 !important; }
.preorder-emails-view .text-success { color: #28a745 !important; }
.preorder-emails-view .text-danger { color: #dc3545 !important; }
</style>
</div>
<div
id="preorder-detail-<?=$preorder->id?>-map"
class="tab-pane"
data-lat="<?=$preorder->adb_hausnummer->borderpoint_lat?>"
data-long="<?=$preorder->adb_hausnummer->borderpoint_long?>"
data-blat="<?=$preorder->adb_hausnummer->gps_lat?>"
data-blong="<?=$preorder->adb_hausnummer->gps_long?>"
data-trench="<?=$preorder->adb_hausnummer->trenches?>"
data-home-trench="<?=$preorder->adb_hausnummer->home_trench?>"
>
<div class="row justify-content-center">
<div class="col-12">
<div class="card">
<div class="card-body">
<div class="card">
<div class="card-body">
<div class="row" id="map-row">
<div id="preorder-map-<?=$preorder->id?>" style="height:50vh; width: 100%"></div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>