Option Strict Off
Option Explicit On
Imports VB = Microsoft.VisualBasic
Imports Microsoft.VisualBasic.PowerPacks
Friend Class frmRecMan
	Inherits System.Windows.Forms.Form
	Private istrFlgst As String
	Private istrNmBco As String
	Private iblnReImp As Boolean
	
	'UPGRADE_WARNING: Event cmbBancos.TextChanged may fire when form is initialized. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="88B12AE1-6DE0-48A0-86F1-60C0686C026A"'
	'UPGRADE_WARNING: ComboBox event cmbBancos.Change was upgraded to cmbBancos.TextChanged which has a new behavior. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="DFCDE711-9694-47D7-9C50-45A99CD8E91E"'
	Private Sub cmbBancos_TextChanged(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles cmbBancos.TextChanged
		Call cmbBancos_SelectedIndexChanged(cmbBancos, New System.EventArgs())
	End Sub
	
	'UPGRADE_WARNING: Event cmbBancos.SelectedIndexChanged may fire when form is initialized. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="88B12AE1-6DE0-48A0-86F1-60C0686C026A"'
	Private Sub cmbBancos_SelectedIndexChanged(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles cmbBancos.SelectedIndexChanged
		istrNmBco = VB6.GetItemString(Me.cmbBancos, Me.cmbBancos.SelectedIndex)
	End Sub
	
	Private Sub cmdEstornaLote_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles cmdEstornaLote.Click
		Call frmEstornaBaixas.SetaParametros(Me, Me.dtpPagamento.value, VB6.GetItemData(Me.cmbBancos, Me.cmbBancos.SelectedIndex), VB6.GetItemString(Me.cmbBancos, Me.cmbBancos.SelectedIndex))
		Call frmEstornaBaixas.Show()
	End Sub
	
	Private Sub cmdLocalizarValorFatura_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles cmdLocalizarValorFatura.Click
		Call frmLocalizaFaturaValor.SetaParametros(Me)
		Call frmLocalizaFaturaValor.Show()
	End Sub
	
	Private Sub cmdReimprimir_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles cmdReimprimir.Click
		Dim lstrSql As String
		Dim lrstAux As ADODB.Recordset
		Dim ldblNumNf As Double
		Dim lstrMesAno As String
		Dim lstrZona As String
		Dim lstrLivro As String
		Dim lstrConta As String
		Dim ldblLiquido As Double
		Dim ldtePagamento As Date
		Dim ldteSituacao As Date
		Dim ldteVencimento As Date
		Dim lstrFlgst As String
		Dim lstrMotivo As String
		Dim llngTotReg As Integer
		Dim ldblTotVlr As Double
		llngTotReg = 0
		ldblTotVlr = 0
		iblnReImp = True
		lrstAux = New ADODB.Recordset
		Call MontaGrid(Me.mfgReimprimir)
		lstrSql = ""
		lstrSql = lstrSql & "SELECT `nf`.`zona`,     " & vbCrLf
		lstrSql = lstrSql & "       `nf`.`livro`,    " & vbCrLf
		lstrSql = lstrSql & "       `nf`.`conta`,    " & vbCrLf
		lstrSql = lstrSql & "       `nf`.`ta`,       " & vbCrLf
		lstrSql = lstrSql & "       `nf`.`flgst`,    " & vbCrLf
		lstrSql = lstrSql & "       `nf`.`datapag`,  " & vbCrLf
		lstrSql = lstrSql & "       `nf`.`datast`,   " & vbCrLf
		lstrSql = lstrSql & "       `nf`.`datavenc`, " & vbCrLf
		lstrSql = lstrSql & "       `nf`.`cons_id`,  " & vbCrLf
		lstrSql = lstrSql & "       `nf`.`unid_id`,  " & vbCrLf
		lstrSql = lstrSql & "       `nf`.`numnf`,    " & vbCrLf
		lstrSql = lstrSql & "       `nf`.`mesano`,   " & vbCrLf
		lstrSql = lstrSql & "       `nf`.`banarrec`, " & vbCrLf
		lstrSql = lstrSql & "       `nf`.`valorliq`, " & vbCrLf
		lstrSql = lstrSql & "       `nf`.`valortot`,  " & vbCrLf
		lstrSql = lstrSql & "       `nf`.`motivopgto` " & vbCrLf
		lstrSql = lstrSql & "  FROM `nf` " & vbCrLf
		lstrSql = lstrSql & " WHERE `nf`.`datapag` = '" & VB6.Format(Me.dtpPagamento.value, "yyyy-MM-dd") & "' " & vbCrLf
		lstrSql = lstrSql & "   AND `nf`.`banarrec` = '" & VB6.GetItemData(Me.cmbBancos, Me.cmbBancos.SelectedIndex) & "' "
		lstrSql = lstrSql & "   AND `nf`.`motivopgto` IS NOT NULL "
		lstrSql = lstrSql & "   AND `nf`.`flgst` = 'P' "
		If IsNumeric(Me.txtFatura.Text) Then
			lstrSql = lstrSql & "   AND `nf`.`numnf` = " & CDbl(Me.txtFatura.Text)
			lstrSql = lstrSql & "   AND `nf`.`mesano` = '" & Me.txtMesAno.Text & "' "
		End If
		Call Conectar(lstrSql, lrstAux)
		With lrstAux
			If .State = ADODB.ObjectStateEnum.adStateOpen Then
				If .RecordCount > 0 Then
					While Not .EOF
						'UPGRADE_WARNING: Use of Null/IsNull() detected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="2EED02CB-5C0E-4DC1-AE94-4FAA3A30F51A"'
						lstrMotivo = IIf(IsDbNull(.Fields("motivopgto").value), "", .Fields("motivopgto").value)
						'UPGRADE_WARNING: Use of Null/IsNull() detected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="2EED02CB-5C0E-4DC1-AE94-4FAA3A30F51A"'
						lstrZona = IIf(IsDbNull(.Fields("zona").value), "", .Fields("zona").value)
						'UPGRADE_WARNING: Use of Null/IsNull() detected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="2EED02CB-5C0E-4DC1-AE94-4FAA3A30F51A"'
						lstrLivro = IIf(IsDbNull(.Fields("livro").value), "", .Fields("livro").value)
						'UPGRADE_WARNING: Use of Null/IsNull() detected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="2EED02CB-5C0E-4DC1-AE94-4FAA3A30F51A"'
						lstrConta = IIf(IsDbNull(.Fields("conta").value), "", .Fields("conta").value)
						lstrFlgst = "Baixada"
						'UPGRADE_WARNING: Use of Null/IsNull() detected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="2EED02CB-5C0E-4DC1-AE94-4FAA3A30F51A"'
						ldtePagamento = IIf(IsDbNull(.Fields("datapag").value), "1900-01-01", .Fields("datapag").value)
						'UPGRADE_WARNING: Use of Null/IsNull() detected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="2EED02CB-5C0E-4DC1-AE94-4FAA3A30F51A"'
						ldteSituacao = IIf(IsDbNull(.Fields("datast").value), "1900-01-01", .Fields("datast").value)
						'UPGRADE_WARNING: Use of Null/IsNull() detected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="2EED02CB-5C0E-4DC1-AE94-4FAA3A30F51A"'
						ldteVencimento = IIf(IsDbNull(.Fields("datavenc").value), "1900-01-01", .Fields("datavenc").value)
						'UPGRADE_WARNING: Use of Null/IsNull() detected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="2EED02CB-5C0E-4DC1-AE94-4FAA3A30F51A"'
						ldblNumNf = IIf(IsDbNull(.Fields("numnf").value), 0, .Fields("numnf").value)
						'UPGRADE_WARNING: Use of Null/IsNull() detected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="2EED02CB-5C0E-4DC1-AE94-4FAA3A30F51A"'
						lstrMesAno = IIf(IsDbNull(.Fields("mesano").value), "", .Fields("mesano").value)
						'UPGRADE_WARNING: Use of Null/IsNull() detected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="2EED02CB-5C0E-4DC1-AE94-4FAA3A30F51A"'
						ldblLiquido = IIf(IsDbNull(.Fields("valorliq").value), 0, .Fields("valorliq").value)
						If ldblLiquido <= 0 Then
							'UPGRADE_WARNING: Use of Null/IsNull() detected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="2EED02CB-5C0E-4DC1-AE94-4FAA3A30F51A"'
							ldblLiquido = IIf(IsDbNull(.Fields("valortot").value), 0, .Fields("valortot").value)
						End If
						Call AdicionaItensGrid(mfgReimprimir, lstrMotivo, lstrMesAno, ldblNumNf, ldblLiquido, ldteVencimento, Me.dtpPagamento.value, (lstrZona & "." & lstrLivro & "." & lstrConta), lstrFlgst, "N", 0, 0)
						llngTotReg = llngTotReg + 1
						ldblTotVlr = ldblTotVlr + ldblLiquido
						Call .MoveNext()
					End While
					Call Imprime((Me.mfgReimprimir), llngTotReg, ldblTotVlr)
				Else
					Call MsgBox("Não existe faturas baixadas no dia " & VB6.Format(Me.dtpPagamento.value, "dd/mm/yyyy") & ", para o banco " & VB6.GetItemString(Me.cmbBancos, Me.cmbBancos.SelectedIndex) & "!", MsgBoxStyle.Information, gstrTituloMensagem)
				End If
				Call .Close()
			End If
		End With
		'UPGRADE_NOTE: Object lrstAux may not be destroyed until it is garbage collected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6E35BFF6-CD74-4B09-9689-3E1A43DF8969"'
		lrstAux = Nothing
	End Sub
	
	Private Sub frmRecMan_Load(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles MyBase.Load
		'-------------------------------
		Call CarregaTabelaComboBox((Me.cmbBancos), "`bancos`", "CONCAT(RIGHT(CONCAT('000',`nrbco`),3),' - ',RIGHT(CONCAT('00000',`nrag`),5),' : ' , `nmbco`)", "`ban_id`", "`nrbco` ASC, `ban_id` ASC ",  , 0, " `tpmovto` <> 'D'")
		'-------------------------------
		Call MontaGrid(Me.mfgDados)
		Call MontaGrid(Me.mfgReimprimir)
		Call SetaCamposRecMan()
		'-------------------------------
		Call opbCodBarras_CheckedChanged(opbCodBarras, New System.EventArgs())
		Call CarregaTabelaComboBox((Me.cmbUsuario), "`usuarios`", "`usuario`", "`id`", "`usuario` ASC LIMIT 0, 1",  , 0, "`recman` = 1")
		iblnReImp = False
	End Sub
	
	Private Sub frmRecMan_KeyPress(ByVal eventSender As System.Object, ByVal eventArgs As System.Windows.Forms.KeyPressEventArgs) Handles MyBase.KeyPress
		Dim KeyAscii As Short = Asc(eventArgs.KeyChar)
		Dim lstrCampo As String
		
		'UPGRADE_ISSUE: Control Name could not be resolved because it was within the generic namespace ActiveControl. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="084D22AD-ECB1-400F-B4C7-418ECEC5E36E"'
		lstrCampo = VB6.GetActiveControl().Name
		Select Case lstrCampo
			Case "txtBarra", "txtFatura", "txtMesAno"
				Call ControleTecla(KeyAscii, "N")
			Case Else
				Call ControleTecla(KeyAscii, "A")
		End Select
		eventArgs.KeyChar = Chr(KeyAscii)
		If KeyAscii = 0 Then
			eventArgs.Handled = True
		End If
	End Sub
	
	Private Sub frmRecMan_KeyUp(ByVal eventSender As System.Object, ByVal eventArgs As System.Windows.Forms.KeyEventArgs) Handles MyBase.KeyUp
		Dim KeyCode As Short = eventArgs.KeyCode
		Dim Shift As Short = eventArgs.KeyData \ &H10000
		Dim lstrCampo As String
		
		If KeyCode = System.Windows.Forms.Keys.Return Or KeyCode = System.Windows.Forms.Keys.ShiftKey Or KeyCode = System.Windows.Forms.Keys.Tab Then
			'UPGRADE_ISSUE: Control Name could not be resolved because it was within the generic namespace ActiveControl. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="084D22AD-ECB1-400F-B4C7-418ECEC5E36E"'
			lstrCampo = VB6.GetActiveControl().Name
			Select Case lstrCampo
				Case "txtBarra", "txtFatura", "txtMesAno"
					Call SelTodoCampo(VB6.GetActiveControl(), True)
			End Select
		End If
	End Sub
	
	'UPGRADE_WARNING: Event opbCodBarras.CheckedChanged may fire when form is initialized. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="88B12AE1-6DE0-48A0-86F1-60C0686C026A"'
	Private Sub opbCodBarras_CheckedChanged(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles opbCodBarras.CheckedChanged
		If eventSender.Checked Then
			Call LigDesCampos()
		End If
	End Sub
	
	'UPGRADE_WARNING: Event opbFaturas.CheckedChanged may fire when form is initialized. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="88B12AE1-6DE0-48A0-86F1-60C0686C026A"'
	Private Sub opbFaturas_CheckedChanged(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles opbFaturas.CheckedChanged
		If eventSender.Checked Then
			Call LigDesCampos()
		End If
	End Sub
	
	Private Sub txtMesAno_Leave(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles txtMesAno.Leave
		Me.txtMesAno.Text = ValidaMesAno(Me.txtMesAno.Text)
		If Len(Trim(Me.txtMesAno.Text)) < 1 Then
			Call MsgBox("Mês/ano inválidos!", MsgBoxStyle.Exclamation, gstrTituloMensagem)
			Call Me.txtMesAno.Focus()
		End If
	End Sub
	
	Private Sub cmdReceber_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles cmdReceber.Click
		Dim lstrSql As String
		Dim lrstAux As ADODB.Recordset
		Dim ldblNumNf As Double
		Dim lstrMesAno As String
		Dim lstrGrTar As String
		Dim lstrZona As String
		Dim lstrLivro As String
		Dim lstrConta As String
		Dim ldblLiquido As Double
		Dim ldtePagamento As Date
		Dim ldteSituacao As Date
		Dim ldteVencimento As Date
		Dim llngConsId As Integer
		Dim llngUnidId As Integer
		Dim llngBanco As Integer
		Dim lstrNome As String
		Dim lblnBaixarNf As Boolean
		
		lrstAux = New ADODB.Recordset
		If Me.opbCodBarras.Checked Then
			If Len(Trim(Me.txtBarra.Text)) < 1 Then
				Call MsgBox("Código de barra está em branco!", MsgBoxStyle.Exclamation, gstrTituloMensagem)
				Call Me.txtBarra.Focus()
			Else
				ldblNumNf = CDbl(ChecaCodBar("numnf", Me.txtBarra.Text))
				lstrMesAno = ChecaCodBar("mesano", Me.txtBarra.Text)
			End If
		Else
			If Len(Trim(Me.txtFatura.Text)) < 1 Then
				Call MsgBox("O número da fatura está em branco!", MsgBoxStyle.Information, gstrTituloMensagem)
				Call Me.txtFatura.Focus()
			ElseIf Len(Trim(Me.txtMesAno.Text)) < 1 Then 
				Call MsgBox("O mês e ano está em branco!", MsgBoxStyle.Information, gstrTituloMensagem)
				Call Me.txtMesAno.Focus()
			Else
				ldblNumNf = CDbl(Me.txtFatura.Text)
				lstrMesAno = Me.txtMesAno.Text
			End If
		End If
		istrFlgst = ""
		If ldblNumNf > 0 And Len(Trim(lstrMesAno)) > 0 Then
			lstrSql = ""
			lstrSql = lstrSql & "SELECT `nf`.`zona`,     " & vbCrLf
			lstrSql = lstrSql & "       `nf`.`livro`,    " & vbCrLf
			lstrSql = lstrSql & "       `nf`.`conta`,    " & vbCrLf
			lstrSql = lstrSql & "       `nf`.`ta`,       " & vbCrLf
			lstrSql = lstrSql & "       `nf`.`flgst`,    " & vbCrLf
			lstrSql = lstrSql & "       `nf`.`datapag`,  " & vbCrLf
			lstrSql = lstrSql & "       `nf`.`datast`,   " & vbCrLf
			lstrSql = lstrSql & "       `nf`.`datavenc`, " & vbCrLf
			lstrSql = lstrSql & "       `nf`.`cons_id`,  " & vbCrLf
			lstrSql = lstrSql & "       `nf`.`unid_id`,  " & vbCrLf
			lstrSql = lstrSql & "       `nf`.`numnf`,    " & vbCrLf
			lstrSql = lstrSql & "       `nf`.`mesano`,   " & vbCrLf
			lstrSql = lstrSql & "       `nf`.`banarrec`, " & vbCrLf
			lstrSql = lstrSql & "       `nf`.`valorliq`, " & vbCrLf
			lstrSql = lstrSql & "       `nf`.`valortot`  " & vbCrLf
			lstrSql = lstrSql & "  FROM `nf` " & vbCrLf
			lstrSql = lstrSql & " WHERE `nf`.`numnf`  = " & ldblNumNf & " " & vbCrLf
			lstrSql = lstrSql & "   AND `nf`.`mesano` = '" & lstrMesAno & "' "
			Call Conectar(lstrSql, lrstAux)
			With lrstAux
				If .RecordCount > 0 Then
					'UPGRADE_WARNING: Use of Null/IsNull() detected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="2EED02CB-5C0E-4DC1-AE94-4FAA3A30F51A"'
					lstrZona = IIf(IsDbNull(.Fields("zona").value), "", .Fields("zona").value)
					'UPGRADE_WARNING: Use of Null/IsNull() detected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="2EED02CB-5C0E-4DC1-AE94-4FAA3A30F51A"'
					lstrLivro = IIf(IsDbNull(.Fields("livro").value), "", .Fields("livro").value)
					'UPGRADE_WARNING: Use of Null/IsNull() detected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="2EED02CB-5C0E-4DC1-AE94-4FAA3A30F51A"'
					lstrConta = IIf(IsDbNull(.Fields("conta").value), "", .Fields("conta").value)
					lblnBaixarNf = VericaPermiteUnidade(lstrZona, lstrLivro, lstrConta)
					'UPGRADE_WARNING: Use of Null/IsNull() detected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="2EED02CB-5C0E-4DC1-AE94-4FAA3A30F51A"'
					lstrGrTar = Mid(IIf(IsDbNull(.Fields("ta").value), "01B", .Fields("ta").value), 3, 1)
					'UPGRADE_WARNING: Use of Null/IsNull() detected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="2EED02CB-5C0E-4DC1-AE94-4FAA3A30F51A"'
					istrFlgst = UCase(IIf(IsDbNull(.Fields("flgst").value), "", .Fields("flgst").value))
					'UPGRADE_WARNING: Use of Null/IsNull() detected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="2EED02CB-5C0E-4DC1-AE94-4FAA3A30F51A"'
					ldtePagamento = IIf(IsDbNull(.Fields("datapag").value), "1900-01-01", .Fields("datapag").value)
					'UPGRADE_WARNING: Use of Null/IsNull() detected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="2EED02CB-5C0E-4DC1-AE94-4FAA3A30F51A"'
					ldteSituacao = IIf(IsDbNull(.Fields("datast").value), "1900-01-01", .Fields("datast").value)
					'UPGRADE_WARNING: Use of Null/IsNull() detected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="2EED02CB-5C0E-4DC1-AE94-4FAA3A30F51A"'
					ldteVencimento = IIf(IsDbNull(.Fields("datavenc").value), "1900-01-01", .Fields("datavenc").value)
					'UPGRADE_WARNING: Use of Null/IsNull() detected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="2EED02CB-5C0E-4DC1-AE94-4FAA3A30F51A"'
					llngConsId = IIf(IsDbNull(.Fields("cons_id").value), 0, .Fields("cons_id").value)
					'UPGRADE_WARNING: Use of Null/IsNull() detected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="2EED02CB-5C0E-4DC1-AE94-4FAA3A30F51A"'
					llngUnidId = IIf(IsDbNull(.Fields("unid_id").value), 0, .Fields("unid_id").value)
					'UPGRADE_WARNING: Use of Null/IsNull() detected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="2EED02CB-5C0E-4DC1-AE94-4FAA3A30F51A"'
					ldblNumNf = IIf(IsDbNull(.Fields("numnf").value), 0, .Fields("numnf").value)
					'UPGRADE_WARNING: Use of Null/IsNull() detected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="2EED02CB-5C0E-4DC1-AE94-4FAA3A30F51A"'
					lstrMesAno = IIf(IsDbNull(.Fields("mesano").value), "", .Fields("mesano").value)
					'UPGRADE_WARNING: Use of Null/IsNull() detected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="2EED02CB-5C0E-4DC1-AE94-4FAA3A30F51A"'
					llngBanco = IIf(IsDbNull(.Fields("banarrec").value), 0, .Fields("banarrec").value)
					'UPGRADE_WARNING: Use of Null/IsNull() detected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="2EED02CB-5C0E-4DC1-AE94-4FAA3A30F51A"'
					ldblLiquido = IIf(IsDbNull(.Fields("valorliq").value), 0, .Fields("valorliq").value)
					If ldblLiquido <= 0 Then
						'UPGRADE_WARNING: Use of Null/IsNull() detected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="2EED02CB-5C0E-4DC1-AE94-4FAA3A30F51A"'
						ldblLiquido = IIf(IsDbNull(.Fields("valortot").value), 0, .Fields("valortot").value)
					End If
					lstrNome = BuscaNomeUnidade(llngUnidId, llngConsId, lstrGrTar)
					If Len(lstrNome) = 0 Then
						lstrNome = BuscaNomeConsumidor(llngConsId)
					End If
					Me.txtNf.Text = CStr(ldblNumNf)
					Me.txtMAno.Text = lstrMesAno
					Me.txtZLC.Text = lstrZona & "." & lstrLivro & "." & lstrConta
					Me.txtValor.Text = VB6.Format(ldblLiquido, "#,##0.00")
					Me.txtVenc.Text = VB6.Format(ldteVencimento, "dd/mm/yyyy")
					Me.txtNome.Text = lstrNome
					Me.txtConsId.Text = CStr(llngConsId)
					Me.txtUnidId.Text = CStr(llngUnidId)
				Else
					'
				End If
				If .State = 1 Then Call .Close()
			End With
			'UPGRADE_NOTE: Object lrstAux may not be destroyed until it is garbage collected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6E35BFF6-CD74-4B09-9689-3E1A43DF8969"'
			lrstAux = Nothing
			'If istrFlgst <> "P" Then
			If istrFlgst <> "C" Then
				'If ldtePagamento = "1900-01-01" Then
				If Me.txtValor.Text <> "" And Val(Me.txtValor.Text) > 0 Then
					If istrFlgst = "P" Or ldtePagamento <> CDate("1900-01-01") Then
						Call MsgBox("Esta fatura já foi paga em " & VB6.Format(ldtePagamento, "dd/mm/yyyy") & "!" & vbCrLf & "Se você clicar em baixar será gerado uma duplicidade.", MsgBoxStyle.Exclamation, gstrTituloMensagem)
					End If
					If Not PesqFatura Then
						'Controla o motivo de baixa não autorizada
						If lblnBaixarNf = False Then
							'If not gblnUsuario_RecMan Then
							With Me.fmeSenha
								.Left = VB6.TwipsToPixelsX(3300)
								.Top = VB6.TwipsToPixelsY(2200)
								.Visible = True
								.Enabled = True
								Call LigDesFrames(Not .Enabled)
								'Call Me.cmbUsuario.SetFocus
								Call Me.txtSenha.Focus()
							End With
							'End If
						Else
							Call AdicionaItensGrid(mfgDados, "BAIXA MANUAL NORMAL", Me.txtMesAno.Text, CDbl(Me.txtNf.Text), CDbl(Me.txtValor.Text), CDate(Me.txtVenc.Text), Me.dtpPagamento.value, Me.txtZLC.Text, istrFlgst, "S", IIf(IsNumeric(Me.txtConsId.Text), Me.txtConsId.Text, 0), IIf(IsNumeric(Me.txtUnidId.Text), Me.txtUnidId.Text, 0))
						End If
					Else
						Call MsgBox("Esta fatura já foi inserida e está na lista!", MsgBoxStyle.Exclamation, gstrTituloMensagem)
					End If
				End If
				'Else
				'  Call MsgBox("Esta fatura já foi paga em " & Format(ldtePagamento, "dd/mm/yyyy") & "!", vbExclamation, gstrTituloMensagem)
				'End If
			Else
				Call MsgBox("Esta fatura foi cancelada!", MsgBoxStyle.Exclamation, gstrTituloMensagem)
			End If
			'Else
			'  Call MsgBox("Esta fatura já foi paga em " & Format(ldtePagamento, "dd/mm/yyyy") & "!", vbExclamation, gstrTituloMensagem)
			'End If
		Else
			Call MsgBox("Número da fatura ou do código de barras é inválido!", MsgBoxStyle.Exclamation, gstrTituloMensagem)
		End If
	End Sub
	
	Private Sub AdicionaItensGrid(ByRef amfgAux As AxMSFlexGridLib.AxMSFlexGrid, ByVal astrMotivo As String, ByVal astrMesAno As String, ByVal adblNumNf As Double, ByVal adblValor As Double, ByVal adteVenc As Date, ByVal adtePgto As Date, ByVal astrZLC As String, ByVal astrFlg As String, ByVal astrTipo As String, ByVal alngConsId As Integer, ByVal alngUnidId As Integer)
		With amfgAux
			.Rows = .Rows + 1
			.set_TextMatrix(.Rows - 1, 0, astrMesAno)
			.set_TextMatrix(.Rows - 1, 1, adblNumNf)
			.set_TextMatrix(.Rows - 1, 2, VB6.Format(adblValor, "#,##0.00"))
			.set_TextMatrix(.Rows - 1, 3, adteVenc)
			.set_TextMatrix(.Rows - 1, 4, adtePgto)
			.set_TextMatrix(.Rows - 1, 5, astrZLC)
			.set_TextMatrix(.Rows - 1, 6, astrFlg)
			.set_TextMatrix(.Rows - 1, 7, astrMotivo)
			.set_TextMatrix(.Rows - 1, 8, alngConsId)
			.set_TextMatrix(.Rows - 1, 9, alngUnidId)
		End With
		If astrTipo = "S" Then
			Me.txtTotReg.Text = CStr(amfgAux.Rows - 1)
			Me.txtValTot.Text = VB6.Format(CDbl(IIf(IsNumeric(Me.txtValTot.Text), Me.txtValTot.Text, 0)) + CDbl(IIf(IsNumeric(Me.txtValor.Text), Me.txtValor.Text, 0)), "#,##0.00")
			Call Me.txtValTot.Refresh()
			Call Me.txtTotReg.Refresh()
			Call VerificaGrade(amfgAux)
			If Me.opbCodBarras.Checked Then
				Call Me.txtBarra.Focus()
			ElseIf Me.opbFaturas.Checked Then 
				Call Me.txtFatura.Focus()
			End If
		End If
	End Sub
	
	Private Function PesqFatura() As Boolean
		'Pesquisa a fatura se ja existe lançada na grid
		Dim llngLinha As Integer
		
		PesqFatura = False
		With Me.mfgDados
			For llngLinha = 1 To .Rows
				If (.get_TextMatrix(llngLinha - 1, 1) = Me.txtNf.Text) And (.get_TextMatrix(llngLinha - 1, 0) = Me.txtMesAno.Text) Then
					PesqFatura = True
					llngLinha = .Rows
				End If
			Next llngLinha
		End With
	End Function
	
	Private Sub VerificaGrade(ByRef amfgAux As AxMSFlexGridLib.AxMSFlexGrid)
		With amfgAux
			Me.dtpPagamento.Enabled = Not .Rows > 1
			Me.cmbBancos.Enabled = Not .Rows > 1
			Me.cmbBancos.BackColor = System.Drawing.ColorTranslator.FromOle(IIf(.Rows > 1, &H8000000F, &H80000005))
		End With
		Call SetaCamposRecMan()
	End Sub
	
	Private Sub cmdDel_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles cmdDel.Click
		With Me.mfgDados
			If .RowSel > 0 Then
				If .Rows > 2 Then
					Me.txtValTot.Text = CStr(CDbl(Me.txtValTot.Text) - CDbl(.get_TextMatrix(.RowSel, 2)))
					Call .RemoveItem(.RowSel)
				Else
					Me.txtValTot.Text = CStr(0)
					.Rows = 1
				End If
			End If
			Me.txtTotReg.Text = CStr(.Rows - 1)
		End With
		Call VerificaGrade(mfgDados)
		If Me.opbCodBarras.Checked Then
			Call Me.txtBarra.Focus()
		ElseIf Me.opbFaturas.Checked Then 
			Call Me.txtFatura.Focus()
		End If
	End Sub
	
	Private Sub cmdImp_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles cmdImp.Click
		iblnReImp = False
		If ValidaBaixa((Me.mfgDados)) Then
			Call Imprime((Me.mfgDados), CInt(Me.txtTotReg.Text), CDbl(Me.txtValTot.Text))
		Else
			Call MsgBox("Foi encontrato problema nas baixas, favor verificar as faturas", MsgBoxStyle.Information, gstrTituloMensagem)
		End If
	End Sub
	
	Private Function CabecaRel(ByVal vsCab As AxVSVIEW6.AxVSPrinter) As Object
		Dim lintCol As Short
		Dim llngLin As Integer
		Dim lstrTemp As String
		Dim lstrAli As String
		
		Call Cabecalho_Relatorio(vsCab, "Recebimento manual", istrNmBco, CStr(3), True, "Pagamento efetuado em:" & VB6.Format(Me.dtpPagamento.value, "dd/mm/yyyy"))
		Call LineFeed(vsCab, 3)
		vsCab.Font = VB6.FontChangeSize(vsCab.Font, 8)
		vsCab.Font = VB6.FontChangeBold(vsCab.Font, True)
		'Determina o tamanho das colunas de acordo com o tamanho da celula da grade
		lstrTemp = "<5mm"
		If Not iblnReImp Then
			With Me.mfgDados
				For lintCol = 0 To .Cols - 3
					If .get_ColAlignment(lintCol) = MSFlexGridLib.AlignmentSettings.flexAlignCenterCenter Then
						lstrAli = "^"
					ElseIf .get_ColAlignment(lintCol) = MSFlexGridLib.AlignmentSettings.flexAlignRightCenter Then 
						lstrAli = ">"
					Else
						lstrAli = "<"
					End If
					lstrTemp = lstrTemp & "|" & lstrAli & "" & Int(((.get_ColWidth(lintCol) - 240) / 100) * 2.8) & "mm"
				Next lintCol
				'Coloca o cabeçalho das informações das colunas de acordo com o cabeçalho da grade
				lstrTemp = lstrTemp & ";"
				For lintCol = 0 To .Cols - 3
					lstrTemp = lstrTemp & "|" & .get_TextMatrix(0, lintCol) & ""
				Next lintCol
			End With
		Else
			With Me.mfgReimprimir
				For lintCol = 0 To .Cols - 3
					If .get_ColAlignment(lintCol) = MSFlexGridLib.AlignmentSettings.flexAlignCenterCenter Then
						lstrAli = "^"
					ElseIf .get_ColAlignment(lintCol) = MSFlexGridLib.AlignmentSettings.flexAlignRightCenter Then 
						lstrAli = ">"
					Else
						lstrAli = "<"
					End If
					lstrTemp = lstrTemp & "|" & lstrAli & "" & Int(((.get_ColWidth(lintCol) - 240) / 100) * 2.8) & "mm"
				Next lintCol
				'Coloca o cabeçalho das informações das colunas de acordo com o cabeçalho da grade
				lstrTemp = lstrTemp & ";"
				For lintCol = 0 To .Cols - 3
					lstrTemp = lstrTemp & "|" & .get_TextMatrix(0, lintCol) & ""
				Next lintCol
			End With
		End If
		vsCab.Table = lstrTemp
	End Function
	
	Private Sub cmdSalvar_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles cmdSalvar.Click
		Dim lstrSql As String
		Dim lintPos As Short
		Dim llngLin As Integer
		Dim lstrZLC As String
		Dim lstrZon As String
		Dim lstrLiv As String
		Dim lstrCon As String
		Dim ldblNNf As Double
		Dim lstrMAn As String
		Dim ldblVlr As Double
		Dim ldtePgo As Date
		Dim lstrFlg As String
		Dim lstrMot As String
		Dim llngBId As Integer
		Dim lstrBNm As String
		Dim llngCon As Integer
		
		Dim llngCId As Integer
		Dim llngUid As Integer
		
		Dim ldteIni As Date
		Dim ldteFim As Date
		
		On Error GoTo ErroBaixar
		ldteIni = BuscaDataBD
		ldteIni = System.Date.FromOADate(CDate(UltimoDiaMes(Month(ldteIni), Year(ldteIni)) & "/" & VB6.Format(ldteIni, "mm/yyyy")).ToOADate + 1)
		ldteFim = CDate(UltimoDiaMes(Month(ldteIni), Year(ldteIni)) & "/" & VB6.Format(ldteIni, "mm/yyyy"))
		
		Me.cmdDel.Enabled = False
		Me.cmdImp.Enabled = False
		Me.cmdSalvar.Enabled = False
		Me.cmdFechar.Enabled = False
		Me.cmdReceber.Enabled = False
		System.Windows.Forms.Application.DoEvents()
		llngBId = VB6.GetItemData(Me.cmbBancos, Me.cmbBancos.SelectedIndex)
		lintPos = InStr(1, VB6.GetItemString(Me.cmbBancos, Me.cmbBancos.SelectedIndex), ":")
		lstrBNm = Trim(Mid(VB6.GetItemString(Me.cmbBancos, Me.cmbBancos.SelectedIndex), lintPos + 1, Len(VB6.GetItemString(Me.cmbBancos, Me.cmbBancos.SelectedIndex)) - lintPos))
		Call myConC.Execute("START TRANSACTION")
		With Me.mfgDados
			For llngLin = 1 To .Rows - 1
				lstrMAn = .get_TextMatrix(llngLin, 0)
				ldblNNf = CDbl(.get_TextMatrix(llngLin, 1))
				ldblVlr = CDbl(.get_TextMatrix(llngLin, 2))
				ldtePgo = CDate(.get_TextMatrix(llngLin, 4))
				lstrZLC = Replace(.get_TextMatrix(llngLin, 5), ".", "")
				lstrZon = VB.Left(lstrZLC, 3)
				lstrLiv = Mid(lstrZLC, 4, 2)
				lstrCon = VB.Right(lstrZLC, 6)
				lstrFlg = .get_TextMatrix(llngLin, 6)
				lstrMot = .get_TextMatrix(llngLin, 7)
				llngCId = IIf(IsNumeric(.get_TextMatrix(llngLin, 8)), .get_TextMatrix(llngLin, 8), 0)
				llngUid = IIf(IsNumeric(.get_TextMatrix(llngLin, 9)), .get_TextMatrix(llngLin, 9), 0)
				If lstrFlg = "P" Then
					Call InsereDevolucao(ldblNNf, lstrMAn, lstrZon, lstrLiv, lstrCon, llngCId, llngUid, ldtePgo, ldblVlr, ldteIni, ldteFim)
					'        If ExisteDevolucao(ldblNnf, lstrMAn) = False Then
					'          lstrSql = ""
					'          lstrSql = lstrSql & "INSERT INTO `devolucao` " & vbCrLf
					'          lstrSql = lstrSql & "        SET `nf`        = " & ldblNnf & ", " & vbCrLf
					'          lstrSql = lstrSql & "            `mesano`    = '" & lstrMAn & "', " & vbCrLf
					'          lstrSql = lstrSql & "            `dataemis`  = '" & Format(BuscaDataBD, "yyyy-MM-dd") & "', " & vbCrLf
					'          lstrSql = lstrSql & "            `datadevol` = NULL, " & vbCrLf
					'          lstrSql = lstrSql & "            `valor`     = " & Replace(ldblVlr, ",", ".") & ", " & vbCrLf
					'          lstrSql = lstrSql & "            `banarrec`  = " & llngBId & ", " & vbCrLf
					'          lstrSql = lstrSql & "            `estado`    = NULL, " & vbCrLf
					'          lstrSql = lstrSql & "            `regnum`    = last_insert_id() "
					'          Call myConC.Execute(lstrSql)
					'        End If
					'        Me.mfgDados.TextMatrix(llngLin, 6) = "Devolução"
					lstrSql = ""
					lstrSql = lstrSql & "UPDATE `nf` " & vbCrLf
					lstrSql = lstrSql & "   SET `motivopgto` = '" & lstrMot & "' " & vbCrLf
					lstrSql = lstrSql & " WHERE `nf`.`numnf`  = " & ldblNNf & vbCrLf
					lstrSql = lstrSql & "   AND `nf`.`mesano` = '" & lstrMAn & "' " & vbCrLf
					Call myConC.Execute(lstrSql)
				Else
					lstrSql = ""
					lstrSql = lstrSql & "UPDATE `nf` " & vbCrLf
					lstrSql = lstrSql & "   SET `flgst`      = 'P', " & vbCrLf
					lstrSql = lstrSql & "       `datapag`    = '" & VB6.Format(ldtePgo, "yyyy-MM-dd") & "', " & vbCrLf
					lstrSql = lstrSql & "       `banarrec`   = " & llngBId & ", " & vbCrLf
					lstrSql = lstrSql & "       `banident`   = '" & lstrBNm & "', " & vbCrLf
					lstrSql = lstrSql & "       `motivopgto` = '" & lstrMot & "' " & vbCrLf
					lstrSql = lstrSql & " WHERE `nf`.`numnf`  = " & ldblNNf & vbCrLf
					lstrSql = lstrSql & "   AND `nf`.`mesano` = '" & lstrMAn & "' " & vbCrLf
					lstrSql = lstrSql & "   AND `nf`.`flgst` <> 'P' "
					Call myConC.Execute(lstrSql)
					lstrSql = ""
					lstrSql = lstrSql & "UPDATE `concorte` " & vbCrLf
					lstrSql = lstrSql & "   SET `sit`     = 'P', " & vbCrLf
					lstrSql = lstrSql & "       `datapag` = '" & VB6.Format(ldtePgo, "yyyy-MM-dd") & "' " & vbCrLf
					lstrSql = lstrSql & " WHERE `concorte`.`numnf`  = " & ldblNNf & vbCrLf
					lstrSql = lstrSql & "   AND `concorte`.`mesano` = '" & lstrMAn & "' "
					Call myConC.Execute(lstrSql)
					Me.mfgDados.set_TextMatrix(llngLin, 6, "Baixada")
					For llngCon = 0 To 11
						lstrSql = ""
						lstrSql = lstrSql & "UPDATE `consumos` SET " & vbCrLf
						lstrSql = lstrSql & "       `datapag" & llngCon & "` = '" & VB6.Format(ldtePgo, "yyyy-MM-dd") & "', " & vbCrLf
						lstrSql = lstrSql & "       `valor" & llngCon & "` = " & Replace(CStr(ldblVlr), ",", ".") & " " & vbCrLf
						lstrSql = lstrSql & " WHERE CONCAT(`zona`,`livro`,`conta`) = '" & lstrZLC & "' " & vbCrLf
						lstrSql = lstrSql & "   AND `mesano" & llngCon & "` = '" & lstrMAn & "' "
						Call myConC.Execute(lstrSql)
					Next llngCon
				End If
			Next llngLin
		End With
		Call myConC.Execute("COMMIT")
		Me.cmdDel.Enabled = True
		Me.cmdImp.Enabled = True
		Me.cmdSalvar.Enabled = True
		Me.cmdFechar.Enabled = True
		Me.cmdReceber.Enabled = True
		System.Windows.Forms.Application.DoEvents()
		If MsgBox("Deseja imprimir?", MsgBoxStyle.YesNo, gstrTituloMensagem) = MsgBoxResult.Yes Then
			Call cmdImp_Click(cmdImp, New System.EventArgs())
		End If
		Call MontaGrid(Me.mfgDados)
		Call MontaGrid(Me.mfgReimprimir)
		Call SetaCamposRecMan()
ErroBaixar: 
		If myConC.Errors.Count > 0 Then
			Call MsgBox("Código: " & myConC.Errors.Item(myConC.Errors.Count - 1).NativeError & vbCrLf & "Descrição:" & myConC.Errors.Item(myConC.Errors.Count - 1).Description, MsgBoxStyle.Critical, gstrTituloMensagem)
			Call myConC.Execute("ROLLBACK")
			Call MsgBox("Não foi possível realizar a baixa, tente novamente", MsgBoxStyle.Information, gstrTituloMensagem)
		ElseIf Err.Number > 0 Then 
			Call MsgBox(Err.Number & " - " & GetErrosVB(Err.Number, Err.Description), MsgBoxStyle.Information, gstrTituloMensagem)
			Call myConC.Execute("ROLLBACK")
			Call MsgBox("Não foi possível realizar a baixa, tente novamente", MsgBoxStyle.Information, gstrTituloMensagem)
		End If
		Me.cmdDel.Enabled = True
		Me.cmdImp.Enabled = True
		Me.cmdSalvar.Enabled = True
		Me.cmdFechar.Enabled = True
		Me.cmdReceber.Enabled = True
	End Sub
	
	Private Function ExisteDevolucao(ByVal adblNumNf As Double, ByVal astrMesAno As String) As Boolean
		Dim lblnRet As Boolean
		Dim lstrSql As String
		Dim lrstAux As ADODB.Recordset
		lrstAux = New ADODB.Recordset
		lblnRet = False
		lstrSql = ""
		lstrSql = lstrSql & "SELECT * " & vbCrLf
		lstrSql = lstrSql & "  FROM `devolucao` " & vbCrLf
		lstrSql = lstrSql & " WHERE `devolucao`.`nf`     = " & adblNumNf & " " & vbCrLf
		lstrSql = lstrSql & "   AND `devolucao`.`mesano` = '" & astrMesAno & "' " & vbCrLf
		lstrSql = lstrSql & " LIMIT 0, 1 "
		Call Conectar(lstrSql, lrstAux)
		With lrstAux
			If .State = ADODB.ObjectStateEnum.adStateOpen Then
				lblnRet = (.RecordCount > 0)
				Call .Close()
			End If
		End With
		'UPGRADE_NOTE: Object lrstAux may not be destroyed until it is garbage collected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6E35BFF6-CD74-4B09-9689-3E1A43DF8969"'
		lrstAux = Nothing
		ExisteDevolucao = lblnRet
	End Function
	
	Private Sub cmdFechar_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles cmdFechar.Click
		If Me.mfgDados.Rows > 1 Then
			If MsgBox("Tem certeza de que deseja sair do recebimento manual sem salvar?", MsgBoxStyle.YesNo + MsgBoxStyle.Question, gstrTituloMensagem) = MsgBoxResult.Yes Then
				Call Me.Close()
			End If
		Else
			Call Me.Close()
		End If
	End Sub
	
	Private Function ChecaCodBar(ByVal astrParte As String, ByVal astrCodBar As String) As String
		Dim lintPos(4) As Short
		Dim lintQtd(4) As Short
		Dim llngAux As Integer
		Dim lstrTipo As String
		
		llngAux = Val(VB.Left(VB.Right(Mid(astrCodBar, 20, 13), 4), 2))
		If llngAux > 12 Then
			lstrTipo = "DOS"
		Else
			lstrTipo = "WINDOWS"
		End If
		
		Select Case gstrEmpresa_Sigla
			Case "EFLUL", "COORSEL"
				If lstrTipo = "DOS" Then
					lintPos(0) = 20
					lintQtd(0) = 5
					lintPos(1) = 27
					lintQtd(1) = 2
					lintPos(2) = 29
					lintQtd(2) = 4
					lintPos(3) = 5
					lintQtd(3) = 9
					lintPos(4) = 14
					lintQtd(4) = 2
				Else
					lintPos(0) = 20
					lintQtd(0) = 9
					lintPos(1) = 29
					lintQtd(1) = 2
					lintPos(2) = 31
					lintQtd(2) = 2
					lintPos(3) = 5
					lintQtd(3) = 9
					lintPos(4) = 14
					lintQtd(4) = 2
				End If
			Case Else
				lintPos(0) = 20
				lintQtd(0) = 7
				lintPos(1) = 27
				lintQtd(1) = 2
				lintPos(2) = 29
				lintQtd(2) = 4
				lintPos(3) = 6
				lintQtd(3) = 8
				lintPos(4) = 14
				lintQtd(4) = 2
		End Select
		Select Case astrParte
			Case "numnf"
				ChecaCodBar = Mid(astrCodBar, lintPos(0), lintQtd(0))
			Case "mesano"
				If lstrTipo = "WINDOWS" Then
					ChecaCodBar = Mid(astrCodBar, lintPos(1), lintQtd(1)) & "/" & IIf(Val(Mid(astrCodBar, lintPos(2), lintQtd(2))) < 50, "20" & Mid(astrCodBar, lintPos(2), lintQtd(2)), "19" & Mid(astrCodBar, lintPos(2), lintQtd(2)))
				Else
					ChecaCodBar = Mid(astrCodBar, lintPos(1), lintQtd(1)) & "/" & Mid(astrCodBar, lintPos(2), lintQtd(2))
				End If
			Case "valor"
				ChecaCodBar = Mid(astrCodBar, lintPos(3), lintQtd(3)) & "." & Mid(astrCodBar, lintPos(4), lintQtd(4))
		End Select
	End Function
	
	Private Function ValidaMesAno(ByVal astrMesAno As String) As String
		astrMesAno = Str_Retira(astrMesAno, "/")
		Select Case Len(astrMesAno)
			Case 1
				If Val(astrMesAno) >= 1 Or Val(astrMesAno) <= 12 Then
					astrMesAno = VB6.Format(astrMesAno, "00") & "/" & VB6.Format(BuscaDataBD, "yyyy")
				Else
					astrMesAno = ""
				End If
			Case 2
				If Val(astrMesAno) >= 1 Or Val(astrMesAno) <= 12 Then
					astrMesAno = VB6.Format(astrMesAno, "00") & "/" & VB6.Format(BuscaDataBD, "yyyy")
				Else
					astrMesAno = ""
				End If
			Case 3
				If Val(VB.Left(astrMesAno, 1)) >= 1 Or Val(VB.Left(astrMesAno, 1)) <= 9 Then
					astrMesAno = VB6.Format(VB.Left(astrMesAno, 1), "00") & "/" & IIf(CDbl(VB.Right(astrMesAno, 2)) >= 51, "19" & VB6.Format(VB.Right(astrMesAno, 2), "00"), "20" & VB6.Format(VB.Right(astrMesAno, 2), "00"))
				Else
					astrMesAno = ""
				End If
			Case 4
				If Val(VB.Left(astrMesAno, 2)) >= 1 Or Val(VB.Left(astrMesAno, 2)) <= 12 Then
					astrMesAno = VB6.Format(VB.Left(astrMesAno, 2), "00") & "/" & IIf(CDbl(VB.Right(astrMesAno, 2)) >= 51, "19" & VB6.Format(VB.Right(astrMesAno, 2), "00"), "20" & VB6.Format(VB.Right(astrMesAno, 2), "00"))
				Else
					astrMesAno = ""
				End If
			Case 5
				If Val(VB.Left(astrMesAno, 1)) >= 1 Or Val(VB.Left(astrMesAno, 1)) <= 9 Then
					astrMesAno = VB6.Format(VB.Left(astrMesAno, 1), "00") & "/" & VB6.Format(VB.Right(astrMesAno, 4), "0000")
				Else
					astrMesAno = ""
				End If
			Case 6
				If Val(VB.Left(astrMesAno, 2)) >= 1 Or Val(VB.Left(astrMesAno, 2)) <= 9 Then
					astrMesAno = VB6.Format(VB.Left(astrMesAno, 2), "00") & "/" & VB6.Format(VB.Right(astrMesAno, 4), "0000")
				Else
					astrMesAno = ""
				End If
			Case Else
				astrMesAno = ""
		End Select
		ValidaMesAno = astrMesAno
	End Function
	
	Private Function BuscaNomeUnidade(ByVal alngUnidId As Integer, ByVal alngConsId As Integer, ByVal astrGrupo As String) As String
		Dim lstrSql As String
		Dim lrstAux As ADODB.Recordset
		lrstAux = New ADODB.Recordset
		lstrSql = ""
		lstrSql = lstrSql & "SELECT `unid" & LCase(astrGrupo) & "`.`unid_id`, " & vbCrLf
		lstrSql = lstrSql & "       `unid" & LCase(astrGrupo) & "`.`cons_id`, " & vbCrLf
		lstrSql = lstrSql & "       `unid" & LCase(astrGrupo) & "`.`nome` " & vbCrLf
		lstrSql = lstrSql & "  FROM `unid" & LCase(astrGrupo) & "` " & vbCrLf
		lstrSql = lstrSql & " WHERE `unid" & LCase(astrGrupo) & "`.`cons_id` = " & alngConsId & " " & vbCrLf
		lstrSql = lstrSql & "   AND `unid" & LCase(astrGrupo) & "`.`unid_id` = " & alngUnidId & " " & vbCrLf
		lstrSql = lstrSql & " LIMIT 0,1 "
		Call Conectar(lstrSql, lrstAux)
		With lrstAux
			If .RecordCount > 0 Then
				'UPGRADE_WARNING: Use of Null/IsNull() detected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="2EED02CB-5C0E-4DC1-AE94-4FAA3A30F51A"'
				BuscaNomeUnidade = Trim(IIf(IsDbNull(.Fields("nome").value), "", .Fields("nome").value))
			Else
				BuscaNomeUnidade = ""
			End If
			If .State = 1 Then Call .Close()
		End With
		'UPGRADE_NOTE: Object lrstAux may not be destroyed until it is garbage collected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6E35BFF6-CD74-4B09-9689-3E1A43DF8969"'
		lrstAux = Nothing
	End Function
	
	Private Function BuscaNomeConsumidor(ByVal alngConsId As Integer) As String
		Dim lstrSql As String
		Dim lrstAux As ADODB.Recordset
		lrstAux = New ADODB.Recordset
		lstrSql = ""
		lstrSql = lstrSql & "SELECT `consum`.`consreg`, " & vbCrLf
		lstrSql = lstrSql & "       `consum`.`nome` " & vbCrLf
		lstrSql = lstrSql & "  FROM `consum` " & vbCrLf
		lstrSql = lstrSql & " WHERE `consum`.`consreg` = " & alngConsId & " " & vbCrLf
		lstrSql = lstrSql & " LIMIT 0, 1 "
		Call Conectar(lstrSql, lrstAux)
		With lrstAux
			If .RecordCount > 0 Then
				'UPGRADE_WARNING: Use of Null/IsNull() detected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="2EED02CB-5C0E-4DC1-AE94-4FAA3A30F51A"'
				BuscaNomeConsumidor = Trim(IIf(IsDbNull(.Fields("nome").value), "", .Fields("nome").value))
			Else
				BuscaNomeConsumidor = ""
			End If
			If .State = 1 Then Call .Close()
		End With
		'UPGRADE_NOTE: Object lrstAux may not be destroyed until it is garbage collected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6E35BFF6-CD74-4B09-9689-3E1A43DF8969"'
		lrstAux = Nothing
	End Function
	
	Private Sub MontaGrid(ByVal amfgAux As AxMSFlexGridLib.AxMSFlexGrid)
		With amfgAux
			.Redraw = False
			.Cols = 10
			.Rows = 1
			.Clear()
			.set_ColWidth(0, 940)
			.set_ColWidth(1, 1240)
			.set_ColWidth(2, 1240)
			.set_ColWidth(3, 1240)
			.set_ColWidth(4, 1240)
			.set_ColWidth(5, 1540)
			.set_ColWidth(6, 840)
			.set_ColWidth(7, 3000)
			.set_ColWidth(8, 0)
			.set_ColWidth(9, 0)
			.set_TextMatrix(0, 0, "Mês/Ano")
			.set_TextMatrix(0, 1, "NF")
			.set_TextMatrix(0, 2, "Valor")
			.set_TextMatrix(0, 3, "Data Venc.")
			.set_TextMatrix(0, 4, "Data Pag. ")
			.set_TextMatrix(0, 5, "ZLC")
			.set_TextMatrix(0, 6, "Estado")
			.set_TextMatrix(0, 7, "Motivo")
			.set_TextMatrix(0, 8, "cons_id")
			.set_TextMatrix(0, 9, "unid_id")
			.set_ColAlignment(0, MSFlexGridLib.AlignmentSettings.flexAlignCenterCenter)
			.set_ColAlignment(1, MSFlexGridLib.AlignmentSettings.flexAlignRightCenter)
			.set_ColAlignment(2, MSFlexGridLib.AlignmentSettings.flexAlignRightCenter)
			.set_ColAlignment(3, MSFlexGridLib.AlignmentSettings.flexAlignCenterCenter)
			.set_ColAlignment(4, MSFlexGridLib.AlignmentSettings.flexAlignCenterCenter)
			.set_ColAlignment(5, MSFlexGridLib.AlignmentSettings.flexAlignCenterCenter)
			.set_ColAlignment(6, MSFlexGridLib.AlignmentSettings.flexAlignCenterCenter)
			.set_ColAlignment(7, MSFlexGridLib.AlignmentSettings.flexAlignLeftCenter)
			.Redraw = True
		End With
	End Sub
	
	Private Sub SetaCamposRecMan()
		With Me.mfgDados
			Me.txtFatura.Text = ""
			Me.txtMesAno.Text = IIf(.Rows <= 1, VB6.Format(BuscaDataBD, "mm") & "/" & VB6.Format(BuscaDataBD, "yyyy"), Me.txtMesAno.Text)
			Me.txtBarra.Text = ""
			Me.dtpPagamento.value = IIf(.Rows <= 1, VB6.Format(BuscaDataBD, "dd/mm/yyyy"), Me.dtpPagamento.value)
			'--------------------------------------
			Me.txtValor.Text = "0,00"
			Me.txtZLC.Text = "000.00.000000"
			Me.txtVenc.Text = "00/00/0000"
			Me.txtNf.Text = "0000000000000"
			Me.txtMAno.Text = "00/0000"
			Me.txtTotReg.Text = IIf(.Rows <= 1, 0, Me.txtTotReg.Text)
			Me.txtValTot.Text = IIf(.Rows <= 1, "0,00", Me.txtValTot.Text)
			Me.txtNome.Text = ""
			'--------------------------------------
			Me.cmdDel.Enabled = .Rows > 1
			Me.cmdImp.Enabled = .Rows > 1
			Me.cmdSalvar.Enabled = .Rows > 1
		End With
	End Sub
	
	Private Sub LigDesCampos()
		With Me.opbCodBarras
			Me.txtBarra.Enabled = .Checked
			Me.txtBarra.BackColor = System.Drawing.ColorTranslator.FromOle(IIf(.Checked, &H80000005, &H8000000F))
			Me.txtBarra.Text = IIf(.Checked, Me.txtBarra.Text, "")
		End With
		With Me.opbFaturas
			Me.txtFatura.Enabled = .Checked
			Me.txtMesAno.Enabled = .Checked
			Me.txtFatura.BackColor = System.Drawing.ColorTranslator.FromOle(IIf(.Checked, &H80000005, &H8000000F))
			Me.txtMesAno.BackColor = System.Drawing.ColorTranslator.FromOle(IIf(.Checked, &H80000005, &H8000000F))
			Me.txtMesAno.Text = IIf(.Checked, VB6.Format(BuscaDataBD, "mm") & "/" & VB6.Format(BuscaDataBD, "yyyy"), "")
			Me.txtFatura.Text = IIf(.Checked, Me.txtFatura.Text, "")
			Me.cmdLocalizarValorFatura.Enabled = .Checked
		End With
		Me.cmdReceber.Enabled = True
	End Sub
	
	Private Function ControleTecla(ByRef aKeyAscii As Short, ByVal astrTipo As String) As Object
		Select Case aKeyAscii
			Case System.Windows.Forms.Keys.Return
				Call SendKeysA(System.Windows.Forms.Keys.Tab, True)
			Case System.Windows.Forms.Keys.Escape
				Call cmdFechar_Click(cmdFechar, New System.EventArgs())
			Case Else
				If astrTipo = "N" And (aKeyAscii <> 8 And (aKeyAscii <> 44 And (aKeyAscii < 48 Or aKeyAscii > 57))) Then
					aKeyAscii = 0
				End If
		End Select
	End Function
	
	Private Function SelTodoCampo(ByRef aObjeto As System.Windows.Forms.TextBox, ByVal ablnTira As Boolean) As Object
		With aObjeto
			.Text = IIf(ablnTira, Str_Retira(.Text, ".-/ "), .Text)
			.SelectionStart = 0
			.SelectionLength = Len(.Text)
		End With
	End Function
	
	Private Function VericaPermiteUnidade(ByVal astrZona As String, ByVal astrLivro As String, ByVal astrConta As String) As Boolean
		Dim lstrUnidade(21) As String
		Dim llngConta As Integer
		Dim lstrZLC As String
		
		VericaPermiteUnidade = False
		lstrZLC = astrZona & astrLivro & astrConta
		lstrUnidade(0) = "00102001262"
		lstrUnidade(1) = "00102001286"
		lstrUnidade(2) = "00101000400"
		lstrUnidade(3) = "00107002000"
		lstrUnidade(4) = "00107001990"
		lstrUnidade(5) = "00102000166"
		lstrUnidade(6) = "00109003480"
		lstrUnidade(7) = "00102000070"
		lstrUnidade(8) = "00104000659"
		lstrUnidade(9) = "00104000940"
		lstrUnidade(10) = "00101000401"
		lstrUnidade(11) = "00102001680"
		lstrUnidade(12) = "00101003085"
		lstrUnidade(13) = "00102001263"
		lstrUnidade(14) = "00111000465"
		lstrUnidade(15) = "00107002002"
		lstrUnidade(16) = "00109003731"
		lstrUnidade(17) = "00111001946"
		lstrUnidade(18) = "00106001395"
		lstrUnidade(19) = "00106002236"
		lstrUnidade(20) = "00110000200"
		lstrUnidade(21) = "00111001769"
		
		For llngConta = 0 To 21
			If lstrZLC = lstrUnidade(llngConta) Then
				VericaPermiteUnidade = True
			End If
		Next llngConta
	End Function
	
	Private Sub LigDesFrames(ByVal ablnAux As Boolean)
		Me.fmeAux(0).Enabled = ablnAux
		Me.fmeAux(1).Enabled = ablnAux
		Me.fmeAux(2).Enabled = ablnAux
	End Sub
	
	Private Function ValidaSenhaUsuario() As Boolean
		Dim lmd5Aux As clsMd5
		Dim lstrSql As String
		Dim lrstAux As ADODB.Recordset
		lrstAux = New ADODB.Recordset
		lmd5Aux = New clsMd5
		ValidaSenhaUsuario = False
		lstrSql = ""
		lstrSql = lstrSql & "SELECT IF(`usuarios`.`senha` = '" & LCase(lmd5Aux.DigestStrToHexStr(Trim(Me.txtSenha.Text))) & "', 1, 0) AS `resultado` " & vbCrLf
		lstrSql = lstrSql & "  FROM `usuarios` " & vbCrLf
		lstrSql = lstrSql & " WHERE `usuarios`.`usuario` = '" & VB6.GetItemString(Me.cmbUsuario, Me.cmbUsuario.SelectedIndex) & "' "
		Call Conectar(lstrSql, lrstAux)
		With lrstAux
			If .State > 0 Then
				If .RecordCount > 0 Then
					If .Fields("resultado").value = "0" Then
						Call MsgBox("Senha inválida!", MsgBoxStyle.Exclamation, gstrTituloMensagem)
					Else
						ValidaSenhaUsuario = True
					End If
				End If
				Call .Close()
			End If
		End With
		'UPGRADE_NOTE: Object lrstAux may not be destroyed until it is garbage collected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6E35BFF6-CD74-4B09-9689-3E1A43DF8969"'
		lrstAux = Nothing
		'UPGRADE_NOTE: Object lmd5Aux may not be destroyed until it is garbage collected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6E35BFF6-CD74-4B09-9689-3E1A43DF8969"'
		lmd5Aux = Nothing
		Me.txtSenha.Text = ""
	End Function
	
	Private Sub txtMotivo_KeyPress(ByVal eventSender As System.Object, ByVal eventArgs As System.Windows.Forms.KeyPressEventArgs) Handles txtMotivo.KeyPress
		Dim KeyAscii As Short = Asc(eventArgs.KeyChar)
		If KeyAscii = System.Windows.Forms.Keys.Return Then
			With Me.fmeMotivo
				.Visible = False
				.Enabled = False
				Call LigDesFrames(Not .Enabled)
			End With
			If Len(Trim(Me.txtMotivo.Text)) > 0 Then
				Call AdicionaItensGrid(mfgDados, (UCase(Me.txtMotivo.Text) & " - AUTORIZADO EM " & VB6.Format(BuscaDataBD, "dd/mm/yyyy") & " POR: " & VB6.GetItemString(Me.cmbUsuario, Me.cmbUsuario.SelectedIndex)), Me.txtMesAno.Text, CDbl(Me.txtNf.Text), CDbl(Me.txtValor.Text), CDate(Me.txtVenc.Text), Me.dtpPagamento.value, Me.txtZLC.Text, istrFlgst, "S", IIf(IsNumeric(Me.txtConsId.Text), Me.txtConsId.Text, 0), IIf(IsNumeric(Me.txtUnidId.Text), Me.txtUnidId.Text, 0))
			Else
				Call MsgBox("Para efetuar esta baixa você deve informar o motivo!", MsgBoxStyle.Exclamation, gstrTituloMensagem)
			End If
		End If
		eventArgs.KeyChar = Chr(KeyAscii)
		If KeyAscii = 0 Then
			eventArgs.Handled = True
		End If
	End Sub
	
	Private Sub txtSenha_KeyPress(ByVal eventSender As System.Object, ByVal eventArgs As System.Windows.Forms.KeyPressEventArgs) Handles txtSenha.KeyPress
		Dim KeyAscii As Short = Asc(eventArgs.KeyChar)
		If KeyAscii = System.Windows.Forms.Keys.Return Then
			With Me.fmeSenha
				.Visible = False
				.Enabled = False
				Call LigDesFrames(Not .Enabled)
			End With
			If ValidaSenhaUsuario = False Then
				Call MsgBox("Você não tem autorização para efetuar esta baixa!", MsgBoxStyle.Exclamation, gstrTituloMensagem)
			Else
				With Me.fmeMotivo
					.Left = VB6.TwipsToPixelsX(3300)
					.Top = VB6.TwipsToPixelsY(2200)
					.Visible = True
					.Enabled = True
					Call LigDesFrames(Not .Enabled)
					Call Me.txtMotivo.Focus()
				End With
			End If
		End If
		eventArgs.KeyChar = Chr(KeyAscii)
		If KeyAscii = 0 Then
			eventArgs.Handled = True
		End If
	End Sub
	
	Private Sub Imprime(ByRef amfgAux As AxMSFlexGridLib.AxMSFlexGrid, ByVal alngTotReg As Integer, ByVal adblTotVlr As Double)
		Dim lfrmAux As FrmRelatorio
		Dim lstrTemp As String
		Dim lintCol As Short
		Dim lstrAli As String
		Dim llngLin As Integer
		lfrmAux = New FrmRelatorio
		With lfrmAux
			.quem_chama = Me
			.VS.Font = VB6.FontChangeName(.VS.Font, "Arial")
			.VS.TableBorder = VSVIEW6.TableBorderSettings.tbNone
			.VS.PageBorder = VSVIEW6.TableBorderSettings.tbNone
			.VS.Orientation = VSVIEW6.OrientationSettings.orLandscape
			.VS.PhysicalPage = True
			.VS.PaperSize = VSVIEW6.PaperSizeSettings.pprA4
			.VS.MarginTop = "7mm"
			.VS.MarginRight = "7mm"
			.VS.MarginLeft = "7mm"
			.VS.MarginBottom = "5mm"
			.VS.MarginFooter = "0mm"
			.VS.MarginHeader = "0mm"
			.VS.StartDoc()
			.VS.Font = VB6.FontChangeSize(.VS.Font, 8)
			
			Call CabecaRel(.VS)
			.VS.Font = VB6.FontChangeSize(.VS.Font, 8)
			.VS.Font = VB6.FontChangeBold(.VS.Font, False)
			
			For llngLin = 1 To amfgAux.Rows - 1
				'Determina o tamanho das colunas de acordo com o tamanho da celula da grade
				lstrTemp = "<5mm"
				
				With amfgAux
					For lintCol = 0 To .Cols - 3
						If .get_ColAlignment(lintCol) = MSFlexGridLib.AlignmentSettings.flexAlignCenterCenter Then
							lstrAli = "^"
						ElseIf .get_ColAlignment(lintCol) = MSFlexGridLib.AlignmentSettings.flexAlignRightCenter Then 
							lstrAli = ">"
						Else
							lstrAli = "<"
						End If
						lstrTemp = lstrTemp & "|" & lstrAli & "" & Int(((.get_ColWidth(lintCol) - 240) / 100) * 2.8) & "mm"
					Next lintCol
					'Pega as informações da grade e coloca nas coluna do relatorio
					lstrTemp = lstrTemp & ";"
					For lintCol = 0 To .Cols - 3
						lstrTemp = lstrTemp & "|" & .get_TextMatrix(llngLin, lintCol) & ""
					Next lintCol
				End With
				.VS.Table = lstrTemp
				If .VS.CurrentLine > 402 Then
					.VS.NewPage()
					.VS.CurrentLine = 1
					Call CabecaRel(.VS)
				End If
			Next llngLin
			Call LineFeed(.VS, 1)
			.VS.Table = "<5mm|>60mm|>50mm|>60mm;|Total de Faturas: " & VB6.Format(alngTotReg, "#,##0") & "||Valor Total: " & VB6.Format(adblTotVlr, "#,##0.00")
			.VS.EndDoc()
			Call .Show()
		End With
		System.Windows.Forms.Application.DoEvents()
		'UPGRADE_NOTE: Object lfrmAux may not be destroyed until it is garbage collected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6E35BFF6-CD74-4B09-9689-3E1A43DF8969"'
		lfrmAux = Nothing
	End Sub
	
	Public Sub SetaValor(ByVal adblNumNf As Double, ByVal astrMesAno As String)
		Me.txtFatura.Text = CStr(adblNumNf)
		Me.txtMesAno.Text = astrMesAno
	End Sub
	
	Private Function ValidaBaixa(ByRef amfgAux As AxMSFlexGridLib.AxMSFlexGrid) As Boolean
		Dim lblnRet As Boolean
		Dim ldblNumNf As Double
		Dim lstrMesAn As String
		Dim lstrFlgst As String
		Dim llngLin As Integer
		lblnRet = True
		llngLin = 1
		With amfgAux
			While llngLin <= .Rows - 1 And lblnRet = True
				lstrMesAn = .get_TextMatrix(llngLin, 0)
				ldblNumNf = IIf(IsNumeric(.get_TextMatrix(llngLin, 1)), .get_TextMatrix(llngLin, 1), 0)
				lblnRet = VerificaExisteRegistro("nf", " flgst='P' and numnf = " & ldblNumNf & " and mesano = '" & lstrMesAn & "' ")
				llngLin = llngLin + 1
			End While
		End With
		ValidaBaixa = lblnRet
	End Function
	
	Private Sub InsereDevolucao(ByVal adblNumNf As Double, ByVal astrMesAno As String, ByVal astrZona As String, ByVal astrLivro As String, ByVal astrConta As String, ByVal alngConsId As Integer, ByVal alngUnidId As Integer, ByVal adtePgto As Date, ByVal adblValor As Double, ByVal adteIni As Date, ByVal adteFim As Date)
		Dim lstrSql As String
		On Error GoTo ErrorInsereDevolucao
		
		lstrSql = ""
		lstrSql = lstrSql & "INSERT INTO `devolucao` SET "
		lstrSql = lstrSql & "            `nf`        = " & adblNumNf & ", "
		lstrSql = lstrSql & "            `mesano`    = '" & astrMesAno & "', "
		lstrSql = lstrSql & "            `dataemis`  = '" & VB6.Format(adtePgto, "yyyy-MM-dd") & "', "
		lstrSql = lstrSql & "            `valor`     =  " & Replace(CStr(adblValor), ",", ".") & ", "
		lstrSql = lstrSql & "            `banarrec`  =  " & VB6.GetItemData(Me.cmbBancos, Me.cmbBancos.SelectedIndex) & ", "
		lstrSql = lstrSql & "            `zona`     = '" & astrZona & "', "
		lstrSql = lstrSql & "            `livro`    = '" & astrLivro & "', "
		lstrSql = lstrSql & "            `conta`    = '" & astrConta & "', "
		lstrSql = lstrSql & "            `pagto`    = '" & VB6.Format(adtePgto, "yyyy-MM-dd") & "', "
		If gstrEmpresa_DevDuplPgtoAuto = "S" Then
			lstrSql = lstrSql & "            `datadevol` = '" & VB6.Format(BuscaDataBD, "yyyy-MM-dd") & "', "
			lstrSql = lstrSql & "            `estado`    = 'D' "
		Else
			lstrSql = lstrSql & "            `datadevol` = '" & "0000-00-00" & "', "
			lstrSql = lstrSql & "            `estado`    = NULL "
		End If
		Call Executar(lstrSql)
		'
		'Insere a devolução na tabela de convênios
		If gstrEmpresa_DevDuplPgtoAuto = "S" Then
			lstrSql = ""
			lstrSql = lstrSql & "INSERT INTO `convenios` SET "
			lstrSql = lstrSql & "            `zona`     = '" & astrZona & "', "
			lstrSql = lstrSql & "            `livro`    = '" & astrLivro & "', "
			lstrSql = lstrSql & "            `conta`    = '" & astrConta & "', "
			lstrSql = lstrSql & "            `cons_id`  =  " & alngConsId & ", "
			lstrSql = lstrSql & "            `unid_id`  =  " & alngUnidId & ", "
			lstrSql = lstrSql & "            `convenio` = '9070000082', "
			lstrSql = lstrSql & "            `sit` = 'Novo', "
			lstrSql = lstrSql & "            `dt_cadastro` = '" & VB6.Format(BuscaDataBD, "yyyy-MM-dd") & "', "
			lstrSql = lstrSql & "            `valor`    = " & Replace(CStr(adblValor), ",", ".") & ", "
			lstrSql = lstrSql & "            `dt_ini`   = '" & VB6.Format(adteIni, "yyyy-MM-dd") & "', "
			lstrSql = lstrSql & "            `dt_fim`   = '" & VB6.Format(adteFim, "yyyy-MM-dd") & "', "
			lstrSql = lstrSql & "            `ref`      = '" & "Fatura " & adblNumNf & " " & astrMesAno & "' "
			Call Executar(lstrSql)
		End If
ErrorInsereDevolucao: 
		If Err.Number > 0 Then
			Call MsgBox(Err.Number & " - " & Err.Description, MsgBoxStyle.Exclamation, gstrTituloMensagem)
		ElseIf myConC.Errors.Count > 0 Then 
			Call MsgBox("Código: " & myConC.Errors.Item(myConC.Errors.Count - 1).NativeError & vbCrLf & "Descrição:" & myConC.Errors.Item(myConC.Errors.Count - 1).Description)
		End If
	End Sub
End Class