-- cobranza en cobro de caja

This commit is contained in:
2025-01-23 13:54:43 -07:00
parent 93fa9eb3b3
commit bf9d9fa2e9
3 changed files with 376 additions and 158 deletions

View File

@@ -505,6 +505,7 @@ Partial Class Ventas_PVCobranza
TieneError = True
End If
HdnCveVenta.Value = CveVenta.ToString
HdnCveCliente.Value = GvRow.DataKey("CveCliente")
TxtImporteContado.Text = GvRow.DataKey("Saldo").FormatoNumero
HdnTotal.Value = GvRow.DataKey("Saldo")
TxtImporteEfectivo.Focus()
@@ -574,12 +575,12 @@ Partial Class Ventas_PVCobranza
Exit Sub
End If
If LtlSaldo.Text.ToDecimal() > Pagado Then
If LtlSaldo.Text.ToDecimal + TxtCxCAplicado.Text.ToDecimal > Pagado Then
Alert("Favor de especificar el saldo total de pagar", TipoMensaje.MsgAdvertencia)
Exit Sub
End If
Dim PagadoSinEfectivo As Decimal = Pagado - TxtImporteEfectivo.Text.ToDecimal
If PagadoSinEfectivo > LtlSaldo.Text.ToDecimal() Then
If PagadoSinEfectivo > (LtlSaldo.Text.ToDecimal() + TxtCxCAplicado.Text.ToDecimal) Then
Alert("El pago con los metodos de pago actuales no puede ser mayor al importe de la venta", TipoMensaje.MsgAdvertencia)
Exit Sub
End If
@@ -652,8 +653,9 @@ Partial Class Ventas_PVCobranza
Dim Fecha As Date = DbRowVenta("Fecha").ToString.ToDate 'NowADS()
Dim MsgError As String = ""
Dim SaldoPendiente As Decimal = DbRowVenta("Saldo").ToString.ToDecimal
Dim SaldoTotalInicial As Decimal = DbRowVenta("Saldo").ToString.ToDecimal
Dim SaldoPendienteVenta As Decimal = DbRowVenta("Saldo").ToString.ToDecimal
Dim SaldoTotalInicialVenta As Decimal = DbRowVenta("Saldo").ToString.ToDecimal
Dim SaldoPendientePagos As Decimal = TxtImporteContado.Text.ToDecimal
Dim PagoAplicado As Decimal = 0
Dim ObjVentas2 As New ClsVentas()
@@ -686,7 +688,7 @@ Partial Class Ventas_PVCobranza
If HdnTipoAmortizacion.Value = "4" Then
If respFactura.Factura.DtAnticiposAplicados IsNot Nothing Then
PagoAplicado += respFactura.Factura.DtAnticiposAplicados.SUM("Importe")
SaldoPendiente = SaldoPendiente - PagoAplicado
SaldoPendienteVenta = SaldoPendienteVenta - PagoAplicado
For Each RowAnt As DataRow In respFactura.Factura.DtAnticiposAplicados.Rows
If Not ActualizaAnticipos(RowAnt("CveIE").ToString().ToEntero(), RowAnt("CveVenta").ToString().ToEntero(), RowAnt("Tipo").ToString(), RowAnt("Folio").ToString(), ObjVentas2, ObjOIEventos) Then
@@ -716,7 +718,7 @@ Partial Class Ventas_PVCobranza
End If
Else
PagoAplicado += respNC.Factura.Total
SaldoPendiente = SaldoPendiente - PagoAplicado
SaldoPendienteVenta = SaldoPendienteVenta - PagoAplicado
For Each RowAnt As DataRow In respNC.Factura.DtAnticiposAplicados.Rows
If Not ActualizaAnticipos(RowAnt("CveIE").ToString().ToEntero(), RowAnt("CveVenta").ToString().ToEntero(), RowAnt("Tipo").ToString(), RowAnt("Folio").ToString(), ObjVentas2, ObjOIEventos) Then
@@ -732,7 +734,7 @@ Partial Class Ventas_PVCobranza
End If
If MsgError = "" Then
If SaldoPendiente > 0 AndAlso VentaContado Then
If SaldoPendienteVenta > 0 AndAlso VentaContado Then
If respFactura IsNot Nothing Then
CvePrePoliza = respFactura.Factura.CvePrePoliza
@@ -741,36 +743,40 @@ Partial Class Ventas_PVCobranza
End If
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, tCveCorte, CveSubProyecto:=VentaActual.CveSubProyecto)
SaldoPendiente -= TxtImporteCredito.Text.ToDecimal
If MsgError = "" AndAlso SaldoPendientePagos > 0 AndAlso TxtImporteCredito.Text.ToDecimal > 0 Then
MsgError = RegistraIE(12, DdlCuentaTarjetaCredito.SelectedValue.ToEntero, SaldoPendienteVenta, TxtImporteCredito.Text.ToDecimal, Fecha, CvePrePoliza, VentaActual, ObjIE, ObjConta, ObjVentas2, tCveCorte, CveSubProyecto:=VentaActual.CveSubProyecto)
SaldoPendienteVenta -= TxtImporteCredito.Text.ToDecimal
SaldoPendientePagos -= 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, tCveCorte, CveSubProyecto:=VentaActual.CveSubProyecto)
SaldoPendiente -= TxtImporteDebito.Text.ToDecimal
If MsgError = "" AndAlso SaldoPendientePagos > 0 AndAlso TxtImporteDebito.Text.ToDecimal > 0 Then
MsgError = RegistraIE(11, DdlCuentaTarjetaDebito.SelectedValue.ToEntero, SaldoPendienteVenta, TxtImporteDebito.Text.ToDecimal, Fecha, CvePrePoliza, VentaActual, ObjIE, ObjConta, ObjVentas2, tCveCorte, CveSubProyecto:=VentaActual.CveSubProyecto)
SaldoPendienteVenta -= TxtImporteDebito.Text.ToDecimal
SaldoPendientePagos -= TxtImporteDebito.Text.ToDecimal
PagoAplicado += TxtImporteDebito.Text.ToDecimal
End If
If SaldoPendiente > 0 AndAlso TxtImporteCheque.Text.ToDecimal > 0 Then
If SaldoPendientePagos > 0 AndAlso TxtImporteCheque.Text.ToDecimal > 0 Then
Dim Obs As String = ""
If DivDatosCheque.Visible Then
Obs = $"{VentaActual.SerieFolio} - Autorizó: {TxtAutorizo.Text}"
End If
MsgError = RegistraIE(3, DdlCuentaCheque.SelectedValue.ToEntero, TxtImporteCheque.Text.ToDecimal, Fecha, CvePrePoliza, VentaActual, ObjIE, ObjConta, ObjVentas2, tCveCorte, Obs:=Obs, CveAutorizacion:=TxtClaveAutorizacion.Text.Trim(), CveSubProyecto:=VentaActual.CveSubProyecto)
SaldoPendiente -= TxtImporteCheque.Text.ToDecimal
MsgError = RegistraIE(3, DdlCuentaCheque.SelectedValue.ToEntero, SaldoPendienteVenta, TxtImporteCheque.Text.ToDecimal, Fecha, CvePrePoliza, VentaActual, ObjIE, ObjConta, ObjVentas2, tCveCorte, Obs:=Obs, CveAutorizacion:=TxtClaveAutorizacion.Text.Trim(), CveSubProyecto:=VentaActual.CveSubProyecto)
SaldoPendienteVenta -= TxtImporteCheque.Text.ToDecimal
SaldoPendientePagos -= 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, tCveCorte, CveSubProyecto:=VentaActual.CveSubProyecto)
SaldoPendiente -= TxtImporteTransferencia.Text.ToDecimal
If MsgError = "" AndAlso SaldoPendientePagos > 0 AndAlso TxtImporteTransferencia.Text.ToDecimal > 0 Then
MsgError = RegistraIE(8, DdlCuentaTransferencia.SelectedValue.ToEntero, SaldoPendienteVenta, TxtImporteTransferencia.Text.ToDecimal, Fecha, CvePrePoliza, VentaActual, ObjIE, ObjConta, ObjVentas2, tCveCorte, CveSubProyecto:=VentaActual.CveSubProyecto)
SaldoPendienteVenta -= TxtImporteTransferencia.Text.ToDecimal
SaldoPendientePagos -= TxtImporteTransferencia.Text.ToDecimal
PagoAplicado += TxtImporteTransferencia.Text.ToDecimal
End If
If MsgError = "" AndAlso SaldoPendiente > 0 AndAlso TxtImporteOtrosContado.Text.ToDecimal > 0 Then
If MsgError = "" AndAlso SaldoPendientePagos > 0 AndAlso TxtImporteOtrosContado.Text.ToDecimal > 0 Then
Dim CveConceptroOtros As Integer = -1
Select Case DdlOtroFormaPago.SelectedValue
@@ -782,24 +788,27 @@ Partial Class Ventas_PVCobranza
CveConceptroOtros = 8
End Select
MsgError = RegistraIE(CveConceptroOtros, DdlCuentaOtrosContado.SelectedValue.ToEntero, TxtImporteOtrosContado.Text.ToDecimal, Fecha, CvePrePoliza, VentaActual, ObjIE, ObjConta, ObjVentas2, tCveCorte, CveSubProyecto:=VentaActual.CveSubProyecto)
SaldoPendiente -= TxtImporteOtrosContado.Text.ToDecimal
MsgError = RegistraIE(CveConceptroOtros, DdlCuentaOtrosContado.SelectedValue.ToEntero, SaldoPendienteVenta, TxtImporteOtrosContado.Text.ToDecimal, Fecha, CvePrePoliza, VentaActual, ObjIE, ObjConta, ObjVentas2, tCveCorte, CveSubProyecto:=VentaActual.CveSubProyecto)
SaldoPendienteVenta -= TxtImporteOtrosContado.Text.ToDecimal
SaldoPendientePagos -= TxtImporteOtrosContado.Text.ToDecimal
PagoAplicado += TxtImporteOtrosContado.Text.ToDecimal
End If
If MsgError = "" AndAlso SaldoPendiente > 0 AndAlso TxtImporteEfectivo.Text.ToDecimal > 0 Then
If MsgError = "" AndAlso SaldoPendientePagos > 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 PagoAplicado >= SaldoPendientePagos Then
TxtCambio.Text = (PagoAplicado - SaldoPendientePagos).FormatoNumero
PagoEfectivo = SaldoPendientePagos
End If
MsgError = RegistraIE(13, DdlCuentaEfectivo.SelectedValue.ToEntero, PagoEfectivo, Fecha, CvePrePoliza, VentaActual, ObjIE, ObjConta, ObjVentas2, tCveCorte, CveSubProyecto:=VentaActual.CveSubProyecto)
SaldoPendiente -= PagoEfectivo
If SaldoPendienteVenta < 0 Then SaldoPendienteVenta = 0
MsgError = RegistraIE(13, DdlCuentaEfectivo.SelectedValue.ToEntero, SaldoPendienteVenta, PagoEfectivo, Fecha, CvePrePoliza, VentaActual, ObjIE, ObjConta, ObjVentas2, tCveCorte, CveSubProyecto:=VentaActual.CveSubProyecto)
SaldoPendienteVenta -= PagoEfectivo
SaldoPendientePagos -= PagoEfectivo
End If
If SaldoPendiente > 0 Then
If SaldoPendienteVenta > 0 Then
MsgError = "Tiene saldo pendiente por aplicar"
End If
@@ -819,8 +828,50 @@ Partial Class Ventas_PVCobranza
End If
End If
If MsgError = "" Then
Dim CveIEPago As Integer = HdnCveIE.Value.ToEntero
'registrar los pagos a cobranza
For Each gvr As GridViewRow In GvCxC.Rows
If gvr.FCCheckBox("Chk").Checked Then
Dim VentaCxC As New Venta(UsuarioActual)
VentaCxC.CveVenta = gvr.DataKey("CveVenta").ToEntero
VentaCxC.TipoDocto = gvr.DataKey("TipoDocto")
VentaCxC.Fecha = gvr.DataKey("Fecha").ToDate
VentaCxC.CveCliente = gvr.DataKey("CveCliente").ToEntero
VentaCxC.CveMoneda = gvr.DataKey("CveMoneda").ToEntero
VentaCxC.SerieFolio = gvr.DataKey("SerieFolio")
VentaCxC.ClienteNombre = "sss" 'gvr.DataKey("ClienteNombre")
VentaCxC.TC = gvr.DataKey("TipoCambio").ToDecimal
VentaCxC.Total = gvr.DataKey("Total").ToDecimal
VentaCxC.IVA = gvr.DataKey("IVA").ToDecimal
VentaCxC.IEPS = gvr.DataKey("IEPS").ToDecimal
VentaCxC.RetIVA = gvr.DataKey("RetIVA").ToDecimal
VentaCxC.RetISR = gvr.DataKey("RetISR").ToDecimal
VentaCxC.PorcentajeIVA = gvr.DataKey("PorcentajeIVA").ToDecimal
VentaCxC.UsuarioActual = UsuarioActual
VentaCxC.CveSubProyecto = gvr.DataKey("CveSubProyecto").ToEntero
Dim Pago As New VentaPago
Pago.ImportePagoVenta = gvr.DataKey("Saldo").ToDecimal
Pago.ImportePago = gvr.DataKey("Saldo").ToDecimal
Pago.CveIE = CveIEPago
Pago.CveMonedaPago = VentaCxC.CveMoneda
Pago.Fecha = NowADS()
Pago.Referencia = VentaCxC.SerieFolio
Pago.TipoPago = "XXX"
Dim ErrorConta As Boolean = AplicaPrePolizaPagoVenta(VentaCxC, Pago, CvePrePoliza, ObjConta)
If ErrorConta Then
MsgError = "Error en aplicación de pago en cobranza"
End If
End If
Next
End If
Else
MsgError = "Error al registrar prepólizas"
MsgError = "Error al registrar prepólizas"
End If
Else
'SI NO TIENE SALDO PENDIENTE NO GENERAR POLIZA PARA EL PAGO
@@ -1020,6 +1071,7 @@ Partial Class Ventas_PVCobranza
TxtImporteTransferencia.Text = ""
TxtImporteOtrosContado.Text = ""
TxtCambio.Text = ""
TxtCxCAplicado.Text = ""
TxtClaveAutorizacion.Text = ""
TxtAutorizo.Text = ""
TxtNCDev.Text = ""
@@ -1028,7 +1080,6 @@ Partial Class Ventas_PVCobranza
CveCliente = -1
CveVendedor = -1
If TmpDTAnticiposNCIxCCliente IsNot Nothing Then
TmpDTAnticiposNCIxCCliente.Clear()
TmpDTAnticiposNCIxCCliente = Nothing
@@ -1216,12 +1267,12 @@ Partial Class Ventas_PVCobranza
For Each dr As DataRow In DtAnticipos.Rows
SBAmortizaciones.AppendLine($"<br><a class=""Texto"" target='_blank' href=""/Compras/PopUpVerFactura.aspx?P={Encripta(String.Format("OP=AMORTIZACIONHIS&CVEIE={0}&CVEVENTA={1}&CVECLIENTE={2}&CVEVENTAAMORTIZADA={3}&MONTO={4}&SALDO={5}",
dr("CveIE").ToString,
dr("CveVenta").ToString,
Retorno.Factura.CveCliente,
Retorno.CveVenta,
Retorno.Factura.Total,
(Retorno.Factura.Total - Retorno.Factura.DtAnticiposAplicados.SUM("Importe"))))}"">Imprimir historial {dr("Folio").ToString}</a><br/>")
dr("CveIE").ToString,
dr("CveVenta").ToString,
Retorno.Factura.CveCliente,
Retorno.CveVenta,
Retorno.Factura.Total,
(Retorno.Factura.Total - Retorno.Factura.DtAnticiposAplicados.SUM("Importe"))))}"">Imprimir historial {dr("Folio").ToString}</a><br/>")
Next
@@ -1488,7 +1539,7 @@ Partial Class Ventas_PVCobranza
Return MsgErrorTimbrado
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, tCveCorte As Integer, Optional Obs As String = "", Optional CveAutorizacion As String = "", Optional CveSubProyecto As Integer = -1) As String
Private Function RegistraIE(Metodo As Integer, CveBancoCuenta As Integer, ImporteAbonoVenta As Decimal, ImporteBancos 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, Optional Obs As String = "", Optional CveAutorizacion As String = "", Optional CveSubProyecto As Integer = -1) As String
Dim Retorno As String = ""
If CveBancoCuenta > 0 Then
Dim CveIEPago As Integer = 0
@@ -1496,25 +1547,31 @@ Partial Class Ventas_PVCobranza
If String.IsNullOrEmpty(Obs) Then
Obs = VentaActual.SerieFolio
End If
CveIEPago = ObjIE.AddBancos_IE(CveBancoCuenta, Metodo, Fecha, "-1", VentaActual.ClienteNombre, ImportePago, 1, 1, Obs, "", False, True, 0, CvePrePoliza, "", UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa, CveCorte:=tCveCorte, CveAutorizacion:=CveAutorizacion, CveSubProyecto:=CveSubProyecto)
CveIEPago = ObjIE.AddBancos_IE(CveBancoCuenta, Metodo, Fecha, "-1", VentaActual.ClienteNombre, ImporteBancos, 1, 1, Obs, "", False, True, 0, CvePrePoliza, "", UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa, CveCorte:=tCveCorte, CveAutorizacion:=CveAutorizacion, CveSubProyecto:=CveSubProyecto)
If CveIEPago > 0 Then
Dim Pago As New VentaPago
Pago.ImportePagoVenta = ImportePago
Pago.ImportePago = ImportePago
Pago.CveIE = CveIEPago
Pago.CveMonedaPago = VentaActual.CveMoneda
Pago.Fecha = NowADS()
Pago.Referencia = VentaActual.SerieFolio
Dim tImportePago As Decimal = If(ImporteBancos > ImporteAbonoVenta, ImporteAbonoVenta, ImporteBancos) 'toma el importe menor para la factura
If ImporteBancos > 0 Then
Dim Pago As New VentaPago
Pago.ImportePagoVenta = tImportePago
Pago.ImportePago = ImporteBancos
Pago.CveIE = CveIEPago
Pago.CveMonedaPago = VentaActual.CveMoneda
Pago.Fecha = NowADS()
Pago.Referencia = VentaActual.SerieFolio
ErrorConta = AplicaPrePolizaPagoVenta(VentaActual, Pago, CvePrePoliza, ObjConta)
End If
ErrorConta = AplicaPrePolizaPagoVenta(VentaActual, Pago, CvePrePoliza, ObjConta)
If ErrorConta Then
Retorno = "Error en aplicación de pago"
End If
Dim MetodoPago As Integer = If(Metodo = 13, 1, If(Metodo = 12, 4, If(Metodo = 11, 5, If(Metodo = 3, 2, 3))))
If Not ErrorConta AndAlso Not ObjVentas.AddVta_VentaPago(VentaActual.CveVenta, MetodoPago, ImportePago) Then
If Not ErrorConta AndAlso Not ObjVentas.AddVta_VentaPago(VentaActual.CveVenta, MetodoPago, ImporteBancos) Then
Retorno = "Error en aplicación de pago.."
ErrorConta = True
End If
HdnCveIE.Value = CveIEPago.ToString
Else
Retorno = "Pago en Bancos no registrado"
ErrorConta = True
@@ -2918,6 +2975,44 @@ Partial Class Ventas_PVCobranza
End Sub
Protected Sub LnkCxC_Click(sender As Object, e As EventArgs)
CargaCxC(1, HdnCveCliente.Value.ToEntero) 'solo pesos
End Sub
Private Sub CargaCxC(pCveMoneda As Integer, pCveCliente As Integer)
Dim Mov As New ClsMovimientos
Dim FechaI As String = IfNull(Request("FechaI"), "-1").ToString
Dim FechaF As String = IfNull(Request("FechaF"), "-1").ToString
Dim FechaCorte As Date = NowADS().AddYears(1).ToShortDateString.ToString.ToDate
If Mov.GetCxCClienteDetalle(pCveCliente, FechaI, FechaF, pCveMoneda, -1, UsuarioActual.CveEmpresa, -1, FechaCorte:=FechaCorte) Then
Dim TmpCxCAux As DataTable
TmpCxCAux = Mov.DtResultados.FiltraParametros("Saldo > 0 AND TipoDocto = 'Ing'", "Fecha,SerieFolio")
GvCxC.DataSource = Mov.DtResultados.FiltraParametros("Saldo > 0 AND TipoDocto = 'Ing'", "Fecha,SerieFolio")
End If
Mov.Dispose()
GvCxC.DataBind()
TxtCxCAplicado.Text = ""
UPPCxC.Update()
RegistraScript("$('#divCxC').modal('show');", "AE2")
End Sub
Protected Sub BtnAplicarCxC_Click(sender As Object, e As EventArgs)
Dim SaldoCxC As Decimal = 0
For Each GvRow As GridViewRow In GvCxC.Rows
If GvRow.FCCheckBox("Chk") IsNot Nothing AndAlso GvRow.FCCheckBox("Chk").Checked Then
SaldoCxC += GvRow.DataKey("Saldo").ToDecimal
End If
Next
TxtCxCAplicado.Text = (SaldoCxC).FormatoNumero
TxtImporteContado.Text = (LtlSaldo.Text.ToDecimal + SaldoCxC).FormatoNumero
RegistraScript("$('#divCxC').hide();", "AE21")
UPPCobranza.Update()
UPPTotalesContado.update
End Sub
End Class
Public Class MRespuestaSAT