;** Rm_4202A *******************************************************************
;*  Relatorio p/ Conferencia Programacao de Corte                              *
;*******************************************************************************
;Autor           : Vise Informatica (VISERP)
;Desenvolvido    : 14/11/2014 por Andrey Fillipe
;Ultima Alteracao:   /  /     por
;Motivo Alteracao:

;*******************************************************************************
;* Rotina para Selecionar Registros                                            *
;*******************************************************************************
Proc Seleciona()
Private CONT
ClearAll

TITULOA = "   PROGRAMACAO DE CORTE    "
TITULOB = "     PRODUCAO DE CORTE     "
TITULOC = "PROGRAMACAO INTERNA/EXTERNA"
TITULOD = " PRODUCAO INTERNA/EXTERNA  "

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
  
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

{Ask} TypeIn Tabela Enter TypeIn "Delete"
Moveto[Diferenca Itens Pecas] TypeIn "Blank"
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="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="YES"
                  EndSwitch
          EndIf
          RefreshDialog
   EndSwitch
EndIf
Switch
  Case Campo="TG_DTFIM":
     MSG_CAMPO="Informe a Data Final"
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        = ""
VSDGDTINI          = BlankDate()
VSDGDTFIM          = BlankDate()
                 
While True

  ShowDialog "Relat¢rio Conferˆncia Corte" 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 09 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

    Pushbutton @ 05,14 width 11 "~O~k"      OK     Default Value "Ok" Tag "YES" To BottonValue
    Pushbutton @ 05,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)

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

  If IsEmpty(Tabela)
     Then MENSAGEM("N„o foi detectada nenhuma diferen‡a")
          Delete Tabela
          Loop
  EndIf
  
  IMPRIREL(Tabela,"R")

  Delete Tabela
  Delete Tabela2

EndWhile
ClearAll
Release Vars All
Release Procs All
