;** Rm_0102 ********************************************************************
;*  Emissao do Inventario Terceirizados                                        *
;*******************************************************************************
;Autor           : Vise Informatica (VISERP)
;Desenvolvido    : 31/05/2010 por Bruno Carvalho
;Ultima Alteracao:   /  /     por 
;Motivo Alteracao: 

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

{Ask} {Pfacc}
Moveto [Numero_Programacao    ] Example "num"
Moveto [Codigo da Empresa     ] TypeIn "~VSDGEMPRESA.."
Moveto [Codigo                ] TypeIn "~VSDGDESTINAT.."
Moveto [Situacao_Programacao  ] TypeIn "Not FINALIZADA"
Moveto [Destino_Producao      ]
Switch
  Case VSDGOPDEST="1": TypeIn "Not INTERNO"
  Case VSDGOPDEST="2": TypeIn "FACCAO"
  Case VSDGOPDEST="3": TypeIn "ESTAMPARIA"
  Case VSDGOPDEST="4": TypeIn "BORDARIA"
  Case VSDGOPDEST="5": TypeIn "LAVANDERIA"
  Case VSDGOPDEST="6": TypeIn "OUTROS"
EndSwitch
{Ask} {PfacRI} Check
Moveto [Numero_Programacao    ] Example "num"
Do_It!
ClearAll

{Ask} {Answer}
Moveto [Quantidade Produzida] TypeIn "Changeto Blank"
Do_It!
ClearAll

Tabela=Cria_Temp(PrivDir())
Rename "Answer" Tabela

{Ask} TypeIn Tabela Enter
Moveto [Numero_Programacao    ] Example "num"
{Ask} {Rfacc}
Moveto [Numero_Producao       ] Example "numprod"
Moveto [Numero_Programacao    ] Check Example "num"
{Ask} {RfacRI} Check
Moveto [Numero_Producao       ] Example "numprod"
Do_It!
ClearAll

CoEdit Tabela,"Answer"
Scan

  Moveto Tabela
  Moveto [Numero_Programacao]
  Locate [Answer->Numero_Programacao],[Answer->Codigo do Item]
  If RetVal
     Then [Quantidade Produzida  ]=[Quantidade Produzida  ]+[Answer->Quantidade Produzida  ]
  EndIf
  Moveto "Answer"

EndScan
Do_It!
ClearAll

{Ask} TypeIn Tabela Enter TypeIn "Fast Delete"
Moveto [Quantidade Programada] Example "qtd"
Moveto [Quantidade Produzida ] TypeIn ">=" Example "qtd"
Do_It!
ClearAll

{Ask} {Pfacc}
Moveto [Numero_Programacao    ] Check Example "num"
Moveto [Codigo da Empresa     ] Check
Moveto [Nome Fantasia Empresa ] Check
Moveto [Data_Programacao      ] Check
Moveto [Destino_Producao      ] Check
Moveto [Codigo                ] Check
Moveto [Nome Fantasia EmitDest] Check
Moveto [Razao Social          ] Check
Moveto [Situacao_Programacao  ] Check
{Ask} TypeIn Tabela Enter Check
Moveto [Numero_Programacao    ] Example "num"
Do_It!
ClearAll


EndProc   ; (Seleciona)

;*******************************************************************************
;* 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()

           If Campo="TG_OPDEST"
              Then ShowPopup " Op‡”es " @ 05,11
                        "~1~= Todos            ": " " : "1",
                        "~2~= Fac‡”es          ": " " : "2",
                        "~3~= Estamparias      ": " " : "3",
                        "~4~= Bordarias        ": " " : "4",
                        "~5~= Lavanderias      ": " " : "5",
                        "~6~= Outros           ": " " : "6"
                   EndMenu
                    To MenuVar
                       If MenuVar<>"Esc"
                          Then VSDGOPDEST=MenuVar
                               Switch
                                 Case VSDGOPDEST="1": VSDGNOMOPDEST="Todos             "
                                 Case VSDGOPDEST="2": VSDGNOMOPDEST="Fac‡”es           "
                                 Case VSDGOPDEST="3": VSDGNOMOPDEST="Estamparias       "
                                 Case VSDGOPDEST="4": VSDGNOMOPDEST="Bordarias         "
                                 Case VSDGOPDEST="5": VSDGNOMOPDEST="Lavanderias       "
                                 Case VSDGOPDEST="6": VSDGNOMOPDEST="Outros            "
                               EndSwitch
                       EndIf
           EndIf

     Case Evento["KeyCode"] =  27:
          Temp=False
          Switch
            Case Campo="TG_EMPRESA"       : Campo="NO"
            Case Campo="TG_OPDEST"        : Campo="TG_EMPRESA"
            Case Campo="TG_DESTINAT"      : Campo="TG_OPDEST"
            Case Campo="TG_OPMODEL"       : Campo="TG_DESTINAT"
            Case Campo="YES" Or Campo="NO": Campo="TG_EMPRESA"
          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_EMPRESA"    : Campo="TG_OPDEST"
                    Case Campo="TG_OPDEST"     :
                         VSDGOPDEST=ControlValue("TG_OPDEST")
                         Switch
                           Case VSDGOPDEST="1": VSDGNOMOPDEST="Todos             "
                           Case VSDGOPDEST="2": VSDGNOMOPDEST="Fac‡”es           "
                           Case VSDGOPDEST="3": VSDGNOMOPDEST="Estamparias       "
                           Case VSDGOPDEST="4": VSDGNOMOPDEST="Bordarias         "
                           Case VSDGOPDEST="5": VSDGNOMOPDEST="Lavanderias       "
                           Case VSDGOPDEST="6": VSDGNOMOPDEST="Outros            "
                           OtherWise: 
													      VSDGOPDEST="1": VSDGNOMOPDEST="Todos             "
                         EndSwitch
                         Campo="TG_DESTINAT"
                    Case Campo="TG_DESTINAT"   : Campo="TG_OPMODEL"
                    Case Campo="TG_OPMODEL"    :
                         VSDGOPMODEL=ControlValue("TG_OPMODEL")
                         If Not IsBlank(VSDGOPMODEL)
                            Then Switch
                                   Case VSDGOPMODEL="1": VSDGNOMOPMODEL="Sint‚tico I"
                                   Case VSDGOPMODEL="2": VSDGNOMOPMODEL="Sint‚tico II"
                                   Case VSDGOPMODEL="3": VSDGNOMOPMODEL="Analˇtico"
                                 EndSwitch
                                 Campo="YES"
                         EndIf
                  EndSwitch
          EndIf
          RefreshDialog
   EndSwitch
EndIf
Switch
  Case Campo="":
     MSG_CAMPO=""
  Case Campo="TG_OPMODEL":
     MSG_CAMPO="Op‡„o: 1=Sint‚tico I  2=Sint‚tico  II 3=Analˇtico"
  Case Campo="TG_OPDEST":
     TECLA="F1=Op‡”es  "
EndSwitch
Monta_Prompt(MSG_CAMPO,TECLA)
Return Temp
EndProc

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

VSDGEMPRESA =""
VSDGOPDEST  ="1"
VSDGDESTINAT=""
VSDGOPMODEL =""

While True
  ShowDialog "Invent rio de terceirizados" Proc "SD_Dialog"
  Trigger "OPEN","ARRIVE"
  Key "F1","ENTER","ESC",
      -104, -105, -106, -107, -108, -109, -110, -111, -112, -113, -139, -140  
   @ 05,12   Height 13 Width 66

    Label  @ 00,00 "Empresa"  For "TG_EMPRESA"
    Accept @ 01,01 Width 07 "A4"  Picture "#*#" Tag "TG_EMPRESA" To VSDGEMPRESA
    Accept @ 01,09 Width 26 "A20" Picture "!*!" Tag "TG_NOMEMP" To VSDGNOMEMP

    Label  @ 02,00 "Op‡”es Destinat rio" For "TG_OPDEST"
    Accept @ 03,04 Width 04 "A1"  Picture "1,2,3,4,5" Tag "TG_OPDEST" To VSDGOPDEST
    Accept @ 03,09 Width 29 "A25"  Picture "!*!" Tag "TG_NOMOPDEST" To VSDGNOMOPDEST

    Label  @ 04,00 "Destinat rio"  For "TG_DESTINAT"
    Accept @ 05,01 Width 07 "A4"  Picture "#*#" Tag "TG_DESTINAT" To VSDGDESTINAT
    Accept @ 05,09 Width 26 "A20" Picture "!*!" Tag "TG_NOMCLI" To VSDGNOMDEST

    Label  @ 06,00 "Modelos de Relat˘rio" For "TG_OPMODEL"
    Accept @ 07,01 Width 04 "A1"  Picture "1,2,3" Tag "TG_OPMODEL" To VSDGOPMODEL
    Accept @ 07,06 Width 29 "A25"  Picture "!*!" Tag "TG_NOMOPMODEL" To VSDGNOMOPMODEL

    Pushbutton @ 09,19 width 11 "~O~k"      OK     Default Value "Ok" Tag "YES" To BottonValue
    Pushbutton @ 09,33 width 11 "~C~ancela" CANCEL                    Tag "NO"  To BottonValue

  EndDialog
  If Not RetVal Then QuitLoop EndIf

  DISPOSITIVO()
  If OK="" Then Loop EndIf

  AGUARDE("Aguarde, Processando Dados")

  Seleciona()

  If IsEmpty("Answer")
     Then MENSAGEM("N„o existem registros a processar")
          Delete "Answer"
          Delete Tabela
          Loop
  EndIf

  Switch
    Case VSDGOPMODEL="1": CopyReport "\\Base\\Sistemas\\Faccao\\Rm_0102" "R" "Answer" "R"
    Case VSDGOPMODEL="2": CopyReport "\\Base\\Sistemas\\Faccao\\Rm_0102" "1" "Answer" "R"
    Case VSDGOPMODEL="3": CopyReport "\\Base\\Sistemas\\Faccao\\Rm_0102" "2" "Answer" "R"
  EndSwitch

  IMPRIREL("Answer","R")

  Delete Tabela
  Delete "Answer"

EndWhile
ClearAll
Release Vars All
Release Procs All
