From 1aa4bdd89e8314c423dae02867d291906f448979 Mon Sep 17 00:00:00 2001 From: Frank Schubert Date: Tue, 28 Feb 2023 16:43:17 +0100 Subject: [PATCH] Added internal billing NBE email for external products --- .../order/exernal_product_nbe_billing.php | 77 +++++++++++++++++++ .../Emailtemplates/order/int_billing_info.php | 6 +- Layout/default/Order/Form.php | 2 +- application/Order/Order.php | 32 ++++++++ application/Order/OrderController.php | 3 + application/Product/Product.php | 7 ++ application/Product/ProductController.php | 4 +- 7 files changed, 124 insertions(+), 7 deletions(-) create mode 100644 Layout/default/Emailtemplates/order/exernal_product_nbe_billing.php diff --git a/Layout/default/Emailtemplates/order/exernal_product_nbe_billing.php b/Layout/default/Emailtemplates/order/exernal_product_nbe_billing.php new file mode 100644 index 000000000..17dca7f5b --- /dev/null +++ b/Layout/default/Emailtemplates/order/exernal_product_nbe_billing.php @@ -0,0 +1,77 @@ +terminations[0]->id; + $op = OrderProductModel::getFirst(['order_id' => $order->id, 'termination_id' => $term_id]); + + if($order->finish_date) { + $billing_start = $order->finish_date; + } else { + $billing_start = date('U'); + } + + if($op->billing_delay) { + $billing_start = strtotime("+".$op->billing_delay." months"); + } + + $subject = ""; + if($order->upgrade) { + $subject .= "[UPGRADE] "; + } + /*$subject .= $order->terminations[0]->building->network->name." - " + ."Verr. ab ".date("m", $billing_start)."/".date("Y", $billing_start)." - " + .$order->owner->customer_number." - " + .str_replace("\n", "", str_replace("\r\n", " ", $order->owner->getCompanyOrName())); + */ + + $subject .= "[".str_replace(["\r","\n"], " ", $op->product->owner->getCompanyOrName())."] Produkt fertiggestellt - "; + + if(is_array($order->terminations) && count($order->terminations)) { + $subject .= $order->terminations[0]->building->network->name." - "; + } + + $subject .= ($order->owner->customer_number) ? $order->owner->customer_number." - " : "" + .str_replace("\n", "", str_replace("\r\n", " ", $order->owner->getCompanyOrName())); + + $this->setReturnValue([ + 'subject' => $subject, + + 'from_email' => "workspace.admin@xinon.at", + 'from_email_name' => "thetool" + ]); + + $nbe_total = 0; +?> +upgrade): ?> +Achtung: UPGRADE + +project: verrechnung +type: Verrechnung +status: Neu +priority: Standard +start date: + +due date: + +Kundennummer: product->owner->customer_number) ? $op->product->owner->customer_number : "null"?> + +Kundenname: product->owner->getCompanyOrName()))?> + +Telefon: product->owner->phone) ? $op->product->owner->phone : "null"?> + +Netzgebiet: terminations[0]->building->network->name?> + +Bauabschnitt: terminations[0]->building->networksection_id) ? $order->terminations[0]->building->networksection->name : "")?> + +Verrechungsstart: / + + +### Rechnungspositionen + +| Anzahl | Produktname | Verrechungsperiode | Preis periodisch | Preis Herstellung | NBE | +|--------|-------------|--------------------|-------------------|-------------------|-----| +products as $op): ?> +price_nbe > 0.0) $nbe_total += ($op->price_nbe / $op->billing_period); ?> +| amount?> | product->name?> | billing_period == 12) ? "Jährlich " : (($op->billing_period == 1) ? "Monatlich" : $op->billing_period."-monatlich")?> | EUR price?> | EUR price_setup?> | EUR price_nbe?> | + + + +**Monatliches NBE:** EUR diff --git a/Layout/default/Emailtemplates/order/int_billing_info.php b/Layout/default/Emailtemplates/order/int_billing_info.php index a60429316..5ca547e76 100644 --- a/Layout/default/Emailtemplates/order/int_billing_info.php +++ b/Layout/default/Emailtemplates/order/int_billing_info.php @@ -72,8 +72,7 @@ Verrechungsstart: / |--------|-------------|--------------------|-------------------|-------------------| products as $op): ?> price_nne > 0.0) $nne_products[] = $op; ?> -amount?> | product->name?> | billing_period == 12) ? "Jährlich " : (($op->billing_period == 1) ? "Monatlich" : $op->billing_period."-monatlich")?> | EUR price?> | EUR price_setup?> - +| amount?> | product->name?> | billing_period == 12) ? "Jährlich " : (($op->billing_period == 1) ? "Monatlich" : $op->billing_period."-monatlich")?> | EUR price?> | EUR price_setup?> | @@ -88,8 +87,7 @@ Netzeigentümer: terminations[0]->building->network->owner->getCompan | Anzahl | Produktname | Verrechungsperiode | Bauabschnitt | NNE | |--------|-------------|--------------------|--------------|-----| -amount?> | product->name?> | billing_period == 12) ? "Jährlich " : (($op->billing_period == 1) ? "Monatlich" : $op->billing_period."-monatlich")?> | termination->building->networksection_id) ? $op->termination->building->networksection->name : ""?> | EUR price_nne?> - +amount?> | product->name?> | billing_period == 12) ? "Jährlich " : (($op->billing_period == 1) ? "Monatlich" : $op->billing_period."-monatlich")?> | termination->building->networksection_id) ? $op->termination->building->networksection->name : ""?> | EUR price_nne?> | diff --git a/Layout/default/Order/Form.php b/Layout/default/Order/Form.php index 268fc6d90..5f27db75d 100644 --- a/Layout/default/Order/Form.php +++ b/Layout/default/Order/Form.php @@ -746,7 +746,7 @@
- +
diff --git a/application/Order/Order.php b/application/Order/Order.php index b493ab021..97f2ebad0 100644 --- a/application/Order/Order.php +++ b/application/Order/Order.php @@ -227,6 +227,38 @@ class Order extends mfBaseModel { } } + public function sendExtBillNbeInfoEmail() { + // TODO template rendern auslagern nach Emailtempate klasse + $tpl = new Layout(); + $tpl->setTemplate("Emailtemplates/order/exernal_product_nbe_billing"); + $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("Billing NBE 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-".MFAPPNAME."-oid", $this->id); + $email->send(); + + return true; + } + } + public function sendFileuploadEmail(OrderFile $file) { $filetype = $file->name; diff --git a/application/Order/OrderController.php b/application/Order/OrderController.php index b3663ae9d..14e8fa175 100644 --- a/application/Order/OrderController.php +++ b/application/Order/OrderController.php @@ -1020,6 +1020,9 @@ class OrderController extends mfBaseController { if(!$order->sendExtBillinfoEmail(new Address($ext_product_owner_id))) { $this->layout()->setFlash("Beim Senden der externen Billing Benachrichtigung ist ein Fehler aufgetreten.", "warning"); } + if(!$order->sendExtBillNbeInfoEmail(new Address($ext_product_owner_id))) { + $this->layout()->setFlash("Beim Senden der internen Billing NBE Benachrichtigung ist ein Fehler aufgetreten.", "warning"); + } } if($int_products) { diff --git a/application/Product/Product.php b/application/Product/Product.php index 4a87e12b5..7d4d0e423 100644 --- a/application/Product/Product.php +++ b/application/Product/Product.php @@ -1,6 +1,7 @@ $name == null) { + if($name == "owner") { + if(!$this->external_id) return null; + $this->owner = new Address($this->external_id); + return $this->owner; + } + if($name == "networks") { $this->networks = []; $productNetworks = ProductNetworkModel::search(['product_id' => $this->id]); diff --git a/application/Product/ProductController.php b/application/Product/ProductController.php index fe3f4dbc4..5f8d385ea 100644 --- a/application/Product/ProductController.php +++ b/application/Product/ProductController.php @@ -32,7 +32,7 @@ class ProductController extends mfBaseController { $filter = $_SESSION[MFAPPNAME.'-Product-filter']; } } - //var_dump($filter); + $this->layout->set("filter", $filter); $filter = $this->getPreparedFilter($filter); @@ -46,7 +46,7 @@ class ProductController extends mfBaseController { if(is_numeric($this->request->s)) { $pagination['start'] = intval($this->request->s); } - //var_dump($filter);exit; + $pagination['maxItems'] = ProductModel::count($filter); $this->layout()->set("pagination", $pagination);