;** PD_0175S *******************************************************************
;** Imprime a Digitacao do Pedido s/ Valor              Cotta Agropecuaria     *
;*******************************************************************************
;Autor           : Vise Informatica (VISERP)
;Desenvolvido  em: 09/12/2010 por Bruno Carvalho
;Ultima Alteracao:   /  /     por 
;Motivo Alteracao: 

;*******************************************************************************
;* Rotina para Impressao do Relatorio                                          *
;*******************************************************************************
Proc IMPPED()
ClearAll

{Ask} {\\Sistemas\\Estoque\\Itens}
Moveto [Codigo do Item  ] TypeIn "_cdite"
Moveto [Localizacao     ] Check
{Ask} {PedidoI} Check
Moveto [Numero do Pedido] TypeIn "~CODPED"
Moveto [Codigo do Item  ] TypeIn "_cdite!"
Do_It!
ClearAll

Sort "Answer" On "Codigo do Item","Item do Pedido"

View "\\sistemas\\estoque\\Itens"
View "PedidoC"
View "PedidoV"

Cabecalho()

Moveto "Answer"
ITEMANTIGO=[Codigo do Item]
CONT=0

Scan
   If [Codigo do Item] <> ITEMANTIGO
      Then If CONT > 1
              Then Print File ARQIMP ASP1+"---------------------------------------------------------------------------------------------"+ASP2+"\n"
                   Print File ARQIMP ASP1+"                                                           Total... |"+ASP2+"\n"
                   ;Limite=Limite+2
           Endif
                   Print File ARQIMP ASP1+"============================================================================================="+ASP2+"\n"
           ;Limite=Limite+1
           ;If Limite >= 62
           ;   Then Print File ARQIMP ASP1+"\f"+ASP2
           ;        Cabecalho()
           ;        Moveto "Answer"
           ;Endif
           ITEMANTIGO=[Codigo do Item]
           CONT=0
      Else IF CONT > 0
              Then Print File ARQIMP ASP1+"---------------------------------------------------------------------------------------------"+ASP2+"\n"
                   ;Limite=Limite+1
           Endif
   Endif

   Moveto "\\sistemas\\estoque\\itens"
   Moveto [Codigo do Item]
   Locate [Answer->Codigo do Item]
   If Retval
      then WSREF=[Referencia]
      else WSREF=""
   EndIf
   Moveto "Answer"

   Print File ARQIMP ASP1+Format("W04,AL",[Item do Pedido])
   Print File ARQIMP Format("W10,AR",[Codigo do Item])+" "
   Print File ARQIMP Format("W25,AL",[Descricao do Item])
   Print File ARQIMP Spaces(01)+Format("W20,AL",WSREF)
   Print File ARQIMP Spaces(01)+Format("W06,AL",[Descricao da Cor_Tecido])
   Print File ARQIMP Spaces(01)+Format("W10.2,EIC",[Quantidade])
   Print File ARQIMP Format("W03,AR",[Unidade Fiscal])+ASP2+"\n"

   ;Limite = Limite + 1
   ;If Limite >= 62
   ;   Then Print File ARQIMP ASP1+"\f"+ASP2
   ;        Cabecalho()
   ;        Moveto "Answer"
   ;Endif
   CONT=CONT+1

EndScan
If CONT > 1
   Then Print File ARQIMP ASP1+"---------------------------------------------------------------------------------------------"+ASP2+"\n"
        Print File ARQIMP ASP1+"                                                           Total... |"+ASP2+"\n"
        ;Limite=Limite+2
Endif
Print File ARQIMP ASP1+"============================================================================================="+ASP2+"\n"
;Limite=Limite+1

;If Limite >= 47
;   Then Print File ARQIMP ASP1+"\f"+ASP2
;        Cabecalho()
;Endif
RodaPe()

EndProc

;*******************************************************************************
;* Impressao do Cabecalho                                                      *
;*******************************************************************************
Proc Cabecalho()

Moveto "PedidoC"
Moveto [Numero do Pedido]
Locate CODPED

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

Print File ARQIMP ASP1+Chr(27)+Chr(80)
Print File ARQIMP CI_15CPP
Print File ARQIMP CI_8LPP

Print File ARQIMP ASP2+"\n"
Print File ARQIMP ASP1+"--------------------------------------------------------------------------------" +ASP2+"\n"
Print File ARQIMP ASP1+Format("W34,AL",NOMEMPRESA)+"Pedido  "+Spaces(08)+"Impressao: "+Format("D13",Today())+"-"+Time()+ASP2+"\n"
Print File ARQIMP ASP1+"--------------------------------------------------------------------------------"+ASP2+"\n\n"

Print File ARQIMP ASP1+CI_IEXP+CI_INEG
pos=SearchFrom("-",[PedidoC->Nome Fantasia Represent],1)
Print File ARQIMP Spaces(24)+"N§ : "+Format("W06.3,AL",[Numero do Pedido])+"/"+ SubStr([PedidoC->Nome Fantasia Represent],1,(Pos-1))+ASP2+"\n"

Print File ARQIMP ASP1+CI_FEXP+CI_FNEG

Print File ARQIMP "Cliente: "+Format("W05,AL",[Codigo])+Format("W46,AL",[Razao Social])+ASP2+"\n"

Print File ARQIMP ASP1+Spaces(09)+Format("W40,AL",[Endereco])
Print File ARQIMP Format("W18,AL",[CGC])+ASP2+"\n"

Print File ARQIMP ASP1+Spaces(09)+Format("W20,AL",[Bairro])
Print File ARQIMP Format("W20,AL",[CEP])
Print File ARQIMP Format("W25,AL",[IE])+ASP2+"\n"

Print File ARQIMP ASP1+Spaces(09)+Format("W20,AL",[Cidade])
Print File ARQIMP Format("W20,AL",[UF])
Print File ARQIMP Format("W25,AL",[Telefone])+ASP2+"\n\n"

Print File ARQIMP ASP1+"Representante: "+Format("W05,AL",[Codigo do Representante])
Print File ARQIMP Format("W25,AL",[Nome Fantasia Represent])
Print File ARQIMP "  Comissao: "+Format("W06.2,EIC",[Comissao do Representante])+ASP2+"% \n"

Print File ARQIMP ASP1+"Emissao: "+Format("D10",[Data de Emissao])+ASP2+"\n\n"


Print File ARQIMP ASP1+CI_12CPP
Print File ARQIMP      "Sq  Item                                                      Cor/T.       Qtde Un Qt/Med    "+ASP2+"\n"
Print File ARQIMP ASP1+"--- --------------------------------------------------------- ------ ---------- -- ----------"+ASP2+"\n"

;Limite = 18

EndProc

;*******************************************************************************
;* Impressao do RodaP‚                                                         *
;*******************************************************************************
Proc RodaPe()
Verifica=False
Moveto "PedidoC"

Print File ARQIMP ASP1+Chr(27)+Chr(80) ;** Matricial ***
Print File ARQIMP ASP2+"\n\n"
Print File ARQIMP ASP1+Spaces(02)+"N§. Volumes:"+"________"
Print File ARQIMP "  Peso.:"+"___________"+ASP2+"\n\n"

Print File ARQIMP ASP1+Spaces(02)+"Observa‡”es: "+Format("W60,AL",SubStr([Observacao na Nota Fiscal],01,60))+ASP2+"\n"

If Substr([Observacao na Nota Fiscal],61,40)<>""
   Then Print File ARQIMP ASP1+Spaces(15)+Format("W40,AL",SubStr([Observacao na Nota Fiscal],61,40))
EndIf

If Substr([Observacao na Nota Fiscal],90,10)<>""
   Then Verifica=True
EndIf

If Verifica=True And Substr([Observacao do Pedido],01,20)<>""
   Then Print File ARQIMP Format("W20,AL",SubStr([Observacao do Pedido],01,20))+ASP2+"\n"
   Else Print File ARQIMP ASP2+"\n"
EndIf
                                               
If Verifica=True And Substr([Observacao do Pedido],21,60)<>""
   Then Print File ARQIMP ASP1+Spaces(15)+Format("W60,AL",SubStr([Observacao do Pedido],21,60))+ASP2+"\n"
EndIf

If Verifica=True And Substr([Observacao do Pedido],81,60)<>""
   Then Print File ARQIMP ASP1+Spaces(15)+Format("W60,AL",SubStr([Observacao do Pedido],81,60))+ASP2+"\n"
EndIf

If Verifica=True And Substr([Observacao do Pedido],141,60)<>""
   Then Print File ARQIMP ASP1+Spaces(15)+Format("W60,AL",SubStr([Observacao do Pedido],141,60))+ASP2+"\n\n"
EndIf

Print File ARQIMP ASP1+ASP2+"\n\n\n\n"

Print File ARQIMP ASP1+Spaces(07)+"  /  /   -                               /  /   -                   "+ASP2+"\n"
Print File ARQIMP ASP1+Spaces(07)+"_____________________________          _____________________________"+ASP2+"\n"
Print File ARQIMP ASP1+Spaces(07)+"Data/Assinatura Separador              Data/Assinatura Medidor     "+ASP2+"\n\n"
Print File ARQIMP ASP1+Spaces(07)+"  /  /   -                               /  /   -                   "+ASP2+"\n"
Print File ARQIMP ASP1+Spaces(07)+"_____________________________          _____________________________"+ASP2+"\n"
Print File ARQIMP ASP1+Spaces(07)+"Data/Assinatura Embalador              Data/Assinatura Conferista  "+ASP2+"\n"
Print File ARQIMP ASP1+Spaces(07)+"  /  /   -                                                         "+ASP2+"\n"
Print File ARQIMP ASP1+Spaces(07)+"_____________________________          ___________       ___________"+ASP2+"\n"
Print File ARQIMP ASP1+Spaces(07)+"Data/Assinatura Volumes                Hora Inicio        Hora Fim  "+ASP2+"\n\n\n"
Print File ARQIMP ASP1+Spaces(07)+"                     _____________________________"+ASP2+"\n"
Print File ARQIMP ASP1+Spaces(07)+"                          Assinatura Diretoria      "+ASP2+"\n\n"
Print File ARQIMP ASP1+CI_15CPP
Print File ARQIMP CI_8LPP
;Print File ARQIMP "\f"+ASP2

EndProc

;*******************************************************************************
;* Rotina Principal                                                            *
;*******************************************************************************

Seta_FilePrint("PD_5009S")
IMPPED()
Imprime_FilePrint("Imprimindo Pedido -> "+PEDIDO,"R")

Release Vars VALOR,DATA, Verifica
Release Procs IMPPED,VENC,Cabecalho,Rodape,
              Seta_FilePrint, Imprime_FilePrint

