;** Ro_0093T********************************************************************
;** Imprime a Digitacao do Romaneio/Termica       Roupa Fillas                 *
;*******************************************************************************
;Autor           : Vise Informatica (VISERP)
;Desenvolvido  em: 11/12/2007 por Anivel Augusto Rodrigues
;Alterado em     : 09/09/2009 por Anivel Augusto Rodrigues
;Motivo Alteracao: Itens de Devolucao
;Ultima Alteracao: 05/08/2017 por Bruno Carvalho
;Motivo Alteracao: Substituido [Valor IR] -> [Valor DebitoCredito]

;*******************************************************************************
;* 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 [Codigo da Destinacao]="005"                         : Print File ARQIMP Format("W30,AL",[Descricao da Destinacao])
  OtherWise                                                 : Print File ARQIMP "         NOTA PROMISSORIA"+"\n"
EndSwitch

Print File ARQIMP "       ROUPAFILLAS DESIGN"
Print File ARQIMP CI_FNEG
Print File ARQIMP "\n"

Print File ARQIMP "EMISSAO..: "+Format("D13",Today())+"-"+Time()+"\n"
Print File ARQIMP "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])+"\n"
Print File ARQIMP Format("W40,AL",[Razao Social])+"\n"
Print File ARQIMP "AUTORIZ: "+Format("AL",[Nome do Autorizado])+"\n"
Print File ARQIMP "    CPF: "+Format("W14,AL",[CPF do Autorizado])+"\n"

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


If Not Isblank(SubStr([Observacao na Nota Fiscal],001,32))
   Then Print File ARQIMP Spaces(02)+"OBS: "
        Moveto "FaturaC"
        Print File ARQIMP Format("W25,AL",SubStr([Observacao na Nota Fiscal],001,25))+"\n"
        If Not IsBlank (SubStr([Observacao na Nota Fiscal],026,32))
           Then Print File ARQIMP Format("W32,AL",SubStr([Observacao na Nota Fiscal],058,32))+"\n"
                If Not IsBlank(SubStr([Observacao na Nota Fiscal],90,32))
                   Then Print File ARQIMP Format("W32,AL",SubStr([Observacao na Nota Fiscal],90,32))+"\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
Print File ARQIMP Fill("=",32)+"\n"
;******************************** IMPRESSAO DOS ITENS ********************************

Moveto "FaturaID"
Moveto [Numero da OF]
Locate [FaturaC->Numero da OF]
If RetVal
   Then QUANTDV=0
        TOTDV  =0
        Print File ARQIMP "------ ITEM(S) DEVOLVIDOS ------"+"\n"
        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])+"\n"

          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"

          QUANTDV=QUANTDV+[Quantidade]
          TOTDV  =TOTDV+[Preco Total]
          Skip
          If EOT() Or
             [Numero da OF]<>[FaturaC->Numero da OF]
             Then QuitLoop
          EndIf
          Print File ARQIMP Fill("-",32)+"\n"
        EndWhile
        Print File ARQIMP "  Total Devolvido...."+Format("W11.2,EIC",TOTDV)+"\n\n"
EndIf

Print File ARQIMP "------ ITEM(S) COMPRADOS -------"+"\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])+"\n"

   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"

   QUANT=QUANT+[Quantidade]
   TOT=TOT+[Preco Total]
   Skip
   If EOT() Or
      [Numero da OF]<>[FaturaC->Numero da OF]
      Then QuitLoop
   EndIf
   Print File ARQIMP Fill("-",32)+"\n"
EndWhile
Print File ARQIMP "  Total Comprado....."+Format("W11.2,EIC",TOT)+"\n"

Moveto "FaturaC"
Print File ARQIMP Fill("-",32)+"\n"
Print File ARQIMP "VR.LEVOU...: "+Format("W08.2,EIC",TOT)+"\n"
Print File ARQIMP "VR.DEVOLVEU: "+Format("W08.2,EIC",TOTDV)+"\n"

Print File ARQIMP CI_INEG
If [Valor DebitoCredito]>0
   Then DIF="Credito"
   Else If [Valor DebitoCredito]<0
           Then DIF="Debito"
           Else DIF="Zero"
        EndIf
EndIf
Print File ARQIMP "DIFERENCA..: "+Format("W08.2,EIC",[Valor DebitoCredito])
Print File ARQIMP " (" + DIF + ")"
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"

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

Print File ARQIMP Fill("-",32)+"\n"
Print File ARQIMP Fill("\n",10)
EndProc ; (IMPRO)

;*******************************************************************************
;* Rotina Principal                                                            *
;*****************+*************************************************************
ArqImp=PrivDir()+"Ro_0093T.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()
