WIP Workorder AH download

This commit is contained in:
Frank Schubert
2024-11-08 12:23:07 +01:00
parent 6c0d334bbc
commit 482e1a4989
4 changed files with 111 additions and 5 deletions

View File

@@ -939,12 +939,12 @@
return false;
}
function downloadWorkorderAh(workorder_id) {
async function downloadWorkorderAh(workorder_id) {
if(!workorder_id) return false;
var filename;
fetch('<?=self::getUrl("RimoWorkorder", "downloadAh")?>')
await fetch('<?=self::getUrl("RimoWorkorder", "downloadAh")?>?id=' + workorder_id)
.then(resp => {
const header = resp.headers.get("Content-disposition");
let matches = header.match(/filename=['"]?([^'"]+)/i);
@@ -970,7 +970,6 @@
})
.catch(() => window.notify("Fehler beim Download des AH-Blatts"));
}
</script>
<?php include(realpath(dirname(__FILE__)."/../../$mfLayoutPackage")."/footer.php"); ?>

View File

@@ -28,7 +28,10 @@ class RimoWorkorder extends mfBaseModel {
public function downloadAh() {
if(!$this->id) return false;
$ah = Rimoapi::getWorkorderAhReport();
$ah = Rimoapi::getWorkorderAhReport($this->rimo_id);
return $ah;
}

View File

@@ -30,7 +30,7 @@ class RimoWorkorderController extends mfBaseController {
$return = $workorder->downloadAh();
if($return === false) {
header("HTTP/1.1 500 Not Found");
echo "Fehler beim Herunterladen des AH-Blatts aus Rimo.";
echo "Fehler beim Herunterladen des AHA-Reports aus Rimo.";
exit;
}

View File

@@ -247,7 +247,111 @@ class Rimoapi {
return false;
}
$items = self::getFilenames($rimo_id);
if(!is_object($items)) {
return false;
}
if(!is_array($items->item) || !count($items->item)) {
return false;
}
foreach($items->item as $item) {
if(!$item->name) continue;
if(!preg_match('/_AHA.pdf$/i', $item->name)) continue;
$filename = $item->name;
}
if(!$filename) {
return false;
}
// fetch file
$params = [];
$params['apiKey'] = RIMO_API_JSON_APIKEY;
$params['objectId'] = $rimo_id;
$params['fileNames'] = $filename;
$ctx_opts = [
'http' => [
'method' => 'GET',
]
];
$qs = http_build_query($params);
$getFileEp = RIMO_API_JSON_URL.RIMO_API_JSON_EP_GET_FILES;
$get_url = $getFileEp."?".$qs;
$ctx = stream_context_create($ctx_opts);
$log->debug(__METHOD__.": Retrieving file from Rimo: $get_url");
$response = file_get_contents($get_url, false, $ctx);
if(!$response) return false;
/* remove boundary from rimo response
header:
--uuid:b0b72203-db4d-4a85-9d26-b01cd08338c1
Content-Type: application/octet-stream
Content-Transfer-Encoding: binary
Content-ID: <101DCY_AHA.pdf>
footer:
--uuid:b0b72203-db4d-4a85-9d26-b01cd08338c1--
*/
$finfo = new Finfo(FILEINFO_MIME);
$mimetype = $finfo->buffer($response);
var_dump($mimetype);exit;
if(!stripos($mimetype, "pdf")) {
return false;
}
return $response;
}
public static function getFilenames($rimo_id) {
if(!$rimo_id) return false;
$log = mfLoghandler::singleton();
$params = [];
$params['apiKey'] = RIMO_API_JSON_APIKEY;
$params['objectId'] = $rimo_id;
$ctx_opts = [
'http' => [
'method' => 'GET',
'header' => 'accept: application/json'
]
];
$qs = http_build_query($params);
$getFileEp = RIMO_API_JSON_URL.RIMO_API_JSON_EP_GET_FILENAMES;
$get_url = $getFileEp."?".$qs;
$ctx = stream_context_create($ctx_opts);
$log->debug(__METHOD__.": Getting Filenames from Rimo: $get_url");
$response = file_get_contents($get_url, false, $ctx);
if($response === false) {
$log->error("Error retrieving filenames from RIMO for $rimo_id");
return false;
}
$resp_data = json_decode($response);
return $resp_data;
}