;** OE_0451 ********************************************************************
;** Imprime a Posi‡Ćo Expedi‡Ćo - Quantidade de Itens                     ***  *
;** Modo Subtotal por item                                                ***  *
;*******************************************************************************
;Autor: Visao/Vise
;Desenvolvido  em: 15/03/2020 por Bruno Carvalho  
;Ultima Alteracao: 01/04/2020 por Bruno Carvalho                                                    
;Motivo Alteracao: Ajustes 
;Ultima Alteracao: 07/04/2021 por Bruno Carvalho                                                    
;Motivo Alteracao: Adicionado Observa‡Ćo do Cliente no cabe‡alho 
;Ultima Alteracao: 08/04/2021 por Bruno Carvalho                                                    
;Motivo Alteracao: Adicionado Representante do Cadastro do Cliente no Cabe‡alho  

;Copia do Modelo "OE_0012" 
;ImpressĆo no Expedic2            

;*******************************************************************************
;* Rotina para Impressao do Relatorio                                          *
;*******************************************************************************

Proc IMPPED()
Private NOMEMPRESA, NUMPEDIDO, RAZSOCIAL, SITUACAOOE, DATALIBERA

CODIGO    =[\Sistemas\Vendas\ExpedC->Codigo               ]
NOMEMPRESA=[\Sistemas\Vendas\ExpedC->Nome Fantasia Empresa]
NUMPEDIDO =[\Sistemas\Vendas\ExpedC->Numero do Pedido     ]
RAZSOCIAL =[\Sistemas\Vendas\ExpedC->Razao Social         ]
SITUACAOOE=[\Sistemas\Vendas\ExpedC->Situacao da OE       ]
DATALIBERA=[\Sistemas\Vendas\ExpedC->Data_Liberacao       ]

Moveto "ExpedC"

CODREP   = ""
NOMREP   = ""
CGC      = ""
ENDERECO = ""
BAIRRO   = ""
CIDADE   = ""
UF       = ""
CEP      = ""
OBS      = ""
REP_COD  = ""
REP_NOM  = ""  
GetRecord "\\Sistemas\\Cadastro\\Destinat" CODIGO To REG_BUSCA_LOOKUP
If RetVal
   Then CODREP  =REG_BUSCA_LOOKUP["Codigo do Representante"]
        NOMREP  =REG_BUSCA_LOOKUP["Nome Fantasia Represent"]
        CGC     =REG_BUSCA_LOOKUP["CGC"]
        ENDERECO=REG_BUSCA_LOOKUP["Endereco"]
        BAIRRO  =REG_BUSCA_LOOKUP["Bairro"]
        CIDADE  =REG_BUSCA_LOOKUP["Cidade"]
        UF      =REG_BUSCA_LOOKUP["UF"]
        CEP     =REG_BUSCA_LOOKUP["Cep"]
        REP_COD =REG_BUSCA_LOOKUP["Codigo do Representante"]
        REP_NOM =REG_BUSCA_LOOKUP["Nome Fantasia Represent"]  
EndIf
                   
GetRecord "\\Sistemas\\Cadastro\\DestObs" CODIGO To REG_OBS
If RetVal
   Then OBS = REG_OBS["Observacoes"]
EndIf

REPRESENTANTE=""
If REP_COD<>""
   Then REPRESENTANTE = REP_COD + " " + REP_NOM 
EndIf

If Not IsAssigned(NOMEMPRESA) Then NOMEMPRESA="" EndIf
;************************* IMPRESSAO DOS ITENS *********************************
Cabecalho()        

Moveto "Answer"
Cont=1
ContIt=0
SEQ=0

CONTPED=0
CONTEXP=0
TOTITEM=0
TOTAL=0
AUX=[Numero da OE]

 Scan
   While AUX=[Numero da OE]
    AUX2=[Codigo do Item]
    Cont=Cont+1
    While AUX2=[Codigo do Item]
      
      NLINHA=NLINHA+2
      TOTITEM=TOTITEM+[Quantidade_Expedida]
         Print File ARQIMP ASP1+Spaces(02)+CI_INEG+Format("W10,AL",[Referencia]) 
         Print File ARQIMP Spaces(01)+Format("W11,AL",[Codigo do Item])
         Print File ARQIMP Format("W49,AL",[Descricao do Item])
         Print File ARQIMP Spaces(01)+Format("W05,AL",[Codigo da Cor_Tecido])
         Print File ARQIMP Spaces(01)+Format("W15,AL",[Descricao da Cor_Tecido])
         Print File ARQIMP Format("W03,AL",[Unidade Fiscal])   
         Print File ARQIMP Format("W11.3,EIC",[Quantidade_Expedida])+CI_FNEG+ASP2+"\n"
Print File ARQIMP ASP1+Spaces(02)+"----------------------------------------------------------------------------------------------------------- "+ASP2+"\n" 
         ContIt=ContIt+1
         Cont=Cont+1
         Skip
         If EOT() Then QuitLoop Endif
         
    EndWhile 
    If NLINHA=65
       Then Print File ARQIMP ASP1+"\f"+ ASP2 + "\n"
            Cabecalho()
    EndIf
    If ContIt>1
       Then Print File ARQIMP ASP1+Spaces(98)+"-----------"+ASP2+"\n" 
            Print File ARQIMP ASP1+Spaces(86)+"Subtotal... "+Format("W11.3,EIC",TOTITEM)+ASP2+"\n\n"  
            Cont=Cont+3 
       Else Print File ARQIMP ASP1+""+ ASP2 + "\n"
            Cont=Cont+1
    EndIf
    ContIt=0
    TOTAL=TOTAL+TOTITEM
    TOTITEM=0
    If EOT() Then QuitLoop Endif
   EndWhile
   Total()
 EndScan
Do_it!
ClearAll

EndProc

;*******************************************************************************
;* Rotina para Impressao do Cabe‡alho                                          *
;*******************************************************************************               
Proc Cabecalho()
Moveto "ExpedC"   
Print File ARQIMP ASP1+CI_6LPP+CI_15CPP+ASP2+"\n"
Print File ARQIMP ASP1+ "  --------------------------------------------------------------------------------------------------------------------------------" + ASP2+"\n"
Print File ARQIMP ASP1+ Spaces(02)+Format("W36,AL",NOMEMPRESA)+Spaces(16)+"Ordem de Expedicao"+Spaces(28)+"Impressao: "+Format("D13",Today())+"-"+Time()                                      + ASP2+"\n"
Print File ARQIMP ASP1+ "  --------------------------------------------------------------------------------------------------------------------------------" +ASP2+ "\n"
Print File ARQIMP ASP1+Spaces(02)+"Numero da OE : "+Format("W12,AL",[Numero da OE])+"    Cliente : "+CODIGO+Spaces(02)+Format("W42,AL",RAZSOCIAL)+CGC+ASP2+"\n"                                                                                     
Print File ARQIMP ASP1+Spaces(02)+"Situacao     : "+Format("W12,AL",SITUACAOOE)+"Obs Cliente : "+Format("W66",OBS)+ASP2+"\n"
Print File ARQIMP ASP1+Spaces(02)+"Representante: "+REPRESENTANTE+ASP2+"\n"
Print File ARQIMP ASP1+Spaces(02)+"Dt Liberacao : "+Format("D13",DATALIBERA)+ASP2+"\n"
Print File ARQIMP ASP1+Spaces(02)+"Obs Expedicao: "+Format("W100,AL",[Observacao])+ASP2+"\n"
Print File ARQIMP ASP1+"  --------------------------------------------------------------------------------------------------------------------------------"+ASP2+ "\n"
Print File ARQIMP ASP1+Spaces(02)+"Ref.:      Item                                                        Cor                   UN  Quantidade "+ASP2+"\n"
Print File ARQIMP ASP1+Spaces(02)+"---------------------------------------------------------------------- --------------------- --- ---------- "+ASP2+"\n" 
NLINHA=12
Moveto "Answer"
EndProc

;*******************************************************************************
;* Rotina para Impressao do Rodap‚                                          *
;*******************************************************************************
Proc Total()

Print File ARQIMP ASP1+"  --------------------------------------------------------------------------------------------------------------------------------"+ASP2+"\n" 
Print File ARQIMP ASP1+ Spaces(89)+"Total... "+Format("W11.3,EIC",TOTAL)+ASP2+"\n\n"
Print File ARQIMP ASP1+ 
           Spaces(04)+"Autorizado: ________________________________________________________________________________       Data: ___/___/___"+ASP2+"\n\n"
Print File ARQIMP ASP1+ 
           Spaces(04)+"Separacao: _________________________________________________________________________________       Data: ___/___/___"+ASP2+"\n\n"
Print File ARQIMP ASP1+ 
           Spaces(04)+"Corte: _____________________________________________________________________________________       Data: ___/___/___"+ASP2+"\n\n"
Print File ARQIMP ASP1+ 
           Spaces(04)+"Embalagem: _________________________________________________________________________________       Data: ___/___/___"+ASP2+"\n\n"
Print File ARQIMP ASP1+ 
           Spaces(04)+"           ____  ______________ Corte(s)           _________________ Volume(s)                     Peso: ________ Kg"+ASP2+"\n\n"                      
                     
EndProc  ;Total()

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

Seta_FilePrint("OE_0001")

NUMOE=[ExpedC->Numero da OE]

{Ask} {ExpedIQ} Check
Moveto [Numero da OE] TypeIn "~NUMOE"
Do_it!

Sort "Answer" On "Numero da OE","Codigo do Item","Sequencia"  
Moveto "Answer"  ClearImage
Moveto "ExpedIQ" ClearImage

View NoWindow "Answer"

Moveto "ExpedC"
CoeditKey

TabelaRef="\\Sistemas\\Vendas\\ExpedIQ"


IMPPED()
Imprime_FilePrint("Imprimindo Posi‡Ćo Expedi‡Ćo -> "+"OE_0001", "R")

Release Vars VALOR,DATA, NOMEMPRESA, NUMPEDIDO, RAZSOCIAL, SITUACAOOE, DATALIBERA,
             CODREP, NOMREP, CODTRA, CODIGO, ENDERECO, BAIRRO, 
             CIDADE, UF, CEP, TabelaRef

Release Procs IMPPED, Cabecalho, Total
