#define versao "20/02/03-20:58"
// cadastro de clientes
//
// 07/09/99
#include "key.ch"

#include 	"Tbrowse.ch"
#include	"inkey.ch"
#include	"box.ch"
#include    "button.ch"

#define CONFIG      "config.ini"  // configuracoes gerais para todos os
                                            // computadores
#define	ENTER			chr(13)+chr(10)
#define ARQUIVOMAX      "max.ini"          // configuracoes particulares MAX

local TelaOP
save scree to telaOP


/*
cadastro.dbf
 1  CODIGO      Numeric      6    0         16  DADOS_ADIC  Memo        10
 2  RAZAO_SOCI  Character   60              17  DATA        Date         8
 3  NOME_DE_FA  Character   60              18  INTERNET    Character   40
 4  PROPRIETAR  Character   40              19  E_MAIL      Character   40
 5  COMPRADOR   Character   40
 6  CGC         Character   18
 7  INSCRICAO_  Character   15
 8  ENDERECO    Character   60
 9  BAIRRO      Character   40
10  CIDADE      Character   40
11  ESTADO      Character    2
12  CEP         Character    9
13  FONE        Character   14
14  FAX         Character   14
15  SELECTED    Logical      1


*/

public vpt_data,datainicial,datafinal
vpt_data = date()
vpt = 0

set color to b/w
@ 0,0

set color to w/b
janela(1,0,41,79)

public selecionado,vnome3
selecionado = 0

vnome3 = ' '
sele cadastro
set order to 1


declare campo[1], titulo[1]
campo[1] = 'it_cad()'
titulo[1] = 'Razao Social                                     Codigo   Fone'


@ 28,1 say repl(chr(196),78)
@ 28,0 say chr(195)
@ 28,79 say chr(180)


@ 17,1 say repl(chr(196),78)
@ 17,0 say chr(195)
@ 17,79 say chr(180)




set color to b/w
@ 0,0
op('&/Menu   Voltar',row(),0)



set color to r/w

@ 42,0
op('&Alterar',row(),col()+2)
op('Des&filtrar',row(),col()+2)
op('&Novo',row(),col()+2)
op('&Obs.',row(),col()+2)
op('&Selecionar',row(),col()+2)
op('&Incluir_Aniver.',row(),col()+2)


set color to gr+/b
centro(' Cadastro ',1,80)

set color to w/b



save scree to tela_cad

keyboard chr(271) && send Back+tab just to clean the keyboard

lastRecord = val(readINI(arquivoINI,'Posicao Cadastro','1'))
dbedit(2,1,16,78,campo,'cadedita',,titulo)
writeINI(arquivoINI,'posicao cadastro',str(recno()))
restore scree from telaOP
return


func it_cad
s = ' '+chr(179)+' '
return(subst(razao_soci,1,46)+s+str(codigo,6)+s+fone)+s+if(selected,'*',' ')


* funcao de edicao
func cadedita
set cursor on
set color to w/b
last = lastkey()

if last = 16 && nao deixa haver repeticao de leitura da buffer
    last = inkey(0)
    return(1)
endif

last = chr(lastkey())

do case
case last = '/' .or. mouse('/menu',0,0)
    save scree to tela_cad
    lastrecord = recno()
    cadMenuTest()
    op = 0
    sele cadastro
    set order to 1
    if reccount() > lastrecord
        go lastrecord
    endif
    restore scree from tela_cad
    keyboard chr(271) && send Back+tab
    return(2)
case ! eof() .and. lastkey() = 7 .and. confirma('Apagar o registro deste cliente?','Apagar','Cancelar') .and.;
    travou()
    upd()

    delete
    unlock
    keyboard chr(271)
    return(2)

case lastkey() = k_altA .or. lastkey() = 13 .or. mouse('Alterar',42,2)
    do clialterar
case lastkey() = k_altS .or. mouse('Selecionar',42,35)
    seleCad()
    return(2)
case lastkey() = k_altI .or. mouse('Incluir_Aniver.',42,47)
    IncAniver()
    keyboard chr(271)

    return(1)
case lastkey() = k_altF .or. mouse('Desfiltrar',42,11)
    filtroCad()
    return(2)
case lastkey() = k_altN .or. mouse('Novo',42,23)
    do clinovo
    return(2)
case lastkey() = k_altO .or. mouse('Obs',42,29) .or. mouseArea(.t.,28,1,40,78)
    do cliobs
    keyboard chr(271)
    return(2)
case lastkey() = 27 .or. mouse('Voltar',0,8)
    return(0)
case last >= '0' .and. last <= 'z' .or. lastkey() = 32
    vprod = chr(lastkey())+space(34)
    save scree to tela_2
    setcolor('b/w')
    janela(8,10,10,32)
    keyboard chr(4)
    @ 8,11 say 'Procurar'
    @ 9,11 get vprod pict '@!s20'
    read
    if asc(vprod) < 58 .and. ! empty(vprod)
        set order to 2
        seek val(vprod)
        if ! found()
        mensa2('Codigo nao encontrado')
        endif
        set order to 1
    else
    if ! empty(vprod)
        if len(rtrim(vprod)) > 1
            set softseek on
        endif
        seek vprod
        set softseek off
    endif
    endif
    rest scree from tela_2
    keyboard chr(16) && envia CTRL * para o buffer para nao haver repeticao de leitura
endcase

set color to w/b
if user = 'MASTER'
    @ 49,0 say ltrim(str(mrow()))+','
    @ row(),col() say ltrim(str(mcol()))
endif
@ 18,1 say 'Fantasia:'
@ 19,1 say 'Endereco:'
@ 20,1 say 'Bairro:'
@ 21,1 say 'Cidade'
@ 20,48 say 'CEP:'
@ 21,48 say 'IE:'
@ 22,1 say 'CNPJ:'
@ 22,48 say 'Celular:'
@ 23,1 say 'Fone:'
@ 23,48 say 'Fax:'
@ 24,1 say 'Propriet.:'
@ 25,1 say 'Comprador:'
@ 26,1 say 'C/C:'
@ 26,48 say 'E-mail:'
@ 27,1 say 'Obs:'


set color to bg/b
@ 18,11 say subst(nome_de_fa,1,60)
@ 19,11 say endereco
@ 20,11 say subst(bairro,1,30)
@ 21,11 say subst(cidade,1,30)
@ 21,col()+1 say estado
@ 20,57 say cep
@ 21,57 say inscricao_
@ 22,11 say CGC
@ 22,57 say celular
@ 23,11 say fone
@ 23,57 say fax
@ 24,11 say proprietario
@ 25,11 say comprador
@ 26,11 say subst(internet,1,30)
@ 26,57 say subst(e_mail,1,20)
@ 27,09 say obs

if ! empty(dbfilter())
    set color to w*/b
    direita('Filtrado!',24,78)
else
    direita('         ',24,78)
endif
sele cadastro
keyboard chr(23)
memoedit(dados_adic,29,1,40,78,.f.)
buf(1)
return(1)





* 1.Novo
* Cliente Novo
proce clinovo
sele cadastro
set order to 2
go bott
vcodigo = cadastro->codigo
set order to 1
save scree to tela_novo
do while .t.
    vxnome = space(60)
    vxendereco = space(60)
    vxbairro = space(40)
    vxcidade = space(40)
    vxestado = space(2)
    vxcep = space(9)
    vxdocumento = space(18)
    vxie = space(15)
    vcodigo = vcodigo + 1
    vxfoner = space(14)
    vxfax = space(14)
    vxCelular = space(14)
    vxObs = space(70)

    store space(40) to vxProprietario, vxComprador, vxEmail, vxInternet
    store space(60) to vxRazao

    if file('cadnew.mem')
        if confirma('A inclusao anterior foi abandonada sem ter sido completada. Voce deseja recuperar aqueles dados?')
            restore from cadnew addi
        else
            dele file cadnew.mem
        endif
    endif
    set color to w/b
    janela(1,0,42,79)
    @ 3,5 say ' Cliente Novo            Codigo: '
    @ 3,col() say vcodigo pict '###### '
    @ 5,5 say 'Fantasia  ' get vxnome pict '@!' valid(clinovov(vxnome))
    @ 7,5 say 'Razao     ' get vxRazao pict '@!'
    @ 8,5 say 'Endereco  ' get vxendereco pict '@!'
    @ 9,5 say 'Bairro    ' get vxbairro pict '@!'
    @ 10,5 say 'Cidade    ' get vxcidade pict '@!'
    @ 11,5 say 'Estado    ' get vxestado pict '@!'
    @ 12,5 say 'CEP       ' get vxcep pict '99999-999'
    @ 13,5 say 'Telefone  ' get vxfoner
    @ 14,5 say 'Fax       ' get vxfax
    @ 15,5 say 'Celular   ' get vxcelular
    @ 16,5 say 'CNPJ      ' get vxdocumento
    @ 17,5 say 'IE        ' get vxie
    @ 18,5 say 'Propriet. ' get vxProprietario pict '@!'
    @ 19,5 say 'Comprador ' get vxComprador pict '@!'
    @ 20,5 say 'E-mail    ' get vxEmail
    @ 21,5 say 'C/C       ' get vxInternet
    @ 22,5 say 'Obs       ' get vxObs pict '@!s40'


    lYes := .t.
    lNo := .t.
    nButton = 0
    @ row()+2, 5 GET lYES PUSHBUTTON ;
                CAPTION " OK ";
                COLOR "w/b,r+/b,b/b,b/b";
                style B_SINGLE;
                STATE  { | |  ReadButton(1,.t.) }

    @ row(),col()+10 GET lNO PUSHBUTTON ;
                CAPTION " Cancelar ";
                COLOR "w/b,r+/b,b/b,b/b";
                style B_SINGLE;
                STATE  { | |  ReadButton(2,.T. ) }

    read

    if lastkey() = 27 .or. nButton = 2
        if ! empty(vxnome)
            save to cadnew all like vx*
        endif
        restore scree from tela_novo
        return
    endif
    vxEmail = lower(vxEmail)
    if apb()
    repl nome_de_fa with vxnome, razao_soci with vxRazao,;
        endereco with vxendereco, bairro with vxbairro, cidade with vxcidade,;
        estado with vxestado, cep with vxcep, cgc with vxdocumento,;
         inscricao_ with vxie, codigo with vcodigo,;
         celular with vxCelular,;
         obs with vxObs

    repl fone with vxfoner,;
         proprietar with vxproprietario,;
         comprador with vxcomprador, e_mail with vxemail, fax with vxfax,;
         internet with vxInternet
    repl dados_adic with memo(dados_Adic,.t.,'Dados Adicionais'), data with date()

    repl id with getid()
    upd()

    if file('cadnew.mem')
        dele file cadnew.mem
    endif

    bip()
    buf(1)
    endif
enddo
lastrecord = recno()


func clinovov(vfnome)
seek vfnome
if found() .and. len(rtrim(vfnome)) > 0
    mensa2('Ja existe cadastro com o nome de: '+rtrim(vfnome)+' codigo '+str(codigo,6))
endif
return(.t.)






* 2.Alterar
* Alterar cadastro
proce clialterar
sele cadastro
save scree to tela_alt
if ! eof() .and. travou()
    set color to w/b
    @ 1,0 clear to 42,79
    set color to w/b
    @ 3,3 say 'Alterar Cliente  Codigo:'
    @ 3,col()+1 get codigo pict '######'
    @ 5,5 say 'Fantasia  ' get nome_de_fa pict '@!'
    @ 6,5 say 'Razao     ' get razao_soci pict '@!'
    @ 8,5 say 'Endereco  ' get endereco pict '@!'
    @ 9,5 say 'Bairro    ' get bairro pict '@!'
    @ 10,5 say 'Cidade    ' get cidade pict '@!'
    @ 11,5 say 'Estado    ' get estado pict '@!'
    @ 12,5 say 'CEP       ' get cep pict '99999-999'
    @ 13,5 say 'Telefone  ' get fone
    @ 14,5 say 'Fax       ' get fax
    @ 15,5 say 'Celular   ' get celular
    @ 16,5 say 'CNPJ      ' get cgc
    @ 17,5 say 'IE        ' get inscricao_
    @ 18,5 say 'Propriet. ' get Proprietar pict '@!'
    @ 19,5 say 'Comprador ' get Comprador pict '@!'
    @ 20,5 say 'E-mail    ' get E_mail
    @ 21,5 say 'C/C       ' get Internet
    @ 22,5 say 'Obs       ' get obs pict '@!s40'


    lYes := .t.
    lNo := .t.
    nButton = 0
    @ row()+2, 5 GET lYES PUSHBUTTON ;
                CAPTION " OK ";
                COLOR "w/b,r+/b,b/b,b/b";
                style B_SINGLE;
                STATE  { | |  ReadButton(1,.t.) }


    read
    upd()

    repl e_mail with lower(e_mail), internet with lower(internet)
    buf(1)
    @ 1,0 clear to 42,79
unlock

endif
restore scree from tela_alt










proce cadimplista
******************************
* imprime listagem de clientes

if ! confirma('Imprimir listagem de clientes?')
    return
endif

* abre saida de impressao em arquivo
if ! gp_ofile()
    if ! pronta()
        return
    endif
endif
sele cadastro
set order to 1
go top
@ 42,0
prog_tela()
oldtime = time()
n1 = 0
n2 = reccount()
pag = 0
set devi to print
condensado(1)
no = subs(nome,1,2)
do while ! eof()
    if cancelada()
        condensado(0)
        eject
        ready()
        set devi to scree
        set print to
        i = inkey(0)
        mensa2('A impressÆo foi cancelada pelo usu rio.')
        return
    endif
    if prow() > 56
        pag = pag+1
        centro('pag. '+strzero(pag,3),prow()+2,80)
        eject
    endif
    if prow() = 0
        @ prow(),6 say lojas->nome
        @ prow()+2,6 say 'Lista de Clientes'
        @ prow()+2,6 say 'Cliente-----------------------------------C¢digo--Fone-----------'
    endif
    n1 = n1+1
    set devi to scree
    prog_dados(oldtime,n1,n2)
    set devi to print
    if subs(nome,1,2) <> no
        no = subst(nome,1,2)
        @ prow()+1,0 say ' '
    endif
    @ prow()+1,6 say nome
    @ prow(),pcol()+2 say codigo
    @ prow(),pcol()+2 say fone
/*
    @ prow(),pcol()+2 say ultima
    @ prow(),pcol()+2 say tipos->descricao
    */
    skip
enddo
@ prow()+1,5 say 'Impresso '
@ prow(),pcol() say data_atual(date())
condensado(0)
eject
ready()
set print to
set devi to scree
return




/*


* imprime endereco do destinatario direto no envelope
* 28/09/97
proce destinatario
if op = 8
    if ! confirma('Imprimir o endere‡o dos clientes contidos no arquivo Cobran‡a?')
        return
    endif
else
    if ! confirma('Imprimir endere‡o do destinat rio no envelope?')
        return
    endif
endif

waiting(1,'Imprimindo')
if op = 7
    sele cadastro
    go top
else
    sele cadastro
    set order to 2
    sele cobranca
    go top
    if reccount() = 0
        mensa2('O arquivo Cobran‡a est  vazio.')
        return
    endif
endif
gp_ofile()
setprc(0,0)
set devi to print
do while ! eof() .and. nextkey() <> 27
    sele cadastro
    if op = 8
        seek cobranca->codigo
        if ! found()
            sele cobranca
            skip
            loop
        endif
    endif
    @ 3,5 say nome
    @ 4,5 say rtrim(endereco) + ' - '+ rtrim(bairro)
    @ 5,5 say rtrim(cidade) + ' - '+rtrim(estado)
    @ 6,5 say 'CEP: '+cep
    eject
    if op = 8
        sele cobranca
    endif
    skip
enddo
set print to
set devi to scree
waiting(0)


*/



proce cliobs
save scree to tela_obs
                sele cadastro
                if ! eof() .and. travou()
                repl dados_adic with memo(dados_adic,.t.,'Dados Adicionais' )
                upd()

                unlock

                endif
restore scree from tela_obs











func iFicha()
// imprime a ficha do cliente
sele cadastro
if ! confirma('Imprimir cadastros?')
    return(.f.)
endif

vSaida = ' '
enter = chr(13) + chr(10)
do while vSaida <> 'I' .and. vSaida <> 'A'
    vSaida = 'I'
    vSaida = Input2('Impressao de Cadastros.'+enter+enter+;
            'Digite I: para impressora,'+enter+;
            '       A: para arquivo.',vSaida)
    vsaida = upper(vsaida)
enddo


if vSaida = 'A'
    arqSaida = 'Cadastro'
    arqSaida = input2('Digite o nome do arquivo',arqSaida)
    arqSaida = rtrim(arqSaida)+'.txt'
    set print to &arqSaida
endif


waiting(1,'Imprimindo...')
linhasPorFolha = 50 // val( readINI(arquivoINI,'Linhas por folha','60') )

set devi to print

setprc(0,0)

do while ! eof()
    if prow()+14 >= linhasPorFolha .and. vSaida = 'I'
        eject
    endif
    if prow() < 2
        imTimbre()
        @ prow()+1,0 say 'Cadastro'
        if len(rtrim(vnome3)) > 0
            @ prow(),pcol()+3 say '(filtrado por "'+rtrim(vnome3)+'")'
        endif
        direita(dtoc(date()),prow(),80)
    endif

    @ prow()+1,0 say repl ('_',80)

    //direita(str(codigo,5),pcol()+1,40)
*    @ prow()+2,0 say 'Fantasia     '+nome_de_fa
*    @ prow()+1,0 say 'Razao Social '+Razao_soci
    @ prow()+2,0 say 'Razao Social '+Razao_soci
    @ prow()+1,0 say 'Fantasia     '+nome_de_fa
    @ prow()+1,0 say 'Proprietario '+Proprietar
    @ prow()+1,0 say 'Comprador    '+Comprador

    @ prow()+1,0 say 'Endereco:    '
        @ prow(),pcol() say endereco
    @ prow()+1,0 say 'Bairro:      '
        @ prow(),pcol() say bairro
    @ prow(),pcol()+3 say 'CEP: '
        @ prow(),pcol() say cep
    @ prow()+1,0 say 'Cidade:      '
        @ prow(),pcol() say rtrim(cidade)
        @ prow(),pcol()+2 say estado
    @ prow()+1,0 say 'CNPJ:        '
        @ prow(),pcol() say cgc
    @ prow(),pcol()+3 say 'IE: '
        @ prow(),pcol() say inscricao_
    @ prow(),pcol()+3 say 'CODIGO: '
        @ prow(),pcol() say ltrim(str(codigo))
    @ prow()+1,0 say 'Fone         '+fone
    @ prow(),pcol()+2 say 'Fax '+Fax
    @ prow(),pcol()+2 say 'Celular '+Celular

// 03/01/02
    @ prow()+1,0 say 'C/C          '+internet
    @ prow()+1,0 say 'E-mail       '+e_mail
    @ prow()+1,0 say 'Obs.   '+obs

    skip
enddo
@ prow()+1,0 say repl('_',80)
eject
set print to
set devi to scree
waiting(0)
if vSaida = 'A'
    mensa2('Os cadastros foram impressos no arquivo '+ArqSaida)
else
    mensa2('Os cadastros foram encaminhados para impressao.')
endif

return(.t.)


func seleCad()
    if ! eof() .and.  travou()
        repl selected with ! selected
        unlock
    endif
    keyboard chr(271)
return .t.

func FiltroCad()
    set filter to
    vnome3 = ''
    mensa2('Filtro desativado!')
    go top
    keyboard chr(271)
return .t.





function CadMENUTest()
   LOCAL oInfo
   SET( _SET_EVENTMASK, INKEY_ALL )
   MSETCURSOR(.T.)
   oInfo:=CadMENUCreate()
   MENUMODAL(oInfo,1,50,1,79,"r/w")
   RETURN ( NIL )

function CadMENUCreate()
   local oTopBar, oPopUp, oPopUp1

      oTopBar := TopBar( 0, 0, 79)
      oTopBar:ColorSpec :="b/w,gr+/r,r/w,gr+/r,N+/w,N+/w"

      oPopUp := PopUp()
      oPopUp :ColorSpec:= "b/w,gr+/r,r/w,gr+/r,N+/w,N+/w"
      oPopUp:AddItem(MenuItem( "&Novo" ,{|| clinovo() },,""))
      oPopUp:AddItem(MenuItem( "&Alterar" ,{|| clialterar() },,""))
      oPopUp:AddItem(MenuItem( "&Observacao" ,{|| Cliobs() },,""))
      oPopUp:AddItem(MenuItem( "&Filtro por cidade" ,{|| FiltCid() },,""))
      oPopUp:AddItem(MenuItem( "Filtro por &selec." ,{|| FiltSelec() },,""))
      oPopUp:AddItem(MenuItem( "&Tirar selecoes" ,{|| TirarSelec() },,""))
      oPopUp:AddItem(MenuItem( "&Inverter selecoes" ,{|| InvertSelec() },,""))


      oTopBar:AddItem( MenuItem ( "&Cadastro",oPopUp) )


      oPopUp := PopUp()
      oPopUp :ColorSpec:= "b/w,gr+/r,r/w,gr+/r,N+/w,N+/w"
      oPopUp:AddItem(MenuItem( "&Cadastro" ,{||  edita(.t.,'Cadastro') },,""))
      oPopUp:AddItem(MenuItem( "&Aniversario" ,{||  editaniver() },,""))

      oTopBar:AddItem( MenuItem ( "&Editar",oPopUp) )

      oPopUp := PopUp()
      oPopUp :ColorSpec:= "b/w,gr+/r,r/w,gr+/r,N+/w,N+/w"
*      oPopUp:AddItem(MenuItem( "&Lista de clientes" ,{|| CadImpLista() },,""))
      oPopUp:AddItem(MenuItem( "&Cadastro" ,{|| IFicha() },,""))
      oPopUp:AddItem(MenuItem( "&Aniversariantes" ,{|| ImpAniver() },,""))

      oTopBar:AddItem( MenuItem ( "&Imprimir",oPopUp) )

      oTopBar:AddItem( MenuItem ( "&Sair_menu",{|| sendEsc() } ) )


   return ( oTopBar)


func filtCid()
            vnome3 = subst(vnome3+space(20),1,20)
            enter = chr(13)+chr(10)
            vnome3 = upper(rtrim(input2('Filtro por cidade.'+enter+enter;
            +'Press. ESC para cancelar o filtro',vnome3)))

            if lastkey() = 27
                set filter to
                vnome3 = ''
            else
                waiting(1,'Filtrando...')
                set filter to cidade = rtrim(vnome3)
                waiting(0)
            endif

func filtSelec()
            vnome3 = 'Selecionado'
            waiting(1,'Filtrando...')
            set filter to selected
            waiting(0)

func tirarSelec()
            waiting(1)
            sele cadastro
            go top
            do while ! eof()
                if selected .and. travou()
                    repl selected with .f.
                    unlock
                endif
                skip
            enddo
waiting(0)

func InvertSelec()
        if confirma('Inverter selecao de todos os cadastros?')
            waiting(1,'Invertendo')
            sele cadastro
            go top
            do while ! eof()
                repl selected with ! selected
                unlock
                skip
            enddo
            go top
            waiting(0)
        endif


func aAniver()
//
//     Silvio Felippe
//
//     28/10/01
//     18:46:46
//
if ! file('aniver.dbf')
// CRIAR ARQUIVO
SELE 0
CREATE TempStru NEW

apb()
replace Field_name with 'Cliente',;
      Field_type with 'n',;
      Field_len with 11,;
      Field_dec with 0

apb()
replace Field_name with 'nome',;
      Field_type with 'c',;
      Field_len with 30,;
      Field_dec with 0

apb()
replace Field_name with 'data',;
      Field_type with 'd',;
      Field_len with 8,;
      Field_dec with 0

apb()
replace Field_name with 'obs',;
      Field_type with 'c',;
      Field_len with 30,;
      Field_dec with 0


CLOSE
CREATE aniver.DBF FROM TempStru
close
erase tempStru.dbf


endif
abriu('aniver.dbf')
if ! file('aniverd.ntx')

    index on data to aniverd
    index on cliente to aniverc
endif
set index to aniverd,aniverc




func editaniver()
aAniver()
edita()
use
return .t.




func IncAniver()
//
//     Silvio Felippe
//
//     28/10/01
//     18:53:50
//
local tela,area

area = select()

save scree to tela
aAniver()
set color to b/w
nCliente = cadastro->codigo
dData = ctod('')
cNome = space(30)
cObs = space(30)
do while .t.
    janela(10,10,17,50)
    @ 11,11 say 'Incluir Aniversario'
    @ row()+2,11 say 'Cliente' get nCliente pict '###########'
    @ row()+1,11 say 'Nome   ' get cNome pict '@!'
    @ row()+1,11 say 'Obs.   ' get cObs pict '@!'
    @ row()+1,11 say 'Data   ' get dData
    read

    if lastkey() = 27
        exit
    endif

    apb()
    repl Cliente with nCliente, nome with cNome, data with dData,;
        obs with cObs

    unlock
enddo
restore scree from tela
use
sele &area

return .t.










func impAniver()
// imprime aniversario
//
//
//     Silvio Felippe
//
//     23/12/01
//     10:24:38
//
local tela
save scree to tela
linhasPorFolha = val( readINI(arquivoINI,'Linhas por folha','60') )

set color to b/w
janela(9,9,13,38)
mesAniver = month(date())

@ 10,10 say 'Impressao de aniversariantes'
@ row()+2,10 say 'Mes de aniversario' get mesAniver pict '##';
    valid(mesAniver > 0 .and. mesAniver < 13)

read
restore scree from tela

if lastkey() = 27
    return .f.
endif

vSaida = ' '
enter = chr(13) + chr(10)
do while vSaida <> 'I' .and. vSaida <> 'A'
    vSaida = 'I'
    vSaida = Input2('Impressao de pedido.'+enter+enter+;
            'Digite I: para impressora,'+enter+;
            '       A: para arquivo.',vSaida)
    vsaida = upper(vsaida)
    if lastkey() = 27
        return(.f.)
    endif
enddo


if vSaida = 'A'
    arqSaida = subst('Aniver'+space(8),1,8)
    arqSaida = input2('Digite o nome do arquivo',arqSaida)
    arqSaida = rtrim(arqSaida)+'.txt'
    if lastkey() = 27
        return(.f.)
    endif

    set print to &arqSaida
endif




waiting(1,'Imprimindo...')
aAniver()
sele aniver
set order to 1
go top

set devi to print
@ prow()+1,0 say 'Aniversariantes do mes '
@ prow(),pcol() say mesAniver pict '##'
*@ prow()+1,0 say ''

do while ! eof()
    if month(data) <> mesAniver
        skip
        loop
    endif

    if vSaida = 'I' .and. prow() > LinhasPorFolha - 4
        eject
    endif

    @ prow()+2,0 say nome
    @ prow(),pcol()+2 say data
    @ prow(),pcol()+2 say obs


    sele cadastro
    set order to 2
    seek aniver->cliente
    if found()

        @ prow()+1,0 say nome_de_fa
        @ prow()+1,0 say rtrim(endereco)
        @ prow(),pcol() say ' - ' + rtrim(bairro)

        @ prow()+1,0 say cep
        @ prow(),pcol()+2 say rtrim(cidade)+' - '+estado

        if ! empty(e_mail)
            @ prow()+1,0 say 'E-mail '+e_mail
        endif
    endif
    sele aniver
    skip
enddo

eject
set devi to scree
set print to
waiting(0)
sele aniver
use

mensa2('Concluido')
return .t.
