;** Ro_0393 ********************************************************************
;** Imprime a Digitacao do Romaneio                             #SPEED BOX#    *
;*******************************************************************************
;Autor           : Vise Informatica (VISERP)
;Desenvolvido  em: 15/02/2017 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()
private descrtab

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

Pega_Endereco_Fatura([FaturaC->Numero da OF])

Moveto "FaturaC"
Moveto [Codigo da Tabela]
GetRecord "\\Sistemas\\Vendas\\Tbprcab" [FaturaC->Codigo da Tabela] To descrtab
If RetVal
   Then descrtab=descrtab["Descricao da Tabela"]
   Else descrtab="?"
EndIf   

Print File ARQIMP CI_10CPP
Print File ARQIMP Fill("=",48)+"\n"
Print File ARQIMP CI_IEXP
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 [Codigo da Destinacao]<>""                           : Print File ARQIMP "PEDIDO"
  OtherWise                                                 : Print File ARQIMP "PEDIDO"
EndSwitch

Print File ARQIMP CI_FEXP
Print File ARQIMP CI_FNEG

Print File ARQIMP Spaces(10)+Username()
Print File ARQIMP "\n"

Print File ARQIMP Spaces(01)+"EMISSAO: "+Format("D13",Today())+"-"+Time()+"  "+
                  " NUMERO:  "+Format("W06.3,AL",NOTAFISC)+"\n"
Print File ARQIMP "VENDEDOR: "+Format("W21,AL",[Nome Fantasia Represent])+"\n"
;Print File ARQIMP Spaces(04)+" TAB: "+Format("W06,AL",[Codigo da Tabela])
;Print File ARQIMP Format("W35,AL",descrtab)+"\n"

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

Print File ARQIMP Spaces(01)+"CLIENTE..: "
Print File ARQIMP Format("W05,AL",[Codigo])
Print File ARQIMP Format("W31,AL",[Razao Social])+"\n"
Print File ARQIMP Spaces(01)+"CPF/CNPJ.: "+Format("W27,AL",[CGC])+"\n"

CLIENTE=[Razao Social]
Print File ARQIMP Spaces(01)+"ENDERECO.: "+ Format("W36,AL",[Endereco])+"\n"
Print File ARQIMP Spaces(01)+"BAIRRO...: "+ Format("W20,AL",[Bairro])+"\n"
Print File ARQIMP Spaces(01)+"FONE.....: " + Format("W19,AL",[Telefone])+"\n"
Print File ARQIMP Spaces(01)+"CIDADE...: "+Format("W20,AL",[Cidade])+Spaces(2)
Print File ARQIMP "PEDIDO: "+[Numero do Pedido]+"\n"

If (LTrim(RTrim(VSD_E_Endereco))<>"O MESMO") And (LTrim(RTrim(VSD_E_Endereco))<>LTrim(RTrim([Endereco]))) And Rtrim(Ltrim(VSD_E_Endereco))<>""
   Then Print File ARQIMP "------------- ENDERECO DE ENTREGA --------------"+"\n"    
        Print File ARQIMP Spaces(01)+"ENDERECO.: "+ Format("W36,AL",VSD_E_Endereco)+"\n"
        Print File ARQIMP Spaces(01)+"BAIRRO...: "+ Format("W20,AL",VSD_E_Bairro)+"\n"
        Print File ARQIMP Spaces(01)+"CIDADE...: "+Format("W20,AL",VSD_E_Cidade)+" - "+Format("W2,AL",VSD_E_UF)+"\n"
EndIf     

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

Print File ARQIMP Fill("-",48)+"\n"
Print File ARQIMP Spaces(01)+"PARCELA"+Spaces(05)+"ND"+Spaces(05)+"VENCIMENTO"+Spaces(07)+"VALOR"+Spaces(02)+"FP"+"\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(4)+AlinhM([Sequencia],2)+Spaces(05)+Format("W4",[Numero de Dias])+
                            Spaces(05)+ Format("D13",[Data])+Spaces(01)+Format("W11.2,EIC",[Valor])+Spaces(02)+Format("W2",[Forma de Pagamento])+"\n"
          Skip
          If EOT() Then QuitLoop EndIf
        EndWhile
EndIf

;******************************** IMPRESSAO DOS ITENS ********************************
Print File ARQIMP Fill("=",48)+"\n"
Print File ARQIMP "   CODIGO     DESCRICAO"+"\n"
Print File ARQIMP "       QTD  UF      Vr.Uni     Vr.Total"+"\n"
Print File ARQIMP Fill("=",48)+"\n"

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

While [Numero da OF]=[FaturaC->Numero da OF]
  CONT_ITE = 0
  COD_ITEM = [Codigo do Item]
  For i From 1 To 10
    If SubStr(COD_ITEM,i,1)="0"
       Then CONT_ITE = CONT_ITE + 1
       Else COD_ITEM = SubStr(COD_ITEM,CONT_ITE+1,Len(COD_ITEM))
            QuitLoop    
    EndIf   
  EndFor

  Print File ARQIMP Spaces(03)+Format("W11,AL",COD_ITEM)+
                    Format("W30,AL",[Descricao do Item])+"\n"
  If Not IsBlank([Informacoes_Adicionais])
     Then INF_ADICIONAL = [Informacoes_Adicionais]
          TM = Int(Len(INF_ADICIONAL)/34)+1
          For i From 1 To TM
            Print File ARQIMP Spaces(14)
            Print File ARQIMP Rtrim((Ltrim(SubStr(INF_ADICIONAL,1,34))))+"\n"
            INF_ADICIONAL = Substr(INF_ADICIONAL,35,Len(INF_ADICIONAL))
          EndFor
  EndIf
  Print File ARQIMP Format("W11.3,EIC",[Quantidade])+" "+
                    Format("W03,AL",[Unidade Fiscal])+"x "+
                    Format("W09.2,EIC",[Preco Unitario])+" = "+
                    Format("W10.2,EIC",[Preco Total])+"\n"
  
  Release Vars CONT_ITE,COD_ITEM,INF_ADICIONAL
  QUANT=QUANT+[Quantidade]
  TOT=TOT+[Preco Total]
  Skip
  If EOT() Then QuitLoop EndIf
EndWhile

Moveto "FaturaC"
Print File ARQIMP Spaces(05)+"------"
Print File ARQIMP Spaces(22)+"------"+"\n"
Print File ARQIMP Spaces(02)+Format("W09.3,EIC",QUANT)
Print File ARQIMP Spaces(17)+Format("W11.2,EIC",[Valor Mercadoria]+[Valor Servico])+"\n"
Print File ARQIMP Fill("-",48)+"\n"

Print File ARQIMP "VR.MERCADORIAS: "+Format("W11.2,EIC",[Valor Mercadoria])+
                  Spaces(02)+"VR.DESCTO: "+Format("W8.2,EIC",[Valor Desconto])+"\n"

Print File ARQIMP "VR.SERVICO....: "+Format("W11.2,EIC",[Valor Servico])+
                  Spaces(02)+"VR.DESCTO: "+Format("W8.2,EIC",[Valor Desconto Servico])+"\n"


Print File ARQIMP "VR.FRETE......: "+Format("W11.2,EIC",[Valor do Frete])+"\n\n"

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

If IsAssigned(VSD_VrTroco)
   Then Print File ARQIMP Spaces(01)+"VR RECEBIDO..: "+Format("W11.2,EIC",VSD_VrTroco)+"\n"
        Print File ARQIMP Spaces(01)+"VR TROCO.....: "+Format("W11.2,EIC",VrTroco)+"\n"
EndIf


If Not Isblank(SubStr([Observacao na Nota Fiscal],001,36))
   Then Print File ARQIMP Spaces(01)+"OBS......: "
        Moveto "FaturaC"
        Print File ARQIMP Format("W36,AL",SubStr([Observacao na Nota Fiscal],001,36))+"\n"
        If Not IsBlank (SubStr([Observacao na Nota Fiscal],037,47))
           Then Print File ARQIMP Spaces(01)+Format("W47,AL",SubStr([Observacao na Nota Fiscal],037,47))+"\n"
                If Not IsBlank(SubStr([Observacao na Nota Fiscal],84,47))
                   Then Print File ARQIMP Spaces(01)+Format("W47,AL",SubStr([Observacao na Nota Fiscal],84,47))+"\n"
                        If Not IsBlank(SubStr([Observacao na Nota Fiscal],131,47))
                           Then Print File ARQIMP Spaces(01)+Format("W47,AL",SubStr([Observacao na Nota Fiscal],131,47))+"\n"
                        EndIf 
                EndIf
        EndIf
EndIf

Print File ARQIMP "\n"
Print File ARQIMP Fill("-",48)+"\n\n\n"
Print File ARQIMP Spaces(04)+Fill("-",40)+"\n"
Print File ARQIMP Spaces(04)+Format("W40,AC",CLIENTE)+"\n"
Print File ARQIMP Fill("-",48)+"\n\n\n\n\n\n"

EndProc ; (IMPRO)

;*******************************************************************************
;* Rotina Principal                                                            *
;*****************+*************************************************************
ArqImp="C:\\RO_0204.Txt"
If IsFile(ArqImp)
   Then Deleta_Arquivo(ARQIMP)
EndIf

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

ImpriArq(Arqimp)

;---- Imprime Arquivo Impressao ------------------------------------------------
;If DISPOSITIVO_OPCAO="V"
;   Then ImpriArq(ARQIMP)
;   Else ImpriSerial(ArqImp,"COM4")
;EndIf

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