Option Explicit On
Option Strict On
Imports System.Data
Imports Extensiones
Partial Class RegPoliza
Inherits ClsPaginas
#Region "P R O P E R T Y"
Private Shared missing As Object = System.Reflection.Missing.Value
Private Property RemoveMovimientos As New ArrayList()
Private Property CvePoliza As Integer
Get
Return CType(ViewState("CvePoliza"), Integer)
End Get
Set(value As Integer)
ViewState("CvePoliza") = value
End Set
End Property
Private Property Opcion As String
Get
Return CType(ViewState("Opcion"), String)
End Get
Set(value As String)
ViewState("Opcion") = value
End Set
End Property
Private Property TmpDT As DataTable
Get
Return CType(ViewState("TmpDT"), DataTable)
End Get
Set(value As DataTable)
ViewState("TmpDT") = value
End Set
End Property
Private Property DTCuentas As DataTable
Get
Return CType(ViewState("DTCuentas"), DataTable)
End Get
Set(value As DataTable)
ViewState("DTCuentas") = value
End Set
End Property
Private Property DTSegmentosNegocio As DataTable
Get
Return CType(ViewState("DTSegmentosNegocio"), DataTable)
End Get
Set(value As DataTable)
ViewState("DTSegmentosNegocio") = value
End Set
End Property
Private Property DtDevoluciones As DataTable
Get
DtDevoluciones = DirectCast(ViewState("DtDevoluciones"), DataTable)
End Get
Set(ByVal value As DataTable)
ViewState("DtDevoluciones") = value
End Set
End Property
Private Property DtProveedoresConta As DataTable
Get
DtProveedoresConta = DirectCast(ViewState("DtProveedoresConta"), DataTable)
End Get
Set(ByVal value As DataTable)
ViewState("DtProveedoresConta") = value
End Set
End Property
Private Property DrParametros As DataRow
Get
DrParametros = If(ViewState("drParametros") IsNot Nothing AndAlso DirectCast(ViewState("drParametros"), DataTable).Rows.Count > 0, DirectCast(ViewState("drParametros"), DataTable).Rows(0), Nothing)
End Get
Set(value As DataRow)
ViewState("drParametros") = value.Table
End Set
End Property
Private Property UsaMonedaExtranjera As Boolean
Get
UsaMonedaExtranjera = CBool(ViewState("UsaMonedaExtranjera"))
End Get
Set(value As Boolean)
ViewState("UsaMonedaExtranjera") = value
End Set
End Property
#End Region
Protected Sub Page_Load(sender As Object, e As EventArgs) Handles Me.LoadComplete
If Not IsPostBack Then
ViewState("Orden0") = ""
ViewState("Orden1") = ""
Me.Form.DefaultButton = BtnConsultar.UniqueID
TxtFecha.Text = Now.ToShortDateString
TxtFechaPoliza.Text = Now.ToShortDateString
If Not UsuarioActual.Empresa.UsaAC Then
tdPolizaComplementaria.Visible = True
End If
Dim ObjConta As New ClsContabilidad
If ObjConta.GetConta_TiposPoliza(UsuarioActual.CveEmpresa) Then
DdlTipo.DataSource = ObjConta.DtResultados.FiltraParametros($"CveEmpresa={UsuarioActual.CveEmpresa} OR CveEmpresa IS NULL")
DdlTipo.DataBind()
DdlTipoPoliza.DataSource = ObjConta.DtResultados.FiltraParametros($"CveEmpresa={UsuarioActual.CveEmpresa} OR CveEmpresa IS NULL")
DdlTipoPoliza.DataBind()
End If
If ObjConta.GetCuentas(-1, "-1", 1, UsuarioActual.CveEmpresa) Then
DTCuentas = ObjConta.DtResultados
End If
DTSegmentosNegocio = GlobalDTSubProyectos(-1, -1, UsuarioActual.CveEmpresa, 1)
Dim dr As DataRow = DTSegmentosNegocio.NewRow
dr("CveSubProyecto") = "0"
dr("SubProyecto") = ""
DTSegmentosNegocio.Rows.InsertAt(dr, 0)
DdlSegNeg.DataSource = DTSegmentosNegocio
DdlSegNeg.DataBind()
If ObjConta.GetParametros(UsuarioActual.CveEmpresa) Then
If ObjConta.DtResultados IsNot Nothing AndAlso ObjConta.DtResultados.Rows.Count > 0 Then
DrParametros = ObjConta.DtResultados.Rows(0)
'vienen datos agruapdos ejemplo 'SSSSSSNNNNSSSSSS, Y un digito significa una opcion
UsaMonedaExtranjera = DrParametros("ParFunc").ToString.Substring(5, 1) = "S"
If UsaMonedaExtranjera Then
GvDatos.Columns(5).Visible = True
GvDatos.Columns(6).Visible = True
td1CargoME.Visible = True
td1AbonoME.Visible = True
td2CargoME.Visible = True
td2AbonoME.Visible = True
End If
End If
End If
ObjConta.Dispose()
LblAbono.Text = "0.00"
LblCargo.Text = "0.00"
If TmpDT Is Nothing Then CreaDTRegPoliza()
If Request("CvePoliza") IsNot Nothing AndAlso Request("CvePoliza").ToEntero() > 0 Then
ChkPolizaComplementaria.Enabled = False
CvePoliza = Request("CvePoliza").ToEntero()
Limpia()
If Request("Opcion") IsNot Nothing AndAlso Request("Opcion").ToString <> "" Then
Opcion = Request("Opcion").ToString
End If
If Opcion = "Com" Then
CargaPolizaComplementaria(CvePoliza)
Else
CargaDatos(CvePoliza)
tdPolizaComplementaria.Visible = False
End If
Else
TxtFechaPoliza.Text = Date.Now.ToShortDateString
CvePoliza = -1
SiguienteFolio()
End If
If UsuarioActual.Empresa.UsaAC Then
LBDevIVA.Visible = False
PnlDevIVA.Visible = False
End If
End If
End Sub
#Region "C A R G A - V A L O R E S"
Private Sub CreaDTRegPoliza()
TmpDT = New DataTable
Dim column As DataColumn = New DataColumn("IdConsec", GetType(Integer))
With column
.AutoIncrement = True
.AutoIncrementSeed = 1
.AutoIncrementStep = 1
End With
TmpDT.Columns.Add(column)
TmpDT.Columns.Add("CvePolizaDetalle", GetType(Integer))
TmpDT.Columns.Add("CvePoliza", GetType(Integer))
TmpDT.Columns.Add("Referencia", GetType(String))
TmpDT.Columns.Add("CveCuenta", GetType(Integer))
TmpDT.Columns.Add("Cuenta", GetType(String))
TmpDT.Columns.Add("CtaCodigo", GetType(String))
TmpDT.Columns.Add("CveSubProyecto", GetType(Integer))
TmpDT.Columns.Add("SubProyecto", GetType(String))
TmpDT.Columns.Add("Concepto", GetType(String))
TmpDT.Columns.Add("Estado", GetType(String))
TmpDT.Columns.Add("Cargo", GetType(Double))
TmpDT.Columns.Add("Abono", GetType(Double))
TmpDT.Columns.Add("CargoME", GetType(Double))
TmpDT.Columns.Add("AbonoME", GetType(Double))
TmpDT.Columns.Add("Folio", GetType(Integer))
End Sub
#End Region
#Region "G R I D - V I E W"
Protected Sub GvDatos_RowCancelingEdit(sender As Object, e As GridViewCancelEditEventArgs) Handles GvDatos.RowCancelingEdit
GvDatos.EditIndex = -1
CargaGrid()
End Sub
Protected Sub GvDatos_RowDataBound(sender As Object, e As GridViewRowEventArgs) Handles GvDatos.RowDataBound
If e.Row.RowType = DataControlRowType.DataRow Then
If e.Row.RowIndex <= 4 Then 'mayor a cero, por si borran los primeros 3 renglones que se conserve el ancho
LblAbono.Text = TmpDT.FiltraParametros("Estado<>'D'").SUM("Abono").FormatoNumero
LblCargo.Text = TmpDT.FiltraParametros("Estado<>'D'").SUM("Cargo").FormatoNumero
LblDiferencia.Text = (LblCargo.Text.Trim.ToDouble - LblAbono.Text.Trim.ToDouble).FormatoNumero
End If
e.Row.Cells(0).HorizontalAlign = HorizontalAlign.Center
e.Row.Cells(2).Style.Add("text-align", "left")
e.Row.FCLiteral("LtlNo").Text = (e.Row.RowIndex + 1).ToString
If e.Row.DBCampo("Cargo") = "0" AndAlso e.Row.FCLiteral("LtlCargo") IsNot Nothing Then e.Row.FCLiteral("LtlCargo").Text = ""
If e.Row.DBCampo("Abono") = "0" AndAlso e.Row.FCLiteral("LtlAbono") IsNot Nothing Then e.Row.FCLiteral("LtlAbono").Text = ""
If e.Row.DBCampo("CargoME") = "0" AndAlso e.Row.FCLiteral("LtlCargoME") IsNot Nothing Then e.Row.FCLiteral("LtlCargoME").Text = ""
If e.Row.DBCampo("AbonoME") = "0" AndAlso e.Row.FCLiteral("LtlAbonoME") IsNot Nothing Then e.Row.FCLiteral("LtlAbonoME").Text = ""
If e.Row.DBCampo("Cargo").ToDouble < 0 AndAlso e.Row.FCLiteral("LtlCargo") IsNot Nothing Then e.Row.FCLiteral("LtlCargo").Text = String.Format("{0}", e.Row.DBCampo("Cargo").FormatoNumero())
If e.Row.DBCampo("Abono").ToDouble < 0 AndAlso e.Row.FCLiteral("LtlAbono") IsNot Nothing Then e.Row.FCLiteral("LtlAbono").Text = String.Format("{0}", e.Row.DBCampo("Abono").FormatoNumero())
If e.Row.DBCampo("Estado").ToString.Trim = "D" Then e.Row.Visible = False
If e.Row.RowState = DataControlRowState.Edit OrElse e.Row.RowState = 5 Then
e.Row.FCDropDownList("DdlCuenta").DataSource = DTCuentas.FiltraParametros("Afectable=1")
e.Row.FCDropDownList("DdlCuenta").DataBind()
e.Row.FCDropDownList("DdlCuenta").SelectedValue = e.Row.DBCampo("CveCuenta")
e.Row.FCDropDownList("DdlSegNeg").DataSource = DTSegmentosNegocio
e.Row.FCDropDownList("DdlSegNeg").DataBind()
e.Row.FCDropDownList("DdlSegNeg").SelectedValue = e.Row.DBCampo("CveSubProyecto")
e.Row.FCTextBox("TxtCargo").Text = e.Row.DBCampo("Cargo").ToString
e.Row.FCTextBox("TxtAbono").Text = e.Row.DBCampo("Abono").ToString
e.Row.FCTextBox("TxtCargoME").Text = e.Row.DBCampo("CargoME").ToString
e.Row.FCTextBox("TxtAbonoME").Text = e.Row.DBCampo("AbonoME").ToString
Else
'e.Row.FCHyperLink("Ref").NavigateUrl = e.Row.DBCampo("SIGReferencia").ContaReferenciaLiga
End If
End If
End Sub
Protected Sub GvDatos_RowDeleting(sender As Object, e As GridViewDeleteEventArgs) Handles GvDatos.RowDeleting
Dim dr() As DataRow = TmpDT.Select(String.Format("IdConsec = {0}", e.Keys("IdConsec")))
dr(0)("Estado") = "D"
TmpDT.AcceptChanges()
BtnNuevo.OnClientClick = "return confirm('Se han hecho cambios que no fueron guardados, ¿Continuar?');"
CargaGrid()
End Sub
Protected Sub GvDatos_RowEditing(sender As Object, e As GridViewEditEventArgs) Handles GvDatos.RowEditing
GvDatos.EditIndex = e.NewEditIndex
CargaGrid()
End Sub
Protected Sub GvDatos_RowUpdating(sender As Object, e As GridViewUpdateEventArgs) Handles GvDatos.RowUpdating
If (GvDatos.Rows(e.RowIndex).FCTextBox("TxtCargo").Text.Length = 0 AndAlso
GvDatos.Rows(e.RowIndex).FCTextBox("TxtAbono").Text.Length = 0) OrElse
(GvDatos.Rows(e.RowIndex).FCTextBox("TxtCargo").Text.Trim.ToDouble > 0 AndAlso
GvDatos.Rows(e.RowIndex).FCTextBox("TxtAbono").Text.Trim.ToDouble > 0) Then
Alert("Debes asignar un valor para CARGO o para ABONO", TipoMensaje.MsgAdvertencia)
Else
Dim dr() As DataRow = TmpDT.Select(String.Format("IdConsec = {0}", e.Keys("IdConsec")))
BtnNuevo.OnClientClick = "return confirm('Se han hecho cambios que no fueron guardados, ¿Continuar?');"
dr(0)("Referencia") = GvDatos.Rows(e.RowIndex).FCTextBox("TxtReferencia").Text.Trim
dr(0)("CveCuenta") = GvDatos.Rows(e.RowIndex).FCDropDownList("DdlCuenta").SelectedValue
dr(0)("CtaCodigo") = GvDatos.Rows(e.RowIndex).FCDropDownList("DdlCuenta").SelectedItem.Text
dr(0)("Cuenta") = GvDatos.Rows(e.RowIndex).FCDropDownList("DdlCuenta").SelectedItem.Text
dr(0)("CveSubProyecto") = GvDatos.Rows(e.RowIndex).FCDropDownList("DdlSegNeg").SelectedValue
dr(0)("SubProyecto") = GvDatos.Rows(e.RowIndex).FCDropDownList("DdlSegNeg").SelectedItem.Text
dr(0)("Concepto") = GvDatos.Rows(e.RowIndex).FCTextBox("TxtNombreConcepto").Text.Trim
dr(0)("Cargo") = GvDatos.Rows(e.RowIndex).FCTextBox("TxtCargo").Text.Trim.ToDouble
dr(0)("Abono") = GvDatos.Rows(e.RowIndex).FCTextBox("TxtAbono").Text.Trim.ToDouble
dr(0)("CargoME") = GvDatos.Rows(e.RowIndex).FCTextBox("TxtCargoME").Text.Trim.ToDouble
dr(0)("AbonoME") = GvDatos.Rows(e.RowIndex).FCTextBox("TxtAbonoME").Text.Trim.ToDouble
dr(0)("Estado") = "U"
TmpDT.AcceptChanges()
GvDatos.EditIndex = -1
CargaGrid()
End If
End Sub
Public Function WSCuentas() As String
Dim Str As New StringBuilder
Dim i As Integer = 0
Dim dt As DataTable = DTCuentas.FiltraParametros("Afectable = 1")
If dt IsNot Nothing Then
For Each dr As DataRow In dt.Rows
i += 1
Str.AppendFormat("{{value:""{0}"",label:""{1}""}}{2}", dr("CveCuenta"), dr("CtaCodigo").ToString.Replace("""", ""), If(i < dt.Rows.Count, ",", ""))
Next
End If
Return Str.ToString
End Function
#End Region
#Region "O R D E N A M I E N T O"
Protected Sub LbOrden_Click(ByVal sender As Object, ByVal e As EventArgs)
Dim Orden As String = ""
Dim Campo As String = ""
Dim gvi As Integer = 0
Dim Literal As Literal = Nothing
Const OrdenInicial As String = ""
Dim Arg(2) As String
Arg = CType(sender, LinkButton).CommandArgument().ToString.Split(";"c)
Campo = Arg(0)
gvi = Arg(1).ToEntero
Literal = CType(CType(sender, LinkButton).NamingContainer.FindControl("Img" & Campo.Replace(",", "_")), Literal)
Campo = Campo.Substring(0, Campo.Length - 1)
If ViewState(String.Format("O{0}", Campo, gvi)) IsNot Nothing AndAlso ViewState(String.Format("O{0}", Campo, gvi)).ToString = String.Format("{0} DESC", Campo) Then
ViewState(String.Format("O{0}", Campo)) = String.Format("{0} ASC", Campo)
Literal.Text = String.Format("")
Else
ViewState(String.Format("O{0}", Campo, gvi)) = String.Format("{0} DESC", Campo)
Literal.Text = String.Format("")
End If
Orden = OrdenInicial & ViewState(String.Format("O{0}", Campo, gvi)).ToString
ViewState("Orden") = Orden
CargaGridDevoluciones(Orden, gvi)
End Sub
Protected Sub CargaGridDevoluciones(Orden As String, gvi As Integer)
Dim DV As DataView = Nothing
DV = New DataView(DtDevoluciones, "", Orden, DataViewRowState.CurrentRows)
If Orden <> String.Empty Then
GvDevoluciones.DataSource = DV.ToTable()
Else
GvDevoluciones.DataSource = DtDevoluciones
End If
ViewState("Orden1") = Orden
GvDevoluciones.DataBind()
UpDevoluciones.Update()
DV.Dispose()
End Sub
#End Region
#Region "I M A G E - B U T T O N Y L I N K S"
Protected Sub BtnConsultar_Click(sender As Object, e As EventArgs) Handles BtnConsultar.Click
Limpia()
CargaDatos(-1, DdlTipo.SelectedValue.ToEntero, TxtFecha.Text.Trim.ToDate, TxtNumero.Text.Trim.ToEntero)
End Sub
Protected Sub BtnGuardar_Click(sender As Object, e As EventArgs) Handles BtnGuardar.Click
If GvDatos.Rows.Count = 0 Then
Alert("Debe agregar movimientos a la póliza.", TipoMensaje.MsgAdvertencia)
Exit Sub
End If
If LblCargo.Text.Trim.ToDouble <> LblAbono.Text.Trim.ToDouble Then
Alert("El total del CARGO debe coincidir con el total del ABONO.", TipoMensaje.MsgAdvertencia)
Exit Sub
End If
BtnGuardar.OnClientClick = "FncVerifica();"
If ChkPolizaComplementaria.Checked Then
If CvePoliza < 0 Then
GuardaPolizaComplementaria()
ElseIf HdnGuardar.Value = "" Or HdnGuardar.Value = "True" Then
ActualizaPolizaComplementaria()
ElseIf HdnGuardar.Value = "False" Then
Alert("Los datos no se guardaron", TipoMensaje.MsgError)
End If
Else
If CvePoliza < 0 Then
GuardaPoliza()
ElseIf HdnGuardar.Value = "" Or HdnGuardar.Value = "True" Then
ActualizaPoliza()
ElseIf HdnGuardar.Value = "False" Then
Alert("Los datos no se guardaron", TipoMensaje.MsgError)
End If
End If
End Sub
Protected Sub BtnNuevo_Click(sender As Object, e As EventArgs) Handles BtnNuevo.Click
CvePoliza = -1
DdlTipo.SelectedIndex = 0
DdlTipoPoliza.SelectedIndex = 0
DdlSegNeg.SelectedIndex = 0
BtnGuardar.OnClientClick = ""
TxtFecha.Text = ""
TxtNumero.Text = ""
TxtFechaPoliza.Text = ""
TxtNumeroPoliza.Text = ""
TxtConcepto.Text = ""
TxtReferencia.Text = ""
TxtCuenta.Text = ""
HdnCveCuenta.Value = ""
TxtNombreConcepto.Text = ""
TxtCargo.Text = ""
TxtAbono.Text = ""
LblCargo.Text = "0.00"
LblAbono.Text = "0.00"
HdnFechaPoliza.Value = TxtFechaPoliza.Text
HdnFolioPoliza.Value = TxtNumeroPoliza.Text
HdnTipoPoliza.Value = DdlTipoPoliza.SelectedValue
BtnEliminar.Visible = False
GvDatos.DataBind()
UpConsultar.Update()
UpTitulos.Update()
UpDatos.Update()
If TmpDT Is Nothing Then CreaDTRegPoliza() Else TmpDT.Rows.Clear()
Limpia()
End Sub
Protected Sub LbAgregar_Click(sender As Object, e As EventArgs) Handles LbAgregar.Click
If HdnCveCuenta.Value.ToEntero <= 0 Then Alert("Debe de seleccionar la cuenta.", TipoMensaje.MsgAdvertencia) : TxtCuenta.Focus() : Exit Sub
If (TxtCargo.Text.Length = 0 And TxtAbono.Text.Length = 0) Or (TxtCargo.Text.Trim.ToDouble > 0 And TxtAbono.Text.Trim.ToDouble > 0) Then
Alert("Debes asignar un valor para CARGO o para ABONO", TipoMensaje.MsgAdvertencia)
Else
If TxtCargo.Text = "" Then TxtCargo.Text = "0"
If TxtAbono.Text = "" Then TxtAbono.Text = "0"
AddRegPolizaDetalle(-1, TxtReferencia.Text, HdnCveCuenta.Value.ToEntero, TxtCuenta.Text, DdlSegNeg.SelectedValue, DdlSegNeg.SelectedItem.Text, TxtNombreConcepto.Text, TxtCargo.Text.ToDouble, TxtAbono.Text.ToDouble)
CargaGrid()
UpDatos.Update()
TxtReferencia.Focus()
DdlSegNeg.SelectedIndex = 0
TxtCargo.Text = ""
TxtAbono.Text = ""
HdnCveCuenta.Value = ""
TxtCuenta.Text = ""
BtnNuevo.OnClientClick = "return confirm('Se han hecho cambios que no fueron guardados, ¿Continuar?')"
End If
End Sub
#End Region
Private Sub CargaGrid()
GvDatos.DataBind()
GvDatos.DataSource = TmpDT
GvDatos.DataBind()
LblAbono.Text = TmpDT.SUM("Abono", "Estado<>'D'").FormatoNumero
LblCargo.Text = TmpDT.SUM("Cargo", "Estado<>'D'").FormatoNumero
LblDiferencia.Text = (LblCargo.Text.Trim.ToDouble - LblAbono.Text.Trim.ToDouble).FormatoNumero
If LblDiferencia.Text.ToDouble >= 0 Then
LblDiferencia.ForeColor = Drawing.Color.Black
Else
BtnGuardar.Enabled = True
LblDiferencia.ForeColor = Drawing.Color.Red
End If
End Sub
#Region " P O L I Z A S - C O M P L E M E N T A R I A S "
Private Sub CargaPolizaComplementaria(tCvePoliza As Integer)
Dim ObjPoliza As New ClsContabilidad
Dim DT As DataTable = Nothing
If ObjPoliza.GetPoliza(tCvePoliza, UsuarioActual.CveEmpresa) Then
DT = ObjPoliza.DtResultados
BtnGuardar.OnClientClick = "FncVerifica();"
ChkPolizaComplementaria.Checked = True
If DT.Rows.Count = 0 Then
TxtFechaPoliza.Text = Now.ToShortDateString
TxtNumeroPoliza.Text = ""
LblCargo.Text = ""
LblAbono.Text = ""
TxtConcepto.Text = ""
Alert("No se encontró ninguna póliza, verifique los datos.", TipoMensaje.MsgAdvertencia)
Else
Dim dr As DataRow = DT.Rows(0)
TxtFechaPoliza.Text = dr("FechaPol").ToString.ToDate.ToShortDateString
HdnFechaPoliza.Value = dr("FechaPol").ToString.ToDate.ToShortDateString
HdnTipoPoliza.Value = DdlTipoPoliza.SelectedValue
TxtNumeroPoliza.Text = dr("Folio").ToString
HdnFolioPoliza.Value = dr("Folio").ToString
TxtConcepto.Text = dr("ConceptoPoliza").ToString
HdnlCargo.Value = dr("Cargos").ToString
HdnlAbono.Value = dr("Abonos").ToString
LblCargo.Text = dr("Cargos").ToString
LblAbono.Text = dr("Abonos").ToString
LblNumPoliza.ToolTip = dr("CvePoliza").ToString
If Math.Abs(dr("Cargos").ToString.ToDecimal - DT.SUM("Cargo")) > 0.001 OrElse Math.Abs(dr("Abonos").ToString.ToDecimal - DT.SUM("Abono")) > 0.001 Then
Dim Str As New StringBuilder
Str.AppendFormat("Los Totales de la póliza no coinciden con los movimientos
Cargos en Póliza: {0} Cargos en Movimientos: {1}
Abonos en Póliza: {2} Abonos en Movimientos: {3}
", dr("Cargos").ToString, DT.SUM("Cargo").ToString, dr("Abonos").ToString, DT.SUM("Abono").ToString)
Alert(Str.ToString, TipoMensaje.MsgError)
End If
CvePoliza = dr("CvePoliza").ToString.ToEntero
End If
End If
ObjPoliza.Dispose()
If TmpDT Is Nothing Then CreaDTRegPoliza()
TmpDT.Clear()
If DT IsNot Nothing Then TmpDT.Merge(DT)
If LblDiferencia.Text.Trim.ToDouble <> 0 Then
Alert("Verifique los cargos y abonos de los movimientos", TipoMensaje.MsgInformacion)
ElseIf HdnlCargo.Value.ToDouble <> LblCargo.Text.ToDouble Then
Alert("El cargo de la póliza " + HdnlCargo.Value + " no coincide con la sumatoria de cargos de los movimientos", TipoMensaje.MsgInformacion)
ElseIf HdnlAbono.Value.ToDouble <> LblAbono.Text.ToDouble Then
Alert("El abono de la póliza " + HdnlAbono.Value + " no coincide con la sumatoria de abonos de los movimientos", TipoMensaje.MsgInformacion)
End If
CargaGrid()
UpTitulos.Update()
UpDatos.Update()
If DT IsNot Nothing Then DT.Dispose()
End Sub
Private Sub GuardaPolizaComplementaria()
Dim OcurrioError As Boolean = False
Dim ObjConta As New ClsContabilidad
Dim tCvePoliza As Integer
Dim NumPoliza As String = "-1"
Dim Tipo As String = ""
ObjConta.IniciaTransacSQL()
If TxtNumeroPoliza.Text.Trim <> "" Then
NumPoliza = TxtNumeroPoliza.Text.Trim
Tipo = "CHQ"
Else
End If
tCvePoliza = ObjConta.AddPoliza(DdlTipoPoliza.SelectedValue.ToEntero, TxtFolio.Text.ToEntero, TxtFechaPoliza.Text.Trim.ToDate, TxtConcepto.Text.Trim, UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa)
If tCvePoliza > 0 Then
'Agrega Movimientos de la poliza
For Each Row As DataRow In TmpDT.Rows
If Row("Cargo").ToString.ToDecimal <> 0 Then
If Not ObjConta.AddPolizaDetalle(tCvePoliza, Row("CveCuenta").ToString.ToEntero, Row("Cuenta").ToString, Row("CveSubProyecto").ToString.ToEntero, False,
Row("Cargo").ToString.ToDouble, Row("Referencia").ToString, Row("Concepto").ToString,
TxtFechaPoliza.Text.Trim.ToDate) Then
OcurrioError = True
End If
Else
If Not ObjConta.AddPolizaDetalle(tCvePoliza, Row("CveCuenta").ToString.ToEntero, Row("Cuenta").ToString, Row("CveSubProyecto").ToString.ToEntero, True,
Row("Abono").ToString.ToDouble, Row("Referencia").ToString, Row("Concepto").ToString,
TxtFechaPoliza.Text.Trim.ToDate) Then
OcurrioError = True
End If
End If
Next
If OcurrioError Then
ObjConta.RollBack()
Alert("Ocurrió un error al guardar la póliza.", TipoMensaje.MsgAdvertencia)
Else
Alert(String.Format("La información se guardó correctamente."), TipoMensaje.MsgInformacion)
ObjConta.Commit()
CvePoliza = tCvePoliza
Limpia()
CargaPolizaComplementaria(CvePoliza)
BtnNuevo.OnClientClick = ""
End If
End If
UpTitulos.Update()
UpDatos.Update()
UpConsultar.Update()
ObjConta.Dispose()
End Sub
Private Sub ActualizaPolizaComplementaria()
Dim OcurrioError As Boolean = False
Dim ObjConta As New ClsContabilidad
Dim Row As DataRow
ObjConta.IniciaTransacSQL()
If ObjConta.UpdatePoliza(TxtFechaPoliza.Text.Trim.ToDate, TxtNumeroPoliza.Text.ToEntero, CvePoliza, TxtConcepto.Text.Trim, DdlTipoPoliza.SelectedValue.ToEntero) Then
For Each Row In TmpDT.Rows
If Row("Estado").ToString.Trim = "D" AndAlso Row("CvePolizaDetalle").ToString.ToEntero > 0 Then
ObjConta.RemovePolizaDetalle(Row("CvePolizaDetalle").ToString.ToEntero)
Else
Dim Importe As Double = If(Row("Cargo").ToString.ToDouble <> 0, Row("Cargo"), Row("Abono")).ToString.ToDouble
Dim TipoMovto As Boolean = Not Row("Cargo").ToString.ToDouble <> 0
If Row("CvePolizaDetalle").ToString.ToEntero <> -1 Then
If Not ObjConta.UpdatePolizaDetalle(Row("CvePolizaDetalle").ToString.ToEntero, Row("CveCuenta").ToString.ToEntero, Row("CveSubProyecto").ToString.ToEntero, TipoMovto, Importe, Row("Referencia").ToString, Row("Concepto").ToString) Then
OcurrioError = True
End If
Else
If Not ObjConta.AddPolizaDetalle(CvePoliza.ToString.ToEntero, Row("CveCuenta").ToString.ToEntero, Row("Cuenta").ToString, Row("CveSubProyecto").ToString.ToEntero, TipoMovto, Importe, Row("Referencia").ToString, Row("Concepto").ToString, TxtFechaPoliza.Text.Trim.ToDate) Then
OcurrioError = True
End If
End If
End If
Next
If OcurrioError Then
ObjConta.RollBack()
Alert("Ocurrió un error al actualizar los movimientos de la póliza complementaria", TipoMensaje.MsgAdvertencia)
Else
Alert("La póliza se actualizó correctamente.", TipoMensaje.MsgInformacion)
ObjConta.Commit()
HdnFechaPoliza.Value = TxtFechaPoliza.Text.ToDate.ToShortDateString
HdnTipoPoliza.Value = DdlTipoPoliza.SelectedValue
CargaPolizaComplementaria(CvePoliza)
BtnNuevo.OnClientClick = ""
End If
Else
ObjConta.RollBack()
End If
ObjConta.Dispose()
End Sub
#End Region
#Region "P R O C E D I M I E N T O S"
Private Sub CargaDatos(tCvePoliza As Integer, Optional CveTipoPoliza As Integer = -1, Optional Fecha As Date = MinFecha, Optional Folio As Integer = -1)
Dim ObjPoliza As New ClsContabilidad
Dim DT As DataTable = Nothing
If (tCvePoliza = -1 And ObjPoliza.GetPoliza(CveTipoPoliza, Fecha, Folio, UsuarioActual.CveEmpresa)) OrElse ObjPoliza.GetPoliza(tCvePoliza, UsuarioActual.CveEmpresa) Then
DT = ObjPoliza.DtResultados
BtnGuardar.OnClientClick = "FncVerifica();"
If DT.Rows.Count = 0 Then
TxtFechaPoliza.Text = Now.ToShortDateString
TxtNumeroPoliza.Text = ""
LblCargo.Text = ""
LblAbono.Text = ""
TxtConcepto.Text = ""
Alert("No se encontró ninguna Póliza, verifique los datos.", TipoMensaje.MsgAdvertencia)
Else
Dim dr As DataRow = DT.Rows(0)
HLImprimir.NavigateUrl = String.Format("/Compras/PopUpVerFactura.aspx?P={0}", Encripta($"OP=POL&CvePoliza={dr("CvePoliza").ToString.ToEntero}"))
TxtFechaPoliza.Text = dr("Fecha").ToString.ToDate.ToShortDateString
HdnFechaPoliza.Value = dr("Fecha").ToString.ToDate.ToShortDateString
DdlTipoPoliza.SelectedValue = dr("CveTipoPoliza").ToString.Trim
HdnTipoPoliza.Value = DdlTipoPoliza.SelectedValue
TxtNumeroPoliza.Text = dr("Folio").ToString
HdnFolioPoliza.Value = dr("Folio").ToString
TxtConcepto.Text = dr("ConceptoPoliza").ToString
HdnlCargo.Value = dr("Cargos").ToString
HdnlAbono.Value = dr("Abonos").ToString
LblCargo.Text = dr("Cargos").ToString
LblAbono.Text = dr("Abonos").ToString
LblNumPoliza.ToolTip = dr("CvePoliza").ToString
If Math.Abs(dr("Cargos").ToString.ToDecimal - DT.SUM("Cargo")) > 0.001 OrElse Math.Abs(dr("Abonos").ToString.ToDecimal - DT.SUM("Abono")) > 0.001 Then
Dim Str As New StringBuilder
Str.AppendFormat("Los Totales de la póliza no coinciden con los movimientos
Cargos en Póliza: {0} Cargos en Movimientos: {1}
Abonos en Póliza: {2} Abonos en Movimientos: {3}
", dr("Cargos").ToString, DT.SUM("Cargo").ToString, dr("Abonos").ToString, DT.SUM("Abono").ToString)
Alert(Str.ToString, TipoMensaje.MsgError)
End If
CvePoliza = dr("CvePoliza").ToString.ToEntero
If UsuarioActual.TienePermisoProceso(145) Then
BtnEliminar.Visible = True
End If
End If
End If
ObjPoliza.Dispose()
TmpDT = DT
TmpDT.Columns.Add("CtaCodigo", GetType(String))
For Each dr As DataRow In TmpDT.Rows
dr("CtaCodigo") = DTCuentas.FiltroPrimeroValor("CtaCodigo", $"CveCuenta={dr("CveCuenta")}")
Next
TmpDT.AcceptChanges()
If LblDiferencia.Text.Trim.ToDouble <> 0 Then
Alert("Verifique los cargos y abonos de los movimientos", TipoMensaje.MsgAdvertencia)
ElseIf HdnlCargo.Value.ToDouble <> LblCargo.Text.ToDouble Then
Alert("El cargo de la póliza " + HdnlCargo.Value + " no coincide con la sumatoria de cargos de los movimientos", TipoMensaje.MsgAdvertencia)
ElseIf HdnlAbono.Value.ToDouble <> LblAbono.Text.ToDouble Then
Alert("El abono de la póliza " + HdnlAbono.Value + " no coincide con la sumatoria de abonos de los movimientos", TipoMensaje.MsgAdvertencia)
End If
RegistraScript("PrendeGVS();") 'Aseguramos que se cargue el gridViewScroll
CargaGrid()
UpTitulos.Update()
UpDatos.Update()
If DT IsNot Nothing Then DT.Dispose()
End Sub
Private Sub GuardaPoliza()
Dim OcurrioError As Boolean = False
Dim ObjConta As New ClsContabilidad
ObjConta.IniciaTransacSQL()
Dim tCvePoliza As Integer
Dim NumPoliza As String = TxtNumeroPoliza.Text.Trim
Dim Tipo As String = ""
If Not TxtNumeroPoliza.Text.Trim <> "" Then
Tipo = "CHQ"
End If
tCvePoliza = ObjConta.AddPoliza(DdlTipoPoliza.SelectedValue.ToEntero, NumPoliza.ToEntero, TxtFechaPoliza.Text.Trim.ToDate, TxtConcepto.Text.Trim, UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa)
If tCvePoliza > 0 Then
'Agrega Movimientos de la poliza
For Each Row As DataRow In TmpDT.Rows
If Row("Cargo").ToString.ToDecimal <> 0 Then
If Not ObjConta.AddPolizaDetalle(tCvePoliza, Row("CveCuenta").ToString.ToEntero, Row("Cuenta").ToString, Row("CveSubProyecto").ToString.ToEntero, False,
Row("Cargo").ToString.ToDouble, Row("Referencia").ToString, Row("Concepto").ToString,
TxtFechaPoliza.Text.Trim.ToDate) Then
OcurrioError = True
End If
Else
If Not ObjConta.AddPolizaDetalle(tCvePoliza, Row("CveCuenta").ToString.ToEntero, Row("Cuenta").ToString, Row("CveSubProyecto").ToString.ToEntero, True,
Row("Abono").ToString.ToDouble, Row("Referencia").ToString, Row("Concepto").ToString,
TxtFechaPoliza.Text.Trim.ToDate) Then
OcurrioError = True
End If
End If
Next
If DtDevoluciones IsNot Nothing AndAlso DtDevoluciones.Rows.Count > 0 Then
'Agrega Devoluciones
For Each row As DataRow In DtDevoluciones.Rows
If Not ObjConta.AddDevolucionesIVA(tCvePoliza, row("IdCuenta").ToString.ToEntero, row("IdProveedor").ToString.ToEntero, row("Tasa").ToString.ToDouble, row("ImporteBase").ToString.ToDouble,
row("ImporteIVA").ToString.ToDouble, row("RetIVA").ToString.ToDouble, row("RetISR").ToString.ToDouble, TxtFechaPoliza.Text.ToDate, row("Referencia").ToString, row("Serie").ToString, row("Folio").ToString.ToEntero, "") Then
OcurrioError = True
End If
Next
End If
If Not OcurrioError Then
If Not ObjConta.AjustaPoliza(tCvePoliza) Then
OcurrioError = True
End If
End If
If OcurrioError Then
ObjConta.RollBack()
Alert("Ocurrió un error al guardar la póliza.", TipoMensaje.MsgAdvertencia)
Else
ObjConta.Commit()
CvePoliza = tCvePoliza
Limpia()
CargaDatos(CvePoliza)
BtnNuevo.OnClientClick = ""
Alert(String.Format("La información se guardó correctamente con el numero de póliza: {0}", ObjConta.ContaFolio), TipoMensaje.MsgInformacion)
End If
End If
UpTitulos.Update()
UpDatos.Update()
UpConsultar.Update()
ObjConta.Dispose()
End Sub
Private Sub AddRegPolizaDetalle(CvePoliza As Integer, Referencia As String, CveCuenta As Integer, Cuenta As String, CveSubProyecto As String, SubProyecto As String, NombreConcepto As String, Cargo As Double, Abono As Double)
Dim Row As DataRow = Nothing
Row = TmpDT.NewRow()
Row("CvePoliza") = CvePoliza
Row("Referencia") = Referencia
Row("CveCuenta") = CveCuenta
Row("Cuenta") = Cuenta
Row("CtaCodigo") = Cuenta
Row("CveSubProyecto") = CveSubProyecto
Row("SubProyecto") = SubProyecto
Row("Concepto") = NombreConcepto
Row("Estado") = "I"
Row("Cargo") = Cargo
Row("Abono") = Abono
TmpDT.Rows.Add(Row)
CargaGrid()
End Sub
Private Sub ActualizaPoliza()
Dim OcurrioError As Boolean = False
Dim ObjConta As New ClsContabilidad
Dim Row As DataRow
ObjConta.IniciaTransacSQL()
If ObjConta.UpdatePoliza(TxtFechaPoliza.Text.Trim.ToDate, TxtNumeroPoliza.Text.ToEntero, CvePoliza.ToString.ToEntero, TxtConcepto.Text.Trim, DdlTipoPoliza.SelectedValue.ToEntero) Then
For Each Row In TmpDT.Rows
If Row("Estado").ToString.Trim = "D" AndAlso Row("CvePolizaDetalle").ToString.ToEntero > 0 Then
ObjConta.RemovePolizaDetalle(Row("CvePolizaDetalle").ToString.ToEntero)
Else
Dim Importe As Double = If(Row("Cargo").ToString.ToDouble <> 0, Row("Cargo"), Row("Abono")).ToString.ToDouble
Dim ImporteME As Double = If(Row("CargoME").ToString.ToDouble <> 0, Row("CargoME"), Row("AbonoME")).ToString.ToDouble
Dim TipoMovto As Boolean = Not Row("Cargo").ToString.ToDouble <> 0
If Row("CvePolizaDetalle").ToString.ToEntero > 0 Then
If Not ObjConta.UpdatePolizaDetalle(Row("CvePolizaDetalle").ToString.ToEntero, Row("CveCuenta").ToString.ToEntero, Row("CveSubProyecto").ToString.ToEntero, TipoMovto, Importe, Row("Referencia").ToString, Row("Concepto").ToString) Then
OcurrioError = True
End If
Else
If Not ObjConta.AddPolizaDetalle(CvePoliza.ToString.ToEntero, Row("CveCuenta").ToString.ToEntero, Row("Cuenta").ToString, Row("CveSubProyecto").ToString.ToEntero, TipoMovto, Importe, Row("Referencia").ToString, Row("Concepto").ToString, TxtFechaPoliza.Text.Trim.ToDate) Then
OcurrioError = True
End If
End If
End If
Next
If OcurrioError Then
ObjConta.RollBack()
Alert("Ocurrió un error al actualizar los movimientos de la póliza", TipoMensaje.MsgAdvertencia)
Else
Alert("La póliza se actualizó correctamente.", TipoMensaje.MsgInformacion)
ObjConta.Commit()
HdnFechaPoliza.Value = TxtFechaPoliza.Text.ToDate.ToShortDateString
HdnTipoPoliza.Value = DdlTipoPoliza.SelectedValue
CargaDatos(CvePoliza)
BtnNuevo.OnClientClick = ""
End If
Else
ObjConta.RollBack()
End If
ObjConta.Dispose()
End Sub
#End Region
Private Sub Limpia()
HdnCveCuenta.Value = ""
HdnlAbono.Value = ""
HdnlCargo.Value = ""
LblDiferencia.Text = ""
DtDevoluciones = Nothing
GvDevoluciones.DataBind()
End Sub
#Region "G R I D - V I E W"
Protected Sub GvDevoluciones_RowDataBound(sender As Object, e As GridViewRowEventArgs) Handles GvDevoluciones.RowDataBound
If e.Row.RowType = DataControlRowType.DataRow Then
If e.Row.RowState = DataControlRowState.Edit OrElse e.Row.RowState = 5 Then
e.Row.FCDropDownList("DdlProveedor").SelectedIndex = -1
e.Row.FCDropDownList("DdlProveedor").DataSource = DtProveedoresConta
e.Row.FCDropDownList("DdlProveedor").DataBind()
e.Row.FCDropDownList("DdlProveedor").SelectedValueExist(e.Row.DataKey("IdProveedor"))
e.Row.FCTextBox("TxtImporteBase").Attributes.Add("onkeyup", String.Format("FormatoMoneda(this);CalculaImporteIVA({0},{1},{2});CalculaImporteSinRet({0},{2},{3});CalculaTotalErogacion({3},{4},{5},{6});", e.Row.FCTextBox("TxtImporteBase").ClientID, e.Row.FCDropDownList("DdlTasa").ClientID, e.Row.FCTextBox("TxtImporteIVA").ClientID, e.Row.FCLabel("LbImporteSinRet").ClientID, e.Row.FCTextBox("TxtRetIVA").ClientID, e.Row.FCTextBox("TxtRetISR").ClientID, e.Row.FCLabel("LbGranTotalAdd").ClientID))
e.Row.FCTextBox("TxtImporteIVA").Attributes.Add("onkeyup", String.Format("FormatoMoneda(this);CalculaImporteSinRet({0},{2},{3});CalculaTotalErogacion({3},{4},{5},{6});", e.Row.FCTextBox("TxtImporteBase").ClientID, e.Row.FCDropDownList("DdlTasa").ClientID, e.Row.FCTextBox("TxtImporteIVA").ClientID, e.Row.FCLabel("LbImporteSinRet").ClientID, e.Row.FCTextBox("TxtRetIVA").ClientID, e.Row.FCTextBox("TxtRetISR").ClientID, e.Row.FCLabel("LbGranTotalAdd").ClientID))
e.Row.FCTextBox("TxtRetIVA").Attributes.Add("onkeyup", String.Format("FormatoMoneda(this);CalculaTotalErogacion({3},{4},{5},{6});", e.Row.FCTextBox("TxtImporteBase").ClientID, e.Row.FCDropDownList("DdlTasa").ClientID, e.Row.FCTextBox("TxtImporteIVA").ClientID, e.Row.FCLabel("LbImporteSinRet").ClientID, e.Row.FCTextBox("TxtRetIVA").ClientID, e.Row.FCTextBox("TxtRetISR").ClientID, e.Row.FCLabel("LbGranTotalAdd").ClientID))
e.Row.FCTextBox("TxtRetISR").Attributes.Add("onkeyup", String.Format("FormatoMoneda(this);CalculaTotalErogacion({3},{4},{5},{6});", e.Row.FCTextBox("TxtImporteBase").ClientID, e.Row.FCDropDownList("DdlTasa").ClientID, e.Row.FCTextBox("TxtImporteIVA").ClientID, e.Row.FCLabel("LbImporteSinRet").ClientID, e.Row.FCTextBox("TxtRetIVA").ClientID, e.Row.FCTextBox("TxtRetISR").ClientID, e.Row.FCLabel("LbGranTotalAdd").ClientID))
End If
End If
End Sub
Protected Sub GvDevoluciones_RowCancelingEdit(sender As Object, e As GridViewCancelEditEventArgs) Handles GvDevoluciones.RowCancelingEdit
GvDevoluciones.EditIndex = -1
CargaGridDevoluciones("", 0)
UpDevoluciones.Update()
End Sub
'Protected Sub GvDevoluciones_RowDeleting(sender As Object, e As GridViewDeleteEventArgs) Handles GvDevoluciones.RowDeleting
' Dim ErrorEliminar = False
' If CvePoliza > 0 Then
' Dim ObjConta As New ClsContabilidad
' If Not ObjConta.RemoveDevolucionesIVA(e.Keys("Id").ToString.ToEntero) Then
' ErrorEliminar = True
' End If
' ObjConta.Dispose()
' CargaDevoluciones()
' Else
' DtDevoluciones.Rows().RemoveAt(e.Keys("Id").ToString.ToEntero - 1)
' CargaGridDevoluciones("", 0)
' End If
' If Not ErrorEliminar Then
' Alert("La Devolución fue eliminada correctamente.", TipoMensaje.MsgInformacion)
' Else
' Alert("Ocurrió un error al eliminar la Devolución", TipoMensaje.MsgError)
' End If
'End Sub
Protected Sub GvDevoluciones_RowEditing(sender As Object, e As GridViewEditEventArgs) Handles GvDevoluciones.RowEditing
GvDevoluciones.EditIndex = e.NewEditIndex
CargaGridDevoluciones("", 0)
End Sub
'Protected Sub GvDevoluciones_RowUpdating(sender As Object, e As GridViewUpdateEventArgs) Handles GvDevoluciones.RowUpdating
' Dim ErrorDevolucion = False
' If CvePoliza > 0 Then
' Dim gvr As GridViewRow = GvDevoluciones.Rows(e.RowIndex)
' Dim ObjConta As New ClsContabilidad
' If ObjConta.UpdateDevolucionesIVA(gvr.DataKey("Id").ToEntero, CvePoliza, DdlCuenta.SelectedValue.ToEntero,
' gvr.FCDropDownList("DdlProveedor").SelectedValue.ToEntero, gvr.FCDropDownList("DdlTasa").SelectedValue.ToDouble,
' gvr.FCTextBox("TxtImporteBase").Text.ToDouble, gvr.FCTextBox("TxtImporteIVA").Text.ToDouble,
' gvr.FCTextBox("TxtRetIVA").Text.ToDouble, gvr.FCTextBox("TxtRetISR").Text.ToDouble, Date.Now,
' gvr.FCTextBox("TxtReferenciaDevolucion").Text, gvr.FCTextBox("TxtSerie").Text, gvr.FCTextBox("TxtFolio").Text.ToEntero) Then
' Alert("Devolución Actualizada con Éxito", TipoMensaje.MsgInformacion)
' Else
' Alert("Ocurrió un error al Actualizar la Devolución", TipoMensaje.MsgError)
' ErrorDevolucion = True
' End If
' ObjConta.Dispose()
' If Not ErrorDevolucion Then
' GvDevoluciones.EditIndex = -1
' CargaDevoluciones()
' End If
' Else
' Dim row() = DtDevoluciones.Select(String.Format("Id = {0}", e.Keys("Id")))
' row(0)("IdProveedor") = GvDevoluciones.Rows(e.RowIndex).FCDropDownList("DdlProveedor").SelectedValue
' row(0)("Tasa") = GvDevoluciones.Rows(e.RowIndex).FCDropDownList("DdlTasa").SelectedValue
' row(0)("ImporteBase") = GvDevoluciones.Rows(e.RowIndex).FCTextBox("TxtImporteBase").Text
' row(0)("ImporteIVA") = GvDevoluciones.Rows(e.RowIndex).FCTextBox("TxtImporteIVA").Text
' row(0)("RetIVA") = GvDevoluciones.Rows(e.RowIndex).FCTextBox("TxtRetIVA").Text
' row(0)("RetISR") = GvDevoluciones.Rows(e.RowIndex).FCTextBox("TxtRetISR").Text
' row(0)("Referencia") = GvDevoluciones.Rows(e.RowIndex).FCTextBox("TxtReferenciaDevolucion").Text
' row(0)("Serie") = GvDevoluciones.Rows(e.RowIndex).FCTextBox("TxtSerie").Text
' row(0)("Folio") = GvDevoluciones.Rows(e.RowIndex).FCTextBox("TxtFolio").Text
' row(0)("Proveedor") = GvDevoluciones.Rows(e.RowIndex).FCDropDownList("DdlProveedor").SelectedItem.Text
' row(0)("ImporteAntesRet") = GvDevoluciones.Rows(e.RowIndex).FCTextBox("TxtImporteBase").Text.ToDouble + GvDevoluciones.Rows(e.RowIndex).FCTextBox("TxtImporteIVA").Text.ToDouble
' row(0)("GranTotal") = row(0)("ImporteAntesRet").ToString.ToDouble - GvDevoluciones.Rows(e.RowIndex).FCTextBox("TxtRetIVA").Text.ToDouble - GvDevoluciones.Rows(e.RowIndex).FCTextBox("TxtRetISR").Text.ToDouble
' GvDevoluciones.EditIndex = -1
' CargaGridDevoluciones("", 0)
' End If
'End Sub
#End Region
#Region "D E V O L U C I O N E S - I V A"
Protected Sub LbAgregarDevolucion_Click(sender As Object, e As EventArgs)
' Dim ErrorDevolucion = False
' If CvePoliza > 0 Then
' Dim ObjConta As New ClsContabilidad
' If ObjConta.AddDevolucionesIVA(CvePoliza, DdlCuenta.SelectedValue.ToEntero, DdlProveedor.SelectedValue.ToEntero, DdlTasa.SelectedValue.ToDouble, TxtImporteBase.Text.ToDouble, TxtImporteIVA.Text.ToDouble,
' TxtRetIVA.Text.ToDouble, TxtRetISR.Text.ToDouble, TxtFechaPoliza.Text.ToDate, TxtReferenciaDevolucion.Text, TxtSerie.Text, TxtFolio.Text.ToEntero, "") Then
' Alert("Devolución Agregada con Éxito", TipoMensaje.MsgInformacion)
' Else
' ErrorDevolucion = True
' Alert("Ocurrió un error al agregar la Devolución", TipoMensaje.MsgAdvertencia)
' End If
' ObjConta.Dispose()
' If Not ErrorDevolucion Then
' CargaDevoluciones()
' End If
' Else
' Dim row = DtDevoluciones.NewRow
' row("ID") = (DtDevoluciones.Rows.Count + 1).ToString
' row("IdProveedor") = DdlProveedor.SelectedValue
' row("Tasa") = DdlTasa.SelectedValue
' row("ImporteBase") = TxtImporteBase.Text
' row("ImporteIVA") = TxtImporteIVA.Text
' row("RetIVA") = TxtRetIVA.Text
' row("RetISR") = TxtRetISR.Text
' row("Referencia") = TxtReferenciaDevolucion.Text
' row("Serie") = TxtSerie.Text
' row("Folio") = TxtFolio.Text
' row("Proveedor") = DdlProveedor.SelectedItem.Text
' row("ImporteAntesRet") = TxtImporteBase.Text.ToDouble + TxtImporteIVA.Text.ToDouble
' row("GranTotal") = row("ImporteAntesRet").ToString.ToDouble - TxtRetIVA.Text.ToDouble - TxtRetISR.Text.ToDouble
' DtDevoluciones.Rows.Add(row)
' CargaGridDevoluciones("", 0)
' End If
' LimpiaDevoluciones()
End Sub
Protected Sub LbAgregarCausacion_Click(sender As Object, e As EventArgs)
' Dim ErrorDevolucion = False
' If CvePoliza > 0 Then
' Dim ObjConta As New ClsContabilidad
' Dim TotalTasa16 As Double = TxtImporteTotalC.Text.ToDouble
' Dim BaseTasa16 As Double = TxtImporteBaseC.Text.ToDouble
' Dim IVATasa16 As Double = TxtIVAC.Text.ToDouble
' Dim IVATasaNoAcreditable As Double = TxtIvaNoAcreditableC.Text.ToDouble
' Dim ISRRetenido As Double = TxtISRRetenidoC.Text.ToDouble
' Dim IVARetenido As Double = TxtIVARetenidoC.Text.ToDouble
' Dim ietu As Double = TxtIETU.Text.ToDouble
' Dim cuenta As String
' Dim CuentasConcatenadas As New StringBuilder
' Dim importeMaximo As Double
' If DrParametros IsNot Nothing Then
' cuenta = DrParametros("CtaFlujo").ToString
' ObjConta.GetCuentasCausaciones(cuenta)
' For Each row As DataRow In ObjConta.DtResultados.Rows
' Dim ct As String = row("IdSubCtade").ToString
' CuentasConcatenadas.AppendFormat("{0},", ct)
' Next
' End If
' importeMaximo = TmpDT.SUM("Cargo", String.Format("CveCuenta IN ( {0} )", CuentasConcatenadas.ToString.TrimEnd(","c))).ToString.ToDecimal
' If LbAgregarCausacion.Text = "Agregar" And importeMaximo = TotalTasa16 Then
' If ObjConta.AddCausacionesIVA(CvePoliza, TotalTasa16, BaseTasa16, IVATasa16, IVATasaNoAcreditable, ISRRetenido, IVARetenido, ChkNoCausar.Checked, IETU:=ietu) Then
' Alert("El movimiento se realizó correctamente", TipoMensaje.MsgInformacion)
' End If
' ElseIf LbAgregarCausacion.Text = "Actualizar" And importeMaximo = TotalTasa16 Then
' If ObjConta.UpdateCausacionesIVA(CvePoliza, TotalTasa16, BaseTasa16, IVATasa16, IVATasaNoAcreditable, ISRRetenido, IVARetenido, ChkNoCausar.Checked, ietu:=ietu) Then
' Alert("El movimiento se realizó correctamente", TipoMensaje.MsgInformacion)
' End If
' Else
' Alert("El importe total desglosado con coincide con el importe de la cuenta de flujo de efectivo", TipoMensaje.MsgAdvertencia)
' End If
' ObjConta.Dispose()
' End If
' CargaCausaciones()
End Sub
Private Sub LimpiaDevoluciones()
TxtSerie.Text = ""
TxtFolio.Text = ""
TxtReferenciaDevolucion.Text = ""
TxtImporteBase.Text = ""
TxtImporteIVA.Text = ""
TxtRetIVA.Text = ""
TxtRetISR.Text = ""
DdlProveedor.SelectedValue = "-1"
TxtSerie.Focus()
End Sub
'Private Sub CargaDevoluciones()
' If CvePoliza > 0 Then
' Dim ObjConta As New ClsContabilidad
' PnlDevIVA.Visible = True
' If ObjConta.GetDevolucionesIVA(-1, CvePoliza) Then
' DtDevoluciones = ObjConta.DtResultados
' Else
' DtDevoluciones = Nothing
' Alert("Ocurrió un error al cargar Devoluciones", TipoMensaje.MsgError)
' End If
' If DtDevoluciones IsNot Nothing Then
' CargaGridDevoluciones("", 0)
' DdlCuenta.SelectedValueExist(DtDevoluciones.MAX("CveCuenta"))
' End If
' ObjConta.Dispose()
' Else
' CreaDtDevoluciones()
' End If
'End Sub
'Private Sub CargaCausaciones()
' If CvePoliza > 0 Then
' Dim ObjConta As New ClsContabilidad
' PnlCauIVA.Visible = True
' If ObjConta.GetCausacionesIVA(-1, CvePoliza) Then
' If ObjConta.DtResultados IsNot Nothing AndAlso ObjConta.DtResultados.Rows.Count > 0 Then
' TxtImporteTotalC.Text = ObjConta.DtResultados.Rows(0)("ImporteTotal").ToString
' TxtImporteBaseC.Text = ObjConta.DtResultados.Rows(0)("ImporteBase").ToString
' TxtIVAC.Text = ObjConta.DtResultados.Rows(0)("IVA").ToString
' TxtIvaNoAcreditableC.Text = ObjConta.DtResultados.Rows(0)("IVANoAcreditable").ToString
' lblEjercicioTexto.Text = ObjConta.DtResultados.Rows(0)("Año").ToString
' LblPeriodoTexto.Text = StrConv(MonthName(ObjConta.DtResultados.Rows(0)("Mes").ToString.ToEntero, False), VbStrConv.ProperCase)
' TxtIVARetenidoC.Text = ObjConta.DtResultados.Rows(1)("ImporteTotal").ToString
' TxtISRRetenidoC.Text = ObjConta.DtResultados.Rows(2)("ImporteTotal").ToString
' LblTotalImporte.Text = ObjConta.DtResultados.Rows(3)("ImporteTotal").ToString
' LblTotalBase.Text = ObjConta.DtResultados.Rows(3)("ImporteBase").ToString
' LblTotalIVA.Text = ObjConta.DtResultados.Rows(3)("IVA").ToString
' LblTotalIvaNoAcreditable.Text = ObjConta.DtResultados.Rows(3)("IVANoAcreditable").ToString
' TxtIETU.Text = ObjConta.DtResultados.Rows(3)("ImporteBase").ToString
' If ObjConta.DtResultados.Rows(0)("NoCausar").ToString = "True" Then
' ChkNoCausar.Checked = True
' Else
' ChkNoCausar.Checked = False
' End If
' If TxtImporteTotalC.Text <> "" Then
' LbAgregarCausacion.Text = "Actualizar"
' End If
' End If
' Else
' Alert("Ocurrió un error al cargar Causaciones", TipoMensaje.MsgError)
' End If
' ObjConta.Dispose()
' End If
'End Sub
Private Sub CreaDtDevoluciones()
DtDevoluciones = New DataTable
DtDevoluciones.Columns.Add("IdProveedor", GetType(Integer))
DtDevoluciones.Columns.Add("Tasa", GetType(String))
DtDevoluciones.Columns.Add("ImporteBase", GetType(Double))
DtDevoluciones.Columns.Add("ImporteIVA", GetType(Double))
DtDevoluciones.Columns.Add("RetIVA", GetType(Double))
DtDevoluciones.Columns.Add("RetISR", GetType(Double))
DtDevoluciones.Columns.Add("Referencia", GetType(String))
DtDevoluciones.Columns.Add("Serie", GetType(String))
DtDevoluciones.Columns.Add("Folio", GetType(String))
DtDevoluciones.Columns.Add("Id", GetType(Integer))
DtDevoluciones.Columns.Add("Proveedor", GetType(String))
DtDevoluciones.Columns.Add("ImporteAntesRet", GetType(Double))
DtDevoluciones.Columns.Add("GranTotal", GetType(Double))
End Sub
#End Region
Protected Sub LBDevIVA_Click(sender As Object, e As EventArgs)
' UpDevoluciones.Update()
' RegistraScript("$get('divDevIVA').style.display='';")
' Dim cont As New ClsContabilidad
' If cont.GetProveedores() Then
' DtProveedoresConta = cont.DtResultados
' DdlProveedor.DataSource = DtProveedoresConta
' DdlProveedor.DataBind()
' DdlProveedor.Items.Insert(0, New ListItem("Seleccione uno", "-1"))
' Else
' DtProveedoresConta = Nothing
' Alert("Ocurrió un error al cargar los Proveedores. Por favor recargue la página.", TipoMensaje.MsgError)
' End If
' cont.Dispose()
' DdlCuenta.DataSource = DTCuentas
' DdlCuenta.DataBind()
' CargaDevoluciones()
End Sub
Protected Sub LBCauIVA_Click(sender As Object, e As EventArgs)
' UpCausaciones.Update()
' RegistraScript("$get('divCauIVA').style.display='';")
' CargaCausaciones()
End Sub
Protected Sub DdlTipoPoliza_SelectedIndexChanged(sender As Object, e As EventArgs)
RegistraScript("ApagaGVS();")
SiguienteFolio()
End Sub
Private Sub SiguienteFolio()
Dim ObjConta As New ClsContabilidad
Dim NumPoliza As Integer = 0
If ObjConta.GetNumeroPoliza(DdlTipoPoliza.SelectedValue.ToEntero, "", TxtFechaPoliza.Text.ToDate, UsuarioActual.CveEmpresa) Then
NumPoliza = ObjConta.DtResultados(0)("NumPoliza").ToString.ToEntero
If NumPoliza > 0 Then
TxtNumeroPoliza.Text = NumPoliza.ToString
Else
Alert("Ocurrió un error al obtener el número de póliza. Por favor recargue la página", TipoMensaje.MsgError)
End If
End If
ObjConta.Dispose()
UpTitulos.Update()
End Sub
#Region " ELIMINAR POLIZA "
Protected Sub BtnEliminar_Click(sender As Object, e As EventArgs)
Dim ObjConta As New ClsContabilidad
ObjConta.IniciaTransacSQL()
Dim ObjMov As New ClsContabilidad()
If ObjConta.RemovePoliza(CvePoliza) Then
If ObjMov.DesvincularPrePolizaContabilizada(CvePoliza, UsuarioActual.CveEmpresa) Then
ObjConta.Commit()
Alert("La Póliza fue eliminada correctamente.", TipoMensaje.MsgInformacion)
BtnNuevo_Click(BtnNuevo, EventArgs.Empty)
Else
ObjConta.RollBack()
Alert("Ocurrió un error al eliminar la Póliza. Por favor vuelva a intentar.", TipoMensaje.MsgError)
End If
Else
ObjConta.RollBack()
Alert("Ocurrió un error al eliminar la Póliza. Por favor vuelva a intentar.", TipoMensaje.MsgError)
End If
ObjConta.Dispose()
End Sub
#End Region
End Class