Added externel product billing email

This commit is contained in:
Frank Schubert
2021-11-09 22:15:53 +01:00
parent bdae10aec1
commit 3f5eb667ac
4 changed files with 184 additions and 4 deletions

View File

@@ -122,6 +122,42 @@ class Order extends mfBaseModel {
}
}
public function sendExtBillinfoEmail() {
// TODO template rendern auslagern nach Emailtempate klasse
$tpl = new Layout();
$tpl->setTemplate("Emailtemplates/order/billing_external_energie");
$tpl->set("order", $this);
$body = $tpl->render();
$values = $tpl->getReturnedValue();
$this->finish_date = null;
$this->save();
//var_dump($values); echo "<pre class='text-monospace'>".$body."</pre>"; exit;
$subject = $values['subject'];
$from = $values['from_email'];
$from_name = $values['from_email_name'];
$to = TT_EXTERNAL_BILLING_EMAIL_TO;
if(!$subject || !$from || !$from_name || !$to) {
$this->log->warn("Internl Billing Email not sent. (subject: '$subject', from: '$from', from_email: '$from_name', 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-Xinon-Oid", $this->id);
$email->send();
return true;
}
}
public function getProperty($name) {
if($this->$name == null) {

View File

@@ -494,6 +494,10 @@ class OrderController extends mfBaseController {
$order->save();
}
$ext_products = false;
$int_products = false;
//var_dump($r->products);exit;
// validate and add products
if(is_array($r->products) && count($r->products)) {
@@ -546,7 +550,11 @@ class OrderController extends mfBaseController {
}
// if product is not external and customer is new, create customer_number and service pin
if(!$prod->external ) {
if($prod->external) {
$ext_products = true;
} else {
$int_products = true;
if(!$owner->customer_number) {
$last_num = AddressModel::getLastCustomerNumber();
$this->log->debug("last_num: $last_num");
@@ -660,8 +668,21 @@ class OrderController extends mfBaseController {
// send order finish email
if($send_to_bill_email) {
if(!$order->sendIntBillinfoEmail()) {
$this->layout()->setFlash("Beim Senden der Billing Benachrichtigung ist ein Fehler aufgetreten.", "warning");
if($ext_products && !$int_products) {
if(!$order->sendExtBillinfoEmail()) {
$this->layout()->setFlash("Beim Senden der externen Billing Benachrichtigung ist ein Fehler aufgetreten.", "warning");
}
}
if($int_products) {
if(!$order->sendIntBillinfoEmail()) {
$this->layout()->setFlash("Beim Senden der Billing Benachrichtigung ist ein Fehler aufgetreten.", "warning");
}
}
if($int_products && $ext_products) {
$this->layout()->setFlash("Eigene und Fremdprodukte gefunden, nur interne Billing Benachrichtigung verschickt.", "warning");
}
}