Bloco de código |
---|
title | Exemplo 1 - Executando a query no objeto de negócio |
---|
collapse | true |
---|
| #include "msobject.ch"
#include "protheus.ch"
#include "totvs.framework.treports.integratedprovider.th"
namespace custom.smartview
@totvsFrameworkTReportsIntegratedProvider(active=.T., team="Framework", tables="SA5,SA2", name="Produto X Fornecedor", country="ALL", initialRelease="12.1.033", customTables="All")
//-------------------------------------------------------------------
/*{Protheus.doc} CustomTReportsBusinessObject
Classe para criação do Objeto de Negócio de Prod x Forn para o TReports
@author Vanessa Ruama
@since 02/03/2023
@version 1.0
*/
//-------------------------------------------------------------------
class CustomTReportsBusinessObject from totvs.framework.treports.integratedprovider.IntegratedProvider
public method new() as object
public method getDisplayName() as character
public method getDescription() as character
public method getData() as object
public method getSchema() as object
protected data aFields as array
protected data aStruct as array
endclass
//-------------------------------------------------------------------
/*{Protheus.doc} new
Método de instância da classe
@return object: self
@author Vanessa Ruama
@since 02/03/2023
@version 1.0
*/
//-------------------------------------------------------------------
method new() class CustomTReportsBusinessObject
_Super:new()
self:appendArea("Framework - Custom")
self:aFields := {"A5_FILIAL", "A5_FORNECE", "A5_LOJA", "A5_NOMEFOR", "A5_PRODUTO", "A5_NOMPROD", "A5_CODPRF", "A2_END"}
self:aStruct := u_getStruct(self:aFields)
return self
//-------------------------------------------------------------------
/*{Protheus.doc} getDisplayName
Retorna o nome de exibição do objeto de negócio
@return string
@author Vanessa Ruama
@since 02/03/2023
@version 1.0
*/
//-------------------------------------------------------------------
method getDisplayName() as character class CustomTReportsBusinessObject
return "Produtos x Fornecedores"
//-------------------------------------------------------------------
/*{Protheus.doc} getDescription
Retorna a descrição do objeto de negócio
@return string
@author Vanessa Ruama
@since 02/03/2023
@version 1.0
*/
//-------------------------------------------------------------------
method getDescription() as character class CustomTReportsBusinessObject
return "Produtos x Fornecedores"
//-------------------------------------------------------------------
/*{Protheus.doc} getData
Retorna os dados do objeto de negócio
@param nPage, numérico, indica a página atual do relatório
@param oFilter, objeto, contém o filtro do TReports
@return object: self:oData
@author Vanessa Ruama
@since 02/03/2023
@version 1.0
*/
//-------------------------------------------------------------------
method getData(nPage as numeric, oFilter as object) as object class CustomTReportsBusinessObject
local cQuery as character
local cAlias as character
local nSkip as numeric
local nCount as numeric
local nX as numeric
local jItems as json
local aPDFields as array
local aAllFields as array
local cRealName as character
local cId as character
nCount := 0
aAllFields := {}
//Verifica se o Smart View retornou os campos utilizados
if oFilter:hasFields()
cQuery := "SELECT " + ArrTokStr(oFilter:getFields(), ",") + " FROM " + RetSQLName("SA5")
else
//Manda todos os campos do schema
cQuery := "SELECT " + self:getSQLFields() + " FROM " + RetSQLName("SA5")
endif
cQuery += " SA5 LEFT JOIN SA2T10 SA2 ON SA5.A5_FORNECE = SA2.A2_COD WHERE SA2.D_E_L_E_T_ = ' '"
//Os filtros serão setados na interface do novo TReports
if oFilter:hasFilter()
cQuery += " AND " + oFilter:getSQLExpression()
endif
self:setPageSize(150)
cAlias := MPSysOpenQuery(cQuery)
if nPage ==<> 1
(cAlias)->(dbGoTop())
else
//Default 100
//Encontra a quantidade de itens que irá pular de acordo com a página atual
nSkip := ((nPage - 1) * self:getPageSize())
(cAlias)->(dbSkip(nSkip))
endif
//Verifica se precisa fazer o tratamento para LGPD
aPDFields := FwProtectedDataUtil():UsrAccessPDField(__cUserID, self:getArrayFields())
lObfuscated := len( aPDFields ) != Len(self:getArrayFields())
aAllFields := self:getStructFields()
while !(cAlias)->(Eof())
jItems := JsonObject():new()
for nX := 1 To Len(aAllFields)
cId := aAllFields[nX]:getName()
cRealName := aAllFields[nX]:getRealName()
if lObfuscated .and. aScan(aPDFields, cRealName) == 0
jItems[cId] := FwProtectedDataUtil():ValueAsteriskToAnonymize((cAlias)->&(cRealName))
else
if cId == "Info"
jItems[cId] := cValToChar(nX)
elseif aAllFields[nX]:getType() == "date"
jItems[cId] := totvs.framework.treports.date.stringToTimeStamp((cAlias)->&(cRealName))
else
jItems[cId] := (cAlias)->&(cRealName)
endif
endif
next nX
self:oData:appendData(jItems)
(cAlias)->(DBSkip())
nCount++
//Sai do loop quando chegar no tamanho de itens da página
if nCount == self:getPageSize()
exit
endif
enddo
//Se não for o último registro indica que terá próxima página
self:setHasNext(!(cAlias)->(Eof()))
(cAlias)->(DBCloseArea())
return self:oData
//-------------------------------------------------------------------
/*{Protheus.doc} getSchema
Retorna a estrutura dos campos
@return object: self:oSchema
@author Vanessa Ruama
@since 02/03/2023
@version 1.0
*/
//-------------------------------------------------------------------
method getSchema() as object class CustomTReportsBusinessObject
Local nX as numeric
for nX := 1 To Len(self:aStruct)
self:addProperty(self:aStruct[nX][1], self:aStruct[nX][2], self:aStruct[nX][3], self:aStruct[nX][4], self:aStruct[nX][5])
Next nX
aAdd(self:aStruct, {"Info", "Info", "string", "Informações", "Info"}) //Campo manual
//Adicionando um campo manual
self:addProperty("Info", "Info", "string", "Informações", "Info")
return self:oSchema
//-------------------------------------------------------------------
/*{Protheus.doc} getStruct
Prepara a estrutura dos campos
@param aCpos array: Array com os campos do relatório
@return array: Array com a estrutura dos campos
@author Vanessa Ruama
@since 02/03/2023
@version 1.0
*/
//-------------------------------------------------------------------
user function getStruct(aCpos)
Local aDeParaCpo as array
Local aCpoTmp as array
Local cCampo as character
Local cCpoQry as character
Local cTipR as character
Local nPos as numeric
Local nC as numeric
aDeParaCpo := {{"C", "string"}, {"D", "date"}, {"N", "number"}, {"L", "boolean"}, {"M", "memo"}}
aCpoTmp := {}
for nC := 1 to Len(aCpos)
cCpoQry := aCpos[nC]
nPos := AT(".", aCpos[nC]) + 1
if nPos > 0
cCampo := Substr(cCpoQry, nPos)
else
cCampo := cCpoQry
endif
cTipo := GetSx3Cache(cCampo, "X3_TIPO")
if (nPos := aScan(aDeParaCpo, {|c| c[01] = cTipo})) > 0
cTipR := aDeParaCpo[nPos, 02]
else
cTipR := "string"
endif
AAdd(aCpoTmp, {strTran(cCampo, "_", ""), FWSX3Util():GetDescription(cCampo), cTipR, FWSX3Util():GetDescription(cCampo), cCampo})
next nC
return (aCpoTmp) |
Bloco de código |
---|
title | Exemplo 2 - Mandando a query para o Framework |
---|
collapse | true |
---|
| #include "msobject.ch"
#include "totvs.framework.treports.integratedprovider.th"
#include "tlpp-core.th"
#include "tlpp-rest.th"
namespace totvs.protheus.saude.treportsintegratedprovider
@totvsFrameworkTReportsIntegratedProvider(active=.T., team="Framework", tables="BA3", name="Famílias", country="ALL", initialRelease="12.1.033", customTables="All")
class BA3TReportsBusinessObject from totvs.framework.treports.integratedprovider.IntegratedProvider
public method new() as object
public method getAreas() as array
public method getDescription() as character
public method getData() as object
public method getSchema() as object
endclass
method new() as object class BA3TReportsBusinessObject
_Super:new()
self:setDisplayName("Famílias")
return self
method getDescription() as character class BA3TReportsBusinessObject
return "Cadastro das Famílias"
method getAreas() as array class BA3TReportsBusinessObject
return {"Saúde"}
method getData(nPage as numeric, oFilter as object) as object class BA3TReportsBusinessObject
local cQuery as character
local cWhere as character
cQuery := "SELECT #QueryFields# FROM " + RetSQLName("BA3") + " WHERE #QueryWhere#"
cWhere := " D_E_L_E_T_ = ' '"
//Define a quantidade máxima por página (Default 100)
self:setPageSize(150)
//Define a query do Objeto de Negócio
self:setQuery(cQuery)
//Define o campo de ordenação da query
self:setOrder("BA3_MATRIC")
//Define o where da query
self:setWhere(cWhere)
return self:oData
method getSchema() as object class BA3TReportsBusinessObject
self:aliasToSchema("BA3" , {"BA3_DATBLO", "BA3_CODINT", "BA3_MATRIC"})
self:addProperty("BA3_VERCON", "BA3_VERCON", "string", "BA3_VERCON", "BA3_VERCON",,,,.F.) //Adicionando como não filtrável, nono parâmetro como falso
self:setPropDisplayName("BA3_VERCON", "Versão (BA3)") //Mudando o displayName da propriedade de BA3_VERCON para Versão (BA3)
return self:oSchema |
Bloco de código |
---|
title | Exemplo 3 - Mandando os dados para o Framework |
---|
collapse | true |
---|
| #include "msobject.ch"
#include "totvs.framework.treports.integratedprovider.th"
#include "tlpp-core.th"
#include "tlpp-rest.th"
namespace totvs.protheus.rh.treportsintegratedprovider
@totvsFrameworkTReportsIntegratedProvider(active=.T., team="Framework", tables="SRA", name="Funcionários", country="ALL", initialRelease="12.1.033", customTables="SRA")
class SRA2TReportsBusinessObject from totvs.framework.treports.integratedprovider.IntegratedProvider
public method new() as object
public method getAreas() as array
public method getDescription() as character
public method getData() as object
public method getSchema() as object
endclass
method new() as object class SRA2TReportsBusinessObject
_Super:new()
self:setDisplayName("Funcionários")
return self
method getDescription() as character class SRA2TReportsBusinessObject
return "Funcionários"
method getAreas() as array class SRA2TReportsBusinessObject
return {"Framework - Custom"}
method getData(nPage as numeric, oFilter as object) as object class SRA2TReportsBusinessObject
self:setPageSize(200)
self:aliasToData("SRA", oFilter)
return self:oData
method getSchema() as object class SRA2TReportsBusinessObject
self:oSchema:aliasToSchema("SRA", {"RA_FILIAL", "RA_MAT", "RA_NOME"})
return self:oSchema |
|