;** RO_0272 ********************************************************************
;** Imprime a Digitacao do Romaneio                    ** TECIDOS BRAZAO **    *
;*******************************************************************************
;Autor           : Vise Informatica (VISERP)
;Desenvolvido  em: 08/11/2013 por Andrey Fillipe
;Ultima Alteracao: 13/02/2019 por Anivel Augusto Rodrigues  
;Motivo Alteracao: Ajustes descricao complementar                
 
;*******************************************************************************
;* Rotina para Impressao do Relatorio                                          *
;*******************************************************************************
Proc IMPFAT()
private regitens

;************************** IMPRESSAO DO CABECALHO *****************************
If Not IsAssigned(NOMEMPRESA)
   Then NOMEMPRESA=""
EndIf
Moveto "Faturac"
Print File ARQIMP chr(27)+chr(67)+chr(33) ;Imprime 33 Linhas por pagina
Print File ARQIMP CI_15CPP
Print File ARQIMP CI_6LPP

Print File ARQIMP Fill("=",132)+"\n"
Print File ARQIMP "\027E"
Print File ARQIMP RTrim(Format("W50,AL","DOCUMENTO NAO FISCAL -"))
If [Descricao da Destinacao]="VENDA BALCAO"
   Then Print File ARQIMP Spaces(01)+Format("W20,AL",[Descricao da Destinacao])+"\n"
   Else Print File ARQIMP Spaces(01)+Format("W20,AL","PEDIDO")+"\n"
EndIf
Print File ARQIMP "\027F"

GetRecord "\\Sistemas\\Cadastro\\Empresas" [FaturaC->Codigo da Empresa] To DynArray EMP
If RetVal
   Then RAZ_SOC = EMP["Razao Social Empresa"]  
        END_EMP = EMP["Endereco Empresa"]
        BAI_EMP = EMP["Bairro Empresa"]
        CEP_EMP = EMP["CEP Empresa"]
        CID_EMP = EMP["Cidade Empresa"]
        UF_EMP  = EMP["UF Empresa"]
        TEL_EMP = EMP["Telefone Empresa"]
   Else RAZ_SOC = ""
        END_EMP = ""
        BAI_EMP = ""
        CID_EMP = ""
        CEP_EMP = ""
        UF_EMP  = ""
        TEL_EMP = ""
EndIf  
 
Print File ARQIMP Format("W40,AL",RAZ_SOC)+"\n"
If BAI_EMP <> ""
   Then Print File ARQIMP Spaces(00)+RTrim(Format("W40,AL",END_EMP))+" - "+RTrim(Format("W20,AL",BAI_EMP))
   Else Print File ARQIMP Spaces(00)+RTrim(Format("W40,AL",END_EMP))
EndIf
If UF_EMP <> ""
   Then If CEP_EMP<>""
           Then Print File ARQIMP Spaces(05)+RTrim(Format("W20,AL",CID_EMP))+" - "+RTrim(Format("W3,AL",UF_EMP))
                Print File ARQIMP Spaces(05)+"CEP: "+RTrim(Format("W10,AL",CEP_EMP))+"\n"
           Else Print File ARQIMP Spaces(05)+RTrim(Format("W20,AL",CID_EMP))+" - "+RTrim(Format("W3,AL",UF_EMP))+"\n"
        EndIf
   Else If CEP_EMP<>""
           Then Print File ARQIMP Spaces(05)+RTrim(Format("W20,AL",CID_EMP))
                Print File ARQIMP Spaces(05)+"CEP: "+RTrim(Format("W10,AL",CEP_EMP))+"\n"
           Else Print File ARQIMP Spaces(05)+RTrim(Format("W20,AL",CID_EMP))+"\n"
        EndIf
EndIf
If TEL_EMP <> ""
   Then Print File ARQIMP Spaces(00)+"FONE: "+Format("W20,AL",TEL_EMP)
EndIf 
 
 
 
 
Print File ARQIMP Spaces(57)+"Emissao: "+Format("D10",[Data de Emissao]) +Spaces(4)+"Impressao: "+Format("D10",Today())+"-"+Time()+ "\n"
Print File ARQIMP Fill("=",132)+"\n"

Print File ARQIMP "Cliente : "+Format("W05,AL",[Codigo])+Format("W46,AL",[Razao Social])
Print File ARQIMP "\027E"
Print File ARQIMP Spaces(57)+"NUMERO: "+Format("W06.3,AL",NOTAFISC)+"\n"
Print File ARQIMP "\027F"

Print File ARQIMP CI_8LPP
Print File ARQIMP "\027P"         ;Imprime 10 Caracteres por polegada

Print File ARQIMP Spaces(00)+Format("W40,AL",[Endereco])
Print File ARQIMP Spaces(01)+Format("W20,AL",[Bairro]) +"\n"

Print File ARQIMP Format("W10,AL",[CEP])
Print File ARQIMP Spaces(02)+Format("W20,AL",[Cidade])
Print File ARQIMP Spaces(01)+Format("W2,AL",[UF])
Print File ARQIMP Spaces(05)+Format("W18,AL",[CGC]) 
Print File ARQIMP Spaces(05)+Format("W25,AL",[IE])+"\n"

Print File ARQIMP "Vendedor: "+Format("W05,AL",[Codigo do Representante])
Print File ARQIMP Format("W25,AL",[Nome Fantasia Represent])+"\n"
Print File ARQIMP "\015"         ;Imprime 17 Caracteres por polegada

;********************* IMPRESSAO DOS ITENS ********************************
Print File ARQIMP "------------------------------------------------------------------------------------------------------------------------------------"+"\n"
Print File ARQIMP Spaces(02)+"Item                                                                                         Un  Quantidade  Unitario        Total"+"\n"
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]

  desccompl     = [Descricao do Item      ]
  
  getrecord "\\sistemas\\estoque\\itens" [Codigo do Item] to regitens 
  If RetVal
     Then 
          if not isblank(regitens["Descricao Complementar"])
             then desccompl=regitens["Descricao Complementar"]
          endif    
  EndIf

  Print File ARQIMP Spaces(01)+Format("W03,AL",[Item da OF])
  Print File ARQIMP Spaces(01)+Format("W11,AL",[Codigo do Item])
  Print File ARQIMP Spaces(01)+Format("W62,AL",desccompl)
; Print File ARQIMP Spaces(01)+Format("W62,AL",[Descricao do Item])
  Print File ARQIMP Spaces(16)+Format("W03,Al",[Unidade Fiscal])

  If [Quantidade]-Int([Quantidade])>0
     Then Print File ARQIMP Format("W011.3,EIC",[Quantidade])
     Else Print File ARQIMP Format("W011,EIC",[Quantidade])
  EndIf

  Print File ARQIMP Format("W10.2,EIC",[Preco Unitario])
  Print File ARQIMP Format("W13.2,EIC",[Preco Total])+"\n"
  TOT   = TOT + [Preco Total]
  Skip
  If EOT() Then QuitLoop EndIf
  CONTADOR = CONTADOR + 1
EndWhile

For ITEM From CONTADOR To 12
    Print File ARQIMP "\n"
EndFor

;********************* IMPRESSAO DOS VENCIMENTOS **************************
;Print File ARQIMP "\018"
Print File ARQIMP "\n"
Print File ARQIMP "Vencimentos: "

Array DATA[9]
Array VALOR[9]
K=0
KV=0
Moveto "FaturaV"
Moveto [Numero da OF]
Locate [FaturaC->Numero da OF]
While [Numero da OF]=[FaturaC->Numero da OF]
  K=K+1
  DATA[K]  = Format("D13",[Data])
  VALOR[K] = Format("W10.2,EIC",[Valor])
  If K=9
     Then VENC()
          K=0
  EndIf
  Skip
  If EOT() Then QuitLoop EndIf
EndWhile
If K>0
   Then VENC()
EndIf
                                                                                                                   
Print File ARQIMP "------------------------------------------------------------------------------------------------------------------------------------"+"\n"

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

Print File ARQIMP Format("W102","Desconto compra:"+Format("W12.2,EIC",[Valor Desconto])+
                         "   CD: "+[Composicao de Dias]+
                         "   NP: "+StrVal([Numero de Parcelas])+Spaces(03))
Print File ARQIMP "Total.............."+Format("W11.2,EIC",TOT)+"\n"

Print File ARQIMP Format("W99","Cond. Pagto: "+[Descricao CondPagto])+Spaces(03)
Print File ARQIMP "Total Liquido......"+Format("W11.2,EIC",[Valor Mercadoria Liquido])+"\n"

Print File ARQIMP "------------------------------------------------------------------------------------------------------------------------------------"+"\n"

Print File ARQIMP Spaces(18)+"*** NAO TROCAMOS TECIDOS CORTADOS ***           "
Print File ARQIMP "*** CAMA, MESA E BANHO SOMENTE COM EMBALAGEM ***"+"\n"
Print File ARQIMP Spaces(21)+"*** PRAZO DE TROCA 10 DIAS ***                   "
Print File ARQIMP "*** NAO EFETUAMOS TROCAS AOS SABADOS ***"+"\n\n"

EndProc
             
;*******************************************************************************
;* Rotina de Impressao dos Vencimentos                                         *
;*******************************************************************************
Proc VENC()
If KV>0
   Then Print File ARQIMP Spaces(13)
EndIf
For I From 1 to K
  Print File ARQIMP DATA[I]+Spaces(02)
EndFor
Print File ARQIMP "\n"
Print File ARQIMP Spaces(13)
For I From 1 to K
  Print File ARQIMP VALOR[I]+Spaces(02)
EndFor
Print File ARQIMP "\n\n"

KV=KV+1
EndProc

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

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

AGUARDE("Imprimindo Romaneio -> "+NOTAFISC)
IMPFAT()

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

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