<?php 
header("Access-Control-Allow-Origin: *");
header("Content-Type:application/json; charset=UTF-8");
header("Access-Control-Allow-Methods:POST");
header("Access-Control-Max-Age:3600");
header("Access-Control-Allow-Headers:Content-Type,Access-Control-Allow-Headers,Authorization,X-Requested-With");

include_once '../Database.php';
include_once 'detalle.php';

$database = new DataBase();
$db = $database->getConnection();

$detalle = new Detalle($db);
try{
	$data = json_decode(file_get_contents("php://input"));
	
	$query = "INSERT INTO detalle SET cotizacion=:cotizacion,concepto=:concepto, cantidad=:cantidad, observacion=:observacion, usuario=:usuario";
	$stm = $detalle->conn->prepare($query);
	$stm->bindParam(":cotizacion",$data->cotizacion);
	$stm->bindParam(":concepto",$data->concepto);
	$stm->bindParam(":cantidad",$data->cantidad);
	$stm->bindParam(":observacion",$data->observacion);
	$stm->bindParam(":usuario",$data->usuario);
	$stmt = $detalle->Insert($stm);
	if($stmt !==false){
		echo json_encode(array("Id"=>$stmt));
	}else{
		echo json_encode(array("Error"=>"No se ha creado el registro"));
	}
}catch(Exception $ex){
	echo json_encode(array("Error"=>"No se ha podido procesar la solicitud"));
}

?>