From 3f5eb667ac277d4be3cc85c0771a74cf0def5fd4 Mon Sep 17 00:00:00 2001 From: Frank Schubert Date: Tue, 9 Nov 2021 22:15:53 +0100 Subject: [PATCH] Added externel product billing email --- .../order/billing_external_energie.php | 123 ++++++++++++++++++ .../Emailtemplates/order/int_billing_info.php | 2 +- application/Order/Order.php | 36 +++++ application/Order/OrderController.php | 27 +++- 4 files changed, 184 insertions(+), 4 deletions(-) create mode 100644 Layout/default/Emailtemplates/order/billing_external_energie.php diff --git a/Layout/default/Emailtemplates/order/billing_external_energie.php b/Layout/default/Emailtemplates/order/billing_external_energie.php new file mode 100644 index 000000000..3d7116e68 --- /dev/null +++ b/Layout/default/Emailtemplates/order/billing_external_energie.php @@ -0,0 +1,123 @@ +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->partner_number." - " + ."hergestellt am ".date("d.m.Y", $order->finish_date) . " - " + ."Verrechnung ab ".date("m", $billing_start)."/".date("Y", $billing_start)." - " + .str_replace("\n", " ", str_replace("\r", "", $order->owner->getCompanyOrName())), + + '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,12))?> | EUR price_setup?> + +----------------------------------------------------------------------------------------------------------------------- + + +terminations) && count($order->terminations)): ?> +Anschluss +========== +terminations as $term): ?> +getAddress()?> + + + + + +Bestelldetails +=============== +Bestelldatum: order_date)?> + +Bestellung abgeschlossen: finish_date)?> + +Einwilligung Datenschutz: allow_contact)? "Ja" : "Nein"?> + + + +Vertragsinhaber +================ +Firma: owner->company?> + +Vorname: owner->firstname?> + +Nachname: owner->lastname?> + +Straße: owner->street?> + +PLZ: owner->zip?> + +Ort: owner->city?> + +Land: owner->country?> + +Telefon: owner->phone?> + +Fax: owner->fax?> + +Mobiltelefon: owner->mobile?> + +Email: owner->email?> + +billingaddress_id > 0 && $order->billingaddress_id != $order->owner_id): ?> + + +Rechnungsempfänger +=================== +Firma: billingaddress->company?> + +Vorname: billingaddress->firstname?> + +Nachname: billingaddress->lastname?> + +Straße: billingaddress->street?> + +PLZ: billingaddress->zip?> + +Ort: billingaddress->city?> + +Land: billingaddress->country?> + +Telefon: billingaddress->phone?> + +Fax: billingaddress->fax?> + +Mobiltelefon: billingaddress->mobile?> + +Email: billingaddress->email?> + + + + +Verrechnung +============ +billing_type == "invoice"): ?> +Verrechnungsart: Rechnung + +Verrechnungsart: SEPA Bankeinzug +Bank: bank_account_bank?> + +Kontoinhaber: bank_account_owner?> + +IBAN: bank_account_iban?> + +BIC: bank_account_bic?> + + diff --git a/Layout/default/Emailtemplates/order/int_billing_info.php b/Layout/default/Emailtemplates/order/int_billing_info.php index dc8973e73..5b4de4b45 100644 --- a/Layout/default/Emailtemplates/order/int_billing_info.php +++ b/Layout/default/Emailtemplates/order/int_billing_info.php @@ -24,7 +24,7 @@ Rechnungspositionen ==================== -Anzahl | Produktname | Verrechungsperiode | Preis periodisch | Preis Herstellung +Anzahl | Produktname | Verrechungsperiode | Preis periodisch | Preis Herstellung ----------------------------------------------------------------------------------------------------------------------- products as $op): ?> product->price_nne > 0.0) $nne_products[] = $op; ?> diff --git a/application/Order/Order.php b/application/Order/Order.php index 97bcda315..c937d5650 100644 --- a/application/Order/Order.php +++ b/application/Order/Order.php @@ -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 "
".$body."
"; 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) { diff --git a/application/Order/OrderController.php b/application/Order/OrderController.php index d09250ad7..c2d96d618 100644 --- a/application/Order/OrderController.php +++ b/application/Order/OrderController.php @@ -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"); } }