diff --git a/App_Code/Modelos.vb b/App_Code/Modelos.vb
index b37795a61..776036e64 100644
--- a/App_Code/Modelos.vb
+++ b/App_Code/Modelos.vb
@@ -654,6 +654,7 @@ Namespace Modelos
End If
End Sub
Public Class MMensajeFactura
+ Public Property Factura As Modelos.Factura
Sub New()
CveVenta = -1
LigaCliente = ""
@@ -1097,7 +1098,7 @@ Namespace Modelos
End If
'MENSAJE PRINCIPAL
- MensajeAlert.AppendFormat(String.Format("
La {0}: {1} se generó correctamente.
", Me.TipoDocumento, Me.SerieFolio))
+ MensajeAlert.AppendFormat(String.Format("
La {0}: {1} se generó correctamente.
", If(Me.TipoDocumento = "Ingresos", "Factura", Me.TipoDocumento), Me.SerieFolio))
' DESCARGA XML - SI SE TIMBRA MANDA CORREO CON FACTURA
@@ -1131,8 +1132,10 @@ Namespace Modelos
End If
'ERROR DE NO TIMBRADO
- If Not SeTimbro And (Me.TipoDocto = "Ing" Or Me.TipoDocto.Contiene("Egs", "Dev") Or Me.TipoDocto = "Ant") Then
- MensajeAlert.AppendFormat("La factura no se pudo timbrar. Por favor intentelo de nuevo a traves del boton Emitir.")
+ If Timbrar Then
+ If Not SeTimbro And (Me.TipoDocto = "Ing" Or Me.TipoDocto.Contiene("Egs", "Dev") Or Me.TipoDocto = "Ant") Then
+ MensajeAlert.AppendFormat("La factura no se pudo timbrar. Por favor intentelo de nuevo a traves del boton Emitir.")
+ End If
End If
'ERROR DE NO TIMBRADO NC
diff --git a/Ventas/PVCobranza.aspx.vb b/Ventas/PVCobranza.aspx.vb
index c42948839..60866a433 100644
--- a/Ventas/PVCobranza.aspx.vb
+++ b/Ventas/PVCobranza.aspx.vb
@@ -397,7 +397,7 @@ Partial Class Ventas_PVCobranza
If DbRowVenta IsNot Nothing Then
Dim VentaActual As New Venta(UsuarioActual)
VentaActual.CveVenta = CveVenta
-
+ VentaActual.TipoDocto = DbRowVenta("TipoDocto").ToString
VentaActual.Fecha = DbRowVenta("Fecha").ToString.ToDate
VentaActual.CveCliente = DbRowVenta("CveCliente").ToString.ToEntero
VentaActual.CveMoneda = DbRowVenta("CveMoneda").ToString.ToEntero
@@ -422,10 +422,30 @@ Partial Class Ventas_PVCobranza
Dim SaldoTotalInicial As Decimal = DbRowVenta("Saldo").ToString.ToDecimal
Dim PagoAplicado As Decimal = 0
- Dim ObjConta As New ClsContabilidad
- Dim ObjIE As New ClsBancos(ObjConta.IniciaTransacSQL())
- Dim ObjVentas2 As New ClsVentas(ObjConta.IniciaTransacSQL())
+ Dim ObjVentas2 As New ClsVentas()
+ Dim ObjIE As New ClsBancos(ObjVentas2.IniciaTransacSQL())
+ Dim ObjConta As New ClsContabilidad(ObjVentas2.IniciaTransacSQL())
+ Dim ObjClientes As New ClsClientes(ObjVentas2.IniciaTransacSQL())
+
+ Dim respFactura As Modelos.Factura.MMensajeFactura = Nothing
+
Try
+ 'FACTURAR LA REMISION PARA HACER EL PAGO
+ If UsuarioActual.CveEmpresa = 193 AndAlso VentaActual.TipoDocto = "Rem" Then
+ respFactura = GenerarFactura(VentaActual, ObjVentas2, ObjClientes)
+
+ If respFactura Is Nothing Then
+ MsgError = "Ocurrío un error al generar la factura"
+ ElseIf (respFactura IsNot Nothing AndAlso respFactura.Mensajes.Count > 0) AndAlso respFactura.TieneError Then
+ MsgError = respFactura.Mensajes(0)
+ End If
+
+ 'REALIZAR EL PAGO EN LA FACTURA
+ If respFactura IsNot Nothing AndAlso Not respFactura.TieneError Then
+ CveVenta = respFactura.CveVenta
+ End If
+ End If
+
CvePrePoliza = ObjConta.AddPrePolizas("PVCobranza", 11, 0, 0, 1, Fecha, $"Pago {VentaActual.SerieFolio}", UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa, CveTipoPoliza:=3)
If CvePrePoliza > 0 Then
@@ -487,21 +507,41 @@ Partial Class Ventas_PVCobranza
End Try
If MsgError = "" Then
- ObjConta.Commit()
- Alert($"Pago Registrado correctamente.
Imprimir ticket", TipoMensaje.MsgInformacion)
+ ObjVentas2.Commit()
+
+ 'SI SE GENERO FACTURA DE INGRESO, TIMBRARLA DESPUES DE REALIZAR EL PAGO
+ If respFactura IsNot Nothing Then
+ If Not respFactura.Factura.TimbrarFactura() Then
+ Alert("La factura no se pudo timbrar", TipoMensaje.MsgAdvertencia)
+ End If
+ End If
+
+ Dim msBuild As New StringBuilder()
+
+ If respFactura IsNot Nothing Then
+ msBuild.Append($"Pago Registrado correctamente.")
+ For Each m In respFactura.Mensajes
+ msBuild.AppendFormat("
{0}", m)
+ Next
+ Else
+ msBuild.Append($"Pago Registrado correctamente.
Imprimir ticket")
+ End If
+
+ Alert(msBuild.ToString(), TipoMensaje.MsgInformacion)
Else
- ObjConta.RollBack()
+ ObjVentas2.RollBack()
Alert(MsgError, TipoMensaje.MsgError)
End If
+ ObjVentas2.Dispose()
ObjConta.Dispose()
ObjIE.Dispose()
- ObjVentas2.Dispose()
+ ObjClientes.Dispose()
If MsgError = "" Then
Try
If UsuarioActual.Empresa.Funcionalidad(109) = "1" Then
- ImpresionDirectaPDF(HdnCveVenta.Value.ToEntero)
+ ImpresionDirectaPDF(CveVenta)
End If
PnlContado.Visible = False
@@ -517,6 +557,113 @@ Partial Class Ventas_PVCobranza
End Sub
+ Private Function GenerarFactura(ByRef VentaRemision As Venta, ByRef ObjVentas As ClsVentas, ByRef ObjClientes As ClsClientes) As Modelos.Factura.MMensajeFactura
+ Dim Retorno As Modelos.Factura.MMensajeFactura = Nothing
+
+ Dim DtRemisiones As New DataTable
+ DtRemisiones.Columns.Add(New DataColumn("CveVenta", GetType(Integer)))
+ DtRemisiones.Columns.Add(New DataColumn("SerieFolio", GetType(String)))
+
+ DtRemisiones.Rows.Add({VentaRemision.CveVenta, VentaRemision.SerieFolio})
+
+ Dim RemisionesLista As New List(Of Integer)
+ RemisionesLista.Add(VentaRemision.CveVenta)
+
+ Dim DtRemisionesPS As New DataTable()
+ Dim DtPagosFacturaGlobal As New DataTable()
+
+ If ObjClientes.GetVentasRemisionesTotales(VentaRemision.CveCliente, VentaRemision.CveVenta.ToString(), 1) Then
+ DtRemisionesPS = ObjClientes.DtResultados.Copy()
+ End If
+
+ Dim ObjFactura = Modelos.Factura.CrearVentaNueva(UsuarioActual, VentaRemision.CveSubProyecto, VentaRemision.CveCliente, VentaRemision.CveMoneda, "Ing")
+
+ ObjFactura.RemisionesLista = RemisionesLista
+ ObjFactura.DtRemisionesPS = DtRemisionesPS
+ ObjFactura.DtRemisiones = DtRemisiones
+
+ For Each Dr As DataRow In ObjFactura.DtRemisionesPS.Rows
+ ObjFactura.AgregarPS(Dr("CvePS").ToString().ToEntero(), Dr("Cantidad").ToString().ToDecimal(), Dr("PU").ToString().ToDecimal(), Dr("Descuento").ToString().ToDecimal, Dr("Obs").ToString(), CveUM:=Dr("CveUM").ToString().ToEntero(),
+ CveProyecto:=Dr("CveProyecto").ToString().ToEntero(), CveSubProyecto:=Dr("CveSubProyecto").ToString().ToEntero(), CveVentaDetallePadre:=Dr("CveVentaDetalle").ToString().ToEntero(), CveVentaDetalleRemision:=Dr("CveVentaDetalle").ToString().ToEntero(),
+ PorcentajeIVA:=Dr("PorcentajeIVA").ToString().ToDecimal())
+ Next
+
+ ObjFactura.GenerarSalidaAlmacen = True
+ ObjFactura.DtInventario = ObjFactura.DtDetalle.FiltraParametros("CveTipoPS = 2").Copy()
+ ObjFactura.CveAlmacen = GlobalDTAlmacen(UsuarioActual.CveEmpresa).FiltroPrimeroValor("CveAlmacen", $"CveTipoAlmacen = 1 AND CveSubProyecto = {VentaRemision.CveSubProyecto}").ToString().ToEntero()
+
+ ObjFactura.CalculaTotales()
+ ObjFactura.PreparaTimbre()
+
+ Dim SbAlert As New StringBuilder()
+
+ Try
+ Retorno = ObjFactura.EmitirFactura(False, Transac:=ObjVentas.IniciaTransacSQL(), Modulo:="Cobranza/GuardarVenta")
+ Retorno.Factura = ObjFactura
+
+ If Retorno IsNot Nothing AndAlso Retorno.CveVenta > 0 Then
+ For Each msg In Retorno.Mensajes
+ SbAlert.AppendFormat("{0}
", msg)
+ Next
+
+ SbAlert.AppendFormat("