Added Preorder admin function Create Workorder

This commit is contained in:
Frank Schubert
2023-05-18 15:52:06 +02:00
parent 108daed7dd
commit de2b478c2f
2 changed files with 83 additions and 11 deletions

View File

@@ -25,12 +25,37 @@
<div class="card">
<div class="card-body">
<div class="row col" id="map-link">
<div class="form-group">
<a href="<?=self::getUrl("Preordercampaign","createRimoWorkorders", ["id" => $campaign->id])?>" class="btn btn-secondary"><i class="far fa-r"></i> <i class="far fa-gears"></i> Workorders in RIMO erstellen</a><br />
Erstellt Workorders für Vorbestelllungen, für die noch keine Workorders erstellt wurden
<h4>Workorders erstellen</h4>
<div class="row justify-content-end">
<div class="col-10">
<div class="row">
<div class="col">
Workorders erstellen für Vorbestellungen, für die noch keine Workorders erstellt wurden:<br />
</div>
</div>
<div class="row mt-1">
<div class="col">
<a href="<?=self::getUrl("Preordercampaign","createRimoWorkorders", ["id" => $campaign->id])?>" class="btn btn-primary"><i class="far fa-r"></i> <i class="far fa-gears"></i> Workorders in RIMO erstellen</a><br />
</div>
</div>
</div>
</div>
<?php if($missing_extref_count || $failed_count): ?>
<div class="row justify-content-end mt-2">
<div class="col-10">
<div class="alert alert-warning">
<?php if($missing_extref_count): ?>
<?=$missing_extref_count?> Wohneinheiten ohne extref (SDIHome_...)<br />
<?php endif; ?>
<?php if($failed_count): ?>
<?=$failed_count?> Workorders konnten nicht erstellt werden.
<?php endif; ?>
</div>
</div>
</div>
<?php endif; ?>
</div>
</div>

View File

@@ -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]);
}
}