B4A=true
Group=Default Group
ModulesStructureVersion=1
Type=Class
Version=11.5
@EndOfDesignText@
Sub Class_Globals
	Private Root As B4XView 'ignore
	Private xui As XUI 'ignore
	
	Dim ruta As String
	Dim q_buscar As String
	Dim forzarbusqueda As Boolean = False
	Dim skmt As SQL
	Dim c As Cursor
	Dim c2 As Cursor
	Dim C3 As Cursor
	Dim s As Cursor
	Dim lv_catalogos As ListView
	Dim lv_promos As ListView
	Dim entro As String
	Dim gest As Button
	Dim lfila As Label
	Dim marca As String
	Dim tipo As String
	Dim subtipo As String
	Private BUSCA As EditText
	Dim ya_entro As String
	Dim TIENE_PROMOS As String
	Dim RES As String
	Dim S1 As Cursor
	Dim bmp As Bitmap
	Dim ciclo As String
	Private b_qr As Button
	Private p_productos As Panel
	Dim clv_productos As CustomListView
	Private ImageView1 As ImageView
	Private Panel3 As Panel
	Private p_prods As Panel
	Private i_prod As ImageView
	Private l_prodX As Label
	Private b_prodMas As Button
	Private l_pCant As Label
	Private et_pCant As EditText
	Private b_prodMenos As Button
	Dim b_terminar1 As Button
	Dim b_continuar As Button
	Private l_total As Label
	Private l_totProds As Label
	Dim totalProds As Int = 0
	Dim totalCompra As Float = 0
	Dim etCantHasFocus As Boolean = False
	Dim prodsMap As Map
	Private l_Cargando As Label
	Private l_info As Label
	Private b_buscar As Button
	Private p_botonesVenta As Panel
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
'	Activity.RemoveAllViews
	Root.LoadLayout("productos")
	ruta = File.DirInternal
	If File.Exists(ruta, "kmt.db") = False Then
		File.Copy(File.DirAssets, "kmt.db", ruta, "kmt.db")
	End If
	ciclo = 1
	l_info.Width = Root.Width * 0.8
	l_info.Left = (Root.Width/2) - (l_info.Width/2)
'	llenaCatalogo(False)
End Sub

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

Sub B4XPage_Appear
	prodsMap.Initialize
	B4XPages.MainPage.skmt.ExecNonQuery2("UPDATE CAT_GUNAPROD SET CAT_GP_TIPOPROD = (?) WHERE CAT_GP_TIPOPROD = (?) ",Array As Object("PRIORITARIO","1"))
	B4XPages.MainPage.skmt.ExecNonQuery2("UPDATE CAT_GUNAPROD SET CAT_GP_TIPOPROD = (?) WHERE CAT_GP_TIPOPROD = (?) ",Array As Object("ESTRATEGICO","2"))
	B4XPages.MainPage.skmt.ExecNonQuery2("UPDATE CAT_GUNAPROD SET CAT_GP_TIPOPROD = (?) WHERE CAT_GP_TIPOPROD = (?) ",Array As Object("COMPLEMENTARIO","3"))
	B4XPages.MainPage.skmt.ExecNonQuery2("UPDATE CAT_GUNAPROD SET CAT_GP_TIPOPROD = (?) WHERE CAT_GP_TIPOPROD = (?) ",Array As Object("CATALOGO REGULAR","0"))
	B4XPages.MainPage.skmt.ExecNonQuery2("UPDATE CAT_GUNAPROD SET CAT_GP_TIPOPROD = (?) WHERE CAT_GP_CLASIF = (?) ",Array As Object("PROMOS","PROMOS"))
	
'	Private left = (Root.Width/2) - ((clv_productos.AsView.Width)/2)
	clv_productos.GetBase.SetLayoutAnimated(100, 0dip, 140dip, Root.Width, 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.
'	Log($"ya_entro=${ya_entro}, entro=${entro}"$)
	If B4XPages.MainPage.bTerminarClicked Then
		lv_catalogos.Visible = True
		lv_promos.Visible = False
		clv_productos.AsView.Visible = False
		B4XPages.MainPage.bTerminarClicked = False
	End If
	If ya_entro <> "1" Then
'		Log("ya_entro <> 1")
		If BUSCA.Text <> "" Then BUSCA.Text =""
		entro ="3"
'		ya_entro = "1" : Log("ya_entro=1")
		lv_catalogos.Clear
		Sleep(100)
		lfila.Text = "CATALOGOS"
		p_productos.Height = Root.Height
		clv_productos.AsView.Visible = False
		lv_catalogos.Visible = True
		p_botonesVenta.Visible = False
		p_botonesVenta.Top = clv_productos.AsView.top + clv_productos.AsView.Height
		lv_promos.Visible = False
	End If
		Dim label1 As Label
		label1 = lv_catalogos.SingleLineLayout.Label
		label1.TextSize = 13
		label1.TextColor = Colors.Black
		lv_catalogos.Clear
		lv_catalogos.AddSingleLine("CATALOGO")
		c = B4XPages.MainPage.skmt.ExecQuery("select count(*) as hayPromos from cat_gunaprod where CAT_GP_TIPOPROD = 'PROMOS'")
		c.Position = 0
		If c.GetInt("hayPromos") > 0 Then
			lv_catalogos.AddSingleLine("PROMOS")
		End If
	Sleep(100)
	l_total.Visible = False
	l_totProds.Visible = False
	l_total.Left = 5dip
	l_totProds.Width = Root.Width * 0.19
	l_total.Left = l_totProds.Width + 20
	l_total.Width = Root.Width * 0.25
'	llenaCatalogo(False)
End Sub

Sub lv_catalogos_ItemClick (Position As Int, Value As Object)
	clv_productos.AsView.Visible = False
	BUSCA.Text = ""
	Dim cliente As C_Cliente = B4XPages.GetPage("Cliente")
'	Log($"value=${Value}"$)
	If Value = "PROMOS" And cliente.cuenta <> "N" Then
		entro = "3"
		marca = "PROMOS"
		tipo = "PROMOS"
	Else if Value = "PROMOS" And cliente.cuenta = "N"  Then
		entro = "5"
		B4XPages.ShowPage("Cliente")
	End If
	If Value = "PROMOS" Then
		LogColor("Promos", Colors.red)
		c2=B4XPages.MainPage.skmt.ExecQuery2("select  CAT_GP_ID, CAT_GP_NOMBRE, CAT_GP_PRECIO, CAT_GP_ALMACEN, CAT_GP_IMG from cat_gunaprod where CAT_GP_PRECIO > 0 AND  CAT_GP_ALMACEN > 0 and CAT_GP_TIPOPROD = ? AND CAT_GP_TIPO = ? AND CAT_GP_SUBTIPO = ?  AND CAT_GP_ID NOT IN (SELECT PE_PROID FROM PEDIDO WHERE PE_CLIENTE IN (Select cuenta from cuentaa) )", Array As String(Value, marca, tipo))
	Else
'		LogColor("Catalogo", Colors.red)
		c2=B4XPages.MainPage.skmt.ExecQuery("select CAT_GP_ID, CAT_GP_NOMBRE, CAT_GP_PRECIO, CAT_GP_ALMACEN, CAT_GP_IMG, CAT_GP_TIPOPROD, CAT_GP_INICIATIVA from cat_gunaprod where CAT_GP_PRECIO > 0 AND CAT_GP_ALMACEN > 0 and CAT_GP_TIPOPROD <> 'PROMOS' ")
	End If
	If Value = "CATALOGO" Then
		lv_catalogos.Visible = False
		lv_promos.Visible = False
'			lv_catalogos.Clear
		lfila.text = "CATALOGO"
'			Dim ins As InputStream
'			Dim bmp As Bitmap
'			Dim jpeg() As Byte
		ProgressDialogShow("Cargando catalogo ...")
		Sleep(100)
		Private inicioContador As String = DateTime.Now
		llenaCatalogo(False)
		clv_productos.AsView.Visible = True
'		Log("PGH")
		LogColor("TIEMPO DE PROCESO DEL CATALOGO: " & ((DateTime.Now-inicioContador)/1000), Colors.Red)
		ProgressDialogHide
		c2.Close
	Else
		clv_productos.AsView.Visible = False
		lv_promos.Visible = True
		lv_catalogos.Visible = False
		lv_promos.Clear
		Dim label1 As Label
		label1 = lv_promos.TwoLinesLayout.Label
		label1.TextSize = 13
		label1.TextColor = Colors.Black
		Dim label2 As Label
		label2 = lv_promos.TwoLinesLayout.SecondLabel
		label2.TextSize = 13
		label2.TextColor = Colors.Black
		Dim label13 As Label
		label13 = lv_promos.TwoLinesAndBitmap.Label
		label13.TextSize = 13
		label13.TextColor = Colors.Black
		Dim label14 As Label
		label14 = lv_promos.TwoLinesAndBitmap.SecondLabel
		label14.TextSize = 13
		label14.TextColor = Colors.Black
		lfila.text = "PROMOS"
'			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.AddTwoLinesAndBitmap(c2.GetString("CAT_GP_NOMBRE"),"# " & c2.GetString("CAT_GP_ALMACEN") & " $ " & c2.GetString("CAT_GP_PRECIO"),bmp)
					
				Private tm As Map = Subs.procesaPromocion(c2.GetString("CAT_GP_ID"), Subs.traeCliente)
				If tm.Get("status") = "ok" Then 'Solo muestrala si hay producto.
					lv_promos.AddTwoLines(c2.GetString("CAT_GP_NOMBRE"),"# " & c2.GetString("CAT_GP_ALMACEN") & " $ " & c2.GetString("CAT_GP_PRECIO") & " F:" & tm.Get("mp").As(Map).Get("prodsFijosCant") & " V:" & tm.Get("mp").As(Map).Get("prodsVariablesCant"))
				End If
			Next
		End If
		c2.Close
	End If
	entro = "4"
'	Else If entro = "4" Then
'		Log("Entro = 4")
'		B4XPages.MainPage.skmt.ExecNonQuery("delete from PROID")
'		B4XPages.MainPage.skmt.ExecNonQuery2("INSERT INTO PROID VALUES (?)", Array As Object(Value))
'		Dim promos As C_Promos = B4XPages.GetPage("Promos")
'		promos.laPromo = Subs.traeProdIdDeBD.Get("id")
'		promos.elCliente = Subs.traeUsuarioDeBD
'		B4XPages.ShowPage("Promos")
End Sub

Sub lv_promos_ItemClick (Position As Int, Value As Object)
	clv_productos.AsView.Visible = False
	Dim cliente As C_Cliente = B4XPages.GetPage("Cliente")
'	Log($"Entro=${entro}, value=${Value}, cuenta=${cliente.cuenta}"$)
	If Value = "PROMOS" And cliente.cuenta <> "N" Then
		entro = "3"
		marca = "PROMOS"
		tipo = "PROMOS"
	Else if Value = "PROMOS" And cliente.cuenta = "N"  Then
		entro = "5"
		B4XPages.ShowPage("Cliente")
	End If
	If entro = "3" Then
		LogColor("Promos", Colors.red)
		c2=B4XPages.MainPage.skmt.ExecQuery2("select  CAT_GP_ID, CAT_GP_NOMBRE, CAT_GP_PRECIO, CAT_GP_ALMACEN, CAT_GP_IMG from cat_gunaprod where CAT_GP_PRECIO > 0 AND  CAT_GP_ALMACEN > 0 and CAT_GP_TIPOPROD = ? AND CAT_GP_TIPO = ? AND CAT_GP_SUBTIPO = ?  AND CAT_GP_ID NOT IN (SELECT PE_PROID FROM PEDIDO WHERE PE_CLIENTE IN (Select cuenta from cuentaa) )", Array As String(Value, marca, tipo))
		clv_productos.AsView.Visible = False
		lv_promos.Visible = True
		lv_catalogos.Visible = False
		lv_promos.Clear
		Dim label1 As Label
		label1 = lv_promos.TwoLinesLayout.Label
		label1.TextSize = 13
		label1.TextColor = Colors.Black
		Dim label2 As Label
		label2 = lv_promos.TwoLinesLayout.SecondLabel
		label2.TextSize = 13
		label2.TextColor = Colors.Black
		Dim label13 As Label
		label13 = lv_promos.TwoLinesAndBitmap.Label
		label13.TextSize = 13
		label13.TextColor = Colors.Black
		Dim label14 As Label
		label14 = lv_promos.TwoLinesAndBitmap.SecondLabel
		label14.TextSize = 13
		label14.TextColor = Colors.Black
		lfila.text = "PROMOS"
'			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.AddTwoLinesAndBitmap(c2.GetString("CAT_GP_NOMBRE"),"# " & c2.GetString("CAT_GP_ALMACEN") & " $ " & c2.GetString("CAT_GP_PRECIO"),bmp)
					
				Private tm As Map = Subs.procesaPromocion(c2.GetString("CAT_GP_ID"), Subs.traeCliente)
				If tm.Get("status") = "ok" Then 'Solo muestrala si hay producto.
					lv_promos.AddTwoLines(c2.GetString("CAT_GP_NOMBRE"),"# " & c2.GetString("CAT_GP_ALMACEN") & " $ " & c2.GetString("CAT_GP_PRECIO") & " F:" & tm.Get("mp").As(Map).Get("prodsFijosCant") & " V:" & tm.Get("mp").As(Map).Get("prodsVariablesCant"))
				End If
			Next
		End If
		c2.Close
		entro = "4"
	Else If entro = "4" Then
		Log("Entro = 4")
		B4XPages.MainPage.skmt.ExecNonQuery("delete from PROID")
		B4XPages.MainPage.skmt.ExecNonQuery2("INSERT INTO PROID VALUES (?)", Array As Object(Value))
		Dim promos As C_Promos = B4XPages.GetPage("Promos")
		promos.laPromo = Subs.traeProdIdDeBD.Get("id")
		promos.elCliente = Subs.traeUsuarioDeBD
		B4XPages.ShowPage("Promos")
	End If
End Sub

Sub llenaCatalogo(limpiar As Boolean)
	Log("LlenaCatalogo")
	If limpiar Then clv_productos.Clear
	Private c2 As Cursor
	c2=B4XPages.MainPage.skmt.ExecQuery("select CAT_GP_ID, CAT_GP_NOMBRE, CAT_GP_PRECIO, CAT_GP_ALMACEN, CAT_GP_IMG, CAT_GP_TIPOPROD, CAT_GP_INICIATIVA from cat_gunaprod where CAT_GP_PRECIO > 0 AND CAT_GP_ALMACEN > 0 and CAT_GP_TIPOPROD <> 'PROMOS' ")
	Private bgColor, textColor As Int
	If c2.RowCount > 0 And clv_productos.Size <> c2.RowCount Then
		clv_productos.Clear : Log("limpiamos productos")
		For i=0 To c2.RowCount -1
			c2.Position=i
			If c2.GetString("CAT_GP_TIPOPROD") = "PRIORITARIO" Then
				bgColor = Colors.RGB(255, 212, 163) 'naranja
			Else If c2.GetString("CAT_GP_TIPOPROD") = "COMPLEMENTARIO" Then
				bgColor = Colors.RGB(177, 200, 249)'azul
			else If c2.GetString("CAT_GP_TIPOPROD") = "CATALOGO REGULAR" Then
				bgColor = Colors.White
			else If c2.GetString("CAT_GP_TIPOPROD") = "ESTRATEGICO" Then
				bgColor = Colors.RGB(241, 255, 163) 'amarillo
			End If
			textColor = Colors.Black
			clv_productos.Add(CreateListItem(c2.GetString("CAT_GP_NOMBRE"), c2.GetString("CAT_GP_PRECIO"), c2.GetString("CAT_GP_ALMACEN"), clv_productos.AsView.Width, 50dip, bmp, c2.GetString("CAT_GP_ID"), bgColor, textColor), c2.GetString("CAT_GP_NOMBRE"))
		Next
	End If
	ponProdsEnCero
	c2.Close
End Sub

Private Sub B4XPage_CloseRequest As ResumableSub
'	BACK key pressed
'	Return True To close, False To cancel
'	ya_entro ="0" : Log("ya_entro=0")
	If l_info.Visible Then
		l_info.Visible = False
		Return False
	else if lv_promos.visible Then
		lv_promos.Visible = False
		lv_catalogos.Visible = True
		p_botonesVenta.Visible = False
		l_total.Visible = False
		l_totProds.Visible = False
		Return False
	else if clv_productos.AsView.Visible Then
		clv_productos.AsView.Visible = False
		lv_catalogos.Visible = True
		p_botonesVenta.Visible = False
		l_total.Visible = False
		l_totProds.Visible = False
		Return False
	else If entro = "4" Then
		entro = "3"
		B4XPage_Appear
		Return True
	Else If entro = "3" Then
		B4XPages.ShowPage("Cliente")
		Return False
	Else
		B4XPages.ShowPage("Cliente")
		Return False
	End If
End Sub

Sub BUSCA_TextChanged (Old As String, New As String)
	q_buscar = "%" & BUSCA.Text & "%"
'	Log($"old=${Old}, new=|${New}|"$)
	Private bgColor, textColor As Int
	Private se As Cursor
	If New.Length > 2 Or forzarbusqueda Then
		forzarbusqueda = False
		Log("searching")
		se=B4XPages.MainPage.skmt.ExecQuery2("select CAT_GP_ID, CAT_GP_NOMBRE, CAT_GP_ALMACEN, CAT_GP_PRECIO, CAT_GP_TIPOPROD, CAT_GP_IMG from cat_gunaprod where CAT_GP_PRECIO > 0 AND CAT_GP_ALMACEN > 0 and CAT_GP_NOMBRE like ? and CAT_GP_CLASIF <>  ?", Array As String(q_buscar,"PROMOS"))  '  order by CAT_GP_NOMBRE asc
'		lv_catalogos.Clear
		lv_catalogos.Visible = False
		lv_promos.Visible = False
		clv_productos.AsView.Visible = True
		clv_productos.Clear
		If se.RowCount > 0 Then
			If se.RowCount > 50 Then ProgressDialogShow("Buscando productos")
			Sleep(100)
			For i=0 To se.RowCount -1
				se.Position=i
				If se.GetString("CAT_GP_TIPOPROD") = "PRIORITARIO" Then
					bgColor = Colors.RGB(255, 212, 163) 'naranja
				Else If se.GetString("CAT_GP_TIPOPROD") = "COMPLEMENTARIO" Then
					bgColor = Colors.RGB(177, 200, 249)'azul
				else If se.GetString("CAT_GP_TIPOPROD") = "CATALOGO REGULAR" Then
					bgColor = Colors.White
				else If se.GetString("CAT_GP_TIPOPROD") = "ESTRATEGICO" Then
					bgColor = Colors.RGB(241, 255, 163) 'amarillo
				End If
				textColor = Colors.Black
				clv_productos.Add(CreateListItem(se.GetString("CAT_GP_NOMBRE"), se.GetString("CAT_GP_PRECIO"), se.GetString("CAT_GP_ALMACEN"), clv_productos.AsView.Width, 50dip, bmp, se.GetString("CAT_GP_ID"), bgColor, textColor), se.GetString("CAT_GP_NOMBRE"))
			Next
			If se.RowCount > 50 Then ProgressDialogHide
			ponProdsEnCero
		End If
		se.Close
		entro= "4"
	End If
End Sub

Sub b_QR_Click
	If ciclo = 1 Then
		ciclo = 2
'		b_qr.Visible = False
		ya_entro  = "0"
		'entro = 3
		B4XPage_Appear
	else if ciclo = 2 Then
		ciclo = 3
		'	ya_entro  = 0
		ya_entro  = "0"
		B4XPage_Appear
'		b_qr.Visible = False
	else if ciclo = 3 Then
		ciclo = 4
		'	ya_entro  = 0
		ya_entro  = "0"
		B4XPage_Appear
'		b_qr.Visible = False
	else if ciclo = 4 Then
		ciclo = 5
		'	ya_entro  = 0
		ya_entro  = "0"
		B4XPage_Appear
'		b_qr.Visible = False
	else if ciclo = 5 Then
		ciclo = 1
		'	ya_entro  = 0
		ya_entro  = "0"
		B4XPage_Appear
'		b_qr.Visible = False
	End If
End Sub

'****************************************************************************
'***************** PARA EL MAS/MENOS *************************************
'****************************************************************************
Sub CreateListItem(Text As String, precioU As String, inv As Int, 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")
	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_pCant.Text = 0
	l_pCant.Tag = precioU&"|"&inv&"|"&prodId
	et_pCant.Tag = precioU&"|"&inv&"|"&prodId
'	Log(l_pCant.Tag)
	et_pCant.BringToFront
'	i_prod.Bitmap = img
	Return p
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($"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 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($"precio|stock:${laCant.tag}"$)
'	Log($"Indice: ${index}, cant:${laCant.Text+1}, precioU: ${laCant.tag}"$)
	Dim esteTag As List = Regex.Split("\|", laCant.Tag)
'	Log(laCant.Tag&"|"&esteTag)
	If laCant.Text = "" Then laCant.Text = 0
	If laCant.Text + 1 <= esteTag.get(1) Then
		laCant.Text = $"$1.0{laCant.Text+1}"$
		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

Sub cuentaProds
	totalProds = 0
	totalCompra = 0
'	Private inicioContador As String = DateTime.Now
	For i = 0 To clv_productos.GetSize - 1
		Private p0 As B4XView = clv_productos.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
'		Private cant2 As Int = 0
'		If cant1.Text <> "" Then cant2 = cant1.Text
		totalProds = totalProds + cant1.Text
		Private esteTag As List = Regex.Split("\|", cant1.Tag)
		If cant1.Text > esteTag.Get(1) Then cant1.Text = esteTag.Get(1)
		If cant1.Text > 0 Then
			Log(esteTag.Get(2) & "|" & cant1.Text)
			totalCompra = totalCompra + (esteTag.get(0) * cant1.text)
			Log($"Cant: ${cant1.Text}, Suma: ${totalCompra}"$)
			Private m As Map
			m=CreateMap("cant":cant1.Text, "precio":esteTag.get(0))
			prodsMap.Put(esteTag.Get(2), m)
		End If
		l_total.Visible = True
		l_totProds.Visible = True
		l_total.Text = $"Total: $$1.2{totalCompra}"$
		l_totProds.text = $"Prods: ${totalProds}"$
	Next
'	LogColor("TIEMPO cuentaProds -=" & ((DateTime.Now-inicioContador)/1000), Colors.Red)
'	LogColor(prodsMap, Colors.blue)
	p_botonesVenta.Visible = True
	Log($"Total Prods: ${totalProds}, Total Compra: $$1.2{totalCompra}"$)
End Sub

Sub ponProdsEnCero
	Private inicioContador As String = DateTime.Now
	Private prodsVendidosList As List
	prodsVendidosList.Initialize
	Private pr As Cursor = B4XPages.MainPage.skmt.ExecQuery($"Select PE_PROID from PEDIDO where PE_CLIENTE='${Subs.traeCliente}'"$)
	If pr.RowCount > 0 Then
		pr.Position = 0
		For i = 0 To pr.RowCount - 1
			pr.Position = i
			prodsVendidosList.Add(pr.GetString("PE_PROID"))
		Next
	End If
	pr.Close
	Log("prodsVendidos="&prodsVendidosList)
	For i = 0 To clv_productos.GetSize - 1
		Private p0 As B4XView = clv_productos.GetPanel(i)
		Private lVendido As B4XView = p0.GetView(1) 'Label l_vendido
		Private pProds As B4XView = p0.GetView(0) 'Panel p_prods
		Private cant1 As B4XView = pProds.GetView(2).GetView(3)
		Private x() As String = Regex.Split("\|", cant1.tag) 'El ultimo dato de cant1.tag es el id del producto.
		If prodsVendidosList.IndexOf(x(x.Length-1)) > -1 Then 'Revisamos si el producto es en la tabla "PEDIDO".
			lVendido.Visible = True
			pProds.GetView(2).As(Panel).Visible = False
		Else
			lVendido.Visible = False
			pProds.GetView(2).As(Panel).Visible = True
		End If
		cant1.Text = 0
	Next
	LogColor("TIEMPO DE PROCESO DEL PONEMOSENCERO: " & ((DateTime.Now-inicioContador)/1000), Colors.Red)
	Log("Ponems en CERO")
End Sub

Private Sub et_pCant_FocusChanged (HasFocus As Boolean)
'	LogColor($"focus changed=${HasFocus}"$, Colors.Magenta)
	etCantHasFocus = HasFocus
	cuentaProds
End Sub

Private Sub b_terminar1_Click
	Log("b_terminar1_Click")
	cuentaProds
	Private p1 As Map
	For Each p As String In prodsMap.Keys
		p1 = prodsMap.Get(p)
		Log(p & "|" & p1)
		Private pn As String = Subs.traeProdNombre(p)
		Subs.guardaProducto(Subs.traeAlmacen, p1.Get("precio"), p1.Get("cant"), pn, p, Subs.traeCliente, Subs.traeFecha, Subs.traeUsuarioDeBD, Subs.traeRuta, 0, B4XPages.MainPage.tipo_venta)
	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 b_continuar_Click
	Log("b_continuar_Click")
	cuentaProds
	Private p1 As Map
	For Each p As String In prodsMap.Keys
		p1 = prodsMap.Get(p)
		Log(p & "|" & p1)
		Private pn As String = Subs.traeProdNombre(p)
		If pn <> "N/A" Then Subs.guardaProducto(Subs.traeAlmacen, p1.Get("precio"), p1.Get("cant"), pn, p, Subs.traeCliente, Subs.traeFecha, Subs.traeUsuarioDeBD, Subs.traeRuta, 0, B4XPages.MainPage.tipo_venta)
	Next
	Log("promos-inv, prods-inv, cat-vis")
	lv_promos.Visible = False
	clv_productos.AsView.Visible = False
	lv_catalogos.Visible = True
'	clv_productos.Clear
	ponProdsEnCero
	prodsMap.Initialize
	Log("Continuar")
'	Activity_KeyPress(KeyCodes.KEYCODE_BACK)
End Sub

Private Sub l_prodX_LongClick
	Log("longclic = "&Sender.as(Label).tag)
	l_info.Text = Sender.as(Label).tag
	l_info.Visible = True
End Sub

Private Sub l_info_Click
	l_info.Visible = False
End Sub

Private Sub lv_promos_ItemLongClick (Position As Int, Value As Object)
	Log("Promo longclic = "&Value)
	Private id As String = ""
	Dim c As Cursor = B4XPages.MainPage.skmt.ExecQuery($"select CAT_GP_ID from cat_gunaprod where CAT_GP_TIPO = 'PROMOS' and CAT_GP_NOMBRE = '${Value}'"$)
	If c.RowCount > 0 Then
		c.Position = 0
		id = c.GetString("CAT_GP_ID")
	End If
	l_info.Text = $"ID: ${id}${CRLF}${Value}"$
	l_info.Visible = True
End Sub

Private Sub b_buscar_Click
	forzarbusqueda = True
	BUSCA_TextChanged("","")
End Sub