Added Preorder admin function Create Workorder
This commit is contained in:
@@ -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("<br />\n", $errors), "error");
|
||||
}
|
||||
if(count($warnings)) {
|
||||
$this->layout()->setFlash(implode("<br />\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]);
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user