#xcommand SE <condicao> ENTAO <comandos> [SENAO SE <xcondicao1> ENTAO <xcomandos1> [SENAO SE <xcondicaoN> ENTAO <xcomandosN>] ] [SENAO <comandosotherwise>] => ;
    ( ( (<condicao>) .and. ( <comandos> ,.t.) ) [ .or. ( (<xcondicao1>) .and. ( <xcomandos1> ,.t.) ) ] [ .or. ( (<xcondicaoN>) .and. ( <xcomandosN> ,.t.) ) ] [.or. ( <comandosotherwise> ,.t.)])
memvar wAaaaMm, oProgressBar, zbCopy, oLst

function hrbMain()
   Private wAaaaMm, zbCopy, hReg, oProgressBar, z_De:=s_datual, z_ate:=s_datual, z_dias, zFgLstProds:='S', bNomeVendedor, cCfop, cCodSit, lFgSoXmlsEmFalta:=.f., zbFor, cPathRemessasXML, zLidos:=0, zSemXml:=0, zSitXml, lFgSoMod55:=.f.
   
   if .not. QuickDialog("c170_totais", "60;5;Parametros", { ;
         {"2;2;Data Inicial das Notas Emitidas:", "@z_De",  @z_De,  "99.99.9999", "", ""}, ;
         {"3;2;Data Final   das Notas Emitidas:", "@z_Ate", @z_ate, "99.99.9999", "", ""} } )
      Return .f.
   endif
   wAaaaMm := Left( Dtos(z_de) , 6)

   if .not. ChecaSped(wAaaaMm)
      Alert("Voce deve processar o SPED antes de;imprimir os conferentes de entrada ou saida !",,"B/W")
      Return .f.
   endif

   // xDbCopyTo(cFileTo, xAliasTo, bFor, aColunas, bWhile, lFgPoeRecno, bPut, bStart, vStruct, vStructAdic)

alert('1')
//    ( Abra('0EXCLUSIVENOIDX', r_siga, 'efd_0150', 'efd_0150', 'efd_0150', 'AaaaMm+COD_PART') , eval(zbCopy, '0150', {||wAaaaMm=AaaaMm}) )
//    ( Abra('0EXCLUSIVENOIDX', r_siga, 'efd_c100', 'efd_C100', 'efd_C100', 'AaaaMm') , eval(zbCopy, 'c100', {||wAaaaMm=AaaaMm.and.ind_oper='1'}) )
//    ( Abra('0EXCLUSIVENOIDX', r_siga, 'efd_c190', 'efd_C190', 'efd_C190', 'AaaaMm+AuxIndOper+AuxCodPart+AuxNumDoc+AuxSer+cfop+Cst_Icms+'AaaaMm+COD_PART') 70eval(zbCopy, '015AaaaMm}) )Str(Aliq_icms,6,2)') , eval(zbCopy, 'c190', {||wAaaaMm=AaaaMm.and.AuxIndOper='1'}) )
   Abra ('0EXCLUSIVENOIDX', r_siga,  'efd_c170', 'efd_C170', 'efd_c170', 'AaaaMm+AuxIndOper+AuxCodPart+AuxNumDoc+AuxSer+AuxCodMod')
   alert('2')
   // dbSeek(wAaaaMm)
   // xDbCopyTo('mem:efdc170', 'efdc170', {||wAaaaMm=AaaaMm}, {||wAaaaMm=AaaaMm}, .t. )

   oProgressBar := myHProgressBar():Create( "Totalizando por CFOPS, CST e %ICMS anomes: "+wAaaaMm)
   oLst:GroupBy('mem:efdc170', {||cfop}, 'auxcodmod, auxindoper, iif(left(cfop,1)$"15","E","S") as aux_ei, cfop, cst_icms, vl_item, vl_bc_icms,aliq_icms as char,vl_icms, vlbcicmsst, vl_icms_st,vl_ipi,vl_pis, vl_cofins', ;
                               {||oProgressBar:step(), wAaaaMm=AaaaMm }, .t.)
   oProgressBar:close()

   alert('3')
    oProgressBar := myHProgressBar():Create( "Totalizando por CFOPS anomes: "+wAaaaMm)
    oLst:GroupBy('mem:_tcfop', {||cfop}, 'cfop, AuxSer, AuxCodMod, vl_item-auxvoutro+vl_desc as vl_merc, auxvoutro, vl_desc, vl_item, 0 as vfrete, vl_icms, vl_icms_st, vl_ipi, vl_item+vl_icms_st+vl_ipi as totliq2, vl_pis, vl_cofins', ;
                                {||oProgressBar:step(), wAaaaMm=AaaaMm }, .t.)
    oProgressBar:close()

dbCloseAll()
alert('2')

//    use ('mem:efd0150') alias _0150 new exclusive
//       index on COD_PART to ('mem:efd0150')
//    use ('mem:efdc100') alias _c100  new exclusive
//       index on cod_mod+ind_oper+ser+num_doc to ('mem:efdc100')
//    use ('mem:efdc190') alias _c190  new exclusive
//       // index on AuxIndOper+AuxCodPart+AuxNumDoc+AuxSer+cfop+Cst_Icms+Str(Aliq_icms,6,2) to ('mem:efdc190')
//       index on AuxIndOper+AuxCodPart+AuxSer+cfop+Cst_Icms+Str(Aliq_icms,6,2) to ('mem:efdc190')
   
//    use ('mem:_tcfop') alias _tcfop new exclusive


//    oLst:AddDbFr3('mem:efd0150', '_0150')
//    oLst:AddDbFr3('mem:efdc100', '_c100')
//    oLst:AddDbFr3('mem:efdc190', '_c190')
//    oLst:AddDbFr3('mem:efd0150', '_0150')
   oLst:AddDbFr3('mem:_tcfop',  '_tcfop')

   use ('mem:efdc170') alias _c170  new exclusive
      index on auxcodmod+auxindoper+cfop+Cst_Icms+Str(Aliq_icms,6,2) to ('mem:efdc170')

      alert('3')

   wCab1:="Conferente de Notas de Saida"
   wCab2:="Periodo de "+Dtoc(z_De)+" a "+Dtoc(z_ate)
   
   oLst:lOutputPdf      := .f.
   oLst:lOutputFr3      := .t.
   oLst:cAliasMaster    := '_c170' 
   oLst:cAlias_DataCols := '_c170'
//   oLst:cReport         := 'c100_conf_sai'
   oLst:cReport         := 'c170_totais_cfop_cst'

   oLst:cTemplateFr3 := 'skel_ListaComGrp.fr3'
   
   debugalert('7 vai :run e :end')

   alert('4')

   cPathRemessasXML:=s_PathDb+'sped\xml_'+Left(wAAAAMM,4)+'_'+Right(wAAAAMM,2) +'\'
    // //  zbFor := {|| zFilenamexml:="", zFg:=.f., lFgOk:=.not. lFgSoXmlsEmFalta .or. .not. (zFg:=ExisteArqXmlSped(cPathRemessasXML, wAaaaMm, _c100->ind_emit, _c100->chv_nfe, _c100->Cod_Sit, @zFileNameXml)), Alert("Pesquisou em "+cPathRemessasXML+";"+Cutpath(zFilenamexml)+";achou zFg="+if(zFg,"S","N") ), lFgOk}
    // //  zbFor := {|| ++zLidos, zFilenamexml:="", zFg:=.f., lFgOk:=.not. lFgSoXmlsEmFalta .or. .not. (zFg:=ExisteArqXmlSped(cPathRemessasXML, wAaaaMm, _c100->ind_emit, _c100->chv_nfe, _c100->Cod_Sit, @zFileNameXml)), if(lFgOk,++zSemXml,), lFgOk}
    // //  _c100->( DbGoTop(), oLst:DbEval(,zbFor) )
    //    _c100->( DbGoTop(), dbEval({||++zLidos, _field->XML:=if(ExisteArqXmlSped(cPathRemessasXML, wAaaaMm, _c100->ind_emit, _c100->chv_nfe, _c100->Cod_Sit),"", (++zSemXml,"NAO") ) }) , dbGoTop() )

    alert('5')

// sfgdebugalert:=.t.

//    se zSemXml=0 entao Alert("Todos os "+lTrim(Str(zLidos,6))+" XMLs do periodo foram exportados!;Nao existem XMLs pendentes de exportacao!;")
//    se lFgSoXmlsEmFalta .and. zSemXml>0 entao _c100->( dbSetFilter({||xml='NAO'},"XML='NAO'"), dbGoTop() )
//    se lFgSoMod55 entao _c100->( dbSetFilter({||cod_mod='55'},"cod_mod='55'"), dbGoTop() )
// zSitXml := "XMLs Gerados: "+lTrim(Str(zLidos,6))+" "+if(zSemXml>0,"Nao Exportados: "+lTrim(Str(zSemXml,6)),"- Todos foram Exportados")

   oLst:Run()
   oLst:End()

// sfgdebugalert:=.f.
   
   dbCloseAll()
   dbDrop('mem:efdc170')
   dbDrop('mem:_tcfop')
//    dbDrop('mem:efd0150')
//    dbDrop('mem:efdc100')
//    dbDrop('mem:efdc190')
   // alert("leu "+str(zLidos)+" faltaram "+Str(zSemXml) )
// sfgdebugalert:=.f.
Return 