;** EC_0223 *********************************************************************
;** Impressao de Carnˆ         ** Fatima Designs **
;*******************************************************************************
;Autor           : Vise Informatica (VISERP)
;Desenvolvido  em: 05/03/2009 por Anivel Augusto Rodrigues
;Alterado em     : 02/04/2009 por Anivel Augusto Rodrigues
;Motivo Alteracao: Ajustes salto de linhas
;Alterado em     : 13/09/2011 por Bruno Carvalho
;Motivo Alteracao: Altera‡Æo para um modelo em folha A4 "EC_0223A" (Imagem de Fundo)
;Ultima Alteracao: 01/12/2011 por Bruno Carvalho
;Motivo Alteracao: Alterado o caminho da Imagem_Fundo

;*******************************************************************************
Proc Imp_Carne()

Array dtv[36]
Array vrv[36]

For I From 1 To 12
  vrv[i]=BlankNum()
  dtv[i]=""
EndFor

i=0
Moveto "FaturaV"                                   
Moveto [Numero da OF]
Locate [FaturaC->Numero da OF]
If RetVal
   Then While [Numero da OF] = [FaturaC->Numero da OF]    
          i=i+1
          vrv[i]=[Valor]                                             
          dtv[i]=[Data]

          Skip
          If EOT()
             Then QuitLoop
          Endif
        EndWhile
EndIf

If i=0
   Then Mensagem("NÆo existe(m) venctimento(s) p/ o carnˆ !")
        Return
EndIf

Moveto "FaturaC"

NPOk=False
cci=0
For wi From 1 to i

  If cci=3
     Then Imp_NP()
          NPOk=True
          cci=0
  EndIf
  cci=cci+1

  Print File ARQIMP CI_10CPP+CI_6LPP+"\n\n"

  Print File ARQIMP Spaces(9)+Format("W7,AL",[Codigo])+Spaces(2)+Completa(NOTAFISC+" "+StrVal(wi)+"/"+StrVal(i),10," ")+Spaces(4)+Format("W36,AL",[Razao Social])+"\n\n\n"

  Print File ARQIMP  Spaces(7)+Format("D10",dtv[wi])+Spaces(3)+Format("W10.2,EIC",Vrv[wi])+Spaces(7)+
        Format("W09,AL",[Codigo])+Spaces(3)+Completa(NOTAFISC+" "+StrVal(wi)+"/"+StrVal(i),11," ")+Spaces(4)+Format("D10",dtv[wi])+"\n\n\n"

  Print File ARQIMP Spaces(62)+Format("W10.2,EIC",Vrv[wi])

  Print File ARQIMP CI_10CPP+CI_8LPP+"\n"

  Print File ARQIMP CI_10CPP+CI_6LPP+"\n\n\n\n\n\n\n"
  
EndFor

Switch
  Case cci=1 : IMPR=2 
  Case cci=2 : IMPR=1 
EndSwitch

If cci=1 Or cci=2
   Then For Woo From 1 To IMPR
           Print File ARQIMP CI_10CPP+CI_8LPP+"\n"
           Print File ARQIMP CI_10CPP+CI_6LPP+"\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n"
        EndFor
        Imp_NP()
   Else If cci=3
           Then Imp_NP()                                     
        EndIf    
EndIf
UnlockRecord

EndProc

;*******************************************************************************
Proc Imp_NP()
;If cci<3
;   Then For nbi From (cci+1) To 3
;          Print File ARQIMP CI_10CPP+CI_8LPP+"\n"
;          Print File ARQIMP CI_10CPP+CI_6LPP+"\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n"
;        EndFor
;        If NPOK
;           Then Print File ARQIMP "\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n"
;                Return
;        EndIf
;EndIf

Print File ARQIMP "\n\n"
Print File ARQIMP Spaces(14)+Format("D13",[Data de Emissao])+Spaces(01)+Format("W12.2,EIC",[Valor Nota Fiscal])+Spaces(5)+
                  Format("W20,AL",[Codigo do Representante])+Spaces(4)+Format("W8,AL",[Codigo])+"\n"

Print File ARQIMP CI_15CPP+"\n"+Spaces(67)+"FATIMA DESIGNS CORTINAS CONF. IND. E COM. LTDA"+"\n"

Print File ARQIMP Spaces(24)+"65.202.863/0001-97"+CI_10CPP+"\n"

ESCEXT([Valor Nota Fiscal])
Print File ARQIMP Spaces(14)+SubStr(EXTENSO,001,55)+"\n"
Print File ARQIMP Spaces(15)+SubStr(EXTENSO,056,54)+"\n\n"

Print File ARQIMP Spaces(44)+Format("W28,AL",[Razao Social])+"\n"

Print File ARQIMP Spaces(14)+Completa(Format("D10",dtv[1]),9," ")+Completa(Format("W10.2,EIC",Vrv[1]),14," ")+"\n"
Print File ARQIMP Spaces(14)+Completa(Format("D10",dtv[2]),9," ")+Completa(Format("W10.2,EIC",Vrv[2]),14," ")+Spaces(7)+[CGC]+"\n"
Print File ARQIMP Spaces(14)+Completa(Format("D10",dtv[3]),9," ")+Completa(Format("W10.2,EIC",Vrv[3]),14," ")+"\n"
Print File ARQIMP Spaces(14)+Completa(Format("D10",dtv[4]),9," ")+Completa(Format("W10.2,EIC",Vrv[4]),14," ")+Spaces(14)+Format("D13",[Data de Emissao])+"\n"
Print File ARQIMP Spaces(14)+Completa(Format("D10",dtv[5]),9," ")+Completa(Format("W10.2,EIC",Vrv[5]),14," ")+"\n\n"

Print File ARQIMP Spaces(18)+Completa([Endereco],40," ")+SubStr([Telefone],1,10)+"\n"
Print File ARQIMP Spaces(18)+[Bairro]+"\n"

Print File ARQIMP CI_10CPP+CI_6LPP+"\n"

Endproc

;*******************************************************************************
;* Copia Imagem para Raiz                                                      *
;*******************************************************************************
Proc Copia_Imagem()
Private VSDGDRIVE,VSDGPASTA

VSDGDRIVE=SubStr(Directory(),1,2)
VSDGPASTA="\\Sistemas\\IMAGENS\\IMG_FUN\\"
IMAGEM_FUNDO="ec_"+SYS_CODIGO_CLIENTE

If IsFile(VSDGDRIVE+VSDGPASTA+IMAGEM_FUNDO+".JPG")
   Then Copia_Arquivo(VSDGDRIVE+VSDGPASTA+IMAGEM_FUNDO+".JPG c:\\vise\\"+IMAGEM_FUNDO+".JPG")
EndIf    

EndProc ;Copia_Imagem()

;*******************************************************************************
;* Rotina Principal                                                            *
;*******************************************************************************
Moveto "FaturaC"
AGUARDE("Imprimindo Carne "+NOTAFISC)

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

Copia_Imagem()
Imp_Carne()
ImpriArq(ARQIMP)

LIMPAGUARDE()

ClearAll
Release Vars IMAGEM_FUNDO