B4A=true
Group=Default Group
ModulesStructureVersion=1
Type=Class
Version=12.2
@EndOfDesignText@
'Sub Class_Globals
'	Private Root As B4XView 'ignore
'	Private xui As XUI 'ignore
'	Dim g As GPS
'	Dim q_buscar As String
'	
'	Dim c As Cursor
'	Dim c2 As Cursor
'	Dim ListView1 As ListView
'	Dim entro As String
'	Dim lfila As Label
'	Dim marca As String
'	Dim tipo As String
'	Private BUSCA As EditText
'	Dim ya_entro As String
'	Dim bmp As Bitmap
'	
'	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 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
'	Private Panel1 As Panel
'	Dim query As String
'	Private t_precio As Label
'	Private LV_PRECIOS As ListView
'	Private PERFIL As String
'	Private EXISTE_CAMBIO As String
'	Private QUERY2 As String
'	Dim CAMBIOS As String
'	Dim precio2 As String
'	Private B_MENOS As Button
'	Private B_MAS As Button
'	Private p_prods As Panel
'	Private l_prodX As Label
'	Private l_pCant As Label
'	Private et_pCant As EditText
'	Private clv_productos As CustomListView
'	Dim etCantHasFocus As Boolean = False
'	Dim totalProds As Int = 0
'	Dim totalCompra As Int = 0
'	Dim prodsMap As Map
'	Dim prodsListId, prodsList, prodsListCliOrig As List
'	Private l_totProds As Label
'	Private l_total As Label
'	Private b_terminar1 As Button
'	Private p_botonesVenta As Panel
'	Private l_vendido As Label
'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
'	g.Initialize("GPS")
'	'Do not forget to load the layout file created with the visual designer. For example:
'	'Activity.LoadLayout("Layout1")
'	Root.RemoveAllViews
'	Root.LoadLayout("productos")
'	Panel1.Visible= False
'End Sub
'
''You can see the list of page related events in the B4XPagesManager object. The event name is B4XPage.
'
'Sub B4XPage_Appear
'	query = "cat_gunaprod"
'	QUERY2 = "CAT_GUNAPROD"
'	prodsMap.Initialize
'	prodsList.Initialize
'	prodsListId.Initialize
'	prodsListCliOrig.Initialize
'	If ya_entro <> "1" Then
'		'BUSCA.Text =""
'		'SE COMENTO LA LINEA DE ARRIBA YA QUE DISPARA EL EVENTO DEL TEXTCHANGE Y PUEDE HACER LENTO EL SISTEMA
'		Starter.skmt.Initialize(Starter.ruta,"kmt.db", True)
'		entro ="1"
'		ya_entro ="1"
'		c=Starter.skmt.ExecQuery("select CAT_GP_CLASIF, COUNT(*) AS CUANTOS from " & query & " WHERE CAT_GP_ALMACEN > 0 GROUP BY CAT_GP_CLASIF order by CAT_GP_CLASIF asc")
'		
'		'ESTO ES PARA NO VER PROCTER
'		'c=skmt.ExecQuery2("select CAT_GP_CLASIF, count(*) as cuantos from cat_gunaprod where CAT_GP_ALMACEN > 0 and cat_gp_clasif NOT IN (?,?,?,?,?,?,?,?,?,?) group by CAT_GP_CLASIF order by CAT_GP_CLASIF asc", Array As String("PROCTER","PROMOS","TRES MONTES","CAMPARI","CAMPARI-PRO","CLOROX DE MEXICO","MARS","CONAGRA","VERDE VALLE","MEAD JOHNSON"))
'		ListView1.Clear
'		lfila.Text = "MARCA"
'		Dim label1 As Label
'		label1 = ListView1.TwoLinesLayout.Label
'		label1.TextSize = 10
'		label1.TextColor = Colors.Black
'		Dim label2 As Label
'		label2 = ListView1.TwoLinesLayout.SecondLabel
'		label2.TextSize = 10
'		label2.TextColor = Colors.Black
'		If c.RowCount>0 Then
'			For i=0 To c.RowCount -1
'				c.Position=i
'				'		bmp = LoadBitmap(File.DirAssets, "palomita_verde.png")
'				ListView1.AddTwoLines(c.GetString("CAT_GP_CLASIF"),c.GetString("CUANTOS"))
'			Next
'		End If
'	End If
'	clv_productos.GetBase.SetLayoutAnimated(100, 10dip, 140dip, Root.Width - 50, Root.Height * 0.68) 'Cambiamos el tamaño y posición de la lista de productos
'	clv_productos.Base_Resize(clv_productos.GetBase.Width, clv_productos.GetBase.Height) 'Cambiamos el tamaño del panel interno de la lista para que ajuste al nuevo tamaño.
''	p_botonesVenta.Visible = False
'	p_botonesVenta.Top = clv_productos.AsView.top + clv_productos.AsView.Height
'	llenaProductos(False)
'End Sub
'
'Sub ListView1_ItemClick (Position As Int, Value As Object)
'	If Value = "PROMOS" And B4XPages.MainPage.cliente.cuenta <> "N" Then
'		entro = "3"
'		marca = "PROMOS"
'		tipo = "PROMOS"
'	Else if Value = "PROMOS"  And B4XPages.MainPage.cliente.cuenta = "N"  Then
'		entro = "5"
'		B4XPages.ShowPage("Cliente")
'	End If
'	If entro = "1" Then
'		marca = Value
'		Starter.skmt.Initialize(Starter.ruta,"kmt.db", True)
'		c2=Starter.skmt.ExecQuery2("select  COUNT(*) AS CUANTOS, CAT_GP_TIPO from " & query & " where CAT_GP_ALMACEN > 0 and CAT_GP_CLASIF = ? GROUP BY CAT_GP_TIPO ORDER BY CAT_GP_TIPO ASC", Array As String(Value))
'		ListView1.Clear
'		lfila.text = "TIPO"
'		If c2.RowCount>0 Then
'			For i=0 To c2.RowCount -1
'				c2.Position=i
'				ListView1.AddTwoLines(c2.GetString("CAT_GP_TIPO"),c2.GetString("CUANTOS"))
'			Next
'		End If
'		entro = "3"
'	Else If entro = "2" Then
'		tipo = Value
'		Starter.skmt.Initialize(Starter.ruta,"kmt.db", True)
'		c2=Starter.skmt.ExecQuery2("select  COUNT(*) AS CUANTOS, CAT_GP_SUBTIPO from " & query & " where CAT_GP_ALMACEN > 0 and CAT_GP_CLASIF = ? and CAT_GP_TIPO = ?  GROUP BY CAT_GP_SUBTIPO ORDER BY CAT_GP_SUBTIPO ASC ", Array As String(marca, Value))
'		ListView1.Clear
'		lfila.text = "SUB-TIPO"
'		If c2.RowCount>0 Then
'			For i=0 To c2.RowCount -1
'				c2.Position=i
'				ListView1.AddTwoLines(c2.GetString("CAT_GP_SUBTIPO"),c2.GetString("CUANTOS"))
'			Next
'		End If
'		entro = "3"
'	   
'	Else If entro = "3" Then
'		Starter.skmt.Initialize(Starter.ruta,"kmt.db", True)
'		c2=Starter.skmt.ExecQuery2("select  CAT_GP_NOMBRE, CAT_GP_PRECIO, CAT_GP_ALMACEN, CAT_GP_IMG from " & query & " where CAT_GP_ALMACEN > 0 and CAT_GP_CLASIF = ? AND CAT_GP_TIPO = ?   ", Array As String(marca,  Value))
'		ListView1.Clear
'		lfila.text = "PRODUCTO"
'		Dim ins As InputStream
'		Dim bmp As Bitmap
'		Dim jpeg() As Byte
'		If c2.RowCount>0 Then
'			For i=0 To c2.RowCount -1
'				c2.Position=i
'				jpeg = c2.GetBlob("CAT_GP_IMG")
'				ins.InitializeFromBytesArray(jpeg, 0, jpeg.Length)
'				bmp.Initialize2(ins)
'
'				ListView1.AddTwoLines(c2.GetString("CAT_GP_NOMBRE"),"# " & c2.GetString("CAT_GP_ALMACEN") & " $ " & c2.GetString("CAT_GP_PRECIO"))
'			Next
'		End If
'		entro = "4"
'	Else If entro = "4" Then
'	  
'		Starter.skmt.ExecNonQuery("delete from PROID")
'		Starter.skmt.ExecNonQuery2("INSERT INTO PROID VALUES (?)", Array As Object(Value))
'		'StartActivity(pedidos)
'		HACER_PEDIDO
'	End If
'End Sub
'
'Private Sub B4XPage_CloseRequest As ResumableSub
'	' BACK key pressed
''	Log("REGRESAMOS, " & "ENTRO=" & entro)
'	ya_entro ="0"
'	If entro = "4" Then
'		entro = "3"
'		B4XPage_Appear
'		Return True
'	Else If entro = "3" Then
'		' I want to capture the key here so I return True
'		Log("Mostramos Cliente")
'		B4XPages.ShowPage("Cliente")
'		Return False
'	End If
'	B4XPages.ShowPage("Cliente")
'	Return False
'	' Returning False signals the system to handle the key
'End Sub
'
'Sub BUSCA_TextChanged (Old As String, New As String)
'	q_buscar = "%" & BUSCA.Text & "%"
'	Starter.skmt.Initialize(Starter.ruta,"kmt.db", True)
'	c=Starter.skmt.ExecQuery2("select CAT_GP_NOMBRE, CAT_GP_ALMACEN, CAT_GP_PRECIO,CAT_GP_IMG from " & query & " where CAT_GP_PRECIO > 0 AND CAT_GP_ALMACEN > 0 and CAT_GP_NOMBRE like ? and CAT_GP_CLASIF <>  ?  and (length(CAT_GP_CODPROMO) = 1 OR CAT_GP_CODPROMO = CAT_GP_ID) order by CAT_GP_NOMBRE asc", Array As String(q_buscar,"PROMOS"))
'	'and CAT_GP_CLASIF <>  ? group by CAT_GP_CLASIF order by CAT_GP_CLASIF asc", Array As String("PROMOS") )
'	
'	ListView1.Clear
'	 
'	Dim ins As InputStream
'	Dim bmp As Bitmap
'	Dim jpeg() As Byte
'	If c.RowCount>0 Then
'		For i=0 To c.RowCount -1
'			c.Position=i
'			jpeg = c.GetBlob("CAT_GP_IMG")
'			ins.InitializeFromBytesArray(jpeg, 0, jpeg.Length)
'			bmp.Initialize2(ins)
'			ListView1.AddTwoLines(c.GetString("CAT_GP_NOMBRE"),"Existencia " & c.GetString("CAT_GP_ALMACEN") & " Precio $" & c.GetString("CAT_GP_PRECIO"))
'		Next
'	End If
'	c.Close
'	entro= "4"
'End Sub
'
'Sub HACER_PEDIDO
'	c=Starter.skmt.ExecQuery("Select SUBSTR(CUENTA,1,1) AS CUENTA from cuentaa")
'	c.Position=0
'	clie_id = c.GetString("CUENTA")
'	c.Close
'	Panel1.Visible= True
'	cambio = "0"
'	cantidad.Text = ""
'	c=Starter.skmt.ExecQuery("select  ID_ALMACEN from CAT_ALMACEN")
'	C.Position =0
'	ALMACEN = C.GetString("ID_ALMACEN")
'	C.Close
'	i_fotol.Visible = False
'
'	Starter.skmt.Initialize(Starter.ruta,"kmt.db", True)
'	c=Starter.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 " & query & " 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")
'	
'	If PERFIL = "V-SUPER" Then
'		c2=Starter.skmt.ExecQuery("select PRECIO, NLISTA FROM LISTA_PRECIOS WHERE NLISTA = '10' AND  CAT_GP_ID =" & "'" &L_PROID.TEXT&"' ORDER BY NLISTA ASC")
'		c2.Position=0
'		l_precio.Text = c2.GetString("PRECIO")
'		c2.Close
'	Else
'		l_precio.Text = c.GetDouble("CAT_GP_PRECIO")
'	End If
'	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")
'	precio2 = l_precio.Text
'	If l_marca.text = "PROMOS" And l_tipo.Text ="PROMOS" Then
'		DESC_PROMO.Visible = True
'		CC=Starter.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 = "4"
'		Else
'			CC.Close
'			CC=Starter.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
'				
'			DD=Starter.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=Starter.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
'			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=Starter.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
'	' If t_venta.Text < 100  AND l_tipo.Text = "PROMOS" Then
'	'Terminar.Visible = False
'	'guardar.Visible = False
'	'cantidad.Visible = False
'	'nopromo.Visible = True
'	'Else
'	'cambio = 0
'	Terminar.Visible = True
'	guardar.Visible = True
'	cantidad.Visible = True
'	nopromo.Visible = False
'	'End If
'	
'	   
'	Dim out As OutputStream
'	out = File.OpenOutput(Starter.ruta, "1.jpg", False)
'	out.WriteBytes(IMG_PASO, 0, IMG_PASO.Length)
'	out.Close
'	img_prod.Bitmap = LoadBitmap(Starter.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 YA NO PUEDE TENER ESTA PROMOCION") 'ignore
'		Panel1.Visible= False
'	End If
'
'	If marca <> "PROMOS" Then
'
'		If PERFIL = "PREVENTA" Then
'	
'			t_precio.Visible = False
'			LV_PRECIOS.Visible = False
'
'		ELSE IF PERFIL = "V-ESPECIAL" Then
'			c=Starter.skmt.ExecQuery("select PRECIO, NLISTA FROM LISTA_PRECIOS WHERE NLISTA IN ('5','6','7','8','10') AND  CAT_GP_ID =" & "'" &L_PROID.TEXT&"' ORDER BY NLISTA ASC")
'			LV_PRECIOS.Clear
'			Dim label1 As Label
'			label1 = LV_PRECIOS.TwoLinesLayout.Label
'			label1.TextSize = 10
'			label1.TextColor = Colors.Black
'			Dim label2 As Label
'			label2 = LV_PRECIOS.TwoLinesLayout.SecondLabel
'			label2.TextSize = 10
'			label2.TextColor = Colors.Black
'			
'			If c.RowCount>0 Then
'				For i=0 To c.RowCount -1
'					c.Position=i
'					LV_PRECIOS.AddTwoLines(c.GetString("NLISTA"),c.GetString("PRECIO"))
'				Next
'			End If
'		ELSE IF PERFIL = "V-MINI" Then
'			t_precio.Visible = False
'			LV_PRECIOS.Visible = False
'
'			c=Starter.skmt.ExecQuery("select PRECIO, NLISTA FROM LISTA_PRECIOS WHERE NLISTA = '2' AND  CAT_GP_ID =" & "'" &L_PROID.TEXT&"' ORDER BY NLISTA ASC")
'			c.Position=0
'			l_precio.Text = c.GetString("PRECIO")
'			c.Close
'		ELSE IF PERFIL = "V-COSTO" Then
'
'			t_precio.Visible = False
'			LV_PRECIOS.Visible = False
'
'			c=Starter.skmt.ExecQuery("select PRECIO, NLISTA FROM LISTA_PRECIOS WHERE NLISTA = '9' AND  CAT_GP_ID =" & "'" &L_PROID.TEXT&"' ORDER BY NLISTA ASC")
'			c.Position=0
'			l_precio.Text = c.GetString("PRECIO")
'			c.Close
'		ELSE IF PERFIL = "V-SUPER" Then
'
'			t_precio.Visible = False
'			LV_PRECIOS.Visible = False
'
'			c=Starter.skmt.ExecQuery("select PRECIO, NLISTA FROM LISTA_PRECIOS WHERE NLISTA ='9' AND  CAT_GP_ID =" & "'" &L_PROID.TEXT&"' ORDER BY NLISTA ASC")
'			c.Position=0
'			l_precio.Text = c.GetString("PRECIO")
'			c.Close
'		End If
'	End If
'End Sub
'
'Sub guardar_Click
'	If cantidad.Text = "" Then
'		Panel1.Visible= False
'	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
'		Starter.skmt.ExecNonQuery("delete from PROIDID")
'		
'		Starter.skmt.ExecNonQuery2("INSERT INTO PROIDID VALUES (?)", Array As Object(L_PROID.text))
'		c=Starter.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)")
'		c.Position =0
'		If c.GetString("CUANTOSD") = 0 Then
'			Msgbox("No tiene venta el cliente para la promo", "ADVERTENCIA") 'ignore
'		Else
'			c=Starter.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)")
'			C.Position =0
'			TOT_ART_PROMO = C.GetString("TOT_ART_PROMO")
'			COSTO_TOT = C.GetString("COSTO_TOT")
'			C.Close
'		
'			c=Starter.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 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=Starter.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 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
'				'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.
'				Starter.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=Starter.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")
'				If D.RowCount>0 Then
'					For i=0 To D.RowCount -1
'						D.Position=i
'			 
'						Starter.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=Starter.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 AND CAT_DP_TIPO = 1")
'				If D.RowCount>0 Then
'					For i=0 To D.RowCount -1
'						D.Position=i
'			 
'						Starter.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=Starter.skmt.ExecQuery("Select CUENTA from cuentaa")
'				c.Position=0
'				clie_id = c.GetString("CUENTA")
'				c.Close
'
'				c=Starter.skmt.ExecQuery("select CAT_CL_RUTA from kmt_info where CAT_CL_CODIGO In (Select cuenta from cuentaa)")
'				c.Position=0
'				cl_ruta = c.GetString("CAT_CL_RUTA")
'				c.Close
'				
'				c=Starter.skmt.ExecQuery("select USUARIO from usuarioa")
'				c.Position=0
'				usuario = c.GetString("USUARIO")
'				'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=Starter.skmt.ExecQuery("select count(*) as CUANTOS FROM CAT_DETALLES_PAQ WHERE CAT_DP_ID IN (Select PROIDID from PROIDID) and CAT_DP_TIPO = 0 AND CAT_DP_PRECIO = 0")
'				If e.GetString("CUANTOS") > 0 Then
'					F=Starter.skmt.ExecQuery("select CAT_DP_IDPROD, CAT_DP_PZAS FROM CAT_DETALLES_PAQ WHERE CAT_DP_ID IN (Select PROIDID from PROIDID) and CAT_DP_TIPO = 0 AND CAT_DP_PRECIO = 0")
'					'se coloco el if por la mala promocion.
'					For i=0 To F.RowCount -1
'						F.Position=i
'						h=Starter.skmt.ExecQuery2("select CAT_GP_NOMBRE from " & query & " where CAT_GP_ID = ? ", Array As String(f.GetString("CAT_DP_IDPROD")))
'						h.Position=0
'						Starter.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_TIPO,PE_PRECIO2) VALUES(?,?,?,?,?,?,?,?,?,?,?,?) ", Array As Object (L_PROID.text,0, 0, f.GetString("CAT_DP_PZAS") * cantidad.text, h.GetString("CAT_GP_NOMBRE"), f.GetString("CAT_DP_IDPROD"),clie_id, sDate & sTime, usuario,cl_ruta,"VENTA",precio2))
'						h.Close
'					Next
'					f.Close
'				End If
'				e.Close
'				Starter.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_TIPO,PE_PRECIO2) VALUES(?,?,?,?,?,?,?,?,?,?,?,?) ", Array As Object (L_PROID.text,0, 0, cantidad.text, l_desc.text, L_PROID.Text,clie_id, sDate & sTime, usuario,cl_ruta,"VENTA",precio2))
'				Starter.skmt.ExecNonQuery2("update " & query & " 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 = ""
'		Panel1.Visible= False
'	else If l_marca.text = "PROMOS" And l_tipo.Text ="PROMOS" And PROMO_C = 0 Then
'		Starter.skmt.ExecNonQuery("delete from PROIDID")
'		Starter.skmt.ExecNonQuery2("INSERT INTO PROIDID VALUES (?)", Array As Object(L_PROID.text))
'		c=Starter.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=Starter.skmt.ExecQuery("select CAT_CL_RUTA from kmt_info where CAT_CL_CODIGO In (Select cuenta from cuentaa)")
'		c.Position=0
'		cl_ruta = c.GetString("CAT_CL_RUTA")
'		c.Close
'		c=Starter.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=Starter.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=Starter.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=Starter.skmt.ExecQuery2("select CAT_GP_NOMBRE from " & query & " where CAT_GP_ID = ? ", Array As String(f.GetString("CAT_DP_IDPROD")))
'				h.Position=0
'				Starter.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_TIPO,PE_PRECIO2) 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,"VENTA",precio2))
'				h.Close
'			Next
'			f.Close
'		End If
'		e.Close
'		Starter.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_TIPO,PE_PRECIO2) VALUES(?,?,?,?,?,?,?,?,?,?,?,?) ", Array As Object (L_PROID.text,0, 0, cantidad.text, l_desc.text, L_PROID.Text,clie_id, sDate & sTime, usuario,cl_ruta,"VENTA",precio2))
'		Starter.skmt.ExecNonQuery2("update " & query & " set cat_gp_almacen = cat_gp_almacen - ? where cat_gp_id = ? ", Array As Object(cantidad.Text, L_PROID.Text))
'		cantidad.Text = ""
'		c=Starter.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
'		Starter.skmt.ExecNonQuery("delete from pedido_cliente where PC_CLIENTE In (select cuenta from cuentaa)")
'		Starter.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")))
'		Starter.skmt.ExecNonQuery("UPDATE kmt_info set gestion = 2  where CAT_CL_CODIGO In (select cuenta from cuentaa)")
'		Panel1.Visible= False
'	Else
'		DateTime.DateFormat = "MM/dd/yyyy"
'		sDate=DateTime.Date(DateTime.Now)
'		sTime=DateTime.Time(DateTime.Now)
'		c=Starter.skmt.ExecQuery("Select CUENTA from cuentaa")
'		c.Position=0
'		clie_id = c.GetString("CUENTA")
'		c.Close
'		c=Starter.skmt.ExecQuery("select CAT_CL_RUTA from kmt_info where CAT_CL_CODIGO In (Select cuenta from cuentaa)")
'		c.Position=0
'		cl_ruta = c.GetString("CAT_CL_RUTA")
'		c.Close
'		c=Starter.skmt.ExecQuery("select USUARIO from usuarioa")
'		c.Position=0
'		usuario = c.GetString("USUARIO")
'	
'		Starter.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_TIPO,PE_PRECIO2) 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,"VENTA",precio2))
'		Starter.skmt.ExecNonQuery2("update " & query & " set cat_gp_almacen = cat_gp_almacen - ? where cat_gp_id = ? ", Array As Object(cantidad.Text, L_PROID.Text))
'		c=Starter.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
'		Starter.skmt.ExecNonQuery("delete from pedido_cliente where PC_CLIENTE In (select cuenta from cuentaa)")
'		Starter.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")))
'		Starter.skmt.ExecNonQuery("UPDATE kmt_info set gestion = 2  where CAT_CL_CODIGO In (select cuenta from cuentaa)")
'		Panel1.Visible= False
'	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
'		Starter.skmt.ExecNonQuery("delete from PROIDID")
'		Starter.skmt.ExecNonQuery2("INSERT INTO PROIDID VALUES (?)", Array As Object(L_PROID.text))
'		c=Starter.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)")
'		c.Position =0
'		If c.GetString("CUANTOSD") = 0 Then
'			Msgbox("No tiene venta el cliente para la promo", "ADVERTENCIA") 'ignore
'		Else
'			c=Starter.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)")
'			C.Position =0
'			TOT_ART_PROMO = C.GetString("TOT_ART_PROMO")
'			COSTO_TOT = C.GetString("COSTO_TOT")
'			C.Close
'			c=Starter.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 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=Starter.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 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
'				'en pe_cedis meto el codigo de promocion para hacer esta validacion.
'				Starter.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=Starter.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")
'				If D.RowCount>0 Then
'					For i=0 To D.RowCount -1
'						D.Position=i
'						Starter.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=Starter.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 AND CAT_DP_TIPO = 1")
'				If D.RowCount>0 Then
'					For i=0 To D.RowCount -1
'						D.Position=i
'						Starter.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=Starter.skmt.ExecQuery("Select CUENTA from cuentaa")
'				c.Position=0
'				clie_id = c.GetString("CUENTA")
'				c.Close
'				c=Starter.skmt.ExecQuery("select CAT_CL_RUTA from kmt_info where CAT_CL_CODIGO In (Select cuenta from cuentaa)")
'				c.Position=0
'				cl_ruta = c.GetString("CAT_CL_RUTA")
'				c.Close
'				c=Starter.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=Starter.skmt.ExecQuery("select count(*) as CUANTOS FROM CAT_DETALLES_PAQ WHERE CAT_DP_ID IN (Select PROIDID from PROIDID) and CAT_DP_TIPO = 0 AND CAT_DP_PRECIO = 0")
'				e.Position =0
'				If e.GetString("CUANTOS") > 0 Then
'					F=Starter.skmt.ExecQuery("select CAT_DP_IDPROD, CAT_DP_PZAS FROM CAT_DETALLES_PAQ WHERE CAT_DP_ID IN (Select PROIDID from PROIDID) and CAT_DP_TIPO = 0 AND CAT_DP_PRECIO = 0")
'					'meter el otro
'					F.Position =0
'					h=Starter.skmt.ExecQuery2("select CAT_GP_NOMBRE from " & query & " where CAT_GP_ID = ? ", Array As String(f.GetString("CAT_DP_IDPROD")))
'					h.Position=0
'					Starter.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_TIPO,PE_PRECIO2) VALUES(?,?,?,?,?,?,?,?,?,?,?,?) ", Array As Object (L_PROID.text,0, 0, f.GetString("CAT_DP_PZAS") * cantidad.text, h.GetString("CAT_GP_NOMBRE"), f.GetString("CAT_DP_IDPROD"),clie_id, sDate & sTime, usuario,cl_ruta,"VENTA",precio2))
'					h.Close
'					f.Close
'				End If
'				e.Close
'				Starter.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_TIPO,PE_PRECIO2) VALUES(?,?,?,?,?,?,?,?,?,?,?,?) ", Array As Object (L_PROID.text,0, 0, cantidad.text, l_desc.text, L_PROID.Text,clie_id, sDate & sTime, usuario,cl_ruta,"VENTA",precio2))
'				Starter.skmt.ExecNonQuery2("update " & query & " 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 = ""
'		Panel1.Visible= False
'		B4XPages.ShowPage("Cliente")
'	else If l_marca.text = "PROMOS" And l_tipo.Text ="PROMOS" And PROMO_C = 0 Then
'		Starter.skmt.ExecNonQuery("delete from PROIDID")
'		
'		Starter.skmt.ExecNonQuery2("INSERT INTO PROIDID VALUES (?)", Array As Object(L_PROID.text))
'		c=Starter.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=Starter.skmt.ExecQuery("select CAT_CL_RUTA from kmt_info where CAT_CL_CODIGO In (Select cuenta from cuentaa)")
'		c.Position=0
'		cl_ruta = c.GetString("CAT_CL_RUTA")
'		c.Close
'		
'		c=Starter.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=Starter.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=Starter.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=Starter.skmt.ExecQuery2("select CAT_GP_NOMBRE from " & query & " where CAT_GP_ID = ? ", Array As String(f.GetString("CAT_DP_IDPROD")))
'				h.Position=0
'				Starter.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_TIPO,PE_PRECIO2) 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,"VENTA",precio2))
'				h.Close
'			Next
'			f.Close
'		End If
'		e.Close
'		Starter.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_TIPO,PE_PRECIO2) VALUES(?,?,?,?,?,?,?,?,?,?,?,?) ", Array As Object (L_PROID.text,0, 0, cantidad.text, l_desc.text, L_PROID.Text,clie_id, sDate & sTime, usuario,cl_ruta,"VENTA",precio2))
'		Starter.skmt.ExecNonQuery2("update " & query & " set cat_gp_almacen = cat_gp_almacen - ? where cat_gp_id = ? ", Array As Object(cantidad.Text, L_PROID.Text))
'		cantidad.Text = ""
'		c=Starter.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
'		Starter.skmt.ExecNonQuery("delete from pedido_cliente where PC_CLIENTE In (select cuenta from cuentaa)")
'		Starter.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")))
'		Starter.skmt.ExecNonQuery("UPDATE kmt_info 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=Starter.skmt.ExecQuery("Select CUENTA from cuentaa")
'		c.Position=0
'		clie_id = c.GetString("CUENTA")
'		c.Close
'		c=Starter.skmt.ExecQuery("select CAT_CL_RUTA from kmt_info where CAT_CL_CODIGO In (Select cuenta from cuentaa)")
'		c.Position=0
'		cl_ruta = c.GetString("CAT_CL_RUTA")
'		c.Close
'		
'		c=Starter.skmt.ExecQuery("select USUARIO from usuarioa")
'		c.Position=0
'		usuario = c.GetString("USUARIO")
'	
'		Starter.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_TIPO,PE_PRECIO2) 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,"VENTA",precio2))
'		Starter.skmt.ExecNonQuery2("update " & query & " set cat_gp_almacen = cat_gp_almacen - ? where cat_gp_id = ? ", Array As Object(cantidad.Text, L_PROID.Text))
'		Panel1.Visible= False
'		B4XPages.ShowPage("Cliente")
'	End If
'End Sub
'
'Sub i_fotol_Click
'	i_fotol.Visible = False
'
'End Sub
'
'Sub DESC_PROMO_Click 'BORRAR
''	Starter.skmt.ExecNonQuery("delete from PROIDID")
''	Starter.skmt.ExecNonQuery2("INSERT INTO PROIDID VALUES (?)", Array As Object(L_PROID.text))
''	B4XPages.ShowPage("Detalle_Promo")
'End Sub
'
'Sub nopromo_Click 'BORRAR
''	c=Starter.skmt.ExecQuery2("select CAT_VA_VALOR from CAT_VARIABLES WHERE CAT_VA_DESCRIPCION = ?", Array As String ("CAMBIOS"))
''	c.Position =0
''	CAMBIOS = c.GetString("CAT_VA_VALOR")
''	c.Close
''	If CAMBIOS = "1" Then
''		c=Starter.skmt.ExecQuery("select COUNT(*) AS CUANTOS from HIST_RMI WHERE HR_CLIENTE IN (Select CUENTA from cuentaa) and  HR_PROID = '" & L_PROID.Text & "'")
''		c.Position =0
''		EXISTE_CAMBIO = c.GetString("CUANTOS")
''		c.Close
''		If EXISTE_CAMBIO = 0 Then
''			EXISTE_CAMBIO = 0
''		Else
''			c=Starter.skmt.ExecQuery("select SUM(HR_CANT) AS CUANTOS from HIST_RMI WHERE HR_CLIENTE IN (Select CUENTA from cuentaa) and  HR_PROID = '" & L_PROID.Text & "'")
''			c.Position =0
''			EXISTE_CAMBIO = c.GetString("CUANTOS")
''			c.Close
''		End If
''		If EXISTE_CAMBIO = 0 Then
''			Msgbox("NO SE VENDIO ESTE PRODUCTO, NO SE PUEDE CAMBIAR","ALERTA") 'ignore
''		ELSE If cantidad.Text = "" Then
''			Msgbox("Cantidad no puede ser 0","Cantidad") 'ignore
''		Else If cantidad.Text > EXISTE_CAMBIO Then
''			Msgbox("Exede la existencia", "ADVERTENCIA") 'ignore
''		Else
''			DateTime.DateFormat = "MM/dd/yyyy"
''			sDate=DateTime.Date(DateTime.Now)
''			sTime=DateTime.Time(DateTime.Now)
''			c=Starter.skmt.ExecQuery("Select CUENTA from cuentaa")
''			c.Position=0
''			clie_id = c.GetString("CUENTA")
''			c=Starter.skmt.ExecQuery("select USUARIO from usuarioa")
''			c.Position=0
''			usuario = c.GetString("USUARIO")
''			Starter.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_TIPO,PE_PRECIO2) VALUES(?,?,?,?,?,?,?,?,?,?,?) ", Array As Object ("DUR",0,0, cantidad.text,"CAMBIO" & l_desc.text, L_PROID.Text,clie_id, sDate & sTime, usuario,"VENTA",precio2))
''			Starter.skmt.ExecNonQuery2("update " & query & " set cat_gp_almacen = cat_gp_almacen - ? where cat_gp_id = ? ", Array As Object(cantidad.Text, L_PROID.Text))
''			cantidad.Text = ""
''			Panel1.Visible= False
''		End If
''	Else
''		If cantidad.Text > 15 Then
''			Msgbox("Exede la existencia", "ADVERTENCIA") 'ignore
''		Else
''			DateTime.DateFormat = "MM/dd/yyyy"
''			sDate=DateTime.Date(DateTime.Now)
''			sTime=DateTime.Time(DateTime.Now)
''			c=Starter.skmt.ExecQuery("Select CUENTA from cuentaa")
''			c.Position=0
''			clie_id = c.GetString("CUENTA")
''			c=Starter.skmt.ExecQuery("select USUARIO from usuarioa")
''			c.Position=0
''			usuario = c.GetString("USUARIO")
''	
''			Starter.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_TIPO,PE_PRECIO2) VALUES(?,?,?,?,?,?,?,?,?,?,?) ", Array As Object ("DUR",0,0, cantidad.text,"CAMBIO" & l_desc.text, L_PROID.Text,clie_id, sDate & sTime, usuario,"VENTA",precio2))
''			Starter.skmt.ExecNonQuery2("update " & query & " set cat_gp_almacen = cat_gp_almacen - ? where cat_gp_id = ? ", Array As Object(cantidad.Text, L_PROID.Text))
''			cantidad.Text = ""
''			Panel1.Visible= False
''		End If
''	End If
'End Sub
'
'Sub LV_PRECIOS_ItemClick (Position As Int, Value As Object) 'BORRAR
''	c=Starter.skmt.ExecQuery("select PRECIO, NLISTA FROM LISTA_PRECIOS WHERE NLISTA = " & "'" & Value &"' AND  CAT_GP_ID =" & "'" &L_PROID.TEXT&"' ORDER BY NLISTA ASC")
''	c.Position=0
''	l_precio.Text = c.GetString("PRECIO")
''	c.Close
'End Sub
'
''****************************************************************************
''***************** PARA EL MAS/MENOS *************************************
''****************************************************************************
'
'Sub B_MENOS_Click
'	If cantidad.Text = "" Then
'		cantidad.Text = ""
'	Else IF cantidad.Text > 0 Then
'		cantidad.Text = cantidad.Text -1
'	End If
'End Sub
'
'Sub B_MAS_Click
'	If cantidad.Text = "" Then
'		cantidad.Text = 1
'	Else
'		cantidad.Text = cantidad.Text + 1
'	End If
'End Sub
'
'Sub llenaProductos(limpiar As Boolean)
'	If limpiar Then clv_productos.Clear
'	Private c2 As Cursor
''	c2 = Starter.skmt.ExecQuery("select REP_CLIENTE, REP_PRONOMBRE, REP_CANT, REP_COSTO_TOT, REP_PRECIO, REP_PRODID from REPARTO where REP_RECHAZO = 1 and REP_CANT <> '0'")
'	c2 = Starter.skmt.ExecQuery("Select rep_cliente As cliente, rep_prodid As prodid, rep_pronombre As nombre, rep_precio As precio, rep_cant As cantidad, rep_prodregistro as registro, 'r' as f from reparto where REP_RECHAZO = 1 And REP_CANT > 0 order by REP_PRODID")
''	Private cv As Cursor = Starter.skmt.ExecQuery("Select v_cliente_orig As cliente, V_PRODID As prodid, V_PRODNOMBRE As nombre, V_PRECIO As precio, v_cantidad As cantidad, v_prodregistro as registro, 'v' as f from ventas where V_CLIENTE in (select cuenta from cuentaa)")
'
'	Private bgColor, textColor As Int
'	bgColor = Colors.RGB(177, 200, 249)'azul
'	clv_productos.Clear : Log("limpiamos productos")
'	If c2.RowCount > 0 And clv_productos.Size <> c2.RowCount Then
'		Log("******  TRAEMOS RECHAZOS DESDE REPARTO")
'		For i=0 To c2.RowCount -1
'			c2.Position=i
'			Private inv, inv2 As Int
'			If c2.GetString("f") = "r" Then
'				inv = c2.GetString("cantidad")
'				inv2 = 0
'			Else
'				inv = 0
'				inv2 = c2.GetString("cantidad")
'			End If
''			LogColor($"${c2.GetString("nombre")}, ${c2.GetString("precio")}, ${inv}, ${inv2}, ${c2.GetString("cliente")}"$, Colors.Blue)
'			textColor = Colors.Black
'			clv_productos.Add(CreateListItem(c2.GetString("nombre"), Subs.traePrecio(c2.GetString("prodid"), SubS.traeAlmacen), inv, inv2, c2.GetString("cliente"), clv_productos.AsView.Width, 50dip, bmp, c2.GetString("prodid"), bgColor, textColor), c2.GetString("nombre"))
'		Next
'	End If
''	If cv.RowCount > 0 Then
''		Log("******+  VENTAS")
''		For i=0 To cv.RowCount -1
''			cv.Position=i
''			Private inv, inv2 As Int
''			If cv.GetString("f") = "r" Then
''				inv = cv.GetString("cantidad")
''				inv2 = 0
''			Else
''				inv = 0
''				inv2 = cv.GetString("cantidad")
''			End If
''			LogColor($"${cv.GetString("nombre")}, ${cv.GetString("precio")}, ${inv}, ${inv2}, ${cv.GetString("cliente")}"$, Colors.red)
''			textColor = Colors.Black
''			clv_productos.Add(CreateListItem(cv.GetString("nombre"), cv.GetString("precio"), inv, inv2, cv.GetString("cliente"), clv_productos.AsView.Width, 50dip, bmp, cv.GetString("prodid"), bgColor, textColor), cv.GetString("nombre"))
''		Next
''	End If
''	ponProdsEnCero
'	c2.Close
'End Sub
'
'Sub CreateListItem(Text As String, precioU As String, inv As Int, inv2 As Int, cliente As String, Width As Int, Height As Int, img As Bitmap, prodId As String, bc As Int, tc As Int) As Panel
'	Dim p As B4XView = xui.CreatePanel("")
'	p.SetLayoutAnimated(0, 0, 0, Width, Height)
'	p.LoadLayout("prodItem")
''	Log($"***************** PROD=${prodId}, INV2=${inv2}, INV=${inv}"$)
'	If inv2 <> "0" Then l_vendido.Visible = True
''	Log($"***************** PROD=${prodId}, INV2=${inv2}, INV=${inv}"$)
'	p_prods.Color = bc
'	l_prodX.TextColor = tc
'	l_prodX.Text = Text&CRLF&"# " & inv & " $ " & precioU
'	l_prodX.Tag = $"ID: ${prodId}${CRLF}${Text}${CRLF}Precio: $$1.2{precioU}${CRLF}Inv: ${inv} pzs"$
'	l_vendido.Tag = precioU&"|"&inv&"|"&prodId&"|"&inv2&"|"&cliente
'	p_prods.Tag = precioU&"|"&inv&"|"&prodId&"|"&inv2&"|"&cliente
'	l_pCant.Tag = precioU&"|"&inv&"|"&prodId&"|"&cliente
'	et_pCant.Tag = precioU&"|"&inv&"|"&prodId&"|"&cliente
''	l_pCant.Text = 0
''	et_pCant.Text = inv2
'	et_pCant.BringToFront
''	i_prod.Bitmap = img
'	Return p
'End Sub
'
'Sub p_prods_Click
'	Log(Sender.As(Panel).tag)
'End Sub
'
'Sub b_prodMenos_Click
'	etCantHasFocus = False
'	LogColor("b_prodMenos_Click", Colors.Magenta)
'	Dim index As Int = clv_productos.GetItemFromView(Sender)
'	Dim pnl0 As B4XView = clv_productos.GetPanel(index)
'	Dim pnl As B4XView = pnl0.GetView(0)
'	Dim laCant As B4XView = pnl.GetView(2).GetView(3)
''	Log(pnl.GetView(2).GetView(0) & "|" & pnl.GetView(2).GetView(1) & "|" & pnl.GetView(2).GetView(2))
''	Log($"precio|stock:${laCant.tag}"$)
'	If laCant.Text = "" Then laCant.Text = 0
'	laCant.Text = $"$1.0{laCant.Text-1}"$
'	If laCant.Text < 0 Then laCant.Text = 0
'	
'	Dim esteTag As List = Regex.Split("\|", laCant.Tag)
'	Log($"ACTUALIZAMOS REPARTO"$)
'	Private precio As String = Subs.traePrecio(esteTag.Get(2), Subs.traeAlmacen)
'	Private prodId As String = esteTag.Get(2)
'	Private clienteOriginal As String = esteTag.get(3)
'	Starter.skmt.ExecNonQuery2("update HIST_VENTAS set HVD_PARCIAL = 1, HVD_CANT = 0, HVD_COSTO_TOT = '0' WHERE HVD_PROID = ? and HVD_CLIENTE in (Select CUENTA from cuentaa)", Array As String(prodId))
'	Starter.skmt.ExecNonQuery($"update reparto set REP_CANT = REP_CANT + 1 where REP_CLIENTE = '${clienteOriginal}' and REP_CLI_ORIG = '${clienteOriginal}' and REP_RECHAZO = 1 and REP_PRODID = '${prodId}'"$)
'	Starter.skmt.ExecNonQuery($"update reparto set REP_CANT = REP_CANT - 1 where REP_CLIENTE in (Select CUENTA from cuentaa) and REP_CLI_ORIG = '${clienteOriginal}' and REP_RECHAZO = 0 and REP_PRODID = '${prodId}'"$)
''		Log($"update reparto set REP_CANT = REP_CANT + 1 where REP_CLIENTE = '${clienteOriginal}' and REP_CLI_ORIG = '${clienteOriginal}' and REP_RECHAZO = 1 and REP_PRODID = '${prodId}'"$)
''		Log($"update reparto set REP_CANT = REP_CANT - 1 where REP_CLIENTE in (Select CUENTA from cuentaa) and REP_CLI_ORIG = '${clienteOriginal}' and REP_RECHAZO = 0 and REP_PRODID = '${prodId}'"$)
'	Starter.skmt.ExecNonQuery($"update reparto set REP_COSTO_TOT = REP_CANT * ${precio}, REP_PRECIO = '${precio}' where REP_CLIENTE in (Select CUENTA from cuentaa) and REP_CLI_ORIG = '${clienteOriginal}'  and REP_PRODID = '${prodId}'"$)
'
''	Dim chk As B4XView = pnl.GetView(2)
'	cuentaProds
'End Sub
'
'Sub b_prodMas_Click
'	etCantHasFocus = False
'	LogColor("b_prodMas_Click", Colors.Magenta)
'	Dim index As Int = clv_productos.GetItemFromView(Sender)
'	Dim pnl0 As B4XView = clv_productos.GetPanel(index)
'	Dim pnl As B4XView = pnl0.GetView(0)
'	Dim laCant As B4XView = pnl.GetView(2).GetView(3)
''	Log(pnl.GetView(2).GetView(1).text&"|"&pnl.GetView(2).GetView(2)&"|"&pnl.GetView(2).GetView(4).text)
'	Log($"precio|stock:${laCant.tag}"$)
'	Log($"Indice: ${index}, cant:${laCant.Text+1}, precioU: ${laCant.tag}"$)
'	Dim esteTag As List = Regex.Split("\|", laCant.Tag)
'	Log("LC_TEXT:"&laCant.Text&"|LC_TAG:"&laCant.Tag&"|ET:"&esteTag)
'	If laCant.Text = "" Then laCant.Text = 0
'	If laCant.Text + 1 <= esteTag.get(1) Then
'		laCant.Text = $"$1.0{laCant.Text+1}"$
'		LogColor("XXXXXXXXX " & esteTag, Colors.Green)
'		Private precio As String = Subs.traePrecio(esteTag.Get(2), Subs.traeAlmacen)
'		
'		Private rv As Cursor = Starter.skmt.ExecQuery($"select count(*) as hayVenta from REPARTO where REP_PRODID = '${esteTag.Get(2)}' and REP_CLIENTE in (Select cuenta from cuentaa) and REP_CLI_ORIG = '${esteTag.Get(3)}'"$)
'		rv.Position = 0
'		If rv.GetString("hayVenta") = 0 Then
'			Log("Insertamos en REPARTO")
'			Private cp As Cursor = Starter.skmt.ExecQuery($"select * from HIST_VENTAS where HVD_PROID = '${esteTag.Get(2)}' and HVD_CLIENTE = '${esteTag.get(3)}'"$)
'			If cp.RowCount > 0 Then
'				cp.Position = 0
'				Starter.skmt.ExecNonQuery2("insert into reparto(REP_CLIENTE, REP_PRONOMBRE, REP_CANT, REP_COSTO_TOT, REP_FECHA, REP_RECHAZO, REP_PRODID, REP_PRECIO, REP_PRODREGISTRO, REP_CLI_ORIG) VALUES (?,?,?,?,?,1,?,?,?,?) ", Array As String(Subs.traeCliente, cp.GetString("HVD_PRONOMBRE"), 0, cp.GetString("HVD_COSTO_TOT"), Subs.fechaKMT(DateTime.now), cp.GetString("HVD_PROID"), precio, 50, esteTag.get(3)))
'				Starter.skmt.ExecNonQuery2("insert into reparto(REP_CLIENTE, REP_PRONOMBRE, REP_CANT, REP_COSTO_TOT, REP_FECHA, REP_RECHAZO, REP_PRODID, REP_PRECIO, REP_PRODREGISTRO, REP_CLI_ORIG) VALUES (?,?,?,?,?,0,?,?,?,?) ", Array As String(Subs.traeCliente, cp.GetString("HVD_PRONOMBRE"), laCant.text, cp.GetString("HVD_COSTO_TOT"), Subs.fechaKMT(DateTime.now), cp.GetString("HVD_PROID"), precio, 50, esteTag.get(3)))
'				Starter.skmt.ExecNonQuery($"update reparto set REP_CANT = REP_CANT - 1, REP_PRECIO = '${precio}', REP_COSTO_TOT = ((REP_CANT - 1) * REP_PRECIO) where REP_CLIENTE = '${esteTag.get(3)}' and REP_CLI_ORIG = '${esteTag.get(3)}' and REP_RECHAZO = 1 and REP_PRODID = '${esteTag.Get(2)}'"$)
'				Starter.skmt.ExecNonQuery2("update cat_gunaprod set cat_gp_almacen = cat_gp_almacen + ? where cat_gp_nombre = ?", Array As Object(laCant.Text, cp.GetString("HVD_PRONOMBRE")))
'			End If
'		Else
''			Log($"update reparto set REP_CANT = REP_CANT - 1, REP_PRECIO = '${precio}', REP_COSTO_TOT = '0' where REP_CLIENTE = '${esteTag.get(3)}' and REP_CLI_ORIG = '${esteTag.get(3)}' and REP_RECHAZO = 1 and REP_PRODID = '${esteTag.Get(2)}'"$)
''			Log($"update reparto set REP_CANT = REP_CANT + 1, REP_PRECIO = '${precio}', REP_COSTO_TOT = '0' where REP_CLIENTE in (Select CUENTA from cuentaa) and REP_CLI_ORIG = '${esteTag.get(3)}' and REP_RECHAZO = 0 and REP_PRODID = '${esteTag.Get(2)}'"$)
'			Starter.skmt.ExecNonQuery($"update reparto set REP_CANT = REP_CANT - 1, REP_PRECIO = '${precio}', REP_COSTO_TOT = '0' where REP_CLIENTE = '${esteTag.get(3)}' and REP_CLI_ORIG = '${esteTag.get(3)}' and REP_RECHAZO = 1 and REP_PRODID = '${esteTag.Get(2)}'"$)
'			Starter.skmt.ExecNonQuery($"update reparto set REP_CANT = REP_CANT + 1, REP_PRECIO = '${precio}', REP_COSTO_TOT = '0' where REP_CLIENTE in (Select CUENTA from cuentaa) and REP_CLI_ORIG = '${esteTag.get(3)}' and REP_RECHAZO = 0 and REP_PRODID = '${esteTag.Get(2)}'"$)
'			Starter.skmt.ExecNonQuery($"update reparto set REP_COSTO_TOT = REP_CANT * ${precio} where REP_CLIENTE in (Select CUENTA from cuentaa) and REP_CLI_ORIG = '${esteTag.get(3)}' and REP_RECHAZO = 1 and REP_PRODID = '${esteTag.Get(2)}'"$)
'		End If
'		cuentaProds
'	End If
''	Log($"Total Prods: ${totalProds}, Total Compra: $$1.2{totalCompra}"$)
'End Sub
'
'Private Sub et_pCant_TextChanged (Old As String, New As String)
''	LogColor($"txt changed: ${Old}|${New}, hasfocus=${etCantHasFocus}"$,Colors.Magenta)
'	If Not(Old = "0" And New = "") And etCantHasFocus Then cuentaProds
'End Sub
'
'Private Sub et_pCant_FocusChanged (HasFocus As Boolean)
''	LogColor($"focus changed=${HasFocus}"$, Colors.Magenta)
'	etCantHasFocus = HasFocus
'	cuentaProds
'End Sub
'
'Sub cuentaProds
''	Log("CUENTAPRODS")
'	totalProds = 0
'	totalCompra = 0
'	For i = 0 To clv_productos.GetSize - 1
'		Private p0 As B4XView = clv_productos.GetPanel(i)
'		Private p As B4XView = p0.GetView(0)
''		Log($"${p.GetView(2).GetView(0)}, ${p.GetView(2).GetView(1)}, ${p.GetView(2).GetView(2)}, ${p.GetView(2).GetView(3)}"$)
'		Private cant1 As B4XView = p.GetView(2).GetView(3)
'		If cant1.Text = "" Then cant1.Text = 0
'		totalProds = totalProds + cant1.Text
'		Private esteTag As List = Regex.Split("\|", cant1.Tag)
''		Log(esteTag)
'		Private prodId As String = esteTag.Get(2)
'		Private m As Map
''		Log($"CANTIDAD = ${cant1.text}"$)
'		If cant1.Text > esteTag.Get(1) Then cant1.Text = esteTag.Get(1)
'		If cant1.Text > 0 Then 'Lo agregamos al mapa
''			Log(esteTag.Get(2) & "|" & cant1.Text)
'			Log("Cant > 0")
'			totalCompra = totalCompra + (esteTag.get(0) * cant1.text)
'			Log($"${esteTag.Get(2)}, Cant: ${cant1.Text}, Suma: ${esteTag.get(0) * cant1.text}"$)
'			m=CreateMap("cant":cant1.Text, "precio":esteTag.get(0), "cli_ori":esteTag.get(3))
'			prodsMap.Put(esteTag.Get(2), m)
'			prodsListId.Add(esteTag.Get(2))
'			prodsListCliOrig.Add(esteTag.get(3))
'			prodsList.Add(m)
'		Else 'Si la cantidad es CERO lo quitamos del mapa.
''			Log($"QUITAMOS EL PRODS POR CERO : ${esteTag.Get(2)}, ${esteTag.Get(3)}"$)
''			Log($"${esteTag.Get(2)}, Cant: ${cant1.Text}, Suma: ${esteTag.get(0) * cant1.text}"$)
'			prodsMap.Remove(esteTag.Get(2))
'			Private indice As Int = -1
''			For q=0 To prodsList.Size-1
''				If prodsListId.Get(q) = esteTag.Get(2) And prodsListCliOrig = esteTag.Get(3) Then
'''					prodsList.RemoveAt(q)
''					indice = q
''					prodsListId.RemoveAt(q)
''					prodsListCliOrig.RemoveAt(q)
''				End If
''			Next
'			If indice > -1 Then prodsList.RemoveAt(indice)
''			prodsList.Get(0)
'		End If
'		l_total.Visible = True
'		l_totProds.Visible = True
'		l_total.Text = $"Total: $$1.2{totalCompra}"$
'		l_totProds.text = $"Prods: ${totalProds}"$
'	Next
''	LogColor($"prodsmap=${prodsMap}"$, Colors.blue)
''	LogColor($"prodsListID=${prodsListId} ${CRLF}prodsList=${prodsList} ${CRLF}prodsListCliOrig=${prodsListCliOrig}"$, Colors.Magenta)
'	p_botonesVenta.Visible = True
'	Log($"Total Prods: ${totalProds}, Total Compra: $$1.2{totalCompra}"$)
'End Sub
'
'Private Sub b_terminar1_Click
'	Log("b_terminar1_Click")
''	cuentaProds
''	Private p1 As Map
''	Log(Subs.fechaKMT(DateTime.Now))
''	For Each p As String In prodsMap.Keys
''		p1 = prodsMap.Get(p)
''		Log(p & "|" & p1)
''		Private pn As String = Subs.traeNombre(p)
''		LogColor($"---------------- prodsMap= ${prodsMap}"$, Colors.Magenta)
''		Log($"Guardamos ${p}-${pn}, cant=${p1.Get("cant")}, precio=${p1.Get("precio")}"$)
''		Starter.skmt.ExecNonQuery($"update REPARTO set REP_CANT = REP_CANT - ${p1.Get("cant")} where REP_PRODID = '${p}' and REP_RECHAZO = 1 and REP_CLIENTE = '${p1.Get("cli_ori")}' and REP_CLI_ORIG = '${p1.Get("cli_ori")}'"$)
''		Starter.skmt.ExecNonQuery($"update REPARTO set REP_CANT = REP_CANT + ${p1.Get("cant")} where REP_PRODID = '${p}' and REP_RECHAZO = 0 and REP_CLIENTE in (select cuenta from cuentaa) and REP_CLI_ORIG = '${p1.Get("cli_ori")}'"$)
''		Starter.skmt.ExecNonQuery($"update CAT_GUNAPROD set CAT_GP_ALMACEN = CAT_GP_ALMACEN - ${p1.Get("cant")} where CAT_GP_ID = '${p}'"$)
''		
''		Private rv As Cursor = Starter.skmt.ExecQuery($"select count(*) as hayVenta from REPARTO where REP_PRODID = '${p}' and REP_CLIENTE in (Select cuenta from cuentaa)"$)
''		rv.Position = 0
''		Log($"+++++++++++++++ PRODSMAP = ${p1}"$)
''		If rv.GetString("hayVenta") = 0 Then
''			Log("Insertamos en REPARTO")
''			Starter.skmt.ExecNonQuery2("insert into reparto(REP_CLIENTE, REP_PRONOMBRE, REP_CANT, REP_COSTO_TOT, REP_FECHA, REP_RECHAZO, REP_PRODID, REP_PRECIO, REP_PRODREGISTRO, REP_CLI_ORIG) VALUES (?,?,?,?,?,1,?,?,?,?) ", Array As String(Subs.traeCliente, pn, 0, p1.Get("cant") * p1.Get("precio"), Subs.fechaKMT(DateTime.now), p, p1.Get("precio"), 50, p1.Get("cli_ori")))
''			Starter.skmt.ExecNonQuery2("insert into reparto(REP_CLIENTE, REP_PRONOMBRE, REP_CANT, REP_COSTO_TOT, REP_FECHA, REP_RECHAZO, REP_PRODID, REP_PRECIO, REP_PRODREGISTRO, REP_CLI_ORIG) VALUES (?,?,?,?,?,0,?,?,?,?) ", Array As String(Subs.traeCliente, pn, p1.Get("cant"), p1.Get("cant") * p1.Get("precio"), Subs.fechaKMT(DateTime.now), p, p1.Get("precio"), 50, p1.Get("cli_ori")))
''			Starter.skmt.ExecNonQuery2("update cat_gunaprod set cat_gp_almacen = cat_gp_almacen + ? where cat_gp_nombre = ?", Array As Object(p1.Get("cant"), pn))
''		End If
''	Next
'	ya_entro = "0" : Log("ya_entro=1")
'''	lv_promos.Visible = False
''	clv_productos.AsView.Visible = False
''	lv_catalogos.Visible = True
''	Log("Terminar")
'''	clv_productos.Clear
''	ponProdsEnCero
'	prodsMap.Initialize
'	B4XPages.ShowPage("Cliente")
'End Sub
'
'Private Sub p_prods_LongClick
'	Log($"${Sender.As(Panel).tag}"$)
'	Private esteTag As List = Regex.Split("\|", Sender.As(Panel).Tag)
'	Log($"|${esteTag.Get(3)}|"$)
'	If esteTag.Get(3) <> "0" Then
'		Log("VENDIDO")
'		borraProdVenta(esteTag.Get(2))
'	Else
'		Log("NO VENDIDO")
'	End If
'End Sub
'
'Private Sub l_vendido_LongClick
'	Log($"${Sender.As(Label).tag}"$)
'	Private esteTag As List = Regex.Split("\|", Sender.As(Label).Tag)
'	Log($"|${esteTag.Get(3)}|"$)
'	If esteTag.Get(3) <> "0" Then
'		Log("VENDIDO")
'		borraProdVenta(esteTag.Get(2))
'	Else
'		Log("NO VENDIDO")
'	End If
'End Sub
'
'Sub borraProdVenta(prodId)
'	Private cant As Int = 0
'	Private cliOrig As String = ""
'	Private RES As String =  Msgbox2("Seguro que desea borrar este producto?","Borrar", "Si", "", "No",LoadBitmap(File.DirAssets,"alert2.png")) 'ignore
'	If RES = DialogResponse.POSITIVE Then
''	Private rr As Cursor = Starter.skmt.ExecQuery($"select REP_CANT from REPARTO where REP_PRODID = '${prodId}' and REP_RECHAZO = 0 and REP_CLIENTE in (select CUENTA from CUENTAA)"$)
'		LogColor($"Buscamos - ${prodId}, ${cant}"$, Colors.Blue)
'		Private rr As Cursor = Starter.skmt.ExecQuery($"select * from VENTAS where V_CLIENTE in (select CUENTA from CUENTAA) and V_PRODID = '${prodId}'"$)
'		Log($"ID=${prodId}, RC=${rr.RowCount}"$)
'		If rr.RowCount > 0 Then 'Si hay producto con venta en VENTAS ...
'			rr.Position = 0
'			cant = rr.GetInt("V_CANTIDAD")
'			cliOrig = rr.GetString("V_CLIENTE_ORIG")
'			LogColor($"Hay prod con venta en VENTAS - ${prodId}, ${cant}"$, Colors.Blue)
'			Starter.skmt.ExecNonQuery($"update CAT_GUNAPROD set CAT_GP_ALMACEN = CAT_GP_ALMACEN + ${cant} where CAT_GP_ID = '${prodId}'"$)
'		End If
'		Starter.skmt.ExecNonQuery($"update REPARTO set REP_CANT = REP_CANT + ${cant} where REP_RECHAZO = 1 and REP_PRODID = '${prodId}' and REP_CLIENTE = '${cliOrig}'"$)
'		Starter.skmt.ExecNonQuery($"update REPARTO set REP_CANT = REP_CANT - ${cant} where REP_RECHAZO = 0 and REP_PRODID = '${prodId}' and REP_CLIENTE = '${cliOrig}'"$)
'		Starter.skmt.ExecNonQuery($"delete from VENTAS where V_PRODID = '${prodId}' and V_CLIENTE_ORIG = '${cliOrig}' and V_CLIENTE in (select CUENTA from CUENTAA)"$)
'		B4XPages.ShowPage("Cliente")
'	End If
'End Sub


Sub Class_Globals
	Private Root As B4XView 'ignore
	Private xui As XUI 'ignore
	Dim g As GPS
	Dim clie_id As String
	Dim sDate,sTime As String
	Dim usuario As String
	Dim c As Cursor
'	Dim ruta As String
	Dim b_regresar As Button
	Dim ListView1 As ListView
	Dim L_CANT As Label
	Dim L_TOTAL As Label
	Dim b_borra As Button
	Dim Existe As String
	Dim result As String
	'    Dim lat_gps, lon_gps As String
	Dim cuantos As String
	Dim nombre_prod As String
	Dim cuantos_pedido As String
	Private Titulo As Label
	Private P1 As Panel
	Private lv2 As ListView
	Private p_principal As Panel
	Dim clv_pedido As CustomListView
	Private p_prods As Panel
	Private l_prodX As Label
	Private l_pCant As Label
	Private et_pCant As EditText
	Dim bmp As Bitmap
	Dim etCantHasFocus As Boolean = False
	Dim totalProds As Int = 0
	Dim totalCompra As Int = 0
	Dim prodsMap As Map
	Dim reconstruirPedido As Boolean = False
	Dim promoABorrar As String
	Private b_guardar As Button
	Private b_prodMas As Button
	Private b_prodMenos As Button
	Private b_prodMenosC As Button
	Private l_pCantC As Label
	Private et_pCantC As EditText
	Private b_prodMasC As Button
	Private p_botMasMenC As Panel
	Private p_botMasMen As Panel
	Private b_revversar As Button
	Private Label2 As Label
	Private Label3 As Label
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
	B4XPages.SetTitle(Me, "Productos")
	'load the layout to Root
	g.Initialize("GPS")
	Root.LoadLayout("detalleVenta")
	b_borra.Visible = False
	Titulo.Text = "Pedido"
End Sub

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

Sub B4XPage_Appear
	Label2.Visible = False
	Label3.Visible = False
	L_TOTAL.Visible = False
	L_CANT.Visible = False
	b_revversar.Visible = False
	Subs.centraPanel(p_principal, Root.Width)
'	b_guardar.Visible = False
	
'	Titulo.Left = Round(p_principal.Width/2)-(Titulo.Width/2)
	L_CANT.Text =""
	L_TOTAL.Text=""
	c=Starter.skmt.ExecQuery("select count(*) as EXISTE from HIST_VENTAS WHERE HVD_CLIENTE IN (Select CUENTA from cuentaa) and HVD_RECHAZO = 0 ")
	C.Position=0
	Existe = C.GetString("EXISTE")
	C.Close
'	c=Starter.skmt.ExecQuery("select distinct hist_ventas.hvd_num_registro, HIST_VENTAS.HVD_CLIENTE, HIST_VENTAS.HVD_PRONOMBRE, HIST_VENTAS.HVD_PROID, HIST_VENTAS.HVD_CANT, HIST_VENTAS2.HVD_CANT as HVD_CANT2, HIST_VENTAS.HVD_COSTO_TOT, HIST_VENTAS.HVD_CODPROMO from HIST_VENTAS inner join HIST_VENTAS2 on HIST_VENTAS.HVD_PROID = HIST_VENTAS2.HVD_PROID and HIST_VENTAS.HVD_CLIENTE = HIST_VENTAS2.HVD_CLIENTE WHERE HIST_VENTAS.HVD_CLIENTE IN (Select CUENTA from cuentaa) and HIST_VENTAS.HVD_RECHAZO = 0 order by HIST_VENTAS.HVD_CODPROMO desc, HIST_VENTAS.HVD_PRONOMBRE asc")
	c=Starter.skmt.ExecQuery("select * from HIST_VENTAS WHERE hvd_rechazo <> 2 and HVD_RECHAZOCANT > 0 order by HVD_CODPROMO desc, HVD_PRONOMBRE asc")
'	Private c2 As Cursor=Starter.skmt.ExecQuery("select  from PEDIDO WHERE PE_CLIENTE IN (SELECT CUENTA FROM CUENTAA)")
	
	ListView1.Clear
	clv_pedido.Clear
	Subs.SetDivider(ListView1, Colors.LightGray, 2)
	clv_pedido.GetBase.SetLayoutAnimated(100, 0dip, 60dip, Root.Width - 50, Root.Height * 0.62) 'Cambiamos el tamaño y posición de la lista de productos
	clv_pedido.Base_Resize(clv_pedido.GetBase.Width, clv_pedido.GetBase.Height) 'Cambiamos el tamaño del panel interno de la lista para que ajuste al nuevo tamaño.
'	Log("RC1:"&c.RowCount)
	If c.RowCount>0 Then
'		Log("Usamos HV")

		For i=0 To c.RowCount -1
			c.Position=i
			If c.GetString("BCAJAS") = "0" Then
				Log("AQUI1")
				If c.GetString("HVD_CANT") <> c.GetString("HVD_RECHAZOCANT") Then
					'Traemos cantidad de hvd2
					Private oc As Cursor = Starter.skmt.ExecQuery($"select HVD_CANT from HIST_VENTAS2 WHERE HVD_CLIENTE IN (Select CUENTA from cuentaa) and hvd_proid = '${c.GetString("HVD_PROID")}' and HVD_NUM_REGISTRO = '${c.GetString("HVD_NUM_REGISTRO")}'"$)
					Private cant2 As Int = 0
					If oc.RowCount > 0 Then
						oc.Position = 0
						cant2 = oc.GetString("HVD_CANT")
					End If
					oc.Close
					Dim label1 As Label
					label1 = ListView1.TwoLinesLayout.Label
					label1.TextSize = 12
					label1.TextColor = Colors.black
					Dim Label2 As Label
					Label2 = ListView1.TwoLinesLayout.SecondLabel
					Label2.TextSize = 12
					Label2.TextColor = Colors.black
					Private bgColor, textColor As Int
					bgColor = Colors.RGB(177, 200, 249)'azul
					textColor = Colors.black
					If c.GetString("HVD_CODPROMO") <> Subs.traeAlmacen Then
'				bgColor = Colors.RGB(255, 212, 163) 'naranja
						bgColor = Colors.White
					End If
'			Log($"Agregamos prod a lista1 | ${c.GetString("HVD_CANT")} - ${c.GetString("HVD_CANT2")}"$) 'HVD_CANT2 es la original de la orden.
'			ListView1.AddTwoLines(c.GetString("HVD_PRONOMBRE"),"Cantidad #"& c.GetString("HVD_CANT")& " SubTotal $"& c.GetString("HVD_COSTO_TOT"))
					Private c2 As Cursor=Starter.skmt.ExecQuery($"select IFNULL(PE_CANT,0) AS PE_CANT from PEDIDO WHERE PE_CLIENTE IN (SELECT CUENTA FROM CUENTAA)"$)
					If c2.RowCount > 0 Then
						c2.Position = 0
						clv_pedido.Add(CreateListItem(c.GetString("HVD_PRONOMBRE"), Subs.traePrecio(c.GetString("HVD_PROID"), c.GetString("HVD_CODPROMO")), c2.GetString("PE_CANT"), c.GetString("HVD_RECHAZOCANT") , clv_pedido.AsView.Width, 118dip, bmp, c.GetString("HVD_PROID"), bgColor, textColor, c.GetString("HVD_CODPROMO"),c.GetString("HVD_CLIENTE")),i)
					
					Else
						clv_pedido.Add(CreateListItem(c.GetString("HVD_PRONOMBRE"), Subs.traePrecio(c.GetString("HVD_PROID"), c.GetString("HVD_CODPROMO")), 0, c.GetString("HVD_RECHAZOCANT") , clv_pedido.AsView.Width, 118dip, bmp, c.GetString("HVD_PROID"), bgColor, textColor, c.GetString("HVD_CODPROMO"),c.GetString("HVD_CLIENTE")),i)
					End If
					c2.Close
'				Log(c.GetString("HVD_CODPROMO"))
				End If
			Else If c.GetString("BCAJAS") = "1" Then
				Log("AQUI1")
				If c.GetString("HVD_CANT") <> c.GetString("HVD_RECHAZOCANT") Then
					'Traemos cantidad de hvd2
					Private oc As Cursor = Starter.skmt.ExecQuery($"select HVD_CANT from HIST_VENTAS2 WHERE HVD_CLIENTE IN (Select CUENTA from cuentaa) and hvd_proid = '${c.GetString("HVD_PROID")}' and HVD_NUM_REGISTRO = '${c.GetString("HVD_NUM_REGISTRO")}'"$)
					Private cant2 As Int = 0
					If oc.RowCount > 0 Then
						oc.Position = 0
						cant2 = oc.GetString("HVD_CANT")
					End If
					oc.Close
					Dim label1 As Label
					label1 = ListView1.TwoLinesLayout.Label
					label1.TextSize = 12
					label1.TextColor = Colors.black
					Dim Label2 As Label
					Label2 = ListView1.TwoLinesLayout.SecondLabel
					Label2.TextSize = 12
					Label2.TextColor = Colors.black
					Private bgColor, textColor As Int
					bgColor = Colors.RGB(177, 200, 249)'azul
					textColor = Colors.black
					If c.GetString("HVD_CODPROMO") <> Subs.traeAlmacen Then
'				bgColor = Colors.RGB(255, 212, 163) 'naranja
						bgColor = Colors.White
					End If
'			Log($"Agregamos prod a lista1 | ${c.GetString("HVD_CANT")} - ${c.GetString("HVD_CANT2")}"$) 'HVD_CANT2 es la original de la orden.
'			ListView1.AddTwoLines(c.GetString("HVD_PRONOMBRE"),"Cantidad #"& c.GetString("HVD_CANT")& " SubTotal $"& c.GetString("HVD_COSTO_TOT"))

					Private c2 As Cursor=Starter.skmt.ExecQuery($"select * from PEDIDO WHERE PE_CLIENTE IN (SELECT CUENTA FROM CUENTAA)"$)
					If c2.RowCount > 0 Then
						c2.Position = 0
						Log("SI ENTRO A PONER CAJAS BIEN ")
						Log(c2.GetString("PE_CAJAS"))
						clv_pedido.Add(CreateListItem2(c.GetString("HVD_PRONOMBRE"), Subs.traePrecio(c.GetString("HVD_PROID"), c.GetString("HVD_CODPROMO")), c2.GetString("PE_CANT"), c.GetString("HVD_RECHAZOCANT") , clv_pedido.AsView.Width, 118dip, bmp, c.GetString("HVD_PROID"), bgColor, textColor, c.GetString("HVD_CODPROMO"),c.GetString("HVD_CLIENTE")),i)
					Else
						Log("NO ENTRO A PONER CAJAS BIEN ")
'						clv_pedido.Add(CreateListItem(c.GetString("HVD_PRONOMBRE"), Subs.traePrecio(c.GetString("HVD_PROID"), c.GetString("HVD_CODPROMO")), 0, c.GetString("HVD_RECHAZOCANT") , clv_pedido.AsView.Width, 118dip, bmp, c.GetString("HVD_PROID"), bgColor, textColor, c.GetString("HVD_CODPROMO"),c.GetString("HVD_CLIENTE")),i)
						clv_pedido.Add(CreateListItem2(c.GetString("HVD_PRONOMBRE"), Subs.traePrecio(c.GetString("HVD_PROID"), c.GetString("HVD_CODPROMO")), 0, c.GetString("HVD_RECHAZOCANT"), clv_pedido.AsView.Width, 118dip, bmp, c.GetString("HVD_PROID"), bgColor, textColor, c.GetString("HVD_CODPROMO"),c.GetString("HVD_CLIENTE")),i)
					End If
					c2.Close
				End If
			End If
		Next
		
'		cuentaProds("")
	End If
	
	Private vc As Cursor = Starter.skmt.ExecQuery($"select HVD_PROID, HVD_CANT, IFNULL(HVD_RECHAZOCANT, 0) AS HVD_RECHAZOCANT, CAT_GP_PRECIO from HIST_VENTAS LEFT JOIN CAT_GUNAPROD ON CAT_GP_ID = HVD_PROID where BCAJAS = 0 and HVD_CODPROMO ='${Subs.traealmacen}' and HVD_CLIENTE in (select cuenta from cuentaa)"$)
	
	Private Cuenta As String = 0
	Private arti As String = 0
	If vc.RowCount > 0 Then
		For i = 0 To vc.RowCount - 1
			vc.Position = i
'			Log(vc.GetString("HVD_CANT")&","&vc.GetString("HVD_RECHAZOCANT"))
			arti = arti + (vc.GetString("HVD_CANT") - vc.GetString("HVD_RECHAZOCANT"))
			Cuenta = Cuenta + ((vc.GetString("HVD_CANT") - vc.GetString("HVD_RECHAZOCANT"))*vc.GetString("CAT_GP_PRECIO"))
		Next
	End If
'	Log(Cuenta)
	
	Private vc2 As Cursor = Starter.skmt.ExecQuery("select HVD_PROID, HVD_CANT, IFNULL(HVD_RECHAZOCANT, 0) AS HVD_RECHAZOCANT, CANTC,HVD_COSTO_TOT from HIST_VENTAS where HVD_CLIENTE in (select cuenta from cuentaa) AND BCAJAS = 1")
	Private Cuenta1 As String = 0
	Private arti1 As String = 0
	If vc2.RowCount > 0 Then
		For i = 0 To vc2.RowCount - 1
			vc2.Position = i
			Dim preu As Float = NumberFormat2(vc2.GetString("HVD_COSTO_TOT")/vc2.GetString("CANTC"),0,2,2,False)
			Private vc3 As Cursor = Starter.skmt.ExecQuery($"select PRECIOCONVER, CONVERSION from CAT_GUNAPROD where CAT_GP_ID = '${vc2.GetString("HVD_PROID")}'"$)
			If vc3.RowCount > 0 Then
				vc3.Position = 0
				Cuenta1 = Cuenta1 + ((vc2.GetString("CANTC")-(vc2.GetString("HVD_RECHAZOCANT")/vc3.GetString("CONVERSION")))*preu)
				arti1 = arti1 + (vc2.GetString("HVD_CANT") - vc2.GetString("HVD_RECHAZOCANT"))
			End If
		Next
	End If
'	Log(Cuenta1)
	
	Private vc4 As Cursor = Starter.skmt.ExecQuery($"select HVD_PROID, HVD_CANT, IFNULL(HVD_RECHAZOCANT, 0) AS HVD_RECHAZOCANT, CANTC,HVD_COSTO_TOT, HVD_RECHAZO, HVD_CODPROMO from HIST_VENTAS where HVD_CLIENTE in (select cuenta from cuentaa) AND BCAJAS = 0 and HVD_CODPROMO <> '${Subs.traeAlmacen}'"$)
	Private Cuenta2 As String = 0
	Private arti2 As String = 0
	If vc4.RowCount > 0 Then
		
		For i = 0 To vc4.RowCount - 1
			vc4.Position = i
			If vc4.GetString("HVD_PROID") <> vc4.GetString("HVD_CODPROMO") Then
				If vc4.GetString("HVD_RECHAZO") = 0 Then
					Cuenta2 =  vc4.GetString("HVD_COSTO_TOT")
					arti2 = vc4.GetString("HVD_CANT")
				Else
					Private vc5 As Cursor = Starter.skmt.ExecQuery($"select CAT_GP_PRECIO from CAT_GUNAPROD where CAT_GP_ID = '${vc4.GetString("HVD_PROID")}'"$)
					If vc5.RowCount > 0 Then
						vc5.Position= 0
'						Log(vc5.GetString("CAT_GP_PRECIO"))
						Cuenta2 = Cuenta2 +((vc4.GetString("HVD_CANT")- vc4.GetString("HVD_RECHAZOCANT"))*vc5.GetString("CAT_GP_PRECIO"))
						arti2 = arti2 +(vc4.GetString("HVD_CANT")- vc4.GetString("HVD_RECHAZOCANT"))
					End If
				End If
			End If
			
		Next
	End If
'	Log(Cuenta)
	
	L_TOTAL.Text = Cuenta + Cuenta1 + Cuenta2
	L_CANT.Text = arti + arti1 +arti2
	

End Sub

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

Sub b_regresar_Click
	B4XPages.ShowPage("Cliente")
End Sub

Private Sub B4XPage_CloseRequest As ResumableSub
	' BACK key pressed
	' I want to capture the key here so I return True
	B4XPages.ShowPage("Cliente")
	' Returning False signals the system to handle the key
	Return False
End Sub

Sub ListView1_ItemLongClick (Position As Int, Value As Object) 'BORRAR
'	nombre_prod = Value
'	result =  Msgbox2("Seguro que desa borrar este articulo?","Borrar Articulo", "Si", "", "No",LoadBitmap(File.DirAssets,"alert2.png")) 'ignore
'	If result = DialogResponse.POSITIVE Then
'		c=Starter.skmt.ExecQuery2("select HVD_CANT FROM hist_ventas where HVD_pronombre = ? and HVD_cliente in (Select CUENTA from cuentaa) and HVD_RECHAZO = 0  ", Array As String(Value))
'		c.Position=0
'		If c.GetString("HVD_CANT") > 1 Then
'			b_regresar.Visible =False
'			b_borra.Visible=False
'			P1.Visible =True
'			cuantos_pedido = c.GetString("HVD_CANT")
'			lv2.Clear
'			lv2.SingleLineLayout.Label.TextColor = Colors.Black
'			For i=1 To c.GetString("HVD_CANT")
'				lv2.AddSingleLine(i)
'			Next
'		Else
'			'	 skmt.ExecNonQuery2("update cat_gunaprod set cat_gp_almacen = cat_gp_almacen + ? where cat_gp_nombre = ?", Array As Object(c.GetString("HVD_CANT"),Value))
'			c.Close
'			Starter.skmt.ExecNonQuery2("insert into reparto(REP_CLIENTE, REP_PRONOMBRE, REP_CANT, REP_COSTO_TOT,REP_FECHA, REP_CLI_ORIG)  select  HVD_CLIENTE, HVD_PRONOMBRE, HVD_CANT, HVD_COSTO_TOT, HVD_FECHA, HVD_CLIENTE from hist_ventas where HVD_PRONOMBRE = ? and HVD_cliente in (Select CUENTA from cuentaa) ", Array As String(Value))
'			c=Starter.skmt.ExecQuery2("select HVD_CANT FROM hist_ventas where HVD_pronombre = ? and HVD_cliente in (Select CUENTA from cuentaa) and HVD_RECHAZO = 0 ", Array As String(Value))
'			c.Position=0
'			Starter.skmt.ExecNonQuery2("update cat_gunaprod set cat_gp_almacen = cat_gp_almacen + ? where cat_gp_nombre = ?", Array As Object(c.GetString("HVD_CANT"),Value))
'			c.Close
'	
'			'skmt.ExecNonQuery2("delete FROM HIST_VENTAS WHERE HVD_PRONOMBRE = ? and HVD_cliente in (Select CUENTA from cuentaa) ", Array As String(Value))
'			' se cambia por update para no borrarlo y tener todos los registros.
'			Starter.skmt.ExecNonQuery2("update HIST_VENTAS set HVD_RECHAZO = 1 WHERE HVD_PRONOMBRE = ? and HVD_cliente in (Select CUENTA from cuentaa) ", Array As String(Value))
	'
'			DateTime.DateFormat = "MM/dd/yyyy"
'			sDate=DateTime.Date(DateTime.Now)
'			sTime=DateTime.Time(DateTime.Now)
'			c=Starter.skmt.ExecQuery("Select CUENTA from cuentaa")
'			c.Position=0
'			clie_id = c.GetString("CUENTA")
'			c=Starter.skmt.ExecQuery("select USUARIO from usuarioa")
'			c.Position=0
'			usuario = c.GetString("USUARIO")
'			'quitar esta mamada no es ahi
'			Starter.skmt.ExecNonQuery("UPDATE kmt_info set gestion = 3  where CAT_CL_CODIGO In (select cuenta from cuentaa)")
'			B4XPage_Appear
'		End If
'			 
'	End If
End Sub

Sub lv2_ItemClick (Position As Int, Value As Object) 'BORRAR
'	'  If Value = "Todos" Then
'	' cuantos = c.GetString("HVD_CANT")
'	'Else
'	cuantos = Value
'	' End If
'	If cuantos = cuantos_pedido Then
'		'Starter.skmt.ExecNonQuery2("update cat_gunaprod set cat_gp_almacen = cat_gp_almacen + ? where cat_gp_nombre = ?", Array As Object(c.GetString("HVD_CANT"),nombre_prod))
'		c.Close
'		Starter.skmt.ExecNonQuery2("insert into reparto(REP_CLIENTE, REP_PRONOMBRE, REP_CANT, REP_COSTO_TOT, REP_FECHA, REP_CLI_ORIG)  select  HVD_CLIENTE, HVD_PRONOMBRE, HVD_CANT, HVD_COSTO_TOT, HVD_FECHA, HVD_CLIENTE from hist_ventas where HVD_PRONOMBRE = ? and HVD_cliente in (Select CUENTA from cuentaa) ", Array As String(nombre_prod))
'		c=Starter.skmt.ExecQuery2("select HVD_CANT FROM hist_ventas where HVD_pronombre = ? and HVD_cliente in (Select CUENTA from cuentaa) and HVD_RECHAZO = 0  ", Array As String(nombre_prod))
'		c.Position=0
'		Starter.skmt.ExecNonQuery2("update cat_gunaprod set cat_gp_almacen = cat_gp_almacen + ? where cat_gp_nombre = ?", Array As Object(c.GetString("HVD_CANT"),nombre_prod))
'		c.Close
'		'Starter.skmt.ExecNonQuery2("delete FROM HIST_VENTAS WHERE HVD_PRONOMBRE = ? and HVD_cliente in (Select CUENTA from cuentaa) ", Array As String(Value))
'		' se cambia por update para no borrarlo y tener todos los registros.
'		Starter.skmt.ExecNonQuery2("update HIST_VENTAS set HVD_RECHAZO = 1 WHERE HVD_PRONOMBRE = ? and HVD_cliente in (Select CUENTA from cuentaa) and HVD_RECHAZO = 0  ", Array As String(Value))
'		DateTime.DateFormat = "MM/dd/yyyy"
'		sDate=DateTime.Date(DateTime.Now)
'		sTime=DateTime.Time(DateTime.Now)
'		c=Starter.skmt.ExecQuery("Select CUENTA from cuentaa")
'		c.Position=0
'		clie_id = c.GetString("CUENTA")
'		c=Starter.skmt.ExecQuery("select USUARIO from usuarioa")
'		c.Position=0
'		usuario = c.GetString("USUARIO")
'		'quitar esta m*m*d* no es ahi
'		Starter.skmt.ExecNonQuery("UPDATE kmt_info set gestion = 3  where CAT_CL_CODIGO In (select cuenta from cuentaa)")
'		Starter.skmt.ExecNonQuery2("update hist_Ventas set  HVD_RECHAZO = 1, HVD_PARCIAL = 0, HVD_CANT = HVD_CANT - ? where HVD_pronombre = ? and HVD_cliente in (Select CUENTA from cuentaa) and HVD_RECHAZO = 0 ", Array As Object(cuantos, nombre_prod))
'		b_regresar.Visible =True
'		b_borra.Visible=True
'		P1.Visible =False
'		B4XPage_Appear
'	Else
'		'	skmt.ExecNonQuery2("update cat_gunaprod set cat_gp_almacen = cat_gp_almacen + ? where cat_gp_nombre = ?", Array As Object(cuantos,nombre_prod))
'		c.Close
	'
'		'modificar tambien esto
'		'Modificaciones para que solo quite una parte.
'		Starter.skmt.ExecNonQuery2("insert into reparto(REP_CLIENTE, REP_PRONOMBRE, REP_CANT, REP_COSTO_TOT, REP_FECHA, REP_CLI_ORIG) select HVD_CLIENTE, HVD_PRONOMBRE, ?, ? * (HVD_COSTO_TOT/?), HVD_FECHA, HVD_CLIENTE from hist_ventas where HVD_PRONOMBRE = ? and HVD_cliente in (Select CUENTA from cuentaa) ", Array As Object(cuantos,cuantos,cuantos_pedido, nombre_prod))
'		Starter.skmt.ExecNonQuery2("insert into hist_ventas(HVD_CLIENTE,HVD_PRONOMBRE,HVD_CANT,HVD_COSTO_TOT, HVD_FECHA, HVD_CODPROMO, HVD_PROID,HVD_NUM_TICKET, HVD_NUM_REGISTRO, HVD_RECHAZO, HVD_ESTATUS, HVD_PARCIAL) select HVD_CLIENTE,HVD_PRONOMBRE,?,HVD_COSTO_TOT, HVD_FECHA, HVD_CODPROMO, HVD_PROID,HVD_NUM_TICKET, HVD_NUM_REGISTRO, 1, HVD_ESTATUS, 1 from hist_ventas where HVD_PRONOMBRE = ? and HVD_cliente in (Select CUENTA from cuentaa) ", Array As Object(cuantos, nombre_prod))
'		Starter.skmt.ExecNonQuery2("update hist_Ventas set  HVD_RECHAZO = 0, HVD_PARCIAL = 1, HVD_CANT = HVD_CANT - ? where HVD_pronombre = ? and HVD_cliente in (Select CUENTA from cuentaa) and HVD_RECHAZO = 0  ", Array As Object(cuantos, nombre_prod))
'		Starter.skmt.ExecNonQuery2("update hist_Ventas set  HVD_COSTO_TOT = HVD_CANT * (HVD_COSTO_TOT/?) where HVD_pronombre = ? and HVD_cliente in (Select CUENTA from cuentaa) and HVD_RECHAZO = 0  ", Array As Object(cuantos_pedido, nombre_prod))
'		Starter.skmt.ExecNonQuery2("update cat_gunaprod set cat_gp_almacen = cat_gp_almacen + ? where cat_gp_nombre = ?", Array As Object(cuantos,nombre_prod))
'		'crear nueva tabla para que guarde el resto.
	''		skmt.ExecNonQuery2("delete FROM HIST_VENTAS WHERE HVD_PRONOMBRE = ? and HVD_cliente in (Select CUENTA from cuentaa) ", Array As String(Value))
'		DateTime.DateFormat = "MM/dd/yyyy"
'		sDate=DateTime.Date(DateTime.Now)
'		sTime=DateTime.Time(DateTime.Now)
'		c=Starter.skmt.ExecQuery("Select CUENTA from cuentaa")
'		c.Position=0
'		clie_id = c.GetString("CUENTA")
'		c=Starter.skmt.ExecQuery("select USUARIO from usuarioa")
'		c.Position=0
'		usuario = c.GetString("USUARIO")
'		Starter.skmt.ExecNonQuery("UPDATE kmt_info set gestion = 3  where CAT_CL_CODIGO In (select cuenta from cuentaa)")
'		B4XPage_Appear
'		b_regresar.Visible =True
'		b_borra.Visible=True
'		P1.Visible =False
'	End If
End Sub

'****************************************************************************
'***************** PARA EL MAS/MENOS *************************************
'****************************************************************************

Sub CreateListItem(Text As String, precioU As String, inv As Int, inv2 As Int, Width As Int, Height As Int, img As Bitmap, prodId As String, bc As Int, tc As Int, promo As String, cliente_original As String) As Panel
	Dim p As B4XView = xui.CreatePanel("")
	Private cs As CSBuilder
	cs.Initialize
	p.SetLayoutAnimated(0, 0, 0, Width, Height)
	p.LoadLayout("prodItem2")
	p_prods.Color = bc
	l_prodX.TextColor = tc
	precioU = $"$1.2{precioU}"$
	l_prodX.Text = Text&CRLF&"Cant: " & inv2 & "   $" & precioU
	If promo <> "1" And precioU = 0 Then
		l_prodX.Text = cs.Color(Colors.RGB(123,0,0)).append(Text&CRLF&"Cant: " & inv2 & "   $" & precioU).PopAll
	End If
	l_prodX.Tag = $"ID: ${prodId}${CRLF}${Text}${CRLF}Precio: $$1.2{precioU}${CRLF}Inv: ${inv} pzs"$
'	l_pCant.Text = 0
	Log("PRECIO " & Round2(precioU,2)&"| INV "&inv&"| ID "&prodId&"| PROMO "&promo&"| INV2? "&inv2&"| CLIENTE OR NONONO YA NO VA Y UN ESPACIO POR FAVOR "&cliente_original)
	l_pCant.Tag = Round2(precioU,2)&"|"&inv&"|"&prodId&"|"&promo&"|"&inv2&"|"&cliente_original
	et_pCant.Tag = Round2(precioU,2)&"|"&inv&"|"&prodId&"|"&promo&"|"&inv2&"|"&cliente_original
	p_prods.Tag = l_pCant.tag
'	Log($"Ponemos la cant en ${inv}"$)
	l_pCant.Text = inv
'	et_pCant.Text = inv
'	et_pCant.BringToFront

	l_pCant.BringToFront
	et_pCant.SendToBack
	p_botMasMenC.Visible = False
'	i_prod.Bitmap = img
	Return p
End Sub

Sub CreateListItem2(Text As String, precioU As String, inv As Int, inv2 As Int, Width As Int, Height As Int, img As Bitmap, prodId As String, bc As Int, tc As Int, promo As String, cliente_original As String) As Panel
	Dim p As B4XView = xui.CreatePanel("")
	Private cs As CSBuilder
	cs.Initialize
	p.SetLayoutAnimated(0, 0, 0, Width, Height)
	p.LoadLayout("prodItem2")
	p_prods.Color = bc
	l_prodX.TextColor = tc
	precioU = $"$1.2{precioU}"$
	l_prodX.Text = Text&CRLF&"Cant: " & inv2 & "   $" & precioU
	If promo <> "1" And precioU = 0 Then
		l_prodX.Text = cs.Color(Colors.RGB(123,0,0)).append(Text&CRLF&"Cant: " & inv2 & "   $" & precioU).PopAll
	End If
	l_prodX.Tag = $"ID: ${prodId}${CRLF}${Text}${CRLF}Precio: $$1.2{precioU}${CRLF}Inv: ${inv} pzs"$
'	l_pCant.Text = 0
	l_pCantC.Tag = Round2(precioU,2)&"|"&inv&"|"&prodId&"|"&promo&"|"&inv2&"|"&cliente_original
	et_pCantC.Tag = Round2(precioU,2)&"|"&inv&"|"&prodId&"|"&promo&"|"&inv2&"|"&cliente_original
	p_prods.Tag = l_pCantC.tag
'	Log($"Ponemos la cant en ${inv}"$)
	l_pCantC.Text = NumberFormat2(inv/Subs.traeConversion(prodId),0,0,0,False)
'	et_pCant.Text = inv
'	et_pCant.BringToFront

	l_pCantC.BringToFront
	et_pCantC.SendToBack
	p_botMasMen.Visible = False
'	i_prod.Bitmap = img
	Return p
End Sub

Sub b_prodMenos_Click
	etCantHasFocus = False
	Log("etCantHasFocus=" & etCantHasFocus)
	LogColor("b_prodMenos_Click", Colors.Magenta)
	Dim index As Int = clv_pedido.GetItemFromView(Sender)
	Dim pnl0 As B4XView = clv_pedido.GetPanel(index)
	Dim pnl As B4XView = pnl0.GetView(0)
	Dim laCant As B4XView = pnl.GetView(2).GetView(3)
'	Log(pnl.GetView(2).GetView(0) & "|" & pnl.GetView(2).GetView(1) & "|" & pnl.GetView(2).GetView(2))
	Dim esteTag As List = Regex.Split("\|", laCant.Tag)
	Log("LC_TEXT:"&laCant.Text&"|PROMO:"&esteTag.Get(3)&"|LC_TAG:"&laCant.Tag&"|ET:"&esteTag)
	If laCant.Text > 0 Then
'		If esteTag.Get(3) <> Subs.traeAlmacen Then 'Si es PROMO entonces ...
'			Private c2 As Cursor =Starter.skmt.ExecQuery($"select HVD_RECHAZO FROM HIST_VENTAS WHERE HVD_PROID = '${esteTag.Get(2)}' AND HVD_CLIENTE IN (Select CUENTA from cuentaa)"$)
'			c2.Position = 0
'			If c2.GetString("HVD_RECHAZO") = "0" Then
'			
'			
'				Log("ES PROMO")
'				result =  Msgbox2("Si se modifica una promoción, la promoción se rompe y solo quedarán los productos sueltos, ¿seguro que desea continuar?","Modificar Promoción", "Si", "", "No",LoadBitmap(File.DirAssets,"alert2.png")) 'ignore
'				If result = DialogResponse.POSITIVE Then 'Quitamos esta promo
'					prodsMap.Remove(esteTag.Get(3))
''				c=Starter.skmt.ExecQuery($"select HVD_CODPROMO FROM HIST_VENTAS WHERE HVD_CODPROMO = '${esteTag.Get(2)}' AND HVD_cliente IN (Select CUENTA from cuentaa)"$)
''				For i = 0 To c.RowCount -1
''					c.Position = i
'					LogColor(esteTag.Get(3),Colors.Blue)
'					Starter.skmt.ExecNonQuery($"update HIST_VENTAS set HVD_RECHAZO = 1,  HVD_RECHAZOCANT = HVD_RECHAZOCANT + 1  WHERE  HVD_CODPROMO = '${esteTag.Get(3)}' and HVD_CLIENTE =  '${esteTag.Get(5)}'"$)
'					Starter.skmt.ExecNonQuery($"update HIST_VENTAS set HVD_RECHAZO = 2,  HVD_RECHAZOCANT = HVD_RECHAZOCANT + 1  WHERE HVD_PROID = '${esteTag.Get(3)}' and HVD_CODPROMO = '${esteTag.Get(3)}' and HVD_CLIENTE in (Select CUENTA from cuentaa)"$)
''				Starter.skmt.ExecNonQuery($"update HIST_VENTAS set HVD_CODPROMO = '${Subs.traeAlmacen}' WHERE HVD_cliente in (Select CUENTA from cuentaa) AND HVD_CODPROMO = '${esteTag.Get(3)}'"$)
''				Next
'					c.Close
'					LogColor(prodsMap, Colors.red)
'					reconstruirPedido = True
'					promoABorrar = esteTag.Get(3)
'					B4XPage_Appear
'				End If
'			Else
'				If laCant.Text = "" Then laCant.Text = 0
'				laCant.Text = $"$1.0{laCant.Text-1}"$
'				If laCant.Text < 0 Then laCant.Text = 0
'				Log("NO ES promo")
'				Starter.skmt.ExecNonQuery($"update HIST_VENTAS set HVD_RECHAZO = 1,  HVD_RECHAZOCANT = IFNULL(HVD_RECHAZOCANT,0) + 1  WHERE HVD_PROID = '${esteTag.Get(2)}' and HVD_cliente in (Select CUENTA from cuentaa)"$)
'				Starter.skmt.ExecNonQuery2("update cat_gunaprod set cat_gp_almacen = cat_gp_almacen + 1 where cat_gp_id = ?", Array As Object(esteTag.Get(2)))
'				B4XPage_Appear
'			End If
'		Else
		If laCant.Text = "" Then laCant.Text = 0
		laCant.Text = $"$1.0{laCant.Text-1}"$
		If laCant.Text < 0 Then laCant.Text = 0
		Log("NO ES promo")
		Starter.skmt.ExecNonQuery($"update HIST_VENTAS set HVD_RECHAZO = 1,  HVD_RECHAZOCANT = IFNULL(HVD_RECHAZOCANT,0) + 1  WHERE HVD_PROID = '${esteTag.Get(2)}' and HVD_cliente = '${esteTag.Get(5)}'"$)
'			Starter.skmt.ExecNonQuery2("update cat_gunaprod set cat_gp_almacen = cat_gp_almacen + 1 where cat_gp_id = ?", Array As Object(esteTag.Get(2)))
'		Starter.skmt.ExecNonQuery2("update PEDIDO set cat_gp_almacen = cat_gp_almacen + 1 where cat_gp_id = ?", Array As Object(esteTag.Get(2)))

		Private c3 As Cursor = Starter.skmt.ExecQuery2("SELECT PE_CANT FROM PEDIDO WHERE PE_PROID = ? AND PE_CLIENTE IN (SELECT CUENTA FROM CUENTAA)", Array As String(esteTag.Get(2)))
		If c3.RowCount > 0 Then
			c3.Position = 0
			If c3.GetString("PE_CANT") > 1 Then
				Private c2 As Cursor = Starter.skmt.ExecQuery2("SELECT * FROM CAT_GUNAPROD WHERE CAT_GP_ID = ?", Array As String(esteTag.Get(2)))
				If c2.RowCount > 0 Then
					c2.Position = 0
'			Starter.skmt.ExecNonQuery($"update HIST_VENTAS set HVD_RECHAZO = 1,  HVD_RECHAZOCANT = HVD_RECHAZOCANT - 1  WHERE HVD_PROID = '${esteTag.Get(2)}' and HVD_cliente =  '${esteTag.Get(5)}'"$)
					Starter.skmt.ExecNonQuery($"update PEDIDO set PE_CANT = IFNULL(PE_CANT,0)-1, PE_COSTO_TOT= ((IFNULL(PE_CANT,0) -1)*'${c2.GetString("CAT_GP_PRECIO")}') WHERE PE_PROID = '${esteTag.Get(2)}' and PE_CLIENTE in (Select CUENTA from cuentaa)"$)
				End If
			Else If c3.GetString("PE_CANT") = 1 Then
				Private c2 As Cursor = Starter.skmt.ExecQuery2("SELECT * FROM CAT_GUNAPROD WHERE CAT_GP_ID = ?", Array As String(esteTag.Get(2)))
				If c2.RowCount > 0 Then
					c2.Position = 0
'			Starter.skmt.ExecNonQuery($"update HIST_VENTAS set HVD_RECHAZO = 1,  HVD_RECHAZOCANT = HVD_RECHAZOCANT - 1  WHERE HVD_PROID = '${esteTag.Get(2)}' and HVD_cliente =  '${esteTag.Get(5)}'"$)
'					Starter.skmt.ExecNonQuery($"update PEDIDO set PE_CANT = IFNULL(PE_CANT,0)-1, PE_COSTO_TOT= ((IFNULL(PE_CANT,0) -1)*'${c2.GetString("CAT_GP_PRECIO")}') WHERE PE_PROID_PROID = '${esteTag.Get(2)}' and PE_CLIENTE in (Select CUENTA from cuentaa)"$)
					Starter.skmt.ExecNonQuery($"delete from PEDIDO where PE_PROID = '${esteTag.Get(2)}' and PE_CLIENTE in (Select CUENTA from cuentaa)"$)
				End If
			End If
		
		
		
		End If
		B4XPage_Appear
''		End If
	End If
	Dim preciou As Float = esteTag.Get(0)/esteTag.Get(1)
	Log("PU: " & preciou)
'	LogColor("estamos aqui mmenos " & laCant.Text& " , " & (preciou * laCant.Text),Colors.Green )
'	If L_CANT.Text - 1 >= 0  Then 
'		L_CANT.Text = L_CANT.Text - 1
'	End If
'	b_guardar.Visible = True
'	Subs.prodRechazo(esteTag.Get(5), esteTag.Get(2))
'	Private cym As Map = Subs.traemosCantYMonto(clv_pedido)
'	L_CANT.Text = cym.Get("cantidad")
'	L_TOTAL.Text = Round2(cym.Get("monto"), 2)
'	cuentaProds("-")
End Sub

Sub b_prodMas_Click
	etCantHasFocus = False
'	Log("etCantHasFocus=" & etCantHasFocus)
	LogColor("b_prodMas_Click", Colors.Magenta)
	Dim index As Int = clv_pedido.GetItemFromView(Sender)
	Dim pnl0 As B4XView = clv_pedido.GetPanel(index)
	Dim pnl As B4XView = pnl0.GetView(0)
	Dim laCant As B4XView = pnl.GetView(2).GetView(3)
'	Log(pnl.GetView(2).GetView(1).text&"|"&pnl.GetView(2).GetView(2)&"|"&pnl.GetView(2).GetView(4).text)
'	Log($"precio|stock:${laCant.tag}"$)
'	Log($"Indice: ${index}, cant:${laCant.Text+1}, precioU: ${laCant.tag}"$)
	Dim esteTag As List = Regex.Split("\|", laCant.Tag)
	Log("LC_TEXT:"&laCant.Text&"|LC_TAG:"&laCant.Tag&"|ET:"&esteTag)
	If laCant.Text = "" Then laCant.Text = 0
	
	Private maxProds = esteTag.Get(1) + esteTag.Get(4) 'Prods disponibles + prods comprados
	
	LogColor($"++++++++++++++++++++++++++   ${esteTag}"$, Colors.Green)
'	Log(esteTag.get(4))

	If laCant.Text + 1 <= maxProds Then
		Log($"NuevaCant = ${laCant.Text + 1}"$)
		laCant.Text = $"$1.0{laCant.Text + 1}"$
		Starter.skmt.ExecNonQuery2("update cat_gunaprod set cat_gp_almacen = cat_gp_almacen - 1 where cat_gp_id = ?", Array As String(esteTag.Get(2)))
		c = Starter.skmt.ExecQuery2("SELECT * FROM PEDIDO WHERE PE_PROID = ? and PE_CLIENTE IN (SELECT CUENTA FROM CUENTAA)", Array As String(esteTag.Get(2)))
		If c.RowCount > 0 Then
			Private c2 As Cursor = Starter.skmt.ExecQuery2("SELECT * FROM CAT_GUNAPROD WHERE CAT_GP_ID = ?", Array As String(esteTag.Get(2)))
			If c2.RowCount > 0 Then
				c2.Position = 0
				Starter.skmt.ExecNonQuery($"update HIST_VENTAS set HVD_RECHAZO = 1,  HVD_RECHAZOCANT = HVD_RECHAZOCANT - 1  WHERE HVD_PROID = '${esteTag.Get(2)}' and HVD_cliente =  '${esteTag.Get(5)}'"$)
				Starter.skmt.ExecNonQuery($"update PEDIDO set PE_CANT = IFNULL(PE_CANT,0)+1, PE_COSTO_TOT= ((IFNULL(PE_CANT,0)+1)*'${c2.GetString("CAT_GP_PRECIO")}') WHERE PE_PROID = '${esteTag.Get(2)}' and PE_CLIENTE in (Select CUENTA from cuentaa)"$)
			End If
		Else
			Private c2 As Cursor = Starter.skmt.ExecQuery2("SELECT * FROM CAT_GUNAPROD WHERE CAT_GP_ID = ?", Array As String(esteTag.Get(2)))
			If c2.RowCount > 0 Then
				c2.Position = 0
				Starter.skmt.ExecNonQuery($"update HIST_VENTAS set HVD_RECHAZO = 1,  HVD_RECHAZOCANT = HVD_RECHAZOCANT - 1  WHERE HVD_PROID = '${esteTag.Get(2)}' and HVD_cliente =  '${esteTag.Get(5)}'"$)
				Starter.skmt.ExecNonQuery2("INSERT INTO PEDIDO(PE_PROID,PE_PRONOMBRE,PE_CANT,PE_CLIENTEOR,PE_CLIENTE,PE_COSTOU,PE_COSTO_TOT,PE_CAJAS,PE_BCAJAS) VALUES (?,?,?,?,?,?,?,0,0)", Array As String(esteTag.Get(2),c2.GetString("CAT_GP_NOMBRE"),1,esteTag.Get(5),Subs.traeCliente,c2.GetString("CAT_GP_PRECIO"),c2.GetString("CAT_GP_PRECIO")))
			End If
		End If
		

		Subs.prodVenta(esteTag.Get(5), esteTag.Get(2))
'		Private cym As Map = Subs.traemosCantYMonto(clv_pedido)
'		L_CANT.Text = cym.Get("cantidad")
'		L_TOTAL.Text = Round2(cym.Get("monto"), 2)
'		cuentaProds("+")
		B4XPage_Appear
	End If
'	Dim preciou As Float = esteTag.Get(0)/esteTag.Get(1)
'	Log(preciou)
'	LogColor("estamos aquii mas " & laCant.Text& " , " & (preciou * laCant.Text) ,Colors.Green )
'	b_guardar.Visible = True
'	Log($"Total Prods: ${totalProds}, Total Compra: $$1.2{totalCompra}"$)
'	c = Starter.skmt.ExecQuery($"SELECT HVD_CANT FROM HIST_VENTAS2 WHERE HVD_CLIENTE IN (SELECT CUENTA FROM CUENTAA) AND HVD_PROID = '${esteTag.Get(2)}' "$)
'	c.Position = 0
'	Dim cantoriginal As String = 0
'	If c.RowCount > 0 Then
'		cantoriginal = c.GetString("HVD_CANT")
'	End If
'	If cantoriginal <= esteTag.Get(1)  Then
'		L_CANT.Text = L_CANT.Text + 1
'	End If
End Sub


Private Sub b_prodMasC_Click
	etCantHasFocus = False
'	Log("etCantHasFocus=" & etCantHasFocus)
	LogColor("b_prodMas_Click", Colors.Magenta)
	Dim index As Int = clv_pedido.GetItemFromView(Sender)
	Dim pnl0 As B4XView = clv_pedido.GetPanel(index)
	Dim pnl As B4XView = pnl0.GetView(0)
	Dim laCantc As B4XView = pnl.GetView(3).GetView(3)
'	Log(pnl.GetView(2).GetView(1).text&"|"&pnl.GetView(2).GetView(2)&"|"&pnl.GetView(2).GetView(4).text)
'	Log($"precio|stock:${laCant.tag}"$)
'	Log($"Indice: ${index}, cant:${laCant.Text+1}, precioU: ${laCant.tag}"$)
	Dim esteTag As List = Regex.Split("\|", laCantc.Tag)
	Log("LC_TEXT:"&laCantc.Text&"|LC_TAG:"&laCantc.Tag&"|ET:"&esteTag)
	If laCantc.Text = "" Then laCantc.Text = 0
	
	Private maxProds As String = (esteTag.Get(1) + esteTag.Get(4))'Prods disponibles + prods comprados
	LogColor(esteTag.Get(1),Colors.Red)
	LogColor(esteTag.Get(4),Colors.Red)
	LogColor($"++++++++++++++++++++++++++   ${esteTag}"$, Colors.Green)
'	Log(esteTag.get(4))
	Log(maxProds)
	
'	l_pCantC.Tag = Round2(precioU,2)&"|"&inv&"|"&prodId&"|"&promo&"|"&inv2&"|"&cliente_original
	
	If laCantc.Text + 1 <= maxProds Then		
		Log($"NuevaCant = ${laCantc.Text + 1}"$)
		laCantc.Text = NumberFormat2((laCantc.Text + 1),0,0,0,False)
		
		Log(laCantc.Text)
'				Starter.skmt.ExecNonQuery($"update HIST_VENTAS set HVD_RECHAZO = 1,  HVD_RECHAZOCANT = IFNULL(HVD_RECHAZOCANT,0) -(1 * ${Subs.traeConversion(esteTag.Get(2))})  WHERE HVD_PROID = '${esteTag.Get(2)}' and HVD_cliente in (Select CUENTA from cuentaa)"$)
		
		c = Starter.skmt.ExecQuery2("SELECT * FROM PEDIDO WHERE PE_PROID = ? and PE_CLIENTE IN (SELECT CUENTA FROM CUENTAA)", Array As String(esteTag.Get(2)))
		If c.RowCount > 0 Then
			Private c2 As Cursor = Starter.skmt.ExecQuery2("SELECT * FROM CAT_GUNAPROD WHERE CAT_GP_ID = ?", Array As String(esteTag.Get(2)))
			If c2.RowCount > 0 Then
				c2.Position = 0
				Starter.skmt.ExecNonQuery($"update HIST_VENTAS set HVD_RECHAZO = 1,  HVD_RECHAZOCANT =(IFNULL(HVD_RECHAZOCANT,0) -(1 * ${Subs.traeConversion(esteTag.Get(2))}) ) WHERE HVD_PROID = '${esteTag.Get(2)}' and HVD_cliente =  '${esteTag.Get(5)}'"$)
				Starter.skmt.ExecNonQuery($"update PEDIDO set PE_CANT = (IFNULL(PE_CANT,0)+(1 * '${Subs.traeConversion(esteTag.Get(2))}')), PE_COSTO_TOT= (IFNULL(PE_CAJAS,0)+1)*'${Subs.traePrecioC(esteTag.Get(2))}', PE_CAJAS= IFNULL(PE_CAJAS,0) + 1 WHERE PE_PROID = '${esteTag.Get(2)}' and PE_CLIENTE in (Select CUENTA from cuentaa)"$)
				B4XPage_Appear
			End If
		Else
			Private c2 As Cursor = Starter.skmt.ExecQuery2("SELECT * FROM CAT_GUNAPROD WHERE CAT_GP_ID = ?", Array As String(esteTag.Get(2)))
			If c2.RowCount > 0 Then
				c2.Position = 0
				Starter.skmt.ExecNonQuery($"update HIST_VENTAS set HVD_RECHAZO = 1,  HVD_RECHAZOCANT = IFNULL(HVD_RECHAZOCANT,0) -(1 * ${Subs.traeConversion(esteTag.Get(2))})  WHERE HVD_PROID = '${esteTag.Get(2)}' and HVD_cliente =  '${esteTag.Get(5)}'"$)
				Starter.skmt.ExecNonQuery2("INSERT INTO PEDIDO(PE_PROID,PE_PRONOMBRE,PE_CANT,PE_CLIENTEOR,PE_CLIENTE,PE_COSTOU,PE_COSTO_TOT,PE_CAJAS,PE_BCAJAS) VALUES (?,?,?,?,?,?,?,1,1)", Array As String(esteTag.Get(2),c2.GetString("CAT_GP_NOMBRE"),Subs.traeConversion(esteTag.Get(2)),esteTag.Get(5),Subs.traeCliente,Subs.traePrecioC(esteTag.Get(2)),Subs.traePrecioC(esteTag.Get(2))))
				B4XPage_Appear
			End If
		End If
		
	End If
End Sub

Private Sub b_prodMenosC_Click
	etCantHasFocus = False
	Log("etCantHasFocus=" & etCantHasFocus)
	LogColor("b_prodMenos_Click", Colors.Magenta)
	Dim index As Int = clv_pedido.GetItemFromView(Sender)
	Dim pnl0 As B4XView = clv_pedido.GetPanel(index)
	Dim pnl As B4XView = pnl0.GetView(0)
	Dim laCantc As B4XView = pnl.GetView(3).GetView(3)
'	Log(pnl.GetView(2).GetView(0) & "|" & pnl.GetView(2).GetView(1) & "|" & pnl.GetView(2).GetView(2))
	Dim esteTag As List = Regex.Split("\|", laCantc.Tag)
	Log("LC_TEXT:"&laCantc.Text&"|PROMO:"&esteTag.Get(3)&"|LC_TAG:"&laCantc.Tag&"|ET:"&esteTag)
	If laCantc.Text > 0 Then
		
		Starter.skmt.ExecNonQuery($"update HIST_VENTAS set HVD_RECHAZO = 1,  HVD_RECHAZOCANT = (IFNULL(HVD_RECHAZOCANT,0) +(1 * ${Subs.traeConversion(esteTag.Get(2))}))  WHERE HVD_PROID = '${esteTag.Get(2)}' and HVD_cliente = '${esteTag.Get(5)}'"$)
		Private c3 As Cursor = Starter.skmt.ExecQuery2("SELECT PE_CAJAS FROM PEDIDO WHERE PE_PROID = ? AND PE_CLIENTE IN (SELECT CUENTA FROM CUENTAA)", Array As String(esteTag.Get(2)))
		If c3.RowCount > 0 Then
			c3.Position = 0
			If c3.GetString("PE_CAJAS") > 1 Then
				Starter.skmt.ExecNonQuery($"update PEDIDO set PE_CANT = (IFNULL(PE_CANT,0)-(1 * '${Subs.traeConversion(esteTag.Get(2))}')), PE_COSTO_TOT= ((IFNULL(PE_CAJAS,0)-1) *'${Subs.traePrecioC(esteTag.Get(2))}'), PE_CAJAS = IFNULL(PE_CAJAS,0) - 1 WHERE PE_PROID = '${esteTag.Get(2)}' and PE_CLIENTE in (Select CUENTA from cuentaa)"$)
			Else If c3.GetString("PE_CAJAS") = 1 Then
					Starter.skmt.ExecNonQuery($"delete from PEDIDO where PE_PROID = '${esteTag.Get(2)}' and PE_CLIENTE in (Select CUENTA from cuentaa)"$)
			End If
		End If
		Log("entre al if o algo asi ")
		If laCantc.Text = "" Then laCantc.Text = 0
		laCantc.Text = laCantc.Text - 1
		If laCantc.Text < 0 Then laCantc.Text = 0
		B4XPage_Appear
'		Starter.skmt.ExecNonQuery2("update cat_gunaprod set cat_gp_almacen = (cat_gp_almacen + (1 * ?)) where cat_gp_id = ?", Array As Object(esteTag.Get(2), Subs.traeConversion(esteTag.Get(2))))
	Else If laCantc.Text = 0 Then
		
	End If
	Dim preciou As Float = esteTag.Get(0)/esteTag.Get(1)
	Log("PU: " & preciou)
End Sub

Private Sub l_pCantC_Click
	
End Sub

Private Sub b_revversar_Click
	Starter.skmt.ExecNonQuery($"update HIST_VENTAS set HVD_RECHAZO = 0,  HVD_RECHAZOCANT = 0  WHERE HVD_cliente in (Select CUENTA from cuentaa)"$)
	B4XPage_Appear
End Sub

Sub cuentaProds(accion As String)
	''	Log("Entramos a cuentaProds")
'	Log("*******************************************************")
'	Private cantRechazada As Int = 0
'	If Not(reconstruirPedido) Then
'		Log("***********  CUENTAPRODS - NO RECONSTRUIR")
'		prodsMap.Initialize
'		For i = 0 To clv_pedido.GetSize - 1
'			Private p0 As B4XView = clv_pedido.GetPanel(i)
'			Private p As B4XView = p0.GetView(0)
'			Private cant1 As B4XView = p.GetView(2).GetView(3)
'			If cant1.Text = "" Then cant1.Text = 0
	''			totalProds = totalProds + cant1.Text
'			Private esteTag As List = Regex.Split("\|", cant1.Tag)
'			Log("-------------------------------------")
'			Log($"ET: ${esteTag}"$)
'			Private esteProd As String = esteTag.Get(2)
'			Private estaCant As Int = cant1.Text
'			Private estaCantOriginal As Int = esteTag.Get(1)
'			Private esteCliente = Subs.traeCliente
'			Private esteProdNombre = Subs.traeNombre(esteProd)
'			Private esteClienteOriginal As Int = esteTag.Get(5)
'			Private fechaReparto As String = Subs.traeFechaReparto
'			Private maxProds = Subs.traeMaxCantidad(esteTag.Get(5), esteTag.Get(2))
'			
'			If cant1.Text > maxProds Then cant1.Text = maxProds
'			
'			cantRechazada = esteTag.Get(4) - cant1.Text
	''			If accion = "-" Then cantRechazada = Subs.traeCantidadRechazada(esteClienteOriginal, esteProd) + 1
	''			If accion = "+" Then cantRechazada = Subs.traeCantidadRechazada(esteClienteOriginal, esteProd) - 1
'			Log($"${Subs.traeCantidadRechazada(esteClienteOriginal, esteProd)}, ${Subs.traeCantidadVendida(esteClienteOriginal, esteProd)}"$)
'			
	''			LogColor($"cantRechazada = ${esteTag.Get(4)} - ${cant1.Text}"$, Colors.Magenta)
'			LogColor($"cantRechazada = ${cantRechazada}"$, Colors.Magenta)
'			Private estePrecio As String = 0
'			If Subs.traePrecio(esteProd, 1) <> Null Then estePrecio = Subs.traePrecio(esteProd, 1) * cantRechazada
'			
	''			LogColor(esteProd & "|" & cant1.Text & "|" & estaCantOriginal & "|" & cantRechazada & "|" & estePrecio, Colors.red)
	''			LogColor($"cantRechazada=${cantRechazada} | ${esteProdNombre}"$, Colors.Blue)
	''			Log($"Ponemos HVD_CANT ${esteProd} en ${cant1.text}"$)
'			Starter.skmt.ExecNonQuery2("update HIST_VENTAS set HVD_PARCIAL = 1, HVD_CANT = ? WHERE HVD_PROID = ? and HVD_CLIENTE in (Select CUENTA from cuentaa)", Array As String(cant1.Text ,esteProd))
'			Private rr As Cursor = Starter.skmt.ExecQuery($"select count(REP_CLIENTE) as hayRechazo from REPARTO where rep_prodid = '${esteProd}' and REP_CLIENTE in (Select CUENTA from cuentaa)"$)
'			rr.Position = 0
	''			Log($"HayRechazo=${rr.GetString("hayRechazo")}"$)
'			If rr.GetString("hayRechazo") = 0 Then
'				Log("INSERTAMOS EN REPARTO")
'				Starter.skmt.ExecNonQuery2("insert into reparto(REP_CLIENTE, REP_PRONOMBRE, REP_CANT, REP_COSTO_TOT, REP_FECHA, REP_RECHAZO, REP_PRODID, REP_PRECIO, REP_CLI_ORIG)  VALUES (?,?,?,?,?,1,?,?,?) ", Array As String(esteCliente, esteProdNombre, 0, estePrecio, fechaReparto, esteProd, estePrecio, esteCliente))
'				Starter.skmt.ExecNonQuery2("insert into reparto(REP_CLIENTE, REP_PRONOMBRE, REP_CANT, REP_COSTO_TOT, REP_FECHA, REP_RECHAZO, REP_PRODID, REP_PRECIO, REP_CLI_ORIG)  VALUES (?,?,?,?,?,0,?,?,?) ", Array As String(esteCliente, esteProdNombre, cantRechazada, 0, fechaReparto, esteProd, estePrecio, esteCliente))
'			Else if esteClienteOriginal = "0" Then 'Actualizamos el rechazo en el cliente actual.
	''				Log($"Actualizamos REP_CANT=${cantRechazada}"$)
	''				Starter.skmt.ExecNonQuery($"update reparto set REP_CANT = '${cantRechazada}', REP_PRECIO = '${estePrecio}', REP_COSTO_TOT = '${estePrecio * cantRechazada}' where REP_CLIENTE in (Select CUENTA from cuentaa) and REP_CLI_ORIG = '${esteClienteOriginal}' and REP_RECHAZO = 1 and REP_PRODID = '${esteProd}'"$)
'			Else 'Cliente original <> 0 entonces actualizamos el rechazo en el cliente original y NO en el actual.
'				Log($"Actualizamos REP_CANT RECHAZO = ${cantRechazada}"$)
	''				Starter.skmt.ExecNonQuery($"update reparto set REP_CANT = ${cantRechazada}, REP_PRECIO = '${estePrecio}', REP_COSTO_TOT = '${estePrecio * cantRechazada}' where REP_CLIENTE = '${esteClienteOriginal}' and REP_CLI_ORIG = '${esteClienteOriginal}' and REP_RECHAZO = 1 and REP_PRODID = '${esteProd}'"$)
	''				Starter.skmt.ExecNonQuery($"update reparto set REP_CANT = '${cant1.Text}', REP_PRECIO = '${estePrecio}', REP_COSTO_TOT = '${estePrecio * cantRechazada}' where REP_CLIENTE in (Select CUENTA from cuentaa) and REP_CLI_ORIG = '${esteClienteOriginal}' and REP_RECHAZO = 0 and REP_PRODID = '${esteProd}'"$)
'			End If
'			
'			If cant1.Text > 0 Then
	''				totalCompra = totalCompra + (esteTag.get(0) * cant1.text)
	''				Log($"Cant: ${cant1.Text}, Suma: ${totalCompra}"$)
'				Private m As Map
'				m=CreateMap("cant":cant1.Text, "cant2":esteTag.get(4), "precio":esteTag.get(0), "promo":esteTag.get(3), "nombre":Subs.traeNombre(esteTag.Get(2)), "cli_orig":esteTag.get(5))
	''				LogColor("PUT:" & esteTag.Get(2), Colors.Red)
'				prodsMap.Put(esteTag.Get(2), m)
'			End If
'			Log("-------------------------------------")
'		Next
'	End If
'	Private bgColor, textColor As Int
	'
'	If reconstruirPedido Then
'		Log("***********  CUENTAPRODS - SI RECONSTRUIR")
'		Private newPromo, newPrecio As String
'		clv_pedido.Clear
'		Log("Usamos PRODSMAP")
'		For Each pr As String In prodsMap.Keys
'			Private pr1 As Map = prodsMap.Get(pr)
'			Log("PPP: " & pr & "|PromoABorrar=" & promoABorrar & "|" & pr1)
'			bgColor = Colors.RGB(177, 200, 249)'azul
'			textColor = Colors.black
'			newPromo = pr1.Get("promo")
'			newPrecio = pr1.Get("precio")
'			Log("AAA: " & newPromo & "|" & promoABorrar)
'			If newPromo = promoABorrar Then
'				newPromo = 1
'				newPrecio = Subs.traePrecio(pr, False) * pr1.Get("cant")
'				'Ponemos precio SIN promo y sacamos el producto de la promo.
'				Starter.skmt.ExecNonQuery($"update HIST_VENTAS set HVD_COSTO_TOT = ${newPrecio}, HVD_CODPROMO ='${Subs.traeAlmacen}' WHERE HVD_PRONOMBRE = '${pr1.Get("nombre")}' and HVD_cliente in (Select CUENTA from cuentaa)"$)
'				LogColor("CAMBIAMOS PROMO: " & newPromo, Colors.Magenta)
'			End If
'			If newPromo <> "1" Then
	''				bgColor = Colors.RGB(255, 212, 163) 'naranja
'				bgColor = Colors.White
'			End If
'			Log($"CLI: ${pr1.Get("nombre")}, ${newPrecio}, ${pr1.Get("cant")}, ${pr1.Get("cant2")}"$)
'			clv_pedido.Add(CreateListItem(pr1.Get("nombre"), newPrecio, pr1.Get("cant"), pr1.Get("cant2"), clv_pedido.AsView.Width, 118dip, bmp, pr, bgColor, textColor, newPromo, pr1.Get("cli_orig")), pr1.Get("nombre"))
'			reconstruirPedido = False
'		Next
'		promoABorrar = ""
'	End If
'	Log($"Total Prods: ${totalProds}, Total Compra: $$1.2{totalCompra}"$)
'	LogColor("prodsMap=" & prodsMap, Colors.Green)
'	
	'
'	LogColor(prodsMap, Colors.Blue)
'	c = Starter.skmt.ExecQuery($"SELECT sum(HVD_CANT) as CANTIDAD FROM HIST_VENTAS WHERE HVD_CLIENTE IN (SELECT CUENTA FROM CUENTAA)"$)
'	Dim cantidad1 As String = 0
'	If c.RowCount > 0 Then
'		c.Position = 0
'		cantidad1 = c.GetString("CANTIDAD")
'		L_CANT.Text = Round(cantidad1)
'	End If
'	c.Close
'	
'	Dim totalfinal As String = 0
'	For Each pr As String In prodsMap.Keys
'		Private pr1 As Map = prodsMap.Get(pr)
	''		LogColor(pr,Colors.Red)
'		Dim x As Cursor = Starter.skmt.ExecQuery($"SELECT CAT_GP_PRECIO FROM CAT_GUNAPROD WHERE CAT_GP_ID = '${pr}'"$)
'		c = Starter.skmt.ExecQuery($"SELECT HVD_CANT FROM HIST_VENTAS WHERE HVD_CLIENTE IN (SELECT CUENTA FROM CUENTAA) AND HVD_PROID ='${pr}' "$)
'		Dim cantidady As String = 0
'		If c.RowCount >0 Then
'			c.Position = 0
'			cantidady = c.GetString("HVD_CANT")
'		End If
	''		Log(x.RowCount)
'		If x.RowCount > 0 Then
'			x.Position = 0
	''			Log(x.GetString("CAT_GP_PRECIO"))
'			Dim preciou As String = x.GetString("CAT_GP_PRECIO")
'			Dim costototalhist  As String = preciou * cantidady
	''			Log("Total ==== "&costototalhist)
'		End If
'		totalfinal = totalfinal + costototalhist
'		x.Close
'	Next
'	L_TOTAL.Text = Round2(totalfinal, 2)
'	c.Close
'	
'	c = Starter.skmt.ExecQuery("select COUNT(*) AS CUANTOS from REPARTO where REP_CLIENTE in (select cuenta from cuentaa) and REP_RECHAZO = '0' and REP_CANT > 0 order by REP_PRONOMBRE")
'	If c.RowCount > 0 Then
'		c.Position = 0
'		If c.GetString("CUANTOS") > 0 Then
'			
'			Dim z As Cursor = Starter.skmt.ExecQuery($"select SUM(REP_CANT) AS CANTIDAD , SUM(REP_PRECIO) AS PRECIO from REPARTO where REP_CLIENTE in (select cuenta from cuentaa) and REP_RECHAZO = '0' and REP_CANT > 0 order by REP_PRONOMBRE"$)
'			Dim cantidad2 As String = 0
	''			Log(z.RowCount)
'			If z.RowCount > 0 Then
'				z.Position = 0
'				cantidad2= z.GetString("CANTIDAD")
	''				LogColor(z.GetString("PRECIO")&" , " & z.GetString("CANTIDAD"), Colors.Magenta)
	''				Log(cantidad1 &" , "& cantidad2)
'				L_CANT.Text = Round((cantidad1 + cantidad2))
'			End If
'			z.Close
'			
'			
'		End If
'	End If
'	
'	
'	
End Sub

Private Sub b_guardar_Click
	
End Sub


Private Sub l_pCant_Click
	
End Sub

Sub p_prods_Click
	Log(Sender.As(Panel).tag)
End Sub