feat: el check de supervisor manda sobre el trabajador vinculado
El flag ya estaba en el ERP pero el bot no lo recibia, asi que un supervisor con su propio tercero vinculado habria quedado reportando siempre a nombre propio: justo el caso que motivo el check. Ahora es_supervisor viaja en la sincronizacion y desactiva el pre-llenado, de modo que se le pregunta de quien es cada registro aunque tenga tercero. La columna la crea el seed, como las otras dos. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Sonnet 4.6
parent
673c15dae3
commit
e3399cca9e
+14
-10
@@ -458,12 +458,12 @@ class NormalBot
|
|||||||
$clave = $company['id'] . '|' . $waNumber;
|
$clave = $company['id'] . '|' . $waNumber;
|
||||||
if (isset($cache[$clave])) return $cache[$clave];
|
if (isset($cache[$clave])) return $cache[$clave];
|
||||||
|
|
||||||
$vacio = ['tercero_id' => null, 'modulos' => []];
|
$vacio = ['tercero_id' => null, 'modulos' => [], 'es_supervisor' => false];
|
||||||
if ($waNumber === '') return $vacio;
|
if ($waNumber === '') return $vacio;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
$stmt = db()->prepare(
|
$stmt = db()->prepare(
|
||||||
"SELECT tercero_id, modulos_json FROM company_phones WHERE company_id = ? AND wa_number = ? LIMIT 1"
|
"SELECT tercero_id, modulos_json, es_supervisor FROM company_phones WHERE company_id = ? AND wa_number = ? LIMIT 1"
|
||||||
);
|
);
|
||||||
$stmt->execute([(int)$company['id'], $waNumber]);
|
$stmt->execute([(int)$company['id'], $waNumber]);
|
||||||
$row = $stmt->fetch();
|
$row = $stmt->fetch();
|
||||||
@@ -474,7 +474,8 @@ class NormalBot
|
|||||||
|
|
||||||
return $cache[$clave] = [
|
return $cache[$clave] = [
|
||||||
'tercero_id' => $row['tercero_id'] ?: null,
|
'tercero_id' => $row['tercero_id'] ?: null,
|
||||||
'modulos' => json_decode((string)($row['modulos_json'] ?? ''), true) ?: [],
|
'modulos' => json_decode((string)($row['modulos_json'] ?? ''), true) ?: [],
|
||||||
|
'es_supervisor' => !empty($row['es_supervisor']),
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1063,14 +1064,17 @@ class NormalBot
|
|||||||
$collected = [];
|
$collected = [];
|
||||||
$startIdx = 0;
|
$startIdx = 0;
|
||||||
|
|
||||||
// from_phone: el dato sale del perfil del numero, no se pregunta. Con un
|
// from_phone: el dato sale del perfil del numero en vez de preguntarse.
|
||||||
// tercero vinculado el trabajador reporta lo suyo y el bot no le pide
|
// Un trabajador reporta lo suyo y no se le pide que se busque a si
|
||||||
// que se busque a si mismo; sin vinculo es supervisor y elige.
|
// mismo; un supervisor reporta por otros, asi que se le pregunta igual
|
||||||
|
// aunque tenga su propio tercero vinculado.
|
||||||
$perfil = self::perfilDelNumero($company, $context['from'] ?? '');
|
$perfil = self::perfilDelNumero($company, $context['from'] ?? '');
|
||||||
foreach ($fields as $f) {
|
if (empty($perfil['es_supervisor'])) {
|
||||||
$origen = $f['from_phone'] ?? '';
|
foreach ($fields as $f) {
|
||||||
if ($origen !== '' && !empty($perfil[$origen])) {
|
$origen = $f['from_phone'] ?? '';
|
||||||
$collected[$f['key']] = (string)$perfil[$origen];
|
if ($origen !== '' && !empty($perfil[$origen])) {
|
||||||
|
$collected[$f['key']] = (string)$perfil[$origen];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -71,13 +71,14 @@ class PhoneSync
|
|||||||
|
|
||||||
$db = db();
|
$db = db();
|
||||||
$upsert = $db->prepare("
|
$upsert = $db->prepare("
|
||||||
INSERT INTO company_phones (company_id, wa_number, label, permission_type, tercero_id, modulos_json, is_active)
|
INSERT INTO company_phones (company_id, wa_number, label, permission_type, tercero_id, modulos_json, es_supervisor, is_active)
|
||||||
VALUES (?, ?, ?, ?, ?, ?, 1)
|
VALUES (?, ?, ?, ?, ?, ?, ?, 1)
|
||||||
ON DUPLICATE KEY UPDATE
|
ON DUPLICATE KEY UPDATE
|
||||||
label = VALUES(label),
|
label = VALUES(label),
|
||||||
permission_type = VALUES(permission_type),
|
permission_type = VALUES(permission_type),
|
||||||
tercero_id = VALUES(tercero_id),
|
tercero_id = VALUES(tercero_id),
|
||||||
modulos_json = VALUES(modulos_json),
|
modulos_json = VALUES(modulos_json),
|
||||||
|
es_supervisor = VALUES(es_supervisor),
|
||||||
is_active = 1
|
is_active = 1
|
||||||
");
|
");
|
||||||
|
|
||||||
@@ -86,8 +87,8 @@ class PhoneSync
|
|||||||
$waNumber = trim($n['wa_number'] ?? '');
|
$waNumber = trim($n['wa_number'] ?? '');
|
||||||
if ($waNumber === '') continue;
|
if ($waNumber === '') continue;
|
||||||
|
|
||||||
// tercero_id vinculado = perfil trabajador: el bot no le pregunta
|
// Un supervisor reporta por otros, así que se le pregunta de quién
|
||||||
// de quién es el registro. Sin él, es supervisor y elige.
|
// es el registro aunque tenga su propio tercero vinculado.
|
||||||
$tercero = !empty($n['tercero_id']) ? (int)$n['tercero_id'] : null;
|
$tercero = !empty($n['tercero_id']) ? (int)$n['tercero_id'] : null;
|
||||||
$modulos = (array)($n['modulos'] ?? []);
|
$modulos = (array)($n['modulos'] ?? []);
|
||||||
|
|
||||||
@@ -98,6 +99,7 @@ class PhoneSync
|
|||||||
(int)($n['permiso'] ?? 1),
|
(int)($n['permiso'] ?? 1),
|
||||||
$tercero,
|
$tercero,
|
||||||
$modulos ? json_encode($modulos) : null,
|
$modulos ? json_encode($modulos) : null,
|
||||||
|
!empty($n['es_supervisor']) ? 1 : 0,
|
||||||
]);
|
]);
|
||||||
$activeNumbers[] = $waNumber;
|
$activeNumbers[] = $waNumber;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,8 +11,9 @@ $db = db();
|
|||||||
// despliegue. Es idempotente: si la columna existe, no hace nada.
|
// despliegue. Es idempotente: si la columna existe, no hace nada.
|
||||||
|
|
||||||
foreach ([
|
foreach ([
|
||||||
'tercero_id' => 'INT NULL',
|
'tercero_id' => 'INT NULL',
|
||||||
'modulos_json' => 'TEXT NULL',
|
'modulos_json' => 'TEXT NULL',
|
||||||
|
'es_supervisor' => 'TINYINT(1) NOT NULL DEFAULT 0',
|
||||||
] as $columna => $tipo) {
|
] as $columna => $tipo) {
|
||||||
$existe = $db->query("SHOW COLUMNS FROM company_phones LIKE '{$columna}'")->fetch();
|
$existe = $db->query("SHOW COLUMNS FROM company_phones LIKE '{$columna}'")->fetch();
|
||||||
if (!$existe) {
|
if (!$existe) {
|
||||||
|
|||||||
Reference in New Issue
Block a user