Files
SIG/Contabilidad/OCDetalleAlmacen.aspx.vb
Rene Molina 99664e4636 ajustes oc
2019-09-20 20:20:38 -07:00

164 lines
6.1 KiB
VB.net

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 CveCuenta176 As Integer = 55169
Dim IdCtaCuenta176 As Integer = 1245
Dim CveCuenta177 As Integer = 55294
Dim IdCtaCuenta177 As Integer = 1148
Dim Chk As CheckBox = GvDrow.FCCheckBox("Chk")
If Chk IsNot Nothing AndAlso Chk.Checked Then
CvePrePoliza = ObjConta.AddPrePolizas(modulo, 3, 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} <br>"
If CvePrePoliza > 0 Then
If Cargo > Abono Then
If (ObjConta.AddPrePolizasDetalle(CvePrePoliza, 1, Diferencia, Referencia, 176, Referencia, Fecha, IdCtaCuenta176, -1, ImporteME:=0, ImporteMX:=Diferencia, CveCompra:=CveCompra, Contabilizable:=1, CveOC:=CveOC, CveOCDetalle:=CveOCDetalle, CveProveedor:=CveProveedor)) Then
If (ObjConta.AddPrePolizasDetalle(CvePrePoliza, 1, -Diferencia, Referencia, 177, Referencia, Fecha, IdCtaCuenta177, -1, ImporteME:=-0, ImporteMX:=-Diferencia, CveCompra:=CveCompra, Contabilizable:=1, 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, 1, -Diferencia, Referencia, 176, Referencia, Fecha, IdCtaCuenta176, -1, ImporteME:=-0, ImporteMX:=-Diferencia, CveCompra:=CveCompra, Contabilizable:=1, CveOC:=CveOC, CveOCDetalle:=CveOCDetalle, CveProveedor:=CveProveedor)) Then
If (ObjConta.AddPrePolizasDetalle(CvePrePoliza, 1, Diferencia, Referencia, 177, Referencia, Fecha, IdCtaCuenta177, -1, ImporteME:=0, ImporteMX:=Diferencia, CveCompra:=CveCompra, Contabilizable:=1, 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 <br> registros procesados: {ContadorProcesados} <br> {mensaje}")
Else
ObjConta.RollBack()
End If
ObjConta.Dispose()
CargaDatos()
End Sub
End Class