Added AHA Report to download in Preorder Index
This commit is contained in:
@@ -939,12 +939,12 @@
|
||||
return false;
|
||||
}
|
||||
|
||||
async function downloadWorkorderAh(workorder_id) {
|
||||
async function downloadWorkorderAha(workorder_id) {
|
||||
if(!workorder_id) return false;
|
||||
|
||||
var filename;
|
||||
|
||||
await fetch('<?=self::getUrl("RimoWorkorder", "downloadAh")?>?id=' + workorder_id)
|
||||
await fetch('<?=self::getUrl("RimoWorkorder", "downloadAha")?>?id=' + workorder_id)
|
||||
.then(resp => {
|
||||
const header = resp.headers.get("Content-disposition");
|
||||
let matches = header.match(/filename=['"]?([^'"]+)/i);
|
||||
@@ -953,7 +953,7 @@
|
||||
window.notify("error", "Fehler beim Download des AH-Blatts");
|
||||
return false;
|
||||
}
|
||||
resp.blob()
|
||||
return resp.blob();
|
||||
})
|
||||
.then(blob => {
|
||||
const url = window.URL.createObjectURL(blob);
|
||||
@@ -968,7 +968,9 @@
|
||||
window.notify("success", "Download gestartet...");
|
||||
//alert('your file has downloaded!'); // or you know, something with better UX...
|
||||
})
|
||||
.catch(() => window.notify("Fehler beim Download des AH-Blatts"));
|
||||
.catch(() => {
|
||||
window.notify("error", "Fehler beim Download des AH-Blatts");
|
||||
});
|
||||
|
||||
}
|
||||
</script>
|
||||
|
||||
@@ -401,7 +401,8 @@
|
||||
<?php foreach($preorder->adb_wohneinheit->rimo_workorders as $wo): ?>
|
||||
<h4>
|
||||
<?=$wo->rimo_name?>
|
||||
<a href="<?=self::getUrl("RimoWorkorder", "downloadAh", ["id" => $wo->id])?>" onclick="event.preventDefault(); downloadWorkorderAh(<?=$wo->id?>);"><i class="fas fa-fw fa-file-download ml-2"></i> AH Blatt</a>
|
||||
<a href="<?=self::getUrl("RimoWorkorder", "downloadAh", ["id" => $wo->id])?>" onclick="event.preventDefault(); downloadWorkorderAha(<?=$wo->id?>);"><i class="fas fa-fw fa-file-download ml-2"></i> AHA Blatt</a>
|
||||
<small class="text-danger">(beta)</small>
|
||||
</h4>
|
||||
<small id="preorder-detail-<?=$preorder->id?>-workorder-<?=$wo->id?>-del"><a href="#" onclick="if(confirm('Achtung: Löscht die Workorder in thetool, aber NICHT in RIMO!')) return deleteWorkorder(<?=$preorder->id?>, <?=$wo->id?>)" class="text-danger"><i class="far fa-times-circle"></i> Workorder löschen</a></small>
|
||||
<table class="table table-sm table-striped" id="preorder-detail-<?=$preorder->id?>-workorder-<?=$wo->id?>">
|
||||
|
||||
@@ -251,7 +251,6 @@ class PreorderApicontroller extends mfBaseApicontroller {
|
||||
"deleted" => 0
|
||||
];
|
||||
|
||||
$preorder_search = [];
|
||||
if($this->me->is("preorderaddressreporting")) {
|
||||
$user_networks_json = $this->me->getFlag("preorder_networks");
|
||||
$user_networks = json_decode($user_networks_json);
|
||||
|
||||
@@ -48,7 +48,7 @@ class OpenAccessId extends mfBaseModel {
|
||||
|
||||
|
||||
public function exportToRimoAndAssignFtu() {
|
||||
$rimo = new OpenAccessId_Helper_Rimo($this->oaid);
|
||||
//$rimo = new OpenAccessId_Helper_Rimo($this->oaid);
|
||||
|
||||
// XXX for now only support ADB Addresses
|
||||
if(!$this->adb_wohneinheit_id) {
|
||||
@@ -91,7 +91,7 @@ class OpenAccessId extends mfBaseModel {
|
||||
}
|
||||
|
||||
if($fetch_ftu) {
|
||||
$resp_data = $rimo->getFtuData($wohneinheit->extref);
|
||||
$resp_data = Rimoapi::getFtuData($this->oaid, $wohneinheit->extref);
|
||||
|
||||
if(!is_array($resp_data->ftus->item) || !count($resp_data->ftus->item)) {
|
||||
$this->log->warning(__METHOD__.": Homes ftus object has no items ".$this->oaid);
|
||||
@@ -120,7 +120,7 @@ class OpenAccessId extends mfBaseModel {
|
||||
$existing_rimo_export_data = $this->getExportData("rimo");
|
||||
//if(!is_object($existing_rimo_export_data) || (!isset($existing_rimo_export_data->oaid_id) || !$existing_rimo_export_data->oaid_id) || (!isset($existing_rimo_export_data->name) || !$existing_rimo_export_data->name)) {
|
||||
|
||||
$oaid_data = $rimo->getOaid();
|
||||
$oaid_data = Rimoapi::getOaid($this->oaid);
|
||||
// try to create, if it fails, it already exists
|
||||
if(!$oaid_data) {
|
||||
$this->createInRimo();
|
||||
@@ -135,12 +135,12 @@ class OpenAccessId extends mfBaseModel {
|
||||
$ftu_data = $wohneinheit->ftu_data;
|
||||
if($ftu_data['id'] && $ftu_data['name']) {
|
||||
|
||||
$resp_data = $rimo->getOaid();
|
||||
$resp_data = Rimoapi::getOaid($this->oaid);
|
||||
|
||||
if(!$resp_data) {
|
||||
// oaid was not found in rimo, try creating it
|
||||
$this->createInRimo();
|
||||
$resp_data = $rimo->getOaid();
|
||||
$resp_data = Rimoapi::getOaid($this->oaid);
|
||||
}
|
||||
|
||||
$assign_oaid = false;
|
||||
@@ -150,7 +150,7 @@ class OpenAccessId extends mfBaseModel {
|
||||
$old_ftu_id = $resp_data->terminiationUnit->id;
|
||||
|
||||
// unassign oaid from FTU
|
||||
$resp_data = $rimo->unassignOaid($old_ftu_id);
|
||||
$resp_data = Rimoapi::unassignOaid($this->oaid, $old_ftu_id);
|
||||
$assign_oaid = true;
|
||||
|
||||
}
|
||||
@@ -160,7 +160,7 @@ class OpenAccessId extends mfBaseModel {
|
||||
|
||||
if ($assign_oaid) {
|
||||
// assign oaid to Wohneinheit FTU
|
||||
$resp_data = $rimo->assignOaid($ftu_data['id']);
|
||||
$resp_data = Rimoapi::assignOaid($this->oaid, $ftu_data['id']);
|
||||
|
||||
// update OAID export data
|
||||
$exp_data_update = json_decode($this->export_data);
|
||||
@@ -212,9 +212,9 @@ class OpenAccessId extends mfBaseModel {
|
||||
}
|
||||
|
||||
public function createInRimo() {
|
||||
$rimo = new OpenAccessId_Helper_Rimo($this->oaid);
|
||||
//$rimo = new OpenAccessId_Helper_Rimo($this->oaid);
|
||||
|
||||
$resp_data = $rimo->createOaid();
|
||||
$resp_data = Rimoapi::createOaid($this->oaid);
|
||||
if(!$resp_data) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -126,7 +126,7 @@ class OpenAccessIdController extends mfBaseController {
|
||||
$old_preorder->save();
|
||||
}
|
||||
|
||||
$rimo = new OpenAccessId_Helper_Rimo($oaid->oaid);
|
||||
//$rimo = new OpenAccessId_Helper_Rimo($oaid->oaid);
|
||||
|
||||
// unassign oaid from rimo ftu
|
||||
//$rimo->unassignOaid($oaid)
|
||||
|
||||
@@ -25,10 +25,10 @@ class RimoWorkorder extends mfBaseModel {
|
||||
}
|
||||
}
|
||||
|
||||
public function downloadAh() {
|
||||
public function getAha() {
|
||||
if(!$this->id) return false;
|
||||
|
||||
$ah = Rimoapi::getWorkorderAhReport($this->rimo_id);
|
||||
$ah = Rimoapi::getWorkorderAhaReport($this->rimo_id);
|
||||
|
||||
return $ah;
|
||||
|
||||
|
||||
@@ -11,7 +11,7 @@ class RimoWorkorderController extends mfBaseController {
|
||||
|
||||
}
|
||||
|
||||
protected function downloadAhAction() {
|
||||
protected function downloadAhaAction() {
|
||||
$workorder_id = $this->request->id;
|
||||
|
||||
if(!$workorder_id || $workorder_id < 1) {
|
||||
@@ -27,7 +27,7 @@ class RimoWorkorderController extends mfBaseController {
|
||||
exit;
|
||||
}
|
||||
|
||||
$return = $workorder->downloadAh();
|
||||
$return = $workorder->getAha();
|
||||
if($return === false) {
|
||||
header("HTTP/1.1 500 Not Found");
|
||||
echo "Fehler beim Herunterladen des AHA-Reports aus Rimo.";
|
||||
@@ -35,7 +35,7 @@ class RimoWorkorderController extends mfBaseController {
|
||||
}
|
||||
|
||||
header("Content-type: text/pdf");
|
||||
header("Content-disposition: attachment; filename=".$workorder->name."_AHA.pdf");
|
||||
header('Content-disposition: attachment; filename="'.$workorder->rimo_name.'_AHA.pdf"');
|
||||
echo $return;
|
||||
exit;
|
||||
}
|
||||
|
||||
@@ -239,7 +239,7 @@ class Rimoapi {
|
||||
return $resp_data;
|
||||
}
|
||||
|
||||
public static function getWorkorderAhReport($rimo_id) {
|
||||
public static function getWorkorderAhaReport($rimo_id) {
|
||||
$log = mfLoghandler::singleton();
|
||||
|
||||
if(!$rimo_id) {
|
||||
@@ -293,31 +293,58 @@ class Rimoapi {
|
||||
|
||||
if(!$response) return false;
|
||||
|
||||
/* remove boundary from rimo response
|
||||
// rimo returns multipart download
|
||||
// check if multipart boundary exists
|
||||
|
||||
header:
|
||||
if(strpos($response, "\n--") !== false) {
|
||||
// file begins with \n--, so boundary exists
|
||||
$boundary_to_pos = strpos($response, "\r\n\r\n");
|
||||
|
||||
--uuid:b0b72203-db4d-4a85-9d26-b01cd08338c1
|
||||
Content-Type: application/octet-stream
|
||||
Content-Transfer-Encoding: binary
|
||||
Content-ID: <101DCY_AHA.pdf>
|
||||
if($boundary_to_pos === false) {
|
||||
$log->warn(__METHOD__.": Cannot find end of boundary");
|
||||
return false;
|
||||
}
|
||||
$new_resp = substr($response, $boundary_to_pos + 4); // including \r\n\r\n
|
||||
|
||||
footer:
|
||||
|
||||
--uuid:b0b72203-db4d-4a85-9d26-b01cd08338c1--
|
||||
*/
|
||||
// get boundary label
|
||||
$m = [];
|
||||
if(!preg_match("/\n(--[^\r\n]+)\r?\n/", $response, $m)) {
|
||||
$log->warn(__METHOD__.": Cannot find boundary label beginning");
|
||||
return false;
|
||||
}
|
||||
if(!array_key_exists(1, $m)) {
|
||||
$log->warn(__METHOD__.": Cannot find boundary label");
|
||||
return false;
|
||||
}
|
||||
$boundary_label = trim($m[1]);
|
||||
if(!$boundary_label) {
|
||||
$log->warn(__METHOD__.": boundary label empty");
|
||||
return false;
|
||||
}
|
||||
|
||||
$boundary_end = $boundary_label."--";
|
||||
|
||||
$boundary_end_pos = strrpos($new_resp, "\r\n".$boundary_end);
|
||||
//echo "$boundary_end $boundary_end_pos\n";exit;
|
||||
|
||||
$filecontent = substr($new_resp, 0, $boundary_end_pos);
|
||||
//echo "$filecontent";exit;
|
||||
|
||||
} else {
|
||||
$filecontent = $response;
|
||||
}
|
||||
|
||||
|
||||
$finfo = new Finfo(FILEINFO_MIME);
|
||||
$mimetype = $finfo->buffer($response);
|
||||
$mimetype = $finfo->buffer($filecontent);
|
||||
|
||||
var_dump($mimetype);exit;
|
||||
//var_dump($mimetype);exit;
|
||||
|
||||
if(!stripos($mimetype, "pdf")) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return $response;
|
||||
return $filecontent;
|
||||
}
|
||||
|
||||
public static function getFilenames($rimo_id) {
|
||||
|
||||
Reference in New Issue
Block a user