diff --git a/application/Api/v1/Modules/Operationaldata/SnoppCitycom.php b/application/Api/v1/Modules/Operationaldata/SnoppCitycom.php index 04c7fb9c8..72865862a 100644 --- a/application/Api/v1/Modules/Operationaldata/SnoppCitycom.php +++ b/application/Api/v1/Modules/Operationaldata/SnoppCitycom.php @@ -2,6 +2,7 @@ namespace application\Api\v1\Modules\Operationaldata; use application\Api\v1\Modules; +use PreorderCtag; require_once(APPDIR."/Api/v1/Modules/ApiControllerModule.php"); @@ -56,6 +57,17 @@ class SnoppCitycom extends Modules\ApiControllerModule return \mfResponse::NotFound(["message" => "Home not found"]); } + // if all services are ordered and active, finish order and return active + $ctag = PreorderCtag::getFirstActive(["preorder_id" => $preorder->id, "service_type" => "inet"]); + if($ctag->ext_id && $ctag->ext_status == "finished") { + if($preorder->status->code < 500) { + $preorder->setNewStatusCode(500); + $preorder->save(); + } + return \mfResponse::Ok(["message" => "Service active already", "activation_status" => "active"]); + } + + // Home must have Status 300, else return deferred if($wohneinheit->status->code < 300) { return \mfResponse::Ok(["message" => "ONT not yet installed. Deferred", "activation_status" => "deferred"]); @@ -86,15 +98,21 @@ class SnoppCitycom extends Modules\ApiControllerModule $cc_api = new \Citycom_OanApiHelper($cc_api_client); // order Service at Citycom and set Preorder to 500 Finished - $services = $cc_api->orderServices($preorder, $cc_home_id, $data); - if(!$services) { + if(!$cc_api->orderServices($preorder, $cc_home_id, $data)) { return \mfResponse::InternalServerError(["message" => "Error activating service"]); } - $preorder->setNewStatusCode(500); - $preorder->save(); + // live check if service is active, if not return deferred + $ctag = PreorderCtag::getFirstActive(["preorder_id" => $preorder->id, "service_type" => "inet"]); + if($ctag->ext_id && $ctag->ext_status == "finished") { + if($preorder->status->code < 500) { + $preorder->setNewStatusCode(500); + $preorder->save(); + } + return \mfResponse::Ok(["message" => "Service active already", "activation_status" => "active"]); + } - return \mfResponse::Ok(["message" => "Services ordered successfully", "activation_status" => "active"]); + return \mfResponse::Ok(["message" => "Services ordered, not yet finished", "activation_status" => "deferred"]); } diff --git a/lib/Citycom/OanApiHelper.php b/lib/Citycom/OanApiHelper.php index 75e37fce9..87404fe7d 100644 --- a/lib/Citycom/OanApiHelper.php +++ b/lib/Citycom/OanApiHelper.php @@ -114,6 +114,20 @@ class Citycom_OanApiHelper { // order all services and save ctags $cc_service_types = $this->api->getServiceTypes(); + $this->log->debug(print_r($want_services, true)); + + // check if we have these services already + foreach($cc_service_types as $stype) { + if(!in_array($stype->name, CITYCOM_OAN_API_SERVICES_FOR_ORDER)) continue; + $ctag_service_type = array_flip(CITYCOM_OAN_API_SERVICES_FOR_ORDER)[$stype->name]; + if(PreorderCtag::getFirstActive(["preorder_id" => $preorder->id, "service_type" => $ctag_service_type])) { + // service was ordered already, remove from want_services + unset($want_services[$ctag_service_type]); + } + } + + $this->log->debug(print_r($want_services, true)); + $new_services = []; if($ctag_range_search) { @@ -124,7 +138,7 @@ class Citycom_OanApiHelper { $this->log->debug(print_r($ctags, true)); - if(!$ctags) { + if(!is_array($ctags)) { $this->log->error(__METHOD__.": No Free Ctags (Preorder ".$preorder->id.")"); return false; } @@ -141,7 +155,6 @@ class Citycom_OanApiHelper { ]; $service_count = 0; - $service_return = []; foreach($cc_service_types as $stype) { // was this service type requested if(!in_array($stype->name, $want_services)) continue; @@ -173,7 +186,7 @@ class Citycom_OanApiHelper { return false; } - $service_return[] = [ + /*$service_return[] = [ "service_number" => $new_service->service_number, "sublocation_id" => $sublocation_id, "service_type" => $ctag_service_type, @@ -182,7 +195,7 @@ class Citycom_OanApiHelper { "serial" => $new_service->ont->serial, "fsan" => $new_service->ont->fsan, ], - ]; + ];*/ /*$service_return[] = [ "sublocation_id" => $sublocation_id, @@ -225,7 +238,7 @@ class Citycom_OanApiHelper { - return $service_return; + return true; }