Files
wms-app/app/cron/etl_gl_maintenance.php
T

44 lines
1.4 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<?php
/**
* etl_gl_maintenance.php — Called by Node.js scheduler every hour.
* Checks and repairs etl_gl_summary (GL summary) for companies in the current slot.
* For stock ETL maintenance use etl_stock_maintenance.php (not yet implemented).
*
* Body: { slot: 14 } (0–23, = HOUR(NOW()) from Node.js)
*/
require '../../assets/utils/cron_auth.php';
require_once '../../assets/utils/classes_ac/EtlManager.php';
$slot = (int)($data['slot'] ?? -1);
if ($slot < 0 || $slot > 23) {
http_response_code(400);
exit(json_encode(['success' => 0, 'message' => 'Invalid slot.']));
}
// Fetch companies whose slot matches this hour
$sth = $pdo1->prepare(
"SELECT company_id FROM company_list WHERE company_id % 24 = :slot"
);
$sth->execute([':slot' => $slot]);
$companies = $sth->fetchAll(PDO::FETCH_COLUMN);
$results = [];
foreach ($companies as $company_id) {
try {
$etl = new EtlManager($pdo2, $pdo1, (int)$company_id);
$result = $etl->checkAndRepair();
$results[] = [
'company_id' => $company_id,
'gaps_found' => $result['gaps_found'],
'periods_rebuilt' => $result['periods_rebuilt'],
];
} catch (Exception $e) {
$results[] = ['company_id' => $company_id, 'error' => $e->getMessage()];
}
}
$answer['success'] = 1;
$answer['slot'] = $slot;
$answer['results'] = $results;
exit(json_encode($answer));