ALIAS _KITS
// a Variavel z_Recno guarda a posicao do registro do arquivo mestre do relatorio

VARIAVEL znil := alert( 'z_Recn='+str(z_Recn) )

// VARIAVEL znil := _KITS->(DbGoto(z_Recno))
VARIAVEL znil := _KITS->(DbGoto(z_Recn))
VARIAVEL zpCod := _KITS->pCod
VARIAVEL zModeloXLS := 'composicao_modelo.xls'
VARIAVEL zNomePlanilha := "composicao_"+StrZero(zpCod,6)

VARIAVEL zkk := 0
VARIAVEL zbl := {|cColLine| left(cColLine,1) + lTrim(Str( Val(SubStr(cColLine,2))+zkk,4)) }

VARIAVEL #TEXTO_FONTE
   Private zoProgressBar, zCmdsDurante, zCmdsDepois, zl:=0, zMaxLines:=33, zPages:=1, zPagesImpressas:=0, zAditivo, zStatus, wOpt:=1, oClasse, zaLines:={}, zCodCli

sfgdebugalert:=.t.
   debugalert('prod: '+lTrim(Str(zpCod)) )

   debugalert('vai ativar excel...')
   oClasse := tCvXls():New()
   debugalert('vai exibir excel...')
   oClasse:oXls:Visible := .t.
   debugalert('exibiu excel...')

   if .not. oClasse:AddSheet( zModeloXLS, zNomePlanilha )
      Alert("Nao consegui abrir modelo de fatura "+zModeloXLS,,"R/W")
      Return .f.
   endif

   _itkits->( DbGoTop(), DbEval({||++zl}) , DbGoTop() )

   debugalert('processara '+lTrim(str(zl,10))+' insumos...')

   // se zl>zMaxLines entao _itkits->( DbGoTop(), DbEval({||++zl},,{||zl>zMaxLines}) , DbGoTop() )
   // debugalert('-> faltam '+hb_valtoexp(zl-zMaxLines)+' linhas')

      DbSelectArea('_KITS')
      DbGoTop()
      oClasse:Cell( eVal(zbl,"c4"), RemoverAcentos(AllTrim(_kits->pDesc), 'ANSI') )
      oClasse:Cell( eVal(zbl,"m4") , Str(_kits->pcLoteProd,12,2) )

      // oClasse:Cell( eVal(zbl,"d5") , Str(_kits->pLargura,12,2) )
      // oClasse:Cell( eVal(zbl,"l5") , Str(_kits->pAltura,12,2) )

   debugalert('processara '+lTrim(str(zl,10))+' insumos...')
   
      zl := 1
      DbSelectArea("_itkits")
      DbGoTop()
      Do While .not. eof() 
         oClasse:Cell( eVal(zbl,"b"+lTrim(Str(10+zl,4))),    lTrim(Str(pCodInsumo,10)) )
         oClasse:Cell( eVal(zbl,"c"+lTrim(Str(10+zl,4))),    AllTrim(pDesc) )
            
         oClasse:Cell( eVal(zbl,"i"+lTrim(Str(10+zl,4))),    lTrim(Str(mQuant,12,4)) )
         oClasse:Cell( eVal(zbl,"j"+lTrim(Str(10+zl,4))),    lTrim(Str(pPecas,12)) )

         oClasse:Cell( eVal(zbl,"k"+lTrim(Str(10+zl,4))),    lTrim(Str(pLargura,12,3)) )
         oClasse:Cell( eVal(zbl,"l"+lTrim(Str(10+zl,4))),    lTrim(Str(pAltura,12,3)) )
         ++zl 
            
         skip
      enddo
      DbSelectArea('_KITS')


      DebugAlert('vai oClasse:oXls:ActiveWorkbook:Save()')
      oClasse:oXls:ActiveWorkbook:Save()

   DbSelectArea('_KITS')
   debugalert('-> finalizou processo...')

sfgdebugalert:=.f.
 
#FIM_TEXTO_FONTE
