;** OC_0377  *******************************************************************
;** Imprime a Digitacao da Ordem de Compra                       ** Pralum **  *
;*******************************************************************************
;Autor           : Vise Informatica (VISERP)
;Desenvolvido  em: 14/02/2017 por Anivel Augusto Rodrigues
;Ultima Altera‡Æo: 03/03/2017 por Rafael Matos
;Motivo Alteracao: Altera‡äes Solicita‡Æo 28816         
;Ultima Altera‡Æo: 10/04/2017 por Bruno Carvalho
;Motivo Alteracao: Adicionado Pedido
;Ultima Altera‡Æo: 12/09/2017 por Bruno Carvalho
;Motivo Alteracao: Adicionado Carregamento  
;Ultima Altera‡Æo: 03/10/2017 por Anivel Augusto Rodrigues
;Motivo Alteracao: Adicionado peso total     

;*******************************************************************************
;* Rotina para Impressao do Relatorio                                          *
;*******************************************************************************
Proc IMPOC()
private pl, regitens

Cabecalho()
pltot=0

Moveto "OCI"
Scan

   if [Unidade Fiscal]="KG"
      then 
           pl=[Quantidade]      
      else
           pl=0
           getrecord "\\sistemas\\estoque\\itens" [Codigo do Item] to regitens
           if retval
              then pl=regitens["Peso Liquido"]*[Quantidade]
           endif
   endif           

   pltot=pltot+pl

   Print File ARQIMP Spaces(02)+Format("W03,AR",StrVal([Item da OC]))+Spaces(1)
   Print File ARQIMP Format("W11,AL",[Codigo do Item])
   Print File ARQIMP Format("W35,AL",[Descricao do Item])
   
   GetRecord "\\Sistemas\\Estoque\\Itens" [Codigo do Item] To regitens
   
   Print File ARQIMP Format("W20,AL",regitens["Referencia"])
   Print File ARQIMP Format("W11.3,EIC",[Quantidade])
   Print File ARQIMP Format("W03,AR",[Unidade Fiscal])
   Print File ARQIMP Format("W11.2,EIC",[Preco Unitario])
   Print File ARQIMP Format("W11.2,EIC",[Preco Total])
   Print File ARQIMP Format("W08,AL",[Codigo CCusto])
   Print File ARQIMP Format("W15,AL",[Descricao CCusto])+"\n"

   if [Informacoes_Adicionais]<>""
      then Print File ARQIMP Spaces(17)+Format("W115,AL",[Informacoes_Adicionais])+"\n"
           Limite = Limite + 1
   endif   
   Print File ARQIMP Fill("-",132)+"\n"

   Limite = Limite + 2
   If Limite > 64
      Then 
           Print File ARQIMP Format("W132,AR","** CONTINUA PROXIMA PAGINA ***")+"\f"
           Cabecalho()
           Moveto "OCI"
   Endif
EndScan

Rodape()
EndProc

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

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

Moveto "OCC"

pag=pag+1

Print File ARQIMP CI_6LPP+CI_15CPP+Format("W50,AL",NOMEMPRESA)+"Impressao: "+Format("D10",Today())+"-"+Time()+spaces(45)+"Pag: "+Format("W3",PAG)+"\n\n"

Print File ARQIMP "Fornecedor: "+Format("W05,AL",[Codigo])+Format("W81,AL",[Razao Social])
Print File ARQIMP CI_INEG+CI_IEXP+"OC N§ "+Format("W06.3,AL",[Numero da OC])+CI_FNEG+CI_FEXP+"\n"


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

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

Print File ARQIMP Spaces(17)+Format("W20,AL",[Cidade])
Print File ARQIMP Format("W20,AL",[UF])
Print File ARQIMP Format("W22,AL",[Contato ])
Print File ARQIMP Format("W25,AL",[Telefone])+"\n\n"

Print File ARQIMP "Comprador.: "+Format("W05,AL",[Codigo do Comprador])
Print File ARQIMP Format("W26,AL",[Nome do Comprador])
Print File ARQIMP "Requisitante: "+Format("W07,AL",[Codigo do Requisitante])
Print File ARQIMP Format("W20,AL",[Descricao Requisitante])+"\n"

Print File ARQIMP "Emissao...: "+Format("D13",[Data de Emissao])+Spaces(26)
Print File ARQIMP "Entrega: "+Format("D13",[Data de Entrega])+Spaces(12)+"Pedido: "+Format("W6",[Numero do Pedido])
Print File ARQIMP Spaces(8)+"Carregamento: "+[Numero_Carregamento_Occ]+"\n\n"

Print File ARQIMP Spaces(02)+"Sq  Item                                          Referˆncia           Quantidade Un PrUnitario    PrTotal CCusto                 "+"\n"
Print File ARQIMP Fill("-",132)+"\n"

Limite=12
EndProc

;*******************************************************************************
;* Impressao do RodaP‚                                                         *
;*******************************************************************************
Proc RodaPe()

;********************* IMPRESSAO DOS TOTAIS **************************

Moveto "OCC"

If Limite > 51
  Then Print File ARQIMP Format("W132,AR","** CONTINUA PROXIMA PAGINA ***")+"\f"

       Cabecalho()
       Moveto "OCC"
Endif

Print File ARQIMP "\n"
Print File ARQIMP Spaces(55)+"  Mecadorias         Desconto     Liquido       Total              Peso Total"+"\n"
                ;;9.999.999,99888.88%777.777,776.666.666,665.555.555,55

Print File ARQIMP Spaces(55)+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("W12.2,EIC",[Valor Nota Fiscal])
Print File ARQIMP Format("W24.3,EIC",pltot)+"\n\n"

Print File ARQIMP "Cond. Pagto: "+[Descricao CondPagto]
Print File ARQIMP "   NP: "+StrVal([Numero de Parcelas])
Print File ARQIMP "   CD: "+[Composicao de Dias]+"   FP: "+[Forma de Pagamento]+"   FR:"+Format("W10.2,EIC",[Valor do Frete])+"\n"
Print File ARQIMP "Transport..: "+[Razao Social Transport]+"\n"
Print File ARQIMP "Observacoes: "

Print File ARQIMP Format("W60,AL",SubStr([Observacoes da OC],001,60))+"\n"
If Substr([Observacoes da OC],61,120)<>""
   Then Print File ARQIMP Spaces(13)+Format("W60,AL",SubStr([Observacoes da OC],61,120))+"\n"
EndIf
If Substr([Observacoes da OC],121,180)<>""
   Then Print File ARQIMP Spaces(13)+Format("W60,AL",SubStr([Observacoes da OC],121,180))+"\n"
EndIf


Moveto "OCC"

Print File ARQIMP "\n\n"

Print File ARQIMP "  /  /   -                               /  /   -                  "+"\n"
Print File ARQIMP "_________________________              ____________________________"+"\n"
Print File ARQIMP "Dt/Assinat Comprador                   Dt/Assinat Almoxarif        "+CI_10CPP+CI_6LPP+"\f"

EndProc

;*******************************************************************************
;* Rotina Principal                                                            *
;*******************************************************************************
Aguarde("Imprimindo OC -> "+OC)

ArqImp=PrivDir()+"OC_0377.Txt"
If IsFile(ArqImp)
   Then Deleta_Arquivo(ARQIMP)
EndIf

pag=0
IMPOC()

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

Release Vars pag, pltot
Release Procs IMPOC,Cabecalho,Rodape
