CLOSE ALL
nn=SQLCONNECT('fss1')

=SQLEXEC(nn,'delete from customer')

USE clientes IN 0

SELECT * FROM clientes WHERE !EMPTY(nombre) INTO CURSOR cclientes
SELECT cclientes
ncont = 0
nrepit = 0
SCAN all
	ncont = ncont +1
	cid = PADL(ncont,12,'0')
	cname = UPPER(ALLTRIM(nombre))
	ccedula = ALLTRIM(ruc)
	ctiporuc = IIF(LEN(ALLTRIM(ccedula))=13,'04','05')
	
	nDV = INT(VAL(SUBSTR(ccedula,10,1)))
	_ss = 0
	FOR _ii = 1 TO 9
		_nn = INT(VAL(SUBSTR(ccedula,_ii,1)))
		_nn = _nn * IIF (_ii % 2 = 0,1,2)
		_nn = int(_nn/10) + (_nn%10)
		_ss = _ss + _nn
	ENDFOR
	_nRet = (10 - (_ss % 10 )) % 10
	IF nDV = _nRet AND !EMPTY(ccedula)
		nestado = 1
	ELSE
		nrepit = nrepit+1
		nestado = 2 
	ENDIF 
	nsexo = 1
	cphone = fono
	caddress = UPPER(ALLTRIM(direcion))
	ccodigo =''
	ccity = UPPER(ALLTRIM(ciudad))
	ccomercio = ALLTRIM(cname)
	cidwarehouse = '000000000001'
	cidsalesman = '00000001'
	napplytax = 1
	cidzona = '000000001'
	cidclase = '000000001'
	npvp = 1
	cidnegocio = '00000001'
	cidruta = '00000001'
	nmoneda = 1
	nlenguaje = 2
	
	ccad = 'insert into customer (id,name,ruc,sexo,phone,address,codigo,city,comercio,idwarehouse,idsalesman,state,applytax,idzona,idclase,pvp,idnegocio,idruta,moneda,lenguaje,tiporuc)'+;
			'values(?cid,?cname,?ccedula,?nsexo,?cphone,?caddress,?ccodigo,?ccity,?ccomercio,?cidwarehouse,?cidsalesman,?nestado,?napplytax,?cidzona,?cidclase,?npvp,?cidnegocio,?cidruta,?nmoneda,?nlenguaje,?ctiporuc)'
	d=SQLEXEC(nn,ccad)	
	?d
	
	SELECT cclientes
ENDSCAN 
WAIT WINDOW nrepit
=MESSAGEBOX('Listo',64,'Info')