Add daily stock lot sellout forecast
This commit is contained in:
1 parent
9a1192ae81
commit
1639960ab6
9 files changed
+440
-3
No files matched your search
@@ -0,0 +1,33 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
require_once __DIR__ . '/../shared/db.php';
|
||||
require_once __DIR__ . '/../erp/lager/forecast.php';
|
||||
|
||||
if (PHP_SAPI !== 'cli') {
|
||||
http_response_code(404);
|
||||
exit;
|
||||
}
|
||||
|
||||
$lockHandle = fopen(dirname(__DIR__, 2) . '/runtime/naurua-erp-cron.lock', 'c');
|
||||
if ($lockHandle === false || !flock($lockHandle, LOCK_EX | LOCK_NB)) {
|
||||
echo json_encode(['status' => 'skipped', 'reason' => 'already_running'], JSON_THROW_ON_ERROR) . PHP_EOL;
|
||||
exit;
|
||||
}
|
||||
|
||||
$env = expand_env_values(parse_env_file(dirname(__DIR__, 2) . '/.env'));
|
||||
$pdo = connect_database($env);
|
||||
|
||||
try {
|
||||
$jobs = [
|
||||
'erp.lager.stock_lot_forecast_refresh' => static fn (): array => run_lager_stock_lot_forecast($pdo),
|
||||
];
|
||||
$results = [];
|
||||
foreach ($jobs as $name => $job) {
|
||||
$results[$name] = $job();
|
||||
}
|
||||
echo json_encode(['status' => 'done', 'jobs' => $results], JSON_THROW_ON_ERROR | JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES) . PHP_EOL;
|
||||
} catch (Throwable $error) {
|
||||
fwrite(STDERR, $error->getMessage() . PHP_EOL);
|
||||
exit(1);
|
||||
}
|
||||
Reference in new issue
Block a user