[FIX] Simulator + ServicesController: allineamento a schema DB reale

simulate-nis2.php:
- sector: ict → ict_services, healthcare → health (enum DB corretto)
- employee_count (non employees_count) per OrganizationController

ServicesController::provision():
- INSERT organizations: rimossi campi non esistenti (legal_form, ateco_code, etc.)
- Usa colonne reali: name, vat_number, employee_count, sector, entity_type, is_active
- entity_type: voluntary → not_applicable (enum non supporta voluntary)

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
DevEnv nis2-agile 2026-03-09 09:30:20 +01:00
parent eb31a0a504
commit 48317e0556
2 changed files with 13 additions and 15 deletions

View File

@ -548,8 +548,12 @@ class ServicesController extends BaseController
]; ];
$rawSector = strtolower($company['sector'] ?? 'ict'); $rawSector = strtolower($company['sector'] ?? 'ict');
$nis2Sector = $sectorMap[$rawSector] ?? $rawSector; $nis2Sector = $sectorMap[$rawSector] ?? $rawSector;
$nis2EntityType = in_array($company['nis2_entity_type'] ?? '', ['essential', 'important', 'voluntary']) $rawEntityType = $company['nis2_entity_type'] ?? 'important';
? $company['nis2_entity_type'] : 'important'; $nis2EntityType = match($rawEntityType) {
'essential' => 'essential',
'voluntary' => 'not_applicable',
default => 'important',
};
if ($existing) { if ($existing) {
$orgId = (int) $existing['id']; $orgId = (int) $existing['id'];
@ -557,22 +561,16 @@ class ServicesController extends BaseController
// ── 4. Crea organizzazione ─────────────────────────────────── // ── 4. Crea organizzazione ───────────────────────────────────
Database::query( Database::query(
'INSERT INTO organizations 'INSERT INTO organizations
(name, legal_form, vat_number, fiscal_code, ateco_code, ateco_description, (name, vat_number, fiscal_code,
legal_address, pec, phone, annual_turnover_eur, employees, annual_turnover_eur, employee_count,
sector, nis2_entity_type, status, sector, entity_type, is_active,
provisioned_by, provisioned_at, license_plan, license_expires_at, provisioned_by, provisioned_at, license_plan, license_expires_at,
license_max_users, lg231_company_id, lg231_order_id) license_max_users, lg231_company_id, lg231_order_id)
VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,\'active\',?,NOW(),?,?,?,?,?)', VALUES (?,?,?,?,?,?,?,1,?,NOW(),?,?,?,?,?)',
[ [
$ragioneSociale, $ragioneSociale,
$company['forma_giuridica'] ?? null,
$partitaIva, $partitaIva,
$company['codice_fiscale'] ?? null, $company['codice_fiscale'] ?? null,
$company['ateco_code'] ?? null,
$company['ateco_description'] ?? null,
$company['sede_legale'] ?? null,
$company['pec'] ?? null,
$company['telefono'] ?? null,
$company['fatturato_annuo'] ?? null, $company['fatturato_annuo'] ?? null,
$company['numero_dipendenti'] ?? null, $company['numero_dipendenti'] ?? null,
$nis2Sector, $nis2Sector,

View File

@ -426,7 +426,7 @@ $COMPANIES = [
'ateco_desc' => 'Produzione di software non connesso all\'edizione', 'ateco_desc' => 'Produzione di software non connesso all\'edizione',
'employees' => 320, 'employees' => 320,
'annual_turnover'=> 18500000, 'annual_turnover'=> 18500000,
'sector' => 'ict', 'sector' => 'ict_services',
'nis2_type' => 'essential', 'nis2_type' => 'essential',
'city' => 'Milano', 'city' => 'Milano',
'province' => 'MI', 'province' => 'MI',
@ -468,7 +468,7 @@ $COMPANIES = [
'ateco_desc' => 'Servizi ospedalieri', 'ateco_desc' => 'Servizi ospedalieri',
'employees' => 750, 'employees' => 750,
'annual_turnover'=> 42000000, 'annual_turnover'=> 42000000,
'sector' => 'healthcare', 'sector' => 'health',
'nis2_type' => 'important', 'nis2_type' => 'important',
'city' => 'Roma', 'city' => 'Roma',
'province' => 'RM', 'province' => 'RM',
@ -644,7 +644,7 @@ foreach ($COMPANIES as $slug => $comp) {
'vat_number' => $comp['vat_number'], 'vat_number' => $comp['vat_number'],
'ateco_code' => $comp['ateco_code'], 'ateco_code' => $comp['ateco_code'],
'sector' => $comp['sector'], 'sector' => $comp['sector'],
'employees_count' => $comp['employees'], 'employee_count' => $comp['employees'],
'annual_turnover_eur' => $comp['annual_turnover'], 'annual_turnover_eur' => $comp['annual_turnover'],
'city' => $comp['city'], 'city' => $comp['city'],
'province' => $comp['province'], 'province' => $comp['province'],