ALIAS CR_RECFX
VARIAVEL zFgRecalcula := (xGetEnv("RECALCULA_ADITIVOS_DE_LOCACAO")="S")
VARIAVEL #TEXTO_FONTE
   Private zCodCli, zCodVnd, zCodPrep, z_rot:=0, zQtdCli:=0, z_totrec:=0, zoProgressBar, zCmdsDurante, zCmdsDepois, zVndNome, zPrepNome, zfnum, ztValLoca, zRecalc, zValOrig
  
   oLst:cAlias_DataCols := '_recfx'
   oLst:cAliasMaster := '_recfx'
   oLst:lPortrait := .t.
   
   oLst:lGeraDbTmp := .f.
   oLst:lOutputFr3 := .f.
   oLst:lOutputPdf := .t.
   
   // oLst:lOutputFr3 := .t.

   oLst:AddCab( {"AplicaFormatacaoDefaultNoCabecalho"=>"nao", "style"=>"font:Helvetica-Bold#size:14", "COLS"=>"0,C"}, "RECEITAS RECORRENTES em "+Dtoc(s_datual)+" as "+time() )
  
   oLst:AddCab( '_LINHA_FINA_' )
   oLst:AddCab( '_CABCOLS_' )
   oLst:AddCab( '_LINHA_GROSSA_' )

   // oLst:AddCol('St;sccrcli->cr_situaca;P;X;2;;')
   oLst:AddCol('Cli;Cr_Cod_Cli;N;999999;6;;')
   oLst:AddCol('Raz.Social;sccrcli->Cr_Nome;P;@s35;35;;') 
   oLst:AddCol('Fantasia;sccrcli->Cr_fantasi;P;@s20;20;;') 
   oLst:AddCol('CNPJ;FormataCnpjCpf(sccrcli->CR_CGC);P;@s18;18;;') 

   oLst:AddCol('Valor;cr_valor;N;@e 9999,999.99;11;;;Direita;Some;')
   //oLst:AddCol('Dt_Inicial;Cr_dataini;D;99.99.9999;10;;')
   oLst:AddCol('Dia;Day(Cr_dataini);P;999;3;;')
   oLst:AddCol('Adit;lTrim(Str(fObraNoCli,2))+"."+lTrim(str(fAditivo,2))+".0";P;@s7;7;;;Direita;NaoSome;')
   oLst:AddCol('Controle;fNum;N;99999999;8;;;Direita;NaoSome;')
   if zFgRecalcula
      oLst:AddCol('Rec;zRecalc;P;!;3;;')
      oLst:AddCol('ValorORig;zValOrig;P;({|x|if(Abs(x-cr_valor)>0.01,Transform(x,"@E 999,999.99"),"          ")});11;;;Direita;NaoSome;')
   endif
   BLOCO_TXT zCmdsDurante
      (zCodCli:=Cr_Cod_Cli , zCodVnd:=Val(cr_zona), zCodPrep:=Preposto, z_totrec+=cr_valor, ++zQtdCli)
      sccrcli->(DbGoto(zCodCli))
      zRecalc:="N"
      if zFgRecalcula
         zValOrig := CR_RECFX->Cr_Valor
         ztValLoca := 0
         zfnum := CR_RECFX->fNum
         DbSelectArea("se_movnf")
         if se_movnf->( DbSeek(zfnum) )
            Do While .Not. Eof() .And. zfnum=mfnum
               if zCodCli=mCodForC .and. mQuant>mQdevol
                  ztValLoca := ztValLoca + (mQuant-mQdevol)*pValLoca
               endif
               DbSkip()
            EndDo
         else
            alert("Nao achou nota "+str(zfnum))
         endif
         DbSelectArea("CR_RECFX")
         if cr_valor+0.009<ztValLoca
            zRecalc:="S"
            RegLock()
            Put_Var("cr_valor", ztValLoca)         
         endif
         if cr_valor>0.and.ztValLoca=0 
            zRecalc:="S"
            RegLock()
            Put_Var("cr_valor", ztValLoca)
            DbSelectArea("sf_fatnf")
            if sf_fatnf->( DbSeek(zfnum) )
               Do While .Not. Eof() .And. zfnum=pfnum
                  SccrDup->(DBSEEK(STRZERO(sf_FatNf->fNumPed,6)), if(day(cr_dt_lqd)=0, (RegLock(),_field->cr_dt_lqd:=cr_dt_venc,DbDelete()), ) )
                  DbSkip()
               EndDo
               // else
               // alert("Nao achou em sf_FatNf nota "+str(zfnum))
            endif
            DbSelectArea("CR_RECFX")
         endif
         
      endif
   FIM_BLOCO_TXT

   // debugalert('2')

   cr_recfx->(if(zFgRecalcula,DbClearFilter(),), DbGoTop(), oLst:DbEval(zCmdsDurante, {||zFgRecalcula .or. cr_valor>0} ) , if(zFgRecalcula,DbCommit(),) )

   // debugalert('3')

   oLst:lFecharGruposAbertos := .t.
   oLst:SetFormatSomaCol(2, {||"** Receitas Cadastradas:"+Str(zQtdCli,4)}, .t.)
   oLst:EvalLineBlocks('DETALHE', '_LINHA_GROSSA_')
   oLst:EvalLineBlocks('DETALHE', {"style"=>"font:Courier-BoldOblique"}, '_SOMACOLS_GLOBAL_' )

   debugalert('finalizou cr_recfx...')
 
#FIM_TEXTO_FONTE