[[Category:RPRT]]
== Descripción ==
A partir de la ejecución, se indica en [[TABLA:reppresqry]] el presupuesto fetcheado en ese momento. Se hace una combinación a partir de la [[TABLA:vidquoten2]] combinada con [[TABLA:vidquoten3]] tomando en 2 partes (por la diferencia entre el [[CTRL:VidQuoteIncluyeDet]]) seleccionando todos los registro en la 1º parte y en la segunda todos aquellos que que no tengan el valor del [[CTRL:VidQuoteIncluyeDet]] = 0 y que no se encuentren dentro de la primera parte. Se agregan para completar el cuadro los datos complementarios de [[TABLA:vidquoten1]], [[TABLA:productos]], [[VISTA:clientes]] y un totalizador por presupuesto que no es posible de generar dentro de la 4º forma normal con las tablas al tiempo de ejecuación del reporte propiamente dicho.

== Composición ==
*[[TABLA:vidquoten2]]
*[[TABLA:vidquoten3]]
*[[TABLA:vidquoten1]]
*[[TABLA:productos]]
*[[VISTA:clientes]]
*[[TABLA:reppresqry]]
== SQL ==
<small><pre>
SELECT 
    U2.VidQuoteID,
    U2.VidQuoteItem,
    U2.VidQuoteProdCantidad,
    U2.VidQuoteProdID,
    U2.Dimension,
    U2.Precio,
    U2.VidQuoteFecha,
    U2.VidQuoteCliente,
    U2.VidQuoteObra,
    U2.RazonSocial,
    U2.Direccion,
    U2.Localidad,
    U2.Provincia,
    U2.VidQuoteElementoID,
    U2.VidQuoteComposicID,
    U2.VidQuoteIncluyeDet,
    U2.DescripcionGral,
    U2.DescripcionElemento,
    U1.PrecioPresup
FROM
-- -----------------------------------
    (
    SELECT
        VidQuoteID,
        SUM(VidQuotePrecio) AS PrecioPresup
    FROM
        vidquoten2
    WHERE
        VidQuoteID IN (SELECT VidQuoteID FROM reppresqry)) AS U1,
-- -----------------------------------
    (
    SELECT 
        vidquoten2.VidQuoteID AS VidQuoteID,
        vidquoten2.VidQuoteItem AS VidQuoteItem,
        vidquoten2.VidQuoteProdCantidad AS VidQuoteProdCantidad,
        vidquoten2.VidQuoteProdID AS VidQuoteProdID,
        CASE
            WHEN `vidquoten2`.`VidQuoteAlto` > 0 THEN
                CONCAT('Dimension(mm): [',
                CAST(`vidquoten2`.`VidQuoteAncho` AS CHAR),'x',
                CAST(`vidquoten2`.`VidQuoteAlto` AS CHAR),']')
            WHEN `vidquoten2`.`VidQuoteAlto` > 0 THEN
                CONCAT('Largo(mm): [',
                CAST(`vidquoten2`.`VidQuoteAncho` AS CHAR),']')
            ELSE
                ''
        END AS Dimension,
        vidquoten2.VidQuotePrecio AS Precio,
        vidquoten1.VidQuoteFecha AS VidQuoteFecha,
        vidquoten1.VidQuoteCliente AS VidQuoteCliente,
        vidquoten1.VidQuoteObra AS VidQuoteObra,
        clientes.RazonSocial AS RazonSocial,
        clientes.Direccion AS Direccion,
        clientes.Localidad AS Localidad,
        clientes.Provincia AS Provincia,
        vidquoten3.VidQuoteElementoID AS VidQuoteElementoID,
        vidquoten3.VidQuoteComposicID AS VidQuoteComposicID,
        vidquoten3.VidQuoteIncluyeDet AS VidQuoteIncluyeDet,
        productos.Descripcion AS DescripcionGral,
        IF(vidquoten3.VidQuoteIncluyeDet = 1,
            productos_1.Descripcion,
            '') AS DescripcionElemento
    FROM
        vidquoten1 AS vidquoten1,
        vidquoten2 AS vidquoten2,
        vidquoten3 AS vidquoten3,
        productos AS productos,
        productos AS productos_1,
        clientes AS clientes
    WHERE
        vidquoten3.VidQuoteIncluyeDet = 1 AND 
        vidquoten1.VidQuoteID = vidquoten2.VidQuoteID AND 
        vidquoten3.VidQuoteID = vidquoten2.VidQuoteID AND 
        vidquoten3.VidQuoteItem = vidquoten2.VidQuoteItem AND
        vidquoten1.VidQuoteCliente = clientes.ClienteID AND
        productos.ProductoID = vidquoten3.VidQuoteProdID AND 
        productos_1.ProductoID = vidquoten3.VidQuoteElementoID AND 
        vidquoten2.VidQuoteID IN (SELECT VidQuoteID FROM reppresqry)
    UNION
    SELECT 
        vidquoten2.VidQuoteID AS VidQuoteID,
        vidquoten2.VidQuoteItem AS VidQuoteItem,
        vidquoten2.VidQuoteProdCantidad AS VidQuoteProdCantidad,
        vidquoten2.VidQuoteProdID AS VidQuoteProdID,
        CASE
            WHEN `vidquoten2`.`VidQuoteAlto` > 0 THEN
                CONCAT('Dimension(mm): [',
                CAST(`vidquoten2`.`VidQuoteAncho` AS CHAR),'x',
                CAST(`vidquoten2`.`VidQuoteAlto` AS CHAR),']')
            WHEN `vidquoten2`.`VidQuoteAlto` > 0 THEN
                CONCAT('Largo(mm): [',
                CAST(`vidquoten2`.`VidQuoteAncho` AS CHAR),']')
            ELSE
                ''
        END AS Dimension,
        vidquoten2.VidQuotePrecio AS Precio,
        vidquoten1.VidQuoteFecha AS VidQuoteFecha,
        vidquoten1.VidQuoteCliente AS VidQuoteCliente,
        vidquoten1.VidQuoteObra AS VidQuoteObra,
        clientes.RazonSocial AS RazonSocial,
        clientes.Direccion AS Direccion,
        clientes.Localidad AS Localidad,
        clientes.Provincia AS Provincia,
        vidquoten3.VidQuoteElementoID AS VidQuoteElementoID,
        vidquoten3.VidQuoteComposicID AS VidQuoteComposicID,
        vidquoten3.VidQuoteIncluyeDet AS VidQuoteIncluyeDet,
        productos.Descripcion AS DescripcionGral,
        IF(vidquoten3.VidQuoteIncluyeDet = 1,
            productos_1.Descripcion,
            '') AS DescripcionElemento
    FROM
        vidquoten1 AS vidquoten1,
        vidquoten2 AS vidquoten2,
        vidquoten3 AS vidquoten3,
        productos AS productos,
        productos AS productos_1,
        clientes AS clientes
    WHERE
        vidquoten2.VidQuoteID IN (SELECT VidQuoteID FROM reppresqry) AND
        vidquoten3.VidQuoteIncluyeDet = 0 AND
        vidquoten1.VidQuoteID = vidquoten2.VidQuoteID AND 
        vidquoten3.VidQuoteID = vidquoten2.VidQuoteID AND 
        vidquoten3.VidQuoteItem = vidquoten2.VidQuoteItem AND 
        vidquoten1.VidQuoteCliente = clientes.ClienteID AND
        productos.ProductoID = vidquoten3.VidQuoteProdID AND 
        productos_1.ProductoID = vidquoten3.VidQuoteElementoID AND
        vidquoten2.VidQuoteItem NOT IN (
            SELECT 
                vidquoten2.VidQuoteItem AS VidQuoteItem
            FROM
                vidquoten2 AS vidquoten2,
                vidquoten3 AS vidquoten3
            WHERE
                vidquoten3.VidQuoteIncluyeDet = 1 AND
                vidquoten3.VidQuoteID = vidquoten2.VidQuoteID AND 
                vidquoten3.VidQuoteItem = vidquoten2.VidQuoteItem AND 
                vidquoten2.VidQuoteID IN (SELECT VidQuoteID FROM reppresqry)
            GROUP BY
                vidquoten2.VidQuoteItem)
    ) AS U2 
-- -----------------------------------
WHERE
    U1.VidQuoteID=U2.VidQuoteID
</pre></small>
== Bitácora ==
*20121122
**Cambio de formato visualización de Dimension a solicitud de FZG. Anterior:
<small><pre>
SELECT 
    U2.VidQuoteID,
    U2.VidQuoteItem,
    U2.VidQuoteProdCantidad,
    U2.VidQuoteProdID,
    U2.Dimension,
    U2.Precio,
    U2.VidQuoteFecha,
    U2.VidQuoteCliente,
    U2.VidQuoteObra,
    U2.RazonSocial,
    U2.Direccion,
    U2.Localidad,
    U2.Provincia,
    U2.VidQuoteElementoID,
    U2.VidQuoteComposicID,
    U2.VidQuoteIncluyeDet,
    U2.DescripcionGral,
    U2.DescripcionElemento,
    U1.PrecioPresup
FROM
-- -----------------------------------
    (
    SELECT
        VidQuoteID,
        SUM(VidQuotePrecio) AS PrecioPresup
    FROM
        vidquoten2
    WHERE
        VidQuoteID IN (SELECT VidQuoteID FROM reppresqry)) AS U1,
-- -----------------------------------
    (
    SELECT 
        vidquoten2.VidQuoteID AS VidQuoteID,
        vidquoten2.VidQuoteItem AS VidQuoteItem,
        vidquoten2.VidQuoteProdCantidad AS VidQuoteProdCantidad,
        vidquoten2.VidQuoteProdID AS VidQuoteProdID,
        CASE
            WHEN `vidquoten2`.`VidQuoteAlto` > 0 THEN
                CONCAT('Dimension(mm): [',
                LPAD(CAST(`vidquoten2`.`VidQuoteAncho` AS CHAR),4,'0000'),'x',
                LPAD(CAST(`vidquoten2`.`VidQuoteAlto` AS CHAR),4,'0000'),']')
            WHEN `vidquoten2`.`VidQuoteAlto` > 0 THEN
                CONCAT('Largo(mm): [',
                LPAD(CAST(`vidquoten2`.`VidQuoteAncho` AS CHAR),4,'0000'),']')
            ELSE
                ''
        END AS Dimension,
        vidquoten2.VidQuotePrecio AS Precio,
        vidquoten1.VidQuoteFecha AS VidQuoteFecha,
        vidquoten1.VidQuoteCliente AS VidQuoteCliente,
        vidquoten1.VidQuoteObra AS VidQuoteObra,
        clientes.RazonSocial AS RazonSocial,
        clientes.Direccion AS Direccion,
        clientes.Localidad AS Localidad,
        clientes.Provincia AS Provincia,
        vidquoten3.VidQuoteElementoID AS VidQuoteElementoID,
        vidquoten3.VidQuoteComposicID AS VidQuoteComposicID,
        vidquoten3.VidQuoteIncluyeDet AS VidQuoteIncluyeDet,
        productos.Descripcion AS DescripcionGral,
        IF(vidquoten3.VidQuoteIncluyeDet = 1,
            productos_1.Descripcion,
            '') AS DescripcionElemento
    FROM
        vidquoten1 AS vidquoten1,
        vidquoten2 AS vidquoten2,
        vidquoten3 AS vidquoten3,
        productos AS productos,
        productos AS productos_1,
        clientes AS clientes
    WHERE
        vidquoten3.VidQuoteIncluyeDet = 1 AND 
        vidquoten1.VidQuoteID = vidquoten2.VidQuoteID AND 
        vidquoten3.VidQuoteID = vidquoten2.VidQuoteID AND 
        vidquoten3.VidQuoteItem = vidquoten2.VidQuoteItem AND
        vidquoten1.VidQuoteCliente = clientes.ClienteID AND
        productos.ProductoID = vidquoten3.VidQuoteProdID AND 
        productos_1.ProductoID = vidquoten3.VidQuoteElementoID AND 
        vidquoten2.VidQuoteID IN (SELECT VidQuoteID FROM reppresqry)
    UNION
    SELECT 
        vidquoten2.VidQuoteID AS VidQuoteID,
        vidquoten2.VidQuoteItem AS VidQuoteItem,
        vidquoten2.VidQuoteProdCantidad AS VidQuoteProdCantidad,
        vidquoten2.VidQuoteProdID AS VidQuoteProdID,
        CASE
            WHEN `vidquoten2`.`VidQuoteAlto` > 0 THEN
                CONCAT('Dimension(mm): [',
                LPAD(CAST(`vidquoten2`.`VidQuoteAncho` AS CHAR),4,'0000'),'x',
                LPAD(CAST(`vidquoten2`.`VidQuoteAlto` AS CHAR),4,'0000'),']')
            WHEN `vidquoten2`.`VidQuoteAlto` > 0 THEN
                CONCAT('Largo(mm): [',
                LPAD(CAST(`vidquoten2`.`VidQuoteAncho` AS CHAR),4,'0000'),']')
            ELSE
                ''
        END AS Dimension,
        vidquoten2.VidQuotePrecio AS Precio,
        vidquoten1.VidQuoteFecha AS VidQuoteFecha,
        vidquoten1.VidQuoteCliente AS VidQuoteCliente,
        vidquoten1.VidQuoteObra AS VidQuoteObra,
        clientes.RazonSocial AS RazonSocial,
        clientes.Direccion AS Direccion,
        clientes.Localidad AS Localidad,
        clientes.Provincia AS Provincia,
        vidquoten3.VidQuoteElementoID AS VidQuoteElementoID,
        vidquoten3.VidQuoteComposicID AS VidQuoteComposicID,
        vidquoten3.VidQuoteIncluyeDet AS VidQuoteIncluyeDet,
        productos.Descripcion AS DescripcionGral,
        IF(vidquoten3.VidQuoteIncluyeDet = 1,
            productos_1.Descripcion,
            '') AS DescripcionElemento
    FROM
        vidquoten1 AS vidquoten1,
        vidquoten2 AS vidquoten2,
        vidquoten3 AS vidquoten3,
        productos AS productos,
        productos AS productos_1,
        clientes AS clientes
    WHERE
        vidquoten2.VidQuoteID IN (SELECT VidQuoteID FROM reppresqry) AND
        vidquoten3.VidQuoteIncluyeDet = 0 AND
        vidquoten1.VidQuoteID = vidquoten2.VidQuoteID AND 
        vidquoten3.VidQuoteID = vidquoten2.VidQuoteID AND 
        vidquoten3.VidQuoteItem = vidquoten2.VidQuoteItem AND 
        vidquoten1.VidQuoteCliente = clientes.ClienteID AND
        productos.ProductoID = vidquoten3.VidQuoteProdID AND 
        productos_1.ProductoID = vidquoten3.VidQuoteElementoID AND
        vidquoten2.VidQuoteItem NOT IN (
            SELECT 
                vidquoten2.VidQuoteItem AS VidQuoteItem
            FROM
                vidquoten2 AS vidquoten2,
                vidquoten3 AS vidquoten3
            WHERE
                vidquoten3.VidQuoteIncluyeDet = 1 AND
                vidquoten3.VidQuoteID = vidquoten2.VidQuoteID AND 
                vidquoten3.VidQuoteItem = vidquoten2.VidQuoteItem AND 
                vidquoten2.VidQuoteID IN (SELECT VidQuoteID FROM reppresqry)
            GROUP BY
                vidquoten2.VidQuoteItem)
    ) AS U2 
-- -----------------------------------
WHERE
    U1.VidQuoteID=U2.VidQuoteID
</pre></small>
*20121101
**CheckStatus
<small><pre>
SELECT 
    U2.VidQuoteID,
    U2.VidQuoteItem,
    U2.VidQuoteProdCantidad,
    U2.VidQuoteProdID,
    U2.Dimension,
    U2.Precio,
    U2.VidQuoteFecha,
    U2.VidQuoteCliente,
    U2.VidQuoteObra,
    U2.RazonSocial,
    U2.Direccion,
    U2.Localidad,
    U2.Provincia,
    U2.VidQuoteElementoID,
    U2.VidQuoteComposicID,
    U2.VidQuoteIncluyeDet,
    U2.DescripcionGral,
    U2.DescripcionElemento,
    U1.PrecioPresup
FROM
-- -----------------------------------
    (
    SELECT
        VidQuoteID,
        SUM(VidQuotePrecio) AS PrecioPresup
    FROM
        vidquoten2
    WHERE
        VidQuoteID IN (SELECT VidQuoteID FROM reppresqry)) AS U1,
-- -----------------------------------
    (
    SELECT 
        vidquoten2.VidQuoteID AS VidQuoteID,
        vidquoten2.VidQuoteItem AS VidQuoteItem,
        vidquoten2.VidQuoteProdCantidad AS VidQuoteProdCantidad,
        vidquoten2.VidQuoteProdID AS VidQuoteProdID,
        CASE
            WHEN `vidquoten2`.`VidQuoteAlto` > 0 THEN
                CONCAT('Dimension(mm): [',
                LPAD(CAST(`vidquoten2`.`VidQuoteAncho` AS CHAR),4,'0000'),'x',
                LPAD(CAST(`vidquoten2`.`VidQuoteAlto` AS CHAR),4,'0000'),']')
            WHEN `vidquoten2`.`VidQuoteAlto` > 0 THEN
                CONCAT('Largo(mm): [',
                LPAD(CAST(`vidquoten2`.`VidQuoteAncho` AS CHAR),4,'0000'),']')
            ELSE
                ''
        END AS Dimension,
        vidquoten2.VidQuotePrecio AS Precio,
        vidquoten1.VidQuoteFecha AS VidQuoteFecha,
        vidquoten1.VidQuoteCliente AS VidQuoteCliente,
        vidquoten1.VidQuoteObra AS VidQuoteObra,
        clientes.RazonSocial AS RazonSocial,
        clientes.Direccion AS Direccion,
        clientes.Localidad AS Localidad,
        clientes.Provincia AS Provincia,
        vidquoten3.VidQuoteElementoID AS VidQuoteElementoID,
        vidquoten3.VidQuoteComposicID AS VidQuoteComposicID,
        vidquoten3.VidQuoteIncluyeDet AS VidQuoteIncluyeDet,
        productos.Descripcion AS DescripcionGral,
        IF(vidquoten3.VidQuoteIncluyeDet = 1,
            productos_1.Descripcion,
            '') AS DescripcionElemento
    FROM
        vidquoten1 AS vidquoten1,
        vidquoten2 AS vidquoten2,
        vidquoten3 AS vidquoten3,
        productos AS productos,
        productos AS productos_1,
        clientes AS clientes
    WHERE
        vidquoten3.VidQuoteIncluyeDet = 1 AND 
        vidquoten1.VidQuoteID = vidquoten2.VidQuoteID AND 
        vidquoten3.VidQuoteID = vidquoten2.VidQuoteID AND 
        vidquoten3.VidQuoteItem = vidquoten2.VidQuoteItem AND
        vidquoten1.VidQuoteCliente = clientes.ClienteID AND
        productos.ProductoID = vidquoten3.VidQuoteProdID AND 
        productos_1.ProductoID = vidquoten3.VidQuoteElementoID AND 
        vidquoten2.VidQuoteID IN (SELECT VidQuoteID FROM reppresqry)
    UNION
    SELECT 
        vidquoten2.VidQuoteID AS VidQuoteID,
        vidquoten2.VidQuoteItem AS VidQuoteItem,
        vidquoten2.VidQuoteProdCantidad AS VidQuoteProdCantidad,
        vidquoten2.VidQuoteProdID AS VidQuoteProdID,
        CASE
            WHEN `vidquoten2`.`VidQuoteAlto` > 0 THEN
                CONCAT('Dimension(mm): [',
                LPAD(CAST(`vidquoten2`.`VidQuoteAncho` AS CHAR),4,'0000'),'x',
                LPAD(CAST(`vidquoten2`.`VidQuoteAlto` AS CHAR),4,'0000'),']')
            WHEN `vidquoten2`.`VidQuoteAlto` > 0 THEN
                CONCAT('Largo(mm): [',
                LPAD(CAST(`vidquoten2`.`VidQuoteAncho` AS CHAR),4,'0000'),']')
            ELSE
                ''
        END AS Dimension,
        vidquoten2.VidQuotePrecio AS Precio,
        vidquoten1.VidQuoteFecha AS VidQuoteFecha,
        vidquoten1.VidQuoteCliente AS VidQuoteCliente,
        vidquoten1.VidQuoteObra AS VidQuoteObra,
        clientes.RazonSocial AS RazonSocial,
        clientes.Direccion AS Direccion,
        clientes.Localidad AS Localidad,
        clientes.Provincia AS Provincia,
        vidquoten3.VidQuoteElementoID AS VidQuoteElementoID,
        vidquoten3.VidQuoteComposicID AS VidQuoteComposicID,
        vidquoten3.VidQuoteIncluyeDet AS VidQuoteIncluyeDet,
        productos.Descripcion AS DescripcionGral,
        IF(vidquoten3.VidQuoteIncluyeDet = 1,
            productos_1.Descripcion,
            '') AS DescripcionElemento
    FROM
        vidquoten1 AS vidquoten1,
        vidquoten2 AS vidquoten2,
        vidquoten3 AS vidquoten3,
        productos AS productos,
        productos AS productos_1,
        clientes AS clientes
    WHERE
        vidquoten2.VidQuoteID IN (SELECT VidQuoteID FROM reppresqry) AND
        vidquoten3.VidQuoteIncluyeDet = 0 AND
        vidquoten1.VidQuoteID = vidquoten2.VidQuoteID AND 
        vidquoten3.VidQuoteID = vidquoten2.VidQuoteID AND 
        vidquoten3.VidQuoteItem = vidquoten2.VidQuoteItem AND 
        vidquoten1.VidQuoteCliente = clientes.ClienteID AND
        productos.ProductoID = vidquoten3.VidQuoteProdID AND 
        productos_1.ProductoID = vidquoten3.VidQuoteElementoID AND
        vidquoten2.VidQuoteItem NOT IN (
            SELECT 
                vidquoten2.VidQuoteItem AS VidQuoteItem
            FROM
                vidquoten2 AS vidquoten2,
                vidquoten3 AS vidquoten3
            WHERE
                vidquoten3.VidQuoteIncluyeDet = 1 AND
                vidquoten3.VidQuoteID = vidquoten2.VidQuoteID AND 
                vidquoten3.VidQuoteItem = vidquoten2.VidQuoteItem AND 
                vidquoten2.VidQuoteID IN (SELECT VidQuoteID FROM reppresqry)
            GROUP BY
                vidquoten2.VidQuoteItem)
    ) AS U2 
-- -----------------------------------
WHERE
    U1.VidQuoteID=U2.VidQuoteID
</pre></small>
*20121002
**Cambio de Estructura por Requerimiento. Query anterior:
<small><pre>
SELECT 
    `visreppres`.`VidQuoteID`,
    `visreppres`.`VidQuoteObra`,
    `visreppres`.`VidQuoteCliente`,
    `visreppres`.`VidQuoteFecha`,
    `visreppres`.`VidQuoteItem`,
    `visreppres`.`VidQuoteProdCantidad`,
    `visreppres`.`VidQuoteProdID`,
    `visreppres`.`VidQuoteDetalle`,
    `visreppres`.`VidQuotePrecioS`,
    `clientes`.`RazonSocial`,
    `clientes`.`Direccion`,
    `clientes`.`Localidad`,
    `clientes`.`Provincia`
FROM
    `fzggestion`.`clientes` AS `clientes`,
    `fzggestion`.`visreppres` AS `visreppres`
WHERE
    `clientes`.`ClienteID` = `visreppres`.`VidQuoteCliente`
ORDER BY 
    `visreppres`.`VidQuoteID` ASC,
    `visreppres`.`VidQuoteObra` ASC,
    `visreppres`.`VidQuoteCliente` ASC,
    `visreppres`.`VidQuoteItem` ASC
</pre></small>
== URL ==