Added Emaillog to PreorderBillingInvoice

This commit is contained in:
Frank Schubert
2025-09-17 12:45:42 +02:00
parent 3506bc51fb
commit 5190ce031b
4 changed files with 223 additions and 4 deletions

View File

@@ -203,7 +203,17 @@ $pagination_entity_name = "Rechnungen";
<td>€ <?=number_format($invoice->total, 2, ",", ".")?></td>
<td>€ <?=number_format($invoice->total_gross - $invoice->total, 2, ",", ".")?></td>
<td>€ <?=number_format($invoice->total_gross, 2, ",", ".")?></td>
<td class="text-monospace text-success"><?=($invoice->date_delivered) ? "<i class='far fa-envelope-circle-check'></i> ".date("d.m.Y H:i", $invoice->date_delivered) : ""?></td>
<td class="text-monospace text-success">
<?php if($invoice->date_delivered): ?>
<?php if($invoice->emailLog): ?>
<a href="#" onclick="displayEmailLogEmail(<?=$invoice->id?>, <?=$invoice->emailLog->id?>); return false;"><i class='far fa-envelope-circle-check'></i></a>
<?php else: ?>
<i class='far fa-envelope-circle-check'></i>
<?php endif ?>
<?=date("d.m.Y H:i", $invoice->date_delivered)?>
<?php endif; ?>
</td>
<td>
<?=$invoice->creator->name?><br />
<?=date("d.m.Y H:i", $invoice->create)?>
@@ -231,6 +241,60 @@ $pagination_entity_name = "Rechnungen";
</div>
<div class="modal" tabindex="-1" id="email-log-modal" style="max-height: 100vh;">
<div class="modal-dialog modal-dialog-centered modal-xl">
<div class="modal-content" style="overflow: auto;">
<div class="modal-header">
<h5 class="modal-title">Emailansicht</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">&times;</span>
</button>
</div>
<div class="modal-body">
<div class="row">
<div class="col">
<table class="table">
<tr>
<th>Von:</th>
<td id="email-log-from-value" class="text-monospace"></td>
</tr><tr>
<th>An:</th>
<td id="email-log-to-value" class="text-monospace"></td>
</tr><tr>
<th>Gesendet:</th>
<td id="email-log-sent-value" class="text-monospace"></td>
</tr><tr>
<th>Betreff:</th>
<td id="email-log-subject-value" class="text-monospace"></td>
</tr>
</table>
</div>
</div>
<div class="row mb-3" id="email-log-header-section">
<div class="col">
<a href="#" onclick="displayEmailLogHeaders(); return false;"><i class="fas fa-chevron-right fa-fw"></i> Alle Header anzeigen</a>
<div id="email-log-header-view" class="mt-2 text-monospace hidden" style="min-height: 48px; width:100%; border: 1px solid #ccc; padding: 8px; font-family: sans-serif;"></div>
</div>
</div>
<div class="row mb-2" id="email-log-body-section">
<div class="col">
<iframe id="email-log-body-view" style="height: 50vh; width:100%; border: 1px solid #000; padding: 8px; font-family: sans-serif; overflow-y: auto;"></iframe>
</div>
</div>
<div class="row mb-3 hidden" id="email-log-attachments-section">
<div class="col-6">
<h5>Dateianhänge</h5>
<ul id="email-log-attachment-list" class="list-group"></ul>
</div>
</div>
</div>
</div>
</div>
</div>
<div class="modal fade" id="sendCopyModal" tabindex="-1" aria-labelledby="sendCopyModalLabel" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
@@ -351,5 +415,91 @@ $pagination_entity_name = "Rechnungen";
status_update = setTimeout(updateStatus, 1000);
<?php endif; ?>
});
async function displayEmailLogEmail(invoice_id, email_id) {
$("#email-log-from-value").text("");
$("#email-log-to-value").text("");
$("#email-log-log-sent-value").text("");
$("#email-log-subject-value").text("");
document.getElementById("email-log-body-view").contentWindow.document.open();
document.getElementById("email-log-body-view").contentWindow.document.write("<html><body>&nbsp;</body></html>");
document.getElementById("email-log-body-view").contentWindow.document.close();
$("#email-log-attachments-section").hide();
$("#email-log-attachment-list").empty();
hideEmailLogHeaders();
if(!email_id) return false;
var resp = await fetch("<?=self::getUrl("PreorderBillingInvoice", "api", ["do" => "getLoggedEmail"])?>&oid=" + invoice_id + "&eid=" + email_id);
console.log(resp);
if(!resp.ok) {
notify("error", "Email konnte nicht geladen werden");
return false;
}
var response = await resp.json();
if(!("result" in response) || typeof response.result !== "object") {
notify("error", "Email konnte nicht geladen werden");
return false;
}
var email = response.result;
$("#email-log-from-value").text(email.from);
$("#email-log-to-value").text(email.to);
$("#email-log-sent-value").text(email.sent);
$("#email-log-subject-value").text(email.subject);
if("headers" in email && typeof email.headers === "object" && Object.keys(email.headers).length > 0) {
for (const [key, value] of Object.entries(email.headers)) {
$("#email-log-header-view").append(
"<strong>" + key + "</strong>: "
+ value.replace(/&/g, '&amp;').replace(/"/g, '&quot;').replace(/'/g, '&#39;').replace(/</g, '&lt;').replace(/>/g, '&gt;')
+ "<br/>");
if(key == "From") {
$("#email-log-from-value").text(value);
}
}
}
if("attachments" in email && typeof email.attachments === "object" && Object.keys(email.attachments).length > 0) {
email.attachments.forEach( (item, index) => {
$("#email-log-attachment-list").append('<li class="list-group-item flex-fill p-1" style="border-radius: 0;"><a href="<?=self::getUrl("EmailLog", "downloadContent")?>?aid=' + item.id + '&hash=' + item.hash + '"><span class="filename text-monospace"><i class="far fa-file"></i> ' + item.filename + '</span></a> (' + Math.round((item.filesize/1024/1024)*100)/100 + ' MB)</li>');
});
$("#email-log-attachments-section").show();
}
document.getElementById("email-log-body-view").contentWindow.document.open();
if(email.bodyIsHtml) {
document.getElementById("email-log-body-view").contentWindow.document.write(email.body);
} else {
var html_body = '<html lang="de"><head><meta charset="utf-8" /></head><body><p>';
html_body += email.body.replaceAll("\r", "").replaceAll("\n", "<br />");
html_body += '</p></body></html>';
document.getElementById("email-log-body-view").contentWindow.document.write(html_body);
}
document.getElementById("email-log-body-view").contentWindow.document.close();
$("#email-log-modal").modal("show");
}
function displayEmailLogHeaders() {
$("#email-log-header-view").toggleClass("hidden");
if($("#email-log-header-view").hasClass("hidden")) {
$("#email-log-header-section").find("i").addClass("fa-chevron-right").removeClass("fa-chevron-down");
} else {
$("#email-log-header-section").find("i").addClass("fa-chevron-down").removeClass("fa-chevron-right");
}
}
function hideEmailLogHeaders() {
$("#email-log-header-view").empty();
if(!$("#email-log-header-view").hasClass("hidden")) {
$("#email-log-header-view").addClass("hidden");
$("#email-log-header-section").find("i").addClass("fa-chevron-down").removeClass("fa-chevron-right");
}
}
</script>
<?php include(realpath(dirname(__FILE__) . "/../../$mfLayoutPackage") . "/footer.php"); ?>

View File

@@ -172,7 +172,9 @@ $pagination_entity_name = "Emails";
$("#email-log-to-value").text("");
$("#email-log-log-sent-value").text("");
$("#email-log-subject-value").text("");
$("#email-log-view").empty();
document.getElementById("email-log-body-view").contentWindow.document.open();
document.getElementById("email-log-body-view").contentWindow.document.write("<html><body>&nbsp;</body></html>");
document.getElementById("email-log-body-view").contentWindow.document.close();
$("#email-log-attachments-section").hide();
$("#email-log-attachment-list").empty();
hideHeaders();
@@ -218,11 +220,16 @@ $pagination_entity_name = "Emails";
$("#email-log-attachments-section").show();
}
document.getElementById("email-log-body-view").contentWindow.document.open();
if(email.bodyIsHtml) {
$("#email-log-body-view").html(email.body);
document.getElementById("email-log-body-view").contentWindow.document.write(email.body);
} else {
$("#email-logbody-view").text(email.body);
var html_body = '<html lang="de"><head><meta charset="utf-8" /></head><body><p>';
html_body += email.body.replaceAll("\r", "").replaceAll("\n", "<br />");
html_body += '</p></body></html>';
document.getElementById("email-log-body-view").contentWindow.document.write(html_body);
}
document.getElementById("email-log-body-view").contentWindow.document.close();
$("#email-log-modal").modal("show");