Perguntas [Resolvido] Seções com itens de queries diferentes

Mais
8 anos 9 meses atrás - 8 anos 9 meses atrás #30006 por rafapucci
Bom dia.
Estou precisando realizar um 'mix' de informações entre as tabelas SD1 e SD3, por enquanto são apenas essas duas, e gostaria de dividir as informações entre seções do TReport. Os parâmetros do relatório serão comuns às duas tabelas, então
A minha dúvida é se necessariamente eu preciso ter uma query unica realizando os joins necessários para popular o relatório ou se eu posso criar dois 'datasets' separados com as queries e utilizar nas seções.

As queries de exemplo seriam algo desse tipo:

SD3
SELECT	SD3.D3_COD, SB1.B1_DESC, SB1.B1_TIPO, SD3.D3_UM, SD3.D3_QUANT, SD3.D3_CUSTO1, SD3.D3_CONTA, CT1.CT1_DESC01 ,SD3.D3_CC, SD3.D3_DOC, SD3.D3_EMISSAO
FROM	SD3010 SD3
INNER JOIN SB1010 SB1 ON SD3.D3_COD = SB1.B1_COD
INNER JOIN CT1010 CT1 ON SD3.D3_CONTA = CT1.CT1_CONTA
WHERE	(SD3.D3_EMISSAO BETWEEN '20160126' AND '20160126') AND
		(SD3.D3_CC BETWEEN '210201' AND '210201' ) AND
		(SD3.D3_CONTA BETWEEN '1140404' AND '1140404') AND
		(SB1.B1_TIPO BETWEEN 'MC' AND 'MC') AND
		(SD3.D_E_L_E_T_ <> '*') AND (SB1.D_E_L_E_T_ <> '*') AND (CT1.D_E_L_E_T_ <> '*')

SD1
SELECT	SD1.D1_COD, SB1.B1_DESC, SB1.B1_TIPO, SD1.D1_UM, SD1.D1_QUANT, SD1.D1_VUNIT, SD1.D1_CUSTO, 
		SD1.D1_CONTA, CT1.CT1_DESC01, SD1.D1_CC, SD1.D1_DOC, SD1.D1_SERIE, SD1.D1_DTDIGIT, SD1.D1_FORNECE, SA2.A2_NOME, SD1.D1_TIPO
FROM	SD1010 SD1
INNER JOIN SB1010 SB1 ON SD1.D1_COD = SB1.B1_COD
INNER JOIN CT1010 CT1 ON SD1.D1_CONTA = CT1.CT1_CONTA
INNER JOIN SA2010 SA2 ON SD1.D1_FORNECE = SA2.A2_COD AND SD1.D1_LOJA = SA2.A2_LOJA
WHERE	(D1_DTDIGIT BETWEEN '20160126' AND '20160126') AND
		(D1_CC BETWEEN '210201' AND '210201' ) AND
		(D1_CONTA BETWEEN '1140404' AND '1140404') AND
		(D1_FORNECE BETWEEN '00833' AND '00833') AND
		(SB1.B1_TIPO BETWEEN 'MC' AND 'MC') AND
		(D1_TIPO = 'N') AND
		(SD1.D_E_L_E_T_ <> '*') AND (SB1.D_E_L_E_T_ <> '*') AND (SA2.D_E_L_E_T_ <> '*') AND (CT1.D_E_L_E_T_ <> '*')


Alguém tem alguma ideia para me ajudar?
Att,
RafaelP
Ultima edição: 8 anos 9 meses atrás por rafapucci.

Por favor Acessar ou Registrar para participar da conversa.

Mais
8 anos 9 meses atrás #30007 por kanaamlrr
Bom dia Rafael,
Você consegue criar duas TRSections separadas para cada uma das querys sem problema nenhum.

segue um "exemplo"
//definição
//Dados sintéticos
TRCell():New(oSecao,"D4_COD"   ,"Q_QRY1",AVSX3("D4_COD"   ,5),AVSX3("D4_COD"   ,6),AVSX3("D4_COD"  ,3),,,"LEFT"  )

//Dados análiticos por OP
TRCell():New(oSecao1,"D4_OP"     ,"Q_QRY2",AVSX3("D4_OP"     ,5),AVSX3("D4_OP"     ,6),AVSX3("D4_OP"     ,3),,,"LEFT"  )


//impressão
Static Function ReportPrint(oReport)
*----------------------------------*
Local cOpAtu := ""

oReport:SetMeter(Q_QRY1->(RecCount())+Q_QRY2->(RecCount()))

oReport:Section("SINTETICO"):Init()    
oReport:SkipLine(3)
Do While Q_QRY1->(!EoF()) .And. !oReport:Cancel()
   oReport:Section("SINTETICO"):PrintLine() //Impressão da linha
   oReport:SkipLine()
   oReport:IncMeter()                     //Incrementa a barra de progresso
   Q_QRY1->( dbSkip() )
EndDo
oReport:Section("SINTETICO"):Finish()    
//Fim da impressão da seção 
oReport:EndPage()
cOpAtu := SubStr(Q_QRY2->D4_OP,1,6)
oReport:Section("ANALITICO"):Init()    
oReport:SkipLine(3)
Do While Q_QRY2->(!EoF()) .And. !oReport:Cancel()
   oReport:Section("ANALITICO"):PrintLine() //Impressão da linha
   oReport:SkipLine()
   oReport:IncMeter()                     //Incrementa a barra de progresso
   Q_QRY2->( dbSkip() )
   If cOpAtu <> SubStr(Q_QRY2->D4_OP,1,6)
      cOpAtu := SubStr(Q_QRY2->D4_OP,1,6)
      oReport:Section("ANALITICO"):Finish()    
      oReport:EndPage()
      oReport:Section("ANALITICO"):Init()    
      oReport:SkipLine(3)
   EndIf
EndDo
oReport:Section("ANALITICO"):Finish()    
  

Return .T.
Repare que ora uso a QRY1 e ora a QRY2

Qualquer dúvida só dizer!
Abraço!

Por favor Acessar ou Registrar para participar da conversa.

Mais
8 anos 9 meses atrás #30021 por rafapucci
Boa tarde, Kanaãm.
Obrigado pela resposta, vou tentar utilizar assim aqui no relatório e te retorno se funcionou corretamente!

Abraço!

Por favor Acessar ou Registrar para participar da conversa.

Mais
8 anos 9 meses atrás #30048 por rafapucci
Bom dia, Kanaãm.
Estou com problema de performance quando estou utilizando esse método que você me passou.
Utilizei uma parametrização comum as duas tabelas e o relatório fica eternamente gerando, provavelmente programei alguma coisa errada na parte do relatório pois quando realizo as queries pelo gerenciador do SQL os resultados aparecem em cerca de alguns segundos.
Pode me ajudar?
Segue o código que estou utilizando:
#Include 'Protheus.ch'
#Include 'Topconn.ch'

User Function RelCust01()

	Local oReport := nil
	Local cPerg:= Padr("RELCUST01",11)

	AjustaSX1(cPerg)
	Pergunte(cPerg,.T.)	          

	oReport := RptDef(cPerg)
	oReport:PrintDialog()

Return

Static Function AjustaSX1(cPerg)

	Local aHelpPorIni := {}
	Local aHelpPorFim := {}
	aAdd( aHelpPorIni, "Selecione a data de início")
	aAdd( aHelpPorIni, " para o filtro dos lançamentos")
	
	aAdd( aHelpPorFim, "Selecione a data de término")
	aAdd( aHelpPorFim, " para o filtro dos lançamentos")
	
	PutSx1(cPerg,"01","Data De?","","","mv_ch1","D",10,0,0,"G","NaoVazio()","","","S","mv_par01","","","","","","","","","","","","","","","","",aHelpPorIni,"","")
	PutSx1(cPerg,"02","Data ate?","","","mv_ch2","D",10,0,0,"G","NaoVazio()","","","S","mv_par02","","","","","","","","","","","","","","","","",aHelpPorFim,"","")
	PutSx1(cPerg,"03","Centro de Custo de ?", "", "", "mv_ch3", "C", tamSx3("CTT_CUSTO")[1], 0, 0, "G", "", "CTT", "", "", "mv_par03","","","","","","","","","","","","","","","","","","","")
	PutSx1(cPerg,"04","Centro de Custo até?", "", "", "mv_ch4", "C", tamSx3("CTT_CUSTO")[1], 0, 0, "G", "", "CTT", "", "", "mv_par04","","","","","","","","","","","","","","","","","","","")
	putSx1(cPerg,"05","Conta Contabil de ?", "", "", "mv_ch5", "C", tamSx3("CT1_CONTA")[1], 0, 0, "G", "", "CT1", "", "", "mv_par05","","","","","","","","","","","","","","","","","","","")
	putSx1(cPerg,"06","Conta Contabil ate ?", "", "", "mv_ch6", "C", tamSx3("CT1_CONTA")[1], 0, 0, "G", "", "CT1", "", "", "mv_par06","","","","","","","","","","","","","","","","","","","")
	putSx1(cPerg,"07","Fornecedor de ?", "", "", "mv_ch7", "C", tamSx3("A2_COD")[1], 0,0, "G", "", "SA2", "", "", "mv_par07","","","","","","","","","","","","","","","","","","","")
	putSx1(cPerg,"08","Fornecedor ate ?", "", "", "mv_ch8", "C", TamSx3("A2_COD")[1], 0,0, "G", "", "SA2", "", "", "mv_par08","","","","","","","","","","","","","","","","","","","")
	
Return

Static Function RptDef(cNome)

	Local oReport := Nil
	Local oSection1:= Nil
	Local oSection2:= Nil
	Local oSection3:= Nil
	
	oReport := TReport():New(cNome,"Relatorio dos Custos",cNome,{|oReport| ReportPrint(oReport)},"Relatorio dos Custos")
	oReport:SetLandScape(.T.)
	oReport:SetTotalInLine(.F.)
	
	oSection1:= TRSection():New(oReport, "Centro de Custo", {"QRYSD1"})
	TRCell():New(oSection1, "D1_CC", "QRYSD1", "Centro de Custo" ,"@!",600)
	
	oSection2:= TRSection():New(oReport, "DadosSD1", {"QRYSD1"})
	TRCell():New(oSection2, "D1_COD", "QRYSD1", "Produto" ,"@!",TamSX3("D1_COD")[1])
	TRCell():New(oSection2, "B1_DESC", "QRYSD1", "Desc. Prod" ,"@!",TamSX3("B1_DESC")[1])
	TRCell():New(oSection2, "B1_TIPO", "QRYSD1", "Tipo" ,"@!",TamSX3("B1_TIPO")[1])
	TRCell():New(oSection2, "D1_UM", "QRYSD1", "Unidade de Medida" ,"@!",TamSX3("D1_UM")[1])
	TRCell():New(oSection2, "D1_QUANT", "QRYSD1", "Quantidade" ,"@!",TamSX3("D1_QUANT")[1])
	TRCell():New(oSection2, "D1_VUNIT", "QRYSD1", "V. Unit" ,"@!",TamSX3("D1_VUNIT")[1])
	TRCell():New(oSection2, "D1_CUSTO", "QRYSD1", "Custo" ,"@!",TamSX3("D1_CUSTO")[1])
	TRCell():New(oSection2, "D1_CONTA", "QRYSD1", "Conta" ,"@!",TamSX3("D1_CONTA")[1])
	TRCell():New(oSection2, "CT1_DESC01", "QRYSD1", "Desc. Conta" ,"@!",TamSX3("CT1_DESC01")[1])
	TRCell():New(oSection2, "D1_CC", "QRYSD1", "CC" ,"@!",TamSX3("D1_CC")[1])
	TRCell():New(oSection2, "D1_DOC", "QRYSD1", "Documento" ,"@!",TamSX3("D1_DOC")[1])
	TRCell():New(oSection2, "D1_SERIE", "QRYSD1", "Série" ,"@!",TamSX3("D1_SERIE")[1])
	TRCell():New(oSection2, "D1_TIPO", "QRYSD1", "Tipo" ,"@!",TamSX3("D1_TIPO")[1])
	TRCell():New(oSection2, "D1_DTDIGIT", "QRYSD1", "Data Dig" ,"@!",TamSX3("D1_DTDIGIT")[1])
	TRCell():New(oSection2, "D1_FORNECE", "QRYSD1", "Fornecedor" ,"@!",TamSX3("D1_FORNECE")[1])
	TRCell():New(oSection2, "A2_NOME", "QRYSD1", "Desc Fornecedor" ,"@!",TamSX3("A2_NOME")[1])
	
	oSection3:= TRSection():New(oReport, "DadosSD3", {"QRYSD3"})
	TRCell():New(oSection3, "D3_COD", "QRYSD3", "Código" ,"@!",TamSX3("D3_COD")[1])
	TRCell():New(oSection3, "B1_DESC", "QRYSD3", "Descrição" ,"@!",TamSX3("B1_DESC")[1])
	TRCell():New(oSection3, "B1_TIPO", "QRYSD3", "Tipo" ,"@!",TamSX3("B1_TIPO")[1])
	TRCell():New(oSection3, "D3_UM", "QRYSD3", "Unidade Medida" ,"@!",TamSX3("D3_UM")[1])
	TRCell():New(oSection3, "D3_QUANT", "QRYSD3", "Quantidade" ,"@!",TamSX3("D3_QUANT")[1])
	TRCell():New(oSection3, "D3_CUSTO1", "QRYSD3", "Custo" ,"@!",TamSX3("D3_CUSTO1")[1])
	TRCell():New(oSection3, "D3_CONTA", "QRYSD3", "Conta" ,"@!",TamSX3("D3_CONTA")[1])
	TRCell():New(oSection3, "CT1_DESC01", "QRYSD3", "Desc Conta" ,"@!",TamSX3("CT1_DESC01")[1])
	TRCell():New(oSection3, "D3_CC", "QRYSD3", "Centro de Custo" ,"@!",TamSX3("D3_CC")[1])
	TRCell():New(oSection3, "D3_DOC", "QRYSD3", "Documento" ,"@!",TamSX3("D3_DOC")[1])
	TRCell():New(oSection3, "D3_EMISSAO", "QRYSD3", "Emissão" ,"@!",TamSX3("D3_EMISSAO")[1])
			
	oReport:SetTotalInLine(.F.)
	oSection1:SetTotalText(" ")
		
Return(oReport)

Static Function ReportPrint(oReport)

	Local oSection1 := oReport:Section(1)
	Local oSection2 := oReport:Section(2)
	Local oSection3 := oReport:Section(3)
	Local cQuerySD1 := ""
	Local cQuerySD3 := ""
	Local cCC := ""
	
	cQuerySD1 +=	"SELECT	SD1.D1_COD, SB1.B1_DESC, SB1.B1_TIPO, SD1.D1_UM, SD1.D1_QUANT, SD1.D1_VUNIT, SD1.D1_CUSTO, " 
	cQuerySD1 += 	"SD1.D1_CONTA, CT1.CT1_DESC01, SD1.D1_CC, SD1.D1_DOC, SD1.D1_SERIE, SD1.D1_DTDIGIT, SD1.D1_FORNECE, SA2.A2_NOME, SD1.D1_TIPO "
	cQuerySD1 += 	"FROM " + RetSQLName("SD1") + " SD1 "
	cQuerySD1 += 	"INNER JOIN " + RetSQLName("SB1") + " SB1 ON SD1.D1_COD = SB1.B1_COD "
	cQuerySD1 += 	"INNER JOIN " + RetSQLName("CT1") + " CT1 ON SD1.D1_CONTA = CT1.CT1_CONTA "
	cQuerySD1 += 	"INNER JOIN " + RetSQLName("SA2") + " SA2 ON SD1.D1_FORNECE = SA2.A2_COD AND SD1.D1_LOJA = SA2.A2_LOJA "
	cQuerySD1 += 	"WHERE	(D1_DTDIGIT BETWEEN '" + Dtos(mv_par01) + "' AND '" + Dtos(mv_par02) + "') AND "
	cQuerySD1 += 	"(D1_CC BETWEEN '" + mv_par03 + "' AND '" + mv_par04 + "') AND "
	cQuerySD1 += 	"(D1_CONTA BETWEEN '" + mv_par05 + "' AND '" + mv_par06 + "') AND "
	cQuerySD1 += 	"(D1_FORNECE BETWEEN '" + mv_par07 + "' AND '" + mv_par08 + "') AND "
	cQuerySD1 += 	"(SB1.B1_TIPO BETWEEN '' AND 'ZZZZZZZZZZZZZZZZZZ') AND "
	cQuerySD1 +=  	"(D1_TIPO = 'N') AND "
	cQuerySD1 += 	"(SD1.D_E_L_E_T_ <> '*') AND (SB1.D_E_L_E_T_ <> '*') AND (SA2.D_E_L_E_T_ <> '*') AND (CT1.D_E_L_E_T_ <> '*') "
	
	cQuerySD3 +=	"SELECT	SD3.D3_COD, SB1.B1_DESC, SB1.B1_TIPO, SD3.D3_UM, SD3.D3_QUANT, SD3.D3_CUSTO1, SD3.D3_CONTA, CT1.CT1_DESC01 ,SD3.D3_CC, SD3.D3_DOC, SD3.D3_EMISSAO "
	cQuerySD3 +=	"FROM " + RetSQLName("SD3") + " SD3 "
	cQuerySD3 +=	"INNER JOIN " + RetSQLName("SB1") + " SB1 ON SD3.D3_COD = SB1.B1_COD "
	cQuerySD3 +=	"INNER JOIN " + RetSQLName("CT1") + " CT1 ON SD3.D3_CONTA = CT1.CT1_CONTA "
	cQuerySD3 +=	"WHERE	(SD3.D3_EMISSAO BETWEEN '" + Dtos(mv_par01) + "' AND '" + Dtos(mv_par02) + "') AND "
	cQuerySD3 +=	"(SD3.D3_CC BETWEEN '" + mv_par03 + "' AND '" + mv_par04 + "') AND "
	cQuerySD3 +=	"(SD3.D3_CONTA BETWEEN '" + mv_par05 + "' AND '" + mv_par06 + "') AND "
	cQuerySD3 +=	"(SB1.B1_TIPO BETWEEN '' AND 'ZZZZZZZZZZZZZZZZZZ') AND "
	cQuerySD3 +=	"(SD3.D_E_L_E_T_ <> '*') AND (SB1.D_E_L_E_T_ <> '*') AND (CT1.D_E_L_E_T_ <> '*') "
	
	
	IF Select("QRYSD1") <> 0
		DbSelectArea("QRYSD1")
		DbCloseArea()
	ENDIF
	
	TCQUERY cQuerySD1 NEW ALIAS "QRYSD1"
	
	IF Select("QRYSD3") <> 0
		DbSelectArea("QRYSD3")
		DbCloseArea()
	ENDIF
	
	TCQUERY cQuerySD3 NEW ALIAS "QRYSD3"
	
	dbSelectArea("QRYSD1")
	QRYSD1->(dbGoTop())
	
	dbSelectArea("QRYSD3")
	QRYSD3->(dbGoTop())
	
	//oReport:SetMeter(QRYSD1->(RecCount())+QRYSD3->(RecCount()))+QRYSN3->(RecCount()))
	oReport:SetMeter(QRYSD1->(RecCount())+QRYSD3->(RecCount()))
	
	While !Eof()
		
		If oReport:Cancel()
			Exit
		EndIf
	
	oSection1:Init()	
	oReport:IncMeter()	
	cCC := QRYSD1->D1_CC
	
	oSection1:Cell("D1_CC"):SetValue(QRYSD1->D1_CC)
	oSection1:Printline()

	oSection2:init()
	oSection3:init()
	
	While(QRYSD1->D1_CC == cCC)
			oReport:IncMeter()

			oSection2:Cell("D1_COD"):SetValue(QRYSD1->D1_COD)
			oSection2:Cell("B1_DESC"):SetValue(QRYSD1->B1_DESC)
			oSection2:Cell("B1_TIPO"):SetValue(QRYSD1->B1_TIPO)
			oSection2:Cell("D1_UM"):SetValue(QRYSD1->D1_UM)
			oSection2:Cell("D1_QUANT"):SetValue(QRYSD1->D1_QUANT)
			oSection2:Cell("D1_VUNIT"):SetValue(QRYSD1->D1_VUNIT)
			oSection2:Cell("D1_CUSTO"):SetValue(QRYSD1->D1_CUSTO)
			oSection2:Cell("D1_CONTA"):SetValue(QRYSD1->D1_CONTA)
			oSection2:Cell("CT1_DESC01"):SetValue(QRYSD1->CT1_DESC01)
			oSection2:Cell("D1_CC"):SetValue(QRYSD1->D1_CC)
			oSection2:Cell("D1_DOC"):SetValue(QRYSD1->D1_DOC)
			oSection2:Cell("D1_SERIE"):SetValue(QRYSD1->D1_SERIE)
			oSection2:Cell("D1_TIPO"):SetValue(QRYSD1->D1_TIPO)
			oSection2:Cell("D1_DTDIGIT"):SetValue(STOD(QRYSD1->D1_DTDIGIT))
			oSection2:Cell("D1_FORNECE"):SetValue(QRYSD1->D1_FORNECE)
			oSection2:Cell("A2_NOME"):SetValue(QRYSD1->A2_NOME)
			oSection2:Printline()
			
			oSection3:Cell("D3_COD"):SetValue(QRYSD3->D3_COD)
			oSection3:Cell("B1_DESC"):SetValue(QRYSD3->B1_DESC)
			oSection3:Cell("B1_TIPO"):SetValue(QRYSD3->B1_TIPO)
			oSection3:Cell("D3_UM"):SetValue(QRYSD3->D3_UM)
			oSection3:Cell("D3_QUANT"):SetValue(QRYSD3->D3_QUANT)
			oSection3:Cell("D3_CUSTO1"):SetValue(QRYSD3->D3_CUSTO1)
			oSection3:Cell("D3_CONTA"):SetValue(QRYSD3->D3_CONTA)
			oSection3:Cell("CT1_DESC01"):SetValue(QRYSD3->CT1_DESC01)
			oSection3:Cell("D3_CC"):SetValue(QRYSD3->D3_CC)
			oSection3:Cell("D3_DOC"):SetValue(QRYSD3->D3_DOC)
			oSection3:Cell("D3_EMISSAO"):SetValue(STOD(QRYSD3->D3_EMISSAO))
			oSection3:Printline()
						
		QRYSD1->(dbSkip())
		QRYSD3->(dbSkip())
	EndDo

	oSection2:Finish()
	oSection3:Finish()
	oReport:ThinLine()
	oSection1:Finish()
	
	EndDo
Return

Por favor Acessar ou Registrar para participar da conversa.

Mais
8 anos 9 meses atrás #30056 por rafapucci
Boa tarde, galera.
Percebi que estava iterando dentro de um loop só do primeiro dataset preenchido (SD1) e por isso ele ficava travado.
Realizei algumas alterações e esta funcionando com a SD1 e SD3, porém preciso inserir a SN3 também.
Realizei o mesmo processo mas não funcionou, alguem tem ideia de onde estou vacilando?
#Include 'Protheus.ch'
#Include 'Topconn.ch'

User Function RelCust01()

	Local oReport := nil
	Local cPerg:= Padr("RELCUST01",11)

	AjustaSX1(cPerg)
	Pergunte(cPerg,.T.)	          

	oReport := RptDef(cPerg)
	oReport:PrintDialog()

Return

Static Function AjustaSX1(cPerg)

	Local aHelpPorIni := {}
	Local aHelpPorFim := {}
	aAdd( aHelpPorIni, "Selecione a data de início")
	aAdd( aHelpPorIni, " para o filtro dos lançamentos")
	
	aAdd( aHelpPorFim, "Selecione a data de término")
	aAdd( aHelpPorFim, " para o filtro dos lançamentos")
	
	PutSx1(cPerg,"01","Data De?","","","mv_ch1","D",10,0,0,"G","NaoVazio()","","","S","mv_par01","","","","","","","","","","","","","","","","",aHelpPorIni,"","")
	PutSx1(cPerg,"02","Data ate?","","","mv_ch2","D",10,0,0,"G","NaoVazio()","","","S","mv_par02","","","","","","","","","","","","","","","","",aHelpPorFim,"","")
	PutSx1(cPerg,"03","Centro de Custo de ?", "", "", "mv_ch3", "C", tamSx3("CTT_CUSTO")[1], 0, 0, "G", "", "CTT", "", "", "mv_par03","","","","","","","","","","","","","","","","","","","")
	PutSx1(cPerg,"04","Centro de Custo até?", "", "", "mv_ch4", "C", tamSx3("CTT_CUSTO")[1], 0, 0, "G", "", "CTT", "", "", "mv_par04","","","","","","","","","","","","","","","","","","","")
	putSx1(cPerg,"05","Conta Contabil de ?", "", "", "mv_ch5", "C", tamSx3("CT1_CONTA")[1], 0, 0, "G", "", "CT1", "", "", "mv_par05","","","","","","","","","","","","","","","","","","","")
	putSx1(cPerg,"06","Conta Contabil ate ?", "", "", "mv_ch6", "C", tamSx3("CT1_CONTA")[1], 0, 0, "G", "", "CT1", "", "", "mv_par06","","","","","","","","","","","","","","","","","","","")
	putSx1(cPerg,"07","Fornecedor de ?", "", "", "mv_ch7", "C", tamSx3("A2_COD")[1], 0,0, "G", "", "SA2", "", "", "mv_par07","","","","","","","","","","","","","","","","","","","")
	putSx1(cPerg,"08","Fornecedor ate ?", "", "", "mv_ch8", "C", TamSx3("A2_COD")[1], 0,0, "G", "", "SA2", "", "", "mv_par08","","","","","","","","","","","","","","","","","","","")
	
Return

Static Function RptDef(cNome)

	Local oReport 	:= Nil
	Local oSection1	:= Nil
	Local oSection2	:= Nil
	Local oSection3	:= Nil
	Local oSection4:= Nil
	
	oReport := TReport():New(cNome,"Relatorio dos Custos",cNome,{|oReport| ReportPrint(oReport)},"Relatorio dos Custos")
	oReport:SetLandScape(.T.)
	oReport:SetTotalInLine(.F.)
	
	oSection1:= TRSection():New(oReport, "Centro de Custo", {"QRYSD1"})
	TRCell():New(oSection1, "D1_CC", "QRYSD1", "Centro de Custo" ,"@!",600)
	
	oSection2:= TRSection():New(oReport, "DadosSD1", {"QRYSD1"})
	TRCell():New(oSection2, "D1_COD", "QRYSD1", "Produto" ,"@!",TamSX3("D1_COD")[1])
	TRCell():New(oSection2, "B1_DESC", "QRYSD1", "Desc. Prod" ,"@!",TamSX3("B1_DESC")[1])
	TRCell():New(oSection2, "B1_TIPO", "QRYSD1", "Tipo" ,"@!",TamSX3("B1_TIPO")[1])
	TRCell():New(oSection2, "D1_UM", "QRYSD1", "Unidade de Medida" ,"@!",TamSX3("D1_UM")[1])
	TRCell():New(oSection2, "D1_QUANT", "QRYSD1", "Quantidade" ,"@!",TamSX3("D1_QUANT")[1])
	TRCell():New(oSection2, "D1_VUNIT", "QRYSD1", "V. Unit" ,"@!",TamSX3("D1_VUNIT")[1])
	TRCell():New(oSection2, "D1_CUSTO", "QRYSD1", "Custo" ,"@!",TamSX3("D1_CUSTO")[1])
	TRCell():New(oSection2, "D1_CONTA", "QRYSD1", "Conta" ,"@!",TamSX3("D1_CONTA")[1])
	TRCell():New(oSection2, "CT1_DESC01", "QRYSD1", "Desc. Conta" ,"@!",TamSX3("CT1_DESC01")[1])
	TRCell():New(oSection2, "D1_CC", "QRYSD1", "CC" ,"@!",TamSX3("D1_CC")[1])
	TRCell():New(oSection2, "D1_DOC", "QRYSD1", "Documento" ,"@!",TamSX3("D1_DOC")[1])
	TRCell():New(oSection2, "D1_SERIE", "QRYSD1", "Série" ,"@!",TamSX3("D1_SERIE")[1])
	TRCell():New(oSection2, "D1_TIPO", "QRYSD1", "Tipo" ,"@!",TamSX3("D1_TIPO")[1])
	TRCell():New(oSection2, "D1_DTDIGIT", "QRYSD1", "Data Dig" ,"@!",TamSX3("D1_DTDIGIT")[1])
	TRCell():New(oSection2, "D1_FORNECE", "QRYSD1", "Fornecedor" ,"@!",TamSX3("D1_FORNECE")[1])
	TRCell():New(oSection2, "A2_NOME", "QRYSD1", "Desc Fornecedor" ,"@!",TamSX3("A2_NOME")[1])
	
	oSection3:= TRSection():New(oReport, "DadosSD3", {"QRYSD3"})
	TRCell():New(oSection3, "D3_COD", "QRYSD3", "Código" ,"@!",TamSX3("D3_COD")[1])
	TRCell():New(oSection3, "B1_DESC", "QRYSD3", "Descrição" ,"@!",TamSX3("B1_DESC")[1])
	TRCell():New(oSection3, "B1_TIPO", "QRYSD3", "Tipo" ,"@!",TamSX3("B1_TIPO")[1])
	TRCell():New(oSection3, "D3_UM", "QRYSD3", "Unidade Medida" ,"@!",TamSX3("D3_UM")[1])
	TRCell():New(oSection3, "D3_QUANT", "QRYSD3", "Quantidade" ,"@!",TamSX3("D3_QUANT")[1])
	TRCell():New(oSection3, "D3_CUSTO1", "QRYSD3", "Custo" ,"@!",TamSX3("D3_CUSTO1")[1])
	TRCell():New(oSection3, "D3_CONTA", "QRYSD3", "Conta" ,"@!",TamSX3("D3_CONTA")[1])
	TRCell():New(oSection3, "CT1_DESC01", "QRYSD3", "Desc Conta" ,"@!",TamSX3("CT1_DESC01")[1])
	TRCell():New(oSection3, "D3_CC", "QRYSD3", "Centro de Custo" ,"@!",TamSX3("D3_CC")[1])
	TRCell():New(oSection3, "D3_DOC", "QRYSD3", "Documento" ,"@!",TamSX3("D3_DOC")[1])
	TRCell():New(oSection3, "D3_EMISSAO", "QRYSD3", "Emissão" ,"@!",10)
	
	oSection4:= TRSection():New(oReport, "DadosSN3", {"QRYSN3"})
	TRCell():New(oSection4, "N3_CCUSTO", "QRYSN3", "Conta Contábil" ,"@!",TamSX3("N3_CCUSTO")[1])
	TRCell():New(oSection4, "N3_VRDMES1", "QRYSN3", "Valor Dep Mes" ,"@!",TamSX3("N3_VRDMES1")[1])
			
	oReport:SetTotalInLine(.F.)
	oSection1:SetTotalText(" ")
		
Return(oReport)

Static Function ReportPrint(oReport)

	Local oSection1 := oReport:Section(1)
	Local oSection2 := oReport:Section(2)
	Local oSection3 := oReport:Section(3)
	Local oSection4 := oReport:Section(4)
	Local cQuerySD1 := ""
	Local cQuerySD3 := ""
	Local cQuerySN3 := ""
	Local cCC := ""
	Local cCCSD3 := ""
	Local cCCSN3 := ""
	
	cQuerySD1 +=	"SELECT	SD1.D1_COD, SB1.B1_DESC, SB1.B1_TIPO, SD1.D1_UM, SD1.D1_QUANT, SD1.D1_VUNIT, SD1.D1_CUSTO, " 
	cQuerySD1 += 	"SD1.D1_CONTA, CT1.CT1_DESC01, SD1.D1_CC, SD1.D1_DOC, SD1.D1_SERIE, SD1.D1_DTDIGIT, SD1.D1_FORNECE, SA2.A2_NOME, SD1.D1_TIPO "
	cQuerySD1 += 	"FROM " + RetSQLName("SD1") + " SD1 "
	cQuerySD1 += 	"INNER JOIN " + RetSQLName("SB1") + " SB1 ON SD1.D1_COD = SB1.B1_COD "
	cQuerySD1 += 	"INNER JOIN " + RetSQLName("CT1") + " CT1 ON SD1.D1_CONTA = CT1.CT1_CONTA "
	cQuerySD1 += 	"INNER JOIN " + RetSQLName("SA2") + " SA2 ON SD1.D1_FORNECE = SA2.A2_COD AND SD1.D1_LOJA = SA2.A2_LOJA "
	cQuerySD1 += 	"WHERE	(D1_DTDIGIT BETWEEN '" + Dtos(mv_par01) + "' AND '" + Dtos(mv_par02) + "') AND "
	cQuerySD1 += 	"(D1_CC BETWEEN '" + mv_par03 + "' AND '" + mv_par04 + "') AND "
	cQuerySD1 += 	"(D1_CONTA BETWEEN '" + mv_par05 + "' AND '" + mv_par06 + "') AND "
	cQuerySD1 += 	"(D1_FORNECE BETWEEN '" + mv_par07 + "' AND '" + mv_par08 + "') AND "
	cQuerySD1 += 	"(SB1.B1_TIPO BETWEEN '' AND 'ZZZZZZZZZZZZZZZZZZ') AND "
	cQuerySD1 +=  	"(D1_TIPO = 'N') AND "
	cQuerySD1 += 	"(SD1.D_E_L_E_T_ <> '*') AND (SB1.D_E_L_E_T_ <> '*') AND (SA2.D_E_L_E_T_ <> '*') AND (CT1.D_E_L_E_T_ <> '*') "
	
	cQuerySD3 +=	"SELECT	TOP 3 SD3.D3_COD, SB1.B1_DESC, SB1.B1_TIPO, SD3.D3_UM, SD3.D3_QUANT, SD3.D3_CUSTO1, SD3.D3_CONTA, CT1.CT1_DESC01 ,SD3.D3_CC, SD3.D3_DOC, SD3.D3_EMISSAO "
	cQuerySD3 +=	"FROM " + RetSQLName("SD3") + " SD3 "
	cQuerySD3 +=	"INNER JOIN " + RetSQLName("SB1") + " SB1 ON SD3.D3_COD = SB1.B1_COD "
	cQuerySD3 +=	"INNER JOIN " + RetSQLName("CT1") + " CT1 ON SD3.D3_CONTA = CT1.CT1_CONTA "
	cQuerySD3 +=	"WHERE	(SD3.D3_EMISSAO BETWEEN '" + Dtos(mv_par01) + "' AND '" + Dtos(mv_par02) + "') AND "
	cQuerySD3 +=	"(SD3.D3_CC BETWEEN '" + mv_par03 + "' AND '" + mv_par04 + "') AND "
	cQuerySD3 +=	"(SD3.D3_CONTA BETWEEN '" + mv_par05 + "' AND '" + mv_par06 + "') AND "
	cQuerySD3 +=	"(SB1.B1_TIPO BETWEEN '' AND 'ZZZZZZZZZZZZZZZZZZ') AND "
	cQuerySD3 +=	"(SD3.D_E_L_E_T_ <> '*') AND (SB1.D_E_L_E_T_ <> '*') AND (CT1.D_E_L_E_T_ <> '*') "
	
	cQuerySN3 +=	"SELECT TOP 1 SN3.N3_VRDMES1, SN3.N3_CCUSTO "
	cQuerySN3 +=	"FROM " + RetSQLName("SN3") + " SN3 "
	cQuerySN3 +=	"WHERE (SN3.N3_CCUSTO BETWEEN '" + mv_par03 + "' AND '" + mv_par04 + "') "
	
	oSection1:Init()
	oSection2:Init()	
	oSection3:Init()
	oSection4:Init()
			
	IF Select("QRYSD1") <> 0
		DbSelectArea("QRYSD1")
		DbCloseArea()
	ENDIF
	
	TCQUERY cQuerySD1 NEW ALIAS "QRYSD1"
	
	IF Select("QRYSD3") <> 0
		DbSelectArea("QRYSD3")
		DbCloseArea()
	ENDIF
	
	TCQUERY cQuerySD3 NEW ALIAS "QRYSD3"
	
	IF Select("QRYSN3") <> 0
		DbSelectArea("QRYSN3")
		DbCloseArea()
	ENDIF
	
	TCQUERY cQuerySN3 NEW ALIAS "QRYSN3"
	
	dbSelectArea("QRYSD1")
	QRYSD1->(dbGoTop())
	
	oReport:SetMeter(QRYSD1->(RecCount())+QRYSD3->(RecCount())+QRYSN3->(RecCount()))
	//oReport:SetMeter(QRYSD1->(RecCount())+QRYSD3->(RecCount()))
	
	While QRYSD1->(!Eof())
		
		If oReport:Cancel()
			Exit
		EndIf
	
	oReport:IncMeter()	
	cCC := QRYSD1->D1_CC
	
	oSection1:Cell("D1_CC"):SetValue(QRYSD1->D1_CC)
	oSection1:Printline()
	
		While(QRYSD1->D1_CC == cCC)
			oReport:IncMeter()

			oSection2:Cell("D1_COD"):SetValue(QRYSD1->D1_COD)
			oSection2:Cell("B1_DESC"):SetValue(QRYSD1->B1_DESC)
			oSection2:Cell("B1_TIPO"):SetValue(QRYSD1->B1_TIPO)
			oSection2:Cell("D1_UM"):SetValue(QRYSD1->D1_UM)
			oSection2:Cell("D1_QUANT"):SetValue(QRYSD1->D1_QUANT)
			oSection2:Cell("D1_VUNIT"):SetValue(QRYSD1->D1_VUNIT)
			oSection2:Cell("D1_CUSTO"):SetValue(QRYSD1->D1_CUSTO)
			oSection2:Cell("D1_CONTA"):SetValue(QRYSD1->D1_CONTA)
			oSection2:Cell("CT1_DESC01"):SetValue(QRYSD1->CT1_DESC01)
			oSection2:Cell("D1_CC"):SetValue(QRYSD1->D1_CC)
			oSection2:Cell("D1_DOC"):SetValue(QRYSD1->D1_DOC)
			oSection2:Cell("D1_SERIE"):SetValue(QRYSD1->D1_SERIE)
			oSection2:Cell("D1_TIPO"):SetValue(QRYSD1->D1_TIPO)
			oSection2:Cell("D1_DTDIGIT"):SetValue(STOD(QRYSD1->D1_DTDIGIT))
			oSection2:Cell("D1_FORNECE"):SetValue(QRYSD1->D1_FORNECE)
			oSection2:Cell("A2_NOME"):SetValue(QRYSD1->A2_NOME)
			oSection2:Printline()
				
			QRYSD1->(dbSkip())
		EndDo
	EndDo
	
	dbSelectArea("QRYSD3")
	QRYSD3->(dbGoTop())
	
	While QRYSD3->(!Eof())
		
		If oReport:Cancel()
			Exit
		EndIf
		
	oReport:IncMeter()	
	cCCSD3 := QRYSD3->D3_CC
	
		While(QRYSD3->D3_CC == cCCSD3)
			oReport:IncMeter()
	
			oSection3:Cell("D3_COD"):SetValue(QRYSD3->D3_COD)
			oSection3:Cell("B1_DESC"):SetValue(QRYSD3->B1_DESC)
			oSection3:Cell("B1_TIPO"):SetValue(QRYSD3->B1_TIPO)
			oSection3:Cell("D3_UM"):SetValue(QRYSD3->D3_UM)
			oSection3:Cell("D3_QUANT"):SetValue(QRYSD3->D3_QUANT)
			oSection3:Cell("D3_CUSTO1"):SetValue(QRYSD3->D3_CUSTO1)
			oSection3:Cell("D3_CONTA"):SetValue(QRYSD3->D3_CONTA)
			oSection3:Cell("CT1_DESC01"):SetValue(QRYSD3->CT1_DESC01)
			oSection3:Cell("D3_CC"):SetValue(QRYSD3->D3_CC)
			oSection3:Cell("D3_DOC"):SetValue(QRYSD3->D3_DOC)
			oSection3:Cell("D3_EMISSAO"):SetValue(STOD(QRYSD3->D3_EMISSAO))
			oSection3:Printline()
				
			QRYSD3->(dbSkip())
		EndDo	
	EndDo
	
	dbSelectArea("QRYSN3")
	QRYSN3->(dbGoTop())
	
	While QRYSN3->(!Eof())
		
		If oReport:Cancel()
			Exit
		EndIf
		
	oReport:IncMeter()	
	cCCSD3 := QRYSN3->N3_CCUSTO
	
		While(QRYSN3->N3_CCUSTO == cCCSN3)
			oReport:IncMeter()
	
			oSection4:Cell("N3_CCUSTO"):SetValue(QRYSD3->N3_CCUSTO)
			oSection4:Cell("N3_VRDMES1"):SetValue(QRYSD3->N3_VRDMES1)
			oSection4:Printline()
				
			QRYSN3->(dbSkip())
		EndDo	
	EndDo
	
	oSection2:Finish()
	oSection3:Finish()
	oSection4:Finish()
	oReport:ThinLine()
	oSection1:Finish()
Return

Por favor Acessar ou Registrar para participar da conversa.

Mais
8 anos 9 meses atrás #30057 por rafapucci
Ops, já encontrei onde estava incorreto.
Foi um erro de ctrl+c e ctrl+v ... Hahaha

Att,
RafaelP.

Por favor Acessar ou Registrar para participar da conversa.

Tempo para a criação da página:0.118 segundos
Joomla templates by a4joomla