--BDH, generar bonificaciones en base al subproyecto

This commit is contained in:
2024-11-04 19:37:36 -07:00
parent 1495c9c697
commit d5b93be073

View File

@@ -6,7 +6,8 @@ Imports System.Data.SqlClient
Imports System.Globalization
Imports System.IO
Imports System.Net
Imports System.Net.Http
Imports System.Net.Http
Imports System.Security.Policy
Imports Extensiones
Imports Microsoft.Reporting.WebForms
Imports Newtonsoft.Json
@@ -209,14 +210,14 @@ Partial Class Clientes
End Set
End Property
Private Property ObjFactura As Modelos.Factura
Get
Return CType(ViewState("ObjFactura"), Modelos.Factura)
End Get
Set(value As Modelos.Factura)
ViewState("ObjFactura") = value
End Set
End Property
'Private Property ObjFactura As Modelos.Factura
' Get
' Return CType(ViewState("ObjFactura"), Modelos.Factura)
' End Get
' Set(value As Modelos.Factura)
' ViewState("ObjFactura") = value
' End Set
'End Property
Private Property CobranzaTelefono As String
Get
@@ -309,14 +310,14 @@ Partial Class Clientes
ViewState("DTPorcentajePrecios") = value
End Set
End Property
Private Property TmpDT As DataTable
Get
Return If(IsNothing(ViewState("TmpDT")), Nothing, CType(ViewState("TmpDT"), DataTable))
End Get
Set(value As DataTable)
ViewState("TmpDT") = value
End Set
End Property
'Private Property TmpDT As DataTable
' Get
' Return If(IsNothing(ViewState("TmpDT")), Nothing, CType(ViewState("TmpDT"), DataTable))
' End Get
' Set(value As DataTable)
' ViewState("TmpDT") = value
' End Set
'End Property
Private Property DtPromociones As DataTable
Get
Return If(IsNothing(ViewState("DtPromociones")), Nothing, CType(ViewState("DtPromociones"), DataTable))
@@ -664,7 +665,7 @@ Partial Class Clientes
Actualizar = False
SetValues()
CargaCombos()
CreaDTVentas()
'CreaDTVentas()
CreaDtPago()
RegistraScript("CargaHeader();")
CargaCombosDirecionesClientesSAT()
@@ -9197,102 +9198,52 @@ Partial Class Clientes
#Region " A C U M U L A D O R E S"
Protected Sub LnkFacturaUsadosCargos_Click(sender As Object, e As EventArgs)
'CveVentaNota = 0
Protected Sub LnkFacturaUsadosBonificacion_Click(sender As Object, e As EventArgs)
Dim DtSubProyectos As DataTable = New DataTable()
DtSubProyectos.Columns.Add(New DataColumn("CveSubProyecto", GetType(Integer)))
'Dim Cargos As Decimal = 0D
'Dim Iva As Decimal = 0D
'For Each GvRow As GridViewRow In GvAcum.Rows
' If GvRow.DataKey("CveConcepto").Toentero() = 1 And GvRow.FCCheckBox("ChkCargo").Checked Then
' Cargos = Cargos + GvRow.DataKey("ImporteCargo").ToDecimal()
' End If
'Next
'Dim CvePS As Integer = UsuarioActual.Empresa.Funcionalidad(534).Toentero() 'CvePS Distruibuidor Cargo Nota
'Dim CveUnidadMedida As Integer
'Dim CveClasificacion As Integer
'If CvePS > 0 Then
' If Cargos > 0 Then
' CveUnidadMedida = GlobalDTPS(UsuarioActual.CveEmpresa, CvePS).FiltroPrimeroValor("CveUnidadMedida").ToString().Toentero()
' CveClasificacion = GlobalDTPS(UsuarioActual.CveEmpresa, CvePS).FiltroPrimeroValor("CveClasificacion").ToString().Toentero()
' Iva = Cargos * 0.16D
' If GenerarNotaCredito(CvePS, 1, CveUnidadMedida, Cargos, Iva, "Clientes/Usados", CveClasificacion) Then
' Alert($"LA nota de crédito fue generada correctamente {SerieNotaAcumulador}-{FolioNotaAcumulador}")
' Else
' Alert("Se presento un error al generar la nota de creédito", TipoMensaje.MsgError)
' End If
' End If
'Else
' Alert("No esta asignada la funcionalidad CvePS Distruibuidor Cargo Nota")
'End If
CreaObjetosVenta(1)
'If ObjFactura.CveCliente > 0 Then
' If TmpDT.Rows.Count > 0 Then
' Dim Retorno = ObjFactura.EmitirFactura(false)
' For Each Mensaje In Retorno.Mensajes
' Alert(Mensaje, If(Retorno.TieneError, TipoMensaje.MsgError, TipoMensaje.MsgInformacion))
' Next
' End If
'End If
CargaUsados()
End Sub
Protected Sub LnkFacturaUsadosBonificacion_Click(sender As Object, e As EventArgs)
'CveVentaNota = 0
'Dim Bonificacion As Decimal = 0D
'Dim Iva As Decimal = 0D
'For Each GvRow As GridViewRow In GvAcum.Rows
' If GvRow.DataKey("CveConcepto").Toentero() = 1 And GvRow.FCCheckBox("ChkBonificacion").Checked Then
' Bonificacion = Bonificacion + GvRow.DataKey("ImporteBonificacion").ToDecimal()
' End If
'Next
'Dim CvePS As Integer = UsuarioActual.Empresa.Funcionalidad(534).Toentero() 'CvePS Distruibuidor Bonificación Nota
'Dim CveUnidadMedida As Integer
'Dim CveClasificacion As Integer
'If CvePS > 0 Then
' If Bonificacion > 0 Then
' CveUnidadMedida = GlobalDTPS(UsuarioActual.CveEmpresa, CvePS).FiltroPrimeroValor("CveUnidadMedida").ToString().Toentero()
' CveClasificacion = GlobalDTPS(UsuarioActual.CveEmpresa, CvePS).FiltroPrimeroValor("CveClasificacion").ToString().Toentero()
' Iva = Bonificacion * 0.16D
' If GenerarNotaCredito(CvePS, 2, CveUnidadMedida, Bonificacion, Iva, "Clientes/Usados", CveClasificacion) Then
' Alert($"LA nota de crédito fue generada correctamente {SerieNotaAcumulador}-{FolioNotaAcumulador}")
' Else
' Alert("Se presento un error al generar la nota de creédito", TipoMensaje.MsgError)
' End If
' End If
'Else
' Alert("No esta asignada la funcionalidad CvePS Distruibuidor Bonificación Nota")
'End If
CreaObjetosVenta(2)
If ObjFactura.CveCliente > 0 Then
If TmpDT.Rows.Count > 0 Then
Dim Retorno As Modelos.Factura.MMensajeFactura = ObjFactura.EmitirFactura(False)
For Each Mensaje As String In Retorno.Mensajes
Alert(Mensaje, If(Retorno.TieneError, TipoMensaje.MsgError, TipoMensaje.MsgInformacion))
Next
For Each GvRow As GridViewRow In GvAcum.Rows
If GvRow.FCCheckBox("ChkBonificacion").Checked Then
DtSubProyectos.Rows.Add(GvRow.DataKey("CveSubProyecto").ToEntero())
End If
Next
Dim StringFolios As New StringBuilder
Dim StringMsg As New StringBuilder
Dim ObjVentas As New ClsVentas
ObjVentas.IniciaTransacSQL()
Dim TieneError As Boolean = False
Try
For Each Row As DataRow In DtSubProyectos.FiltraParametros("", DistinctColumns:={"CveSubProyecto"}).Rows
Dim Resp = CreaObjetosVenta(2, Row("CveSubProyecto").ToString().ToEntero(), ObjVentas)
If Resp.TieneError Then
TieneError = True
StringMsg.Append("Ocurrió un error al generar la RNC de bonificación")
Exit For
Else
StringFolios.AppendFormat("<br/><b>{0}<b/>", Resp.SerieFolio)
End If
Next
Catch ex As Exception
TieneError = True
StringMsg.Append("Ocurrió un error al generar la RNC de bonificación")
End Try
If TieneError Then
ObjVentas.RollBack()
Else
ObjVentas.Commit()
End If
If Not TieneError AndAlso StringFolios.Length > 0 Then
StringMsg.AppendFormat("Se generaron las siguientes remisiones de nota de crédito de bonificación: {0}", StringFolios)
End If
Alert(StringMsg.ToString(), If(TieneError, TipoMensaje.MsgError, TipoMensaje.MsgInformacion))
Alert("Listo")
CargaUsados()
End Sub
@@ -9420,8 +9371,8 @@ Partial Class Clientes
End Sub
Private Sub CreaDTVentas()
TmpDT = New DataTable
Private Function CreaDTVentas() As DataTable
Dim TmpDT = New DataTable
TmpDT.Columns.Add("CveVenta", GetType(Integer))
TmpDT.Columns.Add("Consec", GetType(Integer))
TmpDT.Columns.Add("Cantidad", GetType(Decimal))
@@ -9507,8 +9458,9 @@ Partial Class Clientes
TmpDT.Columns.Add("CveTamaño", GetType(Integer))
TmpDT.Columns.Add("EsCargo", GetType(Boolean))
End Sub
Private Function AgregarProductoServicio(Cantidad As Decimal, CveUM As Integer, UM As String, CveClasificacion As Integer, Clasificacion As String, CvePS As Integer, PS As String, Obs As String,
Return TmpDT
End Function
Private Function AgregarProductoServicio(ByRef TmpDT As DataTable, Cantidad As Decimal, CveUM As Integer, UM As String, CveClasificacion As Integer, Clasificacion As String, CvePS As Integer, PS As String, Obs As String,
PU As Decimal, Descuento As Decimal,
CveProyecto As Integer, Proyecto As String, CveSubProyecto As Integer, SubProyecto As String,
Optional Serie As String = "", Optional TiempoEntrega As String = "", Optional EntregaDirecta As Integer = 0,
@@ -9630,16 +9582,15 @@ Partial Class Clientes
Return Retorno
End Function
Private Sub CreaObjetosVenta(Tipo As Integer)
Dim CveSubProyecto As Integer = -1
Private Function CreaObjetosVenta(Tipo As Integer, CveSubProyecto As Integer, ByRef ObjVentas As ClsVentas) As Modelos.Factura.MMensajeFactura
Dim TmpDT As DataTable = CreaDTVentas()
Dim UsadosBonificacion As List(Of Integer) = New List(Of Integer)
TmpDT.Rows.Clear()
TmpDT.AcceptChanges()
For Each GvRow As GridViewRow In GvAcum.Rows
If GvRow.FCCheckBox("ChkBonificacion").Checked OrElse GvRow.FCCheckBox("ChkCargo").Checked Then
CveSubProyecto = GvRow.DataKey("CveSubProyecto").ToEntero()
If GvRow.FCCheckBox("ChkBonificacion").Checked AndAlso GvRow.DataKey("CveSubProyecto").ToEntero() = CveSubProyecto Then
Dim Cantidad As Decimal = GvRow.DataKey("Cantidad").ToDecimal
Dim PU As Decimal = 0
@@ -9662,6 +9613,8 @@ Partial Class Clientes
End If
If CvePSCargo > 0 AndAlso PU > 0 Then
Dim CveMovto As Integer = GvRow.DataKey("CveMovto").ToEntero()
Dim Dr As DataRow = GlobalDTPS(UsuarioActual.CveEmpresa, CvePSCargo).Rows(0)
If Dr IsNot Nothing Then
CveUnidadMedida = Dr("CveUnidadMedida").ToString().ToEntero()
@@ -9671,8 +9624,10 @@ Partial Class Clientes
Clasificacion = Dr("Clasificacion").ToString()
End If
AgregarProductoServicio(Cantidad, CveUnidadMedida, UnidadMedida, CveClasificacion, Clasificacion, CvePSCargo, PS, "Clientes/Usados", PU, 0, -1, "", DdlSubProyecto.SelectedValue.ToEntero(),
AgregarProductoServicio(TmpDT, Cantidad, CveUnidadMedida, UnidadMedida, CveClasificacion, Clasificacion, CvePSCargo, PS, "Clientes/Usados", PU, 0, -1, "", DdlSubProyecto.SelectedValue.ToEntero(),
DdlSubProyecto.SelectedItem.Text, PorcentajeIVA:=PorcentajeIVA)
UsadosBonificacion.Add(CveMovto)
End If
End If
@@ -9694,20 +9649,9 @@ Partial Class Clientes
DT.Dispose()
End If
ObjFolios.Dispose()
End If
'If FolioNotaCredito(Tipo) Then
' Folio = FolioNotaAcumulador
' Serie = SerieNotaAcumulador
'End If
If ObjFactura IsNot Nothing Then
ObjFactura.Dispose()
ObjFactura = Nothing
End If
ObjFactura = New Modelos.Factura(UsuarioActual)
Dim ObjFactura = New Modelos.Factura(UsuarioActual)
ObjFactura.CveUsuario = UsuarioActual.CveUsuario
ObjFactura.CveEmpresa = UsuarioActual.CveEmpresa
ObjFactura.CveVenta = -1
@@ -9828,20 +9772,12 @@ Partial Class Clientes
ObjFactura.CveTipoRelacion = -1
End If
Dim UsadosBonificacion As List(Of Integer) = New List(Of Integer)
For Each GvRow As GridViewRow In GvAcum.Rows
Dim CveMovto As Integer = GvRow.DataKey("CveMovto").ToEntero()
If (Tipo = 1 And GvRow.FCCheckBox("ChkCargo").Checked) Or (Tipo = 2 And GvRow.FCCheckBox("ChkBonificacion").Checked) Then
UsadosBonificacion.Add(CveMovto)
End If
Next
ObjFactura.UsadosBonificacion = UsadosBonificacion
ObjFactura.TipoBonificacion = Tipo
' ObjFactura.Timbre = PreParaTimbre(ObjFactura)
Return ObjFactura.EmitirFactura(False, Transac:=ObjVentas.IniciaTransacSQL(), Modulo:="Clientes/Bonificacion", MostrarURL:=True)
End Sub
End Function
#End Region