--Facturacion de remisiones en cobranza
This commit is contained in:
@@ -654,6 +654,7 @@ Namespace Modelos
|
|||||||
End If
|
End If
|
||||||
End Sub
|
End Sub
|
||||||
Public Class MMensajeFactura
|
Public Class MMensajeFactura
|
||||||
|
Public Property Factura As Modelos.Factura
|
||||||
Sub New()
|
Sub New()
|
||||||
CveVenta = -1
|
CveVenta = -1
|
||||||
LigaCliente = ""
|
LigaCliente = ""
|
||||||
@@ -1097,7 +1098,7 @@ Namespace Modelos
|
|||||||
End If
|
End If
|
||||||
|
|
||||||
'MENSAJE PRINCIPAL
|
'MENSAJE PRINCIPAL
|
||||||
MensajeAlert.AppendFormat(String.Format("<br/>La {0}: <b>{1}</b> se generó correctamente.<br/><br/>", Me.TipoDocumento, Me.SerieFolio))
|
MensajeAlert.AppendFormat(String.Format("<br/>La {0}: <b>{1}</b> se generó correctamente.<br/><br/>", If(Me.TipoDocumento = "Ingresos", "Factura", Me.TipoDocumento), Me.SerieFolio))
|
||||||
|
|
||||||
|
|
||||||
' DESCARGA XML - SI SE TIMBRA MANDA CORREO CON FACTURA
|
' DESCARGA XML - SI SE TIMBRA MANDA CORREO CON FACTURA
|
||||||
@@ -1131,8 +1132,10 @@ Namespace Modelos
|
|||||||
End If
|
End If
|
||||||
|
|
||||||
'ERROR DE NO TIMBRADO
|
'ERROR DE NO TIMBRADO
|
||||||
If Not SeTimbro And (Me.TipoDocto = "Ing" Or Me.TipoDocto.Contiene("Egs", "Dev") Or Me.TipoDocto = "Ant") Then
|
If Timbrar Then
|
||||||
MensajeAlert.AppendFormat("La factura no se pudo timbrar.</b> Por favor intentelo de nuevo a traves del boton Emitir.")
|
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.</b> Por favor intentelo de nuevo a traves del boton Emitir.")
|
||||||
|
End If
|
||||||
End If
|
End If
|
||||||
|
|
||||||
'ERROR DE NO TIMBRADO NC
|
'ERROR DE NO TIMBRADO NC
|
||||||
|
|||||||
@@ -397,7 +397,7 @@ Partial Class Ventas_PVCobranza
|
|||||||
If DbRowVenta IsNot Nothing Then
|
If DbRowVenta IsNot Nothing Then
|
||||||
Dim VentaActual As New Venta(UsuarioActual)
|
Dim VentaActual As New Venta(UsuarioActual)
|
||||||
VentaActual.CveVenta = CveVenta
|
VentaActual.CveVenta = CveVenta
|
||||||
|
VentaActual.TipoDocto = DbRowVenta("TipoDocto").ToString
|
||||||
VentaActual.Fecha = DbRowVenta("Fecha").ToString.ToDate
|
VentaActual.Fecha = DbRowVenta("Fecha").ToString.ToDate
|
||||||
VentaActual.CveCliente = DbRowVenta("CveCliente").ToString.ToEntero
|
VentaActual.CveCliente = DbRowVenta("CveCliente").ToString.ToEntero
|
||||||
VentaActual.CveMoneda = DbRowVenta("CveMoneda").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 SaldoTotalInicial As Decimal = DbRowVenta("Saldo").ToString.ToDecimal
|
||||||
Dim PagoAplicado As Decimal = 0
|
Dim PagoAplicado As Decimal = 0
|
||||||
|
|
||||||
Dim ObjConta As New ClsContabilidad
|
Dim ObjVentas2 As New ClsVentas()
|
||||||
Dim ObjIE As New ClsBancos(ObjConta.IniciaTransacSQL())
|
Dim ObjIE As New ClsBancos(ObjVentas2.IniciaTransacSQL())
|
||||||
Dim ObjVentas2 As New ClsVentas(ObjConta.IniciaTransacSQL())
|
Dim ObjConta As New ClsContabilidad(ObjVentas2.IniciaTransacSQL())
|
||||||
|
Dim ObjClientes As New ClsClientes(ObjVentas2.IniciaTransacSQL())
|
||||||
|
|
||||||
|
Dim respFactura As Modelos.Factura.MMensajeFactura = Nothing
|
||||||
|
|
||||||
Try
|
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)
|
CvePrePoliza = ObjConta.AddPrePolizas("PVCobranza", 11, 0, 0, 1, Fecha, $"Pago {VentaActual.SerieFolio}", UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa, CveTipoPoliza:=3)
|
||||||
|
|
||||||
If CvePrePoliza > 0 Then
|
If CvePrePoliza > 0 Then
|
||||||
@@ -487,21 +507,41 @@ Partial Class Ventas_PVCobranza
|
|||||||
End Try
|
End Try
|
||||||
|
|
||||||
If MsgError = "" Then
|
If MsgError = "" Then
|
||||||
ObjConta.Commit()
|
ObjVentas2.Commit()
|
||||||
Alert($"Pago Registrado correctamente.<br/><br/> <a href=""/Compras/PopUpVerFactura.aspx?P={Encripta(String.Format("OP=VTA&CVEVENTA={0}&PAG=1&GUARDAR=1&TICKET=1®ENERAR=1", CveVenta))}"" class='Texto'>Imprimir ticket</a>", TipoMensaje.MsgInformacion)
|
|
||||||
|
'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("<br/> {0}", m)
|
||||||
|
Next
|
||||||
|
Else
|
||||||
|
msBuild.Append($"Pago Registrado correctamente.<br/><br/> <a href=""/Compras/PopUpVerFactura.aspx?P={Encripta(String.Format("OP=VTA&CVEVENTA={0}&PAG=1&GUARDAR=1&TICKET=1®ENERAR=1", CveVenta))}"" class='Texto'>Imprimir ticket</a>")
|
||||||
|
End If
|
||||||
|
|
||||||
|
Alert(msBuild.ToString(), TipoMensaje.MsgInformacion)
|
||||||
Else
|
Else
|
||||||
ObjConta.RollBack()
|
ObjVentas2.RollBack()
|
||||||
Alert(MsgError, TipoMensaje.MsgError)
|
Alert(MsgError, TipoMensaje.MsgError)
|
||||||
End If
|
End If
|
||||||
|
|
||||||
|
ObjVentas2.Dispose()
|
||||||
ObjConta.Dispose()
|
ObjConta.Dispose()
|
||||||
ObjIE.Dispose()
|
ObjIE.Dispose()
|
||||||
ObjVentas2.Dispose()
|
ObjClientes.Dispose()
|
||||||
|
|
||||||
If MsgError = "" Then
|
If MsgError = "" Then
|
||||||
Try
|
Try
|
||||||
If UsuarioActual.Empresa.Funcionalidad(109) = "1" Then
|
If UsuarioActual.Empresa.Funcionalidad(109) = "1" Then
|
||||||
ImpresionDirectaPDF(HdnCveVenta.Value.ToEntero)
|
ImpresionDirectaPDF(CveVenta)
|
||||||
End If
|
End If
|
||||||
|
|
||||||
PnlContado.Visible = False
|
PnlContado.Visible = False
|
||||||
@@ -517,6 +557,113 @@ Partial Class Ventas_PVCobranza
|
|||||||
|
|
||||||
End Sub
|
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} <br/>", msg)
|
||||||
|
Next
|
||||||
|
|
||||||
|
SbAlert.AppendFormat("<ul><li><a class=""Texto"" href=""/Compras/PopUpVerFactura.aspx?P={0}"">Descargar PDF Factura</a></li></ul><br/>", Encripta(String.Format("OP=VTA&CVEVENTA={0}&PAG=1&GUARDAR=1", Retorno.CveVenta)))
|
||||||
|
Else
|
||||||
|
SbAlert.Append("Ocurrió un error al generar la factura")
|
||||||
|
End If
|
||||||
|
Catch ex As Exception
|
||||||
|
SbAlert.Append("Ocurrió un error al generar el documento")
|
||||||
|
GuardaLog(ex.ToString())
|
||||||
|
End Try
|
||||||
|
|
||||||
|
If Retorno IsNot Nothing AndAlso Retorno.Mensajes IsNot Nothing AndAlso Retorno.Mensajes.Count > 0 Then
|
||||||
|
Retorno.Mensajes.Clear()
|
||||||
|
Retorno.Mensajes.Add(SbAlert.ToString())
|
||||||
|
|
||||||
|
If Not Retorno.TieneError Then
|
||||||
|
'CONVERTIR LA REMISION EN OBJETO DE FACTURA DE INGRESO, PARA HACER EL PAGO EN LA FACTURA
|
||||||
|
VentaRemision = Nothing
|
||||||
|
|
||||||
|
If ObjVentas.GetVenta(Retorno.CveVenta, UsuarioActual.CveEmpresa) Then
|
||||||
|
Dim DbRowVenta = ObjVentas.DtResultados.Copy().FiltroPrimero("")
|
||||||
|
|
||||||
|
If DbRowVenta IsNot Nothing Then
|
||||||
|
Dim VentaActual As New Venta(UsuarioActual)
|
||||||
|
VentaActual.CveVenta = Retorno.CveVenta
|
||||||
|
VentaActual.TipoDocto = DbRowVenta("TipoDocto").ToString
|
||||||
|
VentaActual.Fecha = DbRowVenta("Fecha").ToString.ToDate
|
||||||
|
VentaActual.CveCliente = DbRowVenta("CveCliente").ToString.ToEntero
|
||||||
|
VentaActual.CveMoneda = DbRowVenta("CveMoneda").ToString.ToEntero
|
||||||
|
VentaActual.SerieFolio = DbRowVenta("SerieFolio").ToString
|
||||||
|
VentaActual.ClienteNombre = DbRowVenta("ClienteNombre").ToString
|
||||||
|
VentaActual.TC = DbRowVenta("TipoCambio").ToString.ToDecimal
|
||||||
|
VentaActual.Total = DbRowVenta("Total").ToString.ToDecimal
|
||||||
|
VentaActual.IVA = DbRowVenta("IVA").ToString.ToDecimal
|
||||||
|
VentaActual.IEPS = DbRowVenta("IEPS").ToString.ToDecimal
|
||||||
|
VentaActual.RetIVA = DbRowVenta("RetIVA").ToString.ToDecimal
|
||||||
|
VentaActual.RetISR = DbRowVenta("RetISR").ToString.ToDecimal
|
||||||
|
|
||||||
|
VentaActual.PorcentajeIVA = DbRowVenta("PorcentajeIVA").ToString.ToDecimal
|
||||||
|
VentaActual.UsuarioActual = UsuarioActual
|
||||||
|
VentaActual.CveSubProyecto = DbRowVenta("CveSubProyecto").ToString.ToEntero
|
||||||
|
|
||||||
|
VentaRemision = VentaActual
|
||||||
|
End If
|
||||||
|
|
||||||
|
End If
|
||||||
|
|
||||||
|
End If
|
||||||
|
Else
|
||||||
|
Retorno = New Modelos.Factura.MMensajeFactura()
|
||||||
|
Retorno.TieneError = True
|
||||||
|
If SbAlert.Length = 0 Then
|
||||||
|
SbAlert.Append("Ocurrió un error al generar la factura")
|
||||||
|
End If
|
||||||
|
Retorno.Mensajes.Add(SbAlert.ToString())
|
||||||
|
End If
|
||||||
|
|
||||||
|
Return Retorno
|
||||||
|
End Function
|
||||||
|
|
||||||
Private Function RegistraIE(Metodo As Integer, CveBancoCuenta As Integer, ImportePago As Decimal, Fecha As Date, CvePrePoliza As Integer, VentaActual As Venta, ByRef ObjIE As ClsBancos, ByRef ObjConta As ClsContabilidad, ByRef ObjVentas As ClsVentas) As String
|
Private Function RegistraIE(Metodo As Integer, CveBancoCuenta As Integer, ImportePago As Decimal, Fecha As Date, CvePrePoliza As Integer, VentaActual As Venta, ByRef ObjIE As ClsBancos, ByRef ObjConta As ClsContabilidad, ByRef ObjVentas As ClsVentas) As String
|
||||||
Dim Retorno As String = ""
|
Dim Retorno As String = ""
|
||||||
Dim CveIEPago As Integer = 0
|
Dim CveIEPago As Integer = 0
|
||||||
@@ -755,17 +902,25 @@ Partial Class Ventas_PVCobranza
|
|||||||
|
|
||||||
Dim ExistePDF As Boolean = False
|
Dim ExistePDF As Boolean = False
|
||||||
Dim ArchivoPDF As String = ""
|
Dim ArchivoPDF As String = ""
|
||||||
|
|
||||||
|
Dim AplicaTicket As Boolean = ObjFactura.CveEmpresa.Contiene(190, 192)
|
||||||
|
|
||||||
If ObjFactura.TipoDocto = "Ing" Then
|
If ObjFactura.TipoDocto = "Ing" Then
|
||||||
ArchivoPDF = String.Format("{0}/PDF/{1}/{2}_Ticket.pdf", UsuarioActual.Empresa.Ruta, ObjFactura.TipoDocto, ObjFactura.SerieFolio)
|
If AplicaTicket Then
|
||||||
|
ArchivoPDF = String.Format("{0}/PDF/{1}/{2}_Ticket.pdf", UsuarioActual.Empresa.Ruta, ObjFactura.TipoDocto, ObjFactura.SerieFolio)
|
||||||
|
Else
|
||||||
|
ArchivoPDF = String.Format("{0}/PDF/{1}/{2}.pdf", UsuarioActual.Empresa.Ruta, ObjFactura.TipoDocto, ObjFactura.SerieFolio)
|
||||||
|
End If
|
||||||
Else
|
Else
|
||||||
ArchivoPDF = String.Format("{0}/PDF/{1}/{2}.pdf", UsuarioActual.Empresa.Ruta, ObjFactura.TipoDocto, ObjFactura.SerieFolio)
|
ArchivoPDF = String.Format("{0}/PDF/{1}/{2}.pdf", UsuarioActual.Empresa.Ruta, ObjFactura.TipoDocto, ObjFactura.SerieFolio)
|
||||||
End If
|
End If
|
||||||
|
|
||||||
If File.Exists(ArchivoPDF) AndAlso ObjFactura.TipoDocto = "Rem" Then
|
If File.Exists(ArchivoPDF) AndAlso ObjFactura.TipoDocto = "Rem" Then
|
||||||
ExistePDF = True
|
ExistePDF = True
|
||||||
Else
|
Else
|
||||||
'REGENERAR EL PDF
|
'REGENERAR EL PDF
|
||||||
Try
|
Try
|
||||||
GenerarPDFVenta(CveVenta, AplicaPagare:="1", GuardarPDF:=True, RegenerarPDF:=True, DescargarArchivo:=False, EsTicket:=True)
|
GenerarPDFVenta(CveVenta, AplicaPagare:="1", GuardarPDF:=True, RegenerarPDF:=True, DescargarArchivo:=False, EsTicket:=AplicaTicket)
|
||||||
If File.Exists(ArchivoPDF) Then
|
If File.Exists(ArchivoPDF) Then
|
||||||
ExistePDF = True
|
ExistePDF = True
|
||||||
End If
|
End If
|
||||||
|
|||||||
@@ -25597,7 +25597,7 @@ Partial Class Ventas
|
|||||||
|
|
||||||
Dim AplicaCancelacionConPagos As Boolean = False
|
Dim AplicaCancelacionConPagos As Boolean = False
|
||||||
|
|
||||||
If UsuarioActual.Empresa.Funcionalidad(109) = "1" AndAlso ObjFactura.TipoDocto.Contiene("Ing", "Rem") AndAlso Not EsRefacturacion AndAlso ObjFactura.Pagado > 0 Then
|
If UsuarioActual.CveRol = 1 AndAlso UsuarioActual.Empresa.Funcionalidad(109) = "1" AndAlso ObjFactura.TipoDocto.Contiene("Ing", "Rem") AndAlso Not EsRefacturacion AndAlso ObjFactura.Pagado > 0 Then
|
||||||
AplicaCancelacionConPagos = True
|
AplicaCancelacionConPagos = True
|
||||||
End If
|
End If
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user