diff --git a/Ventas/PVCobranza.aspx.vb b/Ventas/PVCobranza.aspx.vb index f7939e85d..b71acda4a 100644 --- a/Ventas/PVCobranza.aspx.vb +++ b/Ventas/PVCobranza.aspx.vb @@ -2,7 +2,7 @@ Option Strict On Imports System.Data -Imports System.IO +Imports System.IO Imports Extensiones Partial Class Ventas_PVCobranza @@ -17,8 +17,6 @@ Partial Class Ventas_PVCobranza End Set End Property - - Private Property DineroCaja As Double Get Return If(IsNothing(ViewState("DineroCaja")), 0, ViewState("DineroCaja").ToString().ToDecimal()) @@ -183,7 +181,7 @@ Partial Class Ventas_PVCobranza If ObjPVenta.GetVta_Cortes("-1", "-1", UsuarioActual.CveUsuario, -1, UsuarioActual.CveEmpresa, 0) Then If ObjPVenta.DtResultados.Rows.Count > 0 Then - Total = ObjPVenta.DtResultados(0)("ImporteInicial").ToString().ToDouble + ObjPVenta.DtResultados(0)("VentasEfectivo").ToString().ToDouble + ObjPVenta.DtResultados(0)("Ingresado").ToString().ToDouble - ObjPVenta.DtResultados(0)("Retirado").ToString().ToDouble - ObjPVenta.DtResultados(0)("Devoluciones").ToString().ToDouble + Total = ObjPVenta.DtResultados(0)("ImporteInicial").ToString.ToDouble + ObjPVenta.DtResultados(0)("VentasEfectivo").ToString().ToDouble + ObjPVenta.DtResultados(0)("Ingresado").ToString().ToDouble - ObjPVenta.DtResultados(0)("Retirado").ToString().ToDouble - ObjPVenta.DtResultados(0)("Devoluciones").ToString().ToDouble DineroCaja = Total LblEfectivoEsperado.Text = Total.FormatoNumero(2) LblEfectivoBloqueo.Text = Total.FormatoNumero(2) @@ -388,6 +386,7 @@ Partial Class Ventas_PVCobranza End If Dim PagadoSinEfectivo As Decimal = Pagado - TxtImporteEfectivo.Text.ToDecimal + Dim tCveCorte As Integer = CveCorte If PagadoSinEfectivo > LtlSaldo.Text.ToDecimal() Then Alert("El pago con los metodos de pago actuales no puede ser mayor al importe de la venta", TipoMensaje.MsgAdvertencia) @@ -422,9 +421,10 @@ Partial Class Ventas_PVCobranza VentaActual.PorcentajeIVA = DbRowVenta("PorcentajeIVA").ToString.ToDecimal VentaActual.UsuarioActual = UsuarioActual VentaActual.CveSubProyecto = DbRowVenta("CveSubProyecto").ToString.ToEntero + If tCveCorte <= 0 AndAlso DbRowVenta("CveCorte").ToString.ToEntero > 0 Then tCveCorte = DbRowVenta("CveCorte").ToString.ToEntero Dim CvePrePoliza As Integer - Dim Fecha As Date = NowADS() + Dim Fecha As Date = DbRowVenta("Fecha").ToString.ToDate 'NowADS() Dim MsgError As String = "" Dim SaldoPendiente As Decimal = DbRowVenta("Saldo").ToString.ToDecimal @@ -440,75 +440,76 @@ Partial Class Ventas_PVCobranza Try 'FACTURAR LA REMISION PARA HACER EL PAGO - If UsuarioActual.CveEmpresa = 189 AndAlso VentaActual.TipoDocto = "Rem" Then + If UsuarioActual.CveEmpresa.Contiene(189, 197) AndAlso VentaActual.TipoDocto = "Rem" Then respFactura = GenerarFactura(VentaActual, ObjVentas2, ObjClientes) If respFactura Is Nothing Then - MsgError = "Ocurrío un error al generar la factura" + MsgError = "Ocurrió 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 MsgError = "" Then + 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 - If MsgError = "" AndAlso SaldoPendiente > 0 AndAlso TxtImporteCredito.Text.ToDecimal > 0 Then - MsgError = RegistraIE(12, DdlCuentaTarjetaCredito.SelectedValue.ToEntero, TxtImporteCredito.Text.ToDecimal, Fecha, CvePrePoliza, VentaActual, ObjIE, ObjConta, ObjVentas2) - SaldoPendiente -= TxtImporteCredito.Text.ToDecimal - PagoAplicado += TxtImporteCredito.Text.ToDecimal - End If - - If MsgError = "" AndAlso SaldoPendiente > 0 AndAlso TxtImporteDebito.Text.ToDecimal > 0 Then - MsgError = RegistraIE(11, DdlCuentaTarjetaDebito.SelectedValue.ToEntero, TxtImporteDebito.Text.ToDecimal, Fecha, CvePrePoliza, VentaActual, ObjIE, ObjConta, ObjVentas2) - SaldoPendiente -= TxtImporteDebito.Text.ToDecimal - PagoAplicado += TxtImporteDebito.Text.ToDecimal - End If - - If SaldoPendiente > 0 AndAlso TxtImporteCheque.Text.ToDecimal > 0 Then - MsgError = RegistraIE(3, DdlCuentaCheque.SelectedValue.ToEntero, TxtImporteCheque.Text.ToDecimal, Fecha, CvePrePoliza, VentaActual, ObjIE, ObjConta, ObjVentas2) - SaldoPendiente -= TxtImporteCheque.Text.ToDecimal - PagoAplicado += TxtImporteCheque.Text.ToDecimal - End If - - If MsgError = "" AndAlso SaldoPendiente > 0 AndAlso TxtImporteTransferencia.Text.ToDecimal > 0 Then - MsgError = RegistraIE(8, DdlCuentaTransferencia.SelectedValue.ToEntero, TxtImporteTransferencia.Text.ToDecimal, Fecha, CvePrePoliza, VentaActual, ObjIE, ObjConta, ObjVentas2) - SaldoPendiente -= TxtImporteTransferencia.Text.ToDecimal - PagoAplicado += TxtImporteTransferencia.Text.ToDecimal - End If - - If MsgError = "" AndAlso SaldoPendiente > 0 AndAlso TxtImporteEfectivo.Text.ToDecimal > 0 Then - Dim PagoEfectivo As Decimal = TxtImporteEfectivo.Text.ToDecimal - - PagoAplicado += PagoEfectivo - If PagoAplicado >= SaldoTotalInicial Then - TxtCambio.Text = (PagoAplicado - SaldoTotalInicial).FormatoNumero - PagoEfectivo = SaldoPendiente + If MsgError = "" AndAlso SaldoPendiente > 0 AndAlso TxtImporteCredito.Text.ToDecimal > 0 Then + MsgError = RegistraIE(12, DdlCuentaTarjetaCredito.SelectedValue.ToEntero, TxtImporteCredito.Text.ToDecimal, Fecha, CvePrePoliza, VentaActual, ObjIE, ObjConta, ObjVentas2, tCveCorte) + SaldoPendiente -= TxtImporteCredito.Text.ToDecimal + PagoAplicado += TxtImporteCredito.Text.ToDecimal End If - MsgError = RegistraIE(13, DdlCuentaEfectivo.SelectedValue.ToEntero, PagoEfectivo, Fecha, CvePrePoliza, VentaActual, ObjIE, ObjConta, ObjVentas2) - SaldoPendiente -= PagoEfectivo - End If - If SaldoPendiente > 0 Then - MsgError = "Tiene saldo pendiente por aplicar" - End If + If MsgError = "" AndAlso SaldoPendiente > 0 AndAlso TxtImporteDebito.Text.ToDecimal > 0 Then + MsgError = RegistraIE(11, DdlCuentaTarjetaDebito.SelectedValue.ToEntero, TxtImporteDebito.Text.ToDecimal, Fecha, CvePrePoliza, VentaActual, ObjIE, ObjConta, ObjVentas2, tCveCorte) + SaldoPendiente -= TxtImporteDebito.Text.ToDecimal + PagoAplicado += TxtImporteDebito.Text.ToDecimal + End If - If MsgError = "" AndAlso Not ObjVentas2.UpdateVentaCorte(CveVenta, UsuarioActual.CveEmpresa, CveCorte) Then - MsgError = "Error al aplicar el corte" - End If + If SaldoPendiente > 0 AndAlso TxtImporteCheque.Text.ToDecimal > 0 Then + MsgError = RegistraIE(3, DdlCuentaCheque.SelectedValue.ToEntero, TxtImporteCheque.Text.ToDecimal, Fecha, CvePrePoliza, VentaActual, ObjIE, ObjConta, ObjVentas2, tCveCorte) + SaldoPendiente -= TxtImporteCheque.Text.ToDecimal + PagoAplicado += TxtImporteCheque.Text.ToDecimal + End If - If MsgError = "" AndAlso Not ObjVentas2.UpdateVentaTicketImpreso(CveVenta, 0) Then - MsgError = "No se pudo desmarcar la impresión" - End If + If MsgError = "" AndAlso SaldoPendiente > 0 AndAlso TxtImporteTransferencia.Text.ToDecimal > 0 Then + MsgError = RegistraIE(8, DdlCuentaTransferencia.SelectedValue.ToEntero, TxtImporteTransferencia.Text.ToDecimal, Fecha, CvePrePoliza, VentaActual, ObjIE, ObjConta, ObjVentas2, tCveCorte) + SaldoPendiente -= TxtImporteTransferencia.Text.ToDecimal + PagoAplicado += TxtImporteTransferencia.Text.ToDecimal + End If - Else - MsgError = "Error al registrar prepólizas" + If MsgError = "" AndAlso SaldoPendiente > 0 AndAlso TxtImporteEfectivo.Text.ToDecimal > 0 Then + Dim PagoEfectivo As Decimal = TxtImporteEfectivo.Text.ToDecimal + + PagoAplicado += PagoEfectivo + If PagoAplicado >= SaldoTotalInicial Then + TxtCambio.Text = (PagoAplicado - SaldoTotalInicial).FormatoNumero + PagoEfectivo = SaldoPendiente + End If + MsgError = RegistraIE(13, DdlCuentaEfectivo.SelectedValue.ToEntero, PagoEfectivo, Fecha, CvePrePoliza, VentaActual, ObjIE, ObjConta, ObjVentas2, tCveCorte) + SaldoPendiente -= PagoEfectivo + End If + + If SaldoPendiente > 0 Then + MsgError = "Tiene saldo pendiente por aplicar" + End If + + If MsgError = "" AndAlso Not ObjVentas2.UpdateVentaCorte(CveVenta, UsuarioActual.CveEmpresa, tCveCorte) Then + MsgError = "Error al aplicar el corte" + End If + + If MsgError = "" AndAlso Not ObjVentas2.UpdateVentaTicketImpreso(CveVenta, 0) Then + MsgError = "No se pudo desmarcar la impresión" + End If + + Else + MsgError = "Error al registrar prepólizas" + End If End If Catch ex As Exception MsgError = "Error al registrar el pago" @@ -517,16 +518,14 @@ Partial Class Ventas_PVCobranza If MsgError = "" Then ObjVentas2.Commit() - + Dim msBuild As New StringBuilder() '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) + msBuild.Append("La factura no se pudo timbrar
") 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 @@ -632,7 +631,7 @@ Partial Class Ventas_PVCobranza 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.CveAlmacen = GlobalDTAlmacen(UsuarioActual.CveEmpresa).FiltroPrimeroValor("CveAlmacen", $"CveTipoAlmacen = 1 AND CveSubProyecto = {VentaRemision.CveSubProyecto}", "Orden").ToString().ToEntero() ObjFactura.CalculaTotales() ObjFactura.PreparaTimbre() @@ -706,11 +705,11 @@ Partial Class Ventas_PVCobranza 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, tCveCorte As Integer) As String Dim Retorno As String = "" Dim CveIEPago As Integer = 0 Dim ErrorConta As Boolean - CveIEPago = ObjIE.AddBancos_IE(CveBancoCuenta, Metodo, Fecha, "-1", VentaActual.ClienteNombre, ImportePago, 1, 1, VentaActual.SerieFolio, "", False, True, 0, CvePrePoliza, "", UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa, CveCorte:=CveCorte) + CveIEPago = ObjIE.AddBancos_IE(CveBancoCuenta, Metodo, Fecha, "-1", VentaActual.ClienteNombre, ImportePago, 1, 1, VentaActual.SerieFolio, "", False, True, 0, CvePrePoliza, "", UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa, CveCorte:=tCveCorte) If CveIEPago > 0 Then Dim Pago As New VentaPago Pago.ImportePagoVenta = ImportePago