[[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]]
<dd>
<pre>
SELECT `ContactoID`, `RazonSocial`, `ClienteTag`, `Telefono1`, `Correo1`, `Notas`
FROM `fzggestion`.`contactos` AS `contactos`
WHERE `ClienteTag` = 1 ORDER BY `ContactoID` ASC
</pre>
*[[FORM:ConsultaClientesCRM.SFPresupuesto]]
**[[TABLA:vidquoten1]]
**[[TABLA:vidquoten2]]
<dd>
<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>
*[[FORM:ConsultaClientesCRM.SubFormCobranzas]]
**[[TABLA:accreceiv]]
*[[FORM:ConsultaClientesCRM.SubFormSaldos]]
**[[TABLA:vidquoten1]]
**[[TABLA:vidquoten2]]
**[[TABLA:accreceiv]]
<dd>
<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>
== Estructura ==
== Código Relacionado ==
*[[MACRO:EliminaContenidoCampo]]
*[[MACRO:ActivaFiltroContactos]]
*[[MACRO:ReporteClientesCRM]]

== Bitácora ==
*20131007
*: Se cambia el origen de datos del MainForm de la VISTA:clientes a un SELECT de la [[TABLA:contactos]].
<dl>
<dd>
<pre>
SELECT `ContactoID`, `RazonSocial`, `ClienteTag`, `Telefono1`, `Correo1`, `Notas` 
FROM `fzggestion`.`contactos` AS `contactos` 
WHERE `ClienteTag` = 1 ORDER BY `ContactoID` ASC
</pre>
*: 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]]

== Uso ==