WIP rimo workorders

This commit is contained in:
Frank Schubert
2023-05-18 14:35:15 +02:00
parent e60aede1b4
commit 108daed7dd
3 changed files with 105 additions and 19 deletions

View File

@@ -441,6 +441,13 @@ class PreorderModel {
}
}
if(array_key_exists("workorder_export_date", $filter)) {
$workorder_export_date = $filter['workorder_export_date'];
if($workorder_export_date === null || $workorder_export_date === false) {
$where .= " AND (tt_preorder.workorder_export_date IS NULL OR tt_preorder.workorder_export_date = 0)";
}
}
if(array_key_exists("gemeinde", $filter)) {
$gemeinde = FronkDB::singleton()->escape($filter['gemeinde']);
if($gemeinde) {

View File

@@ -130,24 +130,6 @@ class PreordercampaignController extends mfBaseController {
return $owners;
}
protected function adminAction() {
$this->layout()->setTemplate("Preordercampaign/Admin");
$id = $this->request->id;
if(!is_numeric($id) || !$id) {
$this->layout()->setFlash("Vorbestellkampagne nicht gefunden", "error");
$this->redirect("Preordercampaign");
}
$campaign = new Preordercampaign($id);
if(!$campaign->id) {
$this->layout()->setFlash("Vorbestellkampagne nicht gefunden", "error");
$this->redirect("Preordercampaign");
}
$this->layout()->set("campaign", $campaign);
}
protected function addAction() {
if(!$this->me->is("Admin")) {
$this->redirect("Preordercampaign");
@@ -425,4 +407,101 @@ class PreordercampaignController extends mfBaseController {
}
}
protected function adminAction() {
$this->layout()->setTemplate("Preordercampaign/Admin");
$id = $this->request->id;
if(!is_numeric($id) || !$id) {
$this->layout()->setFlash("Vorbestellkampagne nicht gefunden", "error");
$this->redirect("Preordercampaign");
}
$campaign = new Preordercampaign($id);
if(!$campaign->id) {
$this->layout()->setFlash("Vorbestellkampagne nicht gefunden", "error");
$this->redirect("Preordercampaign");
}
$this->layout()->set("campaign", $campaign);
}
protected function createRimoWorkordersAction() {
$this->layout()->setTemplate("Preordercampaign/Admin");
$id = $this->request->id;
if(!is_numeric($id) || !$id) {
$this->layout()->setFlash("Vorbestellkampagne nicht gefunden", "error");
$this->redirect("Preordercampaign");
}
$campaign = new Preordercampaign($id);
if(!$campaign->id) {
$this->layout()->setFlash("Vorbestellkampagne nicht gefunden", "error");
$this->redirect("Preordercampaign");
}
foreach(PreorderModel::search(["preordercampaign_id" => $id, "workorder_export_date" => null]) as $preorder) {
if($preorder->workorder_export_date) {
$this->log->warning(__METHOD__.": workorder_export_date not null");
}
if(!$preorder->adb_wohneinheit_id) {
//echo "Keine Wohneinheit in Preorder (".$preorder->id.") ".$preorder->ucode." ".$preorder->oaid."\n";
$missing_units[] = $preorder;
continue;
}
$wohneinheit = new ADBWohneinheit($preorder->adb_wohneinheit_id);
if(!$wohneinheit->id) {
echo "Wohneinheit nicht gefunden (Preorder ".$preorder->id." ".$preorder->ucode." ".$preorder->oaid.")\n";
continue;
}
if(!$wohneinheit->extref) {
$missing_extrefs[] = $preorder;
continue;
}
if(!$preorder->oaid) {
if(!$wohneinheit->oaid) {
$wohneinheit->oaid = $wohneinheit->getNewOAID();
$wohneinheit->save();
}
$preorder->oaid = $wohneinheit->oaid;
$preorder->save();
}
$params['apiKey'] = RIMO_API_JSON_APIKEY;
$params["homeId"] = $wohneinheit->extref;
$params["firstName"] = trim($preorder->firstname);
$params["lastName"] = trim($preorder->lastname);
$params["company"] = trim($preorder->company);
$params["phone"] = trim($preorder->phone);
$params["email"] = trim($preorder->email);
$params["orderId"] = $preorder->ucode;
$params["openAccessId"] = $preorder->oaid;
$qs = http_build_query($params);
//echo $qs."\n";
$createOrderEp = RIMO_API_JSON_URL.RIMO_API_JSON_EP_CREATE_WORKORDER;
$post_url = $createOrderEp."?".$qs;
$ctx = stream_context_create($ctx_opts);
$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";
continue;
}
$preorder->workorder_export_date = date('U');
$preorder->workorder_export_data = $response;
$preorder->save();
//var_dump($preorder, $response);
//exit;
}
}
}

View File

@@ -30,7 +30,7 @@ $ctx_opts = [
$missing_units = [];
$missing_extrefs = [];
foreach(PreorderModel::search(["preordercampaign_id" => $campaign_prem_sued ]) as $preorder) {
foreach(PreorderModel::search(["preordercampaign_id" => $campaign_prem_sued]) as $preorder) {
if(in_array($preorder->id, $ignore_preorders)) continue;
if($preorder->workorder_export_date) continue;