;** RO_0181 *******************************************************************
;** Imprime a Digitacao do Romaneio                        ** RADAMES MOTOS   *
;*******************************************************************************
;Autor           : Vise Informatica (VISERP)
;Desenvolvido  em: 11/07/2007 por Nikolas M. Mateus
;Alterado em     : 11/07/2007 por Nikolas M. Mateus
;Motivo Alteracao: Ajustes
;Ultima Alteracao: 15/08/2007 por Anivel Augusto Rodrigues
;Motivo Alteracao: Ajustes Run
;Ultima Alteracao: 30/08/2007 por Nikolas
;Motivo Alteracao: Ajustes Vencimentos
;Ultima Alteracao: 06/11/2007 por Nikolas
;Motivo Alteracao: Ajustes
;Ultima Alteracao: 26/06/2018 por Anivel Augusto Rodrigues                           
;Motivo Alteracao: Ajustes itens mercadoria/servico

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

;* Nao e necessario mudar as configura‡”es para impressao de duas vias
;* Configurado para 11 Itens em cada nota
;************************** IMPRESSAO DO CABECALHO *****************************

If Not IsAssigned(NOMEMPRESA)
   Then NOMEMPRESA=""
EndIf
Moveto "Faturac"
Print File ARQIMP CI_6LPP
Print File ARQIMP CI_15CPP

Print File ARQIMP "Orcamento: "+Format("W06.3,AL",NOTAFISC)+" - Data: "+Format("D10",Today())+" - Hora: "+Time()+Spaces(19)
Print File ARQIMP "Orcamento: "+Format("W06.3,AL",NOTAFISC)+" - Data: "+Format("D10",Today())+" - Hora: "+Time()+"\n"

Print File ARQIMP "Cliente  : "
Print File ARQIMP Format("W05,AL",[Codigo])+Format("W39,AL",[Razao Social])+Spaces(15)
Print File ARQIMP "Cliente  : "
Print File ARQIMP Format("W05,AL",[Codigo])+Format("W39,AL",[Razao Social])+"\n"

Print File ARQIMP Spaces(09)+Format("W39,AL",[Endereco])
;Print File ARQIMP Format("W18,AL",[CGC])+Spaces(04)
Print File ARQIMP Spaces(31)+Format("W39,AL",[Endereco])
Print File ARQIMP Spaces(18)+"\n"
;Print File ARQIMP Format("W18,AL",[CGC])+"\n"

Print File ARQIMP Spaces(09)+Format("W19,AL",[Bairro])
Print File ARQIMP Format("W20,AL",[CEP])
;Print File ARQIMP Format("W18,AL",[IE])+Spaces(04)
Print File ARQIMP Spaces(22)+Format("W19,AL",[Bairro])
Print File ARQIMP Format("W20,AL",[CEP])
Print File ARQIMP Spaces(18)+"\n"
;Print File ARQIMP Format("W18,AL",[IE])+"\n"

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

Print File ARQIMP "Vendedor: "+Format("W05,AL",[Codigo do Representante])
Print File ARQIMP Format("W18,AL",[Nome Fantasia Represent])+Spaces(04)

NOME_USUARIO=""
Moveto [Codigo_Usuario]
KeyPress "F1"
Moveto [Chapa]
Locate [FaturaC->Codigo_Usuario]
If RetVal
   Then NOME_USUARIO=[Nome]
EndIf
KeyPress "Esc"



Print File ARQIMP Spaces(33)+"Vendedor: "+Format("W05,AL",[Codigo do Representante])
Print File ARQIMP Format("W18,AL",[Nome Fantasia Represent])+Spaces(04)+"\n"

;********************* IMPRESSAO DOS ITENS ********************************
Print File ARQIMP "------------------------------------------------------------------"+Spaces(04)
Print File ARQIMP "------------------------------------------------------------------"+"\n"
Print File ARQIMP "Item                               Un   Quant Unitario       Total"+Spaces(04)
Print File ARQIMP "Item                               Un   Quant Unitario       Total"+"\n"
Print File ARQIMP "------------------------------------------------------------------"+Spaces(04)
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]) And (CONTADOR<>12)
  For CON From 1 to 3
     If CON=3
        Then Print File ARQIMP Spaces(03)
     EndIf

     COD_FOR=""
     Moveto [Codigo do Item]
     KeyPress "F1"
     Moveto [Codigo do Item]
     Locate [FaturaI->Codigo do Item]
     If RetVal
        Then COD_FOR=[Codigo Fornecedor]
     EndIf
     KeyPress "Esc"

    ;Print File ARQIMP Format("W13,AL",COD_FOR)
     Print File ARQIMP Format("W13,AL",[Codigo do Item])
     Print File ARQIMP Spaces(01)+Format("W20,AL",[Descricao do Item])
     Print File ARQIMP Spaces(01)+Format("W03,Al",[Unidade Fiscal])
     Print File ARQIMP Format("W07.2,EIC",[Quantidade])
     QUANTOT=0
     QUANTOT=QUANTOT+[Quantidade]
     Print File ARQIMP Format("W09.2,EIC",[Preco Unitario])
     Print File ARQIMP Format("W12.2,EIC",[Preco Total])+Spaces(01)
     CON=CON+1
  EndFor
     TOT   = TOT + [Preco Total]
     CON=1
  Skip
  If EOT() Then QuitLoop EndIf
  CONTADOR = CONTADOR + 1
  Print File ARQIMP "\n"
EndWhile

For ITEM From CONTADOR To 11
    Print File ARQIMP "\n"
EndFor
Print File ARQIMP "-------------------------------------------------------------------"+Spaces(04)
Print File ARQIMP "------------------------------------------------------------------"+"\n"
Print File ARQIMP " TROCA DE MERCADORIA SOMENTE NO PRAZO DE 48 HORAS COM APRESENTACAO"+Spaces(04)
Print File ARQIMP " TROCA DE MERCADORIA SOMENTE NO PRAZO DE 48 HORAS COM APRESENTACAO"+"\n"
Print File ARQIMP "          ***  APOS O VENCIMENTO SERA COBRADO JUROS ***    "+Spaces(11)
Print File ARQIMP "          ***  APOS O VENCIMENTO SERA COBRADO JUROS ***    "+"\n"
Print File ARQIMP "         *** NAO ACEITAMOS DEVOLUCAO, SOMENTE TROCA ***"+Spaces(15)
Print File ARQIMP "         *** NAO ACEITAMOS DEVOLUCAO, SOMENTE TROCA ***"+"\n"

Print File ARQIMP "-------------------------------------------------------------------"+Spaces(03)
Print File ARQIMP "-------------------------------------------------------------------"+"\n"

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

Moveto "FaturaV"
Moveto [Numero da OF]
Locate [FaturaC->Numero da OF]
If RetVal
Then
dtVencto1 = 0
dtVencto2 = 0
dtVencto3 = 0
dtVencto4 = 0
ValorVen1 = 0
ValorVen2 = 0
ValorVen3 = 0
ValorVen4 = 0
    i=1
    While [Numero da OF] = [FaturaC->Numero da OF]
      Switch
      Case i = 1:
            dtvencto1 = [Data ]
            valorven1 = [Valor]
            i=i+1
      Case i = 2:
            dtvencto2 = [Data ]
            valorven2 = [Valor]
            i=i+1

      Case i = 3:
            dtvencto3 = [Data ]
            valorven3 = [Valor]
            i=i+1

      Case i = 4:
            dtvencto4 = [Data ]
            valorven4 = [Valor]
            i=i+1
      EndSwitch
      Skip
      If EOT() Then QuitLoop Endif

    EndWhile
Endif


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

       Print File ARQIMP Spaces(03)+Format("W10,AL",Format("D13",dtvencto1))
       Print File ARQIMP Spaces(03)+Format("W10.2,EIC,AR",valorven1)
       Print File ARQIMP Spaces(09)+"Total.............."+Format("W12.2,EIC",TOT)+Spaces(02)
       Print File ARQIMP Spaces(03)+Format("W10,AL",Format("D13",dtvencto1))
       Print File ARQIMP Spaces(03)+Format("W10.2,EIC,AR",valorven1)
       Print File ARQIMP Spaces(09)+"Total.............."+Format("W12.2,EIC",TOT)+"\n"

       Print File ARQIMP Spaces(03)+Format("W10,AL",Format("D13",dtvencto2))
       Print File ARQIMP Spaces(03)+Format("W10.2,EIC,AR",valorven2)
       Print File ARQIMP Spaces(09)+"Desconto"+Format("W06.2,EIC",[Taxa de Desconto]) + "%...."
       Print File ARQIMP Format("W12.2,EIC",[Valor Desconto])+Spaces(02)
       Print File ARQIMP Spaces(03)+Format("W10,AL",Format("D13",dtvencto2))
       Print File ARQIMP Spaces(03)+Format("W10.2,EIC,AR",valorven2)
       Print File ARQIMP Spaces(09)+"Desconto"+Format("W06.2,EIC",[Taxa de Desconto]) + "%...."
       Print File ARQIMP Format("W12.2,EIC",[Valor Desconto])+"\n"

       Print File ARQIMP Spaces(03)+Format("W10,AL",Format("D13",dtvencto3))
       Print File ARQIMP Spaces(03)+Format("W10.2,EIC,AR",valorven3)
       Print File ARQIMP Spaces(09)+"Total Liquido......"+Format("W12.2,EIC",[Valor Nota Fiscal])+Spaces(02)
       Print File ARQIMP Spaces(03)+Format("W10,AL",Format("D13",dtvencto3))
       Print File ARQIMP Spaces(03)+Format("W10.2,EIC,AR",valorven3)

       Print File ARQIMP Spaces(09)+"Total Liquido......"+Format("W12.2,EIC",[Valor Nota Fiscal])+"\n"
       Print File ARQIMP Spaces(03)+"Condicao de Pagto. "+Format("W25,AL",[Descricao CondPagto])
       Print File ARQIMP Spaces(25)+"Condicao de Pagto. "+Format("W25,AL",[Descricao CondPagto])+"\n"

       Print File ARQIMP Spaces(15)+"Ass: --------------------------------------------"+Spaces(05)
       Print File ARQIMP Spaces(15)+"Ass: --------------------------------------------"+"\n\n\n"


;************************* IMPRESSAO DO RODAPE *********************************
Print File ARQIMP CI_6LPP
Print File ARQIMP CI_10CPP
;Print File ARQIMP "\f"
Print File ARQIMP chr(27)+chr(67)+chr(66) ;Imprime 66 Linhas por pagina
EndProc

;*******************************************************************************
;* Rotina Principal                                                            *
;*******************************************************************************

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

AGUARDE("Imprimindo Romaneio -> "+NOTAFISC)
IMPFAT()
Print File ARQIMP CI_10CPP
Print File ARQIMP CI_6LPP

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

Release Vars VALOR,DATA
Release Procs IMPFAT,VENC
LIMPAGUARDE()

