B4A=true
Group=Default Group
ModulesStructureVersion=1
Type=Class
Version=11.5
@EndOfDesignText@
Sub Mods 'Ignore
	'2023/05/11 - Se modifico "ListView1_ItemLongClick" para que si al borrar un producto de la nota, el total es negativo, entonces se borren todos los RMIs de la orden.
End Sub

Sub Class_Globals
	Private Root As B4XView 'ignore
	Private xui As XUI 'ignore
	'//Process Globals
	Dim clie_id As String
	Dim sDate,sTime As String
	Dim usuario As String
	'//Globals
	Dim c,C_DOE As Cursor
	Dim C1 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
	Private Titulo As Label
	Private b_desc As Button
	Dim DESCUENTO As String
	Dim folio As String
	Dim TIPO As String
	Private CAMBIOS As String
	Dim logger As Boolean = True
	Private B_PEDIDO_DOE As Button
	Private ListView3 As ListView
	Private L_CANT_D As Label
	Private L_TOTAL_D 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)
	If Not(Starter.Logger) Then logger = False
	Root = Root1
	'load the layout to Root
	ruta = File.DirInternal
	Root.LoadLayout("nota")
	borra.Visible = True
	Titulo.Text = "Pedido Actual"
	Starter.skmt.ExecNonQuery("update pedido set pe_folio = 0 where pe_folio is null")
	c=Starter.skmt.ExecQuery("select count(*) as EXISTE from pedido_cliente WHERE pc_cliente IN (Select CUENTA from cuentaa)")
	C.Position=0
	Existe = C.GetString("EXISTE")
	C.Close
	c=Starter.skmt.ExecQuery("select PE_PRONOMBRE,PE_COSTO_TOT, PE_CANT, PE_FOLIO FROM PEDIDO WHERE PE_CLIENTE IN (Select CUENTA from cuentaa) order by PE_PRONOMBRE asc")
	ListView1.Clear
	If c.RowCount>0 Then
		For i=0 To c.RowCount -1
			c.Position=i
			Dim label1 As Label
			label1 = ListView1.TwoLinesLayout.Label
			label1.TextSize = 13
			label1.TextColor = Colors.Black
			Dim label2 As Label
			label2 = ListView1.TwoLinesLayout.SecondLabel
			label2.TextSize = 12
			label2.TextColor = Colors.Black
			ListView1.AddTwoLines(c.GetString("PE_PRONOMBRE"),"Cantidad #"& c.GetString("PE_CANT")& " SubTotal $"& c.GetString("PE_COSTO_TOT")& " Folio "& c.GetString("PE_FOLIO"))
			folio = c.GetString("PE_FOLIO")
		Next
	End If
	If Existe <> 0 Then
		c=Starter.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
	c=Starter.skmt.ExecQuery2("select count(*) as CUANTOS FROM PEDIDO WHERE PE_CLIENTE IN (Select CUENTA from cuentaa) AND PE_CEDIS = ?", Array As String("DOE"))
	c.Position = 0
	ListView1.Visible = True
	L_CANT.Visible = True
	L_TOTAL.Visible = True
	ListView3.Visible = False
	L_CANT_D.Visible = False
	L_TOTAL_D.Visible = False
	If c.GetString("CUANTOS") > 0 Then
		
		B_PEDIDO_DOE.Text = "PEDIDO DON TOÑO"
		B_PEDIDO_DOE.VISIBLE = True
		C_DOE=Starter.skmt.ExecQuery2("select PE_PRONOMBRE,PE_COSTO_TOT, PE_CANT, PE_FOLIO FROM PEDIDO WHERE PE_CEDIS = ? AND PE_CLIENTE IN (Select CUENTA from cuentaa) order by PE_PRONOMBRE asc", Array As String("DOE"))
		ListView3.Clear
		If C_DOE.RowCount>0 Then
			For i=0 To C_DOE.RowCount -1
				C_DOE.Position=i
				Private txtPromo As String = ""
				If C_DOE.GetString("PE_COSTO_TOT") < 0.02 And C_DOE.GetString("PE_COSTO_TOT") >= 0 Then txtPromo = "P - "
				If C_DOE.GetString("PE_COSTO_TOT") < 0 Then txtPromo = "RMI - "
				Dim label1 As Label
				label1 = ListView3.TwoLinesLayout.Label
				label1.TextSize = 15
				label1.TextColor = Colors.Black
				Dim label2 As Label
				label2 = ListView3.TwoLinesLayout.SecondLabel
				label2.TextSize = 12
				label2.TextColor = Colors.Black
				ListView3.AddTwoLines(C_DOE.GetString("PE_PRONOMBRE"),txtPromo & "Cantidad #"& C_DOE.GetString("PE_CANT")& " SubTotal $"& C_DOE.GetString("PE_COSTO_TOT")& " Folio "& C_DOE.GetString("PE_FOLIO"))
				folio = C_DOE.GetString("PE_FOLIO")
			Next
		End If
		C_DOE.Close
		C_DOE=Starter.skmt.ExecQuery2("select sum(pe_cant) AS CANTIDAD, sum(pe_costo_tot) AS MONTO from  pedido where PE_CEDIS <> PE_PROID and pe_cliente in (Select CUENTA from cuentaa)  AND PE_CEDIS = ?", Array As String("DOE"))
		C_DOE.Position=0
		L_CANT_D.Text = C_DOE.GetString("CANTIDAD")
		L_TOTAL_D.Text = C_DOE.GetString("MONTO")
		c.Close
	Else
		B_PEDIDO_DOE.VISIBLE = False
	End If
	c=Starter.skmt.ExecQuery("select count(*) as CUANTOS from kmt_info where (impresion = 1 or cat_cl_codigo in (select ci_cuenta from cliente_impreso)) and CAT_CL_CODIGO in (Select CUENTA from cuentaa)")
	c.Position = 0
	If logger Then Log($"Impreso: ${c.GetString("CUANTOS")}"$)
	If c.GetString("CUANTOS") > 0 Then
		borra.Visible = False
	Else
		borra.Visible = True
	End If
	If Subs.clienteActual = "0" Then borra.Visible = True 'Si el cliente actual es "abordo" entonces SIEMPRE lo dejamos modificar la venta.
	c.Close
	L_CANT.Text =""
	L_TOTAL.Text=""
	Starter.skmt.ExecNonQuery("update pedido set pe_folio = 0 where pe_folio is null")
	c=Starter.skmt.ExecQuery("select count(*) as EXISTE from pedido_cliente WHERE pc_cliente IN (Select CUENTA from cuentaa)")
	C.Position=0
	Existe = C.GetString("EXISTE")
	C.Close
	c=Starter.skmt.ExecQuery2("select PE_PRONOMBRE,PE_COSTO_TOT, PE_CANT, PE_FOLIO FROM PEDIDO WHERE PE_CEDIS <> ? AND PE_CLIENTE IN (Select CUENTA from cuentaa) order by PE_PRONOMBRE asc", Array As String("DOE"))
	ListView1.Clear
	If c.RowCount>0 Then
		For i=0 To c.RowCount -1
			c.Position=i
			Private txtPromo As String = ""
			If c.GetString("PE_COSTO_TOT") < 0.02 And c.GetString("PE_COSTO_TOT") >= 0 Then txtPromo = "P - "
			If c.GetString("PE_COSTO_TOT") < 0 Then txtPromo = "RMI - "
			Dim label1 As Label
			label1 = ListView1.TwoLinesLayout.Label
			label1.TextSize = 15
			label1.TextColor = Colors.Black
			Dim label2 As Label
			label2 = ListView1.TwoLinesLayout.SecondLabel
			label2.TextSize = 12
			label2.TextColor = Colors.Black
			ListView1.AddTwoLines(c.GetString("PE_PRONOMBRE"),txtPromo & "Cantidad #"& c.GetString("PE_CANT")& " SubTotal $"& c.GetString("PE_COSTO_TOT")& " Folio "& c.GetString("PE_FOLIO"))
			folio = c.GetString("PE_FOLIO")
		Next
	End If
	If Existe <> 0 Then
		c=Starter.skmt.ExecQuery2("select sum(pe_cant) AS CANTIDAD, sum(pe_costo_tot) AS MONTO from  pedido where PE_CEDIS <> PE_PROID and pe_cliente in (Select CUENTA from cuentaa) AND PE_CEDIS <> ?", Array As String("DOE"))
		C.Position=0
		L_CANT.Text = c.GetString("CANTIDAD")
		L_TOTAL.Text = c.GetString("MONTO")
		c.Close
		c=Starter.skmt.ExecQuery("select SUM(IFNULL(PE_DESC,0)) AS DESCUENTO FROM PEDIDO WHERE PE_CLIENTE IN (Select CUENTA from cuentaa)")
		c.Position=0
		b_desc.Visible = False
	End If
	c=Starter.skmt.ExecQuery("select count(*) As CUANTOS FROM PEDIDO WHERE PE_CLIENTE IN (Select CUENTA from cuentaa)")
	c.Position = 0
	If c.GetString("CUANTOS") = 0 Then
		folio = 0
	Else
		C1=Starter.skmt.ExecQuery("SELECT SUM(ifnull(PE_FOLIO,0)) AS FOLIO FROM PEDIDO WHERE PE_CLIENTE IN (Select CUENTA from cuentaa)")
		C1.Position = 0
		folio = C1.GetString("FOLIO")
		If C1.GetString("FOLIO") > 0 Then
			folio = 100
		End If
	End If
	c.Close
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
	Subs.iniciaActividad("Cliente")
End Sub

Sub Activity_KeyPress (key As Int) As Boolean
	' BACK key pressed
	If key=KeyCodes.KEYCODE_BACK Then
		' I want to capture the key here so I return True
		Subs.iniciaActividad("Cliente")
		'Return True
	End If
	' Returning False signals the system to handle the key
	Return False
End Sub

Sub borra_Click
	If folio = "0" Or Subs.clienteActual = "0" Then 'Si el folio es 0 o el cliente actual es "abordo", los deja borrar. - Mod por CHV 220512
		result =  Msgbox2("Seguro que desea borrar el pedido?","Cancelar pedido", "Si", "", "No",LoadBitmap(File.DirAssets,"alert2.png")) 'ignore
		If result = DialogResponse.POSITIVE Then
			c=Starter.skmt.ExecQuery("select PE_PROID, PE_CANT, PE_TIPO 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
					TIPO = c.GetString("PE_TIPO")
					If c.GetString("PE_TIPO") = "VENTA" Then
						Starter.skmt.ExecNonQuery2("update cat_gunaprod2 set cat_gp_almacen = cat_gp_almacen + ? where cat_gp_id = ?", Array As Object(c.GetString("PE_CANT"),c.GetString("PE_PROID")))
					Else
						Starter.skmt.ExecNonQuery2("update cat_gunaprod set cat_gp_almacen = cat_gp_almacen + ? where cat_gp_id = ?", Array As Object(c.GetString("PE_CANT"),c.GetString("PE_PROID")))
					End If
				Next
			End If
			Starter.skmt.ExecNonQuery("delete from pedido_cliente where pc_cliente in (Select CUENTA from cuentaa)")
			Starter.skmt.ExecNonQuery("delete from pedido where pe_cliente in (Select CUENTA from cuentaa)")
			Starter.skmt.ExecNonQuery("UPDATE kmt_info set gestion = 0  where CAT_CL_CODIGO In (select cuenta from cuentaa)")
			B4XPage_Appear
		End If
	Else
		Msgbox("CLIENTE YA SE TRANSMITIO, FAVOR DE LLAMAR A SOPORTE PARA ASISTENCIA","AVISO") 'ignore
	End If
End Sub

Sub ListView1_ItemLongClick (Position As Int, Value As Object)
	c=Starter.skmt.ExecQuery("select count(*) as CUANTOS from CLIENTE_IMPRESO where CI_CUENTA in  (Select CUENTA from cuentaa)")
	c.Position = 0
	If c.GetString("CUANTOS") = 0 Or Subs.clienteActual = "0" Then 'Si la venta no está impresa o es abordo entonces continuamos ...
		c=Starter.skmt.ExecQuery2("select count(*) as CUANTOS, sum(PE_COSTO_TOT) as sumaRMIs FROM PEDIDO WHERE PE_CEDIS = ? AND PE_CLIENTE IN (Select CUENTA from cuentaa)", Array As String("DUR"))
		c.Position = 0
		CAMBIOS = c.GetString("CUANTOS")
		c.Close
		c=Starter.skmt.ExecQuery2("select PE_PRONOMBRE,PE_COSTO_TOT, PE_CANT, PE_FOLIO FROM PEDIDO WHERE PE_CLIENTE IN (Select CUENTA from cuentaa) AND PE_PRONOMBRE = ? order by PE_PRONOMBRE asc", Array As String(Value) )
		c.Position = 0
		If c.GetString("PE_FOLIO")  = "0" Or Subs.clienteActual = "0" 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=Starter.skmt.ExecQuery2("select PE_PROID,PE_CANT, PE_TIPO FROM PEDIDO where pe_pronombre = ? and pe_cliente in (Select CUENTA from cuentaa) AND PE_CEDIS <> ? ", Array As String(Value, "DOE"))
				c.Position=0
				TIPO = c.GetString("PE_TIPO")
				If c.GetString("PE_TIPO") = "VENTA" Then
					Starter.skmt.ExecNonQuery2("update cat_gunaprod2 set cat_gp_almacen = cat_gp_almacen + ? where cat_gp_id = ?", Array As Object(c.GetString("PE_CANT"),c.GetString("PE_PROID")))
				Else
					Starter.skmt.ExecNonQuery2("update cat_gunaprod set cat_gp_almacen = cat_gp_almacen + ? where cat_gp_id = ?", Array As Object(c.GetString("PE_CANT"),c.GetString("PE_PROID")))
				End If
				c.Close
				
				
				If TIPO = "VENTA" Then
					c=Starter.skmt.ExecQuery2("select count(*) AS CUANTOS from cat_gunaprod2 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))
				Else
					c=Starter.skmt.ExecQuery2("select count(*) AS CUANTOS from cat_gunaprod 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))
				End If
				c.Position=0
				If c.GetString("CUANTOS") > 0 Then
					Starter.skmt.ExecNonQuery2("delete from pedido where pe_folio = 0 and pe_cedis in (select pe_cedis from pedido where pe_pronombre = ?) and pe_cliente in (Select CUENTA from cuentaa) and pe_cedis <> ?", Array As Object(Value, "DOE"))
				Else
					Starter.skmt.ExecNonQuery2("delete from pedido where pe_folio = 0  and pe_pronombre = ?  and pe_cliente in (Select CUENTA from cuentaa) AND PE_CEDIS <> ?", Array As Object(Value, "DOE"))
				End If
				
				'Borramos RMIs si la venta es menor que los RMIs
				Private x2 As Cursor = Starter.skmt.ExecQuery2("select sum(PE_COSTO_TOT) as sumaRMIs FROM PEDIDO WHERE PE_CEDIS = ? AND PE_CLIENTE IN (Select CUENTA from cuentaa)", Array As String("DUR"))
				Private x As Cursor = Starter.skmt.ExecQuery2("select sum(PE_COSTO_TOT) as sumaNoRMIs FROM PEDIDO WHERE PE_CEDIS <> ? AND PE_CLIENTE IN (Select CUENTA from cuentaa)", Array As String("DUR"))
				x.Position = 0
				x2.Position = 0
				Private sumaRMIs = 0
				Private sumaNoRMIs = 0
				If x2.GetString("sumaRMIs") <> Null Then sumaRMIs = x2.GetString("sumaRMIs")
				If x.GetString("sumaNoRMIs") <> Null Then sumaNoRMIs = x.GetString("sumaNoRMIs")
				LogColor($"${x2.GetString("sumaRMIs")}, ${x.GetString("sumaNoRMIs")}"$, Colors.Magenta)
				If (sumaRMIs + sumaNoRMIs) >= 0 Then
					Log("No borrar RMIs")
				Else
					Log("Borrar RMIs")
					Starter.skmt.ExecNonQuery2("delete FROM PEDIDO WHERE PE_CEDIS = ? AND PE_CLIENTE IN (Select CUENTA from cuentaa)", Array As String("DUR"))
				End If
				
				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")
				c=Starter.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
					Starter.skmt.ExecNonQuery("delete from pedido_cliente where PC_CLIENTE In (select cuenta from cuentaa)")
					If logger Then LogColor($"Insertamos coordenadas en pedido: ${Starter.lon_gps}, ${Starter.lat_gps}"$, Colors.Magenta)
					Starter.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"), Starter.lon_gps, Starter.lat_gps))
					Starter.skmt.ExecNonQuery("UPDATE kmt_info set gestion = 2  where CAT_CL_CODIGO In (select cuenta from cuentaa)")
				Else
					Starter.skmt.ExecNonQuery("delete from pedido_cliente where PC_CLIENTE In (select cuenta from cuentaa)")
					Starter.skmt.ExecNonQuery("UPDATE kmt_info set gestion = 0  where CAT_CL_CODIGO In (select cuenta from cuentaa)")
				End If


			
				B4XPage_Appear
			End If
		Else
			Msgbox("CLIENTE YA SE TRANSMITIO, FAVOR DE LLAMAR A SOPORTE PARA ASISTENCIA","AVISO") 'ignore
		End If
	Else
		ToastMessageShow("Esta venta ya esta impresa, no se puede editar ni borrar.", False)
	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=Starter.skmt.ExecQuery("Select CUENTA from cuentaa")
		c.Position=0
		clie_id = c.GetString("CUENTA")
		c.Close
		c=Starter.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
			Starter.skmt.ExecNonQuery("UPDATE pedido SET PE_COSTO_TOT = PE_COSTO_TOT * .95, PE_DESC = 5 WHERE PE_CLIENTE In (select cuenta from cuentaa)")
			c=Starter.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
			Starter.skmt.ExecNonQuery("delete from pedido_cliente where PC_CLIENTE In (select cuenta from cuentaa)")
			If logger Then LogColor($"Insertamos coordenadas en pedido: ${Starter.lon_gps}, ${Starter.lat_gps}"$, Colors.Magenta)
			Starter.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"), Starter.lon_gps, Starter.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=Starter.skmt.ExecQuery("Select CUENTA from cuentaa")
		c.Position=0
		clie_id = c.GetString("CUENTA")
		c.Close
		c=Starter.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
			Starter.skmt.ExecNonQuery("UPDATE pedido SET PE_COSTO_TOT = PE_COSTO_TOT / .95, PE_DESC = 0 WHERE PE_CLIENTE In (select cuenta from cuentaa)")
			c=Starter.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
			Starter.skmt.ExecNonQuery("delete from pedido_cliente where PC_CLIENTE In (select cuenta from cuentaa)")
			If logger Then LogColor($"Insertamos coordenadas en pedido: ${Starter.lon_gps}, ${Starter.lat_gps}"$, Colors.Magenta)
			Starter.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"), Starter.lon_gps, Starter.lat_gps))
			c.Close
			B4XPage_Appear
		End If
	End If
End Sub

Private Sub B_PEDIDO_DOE_Click
	If B_PEDIDO_DOE.Text = "PEDIDO DON TOÑO" Then
	ListView1.Visible = False
		L_CANT.Visible = False
		L_TOTAL.Visible = False
		B_PEDIDO_DOE.Text = "PEDIDO NORMAL"
		ListView3.Visible = True
		L_CANT_D.Visible = True
		L_TOTAL_D.Visible = True

	Else
		ListView1.Visible = True
		B_PEDIDO_DOE.Text = "PEDIDO DON TOÑO"
		ListView3.Visible = False
		L_CANT_D.Visible = False
		L_TOTAL_D.Visible = False
		L_CANT.Visible = True
		L_TOTAL.Visible = True

	End If
End Sub

Private Sub ListView3_ItemLongClick (Position As Int, Value As Object)

	c=Starter.skmt.ExecQuery("select count(*) as CUANTOS from kmt_info where (impresion = 1 or cat_cl_codigo in (select ci_cuenta from cliente_impreso)) and CAT_CL_CODIGO in (Select CUENTA from cuentaa)")
	c.Position = 0
	If logger Then Log($"Impreso: ${c.GetString("CUANTOS")}"$)
	If c.GetString("CUANTOS") > 0 Then
		ToastMessageShow("Esta venta ya esta impresa, no se puede editar ni borrar.", False)
	Else

	If folio = "0" Or Subs.clienteActual = "0" Then 'Si el folio es 0 o el cliente actual es "abordo", los deja borrar. - Mod por CHV 220512
		result =  Msgbox2("Seguro que desea borrar el pedido?","Cancelar pedido", "Si", "", "No",LoadBitmap(File.DirAssets,"alert2.png")) 'ignore
		If result = DialogResponse.POSITIVE Then
			c=Starter.skmt.ExecQuery2("select PE_PROID,PE_CANT, PE_TIPO FROM PEDIDO where pe_cliente in (Select CUENTA from cuentaa) AND PE_CEDIS = ?", Array As String("DOE"))
			If c.RowCount>0 Then
				For i=0 To c.RowCount -1
					c.Position=i
					TIPO = c.GetString("PE_TIPO")
					If c.GetString("PE_TIPO") = "VENTA" Then
						Starter.skmt.ExecNonQuery2("update cat_gunaprod2 set cat_gp_almacen = cat_gp_almacen + ? where cat_gp_id = ?", Array As Object(c.GetString("PE_CANT"),c.GetString("PE_PROID")))
					Else
						Starter.skmt.ExecNonQuery2("update cat_gunaprod set cat_gp_almacen = cat_gp_almacen + ? where cat_gp_id = ?", Array As Object(c.GetString("PE_CANT"),c.GetString("PE_PROID")))
					End If
				Next
			End If
			
			Starter.skmt.ExecNonQuery2("delete from pedido where pe_cliente in (Select CUENTA from cuentaa) AND PE_CEDIS = ?", Array As Object("DOE"))
			Starter.skmt.ExecNonQuery("UPDATE kmt_info set gestion = 0  where CAT_CL_CODIGO In (select cuenta from cuentaa)")
			B4XPage_Appear
		End If
	Else
		Msgbox("CLIENTE YA SE TRANSMITIO, FAVOR DE LLAMAR A SOPORTE PARA ASISTENCIA","AVISO") 'ignore
	End If
	End If
End Sub