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 zTitulo = ''
VARIAVEL #TEXTO_FONTE
   Private zFormaPg,zFundoCx,zVenda,zQuitacoes,zSangrias,zTotInf,zRecalc,zReinform,zPgtosCxa,nRow,m_fobs, zbPrint
   
   DbGoBottom()
   do while .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", "Fechamento de Caixa", {{"Numero de Fechamento de Caixa:", "@Z_NUMCXA", @Z_NUMCXA, "999999", "", ""} })
      Return
   endif
   Set(20,"PRINTER")
     
   DbSelectArea('si_caixa')
   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)
   zPgtosCxa := if(vpag_caixa=VcpDINH+VcpCHEQ+VcpCART+VcpCONV+VcpCARN,0,vpag_caixa)
   // zDifDinheiro := ViDINH - (fdinh+VDINH+VcrDINH-(VcpDINH+zPgtosCxa))

   oLst:lOutputMatricial := .t.
   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;zTotInf-(zFundoCx+zVenda+zQuitacoes+zSangrias);P;@e 999999.99;9;;;Direita;Some;')
   if z_concilia="S"
      oLst:AddCol('Recalculo;zRecalc;P;@e 999999.99;9;;;Direita;Some;')
      oLst:AddCol('Conciliado;zReinform;P;@e 99999999.99;11;;;Direita;Some;')
      oLst:AddCol('Dif.Final;zReinform-zRecalc;P;@e 999999.99;9;;;Direita;Some;')
   endif

   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,0-(VcpDINH+zPgtosCxa-vsangriaES-vsupriment),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)')

   if sys_segmento="locacao"
   oLst:xPrtD('Duplicatas...: [VCONV+vMist @E 9999999.99]  ([NVEN4+NVEN5 9999] Cupons)          Vendas Alteradas: [VALT @E 9999999.99] ([nAlt 9999] Cupons)')
   else
   oLst:xPrtD('Vda.Convenios: [VCONV-VfPop @E 9999999.99]  ([NVEN4-nFpop 9999] Cupons)          Vendas Alteradas: [VALT @E 9999999.99] ([nAlt 9999] Cupons)')
   oLst:xPrtD('Vda.F Popular: [VfPop @E 9999999.99]  ([nFpop 9999] Cupons)', sys_segmento="farma")
   oLst:xPrtD('Outras Formas: [vMist @E 9999999.99]  ([NVEN5 9999] Cupons)')
   endif
   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('')
   nRow := 0
   // oLst:PrtD({"style"=>"font:Helvetica-Oblique#col:40#row:(oPdf:nLinesPorPagina-6-1)"}, "")
   if len( m_fobs:=AllTrim(obs) ) > 0
      do while ++nRow <= mlCount(m_fobs, 60)
         oLst:PrtD({"style"=>"font:Courier-Oblique#size:8#col:0#row:(oPdf:pRow+1)"}, Rtrim(memoline(m_fobs,60,nRow)) )
      enddo
   endif

   DbGoBottom()
   
#FIM_TEXTO_FONTE
