ALIAS SI_CAIXA
VARIAVEL Z_NUMCXA := if(s_cx_numfech>0, s_cx_numfech, RECC())
VARIAVEL z_concilia := If(type("z_concilia")<>"U",z_concilia,"N")
VARIAVEL wOpcao := 'rolo'
VARIAVEL #TEXTO_FONTE
   Private zTitulo:='',zFormaPg,zFundoCx,zVenda,zQuitacoes,zSangrias,zTotCalc,zTotInf,zRecalc,zReinform,zvPagCaixa,nRow,m_fobs,zhReg,zbPrint,zCalcES,zCalcCH,zCalcCT,zCalcCV,zCalcCA,zFgRoloPDF:=.t.,zFgRoloA4PDF:=.f.,znI:=0,znFpVendas:=0,znFpRecebs:=0,znFpSang:=0
   
   DbGoBottom()
   do while s_cx_numfech=0.and..not.bof().and.dataopen=s_datual.and.s_vb_totcx>1.and.si_caixa<>S_VB_NCAIX
      DbSkip(-1)
      Z_NUMCXA := RECNO()
   enddo
   
   Set(20,"SCREEN")
   if .not. QuickDialog("cxa_prt", "50;6;Fechamento de Caixa", { ;
                  {"2;3;Numero do Movimento do Caixa:", "@Z_NUMCXA", @Z_NUMCXA, "999999", "", ""} ,;
                  {"4;3;CHECKBOX 'Gerar Saida para Impressora de Rolo'", "@zFgRoloPDF", @zFgRoloPDF, "!", "", "" } ,;
                  {"5;3;CHECKBOX 'Gerar Resumo Simplificado em PDF'", "@zFgRoloA4PDF", @zFgRoloA4PDF, "!", "", "" } })
      Return
   endif
   Set(20,"PRINTER")
 
   DbSelectArea('si_caixa')
   oLst:lOutputPdf := .t. 
   si_caixa->( DbGoto(Z_NUMCXA) )
   zTitulo := "Posicao de Fechamento de Caixa Numero "+lTrim(Str(z_numcxa,6))+ "  (Loja:"+lTrim(Str(if(fLoja=0,1,fLoja),3))+" Cxa:"+lTrim(Str(si_caixa,3)+')')
   z_concilia := If(day(dataconf)>0.and.VcnDINH+VcnCHEQ+VcnCART+VcnCONV+vcnCARN>0,"S",z_concilia)
   zvPagCaixa := if(VcpDINH+VcpCHEQ+VcpCART+VcpCONV+VcpCARN<>0,0,vpag_caixa)
   
   debugalert('zFgRoloPDF='+hb_valtoexp(zFgRoloPDF))
   if zFgRoloPDF

      dbCreate('mem:_cx_fp',   {{"GRUPO","C",50,0},{"FORMAPG","C",30,0},{"VALOR","N",12,2}})
      dbCreate('mem:_cx_inf',  {{"FORMAPG","C",30,0},{"VALOR","N",12,2},{"VALOR_INF","N",12,2}})
      dbCreate('mem:_cx_ocor', {{"DESC","C",50,0},{"VALOR","N",12,2},{"QUANT","N",6,0}})
      use ("mem:_cx_fp") new exclusive
      use ("mem:_cx_inf") new exclusive
      use ("mem:_cx_ocor") new exclusive
      DbSelectArea('si_caixa')

      zbPrint:={|cGrupo,cFormaPg,nValor|zhReg:={=>}, zhReg['GRUPO']:=cGrupo,zhReg['FORMAPG']:=cFormaPg,zhReg['VALOR']:=nValor, if((.not."** Sem ocorrencias **"$cFormaPg.and.nValor<>0).or.("** Sem ocorrencias **"$cFormaPg.and.nValor=0),(++znI,oLst:PutRsFR3('_cx_fp',@zhReg)),) }

      eVal(zbPrint, "* FUNDO DE CAIXA *", "em Dinheiro:" , fdinh)
      eVal(zbPrint, "* VENDA REGISTRADA *", "em Dinheiro:"  , VDINH+VPMDINH )
      eVal(zbPrint, "* VENDA REGISTRADA *", "em Cheques:"   , VCHEQ+VPMCHEQ )
      eVal(zbPrint, "* VENDA REGISTRADA *", "em Cartoes:"   , VCART+VPMCART )
      eVal(zbPrint, "* VENDA REGISTRADA *", "em Convenios:" , VCONV+VPMCONV )
      eVal(zbPrint, "* VENDA REGISTRADA *", "Fiado/Boletos:", vMist+VPMCarn )
      eVal(zbPrint, "* VENDA REGISTRADA *", "** Sem ocorrencias **", fdinh+VDINH+VPMDINH+VCHEQ+VPMCHEQ+VCART+VPMCART+VCONV+VPMCONV+vMist+VPMCarn)
      (znFpVendas:=znI, znI:=0)

      eVal(zbPrint, "* RECEBIMENTOS DE FIADOS/OUTROS *", "em Dinheiro:"  , VcrDINH+vsupriment )
      eVal(zbPrint, "* RECEBIMENTOS DE FIADOS/OUTROS *", "em Cheques:"   , VcrCHEQ )
      eVal(zbPrint, "* RECEBIMENTOS DE FIADOS/OUTROS *", "em Cartoes:"   , VcrCART )
      eVal(zbPrint, "* RECEBIMENTOS DE FIADOS/OUTROS *", "em Convenios:" , VcrCONV )
      eVal(zbPrint, "* RECEBIMENTOS DE FIADOS/OUTROS *", "Fiado/Boletos:", VcrCARN )
      eVal(zbPrint, "* RECEBIMENTOS DE FIADOS/OUTROS *", "** Sem ocorrencias **", VcrDINH+vsupriment+VcrCHEQ+VcrCART+VcrCONV+VcrCARN )
      (znFpRecebs:=znI, znI:=0)

      eVal(zbPrint, "* SANGRIAS/RETIRADAS DO CAIXA *", "em Dinheiro:"  , 0-(VcpDINH+zvPagCaixa+vsangriaES) )
      eVal(zbPrint, "* SANGRIAS/RETIRADAS DO CAIXA *", "em Cheques:"   , 0-VcpCHEQ-vsangriaCH )
      eVal(zbPrint, "* SANGRIAS/RETIRADAS DO CAIXA *", "em Cartoes:"   , 0-VcpCART )
      eVal(zbPrint, "* SANGRIAS/RETIRADAS DO CAIXA *", "em Convenios:" , 0-VcpCONV )
      eVal(zbPrint, "* SANGRIAS/RETIRADAS DO CAIXA *", "Fiado/Boletos:", 0-VcpCARN )
      eVal(zbPrint, "* SANGRIAS/RETIRADAS DO CAIXA *", "** Sem ocorrencias **", VcpDINH+zvPagCaixa+vsangriaES+VcpCHEQ+vsangriaCH+VcpCART+VcpCONV+VcpCARN)
      (znFpSang:=znI, znI:=0)
      //sfgdebugalert:=.t.
      zbPrint:={|cFormaPg,nValorInf,nValor|zhReg:={=>}, zhReg['FORMAPG']:=cFormaPg,zhReg['VALOR']:=nValor, zhReg['VALOR_INF']:=nValorInf, if((cFormaPg<>"** Sem ocorrencias **".and.(nValor>0.or.nValorInf>0)).or.(cFormaPg="** Sem ocorrencias **".and.nValor=0.and.nValorInf=0),oLst:PutRsFR3('_cx_inf',@zhReg),) }
      zCalcES:= (fdinh+VDINH+VPMDINH + VcrDINH+vsupriment - (VcpDINH+zvPagCaixa+vsangriaES))
      zCalcCH:= (fcheq+VCHEQ+VPMCHEQ + VcrCHEQ-VcpCHEQ-vsangriaCH)
      zCalcCT:= (fcart+VCART+VPMCART + VcrCART-VcpCART)
      zCalcCV:= (fconv+VCONV+VPMCONV + VcrCONV-VcpCONV)
      zCalcCA:= (fcarn+vMist+VPMCarn + VcrCARN-VcpCARN)

      eVal(zbPrint, "Dinheiro:"  , ViDINH, zCalcES)
      eVal(zbPrint, "Cheques:"   , ViCHEQ, zCalcCH)
      eVal(zbPrint, "Cartoes:"   , ViCART, zCalcCT)
      eVal(zbPrint, "Convenios:" , ViCONV, zCalcCV)
      eVal(zbPrint, "a Prazo:", ViCARN, zCalcCA)
      eVal(zbPrint, "** Sem ocorrencias **", ViDINH+ViCHEQ+ViCART+ViCONV+ViCARN , zCalcES+zCalcCH+zCalcCT+zCalcCV+zCalcCA)
      //sfgdebugalert:=.f.

      zbPrint:={|cOcorrencia,nValor,nQtd| zhReg:={=>}, zhReg['DESC']:=cOcorrencia,zhReg['VALOR']:=nValor, zhReg['QUANT']:=nQtd, oLst:PutRsFR3('_cx_ocor',@zhReg) }

      se znFpVendas>1 entao eVal(zbPrint, "Valor Total das Vendas",            VDINH+VPMDINH+VCHEQ+VPMCHEQ+VCART+VPMCART+VCONV+VPMCONV+vMist+VPMCarn, 0)
      se znFpRecebs>1 entao eVal(zbPrint, "Suprimentos/Quitacoes/Rec.Avulsos", VcrDINH+vsupriment+VcrCHEQ+VcrCART+VcrCONV+VcrCARN, nrec_caixa)
      se znFpSang>1   entao eVal(zbPrint, "Total Sangrias/Pagamentos Avulsos", VcpDINH+zvPagCaixa+vsangriaES+VcpCHEQ+vsangriaCH+VcpCART+VcpCONV+VcpCARN, npag_caixa)

      eVal(zbPrint, "Valor dos Cancelamentos",           vCanc,      nCanc)
      eVal(zbPrint, "Resgates de Notas de Credito",      vavalpago,  npag_nc)
      eVal(zbPrint, "Vendas Alteradas apos Fechamento",  VALT,       nAlt)
      eVal(zbPrint, "Valor das Transferencias",          VTRANSF,    nVen6)
      eVal(zbPrint, "Diferencas de Trocas",              vDev,       nDev)
      se sys_segmento="locacao"  entao eVal(zbPrint, "Valor em Boletos/Duplicatas", VCONV+vMist, NVEN4+NVEN5)
      se sys_segmento="farma"    entao eVal(zbPrint, "Venda em Convenios", VCONV-VfPop, NVEN4-nFpop)
      se sys_segmento="farma"    entao eVal(zbPrint, "Venda Farmacia Popular", VfPop, nFpop)

      //se select('_cx_fp')=0   entao dbUseArea( .T.,, "mem:_cx_fp",, .f., .F. )   senao DbSelectArea('_cx_fp')
      //copy to _zfp
      //se select('_cx_inf')=0  entao dbUseArea( .T.,, "mem:_cx_inf",, .f., .F. )  senao DbSelectArea('_cx_inf')
      //copy to _zinf
      //se select('_cx_ocor')=0 entao dbUseArea( .T.,, "mem:_cx_ocor",, .f., .F. ) senao DbSelectArea('_cx_ocor')
      //copy to _zocor

   endif

   //oLst:AddCab( {"AplicaFormatacaoDefaultNoCabecalho"=>"nao", "style"=>"font:Helvetica-Bold#size:14", "COLS"=>"0,C"}, zTitulo)
   //oLst:AddCab( {"style"=>"font:Helvetica#size:10", "COLS"=>"0,C"}, "Aberto por "+AllTrim(usu_open)+", em "+Dtoc(dataopen)+" 'as "+HoraOpen+" hs")
   //oLst:AddCab( {"style"=>"font:Helvetica#size:10", "COLS"=>"0,C"}, "Fechado por "+AllTrim(usu_fech)+", em "+Dtoc(datafech)+" 'as "+HoraFech+" hs   Situacao Atual: "+AllTrim(SITUACAO))
   //
   //oLst:AddCab( '_LINHA_GROSSA_' )
   //oLst:AddCab( '_CABCOLS_' )
   //oLst:AddCab( '_LINHA_FINA_' )
   //
   //oLst:AddCol('FormaPag;zFormaPg;P;@S9;9;;')
   //oLst:AddCol('Fundo Cxa;zFundoCx;P;@e 999999.99;9;;;Direita;Some;')
   //oLst:AddCol('Venda;zVenda;P;@e 999999.99;9;;;Direita;Some;')
   //oLst:AddCol('Quitacoes;zQuitacoes;P;@e 999999.99;9;;;Direita;Some;')
   //oLst:AddCol('Sangrias;zSangrias;P;@e 999999.99;9;;;Direita;Some;')
   //oLst:AddCol('Tot.Calc;zFundoCx+zVenda+zQuitacoes+zSangrias;P;@e 999999.99;9;;;Direita;Some;')
   //oLst:AddCol('Tot.Inf;zTotInf;P;@e 999999.99;9;;;Direita;Some;')
   //oLst:AddCol('Dif.Cxa;(zFundoCx+zVenda+zQuitacoes+zSangrias)-zTotInf;P;@e 999999.99;9;;;Direita;Some;')
   //se z_concilia="S" entao oLst:AddCol('Recalculo;zRecalc;P;@e 999999.99;9;;;Direita;Some;')
   //se z_concilia="S" entao oLst:AddCol('Conciliado;zReinform;P;@e 99999999.99;11;;;Direita;Some;')
   //se z_concilia="S" entao oLst:AddCol('Dif.Final;zReinform-zRecalc;P;@e 999999.99;9;;;Direita;Some;')
   //
   //zbPrint := {|p1,p2,p3,p4,p5,p6,p7,p8|zFormaPg:=p1,zFundoCx:=p2,zVenda:=p3,zQuitacoes:=p4,zSangrias:=p5,zTotInf:=p6,zRecalc:=p7,zReinform:=p8,oLst:PrtD('_DATACOLS_')}
   //eVal(zbPrint, SxNomeFormaPag('ES'),fdinh,VDINH+VPMDINH,VcrDINH+vsupriment,0-(VcpDINH+zvPagCaixa+vsangriaES),ViDINH,VcncDINH,VcnDINH)
   //eVal(zbPrint, SxNomeFormaPag('CH'),fcheq,VCHEQ+VPMCHEQ,VcrCHEQ,0-VcpCHEQ-vsangriaCH,ViCHEQ,VcncCHEQ,VcnCHEQ)
   //eVal(zbPrint, SxNomeFormaPag('CT'),fcart,VCART+VPMCART,VcrCART,0-VcpCART,ViCART,VcncCART,VcnCART)
   //eVal(zbPrint, SxNomeFormaPag('CV'),fconv,VCONV+VPMCONV,VcrCONV,0-VcpCONV,ViCONV,VcncCONV,VcnCONV)
   //eVal(zbPrint, SxNomeFormaPag('CA'),fcarn,vMist+VPMCarn,VcrCARN,0-VcpCARN,ViCARN,VcncCarn,VcnCARN)
   //   
   //oLst:PrtD('_LINHA_GROSSA_')
   //oLst:SetFormatSomaCol(1, {||"*TOTAIS"}, .t. /*Alterar Descricao do Totalizador Global*/)
   //oLst:PrtD({"style"=>"font:Courier-BoldOblique"}, '_SOMACOLS_GLOBAL_' )
   //
   //oLst:PrtD('_PULE_2_LINHAS_')
   //
   //oLst:xPrtD('Vda.Dinheiro.: [VDINH @E 9999999.99]  ([NVEN1 9999] Cupons)          Transferencias..: [VTRANSF @E 9999999.99] ([nVen6 9999] Cupons)')
   //oLst:xPrtD('Vda.Cheques..: [VCHEQ @E 9999999.99]  ([NVEN2 9999] Cupons)          Cancelamentos...: [VCANC @E 9999999.99] ([nCanc 9999] Cupons)')
   //oLst:xPrtD('Vda.Cartoes..: [VCART @E 9999999.99]  ([NVEN3 9999] Cupons)          Diferenca Trocas: [VDEV @E 9999999.99] ([nDev 9999] Cupons)')
   //
   //se sys_segmento="locacao"  entao oLst:xPrtD('Duplicatas...: [VCONV+vMist @E 9999999.99]  ([NVEN4+NVEN5 9999] Cupons)          Vendas Alteradas: [VALT @E 9999999.99] ([nAlt 9999] Cupons)')
   //se sys_segmento<>"locacao" entao oLst:xPrtD('Vda.Convenios: [VCONV-VfPop @E 9999999.99]  ([NVEN4-nFpop 9999] Cupons)          Vendas Alteradas: [VALT @E 9999999.99] ([nAlt 9999] Cupons)')
   //se sys_segmento<>"locacao" entao oLst:xPrtD('Vda.F Popular: [VfPop @E 9999999.99]  ([nFpop 9999] Cupons)', sys_segmento="farma")
   //se sys_segmento<>"locacao" entao oLst:xPrtD('Outras Formas: [vMist @E 9999999.99]  ([NVEN5 9999] Cupons)')
   //
   //oLst:PrtD('')
   //oLst:PrtD('Sangrias/Pagamentos Avulsos......:'+Transform(vpag_caixa+vsangriaES,'@E 9999999.99') +'  ('+str(npag_caixa,4)+' lancamentos)')
   //oLst:PrtD('Suprimentos/Quitacoes/Rec.Avulsos:'+Transform(vrec_caixa+vsupriment,'@E 9999999.99') +'  ('+str(nrec_caixa,4)+' lancamentos)')
   //se fieldpos('vavalpago')>0 entao oLst:PrtD('Resgates de Notas de Credito ....:'+Transform(vavalpago,'@E 9999999.99') +'  ('+str(npag_nc,4)+' lancamentos)')
   //
   //oLst:PrtD('')
   //
   //if .not. zFgRoloPDF .and. len( m_fobs:=AllTrim(obs) ) > 0
   //   nRow := 0
   //   do while ++nRow <= mlCount(m_fobs, if(zFgRoloPDF,60,50))
   //      oLst:PrtD({"style"=>"font:Courier-Oblique#size:8#col:0#row:(oPdf:pRow+1)"}, Rtrim(memoline(m_fobs,if(zFgRoloPDF,60,50),nRow)) )
   //   enddo
   //endif
   DbGoBottom()

   if zFgRoloPDF

      oLst:PutRsFR3('_sicaixa', si_caixa->(Scatter()) )
      oLst:lOutputFr3      := .t.
      oLst:cAliasMaster    := '_sicaixa' 
      oLst:cAlias_DataCols := '_sicaixa'
      oLst:cReport         := 'cxadia_'+wOpcao

      oLst:Run()
      oLst:End()
      dbCloseAll()
      
      dbDrop('mem:_sicaixa')
      dbDrop('mem:_cx_fp')
      dbDrop('mem:_cx_inf')
      dbDrop('mem:_cx_ocor')

      // Return
   endif
   
#FIM_TEXTO_FONTE
