;** OC_0121  *******************************************************************
;** Imprime a Digitacao da Ordem de Compra                 ** Santa Alice  **  *
;*******************************************************************************
;Autor           : Vise Informatica (VISERP)
;Desenvolvido  em: 25/11/2019 por Anivel Augusto Rodrigues
;Alterado em     :   /  /     por 
;Motivo Alteracao: 

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

CABECALHO()

Moveto "OCI"
Scan

   codforn=""
   getrecord "\\sistemas\\estoque\\itens" [Codigo do Item] to regitens
   if retval
      then codforn=regitens["Codigo Fornecedor"]
   endif   

   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("W21,AL",codforn)
   Print File ARQIMP Format("W31,AL",[Descricao do Item])
   Print File ARQIMP Format("W11.3,EIC",[Quantidade])
   Print File ARQIMP Format("W03,AR",[Unidade Fiscal])
   Print File ARQIMP Format("W11.3,EIC",[Preco Unitario])
   Print File ARQIMP Format("W11.2,EIC",[Preco Total])+"\n"
   Limite = Limite + 1
   If Limite > 62
      Then Print File ARQIMP "\f"
           Cabecalho()
           Moveto "OCI"
   Endif
EndScan
OBS="N"

RODAPE()
EndProc

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

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

Moveto "OCC"

Print File ARQIMP Chr(27)+Chr(67)+Chr(33)
Print File ARQIMP CI_8LPP
Print File ARQIMP CI_10CPP+"\n"

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

Print File ARQIMP CI_IEXP
Print File ARQIMP "\027E"
Print File ARQIMP Spaces(27)+"OC N§ "+Format("W06.3,AL",[Numero da OC])+"\n"
Print File ARQIMP CI_FEXP
Print File ARQIMP "\027F"

Print File ARQIMP "Fornecedor: "+Format("W05,AL",[Codigo])+Format("W46,AL",[Razao Social])+"\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("W25,AL",[Telefone])+"\n\n"

Print File ARQIMP "Comprador.: "+Format("W05,AL",[Codigo do Comprador])
Print File ARQIMP Format("W25,AL",[Nome do Comprador])+"\n"

Print File ARQIMP "Emissao...: "+Format("D13",[Data de Emissao])+Spaces(05)
Print File ARQIMP "Entrega: "+Format("D13",[Data de Entrega])+"\n"

Print File ARQIMP CI_15CPP+"\n"
Print File ARQIMP Spaces(02)+"Sq  Codigo     Codigo Fornecedor    Descricao                       Quantidade Un PrUnitario    PrTotal"+"\n"
Print File ARQIMP Spaces(02)+"--- ---------- -------------------- ------------------------------ ----------- -- ---------- ----------"+"\n"

Limite=18
EndProc

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

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

Moveto "OCC"

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

Print File ARQIMP Spaces(15)+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])+"\n"

Print File ARQIMP CI_10CPP+"\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"

Moveto "OCC"
imprimeobs()

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

EndProc

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

TamObs=78

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 CI_INEG+SubStr(s,posobs,tamobs)+CI_FNEG+"\n"
  posobs=posobs+tamobs
EndFor

endproc

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

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

Print File ARQIMP "\n"
Print File ARQIMP Spaces(19)

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

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

EndProc

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

ARQIMP=PrivDir()+"OC_0000.Txt"
If IsFile(ARQIMP)
   Then Deleta_Arquivo(ARQIMP)
EndIf
IMPOC()
ImpriArq(ARQIMP)

Release Vars VALOR,DATA
Release Procs IMPPED,VENC,Cabecalho,Rodape
