;** Ro_0152C********************************************************************
;** Imprime a Digitacao do Romaneio/Termica                 Bodock Boutique    *
;*******************************************************************************
;Autor: Visao/Vise
;Desenvolvido  em: 19/01/2012 por Bruno Carvalho
;Ultima Alteracao: 26/06/2018 por Anivel Augusto Rodrigues                           
;Motivo Alteracao: Ajustes itens mercadoria/servico

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

;************************* IMPRESSAO DO CABECALHO *****************************
If Not IsAssigned(NOMEMPRESA)
   Then NOMEMPRESA=""
EndIf

Moveto "FaturaC"


Print File ARQIMP Fill("=",32)+"\n"
Print File ARQIMP CI_INEG
Switch
  Case Search("DEV",[Descricao da Destinacao])>0            : Print File ARQIMP "DEVOLU€ŽO"  
  Case Search("SIMPLES REMESSA",[Descricao da Destinacao])>0: Print File ARQIMP "SIMPLES REMESSA"
  Case Search("CONDICIONAL",[Descricao da Destinacao])>0    : Print File ARQIMP SPACES(10)+"CONDICIONAL"+"\n"
  Case [Codigo da Destinacao]="005"                         : Print File ARQIMP Format("W30,AL",[Descricao da Destinacao])
  OtherWise                                                 : Print File ARQIMP "       NOTA  PROMISSORIA"+"\n"
EndSwitch

Print File ARQIMP "        BODOCK BOUTIQUE      "
Print File ARQIMP CI_FNEG
Print File ARQIMP "\n"

Print File ARQIMP "EMISSAO.: "+Format("D13",Today())+"-"+Time()+"     "+
                  "NUMERO: "+Format("W06,AL",NOTAFISC)+"\n"
                  
Print File ARQIMP "VENDEDORA: "+[Nome Fantasia Represent]+"\n"

Print File ARQIMP Fill("-",32)+"\n"

Print File ARQIMP "CLIENTE: "+Format("W04,AL",[Codigo])+" - "+Format("W18,AL",[CGC])
Print File ARQIMP Format("W40,AL",[Razao Social])+"\n"
Print File ARQIMP "AUTORIZ: "+Format("AL",[Nome do Autorizado])+"\n"
Print File ARQIMP "CPF AUTOR.: "+Format("W14,AL",[CPF do Autorizado])+"\n"

Print File ARQIMP "End: "+Format("AL",[Endereco])+"\n"

Print File ARQIMP Format("W20,AL","Bairro: "+[Bairro])+"     "+"\n"

Print File ARQIMP Format("W20,AL","Cidade: "+[Cidade])+"\n"


If Not Isblank(SubStr([Observacao na Nota Fiscal],001,43))
   Then Print File ARQIMP Spaces(02)+"OBS: "
        Moveto "FaturaC"
        Print File ARQIMP Format("W43,AL",SubStr([Observacao na Nota Fiscal],001,43))+"\n"
        If Not IsBlank (SubStr([Observacao na Nota Fiscal],044,43))
           Then Print File ARQIMP Spaces(05)+Format("W43,AL",SubStr([Observacao na Nota Fiscal],044,43))+"\n"
                If Not IsBlank(SubStr([Observacao na Nota Fiscal],87,43))
                   Then Print File ARQIMP Spaces(05)+Format("W43,AL",SubStr([Observacao na Nota Fiscal],87,43))+"\n"
                EndIf
        EndIf
EndIf

;********** PARCELAS/VENCIMENTOS ********************

Print File ARQIMP Fill("-",32)+"\n"
Print File ARQIMP "      DATA DE VENCIMENTO"+"\n"
Print File ARQIMP "PARC"+Spaces(01)+"ND"+Spaces(01)+"VENCIMENTO"+Spaces(01)+"VALOR"+Spaces(01)+"\n"

Moveto "FaturaV"
Moveto [Numero da OF]
Locate [FaturaC->Numero da OF]
If RetVal
   Then While ([Numero da OF]=[FaturaC->Numero da OF])
          Print File ARQIMP Spaces(0)+AlinhM([Sequencia],2)+Spaces(0)+Format("W4",[Numero de Dias])+
                            Spaces(2)+ Format("D13",[Data])+Spaces(0)+Format("W11.2,EIC",[Valor])+Spaces(1)+Format("W2",[Forma de Pagamento])+"\n"
          Skip
          If EOT() Then QuitLoop EndIf
        EndWhile
EndIf
;******************************** IMPRESSAO DOS ITENS ********************************
Print File ARQIMP Fill("=",32)+"\n"
  if([FaturaC->Descricao da Destinacao] <>"CONDICIONAL")
   then 
  Print File ARQIMP "        ITEM COMPRADOS"+"\n"  
Print File ARQIMP Fill("-",32)+"\n"  
  else
  Print File ARQIMP "      ITEM CONDICIONAL"+"\n"
  endif             
Print File ARQIMP Fill("-",32)+"\n"

;Item Codigo      Descri‡Ćo
;     Qtde     Vl unit rio               Vl Item
;     
;123  1234567890  123456789012345678901234567890
;     9999 PC x 12345678                12345678

Moveto "FaturaI"
Moveto [Numero da OF]
Locate [FaturaC->Numero da OF]
QUANT=0
TOT  =0

While [Numero da OF]=[FaturaC->Numero da OF]
   Print File ARQIMP Format("W10,AR",[Codigo do Item])+" "
   Print File ARQIMP Format("W18,AL",[Descricao do Item])

   Print File ARQIMP Format("W09,EIC",[Quantidade])+Spaces(01)
   Print File ARQIMP Format("W02,AL",[Unidade Fiscal])+" x "
   Print File ARQIMP Format("W08.2,EIC",[Preco Unitario])+Spaces(1)
   Print File ARQIMP Format("W08.2,EIC",[Preco Total])+"\n"
      
   Moveto[Codigo do Item]
   If BUSCA_LOOKUP("Codigo do Item",[FaturaI->Codigo do Item],"")
      Then Loc   =REG_BUSCA_LOOKUP["Localizacao"]
   EndIf
   UnlockRecord   
   Print File ARQIMP "Loc: "+ Format("W07,EIC",Loc)+"\n" 
   
   QUANT=QUANT+[Quantidade]
   TOT=TOT+[Preco Total]
   Skip
   If EOT() Then QuitLoop EndIf
Print File ARQIMP Fill("-",32)+"\n"
EndWhile

Moveto "FaturaC"
Print File ARQIMP "Valor Total: "+"\n"
Print File ARQIMP Spaces(2)+Format("W11.2,EIC",[Valor Mercadoria]+[Valor Servico])+"\n"
Print File ARQIMP Fill("-",32)+"\n"
Print File ARQIMP "VR.MERCADORIAS: "+Format("W08.2,EIC",[Valor Mercadoria])+"\n"
Print File ARQIMP "VR.DESCTO: "+Format("W8.2,EIC",[Valor Desconto])+"\n"

Print File ARQIMP "VR.SERVICOS...: "+Format("W08.2,EIC",[Valor Servico   ])+"\n"
Print File ARQIMP "VR.DESCTO: "+Format("W8.2,EIC",[Valor Desconto Servico])+"\n\n"

Print File ARQIMP CI_INEG
Print File ARQIMP Format("W40,AC","VR A PAGAR.: "+ LTrim(Format("W11.2,EIC",[Valor Nota Fiscal])))
Print File ARQIMP CI_FNEG+"\n"

Print File ARQIMP Fill("-",32)+"\n\n\n"

Print File ARQIMP Spaces(02)+Fill("_",28)+"\n"

Print File ARQIMP Format("AL",[Razao Social])+"\n"
Print File ARQIMP "CPF: "+ Format("W18,AL",[CGC])+"\n"

if ([Descricao da Destinacao]<>"CONDICIONAL" )
   Then
        Print File ARQIMP Fill("-",32)+"\n"
        Print File ARQIMP Spaces(01)+"PRAZO PARA TROCA 8 DIAS SOMENTE COM A APRESENTACAO DESTE"+"\n"
        Print File ARQIMP Spaces(04)+" 'NAO TEMOS COBRADOR'     "+"\n"
        Print File ARQIMP Spaces(0)+ "HAVERA AUMENTO APOS O VENCIMENTO "+"\n"


endif
Print File ARQIMP Fill("-",32)+"\n"
Print File ARQIMP Fill("\n",10)

EndProc ; (IMPRO)

;*******************************************************************************
;* Rotina Principal                                                            *
;*****************+*************************************************************
ArqImp=PrivDir()+"Ro_0152C.Txt"
If IsFile(ArqImp)
   Then Deleta_Arquivo(ARQIMP)
EndIf

AGUARDE("Imprimindo Orcamento -> "+NOTAFISC)
IMPRO()

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

Release Vars  CLIENTE,END_ENT,BAI_ENT,CID_ENT,CEP_ENT
Release Procs IMPRO
LIMPAGUARDE()
