diff --git a/Layout/default/Preordercampaign/Admin.php b/Layout/default/Preordercampaign/Admin.php index 14b520133..fc6bee7a5 100644 --- a/Layout/default/Preordercampaign/Admin.php +++ b/Layout/default/Preordercampaign/Admin.php @@ -25,12 +25,37 @@
- diff --git a/application/Preordercampaign/PreordercampaignController.php b/application/Preordercampaign/PreordercampaignController.php index fa28ec787..576804b1e 100644 --- a/application/Preordercampaign/PreordercampaignController.php +++ b/application/Preordercampaign/PreordercampaignController.php @@ -442,6 +442,10 @@ class PreordercampaignController extends mfBaseController { $this->redirect("Preordercampaign"); } + $missing_units = []; + $missing_extrefs = []; + $workorders_created = 0; + $workorders_failed = 0; foreach(PreorderModel::search(["preordercampaign_id" => $id, "workorder_export_date" => null]) as $preorder) { if($preorder->workorder_export_date) { @@ -455,7 +459,7 @@ class PreordercampaignController extends mfBaseController { } $wohneinheit = new ADBWohneinheit($preorder->adb_wohneinheit_id); if(!$wohneinheit->id) { - echo "Wohneinheit nicht gefunden (Preorder ".$preorder->id." ".$preorder->ucode." ".$preorder->oaid.")\n"; + $this->log->error(__METHOD__.": Wohneinheit nicht gefunden (Preorder ".$preorder->id." ".$preorder->ucode." ".$preorder->oaid.")"); continue; } @@ -481,7 +485,14 @@ class PreordercampaignController extends mfBaseController { $params["phone"] = trim($preorder->phone); $params["email"] = trim($preorder->email); $params["orderId"] = $preorder->ucode; - $params["openAccessId"] = $preorder->oaid; + //$params["openAccessId"] = $preorder->oaid; // TODO: flag in campaign to include OAID or not + + $ctx_opts = [ + 'http' => [ + 'method' => 'POST', + 'header' => 'accept: application/json' + ] + ]; $qs = http_build_query($params); //echo $qs."\n"; @@ -489,19 +500,55 @@ class PreordercampaignController extends mfBaseController { $createOrderEp = RIMO_API_JSON_URL.RIMO_API_JSON_EP_CREATE_WORKORDER; $post_url = $createOrderEp."?".$qs; $ctx = stream_context_create($ctx_opts); + $this->log->debug(__METHOD__.": Creating Workorder: $post_url"); + $response = file_get_contents($post_url, false, $ctx); - + if($response === false) { echo "Fehler beim Exportieren der Workorder für Preorder ".$preorder->id." ".$preorder->ucode." ".$preorder->oaid."\n"; + $workorders_failed++; continue; } $preorder->workorder_export_date = date('U'); $preorder->workorder_export_data = $response; $preorder->save(); - - //var_dump($preorder, $response); - //exit; - + $workorders_created++; + } + + $errors = []; + $warnings = []; + + if(count($missing_units)) { + $warnings[] = count($missing_units)." Vobestellungen ohne Wohneinheit"; + } + if(count($missing_extrefs)) { + $warnings[] = count($missing_extrefs)." Wohneinheiten ohne extref (SDIHome_)"; + } + + + if($workorders_failed) { + $errors[] = "$workorders_failed Workorders konnten nicht erstellt werden."; + } + + + if(count($errors)) { + $this->layout()->setFlash(implode("
\n", $errors), "error"); + } + if(count($warnings)) { + $this->layout()->setFlash(implode("
\n", $warnings), "warning"); + } + + if($workorders_created) { + $this->layout()->setFlash("$workorders_created Workorders erfolgreich erstellt", "success"); + } else { + $this->layout()->setFlash("Es konnten keine Workorders erstellt werden", "info"); + } + + + + + $this->redirect("Preordercampaign", "Admin", ["id" => $id]); + } } \ No newline at end of file