;** PdW0222G *******************************************************************
;** Imprime a Importacao do Pedido Gerencial . VisePedidos Windows   ** Lupus **
;*******************************************************************************
;Autor: Visao/Vise
;Desenvolvido  em: 06/06/2011 por Bruno Carvalho
;Alterado em     : 31/05/2017 por Rafael Matos 
;Motivo Alteracao: Removido Pedido TG e Pedido TF

;*******************************************************************************
;* Rotina para Impressao do Cabecalho titulo                                   *
;*******************************************************************************
Proc Cabecalho_tit()
Npag=npag+1

If Not IsAssigned(NOMEMPRESA)
   Then NOMEMPRESA=""
EndIf

Moveto "Ped_Temp"
Print File ARQIMP ASP1+CI_6LPP+CI_15CPP+ASP2
Print File ARQIMP ASP1+ASP2+"\n"
Print File ARQIMP ASP1+ "------------------------------------------------------------------------------------------------------------------------------------" + ASP2+"\n"
Print File ARQIMP ASP1+ Format("W40,AL",NOMEMPRESA)+Spaces(15)+"Pedido de Venda"+Spaces(21)+"Impressao: "+Format("D13",Today())+"-"+Time()+
                        "  Pag: "+Format("W3,EIC",npag)+ASP2+"\n"
Print File ARQIMP ASP1+ "------------------------------------------------------------------------------------------------------------------------------------" +ASP2+ "\n\n"

Print File ARQIMP ASP1+Spaces(02)+"Cliente: "
Print File ARQIMP Format("W05,AL",[Codigo])
Print File ARQIMP Format("W85,AL",[Razao Social])
Print File ARQIMP "N§ do Pedido : "+CI_INEG+CI_IEXP+Format("W06.3,AL",[Numero do Pedido])+CI_FNEG+CI_FEXP+ASP2+"\n"

nlin=6
EndProc

;*******************************************************************************
;* Rotina para Impressao do Cabecalho do Pedido                                *
;*******************************************************************************
Proc Cabecalho_Ped()

Moveto "Ped_Temp"
Cabecalho_Tit()

Print File ARQIMP ASP1+Spaces(16)+Format("W40,AL",[Endereco])
Print File ARQIMP Format("W18,AL",[CGC])+Spaces(07)+"Emissao: "
Print File ARQIMP Format("D13",[Data de Emissao])+Spaces(4)
Print File ARQIMP "Ped.Origem: "+[Numero Pedido Origem]+ASP2+"\n"

Print File ARQIMP ASP1+Spaces(16)+Format("W20,AL",[Bairro])
Print File ARQIMP Format("W20,AL",[CEP])
Print File ARQIMP Format("W25,AL",[IE])
Print File ARQIMP "Entrega: "+Format("D13",[Data de Entrega])+ASP2+"\n"

Print File ARQIMP ASP1+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])+ASP2+"\n\n"

Print File ARQIMP ASP1+Spaces(02)+"Representante: "+Format("W05,AL",[Codigo do Representante])
Print File ARQIMP Format("W25,AL",[Nome Fantasia Represent])
Print File ARQIMP "Destinacao: "+Format("W04,AL",[Codigo da Destinacao])
Print File ARQIMP Format("W25,AL",[Descricao da Destinacao])
Print File ARQIMP "CFO: "+Format("W09,AL",[CFO])+ASP2+"\n"

Print File ARQIMP ASP1+Spaces(02)+"Transportador: "+Format("W05,AL",[Codigo da Transportadora])
Print File ARQIMP Format("W28,AL",[Nome Fantasia Transport])
Print File ARQIMP "Veiculo: "+Format("W08,AL",[Placa do Veiculo])+"-"+Format("W08,AL",[UF Veiculo])
Print File ARQIMP "Frete por Conta: "+Format("W15,AL",[Frete por Conta])+"    Tabela: "+[Codigo da Tabela]+ASP2+"\n"

Nlin=nlin+6
Cabecalho_Item()
EndProc

;*******************************************************************************
;* Rotina para Impressao do Cabecalho do Item                                  *
;*******************************************************************************
Proc Cabecalho_Item()
Print File ARQIMP ASP1+""+ASP2+"\n"
Print File ARQIMP ASP1+"SeqÝRef   ÝDescricao                     Ý  P Ý  M Ý  G Ý  GGÝ  2 "+
"Ý  4 Ý  6 Ý  8 Ý  10Ý  12Ý  14Ý    Ý TotalÝUNÝ  PrUnitÝ   PrTotal"+ASP2+"\n"
                                  ;999 999.9 123456789012345678901234567890 12345678901234567890 99.999 99.999 99.999 99.999 99.999 XX 9.999,99 999.999,99

Nlin=nlin+2
EndProc

;*******************************************************************************
;* Rotina para Impressao do Relatorio                                          *
;*******************************************************************************
Proc IMPPED()
Cabecalho_Ped()

Moveto "Pedidog"
Moveto [Numero do Pedido]
Locate [Ped_Temp->Numero do Pedido]
QUANT=0
QUANT1=0
QUANT2=0
QUANT3=0
QUANT4=0
QUANT5=0
QUANT6=0
QUANT7=0
QUANT8=0
QUANT9=0
QUANT10=0
QUANT11=0
QUANT12=0
TOT=0
SeqItPed=0
While [Numero do Pedido]=[Ped_Temp->Numero do Pedido]
   SeqItPed=SeqItPed+1
   nlin=nlin+1

   If Nlin>=60
      then
           Print File ARQIMP ASP1+"------------------------------------------------------------------"+
                                  "-----------------------------------------------------------------"+ASP2+"\n"
           Print File ARQIMP ASP1+"*** Continua proxima pagina ==> \f"+ASP2+"\n"
           Cabecalho_Tit()
           Cabecalho_Item()
           Moveto "Pedidog"

   Endif

   Print File ARQIMP ASP1+Format("W03,AR",StrVal([Item do Pedido]))+"Ý"
   Print File ARQIMP Format("W06,AL",[Referencia])+"Ý"
   Print File ARQIMP Format("W30,AL",[Descricao do Item])+"Ý"
   Print File ARQIMP Format("W04,EIC",[Qtd1])+"Ý"
   Print File ARQIMP Format("W04,EIC",[Qtd2])+"Ý"
   Print File ARQIMP Format("W04,EIC",[Qtd3])+"Ý"
   Print File ARQIMP Format("W04,EIC",[Qtd4])+"Ý"
   Print File ARQIMP Format("W04,EIC",[Qtd5])+"Ý"
   Print File ARQIMP Format("W04,EIC",[Qtd6])+"Ý"
   Print File ARQIMP Format("W04,EIC",[Qtd7])+"Ý"
   Print File ARQIMP Format("W04,EIC",[Qtd8])+"Ý"
   Print File ARQIMP Format("W04,EIC",[Qtd9])+"Ý"
   Print File ARQIMP Format("W04,EIC",[Qtd10])+"Ý"
   Print File ARQIMP Format("W04,EIC",[Qtd11])+"Ý"
   Print File ARQIMP Format("W04,EIC",[Qtd12])+"Ý"
   Print File ARQIMP Format("W06,EIC",[Qtd1]+[Qtd2 ]+[Qtd3 ]+[Qtd4 ]+
                                      [Qtd5]+[Qtd6 ]+[Qtd7 ]+[Qtd8 ]+
                                      [Qtd9]+[Qtd10]+[Qtd11]+[Qtd12])+"Ý"
   Print File ARQIMP Format("W02,AL",[Unidade Fiscal])+"Ý"
   Print File ARQIMP Format("W08.2,EIC",[Preco Unitario])+"Ý"
   Print File ARQIMP Format("W10.2,EIC",[Preco Total])+ASP2+"\n"

   QUANT  =QUANT  +[Qtd1]+[Qtd2 ]+[Qtd3 ]+[Qtd4 ]+
                   [Qtd5]+[Qtd6 ]+[Qtd7 ]+[Qtd8 ]+
                   [Qtd9]+[Qtd10]+[Qtd11]+[Qtd12]
   QUANT1   =QUANT1   +[Qtd1 ]
   QUANT2   =QUANT2   +[Qtd2 ]
   QUANT3   =QUANT3   +[Qtd3 ]
   QUANT4   =QUANT4   +[Qtd4 ]
   QUANT5   =QUANT5   +[Qtd5 ]
   QUANT6   =QUANT6   +[Qtd6 ]
   QUANT7   =QUANT7   +[Qtd7 ]
   QUANT8   =QUANT8   +[Qtd8 ]
   QUANT9   =QUANT9   +[Qtd9 ]
   QUANT10  =QUANT10  +[Qtd10]
   QUANT11  =QUANT11  +[Qtd11]
   QUANT12  =QUANT12  +[Qtd12]
   TOT=TOT+[Preco Total]
   Skip
   If EOT() Then QuitLoop EndIf
EndWhile

If QUANT1 =0 Then QUANT1 =BlankNum() EndIf
If QUANT2 =0 Then QUANT2 =BlankNum() EndIf
If QUANT3 =0 Then QUANT3 =BlankNum() EndIf
If QUANT4 =0 Then QUANT4 =BlankNum() EndIf
If QUANT5 =0 Then QUANT5 =BlankNum() EndIf
If QUANT6 =0 Then QUANT6 =BlankNum() EndIf
If QUANT7 =0 Then QUANT7 =BlankNum() EndIf
If QUANT8 =0 Then QUANT8 =BlankNum() EndIf
If QUANT9 =0 Then QUANT9 =BlankNum() EndIf
If QUANT10=0 Then QUANT10=BlankNum() EndIf
If QUANT11=0 Then QUANT11=BlankNum() EndIf
If QUANT12=0 Then QUANT12=BlankNum() EndIf

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

Print File ARQIMP ASP1+Spaces(41)+"Ý"
Print File ARQIMP Format("W04,EIC",QUANT1 )+"Ý"
Print File ARQIMP Format("W04,EIC",QUANT2 )+"Ý"
Print File ARQIMP Format("W04,EIC",QUANT3 )+"Ý"
Print File ARQIMP Format("W04,EIC",QUANT4 )+"Ý"
Print File ARQIMP Format("W04,EIC",QUANT5 )+"Ý"
Print File ARQIMP Format("W04,EIC",QUANT6 )+"Ý"
Print File ARQIMP Format("W04,EIC",QUANT7 )+"Ý"
Print File ARQIMP Format("W04,EIC",QUANT8 )+"Ý"
Print File ARQIMP Format("W04,EIC",QUANT9 )+"Ý"
Print File ARQIMP Format("W04,EIC",QUANT10)+"Ý"
Print File ARQIMP Format("W04,EIC",QUANT11)+"Ý"
Print File ARQIMP Format("W04,EIC",QUANT12)+"Ý"
Print File ARQIMP Format("W06,EIC",QUANT)+"Ý"
Print File ARQIMP Spaces(23)+ASP2+"\n"

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

;********************* IMPRESSAO DOS TOTAIS **************************
Moveto "Ped_Temp"

If Nlin>=45
   then Print File ARQIMP ASP1+"*** Continua proxima pagina ==> \f"+ASP2+"\n"
        Cabecalho_Tit()
        Print File ARQIMP ASP1+""+ASP2+"\n"
Endif

Print File ARQIMP ASP1+CI_6LPP+CI_15CPP+ASP2+"\n"
Print File ARQIMP ASP1+"  Mecadorias         Desconto     Liquido    Frete    Seguro   Desp.Aces         IPI       Total     BC.ICMS        ICMS"+ASP2+"\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 ASP1+ Format("W12.2,EIC",[Valor Mercadoria])
Print File ARQIMP Format("W06.2,EIC",[Taxa de Desconto])+"%"
Print File ARQIMP Format("W10.2,EIC",[Valor do Desconto])
Print File ARQIMP Format("W12.2,EIC",[Valor Mercadoria Liquido])
Print File ARQIMP Format("W09.2,EIC",[Valor do Frete])
Print File ARQIMP Format("W10.2,EIC",[Valor do Seguro])
Print File ARQIMP Format("W012.2,EIC",[Valor Despesas Acessorias])
Print File ARQIMP Format("W012.2,EIC",[Valor IPI])
Print File ARQIMP Format("W012.2,EIC",[Valor Nota Fiscal])
Print File ARQIMP Format("W012.2,EIC",[Valor BCICMS])
Print File ARQIMP Format("W012.2,EIC",[Valor ICMS])+ASP2+"\n\n"

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

;********************* IMPRESSAO DOS VENCIMENTOS **************************
Print File ARQIMP ASP1+Spaces(02)+"Vencimentos.....: " 

Array DATA[9]
Array VALOR[9]
K=0
LISTA=1

If Not IsEmpty("PedidoV")
   Then Moveto "PedidoV"
        Moveto [Numero do Pedido]
        Locate [Ped_Temp->Numero do Pedido]
        While [Numero do Pedido]=[Ped_Temp->Numero do Pedido]
          K=K+1
          DATA[K]  = Format("D13",[Data])
          VALOR[K] = Format("W10.2,AL,EIC",[Valor])
          If K=9
             Then VENC()
                  K=0
          EndIf
          Skip
          If EOT() Then QuitLoop EndIf
        EndWhile
        If K>0
           Then VENC()
        EndIf
EndIf
Print File ARQIMP ASP2+"\n"

;************************* IMPRESSAO DO RODAPE ********************************

Moveto "Ped_Temp"

Print File ARQIMP ASP1+spaces(02)+"Obs. do Pedido..: "+"\027E"+Format("W110,AL",SubStr([Observacao do Pedido],001,110))+"\027F"+ASP2+"\n"
If Substr([Observacao do Pedido],111,110)<>""
   Then Print File ARQIMP ASP1+ Spaces(20)+"\027E"+Format("W110,AL",SubStr([Observacao do Pedido],111,110))+"\027F"+ASP2+"\n"
EndIf

Print File ARQIMP ASP1+Spaces(02)+"Obs. Nota Fiscal: "+"\027E"+Format("W100,AL",SubStr([Observacao na Nota Fiscal],001,100))+"\027F"+ASP2+"\n"

If Substr(DEST_OBS,001,110)<>""
   Then Print File ARQIMP ASP1+Spaces(02)+"Obs. Cadastro...: "+"\027E"+Format("W100,AL",SubStr(DEST_OBS,001,100))+"\027F"+ASP2+"\n\n"
   Else Print File ARQIMP ASP1+""+ASP2+"\n\n" 
EndIf

Print File ARQIMP ASP1+Spaces(02)+"Local p/ Entrega: "+Format("W20,AL",[Endereco de Entrega])+ASP2+"\n"
Print File ARQIMP ASP1+Spaces(20)+Format("W15,AL",[Bairro de Entrega])+Format("W11,AL",[CEP de Entrega])
Print File ARQIMP Spaces(40)+"______________________________________________"+ASP2+"\n"
Print File ARQIMP ASP1+Spaces(20)+Format("W15,AL",[Cidade de Entrega])+Format("W03,AL",[UF de Entrega])
Print File ARQIMP Spaces(60)+"Data/Assinatura Responsavel"+ASP2+"\n\n"
Print File ARQIMP ASP1+"------------------------------------------------------------------------------------------------------------------------------------"
Print File ARQIMP CI_10CPP
Print File ARQIMP "\f"+ASP2+"\n"

Moveto "Ped_Temp"

EndProc

;*******************************************************************************
;* Rotina de Impressao dos Vencimentos                                         *
;*******************************************************************************
Proc VENC()
If LISTA>1
   Then Print File ARQIMP ASP1+Spaces(20)
EndIf
LISTA=LISTA+1
For I From 1 to K
  Print File ARQIMP Spaces(03)+DATA[I]+Spaces(02)
EndFor
Print File ARQIMP ASP2+"\n"
Print File ARQIMP ASP1+Spaces(24)
For I From 1 to K
  Print File ARQIMP Spaces(3)+VALOR[I]+Spaces(02)
EndFor
Print File ARQIMP ASP2+"\n"
EndProc

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

View NoWindow "\\Sistemas\\Estoque\\Itens"
View NoWindow "Pedidog"

ASP1=""
ASP2="" 
DEST_OBS = ""

ArqImp=PrivDir()+"PdW0222G.Txt"
Switch
  Case OK="A":
       ARQIMP = DIREPORT+ARQUIVO+".TXT"
  Case OK="V": ASP1="\""
               ASP2="\""
EndSwitch

If IsFile(ArqImp)
   Then Deleta_Arquivo(ARQIMP)
EndIf

{TableAdd} {PedidoI}
{TableAdd} {PedidoV}

SEQG=1
Do_It!

Seta_FilePrint("PDW0222G")
npag=0

Moveto "Ped_Temp"
Moveto [Numero do Pedido]
Locate PEDIDO
If RetVal
   Then View   "\\Sistemas\\Cadastro\\DestObs"
        Moveto [Codigo]
        Locate [Ped_Temp->Codigo]
        If RetVal
           Then If Not IsBlank([Observacoes])
                   Then DEST_OBS=[Observacoes]    
                EndIf
        EndIf

        Moveto "Ped_Temp"
        IMPPED()
        Sleep 1000
        Imprime_FilePrint("Imprimindo Pedido -> "+PEDIDO,"1")
        Sleep 1000
   Else Return
EndIf 

Do_It!
Moveto "PedidoI" ClearImage

Release Vars VALOR,DATA,nlin,npag
Release Procs IMPPED,VENC,Cabecalho_Ped,Cabecalho_Item,cabecalho_tit,
              Seta_FilePrint, Imprime_FilePrint
