Last active
February 15, 2016 12:28
-
-
Save cesarAugusto1994/bc4af9e1b68e1844a0fc to your computer and use it in GitHub Desktop.
2093 - Buscar Prestadores Inadimplentes
This file contains hidden or 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 | |
CONCAT(itxa.storeno, ' / ', pxa.eordno) AS 'Loja / Pedido', | |
CONCAT(pe.id_pessoa, ' - ', pe.nome_pessoa) AS Pestador, | |
DATE_FORMAT(inst.date, '%d/%m/%Y') AS 'Data Compra', | |
itxa.contrno AS Contrato, | |
REPLACE(ROUND((inst.cashamt - inst.downpay) / 100, 2), '.',',') AS 'Valor Financiado', | |
CONCAT(itxa.instno, ' x de ', ROUND(itxa.instamt / 100, 2)) AS 'Parcela/Valor', | |
REPLACE(ROUND(itxa.paidamt / 100, 2), '.', ',') AS 'Valor Pago', | |
DATE_FORMAT(itxa.duedate,'%d/%m/%Y') AS 'Data Vencimento', | |
itxa.paiddate AS 'Data Pagamento', | |
REPLACE(ROUND((((itxa.instamt * inst.noofinst) - (inst.cashamt - inst.downpay)) / inst.noofinst) / 100, 2), '.', ',') AS 'Valor Lucro Parcela', | |
IF(itxa.status = 0, 'em Aberto', if(itxa.status = 2, 'Pagto. Parcial', if(itxa.status = 3, 'SPC', itxa.status))) AS Status, | |
REPLACE(ROUND((itxa.instamt * inst.noofinst) / 100, 2), '.', ',') AS 'Valor Total', | |
REPLACE(ROUND(((itxa.instamt * inst.noofinst) - (inst.cashamt - inst.downpay)) / 100, 2), '.', ',') AS 'Valor Encargos' | |
FROM sqldados.inst inst | |
INNER JOIN sqldados.itxa itxa ON (inst.storeno = itxa.storeno AND inst.contrno = itxa.contrno) | |
INNER JOIN webpdv.prestador pre ON (pre.id_pessoa = inst.custno) | |
INNER JOIN webpdv.pessoas pe ON (pe.id_pessoa = pre.id_pessoa) | |
INNER JOIN webpdv.pedido_forma_pagamento pfp | |
ON (pfp.storeno = inst.storeno AND pfp.obs = inst.contrno) | |
INNER JOIN sqlpdv.pxa pxa | |
ON (pxa.storeno = pfp.storeno AND pxa.pdvno = pfp.pdvno AND pxa.eordno = pfp.ordno AND pxa.custno = inst.custno) | |
WHERE itxa.status IN (0, 2, 3) | |
#AND pfp.xatype = 5 # Crediário | |
#AND pxa.storeno IN (2) # Loja | |
AND itxa.duedate < date_format(now(), '%Y%m%d') # Data de Vencimento | |
GROUP BY itxa.storeno, itxa.contrno, itxa.instno | |
ORDER BY itxa.storeno, itxa.contrno, itxa.duedate; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment