;** Ft_Imp *********************************************************************
;*  Manutencao Grupo de Impostos Importacao                                    *
;*******************************************************************************
;Autor           : Vise Informatica (VISERP)
;Desenvolvido    : 17/03/2016 por Anivel Augusto Rodrigues
;Ultima Alteracao: 04/04/2016 por Anivel Augusto Rodrigues  
;Motivo Alteracao: Ajustes

;*******************************************************************************
;* Carrega Arrays dados Importacao                                             *
;*******************************************************************************
Proc IICarrega_Arrays_Lista(tipo)
Private tipo, indice, wi

wi=0

switch
  case tipo="DECLARACAO":

    DynArray IIArray_Lista_Declaracao[]
      
    switch
      case APLIC_ORIGEM="NOTA":
        Moveto "NotaiDD"
      	Moveto [Codigo da Empresa]
      	Locate EMPRESA,NUMDOC,SERIE,SEQIT
    
      otherwise:
        Moveto "FaturIDD"
        Moveto [Numero da OF]                        
        Locate ORDFAT,SEQIT
      
    endswitch
    If RetVal
       then
            While true
    
              switch
                case APLIC_ORIGEM="NOTA":
                  if [Codigo da Empresa       ]<>EMPRESA or  
                     [Numero do Documento     ]<>NUMDOC  or 
                     [Serie do Documento      ]<>SERIE   or 
                     [Item do Documento       ]<>SEQIT  
                     then quitloop
                  endif   
              
                otherwise:
                  if [Numero da OF            ]<>ORDFAT  or
                     [Item da OF              ]<>SEQIT   
                     then quitloop
                  endif   
              
              endswitch
              
              Wi=Wi+1
              IIAddListaArray(tipo, wi)
    
              Skip
              If EOT() Then QuitLoop EndIf
            EndWhile
    endif

  case tipo="ADICAO":
    Release vars IIArray_Lista_Adicao
    
    DynArray IIArray_Lista_Adicao[]  

    switch
      case APLIC_ORIGEM="NOTA":
        Moveto "NotaiAD"
      	Moveto [Codigo da Empresa]
      	Locate EMPRESA,NUMDOC,SERIE,SEQIT,VSD_I_SEQ
    
      otherwise:
        Moveto "FaturIAD"
        Moveto [Numero da OF]                        
        Locate ORDFAT,SEQIT,VSD_I_SEQ 
      
    endswitch
    If RetVal
       then
            While true
    
              switch
                case APLIC_ORIGEM="NOTA":
                  if [Codigo da Empresa       ]<>EMPRESA or  
                     [Numero do Documento     ]<>NUMDOC  or 
                     [Serie do Documento      ]<>SERIE   or 
                     [Item do Documento       ]<>SEQIT   or  
                     [Sequencia_Doc_Importacao]<>VSD_I_SEQ   
                     then quitloop
                  endif   
              
                otherwise:
                  if [Numero da OF            ]<>ORDFAT  or
                     [Item da OF              ]<>SEQIT   or
                     [Sequencia_Doc_Importacao]<>VSD_I_SEQ          
                     then quitloop
                  endif   
              
              endswitch
              
              Wi=Wi+1
              IIAddListaArray(tipo, wi)

              Skip
              If EOT() Then QuitLoop EndIf
            EndWhile
    endif

endswitch

endproc

;*******************************************************************************
;*                                                                             *
;*******************************************************************************
proc IIAddListaArray(tipo, indice)
private tipo, indice  

switch
  case tipo="DECLARACAO":
    IIArray_Lista_Declaracao[indice]=Format("W04,AL",Alinhm(StrVal([Sequencia_Doc_Importacao]),2))+
                                     Format("W13,AL",[Numero_DocImportacao])+
                                     Completa(Format("D13",[Data_Registro_DI_DSI_DA]),11," ")+
                                     Format("W21,AL",[Nome_Exportador])+Spaces(01)+
                                     Format("W13,AL",[Local_Desembaraco])+Spaces(01)+
                                     Completa(Format("D13",[Data_Desembaraco]),10," ")

  case tipo="ADICAO":
    IIArray_Lista_Adicao[indice]    =Format("W05,AL",Alinhm(StrVal([Sequencia_Adicao]),2))+
                                     Format("W06,AL",StrVal([Numero_Adicao]))+
                                     Format("W05,AL",[Sequencia_Adicao])+                                     
                                     Format("W28,AL",[Nome_Fabricante])+
                                     Format("W12.2",[Valor_Desconto_Adicao])+spaces(1)+
                                     Format("W11,AL",StrVal([Numero_AtoConc_Drawback]))

endswitch

endproc

;*******************************************************************************
;*                                                                             *
;*******************************************************************************
proc IIGravaListaArray(tipo)
private tipo

switch
  case tipo="DECLARACAO":
    switch
      case APLIC_ORIGEM="NOTA":
        Moveto "NotaiDD"
      	Moveto [Codigo da Empresa]
      	Locate EMPRESA,NUMDOC,SERIE,SEQIT,VSD_I_SEQ
    
      otherwise:
        Moveto "FaturIDD"
        Moveto [Numero da OF]                        
        Locate ORDFAT,SEQIT,VSD_I_SEQ
      
    endswitch
    If not RetVal
       then
            switch
              case APLIC_ORIGEM="NOTA":
                Moveto "NotaiDD"
                End Down
                [Codigo da Empresa  ]=EMPRESA
                [Numero do Documento]=NUMDOC           
                [Serie do Documento ]=SERIE
                [Item do Documento  ]=SEQIT   
            
              otherwise:
                Moveto "FaturIDD"
                End Down
                [Numero da OF       ]=ORDFAT
                [Item da OF         ]=SEQIT
              
            endswitch
    endif
    [Sequencia_Doc_Importacao]=VSD_I_SEQ
    [Numero_DocImportacao    ]=VSD_I_NumR
    [Data_Registro_DI_DSI_DA ]=VSD_I_DataR
    [Codigo_Exportador       ]=VSD_I_Exportador
    [Nome_Exportador         ]=VSD_I_NExportador
    [Local_Desembaraco       ]=VSD_I_Local_DEC
    [UF_Desembaraco          ]=VSD_I_UF_DEC
    [Data_Desembaraco        ]=VSD_I_DATA_DEC
    [Tipo_ViaTransporte      ]=VSD_I_TpViaTransp
    [Valor_AFRMM             ]=VSD_I_VrAFRMM
    [Tipo_Intermediacao      ]=VSD_I_TpIntermedio
    [CNPJ_AdqEncomendante    ]=VSD_I_CNPJ_AE
    [UF_AdqEncomendante      ]=VSD_I_UF_AE

    IIAddListaArray(tipo, IIPegaIndiceDaLista(Tipo,VSD_I_SEQ))
    UnLockRecord


  case tipo="ADICAO":
    switch
      case APLIC_ORIGEM="NOTA":
        Moveto "NotaiAD"
      	Moveto [Codigo da Empresa]
      	Locate EMPRESA,NUMDOC,SERIE,SEQIT,VSD_I_SEQ,VSD_I_Seq_A
    
      otherwise:
        Moveto "FaturIAD"
        Moveto [Numero da OF]                        
        Locate ORDFAT,SEQIT,VSD_I_SEQ, VSD_I_Seq_A
      
    endswitch
    If not RetVal
       then
            switch
              case APLIC_ORIGEM="NOTA":
                Moveto "NotaiAD"
                End Down
                [Codigo da Empresa  ]=EMPRESA
                [Numero do Documento]=NUMDOC           
                [Serie do Documento ]=SERIE
                [Item do Documento  ]=SEQIT   
            
              otherwise:
                Moveto "FaturIAD"
                End Down
                [Numero da OF       ]=ORDFAT
                [Item da OF         ]=SEQIT
              
            endswitch
    endif
    [Sequencia_Doc_Importacao]=VSD_I_SEQ
    [Sequencia_Adicao        ]=VSD_I_Seq_A
    [Numero_Adicao           ]=VSD_I_NumA
    [Sequencia_Item_NaAdicao ]=VSD_I_Seq_IA
    [Codigo_Fabricante       ]=VSD_I_Fabricante
    [Nome_Fabricante         ]=VSD_I_NFabricante
    [Valor_Desconto_Adicao   ]=VSD_I_Desconto
    if not isblank(VSD_I_NumD)
       then [Numero_AtoConc_Drawback ]=numval(VSD_I_NumD)
       else [Numero_AtoConc_Drawback ]=blanknum()
    endif   

    IIAddListaArray(tipo, IIPegaIndiceDaLista(Tipo,VSD_I_Seq_A))
    UnLockRecord

endswitch

endproc

;*******************************************************************************
;* Exclusao das Informaäes Adicionais do Item                                 *
;*******************************************************************************
Proc IIExclusao_Lista(tipo,indice)
private tipo, indice

switch
  case tipo="DECLARACAO":
    VSD_I_SEQ=IIPegaSequenciaDaLista(Tipo,indice)

    If DynArraySize(IIArray_Lista_Declaracao)>0 
       and ConfGeral("Confirma a excluso deste registro ?")
       then 
            switch
              case APLIC_ORIGEM="NOTA":
                Moveto "NotaiAD"
              	Moveto [Codigo da Empresa]
              	Locate EMPRESA,NUMDOC,SERIE,SEQIT,VSD_I_SEQ 
            
              otherwise:
                Moveto "FaturIAD"
                Moveto [Numero da OF]                        
                Locate ORDFAT,SEQIT,VSD_I_SEQ
              
            endswitch
            If RetVal
               then
                    While true
                      switch
                        case APLIC_ORIGEM="NOTA":
                          if [Codigo da Empresa       ]<>EMPRESA or  
                             [Numero do Documento     ]<>NUMDOC  or 
                             [Serie do Documento      ]<>SERIE   or 
                             [Item do Documento       ]<>SEQIT   or  
                             [Sequencia_Doc_Importacao]<>VSD_I_SEQ   
                             then quitloop
                          endif   
                      
                        otherwise:
                          if [Numero da OF            ]<>ORDFAT  or
                             [Item da OF              ]<>SEQIT   or
                             [Sequencia_Doc_Importacao]<>VSD_I_SEQ          
                             then quitloop
                          endif   
                      
                      endswitch
                      del
                      If EOT() Then QuitLoop EndIf
                    EndWhile
            endif
                    
            switch
              case APLIC_ORIGEM="NOTA":
                Moveto "NotaiDD"
              	Moveto [Codigo da Empresa]
              	Locate EMPRESA,NUMDOC,SERIE,SEQIT,VSD_I_SEQ
            
              otherwise:
                Moveto "FaturIDD"
                Moveto [Numero da OF]                        
                Locate ORDFAT,SEQIT,VSD_I_SEQ
              
            endswitch
            If RetVal
               then del
               
                    IIRefazLista(tipo,VSD_I_SEQ)
                    release vars IIArray_Lista_Adicao
            endif
    EndIf

  case tipo="ADICAO":
    VSD_I_SEQ_A=IIPegaSequenciaDaLista(Tipo,indice)

    If DynArraySize(IIArray_Lista_Adicao)>0 
       and ConfGeral("Confirma a excluso deste registro ?")
       then 
            switch
              case APLIC_ORIGEM="NOTA":
                Moveto "NotaiAD"
              	Moveto [Codigo da Empresa]
              	Locate EMPRESA,NUMDOC,SERIE,SEQIT,VSD_I_SEQ,VSD_I_SEQ_A
            
              otherwise:
                Moveto "FaturIAD"
                Moveto [Numero da OF]                        
                Locate ORDFAT,SEQIT,VSD_I_SEQ, VSD_I_SEQ_A
              
            endswitch
            If RetVal
               then del
               
                    IIRefazLista(tipo,VSD_I_SEQ_A)
            endif
    endif
    
endswitch

EndProc   ;  IIExclusao_Lista()       

;*******************************************************************************
;*                                                                             *
;*******************************************************************************
proc IIRefazLista(Tipo,seq)
private Tipo, seq, wi, wc, IIArray_Lista_Temp

release vars IIArray_Lista_Temp
DynArray IIArray_Lista_Temp[]
                    
wc=0
                    
switch
  case tipo="DECLARACAO": 
    for wi from 1 to DynArraySize(IIArray_Lista_Declaracao) 
      if seq<>IIPegaSequenciaDaLista(Tipo,wi)
         then wc=wc+1
              IIArray_Lista_Temp[wc]=IIArray_Lista_Declaracao[wi]
      endif   
    endfor
    release vars IIArray_Lista_Declaracao
    DynArray IIArray_Lista_Declaracao[]
    
    If DynArraySize(IIArray_Lista_Temp)>0
       then       
            for wi from 1 to DynArraySize(IIArray_Lista_Temp) 
              IIArray_Lista_Declaracao[wi]=IIArray_Lista_Temp[wi]
            endfor
    endif

  case tipo="ADICAO"    : 
    for wi from 1 to DynArraySize(IIArray_Lista_Adicao) 
      if seq<>IIPegaSequenciaDaLista(Tipo,wi)
         then wc=wc+1
              IIArray_Lista_Temp[wc]=IIArray_Lista_Adicao[wi]
      endif   
    endfor
    release vars IIArray_Lista_Adicao
    DynArray IIArray_Lista_Adicao[]
    
    If DynArraySize(IIArray_Lista_Temp)>0
       then       
            for wi from 1 to DynArraySize(IIArray_Lista_Temp) 
              IIArray_Lista_Adicao[wi]=IIArray_Lista_Temp[wi]
            endfor
    endif

endswitch

release vars IIArray_Lista_Temp

endproc

;*******************************************************************************
;*                                                                             *
;*******************************************************************************
proc IICarregaItemDaLista(Tipo)
private Tipo

switch
  case tipo="DECLARACAO":
    switch
      case APLIC_ORIGEM="NOTA":
        Moveto "NotaiDD"
      	Moveto [Codigo da Empresa]
      	Locate EMPRESA,NUMDOC,SERIE,SEQIT,VSD_I_SEQ
    
      otherwise:
        Moveto "FaturIDD"
        Moveto [Numero da OF]                        
        Locate ORDFAT,SEQIT,VSD_I_SEQ
      
    endswitch
    If RetVal
       then
            VSD_I_NumR         =[Numero_DocImportacao    ]
            VSD_I_DataR        =[Data_Registro_DI_DSI_DA ]
            VSD_I_Exportador   =[Codigo_Exportador       ]
            VSD_I_NExportador  =[Nome_Exportador         ]
            VSD_I_Local_DEC    =[Local_Desembaraco       ]
            VSD_I_UF_DEC       =[UF_Desembaraco          ]
            VSD_I_DATA_DEC     =[Data_Desembaraco        ]
            VSD_I_TpViaTransp  =[Tipo_ViaTransporte      ]
            VSD_I_VrAFRMM      =[Valor_AFRMM             ]
            VSD_I_TpIntermedio =[Tipo_Intermediacao      ]
            VSD_I_CNPJ_AE      =[CNPJ_AdqEncomendante    ]
            VSD_I_UF_AE        =[UF_AdqEncomendante      ]

            IIVerificaTipos("TRANSPORTE"   ,VSD_I_TpViaTransp )
            IIVerificaTipos("INTERMEDIACAO",VSD_I_TpIntermedio)
            
       Else 
            VSD_I_NumR         =""       
            VSD_I_DataR        =BlankDate()
            VSD_I_Exportador   =""
            VSD_I_NExportador  =""
            VSD_I_Local_DEC    =""
            VSD_I_UF_DEC       =""
            VSD_I_DATA_DEC     =BlankDate()
            VSD_I_TpViaTransp  =""
            VSD_I_VrAFRMM      =blanknum()
            VSD_I_TpIntermedio =""
            VSD_I_CNPJ_AE      =""
            VSD_I_UF_AE        =""
    endif

  case tipo="ADICAO":
    switch
      case APLIC_ORIGEM="NOTA":
        Moveto "NotaiAD"
      	Moveto [Codigo da Empresa]
      	Locate EMPRESA,NUMDOC,SERIE,SEQIT,VSD_I_SEQ,VSD_I_Seq_A
    
      otherwise:
        Moveto "FaturIAD"
        Moveto [Numero da OF]                        
        Locate ORDFAT,SEQIT,VSD_I_SEQ, VSD_I_Seq_A
      
    endswitch
    If RetVal
       then
            VSD_I_NumA         =[Numero_Adicao           ]
            VSD_I_Seq_IA       =[Sequencia_Item_NaAdicao ]
            VSD_I_Fabricante   =[Codigo_Fabricante       ]
            VSD_I_NFabricante  =[Nome_Fabricante         ]
            VSD_I_Desconto     =[Valor_Desconto_Adicao   ]
            VSD_I_NumD         =[Numero_AtoConc_Drawback ]
       Else 
            VSD_I_NumA         =BlankNum()
            VSD_I_Seq_IA       =BlankNum()
            VSD_I_Fabricante   =""
            VSD_I_NFabricante  =""
            VSD_I_Desconto     =BlankNum()
            VSD_I_NumD         =BlankNum()
    endif

endswitch

endproc

;*******************************************************************************
;*                                                                             *
;*******************************************************************************
proc IIProximaSequencia(Tipo)
private Tipo, seq

seq=0
switch
  case tipo="DECLARACAO":
    switch
      case APLIC_ORIGEM="NOTA":
        Moveto "NotaiDD"
      	Moveto [Codigo da Empresa]
      	Locate EMPRESA,NUMDOC,SERIE,SEQIT
    
      otherwise:
        Moveto "FaturIDD"
        Moveto [Numero da OF]                        
        Locate ORDFAT,SEQIT
      
    endswitch
    If RetVal
       then while true
              switch
                case APLIC_ORIGEM="NOTA":
                  if [Codigo da Empresa       ]<>EMPRESA or  
                     [Numero do Documento     ]<>NUMDOC  or 
                     [Serie do Documento      ]<>SERIE   or 
                     [Item do Documento       ]<>SEQIT  
                     then quitloop
                  endif   
              
                otherwise:
                  if [Numero da OF            ]<>ORDFAT  or
                     [Item da OF              ]<>SEQIT   
                     then quitloop
                  endif   
                
              endswitch
              seq=[Sequencia_Doc_Importacao]
              skip
              if eot() then quitloop endif
            endwhile
    endif

  case tipo="ADICAO":
    switch
      case APLIC_ORIGEM="NOTA":
        Moveto "NotaiAD"
      	Moveto [Codigo da Empresa]
      	Locate EMPRESA,NUMDOC,SERIE,SEQIT,VSD_I_SEQ
    
      otherwise:
        Moveto "FaturIAD"
        Moveto [Numero da OF]                        
        Locate ORDFAT,SEQIT,VSD_I_SEQ
      
    endswitch
    If RetVal
       then while true
              switch
                case APLIC_ORIGEM="NOTA":
                  if [Codigo da Empresa       ]<>EMPRESA or  
                     [Numero do Documento     ]<>NUMDOC  or 
                     [Serie do Documento      ]<>SERIE   or 
                     [Item do Documento       ]<>SEQIT   or
                     [Sequencia_Doc_Importacao]<>VSD_I_SEQ
                     then quitloop
                  endif   
              
                otherwise:
                  if [Numero da OF            ]<>ORDFAT  or
                     [Item da OF              ]<>SEQIT   or   
                     [Sequencia_Doc_Importacao]<>VSD_I_SEQ
                     then quitloop
                  endif   
                
              endswitch
              seq=[Sequencia_Adicao]
              skip
              if eot() then quitloop endif
            endwhile
    endif

endswitch

return seq+1
endproc


;*******************************************************************************
;*                                                                             *
;*******************************************************************************
proc IIPegaSequenciaDaLista(Tipo,indice)
private Tipo, seq

seq=0
switch
  case tipo="DECLARACAO": seq=NumVal(AlinhM(SubStr(IIArray_Lista_Declaracao[indice],1,2),2))

  case tipo="ADICAO"    : seq=NumVal(AlinhM(SubStr(IIArray_Lista_Adicao[indice]    ,1,2),2))

endswitch

return seq
endproc

;*******************************************************************************
;*                                                                             *
;*******************************************************************************
proc IIPegaIndiceDaLista(Tipo,seq)
private Tipo, seq, indice, wi

indice=0
switch
  case tipo="DECLARACAO": 
    If DynArraySize(IIArray_Lista_Declaracao)>0
       then for wi from 1 to DynArraySize(IIArray_Lista_Declaracao) 
              if seq=IIPegaSequenciaDaLista(Tipo,wi)
                 then indice=wi
                      quitloop
              endif   
            endfor
    endif
    if indice=0 then indice=DynArraySize(IIArray_Lista_Declaracao)+1 endif
  case tipo="ADICAO"    : 
    If DynArraySize(IIArray_Lista_Adicao)>0
       then for wi from 1 to DynArraySize(IIArray_Lista_Adicao) 
              if seq=IIPegaSequenciaDaLista(Tipo,wi)
                 then indice=wi
                      quitloop
              endif   
            endfor
    endif
    if indice=0 then indice=DynArraySize(IIArray_Lista_Adicao)+1     endif

endswitch

return indice
endproc

;*******************************************************************************
;* Rotina de Controle p/ ShowDialog                                            *
;*******************************************************************************
Proc II_Dialog(Disparo,Campo,Evento,Elemento)
Private Disparo,Campo,Evento,Elemento, 
        tab_ref, indicelista, okgravar

Temp=True

If II_INICIO_DIALOG
   Then II_INICIO_DIALOG=False
        Switch
          Case II_TELA=1: Campo="II_BC"
                    Dynarray IIWinArray51[]
                    Window Handle Dialog to IIJANELA1
                    Window GetAttributes IIJANELA1 To IIWinArray51
          
          Case II_TELA=2: Campo="I_NumR"
                    Dynarray IIWinArray52[]
                    Window Handle Dialog to IIJANELA2
                    Window GetAttributes IIJANELA2 To IIWinArray52
          
          Case II_TELA=3: Campo="I_NumA"
                    Dynarray IIWinArray53[]
                    Window Handle Dialog to IIJANELA3
                    Window GetAttributes IIJANELA3 To IIWinArray53
           
        EndSwitch
EndIf

If Disparo="OPEN"
   Then
        TiraSombraShowDialog()
EndIf        

If Disparo="EVENT" And DynArraySize(Evento)>0 And Evento["Type"]="KEY" Then
   Switch
       Case Evento["KeyCode"] = 9:
            Temp=False
            
       Case Evento["KeyCode"] = -59 :  
     
            If Campo="I_Exportador" Or
               Campo="I_UF_DEC"     or 
               Campo="I_UF_AE"      or
               Campo="I_Fabricante"    
               Then
                    Tab_Ref = Table()
                    
                    IIWinArray50["FLOATING"]=False
                    Window SetAttributes IIJANELA0 From IIWinArray50

                    IIWinArray51["FLOATING"]=False
                    Window SetAttributes IIJANELA1 From IIWinArray51

                    IIWinArray52["FLOATING"]=False
                    Window SetAttributes IIJANELA2 From IIWinArray52

                    If Campo="I_Fabricante"    
                       Then
                            IIWinArray53["FLOATING"]=False
                            Window SetAttributes IIJANELA3 From IIWinArray53
                    endif

                    If APLIC_ORIGEM="NOTA"
                       Then Switch
                              Case Campo="I_Exportador"    : Moveto [NotaIDD->Codigo_Exportador  ]  
                              Case Campo="I_UF_DEC"        : Moveto [NotaIDD->UF_Desembaraco     ]
                              Case Campo="I_UF_AE"         : Moveto [NotaIDD->UF_AdqEncomendante ]
                              Case Campo="I_Fabricante"    : Moveto [NotaIAD->Codigo_Fabricante  ]
                            EndSwitch 
                       Else Switch
                              Case Campo="I_Exportador"    : Moveto [FaturIDD->Codigo_Exportador ]  
                              Case Campo="I_UF_DEC"        : Moveto [FaturIDD->UF_Desembaraco    ]
                              Case Campo="I_UF_AE"         : Moveto [FaturIDD->UF_AdqEncomendante]
                              Case Campo="I_Fabricante"    : Moveto [FaturIAD->Codigo_Fabricante ]
                            EndSwitch 
                    EndIf

                    If ConsultaF1()   
                       Then Switch
                              Case Campo="I_Exportador":
                                   VSD_I_Exportador=Reg_ConsultaF1["Codigo"]
                                   VSD_I_NExportador=Reg_ConsultaF1["Razao Social"]

                              Case Campo="I_UF_DEC"       :   
                                   VSD_I_UF_DEC=Reg_ConsultaF1["UF"]

                              Case Campo="I_UF_AE"       :   
                                   VSD_I_UF_AE=Reg_ConsultaF1["UF"]

                              Case Campo="I_Fabricante"   :        
                                   VSD_I_Fabricante=Reg_ConsultaF1["Codigo"]
                                   VSD_I_NFabricante=Reg_ConsultaF1["Razao Social"]

                            EndSwitch        
                    EndIf                          
               
                    Window Select IIJANELA0
                    IIWinArray50["FLOATING"] =True
                    IIWinArray50["HASSHADOW"] =False
                    Window SetAttributes IIJANELA0 From IIWinArray50
  
                    Window Select IIJANELA1
                    IIWinArray51["FLOATING"] =True
                    IIWinArray51["HASSHADOW"] =False
                    Window SetAttributes IIJANELA1 From IIWinArray51
  
                    Window Select IIJANELA2
                    IIWinArray52["FLOATING"] =True
                    IIWinArray52["HASSHADOW"] =False
                    Window SetAttributes IIJANELA2 From IIWinArray52
  
                    If Campo="I_Fabricante"    
                       Then
                            Window Select IIJANELA3
                            IIWinArray53["FLOATING"] =True
                            IIWinArray53["HASSHADOW"] =False
                            Window SetAttributes IIJANELA3 From IIWinArray53
                    endif

                    echo Normal
                    echo off
                    
                    Moveto Tab_Ref
                    
                    Temp=False        
            EndIf
            
            If Campo="I_TpViaTransp" 
               Then
                    ShowPopup " Vias de Transporte " CENTERED
                     "~1~ Mar¡tima                   " : "" :"1",
                     "~2~ Fluvial                    " : "" :"2",
                     "~3~ Lacustre                   " : "" :"3",
                     "~4~ Area                      " : "" :"4",
                     "~5~ Postal                     " : "" :"5",
                     "~6~ Ferrovi ria                " : "" :"6",
                     "~7~ Rodori ria                 " : "" :"7",
                     "~8~ Conduto/Rede de TransmissÆo" : "" :"8",
                     "~9~ Meios Pr¢prios             " : "" :"9",
                     "10 Entrada/Sa¡da Ficta        " : "" :"10",
                     "11 Courier                    " : "" :"11",
                     "12 Handcarry                  " : "" :"12",
                     Separator,
                     "~S~air"                          : " Ignorar opäes"                    :"Cancela"
                    EndMenu
                    To MenuVar
      
                    Echo Off
                    If MenuVar<>"Cancela" and MenuVar<>"Esc"
                       Then VSD_I_TpViaTransp=MenuVar
                            IIVerificaTipos("TRANSPORTE",VSD_I_TpViaTransp)
                    EndIf                                         
            endif
            
            If Campo="I_TpIntermedio" 
               Then
                    ShowPopup " Tipos de Intemediaäes " CENTERED
                     "~1~ ImportaÆo por Conta Pr¢pria " : "" :"1",
                     "~2~ ImportaÆo por Conta e Ordem " : "" :"2",
                     "~3~ ImportaÆo por Encomenda     " : "" :"3",
                     Separator,
                     "~S~air"                 : " Ignorar opäes"                    :"Cancela"
                    EndMenu
                    To MenuVar
      
                    Echo Off
                    If MenuVar<>"Cancela" and MenuVar<>"Esc"
                       Then VSD_I_TpIntermedio=MenuVar
                            IIVerificaTipos("INTERMEDIACAO",VSD_I_TpIntermedio)
                    EndIf                                         
            endif
            
       Case Evento["KeyCode"] =-147:
            Switch
              Case Campo="I_ListaDeclaracao"   : 
                indicelista=ArrayElement
                IIExclusao_Lista("DECLARACAO",ArrayElement)
                ArrayElement=indicelista
               
              Case Campo="I_ListaAdicao"       : 
                indicelista=ArrayElement
                IIExclusao_Lista("ADICAO",    ArrayElement)
                ArrayElement=indicelista
                
            EndSwitch
                                           
      Case Evento["KeyCode"] = "PGDN" Or  Evento["KeyCode"] = -81 : 
           If Campo="I_ListaDeclaracao" or
              Campo="I_ListaAdicao"        
              then AcceptDialog
           endif
              
       Case Evento["KeyCode"] = -82 Or Evento["KeyCode"] = "INS" :
            If Campo="I_ListaDeclaracao" 
               Then 
                    VSD_I_Seq=IIProximaSequencia("DECLARACAO")
                    IIDeclaracaoAdicoes()
            EndIf   

            If Campo="I_ListaAdicao" 
               Then 
                    VSD_I_Seq_A=IIProximaSequencia("ADICAO")
                    IIAdicao()
            EndIf   

      Case Evento["KeyCode"] = 27:  
           Temp=False
           Switch
             Case Campo="II_BC"              : CancelDialog
             Case Campo="II_Valor Imposto"   : Campo="II_BC"
             Case Campo="II_Valor DespAduan" : Campo="II_Valor Imposto"
             Case Campo="II_Valor IOF"       : Campo="II_Valor DespAduan"

             Case Campo="I_Seq"              : CancelDialog 
             case Campo="I_NumR"             : Campo="I_Seq" 
             Case Campo="I_DataR"            : Campo="I_NumR"
             Case Campo="I_Exportador"       : Campo="I_DataR"
             Case Campo="I_Local_DEC"        : Campo="I_Exportador"
             Case Campo="I_UF_DEC"           : Campo="I_Local_DEC"
             Case Campo="I_DATA_DEC"         : Campo="I_UF_DEC" 
             Case Campo="I_TpViaTransp"      : Campo="I_DATA_DEC"
             Case Campo="I_VrAFRMM"          : Campo="I_TpViaTransp" 
             Case Campo="I_TpIntermedio"     : Campo="I_TpViaTransp" 
             Case Campo="I_CNPJ_AE"          : Campo="I_TpIntermedio" 
             Case Campo="I_UF_AE"            : Campo="I_CNPJ_AE" 

             Case Campo="I_Seq_A"            : CancelDialog 
             case Campo="I_NumA"             : Campo="I_Seq_A" 
             Case Campo="I_Seq_IA"           : Campo="I_NumA" 
             Case Campo="I_Fabricante"       : Campo="I_Seq_IA"
             Case Campo="I_Desconto"         : Campo="I_Fabricante"
             Case Campo="I_NumD"             : Campo="I_Desconto" 
           EndSwitch

      Case Evento["KeyCode"] = 13:  
           Switch
             Case Campo="II_BC"               : Campo="II_Valor Imposto" 
                  VSD_II_BC=ControlValue("II_BC")

             Case Campo="II_Valor Imposto"    : Campo="II_Valor DespAduan"
                  VSD_II_Valor_Imp=ControlValue("II_Valor Imposto")

             Case Campo="II_Valor DespAduan"  : Campo="II_Valor IOF" 
                  VSD_II_Valor_Desp=ControlValue("II_Valor DespAduan")

             Case Campo="II_Valor IOF"        : Campo="II_Valor Imposto" 
                  VSD_II_Valor_IOF=ControlValue("II_Valor IOF")

                  If (VSD_II_BC+VSD_II_Valor_Desp+VSD_II_Valor_IOF+VSD_II_Valor_Imp)=0
                     Then Mensagem("Valores de Importao Inv lidos!")
                          Campo="II_BC"
                     Else Campo="I_ListaDeclaracao"
                  EndIf

                  
             ;-- Lista DeclaraÆo ----------------------------------------------
             Case Campo="I_ListaDeclaracao"        :
                  If DynArraySize(IIArray_Lista_Declaracao)>0
                     then
                          indicelista=ArrayElement

                          VSD_I_Seq=IIPegaSequenciaDaLista("DECLARACAO",ArrayElement)
                          IICarregaItemDaLista("DECLARACAO")
                          IICarrega_Arrays_Lista("ADICAO")
                          ArrayElement=1
                          IIDeclaracaoAdicoes()

                          ArrayElement=indicelista
                          
                  endif

             ;-- DeclaraÆo ----------------------------------------------------
             Case Campo="I_Seq"         :  
                  VSD_I_Seq=ControlValue("I_Seq")
                  If IsBlank(VSD_I_Seq) Or VSD_I_Seq = 0 
                     Then VSD_I_Seq=IIProximaSequencia("DECLARACAO")
                  EndIf
                  IICarregaItemDaLista("DECLARACAO")
                  IICarrega_Arrays_Lista("ADICAO")
                  Campo="I_NumR"
                  
             Case Campo="I_NumR"          : Campo="I_DataR"
                  VSD_I_NumR=ControlValue("I_NumR")
             Case Campo="I_DataR"         : Campo="I_Exportador"
                  VSD_I_DataR=ControlValue("I_DataR")
             Case Campo="I_Exportador"    : Campo="I_Local_DEC"
                  VSD_I_Exportador=ControlValue("I_Exportador")
                  If Not IsBlank(VSD_I_Exportador)
                     Then 
                          getrecord "\\sistemas\\cadastro\\destinat" VSD_I_Exportador to regdestinat 
                          if retval
                             Then VSD_I_NExportador=regdestinat["Razao Social"] 
                             Else Mensagem("Exportador no Cadastrado !")
                                  Campo="I_Exportador"
                         EndIf
                 EndIf
             Case Campo="I_Local_DEC"     : Campo="I_UF_DEC"
                  VSD_I_Local_DEC=ControlValue("I_Local_DEC")
                  
             Case Campo="I_UF_DEC"        : Campo="I_DATA_DEC"
                  VSD_I_UF_DEC=ControlValue("I_UF_DEC")
                  If Not IsBlank(VSD_I_UF_DEC)
                     Then 
                          getrecord "\\sistemas\\Vendas\\estados" VSD_I_UF_DEC to regestados
                          If not RetVal
                             Then Mensagem("UF Inv lido!")
                                  Campo="I_UF_DEC"
                         EndIf
                 EndIf                   
                  
             Case Campo="I_DATA_DEC"      : Campo="I_TpViaTransp" 
                  VSD_I_DATA_DEC=ControlValue("I_DATA_DEC")                                 

             Case Campo="I_TpViaTransp"   : Campo="I_VrAFRMM" 
                  VSD_I_TpViaTransp=ControlValue("I_TpViaTransp")  

                  If Not IsBlank(VSD_I_TpViaTransp)
                     Then 
                          if not IIVerificaTipos("TRANSPORTE",VSD_I_TpViaTransp)
                             Then FastMsg("Transporte Inv lido!") 
                                  Campo="I_TpViaTransp"
                             else 
                                  if VSD_I_TpViaTransp<>"1"
                                     then 
                                          VSD_I_VrAFRMM=blanknum()
                                          Campo="I_TpIntermedio"
                                  endif
                          EndIf
                     else VSD_I_NTpViaTransp=""     
                  EndIf                   
                                                 
             Case Campo="I_VrAFRMM"       : Campo="I_TpIntermedio" 
                  VSD_I_VrAFRMM=ControlValue("I_VrAFRMM") 
                                                   
             Case Campo="I_TpIntermedio"  : Campo="I_CNPJ_AE" 
                  VSD_I_TpIntermedio=ControlValue("I_TpIntermedio")

                  If Not IsBlank(VSD_I_TpIntermedio)
                     Then 
                          if not IIVerificaTipos("INTERMEDIACAO",VSD_I_TpIntermedio)
                             Then FastMsg("IntermediaÆo Inv lida!") 
                                  Campo="I_TpIntermedio"
                             else
                                  if VSD_I_TpIntermedio="1"
                                     then 
                                          VSD_I_CNPJ_AE=""
                                          VSD_I_UF_AE  =""
                                          
                                          IIGravarDados(("DECLARACAO"))
                                  endif
                          EndIf
                     else VSD_I_NTpIntermedio=""
                  EndIf                   

                                                   
             Case Campo="I_CNPJ_AE"       : Campo="I_UF_AE" 
                  VSD_I_CNPJ_AE=ControlValue("I_CNPJ_AE")
                                                   
             Case Campo="I_UF_AE"         : 
                  VSD_I_UF_AE=ControlValue("I_UF_AE")                                 

                  okgravar=true
                  If Not IsBlank(VSD_I_UF_AE)
                     Then 
                          getrecord "\\sistemas\\Vendas\\estados" VSD_I_UF_AE to regestados
                          If not RetVal
                             Then Mensagem("UF Inv lido!")
                                  Campo="I_UF_AE"
                                  okgravar=false
                         EndIf
                  EndIf                   

                  if okgravar
                     then
                          IIGravarDados(("DECLARACAO"))
                  endif

             ;-- Lista Adicao --------------------------------------------------
             Case Campo="I_ListaAdicao"        :
                  If DynArraySize(IIArray_Lista_Adicao)>0
                     then 
                          VSD_I_Seq_A=IIPegaSequenciaDaLista("ADICAO",ArrayElement)
                          IICarregaItemDaLista("ADICAO")
                          IIAdicao()
                  endif

             ;-- Adicao --------------------------------------------------------
             Case Campo="I_Seq_A"         :  
                  VSD_I_Seq_A=ControlValue("I_Seq_A")
                  If IsBlank(VSD_I_Seq_A) Or VSD_I_Seq_A = 0 
                     Then VSD_I_Seq_A=IIProximaSequencia("ADICAO")
                  endif   
                  IICarregaItemDaLista("ADICAO")
                  Campo="I_NumA"
                  
             Case Campo="I_NumA"          : Campo="I_Seq_IA"
                  VSD_I_NumA=ControlValue("I_NumA")
                  
             Case Campo="I_Seq_IA"         : Campo="I_Fabricante" 
                  VSD_I_Seq_IA=ControlValue("I_Seq_IA")
                  
             Case Campo="I_Fabricante"    : Campo="I_Desconto"
                  VSD_I_Fabricante=ControlValue("I_Fabricante")
                  If Not IsBlank(VSD_I_Fabricante)
                     Then 
                          getrecord "\\sistemas\\cadastro\\destinat" VSD_I_Fabricante to regdestinat 
                          if retval
                             Then VSD_I_NFabricante=regdestinat["Razao Social"]
                             Else Mensagem("Fabricante no Cadastrado !")
                                  Campo="I_Fabricante"
                         EndIf
                 EndIf
             Case Campo="I_Desconto"      : 
                  VSD_I_Desconto=ControlValue("I_Desconto")
                  campo="I_NumD"
                  
             Case Campo="I_NumD"      : 
                  VSD_I_NumD=ControlValue("I_NumD")

                  IIGravarDados(("ADICAO"))

           EndSwitch
   EndSwitch
EndIf

SelectControl Campo

TECLA=" Esc=Retornar  "
If Campo="I_ListaDeclaracao" or
   Campo="I_ListaAdicao"
   Then TECLA=TECLA+"Ins=Novo  Enter=Editar  Ctrl+Del=Excluir  PgDn=Finalizar"
EndIf

switch
  case II_TELA=1: 

  case II_TELA=2:

  case II_TELA=3: 

endswitch

Switch 
  Case Campo="II_BC"              : MSGCAMPO="Valor Base de C lculo do Imposto de ImportaÆo"
  Case Campo="II_Valor Imposto"   : MSGCAMPO="Valor Imposto de ImportaÆo"
  Case Campo="II_Valor DespAduan" : MSGCAMPO="Valor Despesas Aduaneiras"
  Case Campo="II_Valor IOF"       : MSGCAMPO="Valor Imposto sobre Operaäes Financeiras"

  Case Campo="I_Seq"              : MSGCAMPO="Sequencia da DeclaraÆo"
  Case Campo="I_NumR"             : MSGCAMPO="N£mero do Documento de Importao DI/DSI/DA"
  Case Campo="I_DataR"            : MSGCAMPO="Data de Registro da DI/DSI/DA"
  Case Campo="I_Exportador"       : MSGCAMPO="C¢digo do Exportador"
  Case Campo="I_Local_DEC"        : MSGCAMPO="Local de Desembarao"
  Case Campo="I_UF_DEC"           : MSGCAMPO="Sigla da UF onde ocorreu o Desembarao Aduaneiro"
  Case Campo="I_DATA_DEC"         : MSGCAMPO="Data do Desembarao Aduaneiro"

  Case Campo="I_TpViaTransp"      : MSGCAMPO="Via de Transporte"
  Case Campo="I_VrAFRMM"          : MSGCAMPO="Valor da AFRMM"
  Case Campo="I_TpIntermedio"     : MSGCAMPO="Tipo de IntermediaÆo"
  Case Campo="I_CNPJ_AE"          : MSGCAMPO="CNPJ do Adquriente ou Encomendante"
  Case Campo="I_UF_AE"            : MSGCAMPO="UF do Adquriente ou Encomendante"

  Case Campo="I_Seq_A"            : MSGCAMPO="Sequencia da Adio"
  Case Campo="I_NumA"             : MSGCAMPO="N£mero da Adio"
  Case Campo="I_Seq_IA"           : MSGCAMPO="N£mero sequencial do Item dentro da Adio"
  Case Campo="I_Fabricante"       : MSGCAMPO="C¢digo do Fabricante Estrangeiro"
  Case Campo="I_Desconto"         : MSGCAMPO="Valor  do Desconto do Item da DI - Adio"
  Case Campo="I_NumD"             : MSGCAMPO="N£mero do ato concess¢rio de Drawback 9 ou 11 d¡gitos"

  OtherWise                       : MSGCAMPO=""
EndSwitch                             

If Campo="I_Exportador"  Or 
   Campo="I_UF_DEC"      Or 
   Campo="I_Fabricante"  or
   Campo="I_TpViaTransp" or
   Campo="I_TpIntermedio"
   Then MSGCAMPO=MSGCAMPO+", [F1]Consultar tabela"
EndIf

MontaRodapeSD(MSGCAMPO, TECLA)

Mouse Hide
RefreshDialog
Return TEMP
EndProc     ;  (Geral_Dialog)

;*******************************************************************************
;*                                                                             *
;*******************************************************************************
Proc IIVerificaTipos(tipo,valor)
private tpok, s

tpok=true
switch
  case tipo="TRANSPORTE"   :
    switch
      case valor="1"  : VSD_I_NTpViaTransp ="MARÖTIMA"
      case valor="2"  : VSD_I_NTpViaTransp ="FLUVIAL"
      case valor="3"  : VSD_I_NTpViaTransp ="LACUSTRE"
      case valor="4"  : VSD_I_NTpViaTransp ="AREA"
      case valor="5"  : VSD_I_NTpViaTransp ="POSTAL"
      case valor="6"  : VSD_I_NTpViaTransp ="FERROVOµRIA"
      case valor="7"  : VSD_I_NTpViaTransp ="RODOVIµRIA"
      case valor="8"  : VSD_I_NTpViaTransp ="CONDUTO/REDE TRANSMISSÇO"
      case valor="9"  : VSD_I_NTpViaTransp ="MEIOS PRàPRIOS"
      case valor="10" : VSD_I_NTpViaTransp ="ENTRADA/SAÖDA Ficta"
      case valor="11" : VSD_I_NTpViaTransp ="COURIER"
      case valor="12" : VSD_I_NTpViaTransp ="HANDCARRY"
      otherwise       : VSD_I_NTpViaTransp ="" 
                        tpok=false 
    endswitch
                       
  case tipo="INTERMEDIACAO":
    switch
      case valor="1"  : VSD_I_NTpIntermedio="PRàPRIA"
      case valor="2"  : VSD_I_NTpIntermedio="ORDEM"
      case valor="3"  : VSD_I_NTpIntermedio="ENCOMENDA"
      otherwise       : VSD_I_NTpIntermedio="" 
                        tpok=false 
    endswitch
    
endswitch

return tpok
endproc

;*******************************************************************************
;*                                                                             *
;*******************************************************************************
Proc IIGravarDados(tipo)
private tipo

switch
  case tipo="DECLARACAO": 
    IIGravaListaArray("DECLARACAO")

    IICarrega_Arrays_Lista("ADICAO")
    Campo="I_ListaAdicao"

  case tipo="ADICAO"    : 
    IIGravaListaArray("ADICAO")
    
    AcceptDialog

endswitch

endproc

;*******************************************************************************
;*                                                                             *
;*******************************************************************************
Proc IIAdicao()

IICarregaItemDaLista("ADICAO")

II_TELA          = 3
II_INICIO_DIALOG = True
Mouse Hide 

Showdialog "AdiÆo" Proc "II_Dialog"
   Trigger "OPEN"
   ;;;,"ARRIVE"
    Key "F1","TAB","ReverseTab","ENTER","ESC","PGDN","ClearArea"
     @ 16,01 height 06 width 78                                                     

   Label  @ 00,00 "Seq" For "I_Seq_A"
   Accept @ 01,01 Width 05 "S" picture "##" Tag "I_Seq_A" to VSD_I_Seq_A     
          
   Label  @ 00,06 "N£mero" For "I_NumA"
   Accept @ 01,07 Width 06 "S" picture "###" Tag "I_NumA" to VSD_I_NumA
  
   Label  @ 00,13 "SIA" For "I_Seq_IA"
   Accept @ 01,14 Width 05 "S" picture "##" Tag "I_Seq_IA" to VSD_I_Seq_IA     
          
   Label  @ 00,19 "Fabricante " For "I_Fabricante"
   Accept @ 01,20 Width 07 "A4" picture "[&,#][#*#]" Tag "I_Fabricante" to VSD_I_Fabricante
   Accept @ 01,27 Width 19 "A20" Picture "!*!" Tag "I_NFabricante" To VSD_I_NFabricante

   Label  @ 00,46 "Vr Desconto" For "I_Desconto"
   Accept @ 01,47 Width 13 "N" picture "#*#.[##]" Tag "I_Desconto" to VSD_I_Desconto

   Label  @ 00,60 "N. Drawback" For "I_NumD"
   Accept @ 01,61 Width 14 "A11" picture "#*#" Tag "I_NumD" to VSD_I_NumD

EndDialog

II_TELA = 2
Mouse Show

EndProc

;*******************************************************************************
;* Rotina p/ organizar array                                                   *
;*******************************************************************************
Proc IIDeclaracaoAdicoes()

If (VSD_II_BC+VSD_II_Valor_Desp+VSD_II_Valor_IOF+VSD_II_Valor_Imp)=0
   Then Mensagem("Valores de Importao Inv lidos!")
        Return
EndIf

IICarregaItemDaLista("DECLARACAO")
IICarrega_Arrays_Lista("ADICAO")

II_TELA          = 2
II_INICIO_DIALOG = True
Mouse Hide 

Showdialog "Declarao da Importao" Proc "II_Dialog"
   Trigger "OPEN"
   ;;;,"ARRIVE"
    Key "F1","F3",-61,"TAB","ReverseTab","PGDN","ENTER","INS","ESC","ClearArea",-66,-6,-147,-82,-81
     @ 07,00 height 16 width 80                                                     

   Label  @ 00,00 "Seq" For "I_Seq"
   Accept @ 01,01 Width 05 "S" picture "##" Tag "I_Seq" to VSD_I_Seq     
     
   Label  @ 00,06 "N§ DI/DSI/DIRE.." For "I_NumR"                                                      
   Accept @ 01,07 Width 16 "A12" picture "!*!" Tag "I_NumR" to VSD_I_NumR                                
                                                                                                       
   Label  @ 00,23 "Dt Reg.Docto" For "I_DataR"                                                       
   Accept @ 01,24 Width 13 "D" picture "#[#];.##;.##[##]" Tag "I_DataR" to VSD_I_DataR                    
   
   Label  @ 00,37 "Exportador " For "I_Exportador"
   Accept @ 01,38 Width 07 "A4" picture "[&,#][#*#]" Tag "I_Exportador" to VSD_I_Exportador
   Accept @ 01,45 Width 32 "A20" Picture "!*!" Tag "I_NExportador" To VSD_I_NExportador

   Label  @ 02,00 "Local de Desembarao" For "I_Local_DEC"
   Accept @ 03,01 Width 56 "A45" picture "!*!" Tag "I_Local_DEC" to VSD_I_Local_DEC

   Label  @ 02,57 "<=UF" For "I_UF_DEC"
   Accept @ 03,58 Width 05 "A2" picture "!*!" Tag "I_UF_DEC" to VSD_I_UF_DEC     
     
   Label  @ 02,63 "Dt Des.Aduan" For "I_DATA_DEC"
   Accept @ 03,64 Width 13 "D" picture "#[#];.##;.##[##]" Tag "I_DATA_DEC" to VSD_I_DATA_DEC


   Label  @ 04,00 "Via Transporte" For "I_TpViaTransp"
   Accept @ 05,01 Width 05 "A2"  picture "#*#" Tag "I_TpViaTransp"  to VSD_I_TpViaTransp
   Accept @ 05,05 Width 15 "A20" picture "!*!" Tag "I_NTpViaTransp" to VSD_I_NTpViaTransp

   Label  @ 04,23 "Vr AFRMM" For "I_VrAFRMM"
   Accept @ 05,24 Width 13 "N" picture "#*#.[##]" Tag "I_VrAFRMM" to VSD_I_VrAFRMM

   Label  @ 04,37 "Intermedio" For "I_TpIntermedio"
   Accept @ 05,38 Width 04 "A1" picture "#"   Tag "I_TpIntermedio"  to VSD_I_TpIntermedio
   Accept @ 05,41 Width 08 "A9" picture "!*!" Tag "I_nTpIntermedio" to VSD_I_nTpIntermedio

   Label  @ 04,49 "CNPJ Adquir/Encom" for "I_CNPJ_AE"
   Accept @ 05,50  Width 21 "A18" picture "##.###.###/####-##" Tag "I_CNPJ_AE" to VSD_I_CNPJ_AE

   Label  @ 04,71 "<=UF" For "I_UF_AE"
   Accept @ 05,72 Width 05 "A2" picture "!*!" Tag "I_UF_AE" to VSD_I_UF_AE     
     

   Frame Single From 07,00 to 13,77
   @ 07,01 ?? " Adiäes da DeclaraÆo "
          
   @ 08,01 ?? " Seq  N£mero SIA Fabricante                      Desconto N. Drawback" 
               ;XXXX 9999999999 XXXX 999999999999999999999 9999.99
   PickDynArray @09,01 Height 4 width 76
   Columns 1
    IIArray_Lista_Adicao
     Tag "I_ListaAdicao"
      To ArrayElement 

EndDialog

II_TELA = 1
Mouse Show

EndProc

;*******************************************************************************
;* Rotina Declaracao II                                                        *
;*******************************************************************************
Proc IIDadosImportacao()

Dynarray IIWinArray50[]
Window Handle Dialog to IIJANELA0
Window GetAttributes IIJANELA0 To IIWinArray50

UnLockRecord
If APLIC_ORIGEM="NOTA"
   Then Moveto "NotaC"
   Else Moveto "FaturaC"  
EndIf
UnLockRecord
FormKey
IsLockRecord()

If APLIC_ORIGEM="NOTA"
   Then Moveto "NotaI"
   Else Moveto "FaturaI"  
EndIf

VSD_II_BC        =[II_BC             ]
VSD_II_Valor_Imp =[II_Valor Imposto  ]
VSD_II_Valor_Desp=[II_Valor DespAduan]
VSD_II_Valor_IOF =[II_Valor IOF      ]

IICarrega_Arrays_Lista("DECLARACAO")

II_TELA          = 1
II_INICIO_DIALOG = True
Mouse Hide
                      
Showdialog "Grupo Imposto de Importao" Proc "II_Dialog"
   Trigger "OPEN"
   ;;;,"ARRIVE"
    Key "F1","F3",-61,"TAB","ReverseTab","PGDN","ENTER","INS","ESC","ClearArea",-66,-6,-147,-82,-81
     @ 07,00 height 16 width 80

   Frame Single From 00,00 to 03,77
   @ 00,01 ?? " Valores de Importao "

   Label  @ 01,01 "BC II" For "II_BC"
   Accept @ 02,01 Width 12 "$" picture "#*#.[###]" Tag "II_BC" to VSD_II_BC

   Label  @ 01,14 "Vr II" For "II_Valor Imposto"
   Accept @ 02,14 Width 12 "$" picture "#*#.[###]" Tag "II_Valor Imposto" to VSD_II_Valor_Imp

   Label  @ 01,26 "Vr Dsp.Aduan" For "II_Valor DespAduan"
   Accept @ 02,27 Width 12 "$" picture "#*#.[###]" Tag "II_Valor DespAduan" to VSD_II_Valor_Desp

   Label  @ 01,40 "Vr IOF " For "II_Valor IOF"
   Accept @ 02,40 Width 12 "$" picture "#*#.[###]" Tag "II_Valor IOF" to VSD_II_Valor_IOF
    
   Frame Single From 04,00 to 13,77
   @ 04,01 ?? " Declaraäes da Importao "
   @ 05,01 ?? " Seq N£mero       Dt.Reg.Doc Exportador            Local             Data"
               ;XXX 9999999999  99.99.9999  xxxxxxxxxxxxxxxxxxxxx 999999999999  99.99.9999
               ;4   10          D10         4    13                12            D10       
   PickDynArray @06,01 Height 7 width 76
   Columns 1
    IIArray_Lista_Declaracao
     Tag "I_ListaDeclaracao"
      To ArrayElement

EndDialog
Mouse Show

If APLIC_ORIGEM="NOTA"
   Then Moveto "NotaC"
   Else Moveto "FaturaC"  
EndIf
UnLockRecord
FormKey
IsLockRecord()

If APLIC_ORIGEM="NOTA"
   Then Moveto "NotaI"
        Moveto [Item do Documento]
   	  	Locate SEQIT  

   Else Moveto "FaturaI"
        Moveto [Item da OF       ]
        Locate SEQIT
        
EndIf
[II_BC             ]=VSD_II_BC        
[II_Valor DespAduan]=VSD_II_Valor_Desp
[II_Valor IOF      ]=VSD_II_Valor_IOF 
[II_Valor Imposto  ]=VSD_II_Valor_Imp 

EndProc  ;IIDadosImportacao()

;*******************************************************************************
;* Rotina Principal                                                            *
;*******************************************************************************
If Not IsAssigned(Carrega_Array_Importacao) Then Carrega_Array_Importacao=False EndIf
If Not IsAssigned(Verifica_Importacao) Then Verifica_Importacao="NAO" EndIf
If Not IsAssigned(Cancelar_Importacao) Then Cancelar_Importacao=False EndIf
If Not IsAssigned(CANCELA_IMPORTACAO_FTIMP) Then CANCELA_IMPORTACAO_FTIMP=False EndIf

okimportacao=true

if okimportacao
   then IIDadosImportacao()
endif   

Release Vars  II_TELA, II_INICIO_DIALOG, 
              IIArray_Lista_Declaracao, IIArray_Lista_Adicao, 
              okimportacao,
              IIJANELA0, IIWinArray50,
              IIJANELA1, IIWinArray51,
              IIJANELA2, IIWinArray52,
              IIJANELA3, IIWinArray53 
              
Release Procs IICarrega_Arrays_Lista, IIAddListaArray, IIGravaListaArray, IIExclusao_Lista, IIRefazLista,
              IICarregaItemDaLista, IIProximaSequencia, IIPegaSequenciaDaLista, IIPegaIndiceDaLista,
              II_Dialog, IIAdicao, IIDeclaracaoAdicoes, IIDadosImportacao, IIVerificaTipos, IIGravarDados
              
              
