;** TitCons *******************************************************************
;*  Consulta - Contas a Pagar                                                  *
;*******************************************************************************
;Autor           : Vise Informatica (VISERP)
;Desenvolvido  em: 30/10/2017 por Bruno Carvalho
;Ultima Alteracao: 28/12/2017 por Kamila Gomes
;Motivo Alteracao: Removido Debug
;Ultima Alteracao: 14/07/2018 por Bruno Carvalho
;Motivo Alteracao: Removido a tabela feriados ao carregar as tabelas principais
;Ultima Alteracao: 24/09/2018 por Anivel Augusto Rodrigues
;Motivo Alteracao: Ajustes conta corrente cheque            

;*******************************************************************************
;* Rotina para Controlar Chave da Nota Fiscal                                  *
;*******************************************************************************
Proc CHAVEC()
ORDENA_CAMPO    = "ORD_LANC"
COPIOU_REGISTRO = False

While True
  Origem_Disparo=""
  COPIOU_REGISTRO=False

  Moveto "Titulos"
  Moveto [Numero do Lancamento]
  End
  
  If OPCAO_FORM="6"
     Then Down          
     Else PgDn PgDn PgDn PgDn PgDn
  EndIf
  Moveto [Numero do Lancamento]
  
  SetaCorRegistro("Editar")
  While True

  MSGCAMPO=""
  TECLA=""
  AguardaTeclasPadrao()

  Switch
    Case RetVal="F3":
         If OPCAO_FORM="6"
            Then OPCAO_FORM="4"
            Else OPCAO_FORM="6"
         EndIf
         Del                     
         CHAVEC=5
         Return   
    Case RetVal="F7" Or RetVal="UP" Or RetVal="PGUP" Or RetVal="HOME":
         Del
         While True
           If OPCAO_FORM="6"
              Then PAGINA("Titulos","MR")
              Else PAGINA("Titulos","MT")
           EndIf
           NLANC=[Numero do Lancamento]
           Switch
             Case EDITAR="S":
                  PickForm "4"
                  Echo Normal
                  Echo Off
                  CHAVEC=0
                  Controla_EdicaoC()
             Case EXCLUIR="S" :  
             OtherWise        : QuitLoop
           EndSwitch
           If OPCAO_FORM="4"
              Then PickForm "4"
              Else PickForm "6"
           EndIf
           SetaPosForm()
         EndWhile
         QuitLoop
    Case Retval="ESC":
         CHAVEC=9
         Del
         Return
    Case Retval="ENTER" :
         If IsBlank([]) Then Loop EndIf
         NLANC = [Numero do Lancamento]
         Del      
         PickForm "4"
         Moveto [Numero do Lancamento]
         Locate NLANC
         If Retval
            Then CHAVEC=0
                 If Not IsLockRecord()
                    Then Return
                 EndIf
            Else FastMsg("Lan‡amento nÆo localizado, inser‡Æo nÆo permitida !")
         EndIf
         If OPCAO_FORM="6"
            Then PickForm "6"
         EndIf
         QuitLoop
    EndSwitch
  EndWhile
EndWhile

EndProc ;CHAVEC()

;*******************************************************************************
;* Rotina para Digitacao da Cabeca                                             *
;*******************************************************************************
Proc DIGITAC()

Moveto "Titulos"
SetaCorRegistro("Paginar")          

Moveto Field ncampop
While True
      MSGCAMPO=""
      TECLA=" Esc=Retornar  F5=Observa‡„o             PgDn      "
      Prompt TECLA

      Wait Field
           Message MSGCAMPO
           Until "DOWN","ESC","PGDN","F5",-116

      Switch              
      Case Retval="ESC":
           DIGITAC=False
           CHAVEC=9
           QuitLoop
      Case RetVal="PGDN" Or  Retval="DOWN" Or RetVal=-116 :
           ncampop=Field()
           Tecla_Funcao="F8"
           QuitLoop
      Case Retval="F5" :
           CampoAnt=Field()
           Ler_Memo("Observacoes",14,00,09,79,"Observa‡”es")
           Moveto Field CampoAnt
           Prompt TECLA
      
      EndSwitch
EndWhile

EndProc ;DIGITAC()

;*******************************************************************************
;* Rotina para Digitacao das Notinhas                                          *
;*******************************************************************************
Proc DIGITAN()
                       
Moveto [Valor do Documento]
While True
      MSGCAMPO=""
      TECLA= " Esc=Retornar  F7=Paginar                PgDn/PgUp "
       
      Prompt TECLA
      Wait Field
           Until "ESC","F3","F7","HOME","UP","PGDN","PGUP",-115,-116
      
      Switch
      Case RetVal="F6" Or RetVal="F8"   Or
           RetVal=-115 Or RetVal=-116    : 
           Tecla_Funcao=RetVal
           CHAVEN=9
           Del
           Return      
      Case Retval="ESC" Or Retval="PGUP":
           SetaCorRegistro("Padrao")
           Del
           Tecla_Funcao=-115 ;"F6"
           CHAVEN=9
           Return
      Case Retval="PGDN":
           Del
           CHAVEN=9
           Tecla_Funcao=-116
           DIGITAC =False
           Return
      Case RetVal="F7" Or RetVal="UP" Or RetVal="PGUP" Or RetVal="HOME":
           Del
           While True
             PAGINA("TitNota","MR")
             NLANC   = [Numero do Lancamento]
             NITEM_N = [Sequencia da Nota]
             Switch
               Case EDITAR="S"  : UnLockRecord
               Case EXCLUIR="S" : UnLockRecord
             EndSwitch
             QuitLoop
           EndWhile
           QuitLoop           
      EndSwitch
EndWhile

EndProc

;*******************************************************************************
;* Rotina para Localizar Item                                                  *
;*******************************************************************************
Proc CHAVEI()

Exclusao_Cabeca=False
Moveto "TitBaixa"

Tab_Ant = table()
Moveto "Titulos"
Moveto [Pag_4]
SetaCorRegistro("Invisivel")
Moveto Tab_Ant
Release Vars Tab_Ant

While True
  Moveto [Sequencia da Baixa]
  End
  SEQIT=[Sequencia da Baixa]
  Down
  Moveto [Sequencia da Baixa]

  SetaCorRegistro("Editar")
  While true
    Opcao_Ver=False
    
    
    TECLA= " Esc=Retornar  F7=Paginar  F3=Ver ficha  PgDn/PgUp "
       
    Prompt TECLA
    Wait Field
         Until "ESC","F3","F7","HOME","UP","PGDN","PGUP",-115,-116

    Switch
    Case RetVal="F3":
         Del
         Moveto [Sequencia da Baixa]
         If RecordStatus("New")
            Then MENSAGEM("Sem baixa p/ ver !")
                 QuitLoop
         EndIf      
         Opcao_Ver=True
         CHAVEI=0
         Home
         SEQIT=[Sequencia da Baixa]
         Inicia_Registro()
         Digita_Baixa()
         QuitLoop
    Case Retval="PGDN" Or Retval=-116 :
         Del
         Tecla_Funcao=-116          
         CHAVEI=9
         Return     
    Case RetVal="ESC" Or Retval="PGUP" Or Retval=-115 : 
         Del
         Tecla_Funcao=-115
         CHAVEI=9          
         Return
    Case RetVal="F7" Or RetVal="UP" Or RetVal="PGUP" Or RetVal="HOME":
         Del
         While True
           PAGINA("TitBaixa","MR")
           SEQIT = [Sequencia da Baixa]
           If EDITAR="S"
              Then CHAVEI=0
                   Controla_EdicaoI()
              Else If EXCLUIR="S"
                      Then UnLockRecord
                      Else QuitLoop
                   EndIf
           EndIf
           SetaPosForm()
         EndWhile
         QuitLoop
    EndSwitch
  EndWhile
EndWhile

EndProc ;CHAVEI()

;*******************************************************************************
;* Rotina para Localizar Registro Notinhas                                     *
;*******************************************************************************
Proc CHAVEN()

Var = false
Exclusao_Cabeca=False
    
While True
  Moveto [Sequencia da Nota]
  End
  NITEM_N = [Sequencia da Nota]
  Down

  Opcao_Ver=False
  Opcao_Ler_Cheque=False

  Seta_Sequencia(NITEM_N,False)
  If IsLockRecord()
     Then Del
          Loop
  EndIf

  SetaCorRegistro("Editar")
  While true
    Opcao_Ver=False
    
    Moveto [Valor do Documento]
    TOTVALOR = ImageCSum()
    Moveto [Sequencia da Nota]

    MSGCAMPO=""
    TECLA= " Esc=Retornar  F7=Paginar                PgDn/PgUp "
       
    Prompt TECLA
    Wait Field
         Until "ESC","F3","F7","HOME","UP","PGDN","PGUP",-115,-116
    
    Switch
    Case RetVal="F6" Or RetVal="F9" Or
         RetVal=-115 Or RetVal=-116 Or
         RetVal=-133 Or RetVal="F11":
         Tecla_Funcao=RetVal
         CHAVEN=9
         Del
         Return   
    Case Retval="PGDN" Or Retval=-116 :
         Del
         Tecla_Funcao=-116          
         CHAVEN=9
         Return     
    Case RetVal="ESC" Or Retval="PGUP" : 
         Del
         Tecla_Funcao=-115
         CHAVEN=9          
         Return
    Case RetVal="F7" Or RetVal="UP" Or RetVal="PGUP" Or RetVal="HOME":
         Del
         While True
           Moveto [Valor do Documento]
           TOTVALOR = ImageCSum()
           Moveto [Sequencia da Nota]
           PAGINA("TitNota","MR")
           If EDITAR="S"                                       
              Then UnLockRecord
              Else If EXCLUIR="S"
                      Then UnLockRecord
                      Else QuitLoop
                   EndIf
           Endif
           SetaPosForm()
         EndWhile
         QuitLoop
    EndSwitch
  EndWhile
EndWhile
EndProc

;*******************************************************************************
;* Rotina para Localizar Registro Item                                         *
;*******************************************************************************
Proc CHAVECH()
 
Exclusao_Cabeca=False
While True
  Moveto [Valor]   VSVRCHEQUES=ImageCSum()

  Moveto [Sequencia]
  End
  ITEM = [Sequencia]
  Down
  Moveto [Sequencia]

  Opcao_Ver=False
  Opcao_Ler_Cheque=False

  Seta_Sequencia(ITEM,False)
  If IsLockRecord()
     Then Del
          Loop
  EndIf

  SetaCorRegistro("Editar")
  While True
      Opcao_Ver=True

      MSGCAMPO=""
      TECLA= " Esc=Retornar  F7=Paginar  F3=Ver ficha  PgDn/PgUp "
       
      Prompt TECLA
      Wait Field
           Until "ESC","F3","F7","HOME","UP","PGDN","PGUP",-115,-116

    Switch
    Case RetVal="F6" Or RetVal="F9" Or
         RetVal=-115 Or RetVal=-116 Or
         RetVal=-133 Or RetVal="F11":
         Tecla_Funcao=RetVal
         CHAVECH=9
         Del
         Return   
      Case RetVal="F3":
           Del
           Moveto [Sequencia]
           If RecordStatus("New")
              Then MENSAGEM("Sem Item p/ ver !")
                   QuitLoop
           EndIf
           CHAVECH=0
           Home
           ITEM=[Sequencia]
           Controla_EdicaoCh()
           QuitLoop
      Case Retval="PGDN" Or Retval=-116 :
           Del
           Tecla_Funcao=-116          
           CHAVECH=9
           Return     
      Case RetVal="ESC" Or Retval="PGUP": 
           Del
           Tecla_Funcao=-115
           CHAVECH=9          
           Return         
      Case RetVal="F7" Or RetVal="UP" Or RetVal="PGUP" Or RetVal="HOME":
           Del
           While True
             Moveto [Valor]   VSVRCHEQUES=ImageCSum()
             Moveto [Sequencia]
             PAGINA("Titcheq","MR")
             If EDITAR="S"
                Then CHAVECH=0
                     ITEM=[Sequencia]
                     Controla_EdicaoCh()
                Else If EXCLUIR="S"
                        Then UnLockRecord
                        Else QuitLoop
                     EndIf
             EndIf
             SetaPosForm()
           EndWhile
           QuitLoop
      EndSwitch
  EndWhile
EndWhile

EndProc  ; (CHAVECH)

;*******************************************************************************
;* Rotina de Digitacao Dados a Vista                                           *
;*******************************************************************************
Proc Baixa_Dialog(Disparo,Campo,Evento,Elemento)
Private JANELA, WinArray5

Temp      = True
TECLA     = " Esc=Retornar  "
MSG_CAMPO = ""

Opcao_Ver=True
Campo="I_Seq" 

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
            Case Evento["KeyCode"] = -63:   
                 Ler_Memo("Observacoes",16,03,07,73,"Observa‡”es")
            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 SEQIT=[Sequencia da Baixa]
                      Inicia_Registro()
              EndIf
          EndSwitch
     Case Evento["KeyCode"] = 27:
          CHAVEI=9
          CancelDialog
   EndSwitch
EndIf

SelectControl Campo
If Opcao_Ver=True
   Then TECLA=" Esc=Retornar  Home/End/PgDn/PgUp=Paginar  "
   Else TECLA=" Esc=Retornar  "
EndIf   

Switch
  OtherWise : MSGCAMPO=""
EndSwitch

@ 24,0 ?? TECLA+Spaces(80-Len(TECLA))
PaintCanvas Attribute 31 24,0,24,79
Message(MSGCAMPO)
Mouse Hide
RefreshDialog
Return TEMP

EndProc ;Baixa_Dialog 

;*******************************************************************************
;* Rotina de Controle p/ ShowDialog                                            *
;*******************************************************************************
Proc Item_DialogCH(Disparo,Campo,Evento,Elemento)
Private JANELA, WinArray5
   
Temp      = True
TECLA     = " Esc=Retornar  "
MSG_CAMPO = ""

Campo="I_Seq"

Temp=True
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 ITEM=[Sequencia]
                      Inicia_RegistroCH()
              EndIf
          EndSwitch
      Case (Evento["KeyCode"] = -6 Or Evento["KeyCode"] = -147):
           Temp=False
   EndSwitch
EndIf

SelectControl Campo
MSGCAMPO=""

@ 23,0 ?? ">"+Format("W79,AL",MSGCAMPO)
PaintCanvas Attribute 30 23,0,23,79
          
@ 24,0 ?? TECLA+Spaces(80-Len(TECLA))
PaintCanvas Attribute 31 24,0,24,79

Mouse Hide
RefreshDialog
Return TEMP
EndProc  ; (Item_DialogCH)
               
;*******************************************************************************
;* Digitacao de Cheques                                                        *
;*******************************************************************************
Proc DigitaCH()
 
Showdialog "Dados do Cheque [      ]" Proc "Item_DialogCH"
   Trigger "OPEN","ARRIVE"
    Key "F1","TAB","ReverseTab","ENTER","ESC","F4","ClearArea","HOME","END","PGDN","PGUP",-46, -6, -147
     @ 08,2 height 13 width 76

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

   Label  @ 0,00 "C¢digo CMC7" for "CBChq"
   Accept @ 1,01 Width 37 "A34"  Picture ";#########;###########;#############;#" Tag "CBChq" To VSD_CBChq

  ;Label  @ 0,43 "Situa‡„o" for "Situacao"
  ;Accept @ 1,44  Width 15 "A12" picture "!*!" Tag "Situacao" to VSD_Situacao
                
   Label  @ 0,59 "Dt.Liquida‡Æo" for "DataL"
   Accept @ 1,60  Width 13 "D" picture "#[#];.##;.##[##]" Tag "DataL" to VSD_DataL
                                          
   Label  @ 2,00 "Banco" for "CBanco"
   Accept @ 3,01  Width 6 "A3" picture "!*!" Tag "CBanco" to VSD_CBanco
   Accept @ 3,06  Width 18 "A18" picture "!*!" Tag "NBanco" to VSD_NBanco

   Label  @ 2,24 "Agˆncia" for "Agencia"
   Accept @ 3,25  Width 7 "A6" picture "!*!" Tag "Agencia" to VSD_Agencia

   Label  @ 2,32 "C/C" for "CCorrente"
   Accept @ 3,33  Width 13 "A10" picture "!*!" Tag "CCorrente" to VSD_CCorrente

   Label  @ 2,46 "Cheque" for "NCheque"
   Accept @ 3,47 Width 12 "A9" picture "!*!" Tag "NCheque" to VSD_NCheque

   Label  @ 2,59 "Emitente" for "TipoEmit"
   Accept @ 3,60  Width 13 "A8" picture "PROPRIO,TERCEIRO" Tag "TipoEmit" to VSD_TipoEmit
   
   Label  @ 4,00 "CPF/CNPJ" for "CPF"
   Accept @ 5,01  Width 23 "A18" picture "##[.]###.###/####-##,###.###.###-##" Tag "CPF" to VSD_CPF

   Label  @ 4,24 "Nome do Titular" for "Nome"
   Accept @ 5,25  Width 48 "A40" picture "!*!" Tag "Nome" to VSD_Nome

   Label  @ 6,00 "Cidade" for "Cidade"
   Accept @ 7,01  Width 23 "A20" picture "!*!" Tag "Cidade" to VSD_Cidade

   Label  @ 6,24 "UF" for "UF"
   Accept @ 7,25  Width 5  "A2" picture "!*!" Tag "UF" to VSD_UF

   Label  @ 6,32 "Dt.Vencimento" for "DataV"
   Accept @ 7,33  Width 13 "D" picture "#[#];.##;.##[##]" Tag "DataV" to VSD_DataV

   Label  @ 6,46 "Valor" for "Valor"
   Accept @ 7,47  Width 12 "$" picture "#*#.[##]" Tag "Valor" to VSD_Valor

  ;Label  @ 6,59 "Dt.Entrada " for "DataE"
  ;Accept @ 7,60  Width 13 "D" picture "#[#];.##;.##[##]" Tag "DataE" to VSD_DataE

   Label  @ 08,00 "Observa‡„o do Cheque" for "Obs"
   Accept @ 09,01  Width 72 "A70" picture "!*!" Tag "Obs" to VSD_Obs

   @ 10,00 ?? Format("W52,AL","[Usu rio: "+VSDGU_USUARIO+" "+Format("D13",VSDGU_DATA)+
              " "+VSDGU_HORA+" "+VSDGU_CONTROLE)+
              "Origem: "+Format("W13,AL","CT/"+VSD_Lanctoch)+"]"
   PaintCanvas Attribute 10 10, 01, 10, 72

Enddialog
Mouse Show
ImageRights

EndProc ; (DigitaCH)               
             
;*******************************************************************************
;* Rotina para Pesquisa Cheque                                                 *
;*******************************************************************************
Proc DIGITACH1()

Moveto [Codigo_Banco]
While True

     Opcao_Ver=True

      MSGCAMPO=""
      TECLA= " Esc=Retornar  F7=Paginar                PgDn/PgUp "
       
      Prompt TECLA
      Wait Field
           Until "ESC","F7","HOME","UP","PGUP"
     
     Switch
     Case RetVal="ESC":
          
          Del
          CHAVECH=9
          QuitLoop
     EndSwitch
EndWhile

EndProc   ;DIGITACH1()             
               
;*******************************************************************************
;* Rotina para Lancamento a Vista                                              *
;*******************************************************************************
Proc Digita_Baixa()
INICIO_DIALOG=True
      
ImageRights ReadOnly
MSGCAMPO=""

NC_CDTDESC=80
If [Tipo da Conta]="C" and ([Tipo de Operacao]="05" Or [Tipo de Operacao]="14")
   Then NC_CDTDESC=42   
EndIf

Showdialog "Dados da Baixa [    ]" Proc "Baixa_Dialog"
  Trigger "OPEN","ARRIVE"
    Key "F1","TAB","ReverseTab","ENTER","ESC","ClearArea","HOME","END","PGDN","PGUP","F5"
    @ 04,3 height 19 width 73

  Accept @ -01,41 Width 4 "A2" Tag "I_Seq" To VSD_I_SEQ

  Label  @ 00,00 "Dt Pagto" For "I_DtPagto"
  Accept @ 01,01 Width 13 "D" picture "#[#];.##;.##[##]" Tag "I_DtPagto" to VSD_I_DtPagto

  Label  @ 00,14 "Tipo da Baixa" For "I_TpBaixa"
  Accept @ 01,15 Width 13 "A12" picture "NORMAL,DEVOLUCAO,CANCELADO" Tag "I_TpBaixa" to VSD_I_TpBaixa

  Label  @ 00,28 "Vr Pago" For "I_Vr_Pagto"
  Accept @ 01,29 Width 13 "$" picture "#*#.[##]" Tag "I_Vr_Pagto" to VSD_I_Vr_Pagto

  Label  @ 00,42 "VrJuros/Multa" For "I_Vr_Juros"
  Accept @ 01,43 Width 13 "$" picture "#*#.[##]" Tag "I_Vr_Juros" to VSD_I_Vr_Juros

  Label  @ 00,56 "Vr Descto" For "I_Vr_Descto"
  Accept @ 01,57 Width 13 "$" picture "#*#.[##]" Tag "I_Vr_Descto" to VSD_I_Vr_Descto

  Label  @ 02,00 "Conta" For "I_Conta"
  Accept @ 03,01 Width 07 "A4" picture "#*#" Tag "I_Conta" to VSD_I_Conta
  Accept @ 03,08 Width 34 "A30" picture "!*!" Tag "I_Descricao_Conta" to VSD_I_Descricao_Conta

  Label  @ 02,60 "NDA" For "I_NDA"
  Accept @ 03,61 Width 09 "N" picture "#*#" Tag "I_NDA" to VSD_I_NDA

  Label  @ 04,00 "Tp Opera‡„o" For "I_Tpoper"
  Accept @ 05,01 Width 05 "A2" picture "#*#" Tag "I_Tpoper" to VSD_I_Tpoper
  Accept @ 05,06 Width 22 "A20" picture "!*!" Tag "I_Descricao_Tpoper" to VSD_I_Descricao_Tpoper

  Label  @ 04,28 "Tp Lan‡amento" For "I_Tplanc"
  Accept @ 05,29 Width 04 "A1" picture "&" Tag "I_Tplanc" to VSD_I_Tplanc
  Accept @ 05,33 Width 23 "A20" picture "!*!" Tag "I_Descricao_Tplanc" to VSD_I_Descricao_Tplanc

  Label  @ 06,00 "N§ CH/Docto" For "I_NoCheque"
  Accept @ 07,01 Width 13 "A11" picture "!*!" Tag "I_NoCheque" to VSD_I_NoCheque

  Label  @ 06,14 "Serie" For "I_SrCheq"
  Accept @ 07,15 Width 09 "A6" picture "!*!" Tag "I_SrCheq" to VSD_I_SrCheq

  Label  @ 06,24 "Dt Pre-Datado" For "I_DtCPrDat"
  Accept @ 07,25 Width 04 "A1" picture "S,N" Tag "I_ChPreDat" to VSD_I_ChPreDat
  Accept @ 07,29 Width 13 "D" picture "#[#];.##;.##[##]" Tag "I_DtCPrDat" to VSD_I_DtCPrDat

  Label  @ 06,NC_CDTDESC "Dt Descontado" For "I_DtDesc"
  Accept @ 07,NC_CDTDESC+1 Width 13 "D" picture "#[#];.##;.##[##]" Tag "I_DtDesc" to VSD_I_DtDesc

  Label  @ 08,00 "Plano Contas" For "I_PlContas"
  Accept @ 09,01 Width 16 "A13" picture "!*!" Tag "I_PlContas" to VSD_I_PlContas
  Accept @ 09,17 Width 53 "A40" picture "!*!" Tag "I_Descricao_PlContas" to VSD_I_Descricao_PlContas

  Label  @ 10,00 "Centro Custo" For "I_CCusto"
  Accept @ 11,01 Width 10 "A7" picture "###.###" Tag "I_CCusto" to VSD_I_CCusto
  Accept @ 11,11 Width 31 "A25" picture "!*!" Tag "I_Descricao_CCusto" to VSD_I_Descricao_CCusto

  Label  @ 10,55 "Lan‡to Cxa/Bco" For "I_LCXBC"
  Accept @ 11,61 Width 09 "A6" picture "#*#" Tag "I_LCXBC" to VSD_I_LCXBC

  Label  @ 12,00 "Historico" For "I_Codigo_Hist"
  Accept @ 13,01 Width 07 "A4" picture "#*#" Tag "I_Codigo_Hist" to VSD_I_Codigo_Hist
  Accept @ 13,08 Width 62 "A70" picture "!*!" Tag "I_Descri_Hist" to VSD_I_Descri_Hist

  Label  @ 14,00 "Observa‡äes.." For "I_ObsBaixa"
  Accept @ 15,01 Width 69 "A70" picture "!*!" Tag "I_ObsBaixa" to VSD_I_ObsBaixa

  @ 16,00 ?? Completa("[Usu rio: "+VSDGU_USUARIO+" "+Format("D13",VSDGU_DATA)+" "+VSDGU_HORA+" "+VSDGU_CONTROLE,46," ")+
             Completa("Origem "+VSDGU_ORIGEM+"/"+VSDGU_TPDOCTO+"/"+VSDGU_NUMDOCTO+"-"+VSDGU_SEQDOCTO, 23, " ")+"]"

  PaintCanvas Attribute 10 16, 01, 16, 69

Enddialog
Mouse Show
ImageRights

EndProc  ; (Digita_Baixa)

;*******************************************************************************
;* Rotina para Gravacao/Leitura Pagto a Vista                                  *
;*******************************************************************************
Proc Registro_Baixa(Funcao_Registro)
Private Funcao_Registro

Switch
  Case Funcao_Registro="Ler":
       VSD_I_SEQ                = [Sequencia da Baixa    ]
       VSD_I_LCXBC              = [Lancamento Conta Corrente]
       VSD_I_DtPagto            = [Data do Pagamento     ]
       VSD_I_TpBaixa            = [Tipo da Baixa         ]
       VSD_I_Vr_Pagto           = [Valor do Pagamento    ]
       VSD_I_Vr_Juros           = [Valor do Juros        ]
       VSD_I_Vr_Descto          = [Valor do Desconto     ]
       VSD_I_Conta              = [Codigo da Conta       ]
       VSD_I_Descricao_Conta    = [Descricao da Conta    ]
       VSD_I_NoCheque           = [Numero do Cheque      ]
       VSD_I_SrCheq             = [Serie do Cheque       ]
       VSD_I_ChPreDat           = [Cheque Pre-Datado     ]
       VSD_I_DtCPrDat           = [Data Cheque Pre-Datado]
       VSD_I_DtDesc             = [Data Cheque Descontado]
       VSD_I_PlContas           = [Codigo Plano_Conta    ]
       VSD_I_Descricao_PlContas = LTrim([Descricao Plano_Conta ])
       VSD_I_CCusto             = [Codigo CCusto         ]
       VSD_I_Descricao_CCusto   = LTrim([Descricao CCusto      ])
       VSD_I_Codigo_Hist        = [Codigo do Historico   ]
       VSD_I_Descri_Hist        = [Descricao do Historico]

       VSD_I_Tpoper             = [Tipo de Operacao      ]
       VSD_I_Descricao_Tpoper   = [Descricao Operacao    ]
       VSD_I_Tplanc             = [Tipo de Lancamento    ]
       VSD_I_Descricao_Tplanc   = [Descricao do Lancamento]
       VSD_I_NDA                = VSD_I_DtPagto-[Titulos->Data de Vencimento]
       If VSD_I_NDA<=0 Then  VSD_I_NDA=BlankNum() EndIf

       VSDGU_USUARIO = [Codigo_Usuario     ]
       VSDGU_DATA    = [Data_Inclusao      ]
       VSDGU_HORA    = [Hora_Inclusao      ]
       VSDGU_CONTROLE= [Numero_Controle_Dia]

       VSDGU_ORIGEM  = [Bx Sistema Gerador     ]
       VSDGU_TPDOCTO = [Bx Tipo Docto Gerador  ]
       VSDGU_NUMDOCTO= [Bx Numero Docto Gerador]
       VSDGU_SEQDOCTO= [Bx Sequencia Gerador   ]

       VSD_I_ObsBaixa           =  [Observacoes]
       if CHAVEI=0 And [Tipo da Conta]="C" and ([Tipo de Operacao]="05" Or [Tipo de Operacao]="14")
          then
               Moveto "\\Sistemas\\CtaCor\\MovCont"
               Moveto [Numero do Lancamento]
               Locate [TitBaixa->Lancamento Conta Corrente],
                      [TitBaixa->Codigo da Conta]
               If RetVal
                  then 
                       If [Sistema Gerador       ]="CP"                             and
                          [Empresa Gerador       ]=[TitBaixa->Codigo da Empresa   ] and
                          [Lancamento Gerador    ]=[TitBaixa->Numero do Lancamento] and
                          [Sequencia Gerador     ]=[TitBaixa->Sequencia da Baixa  ] and
                          [Codigo do Documento   ]=[Titulos->Codigo do Documento  ] and
                          [Numero do Documento   ]=[Titulos->Numero do Documento  ]
                          then 
                               VSD_I_DtDesc       =[Data Cheque Descontado        ]
                       endif   
               endif
               Moveto "TitBaixa"
       endif
EndSwitch

EndProc ;Registro_Baixa()

;*******************************************************************************
;* Rotina Carrega Parametros                                                   *
;*******************************************************************************
Proc Carrega_Parametros()
Private Result

Seta_Tipo_Impressora("Matricial")
            
if not getp_titulo([Titulos->Codigo da Empresa])
   then return false
endif   
if not getp_cheq([Titulos->Codigo da Empresa])
   then return false
endif   

Return True

EndProc ; (Carrega_Parametros)

;*******************************************************************************
;* Rotina para Carregar Tabelas                                                *
;*******************************************************************************
Proc Closed Carrega_Tabelas()
UseVars AutoLib, ErrorProc, PARAM_CONSIGNACAO, PARAM_RELAT_NF

View NoWindow "\\Sistemas\\CtaCor\\Conta"
View "\\Sistemas\\CheqRec\\ChequeI"
View "\\Sistemas\\CheqRec\\cdpessoa"
View NoWindow "TitNota"
View NoWindow "TitCheq"
View NoWindow "TitBaixa"
View NoWindow "TitRat"
View NoWindow "\\Sistemas\\CtaPag\\P_Cheque"

CoEdit "Titulos"

If ErrorCode()=4
   Then Do_It!
        ClearAll
        Release Vars All
        Release Procs All
        return
EndIf
PickForm "4"

Moveto "\\Sistemas\\CtaCor\\SaldCont"     SetHighLight Current Record 51 Field 51
Moveto "\\Sistemas\\CtaCor\\MovCont"      SetHighLight Current Record 51 Field 51
Moveto "\\Sistemas\\CheqRec\\ChequeI"     SetHighLight Current Record 51 Field 51
Moveto "\\Sistemas\\CheqRec\\cdpessoa"    SetHighLight Current Record 51 Field 51

Moveto "Titulos"
PickForm "6"

EndProc  ; (Carrega_Tabelas)

;*******************************************************************************
;* Ler ou Gravar Dados do Cheque                                               *
;*******************************************************************************
Proc Registro_ItemCH(Opcao)
Private Opcao

Switch
  Case Opcao="Ler":
       VSD_I_SEQ    =[Sequencia           ]
       If IsBlank([Numero Lancamento Cheque])
          Then VSD_Lanctoch ="CH NAO CADASTRADO"
          Else VSD_Lanctoch =StrVal([Numero Lancamento Cheque])+"/"+StrVal([Sequencia do Cheque])
       EndIf
       VSD_DataL    =[Data_Liquidado      ]
       VSD_DataV    =[Data Vencimento     ]
       VSD_CBanco   =[Codigo_Banco        ]
       VSD_NBanco   =[Nome_Banco          ]
       VSD_Agencia  =[Agencia             ]
       VSD_CCorrente=[Numero_Conta        ]
       VSD_NCheque  =[Numero_Cheque       ]
       VSD_TipoEmit =[Tipo_Emitente       ]
       VSD_Nome     =[Titular_Cheque      ]
       VSD_Cidade   =[Cidade              ]
       VSD_UF       =[UF                  ]
       VSD_Valor    =[Valor               ]
       VSD_Obs      =[Observacao do Cheque]
       VSD_CPF      =[CPF                 ]

       VSDGU_USUARIO = [Codigo_Usuario     ]
       VSDGU_DATA    = [Data_Inclusao      ]
       VSDGU_HORA    = [Hora_Inclusao      ]
       VSDGU_CONTROLE= [Numero_Controle_Dia]
EndSwitch

EndProc  ; (Registro_ItemCH)

;*******************************************************************************
;* Rotina para Iniciar Registro                                                *
;*******************************************************************************
Proc Inicia_Registro()
INICIO_DIALOG=True
Moveto [Sequencia da Baixa]
Locate NLANC,SEQIT
HIOLD =[Codigo do Historico  ]
DTOLD =[Data do Pagamento          ]
VROLD =[Valor do Pagamento         ]
JSOLD =[Valor do Juros             ]
DSOLD =[Valor do Desconto          ]
CCOLD =[Codigo da Conta            ]
NCHOLD=[Numero do Cheque           ]
DCHOLD=[Data Cheque Descontado     ]
LCOLD =[Lancamento Conta Corrente  ]

Registro_Baixa("Ler")

EndProc ;Inicia_Registro()

;*******************************************************************************
;* Rotina para controlar Edicao do registro                                    *
;*******************************************************************************
Proc Controla_EdicaoI()
  
Inicia_Registro()
Digita_Baixa()  
Moveto "TitBaixa"
If RecordStatus("Locked") Then UnLockRecord EndIf        

EndProc ;Controla_EdicaoI()

;*******************************************************************************
;* Rotina para controlar Edicao do registro                                    *
;*******************************************************************************
Proc Controla_EdicaoN()
DIGITAN()
Moveto "TitNota"
If RecordStatus("Locked") Then UnLockRecord EndIf
EndProc

;*******************************************************************************
;* Rotina para Iniciar Registro                                                *
;*******************************************************************************
Proc Inicia_RegistroCH()
INICIO_DIALOG=True
Moveto [Sequencia]
Locate NLANC,ITEM
CopyToArray RegItem
Registro_ItemCH("Ler")
EndProc ; (Inicia_Registro)

;*******************************************************************************
;* Rotina para controlar Edicao do registro                                    *
;*******************************************************************************
Proc Controla_EdicaoCH()
Inicia_RegistroCH()
DigitaCH()
Moveto "Titcheq"
If RecordStatus("Locked") Then UnLockRecord EndIf         
EndProc

;*******************************************************************************
;* Rotina para controlar Edicao do registro                                    *
;*******************************************************************************
Proc Controla_EdicaoC()
COD_EMPRESA=[Codigo da Empresa]
DIGITAC=True
DTLIQ_CH=BlankDate()

ncampop="Numero do Lancamento"
Tecla_Funcao=-10

ImageRights ReadOnly
SetaCorRegistro("Paginar")

While DIGITAC
  Moveto "Titulos"
  
  If Not Carrega_Parametros()
     Then CHAVEI=9
          DIGITAC =False
          Tecla_Funcao=""
          QuitLoop
  EndIf   

  While Not IsBlank(Tecla_Funcao)
    Switch
      Case Tecla_Funcao=-116:
           Switch
             Case Table()="Titulos"  : Tecla_Funcao="F8"       ;F8  => Baixa de T¡tulos (Titbaixa)
						 Case Table()="Titbaixa" : Tecla_Funcao="F6"       ;F6  => Lan‡amento de Cheques (Titcheq)
             Case Table()="Titcheq"  : Tecla_Funcao="F9"       ;F9  => Notinhas (Titnota)
             Case Table()="Titnota"  : Tecla_Funcao=-10        ;-10 => Informa‡äes B sicas do T¡tulo (Titulos)
             OtherWise       : Tecla_Funcao=""
           EndSwitch     
      Case Tecla_Funcao=-115:
           Switch
             Case Table()="Titulos"  : Tecla_Funcao="F9"
						 Case Table()="Titbaixa" : Tecla_Funcao=-10
             Case Table()="Titcheq"  : Tecla_Funcao="F8"
             Case Table()="Titnota"  : Tecla_Funcao="F6"
             OtherWise       : Tecla_Funcao=""
           EndSwitch
    EndSwitch

    Switch
      Case Tecla_Funcao=-10  : Moveto "Titulos"
                               DIGITAC()
                               If CHAVEC=9 Then QuitLoop EndIf
      
      Case Tecla_Funcao="F8" : 
           Moveto "Titulos"
           Moveto [Pag_4]
           Moveto "TitBaixa"
           While True
             CHAVEI()
             If CHAVEI=9 Then QuitLoop EndIf
             Controla_EdicaoI()
           EndWhile
      
      Case Tecla_Funcao="F6": 
           Moveto "Titulos"
           Moveto [Pag_2]

           Moveto "TitCheq"
           While True
             CHAVECH()
             If CHAVECH=9 Then QuitLoop EndIf
             If CHAVECH=1
                Then DigitaCH1()
                Else Controla_EdicaoCH()
             EndIf
           EndWhile
            
      Case Tecla_Funcao="F9" : 
           Moveto "Titulos"
           Moveto [Pag_3]
            
           Moveto "TitNota" 
           Saldo_Atualizado=False
           While True
             CHAVEN()
             If CHAVEN=9 Then QuitLoop EndIf
             Controla_EdicaoN()
           EndWhile
    EndSwitch
  EndWhile
EndWhile

Moveto "Titulos"
If RecordStatus("Locked") Then UnLockRecord EndIf         
If OPCAO_FORM="6"
   Then PickForm "6"
EndIf
SaveTables
EndProc

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

If Not IsAssigned(usandoconsultammaa)  Then usandoconsultammaa=false EndIf

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

Carrega_Tabelas()

CONTA=""
NLANC=""
NLANCC=0

WCSW_NLANC =BlankNum()
WCSW_SDINI =BlankNum()
WCSW_SDATU =BlankNum()
WCSW_BAIXA =BlankNum()

OPCAO_FORM="6"

While True
  vsvrcheques=BlankNum()
   CHAVEC()
   If CHAVEC=9
      Then QuitLoop
   EndIf
   If CHAVEC=5
      Then If OPCAO_FORM="6"
              Then PickForm "6"
              Else PickForm "4"
           EndIf
           Loop
   EndIf
   Controla_EdicaoC()
EndWhile
Do_it!
ClearAll

If Not usandoconsultammaa
   Then Release Vars All
        Release Procs All
   Else Release Vars usandoconsultammaa
        Release Procs CHAVEC,DigitaC,Soma_PrecoTotal,CHAVEI,Item_Dialog,DigitaI,Registro_Item,Inicia_Registro,DIGITAF,
                      DIGITAD,CHAVEV,Carrega_Tabelas,Controla_EdicaoI,Controla_EdicaoC
EndIf
