Added saving Remarks to workorder and to rimo in Preorder

This commit is contained in:
Frank Schubert
2025-03-04 18:26:27 +01:00
parent dc4755d7fd
commit cf7f70b7ea
4 changed files with 123 additions and 0 deletions

View File

@@ -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("<?=self::getUrl("Preorder", "Api")?>", {
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", "<br />");
$("#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);
}
</script>
<?php include(realpath(dirname(__FILE__)."/../../$mfLayoutPackage")."/footer.php"); ?>

View File

@@ -425,6 +425,20 @@
<th>Erstellt</th>
<td class="text-monospace"><?=date("d.m.Y H:i:s", $wo->create)?></td>
</tr>
<tr>
<th>Bemerkung</th>
<td id="wo-remark-<?=$preorder->id?>-<?=$wo->id?>">
<div class="input-group mb-2">
<input type="text" class="form-control" name="new_remark" placeholder="Bemerkung hinzufügen" />
<div class="input-group-append">
<button class="btn btn-primary" type="button" id="button-addon2" onclick="saveRemark(<?=$preorder->id?>, <?=$wo->id?>)">Hinzufügen</button>
</div>
</div>
<div class="remark-text border p-1 text-monospace" id="preorder-detail-<?=$preorder->id?>-workorder-<?=$wo->id?>-remarks">
<?=nl2br(htmlentities($wo->remarks))?>
</div>
</td>
</tr>
</table>
<?php endforeach; ?>

View File

@@ -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;

View File

@@ -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;
}
}