[[Category:FORM]]
== Descripción ==
Consulta resumen de los presupuestos y pagos de clientes basado en su ContactoID. Los presupuestos que figuran son solo aquellos que se encuentren aprobados (cerrados y pasados a Taller).
== Composición ==
*[[FORM:ConsultaClientesCRM.MainForm]]
**[[TABLA:contactos]]
**[[TABLA:vidquoten1]]
**[[TABLA:vidquoten2]]
**[[TABLA:accreceiv]]
<dl><dd>
<small><pre>
SELECT 
    VidQuoteCliente AS ContactoID,
    T3.RazonSocial,
    VidQuotePrecioP
FROM
    (SELECT 
        T1.VidQuoteCliente,
            SUM(T1.VidQuotePrecioP) AS VidQuotePrecioP
    FROM
        ((SELECT 
        vidquoten1.VidQuoteCliente AS VidQuoteCliente,
            'OT' AS TTransaccion,
            vidquoten3.VidQuoteID AS NTransaccion,
            vidquoten1.VidQuoteFecha AS VidQuoteFecha,
            vidquoten1.VidQuoteObra AS VidQuoteObra,
            SUM(vidquoten3.VidQuotePrecioP) AS VidQuotePrecioP
    FROM
        vidquoten1 AS vidquoten1, vidquoten3 AS vidquoten3
    WHERE
        vidquoten1.VidQuoteID = vidquoten3.VidQuoteID AND vidquoten1.VidQuoteEstado = '1'
    GROUP By VidQuoteCliente , TTransaccion , NTransaccion) UNION (SELECT 
        IF(ISNULL(accreceiv.ClienteAR), '00000000', accreceiv.ClienteAR) AS VidQuoteCliente,
            accreceiv.TDocumentoOrg AS TTransaccion,
            accreceiv.NDocumentoOrg AS NTransaccion,
            accreceiv.FechaAR AS VidQuoteFecha,
            '' AS VidQuoteObra,
            accreceiv.ImporteAR * - 1 AS VidQuotePrecioP
    FROM
        fzggestion.accreceiv)) AS T1
    GROUP BY T1.VidQuoteCliente) AS T2,
    contactos AS T3
WHERE
    T2.VidQuoteCliente = T3.ContactoID
</pre></small></dl>
*[[FORM:ConsultaClientesCRM.SFPresupuesto]]
**[[TABLA:vidquoten1]]
**[[TABLA:vidquoten2]]
<dl><dd>
<small><pre>
SELECT DISTINCT 
    `vidquoten1`.`VidQuoteCliente` AS `VidQuoteCliente`,
    `vidquoten3`.`VidQuoteID` AS `VidQuoteID`,
    `vidquoten1`.`VidQuoteObra` AS `VidQuoteObra`,
    `vidquoten1`.`VidQuoteFecha` AS `VidQuoteFecha`,
    `vidquoten1`.`VidQuoteEstado` AS `VidQuoteEstado`,
    SUM( `vidquoten3`.`VidQuotePrecioP` ) AS `VidQuotePrecioP` 
FROM { OJ `fzggestion`.`vidquoten1` AS `vidquoten1` 
    RIGHT OUTER JOIN `fzggestion`.`vidquoten3` AS `vidquoten3`
    ON `vidquoten1`.`VidQuoteID` = `vidquoten3`.`VidQuoteID` } 
WHERE `vidquoten1`.`VidQuoteEstado` = '1' 
GROUP BY `vidquoten3`.`VidQuoteID` 
ORDER BY `VidQuoteCliente` ASC, `VidQuoteID` ASC
</pre></small></dl>
*[[FORM:ConsultaClientesCRM.SubFormCobranzas]]
**[[TABLA:accreceiv]]
*[[FORM:ConsultaClientesCRM.SubFormSaldos]]
**[[TABLA:vidquoten1]]
**[[TABLA:vidquoten2]]
**[[TABLA:accreceiv]]
<dl><dd>
<small><pre>
SELECT 
    T1.VidQuoteCliente,
    SUM(T1.VidQuotePrecioP) AS VidQuotePrecioP
FROM 
    ((SELECT DISTINCT
        vidquoten1.VidQuoteCliente  AS VidQuoteCliente,
        'OT'                        AS TTransaccion,
        vidquoten3.VidQuoteID       AS NTransaccion,
        vidquoten1.VidQuoteFecha    AS VidQuoteFecha,
        vidquoten1.VidQuoteObra     AS VidQuoteObra,
        SUM(vidquoten3.VidQuotePrecioP) 
                                    AS VidQuotePrecioP
    FROM
        vidquoten1 AS vidquoten1,
        vidquoten3 AS vidquoten3
    WHERE
        vidquoten1.VidQuoteID = vidquoten3.VidQuoteID AND
        vidquoten1.VidQuoteEstado = '1'
    GROUP By VidQuoteCliente,TTransaccion,NTransaccion)

    UNION
    (SELECT
        IF(ISNULL(`accreceiv`.`ClienteAR`),'00000000',`accreceiv`.`ClienteAR`) 
                                        AS VidQuoteCliente,
        `accreceiv`.`TDocumentoOrg`     AS TTransaccion,
        `accreceiv`.`NDocumentoOrg`     AS NTransaccion,
        `accreceiv`.`FechaAR`           AS VidQuoteFecha,
        ''                              AS VidQuoteObra,
        `accreceiv`.`ImporteAR` * -1    AS VidQuotePrecioP
    FROM `fzggestion`.`accreceiv`)) AS T1
GROUP BY T1.VidQuoteCliente
</pre></small></dl>
== Estructura ==
== Código Relacionado ==
*[[MACRO:EliminaContenidoCampo]]
*[[MACRO:ActivaFiltroContactos]]
*[[MACRO:ReporteClientesCRM]]

== Bitácora ==
==== Bitácora.20131007 ====
*Se cambia el origen de datos del MainForm de la VISTA:clientes a un SELECT de la [[TABLA:contactos]].
<dl><dd>
<small><pre>
SELECT `ContactoID`, `RazonSocial`, `ClienteTag`, `Telefono1`, `Correo1`, `Notas` 
FROM `fzggestion`.`contactos` AS `contactos` 
WHERE `ClienteTag` = 1 ORDER BY `ContactoID` ASC
</pre></small></dl>
*Se cambian las referencias con los subformularios de ClienteID a ContactoID
*Se cambia la rutina asociada al atributo txtFiltro de [[MACR:ActivaFiltroProductosGeneral]] a [[MACR:ActivaFiltroContactos]]
==== Bitácora.20131018 ====
*Se cambia nuevamente el origen de datos para reflejar que solo se muestre en el Grid aquellos clientes que tienen transacciones y no todos los clientes. El SQL anterior:
<dl><dd>
<small><pre>
SELECT `ContactoID`, `RazonSocial`, `ClienteTag`, `Telefono1`, `Correo1`, `Notas`
FROM `fzggestion`.`contactos` AS `contactos`
WHERE `ClienteTag` = 1 ORDER BY `ContactoID` ASC
</pre></small></dl>
== Uso ==