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 skmt As SQL
	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 Regresar As Button
	
	Dim ListView1 As ListView
	Dim L_CANT As Label
	Dim L_TOTAL As Label
	Dim borra As Button
	Dim Existe As String
	Dim result As String
	'    Dim lat_gps, lon_gps As String
	Dim DESC As String

	Private Titulo As Label
	Private b_desc As Button
	Dim DESCUENTO As String
	Dim folio As String
	Dim tgl As Toggle
	Private almacen As String
	Private p_nota As Panel
	Dim vamoaver As List
	Dim c2 As Cursor
	Dim j3 As Cursor
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
	ruta = File.DirInternal
	Root.LoadLayout("nota")
	borra.Visible = True
	Titulo.Text = "Pedido Actual"
'	If Existe <> 0 Then
'		c=B4XPages.MainPage.skmt.ExecQuery("select pc_noart, pc_monto from pedido_cliente where pc_cliente in (Select CUENTA from cuentaa)")
'		C.Position=0
'		L_CANT.Text = c.GetString("PC_NOART")
'		L_TOTAL.Text = c.GetString("PC_MONTO")
'	End If
End Sub

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

Sub B4XPage_Appear
	' Verificar si el GPS está encendido
	If Not(Starter.gps.GPSEnabled) Then
		ToastMessageShow("Es necesario tener el GPS encendido", True)
		StartActivity(Starter.gps.LocationSettingsIntent)
	End If

	' Obtener el ID del almacén
	c = B4XPages.MainPage.skmt.ExecQuery("SELECT ID_ALMACEN FROM CAT_ALMACEN")
	If c.RowCount > 0 Then
		c.Position = 0
		almacen = c.GetString("ID_ALMACEN")
	End If
	c.Close

	' Limpiar los campos de cantidad y total
	L_CANT.Text = ""
	L_TOTAL.Text = ""

	' Verificar si existen pedidos para el cliente
	c = B4XPages.MainPage.skmt.ExecQuery("SELECT COUNT(*) AS EXISTE FROM pedido_cliente WHERE pc_cliente IN (SELECT CUENTA FROM cuentaa)")
	If c.RowCount > 0 Then
		c.Position = 0
		Existe = c.GetString("EXISTE")
	End If
	c.Close

	' Obtener los pedidos del cliente
	c = B4XPages.MainPage.skmt.ExecQuery("SELECT PE_PRONOMBRE, PE_COSTO_TOT, PE_CANT, PE_FOLIO, PE_CEDIS FROM PEDIDO WHERE PE_CLIENTE IN (SELECT CUENTA FROM cuentaa) ORDER BY PE_CEDIS, PE_PRONOMBRE")
	ListView1.Clear
	vamoaver.Initialize
	Private cs As CSBuilder

	If c.RowCount > 0 Then
		For i = 0 To c.RowCount - 1
			cs.Initialize
			c.Position = i
			Dim label1 As Label
			label1 = ListView1.TwoLinesLayout.Label
			label1.TextSize = 15
			label1.TextColor = Colors.Black
			label1.Color = Colors.White

			Private textColor As Int = Colors.Black
			Dim folio As String = c.GetString("PE_FOLIO")

			' Asignar colores según el tipo de folio
			If folio = "VENTA" Then
				textColor = Colors.RGB(48, 3, 195)
			Else If folio = "PREVENTA_CONTADO" Or folio = "ABORDO" Or folio = "RECARGA" Then
				textColor = Colors.RGB(166, 0, 0)
			Else If folio = "PREVENTA_CREDITO" Then
				textColor = Colors.RGB(0, 128, 0)
			End If

			' Cambiar el color si es una promoción
			If Not(IsNumber(c.GetString("PE_CEDIS"))) And folio = "VENTA" Then
				textColor = Colors.RGB(154, 131, 231)
			Else If Not(IsNumber(c.GetString("PE_CEDIS"))) And folio = "PREVENTA_CONTADO" Then
				folio = "PREVENTA"
				textColor = Colors.RGB(255,0,214)
			Else If Not(IsNumber(c.GetString("PE_CEDIS"))) And folio = "PREVENTA_CREDITO" Then
				folio = "PREVENTA"
				textColor = Colors.RGB(120,178,108)
			End If


			Dim polioreal As String
			If folio = "VENTA" Then
				textColor = Colors.RGB(154,131,231)
			Else If folio = "PREVENTA_CONTADO" Then
				polioreal = "PREVENTA"
				textColor = Colors.RGB(255,111,111)
			Else If folio = "PREVENTA_CREDITO" Then
				polioreal = "PREVENTA"
				textColor = Colors.RGB(120,178,108)
			End If
			LogColor(polioreal,Colors.Gray)
			Dim label2 As Label
			label2 = ListView1.TwoLinesLayout.SecondLabel
			label2.TextSize = 10
			label2.TextColor = Colors.Blue
'			LogColor(folio,Colors.Gray)
			' Agregar el ítem a la lista
'			ListView1.AddTwoLines(cs.Color(textColor).append(c.GetString("PE_PRONOMBRE")).pop, "Cantidad #" & c.GetString("PE_CANT") & " SubTotal $" & c.GetString("PE_COSTO_TOT") & " Folio " & folio )
			ListView1.AddSingleLine(cs.Color(textColor).Size(12).append(c.GetString("PE_PRONOMBRE") & " ").pop.Append(CRLF).Size(8).Color(Colors.Blue).Append("Cantidad #"& c.GetString("PE_CANT")).Append(" SubTotal $"& c.GetString("PE_COSTO_TOT")).Append(" "  & polioreal& " " &c.GetString("PE_CEDIS")).PopAll)
			
			vamoaver.Add(folio)
		Next
	End If

	Log($"EXISTE: ${Existe}"$)

	' Calcular la cantidad total y el monto total
	c = B4XPages.MainPage.skmt.ExecQuery("SELECT IFNULL(SUM(IFNULL(PE_CANT,0)),0) AS PC_NOART, SUM(IFNULL(PE_COSTO_TOT,0)) AS PC_MONTO FROM PEDIDO WHERE PE_CLIENTE IN (SELECT CUENTA FROM cuentaa) AND PE_PROID NOT IN (SELECT CAT_PA_ID FROM PROMOS_COMP)")
	If c.RowCount > 0 Then
		c.Position = 0
		Log($"registros: ${c.RowCount}, arts: ${c.GetString("PC_NOART")}, monto:${c.GetString("PC_MONTO")}"$)
		L_CANT.Text = c.GetString("PC_NOART")
		L_TOTAL.Text = c.GetString("PC_MONTO")
		If L_CANT.Text = Null Or L_CANT.Text = "null" Or L_CANT.Text = "" Then L_CANT.Text = "0"
		If L_TOTAL.Text = Null Or L_TOTAL.Text = "null" Or L_TOTAL.Text = "" Then L_TOTAL.Text = "0"
		c.Close

		' Obtener el descuento total
		c = B4XPages.MainPage.skmt.ExecQuery("SELECT SUM(IFNULL(PE_DESC,0)) AS DESCUENTO FROM PEDIDO WHERE PE_CLIENTE IN (SELECT CUENTA FROM cuentaa)")
		If c.RowCount > 0 Then
			c.Position = 0
			DESC = c.GetString("DESCUENTO")
			b_desc.Visible = False
		End If
		c.Close
	End If

	' Habilitar o deshabilitar el botón de borrar
	If Subs.pedidoGuardado Then
		borra.Enabled = False
	Else
		borra.Enabled = True
	End If
End Sub

Sub Activity_Pause (UserClosed As Boolean)

End Sub

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

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

Private Sub B4XPage_CloseRequest As ResumableSub
'	BACK key pressed
'	Return True To close, False To cancel
	B4XPages.ShowPage("Cliente")
	Return False
End Sub

Sub borra_Click
	Log("Entre al btn borrar")
	result =  Msgbox2("Seguro que desa borrar el pedido?","Cancelar pedido", "Si", "", "No",LoadBitmap(File.DirAssets,"alert2.png")) 'ignore
	If result = DialogResponse.POSITIVE Then
		c=B4XPages.MainPage.skmt.ExecQuery("select PE_PROID,PE_CANT FROM PEDIDO where pe_cliente in (Select CUENTA from cuentaa) ")
		Log($"select PE_PROID,PE_CANT FROM PEDIDO where pe_cliente in (Select CUENTA from cuentaa)"$)
		If c.RowCount>0 Then
			For i=0 To c.RowCount -1
				c.Position=i
				B4XPages.MainPage.skmt.ExecNonQuery2($"update ${Starter.tabla} set cat_gp_almacen = cat_gp_almacen + ? where cat_gp_id = ?"$, Array As Object(c.GetString("PE_CANT"),c.GetString("PE_PROID")))
				B4XPages.MainPage.skmt.ExecNonQuery2("INSERT INTO  INVENT_X_ENVIAR (ALMACEN , PROID , CANTIDAD ) VALUES(?,?,?) ", Array As Object (almacen,c.GetString("PE_PROID"),c.GetString("PE_CANT")* -1))
			Next
		End If
		B4XPages.MainPage.skmt.ExecNonQuery("delete from pedido_cliente where pc_cliente in (Select CUENTA from cuentaa)")
		B4XPages.MainPage.skmt.ExecNonQuery("delete from pedido where pe_cliente in (Select CUENTA from cuentaa)")
		B4XPages.MainPage.skmt.ExecNonQuery("UPDATE kmt_info3 set gestion = 0  where CAT_CL_CODIGO In (select cuenta from cuentaa)")
		B4XPage_Appear
	End If
End Sub

'Sub ListView1_ItemLongClick (Position As Int, Value As Object)
'	Log(Value)
''	If Not(Subs.pedidoGuardado) Then
'	result =  Msgbox2("Seguro que desea borrar este articulo?","Borrar Articulo", "Si", "", "No",LoadBitmap(File.DirAssets,"alert2.png")) 'ignore
'	If result = DialogResponse.POSITIVE Then
'		c=B4XPages.MainPage.skmt.ExecQuery2("select PE_PROID,PE_CANT, PE_FOLIO,PE_CEDIS FROM PEDIDO where pe_pronombre = ? and pe_cliente in (Select CUENTA from cuentaa) ", Array As String(Value))
'		c.Position=0
'		Log(vamoaver.Get(Position))
'		If vamoaver.Get(Position) = "VENTA" Then
'			Log("CAT_GUNAPROD2")
'			Log(Position)
'			Log(Value)
'			Starter.tabla = "CAT_GUNAPROD2"
'		Else
'			Log("CAT_GUNAPROD")
'			Log(Position)
'			Log(Value)
'			Starter.tabla = "CAT_GUNAPROD"
'		End If
''			B4XPages.MainPage.skmt.ExecNonQuery2($"update ${Starter.tabla} set cat_gp_almacen = cat_gp_almacen + ? where cat_gp_id = ?"$, Array As Object(c.GetString("PE_CANT"),c.GetString("PE_PROID")))
'		B4XPages.MainPage.skmt.ExecNonQuery2("INSERT INTO  INVENT_X_ENVIAR (ALMACEN , PROID , CANTIDAD ) VALUES(?,?,?) ", Array As Object (Subs.traeAlmacen,c.GetString("PE_PROID"),c.GetString("PE_CANT")* -1))
'		c2=B4XPages.MainPage.skmt.ExecQuery2($"select count(*) AS CUANTOS from ${Starter.tabla} where  CAT_GP_ID in (select pe_cedis from pedido where pe_pronombre = ? and pe_cliente in (Select CUENTA from cuentaa)) and CAT_GP_CLASIF = 'PROMOS' AND CAT_GP_TIPO = 'PROMOS' AND CAT_GP_SUBTIPO = 'PROMOS'"$, Array As String(Value))
'		c2.Position=0
'		Log(c2.GetString("CUANTOS"))
'		If c2.GetString("CUANTOS") > 0 Then
'			
'			j3 = B4XPages.MainPage.skmt.ExecQuery2("SELECT PE_CEDIS, PE_CANT,PE_PROID, PE_PRONOMBRE FROM PEDIDO WHERE PE_CEDIS IN (SELECT PE_CEDIS FROM PEDIDO WHERE PE_PRONOMBRE = ?) and PE_CLIENTE IN (SELECT CUENTA FROM CUENTAA)",Array As String(Value))
'			Log(j3.RowCount)
'			If j3.RowCount > 0 Then
'				Log("estoy aqui")
'				For i = 0 To j3.RowCount -1
'					Log("aqui tronare?")
'					j3.Position = i
'					
'					If vamoaver.get(Position) = "VENTA" Then
'						Log("Entre aqui?")
'						B4XPages.MainPage.skmt.ExecNonQuery($"update ${Starter.tabla} set cat_gp_almacen = cat_gp_almacen + ${j3.GetString("PE_CANT")} where cat_gp_id = '${j3.Getstring("PE_PROID")}'"$)
''						B4XPages.MainPage.skmt.ExecNonQuery2("delete from pedido where  pe_cedis in (select pe_cedis from pedido where pe_pronombre = ?) and pe_cliente in (Select CUENTA from cuentaa) AND PE_FOLIO = ?", Array As Object(j3.GetString("PE_PRONOMBRE"), c.GetString("PE_FOLIO")))
'						Log("Aqui borro pedido 1")
'						B4XPages.MainPage.skmt.ExecNonQuery2("delete from pedido where pe_cedis <> ? and pe_cliente in (Select CUENTA from cuentaa) AND PE_FOLIO = ?", Array As Object(Subs.traeAlmacen, c.GetString("PE_FOLIO")))
'					Else
'						Log("Esto es Folio: " & vamoaver.get(Position) & "Esto es cedis: " & Subs.traeAlmacen)
'						B4XPages.MainPage.skmt.ExecNonQuery($"update cat_gunaprod set cat_gp_almacen = cat_gp_almacen + ${j3.GetString("PE_CANT")} where cat_gp_id = '${j3.Getstring("PE_PROID")}'"$)
'						B4XPages.MainPage.skmt.ExecNonQuery($"update cat_gunaprod4 set cat_gp_almacen = cat_gp_almacen + ${j3.GetString("PE_CANT")} where cat_gp_id = '${j3.Getstring("PE_PROID")}'"$)
'						Log("Aqui borro pedido 2")
'						B4XPages.MainPage.skmt.ExecNonQuery2("delete from pedido where pe_cedis <> ? and pe_cliente in (Select CUENTA from cuentaa) AND PE_FOLIO = ?", Array As Object(Subs.traeAlmacen, c.GetString("PE_FOLIO")))
'					End If
'				Next
'			End If
'			j3.Close
'		Else
'			Log("Esto no es una promo")
'			If vamoaver.get(Position) = "VENTA" Then
'				Log("Esto no es una promo")
'				B4XPages.MainPage.skmt.ExecNonQuery($"update CAT_GUNAPROD2 set cat_gp_almacen = cat_gp_almacen + ${c.GetString("PE_CANT")} where cat_gp_id = '${c.Getstring("PE_PROID")}'"$)
'						Log("Aqui borro pedido 3")
'				B4XPages.MainPage.skmt.ExecNonQuery2("delete from pedido where pe_cedis = ? and  pe_pronombre = ?  and pe_cliente in (Select CUENTA from cuentaa) AND PE_FOLIO = ?", Array As Object(Subs.traeAlmacen, Value, vamoaver.Get(Position)))
'			Else
'				Log("Esto no es una promo")
'				Log("Esto es Folio: " & vamoaver.get(Position) & "Esto es cedis: " & Subs.traeAlmacen & "Esto es nombre: " & Value)
'				B4XPages.MainPage.skmt.ExecNonQuery($"update CAT_GUNAPROD set cat_gp_almacen = cat_gp_almacen + ${c.GetString("PE_CANT")} where cat_gp_id = '${c.Getstring("PE_PROID")}'"$)
'				B4XPages.MainPage.skmt.ExecNonQuery($"update CAT_GUNAPROD4 set cat_gp_almacen = cat_gp_almacen + ${c.GetString("PE_CANT")} where cat_gp_id = '${c.Getstring("PE_PROID")}'"$)
'						Log("Aqui borro pedido 4")
'				B4XPages.MainPage.skmt.ExecNonQuery2("delete from pedido where pe_cedis = ? and pe_pronombre = ?  and pe_cliente in (Select CUENTA from cuentaa) AND PE_FOLIO = ?", Array As Object(Subs.traeAlmacen, Value, vamoaver.Get(Position)))
'			End If
''			B4XPages.MainPage.skmt.ExecNonQuery($"update ${Starter.tabla} set cat_gp_almacen = cat_gp_almacen + ${c.GetString("PE_CANT")} where cat_gp_id = '${c.Getstring("PE_PROID")}'"$)
''			B4XPages.MainPage.skmt.ExecNonQuery2("delete from pedido where  pe_pronombre = ?  and pe_cliente in (Select CUENTA from cuentaa) AND PE_FOLIO = ?", Array As Object(Value, c.GetString("PE_FOLIO")))
'		End If
'		c.Close
'		c2.Close
'		DateTime.DateFormat = "MM/dd/yyyy"
'		sDate=DateTime.Date(DateTime.Now)
'		sTime=DateTime.Time(DateTime.Now)
'		c=B4XPages.MainPage.skmt.ExecQuery("Select CUENTA from cuentaa")
'		c.Position=0
'		clie_id = c.GetString("CUENTA")
'		c=B4XPages.MainPage.skmt.ExecQuery("select USUARIO from usuarioa")
'		c.Position=0
'		usuario = c.GetString("USUARIO")
'		c=B4XPages.MainPage.skmt.ExecQuery("select sum(pe_costo_tot) as TOTAL_CLIE, SUM(PE_CANT) AS CANT_CLIE, count(*) as CUANTOS FROM PEDIDO WHERE PE_CLIENTE IN (Select CUENTA from cuentaa)")
'		c.Position=0
'		If c.GetString("CUANTOS") > 0 Then
'			B4XPages.MainPage.skmt.ExecNonQuery("delete from pedido_cliente where PC_CLIENTE In (select cuenta from cuentaa)")
'			B4XPages.MainPage.skmt.ExecNonQuery2("insert into pedido_cliente(PC_CLIENTE, PC_FECHA, PC_USER, PC_NOART, PC_MONTO,PC_LON, PC_LAT) 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))
'			B4XPages.MainPage.skmt.ExecNonQuery("UPDATE kmt_info3 set gestion = 0  where CAT_CL_CODIGO In (select cuenta from cuentaa)")
'		Else
'			B4XPages.MainPage.skmt.ExecNonQuery("delete from pedido_cliente where PC_CLIENTE In (select cuenta from cuentaa)")
'			B4XPages.MainPage.skmt.ExecNonQuery("UPDATE kmt_info3 set gestion = 0  where CAT_CL_CODIGO In (select cuenta from cuentaa)")
'		End If
'		B4XPage_Appear
'	End If
''	Else
''		ToastMessageShow("Pedido guardado, NO se puede editar.",False)
''	End If
'End Sub

Sub ListView1_ItemLongClick (Position As Int, Value As Object)
	Log(Value)
	Private X() As String = Regex.Split(" ", Value)
	Private nom As String = ""
	For i = 0 To X.Length -1
		If X(i).Contains(CRLF) Then
		End If
		If Not(X(i).Contains(CRLF)) Then
			nom = nom & " " & X(i)
		Else
			Exit
		End If
	Next
	nom = nom.Trim
	Log(nom)
	Private cedis As String = X(X.Length-1)
	Log(cedis)
		result =  Msgbox2("Seguro que desea borrar este articulo?","Borrar Articulo", "Si", "", "No",LoadBitmap(File.DirAssets,"alert2.png")) 'ignore
		If result = DialogResponse.POSITIVE Then
			Log("|" &nom & "|")
			Log("|" & cedis & "|")
			Log("|" & Subs.traeCliente & "|")
		Private y As Cursor =B4XPages.MainPage.skmt.ExecQuery($"select PE_PROID,PE_CANT, PE_FOLIO FROM PEDIDO where pe_pronombre = '${nom.TRIM}' and pe_cliente in (Select CUENTA from cuentaa) AND PE_CEDIS = '${cedis}' "$)
		Log($"select PE_PROID,PE_CANT, PE_FOLIO FROM PEDIDO where pe_pronombre = '${nom}' and pe_cliente in (Select CUENTA from cuentaa) AND PE_CEDIS = '${cedis}' "$)
			Log(y.RowCount)
			y.Position=0
			Log(vamoaver.Get(Position))
			If vamoaver.Get(Position) = "VENTA" Then
				Log("CAT_GUNAPROD2")
				Log(Position)
				Log(Value)
				Starter.tabla = "CAT_GUNAPROD2"
			Else
				Log("CAT_GUNAPROD")
				Log(Position)
				Log(Value)
				Starter.tabla = "CAT_GUNAPROD"
			End If

		B4XPages.MainPage.skmt.ExecNonQuery2("INSERT INTO  INVENT_X_ENVIAR (ALMACEN , PROID , CANTIDAD ) VALUES(?,?,?) ", Array As Object (Subs.traeAlmacen,y.GetString("PE_PROID"),y.GetString("PE_CANT")* -1))
		Log(cedis)
		Log(Subs.traeAlmacen)
		If cedis <> Subs.traeAlmacen Then
			j3 = B4XPages.MainPage.skmt.ExecQuery2("SELECT PE_CEDIS, PE_CANT,PE_PROID, PE_PRONOMBRE, PE_FOLIO FROM PEDIDO WHERE PE_CEDIS IN (SELECT PE_CEDIS FROM PEDIDO WHERE PE_PRONOMBRE = ? and PE_CEDIS = ?)",Array As String(nom,cedis))
			Log(j3.RowCount)
			If j3.RowCount > 0 Then
				Log("Soy promo")
				For j = 0 To j3.RowCount -1
					Log("aqui tronare?")
				
					j3.Position = j
					Log(j3.GetString("PE_CANT"))
					Log($"update ${Starter.tabla} set CAT_GP_ALMACEN = CAT_GP_ALMACEN + '${j3.GetString("PE_CANT")}' where CAT_GP_ID = '${j3.GetString("PE_PROID")}'"$)
					If vamoaver.Get(Position) = "PREVENTA_CREDITO" Then
						Starter.skmt.ExecNonQuery($"update CAT_GUNAPROD4 set CAT_GP_ALMACEN = CAT_GP_ALMACEN + ${j3.GetString("PE_CANT")} where CAT_GP_ID = '${j3.GetString("PE_PROID")}'"$)
						B4XPages.MainPage.skmt.ExecNonQuery($"delete from pedido where pe_cedis= '${cedis}' and pe_cliente in (Select CUENTA from cuentaa) AND PE_FOLIO = '${j3.GetString("PE_FOLIO")}' AND PE_PROID = '${j3.GetString("PE_PROID")}'"$)', Array As Object(cedis, c.GetString("PE_FOLIO")))
					Else
						Starter.skmt.ExecNonQuery($"update ${Starter.tabla} set CAT_GP_ALMACEN = CAT_GP_ALMACEN + ${j3.GetString("PE_CANT")} where CAT_GP_ID = '${j3.GetString("PE_PROID")}'"$)
						B4XPages.MainPage.skmt.ExecNonQuery($"delete from pedido where pe_cedis= '${cedis}' and pe_cliente in (Select CUENTA from cuentaa) AND PE_FOLIO = '${j3.GetString("PE_FOLIO")}' AND PE_PROID = '${j3.GetString("PE_PROID")}'"$)', Array As Object(cedis, c.GetString("PE_FOLIO")))
								
					End If
				Next
			End If
			j3.Close
		Else
			Log(y.GetString("PE_CANT"))
			Log(y.Getstring("PE_PROID"))
			Log("Esto no es promo")
			If vamoaver.Get(Position) = "PREVENTA_CREDITO" Then
				B4XPages.MainPage.skmt.ExecNonQuery($"update CAT_GUNAPROD4 set cat_gp_almacen = cat_gp_almacen + ${y.GetString("PE_CANT")} where cat_gp_id = '${y.Getstring("PE_PROID")}'"$)
				B4XPages.MainPage.skmt.ExecNonQuery2("delete from pedido where pe_pronombre = ? and pe_cedis = ? and pe_cliente in (Select CUENTA from cuentaa) AND PE_FOLIO = ?", Array As Object(nom, cedis, vamoaver.Get(Position)))
			Else
				B4XPages.MainPage.skmt.ExecNonQuery($"update ${Starter.tabla} set cat_gp_almacen = cat_gp_almacen + ${y.GetString("PE_CANT")} where cat_gp_id = '${y.Getstring("PE_PROID")}'"$)
				B4XPages.MainPage.skmt.ExecNonQuery2("delete from pedido where pe_pronombre = ? and pe_cedis = ? and pe_cliente in (Select CUENTA from cuentaa) AND PE_FOLIO = ?", Array As Object(nom, cedis, vamoaver.Get(Position)))
			End If
		End If
		y.Close
			DateTime.DateFormat = "MM/dd/yyyy"
			sDate=DateTime.Date(DateTime.Now)
			sTime=DateTime.Time(DateTime.Now)
			c=B4XPages.MainPage.skmt.ExecQuery("Select CUENTA from cuentaa")
			c.Position=0
			clie_id = c.GetString("CUENTA")
			c=B4XPages.MainPage.skmt.ExecQuery("select USUARIO from usuarioa")
			c.Position=0
			usuario = c.GetString("USUARIO")
			c=B4XPages.MainPage.skmt.ExecQuery("select sum(pe_costo_tot) as TOTAL_CLIE, SUM(PE_CANT) AS CANT_CLIE, count(*) as CUANTOS FROM PEDIDO WHERE PE_CLIENTE IN (Select CUENTA from cuentaa)")
			c.Position=0
			If c.GetString("CUANTOS") > 0 Then
				B4XPages.MainPage.skmt.ExecNonQuery("delete from pedido_cliente where PC_CLIENTE In (select cuenta from cuentaa)")
				B4XPages.MainPage.skmt.ExecNonQuery2("insert into pedido_cliente(PC_CLIENTE, PC_FECHA, PC_USER, PC_NOART, PC_MONTO,PC_LON, PC_LAT) 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))
				B4XPages.MainPage.skmt.ExecNonQuery("UPDATE kmt_info3 set gestion = 0  where CAT_CL_CODIGO In (select cuenta from cuentaa)")
			Else
				B4XPages.MainPage.skmt.ExecNonQuery("delete from pedido_cliente where PC_CLIENTE In (select cuenta from cuentaa)")
				B4XPages.MainPage.skmt.ExecNonQuery("UPDATE kmt_info3 set gestion = 0  where CAT_CL_CODIGO In (select cuenta from cuentaa)")
			End If
			B4XPage_Appear
		End If

End Sub

Sub b_desc_Click
	If DESCUENTO = "MENOS" Then
		DateTime.DateFormat = "MM/dd/yyyy"
		sDate=DateTime.Date(DateTime.Now)
		sTime=DateTime.Time(DateTime.Now)
		c=B4XPages.MainPage.skmt.ExecQuery("Select CUENTA from cuentaa")
		c.Position=0
		clie_id = c.GetString("CUENTA")
		c.Close
		c=B4XPages.MainPage.skmt.ExecQuery("select USUARIO from usuarioa")
		c.Position=0
		usuario = c.GetString("USUARIO")
		c.Close
		result =  Msgbox2("Seguro que desea dar descuento del 5%?","Dar descuento", "Si", "", "No",LoadBitmap(File.DirAssets,"alert2.png")) 'ignore
		If result = DialogResponse.POSITIVE Then
			B4XPages.MainPage.skmt.ExecNonQuery("UPDATE pedido SET PE_COSTO_TOT = PE_COSTO_TOT * .95, PE_DESC = 5 WHERE PE_CLIENTE In (select cuenta from cuentaa)")
			c=B4XPages.MainPage.skmt.ExecQuery("select sum(pe_costo_tot) as TOTAL_CLIE, SUM(PE_CANT) AS CANT_CLIE, count(*) as CUANTOS FROM PEDIDO WHERE PE_CLIENTE IN (Select CUENTA from cuentaa)")
			c.Position=0
			B4XPages.MainPage.skmt.ExecNonQuery("delete from pedido_cliente where PC_CLIENTE In (select cuenta from cuentaa)")
			B4XPages.MainPage.skmt.ExecNonQuery2("insert into pedido_cliente(PC_CLIENTE, PC_FECHA, PC_USER, PC_NOART, PC_MONTO,PC_LON, PC_LAT) 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))
			c.Close
			B4XPage_Appear
		End If
	ELSE IF DESCUENTO = "MAS" Then
		DateTime.DateFormat = "MM/dd/yyyy"
		sDate=DateTime.Date(DateTime.Now)
		sTime=DateTime.Time(DateTime.Now)
		c=B4XPages.MainPage.skmt.ExecQuery("Select CUENTA from cuentaa")
		c.Position=0
		clie_id = c.GetString("CUENTA")
		c.Close
		c=B4XPages.MainPage.skmt.ExecQuery("select USUARIO from usuarioa")
		c.Position=0
		usuario = c.GetString("USUARIO")
		c.Close
		result =  Msgbox2("Seguro que desea CANCELAR el descuento?","Cancelar descuento", "Si", "", "No",LoadBitmap(File.DirAssets,"alert2.png")) 'ignore
		If result = DialogResponse.POSITIVE Then
			B4XPages.MainPage.skmt.ExecNonQuery("UPDATE pedido SET PE_COSTO_TOT = PE_COSTO_TOT / .95, PE_DESC = 0 WHERE PE_CLIENTE In (select cuenta from cuentaa)")
			c=B4XPages.MainPage.skmt.ExecQuery("select sum(pe_costo_tot) as TOTAL_CLIE, SUM(PE_CANT) AS CANT_CLIE, count(*) as CUANTOS FROM PEDIDO WHERE PE_CLIENTE IN (Select CUENTA from cuentaa)")
			c.Position=0
			B4XPages.MainPage.skmt.ExecNonQuery("delete from pedido_cliente where PC_CLIENTE In (select cuenta from cuentaa)")
			B4XPages.MainPage.skmt.ExecNonQuery2("insert into pedido_cliente(PC_CLIENTE, PC_FECHA, PC_USER, PC_NOART, PC_MONTO,PC_LON, PC_LAT) 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))
			c.Close
			B4XPage_Appear
		End If
	End If
End Sub

Private Sub p_nota_Click
	
End Sub