Added buttons to Order/Index

This commit is contained in:
Frank Schubert
2021-08-27 19:42:34 +02:00
parent 1a0f51360f
commit a40dc708fa
6 changed files with 199 additions and 10 deletions

View File

@@ -51,6 +51,35 @@
<span class="status not-connected" title="Tiefbau ausständig">BNC</span>
<?php endif; ?>
<?php endif; ?>
<?php
$voip = false;
$hw = false;
if(count($order->products)) {
foreach($order->products as $product) {
if(is_array($product->product->attributes) && count($product->product->attributes)) {
if(array_key_exists("hw_only", $product->product->attributes)) {
if($product->product->attributes["hw_only"]->value) {
$hw = true;
}
}
if(array_key_exists("voip_chan", $product->product->attributes)) {
if($product->product->attributes["voip_chan"]->value) {
$voip = true;
}
}
if($hw && $voip_chan) {
break;
}
}
}
}
?>
<?=($voip) ? "<i class='fas fa-phone text-pink ml-1'></i>" : ""?>
<?=($hw) ? "<i class='fas fa-shopping-bag text-pink ml-1'></i>" : ""?>
</td>
<td>
<?=nl2br($order->owner->getCompanyOrName())?>
@@ -70,6 +99,8 @@
<td class="text-monospace"><?=date("d.m.Y", $order->edit)?></td>
<td class="text-monospace"><?=$order->editor->name?></td>
<td style="text-align: left; letter-spacing: 4px; font-size: 1.1em;">
<a href="<?=self::getUrl("Order", "downloadServicePin", ["id" => $order->id])?>"><i class="fas fa-file-alt" title="Service PIN als PDF per Email an Vertragsinhaber"></i></a>
<a href="<?=self::getUrl("Order", "sendServicePin", ["id" => $order->id])?>" onclick="if(!confirm('Soll der Service-PIN an den Vertragsinhaber gesendet werden?')) return false;"><i class="fas fa-paper-plane" title="Service PIN als PDF per Email an Vertragsinhaber"></i></a>
<a href="<?=self::getUrl("Order", "edit", ["id" => $order->id])?>"><i class="far fa-edit" title="Bearbeiten"></i></a>
<a href="<?=self::getUrl("Order", "delete", ["id" => $order->id])?>" onclick="if(!confirm('Bestellung wirklich löschen?')) return false;" class="text-danger" title="Löschen"><i class="fas fa-trash"></i></a>
</td>

View File

@@ -140,5 +140,7 @@ class AddressController extends mfBaseController {
$this->layout()->setFlash("Adresse erfolgreich gespeichert.", "success");
$this->redirect("Address", "Edit", ['id' => $new_id]);
}
}

View File

@@ -383,15 +383,18 @@ class OrderController extends mfBaseController {
if($owner->save()) {
// render service pin PDF
$pdf = new Layout();
$pdf = new PdfForm("Emailtemplates/attachments/new_order_spin.pdf", ["owner" => $owner, "order" => $order]);
$pdfpath = $pdf->render();
$tvalue = $pdf->getReturnedValues();
$pdfname = $tvalue['filename'];
/*$pdf = new Layout();
$pdf->setTemplate("Emailtemplates/attachments/new_order.pdf");
$pdf->set("ressourcePathPrefix", BASEDIR."/public/");
$pdf->set("owner", $owner);
$pdf->set("order", $order);
$pdf->set("order", $order);*/
$pdfpath = $pdf->renderPDF();
$tvalue = $pdf->getReturnedValue();
$pdfname = $tvalue['filename'];
//var_dump($pdfpath);exit;
@@ -513,5 +516,94 @@ class OrderController extends mfBaseController {
$this->redirect("Order");
}
protected function downloadServicePinAction() {
$order_id = $this->request->id;
if(!is_numeric($order_id) || !$order_id) {
$this->layout->setFlash("Adresse nicht gefunden!");
$this->redirect("Order");
}
$order = new Order($order_id);
if(!$order->id) {
$this->layout->setFlash("Bestellung nicht gefunden!");
$this->redirect("Order");
}
$owner = $order->owner;
if(!$owner->customer_number || !$owner->spin) {
$this->layout->setFlash("Vertragsinhaber hat keine Kundennummer oder Service PIN!", "error");
$this->redirect("Order");
}
// render service pin PDF
$pdf = new PdfForm("Emailtemplates/attachments/new_order_spin.pdf", ["owner" => $owner, "order" => $order]);
$pdfpath = $pdf->render();
$tvalue = $pdf->getReturnedValues();
$pdfname = $tvalue['filename'];
$pdf->download($pdfname);
}
protected function sendServicePinAction() {
$order_id = $this->request->id;
if(!is_numeric($order_id) || !$order_id) {
$this->layout->setFlash("Adresse nicht gefunden!");
$this->redirect("Order");
}
$order = new Order($order_id);
if(!$order->id) {
$this->layout->setFlash("Bestellung nicht gefunden!");
$this->redirect("Order");
}
$owner = $order->owner;
if(!$owner->customer_number || !$owner->spin) {
$this->layout->setFlash("Vertragsinhaber hat keine Kundennummer oder Service PIN!", "error");
$this->redirect("Order");
}
// render service pin PDF
$pdf = new PdfForm("Emailtemplates/attachments/new_order_spin.pdf", ["owner" => $owner, "order" => $order]);
$pdfpath = $pdf->render();
$tvalue = $pdf->getReturnedValues();
$pdfname = $tvalue['filename'];
// TODO template rendern auslagern nach Emailtempate klasse
$tpl = new Layout();
$tpl->setTemplate("Emailtemplates/customer/new_order");
$tpl->set("owner", $owner);
$body = $tpl->render();
$values = $tpl->getReturnedValue();
//var_dump($values);exit;
$subject = $values['subject'];
$from = $values['from_email'];
$from_name = $values['from_email_name'];
$to = $owner->email;
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->redirect("Order");
} else {
$email = new Emailnotification();
$email->setSubject($subject);
$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->addAttachment($pdfpath, null, $pdfname, "application/pdf");
$email->send();
$this->layout()->setFlash("Service PIN wurde erfolgreich verschickt..", "success");
$this->redirect("Order");
}
}
}

64
lib/PdfForm/PdfForm.php Normal file
View File

@@ -0,0 +1,64 @@
<?php
class PdfForm {
private $log;
private $layout;
private $template;
private $variables;
private $fullpath;
private $returnValues;
public function __construct($template, $variables) {
$this->log = mfLoghandler::singleton();
$this->layout = new Layout();
$this->template = $template;
$this->variables = $variables;
}
public function render() {
$this->layout->setTemplate($this->template);
$this->layout->set("ressourcePathPrefix", BASEDIR."/public/");
foreach($this->variables as $name => $value) {
$this->layout->set($name, $value);
}
$fullpath = $this->layout->renderPDF();
$this->fullpath = $fullpath;
$this->returnValues = $this->layout->getReturnedValue();
return $fullpath;
}
public function download($filename = false) {
if(!$this->fullpath) {
$this->render();
}
$filepath = $this->fullpath;
if (!$filename && strpos($filepath, "/") !== false) {
$path_parts = explode("/", $filepath);
$filename = end($path_parts);
}
header('Content-Type: application/octet-stream');
header('Content-disposition: attachment; filename="'.$filename.'"');
header('Content-Transfer-Encoding: binary');
header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
header('Content-Type: ' . mime_content_type($filepath));
header("Content-Length: " . filesize($filepath));
readfile($filepath);
exit;
}
public function getFullPath() {
return $this->fullpath;
}
public function getReturnedValues() {
return $this->returnValues;
}
}

View File

@@ -76,7 +76,7 @@ class mfLayout {
$html = $this->render();
if (!$filename)
$filename = date('U') . ".pdf";
$filename = date('U') . "-" . rand(1000, 9999) . ".pdf";
$wk = new mfWkhtmltopdf($html);
@@ -108,10 +108,10 @@ class mfLayout {
header('Content-disposition: attachment; filename=' . $filename);
header('Content-Transfer-Encoding: binary');
header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
header('Content-Type: ' . mime_content_type($filename));
header("Content-Length: " . filesize($filename));
readfile($file);
header('Content-Type: ' . mime_content_type($filepath));
header("Content-Length: " . filesize($filepath));
readfile($filepath);
exit;
}