Imprimi Pgina | Fechar janela

Soma Variável de Valor

Impresso de: Helpfacil - Portal do conhecimento
Nome do Forum: ADVPL
Descrio do Forum: Dvidas sobre a programao em ADVPL
URL:http://www.helpfacil.com.br/display_topic_threads.asp?ForumID=1&TopicID=43721
Data da Impresso: sbado, 23 de outubro de 2021 at 20:16


Topico: Soma Variável de Valor

Postado por: ADVPL_OS
Assunto: Soma Variável de Valor
Data Postagem: quarta-feira, 21 de julho de 2021 at 07:13

Galera, bom dia

Estou com um cdigo para gerar o TXT de Vale Transporte pra Ticket e no meu cdigo o bloco de repetio no aglutina o valor da varivel que recebe o valor total do benefcio de cada registro. No Debug eu vejo que ele recebe o valor, mas no final do cdigo ele no grava no TXT o valor total ele apenas grava o valor total do benefcio do primeiro resultado encontrado na Query.


Algum teria uma ideia de como fazer essa varivel somar o valor de todos os registros da tabela ?

Segue cdigo trexos do cdigo que apresenta a varivel nTVlBilh.:

#include "topconn.ch"
#include "tbiconn.ch"
#include "RWMAKE.ch"

#DEFINE CRLF Chr(13)+Chr(10)

/*
oooooooooooooooooooooooooooooooooooooo
*/

User Function GERAVTSM()


Local aSays:={}, aButtons:= {},aRegs := {} //<== arrays locais de preferencia

//Iniciar Variaveis
cCadastro     := OemToAnsi("Geracao Arquivo de Pedido de Vale Transporte - TICKET")
cPerg          := "GERAVTRAN"
cNome          := ‘‘
cSexo           := ‘‘
cData_Aniv      := ‘‘
cEmail          := ‘‘
cArquivo        := ‘‘
cEmissao        := ‘‘
cDDD            := ‘‘
cTelefone      := ‘‘
cNomeArq     := ‘‘
cLin          := ‘‘
cCab1           := ‘‘
cCab2           := ‘‘
cCab3           := ‘‘
cFilEnt_     := ‘‘
cArq          := ‘‘
//cArqInd          := ‘‘
nReg         := 1           
//nQtdEmp      := 0
//nQtdEnd      := 0
//nQtdFun      := 0                               
//nQtdBnf      := 0
//nQtdVtr      := 0
nOpca         := 0
nHdl          := 0
nAviso          := 0
nPos          := 0
nTipEnt_     := 0
lContinua     := .T.
lEnd          := .T.
aInfoE          := {}
//aSet          := {}

fChkPerg()
Pergunte(cPerg,.F.)

AADD(aSays,OemToAnsi("Este programa gera arquivo VT - TICKET ") )

AADD(aButtons, { 1,.T.,{|o| nOpca := 1,Iif(GpconfOK(),FechaBatch(),nOpca:=0) }} )
AADD(aButtons, { 2,.T.,{|o| FechaBatch() }} )
AADD(aButtons, { 5,.T.,{|| Pergunte(cPerg,.T. ) } } )

FormBatch( cCadastro, aSays, aButtons )

If nOpca == 1
     Processa({|lEnd| fTKTProc(),"Gerando Arquivo"})
Endif

If nHdl > 0
     If fClose(nHdl)
          If lContinua
               Aviso(‘AVISO‘,‘Gerado o arquivo ‘ + AllTrim(cNomeArq) + ‘...‘,{‘OK‘})     
          Else
               If fErase(cNomeArq) == 0
                    If lContinua
                         Aviso(‘AVISO‘,‘No existem registros a serem gravados. A gerao do arquivo ‘ + AllTrim(cNomeArq) + ‘ foi abortada ...‘,{‘OK‘})
                    EndIf     
               Else

                    MsgAlert(‘Ocorreram problemas na tentativa de deletar do arquivo ‘+AllTrim(cNomeArq)+‘.‘)

               EndIf     
          EndIf     
     Else

          MsgAlert(‘Ocorreram problemas no fechamento do arquivo ‘+AllTrim(cNomeArq)+‘.‘)

     EndIf
     
EndIf

//Fechamento das Tabelas Temporarias
If Select("R0NW") > 0
   DbSelectArea("R0NW")
   DbCloseArea("R0NW")
EndIf

If File(cArq + ".DBF")
     //Seleciona Area
     dbSelectArea(‘TMPT‘)
     dbCloseArea(‘TMPT‘)
     
     Ferase(cArq + ".DBF")
//     Ferase (cArqInd+OrdBagExt())
Endif

Return




Static Function fTKTProc()

Local cFilial_Ant := ""
Local cCCusto_Ant := ""

//Variaveis das Perguntas
Pergunte(cPerg,.F.)

//Carrega as Variaveis das Perguntas
cFilDe               := mv_par01     //Filial De
cFilAte               := mv_par02     //Filial Ate
cCcDe               := mv_par03     //Centro de Custo De
cCcAte               := mv_par04     //Centro de Custo Ate
cNome               := mv_par05     //Usurio do Sistema
cNomeArq          := mv_par06     //Nome do Arquivo
dAdmDe          := mv_par07 // Data de admissao inicial
dAdmAte        := mv_par08 // Data de admissao final
cMatrDe        := mv_par09 // Da matricula
cMatrAte        := mv_par10 // Ate a matricula
cUsoDe          := dtos(mv_par11) // Periodo de Uso De
cUsoAte        := dtos(mv_par12) // Periodo de Uso Ate    
dDtEntMax       := dtos(mv_par13) // Data Maxima de Entrega

nHdl := fCreate(cNomeArq)

If nHdl == -1
     MsgAlert(‘O arquivo ‘+AllTrim(cNomeArq)+‘ no pode ser criado! Verifique os parametros.‘,‘Ateno!‘)
     Return
Endif

SRA->(dbSetOrder(1))
       
If Select("R0NW") > 0
   DbSelectArea("R0NW")
   DbCloseArea("R0NW")
EndIf     

//IF MV_PAR15 = 1

cQuery := ""
cQuery += " SELECT RA_FILIAL,RA_CC,RA_MAT,RA_NOME,RA_NASC,RA_CEP,RA_ESTCIVI,RA_CIC,RA_RG,RA_MAE,RA_ADMISSA,RA_ENDEREC, " + Chr(13)
cQuery += " RA_COMPLEM, RA_MUNICIP, RA_ESTADO, RA_RGUF, RA_SEXO, RA_BAIRRO,RN__FRETAD ,RA_LOGRTP,RA_RNE,RJ_DESC,R0_MEIO,R0_QDIAINF," + Chr(13)
cQuery += " RN_ITEMPED,RN_DESC,RN_CODPLAN,RN_VUNIATU,CTT_CUSTO,CTT_DESC01,CTT_ENTREG,R0_DIASPRO,R0_VALCAL,CTT_ENTREG " + Chr(13)
cQuery += " FROM SRA200,SRJ200,SRN200,CTT200,SR0200 " + Chr(13)
cQuery += " Where RA_CODFUNC = RJ_FUNCAO and RA_SITFOLH <> ‘D‘" + Chr(13)
cQuery += " and RA_FILIAL = ‘0202‘" + Chr(13)
cQuery += " and RJ_FILIAL = ‘0202‘" + Chr(13)
cQuery += " and RN_FILIAL = ‘0202‘" + Chr(13)
cQuery += " and R0_FILIAL = ‘0202‘" + Chr(13)
cQuery += " and CTT_FILIAL = ‘0202‘" + Chr(13)
cQuery += " and RA_CC BETWEEN ‘"+cCcDe+"‘ and ‘"+cCcAte+"‘ " + Chr(13)
cQuery += " and RA_MAT = R0_MAT" + Chr(13)
cQuery += " and R0_QDIACAL > 0 " + Chr(13)
cQuery += " and R0_VALCAL > 0 " + Chr(13)
cQuery += " and RN_COD = R0_CODIGO " + Chr(13)
cQuery += " and RA_CC = CTT_CUSTO and RN__FRETAD <> ‘S‘ "   + Chr(13)
cQuery += " and R0_ANOMES = ‘"+MV_PAR14+"‘ " + Chr(13)
cQuery += " and RA_ADMISSA BETWEEN ‘"+dtos(dAdmDe)+"‘ and ‘"+dtos(dAdmAte)+"‘ "
cQuery += " and RA_MAT BETWEEN ‘"+cMatrDe+"‘ and ‘"+cMatrAte+"‘ "
cQuery += " and "+RETSQLNAME("SRA")+".D_E_L_E_T_ = ‘‘"
cQuery += " and "+RETSQLNAME("SRJ")+".D_E_L_E_T_ = ‘‘"                                
cQuery += " and "+RETSQLNAME("SRN")+".D_E_L_E_T_ = ‘‘"
cQuery += " and "+RETSQLNAME("CTT")+".D_E_L_E_T_ = ‘‘"
cQuery += " and "+RETSQLNAME("SR0")+".D_E_L_E_T_ = ‘‘"
cQuery += " ORDER BY RA_FILIAL,RA_CC,RA_MAT "
MemoWrite("QRY_VT",cQuery)

TcQuery cQuery New Alias "R0NW"
R0NW->(DbGotop())

//ENDIF

ProcRegua(SR0->(RecCount()))

//Seleciona Entrega
aInfoE := fEmpInfo(R0NW->RA_FILIAL)

R0NW->(DbGotop())

//Cria DBF Temporario
fCriaDBF()

//Variaveis de Trabalho
dDtEntMin:= DdataBase    
nDUtil := 0
nNrDias := 7
dDtIni := dDataBase
dDtMov := dDtIni
While nDUtil <= nNrDias
     If DataValida(dDtMov) = dDtMov
        nDUtil++
     Endif
dDtMov := dDtMov + 1
EndDo

dDtEntMax:= dDtEntMax

cRespons := cNome
cCgcFat      := "02.566.106/0001-82"    
cCgc     := "02566106000182"
cEmissao := Dtos(ddatabase)
cHora      := time()
cDDD      := "021"
cTelefone:= "0000000"
cPedido := "K." + substr(cEmissao,7,2) + "/" + substr(cEmissao,5,2) + "/" + substr(cEmissao,3,2)
nVlKit      := 0
nVlPtoEn := 20


// Variaveis de somatorio
nTUnid      := 0
nTDepto      := 0
nTFunc      := 0
nTItens     := 0
nSeqItem     := 0
nTReg       := 0

nTHead      := 0
nTTrai      := 0
nTVlBilh    := 0   //Recebe o Valor total do benefcio.
nTVlServ    := 0


//s""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""¿
// Chamada Header de arquivo                                                                                                                    ³
//?""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""T
fHeadLSUP()
nTHead      +=1                                                        

ProcRegua(SR0->(RecCount()))

While R0NW->(!Eof())           
        
     // Quebra de Filiais CNPJs Diferentes
     If cFilial_Ant <> R0NW->RA_FILIAL
               
          // Fecha trailler de quebra
          If !empty(cFilial_Ant )

               //s""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""¿
               // Chamada TT    - Trailler de Pedido TT                                                                                                         ³
               //?""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""T
               fTraiTT(aInfoE)
               nTTrai      += 1
          Endif

          // Atualizacao da Quebra
             cFilial_Ant := R0NW->RA_FILIAL
             nTUnid           += 1
     
          
          //cCgc          := substr(aInfoE[9],1,2)+"."+substr(aInfoE[9],3,3)+"."+substr(aInfoE[9],6,3)+"/"+substr(aInfoE[9],9,4)+"-"+substr(aInfoE[9],13,2)     //transform(aInfoE[9],"99.999.999/999-99")

          //s""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""¿
          //³ Chamada TT    - Header de Pedido TT                          ³
          //?""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""T
          fHeadTT(aInfoE)
          nTHead += 1                                                        

          //s""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""¿
          //³ Chamada TTPE - Registro de Pedido                            ³
          //?""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""T     
          fGeraTTPE(aInfoE)
          nTReg += 1
             
          //s""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""¿
          //³ Chamada TTUN - Registro Unidade de Entrega                  ³
          //?""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""T
          fGeraTTUN(aInfoE)
          nTReg += 1

     Endif
     
     // Quebra de Departamento
     If cCCusto_Ant <> R0NW->RA_CC

          // Atualizacao da Quebra
             cCCusto_Ant := R0NW->RA_CC
             nTDepto      +=1

          //s""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""¿
          //³ Chamada TTDE - Registro de Departamento                     ³
          //?""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""T
          fGeraTTDE(aInfoE)
          nTReg += 1

     Endif

     //s""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""¿
     //³ Chamada TTFU - Registro de Funcionario                      ³
     //?""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""T
     fGeraTTFU(aInfoE)
     nTReg += 1
     nSeqItem := 0

     // Atualizacao da Quebra
        cMat_Ant    := R0NW->RA_MAT
        ntFunc           += 1
        
    While R0NW->(!Eof()) .AND. cMat_Ant = R0NW->RA_MAT
        //While R0NW->(!Eof()) .AND. cFilial_Ant = R0NW->RA_FILIAL .AND. cMat_Ant = R0NW->RA_MAT

          nSeqItem    += 1
          nTItens      += 1
          nTVlBilh    += R0NW->RN_VUNIATU
          nTVlServ     += ( (R0NW->R0_DIASPRO * nTVlBilh) + (nTUnid * nVlPtoEn) )//calculo abaixo ZB_DIASREF
     
          //s""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""¿
          //³ nTVlServ =[(Preco do Kit * Valor dos Bilhetes do Pedido)+               ³
          //³              (Qt de Unidades de Entrega Pagas * Preco p/Ponto de Entrega)] ³
          //?""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""T

          //s""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""¿
          //³ Chamada TTIT - Registro de Itens de Conducao do Funcionario ³
          //?""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""T
          fGeraTTIT(aInfoE)
          nTReg += 1
                 
          R0NW->(DbSkip())
          
          IncProc(‘Gerando o Arquivo... ‘)

        EndDo
     
EndDo   

// Fecha trailler de quebra
If !empty(cFilial_Ant )

     //s""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""¿
     //³ Chamada TT    - Trailler de Pedido TT                        ³
     //?""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""T
     fTraiTT(aInfoE)
     nTTrai      += 1

Endif

//s""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""¿
//³ Chamada Trailler de arquivo                                  ³
//?""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""T
nTTrai      += 1
fTraiLSUP()

//Grava Arquivo Texto

dbSelectArea("TMPT")
TMPT->(dbGoTop())

While TMPT->(!Eof()) .And. lContinua

     cLin     := substr(TMPT->TEXTO,1,len(alltrim(TMPT->TEXTO))-1) + CRLF

     fGravaReg(cLin)
     TMPT->(dbSkip())

Enddo

Return

//s""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""¿
//³ LSUP - Header de Arquivo                                    ³
//?""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""T
Static Function fHeadLSUP()

cLin      := "LSUP5"               
cLin      += substr(cnome,1,8)     
cLin      += SPACE(11)          
cLin      += cEmissao                
cLin      += cHora     
cLin      += "LAYOUT-26/07/2013"     
cLin      += SPACE(107)               
cLin      += "."                         

//Grava Arquivo Temporario

If RecLock("TMPT",.T.)
     TMPT->TEXTO          := cLin
     MSunLock()
Endif

Return                                                    

//s""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""¿
//³ TT    - Header de Pedido TT                                  ³
//?""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""T
Static Function fHeadTT(aInfoE)

cLin     := "T"+SPACE(03)     
cLin      += "A"               
cLin     += cEmissao          
cLin     += "V4.0"          
cLin      += SPACE(060)          
cLin      += "."          

//Grava Arquivo Temporario
If RecLock("TMPT",.T.)
     TMPT->TEXTO          := cLin
     MSunLock()
Endif

//Atualiza Sequencia
//nQtdEmp += 1

Return

//s""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""¿
//³ TTPE - Registro de Pedido TT                                 ³
//?""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""T
Static Function fGeraTTPE(aInfoE)

cLin     := "TTPE"                                             
cLin     += Transform(cCgc,"@R 99.999.999/9999-99")
cLin     += cPedido                                                
cLin     += strzero(nTUnid,4)                              
cLin     += strzero(nTDepto,4)                              
cLin     += strzero(nTFunc,5)                                 
cLin     += strzero(nTItens,6)                              
cLin     += strzero(nTVlServ,16,2)                         
cLin     += strzero(R0NW->R0_VALCAL,16,2) // nTVlBilh bloco do TXT que deveria apresentar o valor total de todos os registros somando o valor do campo R0_VALCAL     
cLin     += cEmissao                                            
cLin      += SPACE(001)                                        
cLin      += cUsoDe                                             
cLin      += cUsoAte                                             
cLin     += strzero(nVlKit,12,2)                               
cLin     += strzero(nVlPtoEn,12,2 )                         
cLin     += "N"                                                  
cLin     += strzero(nTUnid,4)                              
cLin     += "A"                                                  
cLin     += "P"                                                  
cLin     += "%"+SPACE(02)                                   
cLin     += "R$"+SPACE(01)                                   
cLin      += "."                                                  
   
//Grava Arquivo Temporario
If RecLock("TMPT",.T.)
     TMPT->TEXTO          := cLin
     MSunLock()
Endif

Return//Recebe o Valor total do benefcio.// nTVlBilh bloco do TXT que deveria apresentar o valor total de todos os registros somando o valor do campo R0_VALCAL


Respostas:

Postado Por: EMERSON.EN
Data Postagem: quarta-feira, 21 de julho de 2021 at 13:00

voc fez esta afirmao no cdigo:
// nTVlBilh bloco do TXT que deveria apresentar o valor total de todos os registros somando o valor do campo R0_VALCAL

porm a varivel no acumula o valor de R0_VALCAL:
nTVlBilh    += R0NW->RN_VUNIATU
Como mostrado acima, acumulado o valor de RN_VUNIATU







Imprimir Pgina | Fechar Janela