;** RO_0361F *******************************************************************
;** Imprime a Digitacao do ROMANEIO sem NOTAC ** IGARATINGA TECIDOS **         *
;*******************************************************************************
;Autor           : Vise Informatica (VISERP)
;Desenvolvido  em: 02/05/2016 por Anivel Augusto Rodrigues
;Ultima Alteracao: 05/05/2016 por Bruno Carvalho
;Motivo Alteracao: ImpressÆo da 2 Vias  ** ImpressÆo na mesma p gina se itens menos que 12
;Ultima Alteracao: 15/06/2016 por Bruno Carvalho 
;Motivo Alteracao: Adicionado Pega_Endereco_Fatura() e ajustado dados do endere‡o
;Ultima Alteracao: 21/07/2016 por Bruno Carvalho 
;Motivo Alteracao: Ajsutado Vencimentos para quando parcelas maior que 6
;Alterado      em: 02/09/2016 por Anivel Augusto Rodrigues
;Motivo Alteracao: Ajuste SOIMPRIMIROF
;Ultima Alteracao: 26/06/2018 por Anivel Augusto Rodrigues                           
;Motivo Alteracao: Ajustes itens mercadoria/servico

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

ContVia=ContVia+1

If Not IsAssigned(NOMEMPRESA)                               ;;; **** N¶O Ô ROMANEIO Sã IMPRESSAO DA OF *******
   Then NOMEMPRESA=""
EndIf

Moveto "FaturaC"
Pega_Endereco_Fatura([Numero da OF])

Print File ARQIMP CI_15CPP
Print File ARQIMP "  ------------------------------------------------------------------------------------------------------------------------------------" + "\n"
Print File ARQIMP Spaces(02)+Format("W40,AL",NOMEMPRESA)+Spaces(15)+"ORDEM DE FATURA"+Spaces(32)+"Impressao: "+Format("D13",Today())+"-"+Time()+ "\n"
Print File ARQIMP "  ------------------------------------------------------------------------------------------------------------------------------------" + "\n"

Print File ARQIMP Spaces(02)+"Cliente: "
Print File ARQIMP Format("W05,AL",[Codigo])
Print File ARQIMP Format("W97,AL",[Razao Social])
Print File ARQIMP "    N§ da OF : "+Format("W06.3,AL",[Numero da OF])+"\n"

Print File ARQIMP Spaces(16)+Format("W40,AL",[Endereco])
Print File ARQIMP Format("W18,AL",[CGC])+Spaces(07)+"Emissao: "
Print File ARQIMP Format("D13",[Data de Emissao])+"\n"

Print File ARQIMP Spaces(16)+Format("W20,AL",[Bairro])
Print File ARQIMP Format("W20,AL",[CEP])
Print File ARQIMP Format("W25,AL",[IE])+"\n"

Print File ARQIMP Spaces(16)+Format("W20,AL",[Cidade])
Print File ARQIMP Format("W20,AL",[UF])
Print File ARQIMP Format("W25,AL",[Telefone])
Print File ARQIMP "Empresa: "+Format("W05,AL",[Codigo da Empresa])+Format("W20,AL",[Nome Fantasia Empresa])+"\n"

Print File ARQIMP Spaces(02)+"Representante: "+Format("W05,AL",[Codigo do Representante])
Print File ARQIMP Format("W25,AL",[Nome Fantasia Represent])+"\n"

;********************* IMPRESSAO DOS ITENS ********************************
Print File ARQIMP Spaces(02)+"Sq  Item                                                Cor/Tecido                "
Print File ARQIMP "Tm  Quantidade Un PrUnitario    PrTotal            "+"\n"
Print File ARQIMP Spaces(02)+"--- --------------------------------------------------- ------------------------- "
Print File ARQIMP "-- ----------- -- ---------- ----------            "+"\n"

EndProc

;*******************************************************************************
;* Rotina de Impressao dos Itens                                               *
;*******************************************************************************
Proc ITENS()

Moveto "FaturaI"

Cont=1
Cont1=1
CONTA_ITENS = 0

Moveto "FaturaI"
Moveto [Numero da OF]
Locate [FaturaC->Numero da OF]
While [Numero da OF]=[FaturaC->Numero da OF]

  CONTA_ITENS = CONTA_ITENS+1
  Skip
  If EOT() Then QuitLoop EndIf
EndWhile

Moveto "FaturaI"
Moveto [Numero da OF]
Locate [FaturaC->Numero da OF]
While [Numero da OF]=[FaturaC->Numero da OF]

   Print File ARQIMP Spaces(01)+Format("W04,AL",[Item da OF])
   Print File ARQIMP Spaces(01)+Format("W11,AL",[Codigo do Item])
   Print File ARQIMP Format("W41,AL",[Descricao do Item])
   Print File ARQIMP Format("W05,AL",[Codigo da Cor_Tecido])
   Print File ARQIMP Format("W21,AL",[Descricao da Cor_Tecido])
   Print File ARQIMP Format("W03,AR",[Tamanho])
   Print File ARQIMP Format("W11.3,EIC",[Quantidade])
   Print File ARQIMP Format("W03,AR",[Unidade Fiscal])
   Print File ARQIMP Format("W11.2,EIC",[Preco Unitario])
   Print File ARQIMP Format("W11.2,EIC",[Preco Total])+"\n"
   If Cont = 12 
      Then TOTAIS()
           VENCIMENTOS()
           RODAPE()
           Cont=0  
           If Cont1 < CONTA_ITENS
              Then IMPFAT()
           EndIf
           Moveto "FaturaI"   
   EndIf        
   Cont=Cont+1
   Cont1=Cont1+1 

  Skip
  If EOT() Then QuitLoop EndIf
EndWhile
If Cont <> 1
   Then TOTAIS()
        VENCIMENTOS()
        RODAPE()
EndIf   

EndProc 

;*******************************************************************************
;* Rotina de Impressao dos Totais                                              *
;*******************************************************************************
Proc TOTAIS()

Moveto "FaturaC"
Print File ARQIMP "\n"
Print File ARQIMP "  Mecadorias   Desconto              Liquido    Total                        "+"\n"
;;9.999.999,99888.88%777.777,776.666.666,6644.444,44111.111,112.222.222,223.333/333,334.444.444,445.555.555,551.111.111,11

Print File ARQIMP  Format("W12.2,EIC",[Valor Mercadoria])+"  "
Print File ARQIMP Format("W06.2,EIC",[Taxa de Desconto])+"%"
Print File ARQIMP Format("W10.2,EIC",[Valor Desconto])
Print File ARQIMP Format("W12.2,EIC",[Valor Mercadoria Liquido])
Print File ARQIMP Format("W012.2,EIC",[Valor Nota Fiscal])+"\n"

Print File ARQIMP Spaces(02)+"Cond. Pagamento.: "+[Descricao CondPagto]
Print File ARQIMP "   NP: "+StrVal([Numero de Parcelas])
Print File ARQIMP "   N.Volumes.: "+LTrim(Format("W06,EIC",[FaturaC->Numero de Volumes]))
Print File ARQIMP "   Peso Liquido: "+LTrim(Format("W11.3,EIC",[FaturaC->Peso Liquido]))
Print File ARQIMP "   Peso Bruto: "+LTrim(Format("W11.3,EIC",[FaturaC->Peso Bruto]))+"\n"

EndProc

;*******************************************************************************
;* Rotina de Impressao dos Vencimentos                                         *
;*******************************************************************************
Proc VENCIMENTOS()

Print File ARQIMP Spaces(02)+"Vencimentos.....: "

Array DATA[8]
Array VALOR[8]
K=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("W11.2,AL,EIC",[Valor])
  If K=6
     Then VENC()
          K=0
  EndIf
  
  Skip
  If EOT() Then QuitLoop EndIf
  If K=0 Then Print File ARQIMP Spaces(20) EndIf
EndWhile
If K>0
   Then VENC()
EndIf
Print File ARQIMP "\n"

EndProc

;*******************************************************************************
;* Rotina de Impressao do Rodape                                               *
;*******************************************************************************
Proc RODAPE()

Moveto "FaturaC"
Print File ARQIMP Spaces(02)+"Obs: "+Format("W100,AL",SubStr([Observacao na Nota Fiscal],001,100))+"\n"

Print File ARQIMP Spaces(02)+"Local p/ Entrega: "+Format("W20,AL",VSD_E_Endereco)
Print File ARQIMP Spaces(02)+Format("W15,AL",VSD_E_Bairro)+Format("W11,AL",VSD_E_CEP)
Print File ARQIMP Spaces(19)+"_______________________________________________"+"\n"
Print File ARQIMP Spaces(20)+Format("W15,AL",VSD_E_Cidade)+Format("W03,AL",VSD_E_UF)
Print File ARQIMP Spaces(60)+"Data/Assinatura Responsavel"+"\n"
Print File ARQIMP "  ------------------------------------------------------------------------------------------------------------------------------------"
Print File ARQIMP CI_10CPP

If ContVia=2
   Then Print File ARQIMP "\f"+"\n"
        ContVia=0
   Else Print File ARQIMP "\n"     
EndIf

EndProc

;*******************************************************************************
;* Rotina de Impressao dos Vencimentos                                         *
;*******************************************************************************
Proc VENC()

;If RecNo()>8
;   Then Print File ARQIMP  Spaces(20)
;EndIf

For I From 1 to K
  Print File ARQIMP Spaces(03)+DATA[I]+Spaces(02)
EndFor
Print File ARQIMP "\n"
Print File ARQIMP Spaces(22)
For I From 1 to K
  Print File ARQIMP Format("W11.2,EIC",VALOR[I])+Spaces(04)
EndFor
Print File ARQIMP "\n"

EndProc

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

ArqImp=PrivDir()+"Ro_0361F.Txt"
If IsFile(ArqImp)
   Then Deleta_Arquivo(ARQIMP)
EndIf
ContVia=0

if SOIMPRIMIROF
   then AGUARDE("Imprimindo OF -> "+[FaturaC->Numero da OF])
   else AGUARDE("Imprimindo Romaneio -> "+NOTAFISC)
endif

For Wc From 1 To 2
  IMPFAT()
  ITENS()
EndFor

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

Release Vars VALOR,DATA
Release Procs IMPFAT,VENC,ITENS,TOTAIS,VENCIMENTOS,RODAPE
