B4A=true
Group=Default Group
ModulesStructureVersion=1
Type=Class
Version=11.5
@EndOfDesignText@
Sub Class_Globals
	Private Root As B4XView 'ignore
	Private xui As XUI 'ignore
	
	Dim g As GPS
	Dim ruta As String
	Dim skmt As SQL
	Private t3 As Timer
	Dim p As Phone
	Dim sb As StringBuilder
	
	Dim c As Cursor
	Dim e As Cursor
	Dim f As Cursor
	Dim h As Cursor
	Dim CC As Cursor
	Dim DD As Cursor
	Dim l_tipo As Label
	Dim l_sub As Label
	Dim l_marca As Label
	Dim l_desc As Label
	Dim l_precio As Label
	Dim l_bodega As Label
	Dim cantidad As EditText
	Dim guardar As Button
	Dim Terminar As Button
	Dim img_prod As ImageView
	Dim IMG_PASO() As Byte
	Dim L_PROID As Label
	Dim clie_id As String
	Dim sDate,sTime As String
	Dim usuario As String
	'    Dim lat_gps, lon_gps As String
	Dim t_venta As Label
	Dim PROMO_C As String
	Dim i_fotol As ImageView
	Private DESC_PROMO As Button
	Private nopromo As Button
	Dim TOT_ART_PROMO As String
	Dim cambio As String
	Dim COSTO_TOT As String
	Dim ALMACEN As String
	Dim preciosin As String
	Dim cl_ruta As String
	Dim d As Cursor
	Dim TOT_ART_PROMOR As String
	Dim PROMO_CR As String
	Dim TOTAL_PROMO As String
	Dim HCCP_CANT As String
	Dim tgl As Toggle
	Dim precio_Cero As String
	Private BONSABOR As String
	Private BONSABOR2 As String
	Dim cmd As DBCommand
	Private p_pedido As Panel
	dim tipo_venta as string = Subs.traeTipoVentaDeBD
End Sub

'You can add more parameters here.
Public Sub Initialize As Object
	Return Me
End Sub

'This event will be called once, before the page becomes visible.
Private Sub B4XPage_Created (Root1 As B4XView)
	Root = Root1
	'load the layout to Root
	Root.LoadLayout("pedido")
	i_fotol.Visible = False
'	B4XPages.MainPage.reqManager.Initialize(Me, "http://177.244.63.54:1782")
	ruta = File.DirInternal
	If File.Exists(ruta, "kmt.db") = False Then
		File.Copy(File.DirAssets, "kmt.db", ruta, "kmt.db")
	End If
'	skmt.Initialize(ruta,"kmt.db", True)
End Sub

'You can see the list of page related events in the B4XPagesManager object. The event name is B4XPage.

Sub B4XPage_Appear
	tgl.Initialize
	BONSABOR = 0
	BONSABOR2 = 0
	If Not(Starter.gps.GPSEnabled) Then
		ToastMessageShow("Es necesario tener el GPS encendido", True)
		StartActivity(Starter.gps.LocationSettingsIntent)
	End If
	cantidad.Text = ""
	c=B4XPages.MainPage.skmt.ExecQuery("select  ID_ALMACEN from CAT_ALMACEN")
	C.Position =0
	ALMACEN = C.GetString("ID_ALMACEN")
	C.Close
	i_fotol.Visible = False
	sb.Initialize
	p.Shell("ping -c1 -W1 177.244.63.54",Null, sb,Null)
	skmt.Initialize(ruta,"kmt.db", True)
	c=B4XPages.MainPage.skmt.ExecQuery($"select CAT_GP_ID,CAT_GP_NOMBRE,CAT_GP_IMP1,CAT_GP_IMP2,CAT_GP_PRECIO,CAT_GP_CLASIF,CAT_GP_STS,CAT_GP_TIPO,CAT_GP_SUBTIPO,CAT_GP_IMG,CAT_GP_ALMACEN,CAT_GP_DEV  from ${Subs.traeTablaProds(tipo_venta)} where CAT_GP_NOMBRE In (Select PDESC from PROID)"$)
	c.Position=0
	L_PROID.Text = c.GetString("CAT_GP_ID")
	l_tipo.Text = c.GetString("CAT_GP_TIPO")
	l_sub.Text = c.GetString("CAT_GP_SUBTIPO")
	l_marca.Text = c.GetString("CAT_GP_CLASIF")
	l_desc.Text = c.GetString("CAT_GP_NOMBRE")
	l_precio.Text = c.GetDouble("CAT_GP_PRECIO")
	l_bodega.Text = c.GetString("CAT_GP_ALMACEN")
	IMG_PASO = c.GetBlob("CAT_GP_IMG")
	PROMO_C = c.GetString("CAT_GP_STS")
	cambio = c.GetString("CAT_GP_DEV")
	preciosin = c.GetString("CAT_GP_IMP2")
	PROMO_CR = c.GetString("CAT_GP_IMP1")
	cambio = "0"

	e=B4XPages.MainPage.skmt.ExecQuery2("select count(*) as CUANTOS FROM pedido WHERE PE_CEDIS = ? AND PE_CLIENTE  IN (Select cuenta from cuentaa) ", Array As String(c.GetString("CAT_GP_ID")))
	e.Position =0
	If e.GetString("CUANTOS") = 0 Then
		If l_marca.text = "PROMOS" And l_tipo.Text ="PROMOS" Then
			DESC_PROMO.Visible = True
			CC=B4XPages.MainPage.skmt.ExecQuery2("select count(*) as CUANTOS FROM PROMOS_COMP WHERE CAT_PA_ID = ?", Array As String(c.GetString("CAT_GP_ID")))
			CC.Position =0
			If CC.GetString("CUANTOS") = 0 Then
				l_bodega.Text = "0" ' se modifica a cero para evitar error en la promo especial de unilever mayo
			Else
				CC.Close
				CC=B4XPages.MainPage.skmt.ExecQuery2("select CAT_PA_MAXPROM, CAT_PA_MAXPROMREC, CAT_PA_MAXPROMCLIE FROM PROMOS_COMP WHERE CAT_PA_ID = ?", Array As String(c.GetString("CAT_GP_ID")))
				CC.Position =0
				' SE MODIFICA LA APLICACION PARA QUE VEA EL HISTORIAL DE VENTA DEL CLIENTE.
				DD=B4XPages.MainPage.skmt.ExecQuery2("SELECT COUNT(*) AS CUANTOS FROM HIST_CLIENTE_CANT_PROMOS WHERE HCCP_CLIENTE IN (Select cuenta from cuentaa) AND HCCP_PROMO =?", Array As String(c.GetString("CAT_GP_ID")))
				DD.Position =0
				If DD.GetString("CUANTOS")  = 0 Then
					HCCP_CANT = 0
				Else
					DD.Close
					DD=B4XPages.MainPage.skmt.ExecQuery2("SELECT HCCP_CANT FROM HIST_CLIENTE_CANT_PROMOS WHERE HCCP_CLIENTE IN (Select cuenta from cuentaa) AND HCCP_PROMO =?", Array As String(c.GetString("CAT_GP_ID")))
					DD.Position =0
					HCCP_CANT = DD.GetString("HCCP_CANT")
					DD.Close
				End If
				BONSABOR = HCCP_CANT
				DD=B4XPages.MainPage.skmt.ExecQuery2("SELECT COUNT(*) AS CUANTOS FROM HIST_VENTAS WHERE HVD_CLIENTE IN (Select cuenta from cuentaa) AND HVD_PRONOMBRE =?", Array As String(c.GetString("CAT_GP_NOMBRE")))
				DD.Position =0
				If DD.GetString("CUANTOS")  = 0 Then
					HCCP_CANT = 0
				Else
					DD.Close
					DD=B4XPages.MainPage.skmt.ExecQuery2("SELECT SUM(HVD_CANT) AS HCCP_CANT FROM HIST_VENTAS WHERE HVD_CLIENTE IN (Select cuenta from cuentaa) AND HVD_PRONOMBRE =?", Array As String(c.GetString("CAT_GP_NOMBRE")))
					DD.Position =0
					HCCP_CANT = DD.GetString("HCCP_CANT")
					DD.Close
				End If
				DD=B4XPages.MainPage.skmt.ExecQuery2($"Select COUNT(*) AS CUANTOS FROM PEDIDO WHERE PE_CLIENTE IN  (Select cuenta from cuentaa) AND  PE_PROID IN (select CAT_GP_ID   from ${Subs.traeTablaProds(tipo_venta)} where CAT_GP_CLASIF = ?) "$,Array As String(c.GetString("CAT_GP_NOMBRE")))
				DD.Position =0
				BONSABOR2 = DD.GetString("CUANTOS")
				DD.Close
				TOTAL_PROMO = CC.GetString("CAT_PA_MAXPROMCLIE") - HCCP_CANT
				If HCCP_CANT = 0 Then
					l_bodega.Text = CC.GetString("CAT_PA_MAXPROM")
				Else IF TOTAL_PROMO > CC.GetString("CAT_PA_MAXPROMREC") Then
					l_bodega.Text = 	CC.GetString("CAT_PA_MAXPROMREC")
				Else
					l_bodega.Text = TOTAL_PROMO
				End If
			End If
		Else
			DESC_PROMO.Visible = False
		End If
		c.Close
		c=B4XPages.MainPage.skmt.ExecQuery("select CASE WHEN pe_costo_tot is null then 0 else  sum( pe_costo_tot ) end as TOTAL_CLIE FROM PEDIDO WHERE PE_CLIENTE IN (Select CUENTA from cuentaa)")
		c.Position=0
		t_venta.Text = c.GetString("TOTAL_CLIE")
		c.Close
		Terminar.Visible = True
		guardar.Visible = True
		cantidad.Visible = True
		If cambio = "1" Then
			nopromo.Visible = True
		Else
			nopromo.Visible = False
		End If
		Dim out As OutputStream
		out = File.OpenOutput(ruta, "1.jpg", False)
		out.WriteBytes(IMG_PASO, 0, IMG_PASO.Length)
		out.Close
		img_prod.Bitmap = LoadBitmap(ruta,"1.jpg")
		TOT_ART_PROMO = "0"
		TOT_ART_PROMOR = "0"
		If l_marca.text = "PROMOS" And l_tipo.Text ="PROMOS" And l_bodega.Text = "0"  Then
			Msgbox("ALERTA","EL CLIENTE NO PUEDE TENER ESTA PROMOCION") 'ignore
			B4XPages.ShowPage("Productos")
		ELSE IF l_marca.text = "PROMOS" And l_tipo.Text ="PROMOS" And L_PROID.Text = "PROUNI1" And BONSABOR <> "1" And BONSABOR2 = 0 Then
			Msgbox("ALERTA","EL CLIENTE NO PUEDE TENER ESTA PROMOCION") 'ignore
			B4XPages.ShowPage("Productos")
		End If
	Else
		Msgbox("ALERTA","EL CLIENTE YA COMPRO ESTE PRODUCTO REVISAR NOTA") 'ignore
		B4XPages.ShowPage("Productos")
	End If
End Sub

Sub guardar_Click
	If cantidad.Text = "" Then
		B4XPages.ShowPage("Productos")
	ELSE If cantidad.Text > l_bodega.Text Then
		Msgbox("Exede la existencia", "ADVERTENCIA") 'ignore
	Else If l_marca.text = "PROMOS" And l_tipo.Text ="PROMOS" And PROMO_C > 0 And cantidad.Text > 0 Then
		B4XPages.MainPage.skmt.ExecNonQuery("delete from PROIDID")
		B4XPages.MainPage.skmt.ExecNonQuery2("INSERT INTO PROIDID VALUES (?)", Array As Object(L_PROID.text))
		c=B4XPages.MainPage.skmt.ExecQuery("Select count(*) as CUANTOSD from pedido where PE_CLIENTE IN (Select CUENTA from cuentaa)  and pe_proid In (Select cat_dp_idprod from CAT_DETALLES_PAQ WHERE CAT_DP_ID In (Select PROIDID from PROIDID) AND CAT_DP_TIPO = 1)")
		c.Position =0
		If c.GetString("CUANTOSD") = 0 Then
			Msgbox("No tiene venta el cliente para la promo", "ADVERTENCIA") 'ignore
		Else
			c=B4XPages.MainPage.skmt.ExecQuery("Select sum(pe_cant) As TOT_ART_PROMO, sum(PE_COSTO_TOT) as COSTO_TOT from pedido where PE_CLIENTE IN (Select CUENTA from cuentaa)  and pe_proid In (Select cat_dp_idprod from CAT_DETALLES_PAQ WHERE CAT_DP_ID In (Select PROIDID from PROIDID) AND CAT_DP_PRECIO > 1)")
			C.Position =0
			TOT_ART_PROMO = C.GetString("TOT_ART_PROMO")
			COSTO_TOT = C.GetString("COSTO_TOT")
			C.Close
			c=B4XPages.MainPage.skmt.ExecQuery("Select count(*) as CUANTOSD from pedido where PE_CLIENTE IN (Select CUENTA from cuentaa)  and pe_proid In (Select cat_dp_idprod from CAT_DETALLES_PAQ WHERE CAT_DP_ID In (Select PROIDID from PROIDID) AND (CAT_DP_PRECIO = 0.01 or CAT_DP_PRECIO = 1 OR CAT_DP_PRECIO = 0) AND CAT_DP_TIPO = 1)")
			c.Position =0
			If c.GetString("CUANTOSD") = 0 Then
				TOT_ART_PROMOR = "0" 'Msgbox("No tiene venta el cliente para la promo", "ADVERTENCIA")
			Else
				c=B4XPages.MainPage.skmt.ExecQuery("Select sum(pe_cant) As TOT_ART_PROMO, sum(PE_COSTO_TOT) as COSTO_TOT from pedido where PE_CLIENTE IN (Select CUENTA from cuentaa)  and pe_proid In (Select cat_dp_idprod from CAT_DETALLES_PAQ WHERE CAT_DP_ID In (Select PROIDID from PROIDID) AND (CAT_DP_PRECIO = 0.01 or CAT_DP_PRECIO = 1 OR CAT_DP_PRECIO = 0) AND CAT_DP_TIPO = 1)")
				C.Position =0
				TOT_ART_PROMOR = C.GetString("TOT_ART_PROMO")
			End If
			C.Close
			PROMO_C = PROMO_C * cantidad.Text
			PROMO_CR = PROMO_CR * cantidad.Text
			If  TOT_ART_PROMO = PROMO_C And TOT_ART_PROMOR = PROMO_CR Then
				B4XPages.MainPage.skmt.ExecNonQuery2("UPDATE PEDIDO SET PE_CEDIS = (?) WHERE PE_CLIENTE IN (Select CUENTA from cuentaa) and pe_proid In (Select cat_dp_idprod from CAT_DETALLES_PAQ WHERE CAT_DP_ID In (Select PROIDID from PROIDID))", Array As Object(L_PROID.text))
				D=B4XPages.MainPage.skmt.ExecQuery("select CAT_DP_ID, CAT_DP_PRECIO, CAT_DP_PRECIO_SIMPTOS, CAT_DP_IDPROD FROM CAT_DETALLES_PAQ WHERE CAT_DP_ID IN (Select PROIDID from PROIDID) AND CAT_DP_PRECIO > 1")
				If D.RowCount>0 Then
					For i=0 To D.RowCount -1
						D.Position=i
						B4XPages.MainPage.skmt.ExecNonQuery2("UPDATE PEDIDO SET PE_COSTOU = (?), PE_COSTO_TOT = PE_CANT * (?) , PE_COSTO_SIN = (?) WHERE PE_PROID = (?) And PE_CEDIS In (Select PROIDID from PROIDID) AND  PE_CLIENTE IN (Select CUENTA from cuentaa) ",Array As Object( D.GetString("CAT_DP_PRECIO"), D.GetString("CAT_DP_PRECIO"), D.GetString("CAT_DP_PRECIO_SIMPTOS"),D.GetString("CAT_DP_IDPROD")))
					Next
				End If
				D.Close
				D=B4XPages.MainPage.skmt.ExecQuery("select CAT_DP_ID, CAT_DP_PRECIO, CAT_DP_PRECIO_SIMPTOS, CAT_DP_IDPROD FROM CAT_DETALLES_PAQ WHERE CAT_DP_ID IN (Select PROIDID from PROIDID) AND (CAT_DP_PRECIO = 0.01 or CAT_DP_PRECIO = 1 OR CAT_DP_PRECIO = 0) AND CAT_DP_TIPO = 1")
				If D.RowCount>0 Then
					For i=0 To D.RowCount -1
						D.Position=i
						B4XPages.MainPage.skmt.ExecNonQuery2("UPDATE PEDIDO SET PE_COSTOU = (?), PE_COSTO_TOT = PE_CANT * (?) , PE_COSTO_SIN = (?) WHERE PE_PROID = (?) And PE_CEDIS In (Select PROIDID from PROIDID) AND  PE_CLIENTE IN (Select CUENTA from cuentaa) ",Array As Object( D.GetString("CAT_DP_PRECIO"), D.GetString("CAT_DP_PRECIO"), D.GetString("CAT_DP_PRECIO_SIMPTOS"),D.GetString("CAT_DP_IDPROD")))
					Next
				End If
				D.Close
				DateTime.DateFormat = "MM/dd/yyyy"
				sDate=DateTime.Date(DateTime.Now)
				sTime=DateTime.Time(DateTime.Now)
				c=B4XPages.MainPage.skmt.ExecQuery("Select CUENTA from cuentaa")
				c.Position=0
				clie_id = c.GetString("CUENTA")
				c.Close
				c=B4XPages.MainPage.skmt.ExecQuery("select CAT_CL_RUTA from kmt_info3 where CAT_CL_CODIGO In (Select cuenta from cuentaa)")
				c.Position=0
				cl_ruta = c.GetString("CAT_CL_RUTA")
				c.Close
				c=B4XPages.MainPage.skmt.ExecQuery("select USUARIO from usuarioa")
				c.Position=0
				usuario = c.GetString("USUARIO")
				e=B4XPages.MainPage.skmt.ExecQuery("select count(*) as CUANTOS FROM CAT_DETALLES_PAQ WHERE CAT_DP_ID IN (Select PROIDID from PROIDID) and CAT_DP_TIPO = 0 ")
				' SE LO QUITE DE CONDICION AND (CAT_DP_PRECIO = 0.01 or CAT_DP_PRECIO = 1 OR CAT_DP_PRECIO = 0)
				e.Position =0
				If e.GetString("CUANTOS") > 0 Then
					F=B4XPages.MainPage.skmt.ExecQuery("select CAT_DP_IDPROD, CAT_DP_PZAS,CAT_DP_PRECIO FROM CAT_DETALLES_PAQ WHERE CAT_DP_ID IN (Select PROIDID from PROIDID) and CAT_DP_TIPO = 0 ") ' AND (CAT_DP_PRECIO = 0.01 or CAT_DP_PRECIO = 1 OR CAT_DP_PRECIO = 0)
					'meter el otro
					'si jala copiar para guna y el resto
					If f.RowCount>0 Then
						For i=0 To f.RowCount -1
							f.Position=i
							precio_Cero = f.GetString("CAT_DP_PRECIO")
							h=B4XPages.MainPage.skmt.ExecQuery2($"select CAT_GP_NOMBRE from ${Subs.traeTablaProds(tipo_venta)} where CAT_GP_ID = ? "$, Array As String(f.GetString("CAT_DP_IDPROD")))
							h.Position=0
							'0
							B4XPages.MainPage.skmt.ExecNonQuery2("INSERT INTO  PEDIDO (PE_CEDIS,PE_COSTO_TOT,PE_COSTOU,PE_CANT,PE_PRONOMBRE,PE_PROID,PE_CLIENTE,PE_FECHA,PE_USUARIO,PE_RUTA) VALUES(?,?,?,?,?,?,?,?,?,?) ", Array As Object (L_PROID.text,precio_Cero *  f.GetString("CAT_DP_PZAS") * cantidad.text, precio_Cero, f.GetString("CAT_DP_PZAS") * cantidad.text, h.GetString("CAT_GP_NOMBRE"), f.GetString("CAT_DP_IDPROD"),clie_id, sDate & sTime, usuario,cl_ruta))
							h.Close
						Next
					End If
					f.Close
				End If
				e.Close
				B4XPages.MainPage.skmt.ExecNonQuery2("INSERT INTO  PEDIDO (PE_CEDIS,PE_COSTO_TOT,PE_COSTOU,PE_CANT,PE_PRONOMBRE,PE_PROID,PE_CLIENTE,PE_FECHA,PE_USUARIO,PE_RUTA,PE_FOLIO) VALUES(?,?,?,?,?,?,?,?,?,?,?) ", Array As Object (L_PROID.text,0 , 0, cantidad.text, l_desc.text, L_PROID.Text,clie_id, sDate & sTime, usuario,cl_ruta, B4XPages.MainPage.tipo_venta))
				B4XPages.MainPage.skmt.ExecNonQuery2($"update ${Subs.traeTablaProds(tipo_venta)} set cat_gp_almacen = cat_gp_almacen - ? where cat_gp_id = ? "$, Array As Object(cantidad.Text, L_PROID.Text))
			Else
				Msgbox("Tiene " & TOT_ART_PROMO & " " & TOT_ART_PROMOR & " y necesita " & PROMO_C & " " & PROMO_CR & " Para la Promo. " , "ADVERTENCIA") 'ignore
			End If
		End If
		cantidad.Text = ""
		B4XPages.ShowPage("Productos")
	else If l_marca.text = "PROMOS" And l_tipo.Text ="PROMOS" And PROMO_C = 0 Then
		B4XPages.MainPage.skmt.ExecNonQuery("delete from PROIDID")
		B4XPages.MainPage.skmt.ExecNonQuery2("INSERT INTO PROIDID VALUES (?)", Array As Object(L_PROID.text))
		c=B4XPages.MainPage.skmt.ExecQuery("Select CUENTA from cuentaa")
		c.Position=0
		clie_id = c.GetString("CUENTA")
		c.Close
		DateTime.DateFormat = "MM/dd/yyyy"
		sDate=DateTime.Date(DateTime.Now)
		sTime=DateTime.Time(DateTime.Now)
		c=B4XPages.MainPage.skmt.ExecQuery("select CAT_CL_RUTA from kmt_info3 where CAT_CL_CODIGO In (Select cuenta from cuentaa)")
		c.Position=0
		cl_ruta = c.GetString("CAT_CL_RUTA")
		c.Close
		c=B4XPages.MainPage.skmt.ExecQuery("select USUARIO from usuarioa")
		c.Position=0
		usuario = c.GetString("USUARIO")
		'B4XPages.MainPage.skmt.ExecNonQuery2("INSERT INTO  PEDIDO (PE_CEDIS,PE_COSTO_TOT,PE_COSTOU,PE_CANT,PE_PRONOMBRE,PE_PROID,PE_CLIENTE,PE_FECHA,PE_USUARIO) VALUES(?,?,?,?,?,?,?,?,?) ", Array As Object ("COACALCO",cantidad.Text * l_precio.Text, l_precio.text, cantidad.text, l_desc.text, L_PROID.Text,clie_id, sDate & sTime, usuario))
		'para insertar la promo de ades el de regalo en 0
		e=B4XPages.MainPage.skmt.ExecQuery("select count(*) as CUANTOS FROM CAT_DETALLES_PAQ WHERE CAT_DP_ID IN (Select PROIDID from PROIDID) ")
		e.Position =0
		If e.GetString("CUANTOS") > 0 Then
			F=B4XPages.MainPage.skmt.ExecQuery("select CAT_DP_IDPROD, CAT_DP_PZAS, CAT_DP_PRECIO FROM CAT_DETALLES_PAQ WHERE CAT_DP_ID IN (Select PROIDID from PROIDID)")
			For i =0 To f.RowCount -1
				F.Position =i
				h=B4XPages.MainPage.skmt.ExecQuery2($"select CAT_GP_NOMBRE from ${Subs.traeTablaProds(tipo_venta)} where CAT_GP_ID = ? "$, Array As String(f.GetString("CAT_DP_IDPROD")))
				h.Position=0
				B4XPages.MainPage.skmt.ExecNonQuery2("INSERT INTO  PEDIDO (PE_CEDIS,PE_COSTO_TOT,PE_COSTOU,PE_CANT,PE_PRONOMBRE,PE_PROID,PE_CLIENTE,PE_FECHA,PE_USUARIO,PE_RUTA,PE_FOLIO) VALUES(?,?,?,?,?,?,?,?,?,?,?) ", Array As Object (L_PROID.text,f.GetString("CAT_DP_PRECIO") * cantidad.text * f.GetString("CAT_DP_PZAS"), f.GetString("CAT_DP_PRECIO"), f.GetString("CAT_DP_PZAS") * cantidad.text, h.GetString("CAT_GP_NOMBRE"), f.GetString("CAT_DP_IDPROD"),clie_id, sDate & sTime, usuario,cl_ruta, B4XPages.MainPage.tipo_venta))
				h.Close
			Next
			f.Close
		End If
		e.Close
		'0
		B4XPages.MainPage.skmt.ExecNonQuery2("INSERT INTO PEDIDO (PE_CEDIS,PE_COSTO_TOT,PE_COSTOU,PE_CANT,PE_PRONOMBRE,PE_PROID,PE_CLIENTE,PE_FECHA,PE_USUARIO,PE_RUTA,PE_FOLIO) VALUES(?,?,?,?,?,?,?,?,?,?,?) ", Array As Object (L_PROID.text,0, 0, cantidad.text, l_desc.text, L_PROID.Text,clie_id, sDate & sTime, usuario,cl_ruta, B4XPages.MainPage.tipo_venta))
		B4XPages.MainPage.skmt.ExecNonQuery2($"update ${Subs.traeTablaProds(tipo_venta)} set cat_gp_almacen = cat_gp_almacen - ? where cat_gp_id = ? "$, Array As Object(cantidad.Text, L_PROID.Text))
		cantidad.Text = ""
		c=B4XPages.MainPage.skmt.ExecQuery("select sum(pe_costo_tot) as TOTAL_CLIE, SUM(PE_CANT) AS CANT_CLIE, SUM(PE_COSTO_SIN) AS TOTAL_CLIE_SIN FROM PEDIDO WHERE PE_CLIENTE IN (Select CUENTA from cuentaa)")
		c.Position=0
		B4XPages.MainPage.skmt.ExecNonQuery("delete from pedido_cliente where PC_CLIENTE In (select cuenta from cuentaa)")
		B4XPages.MainPage.skmt.ExecNonQuery2("insert into pedido_cliente(PC_CLIENTE, PC_FECHA, PC_USER, PC_NOART, PC_MONTO,PC_LON, PC_LAT,PC_ALMACEN,PC_RUTA,PC_COSTO_SIN) VALUES (?,?,?,?,?,?,?,?,?,?)", Array As Object(clie_id, sDate & sTime, usuario, c.GetString("CANT_CLIE"),c.GetString("TOTAL_CLIE"), B4XPages.MainPage.lon_gps, B4XPages.MainPage.lat_gps,ALMACEN,cl_ruta,c.GetString("TOTAL_CLIE_SIN")))
		B4XPages.MainPage.skmt.ExecNonQuery("UPDATE kmt_info3 set gestion = 2  where CAT_CL_CODIGO In (select cuenta from cuentaa)")
		B4XPages.ShowPage("Productos")
	Else
		DateTime.DateFormat = "MM/dd/yyyy"
		sDate=DateTime.Date(DateTime.Now)
		sTime=DateTime.Time(DateTime.Now)
		c=B4XPages.MainPage.skmt.ExecQuery("Select CUENTA from cuentaa")
		c.Position=0
		clie_id = c.GetString("CUENTA")
		c.Close
		c=B4XPages.MainPage.skmt.ExecQuery("select CAT_CL_RUTA from kmt_info3 where CAT_CL_CODIGO In (Select cuenta from cuentaa)")
		c.Position=0
		cl_ruta = c.GetString("CAT_CL_RUTA")
		c.Close
		c=B4XPages.MainPage.skmt.ExecQuery("select USUARIO from usuarioa")
		c.Position=0
		usuario = c.GetString("USUARIO")
		B4XPages.MainPage.skmt.ExecNonQuery2("INSERT INTO PEDIDO (PE_CEDIS,PE_COSTO_TOT,PE_COSTOU,PE_CANT,PE_PRONOMBRE,PE_PROID,PE_CLIENTE,PE_FECHA,PE_USUARIO,PE_RUTA,PE_COSTO_SIN, PE_FOLIO) VALUES(?,?,?,?,?,?,?,?,?,?,?,?) ", Array As Object (ALMACEN,cantidad.Text * l_precio.Text, l_precio.text, cantidad.text, l_desc.text, L_PROID.Text,clie_id, sDate & sTime, usuario,cl_ruta,preciosin, B4XPages.MainPage.tipo_venta))
		B4XPages.MainPage.skmt.ExecNonQuery2($"update ${Subs.traeTablaProds(tipo_venta)} set cat_gp_almacen = cat_gp_almacen - ? where cat_gp_id = ? "$, Array As Object(cantidad.Text, L_PROID.Text))
		c=B4XPages.MainPage.skmt.ExecQuery("select sum(pe_costo_tot) as TOTAL_CLIE, SUM(PE_CANT) AS CANT_CLIE, SUM(PE_COSTO_SIN) AS TOTAL_CLIE_SIN FROM PEDIDO WHERE PE_CLIENTE IN (Select CUENTA from cuentaa)")
		c.Position=0
		B4XPages.MainPage.skmt.ExecNonQuery("delete from pedido_cliente where PC_CLIENTE In (select cuenta from cuentaa)")
		B4XPages.MainPage.skmt.ExecNonQuery2("insert into pedido_cliente(PC_CLIENTE, PC_FECHA, PC_USER, PC_NOART, PC_MONTO,PC_LON, PC_LAT,PC_ALMACEN,PC_RUTA,PC_COSTO_SIN) VALUES (?,?,?,?,?,?,?,?,?,?)", Array As Object(clie_id, sDate & sTime, usuario, c.GetString("CANT_CLIE"),c.GetString("TOTAL_CLIE"), B4XPages.MainPage.lon_gps, B4XPages.MainPage.lat_gps,ALMACEN,cl_ruta,c.GetString("TOTAL_CLIE_SIN")))
		B4XPages.MainPage.skmt.ExecNonQuery("UPDATE kmt_info3 set gestion = 2  where CAT_CL_CODIGO In (select cuenta from cuentaa)")
		B4XPages.MainPage.skmt.ExecNonQuery2("INSERT INTO INVENT_X_ENVIAR (ALMACEN , PROID , CANTIDAD ) VALUES(?,?,?) ", Array As Object (ALMACEN,L_PROID.Text,cantidad.text))
		B4XPages.ShowPage("Productos")
	End If
End Sub

Sub GPS_LocationChanged (Location1 As Location)
	'lat_gps=Location1.ConvertToSeconds(Location1.Latitude)
	'lon_gps=Location1.ConvertToSeconds(Location1.Longitude)
End Sub

Sub Terminar_Click
	If cantidad.Text = "" Then
		B4XPages.ShowPage("Cliente")
	ELSE If cantidad.Text > l_bodega.Text Then
		Msgbox("Exede la existencia", "ADVERTENCIA") 'ignore
	Else If l_marca.text = "PROMOS" And l_tipo.Text ="PROMOS" And PROMO_C > 0 And cantidad.Text > 0 Then
		B4XPages.MainPage.skmt.ExecNonQuery("delete from PROIDID")
		B4XPages.MainPage.skmt.ExecNonQuery2("INSERT INTO PROIDID VALUES (?)", Array As Object(L_PROID.text))
		c=B4XPages.MainPage.skmt.ExecQuery("Select count(*) as CUANTOSD from pedido where PE_CLIENTE IN (Select CUENTA from cuentaa)  and pe_proid In (Select cat_dp_idprod from CAT_DETALLES_PAQ WHERE CAT_DP_ID In (Select PROIDID from PROIDID) AND CAT_DP_TIPO = 1)")
		c.Position =0
		If c.GetString("CUANTOSD") = 0 Then
			Msgbox("No tiene venta el cliente para la promo", "ADVERTENCIA") 'ignore
		Else
			c=B4XPages.MainPage.skmt.ExecQuery("Select sum(pe_cant) As TOT_ART_PROMO, sum(PE_COSTO_TOT) as COSTO_TOT from pedido where PE_CLIENTE IN (Select CUENTA from cuentaa)  and pe_proid In (Select cat_dp_idprod from CAT_DETALLES_PAQ WHERE CAT_DP_ID In (Select PROIDID from PROIDID) AND CAT_DP_PRECIO > 1)")
			C.Position =0
			TOT_ART_PROMO = C.GetString("TOT_ART_PROMO")
			COSTO_TOT = C.GetString("COSTO_TOT")
			C.Close
			c=B4XPages.MainPage.skmt.ExecQuery("Select count(*) as CUANTOSD from pedido where PE_CLIENTE IN (Select CUENTA from cuentaa)  and pe_proid In (Select cat_dp_idprod from CAT_DETALLES_PAQ WHERE CAT_DP_ID In (Select PROIDID from PROIDID) AND (CAT_DP_PRECIO = 0.01 or CAT_DP_PRECIO = 1 OR CAT_DP_PRECIO = 0) AND CAT_DP_TIPO = 1)")
			c.Position =0
			If c.GetString("CUANTOSD") = 0 Then
				TOT_ART_PROMOR = "0" 'Msgbox("No tiene venta el cliente para la promo", "ADVERTENCIA")
			Else
				c=B4XPages.MainPage.skmt.ExecQuery("Select sum(pe_cant) As TOT_ART_PROMO, sum(PE_COSTO_TOT) as COSTO_TOT from pedido where PE_CLIENTE IN (Select CUENTA from cuentaa)  and pe_proid In (Select cat_dp_idprod from CAT_DETALLES_PAQ WHERE CAT_DP_ID In (Select PROIDID from PROIDID) AND (CAT_DP_PRECIO = 0.01 or CAT_DP_PRECIO = 1 OR CAT_DP_PRECIO = 0) AND CAT_DP_TIPO = 1)")
				C.Position =0
				TOT_ART_PROMOR = C.GetString("TOT_ART_PROMO")
			End If
			C.Close
			PROMO_C = PROMO_C * cantidad.Text
			PROMO_CR = PROMO_CR * cantidad.Text
			If  TOT_ART_PROMO = PROMO_C And TOT_ART_PROMOR = PROMO_CR Then
				' anterior a 29/06/2015
				'B4XPages.MainPage.skmt.ExecNonQuery2("UPDATE PEDIDO SET PE_COSTOU = (?), PE_COSTO_TOT = PE_CANT * (?) WHERE PE_CLIENTE IN (Select CUENTA from cuentaa) and pe_proid In (Select cat_dp_idprod from CAT_DETALLES_PAQ WHERE CAT_DP_ID In (Select PROIDID from PROIDID))", Array As Object(l_precio.text/(TOT_ART_PROMO/cantidad.Text),l_precio.text/(TOT_ART_PROMO/cantidad.Text)))
				'en pe_cedis meto el codigo de promocion para hacer esta validacion.
				B4XPages.MainPage.skmt.ExecNonQuery2("UPDATE PEDIDO SET PE_CEDIS = (?) WHERE PE_CLIENTE IN (Select CUENTA from cuentaa) and pe_proid In (Select cat_dp_idprod from CAT_DETALLES_PAQ WHERE CAT_DP_ID In (Select PROIDID from PROIDID))", Array As Object(L_PROID.text))
				D=B4XPages.MainPage.skmt.ExecQuery("select CAT_DP_ID, CAT_DP_PRECIO, CAT_DP_PRECIO_SIMPTOS, CAT_DP_IDPROD FROM CAT_DETALLES_PAQ WHERE CAT_DP_ID IN (Select PROIDID from PROIDID) AND CAT_DP_PRECIO > 1")
				If D.RowCount>0 Then
					For i=0 To D.RowCount -1
						D.Position=i
						B4XPages.MainPage.skmt.ExecNonQuery2("UPDATE PEDIDO SET PE_COSTOU = (?), PE_COSTO_TOT = PE_CANT * (?) , PE_COSTO_SIN = (?) WHERE PE_PROID = (?) And PE_CEDIS In (Select PROIDID from PROIDID) AND  PE_CLIENTE IN (Select CUENTA from cuentaa) ",Array As Object( D.GetString("CAT_DP_PRECIO"), D.GetString("CAT_DP_PRECIO"), D.GetString("CAT_DP_PRECIO_SIMPTOS"),D.GetString("CAT_DP_IDPROD")))
					Next
				End If
				D.Close
				D=B4XPages.MainPage.skmt.ExecQuery("select CAT_DP_ID, CAT_DP_PRECIO, CAT_DP_PRECIO_SIMPTOS, CAT_DP_IDPROD FROM CAT_DETALLES_PAQ WHERE CAT_DP_ID IN (Select PROIDID from PROIDID) AND (CAT_DP_PRECIO = 0.01 or CAT_DP_PRECIO = 1 OR CAT_DP_PRECIO = 0) AND CAT_DP_TIPO = 1")
				If D.RowCount>0 Then
					For i=0 To D.RowCount -1
						D.Position=i
						B4XPages.MainPage.skmt.ExecNonQuery2("UPDATE PEDIDO SET PE_COSTOU = (?), PE_COSTO_TOT = PE_CANT * (?) , PE_COSTO_SIN = (?) WHERE PE_PROID = (?) And PE_CEDIS In (Select PROIDID from PROIDID) AND  PE_CLIENTE IN (Select CUENTA from cuentaa) ",Array As Object( D.GetString("CAT_DP_PRECIO"), D.GetString("CAT_DP_PRECIO"), D.GetString("CAT_DP_PRECIO_SIMPTOS"),D.GetString("CAT_DP_IDPROD")))
					Next
				End If
				D.Close
				DateTime.DateFormat = "MM/dd/yyyy"
				sDate=DateTime.Date(DateTime.Now)
				sTime=DateTime.Time(DateTime.Now)
				c=B4XPages.MainPage.skmt.ExecQuery("Select CUENTA from cuentaa")
				c.Position=0
				clie_id = c.GetString("CUENTA")
				c.Close
				c=B4XPages.MainPage.skmt.ExecQuery("select CAT_CL_RUTA from kmt_info3 where CAT_CL_CODIGO In (Select cuenta from cuentaa)")
				c.Position=0
				cl_ruta = c.GetString("CAT_CL_RUTA")
				c.Close
				c=B4XPages.MainPage.skmt.ExecQuery("select USUARIO from usuarioa")
				c.Position=0
				usuario = c.GetString("USUARIO")
				'para insertar la promo de ades el de regalo en 0
				e=B4XPages.MainPage.skmt.ExecQuery("select count(*) as CUANTOS FROM CAT_DETALLES_PAQ WHERE CAT_DP_ID IN (Select PROIDID from PROIDID) and CAT_DP_TIPO = 0 ")
				' SE LO QUITE DE CONDICION AND (CAT_DP_PRECIO = 0.01 or CAT_DP_PRECIO = 1 OR CAT_DP_PRECIO = 0)
				e.Position =0
				If e.GetString("CUANTOS") > 0 Then
					F=B4XPages.MainPage.skmt.ExecQuery("select CAT_DP_IDPROD, CAT_DP_PZAS,CAT_DP_PRECIO FROM CAT_DETALLES_PAQ WHERE CAT_DP_ID IN (Select PROIDID from PROIDID) and CAT_DP_TIPO = 0 ") ' AND (CAT_DP_PRECIO = 0.01 or CAT_DP_PRECIO = 1 OR CAT_DP_PRECIO = 0)
					'meter el otro
					'si jala copiar para guna y el resto
					If f.RowCount>0 Then
						For i=0 To f.RowCount -1
							f.Position=i
							precio_Cero = f.GetString("CAT_DP_PRECIO")
							h=B4XPages.MainPage.skmt.ExecQuery2($"select CAT_GP_NOMBRE from ${Subs.traeTablaProds(tipo_venta)} where CAT_GP_ID = ? "$, Array As String(f.GetString("CAT_DP_IDPROD")))
							h.Position=0
							Log(111)
							B4XPages.MainPage.skmt.ExecNonQuery2("INSERT INTO  PEDIDO (PE_CEDIS,PE_COSTO_TOT,PE_COSTOU,PE_CANT,PE_PRONOMBRE,PE_PROID,PE_CLIENTE,PE_FECHA,PE_USUARIO,PE_RUTA,PE_FOLIO) VALUES(?,?,?,?,?,?,?,?,?,?,?) ", Array As Object (L_PROID.text,precio_Cero *  f.GetString("CAT_DP_PZAS") * cantidad.text, precio_Cero, f.GetString("CAT_DP_PZAS") * cantidad.text, h.GetString("CAT_GP_NOMBRE"), f.GetString("CAT_DP_IDPROD"),clie_id, sDate & sTime, usuario,cl_ruta, B4XPages.MainPage.tipo_venta))
							h.Close
						Next
					End If
					f.Close
				End If
				e.Close
				Log(222)
				B4XPages.MainPage.skmt.ExecNonQuery2("INSERT INTO PEDIDO (PE_CEDIS,PE_COSTO_TOT,PE_COSTOU,PE_CANT,PE_PRONOMBRE,PE_PROID,PE_CLIENTE,PE_FECHA,PE_USUARIO,PE_RUTA,PE_FOLIO) VALUES(?,?,?,?,?,?,?,?,?,?,?) ", Array As Object (L_PROID.text,0 , 0, cantidad.text, l_desc.text, L_PROID.Text,clie_id, sDate & sTime, usuario,cl_ruta, B4XPages.MainPage.tipo_venta))
				B4XPages.MainPage.skmt.ExecNonQuery2($"update ${Subs.traeTablaProds(tipo_venta)} set cat_gp_almacen = cat_gp_almacen - ? where cat_gp_id = ? "$, Array As Object(cantidad.Text, L_PROID.Text))
			Else
				Msgbox("Tiene " & TOT_ART_PROMO & " " & TOT_ART_PROMOR & " y necesita " & PROMO_C & " " & PROMO_CR & " Para la Promo. " , "ADVERTENCIA") 'ignore
			End If
		End If
		cantidad.Text = ""
		B4XPages.ShowPage("Cliente")
	else If l_marca.text = "PROMOS" And l_tipo.Text ="PROMOS" And PROMO_C = 0 Then
		B4XPages.MainPage.skmt.ExecNonQuery("delete from PROIDID")
		B4XPages.MainPage.skmt.ExecNonQuery2("INSERT INTO PROIDID VALUES (?)", Array As Object(L_PROID.text))
		c=B4XPages.MainPage.skmt.ExecQuery("Select CUENTA from cuentaa")
		c.Position=0
		clie_id = c.GetString("CUENTA")
		c.Close
		DateTime.DateFormat = "MM/dd/yyyy"
		sDate=DateTime.Date(DateTime.Now)
		sTime=DateTime.Time(DateTime.Now)
		c=B4XPages.MainPage.skmt.ExecQuery("select CAT_CL_RUTA from kmt_info3 where CAT_CL_CODIGO In (Select cuenta from cuentaa)")
		c.Position=0
		cl_ruta = c.GetString("CAT_CL_RUTA")
		c.Close
		c=B4XPages.MainPage.skmt.ExecQuery("select USUARIO from usuarioa")
		c.Position=0
		usuario = c.GetString("USUARIO")
		'para insertar la promo de ades el de regalo en 0
		e=B4XPages.MainPage.skmt.ExecQuery("select count(*) as CUANTOS FROM CAT_DETALLES_PAQ WHERE CAT_DP_ID IN (Select PROIDID from PROIDID) ")
		e.Position =0
		If e.GetString("CUANTOS") > 0 Then
			F=B4XPages.MainPage.skmt.ExecQuery("select CAT_DP_IDPROD, CAT_DP_PZAS, CAT_DP_PRECIO FROM CAT_DETALLES_PAQ WHERE CAT_DP_ID IN (Select PROIDID from PROIDID)")
			For i =0 To f.RowCount -1
				F.Position =i
				h=B4XPages.MainPage.skmt.ExecQuery2($"select CAT_GP_NOMBRE from ${Subs.traeTablaProds(tipo_venta)} where CAT_GP_ID = ? "$, Array As String(f.GetString("CAT_DP_IDPROD")))
				h.Position=0
				Log(333)
				B4XPages.MainPage.skmt.ExecNonQuery2("INSERT INTO  PEDIDO (PE_CEDIS,PE_COSTO_TOT,PE_COSTOU,PE_CANT,PE_PRONOMBRE,PE_PROID,PE_CLIENTE,PE_FECHA,PE_USUARIO,PE_RUTA,PE_FOLIO) VALUES(?,?,?,?,?,?,?,?,?,?,?) ", Array As Object (L_PROID.text,f.GetString("CAT_DP_PRECIO") * cantidad.text * f.GetString("CAT_DP_PZAS"), f.GetString("CAT_DP_PRECIO"), f.GetString("CAT_DP_PZAS") * cantidad.text, h.GetString("CAT_GP_NOMBRE"), f.GetString("CAT_DP_IDPROD"),clie_id, sDate & sTime, usuario,cl_ruta, B4XPages.MainPage.tipo_venta))
				h.Close
			Next
			f.Close
		End If
		e.Close
		Log(444)
		B4XPages.MainPage.skmt.ExecNonQuery2("INSERT INTO PEDIDO (PE_CEDIS,PE_COSTO_TOT,PE_COSTOU,PE_CANT,PE_PRONOMBRE,PE_PROID,PE_CLIENTE,PE_FECHA,PE_USUARIO,PE_RUTA,PE_FOLIO) VALUES(?,?,?,?,?,?,?,?,?,?,?) ", Array As Object (L_PROID.text,0, 0, cantidad.text, l_desc.text, L_PROID.Text,clie_id, sDate & sTime, usuario,cl_ruta, B4XPages.MainPage.tipo_venta))
		B4XPages.MainPage.skmt.ExecNonQuery2($"update ${Subs.traeTablaProds(tipo_venta)} set cat_gp_almacen = cat_gp_almacen - ? where cat_gp_id = ? "$, Array As Object(cantidad.Text, L_PROID.Text))
		cantidad.Text = ""
		c=B4XPages.MainPage.skmt.ExecQuery("select sum(pe_costo_tot) as TOTAL_CLIE, SUM(PE_CANT) AS CANT_CLIE, SUM(PE_COSTO_SIN) AS TOTAL_CLIE_SIN FROM PEDIDO WHERE PE_CLIENTE IN (Select CUENTA from cuentaa)")
		c.Position=0
		B4XPages.MainPage.skmt.ExecNonQuery("delete from pedido_cliente where PC_CLIENTE In (select cuenta from cuentaa)")
		B4XPages.MainPage.skmt.ExecNonQuery2("insert into pedido_cliente(PC_CLIENTE, PC_FECHA, PC_USER, PC_NOART, PC_MONTO,PC_LON, PC_LAT,PC_ALMACEN,PC_RUTA,PC_COSTO_SIN) VALUES (?,?,?,?,?,?,?,?,?,?)", Array As Object(clie_id, sDate & sTime, usuario, c.GetString("CANT_CLIE"),c.GetString("TOTAL_CLIE"), B4XPages.MainPage.lon_gps, B4XPages.MainPage.lat_gps,ALMACEN,cl_ruta,c.GetString("TOTAL_CLIE_SIN")))
		B4XPages.MainPage.skmt.ExecNonQuery("UPDATE kmt_info3 set gestion = 2  where CAT_CL_CODIGO In (select cuenta from cuentaa)")
		B4XPages.ShowPage("Cliente")
	Else
		DateTime.DateFormat = "MM/dd/yyyy"
		sDate=DateTime.Date(DateTime.Now)
		sTime=DateTime.Time(DateTime.Now)
		c=B4XPages.MainPage.skmt.ExecQuery("Select CUENTA from cuentaa")
		c.Position=0
		clie_id = c.GetString("CUENTA")
		c.Close
		c=B4XPages.MainPage.skmt.ExecQuery("select CAT_CL_RUTA from kmt_info3 where CAT_CL_CODIGO In (Select cuenta from cuentaa)")
		c.Position=0
		cl_ruta = c.GetString("CAT_CL_RUTA")
		c.Close
		c=B4XPages.MainPage.skmt.ExecQuery("select USUARIO from usuarioa")
		c.Position=0
		usuario = c.GetString("USUARIO")
		Log(555)
		B4XPages.MainPage.skmt.ExecNonQuery2("INSERT INTO PEDIDO (PE_CEDIS,PE_COSTO_TOT,PE_COSTOU,PE_CANT,PE_PRONOMBRE,PE_PROID,PE_CLIENTE,PE_FECHA,PE_USUARIO,PE_RUTA,PE_COSTO_SIN,PE_FOLIO) VALUES(?,?,?,?,?,?,?,?,?,?,?,?) ", Array As Object (ALMACEN,cantidad.Text * l_precio.Text, l_precio.text, cantidad.text, l_desc.text, L_PROID.Text,clie_id, sDate & sTime, usuario,cl_ruta,preciosin, B4XPages.MainPage.tipo_venta))
		B4XPages.MainPage.skmt.ExecNonQuery2($"update ${Subs.traeTablaProds(tipo_venta)} set cat_gp_almacen = cat_gp_almacen - ? where cat_gp_id = ? "$, Array As Object(cantidad.Text, L_PROID.Text))
		c=B4XPages.MainPage.skmt.ExecQuery("select sum(pe_costo_tot) as TOTAL_CLIE, SUM(PE_CANT) AS CANT_CLIE, SUM(PE_COSTO_SIN) AS TOTAL_CLIE_SIN FROM PEDIDO WHERE PE_CLIENTE IN (Select CUENTA from cuentaa)")
		c.Position=0
		B4XPages.MainPage.skmt.ExecNonQuery("delete from pedido_cliente where PC_CLIENTE In (select cuenta from cuentaa)")
		B4XPages.MainPage.skmt.ExecNonQuery2("insert into pedido_cliente(PC_CLIENTE, PC_FECHA, PC_USER, PC_NOART, PC_MONTO,PC_LON, PC_LAT,PC_ALMACEN,PC_RUTA,PC_COSTO_SIN) VALUES (?,?,?,?,?,?,?,?,?,?)", Array As Object(clie_id, sDate & sTime, usuario, c.GetString("CANT_CLIE"),c.GetString("TOTAL_CLIE"), B4XPages.MainPage.lon_gps, B4XPages.MainPage.lat_gps,ALMACEN,cl_ruta,c.GetString("TOTAL_CLIE_SIN")))
		B4XPages.MainPage.skmt.ExecNonQuery("UPDATE kmt_info3 set gestion = 2  where CAT_CL_CODIGO In (select cuenta from cuentaa)")
		B4XPages.MainPage.skmt.ExecNonQuery2("INSERT INTO INVENT_X_ENVIAR (ALMACEN , PROID , CANTIDAD ) VALUES(?,?,?) ", Array As Object (ALMACEN,L_PROID.Text,cantidad.text))
		B4XPages.ShowPage("Cliente")
	End If
End Sub

Private Sub B4XPage_CloseRequest As ResumableSub
'	BACK key pressed
'	Return True To close, False To cancel
	Msgbox("Presione Boton Terminar.","ADVERTENCIA") 'ignore
	Return False
End Sub

Sub img_prod_Click
	i_fotol.Visible = True
	i_fotol.Bitmap = LoadBitmap(ruta,"1.jpg")
	
End Sub
Sub i_fotol_Click
	i_fotol.Visible = False

End Sub

Sub DESC_PROMO_Click
	B4XPages.MainPage.skmt.ExecNonQuery("delete from PROIDID")
	B4XPages.MainPage.skmt.ExecNonQuery2("INSERT INTO PROIDID VALUES (?)", Array As Object(L_PROID.text))
	B4XPages.ShowPage("detalle_promo")
End Sub

Sub nopromo_Click
	If cantidad.Text = "" Then
		Msgbox("Cantidad no puede ser 0","Cantidad") 'ignore
	Else If cantidad.Text > l_bodega.Text Then
		Msgbox("Exede la existencia", "ADVERTENCIA") 'ignore
	Else
		DateTime.DateFormat = "MM/dd/yyyy"
		sDate=DateTime.Date(DateTime.Now)
		sTime=DateTime.Time(DateTime.Now)
		c=B4XPages.MainPage.skmt.ExecQuery("Select CUENTA from cuentaa")
		c.Position=0
		clie_id = c.GetString("CUENTA")
		c=B4XPages.MainPage.skmt.ExecQuery("select USUARIO from usuarioa")
		c.Position=0
		usuario = c.GetString("USUARIO")
		B4XPages.MainPage.skmt.ExecNonQuery2("INSERT INTO  PEDIDO (PE_CEDIS,PE_COSTO_TOT,PE_COSTOU,PE_CANT,PE_PRONOMBRE,PE_PROID,PE_CLIENTE,PE_FECHA,PE_USUARIO,PE_FOLIO) VALUES(?,?,?,?,?,?,?,?,?,?) ", Array As Object ("COACALCO",0,0, cantidad.text, l_desc.text, L_PROID.Text,clie_id, sDate & sTime, usuario, B4XPages.MainPage.tipo_venta))
		B4XPages.MainPage.skmt.ExecNonQuery2($"update ${Subs.traeTablaProds(tipo_venta)} set cat_gp_almacen = cat_gp_almacen - ? where cat_gp_id = ? "$, Array As Object(cantidad.Text, L_PROID.Text))
		cantidad.Text = ""
		B4XPages.ShowPage("Productos")
	End If
End Sub

Private Sub p_pedido_Click
	
End Sub