;** PD_0185E *******************************************************************
;** Imprime a Digitacao do Pedido/Grade - Expedi‡Ćo ** Territorio Nacional **  *
;*******************************************************************************
;Autor           : Vise Informatica (VISERP)
;Desenvolvido  em: 24/01/2014 por Andrey Fillipe
;Ultima Alteracao: 23/02/2018 por Anivel Augusto Rodrigues
;Motivo Alteracao: Ajustes Sort         


;*******************************************************************************
;* Checa linha na area de impressao dos itens                                  *
;*******************************************************************************
Proc Checa_Linha(nl,tp)
Private nl,tp

If (nlin+nl) >= PARAM_NLINHA
   Then NLIN = 0 + (CONT_NLINHA_VENCTO*2)
        
        Print File ARQIMP "\n"
        Print File ARQIMP Format("W131,AC","*** Continua proxima pagina ==> ")    

        Print File ARQIMP CI_10CPP
        Print File ARQIMP "\f"

        Cabecalho_Tit()
        If tp="Item"
           Then Moveto PrivDir()+"PedidoG"
                Cabecalho_Item()
        EndIf
        nlin=nlin+nl
        Return False
   Else nlin=nlin+nl
        Return True     
EndIf

EndProc ;Checa_Linha()

;*******************************************************************************
;* Verifica as Grades no Pedido                                                *
;*******************************************************************************
Proc Verifica_Grades()
Private wc,gok

DynArray Array_Grade[]
                             
Array array_tittm[12]
Moveto "\\Sistemas\\Estoque\\TpGrade"
Moveto [Codigo da Grade]
Locate Grad
If RetVal
   Then array_tittm[1] =[Titulo Grade1 ]
        array_tittm[2] =[Titulo Grade2 ]
        array_tittm[3] =[Titulo Grade3 ]
        array_tittm[4] =[Titulo Grade4 ]
        array_tittm[5] =[Titulo Grade5 ]
        array_tittm[6] =[Titulo Grade6 ]
        array_tittm[7] =[Titulo Grade7 ]
        array_tittm[8] =[Titulo Grade8 ]
        array_tittm[9] =[Titulo Grade9 ]
        array_tittm[10]=[Titulo Grade10]
        array_tittm[11]=[Titulo Grade11]
        array_tittm[12]=[Titulo Grade12]
   Else For i From 1 to 12
          array_tittm[i]=""
        EndFor
EndIf

If EXIBE_GRADE 
   Then Emite_Grade=Grad                                                        
   Else Emite_Grade=" "
EndIf

Grade=Emite_Grade+ESPACO+
      Format("W4,AR",array_tittm[01])+ESPACO+
      Format("W4,AR",array_tittm[02])+ESPACO+
      Format("W4,AR",array_tittm[03])+ESPACO+
      Format("W4,AR",array_tittm[04])+ESPACO+
      Format("W4,AR",array_tittm[05])+ESPACO+
      Format("W4,AR",array_tittm[06])+ESPACO+
      Format("W4,AR",array_tittm[07])+ESPACO+
      Format("W4,AR",array_tittm[08])+ESPACO+
      Format("W4,AR",array_tittm[09])+ESPACO+
      Format("W4,AR",array_tittm[10])+ESPACO+
      Format("W4,AR",array_tittm[11])+ESPACO+
      Format("W4,AR",array_tittm[12])+ESPACO

Release Vars wc,wi,gok,array_tittm
EndProc

;*******************************************************************************
;* Rotina para Impressao do Cabecalho titulo                                   *
;*******************************************************************************
Proc Cabecalho_Tit()
NPAG = NPAG + 1

If Not IsAssigned(NOMEMPRESA)
   Then NOMEMPRESA=""
EndIf

Moveto "PedidoC"
Print File ARQIMP CI_6LPP+CI_15CPP+"\n"
Print File ARQIMP Fill("-",132)+"\n"
Print File ARQIMP  Completa(NOMEMPRESA,55," ")+"Pedido de Venda"+Spaces(22)+"Impressao: "+Format("D13",Today())+"-"+Time()+
                        "  Pag: "+Format("W3,EIC",npag)+"\n"
Print File ARQIMP Fill("-",132)+"\n"

Print File ARQIMP Spaces(99)+"N§ do Pedido : "+CI_INEG+CI_IEXP+Format("W06.3,AL",[Numero do Pedido])+CI_FNEG+CI_FEXP+"\n\n"

NLIN = NLIN + 6

EndProc ;Cabecalho_Tit()

;*******************************************************************************
;* Rotina para Impressao do Cabecalho do Pedido                                *
;*******************************************************************************
Proc Cabecalho_Ped()

Cabecalho_Tit()

Moveto "PedidoC"
Print File ARQIMP "Cliente: "
Print File ARQIMP Format("W05,AL",[Codigo])
Print File ARQIMP Format("W65,AL",[Razao Social])
Print File ARQIMP "Contato: "+Format("W14,AL",CONTATO)
Print File ARQIMP "Ped.Origem: "+[Numero Pedido Origem]+"\n"

Print File ARQIMP Spaces(14)+Format("W40,AL",[Endereco])
Print File ARQIMP Format("W18,AL",[CGC])+Spaces(07)+"Emissao: "
Print File ARQIMP Format("D13",[Data de Emissao])+"\n"

Print File ARQIMP Spaces(14)+Format("W20,AL",[Bairro])
Print File ARQIMP Format("W20,AL",[CEP])
Print File ARQIMP Format("W25,AL",[IE])
Print File ARQIMP "Entrega: "+Format("D13",[Data de Entrega])+"\n"

Print File ARQIMP Spaces(14)+Format("W40,AL",[Cidade]+"/"+[UF])
Print File ARQIMP Format("W25,AL",[Telefone])
Print File ARQIMP "Empresa: "+Format("W05,AL",[Codigo da Empresa])+Format("W20,AL",[Nome Fantasia Empresa])+"\n\n"

Print File ARQIMP "Representante: "+Format("W05,AL",[Codigo do Representante])
Print File ARQIMP Format("W25,AL",[Nome Fantasia Represent])
Print File ARQIMP "Destinacao: "+Format("W04,AL",[Codigo da Destinacao])
Print File ARQIMP Format("W25,AL",[Descricao da Destinacao])
Print File ARQIMP "CFO: "+Format("W09,AL",[CFO])+"\n"

FRETECONTA=""
Switch
  Case [Frete por Conta]="0" : FRETECONTA="SEM FRETE"
  Case [Frete por Conta]="1" : FRETECONTA="EMITENTE"
  Case [Frete por Conta]="2" : FRETECONTA="DESTINATARIO"
  Case [Frete por Conta]="3" : FRETECONTA="TERCEIROS"
EndSwitch

Print File ARQIMP "Transportador: "+Format("W05,AL",[Codigo da Transportadora])
Print File ARQIMP Format("W28,AL",[Nome Fantasia Transport])
Print File ARQIMP "Veiculo: "+Format("W08,AL",[Placa do Veiculo])+"-"+Format("W08,AL",[UF Veiculo])
Print File ARQIMP "Frete por Conta: "+[Frete por Conta]+" "+FRETECONTA+"\n\n"

NLIN = NLIN + 1

Cabecalho_Item()

EndProc ;Cabecalho_Ped()

;*******************************************************************************
;* Rotina para Impressao do Cabecalho do Item                                  *
;*******************************************************************************
Proc Cabecalho_Item()
Private wc,linha
                                        
Print File ARQIMP Spaces(1)+Fill("-",130)+"\n"
Print File ARQIMP Spaces(1)+"Seq"+ESPACO+"Ref   "+ESPACO+"Descricao                  "+" "+Grade+" Total"+ESPACO+"UN                    "+"\n"

Print File ARQIMP Spaces(1)+"---+------+-----------------------------+----+----+----+----+----+----+----+----+----+----+----+----+------+----------------------"+"\n"

NLIN = NLIN + 3

EndProc ;Cabecalho_Item()

;*******************************************************************************
;* Imprime Totalizador                                                         *
;*******************************************************************************
Proc Totalizador()


For wi From 1 to 12
  If array_tqtd[wi]=0 then array_tqtd[wi]=BlankNum() EndIf
  array_tqtd[13]=array_tqtd[13]+array_tqtd[wi]
EndFor
 
Print File ARQIMP Spaces(1)+"----------------------------------------+----+----+----+----+----+----+----+----+----+----+----+----+------+----------------------"+"\n"

Print File ARQIMP Spaces(41)+ESPACO
Print File ARQIMP Format("W04,EIC",array_tqtd[01])+ESPACO
Print File ARQIMP Format("W04,EIC",array_tqtd[02])+ESPACO
Print File ARQIMP Format("W04,EIC",array_tqtd[03])+ESPACO
Print File ARQIMP Format("W04,EIC",array_tqtd[04])+ESPACO
Print File ARQIMP Format("W04,EIC",array_tqtd[05])+ESPACO
Print File ARQIMP Format("W04,EIC",array_tqtd[06])+ESPACO
Print File ARQIMP Format("W04,EIC",array_tqtd[07])+ESPACO
Print File ARQIMP Format("W04,EIC",array_tqtd[08])+ESPACO
Print File ARQIMP Format("W04,EIC",array_tqtd[09])+ESPACO
Print File ARQIMP Format("W04,EIC",array_tqtd[10])+ESPACO
Print File ARQIMP Format("W04,EIC",array_tqtd[11])+ESPACO
Print File ARQIMP Format("W04,EIC",array_tqtd[12])+ESPACO
Print File ARQIMP Format("W06,EIC",array_tqtd[13])+ESPACO
Print File ARQIMP Spaces(22)+"\n"

Print File ARQIMP Spaces(1)+Fill("-",130)+"\n\n"

NLIN = NLIN + 4

EndProc ;Totalizador()

;*******************************************************************************
;* Rotina para Impressao do Relatorio                                          *
;*******************************************************************************
Proc ImpPed()
Private SEQ

Array array_tqtd[14] 

For wi From 1 to 14
  array_tqtd[wi]=0
EndFor

SEQ  = 0
NPAG = 0

TOTQ = 0
TOTP = 0

MUDOU_GRADE = False

Moveto PrivDir()+"PedidoG"
Moveto [Numero do Pedido]
Locate [Pedidoc->Numero do Pedido]
Grad=[Codigo da Grade]
Verifica_Grades()
Cabecalho_Ped()
Moveto PrivDir()+"PedidoG"
While [Numero do Pedido]=[Pedidoc->Numero do Pedido]

   If Grad<>[Codigo da Grade]
      Then MUDOU_GRADE = True
           Totalizador()
           SEQ  = 0
           Grad=[Codigo da Grade]
           Verifica_Grades()
           Cabecalho_Item()
           
           For wi From 1 to 14
             array_tqtd[wi]=0
           EndFor   
   EndIf
   
   Checa_Linha(1,"Item")
   Moveto PrivDir()+"PedidoG"
   
   SEQ  = SEQ + 1
   
   Print File ARQIMP Format("W04,AR",AlinhM(StrVal(SEQ),3))+ESPACO
   Print File ARQIMP Format("W06,AL",[Referencia])+ESPACO
   Print File ARQIMP Format("W27,AL",[Descricao do Item])
   
   If Emite_Grade=" "
      Then Print File ARQIMP " " 
      Else Print File ARQIMP ESPACO 
   EndIf
   
   Print File ARQIMP Format("W01,AL",Emite_Grade)+ESPACO
   Print File ARQIMP Format("W04,EIC",[Qtd1])+ESPACO
   Print File ARQIMP Format("W04,EIC",[Qtd2])+ESPACO
   Print File ARQIMP Format("W04,EIC",[Qtd3])+ESPACO
   Print File ARQIMP Format("W04,EIC",[Qtd4])+ESPACO
   Print File ARQIMP Format("W04,EIC",[Qtd5])+ESPACO
   Print File ARQIMP Format("W04,EIC",[Qtd6])+ESPACO
   Print File ARQIMP Format("W04,EIC",[Qtd7])+ESPACO
   Print File ARQIMP Format("W04,EIC",[Qtd8])+ESPACO
   Print File ARQIMP Format("W04,EIC",[Qtd9])+ESPACO
   Print File ARQIMP Format("W04,EIC",[Qtd10])+ESPACO
   Print File ARQIMP Format("W04,EIC",[Qtd11])+ESPACO
   Print File ARQIMP Format("W04,EIC",[Qtd12])+ESPACO
   Print File ARQIMP Format("W06,EIC",[Qtd1]+[Qtd2 ]+[Qtd3 ]+[Qtd4 ]+
                                      [Qtd5]+[Qtd6 ]+[Qtd7 ]+[Qtd8 ]+
                                      [Qtd9]+[Qtd10]+[Qtd11]+[Qtd12])+ESPACO
   Print File ARQIMP Format("W02,AL",[Unidade Fiscal])+"\n"

   TOTQ = TOTQ + ([Qtd1]+[Qtd2 ]+[Qtd3 ]+[Qtd4 ]+
                  [Qtd5]+[Qtd6 ]+[Qtd7 ]+[Qtd8 ]+
                  [Qtd9]+[Qtd10]+[Qtd11]+[Qtd12])  
   TOTP = TOTP + [Preco Total] 

   array_tqtd[01]=array_tqtd[01]+[Qtd1 ]
   array_tqtd[02]=array_tqtd[02]+[Qtd2 ]
   array_tqtd[03]=array_tqtd[03]+[Qtd3 ]
   array_tqtd[04]=array_tqtd[04]+[Qtd4 ]
   array_tqtd[05]=array_tqtd[05]+[Qtd5 ]
   array_tqtd[06]=array_tqtd[06]+[Qtd6 ]
   array_tqtd[07]=array_tqtd[07]+[Qtd7 ]
   array_tqtd[08]=array_tqtd[08]+[Qtd8 ]
   array_tqtd[09]=array_tqtd[09]+[Qtd9 ]
   array_tqtd[10]=array_tqtd[10]+[Qtd10]
   array_tqtd[11]=array_tqtd[11]+[Qtd11]
   array_tqtd[12]=array_tqtd[12]+[Qtd12]

   array_tqtd[14]=array_tqtd[14]+[Preco Total]

   Skip
   If EOT() Then QuitLoop EndIf
EndWhile

Totalizador()  

EndProc ;ImpPed()

;*******************************************************************************
;* Rotina para Impressao do Rodape                                             *
;*******************************************************************************
Proc Rodape(QUEBRAFORM)
Private QUEBRAFORM

Moveto "PedidoC"
Print File ARQIMP CI_6LPP+CI_15CPP

Moveto "PedidoC"

If MUDOU_GRADE
   Then Checa_Linha(4,"")
        Print File ARQIMP " ----------------------------------------------------------------------------------------------------------------------------------"+"\n"
        Print File ARQIMP Spaces(87)+"Total Geral   "+ESPACO
        Print File ARQIMP Format("W06,EIC",TOTQ)+ESPACO+"\n"
        Print File ARQIMP " ----------------------------------------------------------------------------------------------------------------------------------"+"\n\n"
EndIf

For i From 1 To Cont_Obs
  Checa_Linha(1,"")
  Print File ARQIMP SubStr(Observacao[i],4,Len(Observacao[i])) 
EndFor 

Checa_Linha(5,"")
Print File ARQIMP "\n"+"  Mecadorias         Desconto     Liquido    Frete    Seguro   Desp.Aces         IPI       Total     BC.ICMS        ICMS"+"\n"

Print File ARQIMP Format("W12.2,EIC",[Valor Mercadoria])
Print File ARQIMP Format("W06.2,EIC",[Taxa de Desconto])+"%"
Print File ARQIMP Format("W10.2,EIC",[Valor do Desconto])
Print File ARQIMP Format("W12.2,EIC",[Valor Mercadoria Liquido])
Print File ARQIMP Format("W09.2,EIC",[Valor do Frete])
Print File ARQIMP Format("W10.2,EIC",[Valor do Seguro])
Print File ARQIMP Format("W012.2,EIC",[Valor Despesas Acessorias])
Print File ARQIMP Format("W012.2,EIC",[Valor IPI])
Print File ARQIMP Format("W012.2,EIC",[Valor Nota Fiscal])
Print File ARQIMP Format("W012.2,EIC",[Valor BCICMS])
Print File ARQIMP Format("W012.2,EIC",[Valor ICMS])+"\n\n"

Print File ARQIMP "Cond. Pagamento.: "+[Descricao CondPagto]
Print File ARQIMP "   FP: "+[Forma de Pagamento]
Print File ARQIMP "   NP: "+StrVal([Numero de Parcelas])
Print File ARQIMP "   CD: "+[Composicao de Dias]
Print File ARQIMP "   N.Volumes.: "+LTrim(Format("W06,EIC",[PedidoC->Numero de Volumes]))
Print File ARQIMP "   Peso Liquido: "+LTrim(Format("W11.3,EIC",[PedidoC->Peso Liquido]))
Print File ARQIMP "   Peso Bruto: "+LTrim(Format("W11.3,EIC",[PedidoC->Peso Bruto]))+"\n"

Imprime_Vencimentos("Imprimir")

Checa_Linha(3,"")
Moveto "PedidoC"

Print File ARQIMP "\n"
Print File ARQIMP "Local p/ Entrega: "+Format("W20,AL",[PedidoC->Endereco de Entrega])+"\n"

Print File ARQIMP Spaces(18)+Format("W15,AL",[PedidoC->Bairro de Entrega])+Format("W11,AL",[PedidoC->CEP de Entrega])
Print File ARQIMP Spaces(40)+"______________________________________________"+"\n"

Print File ARQIMP Spaces(18)+Format("W15,AL",[PedidoC->Cidade de Entrega])+Format("W03,AL",[PedidoC->UF de Entrega])
Print File ARQIMP Spaces(58)+"Data/Assinatura Responsavel"+"\n\n"

Print File ARQIMP Fill("-",132)

Print File ARQIMP CI_10CPP
Print File ARQIMP "\f"

EndProc ;Rodape()

;*******************************************************************************
;* Observa‡Ćo                                                                  *
;*******************************************************************************
Proc Obs(OBS)     
Private OBS,QTD,LABEL_OBS,LINHA,Pos_Inicio,OBS_AUX,QTD_AUX,QTD_LINHA,wia

Switch
  Case OBS="Cadastro" : OBS        = DEST_OBS
                        LABEL_OBS  = "Obs. do Cadastro: "
                        LINHA      = 0   
  Case OBS="Nota"     : OBS        = [Observacao na Nota Fiscal]
                        LABEL_OBS  = "Obs. Nota Fiscal: "
                        LINHA      = 0 
  Case OBS="Pedido"   : OBS        = [Observacao do Pedido] 
                        LABEL_OBS  = "Obs. do Pedido..: "
                        LINHA      = 0 
EndSwitch
     
Pos_Inicio=SearchFrom("\n",OBS,1) 

While True
 If Pos_Inicio > 0
    Then OBS_AUX   = SubStr(OBS,1,Pos_Inicio-1)
    Else OBS_AUX   = OBS
 EndIf   
 OBS       = SubStr(OBS,Pos_Inicio+1,Len(OBS)) 
 QTD_AUX   = Len(OBS_AUX)
 QTD_LINHA = Round(QTD_AUX/NUM_CARACTERES_OBS,0)                     
 If ((QTD_AUX/NUM_CARACTERES_OBS) - QTD_LINHA) > 0
    Then QTD_LINHA = QTD_LINHA + 1
 EndIf   
 For wia From 1 To QTD_LINHA 
   ;***Contador de linhas para cada Observa‡Ćo ***
   Switch 
     Case OBS="Pedido"   : CONT_NLIN_PED = CONT_NLIN_PED + 1
     Case OBS="Cadastro" : CONT_NLIN_CAD = CONT_NLIN_CAD + 1
     Case OBS="Nota"     : CONT_NLIN_NOT = CONT_NLIN_NOT + 1 
   EndSwitch  
   Cont_Obs = Cont_Obs + 1
   
   If LINHA = 0 
      Then LINHA = LABEL_OBS
      Else LINHA = Spaces(18)
   EndIf
   Observacao[Cont_Obs] = AlinhM(StrVal(Cont_Obs),3)+LINHA
   
   LINHA = Substr(OBS_AUX,((wia-1)*NUM_CARACTERES_OBS)+1,NUM_CARACTERES_OBS)
   Observacao[Cont_Obs] = Observacao[Cont_Obs]+"\27E"+LINHA+"\27F"+"\n"   
 EndFor
 If Pos_Inicio = 0 Then Quitloop EndIf
 Pos_Inicio=SearchFrom("\n",OBS,1)                
EndWhile  
LINHA = ""  
        
EndProc ;Obs()

;*******************************************************************************
;* Imprime Vencimentos                                                         *
;*******************************************************************************
Proc Imprime_Vencimentos(Param)
Private Param,wii

Switch
  Case Param = "Monta_Vencimentos" : 
       VENCTO = "Vencimentos....: " 
        
       CONT_NLINHA_VENCTO = 0
        
       DynArray NLINHA1_VENCTO[]
       DynArray NLINHA2_VENCTO[]
        
       Array DATA[7]
       Array VALOR[7]
       K=0
       LISTA=1
        
       If Not IsEmpty("PedidoV")
          Then Moveto "PedidoV"                   
               Moveto [Numero do Pedido]
               Locate [PedidoC->Numero do Pedido]
               While [Numero do Pedido]=[PedidoC->Numero do Pedido]
                 K=K+1
                 DATA[K]  = Format("D13",[Data])
                 VALOR[K] = Format("W10.2,EIC",[Valor])
                 If K=7
                    Then VENC()
                         K=0
                 EndIf
                 Skip
                 If EOT() Then QuitLoop EndIf
               EndWhile
               If K>0
                  Then VENC()
               EndIf
       EndIf
  Case Param = "Imprimir" :
       For wii From 1 To CONT_NLINHA_VENCTO
         Print File ARQIMP NLINHA1_VENCTO[wii]+"\n"
         Print File ARQIMP NLINHA2_VENCTO[wii]+"\n"  
       EndFor
EndSwitch

EndProc ;Imprime_Vencimentos()

;*******************************************************************************
;* Rotina de Impressao dos Vencimentos                                         *
;*******************************************************************************
Proc VENC()

CONT_NLINHA_VENCTO = CONT_NLINHA_VENCTO + 1

NLINHA1_VENCTO[CONT_NLINHA_VENCTO] = ""
NLINHA2_VENCTO[CONT_NLINHA_VENCTO] = ""

If LISTA>1
   Then NLINHA1_VENCTO[CONT_NLINHA_VENCTO] = NLINHA1_VENCTO[CONT_NLINHA_VENCTO] + Spaces(20)
EndIf

LISTA=LISTA+1
For I From 1 to K
  NLINHA1_VENCTO[CONT_NLINHA_VENCTO] = NLINHA1_VENCTO[CONT_NLINHA_VENCTO] + VENCTO + Spaces(03)+DATA[I]+Spaces(02)
  If VENCTO<>"" Then VENCTO="" EndIf
EndFor                                                               

NLINHA2_VENCTO[CONT_NLINHA_VENCTO] = NLINHA2_VENCTO[CONT_NLINHA_VENCTO] + Spaces(23)  
For I From 1 to K
  NLINHA2_VENCTO[CONT_NLINHA_VENCTO] = NLINHA2_VENCTO[CONT_NLINHA_VENCTO] + VALOR[I]+Spaces(05)
EndFor

EndProc ;VENC()

;*******************************************************************************
;* Rotina Principal                                                            *
;*******************************************************************************
AGUARDE("Imprimindo Pedido -> "+PEDIDO)

ArqImp=PrivDir()+"PD_0185E.Txt"

;**** Setando variaveis ********************************************************
EXIBE_GRADE        = False
ESPACO             = "|"
NLIN               = 0
NUM_CARACTERES_OBS = 110
PARAM_NLINHA       = 65
LINHAS_OBS         = False
DEST_OBS           = "" 
CONTATO            = ""
Cont_Obs           = 0
CONT_NLIN_PED      = 0
CONT_NLIN_CAD      = 0
CONT_NLIN_NOT      = 0

;****** Adicionando tabelas para trabalho **************************************
FormKey 
View NoWindow "Pedidog"
CoEditKey
Do_It!

;*******************************************************************************
View "\\Sistemas\\Cadastro\\DestObs"
Moveto [Codigo]
Locate [PedidoC->Codigo]
If RetVal
   Then If Not IsBlank([Observacoes])
           Then DEST_OBS=[Observacoes]
        EndIf
EndIf
Do_It!
ClearImage

;*******************************************************************************
View "\\Sistemas\\Cadastro\\Destinat"

Moveto [Codigo]
Locate [PedidoC->Codigo]
If RetVal
   Then If Not IsBlank([Contato])
           Then CONTATO=[Contato]
        EndIf
EndIf
Do_It!
ClearImage

{Ask} {Pedidog} Check
Moveto [Numero do Pedido] TypeIn "~PEDIDO.."
Do_It!
ClearAll

Sort "Answer" on "Codigo da Grade","Referencia","Codigo do Item" ClearAll
Copy "Answer" PrivDir()+"PedidoG" clearall

View "PedidoC"
Moveto [Numero do Pedido]
Locate PEDIDO

View "PedidoV"
View "\\Sistemas\\Estoque\\TpGrade"
Coedit PrivDir()+"PedidoG"  

;**** Calcula o numero de linhas para impressao da observacao ******************
Moveto "PedidoC"
DynArray Observacao[]

Obs("Pedido")
Obs("Cadastro")
Obs("Nota")

NLIN = NLIN + 7 ;Rodape True

Imprime_Vencimentos("Monta_Vencimentos")
NLIN = NLIN + (CONT_NLINHA_VENCTO*2)

;*******************************************************************************
Moveto PrivDir()+"PedidoG"

ImpPed()
Rodape(False)

ImpriArq(ARQIMP)

Do_It!
;*******************************************************************************
LimpAguarde()

Release Vars  PARAM_NLINHA,NLIN,nl,tp,wc,wi,gok,Array_Grade,Grad,array_tittm,NPAG,
              NOMEMPRESA,ARQIMP,CONTATO,FRETECONTA,linha,Grade,array_tqtd,SEQ,
              TOTQ,TOTP,DATA,VALOR,K,Cont_Obs,OBS,LABEL_OBS,Pos_Inicio,OBS_AUX,QTD_AUX,
              QTD_LINHA,NUM_CARACTERES_OBS,Observacao,array_vrvencto,array_dtvencto,
              CONT_NLIN_PED,CONT_NLIN_CAD,CONT_NLIN_NOT,CONT_NLIN_PED,CONT_NLIN_CAD,
              CONT_NLIN_NOT,Param,wii

Release Procs Checa_Linha,Verifica_Grades,Cabecalho_Tit,Cabecalho_Ped,Cabecalho_Item,
              Rodape,Totalizador,ImpPed,VENC,Obs,Seta_FilePrint,ImpriArq,ImpPed,
              Imprime_Vencimentos
