cesarini Posted March 3, 2014 at 02:17 PM Report #547335 Posted March 3, 2014 at 02:17 PM Bom dia à todos; Venho neste forum que tenho um enorme agradecimento pois ja aprendi muito com ele, solicitar uma ajuda estou a fazer um sistama financeiro ( contas a pagar, receber, conciliação bancaria , etc) estou com grandes problemas para fazer os relatorios estou usando o crystal reports nunca havia ultilizado ele antes e o unico modo que aprendi foi fazer uma viu montar ele e depois passar outro dataset para ele com a mesma estrutura do viu, para não ter que ficar preso somente a uma conexão. Mas o que esta me dando o maior trabalho seria um relatorio de provisionado pois seria como o layout abaixo: Empresa Data1 Data2 Data3 Data4 Test1 tabelaCredito - Tabela Debito Ate dia 03/03/2014 tabelaCredito - Tabela Debito Ate dia 04/03/2014 ate dia 05/03 ...... Test2 tabelaCredito - Tabela Debito Ate dia 03/03/2014 tabelaCredito - Tabela Debito Ate dia 04/03/2014 ate dia 05/03 ...... E ai continua. Meu SQL esta assim mas consigo trazer somente até a primeira data as proximas não faço ideia de como trazer... SELECT DISTINCT cadastro_empresas.EMP_NOMEFANTASIA as Nome_Igreja, (select date_add(now(), interval 1 day)) as data1 , (select date_add(now(), interval 1 day)) as data2, (select date_add(now(), interval 1 day)) as data3, (select date_add(now(), interval 1 day)) as data4, (select date_add(now(), interval 1 day)) as data5, (sum(lancamento_credito.LANCCRED_VALORRECEBER) - sum(lancamento_debito.LANCDEB_VALORRECEBER)) as valor1 from cadastro_empresas inner join cadastro_contas on cadastro_contas.EMP_CODIGO=cadastro_empresas.EMP_CODIGO inner join lancamento_credito on cadastro_contas.BANC_CODIGO=lancamento_credito.BANC_CODIGO inner join lancamento_debito on lancamento_debito.EMP_CODIGO=cadastro_empresas.EMP_CODIGO where lancamento_credito.LANCCRED_DATACREDITO <= "20140302" and lancamento_debito.LANCDEB_DATAVENCIMENTO <= "20140302" group by cadastro_empresas.EMP_CODIGO; Se alguém poder me ajudar agradeço muito!!!
HappyHippyHippo Posted March 3, 2014 at 05:46 PM Report #547408 Posted March 3, 2014 at 05:46 PM não dá para perceber o que pretendes ... IRC : sim, é algo que ainda existe >> #p@p Portugol Plus
cesarini Posted March 3, 2014 at 06:16 PM Author Report #547420 Posted March 3, 2014 at 06:16 PM HappyHippyHippo Eu preciso gerar um relatorio que me traga o saldo das contas bancarias ate tal data, somando os creditos e debitandos os debitos somados desta conta bancaria. Para fazer isso de somente um dia estou conseguindo conforme o exemplo que postei acima, Mas o meu problemas está que o relatorio tem previsão de cinco dias ou seja, a primeira coluna so pode somar os creditos e debitos ate tal data , a proxima coluna soma do dia seguinte e assim por diante.
HappyHippyHippo Posted March 3, 2014 at 06:19 PM Report #547421 Posted March 3, 2014 at 06:19 PM então apresenta aqui a estrutura de tabelas que tens IRC : sim, é algo que ainda existe >> #p@p Portugol Plus
cesarini Posted March 3, 2014 at 06:37 PM Author Report #547422 Posted March 3, 2014 at 06:37 PM https://docs.google.com/file/d/0B5pIrJKj7_seWi1lWUpiUU5rOFE/edit?hl=pt-BR&forcehl=1 esta ai o link da imagem da estrutura...
cesarini Posted March 3, 2014 at 08:28 PM Author Report #547433 Posted March 3, 2014 at 08:28 PM Boa tarde; Consegui chegar o mais perto possível com este código abaixo: create or replace view provisionado (nome_igreja, valor1, valor2) as SELECT cadastro_empresas.EMP_NOMEFANTASIA as Nome_Igreja, (sum(lancamento_credito.LANCCRED_VALORRECEBER) - sum(lancamento_debito.LANCDEB_VALORRECEBER)) as valor1 , null as valor2 from cadastro_empresas inner join cadastro_contas on cadastro_contas.EMP_CODIGO=cadastro_empresas.EMP_CODIGO inner join lancamento_credito on cadastro_contas.BANC_CODIGO=lancamento_credito.BANC_CODIGO inner join lancamento_debito on lancamento_debito.EMP_CODIGO=cadastro_empresas.EMP_CODIGO where lancamento_credito.LANCCRED_DATACREDITO <= "20140302" and lancamento_debito.LANCDEB_DATAVENCIMENTO <= "20140302" group by cadastro_empresas.EMP_CODIGOunion all SELECT null as Nome_Igreja, null as valor1, (sum(lancamento_credito.LANCCRED_VALORRECEBER) - sum(lancamento_debito.LANCDEB_VALORRECEBER)) as valor2 from cadastro_empresas inner join cadastro_contas on cadastro_contas.EMP_CODIGO=cadastro_empresas.EMP_CODIGO inner join lancamento_credito on cadastro_contas.BANC_CODIGO=lancamento_credito.BANC_CODIGO inner join lancamento_debito on lancamento_debito.EMP_CODIGO=cadastro_empresas.EMP_CODIGO where lancamento_credito.LANCCRED_DATACREDITO <= "20140302" and lancamento_debito.LANCDEB_DATAVENCIMENTO <= "20140302" group by cadastro_empresas.EMP_CODIGO; select * from provisionado; que me retorna isso : nome_igreja valor1 valor2 teste -673.5500048828125 NULL IFB Matriz 111948.70003890991 NULL NULL NULL -673.5500048828125 NULL NULL 111948.70003890991 Alguém consegue me informar como faço para ficar assim : nome_igreja valor1 valor2 teste -673.5500048828125 -673.5500048828125 IFB Matriz 111948.70003890991 111948.70003890991 Obrigado...
HappyHippyHippo Posted March 4, 2014 at 05:22 AM Report #547470 Posted March 4, 2014 at 05:22 AM não testado (pelas razões óbvias) : select EMP_NOMEFANTASIA, CDate0.Total, DDate0.Total, CDate1.Total, DDate1.Total, CDate2.Total, DDate2.Total, CDate3.Total, DDate3.Total, CDate4.Total, DDate4.Total from cadastro_empresas AS E inner join cadastro_contas AS C on E.EMP_CODIGO = C.EMP_CODIGO inner join (select BANC_CODIGO, sum(LANCCRED_VALORRECEBER) as Total from lancamento_credito where LANCCRED_DATACREDITO = "2014-03-02" and BANC_CODIGO = E.BANC_CODIGO) as CDate0 on E.BANC_CODIGO = CDate0.BANC_CODIGO inner join (select BANC_CODIGO, sum(LANCDEB_VALORRECEBER) as Total from lancamento_debito where LANCCRED_DATACREDITO = "2014-03-02" and BANC_CODIGO = E.BANC_CODIGO) as DDate0 on E.BANC_CODIGO = DDate0.BANC_CODIGO inner join (select BANC_CODIGO, sum(LANCCRED_VALORRECEBER) as Total from lancamento_credito where LANCCRED_DATACREDITO = adddate("2014-03-02", interval 1 day) and BANC_CODIGO = E.BANC_CODIGO) as CDate1 on E.BANC_CODIGO = CDate1.BANC_CODIGO inner join (select BANC_CODIGO, sum(LANCDEB_VALORRECEBER) as Total from lancamento_debito where LANCCRED_DATACREDITO = adddate("2014-03-02", interval 1 day) and BANC_CODIGO = E.BANC_CODIGO) as DDate1 on E.BANC_CODIGO = DDate1.BANC_CODIGO inner join (select BANC_CODIGO, sum(LANCCRED_VALORRECEBER) as Total from lancamento_credito where LANCCRED_DATACREDITO = adddate("2014-03-02", interval 2 day) and BANC_CODIGO = E.BANC_CODIGO) as CDate2 on E.BANC_CODIGO = CDate2.BANC_CODIGO inner join (select BANC_CODIGO, sum(LANCDEB_VALORRECEBER) as Total from lancamento_debito where LANCCRED_DATACREDITO = adddate("2014-03-02", interval 2 day) and BANC_CODIGO = E.BANC_CODIGO) as DDate2 on E.BANC_CODIGO = DDate2.BANC_CODIGO inner join (select BANC_CODIGO, sum(LANCCRED_VALORRECEBER) as Total from lancamento_credito where LANCCRED_DATACREDITO = adddate("2014-03-02", interval 3 day) and BANC_CODIGO = E.BANC_CODIGO) as CDate3 on E.BANC_CODIGO = CDate3.BANC_CODIGO inner join (select BANC_CODIGO, sum(LANCDEB_VALORRECEBER) as Total from lancamento_debito where LANCCRED_DATACREDITO = adddate("2014-03-02", interval 3 day) and BANC_CODIGO = E.BANC_CODIGO) as DDate3 on E.BANC_CODIGO = DDate3.BANC_CODIGO inner join (select BANC_CODIGO, sum(LANCCRED_VALORRECEBER) as Total from lancamento_credito where LANCCRED_DATACREDITO = adddate("2014-03-02", interval 4 day) and BANC_CODIGO = E.BANC_CODIGO) as CDate4 on E.BANC_CODIGO = CDate4.BANC_CODIGO inner join (select BANC_CODIGO, sum(LANCDEB_VALORRECEBER) as Total from lancamento_debito where LANCCRED_DATACREDITO = adddate("2014-03-02", interval 4 day) and BANC_CODIGO = E.BANC_CODIGO) as DDate4 on E.BANC_CODIGO = DDate4.BANC_CODIGO 1 Report IRC : sim, é algo que ainda existe >> #p@p Portugol Plus
cesarini Posted March 4, 2014 at 04:01 PM Author Report #547504 Posted March 4, 2014 at 04:01 PM (edited) Muito Obrigado HappyHippyHippo; Tive que fazer algumas alterações, mas a sua base me ajudou muito desconhecia a possibilidade de select dentro de inner joins. Segue abaixo o SQL final para que caso ajude alguém e posso dizer que o tópico está encerrado. 🙂 (MySQL) select EMP_NOMEFANTASIA, CDate0.Total, DDate0.Total, CDate1.Total, DDate1.Total, CDate2.Total, DDate2.Total, CDate3.Total, DDate3.Total from cadastro_empresas AS E inner join cadastro_contas AS C on E.EMP_CODIGO = C.EMP_CODIGO inner join (select lancamento_credito.BANC_CODIGO, sum(LANCCRED_VALORRECEBER) as Total from lancamento_credito INNER JOIN cadastro_contas AS C ON lancamento_credito.BANC_CODIGO=C.BANC_CODIGO INNER JOIN cadastro_empresas AS E ON E.EMP_CODIGO = C.EMP_CODIGO where LANCCRED_DATACREDITO <= "2014-03-02" and lancamento_credito.BANC_CODIGO = C.BANC_CODIGO group by E.EMP_CODIGO ) as CDate0 on C.BANC_CODIGO = CDate0.BANC_CODIGO inner join (select lancamento_debito.EMP_CODIGO, sum(LANCDEB_VALORRECEBER) as Total from lancamento_debito INNER JOIN cadastro_empresas AS E ON E.EMP_CODIGO=lancamento_debito.EMP_CODIGO where LANCDEB_DATAVENCIMENTO <= "2014-03-02" and lancamento_debito.EMP_CODIGO = E.EMP_CODIGO group by E.EMP_CODIGO) as DDate0 on E.EMP_CODIGO = DDate0.EMP_CODIGO inner join (select lancamento_credito.BANC_CODIGO, sum(LANCCRED_VALORRECEBER) as Total from lancamento_credito INNER JOIN cadastro_contas AS C ON lancamento_credito.BANC_CODIGO=C.BANC_CODIGO INNER JOIN cadastro_empresas AS E ON E.EMP_CODIGO = C.EMP_CODIGO where LANCCRED_DATACREDITO <= adddate("2014-03-02", interval 1 day) and lancamento_credito.BANC_CODIGO = C.BANC_CODIGO group by E.EMP_CODIGO ) as CDate1 on C.BANC_CODIGO = CDate1.BANC_CODIGO inner join (select lancamento_debito.EMP_CODIGO, sum(LANCDEB_VALORRECEBER) as Total from lancamento_debito INNER JOIN cadastro_empresas AS E ON E.EMP_CODIGO=lancamento_debito.EMP_CODIGO where LANCDEB_DATAVENCIMENTO <= adddate("2014-03-02", interval 1 day) and lancamento_debito.EMP_CODIGO = E.EMP_CODIGO group by E.EMP_CODIGO) as DDate1 on E.EMP_CODIGO = DDate1.EMP_CODIGO inner join (select lancamento_credito.BANC_CODIGO, sum(LANCCRED_VALORRECEBER) as Total from lancamento_credito INNER JOIN cadastro_contas AS C ON lancamento_credito.BANC_CODIGO=C.BANC_CODIGO INNER JOIN cadastro_empresas AS E ON E.EMP_CODIGO = C.EMP_CODIGO where LANCCRED_DATACREDITO <= adddate("2014-03-02", interval 2 day) and lancamento_credito.BANC_CODIGO = C.BANC_CODIGO group by E.EMP_CODIGO ) as CDate2 on C.BANC_CODIGO = CDate2.BANC_CODIGO inner join (select lancamento_debito.EMP_CODIGO, sum(LANCDEB_VALORRECEBER) as Total from lancamento_debito INNER JOIN cadastro_empresas AS E ON E.EMP_CODIGO=lancamento_debito.EMP_CODIGO where LANCDEB_DATAVENCIMENTO <= adddate("2014-03-02", interval 2 day) and lancamento_debito.EMP_CODIGO = E.EMP_CODIGO group by E.EMP_CODIGO) as DDate2 on E.EMP_CODIGO = DDate2.EMP_CODIGO inner join (select lancamento_credito.BANC_CODIGO, sum(LANCCRED_VALORRECEBER) as Total from lancamento_credito INNER JOIN cadastro_contas AS C ON lancamento_credito.BANC_CODIGO=C.BANC_CODIGO INNER JOIN cadastro_empresas AS E ON E.EMP_CODIGO = C.EMP_CODIGO where LANCCRED_DATACREDITO <= adddate("2014-03-02", interval 3 day) and lancamento_credito.BANC_CODIGO = C.BANC_CODIGO group by E.EMP_CODIGO ) as CDate3 on C.BANC_CODIGO = CDate3.BANC_CODIGO inner join (select lancamento_debito.EMP_CODIGO, sum(LANCDEB_VALORRECEBER) as Total from lancamento_debito INNER JOIN cadastro_empresas AS E ON E.EMP_CODIGO=lancamento_debito.EMP_CODIGO where LANCDEB_DATAVENCIMENTO <= adddate("2014-03-02", interval 3 day) and lancamento_debito.EMP_CODIGO = E.EMP_CODIGO group by E.EMP_CODIGO) as DDate3 on E.EMP_CODIGO = DDate3.EMP_CODIGO Edited March 4, 2014 at 04:03 PM by cesarini
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now