;** RO_0438 ********************************************************************
;** Imprime a Digitacao do Romaneio                        ** JOFRAN     **    *
;*******************************************************************************
;Autor           : Vise Informatica (VISERP)
;Desenvolvido  em: 23/08/2019 por Anivel Augusto Rodrigues
;Ultima Alteracao: 04/10/2019 por Anivel Augusto Rodrigues 
;Motivo Alteracao: Ajusets nÆo sair ICMS ST

;*******************************************************************************
;* Rotina para Impressao do Relatorio                                          *
;*******************************************************************************
Proc IMPFAT()

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

Print File ARQIMP Format("W50,AL","CONTROLE INTERNO - Balcao 3")+"Impressao: "+Format("D10",Today())+"-"+Time()+ "\n\n"

Print File ARQIMP "\014"
Print File ARQIMP "\027E"
Print File ARQIMP Spaces(20)+"Orcamento N§ "+Format("W06.3,AL",NOTAFISC)+"\n"
Print File ARQIMP "\020"

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

Print File ARQIMP CI_8LPP
Print File ARQIMP "\027P"         ;Imprime 10 Caracteres por polegada

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

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

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

Print File ARQIMP "Operacao: "
Print File ARQIMP Chr(27)+Chr(71)
Print File ARQIMP ""+[Codigo da Destinacao]+" "+[Descricao da Destinacao]+"\n"
Print File ARQIMP Chr(27)+Chr(72)

Print File ARQIMP "Vendedor: "+Format("W05,AL",[Codigo do Representante])
Print File ARQIMP Format("W25,AL",[Nome Fantasia Represent])+"\n"
Print File ARQIMP "\015"         ;Imprime 17 Caracteres por polegada

;********************* IMPRESSAO DOS ITENS ********************************
Print File ARQIMP "---------------------------------------------------------------------------------------------------------------------"+"\n"
Print File ARQIMP Spaces(02)+"Item                                                                          Un  Quantidade  Unitario        Total"+"\n"
Print File ARQIMP "---------------------------------------------------------------------------------------------------------------------"+"\n"
Moveto "FaturaI"
Moveto [Numero da OF]
Locate [FaturaC->Numero da OF]
QUANT    = 0
TOT      = 0
CONTADOR = 0

While [Numero da OF]=[FaturaC->Numero da OF]
  Print File ARQIMP Spaces(02)+Format("W02,AL",[Item da OF])
  Print File ARQIMP Spaces(01)+Format("W11,AL",[Codigo do Item])
  Print File ARQIMP Spaces(01)+Format("W62,AL",[Descricao do Item])
  Print File ARQIMP Spaces(01)+Format("W03,Al",[Unidade Fiscal])

  If [Quantidade]-Int([Quantidade])>0
     Then Print File ARQIMP Format("W011.3,EIC",[Quantidade])
     Else Print File ARQIMP Format("W011,EIC",[Quantidade])
  EndIf

  Print File ARQIMP Format("W10.2,EIC",[Preco Unitario])
  Print File ARQIMP Format("W13.2,EIC",[Preco Total])+"\n"
  TOT   = TOT + [Preco Total]
  Skip
  If EOT() Then QuitLoop EndIf
  CONTADOR = CONTADOR + 1
EndWhile

For ITEM From CONTADOR To 12
    Print File ARQIMP "\n"
EndFor
Print File ARQIMP "---------------------------------------------------------------------------------------------------------------------"+"\n"

;********************* IMPRESSAO DOS TOTAIS **************************
Moveto "FaturaC"

Print File ARQIMP Spaces(87)+"Total.............."+Format("W11.2,EIC",TOT)+"\n"

Print File ARQIMP "          *** FAVOR MANTER O ENDERECO E O TELEFONE ATUALIZADOS ***"
Print File ARQIMP Spaces(21)+"Desconto"+Format("W06.2,EIC",[Taxa de Desconto]) + "%..."
Print File ARQIMP Format("W12.2,EIC",[Valor Desconto])+"\n"

;;Print File ARQIMP Spaces(87)+"ICMS ST............"+Format("W11.2,EIC",[Valor Substituicao ICMS])+"\n"
Print File ARQIMP Spaces(87)+"Total Liquido......"+Format("W11.2,EIC",[Valor Nota Fiscal])+"\n\n"

Print File ARQIMP Spaces(02)+"Cond. Pagamento.: "+[Descricao CondPagto]
Print File ARQIMP "   NP: "+StrVal([Numero de Parcelas])
Print File ARQIMP "   CD: "+[Composicao de Dias]+"\n"
                              
imprimeobs()
Vencimentos()
Moveto "FaturaC"

;************************* IMPRESSAO DO RODAPE *********************************
Print File ARQIMP "\n\n"
Print File ARQIMP Spaces(12)+"   /   /     -                                   " + "\n"
Print File ARQIMP Spaces(12)+"-------------------------------------------------" + "\n"
Print File ARQIMP Spaces(12)+"              Data e Assinatura"+"\n"
Print File ARQIMP CI_6LPP
Print File ARQIMP CI_10CPP
Print File ARQIMP "\f"
EndProc

;*******************************************************************************
;* Rotina de Impressao dos Vencimentos                                         *
;*******************************************************************************
Proc Vencimentos()
private s1,s2,s3, kv

s1="  Vencimentos.....: "
s2="                    "
s3="                    "
kv=0

Moveto "FaturaV"
Moveto [Numero da OF]
Locate [FaturaC->Numero da OF]
While [Numero da OF]=[FaturaC->Numero da OF]
 if kv=10
    then Print File ARQIMP s1+"\n"
         Print File ARQIMP s2+"\n"
         Print File ARQIMP s3+"\n"

         kv=0
         s1="                  "
         s2="                  "
         s3="                  "
 endif

 kv=kv+1
 s1=s1+spaces(08)+[Forma de Pagamento]+Spaces(02)
 s2=s2+Format("D13",[Data])+Spaces(02)
 s3=s3+Format("W10.2,EIC",[Valor])+Spaces(02)

  Skip
  If EOT() Then QuitLoop EndIf
EndWhile
if kv>0
  then Print File ARQIMP s1+"\n"
       Print File ARQIMP s2+"\n"
       Print File ARQIMP s3+"\n"
endif
endproc

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

TamObs=132

s="Observacoes.....: "+Tira_QuebraLinha([Observacao na Nota Fiscal])

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 Principal                                                            *
;*******************************************************************************
AGUARDE("Imprimindo Romaneio -> "+NOTAFISC)

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

IMPFAT()

ImpriArq(ARQIMP)

Release Vars QUANT,TOT,CONTADOR
Release Procs IMPFAT,imprimeobs,Vencimentos
LIMPAGUARDE()


