Added Button to create RimoWorkorder for legacytransfer Preorders

This commit is contained in:
Frank Schubert
2024-11-14 17:35:53 +01:00
parent c5752de7b7
commit 667027c0f1
4 changed files with 152 additions and 2 deletions

View File

@@ -1014,6 +1014,53 @@
'json');
}
function createWorkorder(pid) {
if(!Number.isInteger(pid) || pid < 1) {
return false;
}
$.post("<?=self::getUrl("Preorder","Api")?>",
{
'do': "createWorkorder",
id: pid,
},
function(success) {
if(success.status == "OK") {
wo = success.result;
html = '<h4> \
' + wo.name + ' \
<a href="<?=self::getUrl("RimoWorkorder", "downloadAh")?>?id=' + wo.id + '" onclick="event.preventDefault(); downloadWorkorderAha(' + wo.id + ');"><i class="fas fa-fw fa-file-download ml-2"></i> AHA Blatt</a> \
</h4> \
<table class="table table-sm table-striped" id="preorder-detail-' + wo.preorder_id + '-workorder-' + wo.id + '"> \
<tr> \
<th>Name</th> \
<td class="text-monospace">' + wo.name + '</td> \
</tr><tr> \
<th>External ID</th> \
<td class="text-monospace">' + wo.external_id + '</td> \
</tr><tr> \
<th>Status</th> \
<td>' + wo.status + '</td> \
</tr> \
<tr> \
<th>Zugewiesen an:</th> \
<td>' + wo.assigned_to + '</td> \
</tr> \
<tr> \
<th>Erstellt</th> \
<td class="text-monospace">' + wo.created + '</td> \
</tr> \
</table>';
$("#preorder-detail-" + wo.preorder_id + "-rimo .workorder-container").append(html);
$("button.create-workorder").remove();
}
},
'json');
return false;
}
function deleteWorkorder(pid, wid) {
//console.log("in delete workorder");
if(!Number.isInteger(pid) || pid < 1) {

View File

@@ -395,14 +395,13 @@
</div>
<div class="row">
<div class="col-6">
<div class="col-6 workorder-container">
<h3>Workorder</h3>
<?php if($preorder->adb_wohneinheit_id && is_array($preorder->adb_wohneinheit->rimo_workorders) && count($preorder->adb_wohneinheit->rimo_workorders)): ?>
<?php foreach($preorder->adb_wohneinheit->rimo_workorders as $wo): ?>
<h4>
<?=$wo->rimo_name?>
<a href="<?=self::getUrl("RimoWorkorder", "downloadAh", ["id" => $wo->id])?>" onclick="event.preventDefault(); downloadWorkorderAha(<?=$wo->id?>);"><i class="fas fa-fw fa-file-download ml-2"></i> AHA Blatt</a>
<small class="text-danger">(beta)</small>
</h4>
<?php if($me->is("Admin")): ?>
<small id="preorder-detail-<?=$preorder->id?>-workorder-<?=$wo->id?>-del"><a href="#" onclick="if(confirm('Achtung: Löscht die Workorder in thetool, aber NICHT in RIMO!')) return deleteWorkorder(<?=$preorder->id?>, <?=$wo->id?>)" class="text-danger"><i class="far fa-times-circle"></i> Workorder löschen</a></small>
@@ -430,6 +429,9 @@
</tr>
</table>
<?php endforeach; ?>
<?php elseif($preorder->adb_wohneinheit_id && $preorder->type == "legacytransfer"): ?>
<button type="button" class="btn btn-outline-primary create-workorder" onclick="createWorkorder(<?=$preorder->id?>)"><i class="fas fa-fw fa-plus"></i> <i class="fas fa-r"></i><i class="fas fa-fw fa-gears"></i> Wokorder erstellen</button>
<?php endif; ?>
</div>

View File

@@ -530,6 +530,69 @@ class Preorder extends mfBaseModel {
}
}
public function createRimoWorkorder() {
if(!$this->adb_wohneinheit_id) {
return false;
}
$wohneinheit = new ADBWohneinheit($this->adb_wohneinheit_id);
if(!$wohneinheit->id) {
$this->log->error(__METHOD__.": Wohneinheit nicht gefunden (Preorder ".$this->id." ".$this->ucode." ".$this->oaid.")");
return false;
}
if(!$wohneinheit->extref) {
return false;
}
if(!$this->oaid) {
$this->setOrCreateOaid();
if(!$this->oaid) {
return false;
}
}
$oaid = OpenAccessIdModel::getFirstOaid($wohneinheit->oaid);
if(!$oaid) {
$this->log->warning(__METHOD__.": OAID '".$wohneinheit->oaid."' not found");
return false;
}
// create and assign OAID if not yet done
$oaid->exportToRimoAndAssignFtu();
// create Workorder
$data = [];
$data["firstname"] = trim($this->firstname);
$data["lastname"] = trim($this->lastname);
$data["company"] = trim($this->company);
$data["phone"] = trim($this->phone);
$data["email"] = trim($this->email);
$data["orderId"] = $this->ucode;
$response = Rimoapi::createWorkorder($wohneinheit->extref, $data);
//var_dump($response);exit;
if(!$response) {
$this->log->error(__METHOD__."Cannot create RimoWorkorder! Invalid Response! (Preorder ucode: ".$this->ucode.")");
return false;
}
$rimo_status = $response->state->userLabel;
if(!$rimo_status) {
$rimo_status = "";
}
$wo = RimoWorkorderModel::create([
"rimo_id" => $response->id,
"rimo_name" => $response->name,
"rimo_status" => $rimo_status,
"adb_wohneinheit_id" => $this->adb_wohneinheit_id,
"create_data" => json_encode($response)
]);
//var_dump($wo);exit;
$wo->save();
return $wo;
}
public function setNewStatusCode($new_status_code) {
if(!$new_status_code) return false;

View File

@@ -992,6 +992,9 @@ class PreorderController extends mfBaseController {
case "updateStatus":
$return = $this->updateStatusApi();
break;
case "createWorkorder":
$return = $this->createWorkorderApi();
break;
case "deleteWorkorder":
$return = $this->deleteWorkorderApi();
break;
@@ -1274,6 +1277,41 @@ class PreorderController extends mfBaseController {
}
private function createWorkorderApi() {
$preorder_id = $this->request->id;
if(!is_numeric($preorder_id) || $preorder_id < 1) {
return false;
}
$preorder = new Preorder($preorder_id);
if(!$preorder->id) {
return false;
}
if($preorder->type != "legacytransfer") {
return false;
}
$workorder = $preorder->createRimoWorkorder();
if(!$workorder) {
return false;
}
$return = [
"id" => $workorder->id,
"name" => $workorder->rimo_name,
"external_id" => $workorder->rimo_id,
"status" => $workorder->rimo_status,
"assigned_to" => $workorder->rimo_team_name,
"created" => date("d.m.Y H:i", $workorder->create),
"preorder_id" => $preorder_id
];
return $return;
}
private function deleteWorkorderApi() {
if(!$this->me->is("Admin")) {
return false;