Dirección y Clave de proveedor
This commit is contained in:
2
.env
2
.env
@@ -1,4 +1,4 @@
|
|||||||
DB_HOST=localhost
|
DB_HOST=DESKTOP-22T88B6
|
||||||
DB_DATABASE=Importaciones_HC
|
DB_DATABASE=Importaciones_HC
|
||||||
DB_USERNAME=sa
|
DB_USERNAME=sa
|
||||||
DB_PASSWORD=Soluciones01
|
DB_PASSWORD=Soluciones01
|
||||||
|
|||||||
@@ -130,12 +130,27 @@ function ajax_lista()
|
|||||||
if ($status === 200 && ($json = json_decode($resp, true)) && is_array($json)) {
|
if ($status === 200 && ($json = json_decode($resp, true)) && is_array($json)) {
|
||||||
foreach ($json as $p) {
|
foreach ($json as $p) {
|
||||||
$clave = htmlspecialchars($p['Clave'] ?? '', ENT_QUOTES);
|
$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[] = [
|
$dataList[] = [
|
||||||
$clave,
|
$clave,
|
||||||
htmlspecialchars($p['Nombre'] ?? '', ENT_QUOTES),
|
htmlspecialchars($p['Nombre'] ?? '', ENT_QUOTES),
|
||||||
htmlspecialchars($p['RFC'] ?? '', ENT_QUOTES),
|
htmlspecialchars($p['RFC'] ?? '', ENT_QUOTES),
|
||||||
htmlspecialchars($p['Ciudad'] ?? '', ENT_QUOTES),
|
htmlspecialchars($p['Ciudad'] ?? '', ENT_QUOTES),
|
||||||
htmlspecialchars($p['Telefono']?? '', ENT_QUOTES),
|
htmlspecialchars($p['Telefono']?? '', ENT_QUOTES),
|
||||||
|
htmlspecialchars($direccion ?? '', ENT_QUOTES),
|
||||||
// Acciones
|
// Acciones
|
||||||
"<a href=\"/IMPORTADORES/proveedores/editar?clave=" . rawurlencode($clave) . "\" class=\"btn btn-sm btn-primary\">✏️</a>
|
"<a href=\"/IMPORTADORES/proveedores/editar?clave=" . rawurlencode($clave) . "\" class=\"btn btn-sm btn-primary\">✏️</a>
|
||||||
<button class=\"btn btn-sm btn-danger\" onclick=\"confirmDelete('{$clave}')\">🗑️</button>"
|
<button class=\"btn btn-sm btn-danger\" onclick=\"confirmDelete('{$clave}')\">🗑️</button>"
|
||||||
@@ -149,7 +164,6 @@ function ajax_lista()
|
|||||||
echo json_encode(['data' => $dataList]);
|
echo json_encode(['data' => $dataList]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* GET /IMPORTADORES/proveedores/eliminar
|
* GET /IMPORTADORES/proveedores/eliminar
|
||||||
* Llama a DELETE /api/proveedores/:clave y redirige
|
* Llama a DELETE /api/proveedores/:clave y redirige
|
||||||
@@ -193,7 +207,6 @@ function crear()
|
|||||||
include __DIR__ . '/../../views/proveedores/crear.php';
|
include __DIR__ . '/../../views/proveedores/crear.php';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* POST /IMPORTADORES/proveedores/guardar
|
* POST /IMPORTADORES/proveedores/guardar
|
||||||
* Procesa el alta de un nuevo proveedor contra la API WinSAAI.
|
* Procesa el alta de un nuevo proveedor contra la API WinSAAI.
|
||||||
@@ -267,5 +280,4 @@ function guardar()
|
|||||||
header('Location: /IMPORTADORES/proveedores/crear');
|
header('Location: /IMPORTADORES/proveedores/crear');
|
||||||
exit;
|
exit;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -64,8 +64,6 @@ function getApiToken(): ?string
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Listado de solicitudes de importación (facturas) del importador logueado
|
* Listado de solicitudes de importación (facturas) del importador logueado
|
||||||
*/
|
*/
|
||||||
@@ -146,7 +144,6 @@ function crear() {
|
|||||||
$unidades_medida[] = $r;
|
$unidades_medida[] = $r;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
include __DIR__ . '/../../views/solicitud_importacion/crear.php';
|
include __DIR__ . '/../../views/solicitud_importacion/crear.php';
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -214,63 +211,59 @@ function guardar() {
|
|||||||
foto_solicitud_url, status, proveedor_clave)
|
foto_solicitud_url, status, proveedor_clave)
|
||||||
OUTPUT INSERTED.id_solicitud
|
OUTPUT INSERTED.id_solicitud
|
||||||
VALUES(?, ?, ?, ?, ?, NULL, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";
|
VALUES(?, ?, ?, ?, ?, NULL, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";
|
||||||
;
|
|
||||||
|
|
||||||
$stmt = sqlsrv_query($conn, $sql, $params, ['Scrollable' => SQLSRV_CURSOR_KEYSET]);
|
$stmt = sqlsrv_query($conn, $sql, $params, ['Scrollable' => SQLSRV_CURSOR_KEYSET]);
|
||||||
if ($stmt === false) {
|
if ($stmt === false) {
|
||||||
die("❌ Error ejecutando INSERT con OUTPUT: " . print_r(sqlsrv_errors(), true));
|
die("❌ Error ejecutando INSERT con OUTPUT: " . print_r(sqlsrv_errors(), true));
|
||||||
}
|
}
|
||||||
|
|
||||||
$new = sqlsrv_fetch_array($stmt, SQLSRV_FETCH_ASSOC);
|
$new = sqlsrv_fetch_array($stmt, SQLSRV_FETCH_ASSOC);
|
||||||
if (!$new || empty($new['id_solicitud'])) {
|
if (!$new || empty($new['id_solicitud'])) {
|
||||||
die("❌ No se pudo recuperar el ID insertado de la factura.");
|
die("❌ No se pudo recuperar el ID insertado de la factura.");
|
||||||
}
|
}
|
||||||
|
|
||||||
$id_solicitud = (int)$new['id_solicitud'];
|
|
||||||
|
|
||||||
|
$id_solicitud = (int)$new['id_solicitud'];
|
||||||
|
|
||||||
|
// Partidas
|
||||||
// Partidas
|
if(!empty($_POST['partidas'])&&is_array($_POST['partidas'])){
|
||||||
if(!empty($_POST['partidas'])&&is_array($_POST['partidas'])){
|
|
||||||
|
|
||||||
$sqlP = "INSERT INTO dbo.solicitud_importacion_partidas
|
$sqlP = "INSERT INTO dbo.solicitud_importacion_partidas
|
||||||
(id_solicitud, descripcion, cantidad_comercial, cantidad_tarifa, valor_factura, peso_bruto, unidad_comercial_id, tasa_preferencial)
|
(id_solicitud, descripcion, cantidad_comercial, cantidad_tarifa, valor_factura, peso_bruto, unidad_comercial_id, tasa_preferencial)
|
||||||
VALUES (?, ?, ?, ?, ?, ?, ?, ?)";
|
VALUES (?, ?, ?, ?, ?, ?, ?, ?)";
|
||||||
|
|
||||||
$partidas_insertadas = 0; // ← contador
|
$partidas_insertadas = 0; // ← contador
|
||||||
|
|
||||||
foreach ($_POST['partidas'] as $i => $p) {
|
foreach ($_POST['partidas'] as $i => $p) {
|
||||||
error_log("Partida $i: " . print_r($p, true));
|
error_log("Partida $i: " . print_r($p, true));
|
||||||
$params = [
|
$params = [
|
||||||
$id_solicitud,
|
$id_solicitud,
|
||||||
trim($p['descripcion'] ?? ''),
|
trim($p['descripcion'] ?? ''),
|
||||||
|
|
||||||
floatval($p['cantidad_comercial'] ?? 0),
|
floatval($p['cantidad_comercial'] ?? 0),
|
||||||
floatval($p['cantidad_tarifa'] ?? 0),
|
floatval($p['cantidad_tarifa'] ?? 0),
|
||||||
floatval($p['valor_factura'] ?? 0),
|
floatval($p['valor_factura'] ?? 0),
|
||||||
floatval($p['peso_bruto'] ?? 0),
|
floatval($p['peso_bruto'] ?? 0),
|
||||||
intval($p['unidad_comercial_id'] ?? 0) ?: null,
|
intval($p['unidad_comercial_id'] ?? 0) ?: null,
|
||||||
|
|
||||||
trim($p['tasa_preferencial'] ?? '')
|
trim($p['tasa_preferencial'] ?? '')
|
||||||
];
|
];
|
||||||
|
|
||||||
if ($params[1] !== '' && $params[2] > 0) {
|
if ($params[1] !== '' && $params[2] > 0) {
|
||||||
$stmtPartida = sqlsrv_query($conn, $sqlP, $params);
|
$stmtPartida = sqlsrv_query($conn, $sqlP, $params);
|
||||||
if ($stmtPartida === false) {
|
if ($stmtPartida === false) {
|
||||||
die("❌ Error insertando partida $i: " . print_r(sqlsrv_errors(), true));
|
die("❌ Error insertando partida $i: " . print_r(sqlsrv_errors(), true));
|
||||||
} else {
|
} else {
|
||||||
$partidas_insertadas++;
|
$partidas_insertadas++;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if ($partidas_insertadas === 0) {
|
if ($partidas_insertadas === 0) {
|
||||||
///header('Location: /IMPORTADORES/solicitud_importacion/crear?error_partidas=1');
|
///header('Location: /IMPORTADORES/solicitud_importacion/crear?error_partidas=1');
|
||||||
// exit;
|
// exit;
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
header('Location: /IMPORTADORES/solicitud_importacion/lista?created=ok');
|
header('Location: /IMPORTADORES/solicitud_importacion/lista?created=ok');
|
||||||
exit;
|
exit;
|
||||||
@@ -393,9 +386,11 @@ function ajax_proveedores()
|
|||||||
$out = ['results' => []];
|
$out = ['results' => []];
|
||||||
if ($status === 200 && ($json = json_decode($resp, true)) && is_array($json)) {
|
if ($status === 200 && ($json = json_decode($resp, true)) && is_array($json)) {
|
||||||
foreach ($json as $p) {
|
foreach ($json as $p) {
|
||||||
|
$clave = $p['Clave'] ?? '';
|
||||||
|
$nombre = $p['Nombre'] ?? '';
|
||||||
$out['results'][] = [
|
$out['results'][] = [
|
||||||
'id' => $p['Clave'] ?? '',
|
'id' => $clave,
|
||||||
'text' => $p['Nombre'] ?? ''
|
'text' => "[$clave] - $nombre"
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -405,10 +400,6 @@ function ajax_proveedores()
|
|||||||
exit;
|
exit;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
function ajax_lista()
|
function ajax_lista()
|
||||||
{
|
{
|
||||||
// 1) Fijamos el header JSON
|
// 1) Fijamos el header JSON
|
||||||
@@ -465,7 +456,6 @@ function ajax_lista()
|
|||||||
echo json_encode(['data' => $dataList]);
|
echo json_encode(['data' => $dataList]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
function update_status() {
|
function update_status() {
|
||||||
|
|
||||||
header('Content-Type: application/json; charset=utf-8');
|
header('Content-Type: application/json; charset=utf-8');
|
||||||
@@ -489,6 +479,4 @@ function update_status() {
|
|||||||
}
|
}
|
||||||
echo json_encode(['success'=>true]);
|
echo json_encode(['success'=>true]);
|
||||||
exit;
|
exit;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -91,7 +91,7 @@
|
|||||||
<a href="/IMPORTADORES/proveedores/crear" class="btn btn-success mb-3">➕ Nuevo Proveedor</a>
|
<a href="/IMPORTADORES/proveedores/crear" class="btn btn-success mb-3">➕ Nuevo Proveedor</a>
|
||||||
|
|
||||||
<div class="card p-3 shadow-sm">
|
<div class="card p-3 shadow-sm">
|
||||||
<br>
|
<br>
|
||||||
<table id="proveedores-table" class="table table-striped nowrap" style="width:100%">
|
<table id="proveedores-table" class="table table-striped nowrap" style="width:100%">
|
||||||
<thead>
|
<thead>
|
||||||
<tr>
|
<tr>
|
||||||
@@ -100,6 +100,7 @@
|
|||||||
<th>RFC</th>
|
<th>RFC</th>
|
||||||
<th>Ciudad</th>
|
<th>Ciudad</th>
|
||||||
<th>Teléfono</th>
|
<th>Teléfono</th>
|
||||||
|
<th>Dirección</th>
|
||||||
<th>Acciones</th>
|
<th>Acciones</th>
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
@@ -146,8 +147,9 @@
|
|||||||
{ data: 1 },
|
{ data: 1 },
|
||||||
{ data: 2 },
|
{ data: 2 },
|
||||||
{ data: 3 },
|
{ data: 3 },
|
||||||
{ data: 4, className: 'text-center' },
|
{ data: 4, className: 'text-center' },
|
||||||
{ data: 5, className: 'text-center' }
|
{ data: 5},
|
||||||
|
{ data: 6, className: 'text-center' }
|
||||||
],
|
],
|
||||||
language: {
|
language: {
|
||||||
processing: '<div class="spinner-border text-primary" role="status"><span class="visually-hidden">Cargando...</span></div>',
|
processing: '<div class="spinner-border text-primary" role="status"><span class="visually-hidden">Cargando...</span></div>',
|
||||||
|
|||||||
Reference in New Issue
Block a user