diff --git a/.env b/.env index b16b6a0..e427a09 100644 --- a/.env +++ b/.env @@ -1,4 +1,4 @@ -DB_HOST=localhost +DB_HOST=DESKTOP-22T88B6 DB_DATABASE=Importaciones_HC DB_USERNAME=sa DB_PASSWORD=Soluciones01 diff --git a/app/controllers/proveedores.php b/app/controllers/proveedores.php index 585c612..1044a54 100644 --- a/app/controllers/proveedores.php +++ b/app/controllers/proveedores.php @@ -130,12 +130,27 @@ function ajax_lista() if ($status === 200 && ($json = json_decode($resp, true)) && is_array($json)) { foreach ($json as $p) { $clave = htmlspecialchars($p['Clave'] ?? '', ENT_QUOTES); + + // Construir dirección + $direccion = trim(implode(', ', array_filter([ + $p['Calles'] ?? '', + 'Num. Ext: ' . ($p['NumExt'] ?? ''), + 'Num. Int: ' . ($p['NumInt'] ?? ''), + $p['Colonia'] ?? '', + $p['Municipio'] ?? '', + $p['Ciudad'] ?? '', + 'C.P. ' . ($p['CodigoPostal'] ?? ''), + $p['EntidadFederativa'] ?? '', + $p['Pais'] ?? '' + ]))); + $dataList[] = [ $clave, htmlspecialchars($p['Nombre'] ?? '', ENT_QUOTES), htmlspecialchars($p['RFC'] ?? '', ENT_QUOTES), htmlspecialchars($p['Ciudad'] ?? '', ENT_QUOTES), htmlspecialchars($p['Telefono']?? '', ENT_QUOTES), + htmlspecialchars($direccion ?? '', ENT_QUOTES), // Acciones "✏️ " @@ -149,7 +164,6 @@ function ajax_lista() echo json_encode(['data' => $dataList]); } - /** * GET /IMPORTADORES/proveedores/eliminar * Llama a DELETE /api/proveedores/:clave y redirige @@ -193,7 +207,6 @@ function crear() include __DIR__ . '/../../views/proveedores/crear.php'; } - /** * POST /IMPORTADORES/proveedores/guardar * Procesa el alta de un nuevo proveedor contra la API WinSAAI. @@ -267,5 +280,4 @@ function guardar() header('Location: /IMPORTADORES/proveedores/crear'); exit; } -} - +} \ No newline at end of file diff --git a/app/controllers/solicitud_importacion.php b/app/controllers/solicitud_importacion.php index ed442bc..04be6c0 100644 --- a/app/controllers/solicitud_importacion.php +++ b/app/controllers/solicitud_importacion.php @@ -64,8 +64,6 @@ function getApiToken(): ?string return null; } - - /** * Listado de solicitudes de importación (facturas) del importador logueado */ @@ -146,7 +144,6 @@ function crear() { $unidades_medida[] = $r; } - include __DIR__ . '/../../views/solicitud_importacion/crear.php'; } @@ -214,63 +211,59 @@ function guardar() { foto_solicitud_url, status, proveedor_clave) OUTPUT INSERTED.id_solicitud VALUES(?, ?, ?, ?, ?, NULL, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"; -; -$stmt = sqlsrv_query($conn, $sql, $params, ['Scrollable' => SQLSRV_CURSOR_KEYSET]); -if ($stmt === false) { - die("❌ Error ejecutando INSERT con OUTPUT: " . print_r(sqlsrv_errors(), true)); -} + $stmt = sqlsrv_query($conn, $sql, $params, ['Scrollable' => SQLSRV_CURSOR_KEYSET]); + if ($stmt === false) { + die("❌ Error ejecutando INSERT con OUTPUT: " . print_r(sqlsrv_errors(), true)); + } -$new = sqlsrv_fetch_array($stmt, SQLSRV_FETCH_ASSOC); -if (!$new || empty($new['id_solicitud'])) { - die("❌ No se pudo recuperar el ID insertado de la factura."); -} - -$id_solicitud = (int)$new['id_solicitud']; + $new = sqlsrv_fetch_array($stmt, SQLSRV_FETCH_ASSOC); + if (!$new || empty($new['id_solicitud'])) { + die("❌ No se pudo recuperar el ID insertado de la factura."); + } + $id_solicitud = (int)$new['id_solicitud']; - -// Partidas -if(!empty($_POST['partidas'])&&is_array($_POST['partidas'])){ + // Partidas + if(!empty($_POST['partidas'])&&is_array($_POST['partidas'])){ - $sqlP = "INSERT INTO dbo.solicitud_importacion_partidas - (id_solicitud, descripcion, cantidad_comercial, cantidad_tarifa, valor_factura, peso_bruto, unidad_comercial_id, tasa_preferencial) - VALUES (?, ?, ?, ?, ?, ?, ?, ?)"; + $sqlP = "INSERT INTO dbo.solicitud_importacion_partidas + (id_solicitud, descripcion, cantidad_comercial, cantidad_tarifa, valor_factura, peso_bruto, unidad_comercial_id, tasa_preferencial) + VALUES (?, ?, ?, ?, ?, ?, ?, ?)"; - $partidas_insertadas = 0; // ← contador + $partidas_insertadas = 0; // ← contador - foreach ($_POST['partidas'] as $i => $p) { - error_log("Partida $i: " . print_r($p, true)); - $params = [ - $id_solicitud, - trim($p['descripcion'] ?? ''), - - floatval($p['cantidad_comercial'] ?? 0), - floatval($p['cantidad_tarifa'] ?? 0), - floatval($p['valor_factura'] ?? 0), - floatval($p['peso_bruto'] ?? 0), - intval($p['unidad_comercial_id'] ?? 0) ?: null, - - trim($p['tasa_preferencial'] ?? '') - ]; + foreach ($_POST['partidas'] as $i => $p) { + error_log("Partida $i: " . print_r($p, true)); + $params = [ + $id_solicitud, + trim($p['descripcion'] ?? ''), + + floatval($p['cantidad_comercial'] ?? 0), + floatval($p['cantidad_tarifa'] ?? 0), + floatval($p['valor_factura'] ?? 0), + floatval($p['peso_bruto'] ?? 0), + intval($p['unidad_comercial_id'] ?? 0) ?: null, + + trim($p['tasa_preferencial'] ?? '') + ]; - if ($params[1] !== '' && $params[2] > 0) { - $stmtPartida = sqlsrv_query($conn, $sqlP, $params); - if ($stmtPartida === false) { - die("❌ Error insertando partida $i: " . print_r(sqlsrv_errors(), true)); - } else { - $partidas_insertadas++; + if ($params[1] !== '' && $params[2] > 0) { + $stmtPartida = sqlsrv_query($conn, $sqlP, $params); + if ($stmtPartida === false) { + die("❌ Error insertando partida $i: " . print_r(sqlsrv_errors(), true)); + } else { + $partidas_insertadas++; + } } } - } - if ($partidas_insertadas === 0) { - ///header('Location: /IMPORTADORES/solicitud_importacion/crear?error_partidas=1'); - // exit; - + if ($partidas_insertadas === 0) { + ///header('Location: /IMPORTADORES/solicitud_importacion/crear?error_partidas=1'); + // exit; + + } } -} - header('Location: /IMPORTADORES/solicitud_importacion/lista?created=ok'); exit; @@ -393,9 +386,11 @@ function ajax_proveedores() $out = ['results' => []]; if ($status === 200 && ($json = json_decode($resp, true)) && is_array($json)) { foreach ($json as $p) { + $clave = $p['Clave'] ?? ''; + $nombre = $p['Nombre'] ?? ''; $out['results'][] = [ - 'id' => $p['Clave'] ?? '', - 'text' => $p['Nombre'] ?? '' + 'id' => $clave, + 'text' => "[$clave] - $nombre" ]; } } @@ -405,10 +400,6 @@ function ajax_proveedores() exit; } - - - - function ajax_lista() { // 1) Fijamos el header JSON @@ -465,7 +456,6 @@ function ajax_lista() echo json_encode(['data' => $dataList]); } - function update_status() { header('Content-Type: application/json; charset=utf-8'); @@ -489,6 +479,4 @@ function update_status() { } echo json_encode(['success'=>true]); exit; - } - - +} \ No newline at end of file diff --git a/views/proveedores/lista.php b/views/proveedores/lista.php index 7a33885..215e626 100644 --- a/views/proveedores/lista.php +++ b/views/proveedores/lista.php @@ -91,7 +91,7 @@ ➕ Nuevo Proveedor
| RFC | Ciudad | Teléfono | +Dirección | Acciones |
|---|