B4A=true
Group=Default Group
ModulesStructureVersion=1
Type=Class
Version=12.8
@EndOfDesignText@
Sub Class_Globals
	Private Root As B4XView 'ignore
	Private xui As XUI 'ignore
	Dim c As Cursor
	Private la_cuenta As Label
	Private La_nombre As Label
	Private la_Calle As Label
	Private la_col As Label
	Private l_entre1 As Label
	Private l_entre2 As Label
	Private l_atiende As Label
	Private Label19 As Label
	Private l_animal As Label
	Private l_limite As Label
	Private l_tipocliente As Label
	Private la_saldotot As Label
	Private Label22 As Label
	Private l_credito As Label
	Private ImageView4 As ImageView
	Private Guardar As Button
	Private p_deuda As Panel
	Private Panel5 As Panel
	Private b_okdeuda As Button
	Private l_deuda As Label
	Private I_fotogrande As ImageView
	Private P_Imagengrande 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
	Root.LoadLayout("Vista_todoslosclientes")
End Sub

Sub HIST_Click
	B4XPages.ShowPage("historicobattodos")
End Sub

Sub B4XPage_Appear
	Log("Entramos")
	c = Starter.skmt.ExecQuery ($"select * from CAT_CATCLIENTESTODOS where CAT_CL_CODIGO in (Select CUENTA from cuentaa)"$)
	If c.RowCount > 0 Then
		c.Position=0
		Log(c.GetString("CAT_CL_NOMBRE"))
		la_cuenta.Text=c.GetString("CAT_CL_CODIGO")
		La_nombre.Text=c.GetString("CAT_CL_NOMBRE")
		la_Calle.Text=c.GetString("CAT_CL_CALLE")
		la_col.Text=c.GetString("CAT_CL_COLONIA")
		l_entre1.Text=c.GetString("CAT_CL_CALLE1")
		l_entre2.Text=c.GetString("CAT_CL_CALLE2")
		l_atiende.Text=c.GetString("CAT_CL_ATIENDE1")
		Label19.Text = c.GetString("CAT_CL_TELEFONO")
		
		l_tipocliente.Text = Subs.traeTipoCliente
		
		Dim fotomostrar As Cursor = Starter.skmt.ExecQuery("SELECT FOTO FROM FOTOS where CLIENTE IN (SELECT CUENTA FROM CUENTAA)")
		If fotomostrar.RowCount > 0 Then
		
			fotomostrar.Position = 0
			Private fotomostrarfinal() As Byte = fotomostrar.GetBlob("FOTO")
			Dim InputStream1 As InputStream
			InputStream1.InitializeFromBytesArray(fotomostrarfinal, 0, fotomostrarfinal.Length)
			Dim Bitmap1 As Bitmap
			Bitmap1.Initialize2(InputStream1)
			InputStream1.Close
			ImageView4.Bitmap = Bitmap1
			Log("aqui si hay foto")
		Else
			ImageView4.Bitmap = LoadBitmap(File.DirAssets,"images.png")
			Log("aqui no hay foto")
		End If
		
		
		
		
	End If
	
	Subs.centraPanel(P_Imagengrande,Root.Width)
	
	Dim coloressaldo As Cursor=B4XPages.MainPage.skmt.ExecQuery("select IFNULL(CAT_CL_CLASIFICADOR3,0) AS CAT_CL_CLASIFICADOR3, IFNULL(CAT_CL_CLASIFICADOR4,0) AS CAT_CL_CLASIFICADOR4, IFNULL(CAT_CL_CLASIFICADOR2,'') AS CAT_CL_CLASIFICADOR2 from CAT_CATCLIENTESTODOS where CAT_CL_CODIGO In (Select cuenta from cuentaa)")
	coloressaldo.Position = 0
		
	l_animal.Text = coloressaldo.GetString("CAT_CL_CLASIFICADOR2")
	If coloressaldo.GetString("CAT_CL_CLASIFICADOR2") = "Chimpancé KIN" Then
		l_animal.Color = Colors.RGB(84,255,172)
		Label22.Color = Colors.RGB(84,255,172)
	Else If coloressaldo.GetString("CAT_CL_CLASIFICADOR2") = "Delfín Niky" Then
		l_animal.Color = Colors.RGB(84,255,245)
		Label22.Color = Colors.RGB(84,255,245)
	Else If coloressaldo.GetString("CAT_CL_CLASIFICADOR2") = "Tortuga KOPI" Then
		l_animal.Color = Colors.RGB(255,123,84)
		Label22.Color = Colors.RGB(255,123,84)
	Else If coloressaldo.GetString("CAT_CL_CLASIFICADOR2") = "Lechuza MON" Then
		l_animal.Color = Colors.RGB(255,250,140)
		Label22.Color = Colors.RGB(255,250,140)
	Else
		l_animal.Color = Colors.Transparent
		Label22.Color = Colors.Transparent
	End If
	
	c = B4XPages.MainPage.skmt.ExecQuery("select IFNULL(CAT_CL_BCREDITO,0) AS CAT_CL_BCREDITO, CAT_CL_LIMITECREDITO from CAT_CATCLIENTESTODOS where CAT_CL_CODIGO In (Select cuenta from cuentaa)")
	c.Position = 0
	If c.GetInt("CAT_CL_BCREDITO") = 1 Then

		Dim pagarepen As Cursor = B4XPages.MainPage.skmt.ExecQuery("select FECHA, SALDO_PENDIENTE FROM ABONOSP WHERE CLIENTE IN (SELECT CUENTA FROM CUENTAA)")
		If pagarepen.RowCount > 0 Then
			pagarepen.Position = 0
			DateTime.DateFormat="dd/MM/yyyy"
			Dim FechaInicio As String = pagarepen.GetString("FECHA")  ' Formato: dd/MM/yyyy
'		Dim FechaHoy As String = DateTime.Date(DateTime.Now)  ' Fecha actual en formato dd/MM/yyyy
			Log(pagarepen.GetString("FECHA"))
			' Convertir las fechas a milisegundos (desde 01/01/1970)
			Dim TicksInicio As Long = DateTime.DateParse(FechaInicio)
			Dim TicksHoy As Long = DateTime.DateParse(DateTime.Date(DateTime.Now))

			' Calcular diferencia en días
			Dim DiferenciaDias As Int = (TicksHoy - TicksInicio) / DateTime.TicksPerDay

			' Mostrar resultado
			Log($"Días transcurridos: ${DiferenciaDias}"$)

			Dim c4 As Cursor=B4XPages.MainPage.skmt.ExecQuery("select IFNULL(CAT_CL_DIASCREDITO,0) AS CAT_CL_DIASCREDITO from kmt_info3 where CAT_CL_CODIGO In (Select cuenta from cuentaa)")
			c4.Position = 0

'				If DiferenciaDias <= c4.GetInt("CAT_CL_DIASCREDITO") + 1 Then
			''					l_credito.Color = Colors.Green
			''					l_limite.Color = Colors.Green
'				Else If DiferenciaDias > c4.GetInt("CAT_CL_DIASCREDITO") + 1 Then
'					l_credito.Color = Colors.Red
'					l_limite.Color = Colors.Red
'				End If
		Else
'				l_credito.Color = Colors.Transparent
'				l_limite.Color = Colors.Transparent
		End If
		l_credito.Visible = True
		l_limite.Visible = True
		l_limite.Text = c.GetInt("CAT_CL_LIMITECREDITO")
	Else If c.GetInt("CAT_CL_BCREDITO") = 0 Then
		l_credito.Visible = False
		l_limite.Visible = False
	End If
End Sub

Private Sub l_limite_Click
	
		
	Dim pagarepen As Cursor = B4XPages.MainPage.skmt.ExecQuery("select FECHA, SALDO_PENDIENTE FROM ABONOSPTOD WHERE CLIENTE IN (SELECT CUENTA FROM CUENTAA)")
	If pagarepen.RowCount > 0 Then
		Dim cs As CSBuilder
		cs.Initialize
		p_deuda.Visible = True
		p_deuda.Width = Root.Width
		p_deuda.Height = Root.Height
		
		pagarepen.Position = 0
		DateTime.DateFormat="dd/MM/yyyy"
		Dim FechaInicio As String = pagarepen.GetString("FECHA")  ' Formato: dd/MM/yyyy
'		Dim FechaHoy As String = DateTime.Date(DateTime.Now)  ' Fecha actual en formato dd/MM/yyyy
		Log(pagarepen.GetString("FECHA"))
		
		' Convertir las fechas a milisegundos (desde 01/01/1970)
		Dim TicksInicio As Long = DateTime.DateParse(FechaInicio)
		Dim TicksHoy As Long = DateTime.DateParse(DateTime.Date(DateTime.Now))

		' Calcular diferencia en días
		Dim DiferenciaDias As Int = (TicksHoy - TicksInicio) / DateTime.TicksPerDay

		' Mostrar resultado
		Log($"Días transcurridos: ${DiferenciaDias}"$)
		
		c=B4XPages.MainPage.skmt.ExecQuery("select IFNULL(CAT_CL_DIASCREDITO,0) AS CAT_CL_DIASCREDITO from CAT_CATCLIENTESTODOS where CAT_CL_CODIGO In (Select cuenta from cuentaa)")
		c.Position = 0

		If DiferenciaDias <= c.GetInt("CAT_CL_DIASCREDITO") + 8 Then
'			Msgbox2Async($"Favor de pagar su credito el día de mañana por un monto  de $${pagarepen.GetString("SALDO_PENDIENTE")}"$, "Recordatorio", "Ok", "", "", LoadBitmap(File.DirAssets,"alert2.png"), False)
			
'			l_deuda.Text = ($"Favor de pagar su credito el día de mañana por un monto  de $${pagarepen.GetString("SALDO_PENDIENTE")}"$)
			l_deuda.Text = cs.Color(Colors.Black).Append("Monto de la deuda:" & CRLF&CRLF).Pop.Size(18).Color(Colors.RGB(48,109,0)).Append("$ "& pagarepen.GetString("SALDO_PENDIENTE")).PopAll
		Else If DiferenciaDias > c.GetInt("CAT_CL_DIASCREDITO") + 8 Then
'			l_deuda.Text = ($"No se puede realizar venta por que presenta ${(DiferenciaDias-(c.GetInt("CAT_CL_DIASCREDITO") +1))} días de atraso en el credito, por un monto de $${pagarepen.GetString("SALDO_PENDIENTE")}"$)
			l_deuda.Text = cs.Color(Colors.Black).Append("Monto de la deuda:" & CRLF&CRLF).Pop.Color(Colors.Red).Size(18).Append("$ " &pagarepen.GetString("SALDO_PENDIENTE")&CRLF&CRLF).Pop.Size(14).Color(Colors.Black).Append("Dias de atraso:" & CRLF&CRLF).Pop.Size(18).Color(Colors.Red).Append((DiferenciaDias-(c.GetInt("CAT_CL_DIASCREDITO") +1))).PopAll
		End If
	Else
		p_deuda.Visible = True
		
		p_deuda.Width = Root.Width
		p_deuda.Height = Root.Height
		
		l_deuda.Text = "No tiene adeudo"
	End If

End Sub


'Private Sub B4XPage_CloseRequest As ResumableSub
''	BACK key pressed
''	Return True To close, False To cancel
'	
'	If P_Imagengrande.Visible Then
'		P_Imagengrande.Visible = False
'		Return False
'	Else if Subs.hayPedido Then
'		ToastMessageShow("Por favor presione el botón de GUARDAR", True)
''		Return False
''	else If p_deuda.Visible Then
''		p_deuda.Visible = False
''		Return False
'	Else
''		Starter.enCliente = False
'		B4XPages.ShowPage("Clientes_Completos")
'	End If
''	Return True
'	Return False
'End Sub

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

Private Sub Guardar_Click
	B4XPages.ShowPage("Principal")
End Sub

Private Sub ImageView4_LongClick
	Private fotomostrar As Cursor = Starter.skmt.ExecQuery("SELECT FOTO FROM FOTOS where CLIENTE IN (SELECT CUENTA FROM CUENTAA)")
	If fotomostrar.RowCount > 0 Then
		
		fotomostrar.Position = 0
		Private fotomostrarfinal() As Byte = fotomostrar.GetBlob("FOTO")
		Dim InputStream1 As InputStream
		InputStream1.InitializeFromBytesArray(fotomostrarfinal, 0, fotomostrarfinal.Length)
		Dim Bitmap1 As Bitmap
		Bitmap1.Initialize2(InputStream1)
		InputStream1.Close
		I_fotogrande.Bitmap = Bitmap1
		Log("aqui si hay foto")
	Else
		I_fotogrande.Bitmap = LoadBitmap(File.DirAssets,"images.png")
		Log("aqui no hay foto")
	End If
	P_Imagengrande.Visible = True
End Sub

Sub P_Imagengrande_click
	P_Imagengrande.Visible = False
End Sub

Private Sub b_okdeuda_Click
	p_deuda.Visible = False
End Sub