<?php
session_start();
$usuarioSession = $_SESSION['USUARIO'];
$grupo = $_SESSION['GRUPO'];
$contacto = $_SESSION['CONTACTO'];
$awa_session_id = $_SESSION['AWA_SESION_ID'];
include('../includes/conex.php');
include('../includes/eat.php');
include('../includes/historial.php');
include('../includes/functions.php');
include('../includes/esquemas.php');
include('../class/Schema.php');
include('../class/MotherCar.php');
include('../class/Static.php');
$cookieUser = filter_input(INPUT_COOKIE, 'usuario') ?? null; 
$cookieIdioma = filter_input(INPUT_COOKIE, 'idioma') ?? null; 
if((!isset($usuarioSession) or $awa_session_id != $awa_id) or (isset($cookieUser) AND $cookieUser != $staticUsu )){
    eatCookies();
    header('Location:../index.php');}
empty($cookieIdioma)?
    include('../lg/LG_' . $cookieIdioma . '.php'):
    include('../lg/LG_SP.php');

$Schema = new Schema($con, $database);

$key = 'COMPRA_BASE = ?, COMPRA_TOTAL = ?';
$type = 'ii';
$array_value = [Statics::SafeInput($con, $_POST['compra_base']), Statics::SafeInput($con, $_POST['compra_total'])];
if(!empty($_POST['procedencia'])) {
    $key .= ',PROCEDENCIA = ?';
    $type .= 'i';
    array_push($array_value, Statics::SafeInput($con, $_POST['procedencia']));
}
if(!empty($_POST['importacion'])) {
    $key .= ',IMPORTACION = ?';
    $type .= 'i';
    array_push($array_value, Statics::SafeInput($con, $_POST['importacion']));
}
if(!empty($_POST['rebu'])) {
    $key .= ',REBU = ?';
    $type .= 'i';
    array_push($array_value, Statics::SafeInput($con, $_POST['rebu']));
}
if(!empty($_POST['compra_iva'])) {
    $key .= ',COMPRA_TIPOIVA = ?';
    $type .= 'i';
    array_push($array_value, Statics::SafeInput($con, $_POST['compra_iva']));
}
$key .= ' WHERE CODIGO = ?';
$type .= 'i';
array_push($array_value, $_SESSION['VEHICULO_RECIEN_CREADO']);

$Schema->executeQuery("UPDATE VEHICULOS SET $key", $type, $array_value);
$_SESSION['MSG_INFO'] = 'DATOS_COMPRA';
$detalle = $actualizacion_lg . ': ' . $comprar_lg;
Statics::add_trace_history($con, $usuarioSession, $_SESSION['VEHICULO_RECIEN_CREADO'], 2, $detalle);
header("Location:../nuevo-vehiculo-datos.php");