
;** nĆo usa mais ***
;Ultima Alteracao: 24/08/2017 por Anivel Augusto Rodrigues

;** Consulta Notas Fiscais******************************************************
;*  Consulta de Nota Fiscal                                                    *
;*******************************************************************************
;Autor           : Vise Informatica (VISERP)
;Desenvolvido  em: 14/06/2006 por Jose Luis Ameno da Silva
;Ultima Alteracao: 15/10/2010 por Bruno Carvalho
;Motivo Alteracao: Ajustes Edita_Memo
;Ultima Alteracao: 14/03/2011 por Bruno Carvalho
;Motivo Alteracao: Ajustes Tributacao de ISSQN  
;Ultima Alteracao: 19/03/2013 por Bruno Carvalho
;Motivo Alteracao: Comentado a linha onde utilizava o campo/variavel "NBM"
;Ultima Alteracao: 07/12/2015 por Anivel Augusto Rodrigues
;Motivo Alteracao: exclusao referencia ao campo INSS

;*******************************************************************************
;* Rotina para Gravacao/Leitura do Item                                        *
;*******************************************************************************
Proc Registro_Item(Funcao_Registro)
Private Funcao_Registro
Switch
  Case Table()="Notai":
       Switch
         Case Funcao_Registro="Ler":
           VSD_I_Seq                    =[Item do Documento         ]
    
           VSD_I_Pedido                 =[Numero Pedido_Orcamento   ]
           VSD_I_Pedido_Item            =[Item Pedido_Orcamento     ]
    
           VSD_I_Tipo_Item              =[Tipo do Item              ]
           VSD_I_Codigo_Item            =[Codigo do Item            ]
           VSD_I_Descricao_Item         =[Descricao do Item         ]
    
           VSD_I_Codigo_Cor_Tecido      =[Codigo da Cor_Tecido      ]
           VSD_I_Descricao_Cor_Tecido   =[Descricao da Cor_Tecido   ]
           VSD_I_Tamanho                =[Tamanho                   ]
    
           VSD_I_Quantidade             =[Quantidade                ]
           VSD_I_UN_Item                =[Unidade Fiscal            ]
           VSD_I_Preco_Unitario         =[Preco Unitario            ]
           VSD_I_Taxa_Desconto_Unitario =[Taxa Desconto Unitario    ]
           VSD_I_Valor_Desconto_Unitario=[Valor Desconto Unitario   ]
           VSD_I_Preco_Total            =Round([Preco Total               ],2)
    
           VSD_I_Custo_Unitario         =[Custo Medio Unitario      ]
           VSD_I_Preco_Tabela           =[Preco Unitario Tabela     ]
    
           VSD_I_CFOP                   =[CFO                       ]
           VSD_I_NCM                    =[NCM                       ]
    
           VSD_I_CST_Item               =[Tipo Tributacao           ]
           VSD_I_TICMS                  =[Tributacao de ICMS        ]
           VSD_I_RBC_ICMS               =[Aliquota Reduzida BCICMS  ]
           VSD_I_AICMS                  =[Aliquota de ICMS          ]
           VSD_I_BC_ICMS                =[ICMS_BC                   ]
           VSD_I_Valor_ICMS             =[Valor do ICMS             ]
    
           VSD_I_CSOSN                  =SubStr([Tipo Tributacao],1,1)+[CSOSN]
           VSD_I_ACSOSN                 =[ICMS_CredSN_Aliquota      ]    
           VSD_I_Valor_CSOSN            =[ICMS_CredSN_Valor         ]
    
           VSD_I_MVA                    =[MVA                       ]
           VSD_I_RBC_ST                 =[ICMS_ST_Aliquota Reduzida ]
           VSD_I_AST                    =[ICMS_ST_Aliquota          ]
           VSD_I_BC_ST                  =[ICMS_ST_BC                ]
           VSD_I_Valor_ST               =[ICMS_ST_Valor             ]
           
           VSD_I_CST_IPI                =[IPI_CST                   ]
           VSD_I_TIPI                   =[Tributacao de IPI         ]
           VSD_I_RBC_IPI                =[Aliquota Reduzida BCIPI   ]
           VSD_I_AIPI                   =[Aliquota de IPI           ]
           VSD_I_BC_IPI                 =[IPI_BC                    ]
           VSD_I_Valor_IPI              =[Valor do IPI              ]
    
           VSD_I_TISSQN                 =[Tributacao de ISSQN       ]
           VSD_I_AISSQN                 =[Aliquota de ISSQN         ]
           VSD_I_BC_ISSQN               =[ISSQN_BC                  ]
           VSD_I_Valor_ISSQN            =[Valor do ISSQN            ]
           VSD_I_CDSERV                 =[Codigo_Servico            ]   
           VSD_I_UFSERV                 =[ISSQN_UF                  ]   
           VSD_I_MUNSERV                =[ISSQN_Municipio           ]   
    
           VSD_I_TPIS                   =""                          
           VSD_I_CST_PIS                =[PIS_CST                   ]
           VSD_I_APIS                   =[PIS_Aliquota              ]
           VSD_I_BC_PIS                 =[PIS_BC                    ]
           VSD_I_Valor_PIS              =[PIS_Valor                 ]
    
           VSD_I_TCOFINS                =""                          
           VSD_I_CST_COFINS             =[COFINS_CST                ]
           VSD_I_ACOFINS                =[COFINS_Aliquota           ]
           VSD_I_BC_COFINS              =[COFINS_BC                 ]
           VSD_I_Valor_COFINS           =[COFINS_Valor              ]
    
           VSD_I_Numero_Volumes         =[Volumes                   ]
           VSD_I_Peso_Liquido           =[Peso Liquido              ]
           VSD_I_Peso_Embalagem         =[Peso Embalagem            ]
           VSD_I_Comissao_Item          =[Comissao do Item          ]
           VSD_I_Tabela                 =[Codigo da Tabela          ]
    
           VSD_I_InfAdic                =[Informacoes_Adicionais    ]
           
           VSD_I_RAT_FRETE              = [Valor Frete Total        ]
           VSD_I_RAT_SEGURO             = [Valor Seguro Total       ]
           VSD_I_RAT_DESCONTO           = [Valor Desconto Total     ]
           VSD_I_RAT_OUTDESP            = [Valor OutDesp Total      ]
  
       EndSwitch
EndSwitch
EndProc  ; (Registro_Item)

;*******************************************************************************
;* Rotina para Iniciar Registro                                                *
;*******************************************************************************
Proc Inicia_Registro()
INICIO_DIALOG=True
Switch
  Case Table()="Notai":
       Opcao_Ver=True
  
       INICIO_DIALOG=True
       Moveto [Item do Documento]
       SEQIT=[Item do Documento]
       Locate [NotaC->Codigo da Empresa],[NotaC->Numero do Documento],
              [NotaC->Serie do Documento],SEQIT
       CopyToArray RegItem
       QUANT   = [Quantidade          ]
       CTTOTAL = NDecimal(([Quantidade]*[Custo Medio Unitario]),2)
EndSwitch
Registro_Item("Ler")

If Search("CUP",[NotaC->Tipo do Documento])>0 And Upper(RegItem["Situacao_Item"])="C"
   Then VSD_I_InfAdic = "** ITEM CANCELADO NO CUPOM **"
EndIf          

EndProc ; (Inicia_Registro)

;*******************************************************************************
;* Rotina para Consultar Itens da Entrada                                      *
;*******************************************************************************
Proc Item_Dialog(Disparo,Campo,Evento,Elemento)

MSG_CAMPO=""
Temp=True

If Opcao_Ver=True Then Campo="I_Seq" EndIf
If Disparo="OPEN"
   Then
        TiraSombraShowDialog()
EndIf        

If Disparo="EVENT" And DynArraySize(Evento)>0 And Evento["Type"]="KEY" Then
   Switch
      Case Opcao_Ver=True:
           Temp=False
           Switch
             Case Evento["KeyCode"] =  27:
                  CancelDialog
             OtherWise:
               Mover_Reg=True
               Switch
                 Case Evento["KeyCode"] = -71:
                      If AtFirst()
                         Then Mover_Reg=False Beep
                         Else Home
                      EndIf
                 Case Evento["KeyCode"] = -79:
                      If AtLast()
                         Then Mover_Reg=False Beep
                         Else End
                      EndIf
                 Case Evento["KeyCode"] = -73:
                      If AtFirst()
                         Then Mover_Reg=False Beep
                         Else Up
                      EndIf
                 Case Evento["KeyCode"] = -81:
                      If AtLast()
                         Then Mover_Reg=False Beep
                         Else Down
                      EndIf
               EndSwitch
               If Mover_Reg=True
                  Then If Table()="Notai"
                          Then SEQIT=[Item do Documento]
                               Inicia_Registro()
                       EndIf
               EndIf
           EndSwitch
   EndSwitch
EndIf
Switch
  Case Campo="I_Seq":
       MSGCAMPO="Sequencia"
  OtherWise:
       MSGCAMPO=""
EndSwitch

TECLA=" Esc=Retornar  Home/End/PgDn/PgUp=Paginar  "

MontaRodapeSD(MSGCAMPO, TECLA)
Return TEMP
EndProc  ; (Item_Dialog)

;*******************************************************************************
;* Rotina para Ver Itens da NF's de Saidas                                     *
;*******************************************************************************
Proc Ficha_Saidas()
Tabela=Table()
Moveto "NotaI"
Inicia_Registro()

Switch
  Case Not IsBlank([Notac->Numero do Pedido]):
       MSG_Pedido_Orcamento="Pedido"
  Case Not IsBlank([Notac->Numero do Orcamento]):
       MSG_Pedido_Orcamento="Orcam."
  OtherWise:
       MSG_Pedido_Orcamento="......"
EndSwitch

If [Situacao_Item]="C" 
   Then ITEM_CANCELADO = "*CANCELADO*"
   Else ITEM_CANCELADO = ""
EndIf
MSGCAMPO=""

Showdialog "Dados do Item [      ]" Proc "Item_Dialog"
   Trigger "OPEN","ARRIVE"
    Key "F1","TAB","ReverseTab","ENTER","ESC","ClearArea","HOME","END","PGDN","PGUP","F4","F7","F8","F9",-33,-6,-147
     @ 02,0 height 21 width 80

   Accept @ -01,43 Width 6 "A3" Tag "I_Seq" To VSD_I_SEQ

   Label  @ 00,02 MSG_Pedido_Orcamento For "I_Pedido"
   Accept @ 00,17 Width 09 "A06" picture "#*#" Tag "I_Pedido" to VSD_I_Pedido
   Label  @ 00,10 "/Item" For "I_Pedido_Item"
   Accept @ 00,27 Width 06 "N" picture "#*#" Tag "I_Pedido_Item" to VSD_I_Pedido_Item

   Label  @ 01,00 ">" For "I_Codigo_Item"
   Accept @ 02,00 Width 16 "A25" picture "!*!" Tag "I_Codigo_Item" to VSD_I_Codigo_Item
   
   Label  @ 01,17 "Descricao Item" For "I_Descricao_Item"
   Accept @ 02,17 Width 42 "A100" picture "!*!" Tag "I_Descricao_Item" to VSD_I_Descricao_Item
   
   Label  @ 01,57 "TI" For "I_Tipo_Item"
   Accept @ 02,58 Width 03 "A1" picture "&" Tag "I_Tipo_Item" to VSD_I_Tipo_Item
   
   @ 01,63 ?? ITEM_CANCELADO
   PaintCanvas Attribute 30 01, 63, 01, 75
   
   Label  @ 03,00 "[F8]Inf.Adic->" For "I_InfAdic"
   Accept @ 03,17 Width 44 "A100" picture "!*!" Tag "I_InfAdic" to VSD_I_InfAdic

   Label  @ 04,00 "Cor/Tecido" For "I_Codigo_Cor_Tecido"
   Accept @ 05,00 Width 07 "A4" picture "!*!" Tag "I_Codigo_Cor_Tecido" to VSD_I_Codigo_Cor_Tecido
   Accept @ 05,06 Width 20 "A20" picture "!*!" Tag "I_Descricao_Cor_Tecido" to VSD_I_Descricao_Cor_Tecido
   Label  @ 04,27 "TM" For "I_Tamanho"
   Accept @ 05,27 Width 05 "A2" picture "!*!" Tag "I_Tamanho" to VSD_I_Tamanho
   Label  @ 04,34 "Tabela" For "I_Tabela"
   Accept @ 05,35 Width 08 "A5" picture "!*!" Tag "I_Tabela" to VSD_I_Tabela

   Label  @ 06,00 "Quantidade" For "I_Quantidade"
   Accept @ 07,00 Width 13 "N" picture "#*#.[###]" Tag "I_Quantidade" to VSD_I_Quantidade
   Label  @ 06,14 "UN" For "I_UN_Item"
   Accept @ 07,14 Width 05 "A2" picture "!*!" Tag "I_UN_Item" to VSD_I_UN_Item                               
   Label  @ 06,20 "Pr.Unitario" For "I_Preco_Unitario"
	 Accept @ 07,20 Width 12 "N" picture "#*#.[######]" Tag "I_Preco_Unitario" to VSD_I_Preco_Unitario
   Label  @ 06,32 "%" For "I_Taxa_Desconto_Unitario"
   Accept @ 07,33 Width 10 "N" picture "#*#.[####]" Tag "I_Taxa_Desconto_Unitario" to VSD_I_Taxa_Desconto_Unitario
   Label  @ 06,34 "/Vr.Desconto" For "I_Valor_Desconto_Unitario"
   Accept @ 07,44 Width 12 "$" picture "#*#.[##]" Tag "I_Valor_Desconto_Unitario" to VSD_I_Valor_Desconto_Unitario
   Label  @ 06,56 "Pr.Total" For "I_Preco_Total"
   Accept @ 07,57 Width 13 "$" picture "#*#.[##]" Tag "I_Preco_Total" to VSD_I_Preco_Total

   Label  @ 08,00 "Ct.Unitario" For "I_Custo_Unitario"
   Accept @ 09,00 Width 13 "$" picture "#*#.[#####]" Tag "I_Custo_Unitario" to VSD_I_Custo_Unitario
   Label  @ 08,20 "Pr.Tabela" For "I_Preco_Tabela"
   Accept @ 09,20 Width 12 "$" picture "#*#.[##]" Tag "I_Preco_Tabela" to VSD_I_Preco_Tabela

   Label  @ 08,43 "% Comiss„o" For "I_Comissao_Item"
   Accept @ 09,44 Width 12 "N" picture "#*#.[###]" Tag "I_Comissao_Item" to VSD_I_Comissao_Item

   @ 10,00 ?? "Impostos CST    %Red    Aliq.  BC        Valor"
                                 
   Label  @ 11,00 " CSOSN" For "I_CSOSN"
   Accept @ 11,08 Width 07 "A4" picture "####" Tag "I_CSOSN" to VSD_I_CSOSN
   PaintCanvas Attribute 112 11, 14, 11, 22
   Accept @ 11,23 Width 08 "N" picture "#*#.[##]" Tag "I_ACSOSN" to VSD_I_ACSOSN
   PaintCanvas Attribute 112 11, 29, 11, 40
   Accept @ 11,40 Width 12 "$" picture "#*#.[##]" Tag "I_Valor_CSOSN" to VSD_I_Valor_CSOSN

   Label  @ 12,00 "  ICMS" For "I_CST_Item"
   Accept @ 12,08 Width 07 "A3" picture "!*!" Tag "I_CST_Item" to VSD_I_CST_Item   
   Accept @ 12,15 Width 10 "N" picture "#*#.[####]" Tag "I_RBC_ICMS" to VSD_I_RBC_ICMS
   Accept @ 12,23 Width 08 "N" picture "#*#.[##]" Tag "I_AICMS" to VSD_I_AICMS
   Accept @ 12,30 Width 11 "$" picture "#*#.[##]" Tag "I_BC_ICMS" to VSD_I_BC_ICMS     
   Accept @ 12,40 Width 12 "$" picture "#*#.[##]" Tag "I_Valor_ICMS" to VSD_I_Valor_ICMS

   Label  @ 13,00 "MVA/ST" For "I_AST"
   Accept @ 13,08 Width 08 "N" picture "#*#.[##]" Tag "I_MVA" to VSD_I_MVA
   Accept @ 13,15 Width 10 "N" picture "#*#.[####]" Tag "I_RBC_ST" to VSD_I_RBC_ST
   Accept @ 13,23 Width 08 "N" picture "#*#.[##]" Tag "I_AST" to VSD_I_AST     
   Accept @ 13,30 Width 11 "$" picture "#*#.[##]" Tag "I_BC_ST" to VSD_I_BC_ST  
   Accept @ 13,40 Width 12 "$" picture "#*#.[##]" Tag "I_Valor_ST" to VSD_I_Valor_ST

   Label  @ 14,00 "   IPI" For "I_CST_IPI"
   Accept @ 14,08 Width 07 "A2" picture "!*!" Tag "I_CST_IPI" to VSD_I_CST_IPI  
   Accept @ 14,15 Width 10 "A2" picture "#*#.[####]" Tag "I_RBC_IPI" to VSD_I_RBC_IPI
   Accept @ 14,23 Width 08 "N" picture "#*#.[##]" Tag "I_AIPI" to VSD_I_AIPI
   Accept @ 14,30 Width 11 "$" picture "#*#.[##]" Tag "I_BC_IPI" to VSD_I_BC_IPI  
   Accept @ 14,40 Width 12 "$" picture "#*#.[##]" Tag "I_Valor_IPI" to VSD_I_Valor_IPI

   Label  @ 15,00 " ISSQN" For "I_TISSQN"
   Accept @ 15,08 Width 07 "A1" picture "D,N,I,S,R" Tag "I_TISSQN" to VSD_I_TISSQN 
   Accept @ 15,15 Width 10 "A2" picture "#*#.[####]" Tag "I_RBC_ISSQN" to VSD_I_RBC_ISSQN
   Accept @ 15,23 Width 08 "N" picture "#*#.[##]" Tag "I_AISSQN" to VSD_I_AISSQN
   Accept @ 15,30 Width 11 "$" picture "#*#.[##]" Tag "I_BC_ISSQN" to VSD_I_BC_ISSQN  
   Accept @ 15,40 Width 12 "$" picture "#*#.[##]" Tag "I_Valor_ISSQN" to VSD_I_Valor_ISSQN

   Label  @ 16,00 "   PIS" For "I_CST_PIS"    
   Accept @ 16,08 Width 07 "A2" picture "!*!" Tag "I_CST_PIS" to VSD_I_CST_PIS  
   Accept @ 16,15 Width 10 "A2" picture "#*#.[####]" Tag "I_RBC_PIS" to VSD_I_RBC_PIS
   Accept @ 16,23 Width 08 "N" picture "#*#.[##]" Tag "I_APIS" to VSD_I_APIS
   Accept @ 16,30 Width 11 "$" picture "#*#.[##]" Tag "I_BC_PIS" to VSD_I_BC_PIS  
   Accept @ 16,40 Width 12 "$" picture "#*#.[##]" Tag "I_Valor_PIS" to VSD_I_Valor_PIS

   Label  @ 17,00 "COFINS" For "I_CST_COFINS"   
   Accept @ 17,08 Width 07 "A2" picture "!*!" Tag "I_CST_COFINS" to VSD_I_CST_COFINS 
   Accept @ 17,15 Width 10 "A2" picture "#*#.[####]" Tag "I_RBC_COFINS" to VSD_I_RBC_COFINS
   Accept @ 17,23 Width 08 "N" picture "#*#.[##]" Tag "I_ACOFINS" to VSD_I_ACOFINS
   Accept @ 17,30 Width 11 "$" picture "#*#.[##]" Tag "I_BC_COFINS" to VSD_I_BC_COFINS  
   Accept @ 17,40 Width 12 "$" picture "#*#.[##]" Tag "I_Valor_COFINS" to VSD_I_Valor_COFINS

   Label  @ 08,57 "CFOP" For "I_CFOP"
   Accept @ 09,57 Width 08 "A4" picture "####" Tag "I_CFOP" to VSD_I_CFOP
   Label  @ 08,66 "NCM" For "I_NCM"
   Accept @ 09,66 Width 11 "A8" picture "#*#" Tag "I_NCM" to VSD_I_NCM

   Label  @ 10,52 "Frete"    For "I_RAT_FRETE"
   Accept @ 11,53 Width 12 "$" picture "#*#.[##]" Tag "I_RAT_FRETE" to VSD_I_RAT_FRETE
   Label  @ 10,65 "Seguro"   For "I_RAT_SEGURO"
   Accept @ 11,66 Width 11 "$" picture "#*#.[##]" Tag "I_RAT_SEGURO" to VSD_I_RAT_SEGURO

   Label  @ 12,52 "Desconto" For "I_RAT_DESCONTO"
   Accept @ 13,53 Width 12 "$" picture "#*#.[##]" Tag "I_RAT_DESCONTO" to VSD_I_RAT_DESCONTO
   Label  @ 12,65 "OutDesp"  For "I_RAT_OUTDESP"
   Accept @ 13,66 Width 11 "$" picture "#*#.[##]" Tag "I_RAT_OUTDESP" to VSD_I_RAT_OUTDESP
   
   Label  @ 14,53 "Servi‡o" For "I_CDSERV"
   Accept @ 15,53 Width 10 "N" picture "#*#" Tag "I_CDSERV" to VSD_I_CDSERV
   Label  @ 14,63 "Municˇpo" For "I_MUNSERV"
   Accept @ 15,63 Width 10 "N" picture "#*#" Tag "I_MUNSERV" to VSD_I_MUNSERV
   Label  @ 14,72 "UF" For "I_UFSERV"
   Accept @ 15,72 Width 5  "A2" picture "!!" Tag "I_UFSERV" to VSD_I_UFSERV

   Label  @ 16,52 "Qtde/Volumes" For "I_Numero_Volumes"
   Accept @ 16,66 Width 11 "N" picture "#*#.[###]" Tag "I_Numero_Volumes" to VSD_I_Numero_Volumes
   Label  @ 17,52 "Peso Liquido" For "I_Peso_Liquido"
   Accept @ 17,66 Width 11 "N" picture "#*#.[###]" Tag "I_Peso_Liquido" to VSD_I_Peso_Liquido
   Label  @ 18,52 "Peso Embal.." For "I_Peso_Embalagem"
   Accept @ 18,66 Width 11 "N" picture "#*#.[###]" Tag "I_Peso_Embalagem" to VSD_I_Peso_Embalagem

Enddialog
Moveto Tabela
EndProc    ;  (Ficha_Saidas)

;*******************************************************************************
;* Rotina para Controlar Chave da Nota Fiscal                                  *
;*******************************************************************************
Proc CHAVEC()

VCITENS =BlankNum()
VSQTDE  =BlankNum()
VSVRMERC=BlankNum()

While True
  Moveto "Notac"
  Moveto [Codigo da Empresa]

  While True

        MSGCAMPO=Field()
        TECLA=" Esc=Sair  "
        If OPCAO_FORM="F"
           Then TECLA=TECLA+"Enter=Visualizar  Ctrl+Z=Pesquisar  Alt+Z=Pr˘ximo "
           Else If Table()="Notac"
                   Then TECLA=TECLA+"Enter=Rela‡„o  Ctrl+Z=Pesquisar  Alt+Z=Pr˘ximo  F8=Observa‡„o"
                   Else If Table()="Notai"
                           Then TECLA=TECLA+"F3=Ver Ficha  Ctrl+Z=Pesquisar  Alt+Z=Pr˘ximo "
                                Moveto [Preco Total      ]   VSVRMERC=ImageCSum()
                                Moveto [Quantidade       ]   VSQTDE  =ImageCSum()
                                Moveto [Item do Documento]   VCITENS =ImageCCount()
                           Else TECLA=TECLA+"Ctrl+Z=Pesquisar  Alt+Z=Pr˘ximo "
                        Endif
                Endif
        EndIf


        If Field()="Codigo da Empresa" And Not IsBlank([Codigo da Empresa])
           Then MSGCAMPO="Empresa: "+[Nome Fantasia Empresa]
        EndIf
        Prompt TECLA

        Wait Field
          Until "ESC","ENTER","F2","F7","F8","HOME","UP","PGDN","FIELDVIEW","PGUP",
                "F3","DOWN","ZOOM","ZOOMNEXT","END","F3","LEFT","RIGHT"
;                -104, -105, -106, -107, -108, -109, -110, -111, -112, -113, -139, -140

        If SubStr(RetVal,1,2)="-1"
           Then SYS_TECLA_ACIONADA=RetVal
                Seta_Tecla_Acionada()
                RetVal="ESC"
        EndIf


        Switch

          Case RetVal="LEFT":
               LEFT
          Case RetVal="RIGHT":
               RIGHT
          Case RetVal = "ZOOM":
               PESQUISA()
               Loop
          Case RetVal = "ZOOMNEXT":
               PESQUISACON()
               Loop
          Case RetVal="F3" And Table()="Notai":
               Opcao_Ver=True
               Ficha_Saidas()
          Case RetVal="HOME":
               HOME
          Case RetVal="END":
               END
          Case RetVal="PGUP":
               PGUP
               If OPCAO_FORM="3"
                  Then If Table()="Notac"
                          Then Moveto "Notav"
                          Else If Table()="Notav"
                                  Then Moveto "Notai"
                                  Else Moveto "Notac"
                                       Moveto [Codigo da Empresa]
                               Endif
                       Endif
               Endif
          Case RetVal="PGDN":
               PGDN
               If OPCAO_FORM="3"
                  Then If Table()="Notac"
                          Then Moveto "Notav"
                          Else If Table()="Notav"
                                  Then Moveto "Notai"
                                  Else Moveto "Notac"
                                       Skip
                                       Moveto [Codigo da Empresa]
                               Endif
                       Endif
               Endif
          Case RetVal="UP":
               If OPCAO_FORM="F" And Not Bot() Or Table()="Notai" And Not Bot()
                  Then UP
               Endif
          Case RetVal="DOWN":
               If OPCAO_FORM="F" Or Table()="Notai"
                  Then DOWN
               Endif
          Case RetVal="ENTER":
               If OPCAO_FORM="F"
                  Then OPCAO_FORM="3"
                  Else OPCAO_FORM="F"
               EndIf
               CHAVEC=5
               Return
          Case Retval="F8":
               If OPCAO_FORM="3"
                  Then CampoAnt=Field()
                       ImageRights ReadOnly
                       Edita_Memo("Observacao na Nota Fiscal",08,01,15,76,"Observa‡”es")
                       Moveto Field CampoAnt
               Endif
          Case Retval="ESC":
               CHAVEC=9
               If OPCAO_FORM="F"
                  Then Return
               Endif
               OPCAO_FORM="F"
               CHAVEC=5
               Return
        EndSwitch
  EndWhile
EndWhile
EndProc   ; (ChaveC)

;*******************************************************************************
;* Rotina Principal Nota Fiscal                                                *
;*******************************************************************************
AutoLib="\\Sistemas\\Cadastro\\Bibliot,\\Sistemas\\Cadastro\\Bib_Show"

If Not IsAssigned(SYS_EMPRESA_DEFAULT) Then SYS_EMPRESA_DEFAULT="" EndIf
If Not IsAssigned(SYS_CODIGO_CLIENTE)  Then SYS_CODIGO_CLIENTE=""  EndIf
If Not IsAssigned(SYS_CONTROLE_DIA)    Then SYS_CONTROLE_DIA=""    EndIf

PARAM_EMPRESA=SYS_EMPRESA_DEFAULT

View "NotaC"
;************** Rotina para tratar o erro de tabela locada ********************
If ErrorCode()=4
   Then Do_It!
        ClearAll
        Release Vars All
        Release Procs All
        return
EndIf

PickForm "F"
OPCAO_FORM="F"

While True
  CHAVEC()
  If CHAVEC=9 Then QuitLoop EndIf
  If CHAVEC=5
     Then Moveto "NotaC"
          If OPCAO_FORM="F"
             Then PickForm "F"
             Else PickForm "3"
          EndIf
          Loop
  EndIf
EndWhile
Do_It!
ClearAll
Release Procs Registro_Item,Inicia_Registro,Item_Dialog,Ficha_Saidas,CHAVEC

