ALIAS HELP
VARIAVEL sFgDebugAlert:=.t.
variavel zaLinhasDaTela := {}
VARIAVEL LST_TP = 60
VARIAVEL znil = SetDebugInfo( .t. )
VARIAVEL z_de = ctod( "01."+SubStr(Dtoc(S_Datual),4) )
VARIAVEL z_ate = s_datual
VARIAVEL zSaldoInicial = 0
VARIAVEL zComplemento = ""
VARIAVEL zAux = ""
variavel oQbe=""
VARIAVEL zoProgressBar    := ''
VARIAVEL zCmdsDurante     := ''
VARIAVEL zSaldoAcum := 0
VARIAVEL ztSupDia:=0
VARIAVEL ztRetDia:=0
VARIAVEL zbDivDesc:=""
VARIAVEL #TEXTO_FONTE
   Private zSxConta, zCodDiv,zctde,zctpara,zDesc,zAux,nvCred,nvDeb,ztCred:=0,ztDeb:=0

   DbCloseAll()
   Abra('0NOIDX',r_siga,'cp_subd', 'cp_subd', 'cp_subd', 'cp_subdiv')
   Abra('0NOIDX',r_siga,'sx_conta','sx_conta')
   Abra('0NOIDX',r_siga,'cp_divis','cp_divis','cp_divis','cp_divisao')
   Abra('0NOIDX',r_siga,'sx_caixa','sx_caixa')

   oQbe:=oQbe():New('tesou01')

   oQbe:AddFiltro(" 9;3;Divisao de Despesas :", {||cp_divisao} ,, 'cp_divis;qbe_pcpdivis', {'Todas','Algumas'})

   oQbe:AddFiltro("10;3;Grupo de Lancamentos:", {||grupo} )
   oQbe:AddFiltro("11;3;Fornecedor / Cliente:", {||cp_cod_for} )
   oQbe:AddFiltro("12;3;Tipo Lancto    (S/R):", {||tipo} )

   aAdd( zaLinhasDaTela, {"3;3;Data inicial:", "@z_De",  @z_De,  "99.99.9999", "", "" } )
   aAdd( zaLinhasDaTela, {"4;3;Data final..:", "@z_Ate", @z_Ate, "99.99.9999", "", "z_Ate>=z_De"} ) 
  
   if .not. oQbe:QuickDialog("Qbe_tesou01", "70;13;Emissao do Livro Caixa", zaLinhasDaTela)
      DbCloseAll()
      Return
   endif
   
   oLst:nFontSize := 10
   oLst:lPortrait := .f.
   oLst:nLinesPorPagina := 40
   // oLst:lPortrait := .t.
   // oLst:nLinesPorPagina := 99

   oLst:cAlias_DataCols := 'tesou'
   oLst:cAliasMaster := 'tesou'

   oLst:Cab1( "DESPESAS POR CENTRO DE CUSTO" )
   oLst:AddCab( {"style"=>"font:Helvetica-Oblique#size:12", "COLS"=>"0,C"}, {|| "Periodo: "+Dtoc(z_de)+" a "+Dtoc(z_ate)+", emitido em "+Dtoc(s_datual)+" as "+Time() } )

   oLst:AddCab( '_LINHA_FINA_' )
   oLst:AddCab( '_CABCOLS_' )
   oLst:AddCab( '_LINHA_GROSSA_' )

   oLst:AddCol('Data;data;D;99.99.9999;10;;')
   oLst:AddCol('Descricao;zDesc;P;@S35;35;;')
   oLst:AddCol('Deb/Cred;transform(Valor,"@E 99,999.99")+if(tipo="S","+","-");P;@S10;10;;;Direita;;')
   oLst:AddCol('Cxa;zCtDe;P;@E 9999;4;;')
   oLst:AddCol('c/f;zCtPara;P;@E 999999;6;;')
   oLst:AddCol('g;Grupo;N;99;2;;;Direita;Some;')
   oLst:AddCol('CCust;left(cp_subdiv,3)+if(Val(Right(cp_subdiv,2))>0,Right(cp_subdiv,2),"");P;99999;5;;')
   oLst:AddCol('Obs;zComplemento;P;@S45;45;;')

   oLst:AddRodape( '_LINHA_FINA_', "", {|| "Pagina "+Str(++pag,4)+" / ####"} )

   oLst:AddGroup( { "KEY"=>{||left(cp_subdiv,3)} } )
   
   oLst:AddGroup( { "HEADER"=>{ {"style"=>"font:Helvetica-Oblique#size:12"}, {||zCodDiv:=VAL(LEFT(CP_SUBDIV,3)), LEFT(CP_SUBDIV,3)+"-"+cp_divis->(DbSeek(zCodDiv), Left(Desc,1)+Lower(SubStr(desc,2)) )}} })
   oLst:AddGroup( { "FOOTER"=>{ '_LINHA_FINA_', '', {|| zCodDiv:=oLst:GroupKeyOld, zAux:="..... Subtotal C.Custo "+zCodDiv+" : "+ lTrim(Transform(abs(ztRetDia),"@E 999,999,999.99")), ztRetDia:=0, zAux} } } )
   oLst:AddGroup( { "FOOTER"=>{ '_PULE_1LINHA_' } } )
   oLst:AddGroup( { "SOMAS"=> {||nvCred:=if(tipo="S",valor,0), nvDeb:=if(tipo="S",0,valor), ztSupDia+=nvCred, ztRetDia+=nvDeb, ztCred+=nvCred, ztDeb+=nvDeb, zSaldoAcum+=nvCred-nvDeb } } )

   zSaldoInicial := 0
   zSaldoAcum := zSaldoInicial

   BLOCO_TXT zCmdsDurante
      zoProgressBar:Step()
      zDesc:=LEFT(desc,1)+lower(Substr(desc,2))
      zctde:=if(tipo="S",cp_cod_for,Sx_Conta)
      zctpara:=if(tipo="S",Sx_Conta,cp_cod_for)
      // zCodDiv:=VAL(LEFT(CP_SUBDIV,3))
      // zComplemento := cp_divis->( DbSeek(zCodDiv), Left(Desc,1)+Lower(SubStr(desc,2)) )
      zCodDiv:=CP_SUBDIV
      // zComplemento := if( VAL(SubStr(CP_SUBDIV,4))>0, CP_SUBD->( DbSeek(zCodDiv), Left(Desc,1)+Lower(SubStr(desc,2)) ), "")
      zComplemento := if( VAL(SubStr(CP_SUBDIV,4))>0, CP_SUBD->( DbSeek(zCodDiv), TokenUpper(desc,,1)), "")
   FIM_BLOCO_TXT
 
   sx_caixa->( DbGoTop(), xDbCopyTo('mem:_cxa', '_cxa', {||tipo="R".and.val(left(Cp_SubDiv,3))>0 .and. Data>=z_de .and. DATA<=z_ate .and. oQbe:Filtro_ok()}) )
   ABRA('0NOIDX','','mem:_cxa',  '_cxa', 'mem:_cxa', 'left(Cp_SubDiv,3)+dtos(data)')

   zoProgressBar := myhProgressBar():Create('Processando Lancamentos...')
   _cxa->( DbGoTop(), oLst:DbEval(zCmdsDurante) )
   zoProgressBar:Close()

   DbCloseAll()
   Abra('0NOIDX',r_siga,'help','help')
   DbGoBottom()
#FIM_TEXTO_FONTE