fixed aha parsing
This commit is contained in:
@@ -97,11 +97,11 @@ class RimoWorkorder extends mfBaseModel {
|
||||
}
|
||||
}
|
||||
|
||||
public static function autoParseForWorkorder(int $workorderId): void {
|
||||
public static function autoParseForWorkorder(int $workorderId, bool $force = false): void {
|
||||
$wo = WorkorderModel::get($workorderId);
|
||||
if (!$wo) return;
|
||||
$meta = json_decode($wo->metadata ?? '{}', true);
|
||||
if (empty($meta['dropcable']['parsed_at']) && $wo->preorderId) {
|
||||
if (($force || empty($meta['dropcable']['parsed_at'])) && $wo->preorderId) {
|
||||
$pre = new Preorder($wo->preorderId);
|
||||
$rimos = $pre->adb_wohneinheit_id ? RimoWorkorderModel::search(['adb_wohneinheit_id' => $pre->adb_wohneinheit_id]) : [];
|
||||
if (!empty($rimos[0])) (new self($rimos[0]->id))->parseAha();
|
||||
@@ -111,15 +111,29 @@ class RimoWorkorder extends mfBaseModel {
|
||||
private function parseDropkabelFromPdf(string $pdf): array {
|
||||
$result = [];
|
||||
$text = (new Parser())->parseContent($pdf)->getPages()[0]?->getText() ?? '';
|
||||
if (!preg_match('/Dropkabel:\s*\n(.+?)(?:Lage:|$)/s', $text, $m)) return $result;
|
||||
|
||||
if (!preg_match('/Dropkabel:\s*\n(.+?)(?:Lage:|$)/s', $text, $m)) {
|
||||
// Try alternative pattern without strict newline requirement
|
||||
if (!preg_match('/Dropkabel[:\s]*(.+?)(?:Lage|Anschluss|$)/si', $text, $m)) {
|
||||
return $result;
|
||||
}
|
||||
}
|
||||
|
||||
$started = false;
|
||||
foreach (explode("\n", $m[1]) as $line) {
|
||||
$line = trim($line);
|
||||
if (!$line) continue;
|
||||
if (stripos($line, 'ID') !== false && stripos($line, 'Type') !== false) { $started = true; continue; }
|
||||
if ($started && preg_match('/^(F-[A-Z0-9\(\)-]+K\d+)\s+(.+)$/i', $line, $p)) {
|
||||
|
||||
// Check for header line (ID and Type columns)
|
||||
if (stripos($line, 'ID') !== false && (stripos($line, 'Type') !== false || stripos($line, 'Typ') !== false)) {
|
||||
$started = true;
|
||||
continue;
|
||||
}
|
||||
|
||||
// Flexible cable ID pattern - matches F26-K009, F-ABC123-K01, F-XYZ(1)-K02, etc.
|
||||
if ($started && preg_match('#^([A-Z][A-Z0-9()/_-]*-K\d+)\s+(.+)$#i', $line, $p)) {
|
||||
$rest = $p[2]; $status = '';
|
||||
foreach (['Planfreigabe', 'Plan released', 'Grobplanung', 'Executed', 'Ausgeführt'] as $s)
|
||||
foreach (['Planfreigabe', 'Plan released', 'Grobplanung', 'Executed', 'Ausgeführt', 'Detailed planning', 'Detailplanung'] as $s)
|
||||
if (preg_match('/\b' . preg_quote($s, '/') . '\s*$/i', $rest)) {
|
||||
$status = $s; $rest = trim(preg_replace('/\b' . preg_quote($s, '/') . '\s*$/i', '', $rest)); break;
|
||||
}
|
||||
@@ -132,6 +146,7 @@ class RimoWorkorder extends mfBaseModel {
|
||||
'laenge_plan' => $lp, 'laenge_ist' => $li, 'status' => $status];
|
||||
}
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user