+
+
+
+
+
+
diff --git a/Ventas/PVCobranza.aspx.vb b/Ventas/PVCobranza.aspx.vb
new file mode 100644
index 000000000..ba2db00f7
--- /dev/null
+++ b/Ventas/PVCobranza.aspx.vb
@@ -0,0 +1,235 @@
+Option Explicit On
+Option Strict On
+
+Imports System.Data
+Imports System.Runtime.Remoting
+Imports Extensiones
+
+Partial Class Ventas_PVCobranza
+ Inherits ClsPaginas
+
+ Protected Sub Page_Load(sender As Object, e As System.EventArgs) Handles Me.Load
+ If Not Page.IsPostBack Then
+ CargaFiltros()
+ End If
+ End Sub
+
+ Private Sub CargaFiltros()
+
+ DdlSubProyecto.DataSource = GlobalDTSubProyectosUsuarios(UsuarioActual.CveUsuario, -1, UsuarioActual.CveEmpresa, -1, 1)
+ DdlSubProyecto.DataBind()
+
+ txtFechaI.Text = Now.AddYears(-1).ToShortDateString
+ txtFechaF.Text = Now.ToShortDateString
+
+ 'DdlCuentaEfectivo.Items.Clear()
+ 'DdlCuentaTarjetaCredito.Items.Clear()
+ 'DdlCuentaTarjetaDebito.Items.Clear()
+ 'DdlCuentaCheque.Items.Clear()
+ 'DdlCuentaTransferencia.Items.Clear()
+
+ Dim DtCC As DataTable = GlobalDTBancosCuentas(UsuarioActual.CveUsuario, CveEmpresa:=UsuarioActual.CveEmpresa)
+ Dim CveMon As Integer = 1
+
+ 'MOSTRAR SOLO CUENTAS DE CONTADO EN BDH
+ 'If UsuarioActual.Empresa.Funcionalidad(531) = "1" Then
+ DdlCuentaEfectivo.DataSource = DtCC.FiltraParametros(String.Format("CveMoneda = {0} AND CveTipoCuenta = 1 AND TieneTerminal = 0", CveMon))
+ DdlCuentaCheque.DataSource = DtCC.FiltraParametros(String.Format("CveMoneda = {0} AND CveTipoCuenta = 1 AND TieneTerminal = 0", CveMon))
+ 'Else
+ ' DdlCuentaEfectivo.DataSource = DtCC.FiltraParametros(String.Format("CveMoneda = {0} AND CveTipoCuenta = 1", CveMon))
+ ' DdlCuentaCheque.DataSource = DtCC.FiltraParametros(String.Format("CveMoneda = {0} AND CveTipoCuenta = 1", CveMon))
+ 'End If
+
+ 'If UsuarioActual.Empresa.Funcionalidad(558) = "1" OrElse UsuarioActual.Empresa.Funcionalidad(531) = "1" Then
+ DdlCuentaTarjetaCredito.DataSource = DtCC.FiltraParametros(String.Format("CveMoneda = {0} AND CveTipoCuenta = 1 AND TieneTerminal = 1", CveMon))
+ DdlCuentaTarjetaDebito.DataSource = DtCC.FiltraParametros(String.Format("CveMoneda = {0} AND CveTipoCuenta = 1 AND TieneTerminal = 1", CveMon))
+ 'Else
+ ' DdlCuentaTarjetaCredito.DataSource = DtCC.FiltraParametros(String.Format("CveMoneda = {0} AND (CveTipoCuenta <> 1 OR TieneTerminal = 1)", CveMon))
+ 'DdlCuentaTarjetaDebito.DataSource = DtCC.FiltraParametros(String.Format("CveMoneda = {0} AND (CveTipoCuenta <> 1 OR TieneTerminal = 1)", CveMon))
+ 'End If
+
+ DdlCuentaTransferencia.DataSource = DtCC.FiltraParametros(String.Format("CveMoneda = {0} AND CveTipoCuenta <> 1", CveMon))
+
+ DtCC.Dispose()
+
+ DdlCuentaEfectivo.DataBind()
+ DdlCuentaTarjetaCredito.DataBind()
+ DdlCuentaTarjetaDebito.DataBind()
+ DdlCuentaCheque.DataBind()
+ DdlCuentaTransferencia.DataBind()
+
+ End Sub
+
+ Private Sub CargaDatos()
+
+ Dim ObjMovtos As New ClsMovimientos()
+ Dim FechaI, FechaF As Date
+ FechaI = If(IsDate(txtFechaI.Text.Trim()), txtFechaI.Text.Trim().ToDate, MinFecha)
+ FechaF = If(IsDate(txtFechaF.Text.Trim()), txtFechaF.Text.Trim().ToDate, MaxFecha).AddDays(1)
+
+ If ObjMovtos.GetCxCDetalle(FechaI, FechaF, -1, DdlSubProyecto.SelectedValue.ToEntero, -1, -1, -1, -1, "-1", "-1", -1, "-1", -1,
+ "-1", 1, UsuarioActual.CveEmpresa, -1, 1,
+ TipoDocto:="Rem", FechaCorte:=NowADS.AddDays(1), CveUsuarioConsulta:=UsuarioActual.CveUsuario, AplicaAnticiposPagados:=0) Then
+
+ Dim dtt As DataTable = ObjMovtos.DSResultados.Tables(0).FiltraParametros("CveVenta > 0")
+ 'si hay ya asignado, solo la mostrará
+ Dim Dtta As DataTable = dtt.FiltraParametros($"CveUsuarioCobranza = {UsuarioActual.CveUsuario}")
+ If Dtta IsNot Nothing AndAlso Dtta.Rows.Count > 0 Then dtt = Dtta
+ GvDatos.DataSource = dtt
+ End If
+ ObjMovtos.Dispose()
+ GvDatos.DataBind()
+ UpL.Update()
+
+ End Sub
+
+ Protected Sub BtnConsultar_Click(sender As Object, e As EventArgs) Handles BtnConsultar.Click
+ CargaDatos()
+ End Sub
+
+ Private Sub GvDatos_RowDataBound(sender As Object, e As GridViewRowEventArgs) Handles GvDatos.RowDataBound
+ If e.Row.RowType = DataControlRowType.DataRow Then
+
+ If e.Row.DBCampo("CveUsuarioCobranza") <> "" Then
+ e.Row.BackColor = Drawing.ColorTranslator.FromHtml("#3598dc")
+ 'e.Row.CssClass = "blue-madison"
+ End If
+ End If
+ End Sub
+
+ Private Sub GvDatos_RowCommand(sender As Object, e As GridViewCommandEventArgs) Handles GvDatos.RowCommand
+ If e.CommandName = "Cobrar" Then
+ Dim ImgBtn As LinkButton = DirectCast(e.CommandSource, LinkButton)
+ Dim GvRow As GridViewRow = DirectCast(ImgBtn.BindingContainer, GridViewRow)
+ Dim TieneError As Boolean = False
+
+ Dim CveVenta As Integer = e.CommandArgument.ToString.ToEntero
+ Dim ObjVentas As New ClsVentas
+ ObjVentas.IniciaTransacSQL()
+ If Not ObjVentas.UpdateAsignaVentaCobranza(CveVenta, 1, UsuarioActual.CveUsuario, -1, "", Now) Then
+ TieneError = True
+ End If
+ HdnCveVenta.Value = CveVenta.ToString
+ TxtImporteEfectivo.Text = GvRow.DataKey("Saldo")
+ TxtImporteEfectivo.Focus()
+ LtlNombre.Text = GvRow.DataKey("DescripcionVenta")
+ LtlSaldo.Text = GvRow.DataKey("Saldo").ToDecimal.FormatoNumero
+ 'carga información para cobranza
+
+ If Not TieneError Then
+ ObjVentas.Commit()
+ PnlContado.Visible = True
+ Else
+ ObjVentas.RollBack()
+ PnlContado.Visible = False
+ Alert("Hubo un error al asignar datos de cobranza", TipoMensaje.MsgInformacion)
+ End If
+
+ ObjVentas.Dispose()
+ 'CargaDatos()
+ End If
+ End Sub
+
+ Private Sub BtnPagar_Click(sender As Object, e As EventArgs) Handles BtnPagar.Click
+ 'registrar pago
+
+ 'validaciones
+ If TxtImporteEfectivo.Text.ToDecimal + TxtImporteCredito.Text.ToDecimal + TxtImporteDebito.Text.ToDecimal + TxtImporteCheque.Text.ToDecimal = 0 Then
+ Alert("Favor de especificar importe", TipoMensaje.ToastAdventencia)
+ Exit Sub
+ End If
+
+ Dim CveVenta As Integer = HdnCveVenta.Value.ToEntero
+ Dim ObjVentas As New ClsVentas
+ If ObjVentas.GetVenta(CveVenta, UsuarioActual.CveEmpresa) Then
+ Dim DbRowVenta As DataRow = ObjVentas.DtResultados.FiltroPrimero("")
+
+ Dim VentaActual As New Venta(UsuarioActual)
+ VentaActual.CveVenta = CveVenta
+
+ 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
+
+ Dim ObjConta As New ClsContabilidad
+ Dim ObjIE As New ClsBancos(ObjConta.IniciaTransacSQL())
+
+ Dim CvePrePoliza As Integer
+ Dim Fecha As Date = NowADS()
+ Dim Mensaje As String = ""
+
+ CvePrePoliza = ObjConta.AddPrePolizas("PVCobranza", 5, 0, 0, 1, Fecha, $"Pago {VentaActual.SerieFolio}", UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa)
+
+ If CvePrePoliza > 0 Then
+
+ If TxtImporteEfectivo.Text.ToDecimal > 0 Then
+ Mensaje = RegistraIE(13, DdlCuentaEfectivo.SelectedValue.ToEntero, TxtImporteEfectivo.Text.ToDecimal, Fecha, CvePrePoliza, VentaActual, ObjIE, ObjConta)
+ End If
+ If TxtImporteCredito.Text.ToDecimal > 0 Then
+ Mensaje = RegistraIE(12, DdlCuentaTarjetaCredito.SelectedValue.ToEntero, TxtImporteCredito.Text.ToDecimal, Fecha, CvePrePoliza, VentaActual, ObjIE, ObjConta)
+ End If
+ If TxtImporteDebito.Text.ToDecimal > 0 Then
+ Mensaje = RegistraIE(11, DdlCuentaTarjetaDebito.SelectedValue.ToEntero, TxtImporteDebito.Text.ToDecimal, Fecha, CvePrePoliza, VentaActual, ObjIE, ObjConta)
+ End If
+ If TxtImporteCheque.Text.ToDecimal > 0 Then
+ Mensaje = RegistraIE(3, DdlCuentaCheque.SelectedValue.ToEntero, TxtImporteCheque.Text.ToDecimal, Fecha, CvePrePoliza, VentaActual, ObjIE, ObjConta)
+ End If
+
+ Else
+ Mensaje = "Error al registrar prepólizas"
+ End If
+
+ If Mensaje = "" Then
+ PnlContado.Visible = False
+ ObjConta.Commit()
+ CargaDatos()
+ Alert("Pago Registrado correctamente.", TipoMensaje.MsgInformacion)
+ Else
+ ObjConta.RollBack()
+ End If
+
+ End If
+
+
+
+ End Sub
+
+ 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) 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)
+ 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
+
+ ErrorConta = AplicaPrePolizaPagoVenta(VentaActual, Pago, CvePrePoliza, ObjConta)
+ If ErrorConta Then
+ Retorno = "Error en aplicación de pago"
+ End If
+ Else
+ Retorno = "Pago en Bancos no registrado"
+ ErrorConta = True
+ End If
+
+ Return Retorno
+ End Function
+
+End Class