Added internal billing info email when order is finished
This commit is contained in:
50
Layout/default/Emailtemplates/order/int_billing_info.php
Normal file
50
Layout/default/Emailtemplates/order/int_billing_info.php
Normal file
@@ -0,0 +1,50 @@
|
||||
<?php
|
||||
$term_id = $order->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 : "<kein Bauabschnitt>")." - "
|
||||
.$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
|
||||
-----------------------------------------------------------------------------------------------------------------------
|
||||
<?php foreach($order->products as $op): ?>
|
||||
<?php if($op->product->price_nne > 0.0) $nne_products[] = $op; ?>
|
||||
<?=sprintf("%-12s", substr($op->amount,0,12))?> | <?=utf8_encode(sprintf("%-42s", utf8_decode(substr($op->product->name,0,42))))?> | <?=utf8_encode(sprintf("%-18s", utf8_decode(($op->billing_period == 12) ? "Jährlich " : (($op->billing_period == 1) ? "Monatlich" : $op->billing_period."-monatlich")) ))?> | <?=sprintf("€ %-14s", substr($op->price,0,14))?> | € <?=$op->price_setup?>
|
||||
|
||||
-----------------------------------------------------------------------------------------------------------------------
|
||||
<?php endforeach; ?>
|
||||
|
||||
<?php if(count($nne_products)): ?>
|
||||
|
||||
Gutschriften
|
||||
=============
|
||||
|
||||
Anzahl | Produktname | Verrechungsperiode | Bauabschnitt | NNE
|
||||
-----------------------------------------------------------------------------------------------------------------------
|
||||
<?php foreach($nne_products as $op): ?>
|
||||
<?=sprintf("%-12s", substr($op->amount,0,12))?> | <?=utf8_encode(sprintf("%-42s", utf8_decode(substr($op->product->name,0,42))))?> | <?=utf8_encode(sprintf("%-18s", utf8_decode(($op->billing_period == 12) ? "Jährlich " : (($op->billing_period == 1) ? "Monatlich" : $op->billing_period."-monatlich")) ))?> | <?=sprintf("%-24s", substr(($op->termination->building->networksection_id) ? $op->termination->building->networksection->name : "<Kein Bauabschnitt>",0,24))?> | € <?=$op->product->price_nne?>
|
||||
|
||||
-----------------------------------------------------------------------------------------------------------------------
|
||||
<?php endforeach; ?>
|
||||
|
||||
<?php endif; // (count($nne_products))?>
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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 "<pre class='text-monospace'>".$body."</pre>"; 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) {
|
||||
|
||||
|
||||
@@ -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");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -75,7 +75,7 @@ class OrderProductModel {
|
||||
|
||||
}
|
||||
|
||||
public static function getFirst() {
|
||||
public static function getFirst($filter = false) {
|
||||
$db = FronkDB::singleton();
|
||||
|
||||
$where = self::getSqlFilter($filter);
|
||||
|
||||
Reference in New Issue
Block a user