Added OrderJournal

This commit is contained in:
Frank Schubert
2021-10-12 22:03:31 +02:00
parent a212d4b4bc
commit c464e111e8
5 changed files with 283 additions and 8 deletions

View File

@@ -194,9 +194,9 @@
<th></th>
</tr>
<?php foreach($orders as $order): ?>
<tr>
<tr class="building-list-tr" id="order-<?=$order->id?>">
<td><?=$order->id?></td>
<td>
<td onclick="toggleOrder(<?=$order->id?>)">
<?php if(is_array($order->terminations) && count($order->terminations)): ?>
<?php if($order->terminations[0]->status->code >= TT_TERMSTATUS_CONNECTED): ?>
<span class="status connected" title="Anschluss connected">CON</span>
@@ -236,23 +236,23 @@
<?=($hw) ? "<i class='fas fa-shopping-bag text-info ml-1' title='Zusatzprodukt vorhanden'></i>" : ""?>
<?=($voip) ? "<i class='fas fa-phone text-info ml-1' title='Voice Produkt vorhanden'></i>" : ""?>
</td>
<td>
<td onclick="toggleOrder(<?=$order->id?>)">
<?=nl2br($order->owner->getCompanyOrName())?>
<?=($order->owner->spin) ? "<br /><span class='text-pink'>".$order->owner->spin."</span>" : ""?>
</td>
<td>
<td onclick="toggleOrder(<?=$order->id?>)">
<?=$order->owner->street?><br />
<?=$order->owner->zip?> <?=$order->owner->city?>
</td>
<td>
<td onclick="toggleOrder(<?=$order->id?>)">
<?php if(is_array($order->terminations) && count($order->terminations)): ?>
<?=$order->terminations[0]->building->street?><?=($order->terminations[0]->name) ? " ".$order->terminations[0]->name : ""?><br />
<?=$order->terminations[0]->building->zip?> <?=$order->terminations[0]->building->city?>
<?php endif; ?>
</td>
<td class="text-monospace"><?=date("d.m.Y", $order->order_date)?></td>
<td class="text-monospace"><?=date("d.m.Y", $order->edit)?></td>
<td class="text-monospace"><?=$order->editor->name?></td>
<td onclick="toggleOrder(<?=$order->id?>)" class="text-monospace"><?=date("d.m.Y", $order->order_date)?></td>
<td onclick="toggleOrder(<?=$order->id?>)" class="text-monospace"><?=date("d.m.Y", $order->edit)?></td>
<td onclick="toggleOrder(<?=$order->id?>)" 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 herunterladen"></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>
@@ -260,6 +260,51 @@
<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>
</tr>
<tr id="order-detail-<?=$order->id?>" class="hidden" style="background-color:#fff">
<td colspan="9">
<div class="row">
<div class="col-lg-12">
<div class="card">
<div class="card-body">
<div class="card-header bg-primary text-white">Bestelljournal</div>
<div class="card mb-1" style="border: 1px solid #ddd">
<div class="card-header bg-light"><button type="button" class="btn btn-sm btn-info" onclick="$('#new-journal-<?=$order->id?>').toggle()"><i class="fas fa-plus"></i> Neuer Eintrag</button></div>
<div id="new-journal-<?=$order->id?>" class="card-body hidden">
<form method="post" action="<?=self::getUrl("OrderJournal", "save")?>">
<input type="hidden" name="order_id" value="<?=$order->id?>" />
<textarea name="text" class="form-control mb-2" style="height:120px;"></textarea>
<button class="btn btn-sm btn-primary" type="submit"><i class="fas fa-save"></i> Speichern</button>
</form>
</div>
</div>
<?php if(is_array($order->journals) && count($order->journals)): ?>
<?php foreach($order->journals as $journal): ?>
<div class="card mb-1" style="border: 1px solid #ddd">
<div class="card-header bg-light p-2"><span class="text-monospace font-weight-bold" style="float: right"><i class="fas fa-clock"></i> <?=date("d.m.Y H:i:s",$journal->create)?></span> Eingetragen von <strong><?=$journal->creator->name?></strong></div>
<div class="card-body p-2">
<?=nl2br($journal->text)?>
</div>
</div>
<?php endforeach; ?>
<?php endif; ?>
</div>
</div>
</div>
</div>
</td>
</tr>
<tr style="display:none;">
<td colspan="9"></td>
</tr>
<?php endforeach; ?>
</table>
@@ -297,4 +342,17 @@
</div>
</div>
<script type="text/javascript">
function toggleOrder(id) {
$('#order-detail-' + id).toggle();
if($('#order-detail-' + id).is(":hidden")) {
$('#order-' + id).removeClass("table-info");
$('#order-' + id).removeClass("text-info");
} else {
$('#order-' + id).addClass("text-info");
$('#order-' + id).addClass("table-info");
}
}
</script>
<?php include(realpath(dirname(__FILE__)."/../")."/footer.php"); ?>

View File

@@ -5,6 +5,7 @@ class Order extends mfBaseModel {
private $billingaddress;
private $products;
private $terminations;
private $journals;
private $files;
private $creator;
private $editor;
@@ -132,6 +133,11 @@ class Order extends mfBaseModel {
return $this->terminations;
}
if($name == "journals") {
$this->journals = OrderJournalModel::search(["order_id" => $this->id]);
return $this->journals;
}
if($name == "files") {
$this->files = OrderFileModel::search(['order_id' => $this->id]);
return $this->files;

View File

@@ -0,0 +1,38 @@
<?php
class OrderJournal extends mfBaseModel {
private $order;
private $creator;
private $editor;
public function getProperty($name) {
if($this->$name == null) {
if(!$this->id) {
return null;
}
if($name == "creator") {
$this->creator = new User($this->create_by);
return $this->creator;
}
if($name == "editor") {
$this->editor = new User($this->edit_by);
return $this->editor;
}
$classname = ucfirst($name);
$idfield = $name."_id";
$this->$name = new $classname($this->$idfield);
if($this->$name->id) {
return $this->$name;
} else {
return null;
}
}
return $this->$name;
}
}

View File

@@ -0,0 +1,61 @@
<?php
class OrderJournalController extends mfBaseController {
protected function init() {
$this->needlogin=true;
$me = new User();
$me->loadMe();
$this->me = $me;
$this->layout()->set("me",$me);
if(!$me->is(["Admin", "salespartner"])) {
$this->redirect("Dashboard");
}
}
protected function saveAction() {
if(!$this->me->is(["Admin", "salespartner"])) {
$this->layout()->setFlash("Keine Berechtigung", "error");
$this->redirect("Dashboard");
}
$r = $this->request;
$order_id = $r->order_id;
if(!is_numeric($order_id) || $order_id < 1) {
$this->layout()->setFlash("Bestellung nicht gefunden!", "error");
$this->redirect("Order");
}
$order = new Order($order_id);
if(!$order->id) {
$this->layout()->setFlash("Bestellung nicht gefunden!", "error");
$this->redirect("Order");
}
$text = trim(htmlentities($r->text));
if(!$text) {
$this->layout()->setFlash("Bitte Text eingeben", "error");
$this->redirect("Order", "Index", [], "order=".$order_id);
}
$journal = new OrderJournal();
$journal->order_id = $order_id;
$journal->text = $text;
$journal->create_by = $this->me->id;
$journal->edit_by = $this->me->id;
if(!$journal->save()) {
$this->layout()->setFlash("Fehler beim speichern!", "error");
$this->redirect("Order", "Index", [], "order=".$order_id);
}
$this->layout()->setFlash("Journaleintrag gespeichert", "success");
$this->redirect("Order", "Index", [], "order=".$order_id);
}
}

View File

@@ -0,0 +1,112 @@
<?php
class OrderJournalModel {
public $name = null;
public $order_id = null;
public $text = null;
public $create_by = null;
public $edit_by = null;
public $create = null;
public $edit = null;
public static function create(Array $data) {
$model = new OrderJournal();
foreach($data as $field => $value) {
if(property_exists(get_called_class(), $field)) {
$model ->$field = $value;
}
}
$me = new User();
$me->loadMe();
if($model->create_by === null) {
$model->create_by = $me->id;
}
if($model->edit_by === null) {
$model->edit_by = $me->id;
}
return $model;
}
public static function getOne($id) {
if(!is_numeric($id) || !$id) {
throw new Exception("Invalid number", 400);
}
$item = [];
$db = FronkDB::singleton();
$res = $db->select("OrderJournal", "*", "id=$id LIMIT 1");
if($db->num_rows($res)) {
$data = $db->fetch_object($res);
$item = new OrderJournal($data);
}
return $item;
}
public static function getAll() {
$items = [];
$db = FronkDB::singleton();
$res = $db->select("OrderJournal", "*");
if($db->num_rows($res)) {
while($data = $db->fetch_object($res)) {
$items[] = new OrderJournal($data);
}
}
return $items;
}
public static function getFirst($filter) {
$db = FronkDB::singleton();
$where = self::getSqlFilter($filter);
$res = $db->select("OrderJournal", "*", "$where ORDER BY `create`");
if($db->num_rows($res)) {
$data = $db->fetch_object($res);
$item = new OrderJournal($data);
if($item->id) {
return $item;
} else {
return null;
}
}
return null;
}
public static function search($filter) {
$items = [];
$db = FronkDB::singleton();
$where = self::getSqlFilter($filter);
$res = $db->select("OrderJournal", "*", "$where ORDER BY `create` DESC");
if($db->num_rows($res)) {
while($data = $db->fetch_object($res)) {
$items[] = new OrderJournal($data);
}
}
return $items;
}
private function getSqlFilter($filter) {
$where = "1=1 ";
//var_dump($filter);exit;
if(array_key_exists("order_id", $filter)) {
$orderid = $filter['order_id'];
if(is_numeric($orderid)) {
$where .= " AND order_id=$orderid";
}
}
//var_dump($filter, $where);exit;
return $where;
}
}