<?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->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' => "XINON Partnerservice"
  ]);
  
?>

Rechnungspositionen
====================

Anzahl       | Produktname                                | Verrechungsperiode | Preis periodisch | Preis Herstellung
-----------------------------------------------------------------------------------------------------------------------
<?php foreach($order->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("EUR %-12s", substr($op->price,0,12))?> | EUR <?=$op->price_setup?>

-----------------------------------------------------------------------------------------------------------------------
<?php endforeach; ?>

<?php if(is_array($order->terminations) && count($order->terminations)): ?>
Anschluss
==========
<?php foreach($order->terminations as $term): ?>
<?=$term->getAddress()?>

<?php endforeach; ?>
<?php endif; ?>


Bestelldetails
===============
Bestelldatum: <?=date("d.m.Y", $order->order_date)?>

Bestellung abgeschlossen: <?=date("d.m.Y", $order->finish_date)?>

Einwilligung Datenschutz: <?=($order->allow_contact)? "Ja" : "Nein"?>



Vertragsinhaber
================
Firma: <?=$order->owner->company?>

Vorname: <?=$order->owner->firstname?>

Nachname: <?=$order->owner->lastname?>

Straße: <?=$order->owner->street?>

PLZ: <?=$order->owner->zip?>

Ort: <?=$order->owner->city?>

Land: <?=$order->owner->country?>

Telefon: <?=$order->owner->phone?>

Fax: <?=$order->owner->fax?>

Mobiltelefon: <?=$order->owner->mobile?>

Email: <?=$order->owner->email?>

<?php if($order->billingaddress_id > 0 && $order->billingaddress_id != $order->owner_id): ?>


Rechnungsempfänger
===================
Firma: <?=$order->billingaddress->company?>

Vorname: <?=$order->billingaddress->firstname?>

Nachname: <?=$order->billingaddress->lastname?>

Straße: <?=$order->billingaddress->street?>

PLZ: <?=$order->billingaddress->zip?>

Ort: <?=$order->billingaddress->city?>

Land: <?=$order->billingaddress->country?>

Telefon: <?=$order->billingaddress->phone?>

Fax: <?=$order->billingaddress->fax?>

Mobiltelefon: <?=$order->billingaddress->mobile?>

Email: <?=$order->billingaddress->email?>

<?php endif; ?>


Verrechnung
============
<?php if($order->billing_type == "invoice"): ?>
Verrechnungsart: Rechnung
<?php else: ?>
Verrechnungsart: SEPA Bankeinzug
Bank: <?=$order->bank_account_bank?>

Kontoinhaber: <?=$order->bank_account_owner?>

IBAN: <?=$order->bank_account_iban?>

BIC: <?=$order->bank_account_bic?>

<?php endif; ?>
