W_UF = "PB" 
z_tela:=Janela(3,0,22,79," Cancelamento de NF Talao ") 
DbCloseAll() 

DbSelectArea(2)
dbUseArea( .F.,, (r_siga-"se_movnf"), "se_movnf", NIL, .F. )
if file(r_siga-"ntx\seim_f"-ordbagext())
   ordListClear(); ordListAdd( (r_siga-"ntx\seim_f") )
else
   dbCreateIndex( (r_siga-"ntx\seim_f"), "mfnum", _CreateBlock("mfnum"), NIL )
endif
Abra ("3",r_siga,"SE_PROD","SE_PROD","SEIP_C","PCOD") 
Abra ("4",r_siga,"SCCRCLI","SCCRCLI") 
Abra ("5",r_siga,"SF_TRN","SF_TRN") 
Abra ("6",r_siga,"SF_CODOP","SF_CODOP","SF_CODOP","CODOP") 
DbSelectArea(1)
dbUseArea( .F.,, (r_siga-"sf_fatnf"), "sf_fatnf", NIL, .F. )
if file(r_siga-"ntx\sf_fatnf"-ordbagext())
   ordListClear(); ordListAdd( (r_siga-"ntx\sf_fatnf") )
else
   dbCreateIndex( (r_siga-"ntx\sf_fatnf"), "fnum", _CreateBlock("fnum"), NIL )
endif      

   Set( 20, "SCREEN" ) 
   zCodFat=0 
   while .T. 
      DevPos( 5, 2 ) ; DevOut("Fatura..: " ) ; SetPos( Row(), Col()+1 ) ; AAdd( GetList, _GET_( zCodFat, "zCodFat", "999999",, ):display() ) 
      ReadModal(GetList) ; GetList := {} 
      if zCodFat<>0.and.!dbSeek( zCodFat ) 
         Mensagem("Nota Fiscal nao Encontrada...Reinforme Numero...",1) 
      else 
         exit 
      endif 
   enddo 
   if zCodFat=0 
      fechajan(@z_tela)
      DbCloseAll() 
      return 
   endif 
 
   dbSelectArea( "SCCRCLI" ) 
   dbGoto(sf_fatnf->FCLI) 
   dbSelectArea( "SF_CODOP" ) 
   dbSeek( sf_fatnf->FCODOP) 
   dbSelectArea( "SF_TRN" ) 
   if sf_fatnf->FTRANSP>0 
      dbGoto(sf_fatnf->FTRANSP) 
   else 
      dbGoto(1) 
   Endif 
   dbSelectArea( "sf_fatnf" ) 

   DevPos( 06, 2 ) ; DevOut( "Cliente.: " +str(sf_fatnf->fcli,6)+" "+Sccrcli->Cr_Nome )
   DevPos( 07, 2 ) ; DevOut( "Emissao.: " +Dtoc(sf_fatnf->fdataemi)+"    Valor...: " +Transform(sf_fatnf->fval,"@E 999,999.99") )

   DevPos( 08, 2 ) ; DevOut( repl("_",78) )
   DevPos( 09, 2 ) ; DevOut('Cod   Descricao                   Ref   Indx   Est      Prc  Quant      Valor')
   i = 0
   ii = 1
   k = 11

   dbSelectArea( "Se_MovNf" ) 
   dbSeek( zCodFat ) 
   while ! Eof() .AND. zCodFat=Mfnum 
         if i > 11
            scroll (10, 2, 20, 77, 1)
            if k % 11 = 0
               Mensagem( 'TECLE ESPACO PARA CONTINUAR ...' )
               inkey (0)
               Mensagem( '                               ' )
            endif
            k = k + 1
            i = 11
         endif
         if .not. se_movnf->(deleted()).and.mfges<>"X"
             se_prod->( DbSeek(se_movnf->pcod) )
             DevPos( i+9,1 ) ; DevOut( str(pcod,5) )
             DevPos( i+9,7 ) ; DevOut( SE_PROD->PDESC )
             DevPos( i+9,63) ; DevOut( str(mquant,5) )
             DevPos( i+9,69) ; DevOut( Transform(mvalor,"999,999.99") )
             i = i + 1
             ii = ii + 1
         endif
         dbSkip(1) 
   ENDDO
   if .not. Simnao (24, 0, 'Confirma Cancelamento da Nota Fiscal ? ', ' Sim ', ' Nao ', 2, 80)
      fechajan(@z_tela)
      DbCloseAll() 
      return 
   endif 
   dbSelectArea( "Se_MovNf" ) 
   dbSeek( zCodFat ) 
   while ! Eof() .AND. zCodFat=Mfnum 
         if mfges="S".and.se_prod->( DbSeek(se_movnf->pcod) ).and..f.
            se_prod->(reglock())
            se_prod->(put_var("peatual",se_prod->peatual-se_movnf->mquant))
         endif
         se_movnf->(reglock())
         se_movnf->(Put_Var("mfges","X"))
         dbSkip(1) 
   ENDDO
   sf_fatnf->(reglock())   
   sf_fatnf->(DbDelete())
   DbCloseAll() 
   Set( 20, "SCREEN" ) 
   Mensagem("Nota Fiscal Cancelada...",1) 

Fechajan(z_tela)
RETU
