;** OC_0294  *******************************************************************
;** Imprime a Digitacao da Ordem de Compra                 ** Divina Panela *
;*******************************************************************************
;Autor           : Vise Informatica (VISERP)
;Desenvolvido  em: 08/11/2012 por Karina Andrade
;Alterado em     : 31/03/2014 por Andrey Fillipe
;Motivo Alteracao: Ajustes (Limite > 62)    
;Alterado em     : 18/03/2017 por Rafael Matos
;Motivo Alteracao: InclusÆo PrUltCompra/UN
;Alterado em     : 05/10/2018 por Rafael Matos
;Motivo Alteracao: Ajustes obs e informac‡oes adicionais item
;Alterado em     : 25/01/2019 por Anivel Augusto Rodrigues
;Motivo Alteracao: Ajustes totais
;Alterado em     : 15/02/2019 por Anivel Augusto Rodrigues
;Motivo Alteracao: Ajustes  %DIF         
;Ultima Alteracao: 19/02/2019 por Anivel Augusto Rodrigues
;Motivo Alteracao: Novo campo Tipo da Operacao OC

;*******************************************************************************
;* Rotina para Impressao do Relatorio                                          *
;*******************************************************************************
Proc IMPOC()
private REG_ITEM, VALOR, UN, DIF

Cabecalho()

QTDTOT=0

Moveto "OCI"
CoeditKey
Scan
   Moveto "OCI"
   Moveto [Codigo do Item]                 
   Ativa_Lookup()
   Moveto [Codigo do Item]
   Locate [OCI->Codigo do Item]
   If Retval                  
      Then CODBARRA =[Codigo de Barras  ] 
           CODFOR   =[Codigo Fornecedor ]
      Else CODBARRA =""
           CODFOR   =""
   EndIf
   KeyPress "ESC"
                                            
   Print File ARQIMP ASP1+Format("W03,AR",StrVal([Item da OC]))+Spaces(1)
   Print File ARQIMP Format("W11,AL",[Codigo do Item])
   Print File ARQIMP Format("W31,AL",[Descricao do Item])
   Print File ARQIMP Format("W18,AL",CODFOR)
   Print File ARQIMP Format("W14,AL",CODBARRA)
   Print File ARQIMP Format("W10.3,EIC",[Quantidade])
   Print File ARQIMP Format("W03,AR",[Unidade Fiscal])
   Print File ARQIMP Format("W10.2,EIC",[Preco Unitario])
   Print File ARQIMP Format("W11.2,EIC",[Preco Total])
   
   GetRecord "\\Sistemas\\Estoque\\Cotacao" [Codigo do Item],[OCC->Codigo] To REG_ITEM
   If Retval
      Then VALOR = REG_ITEM["Valor Unitario" ]
           UN    = REG_ITEM["Unidade Entrada"]
      Else VALOR = ""
           UN    = ""
   EndIf
   DIF=0
   if VALOR>0
      then DIF=([Preco Unitario]*100)/VALOR
           DIF=DIF-100
   endif   
   
   Print File ARQIMP Format("W10.2,EIC",VALOR)+"/"
   Print File ARQIMP Format("W02,AR",UN)
   Print File ARQIMP Format("W07.1,EIC,S+",DIF)+ASP2+"\n"
   
   QTDTOT=QTDTOT+[Quantidade]

   imprimeobs1()

   Limite = Limite + 1
   If Limite > 57
      Then Print File ARQIMP ASP1+"\f"+ASP2+"\n"
           Cabecalho()
           Moveto "OCI"
   Endif


EndScan
OBS="N"

Rodape()
Do_It!
EndProc

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

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

Moveto "OCC"

Open Printer
Printer On

Print File ARQIMP ASP1+CI_15CPP+ASP2+"\n"
Print File ARQIMP ASP1+Format("W100,AL",NOMEMPRESA)+Spaces(04)+"Impressao: "+Format("D10",Today())+"-"+Time()+ASP2+ "\n\n"

Print File ARQIMP ASP1+CI_IEXP+CI_INEG
Print File ARQIMP Spaces(54)+"OC N§ "+Format("W06.3,AL",[Numero da OC])
Print File ARQIMP CI_FEXP+CI_FNEG+ASP2+"\n"

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

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

Print File ARQIMP ASP1+Spaces(17)+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(17)+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+"Comprador.: "+Format("W05,AL",[Codigo do Comprador])
Print File ARQIMP Format("W31,AL",[Nome do Comprador])
Print File ARQIMP "Emissao: "+Format("D13",[Data de Emissao])+Spaces(05)
Print File ARQIMP CI_INEG+"Entrega: "+Format("D13",[Data de Entrega])+"   Operacao: "+[Descricao da Operacao OC]+CI_FNEG+ASP2+"\n\n"

Print File ARQIMP ASP1+"Sq  Item                                      Codigo Fornecedor Codigo Barras Quantidade Un  PrUnitar    PrTotal PrUltComp/UN  %DIF "+ASP2+"\n"
Print File ARQIMP ASP1+"--- ----------------------------------------- ----------------- ------------- ---------- -- --------- ---------- ------------ ------"+ASP2+"\n"
Limite=17
EndProc

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

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

Moveto "OCC"

Print File ARQIMP ASP1+fill("-",132)+ASP2+"\n"

Print File ARQIMP ASP1+CI_INEG+Spaces(59)+"   Quantidades     Mercadorias         Desconto     Liquido       Total"+ASP2+"\n"
                ;;9.999.999,99888.88%777.777,776.666.666,665.555.555,55

Print File ARQIMP ASP1+Spaces(59)+Format("W14.3,EIC",QTDTOT)
Print File ARQIMP Format("W16.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])+CI_FNEG+ASP2+"\n"

Print File ARQIMP ASP1+"Cond. Pagto: "+[Descricao CondPagto]
Print File ARQIMP "   NP: "+StrVal([Numero de Parcelas])
Print File ARQIMP "   CD: "+[Composicao de Dias]+"   FP: "+[Forma de Pagamento]+ASP2+"\n"

Print File ARQIMP ASP1+"Transport..: "+Completa([Razao Social Transport],35," ")
If [Frete por Conta]="1"
   Then Print File ARQIMP "Frete: CIF"
   Else Print File ARQIMP "Frete: FOB"
EndIf
Print File ARQIMP "   VrFrete: "+Format("W10.2,EIC",[Valor do Frete])+ASP2+"\n"

Moveto "OCC"
imprimeobs()

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

Print File ARQIMP ASP1+"  /  /   -                               /  /   -                  "+ASP2+"\n"
Print File ARQIMP ASP1+"_________________________              ____________________________"+ASP2+"\n"
Print File ARQIMP ASP1+"Dt/Assinat Comprador                   Dt/Assinat Almoxarif        "+ASP2+"\n\n"
Print File ARQIMP ASP1+"\f"+ASP2+"\n"
Print File ARQIMP ASP1+CI_15CPP+ASP2+"\n"
Print File ARQIMP ASP1+CI_8LPP+ASP2+"\n"
Printer Off
Close Printer

EndProc

;*******************************************************************************
;* Rotina de Impressao de Observa‡äes                                          *
;*******************************************************************************
proc imprimeobs()
private TamObs, nlobs, posobs, i, s

TamObs=130

s="Observacoes: "+Tira_QuebraLinha([Observacoes da OC])

nlobs=Len(s)/tamobs
If nlobs-Int(nlobs)>0
   Then nlobs=Int(nlobs)+1
   Else nlobs=Int(nlobs)
EndIf

posobs=1
For i from 1 to nlobs
  Print File ARQIMP ASP1+CI_INEG+SubStr(s,posobs,tamobs)+CI_FNEG+ASP2+"\n"
  posobs=posobs+tamobs
EndFor

endproc

;*******************************************************************************
;* Rotina de Impressao de Observa‡äes                                          *
;*******************************************************************************
proc imprimeobs1()
private TamObs, nlobs, posobs, i, s

if isblank([Informacoes_Adicionais])
   then return
endif
   
s=Tira_QuebraLinha([Informacoes_Adicionais])

TamObs=117

nlobs=Len(s)/tamobs
If nlobs-Int(nlobs)>0
   Then nlobs=Int(nlobs)+1
   Else nlobs=Int(nlobs)
EndIf

posobs=1
For i from 1 to nlobs
  Print File ARQIMP ASP1+spaces(15)+SubStr(s,posobs,tamobs)+ASP2+"\n"
  posobs=posobs+tamobs
  Limite = Limite + 1

EndFor

endproc

;*******************************************************************************
;* Rotina de Impressao dos Vencimentos                                         *
;*******************************************************************************
Proc VENC()

If KV>0
   Then Print File ARQIMP ASP1+Spaces(15)
EndIf
For I From 1 to K
  Print File ARQIMP Spaces(03)+DATA[I]+Spaces(02)
EndFor

Print File ARQIMP ASP2+"\n"
Print File ARQIMP ASP1+ Spaces(19)

For I From 1 to K
  Print VALOR[I]+Spaces(02)
EndFor

Print File ARQIMP ASP2+"\n"
KV=KV+1

EndProc

;*******************************************************************************
;* Rotina Principal                                                            *
;*******************************************************************************
Aguarde("Imprimindo OC -> "+OC)
Seta_FilePrint("OC_0294")
IMPOC()
Imprime_FilePrint("","R")

Release Vars VALOR,DATA,QTDTOT
Release Procs IMPOC,VENC,Cabecalho,Rodape,imprimeobs,imprimeobs1


