Histórico da Página
...
Bloco de código |
---|
#include "protheus.ch"
#include "msobject.ch"
// Referência o .th da classe
#include "totvs.framework.treports.integratedprovider.th"
// Cria um novo namespace para sua classe
namespace custom.financeiro.naturezas.integratedprovider
// Caso queira desativar a utilização da classe mudar para active=.F.
@totvsFrameworkTReportsIntegratedProvider(active=.T., team="SIGAFIN", tables="SED", name="Naturezas", country="ALL", initialRelease="12.1.2210")
// Cria uma nova classe e herda a classe principal (IntegratedProvider) com o namespace
class SEDTReportsBusinessObject from totvs.framework.treports.integratedprovider.IntegratedProvider
public method new() as object
endclass |
...
Informações | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Objeto oSchema Serão feitos tratamentos internos neste objeto. Ele possui apenas dois métodos para uso externo, usados em conjunto com os métodos da nova classe, sendo eles: Método AliasToSchema() - Método do objeto oSchema que transforma o alias em um schema, caso seja utilizado apenas o primeiro parâmetro todos os campos serão enviados.
Parâmetros:
Método AddProperty() - Método do objeto oSchema que adiciona uma propriedade ao schema. Parâmetros:
Exemplos de uso estarão abaixo nos métodos criados para a classe IntegratedProvider. Obs: O nome real é necessário para que o filtro seja feito com base no nome real do campo, caso contrário, o mesmo levará em consideração a propriedade name. Método AddParameter() - Método do objeto oSchema que adiciona um parâmetro ao objeto de negócio.
Parâmetros:
|
...
Bloco de código |
---|
method getData(nPage as numeric, oFilter as object) as object class SEDTReportsBusinessObject local cQuery as character local cAlias as character local oExec as object cQuery := "SELECT ED_DESCRIC FROM " + RetSqlName('SED') + " WHERE D_E_L_E_T_ = ' '" if oFilter:hasFilter() cQuery += " AND " + oFilter:getSQLExpression() endif oExec := FwExecStatement():New(ChangeQuery(cQuery)) cAlias := MPSysOpenQueryoExec:OpenAlias(cQuery) while !(cAlias)->(Eof()) self:appendData({"Descrição": (cAlias)->ED_DESCRIC}) (cAlias)->(DBSkip()) enddo (cAlias)->(DBCloseArea()) return self:oData |
...
Define o nome do relatório.
Aviso | ||
---|---|---|
| ||
É obrigatório o envio do DisplayName nos Objetos de Negócio |
Exemplo de uso:
Bloco de código |
---|
SetDisplayName("Naturezas") |
...
Adiciona uma área a qual o relatório pertence.
Aviso | ||
---|---|---|
| ||
É obrigatório o envio de pelo menos uma área nos Objetos de Negócio |
Parâmetros:
Nome | Tipo | Obrigatório | Default | Descrição |
---|---|---|---|---|
cArea | Caracter | X | Nome da área do relatório |
...
Define a descrição do relatório.
Aviso | ||
---|---|---|
| ||
É obrigatório o envio da Descrição nos Objetos de Negócio |
Sintaxe: SetDescription(<cTexto>) → nil
...
Bloco de código | ||||
---|---|---|---|---|
| ||||
#include "msobject.ch" #include "totvs.framework.treports.integratedprovider.th" namespace custom.financeiro.fornecedores.integratedprovider @totvsFrameworkTReportsIntegratedProvider(active=.T., team="SIGACOM", tables="SA2", name="SA2TReportsBusinessObject", country="ALL", initialRelease="12.1.2210") class SA2TReportsBusinessObject 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 SA2TReportsBusinessObject _Super:new() self:setDisplayName("Fornecedores") return self method getDescription() as character class SA2TReportsBusinessObject return "Fornecedores do Protheus" method getAreas() as array class SA2TReportsBusinessObject return {"Financeiro", "Contas a pagar"} method getData(nPage as numeric, oFilter as object) as object class SA2TReportsBusinessObject local cQuery as character local cAlias as character local oExec as object cQuery := "SELECT A2_NOME, A2_COD FROM " + RetSqlName('SA2') + " WHERE D_E_L_E_T_ = ' '" //Os filtros serão setados na interface do novo TReports if oFilter:hasFilter() cQuery += " AND " + oFilter:getSQLExpression() endif oExec := FwExecStatement():New(ChangeQuery(cQuery)) cAlias := MPSysOpenQueryoExec:OpenAlias(cQuery) while !(cAlias)->(Eof()) self:appendData({"Nome": (cAlias)->A2_NOME, "Codigo": (cAlias)->A2_COD}) (cAlias)->(DBSkip()) enddo (cAlias)->(DBCloseArea()) return self:oData method getSchema() as object class SA2TReportsBusinessObject self:addProperty("Nome", "Nome do Fornecedor", "string", "Fornecedor", "A2_NOME") self:addProperty("Codigo", "Codigo do Fornecedor", "string", "Cod do Fornecedor", "A2_COD") return self:oSchema |
Bloco de código | ||||
---|---|---|---|---|
| ||||
#include "msobject.ch" #include "totvs.framework.treports.integratedprovider.th" namespace custom.materiais.produtos.integratedprovider @totvsFrameworkTReportsIntegratedProvider(active=.T., team="SIGACOM", tables="SB1", name="Materiais", country="ALL", initialRelease="12.1.2210") class SB1TReportsBusinessObject 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 endclass method new() class SB1TReportsBusinessObject _Super:new() self:appendArea("Materiais") return self method getDisplayName() as character class SB1TReportsBusinessObject return "Produtos" method getDescription() as character class SB1TReportsBusinessObject return "Produtos do Protheus" method getData(nPage as numeric, oFilter as object) as object class SB1TReportsBusinessObject local cQuery as character local cAlias as character cQuery :local oExec as object cQuery := "SELECT B1_FILIAL, B1_COD, B1_DESC, B1_TIPO, B1_UM, B1_UREV FROM " + RetSQLName("SB1") + " WHERE D_E_L_E_T_ = ' '" //Os filtros serão setados na interface do novo TReports if oFilter:hasFilter() cQuery += " AND " + oFilter:getSQLExpression() endif oExec := FwExecStatement():New(ChangeQuery(cQuery)) cAlias := MPSysOpenQueryoExec:OpenAlias(cQuery) while !(cAlias)->(Eof()) self:appendData({"Filial": (cAlias)->B1_FILIAL,; "Codigo": (cAlias)->B1_COD,; "Descricao": (cAlias)->B1_DESC,; "Tipo": (cAlias)->B1_TIPO, ; "Unidade": (cAlias)->B1_UM, ; "Revisao": iif(!empty((cAlias)->B1_UREV)), FwTimeStamp(5, StoD((cAlias)->B1_UREV), "00:00:00"), nil) }) //O campo data deverá ser enviado no formato correto, se estiver vazio enviar nil (cAlias)->(DBSkip()) enddo (cAlias)->(DBCloseArea()) return self:oData method getSchema() as object class SB1TReportsBusinessObject self:aliasToSchema("SB1", "B1_COD") self:addProperty("Descricao", "Descricao", "string", "Descricao","B1_DESC") self:addProperty("Tipo", "Tipo", "string", "Tipo","B1_TIPO") self:addProperty("Unidade", "Unidade de medida", "string", "Unidade","B1_UM") self:addProperty("Revisao", "Revisao", "date", "Revisao","B1_UREV") return self:oSchema |
...
Informações |
---|
Pode ser utilizado nos métodos new, getData e getSchema da classe. |
...
Bloco de código | ||||
---|---|---|---|---|
| ||||
#include "msobject.ch" #include "protheus.ch" #include "totvs.framework.treports.integratedprovider.th" namespace custom.materiais @totvsFrameworkTReportsIntegratedProvider(active=.T., team="SIGACOM", tables="SB1", name="Materiais", country="ALL", initialRelease="12.1.2210") class SB1TReportsBusinessObject 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 endclass method new() class SB1TReportsBusinessObject _Super:new() self:appendArea("Materiais") self:setIsCBoxLookup(.T., .T.) return self method getDisplayName() as character class SB1TReportsBusinessObject return "Produtos" method getDescription() as character class SB1TReportsBusinessObject return "Produtos do Protheus" method getData(nPage as numeric, oFilter as object) as object class SB1TReportsBusinessObject local cQuery as character local cAlias as character local oExec as object cQuery := "SELECT B1_FILIAL, B1_COD, B1_DESC, B1_TIPO, B1_UM, B1_UREV, B1_FILIAL, B1_PRV1 FROM " + RetSQLName("SB1") + " WHERE D_E_L_E_T_ = ' '" //Os filtros serão setados na interface do novo TReports if oFilter:hasFilter() cQuery += " AND " + oFilter:getSQLExpression() endif oExec := FwExecStatement():New(ChangeQuery(cQuery)) cAlias := MPSysOpenQueryoExec:OpenAlias(cQuery) while !(cAlias)->(Eof()) cDate := iif(!empty((cAlias)->B1_UREV)), FwTimeStamp(5, StoD((cAlias)->B1_UREV), "00:00:00"), nil) self:appendData({"Filial": (cAlias)->B1_FILIAL,; "Codigo": (cAlias)->B1_COD,; "Descricao": (cAlias)->B1_DESC,; "Tipo": (cAlias)->B1_TIPO, ; "Unidade": (cAlias)->B1_UM, ; "Revisao": cDate ,; "Preco": (cAlias)->B1_PRV1}) (cAlias)->(DBSkip()) enddo (cAlias)->(DBCloseArea()) return self:oData method getSchema() as object class SB1TReportsBusinessObject local cComboFil as character cComboFil := "D MG 01=Filial BH; D MG 02=Filial Uberaba" self:addProperty("Filial", "Filial", "string", "Filial", "B1_FILIAL", cComboFil,.F.) self:addProperty("Codigo", "Codigo", "string", "Codigo", "B1_COD") self:addProperty("Descricao", "Descricao", "string", "Descricao","B1_DESC") self:addProperty("Tipo", "Tipo", "string", "Tipo","B1_TIPO") self:addProperty("Unidade", "Unidade de medida", "string", "Unidade","B1_UM") self:addProperty("Revisao", "Revisao", "date", "revisao","B1_UREV") self:addProperty("Data", "Data", "date", "Data","B1_UREV") self:addProperty("Preco", "Preço", "number", "Preço","B1_PRV1") return self:oSchema |
...
Bloco de código | ||||
---|---|---|---|---|
| ||||
#include "msobject.ch" #include "protheus.ch" #include "totvs.framework.treports.integratedprovider.th" namespace custom.materiais.produtos.integratedprovider.lookup @totvsFrameworkTReportsIntegratedProvider(active=.T., team="SIGACOM", tables="SB1", name="Produtos do Protheus", country="ALL", initialRelease="12.1.2210") class SB1TReportsBusinessObject 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 endclass method new() class SB1TReportsBusinessObject _Super:new() self:appendArea("Compras") self:setIsLookUp(.T.) return self method getDisplayName() as character class SB1TReportsBusinessObject return "Produtos" method getDescription() as character class SB1TReportsBusinessObject return "Produtos do Protheus" method getData(nPage as numeric, oFilter as object) as object class SB1TReportsBusinessObject local cQuery as character local cAlias as character local oExec as object cQuery := "SELECT B1_FILIAL, B1_COD, B1_DESC, B1_TIPO, B1_UM, B1_UREV FROM " + RetSQLName("SB1") + " WHERE D_E_L_E_T_ = ' '" //Os filtros serão setados na interface do novo TReports if oFilter:hasFilter() cQuery += " AND " + oFilter:getSQLExpression() endif oExec := FwExecStatement():New(ChangeQuery(cQuery)) cAlias := MPSysOpenQueryoExec:OpenAlias(cQuery) while !(cAlias)->(Eof()) cDate := iif(!empty((cAlias)->B1_UREV)), FwTimeStamp(5, StoD((cAlias)->B1_UREV), "00:00:00"), nil) self:appendData({"Filial": (cAlias)->B1_FILIAL,; "Codigo": (cAlias)->B1_COD,; "Descricao": (cAlias)->B1_DESC,; "Tipo": (cAlias)->B1_TIPO, ; "Unidade": (cAlias)->B1_UM, ; "Revisao": cDate}) (cAlias)->(DBSkip()) enddo (cAlias)->(DBCloseArea()) return self:oData method getSchema() as object class SB1TReportsBusinessObject local cField as character local aStruct as array local lIsRequired as logical Local aDescriptor as array Local nFieldReturn as numeric //Seta a descrição da consulta self:setDescriptor("Código","Código do Produto", "Descrição") cComboFil := "D MG 01=Filial BH; D MG 02=Filial Uberaba; D RJ 01 =Filial RJ" self:aliasToSchema("SB1", {"B1_FILIAL", "B1_COD"}) self:addProperty("Descricao", "Descricao", "string", "Descricao","B1_DESC") self:addProperty("Tipo", "Tipo", "string", "Tipo","B1_TIPO") self:addProperty("Unidade", "Unidade de medida", "string", "Unidade","B1_UM") self:addProperty("Revisao", "Revisao", "date", "revisao","B1_UREV") self:addProperty("Camp Log", "Camp Log", "boolean", "Camp Lógico","B1_LOGI") cField := "B1_COD" aStruct := {} aAdd(aStruct, {"ATF0510001", "ATFA036 EMISSAO DE NOTA EM LOT"}) aAdd(aStruct, {"0003","PRODUTO PADRAO"}) aAdd(aStruct, {"EST00000000000000000000001GGGR","'PRODTO ESTOQUE GRADE EAI INTE"}) lIsRequired := .F. aDescriptor := {"Codigo","Descrição"} nFieldReturn := 1 //Seta os valores para o Lookup self:setLookUpVal(cField, aStruct, lIsRequired, aDescriptor, nFieldReturn) return self:oSchema |
Bloco de código | ||||
---|---|---|---|---|
| ||||
#include "msobject.ch" #include "protheus.ch" #include "totvs.framework.treports.integratedprovider.th" namespace custom.financeiro.fornecedores.integratedprovider.lookup @totvsFrameworkTReportsIntegratedProvider(active=.T., team="SIGAFIN", tables="SA2", name="Fornecedores", country="ALL", initialRelease="12.1.2210") class SA2TReportsBusinessObject 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 SA2TReportsBusinessObject _Super:new() self:setDisplayName("Fornecedores") self:setIsLookUp(.T.) return self method getDescription() as character class SA2TReportsBusinessObject return "Fornecedores do Protheus" method getAreas() as array class SA2TReportsBusinessObject return {"Financeiro", "Contas a pagar"} method getData(nPage as numeric, oFilter as object) as object class SA2TReportsBusinessObject local cQuery as character local cAlias as character local oExec as object cQuery := "SELECT * FROM " + RetSqlName('SA2') + " WHERE D_E_L_E_T_ = ' '" if oFilter:hasFilter() cQuery += " AND " + oFilter:getSQLExpression() endif oExec := FwExecStatement():New(ChangeQuery(cQuery)) cAlias := MPSysOpenQueryoExec:OpenAlias(cQuery) while !(cAlias)->(Eof()) self:appendData({"Nome": (cAlias)->A2_NOME,; "Codigo": (cAlias)->A2_COD,; "Estado": (cAlias)->A2_EST}) (cAlias)->(DBSkip()) enddo (cAlias)->(DBCloseArea()) return self:oData method getSchema() as object class SA2TReportsBusinessObject self:addProperty("Nome", "Nome do Fornecedor", "string", "Nome","A2_NOME") self:addProperty("Codigo", "Código do Fornecedor", "string", "Código", "A2_COD") self:addProperty("Estado", "Sigla da Federacao", "string", "Estado", "A2_EST") //Seta o lookup a partir de uma tabela da SX5 self:setX5Struct("A2_EST", "12", .F.) return self:oSchema |
...
Com isso o desenvolvedor consegue indicar quantos itens serão enviados ao Smart View por requisição.
Informações | ||
---|---|---|
| ||
A paginação mexe diretamente com a performance de como os dados serão buscados via API, se a fonte de dados carrega 100 itens por requisição e uma tabela possui 6.000 registros, ele irá fazer a requisição 60 vezes. Se eu seto o pageSize como 1000, ele irá fazer a requisição 6 vezes porém com um intervalo maior entre as requisições, isso deverá ser visto de acordo com a necessidade de cada área/produto em relação ao objeto de negócio que será construído com essa fonte de dados nativa. |
Método self:setPageSize()
...
Método self:setPageSize()
Seta a quantidade de itens por página.
Nota |
---|
A partir da lib 20240408 esse método esta depreciado. |
Parâmetros:
Nome | Tipo | Obrigatório | Default | Descrição |
---|---|---|---|---|
nPageSize | Númerico | X | 100 | Indica a quantidade de itens por requisição |
...
Nome | Tipo | Obrigatório | Default | Descrição |
---|---|---|---|---|
cQuery | Caracter | X | Indica a query do objeto de negócio |
Aviso | ||
---|---|---|
|
...
| |
|
Exemplo de uso:
Bloco de código |
---|
cQuery := "SELECT * FROM " + RetSQLName("SB1") + " WHERE B1_FILIAL = '"+ FWxFilial('SB1') +"' AND D_E_L_E_T_ = ' ' self:setQuery(cQuery) |
...
Bloco de código | ||||
---|---|---|---|---|
| ||||
#include "msobject.ch" #include "protheus.ch" #include "totvs.framework.treports.integratedprovider.th" namespace custom.materiais @totvsFrameworkTReportsIntegratedProvider(active=.T., team="SIGACOM", tables="SB1", name="Materiais", country="ALL", initialRelease="12.1.2210") class SB1TReportsBusinessObject 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 endclass method new() class SB1TReportsBusinessObject _Super:new() self:appendArea("Materiais - KeyLabel") //Seta o lookup do campo do tipo combobox self:setIsCBoxLookup(.T., .T.) return self method getDisplayName() as character class SB1TReportsBusinessObject return "Produtos" method getDescription() as character class SB1TReportsBusinessObject return "Produtos do Protheus" method getData(nPage as numeric, oFilter as object) as object class SB1TReportsBusinessObject local cQuery as character local cAlias as character local nSkip as numeric local nEnd as numeric local nCount as numeric local oExec as object nCount := 0 cQuery := "SELECT B1_FILIAL, B1_COD, B1_DESC, B1_TIPO, B1_UM, B1_UREV, B1_FILIAL, B1_PRV1 FROM " + RetSQLName("SB1") + " WHERE D_E_L_E_T_ = ' '" //Os filtros serão setados na interface do novo TReports if oFilter:hasFilter() cQuery += " AND " + oFilter:getSQLExpression() endif cAliasoExec := MPSysOpenQueryFwExecStatement():New(ChangeQuery(cQuery)) cAlias := oExec:OpenAlias() //Seta a quantidade de itens por página (Default 100) self:setPageSize(15) //Posiciona o conteúdo da query if nPage > 1 //Encontra a quantidade de itens que irá pular de acordo com a página atual nSkip := ((nPage - 1) * self:getPageSize()) (cAlias)->(dbSkip(nSkip)) endif while !(cAlias)->(Eof()) cDate := iif(!empty((cAlias)->B1_UREV), FwTimeStamp(5, StoD((cAlias)->B1_UREV), "00:00:00"), nil) self:oData:appendData({"Filial": (cAlias)->B1_FILIAL,; "Codigo": (cAlias)->B1_COD,; "Descricao": (cAlias)->B1_DESC,; "Tipo": (cAlias)->B1_TIPO, ; "Unidade": (cAlias)->B1_UM, ; "Revisao": cDate ,; "Preco": (cAlias)->B1_PRV1}) (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 method getSchema() as object class SB1TReportsBusinessObject local cComboFil as character cComboFil := "D MG 01=Filial BH; D MG 02=Filial Uberaba" self:addProperty("Filial", "Filial", "string", "Filial", "B1_FILIAL", cComboFil,.F.) self:addProperty("Codigo", "Codigo", "string", "Codigo", "B1_COD") self:addProperty("Descricao", "Descricao", "string", "Descricao","B1_DESC") self:addProperty("Tipo", "Tipo", "string", "Tipo","B1_TIPO") self:addProperty("Unidade", "Unidade de medida", "string", "Unidade","B1_UM") self:addProperty("Revisao", "Revisao", "date", "revisao","B1_UREV") self:addProperty("Data", "Data", "date", "Data","B1_UREV") self:addProperty("Preco", "Preço", "number", "Preço","B1_PRV1") return self:oSchema |
Bloco de código | ||||
---|---|---|---|---|
| ||||
#include "msobject.ch" #include "protheus.ch" #include "totvs.framework.treports.integratedprovider.th" namespace custom.materiais @totvsFrameworkTReportsIntegratedProvider(active=.T., team="SIGACOM", tables="SA5, SB1", name="Produto X Fornecedor", country="ALL", initialRelease="12.1.2210") //------------------------------------------------------------------- /*{Protheus. doc} MATR190TReportsBusinessObject 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 MATR190TReportsBusinessObject 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 MATR190TReportsBusinessObject _Super:new() self:appendArea("Compras") self:aFields := {"A5_FILIAL", "A5_FORNECE", "A5_LOJA", "A5_NOMEFOR", "A5_PRODUTO", "A5_NOMPROD", "A5_CODPRF", "B1_TIPO", "B1_PESO"} self:aStruct := 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 MATR190TReportsBusinessObject 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 MATR190TReportsBusinessObject 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 MATR190TReportsBusinessObject 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 oExec as object nCount := 0 cQuery := "SELECT A5_FILIAL,A5_PRODUTO,A5_NOMPROD,A5_FORNECE,A5_NOMEFOR,A5_LOJA,A5_CODPRF FROM " + RetSQLName("SA5 " + self:getSQLFields(,,,.T.) + " FROM" + RetSQLName("SA5") cQuery += " SA5 LEFT JOIN " + RetSQLName("SB1") + " SB1 ON SB1.B1_COD = SA5.A5_PRODUTO WHERE SB1.D_E_L_E_T_ = ' ' AND SA5.D_E_L_E_T_ = ' '" //Os filtros serão setados na interface do novo TReports if oFilter:hasFilter() cQuery += " AND " + oFilter:getSQLExpression() endif oExec := FwExecStatement():New(ChangeQuery(cQuery)) cAlias := MPSysOpenQueryoExec:OpenAlias(cQuery) if nPage > 1 //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:aFields) lObfuscated := len( aPDFields ) != Len(self:aFields) while !(cAlias)->(Eof()) jItems := JsonObject():new() for nX := 1 To Len(self:aStruct) if lObfuscated .and. aScan(aPDFields, self:aStruct[nX][5]) == 0 jItems[self:aStruct[nX][1]] := FwProtectedDataUtil():ValueAsteriskToAnonymize((cAlias)->&(self:aStruct[nX][5])) else jItems[self:aStruct[nX][1]] := (cAlias)->&(self:aStruct[nX][5]) 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 MATR190TReportsBusinessObject 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 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 */ //------------------------------------------------------------------- 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"}} 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, {cCampo, FWSX3Util():GetDescription(cCampo), cTipR, FWSX3Util():GetDescription(cCampo), cCampo}) next nC return (aCpoTmp) |
...
Bloco de código | ||||
---|---|---|---|---|
| ||||
#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.2310") 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 data lExistPergunte as logical endclass method new() as object class SRA2TReportsBusinessObject _Super:new() self:setDisplayName("Funcionários") self:lExistPergunte := self:setPergunte("GPER140") //Indica o pergunte que será utilizado no relatório GPER140 if !self:lExistPergunte if !self:setErrorStatus(400,"Sem Pergunte","Verifique o grupo de perguntas informado!") FwLogMsg("WARN",, "SmartView",,, , "Codigo de erro invalido, aceito somente codigos de erro 4xx", , ,) endif FwLogMsg("WARN",, "SmartView",,, , "Grupo de perguntas nao encontrado", , ,) endif return self method getDescription() as character class SRA2TReportsBusinessObject return "Funcionários" method getAreas() as array class SRA2TReportsBusinessObject return {"RH"} method getData(nPage as numeric, oFilter as object) as object class SRA2TReportsBusinessObject local cQuery as character local jParams as json local cWhere as character if !self:lExistPergunte //retorno do método SetPergunte() return self:oData else jParams := oFilter:getParameters() //metodo para retorno do json dos parâmetros cWhere := " D_E_L_E_T_ = ' '" //MV_PAR04 é multivalue if Len(jParams['MV_PAR04']) > 0 cWhere += " AND RA_MAT IN ('" + ArrTokStr(jParams['MV_PAR04'], "','") + "')" endif cQuery := "SELECT #QueryFields# FROM " + RetSQLName("SRA") + " WHERE #QueryWhere#" //Define a quantidade máxima por página (Default 100) self:setPageSize(500) //Define a query do Objeto de Negócio self:setQuery(cQuery) //Define o campo de ordenação da query self:setOrder("RA_MAT") //Define o where da query self:setWhere(cWhere) endif return self:oData method getSchema() as object class SRA2TReportsBusinessObject self:aliasToSchema("SRA" , {"RA_NOME", "RA_FILIAL", "RA_MAT", "RA_EMAIL", "RA_ADMISSA"}) return self:oSchema |
Bloco de código | ||||
---|---|---|---|---|
| ||||
#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.) 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 {"RH"} method getData(nPage as numeric, oFilter as object) as object class SRA2TReportsBusinessObject local cQuery as character local jParams as json local cWhere as character jParams := oFilter:getParameters() //metodo para retorno do json dos parâmetros cWhere := " D_E_L_E_T_ = ' '" cQuery := "SELECT #QueryFields# FROM " + RetSQLName("SRA") + " WHERE #QueryWhere#" //Define a quantidade máxima por página (Default 100) self:setPageSize(500) //Define a query do Objeto de Negócio self:setQuery(cQuery) //Define o campo de ordenação da query self:setOrder("RA_MAT") //Define o where da query self:setWhere(cWhere) return self:oData method getSchema() as object class SRA2TReportsBusinessObject self:aliasToSchema("SRA" , {"RA_NOME", "RA_FILIAL", "RA_MAT", "RA_EMAIL", "RA_ADMISSA"}) self:addParameter("logico","logico","boolean", .F.) //Adicionando o parâmetro manual return self:oSchema |
Bloco de código | ||||
---|---|---|---|---|
| ||||
#include "protheus.ch"
#include "msobject.ch"
#include "totvs.framework.treports.integratedprovider.th"
namespace custom.produtos.fornecedores
@totvsFrameworkTReportsIntegratedProvider(active=.T., team="SIGACOM", tables="SA5", name="Produto X Fornecedor", country="ALL", initialRelease="12.1.2310")
//-------------------------------------------------------------------
/*{Protheus.doc} ProdFornTReportsBusinessObject
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 ProdFornTReportsBusinessObject from totvs.framework.treports.integratedprovider.IntegratedProvider
public method new() as object
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 ProdFornTReportsBusinessObject
_Super:new()
self:appendArea("Compras")
self:setDisplayName("Fornecedores x Produtos")
self:setDescription("Relatório Fornecedores x Produtos com tratamento LGPD")
self:aFields := {"A5_FILIAL", "A5_FORNECE", "A5_LOJA", "A5_NOMEFOR", "A5_PRODUTO", "A5_NOMPROD", "A5_CODPRF", "A5_DTCOM01", "A5_QUANT01"}
self:aStruct := u_getStruct(self:aFields)
return self
//-------------------------------------------------------------------
/*{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 ProdFornTReportsBusinessObject
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 lUseParams as logical
nCount := 0
cQuery := "SELECT " + self:getSQLFields(,,,.T.) + "FROM " + RetSQLName("SA5") + " WHERE D_E_L_E_T_ = ' '"
lUseParams := .T.
//Os filtros serão setados na interface do novo TReports
if oFilter:hasFilter()
cQuery += " AND " + oFilter:getSQLExpression()
endif
jParams := oFilter:getParameters() //metodo para retorno do json dos parâmetros
u_setDefaultParams(@jParams)
//Faz a parametrização na query
cQuery += "AND A5_FORNECE BETWEEN ? AND ? AND A5_DTCOM01 >= ? AND A5_DTCOM01 <= ?"
oExec := FwExecStatement():New(ChangeQuery(cQuery))
oExec:setString(1, jParams['01'][1])
oExec:setString(2, jParams['02'][1])
//Formato da data recebida pelo smart view: 2020-07-02T00:00:00-03:00, temos que fazer a conversão para a query
oExec:setDate(3, StoD( SubStr(StrTran(jParams['03'][1],"-",""),1,8) ))
oExec:setDate(4, StoD( SubStr(StrTran(jParams['04'][1],"-",""),1,8) ))
cAlias := oExec:OpenAlias()
if nPage == 1
(cAlias)->(dbGoTop())
else
//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:aFields)
lObfuscated := len( aPDFields ) != Len(self:aFields)
while !(cAlias)->(Eof())
jItems := JsonObject():new()
for nX := 1 To Len(self:aStruct)
if lObfuscated .and. aScan(aPDFields, self:aStruct[nX][5]) == 0
if self:aStruct[nX][3] == "date"
jItems[self:aStruct[nX][1]] := nil
elseif self:aStruct[nX][3] == "number"
jItems[self:aStruct[nX][1]] := Val( Replicate( "9", Len((cAlias)->&(self:aStruct[nX][5])) ) )
else
jItems[self:aStruct[nX][1]] := FwProtectedDataUtil():ValueAsteriskToAnonymize((cAlias)->&(self:aStruct[nX][5]))
endif
elseif self:aStruct[nX][3] == "date"
jItems[self:aStruct[nX][1]] := totvs.framework.treports.date.stringToTimeStamp((cAlias)->&(self:aStruct[nX][5]))
else
jItems[self:aStruct[nX][1]] := (cAlias)->&(self:aStruct[nX][5])
//Monta os valores do campo Demanda
if self:aStruct[nX][1] == "A5_QUANT01"
if jItems[self:aStruct[nX][1]] <= 50
jItems["Demanda"] := "Demanda baixa"
elseif jItems[self:aStruct[nX][1]] <= 1000
jItems["Demanda"] := "Demanda média"
else //Maior que 1000
jItems["Demanda"] := "Demanda alta"
endif
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 ProdFornTReportsBusinessObject
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
self:addProperty("Demanda", "Demanda", "string", "Demanda do Produto", "Demanda")
self:addParameter("01" , "Fornecedor de", "string", .F.)
self:addParameter("02" , "Fornecedor até", "string", .F.)
self:addParameter("03" , "Data de", "date", .F.)
self:addParameter("04" , "Data até", "date", .F.)
//Consulta dos parâmetros
self:setCustomURL("01", "api/framework/v1/genericLookupService/smartview/SA2", 2)
self:setCustomURL("02", "api/framework/v1/genericLookupService/smartview/SA2", 2)
return self:oSchema
//-------------------------------------------------------------------
/*{Protheus.doc} getStruct
Prepara a estrutura dos campos
@param aFlds 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(aFlds)
Local aConvFld as array
Local aFldTmp as array
Local cCampo as character
Local cFldQry as character
Local cTipR as character
Local nPos as numeric
Local nC as numeric
aConvFld := {{"C", "string"}, {"D", "date"}, {"N", "number"}, {"L", "boolean"}, {"M", "memo"}}
aFldTmp := {}
for nC := 1 to Len(aFlds)
cFldQry := aFlds[nC]
nPos := AT(".", aFlds[nC]) + 1
if nPos > 0
cCampo := Substr(cFldQry, nPos)
else
cCampo := cFldQry
endif
cTipo := GetSx3Cache(cCampo, "X3_TIPO")
if (nPos := aScan(aConvFld, {|c| c[01] = cTipo})) > 0
cTipR := aConvFld[nPos, 02]
else
cTipR := "string"
endif
AAdd(aFldTmp, {cCampo, FWSX3Util():GetDescription(cCampo), cTipR, FwX3Titulo(Upper(cCampo)), cCampo})
next nC
return (aFldTmp)
//-------------------------------------------------------------------
/*{Protheus.doc} setDefaultParams
Seta os valores padrões do parâmetros caso estejam vazios
@param jParam json: Parâmetros recebidos
@author Vanessa Ruama
@since 02/03/2023
@version 1.0
*/
//-------------------------------------------------------------------
user function setDefaultParams(jParams)
if empty(jParams['02'][1])
jParams['02'][1] := "ZZZZZ"
elseif empty(jParams['03'][1])
jParams := totvs.framework.treports.date.dateToTimeStamp(Date())
elseif empty(jParams['04'][1])
jParams := totvs.framework.treports.date.dateToTimeStamp(Date())
endif
return |
Objeto de negócio localizado
...