diff --git a/Layout/default/Preorder/Index.php b/Layout/default/Preorder/Index.php index a894491ac..64f41c837 100644 --- a/Layout/default/Preorder/Index.php +++ b/Layout/default/Preorder/Index.php @@ -1014,6 +1014,53 @@ 'json'); } + function createWorkorder(pid) { + if(!Number.isInteger(pid) || pid < 1) { + return false; + } + + $.post("", + { + 'do': "createWorkorder", + id: pid, + }, + function(success) { + if(success.status == "OK") { + wo = success.result; + html = '

\ + ' + wo.name + ' \ + ?id=' + wo.id + '" onclick="event.preventDefault(); downloadWorkorderAha(' + wo.id + ');"> AHA Blatt \ +

\ + \ + \ + \ + \ + \ + \ + \ + \ + \ + \ + \ + \ + \ + \ + \ + \ + \ + \ + \ +
Name' + wo.name + '
External ID' + wo.external_id + '
Status' + wo.status + '
Zugewiesen an:' + wo.assigned_to + '
Erstellt' + wo.created + '
'; + + $("#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) { diff --git a/Layout/default/Preorder/include/preorder-detail.php b/Layout/default/Preorder/include/preorder-detail.php index 61a45576b..4656952c7 100644 --- a/Layout/default/Preorder/include/preorder-detail.php +++ b/Layout/default/Preorder/include/preorder-detail.php @@ -395,14 +395,13 @@
-
+

Workorder

adb_wohneinheit_id && is_array($preorder->adb_wohneinheit->rimo_workorders) && count($preorder->adb_wohneinheit->rimo_workorders)): ?> adb_wohneinheit->rimo_workorders as $wo): ?>

rimo_name?> $wo->id])?>" onclick="event.preventDefault(); downloadWorkorderAha(id?>);"> AHA Blatt - (beta)

is("Admin")): ?> Workorder löschen @@ -430,6 +429,9 @@ + + adb_wohneinheit_id && $preorder->type == "legacytransfer"): ?> +
diff --git a/application/Preorder/Preorder.php b/application/Preorder/Preorder.php index 7235fbb6d..45b5ad10d 100644 --- a/application/Preorder/Preorder.php +++ b/application/Preorder/Preorder.php @@ -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; diff --git a/application/Preorder/PreorderController.php b/application/Preorder/PreorderController.php index 831350fda..a7077e32a 100644 --- a/application/Preorder/PreorderController.php +++ b/application/Preorder/PreorderController.php @@ -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;