<?php

    // Include DB connection and session control
    include '../db/db.php';
    include '/includes/session_control.php';
    include ($_SERVER['DOCUMENT_ROOT'] .'/funciones/funciones.php');

    // Enable error reporting for debugging
    ini_set('display_errors', 1);
    ini_set('display_startup_errors', 1);
    error_reporting(E_ALL);
    date_default_timezone_set('America/Bogota');
    // Get the id_cotizacion_detalle from the URL
    $id_cotizacion = $_GET['id_cotizacion'];
    
    // Query to fetch the details
    $query = "SELECT tb_cotizaciones.id AS idCotizacion, tb_usuarios.nombre, tb_usuarios.apellido, tb_usuarios.telefono, tb_cotizaciones.fechaCreacion, tb_ciudades.nombre AS Ciudad, tb_departamentos.nombre AS Departamento
FROM (((tb_cotizacion_tipo INNER JOIN tb_cotizaciones ON tb_cotizacion_tipo.id = tb_cotizaciones.idTipo) LEFT JOIN tb_usuarios ON tb_cotizaciones.idUsuario = tb_usuarios.id) LEFT JOIN tb_ciudades ON tb_usuarios.idCiudad = tb_ciudades.id) LEFT JOIN tb_departamentos ON tb_ciudades.idDepartamento = tb_departamentos.id
WHERE (((tb_cotizaciones.id)=$id_cotizacion));";

    $result = mysqli_query($conn, $query);

    if (!$result) {
        error_log("Query failed: " . mysqli_error($conn));
        die("Error executing query");
    }

    $row=mysqli_fetch_array($result);

$fondoblanco=$_SERVER['DOCUMENT_ROOT'].'/cotizaciones/fondos/tipo1.png';
$rutafondo=str_replace('J:/images', 'https://sistema.compranet.com.co/images', $row['linkImagen']);
$anchoposter=1080;
$altoposter=1350;

imagecreatetruecolor($anchoposter,$altoposter);
$fondo = imagenposter($fondoblanco,$anchoposter,$altoposter);

nuevaimagen($fondo,$fondoblanco,1080,1350,0,0);

$idCotizacion=$row['idCotizacion'];


centrartexto($idCotizacion,"Poppins-SemiBold.otf",$fondo,25,'000000',1080,180,0); 


// Replace the path
       
        //error_log("Background image path: " . $background_image);

        //$fondoblanco='fondoblanco.png';



        Header("Content-type: image/png");
        imagepng($fondo);
        imagedestroy($fondo);