ALIAS SE_PRDCC
INDEX SE_PRDCC pdesc

VARIAVEL Z_BLKDH:={||Left(Dtoc(PDATACONT),5)+" "+Left(PHORACONT,5)} 
VARIAVEL Z_BLKDHf:={||Left(Dtoc(PDATACONf),5)+" "+Left(PHORACONf,5)} 
VARIAVEL Z_BLKDHfi:={||Left(Dtoc(PDATACONfi),5)+" "+Left(PHORACONfi,5)} 
VARIAVEL Z_BLKC:={||if(day(pdatacont)>0.and.pestcont<>se_prod->peatual,"*RECONTAR*",if(day(pdatacont)>0.and.PCONTAGEM<>se_prod->peatual,"*_Dif_Est_*",eval(Z_BLKDH)))} 
VARIAVEL Z_BLKF:={||if(day(pdataconf)>0.and.pestconf<>se_prod->peatual,"*RECONFERIR*",if(day(pdataconf)>0.and.PCONFEREN<>se_prod->peatual,"*_Dif_Est_*",eval(Z_BLKDHf)))} 
VARIAVEL Z_BLKCI:={||if(day(pdataconfi)>0.and.pestconfi<>se_prod->peatual,"*RECONFIRMAR*", "* "+if(PCONFIRMA<>se_prod->peatual,Str(PCONFIRMA-se_prod->peatual,6),"_EST_OK_")+" *")} 
VARIAVEL Z_BLK_cc:={||if(day(pdatacont)>0,"*SEM_CONF*",if(day(pdataconf)>0,"*SEM_CONT*","*PENDENTE*"))} 
VARIAVEL Z_BLK_ccc:={||if(PCONTAGEM=PCONFEREN,if(PCONFEREN<>se_prod->peatual,"Pend: "+Str(PCONFEREN-pestconf,5),"_OK_"),"CONT # CONF")} 

COMANDO ANTES #TEXTO_FONTE
   Private zFgOk:=.t.,z_np:=0,Z_SITUACAO:=SPAC(11),zSoSemCad:="N",zCCDifEst:="N",zSemCont:="N",zSemConF:="N",zContDConf:="N",zContIConf:="N",zTotDif:=0,zpCod,zSit,zpEAtual,zpconfirma,ZDIF,ZMFGES,zDtConf,zDtCont
   
   if .not. QuickDialog("lst_seprdcc", "Parametros",{ ;
      {"2;2;Situacao (Ex: 'RECONFIRMA' ou 'RECONF' ou 'Pend:' etc .):", "@z_situacao", @z_situacao, "!!!!!!!!!!!", "", "" } ,;
      {"3;2;Apenas Produtos com Codigos de Barras Nao Cadastrados ..?", "@zSoSemCad",  @zSoSemCad,  "!", "", "" } ,;
      {"4;2;Apenas com Contagem ou Conferencia Diferente do Estoque ?", "@zCCDifEst",  @zCCDifEst,  "!", "", "" } ,;      
      {"5;2;Apenas Produtos que estao sem contagem .................?", "@zSemCont",   @zSemCont  , "!", "", "" } ,;
      {"6;2;Apenas Produtos que estao sem conferencia ..............?", "@zSemConf",   @zSemConf  , "!", "", "" } ,;
      {"7;2;Apenas Produtos com Contagem diferente da Conferencia ..?", "@zContDConf", @zContDConf, "!", "", "" } ,;
      {"8;2;Apenas Produtos com Contagem Igual a Conferencia .......?", "@zContIConf", @zContIConf, "!", "", "" } ,;
      {"9;2;Apenas Diferencas Entre Contag e Estoques a Partir de...:", "@zTotDif",    @zTotDif   , "9999", "", "" } } )
      Return       
   endif
   z_situacao:=AllTrim(UPPER(z_situacao)) 
   // sFgDebugAlert := .t.
   debugalert('2')

   oLst:cAlias_DataCols := '_prdbal'
   oLst:cAliasMaster := '_prdbal'
   
   oLst:lPortrait := .t.
   oLst:lGeraDbTmp := .f.
   oLst:lOutputFr3 := .f.
   oLst:lOutputPdf := .t.
   
   // oLst:lOutputFr3 := .t.

   oLst:Cab1( "Resultado da Contagem x Conferencia do Balanco")
   oLst:AddCab( "" )
   oLst:Cab4(Dtoc(s_datual)+" as "+left(time(),5)+"hs")
   oLst:AddCab( '_LINHA_FINA_' )
   oLst:AddCab( '_CABCOLS_' )
   oLst:AddCab( '_LINHA_GROSSA_' )

   oLst:AddCol('Codigo;pCod;N;999999;6;;')
   oLst:AddCol('Descricao;pDesc;C;@s35;35;;') 
   oLst:AddCol('UND;se_prod->pUnidade;P;@S5;5;;') 

   oLst:AddCol('Unids da\nContagem;pContagem;N;999999999;9;;')
   oLst:AddCol('Unids da\nConferenc;pConferen;N;999999999;9;;')
   oLst:AddCol('Situacao;zSit;P;@S5;5;;') 
   oLst:AddCol('Data da\nContagem;zDtConf;P;@S5;5;;') 

   // oLst:AddCol('Saldo na Hora da\nContag   Conferen;Str(pEstCont,6)+"  "+Str(pEstConf,6);P;@S17;17;;;Direita;NaoSome;')
   oLst:AddCol('Saldo na\nContagem;pEstCont;N;999999999;9;;')
   oLst:AddCol('Saldo na\nConferenc;pEstConf;N;999999999;9;;')

   oLst:AddCol('Saldo\nAgora;zpEAtual;P;9999999;7;;')
   oLst:AddCol('Saldo a\nGravar;zpconfirma;P;9999999;8;;')
   oLst:AddCol('Diferenca;ZDIF;P;9999999;8;;')
   oLst:AddCol('E/S;ZMFGES;P;XXX;3;;')

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

   se select("se_prod")=0 entao Abra("0NOIDX",r_siga,se_prod,"se_prod",seip_c,"pcod")
   Select SE_PRDCC
   dbgotop()
   Do While .not. eof()
      zpCod := pcod 
      se_prod->(DbSeek(zpCod)) 
      zpEAtual := se_prod->peatual 
      zSit := UPPER(pad( if(se_prod->(dbseek(zpCod)),if(day(pdataconfi)>0,eval(z_blkci),IF(day(pdatacont)>0.AND.day(pdataconf)>0,eval(z_blk_ccc),eval(z_blk_cc))),"PRD_NAO_CAD"), 11)) 

      zFgOk:=Z_SITUACAO="".or.Z_SITUACAO$zSit 
      zFgOk:=zFgOk.and. (zCCDifEst="N"  .or. ( (Pcontagem<>zpEAtual.and.day(pdatacont)>0).or.(pconferen<>zpEAtual.and.day(pdataconf)>0) ) )
      zFgOk:=zFgOk.and. (zContDConf="N" .or. (Pcontagem<>pconferen.and.day(pdatacont)>0.and.day(pdataconf)>0) )
      zFgOk:=zFgOk.and. (zContIConf="N" .or. (Pcontagem=pconferen.and.day(pdatacont)>0.and.day(pdataconf)>0) )
      zFgOk:=zFgOk.and. (zSemCont="N"   .or. (day(pdatacont)=0.and.zpEAtual>0) )
      zFgOk:=zFgOk.and. (zSemConf="N"   .or. day(pdataconf)=0 )
      zFgOk:=zFgOk.and. (zSoSemCad="N"  .or. pcod=0 )
      zFgOk:=zFgOk.and. (zTotDif=0      .or. (day(pdatacont)>0.and.abs(pestcont-pcontagem) > zTotDif) )

      if zFgOk
         ++z_np
         zpconfirma := if(day(pdataconfi)=0, se_prod->peatual+PCONFEREN-pestconf, PCONFIRMA)
         ZDIF := zpconfirma - se_prod->peatual
         ZMFGES := if(zdif=0, "*", if(ZDIF>0,"E","S"))
         zDtConf := PAD( eval(Z_BLKDH), 11) 
         zDtCont := PAD( eval(Z_BLKDHF), 11)
         oLst:PrtD("_DATACOLS_")
      endif

      Skip
   EndDo

   oLst:PrtD( '_LINHA_GROSSA_' )
   oLst:PrtD( 'Produtos Listados: '+Transform(z_np,'@E 999,999') )

   debugalert('3')

#FIM_TEXTO_FONTE
