<?php
		header("Access-Control-Allow-Origin: *");
		header("Access-Control-Allow-Headers: access");
		header("Access-Control-Allow-Methods: GET");
		header("Access-Control-Allow-Credentials: true");
		header("Content-Type: application/json; charset=UTF-8");

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

		$database = new DataBase();
		$db = $database->getConnection();
        
		$id = isset($_GET['id'])?$_GET['id']:die();
		$detalle = new Detalle($db);
		try{
			$stmt = $detalle->select("select d.*,c.nombre,c.costo from detalle as d, conceptos as c where c.id=d.concepto and d.cotizacion=".$id);
		$num = $stmt->rowCount();
		if($num>0){
		    $lista=array();
			while($row =$stmt->fetch(PDO::FETCH_ASSOC)){
				extract($row);
				$add_item=array(
					"id"=>$id,
					"cotizacion"=>$cotizacion,
					"concepto"=>$concepto,
					"cantidad"=>$cantidad,
					"precio"=>$costo,
					"conceptoname"=>$nombre,
					"observacion"=>$observacion,
					"fecha"=>$fecha,
					"usuario"=>$usuario,
				);
				array_push($lista,$add_item);
			}
			echo json_encode($lista);
		}
		else {
			echo json_encode(array("Mensaje"=>"No se han encontrado registros"));
		}
	}catch(Exeption $e){
		echo json_encode(array("Error"=>"Error ".$e));
	}
	
		
?>