Imports System.Data Imports Extensiones Partial Class Contabilidad_OCDetalleAlmacen Inherits ClsPaginas Property DTDatos As DataTable Get If ViewState("DTDatos") Is Nothing Then Return New DataTable Else Return DirectCast(ViewState("DTDatos"), DataTable) End If End Get Set(value As DataTable) ViewState("DTDatos") = value End Set End Property Private Sub Contabilidad_OCDetalleAlmacen_Load(sender As Object, e As EventArgs) Handles Me.Load If Not Page.IsPostBack Then CargaDatos() End If End Sub Private Sub CargaDatos() Dim ObjConta As New ClsContabilidad If ObjConta.GetOCDetalleAlmacen(100000D, UsuarioActual.CveEmpresa) Then If ObjConta.DtResultados.Rows.Count > 0 Then DTDatos = ObjConta.DtResultados GvDAtos.DataSource = DTDatos Alert($"Se encontraron {ObjConta.DtResultados.Rows.Count} registros.") Else DTDatos = Nothing Alert("Nos se encontraron registros por proocesar ") GvDAtos.DataSource = Nothing End If Else DTDatos = Nothing GvDAtos.DataSource = Nothing End If GvDAtos.DataBind() ObjConta.Dispose() End Sub Protected Sub BtnProcesarRegistros_Click(sender As Object, e As EventArgs) Dim ObjConta As New ClsContabilidad ObjConta.IniciaTransacSQL() Dim modulo As String = "OC Ajuste Manual" Dim ErrorProcesamiento As Boolean = False Dim mensaje As String = "" Dim ContadorProcesados As Integer = 0 For Each GvDrow As GridViewRow In GvDAtos.Rows Dim CvePrePoliza As Integer = 0 Dim Cargo As Decimal = GvDrow.DataKey("Cargo").ToString.ToDecimal Dim Abono As Decimal = GvDrow.DataKey("Abono").ToString.ToDecimal Dim Diferencia As Decimal = Math.Abs(GvDrow.DataKey("dif").ToString.ToDecimal) Dim CveMoneda As Integer = GvDrow.DataKey("CveMoneda").ToString.ToEntero Dim Fecha As Date = GvDrow.DataKey("Fecha").ToString.ToDate Dim Referencia As String = GvDrow.DataKey("Referencia").ToString Dim CveOCDetalle As Integer = GvDrow.DataKey("CveOrdenCompraDetalle").ToString.ToEntero Dim CveOC As Integer = GvDrow.DataKey("CveOrdenCompra").ToString.ToEntero Dim CveProveedor As Integer = GvDrow.DataKey("CveProveedor").ToString.ToEntero Dim CveCompra As Integer = GvDrow.DataKey("CveCompra").ToString.ToEntero Dim Folio As String = GvDrow.DataKey("Folio").ToString Dim Chk As CheckBox = GvDrow.FCCheckBox("Chk") If Chk IsNot Nothing AndAlso Chk.Checked Then CvePrePoliza = ObjConta.AddPrePolizas(modulo, 74, Diferencia, Diferencia, CveMoneda, Fecha, Referencia, UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa, CveTipoPoliza:=3) GvDrow.Cells(1).Text = CvePrePoliza.ToString mensaje = mensaje & $"CvePrePoliza {CvePrePoliza } OC: {Folio} Importe :{Diferencia}
" If CvePrePoliza > 0 Then If Cargo > Abono Then If (ObjConta.AddPrePolizasDetalle(CvePrePoliza, True, Diferencia, Diferencia, 176, Referencia, Referencia, ImporteME:=Diferencia, CveCompra:=CveCompra, CveOC:=CveOC, CveOCDetalle:=CveOCDetalle, CveProveedor:=CveProveedor)) Then If (ObjConta.AddPrePolizasDetalle(CvePrePoliza, True, -Diferencia, -Diferencia, 177, Referencia, Referencia, CveCompra:=CveCompra, CveOC:=CveOC, CveOCDetalle:=CveOCDetalle, CveProveedor:=CveProveedor)) Then ContadorProcesados = ContadorProcesados + 1 Else ErrorProcesamiento = True Exit For End If Else ErrorProcesamiento = True Exit For End If Else If (ObjConta.AddPrePolizasDetalle(CvePrePoliza, True, -Diferencia, -Diferencia, 176, Referencia, Referencia, CveCompra:=CveCompra, Contabilizable:=True, CveOC:=CveOC, CveOCDetalle:=CveOCDetalle, CveProveedor:=CveProveedor)) Then If (ObjConta.AddPrePolizasDetalle(CvePrePoliza, True, Diferencia, Diferencia, 177, Referencia, Referencia, CveCompra:=CveCompra, Contabilizable:=True, CveOC:=CveOC, CveOCDetalle:=CveOCDetalle, CveProveedor:=CveProveedor)) Then ContadorProcesados = ContadorProcesados + 1 Else ErrorProcesamiento = True Exit For End If Else ErrorProcesamiento = True Exit For End If End If End If End If Next DTDatos.AcceptChanges() If Not ErrorProcesamiento Then ObjConta.Commit() 'ObjConta.RollBack() ' 'BtnProcesarRegistros.Enabled = False Alert($"PrePolizas agregadas correctamente
registros procesados: {ContadorProcesados}
{mensaje}") Else ObjConta.RollBack() End If ObjConta.Dispose() CargaDatos() End Sub End Class