<?php

if (isset($_SERVER['HTTP_ORIGIN'])) {
    header("Access-Control-Allow-Origin: {$_SERVER['HTTP_ORIGIN']}");
    header('Access-Control-Allow-Credentials: true');
    header('Access-Control-Max-Age: 86400'); // cache for 1 day
}

include 'conn.php';
//Select data from database

include 'funciones.php';

session_start();
$_SESSION['database'] = $_GET['database'];
$_SESSION['pr_id'] = $_GET['pr_id'];
$_SESSION['id'] = $_GET['id'];
$_SESSION['nombre'] = $_GET['nombre'];
$_SESSION['no'] = $_GET['no'];

$hoynow = getdate();

// $timeStamp= $hoynow["year"]."-".$hoynow["mon"]."-".$hoynow["mday"] ;
$timeStamp = $hoynow["year"] . "-" . $hoynow["mon"] . "-" . $hoynow["mday"] . " " . $hoynow["hours"] . ":" . $hoynow["minutes"] . ":" . $hoynow["seconds"];

logs($timeStamp);

$montoesql = "select pr_id FROM " . $_SESSION['database'] . ".productos where pr_id='" . $_SESSION['pr_id'] . "' limit 1 ";

logs($montoesql);

$qur = $connection->query($montoesql);

while ($r = mysqli_fetch_assoc($qur)) {

    $_SESSION['pr_id'] = $r['pr_id'];
}

if ($_SESSION['pr_id'] == "") {
    echo "NE";

} else {

    $SQLupdate = "delete from  " . $_SESSION['database'] . ".toma_inv where    id= " . $_SESSION['id'] . " and pr_id='" . $_SESSION['pr_id'] . "' and  nodoc='" . $_SESSION['no'] . "'  and nombre='" . $_SESSION['nombre'] . "'";

//       $SQLupdate="update ".$_SESSION['database'].".gift_certificate set gift_fechae='".$timeStamp."',gift_monto=".$_SESSION['monto'].",a_nombre='".
    //$_SESSION['nombre']."',a_nip='".$_SESSION['ruc']."' where gift_certificate.gift_number='".$_SESSION['numero']."' limit 1 ";

    logs($SQLupdate);

    if ($connection->query($SQLupdate) === true) {
        echo "true";
    } else {
        echo "false";
    }

}

$qur=null;
@mysqli_close($connection);
?>