;** PD_0319 ********************************************************************
;** Imprime a Digitacao dos Pedidos                                ** GM **    *
;*******************************************************************************
;Autor           : Vise Informatica (VISERP)
;Desenvolvido  em: 24/08/2012 por Bruno Carvalho
;Alterado      em: 17/10/2012 por Anivel Augusto Rodrigues
;Motivo Alteracao: Ajustes p/ impressao obs's                    
;Alterado      em: 29/10/2012 por Anivel Augusto Rodrigues
;Motivo Alteracao: Ajustes p/ impressao layout                   

;*******************************************************************************
;* ImpressÆo do Cabe‡alho                                                      *
;*******************************************************************************
Proc Cabecalho()

;************************** IMPRESSAO DO CABECALHO *****************************
If Not IsAssigned(NOMEMPRESA)
   Then NOMEMPRESA=""
EndIf

Moveto "Pedidoc"
PEDIDO=[Numero do Pedido]

Print File ARQIMP CI_6LPP
Print File ARQIMP CI_10CPP
Print File ARQIMP "\n"
;Print File ARQIMP chr(27)+chr(67)+chr(33) ;Imprime 33 Linhas por pagina

Print File ARQIMP Fill("-",78)+"\n"
Print File ARQIMP Format("W6,AL",[Numero do Pedido])+Spaces(30)+"PEDIDO"+"\n" 
Print File ARQIMP Fill("-",78)+"\n"

Print File ARQIMP "CLIENTE.: "+Format("W05,AL",[Codigo])+Format("W30,AL",Upper([Razao Social]))+Spaces(5)+"EMISSAO.: "+Format("D13",[Data de Emissao])+"\n"
Print File ARQIMP "ENDERECO: "+Format("W40,AL",Upper([Endereco]))+"BAIRRO..: "+Format("W15,AL",Upper([Bairro]))+"\n"
Print File ARQIMP "CIDADE..: "+Format("W30,AL",Ltrim(Upper([Cidade]))+"/"+[UF])+"\n"
Print File ARQIMP "PAGTOS..: "+Format("W03,AL",[Condicao de Pagamento])+Format("W20,AL",[Descricao CondPagto])+Spaces(17)+"FONE/FAX: "+Format("W25,AL",[Telefone])+"\n\n"

Print File ARQIMP "    QUANT  CODIGO     DESCRICAO                       PR.UNITARIO        TOTAL"+"\n"
Print File ARQIMP "---------- ---------- ------------------------------ ------------ ------------"+"\n"
                  ;9999999999 AAAAAAAAAA AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA 999999999,99 999999999,99

EndProc ;(Cabecalho)

;*******************************************************************************
;* ImpressÆo dos Itens                                                         *
;*******************************************************************************
Proc Itens()

Moveto "PedidoI"
CoeditKey

QUANT    = 0
TOT      = 0
CONTADOR = 0

Scan
  Checa_Linha(1)
  
  Moveto [Codigo do Item]
  Ativa_Lookup()
  Locate [Pedidoi->Codigo do Item]
  If RetVal
     Then COD_FORNECEDOR = [Codigo Fornecedor]
     Else COD_FORNECEDOR = ""
  EndIf
  KeyPress "ESC"
  Print File ARQIMP Format("W10,EIC",[Quantidade])+Spaces(1) 
  Print File ARQIMP Format("W10,AL",COD_FORNECEDOR)+Spaces(1)
  Print File ARQIMP Format("W30,AL",[Descricao do Item])+Spaces(1)
  Print File ARQIMP Format("W12.2,EIC",[Preco Unitario])+Spaces(1)
  Print File ARQIMP Format("W12.2,EIC",[Preco Total])+"\n"

  TOT   = TOT + [Preco Total]
  CONTADOR = CONTADOR + 1
  UnLockRecord
EndScan
Do_It!

For ITEM From CONTADOR To 12
    Print File ARQIMP "\n"
EndFor

EndProc ;(Itens)

;*******************************************************************************
;* ImpressÆo do Rodap‚                                                         *
;*******************************************************************************
Proc Rodape(QUEBRAFORM)
Private QUEBRAFORM, vrfrete
                                     
Moveto "PedidoC"
Print File ARQIMP Fill("-",78)+"\n"

If [Pedidoc->Frete Incluso na Nota]="S" or
   [Pedidoc->Frete Incluso na Nota]="+"
   Then vrfrete=[Pedidoc->Valor do Frete]
   Else vrfrete=BlankNum()
EndIf   

If QUEBRAFORM                                 
   Then  Print File ARQIMP Spaces(40)+"(=) Total dos Produtos :    **********"+"\n"
         Print File ARQIMP Spaces(40)+"(-) Descontos  **  % . :    **********"+"\n"
         Print File ARQIMP Spaces(40)+"(+) Frete      **  % . :    **********"+"\n"
         Print File ARQIMP Spaces(40)+"(=) Total............. :    **********"+"\n\n"
   Else  Print File ARQIMP Spaces(40)+"(=) Total dos Produtos : "+Format("W13.2,EIC",[Valor Mercadoria])+"\n"
         Print File ARQIMP Spaces(40)+"(-) Descontos "+Format("W4.2,EIC",[Taxa de Desconto])+"% .. : "+Format("W13.2,EIC",[Valor Desconto])+"\n"
         Print File ARQIMP Spaces(40)+"(+) Frete............. : "+Format("W13.2,EIC",vrfrete)+"\n"
         Print File ARQIMP Spaces(40)+"(=) Total............. : "+Format("W13.2,EIC",[Valor Nota Fiscal])+"\n\n"
EndIf

Print File ARQIMP Fill("-",78)+"\n"
;;;;;Print File ARQIMP Format("W78,AC","OBRIGADO PELA PREFERENCIA")+"\n"

If SubStr([Observacao do Pedido],1,65)<>""
   Then Print File ARQIMP "Obs. Pedido: "+SubStr([Observacao do Pedido],1,65)+"\n"
EndIf                                    
If SubStr([Observacao do Pedido],66,65)<>""
   Then Print File ARQIMP Spaces(13)+SubStr([Observacao do Pedido],66,65)+"\n"
EndIf
If SubStr([Observacao na Nota Fiscal],1,65)<>""
   Then Print File ARQIMP "Obs. ROM/NF: "+SubStr([Observacao na Nota Fiscal],1,65)+"\n"
EndIf                                    
If SubStr([Observacao na Nota Fiscal],66,65)<>""
   Then Print File ARQIMP Spaces(13)+SubStr([Observacao na Nota Fiscal],66,65)+"\n"
EndIf

Print File ARQIMP CI_6LPP
Print File ARQIMP CI_10CPP
Print File ARQIMP "\027F"
Print File ARQIMP "\f"

EndProc ;(Rodape)

;*******************************************************************************
;* Checa linha na area de impressÆo dos Itens                                  *
;*******************************************************************************
Proc Checa_Linha(Nl)
Private nl

If (CONTADOR+nl)>(PARAM_NITENS)
   Then RodaPe(True)
        Cabecalho()
        CONTADOR=nl
        Moveto "PedidoI"
   Else CONTADOR=CONTADOR+nl
EndIf

EndProc ;(Checa_Linha)

;*******************************************************************************
;* Rotina Principal                                                            *
;*******************************************************************************
ArqImp=PrivDir()+"PD_0319.Txt"
If IsFile(ArqImp)
   Then Deleta_Arquivo(ARQIMP)
EndIf
                                            
PARAM_NITENS=84

AGUARDE("Imprimindo Pedido -> "+PEDIDO)
Cabecalho()
Itens()
Rodape(False) 

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

Release Vars VALOR,DATA,PARAM_NITENS
Release Procs IMPFAT,VENC
LIMPAGUARDE()