;** Rm_4202 ********************************************************************
;*  Relatorio p/ Conferencia Requsicao                                         *
;*******************************************************************************
;Autor           : Vise Informatica (VISERP)
;Desenvolvido    : 30/09/2011 por Bruno Carvalho
;Ultima Alteracao: 14/11/2014 por Andrey Fillipe
;Motivo Alteracao: Desmembrado esse relatorio em 07 "RM_4202A" e 08 "RM_4202B"
;
;*******************************************************************************
;* Rotina para Selecionar Registros                                            *
;*******************************************************************************
;Proc Seleciona(TIPO)
;Private TIPO,CONT
;ClearAll
;
;TITULOA = "   PROGRAMACAO DE CORTE    "
;TITULOB = "     PRODUCAO DE CORTE     "
;TITULOC = "PROGRAMACAO INTERNA/EXTERNA"
;TITULOD = " PRODUCAO INTERNA/EXTERNA  "
;
;Switch 
;  Case TIPO="CORTE" :
;      For CONT From 1 To 2
;      Switch
;       Case CONT = 1 :
;            {Ask} TypeIn "\\Sistemas\\Faccao\\Cfacc" Enter
;            Moveto [Numero_Corte           ] Check TypeIn "as Numero"
;            Moveto [Codigo da Empresa      ] Check TypeIn "~VSDGEMPRESA.."
;            Moveto [Nome Fantasia Empresa  ] Check
;            Moveto [Data_Programacao       ] Check TypeIn ">=~VSDGDTINI,<=~VSDGDTFIM, as Data"
;            Moveto [Hora_Programacao       ] Check TypeIn "as Hora"
;            Moveto [Situacao_Programacao   ] Check TypeIn "as ProgCorte"
;            Do_It!
;            ClearAll
;            
;            {Ask} {Answer}                                                           
;            Moveto [ProgCorte              ] TypeIn "Changeto ProgC"
;            Do_It!
;            ClearAll
;            
;            {Ask} {Answer}
;            Moveto [Numero                 ] Example "ncort"
;            Moveto [Codigo da Empresa      ] Example "codemp"
;            Moveto [Nome Fantasia Empresa  ] Example "fanemp"
;            Moveto [Data                   ] Example "dtprg"
;            Moveto [Hora                   ] Example "hprog"
;            Moveto [ProgCorte              ] Example "ProgC"
;            {Ask} TypeIn Tabela Enter TypeIn "Fast Insert"
;            Moveto [Numero                 ] Example "ncort"
;            Moveto [Codigo da Empresa      ] Example "codemp"
;            Moveto [Nome Fantasia Empresa  ] Example "fanemp"
;            Moveto [Data                   ] Example "dtprg"
;            Moveto [Hora                   ] Example "hprog"
;            Moveto [ProgCorte              ] Example "ProgC"
;            Do_It!
;            ClearAll
;       Case CONT = 2 :
;            {Ask} TypeIn "\\Sistemas\\Faccao\\Pcfacc" Enter
;            Moveto [Numero_Producao_Corte  ] Check TypeIn "as Numero"
;            Moveto [Codigo da Empresa      ] Check TypeIn "~VSDGEMPRESA.."
;            Moveto [Nome Fantasia Empresa  ] Check
;            Moveto [Data_Producao          ] Check TypeIn ">=~VSDGDTINI,<=~VSDGDTFIM, as Data"
;            Moveto [Destino_Producao       ] Check
;            Moveto [Situacao_Producao      ] Check TypeIn "as ProgCorte"
;            Do_It!
;            ClearAll
;            
;            {Ask} {Answer}
;            Moveto [ProgCorte              ] TypeIn "Changeto ProdC"
;            Do_It!
;            ClearAll
;            
;            {Ask} {Answer}
;            Moveto [Numero                 ] Example "nprod"
;            Moveto [Codigo da Empresa      ] Example "codemp"
;            Moveto [Nome Fantasia Empresa  ] Example "fanemp"
;            Moveto [Data                   ] Example "dtprod"
;            Moveto [Destino_Producao       ] Example "destp"
;            Moveto [ProgCorte              ] Example "ProdC"
;            {Ask} TypeIn Tabela Enter TypeIn "Fast Insert"
;            Moveto [Numero                 ] Example "nprod"
;            Moveto [Codigo da Empresa      ] Example "codemp"
;            Moveto [Nome Fantasia Empresa  ] Example "fanemp"
;            Moveto [Data                   ] Example "dtprod"
;            Moveto [Destino_Producao       ] Example "destp"
;            Moveto [ProgCorte              ] Example "ProdC"
;            Do_It!
;            ClearAll
;      EndSwitch
;
;      Tabela2=Cria_Temp(PrivDir())
;      Rename "Answer" Tabela2 
;
;      ;*** Itens PadrÆo ****
;      {Ask} TypeIn Tabela2 Enter
;      Moveto [Numero                 ] Example "ncort"
;      Switch 
;       Case CONT = 1 :
;            {Ask} TypeIn "\\Sistemas\\Faccao\\Cfacri" Enter
;            Moveto [Numero_Corte           ] Check TypeIn "_ncort, as Numero"
;            Moveto [Quantidade Programada  ] TypeIn "Calc Sum as Qtd"
;            Do_It!
;            ClearAll
;       Case CONT = 2 :
;            {Ask} TypeIn "\\Sistemas\\Faccao\\Pcfacri" Enter
;            Moveto [Numero_Producao_Corte  ] Check TypeIn "_ncort, as Numero"
;            Moveto [Quantidade Produzida   ] TypeIn "Calc Sum as Qtd"
;            Do_It!
;            ClearAll 
;      EndSwitch 
;          
;      {Ask} {Answer}
;      Moveto [Numero                 ] Example "ncort"
;      Moveto [Qtd                    ] TypeIn "_qtd"
;      {Ask} TypeIn Tabela Enter TypeIn "Fast"
;      Moveto [Numero                 ] Example "ncort"
;      Moveto [Soma Itens Pecas       ] TypeIn "Changeto _qtd"
;      Do_It!
;      ClearAll     
;      
;      ;*** Itens Grade ****
;      {Ask} TypeIn Tabela2 Enter
;      Moveto [Numero                 ] Example "ncort"
;      Switch 
;       Case CONT = 1 :
;            {Ask} TypeIn "\\Sistemas\\Faccao\\CfacriG" Enter
;            Moveto [Numero_Corte           ] Check TypeIn "_ncort, as Numero"
;            Moveto [Quantidade Programada  ] TypeIn "Calc Sum as Qtd"
;            Do_It!
;            ClearAll
;       Case CONT = 2 :
;            {Ask} TypeIn "\\Sistemas\\Faccao\\PcfacriG" Enter
;            Moveto [Numero_Producao_Corte  ] Check TypeIn "_ncort, as Numero"
;            Moveto [Quantidade Produzida   ] TypeIn "Calc Sum as Qtd"
;            Do_It!
;            ClearAll
;      EndSwitch       
;
;      {Ask} {Answer}
;      Moveto [Numero                 ] Example "ncort"
;      Moveto [Qtd                    ] TypeIn "_qtd"
;      {Ask} TypeIn Tabela Enter TypeIn "Fast"
;      Moveto [Numero                 ] Example "ncort"
;      Moveto [Soma Itens Grade Pecas ] TypeIn "Changeto _qtd"
;      Do_It!
;      ClearAll
;      EndFor
;  Case TIPO="PRODUCAO" :
;      For CONT From 1 To 2
;      Switch
;       Case CONT = 1 :
;            {Ask} TypeIn "\\Sistemas\\Faccao\\Pfacc" Enter
;            Moveto [Numero_Programacao     ] Check TypeIn "as Numero"
;            Moveto [Codigo da Empresa      ] Check TypeIn "~VSDGEMPRESA.."
;            Moveto [Nome Fantasia Empresa  ] Check
;            Moveto [Data_Programacao       ] Check TypeIn ">=~VSDGDTINI,<=~VSDGDTFIM, as Data"
;            Moveto [Hora_Programacao       ] Check TypeIn "as Hora"
;            Moveto [Destino_Producao       ] Check
;            Moveto [Situacao_Programacao   ] Check TypeIn "as ProgCorte"
;            Do_It!
;            ClearAll
;            
;            {Ask} {Answer}
;            Moveto [ProgCorte              ] TypeIn "Changeto ProgIE"
;            Do_It!
;            ClearAll
;            
;            {Ask} {Answer}
;            Moveto [Numero                 ] Example "ncort"
;            Moveto [Codigo da Empresa      ] Example "codemp"
;            Moveto [Nome Fantasia Empresa  ] Example "fanemp"
;            Moveto [Data                   ] Example "dtprg"
;            Moveto [Hora                   ] Example "hprog"
;            Moveto [Destino_Producao       ] Example "Dprog"
;            Moveto [ProgCorte              ] Example "ProgC"
;            {Ask} TypeIn Tabela Enter TypeIn "Fast Insert"
;            Moveto [Numero                 ] Example "ncort"
;            Moveto [Codigo da Empresa      ] Example "codemp"
;            Moveto [Nome Fantasia Empresa  ] Example "fanemp"
;            Moveto [Data                   ] Example "dtprg"
;            Moveto [Hora                   ] Example "hprog"
;            Moveto [Destino_Producao       ] Example "Dprog"
;            Moveto [ProgCorte              ] Example "ProgC"
;            Do_It!
;            ClearAll
;       Case CONT = 2 :
;            {Ask} TypeIn "\\Sistemas\\Faccao\\Rfacc" Enter
;            Moveto [Numero_Producao        ] Check TypeIn "as Numero"
;            Moveto [Codigo da Empresa      ] Check TypeIn "~VSDGEMPRESA.."
;            Moveto [Nome Fantasia Empresa  ] Check
;            Moveto [Data_Producao          ] Check TypeIn ">=~VSDGDTINI,<=~VSDGDTFIM, as Data"
;            Moveto [Destino_Producao       ] Check
;            Moveto [Situacao_Producao      ] Check TypeIn "as ProgCorte"
;            Do_It!
;            ClearAll
;            
;            {Ask} {Answer}
;            Moveto [ProgCorte              ] TypeIn "Changeto ProdIE"
;            Do_It!
;            ClearAll
;            
;            {Ask} {Answer}
;            Moveto [Numero                 ] Example "nprod"
;            Moveto [Codigo da Empresa      ] Example "codemp"
;            Moveto [Nome Fantasia Empresa  ] Example "fanemp"
;            Moveto [Data                   ] Example "dtprod"
;            Moveto [Destino_Producao       ] Example "destp"
;            Moveto [ProgCorte              ] Example "ProdC"
;            {Ask} TypeIn Tabela Enter TypeIn "Fast Insert"
;            Moveto [Numero                 ] Example "nprod"
;            Moveto [Codigo da Empresa      ] Example "codemp"
;            Moveto [Nome Fantasia Empresa  ] Example "fanemp"
;            Moveto [Data                   ] Example "dtprod"
;            Moveto [Destino_Producao       ] Example "destp"
;            Moveto [ProgCorte              ] Example "ProdC"
;            Do_It!
;            ClearAll
;      EndSwitch
;
;      Tabela2=Cria_Temp(PrivDir())
;      Rename "Answer" Tabela2 
;
;      ;*** Itens PadrÆo ****
;      {Ask} TypeIn Tabela2 Enter
;      Moveto [Numero                 ] Example "ncort"
;      Switch 
;       Case CONT = 1 :
;            {Ask} TypeIn "\\Sistemas\\Faccao\\Pfacri" Enter
;            Moveto [Numero_Programacao     ] Check TypeIn "_ncort, as Numero"
;            Moveto [Quantidade Programada  ] TypeIn "Calc Sum as Qtd"
;            Do_It!
;            ClearAll
;       Case CONT = 2 :
;            {Ask} TypeIn "\\Sistemas\\Faccao\\Rfacri" Enter
;            Moveto [Numero_Producao        ] Check TypeIn "_ncort, as Numero"
;            Moveto [Quantidade Produzida   ] TypeIn "Calc Sum as Qtd"
;            Do_It!
;            ClearAll 
;      EndSwitch 
;          
;      {Ask} {Answer}
;      Moveto [Numero                 ] Example "ncort"
;      Moveto [Qtd                    ] TypeIn "_qtd"
;      {Ask} TypeIn Tabela Enter TypeIn "Fast"
;      Moveto [Numero                 ] Example "ncort"
;      Moveto [Soma Itens Pecas       ] TypeIn "Changeto _qtd"
;      Do_It!
;      ClearAll
;      
;      ;*** Itens Grade ****
;      {Ask} TypeIn Tabela2 Enter
;      Moveto [Numero                 ] Example "ncort"
;      Switch 
;       Case CONT = 1 :
;            {Ask} TypeIn "\\Sistemas\\Faccao\\PfacriG" Enter
;            Moveto [Numero_Programacao     ] Check TypeIn "_ncort, as Numero"
;            Moveto [Quantidade Programada  ] TypeIn "Calc Sum as Qtd"
;            Do_It!
;            ClearAll
;       Case CONT = 2 :
;            {Ask} TypeIn "\\Sistemas\\Faccao\\RfacriG" Enter
;            Moveto [Numero_Producao        ] Check TypeIn "_ncort, as Numero"
;            Moveto [Quantidade Produzida   ] TypeIn "Calc Sum as Qtd"
;            Do_It!
;            ClearAll
;      EndSwitch       
;
;      {Ask} {Answer}
;      Moveto [Numero                 ] Example "ncort"
;      Moveto [Qtd                    ] TypeIn "_qtd"
;      {Ask} TypeIn Tabela Enter TypeIn "Fast"
;      Moveto [Numero                 ] Example "ncort"
;      Moveto [Soma Itens Grade Pecas ] TypeIn "Changeto _qtd"
;      Do_It!
;      ClearAll
;      EndFor
;EndSwitch
;
;EndProc   ;  (Seleciona)
;
;*******************************************************************************
;* Rotina Processa                                                             *
;*******************************************************************************
;Proc Processa()
;
;Edit Tabela
;Scan
;  [Diferenca Itens Pecas]=NDecimal([Soma Itens Pecas]-[Soma Itens Grade Pecas],2)
;  If [Diferenca Itens Pecas]=0 Or [Diferenca Itens Pecas]=-0    Then [Diferenca Itens Pecas]=BlankNum() EndIf
;  If SYS_CLIENTE_CONFEC=""
;     Then
;          [Soma Itens Pecas     ]=BlankNum()
;          [Diferenca Itens Pecas]=BlankNum()
;  EndIf   
;
;EndScan
;Do_It!
;ClearAll
;
;EndProc
;
;*******************************************************************************
;* Rotina                                                                      *
;*******************************************************************************
;Proc SD_Dialog(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"] = -59: Dialog_F1()
;     Case Evento["KeyCode"] =  27:
;          Temp=False
;          Switch
;            Case Campo="TG_EMPRESA"        : Campo="NO"
;            Case Campo="TG_DTINI"          : Campo="TG_EMPRESA"
;            Case Campo="TG_DTFIM"          : Campo="TG_DTINI"
;            Case Campo="TG_OPRELATORIO"    : Campo="TG_DTFIM"
;            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_DTINI"
;                    Case Campo="TG_DTINI"         : Campo="TG_DTFIM"
;                    Case Campo="TG_DTFIM"         : Campo="TG_OPRELATORIO"
;                    Case Campo="TG_OPRELATORIO" :
;                         VSDGOPRELATORIO=ControlValue("TG_OPRELATORIO")
;                         Switch
;                            Case VSDGOPRELATORIO="1": VSDGNOMOPRELATORIO="PROGRAMACAO DE CORTE"
;                            Case VSDGOPRELATORIO="2": VSDGNOMOPRELATORIO="PRODUCAO INTERNA/EXTERNA"
;                            OtherWise               : VSDGOPRELATORIO="3"
;                                                      VSDGNOMOPRELATORIO="AMBOS"
;                         EndSwitch
;                         Campo="YES"
;                  EndSwitch
;          EndIf
;          RefreshDialog
;   EndSwitch
;EndIf
;Switch
;  Case Campo="TG_DTFIM":
;     MSG_CAMPO="Informe a Data Final"
;  Case Campo="TG_OPRELATORIO":
;     MSG_CAMPO="1=Programa‡„o de Corte   2=Produ‡„o Interna/Externa   3=AMBOS "
;Endswitch
;Monta_Prompt(MSG_CAMPO,TECLA)
;Return Temp
;EndProc
;
;*******************************************************************************
;* ROTINA PRINCIPAL                                                            *
;*******************************************************************************
;AutoLib="\\Sistemas\\Cadastro\\Bib_Show,\\Sistemas\\Cadastro\\Bibliot"
;LimpAguarde()
;
;If Not IsAssigned(SYS_CLIENTE_CONFEC)  Then SYS_CLIENTE_CONFEC="*"  EndIf
;
;VSDGEMPRESA        = ""
;VSDGOPRELATORIO    = ""
;VSDGNOMOPRELATORIO = ""
;VSDGDTINI          = BlankDate()
;VSDGDTFIM          = BlankDate()
;                 
;While True
;
;  ShowDialog "Relat¢rio Conferˆncia Requsi‡„o" Proc "SD_Dialog"
;  Trigger "OPEN","ARRIVE"
;  Key "F1","ENTER","ESC","TAB",
;      -104, -105, -106, -107, -108, -109, -110, -111, -112, -113, -139, -140  
;   @ 09,12 Height 11 Width 56
;
;    Label  @ 00,01 "Empresa"  For "TG_EMPRESA"
;    Accept @ 01,02 Width 07 "A4"  Picture "[&,#][#*#]" Tag "TG_EMPRESA"    To VSDGEMPRESA
;    Accept @ 01,10 Width 24 "A20" Picture "!*!" Tag "TG_NOMEMPRESA" To VSDGNOMEMP
;
;    Label  @ 02,01 "Per¡odo de emissÆo" For "TG_DTINI"
;    Label  @ 03,01 "de" For "TG_DTINI"
;    Accept @ 03,05 Width 13 "D"  Picture "#[#];.##;.##[##]" Tag "TG_DTINI" To VSDGDTINI
;    Label  @ 03,16 "at‚" For "TG_DTFIM"
;    Accept @ 03,21 Width 13 "D"  Picture "#[#];.##;.##[##]" Tag "TG_DTFIM" To VSDGDTFIM
;
;    Label  @ 04,04 "Op‡„o do Relat¢rio" For "TG_OPRELATORIO"
;    Accept @ 05,05 Width 04 "A1"  Picture "1,2,3" Tag "TG_OPRELATORIO" To VSDGOPRELATORIO
;    Accept @ 05,10 Width 28 "A25"  Picture "!*!" Tag "TG_NOMOPRELANASINT2" To VSDGNOMOPRELATORIO
;
;    Pushbutton @ 07,14 width 11 "~O~k"      OK     Default Value "Ok" Tag "YES" To BottonValue
;    Pushbutton @ 07,28 width 11 "~C~ancela" CANCEL                    Tag "NO"  To BottonValue
;
;  EndDialog
;  If Not RetVal Then QuitLoop EndIf
If Not Valida_ShowDialog("") Then Loop EndIf
;
;  If IsBlank(VSDGDTFIM)
;     Then Mensagem("Data Final Invalida !")
;          Loop
;  EndIf
;
;  DISPOSITIVO()
;  If OK="" Then Loop EndIf
;
;  AGUARDE("Aguarde, gerando o relat¢rio")
;  Tabela=Cria_Temp(PrivDir())
;  Copy "\\Base\\Sistemas\\Faccao\\RM_4202" Tabela
;  Empty(Tabela)
;
;  Switch
;    Case VSDGOPRELATORIO="1" : Seleciona("CORTE")
;    Case VSDGOPRELATORIO="2" : Seleciona("PRODUCAO")
;    OtherWise                : Seleciona("CORTE")
;                               Seleciona("PRODUCAO")  
;  EndSwitch
;
;  If IsEmpty(Tabela)
;     Then MENSAGEM("N„o existem registros a processar")
;          Delete Tabela
;          Loop
;  EndIf
;
;  Processa()
;
;  IMPRIREL(Tabela,"R")
;
;  Delete Tabela
;  Delete Tabela2
;
;EndWhile
;ClearAll
;Release Vars All
;Release Procs All