From cf7f70b7eabd0512cbbf314e999feabaabd290b7 Mon Sep 17 00:00:00 2001 From: Frank Schubert Date: Tue, 4 Mar 2025 18:26:27 +0100 Subject: [PATCH] Added saving Remarks to workorder and to rimo in Preorder --- Layout/default/Preorder/Index.php | 39 +++++++++++++++++++ .../Preorder/include/preorder-detail.php | 14 +++++++ application/Preorder/PreorderController.php | 37 ++++++++++++++++++ lib/Rimoapi/Rimoapi.php | 33 ++++++++++++++++ 4 files changed, 123 insertions(+) diff --git a/Layout/default/Preorder/Index.php b/Layout/default/Preorder/Index.php index 1e4677ea4..7053cff9c 100644 --- a/Layout/default/Preorder/Index.php +++ b/Layout/default/Preorder/Index.php @@ -1273,5 +1273,44 @@ $pagination_entity_name = "Vorbestellungen"; }); } + + async function saveRemark(pid, wid) { + if(!pid || !wid) return false; + + var new_remark_elem = $("#wo-remark-" + pid + "-" + wid + " input[name='new_remark']"); + var new_remark = new_remark_elem.val(); + + new_remark_elem.prop("readonly", true); + + + await fetch("", { + method: "POST", + headers: { + 'Content-Type': 'application/x-www-form-urlencoded;charset=UTF-8' + }, + body: new URLSearchParams({ + do: "addWorkorderRemark", + preorder_id: pid, + workorder_id: wid, + remark: new_remark + }) + }).then(resp => { + if(resp.ok) { + return resp.json(); + } + }).then((data) => { + if(data.status == "OK") { + var remark = data.result.remark.replaceAll("\n", "
"); + $("#wo-remark-" + pid + "-" + wid + " div.remark-text").html(remark); + new_remark_elem.val(""); + window.notify("success", "Bemerkung gespeichert"); + } else { + window.notify("error", "Fehler beim Speichern der Bemerkung"); + } + }); + + new_remark_elem.prop("readonly", false); + + } \ No newline at end of file diff --git a/Layout/default/Preorder/include/preorder-detail.php b/Layout/default/Preorder/include/preorder-detail.php index 7ef1633aa..accb01668 100644 --- a/Layout/default/Preorder/include/preorder-detail.php +++ b/Layout/default/Preorder/include/preorder-detail.php @@ -425,6 +425,20 @@ Erstellt create)?> + + Bemerkung + +
+ +
+ +
+
+
+ remarks))?> +
+ + diff --git a/application/Preorder/PreorderController.php b/application/Preorder/PreorderController.php index e2588193e..10b43857d 100644 --- a/application/Preorder/PreorderController.php +++ b/application/Preorder/PreorderController.php @@ -1058,6 +1058,9 @@ class PreorderController extends mfBaseController { case "setStatusFlag": $return = $this->setStatusFlagApi(); break; + case "addWorkorderRemark": + $return = $this->addWorkorderRemarkApi(); + break; default: $return = false; } @@ -1071,6 +1074,40 @@ class PreorderController extends mfBaseController { $this->returnJson($data); } + private function addWorkorderRemarkApi() { + $preorder_id = $this->request->preorder_id; + $workorder_id = $this->request->workorder_id; + $new_remark = $this->request->remark; + + $preorder = new Preorder($preorder_id); + if(!$preorder->id) { + $this->log->debug(__METHOD__.": preorder ($preorder_id) not found"); + return false; + } + + $workorder = new RimoWorkorder($workorder_id); + if(!$workorder->id) { + $this->log->debug(__METHOD__.": workorder ($workorder_id) not found"); + return false; + } + + // upload remark to Rimo + if(!Rimoapi::addRemark($workorder->rimo_id, $new_remark)) { + return false; + } + + $remarks = $workorder->remarks; + if($remarks) { + $remarks .= "\n"; + } + $remarks .= date("d.m.Y").": ".$new_remark; + + $workorder->remarks = $remarks; + $workorder->save(); + + return ["message" => "Remark added successfully", "preorder_id" => $preorder_id, "workorder_id" => $workorder_id, "remark" => $workorder->remarks]; + } + private function setStatusFlagApi() { $preorder_id = $this->request->preorder_id; $flag_id = $this->request->flag_id; diff --git a/lib/Rimoapi/Rimoapi.php b/lib/Rimoapi/Rimoapi.php index dafa4bf6a..2b6c51224 100644 --- a/lib/Rimoapi/Rimoapi.php +++ b/lib/Rimoapi/Rimoapi.php @@ -464,5 +464,38 @@ class Rimoapi { return $resp_data; } + public static function addRemark($object_id, $text) { + if(!$object_id || !$text) return false; + + $log = mfLoghandler::singleton(); + + $params = []; + $params['apiKey'] = RIMO_API_JSON_APIKEY; + $params['objectId'] = $object_id; + $params['text'] = $text; + + $ctx_opts = [ + 'http' => [ + 'method' => 'GET', + 'header' => 'accept: application/json' + ] + ]; + + $qs = http_build_query($params); + + $addRemarkEp = RIMO_API_JSON_URL.RIMO_API_JSON_EP_ADD_REMARK; + + $get_url = $addRemarkEp."?".$qs; + $ctx = stream_context_create($ctx_opts); + $log->debug(__METHOD__.": Adding Remark to $object_id: $get_url"); + $response = file_get_contents($get_url, false, $ctx); + + if($response === false) { + $log->error("Error adding Remark to $object_id"); + return false; + } + + return true; + } } \ No newline at end of file