== Descripción ==
Visualización del Resumen de Saldos de CRM. Comparación de saldos de presupuestos aprobados versus cobranzas
== Composición ==
*[[FORM:PosicionCRM.MainForm]]
**[[TABLA:vidquoten1]]
**[[TABLA:vidquoten3]]
<dl>
<dd>
<pre>
SELECT 
    ClienteID,
    TDocumentOrg,
    NDocumentoOrg,
    FechaOp,
    SUM(ImporteDeu) AS SaldoDeudor,
    SUM(ImporteAcr) AS SaldoAcreedor,
    SUM(ImporteDeu)-SUM(ImporteAcr) AS Saldo
FROM 
    ((SELECT DISTINCT
        vidquoten1.VidQuoteCliente AS ClienteID,
        'OT' AS TDocumentOrg,
        vidquoten3.VidQuoteID AS NDocumentoOrg,
        vidquoten1.VidQuoteFecha AS FechaOp,
        SUM(vidquoten3.VidQuotePrecioP) AS ImporteDeu,
        0 AS ImporteAcr
    FROM
        vidquoten1 AS vidquoten1,
        vidquoten3 AS vidquoten3
    WHERE
        vidquoten1.VidQuoteID = vidquoten3.VidQuoteID AND
        vidquoten1.VidQuoteEstado = '1'
    GROUP BY ClienteID,NDocumentoOrg)
    UNION
    (SELECT
        IF(ISNULL(`accreceiv`.`ClienteAR`),'00000000',`accreceiv`.`ClienteAR`) AS ClienteID,
        `accreceiv`.`TDocumentoOrg`,
        `accreceiv`.`NDocumentoOrg`,
        `accreceiv`.`FechaAR` AS FechaOp,
        0 AS ImporteDeu,
        `accreceiv`.`ImporteAR` AS ImporteAcr
    FROM `fzggestion`.`accreceiv`)) AS T1
GROUP BY ClienteID
</pre>
</dl>
**[[FORM:PosicionCRM.SFPresupuesto]]
***[[TABLA:vidquoten1]]
***[[TABLA:vidquoten3]]
<dl>
<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>
</dl>
**[[FORM:PosicionCRM.SFCobranzas]]
***[[TABLA:accreceiv]]
**[[FORM:PosicionCRM.SubFormSaldo]]
***[[TABLA:vidquoten1]]
***[[TABLA:vidquoten3]]
<dl>
<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>
</dl>
*[[FORM:PosicionCRM.SubFormCliente]]
*[[TABLA:vidquoten1]]
*[[TABLA:vidquoten3]]
*[[TABLA:clientes]]

== Estructura ==
<small><pre>
SELECT 
    ClienteID,
    TDocumentOrg,
    NDocumentoOrg,
    FechaOp,
    SUM(ImporteDeu) AS SaldoDeudor,
    SUM(ImporteAcr) AS SaldoAcreedor,
    SUM(ImporteDeu)-SUM(ImporteAcr) AS Saldo
FROM 
    ((SELECT DISTINCT
        vidquoten1.VidQuoteCliente AS ClienteID,
        'OT' AS TDocumentOrg,
        vidquoten3.VidQuoteID AS NDocumentoOrg,
        vidquoten1.VidQuoteFecha AS FechaOp,
        SUM(vidquoten3.VidQuotePrecioP) AS ImporteDeu,
        0 AS ImporteAcr
    FROM
        vidquoten1 AS vidquoten1,
        vidquoten3 AS vidquoten3
    WHERE
        vidquoten1.VidQuoteID = vidquoten3.VidQuoteID AND
        vidquoten1.VidQuoteEstado = '1'
    GROUP BY ClienteID,NDocumentoOrg)
    UNION
    (SELECT
        IF(ISNULL(`accreceiv`.`ClienteAR`),'00000000',`accreceiv`.`ClienteAR`) AS ClienteID,
        `accreceiv`.`TDocumentoOrg`,
        `accreceiv`.`NDocumentoOrg`,
        `accreceiv`.`FechaAR` AS FechaOp,
        0 AS ImporteDeu,
        `accreceiv`.`ImporteAR` AS ImporteAcr
    FROM `fzggestion`.`accreceiv`)) AS T1
GROUP BY ClienteID
</pre></small>
== Código Relacionado ==
*[[MACRO:ReporteClientesCRM]]
== Bitácora ==
== Uso ==