;** PreBolet *******************************************************************
;*  Emissao de Pre-Boletas                                                     *
;*******************************************************************************
;Autor           : Vise Informatica (VISERP)
;Desenvolvido    : 23/04/2004 por Anivel Augusto Rodrigues
;Ultima Alteracao: 03/12/2004 por Anivel Augusto Rodrigues
;Motivo Alteracao: Ajustes
;Alterado em     : 29/06/2006 por Antonio Marcelo Alves
;Motivo Alteracao: Inclusao ImpriArq()
;Ultima Alteracao: 14/08/2007 por Antonio Marcelo Alves
;Motivo Alteracao: Ajustes Deleta_Arquivo
;Ultima Alteracao: 30/12/2010 por Bruno Carvalho
;Motivo Alteracao: Ajustes Novo Layout de Teclas

;*******************************************************************************
;* Rotina para Localizar Registro                                              *
;*******************************************************************************
Proc CHAVE()
While True
  End
  Down
  Moveto [Codigo]

  While True

  TECLA="F1=Tabelas"
  AguardaTeclasPadrao()

  If RetVal=-33
     Then Echo Normal
          Echo Off
          ShowPopup " Fun‡”es " CENTERED
           "F5 ~L~impar     ": " Limpa registros                  " :"F5",
           "F6 ~I~mprimir   ": " Imprime registro                 " :"F6", 
           "~C~ancelar      ": " Cancelar a Opera‡„o              " : "CANCELAR"
          EndMenu
          To MenuVar
          Echo Off
          
          If MenuVar="CANCELAR" or MenuVar="Esc"
             Then Loop
          EndIf                                         
          RetVal=MenuVar
  EndIf

  Switch
    Case RetVal=-33 : SemFuncoes()
    Case RetVal="F3": SemFicha()
    Case RetVal=-94 : MsgTeclasPadrao()
    Case RetVal="F5":
         ConfGeral("Confirma a exclus„o dos registro desta relac„o ?")
         If OK="S"
             Then Limpar()
         EndIf
         QuitLoop
    Case RetVal="F6":
         Del
         If Not IsEmpty("PB_0000")
            Then Imprimir()
         EndIf
         QuitLoop
    Case RetVal="F1":
         If Field()="Codigo"
            Then CONSULTAF1()
         EndIf
    Case RetVal="F7" Or RetVal="UP" Or RetVal="PGUP" Or RetVal="HOME":
         While True
           PAGINA("PB_0000","MR")
           If EDITAR="S"
              Then CHAVE=0
                   Return
              Else If EXCLUIR="S"
                      Then CONFIRMA()
                           If OK="S"
                              Then DEL
                              Else UnLockRecord
                           EndIf
                      Else QuitLoop
                   EndIf
           EndIf
         EndWhile
         QuitLoop
    Case Retval="ESC":
         CHAVE=9
         Del
         Return
    Case RetVal="ENTER":
         If IsBlank([])
            Then Loop
         EndIf
         []=Alinh()
         CODIGO=[]
         Del
         Locate CODIGO
         If Retval
            Then CHAVE=0
            Else CHAVE=1
                 End Down
                 [Codigo]=CODIGO
         EndIf
         If Not IsLockRecord()
            Then Return
         EndIf
         Quitloop
    EndSwitch
  EndWhile
EndWhile
EndProc

;*******************************************************************************
;* Rotina para Digitar Quantidade                                              *
;*******************************************************************************
Proc DIGITA()
Moveto [Quantidade]
While True

  TECLA=" Esc=Retornar  "

  If CHAVE=0
     Then TECLA=TECLA+"Del=Excluir  "
  EndIf

  Prompt TECLA

  Wait Field
       Until "ESC","ENTER","DEL","FIELDVIEW","F35"

  Switch
  Case Retval="ESC":
       If CHAVE=1
          Then Del
          Else If RecordStatus("Modified")
                  Then Undo
               EndIf
       EndIf
       CHAVE=9
       QuitLoop
  Case Retval="ENTER":
       If IsBlank([])
          Then []=1
       EndIf
       [Codigo Empresa]="0001"
       QuitLoop
  Case Retval="FIELDVIEW" or Retval="F35":
       EDITFIELD()
  Case Retval="DEL":
       If CHAVE=0
          Then CONFIRMA()
               If OK="S"
                  Then DEL
                       QuitLoop
               EndIf
       EndIf
  EndSwitch
EndWhile
EndProc

;*******************************************************************************
;* Rotina Limpar Registros                                                     *
;*******************************************************************************
Proc Limpar()
Aguarde("Aguarde, Excluindo registros")
Do_It!
Empty("PB_0000")
CoEditKey
PickForm "F"
EndProc

;*******************************************************************************
;* Rotina Impressao                                                            *
;*******************************************************************************
Proc Imprimir()
Do_It!

DispositivoI("PREB")
If OK=""
   Then CoEditKey
        Return
EndIf
ClearAll

AGUARDE("Aguarde, Gerando Relat¢rio")
{Ask} {PB_0000} Check
Do_It!
ClearAll
Empty("Answer")

View "Answer"
CoEdit "PB_0000"
Scan
  CopyToArray REG
  Moveto "Answer"
  For I From 1 to [PB_0000->Quantidade]
    End
    Down
    CopyFromArray Reg
  EndFor
  Moveto "PB_0000"
EndScan
Do_It!
ClearAll


AGUARDE("Aguarde, Imprimindo boletas")

ArqImp=PrivDir()+"PreBol.Txt"
If IsFile(ArqImp)
   Then Deleta_Arquivo(ARQIMP)
EndIf

View "Answer"
Scan
  Play "PB_0117"
EndScan
ClearAll

;---- Imprime Arquivo Impressao ------------------------------------------------
ImpriArq(ARQIMP)

Delete "Answer"

CoEdit "PB_0000"
PickForm "F"
EndProc

;************************************
;* ROTINA PARA LIMPAR AGUARDE       *
;************************************
Proc LimpAguarde2L()
@ 23,0 ?? Fill(" ",80)
PaintCanvas Attribute 31 23,0,23,79
@ 24,0 ?? Fill(" ",80)
PaintCanvas Attribute 31 24,0,24,79
EndProc ; (LimpAguarde2L)

;*******************************************************************************
;* Rotina Principal                                                            *
;*******************************************************************************
AutoLib="\\Sistemas\\Cadastro\\Bibliot,\\Sistemas\\Cadastro\\Bib_Show"
If Not IsAssigned(SYS_EMPRESA_DEFAULT) Then SYS_EMPRESA_DEFAULT="" EndIf

MSGDUP=""
View "DocMsg"
Locate SYS_EMPRESA_DEFAULT,"BOL"
If RetVal
   Then MSGDUP=[Mensagem]
EndIf
ClearAll

CoEdit "PB_0000"
PickForm "F"

While True
  CHAVE()
  If CHAVE=9 Then QuitLoop EndIf
  DIGITA()
EndWhile
Do_It!
ClearAll
Release Vars All
Release Procs All

