;** Pd_0326G *******************************************************************
;** Imprime a Digitacao do Pedido/Grade c/preco           ** HROPER **         *
;*******************************************************************************
;Autor           : Vise Informatica (VISERP)
;Desenvolvido  em: 06/12/2012 por Anivel Augusto Rodrigues
;Alterado em     : 14/12/2012 por Bruno Carvalho 
;Motivo Alteracao: Ajustes p/ agrupar itens de mesma grade e os separando quando for grade diferente                               
;Alterado em     : 21/12/2012 por Bruno Carvalho 
;Motivo Alteracao: Removido a label "Total da Grade" e "Total Geral", assim como o total de cada grade e o total geral delas                               
;Alterado em     : 25/01/2013 por Bruno Carvalho 
;Motivo Alteracao: Comentado a linha que totalizavam a grade
;Ultima Alteracao: 23/02/2018 por Anivel Augusto Rodrigues
;Motivo Alteracao: Ajustes Sort         
;Ultima Alteracao: 05/12/2018 por Anivel Augusto Rodrigues
;Motivo Alteracao: Ajustes finalizar clearall

;*******************************************************************************
;* Verifica Vencimentos do Pedido                                              *
;*******************************************************************************
Proc Verifica_Vencimentos()
Private wc

DynArray array_dtvencto[]
DynArray array_vrvencto[]
wc=0

If Not IsEmpty("PedidoV")
   Then Moveto "PedidoV"
        Moveto [Numero do Pedido]
        Locate [PedidoC->Numero do Pedido]
        While [Numero do Pedido]=[PedidoC->Numero do Pedido]
          wc=wc+1
          array_dtvencto[wc]=Format("D13",[Data])
          array_vrvencto[wc]=Format("W10.2,EIC",[Valor])
          Skip
          If EOT() Then QuitLoop EndIf
        EndWhile
EndIf

Release Vars wc
EndProc

;*******************************************************************************
;* Imprime Vencimentos do Pedido                                               *
;*******************************************************************************
Proc Imprime_Vencimentos()
Private tit_vencto,linha_dtvencto,linha_vrvencto,wi,wc

tit_vencto    ="Vencimentos.....: "
linha_dtvencto=""
linha_vrvencto=""
wi=0
For wc From 1 to DynArraySize(Array_dtvencto)
  wi=wi+1

  linha_dtvencto=linha_dtvencto+array_dtvencto[wc]+Spaces(02)
  linha_vrvencto=linha_vrvencto+array_vrvencto[wc]+Spaces(02)

  If wi=12
     Then Checa_Linha(2,"")
          Print File ARQIMP "  "+tit_vencto+linha_dtvencto+"\n"
          Print File ARQIMP Spaces(18)+linha_vrvencto+"\n"

          wi            =0
          tit_vencto    =Spaces(18)
          linha_dtvencto=""
          linha_vrvencto=""
  EndIf
EndFor
If wi>0
   Then Checa_Linha(2,"")
        Print File ARQIMP "  "+tit_vencto+linha_dtvencto+"\n"
        Print File ARQIMP Spaces(18)+linha_vrvencto+"\n"
EndIf

Release Vars tit_vencto,linha_dtvencto,linha_vrvencto,wi,wc
EndProc
            
;*******************************************************************************
;* Imprime Observacoes do Pedido                                               *
;*******************************************************************************
Proc Imprime_Observacoes()
Private obs,tit_obs,wi,wc,tamobs,nlobs,posobs,tit_obs
 
CoeditKey
IsLockRecord()

;***************************************************

tamobs=152
For wc From 1 To 3
	Switch
    Case wc=1 : obs    =[PedidoC->Observacao do Pedido     ]
                tit_obs="   "+"Obs. do Pedido..: "
    Case wc=2 : obs    =[PedidoC->Observacao na Nota Fiscal]
                tit_obs="   "+"Obs. Nota Fiscal: "
    Case wc=3 : If DEST_OBS<>""
                   Then obs    =DEST_OBS
                        tit_obs="Obs. do Cliente.: "
                   Else QuitLoop
                EndIf                   
	EndSwitch
                                 
  nlobs=Len(obs)/tamobs
	If nlobs-Int(nlobs)>0
		 Then nlobs=Int(nlobs)+1
		 Else nlobs=Int(nlobs)
	EndIf
	If nlobs=0 Then nlobs=1 EndIf

	posobs=1
	For wi from 1 to nlobs
		Checa_Linha(1,"")
    Print File ARQIMP tit_obs+"\027E"+SubStr(obs,posobs,tamobs)+"\027F"+"\n"
    tit_obs=Spaces(18)
    posobs =posobs+tamobs
	EndFor
EndFor

Release Vars obs,tit_obs,wi,wc,tamobs,nlobs,posobs,tit_obs
EndProc

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

DynArray Array_Grade[]

CodGrade = "***"

Moveto Tabela
Moveto [Numero do Pedido]
Locate [Pedidoc->Numero do Pedido]
While [Numero do Pedido]=[Pedidoc->Numero do Pedido]
  gok=False
  For wc From 1 to DynArraySize(Array_Grade)
    If Array_Grade[wc]=[Codigo da Grade]
       Then gok =True
    EndIf
  EndFor
  
  If Not gok
     Then Array_Grade[DynArraySize(Array_Grade)+1]=Completa([Codigo da Grade],1," ")
          CodGrade=Completa([Codigo da Grade],1," ")
  EndIf

  Skip
  If EOT() Then QuitLoop EndIf
EndWhile

Array array_tittm[12]
Moveto "\\Sistemas\\Estoque\\TpGrade"
Moveto [Codigo da Grade]
For wc From 1 to DynArraySize(Array_Grade)
  Locate SubStr(Array_Grade[wc],1,1)
  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

  Array_Grade[wc]=Array_Grade[wc]+"Ý"+
                  Format("W4,AR",array_tittm[01])+"Ý"+
                  Format("W4,AR",array_tittm[02])+"Ý"+
                  Format("W4,AR",array_tittm[03])+"Ý"+
                  Format("W4,AR",array_tittm[04])+"Ý"+
                  Format("W4,AR",array_tittm[05])+"Ý"+
                  Format("W4,AR",array_tittm[06])+"Ý"+
                  Format("W4,AR",array_tittm[07])+"Ý"+
                  Format("W4,AR",array_tittm[08])+"Ý"+
                  Format("W4,AR",array_tittm[09])+"Ý"+
                  Format("W4,AR",array_tittm[10])+"Ý"+
                  Format("W4,AR",array_tittm[11])+"Ý"+
                  Format("W4,AR",array_tittm[12])+"Ý"
EndFor
Moveto Tabela

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("-",172)+"\n"
Print File ARQIMP "   "+Completa(NOMEMPRESA,55," ")+"Pedido de Venda"+Spaces(62)+"Impressao: "+Format("D13",Today())+"-"+Time()+
                        "  Pag: "+Format("W3,EIC",npag)+"\n"
Print File ARQIMP "   "+Fill("-",172)+"\n"

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

nlin=5
EndProc

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

Moveto "PedidoC"
Cabecalho_Tit()

Print File ARQIMP "   Cliente: "
Print File ARQIMP Format("W05,AL",[Codigo])
Print File ARQIMP Format("W92,AL",[Razao Social])
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])+Spaces(05)
Print File ARQIMP "      Empresa: "+Format("W05,AL",[Codigo da Empresa])+Format("W20,AL",[Nome Fantasia Empresa])+"\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])+Spaces(05)
Print File ARQIMP "Representante: "+Format("W05,AL",[Codigo do Representante])
Print File ARQIMP Format("W25,AL",[Nome Fantasia Represent])+"\n"

Print File ARQIMP "   "+Spaces(14)+Format("W20,AL",[Cidade])
Print File ARQIMP Format("W20,AL",[UF])
Print File ARQIMP Format("W25,AL",[Telefone])
Print File ARQIMP " Tabela: "+Format("W15,AL",[Codigo da Tabela])
Print File ARQIMP "   Destinacao: "+Format("W04,AL",[Codigo da Destinacao])
Print File ARQIMP Format("W31,AL",[Descricao da Destinacao])
Print File ARQIMP "CFO: "+Format("W09,AL",[CFO])+"\n"

nlin=nlin+6

EndProc

;*******************************************************************************
;* Rotina para Impressao do Cabecalho do Item                                  *
;*******************************************************************************
Proc Cabecalho_Item(MODO)
Private MODO            

Moveto Tabela

Switch
  Case MODO="CabecalhoItem" : 
       Print File ARQIMP "  "+"    Ý      Ý                                                                   Ý"+
                         " Ý    Ý    Ý    Ý    Ý    Ý    Ý    Ý    Ý    Ý    Ý    Ý    Ý      Ý  Ý        Ý"+"\n"
  Case MODO = "Cabecalho"   :
       Print File ARQIMP "  "+" SeqÝRef   ÝDescricao                                 Cor                      Ý"+Array_Grade[ContGrade]+" TotalÝUNÝ  PrUnitÝ   PrTotal"+"\n"
  OtherWise                 : 
       Print File ARQIMP "  "+"    Ý      Ý                                                                   Ý"+
                         " Ý    Ý    Ý    Ý    Ý    Ý    Ý    Ý    Ý    Ý    Ý    Ý    Ý      Ý  Ý        Ý"+"\n"      
EndSwitch      
nlin=nlin+1
     
If MODO<>""
   Then Print File ARQIMP "  "+" ---+------+-------------------------------------------------------------------+-+"+
                          "----+----+----+----+----+----+----+----+----+----+----+----+------+--+--------+----------"+"\n"
                          
        nlin=nlin+1                  
EndIf                          

EndProc ;Cabecalho_Item()

;*******************************************************************************
;* Rodape para Itens                                                           *
;*******************************************************************************
Proc Rodape(tp)
Private tp

;If tp="Item"
;   Then Print File ARQIMP "   "+Fill("-",170)+"\n"
;Endif
Print File ARQIMP "\n"
Print File ARQIMP Format("W173,AC","*** Continua proxima pagina ==> ")+"\f"+"\n"

EndProc ;Rodape()

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

If (nlin+nl)>=40
   Then Rodape(tp)
        Cabecalho_Tit()
        If tp="Item"
           Then Print File ARQIMP "   "+Fill("-",170)+"\n"
                Cabecalho_Item("Cabecalho")
        EndIf
EndIf
nlin=nlin+nl
EndProc


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

npag=0
nlin=0

Array array_tqtd[14]  ;** controla total   13=total pecas  14=total valor **
For wi From 1 to 14
  array_tqtd[wi]=0
EndFor

Array array_qtdref[14] 

Verifica_Vencimentos()
Verifica_Grades()
Cabecalho_Ped()

Print File ARQIMP  "   "+Fill("-",170)+"\n" 
nlin=nlin+1

Itens()

EndProc ;ImpPed()

;*******************************************************************************
;* Rotina para Impressao Total das Referencias                                 *
;*******************************************************************************
Proc Imprime_Total_Ref(TIPO)
Private TIPO,Contador

If ContGrade > 1 
   Then array_qtdref[13]=0
        For wi From 1 to 14
         If array_qtdref[wi]=0 Then array_qtdref[wi]=BlankNum() EndIf
         If wi=13 Or wi=14 Then Loop EndIf
         array_qtdref[13]=array_qtdref[13]+array_qtdref[wi]
        EndFor  

        If TIPO<>""
           Then Contador=ContGrade
           Else Contador=ContGrade-1 
        EndIf

        Checa_Linha(1,"")
        ;Checa_Linha(3,"")
        Print File ARQIMP "   --------------------------------------------------------------------------------+"+
                          "----+----+----+----+----+----+----+----+----+----+----+----+------+-----------+----------"+"\n"
        
        ; **** Totalizador por Grade *******************************************
        ;Print File ARQIMP Spaces(83)+"Ý"
        ;Print File ARQIMP Spaces(4)+"Ý"
        ;Print File ARQIMP Spaces(4)+"Ý"
        ;Print File ARQIMP Spaces(4)+"Ý"
        ;Print File ARQIMP Spaces(4)+"Ý"
        ;Print File ARQIMP Spaces(4)+"Ý"
        ;Print File ARQIMP Spaces(4)+"Ý"
        ;Print File ARQIMP Spaces(4)+"Ý"
        ;Print File ARQIMP Spaces(4)+"Ý"
        ;Print File ARQIMP Spaces(4)+"Ý"
        ;Print File ARQIMP Spaces(4)+"Ý"
        ;Print File ARQIMP Spaces(4)+"Ý"
        ;Print File ARQIMP Spaces(4)+"Ý"
                
        ; **** Quantidade ******************************************************        
        ;Print File ARQIMP Spaces(60)+Format("W23","Total da Grade "+SubStr(Array_Grade[Contador],1,1))+"Ý"
        ;Print File ARQIMP Format("W04,EIC",array_qtdref[01])+"Ý"
        ;Print File ARQIMP Format("W04,EIC",array_qtdref[02])+"Ý"
        ;Print File ARQIMP Format("W04,EIC",array_qtdref[03])+"Ý"
        ;Print File ARQIMP Format("W04,EIC",array_qtdref[04])+"Ý"
        ;Print File ARQIMP Format("W04,EIC",array_qtdref[05])+"Ý"
        ;Print File ARQIMP Format("W04,EIC",array_qtdref[06])+"Ý"
        ;Print File ARQIMP Format("W04,EIC",array_qtdref[07])+"Ý"
        ;Print File ARQIMP Format("W04,EIC",array_qtdref[08])+"Ý"
        ;Print File ARQIMP Format("W04,EIC",array_qtdref[09])+"Ý"
        ;Print File ARQIMP Format("W04,EIC",array_qtdref[10])+"Ý"
        ;Print File ARQIMP Format("W04,EIC",array_qtdref[11])+"Ý"
        ;Print File ARQIMP Format("W04,EIC",array_qtdref[12])+"Ý"
        
        ; **** Totalizador por Grade/Quantidade ********************************
        ;Print File ARQIMP Format("W06,EIC",array_qtdref[13])+"Ý" 
        ;Print File ARQIMP Spaces(2)+"Ý" 
        ;Print File ARQIMP Spaces(8)+"Ý"
        ;Print File ARQIMP Format("W10.2,EIC",array_qtdref[14])+"\n"            
        ;Print File ARQIMP "   --------------------------------------------------------------------------------+"+
        ;                  "----+----+----+----+----+----+----+----+----+----+----+----+------+-----------+----------"+"\n"
EndIf

EndProc ;Imprime_Total_Ref()

;*******************************************************************************
;* Rotina para Impressao dos itens                                             *
;*******************************************************************************
Proc Itens()

ContGrade=0
COD_GRADE="***"

Moveto Tabela
Moveto [Numero do Pedido]
Locate [Pedidoc->Numero do Pedido]
While [Numero do Pedido]=[Pedidoc->Numero do Pedido]
   If COD_GRADE<>[Codigo da Grade]
       Then COD_GRADE=[Codigo da Grade]
            ContGrade = ContGrade + 1 
            
            Imprime_Total_Ref("")
            Cabecalho_Item("Cabecalho")
            
            For wi From 1 to 14
             array_qtdref[wi]=0
            EndFor     
   EndIf     
   Moveto Tabela
   Checa_Linha(1,"Item")    
   
   Print File ARQIMP "  "+Format("W04,AR",StrVal([Item do Pedido]))+"Ý"
   Print File ARQIMP Format("W06,AL",[Referencia])+"Ý"
   Print File ARQIMP Format("W27,AL",[Descricao do Item])+Spaces(15)
   Print File ARQIMP Format("W05,AL",[Codigo da Cor_Tecido])
   Print File ARQIMP Format("W20,AL",[Descricao da Cor_Tecido])+"Ý"
   Print File ARQIMP Format("W01,AL",[Codigo da Grade])+"Ý"
   Print File ARQIMP Format("W04,EIC",[Qtd1])+"Ý"
   Print File ARQIMP Format("W04,EIC",[Qtd2])+"Ý"
   Print File ARQIMP Format("W04,EIC",[Qtd3])+"Ý"
   Print File ARQIMP Format("W04,EIC",[Qtd4])+"Ý"
   Print File ARQIMP Format("W04,EIC",[Qtd5])+"Ý"
   Print File ARQIMP Format("W04,EIC",[Qtd6])+"Ý"
   Print File ARQIMP Format("W04,EIC",[Qtd7])+"Ý"
   Print File ARQIMP Format("W04,EIC",[Qtd8])+"Ý"
   Print File ARQIMP Format("W04,EIC",[Qtd9])+"Ý"
   Print File ARQIMP Format("W04,EIC",[Qtd10])+"Ý"
   Print File ARQIMP Format("W04,EIC",[Qtd11])+"Ý"
   Print File ARQIMP Format("W04,EIC",[Qtd12])+"Ý"
   Print File ARQIMP Format("W06,EIC",[Qtd1]+[Qtd2 ]+[Qtd3 ]+[Qtd4 ]+
                                      [Qtd5]+[Qtd6 ]+[Qtd7 ]+[Qtd8 ]+
                                      [Qtd9]+[Qtd10]+[Qtd11]+[Qtd12])+"Ý"
   Print File ARQIMP Format("W02,AL",[Unidade Fiscal])+"Ý"
   Print File ARQIMP Format("W08.2,EIC",[Preco Unitario])+"Ý"
   Print File ARQIMP Format("W10.2,EIC",[Preco Total])+"\n"

   ; *** Total por Referencia
   array_qtdref[01]=array_qtdref[01]+[Qtd1 ]
   array_qtdref[02]=array_qtdref[02]+[Qtd2 ]
   array_qtdref[03]=array_qtdref[03]+[Qtd3 ]
   array_qtdref[04]=array_qtdref[04]+[Qtd4 ]
   array_qtdref[05]=array_qtdref[05]+[Qtd5 ]
   array_qtdref[06]=array_qtdref[06]+[Qtd6 ]
   array_qtdref[07]=array_qtdref[07]+[Qtd7 ]
   array_qtdref[08]=array_qtdref[08]+[Qtd8 ]
   array_qtdref[09]=array_qtdref[09]+[Qtd9 ]
   array_qtdref[10]=array_qtdref[10]+[Qtd10]
   array_qtdref[11]=array_qtdref[11]+[Qtd11]
   array_qtdref[12]=array_qtdref[12]+[Qtd12]
   array_qtdref[14]=array_qtdref[14]+[Preco Total]

   ; ***  Total Geral
   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

Imprime_Total_Ref("Fim")

;************** IMPRESSAO DOS TOTAIS DAS GRADES DO PEDIDO ****************
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

Checa_Linha(2,"")
;Print File ARQIMP "   --------------------------------------------------------------------------------+"+
;                  "----+----+----+----+----+----+----+----+----+----+----+----+------+-----------+----------"+"\n"

Print File ARQIMP Spaces(83)+"Ý"
Print File ARQIMP Spaces(4)+"Ý"
Print File ARQIMP Spaces(4)+"Ý"
Print File ARQIMP Spaces(4)+"Ý"
Print File ARQIMP Spaces(4)+"Ý"
Print File ARQIMP Spaces(4)+"Ý"
Print File ARQIMP Spaces(4)+"Ý"
Print File ARQIMP Spaces(4)+"Ý"
Print File ARQIMP Spaces(4)+"Ý"
Print File ARQIMP Spaces(4)+"Ý"
Print File ARQIMP Spaces(4)+"Ý"
Print File ARQIMP Spaces(4)+"Ý"
Print File ARQIMP Spaces(4)+"Ý"

;Print File ARQIMP Spaces(83)+"Ý"
;Print File ARQIMP Format("W04,EIC",array_tqtd[01])+"Ý"
;Print File ARQIMP Format("W04,EIC",array_tqtd[02])+"Ý"
;Print File ARQIMP Format("W04,EIC",array_tqtd[03])+"Ý"
;Print File ARQIMP Format("W04,EIC",array_tqtd[04])+"Ý"
;Print File ARQIMP Format("W04,EIC",array_tqtd[05])+"Ý"
;Print File ARQIMP Format("W04,EIC",array_tqtd[06])+"Ý"
;Print File ARQIMP Format("W04,EIC",array_tqtd[07])+"Ý"
;Print File ARQIMP Format("W04,EIC",array_tqtd[08])+"Ý"
;Print File ARQIMP Format("W04,EIC",array_tqtd[09])+"Ý"
;Print File ARQIMP Format("W04,EIC",array_tqtd[10])+"Ý"
;Print File ARQIMP Format("W04,EIC",array_tqtd[11])+"Ý"
;Print File ARQIMP Format("W04,EIC",array_tqtd[12])+"Ý"

Print File ARQIMP Format("W06,EIC",array_tqtd[13])+"Ý"
Print File ARQIMP Spaces(2)+"Ý" 
Print File ARQIMP Spaces(8)+"Ý"
Print File ARQIMP Format("W10.2,EIC",array_tqtd[14])+"\n"

Print File ARQIMP "   "+Fill("-",170)+"\n"


;***************** IMPRESSAO DOS TOTAIS DO PEDIDO  ***************
Moveto "PedidoC"

Checa_Linha(2,"")
Print File ARQIMP CI_6LPP+CI_15CPP
Print File ARQIMP Spaces(30)+"  Mecadorias         Desconto     Liquido    Frete    Seguro   Desp.Aces         IPI       Total     BC.ICMS        ICMS"+"\n"
								 ;;9.999.999,99888.88%777.777,776.666.666,6644.444,44111.111,112.222.222,223.333/333,334.444.444,445.555.555,551.111.111,11

Print File ARQIMP Spaces(30)
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"

Checa_Linha(1,"")
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.: "+Format("W06,EIC",[PedidoC->Numero de Volumes])
Print File ARQIMP "   Peso Liquido: "+Format("W11.3,EIC",[PedidoC->Peso Liquido])
Print File ARQIMP "   Peso Bruto: "+Format("W11.3,EIC",[PedidoC->Peso Bruto])+"\n"

;********************* IMPRESSAO DOS VENCIMENTOS *******************************
Imprime_Vencimentos()

;********************* IMPRESSAO DO RODAPE *************************************
Imprime_Observacoes()

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

Checa_Linha(5,"")
Print File ARQIMP "   "+"Transportador   : "+Format("W05,AL",[PedidoC->Codigo da Transportadora])
Print File ARQIMP Format("W28,AL",[PedidoC->Nome Fantasia Transport])
Print File ARQIMP "Veiculo: "+Format("W08,AL",[PedidoC->Placa do Veiculo])+"-"+Format("W08,AL",[PedidoC->UF Veiculo])
Print File ARQIMP "Frete por Conta: "+[PedidoC->Frete por Conta]+" "+FRETECONTA+"\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(72)+"______________________________________________"+"\n"

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

Print File ARQIMP "   "+Fill("-",172)
Print File ARQIMP CI_10CPP
Print File ARQIMP "\f"
EndProc

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

Seta_FilePrint("Pd_0326G")
Switch
	Case OK="A": ARQIMP = DIREPORT+ARQUIVO+".TXT"
EndSwitch


;****** Adicionando tabelas para trabalho **************************************
FormKey 
Tabela=Cria_Temp(PrivDir())

NPED=[Pedidoc->Numero do Pedido]

{Ask} {PedidoG} Check
Moveto [Numero do Pedido] TypeIn "~NPED.." 
Do_It!

Sort "Answer" on "Codigo da Grade","Referencia","Codigo do Item"
Rename "Answer" Tabela


View NoWindow "\\Sistemas\\Estoque\\TpGrade"
View NoWindow Tabela
View NoWindow "PedidoV"
View NoWindow "Pedidog"
CoEditKey

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

Moveto Tabela

;*******************************************************************************
ImpPed()
Impressao_Orientacao="Paisagem"
ImpriArq(ARQIMP)


;****** Liberando tabelas de trabalho ******************************************
Do_It!
ClearAll

;*******************************************************************************
                               
LimpAguarde()

Release Vars  nlin,npag,array_vrvencto,array_dtvencto,array_grade,
              array_tqtd

Release Procs Seta_FilePrint,ImpPed,ImpriArq,
              Cabecalho_Ped,Cabecalho_Item,Cabecalho_Tit,Rodape,
              Imprime_Vencimentos,Imprime_Observacoes,
              Checa_Linha,Itens,Imprime_Total_Ref,
              Verifica_Vencimentos,Verifica_Grades

