;** RO_0054 ********************************************************************
;** Imprime a Digitacao do Romaneio                        ** CARMIG **
;*******************************************************************************
;Autor           : Vise Informatica (VISERP)
;Desenvolvido  em: 04/08/2005 por Antonio Marcelo Alves
;Motivo Alteracoa: Ajuste ARQIMP
;Ultima Alteracao: 14/08/2007 por Antonio Marcelo Alves
;Motivo Alteracao: Ajustes Deleta_Arquivo

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

;* Nao eh necessario mudar as configura‡”es para impressao de duas vias

;************************** IMPRESSAO DO CABECALHO *****************************
If Not IsAssigned(NOMEMPRESA)
   Then NOMEMPRESA=""
EndIf
Moveto "Faturac"
cont = [Numero de Parcelas]
Print File ARQIMP CI_6LPP
Print File ARQIMP CI_15CPP
Print File ARQIMP Chr(27)+Chr(71)
Print File ARQIMP "CARMIG                                                            "+Spaces(03)
Print File ARQIMP "CARMIG"+"\n"
Print File ARQIMP Chr(27)+Chr(72)
Print File ARQIMP "Orcamento: "+Format("W06.3,AL",NOTAFISC)+" - Data: "+Format("D10",Today())+" - Hora: "+Time()+Spaces(18)
Print File ARQIMP "Orcamento: "+Format("W06.3,AL",NOTAFISC)+" - Data: "+Format("D10",Today())+" - Hora: "+Time()+"\n"
Print File ARQIMP "Cliente  : "
Print File ARQIMP Chr(27)+Chr(71)
Print File ARQIMP Format("W05,AL",[Codigo])+Format("W29,AL",[Razao Social])+Spaces(24)
Print File ARQIMP Chr(27)+Chr(72)
Print File ARQIMP "Cliente  : "
Print File ARQIMP Chr(27)+Chr(71)
Print File ARQIMP Format("W05,AL",[Codigo])+Format("W29,AL",[Razao Social])+"\n"
Print File ARQIMP Chr(27)+Chr(72)

Print File ARQIMP Spaces(09)+Format("W39,AL",[Endereco])
Print File ARQIMP Format("W18,AL",[CGC])+Spaces(03)
Print File ARQIMP Spaces(09)+Format("W39,AL",[Endereco])
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(03)
Print File ARQIMP Spaces(09)+Format("W19,AL",[Bairro])
Print File ARQIMP Format("W20,AL",[CEP])
Print File ARQIMP Format("W18,AL",[IE])+"\n"

Print File ARQIMP  Spaces(09)+Format("W17,AL",[Telefone])+Spaces(44)
Print File ARQIMP  Spaces(09)+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(37)
Print File ARQIMP "Vendedor: "+Format("W05,AL",[Codigo do Representante])
Print File ARQIMP Format("W18,AL",[Nome Fantasia Represent])+"\n"

;NOME_USUARIO=""
;Moveto [Codigo_Usuario]
;Ativa_Lookup()
;Moveto [Chapa]
;Locate [FaturaC->Codigo_Usuario]
;If RetVal
;   Then NOME_USUARIO=[Nome]
;EndIf
;KeyPress "Esc"

;Print File ARQIMP "Cortador: "+Format("W05,AL",[Codigo_Usuario])
;Print File ARQIMP Format("W14,AL",NOME_USUARIO)+Spaces(03)
;Print File ARQIMP "Vendedor: "+Format("W05,AL",[Codigo do Representante])
;Print File ARQIMP Format("W18,AL",[Nome Fantasia Represent])+Spaces(04)
;Print File ARQIMP "Cortador: "+Format("W05,AL",[Codigo_Usuario])
;Print File ARQIMP Format("W14,AL",NOME_USUARIO)+"\n"

;********************* IMPRESSAO DOS ITENS ********************************
Print File ARQIMP "------------------------------------------------------------------"+Spaces(03)
Print File ARQIMP "------------------------------------------------------------------"+"\n"
Print File ARQIMP "Item                               Un   Quant Unitario       Total"+Spaces(03)
Print File ARQIMP "Item                               Un   Quant Unitario       Total"+"\n"
Print File ARQIMP "------------------------------------------------------------------"+Spaces(03)
Print File ARQIMP "------------------------------------------------------------------"+"\n"
Moveto "FaturaI"
Moveto [Numero da OF]
Locate [FaturaC->Numero da OF]
QUANTOT    = 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(02)
     EndIf
     Print File ARQIMP Format("W10,AL",[Codigo do Item])
     Print File ARQIMP Spaces(01)+Format("W23,AL",[Descricao do Item])
     Print File ARQIMP Spaces(01)+Format("W03,Al",[Unidade Fiscal])
     Print File ARQIMP Format("W07.2,EIC",[Quantidade])

     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 12
    Print File ARQIMP "\n"
EndFor

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

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

;Moveto "FaturaC"
;LINHA1=""
;LINHA2=""

;If [Descricao CondPagto]<>"CONTRA APRESENTACAO"
;   Then For i From 1 To cont
;          If Not IsBlank(dtvencto[i])
;            Then LINHA1=LINHA1+Spaces(02)+Format("W10,AL",Format("D13",dtvencto[i]))
;                 LINHA2=LINHA2+Spaces(02)+Format("W10.2,EIC,AR",valorven[i])
;
;          EndIf
;        EndFor
;EndIf
;
;Print File ARQIMP LINHA1
;Print File ARQIMP LINHA1+"\n"
;Print File ARQIMP LINHA2
;Print File ARQIMP LINHA2+"\n"





;********************* 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 Mercadoria Liquido])+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 Mercadoria Liquido])+"\n\n"

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

Print File ARQIMP "-------------------------------------------------------------------"+Spaces(03)
Print File ARQIMP "------------------------------------------------------------------"+"\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_0054.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()


