Option Explicit On
Option Strict On
Imports System.Data
Imports System.Drawing
Imports Extensiones
'Imports System.Activities.Statements
'Imports msExcel = Microsoft.Office.Interop.Excel
'Imports VBIDE
Partial Class RegPoliza
Inherits ClsPaginas
#Region "P R O P E R T Y"
Private Property NumRow As Integer
Private Property IDPoliza As Integer
Get
Return CType(ViewState("IDPoliza"), Integer)
End Get
Set(value As Integer)
ViewState("IDPoliza") = value
End Set
End Property
Private Property CvePrePoliza As Integer
Get
Return CType(ViewState("CvePrePoliza"), Integer)
End Get
Set(value As Integer)
ViewState("CvePrePoliza") = 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 RemoveMovimientos As New ArrayList()
' Get
' Return CType(ViewState("RemoveMovimientos"), ArrayList())
' End Get
' Set(value As ArrayList())
' ViewState("RemoveMovimientos") = 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
Private Property FechaPolizaOld As String
Get
Return CType(ViewState("FechaPolizaOld"), String)
End Get
Set(value As String)
ViewState("FechaPolizaOld") = value
End Set
End Property
Private Property TipoPolizaOld As String
Get
Return CType(ViewState("TipoPolizaOld"), String)
End Get
Set(value As String)
ViewState("TipoPolizaOld") = value
End Set
End Property
Private Property ConceptoOld As String
Get
Return CType(ViewState("ConceptoOld"), String)
End Get
Set(value As String)
ViewState("ConceptoOld") = value
End Set
End Property
Private Property DT As DataTable
Get
Return CType(ViewState("DT"), DataTable)
End Get
Set(value As DataTable)
ViewState("DT") = value
End Set
End Property
#End Region
Protected Sub Page_Load(sender As Object, e As EventArgs) Handles Me.LoadComplete
If Not IsPostBack Then
If UsuarioActual.Empresa.TipoContabilizacion = 1 OrElse UsuarioActual.Empresa.TipoContabilidad = 1 Then
Response.Redirect("/Contabilidad/RegPrePolizaS.aspx")
End If
ViewState("Orden0") = ""
ViewState("Orden1") = ""
CvePrePoliza = -1
Me.Form.DefaultButton = BtnConsultar.UniqueID
TxtFecha.Text = NowADS().ToShortDateString
TxtFechaPoliza.Text = NowADS().ToShortDateString
If UsuarioActual.Empresa.UsaAC Then
Else
tdPolizaComplementaria.Visible = True
End If
If UsuarioActual.Empresa.UsaContabilidad Then
Dim ObjConta As New ClsContPAQi(UsuarioActual.Empresa)
If ObjConta.GetTiposPoliza(-1, "-1") Then
DdlTipo.DataSource = ObjConta.DtResultados
DdlTipo.DataBind()
DdlTipoPoliza.DataSource = ObjConta.DtResultados
DdlTipoPoliza.DataBind()
End If
If ObjConta.GetCuentas(-1, "-1", 1) Then
DTCuentas = ObjConta.DtResultados
End If
If ObjConta.GetSegmentosNegocio(-1, "-1") Then
DTSegmentosNegocio = ObjConta.DtResultados
Dim dr As DataRow = DTSegmentosNegocio.NewRow
dr("Id") = "0"
dr("Codigo") = ""
dr("Nombre") = ""
DTSegmentosNegocio.Rows.InsertAt(dr, 0)
DdlSegNeg.DataSource = DTSegmentosNegocio
DdlSegNeg.DataBind()
End If
If ObjConta.GetParametros() 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()
Else
Alert("Este módulo requiere el uso de Contabilidad.", TipoMensaje.MsgAdvertencia)
BtnConsultar.Enabled = False
BtnGuardar.Visible = False
BtnNuevo.Visible = False
LbAgregar.Enabled = False
HlAgregarExcel.Visible = False
HLImprimir.Visible = False
LBDevIVA.Visible = False
LBCauIVA.Visible = False
End If
LblAbono.Text = "0.00"
LblCargo.Text = "0.00"
If TmpDT Is Nothing Then CreaDTRegPoliza()
If Request("IdPoliza") IsNot Nothing AndAlso Request("IdPoliza").ToEntero() > 0 Then
ChkPolizaComplementaria.Enabled = False
IDPoliza = Request("IdPoliza").ToEntero()
'CveEmpresa = Request("CveEmpresa").ToEntero()
'ViewState("Empresa") = If(Request("Empresa") IsNot Nothing, Request("Empresa"), EmpresaActual)
limpia()
If Request("Opcion") IsNot Nothing AndAlso Request("Opcion").ToString <> "" Then
Opcion = Request("Opcion").ToString
End If
'btnImprimir.OnClientClick = "javascript:PrintPoliza('/Direccion/EdosFinancieros/PopUpImpPoliza.aspx?Empresa=" & Request("Empresa") & "&IdPoliza=" & Request("IdPoliza") & "', 900, 800); return false;"
If Opcion = "Com" Then
CargaPolizaComplementaria(IDPoliza)
Else
CargaDatos(IDPoliza, -1, -1, -1, -1)
tdPolizaComplementaria.Visible = False
End If
Else
TxtFechaPoliza.Text = NowADS().ToShortDateString
IDPoliza = -1
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("Id", GetType(Integer))
TmpDT.Columns.Add("NumMovto", GetType(Integer))
TmpDT.Columns.Add("Referencia", GetType(String))
TmpDT.Columns.Add("IdCuenta", GetType(Integer))
TmpDT.Columns.Add("CuentaFormato", GetType(String))
TmpDT.Columns.Add("Cuenta", GetType(String))
TmpDT.Columns.Add("CtaCodigo", GetType(String))
TmpDT.Columns.Add("IdSegNeg", GetType(Integer))
TmpDT.Columns.Add("SegNeg", GetType(String))
TmpDT.Columns.Add("Concepto", 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("Estado", GetType(String))
TmpDT.Columns.Add("Folio", GetType(Integer))
TmpDT.Columns.Add("SIGReferencia", GetType(String))
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()
'upDatos.Update()
End Sub
Protected Sub GvDatos_RowDataBound(sender As Object, e As GridViewRowEventArgs) Handles GvDatos.RowDataBound
If e.Row.RowType = DataControlRowType.DataRow Then
'e.Row.Cells(0).Width = Unit.Percentage(5) '.Pixel(50) 'No 43
'e.Row.Cells(1).Width = Unit.Percentage(5) '.Pixel(50) 'Referencia 90
'e.Row.Cells(2).Width = Unit.Percentage(25) '.Pixel(200) 'Cuenta 230
'e.Row.Cells(3).Width = Unit.Percentage(5) '.Pixel(50) 'SegNeg 90
'e.Row.Cells(4).Width = Unit.Percentage(20) '.Pixel(200) 'Nombre/Concepto 250
'e.Row.Cells(5).Width = Unit.Percentage(10) '.Pixel(100) 'Cargo 80
'e.Row.Cells(6).Width = Unit.Percentage(10) '.Pixel(100) 'Abono 80
'e.Row.Cells(7).Width = Unit.Percentage(10) '.Pixel(150) 'Editar 100
'e.Row.Cells(8).Width = Unit.Percentage(10) '.Pixel(50) 'Eliminar 50
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")
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
e.Row.FCLiteral("LtlNo").Text = (e.Row.RowIndex + 1).ToString ' e.Row.DBCampo("IdConsec") '
If e.Row.RowState = DataControlRowState.Edit OrElse e.Row.RowState = 5 Then
e.Row.FCDropDownList("DdlCuenta").DataSource = DTCuentas
e.Row.FCDropDownList("DdlCuenta").DataBind()
e.Row.FCDropDownList("DdlCuenta").SelectedValue = e.Row.DBCampo("IdCuenta")
e.Row.FCDropDownList("DdlSegNeg").DataSource = DTSegmentosNegocio
e.Row.FCDropDownList("DdlSegNeg").DataBind()
e.Row.FCDropDownList("DdlSegNeg").SelectedValue = e.Row.DBCampo("IdSegNeg")
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")))
'TmpDT.Rows.Remove(Dr(0))
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)("IdCuenta") = GvDatos.Rows(e.RowIndex).FCDropDownList("DdlCuenta").SelectedValue
dr(0)("CtaCodigo") = GvDatos.Rows(e.RowIndex).FCDropDownList("DdlCuenta").SelectedItem.Text
dr(0)("CuentaFormato") = GvDatos.Rows(e.RowIndex).FCDropDownList("DdlCuenta").SelectedItem.Text
dr(0)("IdSegNeg") = GvDatos.Rows(e.RowIndex).FCDropDownList("DdlSegNeg").SelectedValue
dr(0)("SegNeg") = 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("Id"), 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
'If gvi = 1 Then
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
'End If
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, TxtFecha.Text.Trim.ToDate.Year, TxtFecha.Text.Trim.ToDate.Month, DdlTipo.SelectedValue.ToEntero, 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)
'BtnGuardar.Attributes.Add("onClientClicked", "javascript:confirm('¿La suma de los CARGOS no coincide con la suma de los ABONOS, ¿Desea guardar la información?')")
Exit Sub
End If
BtnGuardar.OnClientClick = "FncVerifica();"
If ChkPolizaComplementaria.Checked Then
If IDPoliza < 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 IDPoliza < 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
DdlTipo.SelectedIndex = 0
TxtFecha.Text = ""
TxtNumero.Text = ""
TxtFechaPoliza.Text = ""
TxtNumeroPoliza.Text = ""
DdlTipoPoliza.SelectedIndex = 0
HdnFechaPoliza.Value = TxtFechaPoliza.Text
HdnFolioPoliza.Value = TxtNumeroPoliza.Text
HdnTipoPoliza.Value = DdlTipoPoliza.SelectedValue
BtnGuardar.OnClientClick = ""
BtnEliminar.Visible = False
IDPoliza = -1
'HdnIdPoliza.Value = ""
TxtConcepto.Text = ""
TxtReferencia.Text = ""
TxtCuenta.Text = ""
HdnCveCuenta.Value = ""
DdlSegNeg.SelectedIndex = 0
TxtNombreConcepto.Text = ""
TxtCargo.Text = ""
TxtAbono.Text = ""
LblCargo.Text = "0.00"
LblAbono.Text = "0.00"
'Llenagrid()
GvDatos.DataBind()
UpConsultar.Update()
upTitulos.Update()
upDatos.Update()
If TmpDT Is Nothing Then CreaDTRegPoliza() Else TmpDT.Rows.Clear()
limpia()
End Sub
'Protected Sub BtnImprimir_Click(sender As Object, e As EventArgs) Handles BtnImprimir.Click
' If TmpDT.Rows.Count = 0 Then
' Alert("Debe consultar una póliza antes de imprimir ...", TipoMensaje.MsgAdvertencia)
' Else
' 'GeneraPDF(NowADS(), "Sin Timbrar", "Sin Timbrar", New Date(1, 1, 1), "Sin Timbrar", TmpDT, "Sin Timbrar", "Sin Timbrar", RutaCBB, If(LblSerie.Text.Trim = String.Empty, TxtFolio.Text.Trim, LblSerie.Text.Trim & "-" & TxtFolio.Text.Trim), "", True, False)
' GeneraPDF()
' End If
'End Sub
Protected Sub LBImprimir_Click(sender As Object, e As EventArgs)
'If TmpDT.Rows.Count = 0 Then
' Alert("Debe consultar una póliza antes de imprimir ...", TipoMensaje.MsgAdvertencia)
'Else
' 'GeneraPDF(NowADS(), "Sin Timbrar", "Sin Timbrar", New Date(1, 1, 1), "Sin Timbrar", TmpDT, "Sin Timbrar", "Sin Timbrar", RutaCBB, If(LblSerie.Text.Trim = String.Empty, TxtFolio.Text.Trim, LblSerie.Text.Trim & "-" & TxtFolio.Text.Trim), "", True, False)
' GeneraPDF()
'End If
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, DdlCuenta.SelectedValue, DdlCuenta.SelectedItem.Text, DdlSegNeg.SelectedValue, DdlSegNeg.SelectedItem.Text, TxtNombreConcepto.Text, TxtCargo.Text.ToDouble, TxtAbono.Text.ToDouble)
'HdnCveCuenta
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()
'TxtReferencia.Text = ""
DdlSegNeg.SelectedIndex = 0
'TxtNombreConcepto.Text = ""
TxtCargo.Text = ""
TxtAbono.Text = ""
HdnCveCuenta.Value = ""
TxtCuenta.Text = ""
BtnNuevo.OnClientClick = "return confirm('Se han hecho cambios que no fueron guardados, ¿Continuar?')"
' RegistraScript(" $(function () { $(""#DdlCuenta"").combobox().parent().find(""input.ui-autocomplete-input"").css('width', '175px'); $(""#toggle"").click(function () { $(""#DdlCuenta"").toggle();});});")
End If
End Sub
#End Region
Private Sub CargaGrid()
GvDatos.DataBind()
GvDatos.DataSource = TmpDT '.FiltraParametros("Estado<>'D'")
GvDatos.DataBind()
LblAbono.Text = TmpDT.SUM("Abono", "Estado<>'D'").FormatoNumero
'LblCargo.Text = TmpDT.SUM("Cargo,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
' BtnGuardar.OnClientClick = "return confirm('La suma de los CARGOS no coincide con la suma de los ABONOS, ¿Desea guardar la información?')"
'BtnGuardar.Enabled = False
LblDiferencia.ForeColor = Drawing.Color.Black
Else
'BtnGuardar.OnClientClick = ""
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(tIDPoliza As Integer)
Dim ObjPoliza As New ClsContabilidad
Dim DT As DataTable = Nothing
If ObjPoliza.GetPoliza(tIDPoliza, UsuarioActual.CveEmpresa) Then
DT = ObjPoliza.DtResultados
BtnGuardar.OnClientClick = "FncVerifica();"
ChkPolizaComplementaria.Checked = True
If DT.Rows.Count = 0 Then
TxtFechaPoliza.Text = NowADS().ToShortDateString
TxtNumeroPoliza.Text = ""
LblCargo.Text = ""
LblAbono.Text = ""
TxtConcepto.Text = ""
Alert("No se encontró ninguna póliza, verifique los datos.", TipoMensaje.MsgAdvertencia)
'HdnIdPoliza.Value = ""
Else
'TxtFecha.Text = ""
'TxtNumero.Text = ""
'DdlTipo.SelectedIndex = 0
Dim dr As DataRow = DT.Rows(0)
TxtFechaPoliza.Text = dr("FechaPol").ToString.ToDate.ToShortDateString
HdnFechaPoliza.Value = dr("FechaPol").ToString.ToDate.ToShortDateString
'DdlTipoPoliza.SelectedValue = dr("CodigoTipoPoliza").ToString.Trim
HdnTipoPoliza.Value = DdlTipoPoliza.SelectedValue
'LtlNumeroPoliza.Text = dr("Folio")
TxtNumeroPoliza.Text = dr("Folio").ToString
'HdnIdPoliza.Value = dr("IdPoliza").ToString 'Id de la Póliza lo da automaticamente el sistema ContPAQi
HdnFolioPoliza.Value = dr("Folio").ToString 'Folio de la poliza
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("IdPoliza").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
'TxtFechaPoliza.AutoPostBack = True
'DdlTipoPoliza.AutoPostBack = True
'TxtNumeroPoliza.AutoPostBack = True
IDPoliza = dr("IdPoliza").ToString.ToEntero
' CargaDevoluciones()
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
' ObjConta.IniciaTransacSQL()
' Dim tIdPoliza As Integer
' Dim NumPoliza As String = "-1"
' Dim Tipo As String = ""
' If TxtNumeroPoliza.Text.Trim <> "" Then
' NumPoliza = TxtNumeroPoliza.Text.Trim
' Tipo = "CHQ"
' Else
' End If
' tIdPoliza = ObjConta.AddPoliza(DdlTipoPoliza.SelectedValue.ToEntero, TxtFolio.Text.ToEntero, TxtFechaPoliza.Text.Trim.ToDate, TxtConcepto.Text.Trim, UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa)
' If tIdPoliza > 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(tIdPoliza, Row("IdCuenta").ToString.ToEntero, Row("CuentaFormato").ToString, 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(tIdPoliza, Row("IdCuenta").ToString.ToEntero, Row("CuentaFormato").ToString, 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()
' IDPoliza = tIdPoliza
' limpia()
' CargaPolizaComplementaria(IDPoliza)
' 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(DdlTipoPoliza.SelectedValue.ToEntero, TxtNumeroPoliza.Text.ToEntero, TxtFechaPoliza.Text.Trim.ToDate, TxtConcepto.Text.Trim, UsuarioActual.CveUsuario, IDPoliza) Then
' For Each Row In TmpDT.Rows
' If Row("Estado").ToString.Trim = "D" AndAlso Row("Id").ToString.ToEntero > 0 Then
' ObjConta.RemovePolizaDetalle(Row("Id").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("Id").ToString.ToEntero <> -1 Then
' If Not ObjConta.UpdatePolizaDetalle(Row("Id").ToString.ToEntero, Row("IdCuenta").ToString.ToEntero, If(Row("CuentaFormato").ToString <> "", Row("CuentaFormato").ToString, Row("Cuenta").ToString), TipoMovto, Importe, Row("Referencia").ToString, Row("Concepto").ToString, TxtFechaPoliza.Text.Trim.ToDate) Then
' OcurrioError = True
' End If
' Else
' If Not ObjConta.AddPolizaDetalle(IDPoliza.ToString.ToEntero, Row("IdCuenta").ToString.ToEntero, Row("CuentaFormato").ToString, 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(IDPoliza)
' 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(tIDPoliza As Integer, Ejercicio As Integer, Periodo As Integer, TipoPoliza As Integer, Numero As Integer)
Dim ObjPoliza As New ClsContPAQi(UsuarioActual.Empresa)
Dim ObjConta As New ClsContabilidad
'Dim DT As DataTable = Nothing
If ObjPoliza.GetPoliza(tIDPoliza, Ejercicio, Periodo, TipoPoliza, Numero) Then
DT = ObjPoliza.DtResultados
BtnGuardar.OnClientClick = "FncVerifica();"
If DT.Rows.Count = 0 Then
TxtFechaPoliza.Text = NowADS().ToShortDateString
TxtNumeroPoliza.Text = ""
LblCargo.Text = ""
LblAbono.Text = ""
TxtConcepto.Text = ""
Alert("No se encontró ninguna Póliza, verifique los datos.", TipoMensaje.MsgAdvertencia)
'HdnIdPoliza.Value = ""
Else
'TxtFecha.Text = ""
'TxtNumero.Text = ""
'DdlTipo.SelectedIndex = 0
Dim dr As DataRow = DT.Rows(0)
HLImprimir.NavigateUrl = String.Format("/Compras/PopUpVerFactura.aspx?P={0}", Encripta($"OP=POL&CvePoliza={dr("IdPoliza").ToString.ToEntero}"))
HLImprimir.Visible = True
TxtFechaPoliza.Text = dr("FechaPol").ToString.ToDate.ToShortDateString
HdnFechaPoliza.Value = dr("FechaPol").ToString.ToDate.ToShortDateString
DdlTipoPoliza.SelectedValue = dr("CodigoTipoPoliza").ToString.Trim
HdnTipoPoliza.Value = DdlTipoPoliza.SelectedValue
'LtlNumeroPoliza.Text = dr("Folio")
TxtNumeroPoliza.Text = dr("Folio").ToString
'HdnIdPoliza.Value = dr("IdPoliza").ToString 'Id de la Póliza lo da automaticamente el sistema ContPAQi
HdnFolioPoliza.Value = dr("Folio").ToString 'Folio de la poliza
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("IdPoliza").ToString
'Datos para bitacora
FechaPolizaOld = TxtFechaPoliza.Text
TipoPolizaOld = DdlTipoPoliza.SelectedItem.Text
ConceptoOld = TxtConcepto.Text
CargaGvBitacora(dr("IdPoliza").ToString.ToEntero)
'If dr("Cargos").ToString <> DT.SUM("Cargo").ToString Or dr("Abonos").ToString <> DT.SUM("Abono").ToString 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
'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
'ChkPolizaComplementaria.Visible = False
'DdlTipoPoliza.AutoPostBack = True
'TxtNumeroPoliza.AutoPostBack = True
IDPoliza = dr("IdPoliza").ToString.ToEntero
If ObjConta.GetPrePoliza(-1, UsuarioActual.CveEmpresa, IDPoliza) Then
If ObjConta.DtResultados.Rows.Count > 0 Then
CvePrePoliza = ObjConta.DtResultados.Rows(0)("CvePrePoliza").ToString.ToEntero
If UsuarioActual.CveRol = 1 Then
BtnNuevo.BackColor = Color.Yellow
BtnNuevo.ToolTip = CvePrePoliza.ToString
HplCvePrep.Visible = True
HplCvePrep.NavigateUrl = "/Contabilidad/RegPrePolizas.aspx?CvePrePoliza=" & CvePrePoliza
End If
End If
End If
If UsuarioActual.TienePermisoProceso(145) Then
BtnEliminar.Visible = True
End If
' CargaDevoluciones()
End If
If Request("Regenera") IsNot Nothing AndAlso Request("Regenera").ToString = "1" Then
GeneraPrePoliza(tIDPoliza, DT, CvePrePoliza)
End If
End If
ObjPoliza.Dispose()
ObjConta.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
RegistraScript("PrendeGVS();") 'Aseguramos que se cargue el gridViewScroll
CargaGrid()
upTitulos.Update()
upDatos.Update()
UpAcciones.Update()
If DT IsNot Nothing Then DT.Dispose()
End Sub
Private Sub GuardaPoliza()
Dim OcurrioError As Boolean = False
Dim ObjConta As New ClsContPAQi(UsuarioActual.Empresa)
ObjConta.IniciaTransacSQL()
Dim tIdPoliza As Integer
Dim NumPoliza As String = "-1"
Dim Tipo As String = ""
If TxtNumeroPoliza.Text.Trim <> "" Then
NumPoliza = TxtNumeroPoliza.Text.Trim
Tipo = "CHQ"
Else
End If
tIdPoliza = ObjConta.AddPoliza(DdlTipoPoliza.SelectedValue.ToEntero, TxtConcepto.Text.Trim, LblCargo.Text.Trim.ToDouble, LblAbono.Text.Trim.ToDouble, UsuarioActual.CveUsuario, TxtFechaPoliza.Text.Trim.ToDate, NumPoliza, Tipo)
If tIdPoliza > 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.AddMovimiento(tIdPoliza, Row("IdCuenta").ToString.ToEntero, False,
Row("Cargo").ToString.ToDouble, Row("Referencia").ToString, Row("Concepto").ToString,
Row("IdSegNeg").ToString.ToEntero, TxtFechaPoliza.Text.Trim.ToDate, "", Row("CargoME").ToString.ToDouble) Then
OcurrioError = True
End If
Else
If Not ObjConta.AddMovimiento(tIdPoliza, Row("IdCuenta").ToString.ToEntero, True,
Row("Abono").ToString.ToDouble, Row("Referencia").ToString, Row("Concepto").ToString,
Row("IdSegNeg").ToString.ToEntero, TxtFechaPoliza.Text.Trim.ToDate, "", Row("AbonoME").ToString.ToDouble) 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(tIdPoliza, 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, "", UsuarioActual.CveEmpresa) Then
OcurrioError = True
End If
Next
End If
If Not OcurrioError Then
If Not ObjConta.AjustaPoliza(tIdPoliza) Then
OcurrioError = True
End If
End If
If OcurrioError Then
ObjConta.RollBack()
Alert("Ocurrió un error al guardar la póliza", TipoMensaje.MsgAdvertencia)
Else
'Alert("La información se guardó correctamente con el numero de poliza " + IdPoliza.ToString + ".", TipoMensaje.MsgInformacion)
Alert(String.Format("La información se guardó correctamente con el numero de póliza: {0}", ObjConta.Folio), TipoMensaje.MsgInformacion)
ObjConta.Commit()
IDPoliza = tIdPoliza
'recargo la informacion, por si hacen cambios en la poliza
limpia()
CargaDatos(IDPoliza, -1, -1, -1, -1)
BtnNuevo.OnClientClick = ""
End If
End If
upTitulos.Update()
upDatos.Update()
UpConsultar.Update()
ObjConta.Dispose()
End Sub
Private Sub AddRegPolizaDetalle(IdMovimiento As Integer, Referencia As String, CveCuenta As Integer, Cuenta As String, IdSegNeg As String, SegNeg As String, NombreConcepto As String, Cargo As Double, Abono As Double)
Dim Row As DataRow = Nothing
Row = TmpDT.NewRow()
Row("Id") = IdMovimiento
Row("NumMovto") = TmpDT.Rows.Count + 1
Row("Referencia") = Referencia
Row("IdCuenta") = CveCuenta
Row("CuentaFormato") = Cuenta
Row("CtaCodigo") = Cuenta
Row("IdSegNeg") = IdSegNeg
Row("SegNeg") = SegNeg
Row("Concepto") = NombreConcepto
Row("Cargo") = Cargo
Row("Abono") = Abono
Row("Estado") = "I"
TmpDT.Rows.Add(Row)
CargaGrid()
End Sub
Private Sub ActualizaPoliza()
Dim OcurrioError As Boolean = False
Dim ObjContabilidad As New ClsContabilidad()
ObjContabilidad.IniciaTransacSQL()
Dim ObjConta As New ClsContPAQi(UsuarioActual.Empresa)
ObjConta.IniciaTransacSQL()
Dim Row As DataRow
Dim ObjGral As New ClsGenerales()
ObjGral.IniciaTransacSQL()
'ObjConta.UpdatePoliza(TxtConcepto.Text.Trim, LblCargo.Text.Trim.ToDouble, LblAbono.Text.Trim.ToDouble, UsuarioActual.CveUsuario, TxtFechaPoliza.Text.Trim.ToDate, LtlNumeroPoliza.Text.Trim.ToEntero, DdlTipoPoliza.SelectedValue.ToEntero, HdnIdPoliza.Value)
If ObjConta.UpdatePoliza(TxtConcepto.Text.Trim, LblCargo.Text.Trim.ToDouble, LblAbono.Text.Trim.ToDouble, UsuarioActual.CveUsuario, TxtFechaPoliza.Text.Trim.ToDate, TxtNumeroPoliza.Text, DdlTipoPoliza.SelectedValue.ToEntero, IDPoliza.ToString.ToEntero) Then
'Dim ResultadoTabla As New StringBuilder()
'ResultadoTabla.Append("
| " & Row("Id").ToString & " |
| " & RemoveMovimientos.Item(i).ToString & " |