Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
38a508553d | ||
|
|
a2e838cd01 | ||
|
|
b47c929a56 | ||
|
|
2ff00a077d | ||
|
|
b6b2ad0a9b | ||
|
|
7ed834935d | ||
|
|
3c5845bf6b | ||
|
|
21790ca250 | ||
|
|
2c7ef3f7af | ||
|
|
c7f9f7fe4b | ||
|
|
c172724f28 | ||
|
|
f05cecd947 | ||
|
|
f1db43f207 | ||
|
|
143ae01b57 | ||
|
|
2cf3f041be | ||
|
|
9fffafc447 | ||
|
|
466fb29089 | ||
|
|
b23d7736c0 | ||
|
|
5b1593ed78 | ||
|
|
ff7706497d | ||
|
|
cb002c60f9 | ||
|
|
74b91d0c8a | ||
|
|
53c8f2b4ab | ||
|
|
b7baea652b | ||
|
|
9e6d9e45cb | ||
|
|
82b587ea6a | ||
|
|
88e7e8de65 | ||
|
|
b265769047 | ||
|
|
9a40f5cbd0 | ||
|
|
ce579d1667 | ||
|
|
bc6d4604e3 |
@@ -12,8 +12,8 @@ android {
|
|||||||
applicationId = "com.korexlabs.dhinspeccion"
|
applicationId = "com.korexlabs.dhinspeccion"
|
||||||
minSdk = 26
|
minSdk = 26
|
||||||
targetSdk = 36
|
targetSdk = 36
|
||||||
versionCode = 24
|
versionCode = 25
|
||||||
versionName = "0.15.2"
|
versionName = "0.16.0"
|
||||||
|
|
||||||
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
|
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
|
||||||
vectorDrawables.useSupportLibrary = true
|
vectorDrawables.useSupportLibrary = true
|
||||||
|
|||||||
@@ -168,10 +168,6 @@ class MainViewModel(application: Application) : AndroidViewModel(application) {
|
|||||||
error = "Elegí si el Acta es urgente o no urgente."
|
error = "Elegí si el Acta es urgente o no urgente."
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if (asset == null) {
|
|
||||||
error = "Seleccioná primero una Instalación o Subinstalación para iniciar el Acta."
|
|
||||||
return
|
|
||||||
}
|
|
||||||
if (acts.any { it.status == "DRAFT" }) {
|
if (acts.any { it.status == "DRAFT" }) {
|
||||||
error = "Ya existe un Acta en borrador. Bloqueala o cancelala antes de crear la siguiente."
|
error = "Ya existe un Acta en borrador. Bloqueala o cancelala antes de crear la siguiente."
|
||||||
return
|
return
|
||||||
@@ -179,7 +175,7 @@ class MainViewModel(application: Application) : AndroidViewModel(application) {
|
|||||||
launchBusy {
|
launchBusy {
|
||||||
val created = actsRepository.create(
|
val created = actsRepository.create(
|
||||||
currentVisit.id,
|
currentVisit.id,
|
||||||
asset.id,
|
asset?.id,
|
||||||
currentVisit.code,
|
currentVisit.code,
|
||||||
urgency,
|
urgency,
|
||||||
)
|
)
|
||||||
@@ -188,17 +184,18 @@ class MainViewModel(application: Application) : AndroidViewModel(application) {
|
|||||||
loadActsInternal(currentVisit.id, selectDraft = false)
|
loadActsInternal(currentVisit.id, selectDraft = false)
|
||||||
val urgencyLabel = if (urgency == "URGENT") "urgente" else "no urgente"
|
val urgencyLabel = if (urgency == "URGENT") "urgente" else "no urgente"
|
||||||
notice = "${created.code} creada como $urgencyLabel. Los Hallazgos nuevos quedarán vinculados explícitamente a esta Acta."
|
notice = "${created.code} creada como $urgencyLabel. Los Hallazgos nuevos quedarán vinculados explícitamente a esta Acta."
|
||||||
if (selectedFieldAsset?.capture?.readyForFinding == true) {
|
if (asset != null && selectedFieldAsset?.capture?.readyForFinding == true) {
|
||||||
loadFindingOptionsInternal(currentVisit.id, asset.id, created.id)
|
loadFindingOptionsInternal(currentVisit.id, asset.id, created.id)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun createAct(urgency: String = "NON_URGENT") = createActForSelectedInventory(urgency)
|
||||||
|
|
||||||
fun searchInventory(search: String, parentId: String? = null) {
|
fun searchInventory(search: String, parentId: String? = null) {
|
||||||
val currentVisit = visit ?: return
|
val currentVisit = visit ?: return
|
||||||
launchBusy {
|
launchBusy {
|
||||||
val effectiveParentId = parentId ?: inventoryParentId ?: currentVisit.scopeAsset?.id ?: currentVisit.operationalArea?.id
|
inventory = repository.fieldInventory(currentVisit.id, search, parentId).data
|
||||||
inventory = repository.fieldInventory(currentVisit.id, search, effectiveParentId).data
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -329,7 +329,7 @@ class MobileActsRepository(context: Context) {
|
|||||||
|
|
||||||
suspend fun create(
|
suspend fun create(
|
||||||
visitId: String,
|
visitId: String,
|
||||||
assetId: String,
|
assetId: String? = null,
|
||||||
visitCode: String,
|
visitCode: String,
|
||||||
urgency: String = "NON_URGENT",
|
urgency: String = "NON_URGENT",
|
||||||
): MobileActDetail = authorized { session ->
|
): MobileActDetail = authorized { session ->
|
||||||
@@ -341,7 +341,7 @@ class MobileActsRepository(context: Context) {
|
|||||||
urgency = urgency,
|
urgency = urgency,
|
||||||
title = "Acta de inspección $visitCode",
|
title = "Acta de inspección $visitCode",
|
||||||
summary = "Acta de inspección en curso. Los Hallazgos y observaciones se incorporan de forma trazable durante la inspección.",
|
summary = "Acta de inspección en curso. Los Hallazgos y observaciones se incorporan de forma trazable durante la inspección.",
|
||||||
assetIds = listOf(assetId),
|
assetIds = listOfNotNull(assetId),
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -86,7 +86,10 @@ fun F3VisitRoot(model: MainViewModel) {
|
|||||||
inventoryMode = true
|
inventoryMode = true
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
inventoryMode -> F3FieldInventoryScreen(model, onBack = { inventoryMode = false })
|
inventoryMode -> F3FieldInventoryScreen(model, onBack = {
|
||||||
|
inventoryMode = false
|
||||||
|
actsMode = true
|
||||||
|
})
|
||||||
else -> F3VisitOverview(
|
else -> F3VisitOverview(
|
||||||
model = model,
|
model = model,
|
||||||
onInventory = { inventoryMode = true },
|
onInventory = { inventoryMode = true },
|
||||||
@@ -119,6 +122,9 @@ private fun F3VisitOverview(
|
|||||||
}
|
}
|
||||||
Text(visit.code, style = MaterialTheme.typography.headlineMedium, fontWeight = FontWeight.Bold)
|
Text(visit.code, style = MaterialTheme.typography.headlineMedium, fontWeight = FontWeight.Bold)
|
||||||
Text("${visit.operatorCompany?.name ?: "Sin operadora"} · ${visit.operationalArea?.name ?: "Sin área"}")
|
Text("${visit.operatorCompany?.name ?: "Sin operadora"} · ${visit.operationalArea?.name ?: "Sin área"}")
|
||||||
|
visit.scopeAsset?.let {
|
||||||
|
Text("Yacimiento: ${it.name}", style = MaterialTheme.typography.bodyMedium, fontWeight = FontWeight.SemiBold)
|
||||||
|
}
|
||||||
visit.plannedStartAt?.let {
|
visit.plannedStartAt?.let {
|
||||||
Text("Planificada: ${f3ShortDate(it)}", style = MaterialTheme.typography.bodySmall)
|
Text("Planificada: ${f3ShortDate(it)}", style = MaterialTheme.typography.bodySmall)
|
||||||
}
|
}
|
||||||
@@ -138,10 +144,10 @@ private fun F3VisitOverview(
|
|||||||
colors = CardDefaults.cardColors(containerColor = MaterialTheme.colorScheme.primaryContainer),
|
colors = CardDefaults.cardColors(containerColor = MaterialTheme.colorScheme.primaryContainer),
|
||||||
) {
|
) {
|
||||||
Column(Modifier.padding(14.dp), verticalArrangement = Arrangement.spacedBy(8.dp)) {
|
Column(Modifier.padding(14.dp), verticalArrangement = Arrangement.spacedBy(8.dp)) {
|
||||||
Text("La inspección todavía no comenzó", fontWeight = FontWeight.Bold)
|
Text("Todo listo para comenzar", fontWeight = FontWeight.Bold)
|
||||||
Text("Iniciarla registra fecha/hora real y tu usuario como actor de campo.")
|
Text("Al iniciar, pasás directamente a las Actas de esta inspección.")
|
||||||
Button(
|
Button(
|
||||||
onClick = { model.startVisit() },
|
onClick = { model.startVisit(); onActs() },
|
||||||
enabled = !model.busy,
|
enabled = !model.busy,
|
||||||
modifier = Modifier.fillMaxWidth(),
|
modifier = Modifier.fillMaxWidth(),
|
||||||
) { Text(if (model.busy) "Iniciando…" else "Iniciar inspección") }
|
) { Text(if (model.busy) "Iniciando…" else "Iniciar inspección") }
|
||||||
@@ -150,12 +156,12 @@ private fun F3VisitOverview(
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (visit.status == "IN_PROGRESS") {
|
if (visit.status == "IN_PROGRESS") {
|
||||||
Button(onClick = onInventory, modifier = Modifier.fillMaxWidth()) {
|
Button(onClick = onActs, modifier = Modifier.fillMaxWidth()) {
|
||||||
Text("Abrir Inventario de campo")
|
|
||||||
}
|
|
||||||
OutlinedButton(onClick = onActs, modifier = Modifier.fillMaxWidth()) {
|
|
||||||
val open = model.acts.count { it.status == "DRAFT" || it.status == "READY" }
|
val open = model.acts.count { it.status == "DRAFT" || it.status == "READY" }
|
||||||
Text("Actas de la inspección · ${model.acts.size}${if (open > 0) " · $open abiertas" else ""}")
|
Text("Abrir Actas · ${model.acts.size}${if (open > 0) " · $open abiertas" else ""}")
|
||||||
|
}
|
||||||
|
OutlinedButton(onClick = onInventory, modifier = Modifier.fillMaxWidth()) {
|
||||||
|
Text("Inventario / Hallazgos")
|
||||||
}
|
}
|
||||||
} else if (visit.status == "CLOSED") {
|
} else if (visit.status == "CLOSED") {
|
||||||
OutlinedButton(onClick = onActs, modifier = Modifier.fillMaxWidth()) {
|
OutlinedButton(onClick = onActs, modifier = Modifier.fillMaxWidth()) {
|
||||||
@@ -163,7 +169,7 @@ private fun F3VisitOverview(
|
|||||||
}
|
}
|
||||||
} else if (visit.status == "PLANNED") {
|
} else if (visit.status == "PLANNED") {
|
||||||
Text(
|
Text(
|
||||||
"Primero iniciá la inspección para habilitar altas, fotografías, Actas y Hallazgos.",
|
"Primero iniciá la inspección para habilitar Actas, Hallazgos y altas de campo.",
|
||||||
style = MaterialTheme.typography.bodySmall,
|
style = MaterialTheme.typography.bodySmall,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
@@ -209,7 +215,9 @@ private fun F3FieldInventoryScreen(model: MainViewModel, onBack: () -> Unit) {
|
|||||||
var search by rememberSaveable(visit.id) { mutableStateOf("") }
|
var search by rememberSaveable(visit.id) { mutableStateOf("") }
|
||||||
var showCreate by rememberSaveable(visit.id) { mutableStateOf(false) }
|
var showCreate by rememberSaveable(visit.id) { mutableStateOf(false) }
|
||||||
var parentId by rememberSaveable(visit.id) { mutableStateOf<String?>(null) }
|
var parentId by rememberSaveable(visit.id) { mutableStateOf<String?>(null) }
|
||||||
var parentLabel by rememberSaveable(visit.id) { mutableStateOf("Área de la inspección") }
|
var parentLabel by rememberSaveable(visit.id) {
|
||||||
|
mutableStateOf(visit.scopeAsset?.name ?: "Yacimiento de la inspección")
|
||||||
|
}
|
||||||
var name by rememberSaveable(visit.id) { mutableStateOf("") }
|
var name by rememberSaveable(visit.id) { mutableStateOf("") }
|
||||||
var commonName by rememberSaveable(visit.id) { mutableStateOf("") }
|
var commonName by rememberSaveable(visit.id) { mutableStateOf("") }
|
||||||
var selectedTypeId by rememberSaveable(visit.id) { mutableStateOf<String?>(null) }
|
var selectedTypeId by rememberSaveable(visit.id) { mutableStateOf<String?>(null) }
|
||||||
@@ -323,10 +331,10 @@ private fun F3FieldInventoryScreen(model: MainViewModel, onBack: () -> Unit) {
|
|||||||
horizontalArrangement = Arrangement.SpaceBetween,
|
horizontalArrangement = Arrangement.SpaceBetween,
|
||||||
verticalAlignment = Alignment.CenterVertically,
|
verticalAlignment = Alignment.CenterVertically,
|
||||||
) {
|
) {
|
||||||
OutlinedButton(onClick = onBack) { Text("Volver") }
|
OutlinedButton(onClick = onBack) { Text("Acta") }
|
||||||
Column(horizontalAlignment = Alignment.End) {
|
Column(horizontalAlignment = Alignment.End) {
|
||||||
Text("Inventario de campo", style = MaterialTheme.typography.titleLarge, fontWeight = FontWeight.Bold)
|
Text("Nuevo Hallazgo", style = MaterialTheme.typography.titleLarge, fontWeight = FontWeight.Bold)
|
||||||
Text("Área → Yacimiento → Instalación → Subinstalación", style = MaterialTheme.typography.bodySmall)
|
Text("Elegí una Instalación o Subinstalación", style = MaterialTheme.typography.bodySmall)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Column(Modifier.padding(horizontal = 16.dp)) { F3MessageStrip(model) }
|
Column(Modifier.padding(horizontal = 16.dp)) { F3MessageStrip(model) }
|
||||||
@@ -410,170 +418,182 @@ private fun F3FieldInventoryScreen(model: MainViewModel, onBack: () -> Unit) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Row(
|
Card(Modifier.fillMaxWidth().padding(horizontal = 16.dp, vertical = 4.dp)) {
|
||||||
Modifier.fillMaxWidth().padding(horizontal = 16.dp),
|
Column(Modifier.padding(12.dp), verticalArrangement = Arrangement.spacedBy(8.dp)) {
|
||||||
verticalAlignment = Alignment.CenterVertically,
|
Text("¿Dónde encontraste el Hallazgo?", fontWeight = FontWeight.Bold)
|
||||||
) {
|
OutlinedTextField(
|
||||||
OutlinedTextField(
|
value = search,
|
||||||
value = search,
|
onValueChange = { search = it },
|
||||||
onValueChange = { search = it },
|
label = { Text("Buscar instalación o subinstalación") },
|
||||||
label = { Text("Buscar por nombre o código") },
|
modifier = Modifier.fillMaxWidth(),
|
||||||
modifier = Modifier.weight(1f),
|
singleLine = true,
|
||||||
singleLine = true,
|
)
|
||||||
)
|
Row(
|
||||||
Spacer(Modifier.width(8.dp))
|
Modifier.fillMaxWidth(),
|
||||||
Button(onClick = { model.searchInventory(search) }, enabled = !model.busy) { Text("Buscar") }
|
horizontalArrangement = Arrangement.spacedBy(8.dp),
|
||||||
}
|
) {
|
||||||
|
Button(
|
||||||
Row(
|
onClick = { model.searchInventory(search) },
|
||||||
Modifier.fillMaxWidth().padding(16.dp),
|
enabled = !model.busy,
|
||||||
horizontalArrangement = Arrangement.SpaceBetween,
|
modifier = Modifier.weight(1f),
|
||||||
verticalAlignment = Alignment.CenterVertically,
|
) { Text("Buscar") }
|
||||||
) {
|
OutlinedButton(
|
||||||
Column {
|
onClick = {
|
||||||
Text("Alta en campo", fontWeight = FontWeight.Bold)
|
showCreate = !showCreate
|
||||||
Text("Padre: $parentLabel", style = MaterialTheme.typography.bodySmall)
|
if (showCreate) model.loadFieldTypes(parentId)
|
||||||
|
},
|
||||||
|
modifier = Modifier.weight(1f),
|
||||||
|
) { Text(if (showCreate) "Cancelar" else "+ Agregar") }
|
||||||
|
}
|
||||||
}
|
}
|
||||||
OutlinedButton(onClick = {
|
|
||||||
showCreate = !showCreate
|
|
||||||
if (showCreate) model.loadFieldTypes(parentId)
|
|
||||||
}) { Text(if (showCreate) "Ocultar" else "Agregar") }
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (showCreate) {
|
if (showCreate) {
|
||||||
Column(
|
Card(Modifier.fillMaxWidth().padding(horizontal = 16.dp, vertical = 6.dp)) {
|
||||||
Modifier
|
Column(
|
||||||
.fillMaxWidth()
|
Modifier
|
||||||
.padding(horizontal = 16.dp)
|
.fillMaxWidth()
|
||||||
.verticalScroll(rememberScrollState())
|
.padding(12.dp)
|
||||||
.weight(1f, fill = false),
|
.verticalScroll(rememberScrollState())
|
||||||
verticalArrangement = Arrangement.spacedBy(10.dp),
|
.weight(1f, fill = false),
|
||||||
) {
|
verticalArrangement = Arrangement.spacedBy(10.dp),
|
||||||
if (parentId != null) {
|
) {
|
||||||
OutlinedButton(onClick = {
|
Text("Nueva alta de campo", style = MaterialTheme.typography.titleMedium, fontWeight = FontWeight.Bold)
|
||||||
parentId = null
|
Text("Ubicación: $parentLabel", style = MaterialTheme.typography.bodySmall)
|
||||||
parentLabel = "Área de la inspección"
|
if (parentId != null) {
|
||||||
resetCreateForm()
|
OutlinedButton(onClick = {
|
||||||
selectedTypeId = null
|
parentId = null
|
||||||
model.loadFieldTypes(null)
|
parentLabel = visit.scopeAsset?.name ?: "Yacimiento de la inspección"
|
||||||
}) { Text("Volver al Área") }
|
resetCreateForm()
|
||||||
}
|
selectedTypeId = null
|
||||||
|
model.loadFieldTypes(null)
|
||||||
|
}) { Text("Volver al Yacimiento") }
|
||||||
|
}
|
||||||
|
|
||||||
if (model.fieldTypes.isEmpty()) {
|
if (model.fieldTypes.isEmpty()) {
|
||||||
Text("Este nivel no admite más hijos estructurales.")
|
Text("No hay un tipo disponible para esta ubicación.")
|
||||||
} else {
|
} else {
|
||||||
Text("Vas a crear", style = MaterialTheme.typography.bodySmall)
|
Text("Tipo de registro", style = MaterialTheme.typography.bodySmall)
|
||||||
LazyRow(horizontalArrangement = Arrangement.spacedBy(8.dp)) {
|
LazyRow(horizontalArrangement = Arrangement.spacedBy(8.dp)) {
|
||||||
items(model.fieldTypes, key = { it.id }) { type ->
|
items(model.fieldTypes, key = { it.id }) { type ->
|
||||||
AssistChip(
|
AssistChip(
|
||||||
onClick = {
|
onClick = {
|
||||||
selectedTypeId = type.id
|
selectedTypeId = type.id
|
||||||
selectedFamilyId = null
|
selectedFamilyId = null
|
||||||
attributeValues.clear()
|
attributeValues.clear()
|
||||||
},
|
},
|
||||||
label = { Text(if (type.id == selectedTypeId) "✓ ${type.name}" else type.name) },
|
label = { Text(if (type.id == selectedTypeId) "✓ ${type.name}" else type.name) },
|
||||||
)
|
)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if (selectedType?.familyRequired == true) {
|
if (selectedType?.familyRequired == true) {
|
||||||
Text("Familia técnica", fontWeight = FontWeight.Bold)
|
Text("Clasificación", fontWeight = FontWeight.Bold)
|
||||||
Text(
|
Text(
|
||||||
"Elegí la que corresponda al Excel. Si no existe, usá Otro / no catalogado; nunca quedás bloqueado.",
|
"Elegí el tipo técnico. Si no está catalogado, usá Otro / no catalogado.",
|
||||||
style = MaterialTheme.typography.bodySmall,
|
style = MaterialTheme.typography.bodySmall,
|
||||||
)
|
)
|
||||||
LazyRow(horizontalArrangement = Arrangement.spacedBy(8.dp)) {
|
LazyRow(horizontalArrangement = Arrangement.spacedBy(8.dp)) {
|
||||||
items(selectedType.families, key = { it.id }) { family ->
|
items(selectedType.families, key = { it.id }) { family ->
|
||||||
AssistChip(
|
AssistChip(
|
||||||
onClick = { selectedFamilyId = family.id },
|
onClick = { selectedFamilyId = family.id },
|
||||||
label = {
|
label = {
|
||||||
val prefix = when {
|
val prefix = when {
|
||||||
selectedFamilyId == family.id -> "✓ "
|
selectedFamilyId == family.id -> "✓ "
|
||||||
family.isOther -> "+ "
|
family.isOther -> "+ "
|
||||||
else -> ""
|
else -> ""
|
||||||
}
|
}
|
||||||
Text(prefix + family.name)
|
Text(prefix + family.name)
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
selectedFamily?.let { family ->
|
||||||
|
if (family.isOther) {
|
||||||
|
Text(
|
||||||
|
"Se registrará como no catalogado para revisión posterior en oficina.",
|
||||||
|
color = MaterialTheme.colorScheme.secondary,
|
||||||
|
style = MaterialTheme.typography.bodySmall,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
if (family.informationLabels.isNotEmpty()) {
|
||||||
|
Text(
|
||||||
|
"Información esperada: ${family.informationLabels.joinToString(" · ")}",
|
||||||
|
style = MaterialTheme.typography.bodySmall,
|
||||||
|
)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
selectedFamily?.let { family ->
|
|
||||||
if (family.isOther) {
|
|
||||||
Text(
|
|
||||||
"Se registrará como familia no catalogada para revisión posterior en oficina.",
|
|
||||||
color = MaterialTheme.colorScheme.secondary,
|
|
||||||
style = MaterialTheme.typography.bodySmall,
|
|
||||||
)
|
|
||||||
}
|
|
||||||
if (family.informationLabels.isNotEmpty()) {
|
|
||||||
Text(
|
|
||||||
"Información esperada: ${family.informationLabels.joinToString(" · ")}",
|
|
||||||
style = MaterialTheme.typography.bodySmall,
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
OutlinedTextField(
|
|
||||||
value = name,
|
|
||||||
onValueChange = { name = it },
|
|
||||||
label = { Text("Nombre identificable *") },
|
|
||||||
modifier = Modifier.fillMaxWidth(),
|
|
||||||
)
|
|
||||||
OutlinedTextField(
|
|
||||||
value = commonName,
|
|
||||||
onValueChange = { commonName = it },
|
|
||||||
label = { Text("Nombre habitual") },
|
|
||||||
modifier = Modifier.fillMaxWidth(),
|
|
||||||
)
|
|
||||||
|
|
||||||
selectedType?.attributes?.forEach { definition ->
|
|
||||||
OutlinedTextField(
|
OutlinedTextField(
|
||||||
value = attributeValues[definition.code].orEmpty(),
|
value = name,
|
||||||
onValueChange = { attributeValues[definition.code] = it },
|
onValueChange = { name = it },
|
||||||
label = { Text(definition.name + if (definition.isRequired) " *" else "") },
|
label = { Text("Nombre o código identificable *") },
|
||||||
supportingText = {
|
modifier = Modifier.fillMaxWidth(),
|
||||||
val details = listOfNotNull(definition.unit, definition.options?.toString()).joinToString(" · ")
|
)
|
||||||
if (details.isNotBlank()) Text(details)
|
OutlinedTextField(
|
||||||
},
|
value = commonName,
|
||||||
keyboardOptions = KeyboardOptions(
|
onValueChange = { commonName = it },
|
||||||
keyboardType = if (
|
label = { Text("Nombre habitual") },
|
||||||
definition.dataType.uppercase() in setOf("NUMBER", "DECIMAL", "INTEGER", "FLOAT")
|
|
||||||
) KeyboardType.Decimal else KeyboardType.Text,
|
|
||||||
),
|
|
||||||
modifier = Modifier.fillMaxWidth(),
|
modifier = Modifier.fillMaxWidth(),
|
||||||
)
|
)
|
||||||
}
|
|
||||||
|
|
||||||
val attributesReady = selectedType?.attributes
|
selectedType?.attributes?.forEach { definition ->
|
||||||
?.filter { it.isRequired }
|
OutlinedTextField(
|
||||||
?.all { attributeValues[it.code].orEmpty().isNotBlank() }
|
value = attributeValues[definition.code].orEmpty(),
|
||||||
?: false
|
onValueChange = { attributeValues[definition.code] = it },
|
||||||
val familyReady = selectedType?.familyRequired != true || selectedFamilyId != null
|
label = { Text(definition.name + if (definition.isRequired) " *" else "") },
|
||||||
Button(
|
supportingText = {
|
||||||
onClick = {
|
val details = listOfNotNull(definition.unit, definition.options?.toString()).joinToString(" · ")
|
||||||
if (f3HasLocation(context)) createWithLocation()
|
if (details.isNotBlank()) Text(details)
|
||||||
else locationPermissionLauncher.launch(
|
},
|
||||||
arrayOf(
|
keyboardOptions = KeyboardOptions(
|
||||||
Manifest.permission.ACCESS_FINE_LOCATION,
|
keyboardType = if (
|
||||||
Manifest.permission.ACCESS_COARSE_LOCATION,
|
definition.dataType.uppercase() in setOf("NUMBER", "DECIMAL", "INTEGER", "FLOAT")
|
||||||
|
) KeyboardType.Decimal else KeyboardType.Text,
|
||||||
),
|
),
|
||||||
|
modifier = Modifier.fillMaxWidth(),
|
||||||
)
|
)
|
||||||
},
|
}
|
||||||
enabled = selectedType != null && name.isNotBlank() && attributesReady && familyReady && !model.busy,
|
|
||||||
modifier = Modifier.fillMaxWidth(),
|
val attributesReady = selectedType?.attributes
|
||||||
) { Text("Capturar GPS y crear") }
|
?.filter { it.isRequired }
|
||||||
HorizontalDivider()
|
?.all { attributeValues[it.code].orEmpty().isNotBlank() }
|
||||||
|
?: false
|
||||||
|
val familyReady = selectedType?.familyRequired != true || selectedFamilyId != null
|
||||||
|
Button(
|
||||||
|
onClick = {
|
||||||
|
if (f3HasLocation(context)) createWithLocation()
|
||||||
|
else locationPermissionLauncher.launch(
|
||||||
|
arrayOf(
|
||||||
|
Manifest.permission.ACCESS_FINE_LOCATION,
|
||||||
|
Manifest.permission.ACCESS_COARSE_LOCATION,
|
||||||
|
),
|
||||||
|
)
|
||||||
|
},
|
||||||
|
enabled = selectedType != null && name.isNotBlank() && attributesReady && familyReady && !model.busy,
|
||||||
|
modifier = Modifier.fillMaxWidth(),
|
||||||
|
) { Text("Guardar alta y capturar GPS") }
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Text("Estructura disponible", modifier = Modifier.padding(horizontal = 16.dp, vertical = 8.dp), fontWeight = FontWeight.Bold)
|
Text(
|
||||||
|
"Instalaciones y subinstalaciones",
|
||||||
|
modifier = Modifier.padding(horizontal = 16.dp, vertical = 8.dp),
|
||||||
|
fontWeight = FontWeight.Bold,
|
||||||
|
)
|
||||||
LazyColumn(
|
LazyColumn(
|
||||||
Modifier.fillMaxSize().padding(horizontal = 16.dp),
|
Modifier.fillMaxSize().padding(horizontal = 16.dp),
|
||||||
verticalArrangement = Arrangement.spacedBy(8.dp),
|
verticalArrangement = Arrangement.spacedBy(8.dp),
|
||||||
) {
|
) {
|
||||||
items(model.inventory, key = { it.id }) { item ->
|
items(
|
||||||
|
model.inventory.filter { candidate ->
|
||||||
|
candidate.type?.let(::f3TypeCode) in setOf("instalacion", "subinstalacion")
|
||||||
|
},
|
||||||
|
key = { it.id },
|
||||||
|
) { item ->
|
||||||
F3InventoryCard(
|
F3InventoryCard(
|
||||||
item = item,
|
item = item,
|
||||||
onInspect = { model.selectExisting(item) },
|
onInspect = { model.selectExisting(item) },
|
||||||
@@ -611,10 +631,10 @@ private fun F3CaptureCard(
|
|||||||
if (captureRequired) {
|
if (captureRequired) {
|
||||||
Text("GPS de alta: ${if (gps) "OK" else "pendiente"} · Fotos: $photos")
|
Text("GPS de alta: ${if (gps) "OK" else "pendiente"} · Fotos: $photos")
|
||||||
if (!ready) {
|
if (!ready) {
|
||||||
Text("Antes de registrar Hallazgos, completá GPS + foto.", color = MaterialTheme.colorScheme.error)
|
Text("Antes de registrar el Hallazgo, completá GPS + foto.", color = MaterialTheme.colorScheme.error)
|
||||||
Button(onClick = onPhoto, modifier = Modifier.fillMaxWidth()) { Text("Tomar foto obligatoria") }
|
Button(onClick = onPhoto, modifier = Modifier.fillMaxWidth()) { Text("Tomar foto obligatoria") }
|
||||||
} else {
|
} else {
|
||||||
Text("Captura completa · listo para Hallazgos", color = MaterialTheme.colorScheme.primary)
|
Text("Captura completa · listo para el Hallazgo", color = MaterialTheme.colorScheme.primary)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
Text("Registro existente seleccionado.", style = MaterialTheme.typography.bodySmall)
|
Text("Registro existente seleccionado.", style = MaterialTheme.typography.bodySmall)
|
||||||
@@ -631,8 +651,8 @@ private fun F3InventoryCard(
|
|||||||
) {
|
) {
|
||||||
val typeCode = item.type?.let(::f3TypeCode).orEmpty()
|
val typeCode = item.type?.let(::f3TypeCode).orEmpty()
|
||||||
val canHaveFinding = typeCode in setOf("instalacion", "subinstalacion")
|
val canHaveFinding = typeCode in setOf("instalacion", "subinstalacion")
|
||||||
val canHaveChild = typeCode in setOf("yacimiento", "instalacion")
|
val canHaveChild = typeCode == "instalacion"
|
||||||
val childLabel = if (typeCode == "yacimiento") "Agregar instalación aquí" else "Agregar subinstalación aquí"
|
val childLabel = "+ Agregar subinstalación"
|
||||||
|
|
||||||
Card(Modifier.fillMaxWidth()) {
|
Card(Modifier.fillMaxWidth()) {
|
||||||
Column(Modifier.padding(12.dp), verticalArrangement = Arrangement.spacedBy(5.dp)) {
|
Column(Modifier.padding(12.dp), verticalArrangement = Arrangement.spacedBy(5.dp)) {
|
||||||
@@ -646,12 +666,12 @@ private fun F3InventoryCard(
|
|||||||
}
|
}
|
||||||
if (canHaveFinding) {
|
if (canHaveFinding) {
|
||||||
Text(
|
Text(
|
||||||
if (item.readyForFinding) "Disponible para Hallazgos" else "GPS/foto pendiente",
|
if (item.readyForFinding) "Disponible" else "GPS/foto pendiente",
|
||||||
color = if (item.readyForFinding) MaterialTheme.colorScheme.primary else MaterialTheme.colorScheme.error,
|
color = if (item.readyForFinding) MaterialTheme.colorScheme.primary else MaterialTheme.colorScheme.error,
|
||||||
style = MaterialTheme.typography.bodySmall,
|
style = MaterialTheme.typography.bodySmall,
|
||||||
)
|
)
|
||||||
OutlinedButton(onClick = onInspect, modifier = Modifier.fillMaxWidth()) {
|
Button(onClick = onInspect, modifier = Modifier.fillMaxWidth()) {
|
||||||
Text(if (item.selectedInInspection) "Abrir Hallazgos" else "Usar en esta inspección")
|
Text(if (item.selectedInInspection) "Seleccionar para Hallazgo" else "Usar para Hallazgo")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (canHaveChild) {
|
if (canHaveChild) {
|
||||||
|
|||||||
@@ -126,13 +126,14 @@ fun MobileActsScreen(
|
|||||||
Text("Actas", style = MaterialTheme.typography.titleLarge, fontWeight = FontWeight.Bold)
|
Text("Actas", style = MaterialTheme.typography.titleLarge, fontWeight = FontWeight.Bold)
|
||||||
}
|
}
|
||||||
Text("${visit.code} · ${visit.operatorCompany?.name.orEmpty()}")
|
Text("${visit.code} · ${visit.operatorCompany?.name.orEmpty()}")
|
||||||
|
visit.scopeAsset?.let { Text("Yacimiento: ${it.name}", style = MaterialTheme.typography.bodySmall) }
|
||||||
F32ActMessage(model)
|
F32ActMessage(model)
|
||||||
|
|
||||||
Card(Modifier.fillMaxWidth()) {
|
Card(Modifier.fillMaxWidth()) {
|
||||||
Column(Modifier.padding(12.dp), verticalArrangement = Arrangement.spacedBy(8.dp)) {
|
Column(Modifier.padding(12.dp), verticalArrangement = Arrangement.spacedBy(8.dp)) {
|
||||||
Text("Actas de esta Inspección", fontWeight = FontWeight.Bold)
|
Text("Actas de esta inspección", fontWeight = FontWeight.Bold)
|
||||||
if (model.acts.isEmpty()) {
|
if (model.acts.isEmpty()) {
|
||||||
Text("Todavía no hay Actas. La primera se inicia sobre una Instalación/Subinstalación seleccionada.")
|
Text("Todavía no hay Actas. Creá la primera y después agregá los Hallazgos.")
|
||||||
}
|
}
|
||||||
model.acts.forEach { act ->
|
model.acts.forEach { act ->
|
||||||
val active = selected?.id == act.id
|
val active = selected?.id == act.id
|
||||||
@@ -156,15 +157,15 @@ fun MobileActsScreen(
|
|||||||
Modifier.fillMaxWidth(),
|
Modifier.fillMaxWidth(),
|
||||||
colors = CardDefaults.cardColors(containerColor = MaterialTheme.colorScheme.primaryContainer),
|
colors = CardDefaults.cardColors(containerColor = MaterialTheme.colorScheme.primaryContainer),
|
||||||
) {
|
) {
|
||||||
Column(Modifier.padding(12.dp), verticalArrangement = Arrangement.spacedBy(8.dp)) {
|
Column(Modifier.padding(14.dp), verticalArrangement = Arrangement.spacedBy(10.dp)) {
|
||||||
Text("Nueva Acta", fontWeight = FontWeight.Bold)
|
Text("Nueva Acta", style = MaterialTheme.typography.titleMedium, fontWeight = FontWeight.Bold)
|
||||||
if (model.acts.any { it.status == "LOCKED" }) {
|
if (model.acts.any { it.status == "LOCKED" }) {
|
||||||
Text(
|
Text(
|
||||||
"Podés abrir una nueva Acta aunque otra esté BLOQUEADA esperando firmas. Sólo se permite un borrador a la vez.",
|
"Podés abrir una nueva Acta aunque otra esté BLOQUEADA esperando firmas. Sólo se permite un borrador a la vez.",
|
||||||
style = MaterialTheme.typography.bodySmall,
|
style = MaterialTheme.typography.bodySmall,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
Text("Urgencia del Acta", fontWeight = FontWeight.Bold)
|
Text("Urgencia", fontWeight = FontWeight.Bold)
|
||||||
Row(Modifier.fillMaxWidth(), horizontalArrangement = Arrangement.spacedBy(8.dp)) {
|
Row(Modifier.fillMaxWidth(), horizontalArrangement = Arrangement.spacedBy(8.dp)) {
|
||||||
AssistChip(
|
AssistChip(
|
||||||
onClick = { newActUrgency = "NON_URGENT" },
|
onClick = { newActUrgency = "NON_URGENT" },
|
||||||
@@ -183,20 +184,15 @@ fun MobileActsScreen(
|
|||||||
},
|
},
|
||||||
style = MaterialTheme.typography.bodySmall,
|
style = MaterialTheme.typography.bodySmall,
|
||||||
)
|
)
|
||||||
val selectedInventory = model.selectedFieldAsset?.asset
|
Text(
|
||||||
if (selectedInventory == null) {
|
"Abrí el Acta primero. Después elegís la Instalación o Subinstalación al agregar cada Hallazgo.",
|
||||||
Text("Primero elegí una Instalación o Subinstalación desde Inventario de campo. Ese registro será el primer elemento del Acta.")
|
style = MaterialTheme.typography.bodySmall,
|
||||||
Button(onClick = onGoInventory, modifier = Modifier.fillMaxWidth()) {
|
)
|
||||||
Text("Ir a Inventario y elegir")
|
Button(
|
||||||
}
|
onClick = { model.createAct(newActUrgency) },
|
||||||
} else {
|
enabled = !model.busy,
|
||||||
Text("Inventario inicial: ${selectedInventory.name} · ${selectedInventory.code}")
|
modifier = Modifier.fillMaxWidth(),
|
||||||
Button(
|
) { Text("Crear nueva Acta") }
|
||||||
onClick = { model.createActForSelectedInventory(newActUrgency) },
|
|
||||||
enabled = !model.busy,
|
|
||||||
modifier = Modifier.fillMaxWidth(),
|
|
||||||
) { Text("Crear nueva Acta") }
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -220,7 +216,21 @@ fun MobileActsScreen(
|
|||||||
|
|
||||||
when (selected.status) {
|
when (selected.status) {
|
||||||
"DRAFT" -> {
|
"DRAFT" -> {
|
||||||
Text("1. Responsable de la empresa", style = MaterialTheme.typography.titleMedium, fontWeight = FontWeight.Bold)
|
Card(
|
||||||
|
Modifier.fillMaxWidth(),
|
||||||
|
colors = CardDefaults.cardColors(containerColor = MaterialTheme.colorScheme.primaryContainer),
|
||||||
|
) {
|
||||||
|
Column(Modifier.padding(14.dp), verticalArrangement = Arrangement.spacedBy(8.dp)) {
|
||||||
|
Text("Hallazgos", style = MaterialTheme.typography.titleMedium, fontWeight = FontWeight.Bold)
|
||||||
|
Text("Buscá una Instalación o Subinstalación existente. Si no está, podés agregarla en campo en el mismo flujo.")
|
||||||
|
Button(onClick = onGoInventory, modifier = Modifier.fillMaxWidth()) {
|
||||||
|
Text("+ Agregar Hallazgo")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
HorizontalDivider()
|
||||||
|
Text("Responsable de la empresa", style = MaterialTheme.typography.titleMedium, fontWeight = FontWeight.Bold)
|
||||||
Row(Modifier.fillMaxWidth(), horizontalArrangement = Arrangement.spacedBy(8.dp)) {
|
Row(Modifier.fillMaxWidth(), horizontalArrangement = Arrangement.spacedBy(8.dp)) {
|
||||||
AssistChip(onClick = { attendance = "PRESENT" }, label = { Text(if (attendance == "PRESENT") "✓ Presente" else "Presente") })
|
AssistChip(onClick = { attendance = "PRESENT" }, label = { Text(if (attendance == "PRESENT") "✓ Presente" else "Presente") })
|
||||||
AssistChip(onClick = { attendance = "ABSENT" }, label = { Text(if (attendance == "ABSENT") "✓ Ausente" else "Ausente") })
|
AssistChip(onClick = { attendance = "ABSENT" }, label = { Text(if (attendance == "ABSENT") "✓ Ausente" else "Ausente") })
|
||||||
@@ -259,12 +269,7 @@ fun MobileActsScreen(
|
|||||||
}
|
}
|
||||||
|
|
||||||
HorizontalDivider()
|
HorizontalDivider()
|
||||||
Text("2. Hallazgos / verificaciones", style = MaterialTheme.typography.titleMedium, fontWeight = FontWeight.Bold)
|
Text("Finalizar contenido", style = MaterialTheme.typography.titleMedium, fontWeight = FontWeight.Bold)
|
||||||
Text("Los Hallazgos se cargan desde Inventario y quedan vinculados explícitamente a ${selected.code}. El Acta también puede finalizar sin Hallazgos cuando corresponde dejar constancia de una inspección o verificación sin nuevos incumplimientos.")
|
|
||||||
Button(onClick = onGoInventory, modifier = Modifier.fillMaxWidth()) { Text("Ir a Inventario / Hallazgos") }
|
|
||||||
|
|
||||||
HorizontalDivider()
|
|
||||||
Text("3. Finalizar contenido", style = MaterialTheme.typography.titleMedium, fontWeight = FontWeight.Bold)
|
|
||||||
Text("Al BLOQUEAR el Acta, el contenido y los Hallazgos quedan inmutables. Esta acción no se puede deshacer.")
|
Text("Al BLOQUEAR el Acta, el contenido y los Hallazgos quedan inmutables. Esta acción no se puede deshacer.")
|
||||||
Button(
|
Button(
|
||||||
onClick = { model.prepareSelectedAct() },
|
onClick = { model.prepareSelectedAct() },
|
||||||
|
|||||||
@@ -8,8 +8,8 @@ class ReleaseMetadataTest {
|
|||||||
@Test
|
@Test
|
||||||
fun debugBuildKeepsSeparateApplicationIdentity() {
|
fun debugBuildKeepsSeparateApplicationIdentity() {
|
||||||
assertEquals("com.korexlabs.dhinspeccion.debug", BuildConfig.APPLICATION_ID)
|
assertEquals("com.korexlabs.dhinspeccion.debug", BuildConfig.APPLICATION_ID)
|
||||||
assertEquals(24, BuildConfig.VERSION_CODE)
|
assertEquals(25, BuildConfig.VERSION_CODE)
|
||||||
assertEquals("0.15.2-debug", BuildConfig.VERSION_NAME)
|
assertEquals("0.16.0-debug", BuildConfig.VERSION_NAME)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|||||||
@@ -36,6 +36,20 @@ export interface FieldBriefingAct {
|
|||||||
findings: FieldBriefingFinding[];
|
findings: FieldBriefingFinding[];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function toIsoDate(value: unknown): string {
|
||||||
|
const parsed = value instanceof Date
|
||||||
|
? value
|
||||||
|
: value == null
|
||||||
|
? new Date()
|
||||||
|
: new Date(String(value));
|
||||||
|
|
||||||
|
if (Number.isNaN(parsed.getTime())) {
|
||||||
|
throw new Error('La fecha planificada de la inspección no es válida');
|
||||||
|
}
|
||||||
|
|
||||||
|
return parsed.toISOString().slice(0, 10);
|
||||||
|
}
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class FieldBriefingService {
|
export class FieldBriefingService {
|
||||||
constructor(private readonly dataSource: DataSource) {}
|
constructor(private readonly dataSource: DataSource) {}
|
||||||
@@ -67,7 +81,9 @@ export class FieldBriefingService {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
const plannedOn = String(visit.plannedStartAt ?? new Date().toISOString()).slice(0, 10);
|
// PostgreSQL/pg entrega los timestamptz como Date. String(date).slice(0, 10)
|
||||||
|
// produce textos como "Thu Sep 17", que PostgreSQL rechaza al castear a date.
|
||||||
|
const plannedOn = toIsoDate(visit.plannedStartAt);
|
||||||
|
|
||||||
const rows = (await this.dataSource.query(`
|
const rows = (await this.dataSource.query(`
|
||||||
WITH prior_acts AS (
|
WITH prior_acts AS (
|
||||||
|
|||||||
@@ -0,0 +1,39 @@
|
|||||||
|
import { MigrationInterface, QueryRunner } from 'typeorm';
|
||||||
|
|
||||||
|
export class F62FreezeInspectionContext1790098200000 implements MigrationInterface {
|
||||||
|
name = 'F62FreezeInspectionContext1790098200000';
|
||||||
|
|
||||||
|
public async up(queryRunner: QueryRunner): Promise<void> {
|
||||||
|
await queryRunner.query(`
|
||||||
|
CREATE OR REPLACE FUNCTION prevent_inspection_context_mutation()
|
||||||
|
RETURNS trigger LANGUAGE plpgsql AS $$
|
||||||
|
BEGIN
|
||||||
|
IF NEW.operational_area_id IS DISTINCT FROM OLD.operational_area_id
|
||||||
|
OR NEW.scope_asset_id IS DISTINCT FROM OLD.scope_asset_id
|
||||||
|
OR NEW.operator_company_id IS DISTINCT FROM OLD.operator_company_id THEN
|
||||||
|
RAISE EXCEPTION USING
|
||||||
|
ERRCODE='23514',
|
||||||
|
MESSAGE='El Área, Yacimiento y Operadora de una Inspección quedan fijos desde su creación';
|
||||||
|
END IF;
|
||||||
|
RETURN NEW;
|
||||||
|
END $$
|
||||||
|
`);
|
||||||
|
|
||||||
|
await queryRunner.query(`
|
||||||
|
DROP TRIGGER IF EXISTS trg_inspection_context_immutable ON inspection_visits
|
||||||
|
`);
|
||||||
|
await queryRunner.query(`
|
||||||
|
CREATE TRIGGER trg_inspection_context_immutable
|
||||||
|
BEFORE UPDATE OF operational_area_id, scope_asset_id, operator_company_id
|
||||||
|
ON inspection_visits
|
||||||
|
FOR EACH ROW EXECUTE FUNCTION prevent_inspection_context_mutation()
|
||||||
|
`);
|
||||||
|
}
|
||||||
|
|
||||||
|
public async down(queryRunner: QueryRunner): Promise<void> {
|
||||||
|
await queryRunner.query(`
|
||||||
|
DROP TRIGGER IF EXISTS trg_inspection_context_immutable ON inspection_visits
|
||||||
|
`);
|
||||||
|
await queryRunner.query('DROP FUNCTION IF EXISTS prevent_inspection_context_mutation()');
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,57 @@
|
|||||||
|
import { MigrationInterface, QueryRunner } from 'typeorm';
|
||||||
|
|
||||||
|
export class F63MobileFieldCommonAttributes1790099100000 implements MigrationInterface {
|
||||||
|
name = 'F63MobileFieldCommonAttributes1790099100000';
|
||||||
|
|
||||||
|
public async up(queryRunner: QueryRunner): Promise<void> {
|
||||||
|
await queryRunner.query(`
|
||||||
|
WITH target_types AS (
|
||||||
|
SELECT id
|
||||||
|
FROM asset_types
|
||||||
|
WHERE lower(code) IN ('instalacion','subinstalacion')
|
||||||
|
), fields(code,name,sort_order) AS (
|
||||||
|
VALUES
|
||||||
|
('campo_marca','Marca',10),
|
||||||
|
('campo_modelo','Modelo',20),
|
||||||
|
('campo_capacidad','Capacidad',30),
|
||||||
|
('campo_numero_serie','Número de serie',40),
|
||||||
|
('campo_funcion','Función',50)
|
||||||
|
)
|
||||||
|
INSERT INTO asset_attribute_definitions (
|
||||||
|
asset_type_id, code, name, data_type, is_required, is_active, sort_order
|
||||||
|
)
|
||||||
|
SELECT target.id, fields.code, fields.name, 'TEXT'::asset_attribute_data_type,
|
||||||
|
false, true, fields.sort_order
|
||||||
|
FROM target_types target
|
||||||
|
CROSS JOIN fields
|
||||||
|
WHERE NOT EXISTS (
|
||||||
|
SELECT 1
|
||||||
|
FROM asset_attribute_definitions existing
|
||||||
|
WHERE existing.asset_type_id=target.id
|
||||||
|
AND lower(existing.code)=lower(fields.code)
|
||||||
|
)
|
||||||
|
`);
|
||||||
|
}
|
||||||
|
|
||||||
|
public async down(queryRunner: QueryRunner): Promise<void> {
|
||||||
|
await queryRunner.query(`
|
||||||
|
DELETE FROM asset_attribute_values value
|
||||||
|
USING asset_attribute_definitions definition, asset_types type
|
||||||
|
WHERE value.definition_id=definition.id
|
||||||
|
AND definition.asset_type_id=type.id
|
||||||
|
AND lower(type.code) IN ('instalacion','subinstalacion')
|
||||||
|
AND definition.code IN (
|
||||||
|
'campo_marca','campo_modelo','campo_capacidad','campo_numero_serie','campo_funcion'
|
||||||
|
)
|
||||||
|
`);
|
||||||
|
await queryRunner.query(`
|
||||||
|
DELETE FROM asset_attribute_definitions definition
|
||||||
|
USING asset_types type
|
||||||
|
WHERE definition.asset_type_id=type.id
|
||||||
|
AND lower(type.code) IN ('instalacion','subinstalacion')
|
||||||
|
AND definition.code IN (
|
||||||
|
'campo_marca','campo_modelo','campo_capacidad','campo_numero_serie','campo_funcion'
|
||||||
|
)
|
||||||
|
`);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,7 +1,6 @@
|
|||||||
import { Transform } from 'class-transformer';
|
import { Transform } from 'class-transformer';
|
||||||
import {
|
import {
|
||||||
ArrayMaxSize,
|
ArrayMaxSize,
|
||||||
ArrayMinSize,
|
|
||||||
ArrayUnique,
|
ArrayUnique,
|
||||||
IsArray,
|
IsArray,
|
||||||
IsEnum,
|
IsEnum,
|
||||||
@@ -42,7 +41,6 @@ export class CreateInspectionActDto {
|
|||||||
observations?: string | null;
|
observations?: string | null;
|
||||||
|
|
||||||
@IsArray()
|
@IsArray()
|
||||||
@ArrayMinSize(1)
|
|
||||||
@ArrayMaxSize(200)
|
@ArrayMaxSize(200)
|
||||||
@ArrayUnique()
|
@ArrayUnique()
|
||||||
@IsUUID('4', { each: true })
|
@IsUUID('4', { each: true })
|
||||||
|
|||||||
@@ -656,6 +656,7 @@ export class InspectionActsService {
|
|||||||
visitId: string,
|
visitId: string,
|
||||||
assetIds: string[],
|
assetIds: string[],
|
||||||
): Promise<void> {
|
): Promise<void> {
|
||||||
|
if (assetIds.length === 0) return;
|
||||||
const [row] = (await manager.query(`
|
const [row] = (await manager.query(`
|
||||||
SELECT COUNT(*)::integer AS count
|
SELECT COUNT(*)::integer AS count
|
||||||
FROM inspection_visit_assets
|
FROM inspection_visit_assets
|
||||||
@@ -663,7 +664,7 @@ export class InspectionActsService {
|
|||||||
AND asset_id = ANY($2::uuid[])
|
AND asset_id = ANY($2::uuid[])
|
||||||
AND included = true
|
AND included = true
|
||||||
`, [visitId, assetIds])) as Array<{ count: number }>;
|
`, [visitId, assetIds])) as Array<{ count: number }>;
|
||||||
if (assetIds.length < 1 || Number(row?.count ?? 0) !== assetIds.length) {
|
if (Number(row?.count ?? 0) !== assetIds.length) {
|
||||||
throw new BadRequestException({
|
throw new BadRequestException({
|
||||||
code: 'INSPECTION_ACT_ASSET_INVALID',
|
code: 'INSPECTION_ACT_ASSET_INVALID',
|
||||||
message: 'Cada inventario del acta debe estar incluido en la inspección',
|
message: 'Cada inventario del acta debe estar incluido en la inspección',
|
||||||
|
|||||||
@@ -1,9 +1,9 @@
|
|||||||
import { Transform } from 'class-transformer';
|
import { Transform } from 'class-transformer';
|
||||||
import {
|
import {
|
||||||
|
IsEmpty,
|
||||||
IsISO8601,
|
IsISO8601,
|
||||||
IsOptional,
|
IsOptional,
|
||||||
IsString,
|
IsString,
|
||||||
IsUUID,
|
|
||||||
MaxLength,
|
MaxLength,
|
||||||
} from 'class-validator';
|
} from 'class-validator';
|
||||||
|
|
||||||
@@ -17,15 +17,15 @@ export class UpdateInspectionVisitDto {
|
|||||||
objective?: string | null;
|
objective?: string | null;
|
||||||
|
|
||||||
@IsOptional()
|
@IsOptional()
|
||||||
@IsUUID('4')
|
@IsEmpty({ message: 'El Yacimiento se fija al crear la Inspección y no puede modificarse' })
|
||||||
scopeAssetId?: string | null;
|
scopeAssetId?: string | null;
|
||||||
|
|
||||||
@IsOptional()
|
@IsOptional()
|
||||||
@IsUUID('4')
|
@IsEmpty({ message: 'El Área se fija al crear la Inspección y no puede modificarse' })
|
||||||
operationalAreaId?: string | null;
|
operationalAreaId?: string | null;
|
||||||
|
|
||||||
@IsOptional()
|
@IsOptional()
|
||||||
@IsUUID('4')
|
@IsEmpty({ message: 'La Operadora se fija al crear la Inspección y no puede modificarse' })
|
||||||
operatorCompanyId?: string | null;
|
operatorCompanyId?: string | null;
|
||||||
|
|
||||||
@IsOptional()
|
@IsOptional()
|
||||||
|
|||||||
@@ -61,7 +61,7 @@ export class F3FieldInventoryStructureService {
|
|||||||
principal: AuthPrincipal,
|
principal: AuthPrincipal,
|
||||||
) {
|
) {
|
||||||
const base = await this.fieldInventory.types(visitId, parentId, principal) as unknown as FieldTypesBase;
|
const base = await this.fieldInventory.types(visitId, parentId, principal) as unknown as FieldTypesBase;
|
||||||
const effectiveParentId = parentId ?? base.context.area.id;
|
const effectiveParentId = parentId ?? base.parent.id;
|
||||||
const parent = await this.parent(effectiveParentId);
|
const parent = await this.parent(effectiveParentId);
|
||||||
const expectedTypeCode = STRUCTURAL_CHILD[parent.typeCode.toLowerCase()];
|
const expectedTypeCode = STRUCTURAL_CHILD[parent.typeCode.toLowerCase()];
|
||||||
const data = expectedTypeCode
|
const data = expectedTypeCode
|
||||||
|
|||||||
@@ -0,0 +1,17 @@
|
|||||||
|
import { Controller, Get, Param, ParseUUIDPipe, Query } from '@nestjs/common';
|
||||||
|
import { RequirePermissions } from '../authorization/decorators/require-permissions.decorator';
|
||||||
|
import { InspectionPreventiveCandidatesService } from './inspection-preventive-candidates.service';
|
||||||
|
|
||||||
|
@Controller('inspection-visits')
|
||||||
|
export class InspectionPreventiveCandidatesController {
|
||||||
|
constructor(private readonly candidates: InspectionPreventiveCandidatesService) {}
|
||||||
|
|
||||||
|
@Get(':id/preventive-candidates')
|
||||||
|
@RequirePermissions('inspections.read')
|
||||||
|
list(
|
||||||
|
@Param('id', new ParseUUIDPipe({ version: '4' })) id: string,
|
||||||
|
@Query('search') search?: string,
|
||||||
|
) {
|
||||||
|
return this.candidates.list(id, search);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,77 @@
|
|||||||
|
import { Injectable, NotFoundException } from '@nestjs/common';
|
||||||
|
import { DataSource } from 'typeorm';
|
||||||
|
|
||||||
|
export interface InspectionPreventiveCandidate {
|
||||||
|
id: string;
|
||||||
|
code: string;
|
||||||
|
name: string;
|
||||||
|
typeName: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Injectable()
|
||||||
|
export class InspectionPreventiveCandidatesService {
|
||||||
|
constructor(private readonly dataSource: DataSource) {}
|
||||||
|
|
||||||
|
async list(visitId: string, search?: string): Promise<{ data: InspectionPreventiveCandidate[] }> {
|
||||||
|
const [context] = (await this.dataSource.query(`
|
||||||
|
SELECT
|
||||||
|
visit.operational_area_id AS "operationalAreaId",
|
||||||
|
COALESCE(visit.scope_asset_id, visit.operational_area_id) AS "scopeAssetId"
|
||||||
|
FROM inspection_visits visit
|
||||||
|
WHERE visit.id = $1::uuid
|
||||||
|
`, [visitId])) as Array<{
|
||||||
|
operationalAreaId: string | null;
|
||||||
|
scopeAssetId: string | null;
|
||||||
|
}>;
|
||||||
|
|
||||||
|
if (!context) {
|
||||||
|
throw new NotFoundException({
|
||||||
|
code: 'INSPECTION_VISIT_NOT_FOUND',
|
||||||
|
message: 'Visita de inspección no encontrada',
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!context.operationalAreaId || !context.scopeAssetId) return { data: [] };
|
||||||
|
|
||||||
|
const term = search?.trim().slice(0, 200) ?? '';
|
||||||
|
const rows = (await this.dataSource.query(`
|
||||||
|
WITH RECURSIVE scope_tree AS (
|
||||||
|
SELECT root.id
|
||||||
|
FROM assets root
|
||||||
|
WHERE root.id = $2::uuid
|
||||||
|
UNION ALL
|
||||||
|
SELECT child.id
|
||||||
|
FROM assets child
|
||||||
|
INNER JOIN scope_tree parent_scope ON parent_scope.id = child.parent_id
|
||||||
|
)
|
||||||
|
SELECT
|
||||||
|
asset.id,
|
||||||
|
asset.code,
|
||||||
|
asset.name,
|
||||||
|
asset_type.name AS "typeName"
|
||||||
|
FROM scope_tree
|
||||||
|
INNER JOIN assets asset ON asset.id = scope_tree.id
|
||||||
|
INNER JOIN asset_types asset_type ON asset_type.id = asset.asset_type_id
|
||||||
|
WHERE asset.id <> $2::uuid
|
||||||
|
AND asset.operational_area_id = $3::uuid
|
||||||
|
AND asset.information_status <> 'INACTIVE'
|
||||||
|
AND lower(asset_type.code) IN ('instalacion', 'subinstalacion')
|
||||||
|
AND NOT EXISTS (
|
||||||
|
SELECT 1
|
||||||
|
FROM inspection_visit_assets linked
|
||||||
|
WHERE linked.visit_id = $1::uuid
|
||||||
|
AND linked.asset_id = asset.id
|
||||||
|
)
|
||||||
|
AND (
|
||||||
|
$4::text = ''
|
||||||
|
OR asset.code ILIKE '%' || $4::text || '%'
|
||||||
|
OR asset.name ILIKE '%' || $4::text || '%'
|
||||||
|
OR COALESCE(asset.common_name, '') ILIKE '%' || $4::text || '%'
|
||||||
|
)
|
||||||
|
ORDER BY asset_type.name, asset.name, asset.code
|
||||||
|
LIMIT 100
|
||||||
|
`, [visitId, context.scopeAssetId, context.operationalAreaId, term])) as InspectionPreventiveCandidate[];
|
||||||
|
|
||||||
|
return { data: rows };
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -10,17 +10,25 @@ import { FieldInventoryController } from './field-inventory.controller';
|
|||||||
import { FieldInventoryService } from './field-inventory.service';
|
import { FieldInventoryService } from './field-inventory.service';
|
||||||
import { InspectionPlanningCreateService } from './inspection-planning-create.service';
|
import { InspectionPlanningCreateService } from './inspection-planning-create.service';
|
||||||
import { InspectionPlanningHierarchyService } from './inspection-planning-hierarchy.service';
|
import { InspectionPlanningHierarchyService } from './inspection-planning-hierarchy.service';
|
||||||
|
import { InspectionPreventiveCandidatesController } from './inspection-preventive-candidates.controller';
|
||||||
|
import { InspectionPreventiveCandidatesService } from './inspection-preventive-candidates.service';
|
||||||
import { InspectionVisitLifecycleService } from './inspection-visit-lifecycle.service';
|
import { InspectionVisitLifecycleService } from './inspection-visit-lifecycle.service';
|
||||||
import { InspectionVisitsController } from './inspection-visits.controller';
|
import { InspectionVisitsController } from './inspection-visits.controller';
|
||||||
import { InspectionVisitsService } from './inspection-visits.service';
|
import { InspectionVisitsService } from './inspection-visits.service';
|
||||||
|
|
||||||
@Module({
|
@Module({
|
||||||
imports: [AuditModule, AssetMasterModule, InspectionFindingsModule],
|
imports: [AuditModule, AssetMasterModule, InspectionFindingsModule],
|
||||||
controllers: [InspectionVisitsController, FieldInventoryController, FieldFindingsController],
|
controllers: [
|
||||||
|
InspectionVisitsController,
|
||||||
|
InspectionPreventiveCandidatesController,
|
||||||
|
FieldInventoryController,
|
||||||
|
FieldFindingsController,
|
||||||
|
],
|
||||||
providers: [
|
providers: [
|
||||||
{ provide: InspectionVisitsService, useClass: F4InspectionVisitsService },
|
{ provide: InspectionVisitsService, useClass: F4InspectionVisitsService },
|
||||||
InspectionPlanningCreateService,
|
InspectionPlanningCreateService,
|
||||||
InspectionPlanningHierarchyService,
|
InspectionPlanningHierarchyService,
|
||||||
|
InspectionPreventiveCandidatesService,
|
||||||
InspectionVisitLifecycleService,
|
InspectionVisitLifecycleService,
|
||||||
FieldInventoryService,
|
FieldInventoryService,
|
||||||
F3FieldInventoryStructureService,
|
F3FieldInventoryStructureService,
|
||||||
|
|||||||
@@ -7,16 +7,16 @@ function mountedRepoFile(path: string): string {
|
|||||||
return readFileSync(resolve(process.cwd(), '..', path), 'utf8');
|
return readFileSync(resolve(process.cwd(), '..', path), 'utf8');
|
||||||
}
|
}
|
||||||
|
|
||||||
test('F6.1 Android test cut targets production API and has a distinct installable debug version', () => {
|
test('F6.3 Android test cut targets production API and has a distinct installable debug version', () => {
|
||||||
const gradle = mountedRepoFile('android-app/app/build.gradle.kts');
|
const gradle = mountedRepoFile('android-app/app/build.gradle.kts');
|
||||||
|
|
||||||
assert.match(gradle, /versionCode = 24/);
|
assert.match(gradle, /versionCode = 25/);
|
||||||
assert.match(gradle, /versionName = "0\.15\.2"/);
|
assert.match(gradle, /versionName = "0\.16\.0"/);
|
||||||
assert.match(gradle, /https:\/\/dhv2\.korexlabs\.com\/api\/v3\//);
|
assert.match(gradle, /https:\/\/dhv2\.korexlabs\.com\/api\/v3\//);
|
||||||
assert.match(gradle, /applicationIdSuffix = "\.debug"/);
|
assert.match(gradle, /applicationIdSuffix = "\.debug"/);
|
||||||
});
|
});
|
||||||
|
|
||||||
test('F5/F6.1 field inventory exposes Other families as reviewable choices to Android', () => {
|
test('F5/F6.3 field inventory exposes Other families as reviewable choices to Android', () => {
|
||||||
const service = readFileSync(
|
const service = readFileSync(
|
||||||
resolve(process.cwd(), 'src/inspection-visits/f3-field-inventory-structure.service.ts'),
|
resolve(process.cwd(), 'src/inspection-visits/f3-field-inventory-structure.service.ts'),
|
||||||
'utf8',
|
'utf8',
|
||||||
|
|||||||
@@ -62,11 +62,17 @@ test('F6.1 operator choices are resolved at the planned timestamp', () => {
|
|||||||
assert.match(createPage, /\[areaId, plannedStartAt\]/);
|
assert.match(createPage, /\[areaId, plannedStartAt\]/);
|
||||||
});
|
});
|
||||||
|
|
||||||
test('F6.1 WEB keeps Area and Yacimiento as separate concepts when editing', () => {
|
test('F6.1 WEB keeps Area and Yacimiento as separate concepts and freezes context after creation', () => {
|
||||||
const source = web('src/pages/InspectionVisitEditorF4Page.tsx');
|
const source = web('src/pages/InspectionVisitEditorF4Page.tsx');
|
||||||
|
|
||||||
assert.doesNotMatch(source, /<span>Área \/ Yacimiento<\/span>/);
|
assert.doesNotMatch(source, /<span>Área \/ Yacimiento<\/span>/);
|
||||||
assert.match(source, /<span>Área<\/span>/);
|
assert.match(source, /<span>Área<\/span>/);
|
||||||
assert.match(source, /<span>Yacimiento<\/span>/);
|
assert.match(source, /<span>Yacimiento<\/span>/);
|
||||||
assert.match(source, /scopeAssetId: visit\?\.scopeAsset\?\.id \?\? null/);
|
assert.match(source, /<span>Operadora<\/span>/);
|
||||||
|
assert.match(source, /visit\.operationalArea\.name[\s\S]{0,160}readOnly/);
|
||||||
|
assert.match(source, /visit\.scopeAsset\.name[\s\S]{0,160}readOnly/);
|
||||||
|
assert.match(source, /visit\.operatorCompany\.name[\s\S]{0,160}readOnly/);
|
||||||
|
assert.doesNotMatch(source, /updateInspectionVisit\(id, \{[\s\S]{0,300}scopeAssetId:/);
|
||||||
|
assert.doesNotMatch(source, /updateInspectionVisit\(id, \{[\s\S]{0,300}operationalAreaId:/);
|
||||||
|
assert.doesNotMatch(source, /updateInspectionVisit\(id, \{[\s\S]{0,300}operatorCompanyId:/);
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -75,12 +75,20 @@ test('F6.1 historical operational lists read Company and Area from the parent In
|
|||||||
assert.doesNotMatch(reports, /context_asset\.operator_company_id/);
|
assert.doesNotMatch(reports, /context_asset\.operator_company_id/);
|
||||||
});
|
});
|
||||||
|
|
||||||
test('F6.1 WEB Inventory searches use physical Area and never the operator snapshot filter', () => {
|
test('F6.1 WEB Inventory searches use physical scope and never the operator snapshot filter', () => {
|
||||||
const inspectionEditor = source('../web-v2/src/pages/InspectionVisitEditorF4Page.tsx');
|
const inspectionEditor = source('../web-v2/src/pages/InspectionVisitEditorF4Page.tsx');
|
||||||
|
const preventiveApi = source('../web-v2/src/features/inspections/preventiveCandidatesApi.ts');
|
||||||
|
const preventiveService = source('src/inspection-visits/inspection-preventive-candidates.service.ts');
|
||||||
const fieldDiscoveries = source('../web-v2/src/pages/FieldDiscoveriesPage.tsx');
|
const fieldDiscoveries = source('../web-v2/src/pages/FieldDiscoveriesPage.tsx');
|
||||||
const inventoryMerge = source('../web-v2/src/lib/inventoryMergeApi.ts');
|
const inventoryMerge = source('../web-v2/src/lib/inventoryMergeApi.ts');
|
||||||
|
|
||||||
for (const page of [inspectionEditor, fieldDiscoveries, inventoryMerge]) {
|
assert.match(inspectionEditor, /listInspectionPreventiveCandidates\(id, assetSearch\)/);
|
||||||
|
assert.match(preventiveApi, /inspection-visits\/\$\{visitId\}\/preventive-candidates/);
|
||||||
|
assert.match(preventiveService, /COALESCE\(visit\.scope_asset_id, visit\.operational_area_id\) AS "scopeAssetId"/);
|
||||||
|
assert.doesNotMatch(preventiveService, /asset\.operator_company_id/);
|
||||||
|
assert.doesNotMatch(inspectionEditor, /listAssets\(\{[\s\S]{0,300}operatorCompanyId:/);
|
||||||
|
|
||||||
|
for (const page of [fieldDiscoveries, inventoryMerge]) {
|
||||||
assert.match(page, /listAssets\(\{[\s\S]{0,300}operationalAreaId:/);
|
assert.match(page, /listAssets\(\{[\s\S]{0,300}operationalAreaId:/);
|
||||||
assert.doesNotMatch(page, /listAssets\(\{[\s\S]{0,300}operatorCompanyId:/);
|
assert.doesNotMatch(page, /listAssets\(\{[\s\S]{0,300}operatorCompanyId:/);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,40 @@
|
|||||||
|
import assert from 'node:assert/strict';
|
||||||
|
import { readFileSync } from 'node:fs';
|
||||||
|
import { resolve } from 'node:path';
|
||||||
|
import test from 'node:test';
|
||||||
|
|
||||||
|
const api = (path: string) => readFileSync(resolve(process.cwd(), path), 'utf8');
|
||||||
|
const web = (path: string) => readFileSync(resolve(process.cwd(), '..', 'web-v2', path), 'utf8');
|
||||||
|
|
||||||
|
test('F6.2 protects the frozen Inspection context at database level', () => {
|
||||||
|
const migration = api('src/database/migrations/1790098200000-f6-2-freeze-inspection-context.ts');
|
||||||
|
|
||||||
|
assert.match(migration, /prevent_inspection_context_mutation/);
|
||||||
|
assert.match(migration, /NEW\.operational_area_id IS DISTINCT FROM OLD\.operational_area_id/);
|
||||||
|
assert.match(migration, /NEW\.scope_asset_id IS DISTINCT FROM OLD\.scope_asset_id/);
|
||||||
|
assert.match(migration, /NEW\.operator_company_id IS DISTINCT FROM OLD\.operator_company_id/);
|
||||||
|
assert.match(migration, /BEFORE UPDATE OF operational_area_id, scope_asset_id, operator_company_id/);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('F6.2 preventive candidates are descendants of the frozen Yacimiento only', () => {
|
||||||
|
const service = api('src/inspection-visits/inspection-preventive-candidates.service.ts');
|
||||||
|
const controller = api('src/inspection-visits/inspection-preventive-candidates.controller.ts');
|
||||||
|
|
||||||
|
assert.match(service, /COALESCE\(visit\.scope_asset_id, visit\.operational_area_id\) AS "scopeAssetId"/);
|
||||||
|
assert.match(service, /WITH RECURSIVE scope_tree AS/);
|
||||||
|
assert.match(service, /child\.parent_id/);
|
||||||
|
assert.match(service, /asset\.operational_area_id = \$3::uuid/);
|
||||||
|
assert.match(service, /lower\(asset_type\.code\) IN \('instalacion', 'subinstalacion'\)/);
|
||||||
|
assert.match(service, /NOT EXISTS \([\s\S]*inspection_visit_assets linked/);
|
||||||
|
assert.match(controller, /:id\/preventive-candidates/);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('F6.2 WEB uses the server-scoped preventive selector instead of the mutable Area form', () => {
|
||||||
|
const page = web('src/pages/InspectionVisitEditorF4Page.tsx');
|
||||||
|
const apiClient = web('src/features/inspections/preventiveCandidatesApi.ts');
|
||||||
|
|
||||||
|
assert.match(page, /listInspectionPreventiveCandidates\(id, assetSearch\)/);
|
||||||
|
assert.doesNotMatch(page, /listAssets\(\{[\s\S]{0,220}operationalAreaId: form\.operationalAreaId/);
|
||||||
|
assert.match(page, /Sólo se muestran Instalaciones y Subinstalaciones pertenecientes al Yacimiento/);
|
||||||
|
assert.match(apiClient, /inspection-visits\/\$\{visitId\}\/preventive-candidates/);
|
||||||
|
});
|
||||||
@@ -0,0 +1,49 @@
|
|||||||
|
import assert from 'node:assert/strict';
|
||||||
|
import { readFileSync } from 'node:fs';
|
||||||
|
import { resolve } from 'node:path';
|
||||||
|
import test from 'node:test';
|
||||||
|
|
||||||
|
function source(path: string) {
|
||||||
|
return readFileSync(resolve(process.cwd(), path), 'utf8');
|
||||||
|
}
|
||||||
|
|
||||||
|
test('F6.3 field types start at the frozen Yacimiento instead of the Area', () => {
|
||||||
|
const structure = source('src/inspection-visits/f3-field-inventory-structure.service.ts');
|
||||||
|
assert.match(structure, /parentId \?\? base\.parent\.id/);
|
||||||
|
assert.doesNotMatch(structure, /parentId \?\? base\.context\.area\.id/);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('F6.3 an Acta can start empty and receive Inventory when Hallazgos are added', () => {
|
||||||
|
const dto = source('src/inspection-acts/dto/create-inspection-act.dto.ts');
|
||||||
|
const service = source('src/inspection-acts/inspection-acts.service.ts');
|
||||||
|
const mobile = source('../android-app/app/src/main/java/com/korexlabs/dhinspeccion/data/MobileActs.kt');
|
||||||
|
|
||||||
|
assert.doesNotMatch(dto, /ArrayMinSize\(1\)/);
|
||||||
|
assert.match(service, /if \(assetIds\.length === 0\) return/);
|
||||||
|
assert.match(mobile, /assetIds = listOfNotNull\(assetId\)/);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('F6.3 every Installation and Subinstallation receives the common field card', () => {
|
||||||
|
const migration = source('src/database/migrations/1790099100000-f6-3-mobile-field-common-attributes.ts');
|
||||||
|
|
||||||
|
for (const label of ['Marca', 'Modelo', 'Capacidad', 'Número de serie', 'Función']) {
|
||||||
|
assert.match(migration, new RegExp(label));
|
||||||
|
}
|
||||||
|
assert.match(migration, /'instalacion','subinstalacion'/);
|
||||||
|
assert.match(migration, /'TEXT'::asset_attribute_data_type/);
|
||||||
|
assert.match(migration, /false, true/);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('F6.3 Android follows Inspección → Acta → Hallazgo → Inventario', () => {
|
||||||
|
const root = source('../android-app/app/src/main/java/com/korexlabs/dhinspeccion/ui/F3VisitRoot.kt');
|
||||||
|
const acts = source('../android-app/app/src/main/java/com/korexlabs/dhinspeccion/ui/MobileActsScreen.kt');
|
||||||
|
const vm = source('../android-app/app/src/main/java/com/korexlabs/dhinspeccion/MainViewModel.kt');
|
||||||
|
|
||||||
|
assert.match(root, /model\.startVisit\(\); onActs\(\)/);
|
||||||
|
assert.match(root, /Text\("Nuevo Hallazgo"/);
|
||||||
|
assert.match(root, /Buscar instalación o subinstalación/);
|
||||||
|
assert.match(acts, /Text\("\+ Agregar Hallazgo"\)/);
|
||||||
|
assert.match(acts, /model\.createAct\(newActUrgency\)/);
|
||||||
|
assert.match(vm, /fun createAct\(urgency: String = "NON_URGENT"\)/);
|
||||||
|
assert.match(vm, /repository\.fieldInventory\(currentVisit\.id, search, parentId\)/);
|
||||||
|
});
|
||||||
@@ -0,0 +1,50 @@
|
|||||||
|
import assert from 'node:assert/strict';
|
||||||
|
import test from 'node:test';
|
||||||
|
import type { DataSource } from 'typeorm';
|
||||||
|
import { FieldBriefingService } from '../../src/act-administration/field-briefing.service';
|
||||||
|
|
||||||
|
test('field briefing convierte el timestamptz de pg a YYYY-MM-DD antes del cast SQL', async () => {
|
||||||
|
const calls: Array<{ sql: string; params: unknown[] }> = [];
|
||||||
|
let queryNumber = 0;
|
||||||
|
|
||||||
|
const dataSource = {
|
||||||
|
query: async (sql: string, params: unknown[]) => {
|
||||||
|
calls.push({ sql, params });
|
||||||
|
queryNumber += 1;
|
||||||
|
|
||||||
|
if (queryNumber === 1) {
|
||||||
|
return [{
|
||||||
|
id: '11111111-1111-4111-8111-111111111111',
|
||||||
|
code: 'INSP-00002-17-09-26',
|
||||||
|
status: 'DRAFT',
|
||||||
|
plannedStartAt: new Date('2026-09-17T23:42:00.000Z'),
|
||||||
|
areaId: '22222222-2222-4222-8222-222222222222',
|
||||||
|
companyId: '33333333-3333-4333-8333-333333333333',
|
||||||
|
areaCode: 'PRES-AREA-TEST',
|
||||||
|
areaName: 'Barrancas',
|
||||||
|
companyCode: 'PRES-ORG-TEST',
|
||||||
|
companyName: 'Petróleos Sudamericanos Energy S.A.',
|
||||||
|
}];
|
||||||
|
}
|
||||||
|
|
||||||
|
return [];
|
||||||
|
},
|
||||||
|
} as unknown as DataSource;
|
||||||
|
|
||||||
|
const result = await new FieldBriefingService(dataSource).forVisit(
|
||||||
|
'11111111-1111-4111-8111-111111111111',
|
||||||
|
);
|
||||||
|
|
||||||
|
assert.equal(calls.length, 2);
|
||||||
|
assert.equal(calls[1]?.params[3], '2026-09-17');
|
||||||
|
assert.equal(result.plannedOn, '2026-09-17');
|
||||||
|
assert.deepEqual(result.summary, {
|
||||||
|
acts: 0,
|
||||||
|
findings: 0,
|
||||||
|
inventoryItems: 0,
|
||||||
|
responseOverdue: 0,
|
||||||
|
commitmentOverdue: 0,
|
||||||
|
verificationPending: 0,
|
||||||
|
});
|
||||||
|
assert.deepEqual(result.acts, []);
|
||||||
|
});
|
||||||
@@ -7,6 +7,7 @@ import { ChangeInspectionVisitStatusDto } from '../../src/inspection-visits/dto/
|
|||||||
import { CreateInspectionVisitDto } from '../../src/inspection-visits/dto/create-inspection-visit.dto';
|
import { CreateInspectionVisitDto } from '../../src/inspection-visits/dto/create-inspection-visit.dto';
|
||||||
import { ReplaceInspectionVisitAssetsDto } from '../../src/inspection-visits/dto/replace-inspection-visit-assets.dto';
|
import { ReplaceInspectionVisitAssetsDto } from '../../src/inspection-visits/dto/replace-inspection-visit-assets.dto';
|
||||||
import { ReplaceInspectionVisitTeamDto } from '../../src/inspection-visits/dto/replace-inspection-visit-team.dto';
|
import { ReplaceInspectionVisitTeamDto } from '../../src/inspection-visits/dto/replace-inspection-visit-team.dto';
|
||||||
|
import { UpdateInspectionVisitDto } from '../../src/inspection-visits/dto/update-inspection-visit.dto';
|
||||||
|
|
||||||
const AREA_ID = '16e54e65-60cf-4739-b0d1-ccdd904fbfd5';
|
const AREA_ID = '16e54e65-60cf-4739-b0d1-ccdd904fbfd5';
|
||||||
const COMPANY_ID = 'ce96211d-ac15-4421-8868-4185323aff61';
|
const COMPANY_ID = 'ce96211d-ac15-4421-8868-4185323aff61';
|
||||||
@@ -25,6 +26,25 @@ test('visit DTO accepts only the minimum planning data required for quick creati
|
|||||||
assert.equal(dto.leadInspectorUserId, USER_ID);
|
assert.equal(dto.leadInspectorUserId, USER_ID);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('visit update DTO keeps Area, Yacimiento and Operadora immutable after creation', async () => {
|
||||||
|
const contextAttempt = plainToInstance(UpdateInspectionVisitDto, {
|
||||||
|
operationalAreaId: AREA_ID,
|
||||||
|
scopeAssetId: AREA_ID,
|
||||||
|
operatorCompanyId: COMPANY_ID,
|
||||||
|
});
|
||||||
|
const errors = await validate(contextAttempt);
|
||||||
|
assert.equal(errors.some((error) => error.property === 'operationalAreaId'), true);
|
||||||
|
assert.equal(errors.some((error) => error.property === 'scopeAssetId'), true);
|
||||||
|
assert.equal(errors.some((error) => error.property === 'operatorCompanyId'), true);
|
||||||
|
|
||||||
|
const ordinaryUpdate = plainToInstance(UpdateInspectionVisitDto, {
|
||||||
|
objective: 'Control preventivo programado',
|
||||||
|
plannedStartAt: '2026-09-17T12:00:00.000Z',
|
||||||
|
instructions: 'Coordinar ingreso con la Operadora.',
|
||||||
|
});
|
||||||
|
assert.deepEqual(await validate(ordinaryUpdate), []);
|
||||||
|
});
|
||||||
|
|
||||||
test('asset and team DTOs reject duplicate references', async () => {
|
test('asset and team DTOs reject duplicate references', async () => {
|
||||||
const assets = Object.assign(new ReplaceInspectionVisitAssetsDto(), {
|
const assets = Object.assign(new ReplaceInspectionVisitAssetsDto(), {
|
||||||
assetIds: [AREA_ID, AREA_ID],
|
assetIds: [AREA_ID, AREA_ID],
|
||||||
|
|||||||
@@ -0,0 +1,43 @@
|
|||||||
|
export interface InspectionPreventiveCandidate {
|
||||||
|
id: string;
|
||||||
|
code: string;
|
||||||
|
name: string;
|
||||||
|
typeName: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
interface PreventiveCandidateResponse {
|
||||||
|
data: InspectionPreventiveCandidate[];
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function listInspectionPreventiveCandidates(
|
||||||
|
visitId: string,
|
||||||
|
search = '',
|
||||||
|
): Promise<InspectionPreventiveCandidate[]> {
|
||||||
|
const query = new URLSearchParams();
|
||||||
|
const term = search.trim();
|
||||||
|
if (term) query.set('search', term);
|
||||||
|
|
||||||
|
const response = await fetch(
|
||||||
|
`/api/v3/inspection-visits/${visitId}/preventive-candidates${query.size ? `?${query}` : ''}`,
|
||||||
|
{
|
||||||
|
method: 'GET',
|
||||||
|
credentials: 'same-origin',
|
||||||
|
headers: { Accept: 'application/json' },
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
|
if (!response.ok) {
|
||||||
|
let message = 'No se pudo cargar el Inventario disponible para esta Inspección';
|
||||||
|
try {
|
||||||
|
const payload = await response.json() as { message?: string | string[] };
|
||||||
|
if (Array.isArray(payload.message)) message = payload.message.join('. ');
|
||||||
|
else if (payload.message) message = payload.message;
|
||||||
|
} catch {
|
||||||
|
// Conserva el mensaje funcional cuando la respuesta no sea JSON.
|
||||||
|
}
|
||||||
|
throw new Error(message);
|
||||||
|
}
|
||||||
|
|
||||||
|
const payload = await response.json() as PreventiveCandidateResponse;
|
||||||
|
return payload.data ?? [];
|
||||||
|
}
|
||||||
@@ -11,13 +11,18 @@ import {
|
|||||||
inspectionStatusClass,
|
inspectionStatusClass,
|
||||||
inspectionVisitStatusLabel,
|
inspectionVisitStatusLabel,
|
||||||
} from '../features/inspections/inspectionPresentation';
|
} from '../features/inspections/inspectionPresentation';
|
||||||
|
import {
|
||||||
|
listInspectionPreventiveCandidates,
|
||||||
|
} from '../features/inspections/preventiveCandidatesApi';
|
||||||
|
import type {
|
||||||
|
InspectionPreventiveCandidate,
|
||||||
|
} from '../features/inspections/preventiveCandidatesApi';
|
||||||
import {
|
import {
|
||||||
createInspectionVisit,
|
createInspectionVisit,
|
||||||
excludeInspectionVisitAsset,
|
excludeInspectionVisitAsset,
|
||||||
generateInspectionVisitChecklist,
|
generateInspectionVisitChecklist,
|
||||||
getInspectionVisit,
|
getInspectionVisit,
|
||||||
includeInspectionVisitAsset,
|
includeInspectionVisitAsset,
|
||||||
listAssets,
|
|
||||||
listInspectionAssignees,
|
listInspectionAssignees,
|
||||||
listInspectionPlanningAreas,
|
listInspectionPlanningAreas,
|
||||||
listInspectionPlanningOperators,
|
listInspectionPlanningOperators,
|
||||||
@@ -26,7 +31,6 @@ import {
|
|||||||
updateInspectionVisit,
|
updateInspectionVisit,
|
||||||
} from '../lib/api';
|
} from '../lib/api';
|
||||||
import type {
|
import type {
|
||||||
AssetListItem,
|
|
||||||
InspectionPerson,
|
InspectionPerson,
|
||||||
InspectionPlanningContextAsset,
|
InspectionPlanningContextAsset,
|
||||||
InspectionVisit,
|
InspectionVisit,
|
||||||
@@ -100,7 +104,7 @@ export function InspectionVisitEditorF4Page() {
|
|||||||
const [areas, setAreas] = useState<InspectionPlanningContextAsset[]>([]);
|
const [areas, setAreas] = useState<InspectionPlanningContextAsset[]>([]);
|
||||||
const [operators, setOperators] = useState<InspectionPlanningContextAsset[]>([]);
|
const [operators, setOperators] = useState<InspectionPlanningContextAsset[]>([]);
|
||||||
const [assignees, setAssignees] = useState<InspectionPerson[]>([]);
|
const [assignees, setAssignees] = useState<InspectionPerson[]>([]);
|
||||||
const [assets, setAssets] = useState<AssetListItem[]>([]);
|
const [assets, setAssets] = useState<InspectionPreventiveCandidate[]>([]);
|
||||||
const [assetSearch, setAssetSearch] = useState('');
|
const [assetSearch, setAssetSearch] = useState('');
|
||||||
const [newAssetId, setNewAssetId] = useState('');
|
const [newAssetId, setNewAssetId] = useState('');
|
||||||
const [leadInspectorId, setLeadInspectorId] = useState('');
|
const [leadInspectorId, setLeadInspectorId] = useState('');
|
||||||
@@ -136,9 +140,9 @@ export function InspectionVisitEditorF4Page() {
|
|||||||
};
|
};
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
listInspectionPlanningAreas().then(setAreas).catch(() => undefined);
|
if (isNew) listInspectionPlanningAreas().then(setAreas).catch(() => undefined);
|
||||||
if (canAssign) listInspectionAssignees().then(setAssignees).catch(() => undefined);
|
if (canAssign) listInspectionAssignees().then(setAssignees).catch(() => undefined);
|
||||||
}, [canAssign]);
|
}, [canAssign, isNew]);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (!isNew || form.operationalAreaId || !context.areaId) return;
|
if (!isNew || form.operationalAreaId || !context.areaId) return;
|
||||||
@@ -158,29 +162,27 @@ export function InspectionVisitEditorF4Page() {
|
|||||||
}, [id]);
|
}, [id]);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (!form.operationalAreaId) {
|
if (!isNew || !form.operationalAreaId) {
|
||||||
setOperators([]);
|
setOperators([]);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
listInspectionPlanningOperators(form.operationalAreaId)
|
listInspectionPlanningOperators(form.operationalAreaId)
|
||||||
.then(setOperators)
|
.then(setOperators)
|
||||||
.catch(() => setOperators([]));
|
.catch(() => setOperators([]));
|
||||||
}, [form.operationalAreaId]);
|
}, [form.operationalAreaId, isNew]);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (!form.operationalAreaId || !form.operatorCompanyId) {
|
if (!id || !visit) {
|
||||||
setAssets([]);
|
setAssets([]);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const timer = window.setTimeout(() => {
|
const timer = window.setTimeout(() => {
|
||||||
listAssets({
|
listInspectionPreventiveCandidates(id, assetSearch)
|
||||||
pageSize: 100,
|
.then(setAssets)
|
||||||
search: assetSearch.trim(),
|
.catch((requestError) => setError(errorMessage(requestError)));
|
||||||
operationalAreaId: form.operationalAreaId,
|
|
||||||
}).then((response) => setAssets(response.data)).catch(() => undefined);
|
|
||||||
}, 220);
|
}, 220);
|
||||||
return () => window.clearTimeout(timer);
|
return () => window.clearTimeout(timer);
|
||||||
}, [assetSearch, form.operationalAreaId, form.operatorCompanyId]);
|
}, [id, assetSearch, visit?.updatedAt]);
|
||||||
|
|
||||||
const planningEditable = !visit || visit.status === 'DRAFT' || visit.status === 'PLANNED';
|
const planningEditable = !visit || visit.status === 'DRAFT' || visit.status === 'PLANNED';
|
||||||
const activeAssetIds = useMemo(() => new Set(visit?.assets.map((asset) => asset.id) ?? []), [visit]);
|
const activeAssetIds = useMemo(() => new Set(visit?.assets.map((asset) => asset.id) ?? []), [visit]);
|
||||||
@@ -209,13 +211,10 @@ export function InspectionVisitEditorF4Page() {
|
|||||||
} else if (id) {
|
} else if (id) {
|
||||||
applyVisit(await updateInspectionVisit(id, {
|
applyVisit(await updateInspectionVisit(id, {
|
||||||
objective: form.objective.trim() || null,
|
objective: form.objective.trim() || null,
|
||||||
scopeAssetId: visit?.scopeAsset?.id ?? null,
|
|
||||||
operationalAreaId: form.operationalAreaId || null,
|
|
||||||
operatorCompanyId: form.operatorCompanyId || null,
|
|
||||||
plannedStartAt,
|
plannedStartAt,
|
||||||
instructions: form.instructions.trim() || null,
|
instructions: form.instructions.trim() || null,
|
||||||
}));
|
}));
|
||||||
setSuccess('Planificación actualizada. Regenerá el checklist si cambió contexto o fecha.');
|
setSuccess('Planificación actualizada. Si cambió la fecha, regenerá el checklist.');
|
||||||
}
|
}
|
||||||
} catch (requestError) {
|
} catch (requestError) {
|
||||||
setError(errorMessage(requestError));
|
setError(errorMessage(requestError));
|
||||||
@@ -240,6 +239,7 @@ export function InspectionVisitEditorF4Page() {
|
|||||||
setBusy(true); setError(''); setSuccess('');
|
setBusy(true); setError(''); setSuccess('');
|
||||||
try {
|
try {
|
||||||
applyVisit(await replaceInspectionVisitAssets(id, [...activeAssetIds, newAssetId]), false);
|
applyVisit(await replaceInspectionVisitAssets(id, [...activeAssetIds, newAssetId]), false);
|
||||||
|
setAssets((current) => current.filter((asset) => asset.id !== newAssetId));
|
||||||
setNewAssetId('');
|
setNewAssetId('');
|
||||||
setSuccess('Registro agregado como preventivo.');
|
setSuccess('Registro agregado como preventivo.');
|
||||||
} catch (requestError) { setError(errorMessage(requestError)); }
|
} catch (requestError) { setError(errorMessage(requestError)); }
|
||||||
@@ -340,12 +340,12 @@ export function InspectionVisitEditorF4Page() {
|
|||||||
{error && <Alert>{error}</Alert>}{success && <Alert type="success">{success}</Alert>}
|
{error && <Alert>{error}</Alert>}{success && <Alert type="success">{success}</Alert>}
|
||||||
|
|
||||||
<form className={`panel form-panel ${isNew ? 'inspection-quick-create' : ''}`} onSubmit={saveGeneral}>
|
<form className={`panel form-panel ${isNew ? 'inspection-quick-create' : ''}`} onSubmit={saveGeneral}>
|
||||||
<div className="panel-heading"><div><span className="eyebrow">{isNew ? 'CREACIÓN RÁPIDA' : 'PLANIFICACIÓN'}</span><h2>Contexto y fecha de inicio</h2><p className="section-copy">No existe título independiente ni fecha de fin planificada. El cierre real se registra al terminar el trabajo de campo.</p></div>{visit && <small className="muted">Actualizado {formatDate(visit.updatedAt)}</small>}</div>
|
<div className="panel-heading"><div><span className="eyebrow">{isNew ? 'CREACIÓN RÁPIDA' : 'PLANIFICACIÓN'}</span><h2>Contexto y fecha de inicio</h2><p className="section-copy">El Área, Yacimiento y Operadora quedan fijados al crear la Inspección. La fecha puede reprogramarse antes del trabajo de campo.</p></div>{visit && <small className="muted">Actualizado {formatDate(visit.updatedAt)}</small>}</div>
|
||||||
{visit && <div className="inspection-generated-code"><small>Identificador institucional</small><strong>{visit.code}</strong></div>}
|
{visit && <div className="inspection-generated-code"><small>Identificador institucional</small><strong>{visit.code}</strong></div>}
|
||||||
<div className="form-grid">
|
<div className="form-grid">
|
||||||
<label className="field"><span>Área</span><SearchableSelect searchPlaceholder="Buscar Área…" value={form.operationalAreaId} onChange={(event) => { context.setAreaId(event.target.value); setForm((current) => ({ ...current, operationalAreaId: event.target.value, operatorCompanyId: '' })); }} required disabled={!canManage || !planningEditable}><option value="">Seleccionar Área…</option>{areas.map((area) => <option key={area.id} value={area.id}>{area.name} · {area.code}</option>)}</SearchableSelect></label>
|
{isNew ? <label className="field"><span>Área</span><SearchableSelect searchPlaceholder="Buscar Área…" value={form.operationalAreaId} onChange={(event) => { context.setAreaId(event.target.value); setForm((current) => ({ ...current, operationalAreaId: event.target.value, operatorCompanyId: '' })); }} required disabled={!canManage || !planningEditable}><option value="">Seleccionar Área…</option>{areas.map((area) => <option key={area.id} value={area.id}>{area.name} · {area.code}</option>)}</SearchableSelect></label> : <label className="field"><span>Área</span><input value={visit?.operationalArea ? `${visit.operationalArea.name} · ${visit.operationalArea.code}` : 'Sin Área'} readOnly aria-readonly="true" /></label>}
|
||||||
{!isNew && <label className="field"><span>Yacimiento</span><input value={visit?.scopeAsset?.name ?? 'Sin Yacimiento'} readOnly aria-readonly="true" /></label>}
|
{!isNew && <label className="field"><span>Yacimiento</span><input value={visit?.scopeAsset ? `${visit.scopeAsset.name} · ${visit.scopeAsset.code}` : 'Sin Yacimiento'} readOnly aria-readonly="true" /></label>}
|
||||||
<label className="field"><span>Operadora</span><SearchableSelect searchPlaceholder="Buscar Operadora…" value={form.operatorCompanyId} onChange={(event) => { context.setCompanyId(event.target.value); setForm((current) => ({ ...current, operatorCompanyId: event.target.value })); }} required disabled={!canManage || !planningEditable || !form.operationalAreaId}><option value="">Seleccionar Operadora…</option>{operators.map((operator) => <option key={operator.id} value={operator.id}>{operator.name} · {operator.code}</option>)}</SearchableSelect></label>
|
{isNew ? <label className="field"><span>Operadora</span><SearchableSelect searchPlaceholder="Buscar Operadora…" value={form.operatorCompanyId} onChange={(event) => { context.setCompanyId(event.target.value); setForm((current) => ({ ...current, operatorCompanyId: event.target.value })); }} required disabled={!canManage || !planningEditable || !form.operationalAreaId}><option value="">Seleccionar Operadora…</option>{operators.map((operator) => <option key={operator.id} value={operator.id}>{operator.name} · {operator.code}</option>)}</SearchableSelect></label> : <label className="field"><span>Operadora</span><input value={visit?.operatorCompany ? `${visit.operatorCompany.name} · ${visit.operatorCompany.code}` : 'Sin Operadora'} readOnly aria-readonly="true" /></label>}
|
||||||
<label className="field"><span>Fecha y hora de inicio</span><input type="datetime-local" value={form.plannedStartAt} onChange={(event) => setForm((current) => ({ ...current, plannedStartAt: event.target.value }))} required disabled={!canManage || !planningEditable} /></label>
|
<label className="field"><span>Fecha y hora de inicio</span><input type="datetime-local" value={form.plannedStartAt} onChange={(event) => setForm((current) => ({ ...current, plannedStartAt: event.target.value }))} required disabled={!canManage || !planningEditable} /></label>
|
||||||
{isNew && <label className="field"><span>Inspector responsable</span><SearchableSelect searchPlaceholder="Buscar Inspector…" value={leadInspectorId} onChange={(event) => setLeadInspectorId(event.target.value)} required disabled={!canAssign}><option value="">Seleccionar Inspector…</option>{assignees.map((person) => <option key={person.id} value={person.id}>{personName(person)} · {person.username}</option>)}</SearchableSelect></label>}
|
{isNew && <label className="field"><span>Inspector responsable</span><SearchableSelect searchPlaceholder="Buscar Inspector…" value={leadInspectorId} onChange={(event) => setLeadInspectorId(event.target.value)} required disabled={!canAssign}><option value="">Seleccionar Inspector…</option>{assignees.map((person) => <option key={person.id} value={person.id}>{personName(person)} · {person.username}</option>)}</SearchableSelect></label>}
|
||||||
</div>
|
</div>
|
||||||
@@ -354,15 +354,15 @@ export function InspectionVisitEditorF4Page() {
|
|||||||
</form>
|
</form>
|
||||||
|
|
||||||
{visit && <article className="panel inspection-checklist-panel">
|
{visit && <article className="panel inspection-checklist-panel">
|
||||||
<div className="panel-heading"><div><span className="eyebrow">CHECKLIST TÉCNICO</span><h2>Antecedentes y controles</h2><p className="section-copy">Se construye por Área, Operadora y fecha. Las respuestas administrativas de empresa no modifican este checklist.</p></div>{canManage && planningEditable && <button type="button" className="button secondary" onClick={() => void regenerateChecklist()} disabled={busy}>Regenerar checklist</button>}</div>
|
<div className="panel-heading"><div><span className="eyebrow">CHECKLIST TÉCNICO</span><h2>Antecedentes y controles</h2><p className="section-copy">Se construye para el Área, Yacimiento y Operadora fijados en la Inspección, tomando la fecha planificada. Las respuestas administrativas de empresa no modifican este checklist.</p></div>{canManage && planningEditable && <button type="button" className="button secondary" onClick={() => void regenerateChecklist()} disabled={busy}>Regenerar checklist</button>}</div>
|
||||||
{visit.checklist.stale && <Alert>El contexto o la fecha cambió. Regenerá el checklist antes de planificar.</Alert>}
|
{visit.checklist.stale && <Alert>La fecha cambió. Regenerá el checklist antes de planificar.</Alert>}
|
||||||
<div className="inspection-checklist-metrics"><div><strong>{visit.checklist.verificationOverdue}</strong><span>controles vencidos</span></div><div><strong>{visit.checklist.upcomingControls}</strong><span>próximos 30 días</span></div><div><strong>{visit.checklist.antecedents}</strong><span>antecedentes</span></div><div><strong>{visit.checklist.actionableAssets}</strong><span>registros sugeridos</span></div></div>
|
<div className="inspection-checklist-metrics"><div><strong>{visit.checklist.verificationOverdue}</strong><span>controles vencidos</span></div><div><strong>{visit.checklist.upcomingControls}</strong><span>próximos 30 días</span></div><div><strong>{visit.checklist.antecedents}</strong><span>antecedentes</span></div><div><strong>{visit.checklist.actionableAssets}</strong><span>registros sugeridos</span></div></div>
|
||||||
{visit.checklist.items.length === 0 ? <EmptyState title="Sin antecedentes" text="No hay Hallazgos históricos técnicos para este contexto." /> : <div className="table-scroll"><table><thead><tr><th>Tipo</th><th>Hallazgo</th><th>Inventario</th><th>Fecha</th><th>Gravedad</th></tr></thead><tbody>{visit.checklist.items.map((item) => <tr key={item.id}><td><span className={`status-badge ${item.itemKind === 'ANTECEDENT' ? '' : 'warning'}`}>{checklistLabel(item.itemKind)}</span></td><td><Link className="history-asset-link" to={`/hallazgos/${item.findingId}`}><strong>{item.findingTitle}</strong><small>{item.findingCode}</small></Link></td><td><Link className="history-asset-link" to={`/inventarios/${item.asset.id}`}><strong>{item.asset.name}</strong><small>{item.asset.code} · {item.asset.typeName}</small></Link></td><td>{formatDateOnly(item.referenceOn)}</td><td>{item.severity ?? '—'}</td></tr>)}</tbody></table></div>}
|
{visit.checklist.items.length === 0 ? <EmptyState title="Sin antecedentes" text="No hay Hallazgos históricos técnicos para este contexto." /> : <div className="table-scroll"><table><thead><tr><th>Tipo</th><th>Hallazgo</th><th>Inventario</th><th>Fecha</th><th>Gravedad</th></tr></thead><tbody>{visit.checklist.items.map((item) => <tr key={item.id}><td><span className={`status-badge ${item.itemKind === 'ANTECEDENT' ? '' : 'warning'}`}>{checklistLabel(item.itemKind)}</span></td><td><Link className="history-asset-link" to={`/hallazgos/${item.findingId}`}><strong>{item.findingTitle}</strong><small>{item.findingCode}</small></Link></td><td><Link className="history-asset-link" to={`/inventarios/${item.asset.id}`}><strong>{item.asset.name}</strong><small>{item.asset.code} · {item.asset.typeName}</small></Link></td><td>{formatDateOnly(item.referenceOn)}</td><td>{item.severity ?? '—'}</td></tr>)}</tbody></table></div>}
|
||||||
</article>}
|
</article>}
|
||||||
|
|
||||||
{visit && visit.verificationFindings.length > 0 && <article className="panel verification-visit-findings"><div className="panel-heading"><div><span className="eyebrow">VERIFICACIÓN</span><h2>Hallazgos a controlar</h2></div><span className="count-pill">{visit.verificationFindings.length}</span></div><div className="dossier-link-list">{visit.verificationFindings.map((finding) => <Link key={finding.id} to={`/hallazgos/${finding.id}`}><div><strong>{finding.title}</strong><small>{finding.code} · {finding.assetName} · objetivo {formatDateOnly(finding.targetControlOn ?? finding.nextControlOn)}</small>{finding.resultNotes && <small>{finding.resultNotes}</small>}</div><span>{finding.outcome === 'RESOLVED' ? 'Solucionado' : finding.outcome === 'NOT_RESOLVED' ? 'No solucionado' : finding.outcome === 'REQUIRES_NEW_DATE' ? 'Reprogramar' : 'Pendiente'}</span><Icon name="chevron" size={16} /></Link>)}</div></article>}
|
{visit && visit.verificationFindings.length > 0 && <article className="panel verification-visit-findings"><div className="panel-heading"><div><span className="eyebrow">VERIFICACIÓN</span><h2>Hallazgos a controlar</h2></div><span className="count-pill">{visit.verificationFindings.length}</span></div><div className="dossier-link-list">{visit.verificationFindings.map((finding) => <Link key={finding.id} to={`/hallazgos/${finding.id}`}><div><strong>{finding.title}</strong><small>{finding.code} · {finding.assetName} · objetivo {formatDateOnly(finding.targetControlOn ?? finding.nextControlOn)}</small>{finding.resultNotes && <small>{finding.resultNotes}</small>}</div><span>{finding.outcome === 'RESOLVED' ? 'Solucionado' : finding.outcome === 'NOT_RESOLVED' ? 'No solucionado' : finding.outcome === 'REQUIRES_NEW_DATE' ? 'Reprogramar' : 'Pendiente'}</span><Icon name="chevron" size={16} /></Link>)}</div></article>}
|
||||||
|
|
||||||
{visit && planningEditable && canManage && <form className="panel survey-add-target" onSubmit={addPreventiveAsset}><div className="panel-heading"><div><span className="eyebrow">PREVENTIVO</span><h2>Agregar Inventario sin pendiente previo</h2></div></div><label className="field"><span>Buscar Inventario</span><input value={assetSearch} onChange={(event) => setAssetSearch(event.target.value)} placeholder="Código o nombre" /></label><label className="field"><span>Inventario</span><SearchableSelect value={newAssetId} onChange={(event) => setNewAssetId(event.target.value)} required><option value="">Seleccionar…</option>{candidateAssets.map((asset) => <option key={asset.id} value={asset.id}>{asset.code} · {asset.name} · {asset.type.name}</option>)}</SearchableSelect></label><div className="form-actions"><button className="button primary" disabled={busy || !newAssetId}><Icon name="plus" />Agregar preventivo</button></div></form>}
|
{visit && planningEditable && canManage && <form className="panel survey-add-target" onSubmit={addPreventiveAsset}><div className="panel-heading"><div><span className="eyebrow">PREVENTIVO</span><h2>Agregar Inventario sin pendiente previo</h2><p className="section-copy">Sólo se muestran Instalaciones y Subinstalaciones pertenecientes al Yacimiento fijado para esta Inspección.</p></div></div><label className="field"><span>Buscar Inventario</span><input value={assetSearch} onChange={(event) => setAssetSearch(event.target.value)} placeholder="Código o nombre" /></label><label className="field"><span>Inventario</span><SearchableSelect value={newAssetId} onChange={(event) => setNewAssetId(event.target.value)} required><option value="">Seleccionar…</option>{candidateAssets.map((asset) => <option key={asset.id} value={asset.id}>{asset.code} · {asset.name} · {asset.typeName}</option>)}</SearchableSelect></label><div className="form-actions"><button className="button primary" disabled={busy || !newAssetId}><Icon name="plus" />Agregar preventivo</button></div></form>}
|
||||||
|
|
||||||
{visit && <article className="table-panel inspection-assets"><div className="table-summary"><strong>{visit.assets.length} incluidos</strong><span>{visit.checklist.excludedAssets} excluidos con trazabilidad</span></div>{visit.planningAssets.length === 0 ? <EmptyState title="Sin Inventarios" text="Generá el checklist o agregá un preventivo." /> : <div className="table-scroll"><table><thead><tr><th>Inventario</th><th>Origen</th><th>Estado</th><th>Motivo</th><th /></tr></thead><tbody>{visit.planningAssets.map((asset) => <tr key={asset.id}><td><Link className="history-asset-link" to={`/inventarios/${asset.id}`}><strong>{asset.name}</strong><small>{asset.code} · {asset.typeName}</small></Link></td><td>{sourceLabel(asset.planningSource)}</td><td>{asset.included ? 'Incluido' : 'Excluido'}</td><td>{asset.exclusionReason ?? '—'}</td><td>{canManage && planningEditable && (asset.included ? <button type="button" className="button danger-outline compact" onClick={() => void excludeAsset(asset.id)}>Excluir</button> : <button type="button" className="button secondary compact" onClick={() => void reincludeAsset(asset.id)}>Reincorporar</button>)}</td></tr>)}</tbody></table></div>}</article>}
|
{visit && <article className="table-panel inspection-assets"><div className="table-summary"><strong>{visit.assets.length} incluidos</strong><span>{visit.checklist.excludedAssets} excluidos con trazabilidad</span></div>{visit.planningAssets.length === 0 ? <EmptyState title="Sin Inventarios" text="Generá el checklist o agregá un preventivo." /> : <div className="table-scroll"><table><thead><tr><th>Inventario</th><th>Origen</th><th>Estado</th><th>Motivo</th><th /></tr></thead><tbody>{visit.planningAssets.map((asset) => <tr key={asset.id}><td><Link className="history-asset-link" to={`/inventarios/${asset.id}`}><strong>{asset.name}</strong><small>{asset.code} · {asset.typeName}</small></Link></td><td>{sourceLabel(asset.planningSource)}</td><td>{asset.included ? 'Incluido' : 'Excluido'}</td><td>{asset.exclusionReason ?? '—'}</td><td>{canManage && planningEditable && (asset.included ? <button type="button" className="button danger-outline compact" onClick={() => void excludeAsset(asset.id)}>Excluir</button> : <button type="button" className="button secondary compact" onClick={() => void reincludeAsset(asset.id)}>Reincorporar</button>)}</td></tr>)}</tbody></table></div>}</article>}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user