Added emailtemplate for Cancel notification
This commit is contained in:
@@ -30,6 +30,7 @@ class Contract extends mfBaseModel {
|
||||
private $relocationTo;
|
||||
private $vatgroup;
|
||||
private $vatrate;
|
||||
private $voicenumbers;
|
||||
private $finisher;
|
||||
private $canceler;
|
||||
private $creator;
|
||||
@@ -203,6 +204,12 @@ class Contract extends mfBaseModel {
|
||||
|
||||
}
|
||||
|
||||
public function getVoicenumbers() {
|
||||
$voicenumber = $this->getConfigValue("voicenumberblock_voicenumber");
|
||||
$numbers = json_decode($voicenumber->json);
|
||||
return $numbers;
|
||||
}
|
||||
|
||||
public function getConfigValue($itemname) {
|
||||
$configvalues = $this->getProperty("configvalues");
|
||||
if(!$configvalues) return null;
|
||||
@@ -224,6 +231,54 @@ class Contract extends mfBaseModel {
|
||||
return true;
|
||||
}
|
||||
|
||||
public function sendCancelNotification($linked_contracts = []) {
|
||||
$pdf_vars = [
|
||||
"contract" => $this,
|
||||
"linked_contracts" => $linked_contracts,
|
||||
"owner" => $this->getProperty("owner")
|
||||
];
|
||||
$pdf = new PdfForm("Emailtemplates/attachments/cancel_notification.pdf", $pdf_vars);
|
||||
//$pdf->download();
|
||||
//exit;
|
||||
$pdfpath = $pdf->render();
|
||||
$tvalue = $pdf->getReturnedValues();
|
||||
$pdfname = $tvalue["filename"];
|
||||
|
||||
// send email to customer
|
||||
$tpl = new Layout();
|
||||
$tpl->setTemplate("Emailtemplates/customer/cancel_notification");
|
||||
|
||||
foreach($pdf_vars as $name => $val) {
|
||||
$tpl->set($name, $val);
|
||||
}
|
||||
|
||||
$body = $tpl->render();
|
||||
$values = $tpl->getReturnedValue();
|
||||
|
||||
$subject = $values['subject'];
|
||||
$from = $values['from_email'];
|
||||
$from_name = $values['from_email_name'];
|
||||
$to = $this->owner->email;
|
||||
|
||||
if(!$subject || !$from || !$from_name || !$to) {
|
||||
$this->log->warn("Service PIN Email not sent. (subject: '$subject', from: '$from_name', from_email: '$from', to: '$to')");
|
||||
} else {
|
||||
$email = new Emailnotification();
|
||||
$email->setSubject($subject);
|
||||
$email->setBody($body);
|
||||
$email->setFrom($from, $from_name);
|
||||
$email->setTo($to);
|
||||
$email->setHeader("X-".MFAPPNAME."-Cid", $this->id);
|
||||
$email->addAttachment($pdfpath, null, $pdfname, "application/pdf");
|
||||
$email->send();
|
||||
|
||||
$email->setTo("office@xinon.at");
|
||||
$email->send();
|
||||
|
||||
$this->log->info(__METHOD__.": Sending Cancel Notication for ".$this->owner_id." to $to");
|
||||
}
|
||||
}
|
||||
|
||||
public function getProperty($name) {
|
||||
if($this->$name == null) {
|
||||
|
||||
@@ -336,6 +391,12 @@ class Contract extends mfBaseModel {
|
||||
$this->vatrate = $vatrate;
|
||||
return $this->vatrate;
|
||||
}
|
||||
|
||||
if($name == "voicenumbers") {
|
||||
$numbers = $this->getVoicenumbers();
|
||||
$this->voicenumbers = $numbers;
|
||||
return $this->voicenumbers;
|
||||
}
|
||||
|
||||
if($name == "journals") {
|
||||
$this->journals = array_reverse(ContractjournalModel::search(["contract_id" => $this->id]));
|
||||
|
||||
@@ -195,6 +195,7 @@ class ContractController extends mfBaseController
|
||||
$this->redirect("Contract", "cancel", ["contract_id" => $contract->id]);
|
||||
}
|
||||
|
||||
$linked_contracts = [];
|
||||
if(is_array($r->links)) {
|
||||
foreach($r->links as $link_id => $action) {
|
||||
if($action == "cancel") {
|
||||
@@ -205,6 +206,8 @@ class ContractController extends mfBaseController
|
||||
continue;
|
||||
}
|
||||
|
||||
$linked_contracts[] = $link_contract;
|
||||
|
||||
$link_contract->cancel_date = $cancel_date->getTimestamp();
|
||||
if(!$link_contract->save()) {
|
||||
$this->layout()->setFlash("Fehler beim Speichern von verlinktem Vertrag", "warning");
|
||||
@@ -213,11 +216,38 @@ class ContractController extends mfBaseController
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
$this->layout()->setFlash("Kündigung gespeichert", "success");
|
||||
$this->redirect("Contract", "view", ["contract_id" => $contract->id]);
|
||||
|
||||
}
|
||||
|
||||
protected function sendCancelNotification() {
|
||||
$contract_id = $this->request->contract_id;
|
||||
$contract = new Contract($contract_id);
|
||||
|
||||
$linked_contracts = [];
|
||||
foreach($contract->links as $link) {
|
||||
if($link->origin_contract_id == $contract_id) {
|
||||
$link_contract = $link->contract;
|
||||
} else {
|
||||
$link_contract = $link->origin;
|
||||
}
|
||||
if($link_contract->owner_id != $contract->owner_id) continue;
|
||||
$linked_contracts[] = $link_contract;
|
||||
}
|
||||
|
||||
$contract->sendCancelNotification($linked_contracts);
|
||||
|
||||
$this->layout()->setFlash("gesendet", "success");
|
||||
$this->redirect("Contract", "view", ["contract_id" => $contract_id]);
|
||||
|
||||
|
||||
}
|
||||
|
||||
protected function productchangeAction()
|
||||
{
|
||||
$this->layout()->setTemplate("Contract/ProductchangeForm");
|
||||
|
||||
Reference in New Issue
Block a user