Started Invoice Email Delivery

This commit is contained in:
Frank Schubert
2024-07-10 15:15:32 +02:00
parent 37c361282e
commit f683803913
7 changed files with 193 additions and 93 deletions
+61
View File
@@ -99,6 +99,67 @@ XINON GmbH";
return (new QRCode)->render($epc);
}
public function sendByEmail($to_email = false) {
if(!$this->id) return false;
$pdf = $this->getProperty("pdf");
if(!$pdf || !$pdf->name) {
return false;
}
$pdf_filename = $pdf->getFullPath();
if(!$pdf_filename || !file_exists($pdf_filename)) {
return false;
}
$tpl = new Layout();
$tpl->setTemplate("Emailtemplates/invoice/invoice-email");
$pdf_vars = [
"invoice" => $this
];
foreach($pdf_vars as $name => $val) {
$tpl->set($name, $val);
}
$body = $tpl->render();
$values = $tpl->getReturnedValue();
$subject = $values['subject'];
$from = $values['from_email'];
$from_name = $values['from_email_name'];
if($to_email) {
$to = $to_email;
} else {
$to = trim($this->email);
}
if(!$to) {
$this->log->error(__METHOD__.": Invoice ".$this->invoice_number." missing email");
}
if(!$subject || !$from || !$from_name || !$to) {
$this->log->warn("Invoice ".$this->invoice_number." could not be sent. Values missing. (subject: '$subject', from: '$from_name', from_email: '$from', to: '$to')");
return false;
} else {
$email = new Emailnotification();
$email->setSubject($subject);
$email->setBody($body);
$email->setFrom($from, $from_name);
$email->setTo($to);
$email->setHeader("X-".MFAPPNAME."-Iid", $this->id);
$email->addAttachment($pdf_filename, null, $pdf->name, "application/pdf");
$email->send();
$this->log->info(__METHOD__.": Sending Invoice ".$this->invoice_number." to $to");
}
return true;
}
public function getProperty($name) {
if($this->$name == null) {