88 lines
2.9 KiB
PHP
88 lines
2.9 KiB
PHP
#!/usr/bin/php
|
|
<?php
|
|
|
|
require("../config/config.php");
|
|
|
|
define('FRONKDB_SQLDEBUG',false);
|
|
error_reporting(E_ALL & ~(E_NOTICE | E_STRICT | E_DEPRECATED));
|
|
|
|
require_once(LIBDIR."/mvcfronk/mfRouter/mfRouter.php");
|
|
require_once(LIBDIR."/mvcfronk/mfBase/mfBaseModel.php");
|
|
require_once(LIBDIR."/mvcfronk/mfBase/mfBaseController.php");
|
|
|
|
$me = new User(1);
|
|
|
|
echo "[" . date('Y-m-d H:i:s') . "] Starting AHA re-parse for workorders with technical data enabled\n";
|
|
|
|
// Get all tenant configs with showTechnicalData enabled
|
|
$tenantConfigs = WorkorderTenantConfigModel::getAll(['showTechnicalData' => 1]);
|
|
$addressIds = array_column($tenantConfigs, 'addressId');
|
|
|
|
if (empty($addressIds)) {
|
|
echo "[" . date('Y-m-d H:i:s') . "] No tenant configs with showTechnicalData enabled found\n";
|
|
exit;
|
|
}
|
|
|
|
echo "[" . date('Y-m-d H:i:s') . "] Found " . count($tenantConfigs) . " tenant configs with technical data enabled\n";
|
|
|
|
// Get all active workorders
|
|
$activeStatuses = ['new', 'assigned', 'scheduled', 'in_progress', 'correction_requested',
|
|
'intervention_required', 'civil_engineering_required', 'civil_engineering_completed',
|
|
'problem_solved', 'documented'];
|
|
|
|
$workorders = WorkorderModel::getAll(['status' => $activeStatuses]);
|
|
|
|
echo "[" . date('Y-m-d H:i:s') . "] Found " . count($workorders) . " active workorders\n";
|
|
|
|
$parsedCount = 0;
|
|
$skippedCount = 0;
|
|
$errorCount = 0;
|
|
|
|
foreach ($workorders as $workorder) {
|
|
// Check if workorder belongs to a tenant with technical data enabled
|
|
if (!$workorder->preorderId) {
|
|
$skippedCount++;
|
|
continue;
|
|
}
|
|
|
|
$preorder = new Preorder($workorder->preorderId);
|
|
if (!$preorder->id || !$preorder->adb_wohneinheit_id) {
|
|
$skippedCount++;
|
|
continue;
|
|
}
|
|
|
|
// Find RimoWorkorder for this preorder's wohneinheit
|
|
$rimoWorkorders = RimoWorkorderModel::search(['adb_wohneinheit_id' => $preorder->adb_wohneinheit_id]);
|
|
if (empty($rimoWorkorders)) {
|
|
$skippedCount++;
|
|
continue;
|
|
}
|
|
|
|
$rimoWorkorder = new RimoWorkorder($rimoWorkorders[0]->id);
|
|
if (!$rimoWorkorder->id) {
|
|
$skippedCount++;
|
|
continue;
|
|
}
|
|
|
|
echo "[" . date('Y-m-d H:i:s') . "] Parsing AHA for Workorder #{$workorder->id} (RimoWorkorder #{$rimoWorkorder->id})... ";
|
|
|
|
try {
|
|
$result = $rimoWorkorder->parseAha();
|
|
if ($result['success']) {
|
|
echo "OK - {$result['dropkabel_count']} cables, map: " . ($result['has_map'] ? 'yes' : 'no') . "\n";
|
|
$parsedCount++;
|
|
} else {
|
|
echo "FAILED - {$result['message']}\n";
|
|
$errorCount++;
|
|
}
|
|
} catch (Exception $e) {
|
|
echo "ERROR - " . $e->getMessage() . "\n";
|
|
$errorCount++;
|
|
}
|
|
|
|
// Small delay to avoid overloading the Rimo API
|
|
usleep(100000); // 100ms
|
|
}
|
|
|
|
echo "[" . date('Y-m-d H:i:s') . "] Completed: Parsed: $parsedCount, Skipped: $skippedCount, Errors: $errorCount\n";
|