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

@@ -10,6 +10,7 @@ class PreorderBillingInvoice extends mfBaseModel {
private $pdf;
private $csv;
private $emailLog;
private $creator;
private $editor;
@@ -278,6 +279,14 @@ RML Infrastruktur GmbH";
return $this->csv;
}
if($name == "emailLog") {
$emaillog = EmailLog::getFirst(["object_type" => "PreorderBillingInvoice", "object_id" => $this->id]);
if($emaillog) {
$this->emailLog = $emaillog;
}
return $this->emailLog;
}
if($name == "creator") {
$creator = mfValuecache::singleton()->get("Worker-id-".$this->create_by);
if($creator) {

View File

@@ -998,6 +998,9 @@ class PreorderBillingInvoiceController extends mfBaseController {
case "getActiveJobs":
$return = $this->getActiveJobsApi();
break;
case "getLoggedEmail":
$return = $this->getLoggedEmail();
break;
default:
$return = false;
}
@@ -1011,6 +1014,56 @@ class PreorderBillingInvoiceController extends mfBaseController {
$this->returnJson($data);
}
protected function getLoggedEmail() {
$invoice_id = $this->request->oid;
$emaillog_id = $this->request->eid;
if(!is_numeric($invoice_id) || $invoice_id < 1) {
return false;
}
if(!is_numeric($emaillog_id) || $emaillog_id < 1) {
return false;
}
$invoice = new PreorderBillingInvoice($invoice_id);
if(!$invoice->id) {
return false;
}
$emaillog = new EmailLog($emaillog_id);
if(!$emaillog->id) {
return false;
}
$return = [
"invoice_id" => $invoice_id,
"emaillog_id" => $emaillog_id,
"from" => $emaillog->from,
"to" => $emaillog->to,
"subject" => $emaillog->subject,
"body" => ($emaillog->body_html) ? $emaillog->body_html : $emaillog->body_text,
"bodyIsHtml" => (bool) $emaillog->body_html,
"sent" => date("d.m.Y H:i", $emaillog->create),
"headers" => json_decode($emaillog->headers),
"attachments" => [],
];
if(is_array($emaillog->attachments) && count($emaillog->attachments)) {
foreach($emaillog->attachments as $attachment) {
$return["attachments"][] = [
"id" => $attachment->id,
"hash" => $attachment->content->sha256,
"filename" => $attachment->filename,
"filesize" => ($attachment->content) ? $attachment->content->filesize : 0,
"mimetype" => ($attachment->content) ? $attachment->content->mimetype : "",
];
}
}
return $return;
}
private function getActiveJobsApi() {
$now = new DateTime("now");
$jobs = [];