PARAMETERS cBdd, cIdView, cIdServ


SET TALK off
SET STATUS BAR OFF
SET SYSMENU off
SET DELETED on
SET CONFIRM OFF
SET NOTIFY off
SET SAFETY off
SET CENTURY ON
SET DATE TO DMY
SET FIXED OFF
SET DECIMALS TO 5
SET ESCAPE On

SET PATH TO proj,json,classes, form,prg,class

IF EMPTY(cIdServ)
	cIdServ = '1'
ENDIF



PUBLIC lSalir

lSalir=.F.

ON ESCAPE lSalir=.t.


IF EMPTY(cBdd)
	cBdd='fss1'
ENDIF

DECLARE Sleep IN Win32API INTEGER   


DO app.prg WITH cBdd

oApp.lgServ			 = .T.

IF oApp.lGhostLocal
	oApp.host = 'localhost'+IIF(!EMPTY(oApp.portjson),':'+oApp.portjson,'')
ENDIF


_screen.Caption = 'Ghost-Server '+cIdServ+ '   ('+oApp.host+') '



oApp.sqlexec('select id, cast(param as char) as param from ghost_json where cmd="pda_pedido" and fecha="20171118"', 'curPedidos')

SELECT curPedidos
brow
SCAN all
	WAIT WINDOW curPedidos.id NOWAIT
	

	IF !oApp.android_reverse_cd(curPedidos.param)
		MESSAGEBOX('Error en definicion de pedido:' +curPedidos.param, 63, 'GhostM')	
		RETURN 
	ENDIF


	cIdBasketPDa = STRTRAN(ALLTRIM(pda_cur_cab.date)+ALLTRIM(TRANSFORM(pda_cur_cab.id))+ALLTRIM(TRANSFORM(pda_cur_cab.idsalesman)),'-','')
	
	
	TEXT TO ccc NOSHOW textmerge
		UPDATE ghost_json SET fechahora="<<ALLTRIM(pda_cur_cab.date)+' '+ALLTRIM(pda_cur_cab.hora)>>", llave="<<cIdBasketPDa>>" WHERE id=<<curPedidos.id>>
	ENDTEXT
	
	
	oApp.sqlexec(ccc)
	
	SELECT curPedidos
ENDSCAN



return

SQLEXEC(oApp.nConn,'ALTER TABLE ghost_json ADD fechahora datetime default "20170101"')
SQLEXEC(oApp.nConn,'ALTER TABLE ghost_json ADD llave varchar(20) default ""')

oApp.sqlexec('select id, cast(param as char) as param from ghost_json where cmd="pda_pedido"', 'curPedidos')

SELECT curPedidos
SCAN all
	WAIT WINDOW curPedidos.id NOWAIT
	

	IF !oApp.android_reverse_cd(curPedidos.param)
		MESSAGEBOX('Error en definicion de pedido:' +curPedidos.param, 63, 'GhostM')	
		RETURN 
	ENDIF


	cIdBasketPDa = STRTRAN(ALLTRIM(pda_cur_cab.date)+ALLTRIM(TRANSFORM(pda_cur_cab.id))+ALLTRIM(TRANSFORM(pda_cur_cab.idsalesman)),'-','')
	
	
	TEXT TO ccc NOSHOW textmerge
		UPDATE ghost_json SET fechahora="<<ALLTRIM(pda_cur_cab.date)+' '+ALLTRIM(pda_cur_cab.hora)>>", llave="<<cIdBasketPDa>>" WHERE id=<<curPedidos.id>>
	ENDTEXT
	
	
	oApp.sqlexec(ccc)
	
	SELECT curPedidos
ENDSCAN
