;** OC_0117   *******************************************************************
;** Imprime relacao de carregamento                        ** CAzevedo **      *
;*******************************************************************************
;Autor           : Vise Informatica (VISERP)
;Desenvolvido  em: 06/01/2004 por Anivel Augusto Rodrigues
;Alterado em     : 11/02/2004 por Anivel Augusto Rodrigues
;Motivo Alteracao: Ajustes
;Alterado em     : 20/06/2006 por Antonio Marcelo Alves
;Motivo Alteracao: Inclusao ImpriArq()
;Alterado em     : 28/03/2007 por Anivel Augusto Rodrigues
;Motivo Alteracao: Ajustes
;Ultima Alteracao: 14/08/2007 por Antonio Marcelo Alves
;Motivo Alteracao: Ajustes Deleta_Arquivo

;*******************************************************************************
;* Rotina p/ Impressao                                                         *
;*******************************************************************************
Proc Imprimir()
AGUARDE("Aguarde, processando dados")

Print File ARQIMP ASP1+CI_10CPP+CI_8LPP+ASP2+"\n"
If Not IsAssigned(NOMEMPRESA) Then NOMEMPRESA="TESTE" EndIf

View "FaturaC"
View "Answer"

NOF="***"

pag=0
c=0
wc=0
NITENS=0
PESO =0
Scan
  If [Numero da OF]<>NOF
     Then If pag>0
             Then Rodape()
          EndIf

          NOF=[Numero da OF]

          Moveto "FaturaC"
          Moveto [Numero da OF]
          Locate [Answer->Numero da OF]
          If RetVal
             Then CODREPR=[Codigo do Representante]
                  NOMREPR=[Nome Fantasia Represent]
                  NPED   =[Numero do Pedido       ]
             Else CODREPR=""
                  NOMREPR=""
                  NPED   =""
          EndIf
          Moveto "Answer"

          Cabecalho()
          wc=1
  EndIf

  Detalhe()
  NITENS=NITENS+1
  PESO =PESO +(([Peso Liquido]+[Peso Embalagem])*[Quantidade])
EndScan
NOF="***"
Rodape()
Print File ARQIMP ASP1+CI_10CPP+ASP2+"\n"
Print File ARQIMP ASP1+CI_6LPP+ASP2+"\n"
ClearAll
EndProc   ;  (Imprimir)

;*******************************************************************************
;* Rotina p/ Cabecalho                                                         *
;*******************************************************************************
Proc ChecaLinhaPagina()
If C>=80
   Then Rodape()
        Cabecalho()
EndIf
EndProc

;*******************************************************************************
;* Rotina p/ Cabecalho                                                         *
;*******************************************************************************
Proc Cabecalho()
While True
  pag=pag+1

  If OPCAOPAG<>"Todas"
     Then If pag<OPCAOPAGINI Or
             pag>OPCAOPAGFIM
             Then QuitLoop
          EndIf
  EndIf

  Print File ARQIMP ASP1+Fill("-",80)+ASP2+"\n"

  Print File ARQIMP ASP1+COMPLETA(NOMEMPRESA,41," ")+"Emissao.: "+
             AlinhM(LTrim(Format("D13",Today())),10)+"-"+
             AlinhM(SubStr(Time(),1,5),5)+"  Pag.:"+Format("W4,EIC",pag)+ASP2+"\n"

  Print File ARQIMP ASP1+Fill("-",80)+ASP2+"\n"

  Print File ARQIMP ASP1+CI_INEG+ASP2+"\n"

  Print File ARQIMP ASP1+Spaces(02)+"        Responsavel: "
  Print File ARQIMP Format("W05,AL",CODREPR)
  Print File ARQIMP Format("W25,AL",NOMREPR)
  Print File ARQIMP Spaces(06)+"N. NF ["+[Numero da OF]+"]"
  Print File ARQIMP ASP2+"\n"

  Print File ARQIMP ASP1+Spaces(02)+"Carregamento Pedido: "+NPED
  Print File ARQIMP ASP2+"\n"

  Print File ARQIMP ASP1+CI_FNEG+ASP2+"\n"

  Print File ARQIMP ASP1+"Sq  Item   Descricao                          Qtde Un  V1 Retorno  V2 Obs       "+ASP2+"\n"
  Print File ARQIMP ASP1+"---.------.------------------------------.--------.--.---.-------.---.----------"+ASP2+"\n"

  QuitLoop
EndWhile
C=9

EndProc   ; (Cabecalho)

;*******************************************************************************
;* Rotina p/ Detalhe                                                           *
;*******************************************************************************
Proc Detalhe()
ChecaLinhaPagina()

C=C+2
If Len([Descricao do Item])>30
   Then C=C+1
EndIf
While True
  If OPCAOPAG<>"Todas"
     Then If pag<OPCAOPAGINI Or
             pag>OPCAOPAGFIM
             Then QuitLoop
          EndIf
  EndIf

  Print File ARQIMP ASP1+Format("W03,AR",StrVal([Item da OF]))
  Print File ARQIMP "|"+Format("W06,AR",StrVal(NumVal([Codigo do Item])))
  Print File ARQIMP "|"+Format("W30,AL",[Descricao do Item])

  If [Quantidade]-Int([Quantidade])>0
     Then Print File ARQIMP "|"+Format("W8.1,EIC",[Quantidade])
     Else Print File ARQIMP "|"+Format("W6,EIC",[Quantidade])+Spaces(2)
  EndIf
  Print File ARQIMP "|"+Format("W02,AR",[Unidade Fiscal])
  Print File ARQIMP "|   |       |   |"
  Print File ARQIMP ASP2+"\n"

  If Len([Descricao do Item])>30
     Then Print File ARQIMP ASP1+"  |      |"+
          Completa(SubStr([Descricao do Item],31,30),30," ")+
          "|        |  |   |       |   |"+ASP2+"\n"
  EndIf

  Print File ARQIMP ASP1+"---.- - --.- - - - - - - - - - - - - - --.- - - --.--.- -.- - - -.- -.- - - - - "+ASP2+"\n"

  QuitLoop
EndWhile
EndProc    ;  (Detalhe)

;*******************************************************************************
;* Rotina p/ Total/Rodape                                                      *
;*******************************************************************************
Proc Rodape()
If OPCAOPAG<>"Todas"
   Then If pag<OPCAOPAGINI Or
           pag>OPCAOPAGFIM
           Then Return
        EndIf
EndIf

While C<80
  Print File ARQIMP ASP1+"   |      |                              |        |  |   |       |   |"+ASP2+"\n"
  Print File ARQIMP ASP1+"---.- - --.- - - - - - - - - - - - - - --.- - - --.--.- -.- - - -.- -.- - - - - "+ASP2+"\n"
  c=c+2
EndWhile

If [Numero da OF]=NOF
   Then Print File ARQIMP ASP1+Spaces(67)+"Continua =>  "+ASP2+"\n"
   Else Print File ARQIMP ASP1+"--------------------------------------------------------------------------------"+ASP2+"\n"
        Print File ARQIMP ASP1+"              Peso Estimado: "+Format("W09.1,EIC",PESO)
        Print File ARQIMP Spaces(10)+Format("W09,EIC",NITENS)+" Itens "+ASP2+"\n"
EndIf
Print File ARQIMP ASP1+"\f"+ASP2+"\n"

EndProc    ;  (Total)


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

ASP1=""
ASP2=""
ARQIMP = DIREPORT+"OC_0117.TXT"
Switch
  Case OK="A": ARQIMP = DIREPORT+ARQUIVO+".TXT"
  Case OK="V": ASP1="\""
               ASP2="\""
EndSwitch
If IsFile(ARQIMP) 
   Then Deleta_Arquivo(ARQIMP) 
EndIf

AGUARDE("Imprimindo")
Imprimir()
If OK="V"
   Then If IsTable("Answer") Then Delete "Answer" EndIf
        {Tools} {Copy} {Table} {\\Base\\Sistemas\\Estoque\\Rm_tx160} {Answer} ClearAll
        {Tools} {ExportImport} {Import} {ASCII} {AppendDelimited} TypeIn ARQIMP Enter
        {Answer} ClearAll
        OPCAOPAG="Todas"
        IMPRIREL("Answer","R")
        Deleta_Arquivo(ARQIMP)
   Else Mensagem("Impress„o Concluida !")
        If OK="I"
           Then ;---- Imprime Arquivo Impressao ------------------------------------------------
                ImpriArq(ARQIMP)
        EndIf
EndIf

Release Procs Imprimir, Cabecalho, Detalhe, Rodape


