Files
SIG/Ventas/PVCobranza.aspx.vb
rrene 2d98625aef -- mejora.
--- facturaglobal. considerar de todos los clientes para emitir
2024-03-29 10:11:49 -07:00

667 lines
30 KiB
VB.net

Option Explicit On
Option Strict On
Imports System.Data
Imports System.IO
Imports Extensiones
Partial Class Ventas_PVCobranza
Inherits ClsPaginas
Private Property CveCorte As Integer
Get
Return ViewState("CveCorte").ToString.ToEntero
End Get
Set(value As Integer)
ViewState("CveCorte") = value
End Set
End Property
Private Property DineroCaja As Double
Get
Return If(IsNothing(ViewState("DineroCaja")), 0, ViewState("DineroCaja").ToString().ToDecimal())
End Get
Set(value As Double)
ViewState("DineroCaja") = value
End Set
End Property
Protected Sub Page_Load(sender As Object, e As System.EventArgs) Handles Me.Load
If Not Page.IsPostBack Then
CveCorte = 0
CargaFiltros()
If UsuarioActual.TienePermisoProceso(371) Then
CargaCorteCaja()
End If
End If
End Sub
Private Sub CargaFiltros()
DdlSubProyecto.DataSource = GlobalDTSubProyectosUsuarios(UsuarioActual.CveUsuario, -1, UsuarioActual.CveEmpresa, -1, 1)
DdlSubProyecto.DataBind()
txtFechaI.Text = Now.AddDays(-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", CveMon))
DdlCuentaCheque.DataSource = DtCC.FiltraParametros(String.Format("CveMoneda = {0} AND CveTipoCuenta = 1", CveMon))
'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))
DdlCuentaTransferencia.DataSource = DtCC.FiltraParametros(String.Format("CveMoneda = {0} AND CveTipoCuenta <> 1", CveMon))
DtCC.Dispose()
DdlCuentaEfectivo.DataBind()
DdlCuentaTarjetaCredito.DataBind()
DdlCuentaTarjetaDebito.DataBind()
DdlCuentaCheque.DataBind()
DdlCuentaTransferencia.DataBind()
TxtImporteEfectivo.Attributes.Add("onKeyUp", "CalculaTotalPagoContado();")
TxtImporteCredito.Attributes.Add("onKeyUp", "CalculaTotalPagoContado();")
TxtImporteDebito.Attributes.Add("onKeyUp", "CalculaTotalPagoContado();")
TxtImporteCheque.Attributes.Add("onKeyUp", "CalculaTotalPagoContado();")
TxtImporteTransferencia.Attributes.Add("onKeyUp", "CalculaTotalPagoContado();")
TxtImporteOtrosContado.Attributes.Add("onKeyUp", "CalculaTotalPagoContado();")
TxtEfectivoEnCaja.Attributes.Add("onKeyUp", "CalculaDiferencia();")
TxtEfectivoCajaBloqueo.Attributes.Add("onKeyUp", "CalculaDiferenciaBloqueo();")
End Sub
Private Sub CargaCorteCaja()
Dim DebeCerrarCorte As Boolean = False
'Checar si hay un Turno Abierto
Dim ObjPVenta As New ClsPuntoVenta
If ObjPVenta.GetVta_Cortes("-1", "-1", UsuarioActual.CveUsuario, -1, UsuarioActual.CveEmpresa, 0) Then
If ObjPVenta.DtResultados.Rows.Count > 0 Then
CveCorte = ObjPVenta.CveCorte
Dim FechaICorte As Date = ObjPVenta.FechaInicial.Date '.AddDays(-5)
If FechaICorte < NowADS().Date Then
DebeCerrarCorte = True
LblMotivoBloqueo.Text = $"Existe un corte del día <b>{FechaICorte.ToString("dd/MM/yyyy")}</b>. Favor de cerrarlo para iniciar un nuevo corte."
Else
LblTurno.Text = ObjPVenta.FechaInicial.ToShortDateString
BtnIniciarTurno.Visible = False
LkbEstadodeCaja.Visible = True
LkbIngreso.Visible = True
LkbRetiro.Visible = True
UpTurno.Visible = True
End If
Else
UpTurno.Visible = False
'Ingresar un nuevo Turno
RegistraScript("window.onload = function MuestraCorteCaja() { document.getElementById(""C_btnShow"").click(); }")
End If
End If
ObjPVenta.Dispose()
If DebeCerrarCorte Then
CargaDatosCorte()
RegistraScript("window.onload = function MuestraPantallaBloqueo() { document.getElementById(""C_btnShowBloqueo"").click(); }")
End If
End Sub
Private Sub CargaDatosCorte()
Dim ObjPVenta As New ClsPuntoVenta
Dim Total As Double
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
DineroCaja = Total
LblEfectivoEsperado.Text = Total.FormatoNumero(2)
LblEfectivoBloqueo.Text = Total.FormatoNumero(2)
Dim Dt As New DataTable
Dt.Columns.Add("Descripcion", GetType(String))
Dt.Columns.Add("Importe", GetType(Decimal))
Dim Dr1 As DataRow = Dt.NewRow
Dr1("Descripcion") = "Fondo de Caja"
Dr1("Importe") = ObjPVenta.DtResultados(0)("ImporteInicial").ToString().ToDouble
Dt.Rows.Add(Dr1)
Dim Dr2 As DataRow = Dt.NewRow
Dr2("Descripcion") = "Ventas en Efectivo"
Dr2("Importe") = ObjPVenta.DtResultados(0)("VentasEfectivo").ToString().ToDouble
Dt.Rows.Add(Dr2)
Dim Dr21 As DataRow = Dt.NewRow
Dr21("Descripcion") = "Devoluciones"
Dr21("Importe") = ObjPVenta.DtResultados(0)("Devoluciones").ToString().ToDouble
Dt.Rows.Add(Dr21)
'Dim Dr3 = Dt.NewRow
'Dr3("Descripcion") = "Propinas"
'Dr3("Importe") = ObjPVenta.DtResultados(0)("Propina").ToString().ToDouble
'Dt.Rows.Add(Dr3)
Dim Dr4 As DataRow = Dt.NewRow
Dr4("Descripcion") = "Entradas"
Dr4("Importe") = ObjPVenta.DtResultados(0)("Ingresado").ToString().ToDouble
Dt.Rows.Add(Dr4)
Dim Dr5 As DataRow = Dt.NewRow
Dr5("Descripcion") = "Salidas"
Dr5("Importe") = ObjPVenta.DtResultados(0)("Retirado").ToString().ToDouble
Dt.Rows.Add(Dr5)
Dim Dr6 As DataRow = Dt.NewRow
Dr6("Descripcion") = "Total"
Dr6("Importe") = Total
Dt.Rows.Add(Dr6)
GvDineroCaja.DataSource = Dt
GvDineroCaja.DataBind()
UpDineroCaja.Update()
UpTerminarCorte.Update()
End If
End If
ObjPVenta.Dispose()
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.GetRemisionesCobranza(UsuarioActual.CveEmpresa, DdlSubProyecto.SelectedValue.ToEntero, FechaI, FechaF) Then
Dim dtt As DataTable = ObjMovtos.DtResultados.FiltraParametros($"CveVenta > 0 AND (CveUsuarioCobranza IS NULL OR CveUsuarioCobranza = {UsuarioActual.CveUsuario})")
'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()
TxtImporteEfectivo.Text = ""
TxtImporteCredito.Text = ""
TxtImporteDebito.Text = ""
TxtImporteCheque.Text = ""
TxtImporteTransferencia.Text = ""
TxtImporteOtrosContado.Text = ""
TxtCambio.Text = ""
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
If e.Row.DBCampo("CveCondicionEntrega").ToEntero() = 9 Then
e.Row.FCLinkButton("LnkImprimir").Visible = True
ScriptManager.GetCurrent(Me).RegisterPostBackControl(e.Row.FCLinkButton("LnkImprimir"))
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()
Try
If Not ObjVentas.UpdateAsignaVentaCobranza(CveVenta, 1, UsuarioActual.CveUsuario, -1, "", Now) Then
TieneError = True
End If
HdnCveVenta.Value = CveVenta.ToString
'según la forma de pago va a establecer el valor para pago.
Select Case GvRow.DataKey("CveFormaPago33")
Case "1"
TxtImporteEfectivo.Text = GvRow.DataKey("Saldo").FormatoNumero
Case "2"
TxtImporteCheque.Text = GvRow.DataKey("Saldo").FormatoNumero
Case "3"
TxtImporteTransferencia.Text = GvRow.DataKey("Saldo").FormatoNumero
Case "4"
TxtImporteCredito.Text = GvRow.DataKey("Saldo").FormatoNumero
Case "18"
TxtImporteDebito.Text = GvRow.DataKey("Saldo").FormatoNumero
Case Else
TxtImporteEfectivo.Text = GvRow.DataKey("Saldo").FormatoNumero
End Select
TxtImporteContado.Text = GvRow.DataKey("Saldo").FormatoNumero
HdnTotal.Value = GvRow.DataKey("Saldo")
TxtImporteEfectivo.Focus()
LtlNombre.Text = GvRow.DataKey("AtencionA")
LtlFolio.Text = GvRow.DataKey("SerieFolio")
LtlSaldo.Text = GvRow.DataKey("Saldo").ToDecimal.FormatoNumero
Catch ex As Exception
TieneError = True
End Try
'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
Dim Pagado As Decimal = TxtImporteEfectivo.Text.ToDecimal + TxtImporteCredito.Text.ToDecimal + TxtImporteDebito.Text.ToDecimal + TxtImporteCheque.Text.ToDecimal + TxtImporteTransferencia.Text.ToDecimal
If Pagado = 0 Then
Alert("Favor de especificar importe", TipoMensaje.MsgAdvertencia)
Exit Sub
End If
If LtlSaldo.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
Alert("El pago con los metodos de pago actuales no puede ser mayor al importe de la venta", TipoMensaje.MsgAdvertencia)
Exit Sub
End If
Dim CveVenta As Integer = HdnCveVenta.Value.ToEntero
Dim DbRowVenta As DataRow = Nothing
Dim ObjVentas As New ClsVentas
If ObjVentas.GetVenta(CveVenta, UsuarioActual.CveEmpresa) Then
DbRowVenta = ObjVentas.DtResultados.Copy().FiltroPrimero("")
End If
ObjVentas.Dispose()
If DbRowVenta IsNot Nothing Then
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 CvePrePoliza As Integer
Dim Fecha As Date = NowADS()
Dim MsgError As String = ""
Dim SaldoPendiente As Decimal = DbRowVenta("Saldo").ToString.ToDecimal
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())
Try
CvePrePoliza = ObjConta.AddPrePolizas("PVCobranza", 5, 0, 0, 1, Fecha, $"Pago {VentaActual.SerieFolio}", UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa)
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
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 Not ObjVentas2.UpdateVentaCorte(CveVenta, UsuarioActual.CveEmpresa, CveCorte) Then
MsgError = "Error al aplicar el corte"
End If
Else
MsgError = "Error al registrar prepólizas"
End If
Catch ex As Exception
MsgError = "Error al registrar el pago"
GuardaLog(ex.ToString())
End Try
If MsgError = "" Then
ObjConta.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&REGENERAR=1", CveVenta))}"" class='Texto'>Imprimir ticket</a>", TipoMensaje.MsgInformacion)
Else
ObjConta.RollBack()
Alert(MsgError, TipoMensaje.MsgError)
End If
ObjConta.Dispose()
ObjIE.Dispose()
ObjVentas2.Dispose()
If MsgError = "" Then
Try
If UsuarioActual.Empresa.Funcionalidad(109) = "1" Then
ImpresionDirectaPDF(HdnCveVenta.Value.ToEntero)
End If
PnlContado.Visible = False
HdnCveVenta.Value = ""
CargaDatos()
Catch ex As Exception
GuardaLog(ex.ToString())
End Try
End If
Else
Alert("Ocurrió un error al cargar la venta", TipoMensaje.MsgError)
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, ByRef ObjVentas As ClsVentas) 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)
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
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
Retorno = "Error en aplicación de pago.."
ErrorConta = True
End If
Else
Retorno = "Pago en Bancos no registrado"
ErrorConta = True
End If
Return Retorno
End Function
Protected Sub BtnCerrarCaja_Click(sender As Object, e As EventArgs)
RegistraScript("$('#DivEstadoCaja').modal('hide')")
RegistraScript("$('#DivTerminarCorte').modal()", "divterminarcorte")
End Sub
Protected Sub LkbIngreso_Click(sender As Object, e As EventArgs)
CargaIngresoEgreso(1)
End Sub
Public Sub CargaIngresoEgreso(Opcion As Integer)
RegistraScript("$('#DivIngresoEgreso').modal()")
If Opcion = 1 Then
LblTituloIE.Text = "Ingreso de Efectivo: "
HdnTipoMovimiento.Value = "1"
ElseIf Opcion = 0 Then
LblTituloIE.Text = "Retiro de Efectivo: "
HdnTipoMovimiento.Value = "0"
End If
UpIngresoEgreso.Update()
End Sub
Protected Sub LkbRetiro_Click(sender As Object, e As EventArgs)
CargaIngresoEgreso(0)
End Sub
Private Sub LkbEstadodeCaja_Click(sender As Object, e As EventArgs) Handles LkbEstadodeCaja.Click
CargaDatosCorte()
CargaVentasPago()
CargaEntradasSalidas()
RegistraScript("$('#DivEstadoCaja').modal()")
End Sub
Private Sub CargaVentasPago()
Dim ObjPVenta As New ClsPuntoVenta
If ObjPVenta.GetVta_MetodosPago(CveCorte) Then
If ObjPVenta.DtResultados.Rows.Count > 0 Then
GvMetodosPago.DataSource = ObjPVenta.DtResultados
GvMetodosPago.DataBind()
UpMetodosPago.Update()
End If
End If
ObjPVenta.Dispose()
End Sub
Private Sub CargaEntradasSalidas()
Dim ObjPVenta As New ClsPuntoVenta
'Salida
If ObjPVenta.GetVta_MovimientosCajas(CveCorte, 0) Then
If ObjPVenta.DtResultados.Rows.Count > 0 Then
GvEgresos.DataSource = ObjPVenta.DtResultados
GvEgresos.DataBind()
UpEgresos.Update()
End If
End If
'Entrada
If ObjPVenta.GetVta_MovimientosCajas(CveCorte, 1) Then
If ObjPVenta.DtResultados.Rows.Count > 0 Then
GvIngresos.DataSource = ObjPVenta.DtResultados
GvIngresos.DataBind()
UpIngresos.Update()
End If
End If
ObjPVenta.Dispose()
End Sub
Private Sub BtnCerrarTurno_Click(sender As Object, e As EventArgs) Handles BtnCerrarTurno.Click
Dim ObjPVenta As New ClsPuntoVenta
If TxtEfectivoEnCaja.Text.Trim <> "" Then
If ObjPVenta.UpdateFinalizadoVtaCortes(CveCorte, TxtEfectivoEnCaja.Text.ToDouble, LblDiferenciaCaja.Text.ToDouble, NowADS(), UsuarioActual.CveEmpresa) Then
RegistraScript($"window.location.href = '/Compras/PopUpVerFactura.aspx?P={Encripta(String.Format("OP=CORT&CVECORTE={0}&FORMATO={1}", CveCorte, "PDF"))}'", "Imprimir")
Dim Liga As String = "document.location.href=""/Ventas/PVCobranza.aspx"";"
Alert("Se ha cerrado el turno correctamente.", TipoMensaje.MsgInformacion, Liga)
End If
End If
ObjPVenta.Dispose()
End Sub
Private Sub BtnCerrarBloqueo_Click(sender As Object, e As EventArgs) Handles BtnCerrarBloqueo.Click
Dim ObjPVenta As New ClsPuntoVenta
If TxtEfectivoCajaBloqueo.Text.Trim <> "" Then
If ObjPVenta.UpdateFinalizadoVtaCortes(CveCorte, TxtEfectivoCajaBloqueo.Text.ToDouble, LblDiferenciaCajaBloqueo.Text.ToDouble, NowADS(), UsuarioActual.CveEmpresa) Then
RegistraScript($"window.location.href = '/Compras/PopUpVerFactura.aspx?P={Encripta(String.Format("OP=CORT&CVECORTE={0}&FORMATO={1}", CveCorte, "PDF"))}'", "Imprimir")
Dim Liga As String = "document.location.href=""/Ventas/PVCobranza.aspx"";"
Alert("Se ha cerrado el turno correctamente.", TipoMensaje.MsgInformacion, Liga)
End If
Else
Alert("Debe especificar el efectivo en caja", TipoMensaje.MsgAdvertencia)
RegistraScript("window.onload = function MuestraPantallaBloqueo() { document.getElementById(""C_btnShowBloqueo"").click(); }")
End If
ObjPVenta.Dispose()
End Sub
Private Sub BtnIniciarTurno_Click(sender As Object, e As EventArgs) Handles BtnIniciarTurno.Click
Dim ObjPVenta As New ClsPuntoVenta
ObjPVenta.AddVtaCortes(NowADS(), TxtDineroCaja.Text.ToDecimal, UsuarioActual.CveUsuario, "", UsuarioActual.CveEmpresa)
CveCorte = ObjPVenta.CveCorte
LblTurno.Text = NowADS().ToShortDateString
UpTurno.Visible = True
LkbEstadodeCaja.Visible = True
LkbIngreso.Visible = True
LkbRetiro.Visible = True
BtnIniciarTurno.Visible = False
ObjPVenta.Dispose()
RegistraScript("$('#DivCorteDeCaja').hide();")
UpTurno.Update()
End Sub
Private Sub BtnAceptarIE_Click(sender As Object, e As EventArgs) Handles BtnAceptarIE.Click
Dim ObjPVenta As New ClsPuntoVenta
If TxtCantidadIE.Text.ToEntero() > 0 Then
If ObjPVenta.AddVta_MovimientosCajas(CveCorte, UsuarioActual.CveUsuario, TxtCantidadIE.Text.ToDouble, TxtDescripcionIE.Text, HdnTipoMovimiento.Value.ToEntero(), NowADS()) Then
TxtCantidadIE.Text = ""
TxtDescripcionIE.Text = ""
RegistraScript("$('#DivIngresoEgreso').modal('hide')", "divingresoegreso")
Alert("El movimiento se realizó correctamente")
UpIngresoEgreso.Update()
End If
End If
ObjPVenta.Dispose()
End Sub
Private Sub ImpresionDirectaPDF(CveVenta As Integer)
Dim ObjFactura As New Modelos.Factura(UsuarioActual, CveVenta, UsuarioActual.CveEmpresa, CargaDTDetalle:=False, CargaDatosCliente:=False, CargaDatosRelacionados:=False, VerificaAlmacen:=False)
Dim ExistePDF As Boolean = False
Dim ArchivoPDF As String = ""
If ObjFactura.TipoDocto = "Ing" 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
If File.Exists(ArchivoPDF) AndAlso ObjFactura.TipoDocto = "Rem" Then
ExistePDF = True
Else
'REGENERAR EL PDF
Try
GenerarPDFVenta(CveVenta, AplicaPagare:="1", GuardarPDF:=True, RegenerarPDF:=True, DescargarArchivo:=False, EsTicket:=True)
If File.Exists(ArchivoPDF) Then
ExistePDF = True
End If
Catch ex As Exception
OnError("Ocurrió un error al regenerar el PDF", ex)
End Try
End If
If ExistePDF Then
Dim pdf64 As String = ""
'DUPLICA EL PDF
Using ms As New MemoryStream
Using pdfdoc As New iText.Kernel.Pdf.PdfDocument(New iText.Kernel.Pdf.PdfWriter(ms))
pdfdoc.InitializeOutlines()
Dim reporteByte As New MemoryStream(System.IO.File.ReadAllBytes(ArchivoPDF))
Dim docPDF As New iText.Kernel.Pdf.PdfDocument(New iText.Kernel.Pdf.PdfReader(reporteByte))
docPDF.CopyPagesTo(1, docPDF.GetNumberOfPages(), pdfdoc)
docPDF.CopyPagesTo(1, docPDF.GetNumberOfPages(), pdfdoc)
docPDF.Close()
pdfdoc.Close()
End Using
pdf64 = Convert.ToBase64String(ms.ToArray())
End Using
RegistraScript($"impresionBase64('{pdf64}');", "Imprimir")
Else
Alert("No se pudo imprimir el pdf directamente. favor de descargar manualmente el pdf.", TipoMensaje.MsgAdvertencia)
End If
End Sub
Protected Sub LnkLiberar_Click(sender As Object, e As EventArgs)
Dim ObjVentas As New ClsVentas
If ObjVentas.UpdateAsignaVentaCobranza(HdnCveVenta.Value.ToEntero, -1, -1, -1, "", Now) Then
PnlContado.Visible = False
HdnCveVenta.Value = ""
CargaDatos()
End If
ObjVentas.Dispose()
End Sub
Protected Sub LnkImprimir_Click(sender As Object, e As EventArgs)
Dim GvRow As GridViewRow = DirectCast(DirectCast(sender, LinkButton).NamingContainer, GridViewRow)
Dim CveVenta As Integer = GvRow.DataKey("CveVenta").ToEntero()
If CveVenta > 0 Then
ImpresionDirectaPDF(CveVenta)
End If
End Sub
End Class