Private zEmpnome, zEmprua, zEmpbairro, zEmpcep, zEmpcidade, zEmpuf, zEmpfone, zEmpinscest, zEmpisncmun, zEmail, zEmpcgc
Private zAreaOrig, zfNumPed, zfnum, zfVal, zParcela, zCrValor, zCrNumPed, zCrDtVenc, z_extenso, zCrDtEmis, zAliasDup
Private m_cr_nome, m_cr_rua, m_cr_cidade, m_cr_uf, m_cr_cep, m_cr_cgc, m_cr_est

zEmpnome    := hDadosEmp["EMP_NOME"]
zEmprua     := hDadosEmp["EMP_RUA"]+" "+hDadosEmp["EMP_NUMRUA"]
zEmpbairro  := hDadosEmp["EMP_BAIRRO"]
zEmpcep     := hDadosEmp["EMP_CEP"]
zEmpcidade  := hDadosEmp["EMP_CIDADE"]
zEmpuf      := hDadosEmp["EMP_UF"]
zEmpfone    := hDadosEmp["EMP_FONE"]
zEmpinscest := hDadosEmp["EMP_IE"]
zEmpisncmun := hDadosEmp["EMP_IM"]
zEmail      := hDadosEmp["EMP_EMAIL"]
zEmpcgc     := FormataCnpjCpf(hDadosEmp["CNPJ"])

   zAliasDup := if(select('_duplcli')>0,'_duplcli','sccrdup')
  
   zAreaOrig := Select()
   if( select('sf_fat')=0, Abra ('0NOIDX', r_siga, sf_fat, "sf_fat",   sf_fat_p, 'fnumped') , '')
   zfNumped := (zAliasDup)->fnumped
   zfval := if( sf_fat->(DbSeek(zfNumped)), sf_fat->fVal, (zAliasDup)->cr_valor)
   zfnum := sf_fat->fnum
   dbselectarea(zAreaOrig)

zParcela  := AllTrim(SubStr( (zAliasDup)->cr_num_ped, 7))
if empty(zParcela)
   zParcela  := Left((zAliasDup)->cr_num_ped,6)
endif
zCrValor  := (zAliasDup)->cr_valor
zCrNumPed := (zAliasDup)->cr_num_ped
zCrDtVenc := (zAliasDup)->cr_dt_venc
zCrDtEmis := (zAliasDup)->cr_dt_emis

m_cr_nome   := AllTrim( sccrcli->cr_nome )
m_cr_rua    := AllTrim( sccrcli->cr_rua )
m_cr_cidade := AllTrim( sccrcli->cr_cidade )
m_cr_uf     := AllTrim( sccrcli->cr_uf )
m_cr_cep    := AllTrim( sccrcli->cr_cep )
m_cr_cgc    := AllTrim( sccrcli->cr_cgc )
m_cr_est    := AllTrim( sccrcli->cr_insc_es )
z_extenso   := NumExt( (zAliasDup)->cr_valor )

ProcessTemplateRtf()