;* ExpBling ********************************************************************
;* Exporta ID Site para Bling **Ajusta dados conforme planilha .xls            *
;*******************************************************************************
;Autor           : Vise Informatica (VISERP)
;Desenvolvido    : 22/09/2020 por Bruno Carvalho
;Ultima Alteracao:   /  /     por                 
;Motivo Alteracao:

;Bling.XLS -> Arquivo necess rio para ser realizado o ajuste nesta planilha, referente … coluna "B2" em arquivo xls.
;Onde ser  exportado conforme codigo do item, o ID SITE (TrayCorp) para esta coluna nesta planilha 
;e assim ser exportado para o sistema Bling. 

;*******************************************************************************
;* Rotina                                                                      *
;*******************************************************************************
Proc Gera_Tabela()
        
{Ask} {\\Sistemas\\Estoque\\Itens}
Moveto [Codigo do Item          ] Check TypeIn "_CodI"
Moveto [Tipo do Item            ]       TypeIn "P Or T"
Moveto [Codigo da Familia       ]       TypeIn "~VSDGFAMI.."
Moveto [Codigo do Grupo         ]       TypeIn "~VSDGGRP.."
Moveto [Codigo da Marca         ]       TypeIn "~VSDGMARCA.."
Moveto [Referencia              ]       TypeIn "~VSDGREFERENCIA.."
Moveto [Inativo                 ]       TypeIn "Not S"
{Ask} {\\Sistemas\\Estoque\\Iten_Eco}
Moveto [Codigo do Item          ]       TypeIn "_CodI"
Moveto [IdSite                  ] Check
Do_it!
ClearAll 

EndProc ;Gera_Tabela()

;*******************************************************************************
;* Rotina                                                                      *
;*******************************************************************************
Proc SD_Dialog(Disparo,Campo,Evento,Elemento)
Temp=True
TECLA=""
MSG_CAMPO=""
If Disparo="OPEN"  Then AoCriarShowDialog() EndIf
If Disparo="EVENT" And Evento["Type"]="KEY" Then
   Switch
     Case Evento["KeyCode"] = -59: 
          Dialog_F1()            
     Case Evento["KeyCode"] =  27:
          Temp=False
          Switch                                 
            Case Campo="TG_FAMI"        : Campo="NO"                       
            Case Campo="TG_GRP"         : Campo="TG_FAMI"                               
            Case Campo="TG_MARCA"       : Campo="TG_GRP"                              
            Case Campo="TG_REFERENCIA"  : Campo="TG_MARCA"                          
            Case Campo="YES" Or Campo="NO": Campo="TG_FAMI"
          EndSwitch
     Case (Evento["KeyCode"] <= -104 And Evento["KeyCode"] >= -113) Or 
           Evento["KeyCode"]  = -139 Or  Evento["KeyCode"]  = -140:
           SYS_TECLA_ACIONADA=Evento["KeyCode"]
           Seta_Tecla_Acionada()
           CancelDialog
     Case Evento["KeyCode"] = 13:
          Temp=False
          If Checa_TAG()
             Then Switch
                    Case Campo="TG_FAMI"        : Campo="TG_GRP"                              
                    Case Campo="TG_GRP"         : Campo="TG_MARCA"                              
                    Case Campo="TG_MARCA"       : Campo="TG_REFERENCIA"                       
                    Case Campo="TG_REFERENCIA"  : Campo="YES"
                  EndSwitch
          EndIf
          RefreshDialog
   EndSwitch
EndIf

Monta_Prompt(MSG_CAMPO,TECLA)
Return Temp

EndProc ;SD_Dialog()                                                         

;*******************************************************************************
;* ROTINA PRINCIPAL                                                            *
;*******************************************************************************
AutoLib="\\Sistemas\\Cadastro\\Bib_Show,\\Sistemas\\Cadastro\\Bibliot"
LimpAguarde()
Sys_Valor()

VSDGEMPRESA    = ""            
VSDGNOMEMP     = ""            
VSDGFAMI       = ""            
VSDGNOMFAMI    = ""            
VSDGGRP        = ""            
VSDGNOMGRP     = ""            
VSDGMARCA      = ""            
VSDGNOMMARCA   = ""            
VSDGREFERENCIA = ""            

While True
 ShowDialog "Ajusta dados [BLING]" Proc "SD_Dialog"
   Trigger "OPEN","ARRIVE"
    Key "TAB","ReverseTab","ENTER","ESC","F1",
      -104, -105, -106, -107, -108, -109, -110, -111, -112, -113, -139, -140    
     @ 05,12 Height 13 Width 72
     
    Label  @ 00,00 "Familia"  For "TG_FAMI"                                                           
    Accept @ 01,02 Width 06 "A3"  Picture "#*#" Tag "TG_FAMI" To VSDGFAMI                             
    Accept @ 01,09 Width 25 "A25" Picture "!*!" Tag "TG_NOMFAMI" To VSDGNOMFAMI                       
                                                                                                      
    Label  @ 02,00 "Grupo"  For "TG_GRP"                                                              
    Accept @ 03,02 Width 06 "A3"  Picture "#*#" Tag "TG_GRP" To VSDGGRP                               
    Accept @ 03,09 Width 25 "A25" Picture "!*!" Tag "TG_NOMGRP" To VSDGNOMGRP                         
                                                                                                      
    Label  @ 04,00 "Marca"  For "TG_MARCA"                                                            
    Accept @ 05,02 Width 06 "A3"  Picture "#*#" Tag "TG_MARCA"    To VSDGMARCA                        
    Accept @ 05,09 Width 25 "A25" Picture "!*!" Tag "TG_NOMMARCA" To VSDGNOMMARCA                     
                                                                                                      
    Label  @ 06,00 "Referˆncia"  For "TG_REFERENCIA"                                                  
    Accept @ 07,01 Width 21 "A20" Picture "!*!" Tag "TG_REFERENCIA"     To VSDGREFERENCIA             
 
    Pushbutton @ 09,22 width 13 "~O~k"      OK     Default Value "Ok" Tag "YES" To BottonValue
    Pushbutton @ 09,36 width 13 "~C~ancela" CANCEL                    Tag "NO"  To BottonValue

  EndDialog
  If Not RetVal Then QuitLoop EndIf
                 
  ;If IsBlank(VSDGEMPRESA)
  ;   Then Mensagem("A empresa deve ser informada!")
  ;        Loop
  ;EndIf
  
  CI_20CPP            = Chr(27)+Chr(77)+Chr(15)
  CI_F_TIMES          = CI_20CPP
  PDFZEBRA            = False
  DISPOSITIVO_OPCAO   = "A"
  TIPO_DOCTO          = 2 ;Excel
  
  ;Diret¢rio de Origem/Trabalho
  DIR_SITE =  SubStr(Directory(),1,2) + "\\Sistemas\\Exporta\\Modelo\\BLING"
  DIREPORT = "\\Sistemas\\Exporta\\Dados\\BLING"
  
  If DirExists(DIREPORT)=0
     Then Cria_Pasta(DIREPORT)
          Sleep 2000
  EndIf
  
  DIREPORT = SubStr(Directory(),1,2) + DIREPORT + "\\"
  If Not IsFile(DIREPORT+"Bling.xls")
     Then Mensagem("Arquivo [Bling.xls] nÆo foi localizado na pasta de trabalho: "+SubStr(Directory(),1,2)+"\\Sistemas\\Exporta\\Dados\\Bling !")
          Loop
  EndIf
      
  Gera_Tabela()
     
  If IsEmpty("Answer")
     Then Mensagem("N„o existem registros a processar")
          Loop
  EndIf
  
  Copia_Arquivo(DIR_SITE + "\\EXP_BLIN.xlsm" + " " + DIREPORT + "EXP_BLIN.xlsm")
  
  ARQUIVO             = "TEMP"
  GERA_ARQUIVO_OCULTO = True   
    
  TABELA = DIREPORT + "TEMP.DB"  
  IMPRIREL("Answer","R")
                
  FileWrite PrivDir() + "funcao1.txt"  From  "EXEF|" + DIREPORT + "EXP_BLIN.xlsm"               
  ExecVise(PrivDir()+"funcao1.txt")
     
EndWhile
ClearAll
Release Vars All
Release Procs All