;** Rc_0120  *******************************************************************
;*  Listagem de Itens p/ Contagem                                              *
;*******************************************************************************
;Autor: Visao/Vise
;Desenvolvido    : 14/11/2002 por Anivel Augusto Rodrigues
;Ultima Alteracao: 01/09/2003 por Karen Lauar Nery
;Motivo Alteracao: Acrescimo Localizacao
;Ultima Alteracao: 29/12/2010 por Karina Andrade
;Motivo Alteracao: Add Report com Localizao Rc_Itens 2 e 3
;Ultima Alteracao: 26/12/2011 por Karina Andrade
;Motivo Alteracao: Ajustes VSDGLOCAL em Seleciona()
;Ultima Alteracao: 27/12/2011 por Karina Andrade
;Motivo Alteracao: Add Report por Localizao Rc_Itens 10 e 11
;Ultima Alteracao: 28/08/2012 por Kamila Gomes
;Motivo Alteracao: Add Report por Marca e Grupo Rc_Itens 12 e 13
;Ultima Alteracao: 06/09/2012 por Bruno Carvalho
;Motivo Alteracao: Ajustes p/ ser exibido CodFornecedor ao inv‚s do CodItem no report "0319"
;Ultima Alteracao: 19/09/2012 por Anivel Augusto Rodrigues
;Motivo Alteracao: Ajustes Substitui‡Æo Editor novo arquivo por FileWrite

;*******************************************************************************
;* Rotina p/ Selecionar e Order Registros                                      *
;*******************************************************************************
Proc Seleciona()
ClearAll

{Ask} {Itens} Check
Moveto [Tipo do Item        ] TypeIn "~VSDGTPITEM.."
Moveto [Codigo da Familia   ] TypeIn "~VSDGFAMI.."
Moveto [Codigo do Grupo     ] TypeIn "~VSDGGRP.."
Moveto [Codigo da Marca     ] TypeIn "~VSDGMARCA.."
Moveto [Codigo da Cor_Tecido] TypeIn "~VSDGCORTECIDO.."
If VSDGLOCAL<>""
  Then Moveto [Localizacao         ] TypeIn "~VSDGLOCAL.."
EndIf  
Moveto [Inativo             ]
Switch
  Case VSDGSTATUS="1": TypeIn "N"
  Case VSDGSTATUS="2": TypeIn "S"
EndSwitch
Do_It!
ClearAll

EndProc

;*******************************************************************************
;* Rotina                                                                      *
;*******************************************************************************
Proc SD_Dialog(Disparo,Campo,Evento,Elemento)
Temp=True
MSG_CAMPO=""
TECLA    ="F10=Parƒmetros"

If Disparo="OPEN"  Then AoCriarShowDialog() EndIf
If Disparo="EVENT" And Evento["Type"]="KEY" Then
   Switch
     Case Evento["KeyCode"] =   9: Temp=False
     Case Evento["KeyCode"] = -59: Dialog_F1()
     Case Evento["KeyCode"] = -68  :
          Temp=False
          Relatorios()
     Case Evento["KeyCode"] =  27:
          Temp=False
          Switch
            Case Campo="TG_TPITEM"         : Campo="NO"
            Case Campo="TG_FAMI"           : Campo="TG_TPITEM"
            Case Campo="TG_GRP"            : Campo="TG_FAMI"
            Case Campo="TG_MARCA"          : Campo="TG_GRP"
            Case Campo="TG_COR_TECIDO"     : Campo="TG_MARCA"
            Case Campo="TG_STATUS"         : Campo="TG_COR_TECIDO"
            Case Campo="TG_LOCAL"          : Campo="TG_STATUS"
            Case Campo="TG_OPRELCODALF"    : Campo="TG_LOCAL"
            Case Campo="YES" Or Campo="NO" : Campo="TG_TPITEM"
          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_TPITEM"     : Campo="TG_FAMI"
                    Case Campo="TG_FAMI"       : Campo="TG_GRP"
                    Case Campo="TG_GRP"        : Campo="TG_MARCA"
                    Case Campo="TG_MARCA"      : Campo="TG_COR_TECIDO"
                    Case Campo="TG_COR_TECIDO" : Campo="TG_STATUS"
                    Case Campo="TG_STATUS"     : Campo="TG_LOCAL"
                    Case Campo="TG_LOCAL"      : Campo="TG_OPRELCODALF"
                         VSDGLOCAL=ControlValue("TG_LOCAL")
                         If Upper(VSDGLOCAL)="TODAS"
                            Then LOCAL=""
                            Else LOCAL=VSDGLOCAL
                         EndIf
                    Case Campo="TG_OPRELCODALF":Campo="YES"
                  EndSwitch
          EndIf
          RefreshDialog
   EndSwitch
EndIf
If Campo="TG_LOCAL"
   Then MSG_CAMPO="Use '..' ou Em Branco=Todas"
EndIf
Monta_Prompt(MSG_CAMPO,TECLA)
Return Temp
EndProc


;*******************************************************************************
;* Rotina                                                                      *
;*******************************************************************************
Proc SD_Dialog2(Disparo,Campo,Evento,Elemento)
Temp=True
MSG_CAMPO=""
TECLA    =""
If Disparo="OPEN"  Then AoCriarShowDialog() EndIf
If Disparo="EVENT" And Evento["Type"]="KEY" Then
   Switch
     Case Evento["KeyCode"] = 9    : Temp=False
     Case Evento["KeyCode"] =  27  :
          Temp=False
          Switch
            Case Campo="TG_OPRELATORIO"    : Campo="NO"
            Case Campo="YES" Or Campo="NO" : Campo="TG_OPRELATORIO"
          EndSwitch
     Case Evento["KeyCode"] = 13:
          Temp=False

          If Checa_TAG()           
             Then Switch
                    Case Campo="TG_OPRELATORIO"  : 
                         VSDGOPRELATORIO=ControlValue("TG_OPRELATORIO")
                         Campo="YES"
                  EndSwitch
          EndIf
   EndSwitch
EndIf
Switch
  Case Campo="TG_OPRELATORIO":
     MSG_CAMPO="Selecione o op‡„o desejada !"
     TECLA    ="=Selecionar  "
Endswitch
Monta_Prompt(MSG_CAMPO,TECLA)
Return Temp
EndProc

;*******************************************************************************
;* Rotina Impressao                                                            *
;*******************************************************************************
Proc Relatorios()
private ncampo,ntecla,nmsg_campo

ncampo    =campo
nmsg_campo=msg_campo
ntecla    =tecla

ShowDialog "Parƒmetros" Proc "SD_Dialog2"
Trigger "OPEN","ARRIVE"
Key "F1","ENTER","ESC","TAB"
 @ 01,01 Height 14 Width 55

  Label @ 00,00 "Modelos de Relat¢rios"  For "TG_OPRELATORIO"
  PickDynArray @1,01 Height 8 width 51
   Columns 1
    Array_OpRelatorios
     Tag "TG_OPRELATORIO"
      To VSDGOPRELATORIO

  Pushbutton @ 10,10 width 11 "~O~k"      OK     Default Value "Ok" Tag "YES" To BottonValue
  Pushbutton @ 10,24 width 11 "~C~ancela" CANCEL                    Tag "NO"  To BottonValue
EndDialog
If RetVal
   Then ConfOpcoes("Gravar")
EndIf

campo    =ncampo
msg_campo=nmsg_campo
tecla    =ntecla
EndProc ;(Relatorios)

;************************************
;* ROTINA PARA Ler/Gravacao Opcao   *
;************************************
Proc ConfOpcoes(Opcao)
Private Opcao

Switch
  Case Opcao="Ler":
       DynArray Array_OpRelatorios[]
       Array_OpRelatorios[01]="01 - Itens +Comiss„o"
       Array_OpRelatorios[02]="02 - Itens +Peso Liquido"
       Array_OpRelatorios[03]="03 - Itens +Comiss„o/Descr.Complementar"
       Array_OpRelatorios[04]="04 - Itens  Marca/Descr.Complementar"
       Array_OpRelatorios[05]="05 - Itens + Comiss„o/Localiza‡„o"
       Array_OpRelatorios[06]="06 - Localiza‡„o/Itens + Comiss„o"
       Array_OpRelatorios[07]="07 - Itens  Marca/Descr.Complementar II"
       If IsFile("OR_0120.sc")
           Then Play "OR_0120"
           Else VSDGOPRELATORIO  =1
                VSDGNCASASDEC    =3
       EndIf
  Case Opcao="Gravar":
       FileWrite        "OR_0120.sc" From ";****** Variaveis de Configura‡„o Modelo Relatorio Vise Informatica"+"\n"
       FileWrite Append "OR_0120.sc" From "VSDGOPRELATORIO="+StrVal(VSDGOPRELATORIO)+"\n"
EndSwitch
EndProc ;

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

ConfOpcoes("Ler")
ClearAll

VSDGTPITEM     = ""
VSDGFAMI       = ""
VSDGGRP        = ""
VSDGMARCA      = ""
VSDGCORTECIDO  = ""
VSDGLOCAL      = ""
VSDGSTATUS     =""

While True

  ShowDialog "Rela‡„o de Itens p/ Contagem" Proc "SD_Dialog"
  Trigger "OPEN","ARRIVE"
  Key "F1","ENTER","ESC","TAB",-68,
      -104, -105, -106, -107, -108, -109, -110, -111, -112, -113, -139, -140  
  @ 04,12   Height 21 Width 55

    Label  @ 00,00 "Tipo Estoque"  For "TG_TPITEM"
    Accept @ 01,01 Width 04 "A1"  Picture "!" Tag "TG_TPITEM"      To VSDGTPITEM
    Accept @ 01,06 Width 23 "A20" Picture "!*!" Tag "TG_NOMTPITEM" To VSDGNOMTPITEM

    Label  @ 02,00 "Familia"  For "TG_FAMI"
    Accept @ 03,01 Width 06 "A3"  Picture "#*#" Tag "TG_FAMI"      To VSDGFAMI
    Accept @ 03,08 Width 28 "A25" Picture "!*!" Tag "TG_NOMFAMI"   To VSDGNOMFAMI

    Label  @ 04,00 "Grupo"  For "TG_GRP"
    Accept @ 05,01 Width 06 "A3"  Picture "#*#" Tag "TG_GRP"       To VSDGGRP
    Accept @ 05,08 Width 28 "A25" Picture "!*!" Tag "TG_NOMGRP"    To VSDGNOMGRP

    Label  @ 06,00 "Marca" For "TG_MARCA"
    Accept @ 07,01 Width 06 "A3"  Picture "#*#" Tag "TG_MARCA"     To VSDGMARCA
    Accept @ 07,08 Width 28 "A25" Picture "!*!" Tag "TG_NOMMARCA"  To VSDGNOMMARCA

    Label  @ 08,00 "Cor" For "TG_COR_TECIDO"
    Accept @ 09,01 Width 07 "A4"  Picture "#*#" Tag "TG_COR_TECIDO"    To VSDGCORTECIDO
    Accept @ 09,09 Width 28 "A25" Picture "!*!" Tag "TG_NOMCOR_TECIDO" To VSDGNOMCORTECIDO

    Label  @ 10,00 "Status do Item" For "TG_STATUS"
    Accept @ 11,01 Width 04 "A1"  Picture "1,2,3" Tag "TG_STATUS" To VSDGSTATUS
    Accept @ 11,06 Width 23 "A12" Picture "!*!" Tag "TG_NOMSTATUS" To VSDGNOMSTATUS

    Label  @ 12,00 "Localiza‡„o"  For "TG_LOCAL"
    Accept @ 13,01 Width 23 "A20"  Picture "!*!" Tag "TG_LOCAL" To VSDGLOCAL

    Label  @ 14,00 "Ordem" For "TG_OPRELCODALF"
    Accept @ 15,01 Width 04 "A1"  Picture "1,2" Tag "TG_OPRELCODALF" To VSDGOPRELCODALF
    Accept @ 15,06 Width 15 "A12" Picture "!*!" Tag "TG_NOMOPRELCODALF" To VSDGNOMOPRELCODALF

    Pushbutton @ 17,14 width 11 "~O~k"      OK     Default Value "Ok"  Tag "YES" To BottonValue
    Pushbutton @ 17,28 width 11 "~C~ancela" CANCEL                     Tag "NO"  To BottonValue

  EndDialog
  If Not RetVal Then QuitLoop EndIf

  DISPOSITIVO()
  If OK="" Then Loop EndIf

  AGUARDE("Aguarde, gerando o relat¢rio")

  SELECIONA()

  If IsEmpty("Answer")
     Then MENSAGEM("N„o existem registros a processar")
          Loop
  EndIf
  
  If SYS_CODIGO_CLIENTE="0319"
     Then {Ask} {\\Sistemas\\Estoque\\Itens}
          Moveto [Codigo do Item   ] Example "CodI"
          Moveto [Codigo Fornecedor] Example "CodF"
          {Ask} {Answer}
          Moveto [Codigo do Item   ] Example "CodI" TypeIn " ,Changeto _CodF"
          Do_It!
          ClearAll
  EndIf   

  If SubStr(Array_OpRelatorios[VSDGOPRELATORIO],1,2)="01"
     Then If VSDGOPRELCODALF="1"
             Then CopyReport "\\Base\\Sistemas\\Estoque\\Itens" "13" "Answer" "R"
             Else CopyReport "\\Base\\Sistemas\\Estoque\\Itens" "14" "Answer" "R"
          EndIf
  EndIf
  If SubStr(Array_OpRelatorios[VSDGOPRELATORIO],1,2)="02"
     Then If VSDGOPRELCODALF="1"
             Then CopyReport "\\Base\\Sistemas\\Estoque\\RC_Itens" "R" "Answer" "R"
             Else CopyReport "\\Base\\Sistemas\\Estoque\\RC_Itens" "1" "Answer" "R"
          EndIf
  EndIf
  If SubStr(Array_OpRelatorios[VSDGOPRELATORIO],1,2)="03"
     Then If VSDGOPRELCODALF="1"
             Then CopyReport "\\Base\\Sistemas\\Estoque\\RC_Itens" "4" "Answer" "R"
             Else CopyReport "\\Base\\Sistemas\\Estoque\\RC_Itens" "5" "Answer" "R"
          EndIf
  EndIf
  If SubStr(Array_OpRelatorios[VSDGOPRELATORIO],1,2)="04"
     Then If VSDGOPRELCODALF="1"
             Then CopyReport "\\Base\\Sistemas\\Estoque\\RC_Itens" "6" "Answer" "R"
             Else CopyReport "\\Base\\Sistemas\\Estoque\\RC_Itens" "7" "Answer" "R"
          EndIf
  EndIf
  If SubStr(Array_OpRelatorios[VSDGOPRELATORIO],1,2)="05"
       Then If VSDGOPRELCODALF="1"
               Then CopyReport "\\Base\\Sistemas\\Estoque\\RC_Itens" "2" "Answer" "R"
               Else CopyReport "\\Base\\Sistemas\\Estoque\\RC_Itens" "3" "Answer" "R"
            EndIf
  EndIf
  If SubStr(Array_OpRelatorios[VSDGOPRELATORIO],1,2)="06"
       Then If VSDGOPRELCODALF="1"
               Then CopyReport "\\Base\\Sistemas\\Estoque\\RC_Itens" "10" "Answer" "R"
               Else CopyReport "\\Base\\Sistemas\\Estoque\\RC_Itens" "11" "Answer" "R"
            EndIf
  EndIf
  If SubStr(Array_OpRelatorios[VSDGOPRELATORIO],1,2)="07"
       Then If VSDGOPRELCODALF="1"
               Then CopyReport "\\Base\\Sistemas\\Estoque\\RC_Itens" "12" "Answer" "R"
               Else CopyReport "\\Base\\Sistemas\\Estoque\\RC_Itens" "13" "Answer" "R"
            EndIf
  EndIf

  IMPRIREL("Answer","R")

  Delete "Answer"
EndWhile
ClearAll
Release Vars All
Release Procs All

