;** PD_0396s *******************************************************************
;** Imprime a Digitacao do Pedido                          ** REAL TECIDOS **  *
;*******************************************************************************
;Autor: Visao/Vise
;Desenvolvido  em: 13/04/2017 por Kamila Gomes
;Alterado em     : 02/06/2017 por Anivel Augusto Rodrigues
;Motivo Alteracao: Observacao do Pedido

;*******************************************************************************
;* Rotina para Impressao do Relatorio                                          *
;*******************************************************************************

PARAM_NITENS = 22

;************************** IMPRESSAO DO CABECALHO *****************************
Proc Cabecalho();
If Not IsAssigned(NOMEMPRESA)
   Then NOMEMPRESA=""
EndIf
Moveto "PedidoC"
Print File ARQIMP chr(27)+chr(67)+chr(33) ;Imprime 33 Linhas por pagina
Print File ARQIMP CI_10CPP
Print File ARQIMP CI_8LPP

DATA=StrVal([Data de Emissao])
If Len(DATA)=9 Then DATA="0"+DATA EndIf
DATA = SubStr(DATA,1,2) +"/"+ SubStr(DATA,4,2) +"/"+ SubStr(DATA,7,4)

Print File ARQIMP "\015"          ;Imprime 17 Caracteres por polegada
Print File ARQIMP Fill("-",130)+"\n"

Print File ARQIMP Spaces(57)+"Pedido Expedicao"+Spaces(16)+"EMISSAO: "+DATA+Spaces(2)+"ORCAMENTO N§: "+Format("W7,AL",[Numero do Pedido])+"\n"
Print File ARQIMP Fill("-",130)+"\n"
Print File ARQIMP "\027E"+" Cliente.: "+Format("W15,AL",[Razao Social])+"\027F"+"\n"

Print File ARQIMP "----------------------------------------------------------------------------------------------------------------------------------"+"\n"
Print File ARQIMP "\027E" + "Quantidade   UN  Codigo  Descricao                       Composi‡Æo             O b s e r v a ‡ Æ o :                   " +"\027F"  +"\n"
Print File ARQIMP "----------------------------------------------------------------------------------------------------------------------------------"+"\n"

EndProc ;(Cabecalho)                           

;************************** IMPRESSAO DOS ITENS ********************************
Proc Itens()
Print File ARQIMP CI_6LPP
Moveto "PedidoI"
QUANT    = 0
TOT      = 0
CONTADOR = 0

While [Numero do Pedido]=[PedidoC->Numero do Pedido]
  Checa_Linha(1)

  CODITEM=[Codigo do Item]
  While SubStr(CODITEM,1,1)="0"
    CODITEM=SubStr(CODITEM,2,Len(CODITEM))
  EndWhile
  
  GetRecord "\\Sistemas\\Estoque\\Iten_tec" [Codigo do Item] to REG_ITEN_TEC
  If RetVal
    Then COMPOSICAO = REG_ITEN_TEC["Composicao"]
    Else COMPOSICAO = ""
  EndIf

  LINHA_ITEM = "\027E"+ Format("W12.3,AL",[Quantidade])+"\027F"
  LINHA_ITEM = LINHA_ITEM + Spaces(01) + "\027E"+ Format("W03,Al",[Unidade Fiscal])+"\027F"
  LINHA_ITEM = LINHA_ITEM + Spaces(01) + "\027E"+ Format("W06,AR",CODITEM)+"\027F"
  LINHA_ITEM = LINHA_ITEM + Spaces(02) + "\027E"+ Format("W30,AL",[Descricao do Item])+"\027F"
  LINHA_ITEM = LINHA_ITEM + Spaces(02) + "\027E"+ Format("W20,AL",COMPOSICAO)+"\027F"
  LINHA_ITEM = LINHA_ITEM + Spaces(02) + "\027E"+ Format("W50,AL",[Observacao_Item])+"\027F"
  
  Print File ARQIMP LINHA_ITEM + "\n"
  Print File ARQIMP Fill("-",130)+"\n"
  
  Skip
  If EOT() Then QuitLoop EndIf
EndWhile

Imprime_Observacoes()

For ITEM From CONTADOR To PARAM_NITENS
    Print File ARQIMP "\n"
EndFor
Print File ARQIMP CI_8LPP  
EndProc ;(Itens)

;*** Imprime Rodape ************************************************************
Proc Rodape()
Print File ARQIMP CI_6LPP
Print File ARQIMP CI_10CPP
Print File ARQIMP "\f"

EndProc ;Rodape

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

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

;*******************************************************************************
;* Imprime Observacoes do Pedido                                               *
;*******************************************************************************
Proc Imprime_Observacoes()
Private obs,tamobs,nlobs,posobs,i

obs="Observacoes: "+[PedidoC->Observacao do Pedido]

tamobs=130

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 i from 1 to nlobs
  Checa_Linha(1)
  Print File ARQIMP CI_INEG+SubStr(obs,posobs,tamobs)+CI_FNEG+"\n"

  posobs =posobs+tamobs
EndFor

Release Vars obs,tamobs,nlobs,posobs,i
EndProc


;*******************************************************************************
;* Rotina Principal                                                            *
;*******************************************************************************
ArqImp=PrivDir()+"PD_0318S.Txt"
If IsFile(ArqImp)
   Then Deleta_Arquivo(ARQIMP)
EndIf
Moveto "PedidoC"

AGUARDE("Imprimindo Pedido -> "+[Numero do Pedido])
Cabecalho()
Itens()
Rodape()

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

Release Vars CONTADOR,PARAM_NITENS,DATA,QUANT,TOT,LINHA_ITEM,COMPOSICAO,CODITEM,ITEM
Release Procs Cabecalho,Itens,Rodape,Checa_Linha,Imprime_Observacoes
LIMPAGUARDE()
