;** Pd_0079G *******************************************************************
;** Imprime a Digitacao do Pedido/Grade c/preco     **Isabela Garcia**         *
;*******************************************************************************
;Autor: Visao/Vise
;Desenvolvido  em: 29/01/2010 por Bruno Carvalho
;Alterado em     : 29/01/2010 por Bruno Carvalho
;Motivo Alteracao: Adapta‡Æo do Relat¢rio PD_0227G
;Alterado em     : 02/02/2010 por Cleber Alves
;Motivo Alteracao: Ajustes
;Alterado em     : 12/02/2010 por Anivel Augusto Rodrigues
;Motivo Alteracao: Ajustes
;Alterado em     : 18/02/2010 por Cleber Alves
;Motivo Alteracao: Ajustes
;Alterado em     : 23/02/2010 por Cleber Alves
;Motivo Alteracao: Ajustes
;Alterado em     : 27/12/2010 por Bruno Carvalho
;Motivo Alteracao: Ajustes Frete por Conta
;Alterado em     : 27/03/2015 por Bruno Carvalho
;Motivo Alteracao: Adicionado OtherWise para FRETECONTA
;Alterado em     : 31/05/2017 por Rafael Matos
;Motivo Alteracao: Removido Pedido TG e Pedido TF
;Alterado em     : 28/12/2017 por Anivel Augusto Rodrigues
;Motivo Alteracao: Ajustes quebra por familia

;*******************************************************************************
;* Imprime Observacoes do Pedido                                               *
;*******************************************************************************
Proc Imprime_Observacoes()
Private obs,tit_obs,wi,wc,tamobs,nlobs,posobs,tit_obs

tamobs=112
For wc From 1 To 2
	Switch
    Case wc=1 : obs    =[PedidoC->Observacao do Pedido     ]
                tit_obs="Obs. do Pedido..: "
    Case wc=2 : obs    =[PedidoC->Observacao na Nota Fiscal]
                tit_obs="Obs. Nota Fiscal: "
	EndSwitch

  nlobs=Len(obs)/tamobs
	If nlobs-Int(nlobs)>0
		 Then nlobs=Int(nlobs)+1
		 Else nlobs=Int(nlobs)
	EndIf
	If nlobs=0 Then nlobs=1 EndIf

	posobs=1
	For i from 1 to nlobs
		Checa_Linha(1,"")
    Print File ARQIMP ASP1+tit_obs+SubStr(obs,posobs,tamobs)+ASP2+"\n"

    tit_obs=Spaces(18)
    posobs =posobs+tamobs
	EndFor
EndFor

Release Vars obs,tit_obs,wi,wc,tamobs,nlobs,posobs,tit_obs
EndProc

;*******************************************************************************
;* Verifica as Grades no Pedido                                                *
;*******************************************************************************
Proc Verifica_Grades()
Private wc,gok

DynArray Array_Grade[]

Moveto "pedidog"
Moveto [Numero do Pedido]
Locate [Pedidoc->Numero do Pedido]
While [Numero do Pedido]=[Pedidoc->Numero do Pedido]
  gok=False
  For wc From 1 to DynArraySize(Array_Grade)
    If Array_Grade[wc]=[Codigo da Grade]
       Then gok =True
    EndIf
  EndFor
  If Not gok
     Then Array_Grade[DynArraySize(Array_Grade)+1]=Completa([Codigo da Grade],1," ")
  EndIf

  Skip
  If EOT() Then QuitLoop EndIf
EndWhile

Array array_tittm[12]
Moveto "\\Sistemas\\Estoque\\TpGrade"
Moveto [Codigo da Grade]
For wc From 1 to DynArraySize(Array_Grade)
  Locate SubStr(Array_Grade[wc],1,1)
  If RetVal
     Then array_tittm[1] =[Titulo Grade1 ]
          array_tittm[2] =[Titulo Grade2 ]
          array_tittm[3] =[Titulo Grade3 ]
          array_tittm[4] =[Titulo Grade4 ]
          array_tittm[5] =[Titulo Grade5 ]
          array_tittm[6] =[Titulo Grade6 ]
          array_tittm[7] =[Titulo Grade7 ]
          array_tittm[8] =[Titulo Grade8 ]
          array_tittm[9] =[Titulo Grade9 ]
          array_tittm[10]=[Titulo Grade10]
          array_tittm[11]=[Titulo Grade11]
          array_tittm[12]=[Titulo Grade12]
     Else For i From 1 to 12
            array_tittm[i]=""
          EndFor
  EndIf

  Array_Grade[wc]=Array_Grade[wc]+" "+
                  Format("W4,AR",array_tittm[01])+" "+
                  Format("W4,AR",array_tittm[02])+" "+
                  Format("W4,AR",array_tittm[03])+" "+
                  Format("W4,AR",array_tittm[04])+" "+
                  Format("W4,AR",array_tittm[05])+" "+
                  Format("W4,AR",array_tittm[06])+" "+
                  Format("W4,AR",array_tittm[07])+" "+
                  Format("W4,AR",array_tittm[08])+" "+
                  Format("W4,AR",array_tittm[09])+" "+
                  Format("W4,AR",array_tittm[10])+" "+
                  Format("W4,AR",array_tittm[11])+" "+
                  Format("W4,AR",array_tittm[12])+" "
EndFor
Moveto "pedidog"

Release Vars wc,wi,gok,array_tittm
EndProc

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

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

Moveto "PedidoC"
Print File ARQIMP ASP1+CI_6LPP+CI_15CPP+ASP2+"\n"
Print File ARQIMP ASP1+Fill("-",132)+ASP2+"\n"
Print File ARQIMP ASP1+ Completa(NOMEMPRESA,55," ")+"Pedido de Venda"+Spaces(22)+"Impressao: "+Format("D13",Today())+"-"+Time()+
                        "  Pag: "+Format("W3,EIC",npag)+ASP2+"\n"
Print File ARQIMP ASP1+Fill("-",132)+ASP2+"\n"

Print File ARQIMP ASP1+Spaces(99)+"N§ do Pedido : "+CI_INEG+CI_IEXP+Format("W06.3,AL",[Numero do Pedido])+CI_FNEG+CI_FEXP+ASP2+"\n\n"

nlin=6
EndProc

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

Moveto "PedidoC"
Cabecalho_Tit()

Print File ARQIMP ASP1+"Cliente: "
Print File ARQIMP Format("W05,AL",[Codigo])
Print File ARQIMP Format("W88,AL",[Razao Social])
Print File ARQIMP "Ped.Origem: "+[Numero Pedido Origem]+ASP2+"\n"

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

Print File ARQIMP ASP1+Spaces(14)+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(14)+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+"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])+"      Tabela: "+[Codigo da Tabela]+ASP2+"\n"

Switch
  Case [Frete por Conta]="1" : FRETECONTA="EMITENTE"
  Case [Frete por Conta]="2" : FRETECONTA="DESTINATARIO"
  Case [Frete por Conta]="3" : FRETECONTA="TERCEIROS"
  OtherWise                  : FRETECONTA="SEM FRETE" 
EndSwitch

Print File ARQIMP ASP1+"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: "+[Frete por Conta]+" "+FRETECONTA+ASP2+"\n\n"

nlin=nlin+8

Cabecalho_Item()
EndProc

;*******************************************************************************
;* Rotina para Impressao do Cabecalho do Item                                  *
;*******************************************************************************
Proc Cabecalho_Item()
Private wc,linha

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

Moveto PrivDir()+"pedidoog"
For wc From 1 to DynArraySize(Array_Grade)
  If wc=DynArraySize(Array_Grade)
     Then linha=" Seq Ref    Descricao                   "+Array_Grade[wc]+" Total UN                    "
     Else linha="                                        "+Array_Grade[wc]+"                             "
  EndIf
  Print File ARQIMP ASP1+linha+ASP2+"\n"
  nlin=nlin+1
EndFor

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

nlin=nlin+2
EndProc

;*******************************************************************************
;* Rodape para Itens                                                           *
;*******************************************************************************
Proc Rodape(tp)
Private tp
If tp="Item"
   Then Print File ARQIMP ASP1+ " ----------------------------------------------------------------------------------------------------------------------------------"+ASP2+"\n"
Endif
Print File ARQIMP ASP1+ASP2+"\n"
;Print File ARQIMP ASP1+Format("W132,AR","*** Continua proxima pagina ==> ")+"\f"+ASP2+"\n"
Print File ARQIMP ASP1+Spaces(90)+"*** Continua proxima pagina ==> \f"+ASP2+"\n"
EndProc

;*******************************************************************************
;* Familia                                                                     *
;*******************************************************************************
Proc GrupoFamilia()

Checa_Linha(1,"Item")
Print File ARQIMP ASP1+"     Familia: "+[Codigo da Familia]+" - "+[Descricao da Familia]+ASP2+"\n"

EndProc

;*******************************************************************************
;* totaliza Familia                                                            *
;*******************************************************************************
Proc TotalizaGrupoFamilia()
private wi

if familiacont<=1
   then Checa_Linha(1,"Item")
        Print File ARQIMP ASP1+ASP2+"\n"     
        return
endif   

For wi From 1 to 12
  If array_fqtd[wi]=0 then array_fqtd[wi]=BlankNum() EndIf
  array_fqtd[13]=array_fqtd[13]+array_fqtd[wi]
EndFor


Checa_Linha(4,"Item")
Print File ARQIMP ASP1+" ---------------------------------------- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ------ -- -------- ----------"+ASP2+"\n"
Print File ARQIMP ASP1+Completa("     SubTotal=>",42," ")
Print File ARQIMP Format("W04,EIC",array_fqtd[01])+" "
Print File ARQIMP Format("W04,EIC",array_fqtd[02])+" "
Print File ARQIMP Format("W04,EIC",array_fqtd[03])+" "
Print File ARQIMP Format("W04,EIC",array_fqtd[04])+" "
Print File ARQIMP Format("W04,EIC",array_fqtd[05])+" "
Print File ARQIMP Format("W04,EIC",array_fqtd[06])+" "
Print File ARQIMP Format("W04,EIC",array_fqtd[07])+" "
Print File ARQIMP Format("W04,EIC",array_fqtd[08])+" "
Print File ARQIMP Format("W04,EIC",array_fqtd[09])+" "
Print File ARQIMP Format("W04,EIC",array_fqtd[10])+" "
Print File ARQIMP Format("W04,EIC",array_fqtd[11])+" "
Print File ARQIMP Format("W04,EIC",array_fqtd[12])+" "
Print File ARQIMP Format("W06,EIC",array_fqtd[13])+" "+ASP2+"\n\n"

EndProc

;*******************************************************************************
;* Familia                                                                     *
;*******************************************************************************
Proc ZeraGrupoFamilia()
private wi

Array array_fqtd[14]  ;** controla total   13=total pecas  14=total valor **
For wi From 1 to 14
 array_fqtd[wi]=0
EndFor
  
familiaant =[Codigo da Familia]
familiacont=0
GrupoFamilia() 

EndProc

;*******************************************************************************
;* Checa linha na area de impressao dos itens                                  *
;*******************************************************************************
Proc Checa_Linha(nl,tp)
private nl,tp

If (nlin+nl)>=62
   Then Rodape(tp)
        Cabecalho_Tit()
        If tp="Item"
           Then Cabecalho_Item()
                GrupoFamilia()
        EndIf
EndIf
nlin=nlin+nl
EndProc


;*******************************************************************************
;* Rotina para Impressao do Relatorio                                          *
;*******************************************************************************
Proc ImpPed()
private familiaant, familiacont

npag=0
nlin=0
SeqItPed=0

Array array_tqtd[14]  ;** controla total   13=total pecas  14=total valor **
For wi From 1 to 14
  array_tqtd[wi]=0
EndFor

Verifica_Grades()
Cabecalho_Ped()

familiaant ="****"
familiacont=0

Moveto PrivDir()+"pedidoog"
Moveto [Numero do Pedido]
Locate [Pedidoc->Numero do Pedido]
While [Numero do Pedido]=[Pedidoc->Numero do Pedido]

   if [Codigo da Familia]<>familiaant
      then if familiaant<>"****"
              then TotalizaGrupoFamilia()
           endif
           ZeraGrupoFamilia()
   endif     
   familiacont=familiacont+1

   Checa_Linha(1,"Item")

   SeqItPed=SeqItPed+1

   Print File ARQIMP ASP1+Format("W04,AR",StrVal(SeqItPed))+" "
   Print File ARQIMP Format("W06,AL",[Referencia])+" "
   Print File ARQIMP Format("W27,AL",[Descricao do Item])+" "
   Print File ARQIMP Format("W01,AL",[Codigo da Grade])+" "
   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])+" "+ASP2+"\n"

   ;-- total itens ----------------------------
   array_tqtd[01]=array_tqtd[01]+[Qtd1 ]
   array_tqtd[02]=array_tqtd[02]+[Qtd2 ]
   array_tqtd[03]=array_tqtd[03]+[Qtd3 ]
   array_tqtd[04]=array_tqtd[04]+[Qtd4 ]
   array_tqtd[05]=array_tqtd[05]+[Qtd5 ]
   array_tqtd[06]=array_tqtd[06]+[Qtd6 ]
   array_tqtd[07]=array_tqtd[07]+[Qtd7 ]
   array_tqtd[08]=array_tqtd[08]+[Qtd8 ]
   array_tqtd[09]=array_tqtd[09]+[Qtd9 ]
   array_tqtd[10]=array_tqtd[10]+[Qtd10]
   array_tqtd[11]=array_tqtd[11]+[Qtd11]
   array_tqtd[12]=array_tqtd[12]+[Qtd12]
   array_tqtd[14]=array_tqtd[14]+[Preco Total]
   
   
   ;-- total grupo familia --------------------
   array_fqtd[01]=array_fqtd[01]+[Qtd1 ]
   array_fqtd[02]=array_fqtd[02]+[Qtd2 ]
   array_fqtd[03]=array_fqtd[03]+[Qtd3 ]
   array_fqtd[04]=array_fqtd[04]+[Qtd4 ]
   array_fqtd[05]=array_fqtd[05]+[Qtd5 ]
   array_fqtd[06]=array_fqtd[06]+[Qtd6 ]
   array_fqtd[07]=array_fqtd[07]+[Qtd7 ]
   array_fqtd[08]=array_fqtd[08]+[Qtd8 ]
   array_fqtd[09]=array_fqtd[09]+[Qtd9 ]
   array_fqtd[10]=array_fqtd[10]+[Qtd10]
   array_fqtd[11]=array_fqtd[11]+[Qtd11]
   array_fqtd[12]=array_fqtd[12]+[Qtd12]
   array_fqtd[14]=array_fqtd[14]+[Preco Total]
   

   Skip
   If EOT() Then QuitLoop EndIf
EndWhile
TotalizaGrupoFamilia()

;************** IMPRESSAO DOS TOTAIS DAS GRADES DO PEDIDO ****************
For wi From 1 to 12
  If array_tqtd[wi]=0 then array_tqtd[wi]=BlankNum() EndIf
  array_tqtd[13]=array_tqtd[13]+array_tqtd[wi]
EndFor

Checa_Linha(4,"")
Print File ARQIMP ASP1+" ---------------------------------------- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ------ -- -------- ----------"+ASP2+"\n"

Print File ARQIMP ASP1+Completa("     Total=>",42," ")
Print File ARQIMP Format("W04,EIC",array_tqtd[01])+" "
Print File ARQIMP Format("W04,EIC",array_tqtd[02])+" "
Print File ARQIMP Format("W04,EIC",array_tqtd[03])+" "
Print File ARQIMP Format("W04,EIC",array_tqtd[04])+" "
Print File ARQIMP Format("W04,EIC",array_tqtd[05])+" "
Print File ARQIMP Format("W04,EIC",array_tqtd[06])+" "
Print File ARQIMP Format("W04,EIC",array_tqtd[07])+" "
Print File ARQIMP Format("W04,EIC",array_tqtd[08])+" "
Print File ARQIMP Format("W04,EIC",array_tqtd[09])+" "
Print File ARQIMP Format("W04,EIC",array_tqtd[10])+" "
Print File ARQIMP Format("W04,EIC",array_tqtd[11])+" "
Print File ARQIMP Format("W04,EIC",array_tqtd[12])+" "
Print File ARQIMP Format("W06,EIC",array_tqtd[13])+" "
Print File ARQIMP Spaces(11)+" "+ASP2+"\n"

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


;************** IMPRESSAO DOS TOTAIS DAS FAMILIAS ************************
PRECOTOT=0
QTDETOT=0

;Checa_Linha(3,"")
;Print File ARQIMP "*** Resumo ***"+ASP2+"\n"
;Print File ARQIMP " Familia                     Qtde Un "+"\n"
;Print File ARQIMP " ------------------------ ------- -- "+"\n"

;Moveto PrivDir()+"Pedidotf"
;Moveto [Numero do Pedido]
;Locate [PedidoC->Numero do Pedido]
;While [Numero do Pedido]=[PedidoC->Numero do Pedido]
;   Checa_Linha(1,"")
;   Moveto PrivDir()+"Pedidotf"

;   Print File ARQIMP Spaces(01)+Format("W03,AR",[Codigo da Familia])
;   Print File ARQIMP Spaces(01)+Format("W20,AL",[Descricao da Familia])
;   Print File ARQIMP Spaces(02)+Format("W06,EIC",[Quantidade])
;   Print File ARQIMP Spaces(01)+Format("W02,AL",[Unidade Fiscal])+"\n"
;   QTDETOT=QTDETOT+[Quantidade]
;   Skip
;   If EOT() Then QuitLoop EndIf
;EndWhile

;Checa_Linha(3,"")
;Print File ARQIMP Spaces(27)+"-------    "+"\n"
;Print File ARQIMP Spaces(06)+"Totais..."
;Print File ARQIMP Spaces(12)+Format("W06,EIC",QTDETOT)+"\n\n"


;***************** IMPRESSAO DOS TOTAIS DO PEDIDO  ***************
Moveto "PedidoC"

Checa_Linha(1,"")
Print File ARQIMP ASP1+"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",[PedidoC->Numero de Volumes]))
Print File ARQIMP "   Peso Liquido: "+LTrim(Format("W11.3,EIC",[PedidoC->Peso Liquido]))
Print File ARQIMP "   Peso Bruto: "+LTrim(Format("W11.3,EIC",[PedidoC->Peso Bruto]))+ASP2+"\n"

;********************* IMPRESSAO DO RODAPE *************************************
Imprime_Observacoes()

Checa_Linha(5,"")
Print File ARQIMP ASP1+"Local p/ Entrega: "+Format("W20,AL",[PedidoC->Endereco de Entrega])+ASP2+"\n"

Print File ARQIMP ASP1+Spaces(18)+Format("W15,AL",[PedidoC->Bairro de Entrega])+Format("W11,AL",[PedidoC->CEP de Entrega])
Print File ARQIMP Spaces(40)+"______________________________________________"+ASP2+"\n"

Print File ARQIMP ASP1+Spaces(18)+Format("W15,AL",[PedidoC->Cidade de Entrega])+Format("W03,AL",[PedidoC->UF de Entrega])
Print File ARQIMP Spaces(60)+"Data/Assinatura Responsavel"+ASP2+"\n\n"

Print File ARQIMP ASP1+Fill("-",132)
Print File ARQIMP CI_10CPP
Print File ARQIMP "\f"+ASP2
EndProc




;*******************************************************************************
;* Rotina Principal                                                            *
;*******************************************************************************
AGUARDE("Imprimindo Pedido -> "+PEDIDO)

;****** Adicionando tabelas para trabalho **************************************
View NoWindow "\\Sistemas\\Estoque\\TpGrade"
View NoWindow "\\Sistemas\\Estoque\\Itens"

If Istable(PrivDir()+"Pedidoog")
   Then Delete PrivDir()+"Pedidoog"
EndIf

TABELA_TEMP=Cria_Tabela("","Numero do Pedido(A6*),Sequencia(S*),Referencia(A20),Codigo do Item(A10),Codigo da Cor_Tecido(A4),Preco Unitario($),Descricao do Item(A100),"+
"Descricao da Cor_Tecido(A20),Qtd1(S),Qtd2(S),Qtd3(S),Qtd4(S),Qtd5(S),Qtd6(S),Qtd7(S),Qtd8(S),Qtd9(S),Qtd10(S),Qtd11(S),Qtd12(S),Unidade Fiscal(A4), Preco Total($),"+
"Aliquota de IPI(N),Aliquota de ICMS(N),Peso Liquido(N),Peso Embalagem(N),Volumes(N),Codigo da Grade(A1),Codigo da Familia(A3),Descricao da Familia(A30)")

Adiciona_Indice_Secundario(TABELA_TEMP,"Indpdgrd","Codigo do Item,Codigo da Cor_Tecido,Preco Unitario,Numero do Pedido,Sequencia")

CoEditKey

{TableAdd} TypeIn TABELA_TEMP Enter
{TableAdd} {PedidoG}
{TableAdd} {PedidoV}

SEQG=1
Moveto "Pedidog"
Moveto [Numero do Pedido]
Locate [PedidoC->Numero do Pedido]
While [Numero do Pedido]=[PedidoC->Numero do Pedido]
  WSITE=[Codigo do Item]
  WSREF=[Referencia]

  WSCOR=[Codigo da Cor_Tecido]
  WSPRU =[Preco Unitario      ]

  Moveto TABELA_TEMP
  Moveto [Codigo do Item]
  Locate IndexOrder by "Indpdgrd" WSREF,WSCOR,WSPRU
  If Not RetVal
     Then End
          Down
          [Numero do Pedido       ]=[Pedidog->Numero do Pedido       ]
          [Sequencia              ]=SEQG
          [Codigo do Item         ]=WSREF
          [Codigo da Cor_Tecido   ]=[Pedidog->Codigo da Cor_Tecido   ]
          [Preco Unitario         ]=[Pedidog->Preco Unitario         ]
          [Descricao do Item      ]=[Pedidog->Descricao do Item      ]
          [Descricao da Cor_Tecido]=[Pedidog->Descricao da Cor_Tecido]
          [Unidade Fiscal         ]=[Pedidog->Unidade Fiscal         ]

          [Referencia             ]=[Pedidog->Referencia             ]
          [Codigo da Grade        ]=[Pedidog->Codigo da Grade        ]
          
          getrecord "\\sistemas\\estoque\\itens" WSITE to regitens
          if retval
             then [Codigo da Familia   ]=regitens["Codigo da Familia"   ]
                  [Descricao da Familia]=regitens["Descricao da Familia"]
          endif   
          SEQG=SEQG+1
  EndIf


  [Qtd1    ]=[Qtd1    ]+[Pedidog->Qtd1 ]
  [Qtd2    ]=[Qtd2    ]+[Pedidog->Qtd2 ]
  [Qtd3    ]=[Qtd3    ]+[Pedidog->Qtd3 ]
  [Qtd4    ]=[Qtd4    ]+[Pedidog->Qtd4 ]
  [Qtd5    ]=[Qtd5    ]+[Pedidog->Qtd5 ]
  [Qtd6    ]=[Qtd6    ]+[Pedidog->Qtd6 ]
  [Qtd7    ]=[Qtd7    ]+[Pedidog->Qtd7 ]
  [Qtd8    ]=[Qtd8    ]+[Pedidog->Qtd8 ]
  [Qtd9    ]=[Qtd9    ]+[Pedidog->Qtd9 ]
  [Qtd10   ]=[Qtd10   ]+[Pedidog->Qtd10]
  [Qtd11   ]=[Qtd11   ]+[Pedidog->Qtd11]
  [Qtd12   ]=[Qtd12   ]+[Pedidog->Qtd12]
  [Preco Total]=[Preco Unitario]*([Qtd1   ]+[Qtd2   ]+[Qtd3   ]+[Qtd4    ]+
                                  [Qtd5   ]+[Qtd6   ]+[Qtd7   ]+[Qtd8    ]+
                                  [Qtd9   ]+[Qtd10  ]+[Qtd11  ]+[Qtd12   ])

  If [Qtd1    ]=0 then [Qtd1    ] = BlankNum() EndIf
  If [Qtd2    ]=0 then [Qtd2    ] = BlankNum() EndIf
  If [Qtd3    ]=0 then [Qtd3    ] = BlankNum() EndIf
  If [Qtd4    ]=0 then [Qtd4    ] = BlankNum() EndIf
  If [Qtd5    ]=0 then [Qtd5    ] = BlankNum() EndIf
  If [Qtd6    ]=0 then [Qtd6    ] = BlankNum() EndIf
  If [Qtd7    ]=0 then [Qtd7    ] = BlankNum() EndIf
  If [Qtd8    ]=0 then [Qtd8    ] = BlankNum() EndIf
  If [Qtd9    ]=0 then [Qtd9    ] = BlankNum() EndIf
  If [Qtd10   ]=0 then [Qtd10   ] = BlankNum() EndIf
  If [Qtd11   ]=0 then [Qtd11   ] = BlankNum() EndIf
  If [Qtd12   ]=0 then [Qtd12   ] = BlankNum() EndIf

  UnLockRecord

  Moveto "Pedidog"
  Skip
  If EOT() Then QuitLoop EndIf
EndWhile
Do_It!

Sort TABELA_TEMP On "Numero do Pedido","Descricao da Familia","Codigo da Familia","Codigo do Item" To PrivDir()+"Pedidoog"

Moveto "PedidoC"

;Seta_FilePrint("Pd_0079G")
;Switch
;	Case OK="A": ARQIMP = DIREPORT+ARQUIVO+".TXT"
;EndSwitch

Seta_FilePrint("Pd_0079S")
IMPPED()
Do_It!
Imprime_FilePrint("","")

;ImpriArq(ARQIMP)


Moveto "Pedidog" ClearImage
Moveto "PedidoV" ClearImage
Moveto TABELA_TEMP ClearImage
Delete TABELA_TEMP
Moveto PrivDir()+"Pedidoog" ClearImage
Delete PrivDir()+"Pedidoog"


Release Vars  nlin,npag,array_vrvencto,array_dtvencto,array_grade,
              array_tqtd, regitens, array_fqtd

Release Procs Seta_FilePrint,ImpPed,ImpriArq,
              Cabecalho_Ped,Cabecalho_Item,Cabecalho_Tit,Rodape,
              Imprime_Vencimentos,Imprime_Observacoes,
              Checa_Linha,
              Verifica_Vencimentos,Verifica_Grades,
              GrupoFamilia,TotalizaGrupoFamilia,ZeraGrupoFamilia
