From 768b39f67ec84b9b9a413489476ded0e2c748550 Mon Sep 17 00:00:00 2001 From: Frank Schubert Date: Fri, 8 Oct 2021 15:24:03 +0200 Subject: [PATCH] Added internal billing info email when order is finished --- .../Emailtemplates/order/int_billing_info.php | 50 +++++++++++++++++++ application/Building/Building.php | 1 + application/Order/Order.php | 37 ++++++++++++-- application/Order/OrderController.php | 26 +++++++--- .../OrderProduct/OrderProductModel.php | 2 +- 5 files changed, 105 insertions(+), 11 deletions(-) create mode 100644 Layout/default/Emailtemplates/order/int_billing_info.php diff --git a/Layout/default/Emailtemplates/order/int_billing_info.php b/Layout/default/Emailtemplates/order/int_billing_info.php new file mode 100644 index 000000000..973717b12 --- /dev/null +++ b/Layout/default/Emailtemplates/order/int_billing_info.php @@ -0,0 +1,50 @@ +terminations[0]->id; + $op = OrderProductModel::getFirst(['order_id' => $order->id, 'termination_id' => $term_id]); + + $billing_start = date('U'); + if($op->billing_delay) { + $billing_start = strtotime("+".$op->billing_delay." months"); + } + //var_dump($order->terminations[0]->building);exit; + $this->setReturnValue([ + 'subject' => $order->terminations[0]->building->network->name." - " + .(($order->terminations[0]->building->networksection_id) ? $order->terminations[0]->building->networksection->name : "")." - " + .$order->owner->customer_number." - " + .str_replace("\n", "", str_replace("\r\n", " ", $order->owner->getCompanyOrName()))." - " + ."Verrechnung ab ".date("m", $billing_start)."/".date("Y", $billing_start), + 'from_email' => TT_OUTGOING_EMAIL, + 'from_email_name' => TT_OUTGOING_EMAIL_NAME + ]); + + $nne_products = []; +?> + +Rechnungspositionen +==================== + +Anzahl | Produktname | Verrechungsperiode | Preis periodisch | Preis Herstellung +----------------------------------------------------------------------------------------------------------------------- +products as $op): ?> +product->price_nne > 0.0) $nne_products[] = $op; ?> +amount,0,12))?> | product->name,0,42))))?> | billing_period == 12) ? "Jährlich " : (($op->billing_period == 1) ? "Monatlich" : $op->billing_period."-monatlich")) ))?> | price,0,14))?> | € price_setup?> + +----------------------------------------------------------------------------------------------------------------------- + + + + +Gutschriften +============= + +Anzahl | Produktname | Verrechungsperiode | Bauabschnitt | NNE +----------------------------------------------------------------------------------------------------------------------- + +amount,0,12))?> | product->name,0,42))))?> | billing_period == 12) ? "Jährlich " : (($op->billing_period == 1) ? "Monatlich" : $op->billing_period."-monatlich")) ))?> | termination->building->networksection_id) ? $op->termination->building->networksection->name : "",0,24))?> | € product->price_nne?> + +----------------------------------------------------------------------------------------------------------------------- + + + + + diff --git a/application/Building/Building.php b/application/Building/Building.php index b94837d5e..0b92464e9 100644 --- a/application/Building/Building.php +++ b/application/Building/Building.php @@ -4,6 +4,7 @@ class Building extends mfBaseModel { protected $forcestr = ['street','zip','phone','email','note']; private $network; + private $networksection; private $pop; private $type; private $status; diff --git a/application/Order/Order.php b/application/Order/Order.php index 3fbc86339..f75ff3f9b 100644 --- a/application/Order/Order.php +++ b/application/Order/Order.php @@ -46,10 +46,6 @@ class Order extends mfBaseModel { return $terminations; } - public function createIvtCustomer($data) { - - } - public function deletePositions() { if(!is_array($this->getProperty("products")) || !count($this->getProperty("products"))) { return true; @@ -71,6 +67,39 @@ class Order extends mfBaseModel { } } + public function sendIntBillinfoEmail() { + // TODO template rendern auslagern nach Emailtempate klasse + $tpl = new Layout(); + $tpl->setTemplate("Emailtemplates/order/int_billing_info"); + $tpl->set("order", $this); + $body = $tpl->render(); + + $values = $tpl->getReturnedValue(); + + //var_dump($values); echo "
".$body."
"; exit; + + $subject = $values['subject']; + $from = $values['from_email']; + $from_name = $values['from_email_name']; + $to = TT_INTERNAL_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) { diff --git a/application/Order/OrderController.php b/application/Order/OrderController.php index 239ff85ba..c43d8bcc3 100644 --- a/application/Order/OrderController.php +++ b/application/Order/OrderController.php @@ -385,6 +385,8 @@ class OrderController extends mfBaseController { $order_data['finish_after_comment'] = $r->finish_after_comment; } + + $send_to_bill_email = false; $order_data['edit_by'] = $this->me->id; //var_dump($r); if($r->order_finished == "1" && $this->me->is("Admin", "netoperator")) { @@ -393,6 +395,12 @@ class OrderController extends mfBaseController { } else { $order_data['finish_date'] = date("U"); } + + if(!$order->finish_date) { + // first same finishing order + $send_to_bill_email = true; + } + } //var_dump($order_data);exit; if($mode == "add") { @@ -600,8 +608,14 @@ class OrderController extends mfBaseController { $this->layout()->setFlash("Dateiupload fehlgeschlagen", "warn"); } } - - + } + + + // 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"); + } } $this->layout()->setFlash("Bestellung erfolgreich gespeichert.", "success"); @@ -720,7 +734,7 @@ class OrderController extends mfBaseController { if(!$subject || !$from || !$from_name || !$to) { $this->log->warn("Service PIN Email not sent. (subject: '$subject', from: '$from', from_email: '$from_name', to: '$to')"); - $this->layout()->setFlash("Beim Email versenden ist ein Fehler aufgetragen.", "error"); + $this->layout()->setFlash("Beim Email versenden ist ein Fehler aufgetreten.", "error"); $this->redirect("Order"); } else { $email = new Emailnotification(); @@ -728,12 +742,12 @@ class OrderController extends mfBaseController { $email->setBody($body); $email->setFrom($from, $from_name); $email->setTo($to); - $email->setHeader("X-xinon-oid", $order->id); - $email->setHeader("X-xinon-pid", $product->id); + $email->setHeader("X-Xinon-Oid", $order->id); + $email->setHeader("X-Xinon-Pid", $product->id); $email->addAttachment($pdfpath, null, $pdfname, "application/pdf"); $email->send(); - $this->layout()->setFlash("Service PIN wurde erfolgreich verschickt..", "success"); + $this->layout()->setFlash("Service PIN wurde erfolgreich versendet.", "success"); $this->redirect("Order"); } } diff --git a/application/OrderProduct/OrderProductModel.php b/application/OrderProduct/OrderProductModel.php index 76a0751d0..d8c820b1a 100644 --- a/application/OrderProduct/OrderProductModel.php +++ b/application/OrderProduct/OrderProductModel.php @@ -75,7 +75,7 @@ class OrderProductModel { } - public static function getFirst() { + public static function getFirst($filter = false) { $db = FronkDB::singleton(); $where = self::getSqlFilter($filter);