Last active
September 30, 2015 16:12
-
-
Save MarioCares/077ed55d3c404cbeb2a6 to your computer and use it in GitHub Desktop.
Órdenes que el sistema no ha sido capaz de finalizar automágicamente ...
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
SELECT | |
o.id, | |
o.numero, | |
@total_orden := o.total AS total_orden, | |
@total_pagos := ( | |
SELECT (COALESCE(SUM(dt.monto), 0) - COALESCE(SUM(nc.monto), 0)) AS total | |
FROM finanzas_documento_tributario AS dt | |
LEFT JOIN finanzas_notacredito AS nc ON nc.documentotributario_id = dt.id | |
WHERE dt.ordencompra_id = o.id) AS total_pagos, | |
o.estado_id, | |
o.orden_at, | |
(@total_orden - @total_pagos) as total_final | |
FROM finanzas_ordencompra AS o | |
WHERE YEAR(o.orden_at) = YEAR(NOW()) AND o.estado_id NOT IN (3,4) AND o.departamento = "SALUD" | |
HAVING total_final BETWEEN -100 AND 100 | |
ORDER BY total_final DESC |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment