47 lines
1.9 KiB
PHP
47 lines
1.9 KiB
PHP
<?php
|
|
session_start();
|
|
require_once 'db/config.php';
|
|
|
|
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
|
date_default_timezone_set('America/Lima');
|
|
$usuario_id = filter_input(INPUT_POST, 'usuario_id', FILTER_VALIDATE_INT);
|
|
$fecha_actualizacion = $_POST['fecha_actualizacion'] ?? null;
|
|
$ciudad_id = filter_input(INPUT_POST, 'ciudad_id', FILTER_VALIDATE_INT);
|
|
|
|
if ($usuario_id && $fecha_actualizacion && $ciudad_id) {
|
|
$pdo = db();
|
|
try {
|
|
$pdo->beginTransaction();
|
|
|
|
$fecha_hora_actual = date('Y-m-d H:i:s');
|
|
$stmt = $pdo->prepare('INSERT INTO stock_confirmaciones (usuario_id, fecha_hora, fecha_actualizacion) VALUES (:usuario_id, :fecha_hora, :fecha_actualizacion)');
|
|
$stmt->execute([
|
|
'usuario_id' => $usuario_id,
|
|
'fecha_hora' => $fecha_hora_actual,
|
|
'fecha_actualizacion' => $fecha_actualizacion
|
|
]);
|
|
|
|
$confirmacion_id = $pdo->lastInsertId();
|
|
|
|
$stmt_ciudad = $pdo->prepare('INSERT INTO stock_confirmacion_ciudades (confirmacion_id, ciudad_id) VALUES (:confirmacion_id, :ciudad_id)');
|
|
$stmt_ciudad->execute([
|
|
'confirmacion_id' => $confirmacion_id,
|
|
'ciudad_id' => $ciudad_id
|
|
]);
|
|
|
|
$pdo->commit();
|
|
|
|
$_SESSION['flash_message'] = ['type' => 'success', 'message' => 'Entrega registrada exitosamente.'];
|
|
} catch (PDOException $e) {
|
|
$pdo->rollBack();
|
|
error_log('Error en handle_confirmacion_stock.php: ' . $e->getMessage());
|
|
$_SESSION['flash_message'] = ['type' => 'danger', 'message' => 'Error al registrar la entrega.'];
|
|
}
|
|
} else {
|
|
$_SESSION['flash_message'] = ['type' => 'danger', 'message' => 'Por favor, complete todos los campos.'];
|
|
}
|
|
}
|
|
|
|
header('Location: confirmacion_stock.php');
|
|
exit;
|
|
?>
|