Option Explicit On
Option Strict On
Imports Extensiones
Imports System.Data
Imports System.IO
Imports System.Linq
Imports System.Security.Cryptography.X509Certificates
Imports System.Globalization
Imports System.Net.Http
Imports Microsoft.Reporting.WebForms
Partial Class PV
Inherits ClsPaginas
#Region "PROPIEDADES"
Private Const NumeroDecimales As Integer = 2
Dim ColumnaDescuento As Integer = 6
Dim ColumnaIVA As Integer = 7
Dim ColumnaIEPS As Integer = 8
Dim ColumnaRetIVA As Integer = 9
Dim ColumnaRetISR As Integer = 10
Dim ColumnaEditar As Integer = 12
Dim ColumnaEliminar As Integer = 13
'Factura de ventas
Dim DTConceptos As DataTable
Private Property Version As String
Private Property Fecha As String
Private Property SerieXML As String
Private Property FolioXML As String
Private Property SubTotal As Decimal
Private Property Total As Decimal = 0
Private Property Descuentos As Decimal = 0
Private Property EmisorRFC As String
Private Property ReceptorRFC As String
Private Property TrasladoIVA As Decimal = 0
Private Property RetencionIVA As Decimal = 0
Private Property RetencionISR As Decimal = 0
Private Property TrasladoIEPS As Decimal = 0
Private Property TFDUUID As String = ""
Private Property Moneda As String = ""
Private Property TipoComprobante As String = ""
Private Property OtrosImpuestos As Decimal = 0
Private Property TotalRetenciones As Decimal = 0
Private Property SumaTotalRetenciones As Decimal = 0
Private Property TotalTraslados As Decimal = 0
Private Property SumaTotalTraslados As Decimal = 0
Private Property SubTotalConceptos As Decimal = 0
Private Property Redondeo As Decimal = 0
Private Property EsSupervisor As Boolean = False
Private Property MandarCorreoSupervisor As Boolean = False
Public Property EstablecioFolio As Boolean
Get
Return CBool(ViewState("EstablecioFolio").ToString)
End Get
Set(value As Boolean)
ViewState("EstablecioFolio") = value
End Set
End Property
Private ReadOnly Property ExFolioFactura As Boolean
Get
Return CBool(ViewState("ExFolioFactura"))
End Get
End Property
Private Property CveFactura As Integer
Get
Return ViewState("CveFactura").ToString.ToEntero
End Get
Set(value As Integer)
ViewState("CveFactura") = value
End Set
End Property
Private Property IdPoliza As Integer
Get
Return ViewState("IdPoliza").ToString.ToEntero
End Get
Set(value As Integer)
ViewState("IdPoliza") = value
End Set
End Property
Private Property RemisionesLista As List(Of Integer)
Get
Return If(IsNothing(ViewState("RemisionesLista")), Nothing, CType(ViewState("RemisionesLista"), List(Of Integer)))
End Get
Set(value As List(Of Integer))
ViewState("RemisionesLista") = value
End Set
End Property
Private Property HuboCambioRemi As Boolean
Get
Return If(IsNothing(ViewState("HuboCambioRemi")), False, CType(ViewState("HuboCambioRemi"), Boolean))
End Get
Set(value As Boolean)
ViewState("HuboCambioRemi") = value
End Set
End Property
Private Property EsCreaApartirDe As Boolean
Get
Return If(IsNothing(ViewState("EsCreaApartirDe")), False, CType(ViewState("EsCreaApartirDe"), Boolean))
End Get
Set(value As Boolean)
ViewState("EsCreaApartirDe") = value
End Set
End Property
Private Property RequiereAlmacenDestino As Boolean
Get
Return If(IsNothing(ViewState("RequiereAlmacenDestino")), False, CType(ViewState("RequiereAlmacenDestino"), Boolean))
End Get
Set(value As Boolean)
ViewState("RequiereAlmacenDestino") = value
End Set
End Property
Private Property EmpresaActual As Empresa
Get
Return CType(ViewState("EmpresaActual"), Empresa)
End Get
Set(value As Empresa)
ViewState("EmpresaActual") = value
End Set
End Property
Private ReadOnly Property CveCliente As Integer
Get
Return ViewState("CveCliente").ToString.ToEntero
End Get
End Property
Private Property CveClienteSucursal As Integer
Get
If ViewState("CveClienteSucursal") Is Nothing Then
Return -1
Else
Return ViewState("CveClienteSucursal").ToString.ToEntero
End If
End Get
Set(value As Integer)
ViewState("CveClienteSucursal") = value
End Set
End Property
Private Property CveUsuarioActual As Integer
Get
Return ViewState("CveUsuarioActual").ToString.ToEntero
End Get
Set(value As Integer)
ViewState("CveUsuarioActual") = value
End Set
End Property
Private ReadOnly Property Mail As String
Get
Return ViewState("Mail").ToString
End Get
End Property
Private ReadOnly Property MailCC As String
Get
Return ViewState("MailCC").ToString
End Get
End Property
Private ReadOnly Property CveVenta As Integer
Get
Return ViewState("CveVenta").ToString.ToEntero
End Get
End Property
Private Property CveVentaPadre As Integer
Get
Return If(IsNothing(ViewState("CveVentaPadre")), -1, ViewState("CveVentaPadre").ToString.ToEntero)
End Get
Set(value As Integer)
ViewState("CveVentaPadre") = value
End Set
End Property
Private ReadOnly Property CveDevolucion As Integer
Get
Return ViewState("CveDevolucion").ToString.ToEntero
End Get
End Property
Private Property IsTotalxConcepto As Boolean
Get
Return If(IsNothing(ViewState("IsTotalxConcepto")), False, CBool(ViewState("IsTotalxConcepto").ToString))
End Get
Set(value As Boolean)
ViewState("IsTotalxConcepto") = value
End Set
End Property
Private ReadOnly Property CveAlmacenTransitorio As Integer
Get
Return ViewState("CveAlmacenTransitorio").ToString.ToEntero
End Get
End Property
Private ReadOnly Property NuevaFactura As Integer
Get
Return ViewState("NuevaFactura").ToString.ToEntero
End Get
End Property
Private ReadOnly Property VentaFolio As String
Get
Return ViewState("VentaFolio").ToString
End Get
End Property
Private ReadOnly Property SelloCancelacion As String
Get
Return ViewState("SelloCancelacion").ToString
End Get
End Property
Private ReadOnly Property FechaCancelacion As DateTime
Get
Return ViewState("FechaCancelacion").ToString.ToDateTime
End Get
End Property
Private ReadOnly Property FolioFiscal As String
Get
Return ViewState("FolioFiscal").ToString
End Get
End Property
Private ReadOnly Property Ruta As String
Get
Return ModExtensiones.DirectorioBaseEmpresas & "Empresas\" & UsuarioActual.CveEmpresa & "\"
End Get
End Property
Private ReadOnly Property RutaPruebas As String
Get
Return ModExtensiones.DirectorioBaseEmpresas & "Empresas\1\"
End Get
End Property
Private ReadOnly Property TipoCambio As Double
Get
Return ViewState("TipoCambio").ToString.ToDouble
End Get
End Property
Private ReadOnly Property ProcesoCorrecto As Boolean
Get
Return CBool(ViewState("ProcesoCorrecto"))
End Get
End Property
'Folios
Private ReadOnly Property CveFolio As Integer
Get
Return ViewState("CveFolio").ToString.ToEntero
End Get
End Property
Private ReadOnly Property NumAprobacion As Long
Get
Return CLng(ViewState("NumAprobacion").ToString)
End Get
End Property
Private ReadOnly Property FechaAprobacion As Date
Get
Return ViewState("FechaAprobacion").ToString.ToDate
End Get
End Property
Private ReadOnly Property FolioActual As String
Get
Return ViewState("FolioActual").ToString
End Get
End Property
'Sucursal
Private ReadOnly Property Serie As String
Get
Return ViewState("Serie").ToString
End Get
End Property
Private ReadOnly Property Folio As Integer
Get
Return ViewState("Folio").ToString.ToEntero
End Get
End Property
Private ReadOnly Property FormatoFactura As String
Get
Return ViewState("FormatoFactura").ToString
End Get
End Property
Private ReadOnly Property TipoFormato As String
Get
Return ViewState("TipoFormato").ToString
End Get
End Property
Private ReadOnly Property IVA As Double
Get
Return ViewState("IVA").ToString.ToDouble
End Get
End Property
'Cliente
Private ReadOnly Property NombreCliente As String
Get
Return ViewState("NombreCliente").ToString
End Get
End Property
Private ReadOnly Property Vendedor As String
Get
Return ViewState("Vendedor").ToString
End Get
End Property
Private ReadOnly Property CtaContable As String
Get
Return ViewState("CtaContable").ToString
End Get
End Property
Private ReadOnly Property IdCtaContClientes As Integer
Get
Return ViewState("IdCtaContClientes").ToString.ToEntero
End Get
End Property
Private ReadOnly Property IdCtaContMonedaExtranjera As Integer
Get
Return ViewState("IdCtaContMonedaExtranjera").ToString.ToEntero
End Get
End Property
Private ReadOnly Property IdCtaContComplementaria As Integer
Get
Return ViewState("IdCtaContComplementaria").ToString.ToEntero
End Get
End Property
Private ReadOnly Property IdCtaContAnticipos As Integer
Get
Return ViewState("IdCtaContAnticipos").ToString.ToEntero
End Get
End Property
Private ReadOnly Property IdCtaContRetIVA As Integer
Get
Return ViewState("IdCtaContRetIVA").ToString.ToEntero
End Get
End Property
Private ReadOnly Property IdCtaContRetISR As Integer
Get
Return ViewState("IdCtaContRetISR").ToString.ToEntero
End Get
End Property
Private ReadOnly Property IdCtaContDSV As Integer
Get
Return ViewState("IdCtaContDSV").ToString.ToEntero
End Get
End Property
Private ReadOnly Property CodCliente As String
Get
Return ViewState("CodCliente").ToString
End Get
End Property
Private ReadOnly Property CliNoExt As String
Get
Return ViewState("CliNoExt").ToString
End Get
End Property
Private ReadOnly Property CliNoInt As String
Get
Return ViewState("CliNoInt").ToString
End Get
End Property
Private ReadOnly Property CliLocalidad As String
Get
Return ViewState("CliLocalidad").ToString
End Get
End Property
Private ReadOnly Property CliPais As String
Get
Return ViewState("CliPais").ToString
End Get
End Property
Private ReadOnly Property SucCalle As String
Get
Return ViewState("SucCalle").ToString
End Get
End Property
Private ReadOnly Property CliCorreoCot As String
Get
If ViewState("CliCorreoCot") Is Nothing Then
Return ""
Else
Return ViewState("CliCorreoCot").ToString
End If
End Get
End Property
Private ReadOnly Property SucNoExt As String
Get
Return ViewState("SucNoExt").ToString
End Get
End Property
Private ReadOnly Property SucNoInt As String
Get
Return ViewState("SucNoInt").ToString
End Get
End Property
Private ReadOnly Property SucColonia As String
Get
Return ViewState("SucColonia").ToString
End Get
End Property
Private ReadOnly Property SucLocalidad As String
Get
Return ViewState("SucLocalidad").ToString
End Get
End Property
Private ReadOnly Property SucMunicipio As String
Get
Return ViewState("SucMunicipio").ToString
End Get
End Property
Private ReadOnly Property SucEstado As String
Get
Return ViewState("SucEstado").ToString
End Get
End Property
Private ReadOnly Property SucPais As String
Get
Return ViewState("SucPais").ToString
End Get
End Property
Private ReadOnly Property SucCP As String
Get
Return ViewState("SucCP").ToString
End Get
End Property
Private ReadOnly Property MatCalle As String
Get
Return ViewState("MatCalle").ToString
End Get
End Property
Private ReadOnly Property MatNoExt As String
Get
Return ViewState("MatNoExt").ToString
End Get
End Property
Private ReadOnly Property MatNoInt As String
Get
Return ViewState("MatNoInt").ToString
End Get
End Property
Private ReadOnly Property MatColonia As String
Get
Return ViewState("MatColonia").ToString
End Get
End Property
Private ReadOnly Property MatLocalidad As String
Get
Return ViewState("MatLocalidad").ToString
End Get
End Property
Private ReadOnly Property MatMunicipio As String
Get
Return ViewState("MatMunicipio").ToString
End Get
End Property
Private ReadOnly Property MatEstado As String
Get
Return ViewState("MatEstado").ToString
End Get
End Property
Private ReadOnly Property MatPais As String
Get
Return ViewState("MatPais").ToString
End Get
End Property
Private ReadOnly Property MatCP As String
Get
Return ViewState("MatCP").ToString
End Get
End Property
Private ReadOnly Property AplicaFEMSA As Boolean
Get
Return CBool(ViewState("AplicaFEMSA"))
End Get
End Property
Private ReadOnly Property AplicaDetallista As Boolean
Get
Return CBool(ViewState("AplicaDetallista"))
End Get
End Property
Private ReadOnly Property AplicaFord As Boolean
Get
Return CBool(ViewState("AplicaFord"))
End Get
End Property
Private ReadOnly Property CveOS As Integer
Get
Return ViewState("CveOS").ToString.ToEntero
End Get
End Property
Private ReadOnly Property SaldoVenta As Decimal
Get
Return If(IsNothing(ViewState("SaldoVenta")), 0, ViewState("SaldoVenta").ToString.ToDecimal)
End Get
End Property
Private Property CvePSAmortizacion As Integer
Get
Return ViewState("CvePSAmortizacion").ToString.ToEntero
End Get
Set(value As Integer)
ViewState("CvePSAmortizacion") = value
End Set
End Property
Private ReadOnly Property ClienteRetIVA As Decimal
Get
Return ViewState("ClienteRetIVA").ToString.ToDecimal
End Get
End Property
Private ReadOnly Property ClienteRetISR As Decimal
Get
Return ViewState("ClienteRetISR").ToString.ToDecimal
End Get
End Property
Private ReadOnly Property ClienteDesglosaIEPS As Boolean
Get
Return CType(ViewState("ClienteDesglosaIEPS").ToString, Boolean)
End Get
End Property
Private Property CvePrePoliza As Integer
Get
Return ViewState("CvePrePoliza").ToString.ToEntero
End Get
Set(value As Integer)
ViewState("CvePrePoliza") = value
End Set
End Property
Private ReadOnly Property SeGuardoPrePoliza As Boolean
Get
Return CBool(ViewState("SeGuardoPrePoliza"))
End Get
End Property
Private Property CveVentaFacturada As Integer
Get
Return ViewState("CveVentaFacturada").ToString.ToEntero
End Get
Set(value As Integer)
ViewState("CveVentaFacturada") = value
End Set
End Property
Private Property Modalidad As String
Get
Return ViewState("Modalidad").ToString
End Get
Set(value As String)
ViewState("Modalidad") = value
End Set
End Property
Private Property Index As Integer
Get
Return ViewState("Index").ToString.ToEntero
End Get
Set(value As Integer)
ViewState("Index") = value
End Set
End Property
Private Property CveVentaDetalle As Integer
Get
Return If(ViewState("CveVentaDetalle") Is Nothing, -1, ViewState("CveVentaDetalle").ToString.ToEntero)
End Get
Set(value As Integer)
ViewState("CveVentaDetalle") = value
End Set
End Property
Private ReadOnly Property AplicarVentaFacturada As Boolean
Get
Return CBool(ViewState("AplicarVentaFacturada"))
End Get
End Property
'Estimaciones
Private Property CveContrato As Integer
Get
Return ViewState("CveContrato").ToString.ToEntero
End Get
Set(value As Integer)
ViewState("CveContrato") = value
End Set
End Property
Private Property CvePedido As Integer
Get
Return ViewState("CvePedido").ToString.ToEntero
End Get
Set(value As Integer)
ViewState("CvePedido") = value
End Set
End Property
Private Property TipoContrato As Integer
Get
Return ViewState("TipoContrato").ToString.ToEntero
End Get
Set(value As Integer)
ViewState("TipoContrato") = value
End Set
End Property
Private Property Opcion As String
Get
Return ViewState("Opcion").ToString
End Get
Set(value As String)
ViewState("Opcion") = value
End Set
End Property
'Presupuesto
Private Property CvePresupuesto As Integer
Get
Return ViewState("CvePresupuesto").ToString.ToEntero
End Get
Set(value As Integer)
ViewState("CvePresupuesto") = value
End Set
End Property
Private Property TotalOtrosConceptos As Decimal
Get
Return ViewState("TotalOtrosConceptos").ToString.ToDecimal
End Get
Set(value As Decimal)
ViewState("TotalOtrosConceptos") = value
End Set
End Property
Private Property DevolucionAlmacen As Integer
Get
Return ViewState("DevolucionAlmacen").ToString.ToEntero
End Get
Set(value As Integer)
ViewState("DevolucionAlmacen") = value
End Set
End Property
Private Property CveMetodoPagoCliente As Integer
Get
Return ViewState("CveMetodoPagoCliente").ToString.ToEntero
End Get
Set(value As Integer)
ViewState("CveMetodoPagoCliente") = value
End Set
End Property
Private Property PlazoCobranza As Integer
Get
Return ViewState("PlazoCobranza").ToString.ToEntero
End Get
Set(value As Integer)
ViewState("PlazoCobranza") = value
End Set
End Property
Private ReadOnly Property SubProyectoPorcentajeIVA As Decimal
Get
Return ViewState("SubProyectoPorcentajeIVA").ToString.ToDecimal
End Get
End Property
Private Property EstatusCliente As Boolean
Get
Return CBool(ViewState("EstatusCliente").ToString)
End Get
Set(value As Boolean)
ViewState("EstatusCliente") = value
End Set
End Property
Private Property EnviarCorreoCliente As Boolean
Get
Return CBool(ViewState("EnviarCorreoCliente").ToString)
End Get
Set(value As Boolean)
ViewState("EnviarCorreoCliente") = value
End Set
End Property
Private ReadOnly Property ClasificacionesDescuentos As Dictionary(Of Integer, Decimal)
Get
Return New Dictionary(Of Integer, Decimal) From {
{20516, 0.23D}, 'Descuento para lubricantes LTH
{20515, 0.24D} 'Descuento para filtros LTH
}
End Get
End Property
#End Region
#Region "PROPIEDADES DE PUNTO DE VENTA"
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 Entrega As String
Get
Return ViewState("Entrega").ToString
End Get
Set(value As String)
ViewState("Entrega") = value
End Set
End Property
Private Property Vigencia As String
Get
Return ViewState("Vigencia").ToString
End Get
Set(value As String)
ViewState("Vigencia") = value
End Set
End Property
Private Property DineroCaja As Double
Get
Return ViewState("DineroCaja").ToString.ToDouble
End Get
Set(value As Double)
ViewState("DineroCaja") = value
End Set
End Property
Private Property TmpDTMetodosPago As DataTable
Get
Return If(IsNothing(ViewState("TmpDTMetodosPago")), Nothing, CType(ViewState("TmpDTMetodosPago"), DataTable))
End Get
Set(value As DataTable)
ViewState("TmpDTMetodosPago") = value
End Set
End Property
Private Property DTBCIUsados As DataTable
Get
Return If(IsNothing(ViewState("DTBCIUsados")), Nothing, CType(ViewState("DTBCIUsados"), DataTable))
End Get
Set(value As DataTable)
ViewState("DTBCIUsados") = value
End Set
End Property
#End Region
#Region "PROPIEDADES CONTRATOS"
Private Property DtContratos As DataTable
Get
Return If(IsNothing(ViewState("DtContratos")), Nothing, CType(ViewState("DtContratos"), DataTable))
End Get
Set(value As DataTable)
ViewState("DtContratos") = value
End Set
End Property
#End Region
#Region " PROPIEDADES NUEVAS | GUARDAR - IMPRESION | IPP "
Private Property ErrorList As List(Of String)
Get
Return CType(ViewState("ErrorList"), List(Of String))
End Get
Set(value As List(Of String))
ViewState("ErrorList") = value
End Set
End Property
Private Property MensajeAlert As StringBuilder
Get
Return CType(ViewState("MensajeAlert"), StringBuilder)
End Get
Set(value As StringBuilder)
ViewState("MensajeAlert") = value
End Set
End Property
Private Property ObjFactura As Modelos.Factura
Get
Return CType(ViewState("ObjFactura"), Modelos.Factura)
End Get
Set(value As Modelos.Factura)
ViewState("ObjFactura") = value
End Set
End Property
#End Region
#Region " PROPIEDADES OC "
Private Property CveOC As Integer
Get
Return ViewState("CveOC").ToString.ToEntero
End Get
Set(value As Integer)
ViewState("CveOC") = value
End Set
End Property
#End Region
#Region "PROPIEDADES DATATABLE"
Private Property DtRemisionesPS As DataTable
Get
Return If(IsNothing(ViewState("DtRemisionesPS")), Nothing, CType(ViewState("DtRemisionesPS"), DataTable))
End Get
Set(value As DataTable)
ViewState("DtRemisionesPS") = value
End Set
End Property
Private Property DtRemisionesTmpDT As DataTable
Get
Return If(IsNothing(ViewState("DtRemisionesTmpDT")), Nothing, CType(ViewState("DtRemisionesTmpDT"), DataTable))
End Get
Set(value As DataTable)
ViewState("DtRemisionesTmpDT") = value
End Set
End Property
Private Property DTPresupuestoIngresos As DataTable
Get
Return CType(ViewState("DTPresupuestoIngresos"), DataTable)
End Get
Set(value As DataTable)
ViewState("DTPresupuestoIngresos") = value
End Set
End Property
Private Property DtInv As DataTable
Get
Return CType(ViewState("DtInv"), DataTable)
End Get
Set(value As DataTable)
ViewState("DtInv") = value
End Set
End Property
Private Property DTFacNC As DataTable
Get
Return If(IsNothing(ViewState("DTFacNC")), Nothing, CType(ViewState("DTFacNC"), DataTable))
End Get
Set(value As DataTable)
ViewState("DTFacNC") = value
End Set
End Property
Private Property DtPromociones As DataTable
Get
Return If(IsNothing(ViewState("DtPromociones")), Nothing, CType(ViewState("DtPromociones"), DataTable))
End Get
Set(value As DataTable)
ViewState("DtPromociones") = value
End Set
End Property
Private Property DTSucursal As DataTable
Get
Return If(IsNothing(ViewState("DTSucursal")), Nothing, CType(ViewState("DTSucursal"), DataTable))
End Get
Set(value As DataTable)
ViewState("DTSucursal") = value
End Set
End Property
Private Property TmpDT As DataTable
Get
Return If(IsNothing(ViewState("TmpDT")), Nothing, CType(ViewState("TmpDT"), DataTable))
End Get
Set(value As DataTable)
ViewState("TmpDT") = value
End Set
End Property
Private Property TmpDTAjustes As DataTable
Get
Return If(IsNothing(ViewState("TmpDTAjustes")), Nothing, CType(ViewState("TmpDTAjustes"), DataTable))
End Get
Set(value As DataTable)
ViewState("TmpDTAjustes") = value
End Set
End Property
Private Property TmpDTRecepcionUsados As DataTable
Get
Return If(IsNothing(ViewState("TmpDTRecepcionUsados")), Nothing, CType(ViewState("TmpDTRecepcionUsados"), DataTable))
End Get
Set(value As DataTable)
ViewState("TmpDTRecepcionUsados") = value
End Set
End Property
Private Property TmpDTPolizaVirtual As DataTable
Get
Return If(IsNothing(ViewState("TmpDTPolizaVirtual")), Nothing, CType(ViewState("TmpDTPolizaVirtual"), DataTable))
End Get
Set(value As DataTable)
ViewState("TmpDTPolizaVirtual") = value
End Set
End Property
Private Property TmpDTImpuestos As DataTable
Get
Return If(IsNothing(ViewState("TmpDTImpuestos")), Nothing, CType(ViewState("TmpDTImpuestos"), DataTable))
End Get
Set(value As DataTable)
ViewState("TmpDTImpuestos") = value
End Set
End Property
Private Property TmpDTEnvioDireccion As DataTable
Get
Return If(IsNothing(ViewState("TmpDTEnvioDireccion")), Nothing, CType(ViewState("TmpDTEnvioDireccion"), DataTable))
End Get
Set(value As DataTable)
ViewState("TmpDTEnvioDireccion") = value
End Set
End Property
Private Property TmpDTDeducciones As DataTable
Get
Return If(IsNothing(ViewState("TmpDTDeducciones")), Nothing, CType(ViewState("TmpDTDeducciones"), DataTable))
End Get
Set(value As DataTable)
ViewState("TmpDTDeducciones") = value
End Set
End Property
Private Property TmpDTComplementos As DataTable
Get
Return If(IsNothing(ViewState("TmpDTComplementos")), Nothing, CType(ViewState("TmpDTComplementos"), DataTable))
End Get
Set(value As DataTable)
ViewState("TmpDTComplementos") = value
End Set
End Property
Private Property DTmpC As DataTable
Get
Return If(IsNothing(ViewState("DTmpC")), Nothing, CType(ViewState("DTmpC"), DataTable))
End Get
Set(value As DataTable)
ViewState("DTmpC") = value
End Set
End Property
Private Property DTmpF As DataTable
Get
Return If(IsNothing(ViewState("DTmpF")), Nothing, CType(ViewState("DTmpF"), DataTable))
End Get
Set(value As DataTable)
ViewState("DTmpF") = value
End Set
End Property
Private Property DTRemisiones As DataTable
Get
Return If(IsNothing(ViewState("DTRemisiones")), Nothing, CType(ViewState("DTRemisiones"), DataTable))
End Get
Set(value As DataTable)
ViewState("DTRemisiones") = value
End Set
End Property
Private Property DtPagos As DataTable
Get
Return CType(ViewState("DtPagos"), DataTable)
End Get
Set(value As DataTable)
ViewState("DtPagos") = value
End Set
End Property
Private Property DtPUFacturas As DataTable
Get
Return CType(ViewState("DtPUFacturas"), DataTable)
End Get
Set(value As DataTable)
ViewState("DtPUFacturas") = value
End Set
End Property
Private Property DtModelosAuto As DataTable
Get
Return CType(ViewState("DtModelosAuto"), DataTable)
End Get
Set(value As DataTable)
ViewState("DtModelosAuto") = value
End Set
End Property
#End Region
#Region "PROPIEDADES ACUMULADORES"
Private Property ConsecutivoVenta As Integer
Get
Return ViewState("ConsecutivoVenta").ToString.ToEntero
End Get
Set(value As Integer)
ViewState("ConsecutivoVenta") = value
End Set
End Property
Private Property ModalidadAjuste As String
Get
Return ViewState("ModalidadAjuste").ToString
End Get
Set(value As String)
ViewState("ModalidadAjuste") = value
End Set
End Property
Private Property IndexAjuste As Integer
Get
Return ViewState("IndexAjuste").ToString.ToEntero
End Get
Set(value As Integer)
ViewState("IndexAjuste") = value
End Set
End Property
#End Region
Protected Sub Page_Load(sender As Object, e As System.EventArgs) Handles Me.Load
If Not IsPostBack Then
DdlBPPS.setEsWebService(True)
DdlBPPS.ddlWS.Attributes.Add("data-clear", "1")
ViewState("ProcesoCorrecto") = True
ViewState("NuevaFactura") = -1
ViewState("CveDevolucion") = -1
ViewState("CvePedido") = -1
ViewState("TipoContrato") = -1
ViewState("CveVenta") = -1
ViewState("CveOS") = -1
ViewState("CveFactura") = -1
ViewState("CveMetodoPagoCliente") = -1
ViewState("Entrega") = ""
ViewState("Vigencia") = ""
ViewState("AplicarVentaFacturada") = False
ViewState("SeGuardoPrePoliza") = False
ViewState("SubProyectoPorcentajeIVA") = 0
ViewState("ClienteDesglosaIEPS") = False
ViewState("ClienteRetIVA") = 0
ViewState("ClienteRetISR") = 0
ViewState("EnviarCorreoCliente") = False
CveVentaDetalle = -1
EstablecioFolio = False
EstatusCliente = False
RemisionesLista = New List(Of Integer)
CvePrePoliza = 0
TotalOtrosConceptos = 0
CveUsuarioActual = UsuarioActual.CveUsuario
EmpresaActual = UsuarioActual.Empresa
IdPoliza = 0
CveCorte = -1
CveContrato = -1
DevolucionAlmacen = 0
CvePSAmortizacion = 0
PlazoCobranza = 0
IndexAjuste = 0
ConsecutivoVenta = 0
ModalidadAjuste = ""
EsCreaApartirDe = False
RequiereAlmacenDestino = False
TmpDTComplementos = New DataTable
DtPUFacturas = New DataTable
Modalidad = ""
Index = -1
If UsuarioActual.Empresa.Funcionalidad(531) = "1" Then
ChkAjuste.Visible = True
Else
ChkAjuste.Visible = False
End If
If UsuarioActual.CveEmpresa = 72 Then
TabAlmacen.Visible = False
End If
SetValues()
CvePresupuesto = 0
'MODALIDADES
If Request("Op") IsNot Nothing AndAlso Request("Op").ToString <> "" Then
Opcion = Request("Op").ToString
Else
Opcion = "Ing"
End If
'proceso 163, que activa al edicion de folios.
TxtFecha.Text = Now.ToShortDateString()
LblUsuario.Text = UsuarioActual.Usuario
TxtCantidad.Attributes.Add("onKeyUp ", "Recalcula();")
TxtPrecio.Attributes.Add("onKeyUp ", "Recalcula();")
ImgDescPU.Attributes.Add("onclick", "javascript:$('#ModalDescuento').modal(); $get('LblTitulo1').style.display = ''; $get('LblTitulo2').style.display = 'none'; $get('LblTituloTipo1').style.display = ''; $get('LblTituloTipo2').style.display = 'none'; $get('HdnTipoDescuento').value = '0'; $get('LblPrecio1').style.display = ''; $get('LblTotalPS1').style.display = 'none'; $get('LblSubTotal1').style.display = 'none'; $get('LblAmort').style.display = 'none'; $get('BtnAplicarDescP').style.display = ''; $get('BtnAplicarDescG').style.display = 'none'; $get('TrMotivoDescuento').style.display = '';")
'ImgDescConcepto.Attributes.Add("onclick", "javascript:$('#ModalDescuento').modal(); $get('LblTitulo1').style.display = ''; $get('LblTitulo2').style.display = 'none'; $get('LblTituloTipo1').style.display = ''; $get('LblTituloTipo2').style.display = 'none'; $get('HdnTipoDescuento').value = '1'; $get('LblPrecio1').style.display = 'none'; $get('LblTotalPS1').style.display = ''; $get('LblSubTotal1').style.display = 'none'; $get('LblAmort').style.display = 'none'; $get('BtnAplicarDescP').style.display = ''; $get('BtnAplicarDescG').style.display = 'none'; $get('TrMotivoDescuento').style.display = '';")
ImgDescTotal.Attributes.Add("onclick", "javascript:$('#ModalDescuento').modal(); $get('LblTitulo1').style.display = ''; $get('LblTitulo2').style.display = 'none'; $get('LblTituloTipo1').style.display = ''; $get('LblTituloTipo2').style.display = 'none'; $get('HdnTipoDescuento').value = '2'; $get('LblPrecio1').style.display = 'none'; $get('LblTotalPS1').style.display = 'none'; $get('LblSubTotal1').style.display = ''; $get('LblAmort').style.display = 'none'; $get('BtnAplicarDescP').style.display = 'none'; $get('BtnAplicarDescG').style.display = ''; $get('TrMotivoDescuento').style.display = '';")
ImgOtrosConceptos.Attributes.Add("onclick", "javascript:$('#ModalOtrosConceptos').modal();")
LkbAgregarComplementos.Attributes.Add("onclick", "javascript:$('#ModalComplementos').modal();")
'ImgCerrar.Attributes.Add("OnClick", "$('#DivAnticipos').hide();")
'LkbEstadodeCaja.Attributes.Add("OnClick", "MuestraEstadoCaja();")
'LkbIngreso.Attributes.Add("OnClick", "MuestraIngresoEgreso(1);")
'LkbRetiro.Attributes.Add("OnClick", "MuestraIngresoEgreso(0);")
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();")
TxtEfectivoEnCaja.Attributes.Add("onKeyUp", "CalculaDiferencia();")
'ImgCerrarTerminoCorte.Attributes.Add("OnClick", "$('#DivTerminarCorte').hide();")
'ImgCerrarIE.Attributes.Add("OnClick", "$('#DivIngresoEgreso').hide();")
'ImgCerrarEstadoCaja.Attributes.Add("OnClick", "$('#DivEstadoCaja').hide();")
TxtPorDescP.Attributes.Add("onKeyUp", "CalculaDescuento();")
TxtDescP.Attributes.Add("onKeyUp", "CalculaDescuentoMonto();")
'TxtFechaAjuste.Attributes.Add("onchange", "CalculaMesesUso();")
CreaDTmpC()
CreaDTmpF()
CargaDdlSubProyectos()
CargaSucursales()
CargaClasificaciones()
CargaPS(-1, DdlPS)
CargaPS(-1, DdlPSAjuste, AplicaAlmacen:=False)
CargaEmpresa()
CreaDTVentas()
CargaMetodosPago()
CargaUsoCFDI()
CargaMonedas()
CargaVendedores()
CambiaTipoDocto()
CargarAlmacenes()
CargaFormaEntrega()
CargaCuentasTerminal()
If UsuarioActual.Empresa.Funcionalidad(531).ToString = "1" Then
CargaAjuste()
RVPorDesc.MaximumValue = UsuarioActual.DescuentoAutorizado.ToString
RVPorDesc.ErrorMessage = $"El rango para el % de descuento debe de estar entre 0 y {UsuarioActual.DescuentoAutorizado.ToString}."
End If
LimpiaEscondeContado()
'Carga cliente
If Request("CveCliente") IsNot Nothing AndAlso IsNumeric(Request("CveCliente")) AndAlso Request("CveCliente").ToEntero > 0 AndAlso Request("CveFactura") Is Nothing Then
ViewState("CveCliente") = Request("CveCliente")
HdnCveCliente.Value = Request("CveCliente")
CargaCliente(CveCliente)
ElseIf Request("CveFactura") IsNot Nothing AndAlso IsNumeric(Request("CveFactura")) AndAlso Request("CveFactura").ToEntero > 0 AndAlso Request("CveCliente") IsNot Nothing AndAlso IsNumeric(Request("CveCliente")) AndAlso Request("CveCliente").ToEntero > 0 Then
ViewState("CveCliente") = Request("CveCliente")
ViewState("CveFactura") = Request("CveFactura").ToEntero
CargaCliente(CveCliente)
Else
ViewState("CveCliente") = -1
HdnCveCliente.Value = "-1"
End If
'CARGA VENTA
If Request("CveVenta") IsNot Nothing Then
ViewState("CveVenta") = Request("CveVenta").ToString().ToEntero()
CargaVenta()
End If
'CARGA PARA FACTURAR
ViewState("CveRemision") = IfNull(Request("CveRemision").ToEntero, 0)
ViewState("CveCotizacion") = IfNull(Request("CveCotizacion").ToEntero, 0)
If ViewState("CveCotizacion").ToString.ToEntero > 0 Then
EsCreaApartirDe = True
End If
If UsuarioActual.CveVendedor > 0 Then
If CveVenta = -1 AndAlso Not DdlVendedor.SelectedValue.ToEntero > 0 Then DdlVendedor.SelectedValueExist(UsuarioActual.CveVendedor.ToString)
If DdlVendedor.SelectedValue.ToEntero > 0 AndAlso Not UsuarioActual.TienePermisoProceso(161) Then
DdlVendedor.Enabled = False
End If
'multiples vendedores visible
If UsuarioActual.TienePermisoProceso(153) Then
DdlVendedor.Enabled = True
End If
End If
If UsuarioActual.Empresa.Funcionalidad(301).ToEntero > 0 Then
TxtFecha.Enabled = False
ImgFecha.Visible = False
End If
CargarCodigo()
'RegistraScript("FnSuma()")
TxtSubTotal.Attributes.Add("onKeyUp", "FnSuma()")
TxtIVA.Attributes.Add("onKeyUp", "FnSuma()")
TxtIEPS.Attributes.Add("onKeyUp", "FnSuma()")
TxtRetIVA.Attributes.Add("onKeyUp", "FnSuma()")
TxtRetISR.Attributes.Add("onKeyUp", "FnSuma()")
'Permitir Edicion de Iva
If UsuarioActual.Empresa.Funcionalidad(509) = "1" Then
TxtIVA.Enabled = True
End If
'Cortes de Caja
If UsuarioActual.TienePermisoProceso(160) Then
CargaCorteCaja()
End If
'**********************************
'Complementos de Timbrado
Dim ObjVenta As New ClsVentas
If ObjVenta.GetVentaComplementos() Then
RblComplementos.DataSource = ObjVenta.DtResultados
RblComplementos.DataBind()
UpComplementos.Update()
End If
ObjVenta.Dispose()
If Not UsuarioActual.CveEmpresa.Contiene(1, 119) Then 'PAGO CON TERMINAL PARA JAM
RBLPago.Items.RemoveAt(2)
End If
'CARGA VALORES INICIALES PARA AGREGAR PS DESDE MODAL
CargaMetodosPSModal()
If UsuarioActual.CveEmpresa.Contiene(72, 80, 1, 119) Then
BtnEmitirImprimir.Attributes.Add("data-toggle", "confirmation")
BtnEmitirImprimir.Attributes.Add("data-popout", "true")
BtnEmitirImprimir.Attributes.Add("data-original-title", "confirmar")
BtnEmitirImprimir.Attributes.Add("data-btn-ok-label", "Guardar")
BtnEmitirImprimir.Attributes.Add("data-html", "true")
End If
If UsuarioActual.Empresa.Funcionalidad(569) = "1" Then
DdlTipoComprobante.Items.Add(New ListItem("Remisión", "Rem"))
DdlTipoComprobante.SelectedValueExist("Rem")
End If
DdlTipoDefecto.Width = New Unit(260%)
'Le quitamos el tamaño extra
'RegistraScript("window.onload = function AjustarVentana() { $('.page-content').css('min-height','100%'); }")
End If
End Sub
Private Function CargaVenta() As Boolean
Dim Retorno As Boolean = False
'CARGA PARA FACTURACION
Dim CveRemision As Integer = IfNull(ViewState("CveRemision"), 0).ToString.ToEntero
Dim CveCotizacion As Integer = IfNull(ViewState("CveCotizacion"), 0).ToString.ToEntero
Dim CveVenta As Integer = Me.CveVenta
CveVenta = If(CveRemision > 0, CveRemision, CveVenta)
CveVenta = If(CveCotizacion > 0, CveCotizacion, CveVenta)
CveVenta = If(CvePedido > 0, CvePedido, CveVenta)
Dim SerieFolioPadre As String
Dim ObjVentas As New ClsVentas()
Try
If ObjVentas.GetVenta(CveVenta, UsuarioActual.CveEmpresa) Then
If ObjVentas.DtResultados IsNot Nothing AndAlso ObjVentas.DtResultados.Rows.Count > 0 Then
Dim DbRowVenta As DataRow = ObjVentas.DtResultados.Rows(0)
Dim CveCliente As Integer = DbRowVenta("CveCliente").ToString.ToEntero
Dim ObjUsados As New ClsVentas
Dim DtUsados As DataTable = Nothing
If ObjUsados.GetVentasUsados(CveVenta, DdlSubProyectoDatos.SelectedValue.ToEntero(), DbRowVenta("Fecha").ToString.ToDateTime, UsuarioActual.CveEmpresa) Then
DtUsados = ObjUsados.DtResultados
End If
ObjUsados.Dispose()
'Me.CveEstatusFacturaPadre = DbRowVenta("CveEstatusFacturaPadre").ToString.ToEntero
'CargaEncabezado
DdlTipoComprobante.SelectedValue = DbRowVenta("TipoDocto").ToString
'contado 0, credito 1, terminal 2
If ObjVentas.DtResultados(0)("CondicionesPago").ToString.ToEntero = 1 Then
RBLPago.SelectedValue = "1"
RBLPago_SelectedIndexChanged(Nothing, Nothing)
UPCondicionesPago.Update()
ElseIf ObjVentas.DtResultados(0)("CondicionesPago").ToString.ToEntero = 0 Then
RBLPago.SelectedValue = "2"
RBLPago.Items(0).Enabled = False
RBLPago_SelectedIndexChanged(Nothing, Nothing)
UPCondicionesPago.Update()
Else
DdlCuentasTerminal.SelectedValue = DbRowVenta("CveCuentaTerminal").ToString
RBLPago.SelectedValue = "3"
RBLPago.Items(0).Enabled = False
RBLPago_SelectedIndexChanged(Nothing, Nothing)
UPCondicionesPago.Update()
End If
'CargaDetalle
If ObjVentas.GetVentaDetalle(CveVenta) Then
TmpDT = ObjVentas.DtResultados.Copy()
TmpDT.Columns.Add("EntregaDirecta", GetType(Integer))
TmpDT.Columns.Add("CveMovimientoDetallePedido", GetType(Integer))
TmpDT.Columns.Add("ConsecPSPadre", GetType(Integer))
GvPS.DataSource = TmpDT
GvPS.DataBind()
End If
'ESCONDE ACCIONES
UpnTools.Update()
HdnCveCliente.Value = CveCliente.ToString
ViewState("CveCliente") = CveCliente
ViewState("CveEmpresaCRM") = DbRowVenta("CveEmpresaCRM").ToString.ToEntero
ViewState("CveAcercamientoCRM") = DbRowVenta("CveAcercamientoCRM").ToString.ToEntero
Entrega = DbRowVenta("Entrega").ToString
Vigencia = DbRowVenta("Vigencia").ToString.ToDate.ToShortDateString
HplSaldoAuxiliar.Text = DbRowVenta("Saldo").ToString.FormatoNumero(2)
If Not HplSaldoAuxiliar.Text.ToDouble > 0 Then
HplSaldoAuxiliar.Visible = False
End If
HdnPagado.Value = DbRowVenta("Pagado").ToString
TxtTotal.Text = DbRowVenta("Total").ToString.FormatoNumero(2)
HdnVentaSaldo.Value = (SaldoVenta).ToString
CvePrePoliza = DbRowVenta("CvePrePoliza").ToString.ToEntero
CveVentaFacturada = DbRowVenta("CveVentaFacturada").ToString.ToEntero
DdlMoneda.SelectedValue = DbRowVenta("CveMoneda").ToString
CambiaMoneda()
If CveCliente > 0 Then
CargaCliente(CveCliente, -1) 'Estatus activo, se requiere para cargar una factura en la que el cliente a sido eliminado
End If
ViewState("CveAlmacenTransitorio") = DbRowVenta("CveAlmacenTraspasoDestino").ToString.ToEntero
DevolucionAlmacen = DbRowVenta("EsDevolucionVenta").ToString.ToEntero
'sino esta cargada la información del metodo de pago que le corresponde, la recarga para que se le pueda asignar
If DdlMetodoPago33.SelectedValue <> DbRowVenta("CveMetodoPago33").ToString Then
CargaFormaPago(DbRowVenta("CveMetodoPago33").ToString.ToEntero)
End If
DdlMetodoPago33.SelectedValueExist(DbRowVenta("CveMetodoPago33").ToString)
DdlFormaPago33.SelectedValueExist(DbRowVenta("CveFormaPago33").ToString.ToEntero)
If DdlFormaPago33.SelectedValue <> DbRowVenta("CveFormaPago33").ToString And DbRowVenta("CveFormaPago33").ToString <> "" Then
'sino está seleccionada la asginada la debe de cargar
Dim Nombre As String = GlobalDTVtaFormaPago().FiltroPrimeroValor("FormaPagoSAT", String.Format("CveFormaPago={0}", DbRowVenta("CveFormaPago33")))
DdlFormaPago33.Items.Add(New ListItem(Nombre, DbRowVenta("CveFormaPago33").ToString))
DdlFormaPago33.SelectedValueExist(DbRowVenta("CveFormaPago33").ToString.ToEntero)
End If
DdlUsoCFDI.SelectedValueExist(DbRowVenta("CveUsoCFDI").ToString)
If DbRowVenta("CveTipoRelacion").ToString.ToEntero > 0 Then
TrTipoRelacion.Visible = True
DdlTiposRelacion.SelectedValueExist(DbRowVenta("CveTipoRelacion").ToString.ToEntero)
HdnFolioFiscalNC.Value = DbRowVenta("FolioFiscalPadre").ToString
End If
ViewState("FolioFiscal") = DbRowVenta("FolioFiscal").ToString
LblSerie.Text = DbRowVenta("Serie").ToString
ViewState("Serie") = DbRowVenta("Serie").ToString
ViewState("Folio") = DbRowVenta("Folio").ToString.ToEntero
TxtFolio.Text = DbRowVenta("Folio").ToString
LblFolioFiscal.Text = DbRowVenta("FolioFiscal").ToString
TxtFecha.Text = DbRowVenta("Fecha").ToString
TxtSubTotal.Text = DbRowVenta("SubTotal").ToString.FormatoNumero(2)
LblDescuentos.Text = DbRowVenta("Descuento").ToString.FormatoNumero(2)
LblAmortizacion.Text = DbRowVenta("Amortizacion").ToString.FormatoNumero(2)
TxtSubTotal2.Text = (TxtSubTotal.Text.Replace(",", "").Trim.Trim.ToDouble - LblDescuentos.Text.Replace(",", "").Trim.Trim.ToDouble - LblAmortizacion.Text.Replace(",", "").Trim.Trim.ToDouble).FormatoNumero(2)
TxtIVA.Text = DbRowVenta("IVA").ToString.FormatoNumero(2)
TxtRetIVA.Text = DbRowVenta("RetIVA").ToString.FormatoNumero(2)
If TxtRetIVA.Text.ToDecimal() > 0 Then
TrRetIVA.Style.Add("display", "")
UsuarioActual.Empresa.MostrarRetIVA = True
If TmpDT IsNot Nothing Then
Dim PorcentajeRetIVA = (TmpDT.MAX("PorcentajeRetIVA").ToDecimal() * 100)
LblRetIVA.Text = PorcentajeRetIVA.FormatoNumero(2)
End If
End If
TxtRetISR.Text = DbRowVenta("RetISR").ToString.FormatoNumero(2)
TxtIEPS.Text = DbRowVenta("IEPS").ToString.FormatoNumero(2)
TrIEPS.Visible = TxtIEPS.Text.ToDouble > 0
TxtTotal.Text = DbRowVenta("Total").ToString.FormatoNumero(2)
HdnTotalVenta.Value = DbRowVenta("Total").ToString.FormatoNumero(2)
TxtMotivoDescuento.Text = DbRowVenta("MotivoDescuento").ToString
TxtObsFact.Text = DbRowVenta("Observaciones").ToString
LblUsuario.Text = DbRowVenta("Nombre").ToString
LblSeTimbro.Text = DbRowVenta("SeTimbro").ToString
LblMail.Text = DbRowVenta("EnvioMail").ToString
TxtFechaPago.Text = DbRowVenta("FechaVencimiento").ToString
TxtFechaVencimientoCotizacion.Text = Vigencia
HdnIVAOriginal.Value = TxtIVA.Text
DdlTiposRelacion.SelectedValueExist(DbRowVenta("CveTipoRelacion"))
If DbRowVenta("CveTipoRelacion").ToString.ToEntero > 0 Then
TrTipoRelacion2.Visible = True
LblTipoRelacion.Text = DbRowVenta("TipoRelacion").ToString
HdnFolioFiscalNC.Value = DbRowVenta("FolioFiscalPadre").ToString
End If
'Envio Direccion
If DbRowVenta("CveDireccionEnvio").ToString.ToEntero > 0 AndAlso DbRowVenta("CveDireccionEnvio").ToString IsNot Nothing Then
ChkDireccionEnvio.Checked = True
DdlDireccionEnvio.SelectedValueExist(DbRowVenta("CveDireccionEnvio").ToString.ToEntero)
DdlDireccionEnvio.Enabled = False
ChkDireccionEnvio.Enabled = False
DdlDireccionEnvio.Visible = True
trDireccionEnvio.Visible = True
End If
TxtTipoCambio.Text = DbRowVenta("TipoCambio").ToString
ViewState("SelloCancelacion") = DbRowVenta("SelloCancelacion").ToString
ViewState("FechaCancelacion") = DbRowVenta("FechaCancelacion").ToString.ToDateTime
TxtAtencionA.Text = DbRowVenta("AtencionA").ToString
TxtTelefonoGenerico.Text = DbRowVenta("TelefonoGenerico").ToString
CveVentaPadre = DbRowVenta("CveVentaPadre").ToString.ToEntero
SerieFolioPadre = DbRowVenta("SerieFolioPadre").ToString
If DdlVendedor.SelectedValue.ToEntero > 0 AndAlso Not UsuarioActual.TienePermisoProceso(161) Then
DdlVendedor.Enabled = False
End If
If CveVentaPadre > 0 Then
If IsNothing(Request("CveDevolucion")) AndAlso IsNumeric(Request("CveDevolucion")) Then
DdlNCFactura.Visible = True
Else
DdlNCFactura.Visible = False
End If
trNCFactura.Visible = True
LblSerieFolioPadre.Visible = True
LblSerieFolioPadre.Text = String.Format("{1}", CveVentaPadre, SerieFolioPadre)
End If
DdlSucursalCliente.SelectedValueExist(DbRowVenta("CveClienteSucursal").ToString)
If DdlSubProyectoDatos.Items.Count = 0 Then
DdlSubProyectoDatos.Items.Insert(0, New ListItem("Seleccione", "-1"))
End If
DdlSubProyectoDatos.SelectedValueExistInsert(DbRowVenta("CveSubProyecto").ToString, DbRowVenta("SubProyecto").ToString)
CargarAlmacenes()
CargaClienteSucursal(DbRowVenta("CveClienteSucursal").ToString.ToEntero)
If DbRowVenta("CveContrato").ToString.ToEntero > 0 Then
CveContrato = DbRowVenta("CveContrato").ToString.ToEntero
End If
IdPoliza = DbRowVenta("IdPoliza").ToString.ToEntero
'Carga si es Contabilizada
If IdPoliza > 0 Then
HLContabilizada.Text = "Si"
HLContabilizada.NavigateUrl = $"/Contabilidad/RegPoliza.aspx?IdPoliza={DbRowVenta("IdPoliza")}"
trContabilizada.Visible = True
End If
If DbRowVenta("IdPolizaCancelacion").ToString.ToEntero > 0 Then
HPLContaCancelacion.Text = "Cancelación"
HPLContaCancelacion.NavigateUrl = String.Format("/Contabilidad/RegPoliza.aspx?IdPoliza={0}", DbRowVenta("IdPolizaCancelacion"))
trContabilizada.Visible = True
End If
'CARGA IMPUESTOS LOCALES
If ObjVentas.GetVentaImpuestosLocales(CveVenta) Then
If ObjVentas.DtResultados.Rows.Count > 0 Then
TrOtros.Visible = True
TmpDTImpuestos = ObjVentas.DtResultados
GvImpuestosLocales2.DataSource = ObjVentas.DtResultados
GvImpuestosLocales2.DataBind()
GvImpuestosLocales2.Enabled = False
GvImpuestosLocales2.Visible = True
End If
End If
DdlVendedor.SelectedValue = DbRowVenta("CveVendedor").ToString
DdlTipoComprobante.Enabled = False
'TxtDocto.Enabled = False
DeshabilitarEdicion()
'CargaLeyendasFiscales
ViewState("VentaFolio") = If(LblSerie.Text.Trim.Length = 0, TxtFolio.Text.Trim, LblSerie.Text.Trim & "-" & TxtFolio.Text.Trim)
CalculaTotalesVenta(False)
tdVigencia.Visible = DdlTipoComprobante.SelectedValue.Contiene("Cot")
tdFechaVigencia.Visible = DdlTipoComprobante.SelectedValue.Contiene("Cot")
If DbRowVenta("TipoDocto").ToString = "Rem" Then
For Each Gvr As GridViewRow In GvPS.Rows
Gvr.FCLinkButton("imgE").Visible = False
Gvr.FCLinkButton("imgD").Visible = False
Next
'ACTIVA BOTONERA | DEBE TENER CONCEPTOS PENDIENTES DE FACTURAR
If TmpDT.SUM("CantidadFacturadaRem") < TmpDT.SUM("Cantidad") Then
TrEmitir.Visible = False
BtnPermisoEditarRemision.Visible = True
'ACTIVA CONVERSION DE MONEDA
If DdlMoneda.SelectedValue.ToEntero = 1 Then
TrConversionDolares.Visible = True
ChkConvertirDolares.Enabled = True
TxtTipoCambioDlls.Enabled = True
Else
TrConversionTipoCambio.Visible = True
ChkConvertirDoctoPesos.Enabled = True
TxtTipoCambio.Enabled = True
End If
End If
End If
If UsuarioActual.CveEmpresa = 48 Then
TxtFecha.AutoPostBack = True
End If
UpPS.Update()
UpContado.Update()
UpEstatus.Update()
Retorno = True
Else
ViewState("CveVenta") = -1
Alert("El documento solicitado no existe, favor de revisar su búsqueda.", TipoMensaje.MsgAdvertencia)
End If
End If
Catch ex As Exception
OnError("Ocurrió un error al cargar la venta", ex)
End Try
ObjVentas.Dispose()
Return Retorno
End Function
#Region "E D I T A R - R E M I S I O N"
Private Sub DeshabilitarEdicion()
'PORLET CLIENTE
'DESACTIVA CAMBIO DE CLIENTE
HlCliente.Attributes.Remove("class")
HlCliente.Attributes.Add("class", "Texto disabled")
TxtCodigo.ReadOnly = True
ChkEnviarFactura.Enabled = False
ChkDireccionEnvio.Enabled = False
TxtAtencionA.Enabled = False
TxtFechaVencimientoCotizacion.Enabled = False
TxtCantidad.Enabled = False
DdlClasificacion.Enabled = False
DdlPS.Enabled = False
TxtObsPS.Enabled = False
TxtPrecio.Enabled = False
ImgDescPU.Attributes.Clear()
ImgDescTotal.Attributes.Clear()
LbAgregar.Enabled = False
DdlCuentasTerminal.Enabled = False
For Each Row As GridViewRow In GvPS.Rows
Row.FCLiteral("LtlConsecutivo").Text = (Row.RowIndex + 1).ToString()
Next
GvPS.Columns(ColumnaEditar).HeaderText = ""
GvPS.Columns(ColumnaEliminar).HeaderText = ""
'GvPS.Columns(ColumnaEliminar).Visible = False
TxtObsFact.Enabled = False
TxtMotivoDescuento.Enabled = False
'GvLeyendasFiscales.Enabled = False
TxtSubTotal.ReadOnly = True
TxtIVA.ReadOnly = True
TxtRetIVA.ReadOnly = True
TxtRetISR.ReadOnly = True
TxtIEPS.ReadOnly = True
TxtTotal.ReadOnly = True
'Sección Detalle
DdlMoneda.Enabled = False
'DdlSucursalEjecucion.Enabled = False
'DdlSucursalCobranza.Enabled = False
DdlVendedor.Enabled = False
DdlSucursalCliente.Enabled = False
ChkConvertirDoctoPesos.Enabled = False
ChkConvertirDolares.Enabled = False
TxtTipoCambio.Enabled = False
TxtTipoCambioDlls.Enabled = False
'Condiciones de Pago
RBLPago.Enabled = False
DdlFormaPago33.Enabled = False
DdlUsoCFDI.Enabled = False
DdlMetodoPago33.Enabled = False
'TxtNumCtaPago.Enabled = False
If DdlTipoComprobante.SelectedValue.Contiene("Ing", "Ant", "Rem") Then
TxtFechaPago.ReadOnly = Not UsuarioActual.TienePermisoProceso(260)
Else
TxtFechaPago.ReadOnly = False
End If
imgCalendario.Enabled = False
BtnEmitirImprimir.Visible = False
End Sub
Private Sub HabilitarEdicion()
TxtCodigo.ReadOnly = False
ChkEnviarFactura.Enabled = True
ChkDireccionEnvio.Enabled = True
TxtAtencionA.Enabled = True
TxtFechaVencimientoCotizacion.Enabled = True
TxtCantidad.Enabled = True
DdlClasificacion.Enabled = True
DdlPS.Enabled = True
TxtObsPS.Enabled = True
TxtPrecio.Enabled = True
ImgDescPU.Attributes.Clear()
ImgDescTotal.Attributes.Clear()
LbAgregar.Enabled = True
DdlCuentasTerminal.Enabled = True
For Each Row As GridViewRow In GvPS.Rows
Row.FCLiteral("LtlConsecutivo").Text = (Row.RowIndex + 1).ToString()
Next
GvPS.Columns(ColumnaEditar).HeaderText = ""
GvPS.Columns(ColumnaEliminar).HeaderText = ""
TxtObsFact.Enabled = True
TxtMotivoDescuento.Enabled = True
TxtSubTotal.ReadOnly = False
TxtIVA.ReadOnly = False
TxtRetIVA.ReadOnly = False
TxtRetISR.ReadOnly = False
TxtIEPS.ReadOnly = False
TxtTotal.ReadOnly = False
'Sección Detalle
DdlMoneda.Enabled = True
DdlVendedor.Enabled = True
DdlSucursalCliente.Enabled = True
ChkConvertirDoctoPesos.Enabled = True
ChkConvertirDolares.Enabled = True
TxtTipoCambio.Enabled = True
TxtTipoCambioDlls.Enabled = True
'Condiciones de Pago
RBLPago.Enabled = True
DdlFormaPago33.Enabled = True
DdlUsoCFDI.Enabled = True
DdlMetodoPago33.Enabled = True
If DdlTipoComprobante.SelectedValue.Contiene("Ing", "Ant", "Rem") Then
TxtFechaPago.ReadOnly = Not UsuarioActual.TienePermisoProceso(260)
Else
TxtFechaPago.ReadOnly = False
End If
imgCalendario.Enabled = True
End Sub
Private Sub BtnPermisoEditarRemision_Click(sender As Object, e As EventArgs) Handles BtnPermisoEditarRemision.Click
HabilitarEdicion()
BtnPermisoEditarRemision.Visible = False
BtnEditarRemision.Visible = True
TxtObsFact.Enabled = True
DdlUsoCFDI.Enabled = True
DdlMetodoPago33.Enabled = True
DdlFormaPago33.Enabled = True
UPCondicionesPago.Update()
RBLPago.Enabled = True
ViewState("CveClienteAnterior") = CveCliente
'SI EL DETALLE NO TIENE MOVIMIENTOS DE INVENTARIO ES VISIBLE
Dim CantidadFacturadaRemision = 0.0
For Each Gvr As GridViewRow In GvPS.Rows
Gvr.FCLinkButton("imgE").Visible = Not Gvr.DataKey("CantidadFacturadaRem").ToString.ToDouble > 0 AndAlso Gvr.DataKey("EsCargo") = "False"
Gvr.FCLinkButton("imgD").Visible = Not Gvr.DataKey("CantidadInventario").ToString.ToDouble > 0 AndAlso Gvr.DataKey("EsCargo") = "False"
CantidadFacturadaRemision += Gvr.DataKey("CantidadFacturadaRem").ToString.ToDouble
Next
'ACTIVA CAMBIO DE CLIENTE - SI NO TIENE NADA FACTURADO
If Not CantidadFacturadaRemision > 0 AndAlso UsuarioActual.TienePermisoProceso(284) Then
HlCliente.Attributes.Remove("class")
HlCliente.Attributes.Add("class", "Texto")
TxtCodigo.ReadOnly = False
End If
TxtCantidad.Enabled = True
DdlClasificacion.Enabled = True
DdlPS.Enabled = True
TxtObsPS.Enabled = True
TxtPrecio.Enabled = True
LbAgregar.Enabled = True
ImgDescTotal.Attributes.Add("onclick", "javascript:$('#ModalDescuento').modal(); $get('LblTitulo1').style.display = ''; $get('LblTitulo2').style.display = 'none'; $get('LblTituloTipo1').style.display = ''; $get('LblTituloTipo2').style.display = 'none'; $get('HdnTipoDescuento').value = '2'; $get('LblPrecio1').style.display = 'none'; $get('LblTotalPS1').style.display = 'none'; $get('LblSubTotal1').style.display = ''; $get('LblAmort').style.display = 'none'; $get('BtnAplicarDescP').style.display = 'none'; $get('BtnAplicarDescG').style.display = ''; $get('TrMotivoDescuento').style.display = '';")
LblSubTotal1.Text = TxtSubTotal.Text
LblAmort.Text = TxtSubTotal.Text
UpPS.Update()
UpCliente.Update()
UPObservaciones.Update()
End Sub
Private Sub BtnEditarRemision_Click(sender As Object, e As EventArgs) Handles BtnEditarRemision.Click
Dim OcurrioError As Boolean = False
CreaObjetosVenta()
Dim ObjVentas As New ClsVentas
ObjVentas.IniciaTransacSQL()
Dim ObjConta As New ClsContabilidad(ObjVentas.IniciaTransacSQL())
Dim ObjBancos As New ClsBancos(ObjVentas.IniciaTransacSQL())
Dim ObjCGame As New ClsCGame(ObjVentas.IniciaTransacSQL())
Dim ObjAcum As New ClsAcumuladores(ObjVentas.IniciaTransacSQL())
Dim ObjAC As ClsContPAQi = Nothing
Dim Moneda As Integer = DdlMoneda.SelectedValue.ToEntero
Dim TipoCambio As Double = TxtTipoCambio.Text.ToDouble
Try
'CONVERTIR REMISION - TIPO MONEDA -DOLARES A PESOS
If DdlMoneda.SelectedValue.ToEntero <> 2 AndAlso ChkConvertirDolares.Checked Then
Dim TmpDTTotales As DataTable = TmpDT.FiltraParametros("EliminarDB = False")
For Each Row As DataRow In TmpDTTotales.Rows
Row("PU") = Math.Round(Row("PU").ToString.ToDecimal / TxtTipoCambioDlls.Text.Trim.ToDecimal, 6)
Row("Total") = Math.Round(Row("Cantidad").ToString.ToDecimal * Row("PU").ToString.ToDecimal, NumeroDecimales)
Row("TotalImporte") = Math.Round(Row("Cantidad").ToString.ToDecimal * Row("PU").ToString.ToDecimal, NumeroDecimales)
Row("Descuento") = Math.Round(Row("Descuento").ToString.ToDecimal / TxtTipoCambioDlls.Text.Trim.ToDecimal, NumeroDecimales)
Row("ImporteIEPS") = Math.Round(Row("ImporteIEPS").ToString.ToDecimal / TxtTipoCambioDlls.Text.Trim.ToDecimal, NumeroDecimales)
Row("ImporteIVA") = Math.Round(Row("ImporteIVA").ToString.ToDecimal / TxtTipoCambioDlls.Text.Trim.ToDecimal, NumeroDecimales)
Row("ImporteRetIVA") = Math.Round(Row("ImporteRetIVA").ToString.ToDecimal / TxtTipoCambioDlls.Text.Trim.ToDecimal, NumeroDecimales)
Row("ImporteRetISR") = Math.Round(Row("ImporteRetISR").ToString.ToDecimal / TxtTipoCambioDlls.Text.Trim.ToDecimal, NumeroDecimales)
Next
Dim ImpuestosLocales As Double = 0
For Each gvr As GridViewRow In GvImpuestosLocales2.Rows
If gvr.RowType = DataControlRowType.DataRow Then
gvr.FCTextBox("TxtImpuestoLocalPS").Text = (gvr.FCTextBox("TxtImpuestoLocalPS").Text.ToDouble / TxtTipoCambioDlls.Text.Trim.ToDecimal).FormatoNumero
ImpuestosLocales += Math.Round(gvr.FCTextBox("TxtImpuestoLocalPS").Text.ToDouble / TxtTipoCambioDlls.Text.Trim.ToDecimal, NumeroDecimales)
End If
Next
TxtSubTotal.Text = TmpDTTotales.SUM("Total").ToDecimal.FormatoNumero
LblDescuentos.Text = TmpDTTotales.SUM("Descuento").ToDecimal.FormatoNumero
LblAmortizacion.Text = Math.Round(LblAmortizacion.Text.Trim.ToDecimal / TxtTipoCambioDlls.Text.Trim.ToDecimal, NumeroDecimales).FormatoNumero
TxtIVA.Text = TmpDTTotales.SUM("ImporteIVA").ToDecimal.FormatoNumero
TxtRetIVA.Text = TmpDTTotales.SUM("ImporteRetIVA").ToDecimal.FormatoNumero
TxtRetISR.Text = TmpDTTotales.SUM("ImporteRetISR").ToDecimal.FormatoNumero
TxtIEPS.Text = TmpDTTotales.SUM("ImporteIEPS").ToDecimal.FormatoNumero
TxtTotal.Text = (TxtSubTotal.Text.ToDecimal - LblDescuentos.Text.ToDecimal - LblAmortizacion.Text.ToDecimal + TxtIVA.Text.ToDecimal + TxtIEPS.Text.ToDecimal - TxtRetIVA.Text.ToDecimal - TxtRetISR.Text.ToDecimal - ImpuestosLocales).ToDecimal.FormatoNumero
TipoCambio = TxtTipoCambioDlls.Text.Trim.ToDecimal
Moneda = 2
End If
'CONVERTIR REMISION - TIPO MONEDA -PESO A DOLARES
If DdlMoneda.SelectedValue.ToEntero <> 1 AndAlso ChkConvertirDoctoPesos.Checked Then
Dim TmpDTTotales As DataTable = TmpDT.FiltraParametros("EliminarDB = False")
Dim Importe As Decimal
Dim TCC As Decimal = TxtTipoCambio.Text.Trim.ToDecimal
For Each Row As DataRow In TmpDTTotales.Rows
Row("PU") = Math.Round(Row("PU").ToString.ToDecimal * TCC, 6)
Row("Total") = Math.Round(Row("Cantidad").ToString.ToDecimal * Row("PU").ToString.ToDecimal, NumeroDecimales)
Row("TotalImporte") = Math.Round(Row("Cantidad").ToString.ToDecimal * Row("PU").ToString.ToDecimal, NumeroDecimales)
Row("Descuento") = Math.Round(Row("Descuento").ToString.ToDecimal * TCC, NumeroDecimales)
Importe = Row("Total").ToString.ToDecimal - Row("Descuento").ToString.ToDecimal
Row("ImporteIEPS") = Math.Round(Importe * Row("PorcentajeIEPS").ToString.ToDecimal, NumeroDecimales)
Row("ImporteIVA") = Math.Round(Importe * Row("PorcentajeIVA").ToString.ToDecimal, NumeroDecimales)
Row("ImporteRetIVA") = Math.Round(Importe * Row("PorcentajeRetIVA").ToString.ToDecimal, NumeroDecimales)
Row("ImporteRetISR") = Math.Round(Importe * Row("PorcentajeRetISR").ToString.ToDecimal, NumeroDecimales)
Next
Dim ImpuestosLocales As Double = 0
For Each gvr As GridViewRow In GvImpuestosLocales2.Rows
If gvr.RowType = DataControlRowType.DataRow Then
gvr.FCTextBox("TxtImpuestoLocalPS").Text = (gvr.FCTextBox("TxtImpuestoLocalPS").Text.ToDouble * TxtTipoCambio.Text.Trim.ToDecimal).FormatoNumero
ImpuestosLocales += Math.Round(gvr.FCTextBox("TxtImpuestoLocalPS").Text.ToDouble * TxtTipoCambio.Text.Trim.ToDecimal, NumeroDecimales)
End If
Next
TxtSubTotal.Text = TmpDTTotales.SUM("Total").ToDecimal.FormatoNumero
LblDescuentos.Text = TmpDTTotales.SUM("Descuento").ToDecimal.FormatoNumero
LblAmortizacion.Text = Math.Round(LblAmortizacion.Text.Trim.ToDecimal * TxtTipoCambio.Text.Trim.ToDecimal, NumeroDecimales).FormatoNumero
TxtIVA.Text = TmpDTTotales.SUM("ImporteIVA").ToDecimal.FormatoNumero
TxtRetIVA.Text = TmpDTTotales.SUM("ImporteRetIVA").ToDecimal.FormatoNumero
TxtRetISR.Text = TmpDTTotales.SUM("ImporteRetISR").ToDecimal.FormatoNumero
TxtIEPS.Text = TmpDTTotales.SUM("ImporteIEPS").ToDecimal.FormatoNumero
TxtTotal.Text = (TxtSubTotal.Text.ToDecimal - LblDescuentos.Text.ToDecimal - LblAmortizacion.Text.ToDecimal + TxtIVA.Text.ToDecimal + TxtIEPS.Text.ToDecimal - TxtRetIVA.Text.ToDecimal - TxtRetISR.Text.ToDecimal - ImpuestosLocales).ToDecimal.FormatoNumero
TipoCambio = 1
Moneda = 1
End If
'ELIMINA LOS DETALLES
If Not OcurrioError Then
Dim DtEliminados As DataTable = TmpDT.FiltraParametros("EliminarDB = True AND CveVentaDetalle > 0", "", {"CveVentaDetalle"})
For Each Dr1 As DataRow In DtEliminados.Rows
If Not ObjVentas.RemoveVentasDetalle(CveVenta, Dr1("CveVentaDetalle").ToString.ToEntero) Then
OcurrioError = True
End If
Next
End If
'Actualizo los parametros de la venta
If Not ObjVentas.UpdateVentas(TxtSubTotal.Text.ToDecimal, LblDescuentos.Text.ToDecimal, TxtIVA.Text.ToDecimal, TxtIEPS.Text.ToDecimal, TxtTotal.Text.ToDecimal, Moneda, TipoCambio, TxtFecha.Text.Trim.ToDate, TxtObsFact.Text.Trim,
UsuarioActual.CveEmpresa, CveVenta, 0, 0,
Vigencia:=TxtFechaVencimientoCotizacion.Text.Trim.ToDate, CondicionesPago:=If(RBLPago.SelectedValue = "2", 0, 1),
PedidoContrato:="", AtencionA:=TxtAtencionA.Text.Trim, CveMetodoPago33:=DdlMetodoPago33.SelectedValue.ToEntero,
CveFormaPago33:=DdlFormaPago33.SelectedValue.ToEntero, TipoDocto:="Rem", CveCliente:=CveCliente, CveClienteSucursal:=CveClienteSucursal,
OrdenCompra:="", RetIVA:=TxtRetIVA.Text.ToDecimal, RetISR:=TxtRetISR.Text.ToDecimal, Kilometraje:=0) Then
OcurrioError = True
End If
'Cargo de nueva cuenta el detalle de Ventas (Conceptos)
If Not OcurrioError Then
Dim index As Integer = 0
For Each Row As DataRow In TmpDT.FiltraParametros("EliminarDB = False").Rows
Dim CveVentaDetalle As Integer = Row("CveVentaDetalle").ToString.ToEntero()
If CveVentaDetalle > 0 Then
If Not ObjVentas.UpdateVentaDetalleRemision(Row("CveVentaDetalle").ToString.ToEntero, Row("CvePS").ToString.ToEntero, Row("Cantidad").ToString.ToDecimal, Row("PU").ToString.ToDecimal(), Row("ImporteIEPS").ToString.ToDecimal(), Row("PorcentajeIEPS").ToString().ToDecimal(), Row("Obs").ToString, UsuarioActual.CveUsuario) Then
OcurrioError = True
Exit For
End If
Else
If Not ObjVentas.AddVentaDetalle(CveVenta, Row("CvePS").ToString.ToEntero, Row("Cantidad").ToString.ToDouble, Row("CveUM").ToString.ToEntero,
Row("PU").ToString.ToDouble(If(ChkConvertirDoctoPesos.Checked, TxtTipoCambio.Text.ToDecimal, 1)), Row("ImporteIVA").ToString.ToDouble, Math.Round((Row("Total").ToString.ToDouble(If(ChkConvertirDoctoPesos.Checked, TxtTipoCambio.Text.ToDecimal, 1)) * (1 + Row("PorcentajeIVA").ToString.ToDouble(If(ChkConvertirDoctoPesos.Checked, TxtTipoCambio.Text.ToDecimal, 1)))), 6),
Row("Obs").ToString, Row("Descuento").ToString.ToDouble(If(ChkConvertirDoctoPesos.Checked, TxtTipoCambio.Text.ToDecimal, 1)), Row("TipoDescuento").ToString.ToEntero, Row("CveSubProyecto").ToString.ToEntero, Row("CvePresupuestoIngreso").ToString.ToEntero, PorcentajeIVA:=Row("PorcentajeIVA").ToString.ToDecimal, IEPS:=Row("ImporteIEPS").ToString.ToDouble(If(ChkConvertirDoctoPesos.Checked, TxtTipoCambio.Text.ToDecimal, 1)), PorcentajeIEPS:=Row("PorcentajeIEPS").ToString.ToDouble, TiempoEntrega:=Row("TiempoEntrega").ToString,
CveVentaDetallePadre:=Row("CveVentaDetalle").ToString.ToEntero, CveContratoDetalle:=Row("CveContratoDetalle").ToString.ToEntero, CvePromocionDetalle:=If(DtPromociones IsNot Nothing, DtPromociones.FiltroPrimeroValor("CvePromocionDetalle", $"CvePS={Row("CvePS").ToString}").ToEntero, -1),
ImporteRetIVA:=Row("ImporteRetIVA").ToString.ToDouble, ImporteRetISR:=Row("ImporteRetISR").ToString.ToDouble, PorcentajeRetIVA:=Row("PorcentajeRetIVA").ToString.ToDouble, PorcentajeRetISR:=Row("PorcentajeRetISR").ToString.ToDouble, CuentaPredial:=Row("CuentaPredial").ToString) Then
OcurrioError = True
Exit For
Else
TmpDT.Rows(index)("CveVentaDetalle") = ObjVentas.CveVentaDetalle
If TmpDTRecepcionUsados IsNot Nothing Then
If TmpDTRecepcionUsados.Select($"CvePS={Row("CvePS").ToString.ToEntero}").Length > 0 Then
Dim rowInv As DataRow = TmpDTRecepcionUsados.Select($"CvePS={Row("CvePS").ToString.ToEntero}")(0)
rowInv("CveVentaDetalle") = ObjVentas.CveVentaDetalle
End If
End If
If TmpDTAjustes IsNot Nothing AndAlso TmpDTAjustes.Rows.Count > 0 Then
If TmpDTAjustes.Select($"ConsecutivoVenta={Row("Consec").ToString.ToEntero}").Length > 0 Then
Dim DrAju As DataRow = TmpDTAjustes.Select($"ConsecutivoVenta={Row("Consec").ToString.ToEntero}")(0)
DrAju("CveVentaDetalle") = ObjVentas.CveVentaDetalle
End If
End If
If TmpDTPolizaVirtual IsNot Nothing Then
If TmpDTPolizaVirtual.Select($"CvePS={Row("CvePS").ToString.ToEntero}").Length > 0 Then
Dim RowPoliza As DataRow = TmpDTPolizaVirtual.Select($"CvePS={Row("CvePS").ToString.ToEntero}")(0)
RowPoliza("CveVentaDetalle") = ObjVentas.CveVentaDetalle
End If
End If
End If
End If
index = index + 1
Next
End If
'RECARGA LOS DATOS
ObjFactura.Dispose()
ObjFactura = Nothing
ObjFactura = New Modelos.Factura(UsuarioActual, CveVenta, UsuarioActual.CveEmpresa)
If ObjFactura Is Nothing Then
OcurrioError = True
Else
TmpDT = ObjFactura.DtDetalle
TmpDT.Columns.Add("EntregaDirecta", GetType(Integer))
TmpDT.Columns.Add("CveMovimientoDetallePedido", GetType(Integer))
Dim NumRowsPS As Integer = 0
Dim CantidadPS As Decimal = 0
For Each GvRow As GridViewRow In GvPS.Rows
If GvRow.RowType = DataControlRowType.DataRow Then
NumRowsPS += 1
CantidadPS += GvRow.DataKey("Cantidad").ToDecimal()
End If
Next
'VALIDA NUMERO DE REGISTROS
If TmpDT.Rows.Count <> NumRowsPS Then
OcurrioError = True
End If
'VALIDA CANTIDAD DE REGISTROS
If TmpDT.SUM("Cantidad") <> CantidadPS Then
OcurrioError = True
End If
End If
'GUARDA USADOS
If Not OcurrioError AndAlso Not ObjVentas.EliminarUsados(CveVenta) Then
OcurrioError = True
End If
If Not OcurrioError AndAlso TmpDTRecepcionUsados IsNot Nothing Then
For Each drow As DataRow In TmpDTRecepcionUsados.Rows
If Not ObjVentas.AddVentaUsado(CveVenta, drow("CvePS").ToString.ToEntero, drow("Cantidad").ToString.ToDecimal, drow("PU").ToString.ToDecimal, drow("CveBCIUsado").ToString.ToEntero, drow("CveModeloAuto").ToString.ToEntero) Then
OcurrioError = True
Exit For
End If
Next
End If
'GUARDAR AJUSTES'
If Not OcurrioError AndAlso Not ObjAcum.EliminarGarantiasDetalle(CveVenta) Then
OcurrioError = True
End If
If Not OcurrioError AndAlso TmpDTAjustes IsNot Nothing AndAlso TmpDTAjustes.Rows.Count > 0 Then
For Each Dr As DataRow In TmpDTAjustes.Rows
If Not ObjAcum.AddGarantiasDetalle(Dr("CveVentaDetalle").ToString.ToEntero, Dr("CvePS").ToString.ToEntero, Dr("CveFolioGarantia").ToString.ToEntero, Dr("CveTipoUso").ToString.ToEntero,
Dr("CodigoEnsamble").ToString, Dr("CodigoLinea").ToString, Dr("CodigoInspeccion").ToString, Dr("CveTipoDefecto").ToString.ToEntero,
Dr("NumPoliza").ToString, Dr("Importe").ToString.ToDouble, Dr("Consecutivo").ToString, Dr("FechaAjuste").ToString.ToDateTime(), Dr("PorcentajeAjuste").ToString.ToDecimal()) Then
ErrorList.Add("Ocurrió un error al agregar la garantia detalle.")
End If
Next
End If
'GUARDAR POLIZA VIRTUAL
If Not OcurrioError AndAlso Not ObjAcum.EliminarPolizaVirtual(CveVenta) Then
OcurrioError = True
End If
If Not OcurrioError AndAlso TmpDTPolizaVirtual IsNot Nothing Then
For Each drow As DataRow In TmpDTPolizaVirtual.Rows
If ObjAcum.AddPolizaVirtual(CveVenta, drow("CveVentaDetalle").ToString().ToEntero(), drow("CvePS").ToString.ToEntero, drow("Cantidad").ToString.ToDecimal, drow("PU").ToString.ToDecimal, drow("Descuento").ToString.ToDecimal,
drow("Total").ToString.ToDecimal, drow("TipoServicio").ToString.ToEntero, drow("TipoPoliza").ToString.ToEntero, drow("CveModeloAuto").ToString.ToEntero, drow("AnioVehiculo").ToString.ToEntero, CBool(drow("TieneUsado").ToString),
drow("FechaUsado").ToString().ToDateTime, drow("CvePSUsado").ToString.ToEntero, drow("CveBCIUsado").ToString.ToEntero) Then
Else
OcurrioError = True
Exit For
End If
Next
End If
'Actualizo impuestos locales
If Not OcurrioError Then
For Each gvr As GridViewRow In GvImpuestosLocales2.Rows
If gvr.RowType = DataControlRowType.DataRow Then
If Not ObjVentas.UpdateVentaImpuestoLocales(CveVenta, gvr.DataKey("CveImpuestoLocal").ToString.ToEntero, gvr.FCTextBox("TxtImpuestoLocalPS").Text.ToDecimal) Then
OcurrioError = True
End If
End If
Next
End If
'REGENERAR LOS SALDOS
If Not OcurrioError Then
OcurrioError = Not ObjFactura.RegenerarPrePolizas(ObjVentas.IniciaTransacSQL(), ObjAC)
End If
Catch ex As Exception
OcurrioError = True
OnError("Ocurrió un error al actualizar la remisión", ex)
End Try
If OcurrioError Then
ObjVentas.RollBack()
Alert("Ocurrió un error al guardar los cambios. Por favor intente de nuevo.", TipoMensaje.MsgError)
Else
ObjVentas.Commit()
If ObjAC IsNot Nothing Then ObjAC.Commit()
Alert("Los cambios se guardaron correctamente.", TipoMensaje.MsgInformacion, JSBtnAceptar:="document.location.href=""/Ventas/PV.aspx"";")
End If
ObjVentas.Dispose()
ObjConta.Dispose()
ObjBancos.Dispose()
If ObjAC IsNot Nothing Then ObjAC.Dispose()
End Sub
#End Region
#Region "PUNTO DE VENTA"
Private Sub CargaCorteCaja()
'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
LblEstatusCaja.Text = ObjPVenta.FechaInicial.ToShortDateString
TrEstatusCaja.Visible = True
BtnIniciarTurno.Visible = False
LkbEstadodeCaja.Visible = True
LkbIngreso.Visible = True
LkbRetiro.Visible = True
Else
'Ingresar un nuevo Turno
RegistraScript("window.onload = function MuestraCorteCaja() { document.getElementById(""C_btnShow"").click(); }")
End If
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(Now, TxtDineroCaja.Text.ToDecimal, UsuarioActual.CveUsuario, TxtDescripcionCaja.Text, UsuarioActual.CveEmpresa)
CveCorte = ObjPVenta.CveCorte
LblEstatusCaja.Text = Now.ToShortDateString
TrEstatusCaja.Visible = True
LkbEstadodeCaja.Visible = True
LkbIngreso.Visible = True
LkbRetiro.Visible = True
BtnIniciarTurno.Visible = False
ObjPVenta.Dispose()
RegistraScript("$('#DivCorteDeCaja').hide();")
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 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)("Propina").ToString.ToDouble + ObjPVenta.DtResultados(0)("Ingresado").ToString.ToDouble - ObjPVenta.DtResultados(0)("Retirado").ToString.ToDouble
DineroCaja = Total
LblEfectivoEsperado.Text = Total.FormatoNumero(2)
Dim Dt As New DataTable
Dt.Columns.Add("Descripcion", GetType(String))
Dt.Columns.Add("Importe", GetType(Decimal))
Dim Dr1 = Dt.NewRow
Dr1("Descripcion") = "Fondo de Caja"
Dr1("Importe") = ObjPVenta.DtResultados(0)("ImporteInicial").ToString.ToDouble
Dt.Rows.Add(Dr1)
Dim Dr2 = Dt.NewRow
Dr2("Descripcion") = "Ventas en Efectivo"
Dr2("Importe") = ObjPVenta.DtResultados(0)("VentasEfectivo").ToString.ToDouble
Dt.Rows.Add(Dr2)
Dim Dr3 = Dt.NewRow
Dr3("Descripcion") = "Propinas"
Dr3("Importe") = ObjPVenta.DtResultados(0)("Propina").ToString.ToDouble
Dt.Rows.Add(Dr3)
Dim Dr4 = Dt.NewRow
Dr4("Descripcion") = "Entradas"
Dr4("Importe") = ObjPVenta.DtResultados(0)("Ingresado").ToString.ToDouble
Dt.Rows.Add(Dr4)
Dim Dr5 = Dt.NewRow
Dr5("Descripcion") = "Salidas"
Dr5("Importe") = ObjPVenta.DtResultados(0)("Retirado").ToString.ToDouble
Dt.Rows.Add(Dr5)
Dim Dr6 = 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 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 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, Now) Then
TxtCantidadIE.Text = ""
TxtDescripcionIE.Text = ""
RegistraScript("$('#DivIngresoEgreso').modal('hide')", "divingresoegreso")
Alert("El movimiento se realizo correctamente")
UpIngresoEgreso.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, Now, 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 = "document.location.href=""/Ventas/PV.aspx"";"
Alert("Se ha cerrado el turno correctamente.", TipoMensaje.MsgInformacion, Liga)
End If
End If
ObjPVenta.Dispose()
End Sub
Private Sub BtnCancelar_Click(sender As Object, e As EventArgs) Handles BtnCancelar.Click
Response.Redirect("~/Inicio.aspx")
End Sub
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()", "divingresoegreso")
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
#End Region
#Region "CARGAS"
Private Sub ConfiguraTipoDocto()
'Esconde Todo
TdOrdenPago.Visible = False
Tr33.Visible = False
Tr32.Visible = False
'si tiene la funcionalidad que se active independiente del tipo de documento RMF 15-10-2017
Tr33.Visible = True
Tr32.Visible = False
'' NO CONOCEN EL SWTICH (SELECT EN .NET) ?? O COMO ?? - IPP
If DdlTipoComprobante.SelectedValue.Contiene("Ing", "Ant") Then
BtnEmitirImprimir.Text = "Emitir e Imprimir"
'TdReferencia.Style.Add("display", "none")
End If
UpFacturar.Update()
End Sub
Private Sub CargaMetodosPago()
DdlMetodoPago.DataSource = GlobalDTMetodosPago.FiltraParametros("Estatus = 'Activo'", "ClaveSAT") '.FiltraParametros("CveMetodoPago > 0 ")
DdlMetodoPago.DataBind()
'FACTURACION 3.3
DdlMetodoPago33.DataSource = GlobalDTVtaMetodoPago
DdlMetodoPago33.DataBind()
DdlMetodoPago33.SelectedValue = "3"
If UsuarioActual.CveEmpresa = 119 Then
CargaFormaPago(DdlMetodoPago33.SelectedValue.ToEntero)
Else
CargaFormaPago(-1)
End If
'End If
End Sub
Private Sub CargaFormaPago(CveMetodoPago As Integer)
'FACTURACION 3.3
Dim dtt As DataTable = Nothing
If CveMetodoPago > 0 Then
dtt = GlobalDTVtaFormaPago.FiltraParametros(If(CveMetodoPago = 1, " CveFormaPago <> 20 ", "CveFormaPago = 20"))
Else
dtt = GlobalDTVtaFormaPago
End If
DdlFormaPago33.Items.Clear()
DdlFormaPago33.ClearSelection()
DdlFormaPago33.DataBind()
DdlFormaPago33.DataSource = dtt
DdlFormaPago33.DataBind()
DdlFormaCliente.DataSource = dtt
DdlFormaCliente.DataBind()
DdlMetodoCliente.DataSource = GlobalDTVtaMetodoPago
DdlMetodoCliente.DataBind()
'End If
End Sub
Private Sub CargaUsoCFDI()
DdlUsoCFDI.DataSource = GlobalDTSATUsosCFDI(UsuarioActual.Empresa.EsPersonaFisica)
DdlUsoCFDI.DataBind()
End Sub
Private Sub CargaNuevaFactura(OVenta As ClsVentas)
Dim ObjVentas As ClsVentas
If OVenta IsNot Nothing Then
ObjVentas = OVenta
Else
ObjVentas = New ClsVentas()
End If
If ObjVentas.GetVenta(CveVenta, UsuarioActual.CveEmpresa) Then
If ObjVentas.DtResultados IsNot Nothing AndAlso ObjVentas.DtResultados.Rows.Count > 0 Then
Dim drv As DataRow = ObjVentas.DtResultados.Rows(0)
'CargaCliente
Dim CveCliente As Integer = drv("CveCliente").ToString.ToEntero
If UsuarioActual.CveEmpresa = 2 AndAlso UsuarioActual.CveUsuario = 77 AndAlso Not CveCliente.Contiene(10450, 10460, 10458) Then
Exit Sub
ElseIf UsuarioActual.CveEmpresa = 2 AndAlso UsuarioActual.CveUsuario = 21 AndAlso Not CveCliente.Contiene(27448) Then
Exit Sub
End If
HdnCveCliente.Value = CveCliente.ToString
ViewState("CveCliente") = CveCliente
CargaCliente(CveCliente)
'Carga Detalle Sucursal
DdlSucursalCliente.SelectedValueExist(drv("CveClienteSucursal").ToString)
DdlSubProyectoDatos.SelectedValueExist(drv("CveSubProyecto").ToString)
CargaClienteSucursal(drv("CveClienteSucursal").ToString.ToEntero)
'CargaDetalle
If ObjVentas.GetVentaDetalle(CveVenta) Then
TmpDT = ObjVentas.DtResultados.Copy()
TmpDT.Columns.Add("EntregaDirecta", GetType(Integer))
TmpDT.Columns.Add("CveMovimientoDetallePedido", GetType(Integer))
GvPS.DataSource = TmpDT
GvPS.DataBind()
For Each Gvr As GridViewRow In GvPS.Rows
Gvr.FCLinkButton("imgE").Visible = False
Gvr.FCLinkButton("imgD").Visible = False
Next
End If
'Carga Totales
TxtSubTotal.Text = drv("SubTotal").ToString.FormatoNumero(2)
LblDescuentos.Text = drv("Descuento").ToString.FormatoNumero(2)
LblAmortizacion.Text = drv("Amortizacion").ToString.FormatoNumero(2)
TxtSubTotal2.Text = (TxtSubTotal.Text.Replace(",", "").Trim.Trim.ToDouble - LblDescuentos.Text.Replace(",", "").Trim.Trim.ToDouble - LblAmortizacion.Text.Replace(",", "").Trim.Trim.ToDouble).FormatoNumero(2)
TxtIVA.Text = drv("IVA").ToString.FormatoNumero(2)
TxtRetIVA.Text = drv("RetIVA").ToString.FormatoNumero(2)
TxtRetISR.Text = drv("RetISR").ToString.FormatoNumero(2)
TxtTotal.Text = drv("Total").ToString.FormatoNumero(2)
HdnVentaSaldo.Value = drv("Total").ToString
TxtMotivoDescuento.Text = drv("MotivoDescuento").ToString
TxtObsFact.Text = drv("Observaciones").ToString
DdlMoneda.SelectedValue = drv("CveMoneda").ToString
TxtTipoCambio.Text = drv("TipoCambio").ToString
DdlVendedor.SelectedValue = drv("CveVendedor").ToString
DdlMetodoPago.SelectedValueExist(drv("CveMetodoPago").ToString)
HdnIVAOriginal.Value = TxtIVA.Text
'JJMQ 20160506: Se agrego para la validacion de pago de contado.
'CVImporteContado.ValueToCompare = TxtTotal.Text.Replace(",", "")
If DdlVendedor.SelectedValue.ToEntero > 0 AndAlso Not UsuarioActual.TienePermisoProceso(161) Then
DdlVendedor.Enabled = False
End If
UpPS.Update()
UpContado.Update()
End If
End If
If OVenta Is Nothing Then
ObjVentas.Dispose()
End If
End Sub
Private Sub CargaSucursales()
If UsuarioActual.TienePermisoProceso(152) Then DdlSubProyectoDatos.Enabled = False
End Sub
Private Sub CargaEstados(Optional ClaveSATPais As String = "MEX")
DdlEstadoSAT.Items.Clear()
DdlEstadoSAT.DataSource = GlobalDTEstado(ClaveSATPais)
DdlEstadoSAT.DataBind()
DdlEstadoSAT.Items.Insert(0, New ListItem("Seleccione", "-1"))
If UsuarioActual.CveEmpresa = 140 AndAlso ClaveSATPais = "MEX" Then
DdlEstadoSAT.SelectedValueExist("26")
End If
End Sub
Protected Sub DdlSATPais_SelectedIndexChanged(sender As Object, e As EventArgs)
CargaEstados(DdlSATPais.SelectedValue)
End Sub
Private Sub CargaEmpresa()
If UsuarioActual.Empresa.UsaContabilidad Then
Dim ObjFisConfiguracion As New ClsFISConfiguracion
If ObjFisConfiguracion.GetConfiguracion(UsuarioActual.CveEmpresa) Then
ViewState("IdCtaContDSV") = ObjFisConfiguracion.ERDSV
Else
ViewState("IdCtaContDSV") = 0
End If
ObjFisConfiguracion.Dispose()
Else
ViewState("IdCtaContDSV") = 0
End If
End Sub
Private Sub CargaMonedas()
DdlMoneda.DataSource = GlobalDTMonedas
DdlMoneda.DataBind()
End Sub
Private Sub CargarAlmacenes()
If CveVenta > 0 Then
DivAlmacen.Visible = False
Else
ddlAlmacen.Items.Clear()
ddlAlmacen.DataSource = GlobalDTAlmacenUsuarios(UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa).FiltraParametros($"CveSubProyecto = {DdlSubProyectoDatos.SelectedValue.ToEntero}")
ddlAlmacen.Items.Insert(0, New ListItem(" Seleccione ", "-1"))
ddlAlmacen.DataBind()
If GlobalDTAlmacenUsuarios(UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa).FiltraParametros($"CveSubProyecto = {DdlSubProyectoDatos.SelectedValue.ToEntero}").Rows.Count > 0 Then
ddlAlmacen.SelectedValueExist(UsuarioActual.CveAlmacen)
End If
End If
'SI TIENE CONTRATO NO SE MUEVE
If Not CveContrato > 0 Then
DdlAlmacenAsignado.Items.Clear()
DdlAlmacenAsignado.DataSource = GlobalDTAlmacenUsuarios(UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa, CveTipoAlmacen:=-1).FiltraParametros($"CveSubProyecto = {DdlSubProyectoDatos.SelectedValue.ToEntero} AND CveTipoAlmacen IN (4,10)")
DdlAlmacenAsignado.Items.Insert(0, New ListItem(" Seleccione ", "-1"))
DdlAlmacenAsignado.SelectedValue = "-1"
DdlAlmacenAsignado.DataBind()
DdlAlmacenAsignado.SelectedValueExist(GlobalDTAlmacen(UsuarioActual.CveEmpresa).FiltroPrimeroValor("CveAlmacen", $"CveTipoAlmacen = 10 AND CveSubProyecto = {DdlSubProyectoDatos.SelectedValue.ToEntero}").ToString.ToEntero)
End If
If CveContrato > 0 AndAlso DdlTipoComprobante.SelectedValue.Contiene("Ped", "PeC") Then
DdlAlmacenAsignado.DataSource = GlobalDTAlmacenUsuarios(UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa, CveTipoAlmacen:=-1).FiltraParametros($"CveSubProyecto = {DdlSubProyectoDatos.SelectedValue.ToEntero}")
DdlAlmacenAsignado.Items.Insert(0, New ListItem(" Seleccione ", "-1"))
DdlAlmacenAsignado.SelectedValue = "-1"
DdlAlmacenAsignado.DataBind()
DdlAlmacenAsignado.SelectedValueExist(GlobalDTAlmacen(UsuarioActual.CveEmpresa).FiltroPrimeroValor("CveAlmacen", $"CveSubProyecto = {DdlSubProyectoDatos.SelectedValue}").ToString.ToEntero)
End If
UpINV.Update()
End Sub
Private Sub CargaFormaEntrega()
'TrFormaEntrega.Visible = True
DdlFormaEntrega.DataSource = GlobalDTVtaCondicionesEntrega(UsuarioActual.CveEmpresa)
DdlFormaEntrega.DataBind()
DdlFormaEntrega.Items.Insert(0, New ListItem("Seleccione", "-1"))
End Sub
Private Sub CargaCliente(CveCliente As Integer, Optional Estatus As Integer = 1)
Dim ObjCliente As New ClsClientes()
Try
If ObjCliente.GetClientes(CveCliente, "-1", "-1", "-1", "-1", "-1", "-1", -1, UsuarioActual.CveEmpresa, Estatus, TipoCliente:=-1) Then
If ObjCliente.DtResultados.Rows.Count > 0 Then
TxtCodigo.Text = ObjCliente.Codigo
LblCliente.Text = String.Format("{1}", CveCliente, ObjCliente.Nombre)
ViewState("NombreCliente") = ObjCliente.Nombre
LtlCliente.Text = ObjCliente.Nombre
ChkEnviarFactura.Checked = ObjCliente.EnviarFactura
ViewState("Mail") = If(DdlTipoComprobante.SelectedValue = "Cot", ObjCliente.MailCotizacion, ObjCliente.Mail)
ViewState("MailCC") = ObjCliente.NotificarA
LblDireccion.Text = ObjCliente.Direccion
LblColonia.Text = ObjCliente.Colonia
LblCiudad.Text = ObjCliente.Ciudad
LblEstado.Text = ObjCliente.Estado
LblCP.Text = ObjCliente.CP
LblRFC.Text = ObjCliente.RFC
LblTelefono.Text = ObjCliente.Telefono
LblRetIVA.Text = ObjCliente.RetIVA.ToString.FormatoNumero(5)
LblRetISR.Text = ObjCliente.RetISR.ToString.FormatoNumero(5)
ViewState("ClienteRetIVA") = ObjCliente.RetIVA / 100
ViewState("ClienteRetISR") = ObjCliente.RetISR / 100
ViewState("RetIVAFletes") = ObjCliente.RetieneIVAFletes
If ObjCliente.RetieneIVAFletes Then
TrRetIVA.Style.Add("display", "")
UsuarioActual.Empresa.MostrarRetIVA = True
End If
ViewState("Vendedor") = ObjCliente.Vendedor
ViewState("CtaContable") = ObjCliente.CuentaContable
ViewState("IdCtaContClientes") = ObjCliente.IdCtaContClientes
ViewState("IdCtaContMonedaExtranjera") = ObjCliente.IdCtaContMonedaExtranjera
ViewState("IdCtaContComplementaria") = ObjCliente.IdCtaContComplementaria
ViewState("IdCtaContAnticipos") = ObjCliente.IdCtaContAnticipos
ViewState("IdCtaContRetIVA") = ObjCliente.IdCtaContRetIVA
ViewState("IdCtaContRetISR") = ObjCliente.IdCtaContRetISR
ViewState("CodCliente") = ObjCliente.Codigo
ViewState("ClienteDesglosaIEPS") = ObjCliente.DesglosaIEPS
If (Boolean.Parse(ObjCliente.DtResultados(0)("EsDistribuidor").ToString)) Then
TrEsDistribuidor.Visible = True
If Not String.IsNullOrEmpty(ObjCliente.Vendedor) Then
LbVendedor.Text = GlobalDTVendedores(UsuarioActual.CveEmpresa).FiltroPrimeroValor("Vendedor", $"CveVendedor = {ObjCliente.Vendedor}")
End If
Else
TrEsDistribuidor.Visible = False
End If
ViewState("CliNoExt") = ObjCliente.NoExt
ViewState("CliNoInt") = ObjCliente.NoInt
ViewState("CliLocalidad") = If(ObjCliente.Localidad.Trim.Length = 0, ObjCliente.Ciudad.Trim, ObjCliente.Localidad.Trim)
ViewState("CliPais") = ObjCliente.Pais
'ViewState("NumCtaPago") = ObjCliente.NumCtaPago
EnviarCorreoCliente = ObjCliente.EnviarFactura
ChkEnviarFactura.Visible = True
ChkEnviarFactura.Checked = EnviarCorreoCliente
LblEnviarMail.Visible = True
Dim dr As DataRow = Nothing
dr = GlobalDTSubProyectos(-1).FiltroPrimero("Estatus = 'Activo' AND CveEmpresa = " & UsuarioActual.CveEmpresa)
If dr IsNot Nothing Then
ViewState("MatCalle") = dr("Calle")
ViewState("MatNoExt") = dr("NoExt")
ViewState("MatNoInt") = dr("NoInt")
ViewState("MatColonia") = dr("Colonia")
ViewState("MatLocalidad") = dr("Localidad")
ViewState("MatMunicipio") = dr("Municipio")
ViewState("MatEstado") = dr("Estado")
ViewState("MatPais") = dr("Pais")
ViewState("MatCP") = dr("CP")
End If
If CveVenta <= 0 Then
CveMetodoPagoCliente = ObjCliente.DtResultados.Rows(0)("CveMetodoPago").ToString.ToEntero
DdlUsoCFDI.SelectedValueExist(ObjCliente.CveUsoCFDI.ToString)
DdlMetodoPago.SelectedValueExist(ObjCliente.CveMetodoPago.ToString)
DdlMetodoPago33.SelectedValueExist(ObjCliente.CveMetodoPago33.ToString)
'DdlMetodoPago33.SelectedValueExist(ObjCliente.DtResultados.Rows(0)("CveMetodoPago33").ToString)
DdlMetodoPago33_SelectedIndexChanged(DdlMetodoPago33, EventArgs.Empty)
DdlFormaPago33.SelectedValueExist(ObjCliente.CveFormaPago33.ToString)
'DdlFormaPago33.SelectedValueExist(ObjCliente.DtResultados.Rows(0)("CveFormaPago33").ToString)
DdlUsoCFDI.SelectedValueExist(ObjCliente.DtResultados.Rows(0)("CveUsoCFDI").ToString)
End If
TxtFechaPago.Text = (Now.AddDays(ObjCliente.PlazoCobranza)).ToShortDateString
If ObjCliente.DtResultados(0)("CveVendedor").ToString.ToEntero > 0 Then
DdlVendedor.SelectedValueExist(ObjCliente.DtResultados(0)("CveVendedor").ToString.ToEntero)
End If
If DdlVendedor.SelectedValue.ToEntero > 0 AndAlso Not UsuarioActual.TienePermisoProceso(161) Then
DdlVendedor.Enabled = False
End If
EstatusCliente = ObjCliente.Estatus
If Not EstatusCliente Then
BtnEmitirImprimir.Enabled = False
Alert("El Cliente seleccionado no esta activo", TipoMensaje.MsgAdvertencia)
Else
BtnEmitirImprimir.Enabled = True
End If
UpFacturar.Update()
If UsuarioActual.Empresa.UsaInventarios Then
RblTipo.Items.Remove(RblTipo.Items.FindByValue("1"))
RblTipo.Items.Remove(RblTipo.Items.FindByValue("2"))
End If
UpnTools.Update()
If Not CveVenta > 0 Then
If ObjCliente.DtResultados.Rows.Count > 0 Then
If UsuarioActual.TienePermisoProceso(152) Then
DdlSubProyectoDatos.SelectedValueExist(UsuarioActual.CveSubProyecto)
DdlSubProyectoDatos.Enabled = False
Else
DdlSubProyectoDatos.SelectedValueExist(ObjCliente.CveSubProyecto)
End If
'RECARGA LOS VALORES DE LA SUCURSAL
CambiaSucursal()
UpParametros.Update()
End If
Else
CargaFormatoSucursal()
UpParametros.Update()
End If
If ObjCliente.GetSucursales(CveCliente) Then
DdlSucursalCliente.DataSource = ObjCliente.DtResultados
If ObjCliente.DtResultados.Rows.Count > 0 Then
trsucursalciente.Visible = True
Else
trsucursalciente.Visible = False
End If
Else
trsucursalciente.Visible = False
DdlSucursalCliente.DataSource = Nothing
End If
DdlSucursalCliente.DataBind()
LbAgregar.Enabled = True
UpEstatus.Update()
UpPS.Update()
UpParametros.Update()
UPCondicionesPago.Update()
UpComplementos.Update()
CargarAlmacenes()
CargaFacturasAjuste()
Else
Alert("El cliente solicitado no existe, por favor intente de nuevo.", TipoMensaje.MsgError)
End If
End If
Catch ex As Exception
OnError("Ocurrió un error al asignar el cliente", ex)
End Try
ObjCliente.Dispose()
UPCondicionesPago.Update()
End Sub
Private Sub CambiaSucursal()
CargaFormatoSucursal()
CargaFolios()
CargaVendedores()
CargarAlmacenes()
DdlPS.Attributes.Remove("data-cvesubproyecto")
DdlPS.Attributes.Add("data-cvesubproyecto", DdlSubProyectoDatos.SelectedValue)
UpPS.Update()
End Sub
Private Sub CargaFormatoSucursal()
Dim dr = GlobalDTSubProyectos(-1, CveEmpresa:=UsuarioActual.CveEmpresa).FiltroPrimero(String.Format("CveSubProyecto = {0}", If(DdlSubProyectoDatos.SelectedValue = "", "-1", DdlSubProyectoDatos.SelectedValue)))
If dr IsNot Nothing Then
ViewState("SucCalle") = dr("Calle")
ViewState("SucNoExt") = dr("NoExt")
ViewState("SucNoInt") = dr("NoInt")
ViewState("SucColonia") = dr("Colonia")
ViewState("SucLocalidad") = dr("Localidad")
ViewState("SucMunicipio") = dr("Municipio")
ViewState("SucEstado") = dr("Estado")
ViewState("SucPais") = dr("Pais")
ViewState("SucCP") = dr("CP")
ViewState("FormatoFactura") = dr("FormatoFactura")
ViewState("IVA") = dr("IVA")
ViewState("SubProyectoPorcentajeIVA") = dr("IVA")
ViewState("TipoFormato") = dr("TipoFormato")
ViewState("Serie") = dr("Serie")
LblSerie.Text = dr("Serie").ToString
If SerieXML <> "" Then LblSerie.Text = SerieXML
If dr("TipoVenta").ToString = "1" Then
UpnTools.Update()
'activa el modo de pago efectivo directamente, y es venta nueva
If ViewState("CveVenta").ToString.ToEntero < 0 Then InicializaCondicionesPago()
DdlFormaPago.SelectedValueExist("0")
DdlMetodoPago.SelectedValueExist("1")
RBLPago.SelectedValue = "2"
LimpiaEscondeContado()
If DdlCuentaEfectivo.Items.Count = 2 Then
DdlCuentaEfectivo.SelectedIndex = 0
End If
End If
End If
DdlMetodoPago.SelectedValueExist(CveMetodoPagoCliente.ToString)
UpFacturar.Update()
UpParametros.Update()
End Sub
Private Sub CargaClienteSucursal(CveClienteSuc As Integer, Optional ByRef ObjVentas As ClsVentas = Nothing)
Dim ObjCliente As New ClsClientes
If CveClienteSuc > 0 Then
If ObjCliente.GetSucursales(CveCliente, CveClienteSuc) Then
If ObjCliente.DtResultados.Rows.Count > 0 Then
Dim Correo = ObjCliente.DtResultados.Rows(0)("Correo").ToString
If Correo.Trim.Length > 0 Then
ViewState("Mail") = Correo
End If
LblDireccion.Text = ObjCliente.DtResultados.Rows(0)("Direccion").ToString
LblColonia.Text = ObjCliente.DtResultados.Rows(0)("Colonia").ToString
LblCiudad.Text = ObjCliente.DtResultados.Rows(0)("Ciudad").ToString
LblEstado.Text = ObjCliente.DtResultados.Rows(0)("Estado").ToString
'TxtNumCtaPago.Text = ObjCliente.DtResultados.Rows(0)("NumCtaPago").ToString
LblTelefono.Text = ObjCliente.DtResultados.Rows(0)("Telefono").ToString
LblCP.Text = ObjCliente.DtResultados.Rows(0)("CP").ToString
ViewState("CliLocalidad") = ObjCliente.DtResultados.Rows(0)("Localidad").ToString
ViewState("CliPais") = ObjCliente.DtResultados.Rows(0)("Pais").ToString
ViewState("CliNoExt") = ObjCliente.DtResultados.Rows(0)("NoExt").ToString
ViewState("CliNoInt") = ObjCliente.DtResultados.Rows(0)("NoInt").ToString
DdlVendedor.SelectedValueExist(ObjCliente.DtResultados.Rows(0)("CveVendedor").ToString)
ViewState("CveClienteSucursal") = ObjCliente.DtResultados(0)("CveClienteSucursal").ToString
ViewState("CliCorreoCot") = ObjCliente.DtResultados.Rows(0)("CorreoCotizacion").ToString
If ObjCliente.DtResultados.Rows(0)("Estatus").ToString <> "Activo" Then
RBLPago.Items(0).Enabled = False
Alert("La Sucursal/Departamento del cliente se encuentra inactivo")
End If
If CveVenta <= 0 Then
CveMetodoPagoCliente = ObjCliente.DtResultados.Rows(0)("CveMetodoPago").ToString.ToEntero
DdlMetodoPago.SelectedValueExist(CveMetodoPagoCliente.ToString)
DdlFormaPago33.SelectedValueExist(ObjCliente.DtResultados.Rows(0)("CveFormaPago33").ToString)
DdlMetodoPago33.SelectedValueExist(ObjCliente.DtResultados.Rows(0)("CveMetodoPago33").ToString)
DdlUsoCFDI.SelectedValueExist(ObjCliente.DtResultados.Rows(0)("CveUsoCFDI").ToString)
End If
If CveVenta < 0 Then TxtAtencionA.Text = ObjCliente.DtResultados.Rows(0)("Contacto").ToString
End If
Else
Alert("No se pudieron cargar los datos de la sucursal", TipoMensaje.MsgAdvertencia)
End If
Else
If ObjCliente.GetClientes(CveCliente, "-1", "-1", "-1", "-1", "-1", "-1", -1, UsuarioActual.CveEmpresa, TipoCliente:=-1) Then
If ObjCliente.DtResultados.Rows.Count > 0 Then
ViewState("Mail") = If(DdlTipoComprobante.SelectedValue = "Cot", ObjCliente.MailCotizacion, ObjCliente.Mail)
LblDireccion.Text = ObjCliente.Direccion
LblColonia.Text = ObjCliente.Colonia
LblCiudad.Text = ObjCliente.Ciudad
LblEstado.Text = ObjCliente.Estado
LblCP.Text = ObjCliente.CP
LblTelefono.Text = ObjCliente.Telefono
DdlVendedor.SelectedValueExist(ObjCliente.DtResultados.Rows(0)("CveVendedor").ToString)
ViewState("CliNoExt") = ObjCliente.NoExt
ViewState("CliNoInt") = ObjCliente.NoInt
PlazoCobranza = ObjCliente.PlazoCobranza
If CveVenta <= 0 Then
CveMetodoPagoCliente = ObjCliente.CveMetodoPago
DdlMetodoPago.SelectedValueExist(CveMetodoPagoCliente.ToString)
DdlFormaPago33.SelectedValueExist(ObjCliente.CveFormaPago33)
DdlMetodoPago33.SelectedValueExist(ObjCliente.CveMetodoPago33)
DdlUsoCFDI.SelectedValueExist(ObjCliente.CveUsoCFDI)
End If
End If
End If
End If
'SI LA SUCURSAL DEL CLIENTE NO TIENE VENDEDOR SELECCIONAMOS EL DEL USUARIO
If Not DdlVendedor.SelectedValue.ToEntero > 0 Then
DdlVendedor.SelectedValueExist(UsuarioActual.CveVendedor.ToString)
End If
UPPVentas.Update()
UpEstatus.Update()
UPCondicionesPago.Update()
ObjCliente.Dispose()
End Sub
Private Sub SetValues()
ViewState("TipoCambio") = 1
If UsuarioActual.Empresa.MostrarRetIVA Then TrRetIVA.Style.Add("display", "")
If UsuarioActual.Empresa.MostrarRetISR Then TrRetISR.Style.Add("display", "")
End Sub
Private Sub CargaClasificaciones()
If UsuarioActual.Empresa.UsaAC Then
DdlClasificacion.DataSource = GlobalDTClasificaciones(UsuarioActual.CveEmpresa, UsoClasificacion:=1).FiltraParametros(" Codigo = '' OR Codigo IS NULL ", Orderby:="Clasificacion")
Else
DdlClasificacion.DataSource = GlobalDTClasificaciones(UsuarioActual.CveEmpresa, UsoClasificacion:=1).FiltraParametros("Estado = 1", Orderby:="Clasificacion")
End If
DdlClasificacion.DataBind()
End Sub
Private Sub CargaPS(CveClasificacion As Integer, Objeto As ADServerControl.Dropdownlost, Optional AplicaAlmacen As Boolean = True)
Objeto.setEsWebService(UsuarioActual.Empresa.Funcionalidad(141).ToString = "1")
If Not UsuarioActual.Empresa.Funcionalidad(141).ToString = "1" Then
Objeto.ddl.Items.Clear()
Objeto.ddl.DataSource = GlobalDTPSSimplificado(UsuarioActual.CveEmpresa, CveClasificacion:=CveClasificacion, Estatus:=1, AplicaParaVenta:=1)
Objeto.ddl.DataBind()
Objeto.ddl.Items.Insert(0, New ListItem("*** Actualizar listado de Productos o Servicios ***", "-2"))
Objeto.ddl.Items.Insert(0, New ListItem("Seleccione el Producto", "-1"))
Else
Objeto.Attributes.Add("data-cvesubproyecto", DdlSubProyectoDatos.SelectedValue)
'Objeto.ddlWS.Attributes.Add("data-cveclasificacion", CveClasificacion.ToString)
Objeto.ddlWS.Attributes.Add("data-cveclasificacion", "-1")
Objeto.ddlWS.Attributes.Add("data-aplicaparaventa", "1")
If AplicaAlmacen Then
Objeto.ddlWS.Attributes.Add("data-pagina", "ventas/ventas")
Else
Objeto.ddlWS.Attributes.Add("data-pagina", "-1")
End If
Objeto.ddlWS.Attributes.Add("data-aplicaparaventa", "1")
Objeto.ddlWS.Attributes.Add("data-Estatus", "1")
End If
End Sub
Private Sub CargaFolios()
If ExFolioFactura Then
Exit Sub
End If
If DdlSubProyectoDatos.SelectedValue.ToEntero <= 0 Then
Alert("No se tienen asignadas sucursales", TipoMensaje.MsgError)
Exit Sub
End If
'If UsuarioActual.CveEmpresa = 119 AndAlso DdlTipoComprobante.SelectedValue <> "Cot" AndAlso (CveVenta <= 0 Or (DtVentasNC IsNot Nothing AndAlso DtVentasNC.Rows.Count > 0) Or CveDevolucion > 0) Then
' TxtFolio.Text = ""
'Else
Dim ObjFolios As New ClsGralFolios()
Dim TipoDoctoConsulta As String = If(DdlTipoComprobante.SelectedValue = "Ant", "Ing", If(DdlTipoComprobante.SelectedValue = "PA", "Rem", DdlTipoComprobante.SelectedValue))
If ObjFolios.GetFolios(TipoDoctoConsulta, UsuarioActual.CveEmpresa) Then
Dim DT As DataTable = ObjFolios.DtResultados.FiltraParametros(String.Format(" CveSubProyecto = {0} And Estado = 'Activo'", DdlSubProyectoDatos.SelectedValue))
If DT.Rows.Count > 0 Then
ViewState("CveFolio") = DT.Rows(0)("CveFolio").ToString.ToEntero
'ViewState("NumAprobacion") = CLng(DT.Rows(0)("Aprobacion").ToString)
'ViewState("FechaAprobacion") = DT.Rows(0)("FechaAprobacion").ToString.ToDate
ViewState("FolioActual") = DT.Rows(0)("FActual").ToString
LblSerie.Text = DT.Rows(0)("Serie").ToString
TxtFolio.Text = DT.Rows(0)("FActual").ToString
BtnEmitirImprimir.Visible = True
UpFacturar.Update()
Else
Alert("No tiene registrados Folios para " & DdlTipoComprobante.SelectedItem.Text & " en esta sucursal.", TipoMensaje.MsgAdvertencia)
BtnEmitirImprimir.Visible = False
UpFacturar.Update()
End If
DT.Dispose()
End If
ObjFolios.Dispose()
'End If
End Sub
Private Sub CargaDdlSubProyectos()
DdlSubProyectoDatos.DataSource = GlobalDTSubProyectosUsuarios(UsuarioActual.CveUsuario, -1, UsuarioActual.CveEmpresa, -1, 1).FiltraParametros("EsSucursal = True ")
DdlSubProyectoDatos.DataBind()
End Sub
Private Sub CargaVendedores()
Dim CveVendedorActual = DdlVendedor.SelectedValue
DdlVendedor.Items.Clear()
If UsuarioActual.Empresa.Funcionalidad(302) = "1" AndAlso DdlSubProyectoDatos.SelectedValue.ToEntero > 0 Then
DdlVendedor.DataSource = GlobalDTVendedores(UsuarioActual.CveEmpresa).FiltraParametros(String.Format("CveSubProyecto = {0}", DdlSubProyectoDatos.SelectedValue)).FiltraParametros("VendedorTipo = 1")
Else
DdlVendedor.DataSource = GlobalDTVendedores(UsuarioActual.CveEmpresa).FiltraParametros("VendedorTipo = 1")
End If
DdlVendedor.SelectedValue = "0"
DdlVendedor.Items.Insert(0, New ListItem("Sin Asignar", "0"))
DdlVendedor.DataBind()
DdlVendedor.SelectedValueExist(CveVendedorActual)
If Not DdlVendedor.SelectedValue.ToEntero > 0 Then
DdlVendedor.SelectedValueExist(UsuarioActual.CveVendedor.ToString)
End If
'SELECCIONA VENDEDOR DEL USUARIO CUANDO SEA VENTA NUEVA Y SIN CLIENTE
If UsuarioActual.CveVendedor > 0 Then
If CveVenta = -1 AndAlso Not DdlVendedor.SelectedValue.ToEntero() > 0 Then DdlVendedor.SelectedValueExist(UsuarioActual.CveVendedor.ToString())
If DdlVendedor.SelectedValue.ToEntero() > 0 AndAlso Not UsuarioActual.TienePermisoProceso(161) Then
DdlVendedor.Enabled = False
End If
'multiples vendedores visible
If UsuarioActual.TienePermisoProceso(153) Then
DdlVendedor.Enabled = True
End If
End If
End Sub
Private Sub ObtenerFechaVencimientoCER()
Try
Dim CerFile As New FileStream(Ruta & "Certificados\" & UsuarioActual.Empresa.ArchivoCer, FileMode.Open, FileAccess.Read)
Dim Size As Integer = CerFile.Length.ToString.ToEntero()
Dim Data As Byte() = New Byte(Size - 1) {}
Size = CerFile.Read(Data, 0, Size)
CerFile.Close()
CerFile.Dispose()
Dim x509 As New X509Certificate2()
x509.Import(Data)
If x509.NotAfter <= Now() Then
BtnEmitirImprimir.Enabled = False
Alert("La fecha del certificado ha expirado", TipoMensaje.MsgAdvertencia)
End If
Catch ex As Exception
Alert("No se pudo verificar la fecha del certificado", TipoMensaje.ToastError)
End Try
End Sub
#End Region
#Region "GVPS"
Protected Sub GvPS_RowDeleting(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewDeleteEventArgs) Handles GvPS.RowDeleting
Dim DbRow As DataRow = Nothing
DbRow = TmpDT.Rows(e.RowIndex)
Me.CveVentaDetalle = DbRow("CveVentaDetalle").ToString().ToEntero()
If Me.CveVentaDetalle <= 0 Then
EliminarUsados(DbRow("Consec").ToString().ToEntero())
TmpDT.Rows.Remove(DbRow)
Else
EliminarUsados()
DbRow("EliminarDB") = True
End If
GvPS.DataSource = TmpDT.FiltraParametros("EliminarDB = False")
DtInv = TmpDT.Copy.FiltraParametros("CveTipoPS = 2")
GvPS.DataBind()
CargaGVInv(DtInv)
CalculaTotalesVenta()
Alert("Eliminado Correctamente.", TipoMensaje.MsgInformacion)
Me.CveVentaDetalle = -1
UpContado.Update()
End Sub
Protected Sub GvPS_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles GvPS.RowDataBound
If e.Row.RowType = DataControlRowType.DataRow Then
e.Row.Attributes("id") = e.Row.RowIndex.ToString
'MODO NORMAL
If UsuarioActual.Empresa.UsaAC Then
e.Row.FCDropDownList("DdlFR").DataSource = DTPresupuestoIngresos
e.Row.FCDropDownList("DdlFR").DataBind()
e.Row.FCDropDownList("DdlFR").SelectedValue = e.Row.DBCampo("CvePresupuestoIngreso")
'e.Row.FCDropDownList("DdlFR").Enabled = False
End If
If e.Row.DataKey("IEPS").ToDouble > 0 Then : TrIEPS.Visible = True : End If
If NuevaFactura = 1 Then
'PUEDE EDTIRAR EL PU DEL PRODUCTO
If UsuarioActual.TienePermisoProceso(222) Then
' e.Row.FCTextBox("TxtPrecio").Enabled = True
e.Row.FCLinkButton("imgD").Visible = True
e.Row.FCLinkButton("imgD").Visible = False
Else
e.Row.FCLinkButton("imgD").Visible = False
e.Row.FCLinkButton("imgE").Visible = False
End If
End If
If UsuarioActual.Empresa.CvePlataforma = 2 Then
e.Row.FCLinkButton("imgE").Visible = False
e.Row.FCLinkButton("imgEPyME").Visible = True
End If
End If
End Sub
Protected Sub OrdenarGvPS(ByVal sender As Object, ByVal e As EventArgs)
For Each row As GridViewRow In GvPS.Rows
TmpDT.Rows(row.RowIndex)("Orden") = row.FCTextBox("TxtOrden").Text.ToEntero
Next
Dim resultados = From OrdenDT In TmpDT
Order By OrdenDT("Orden").ToString.ToEntero
Select OrdenDT
TmpDT = resultados.CopyToDataTable
CalculaTotalesVenta()
GvPS.DataSource = TmpDT.FiltraParametros("EliminarDB = False")
GvPS.DataBind()
UpPS.Update()
End Sub
#End Region
#Region "GVINV"
Private Sub GvInv_RowDataBound(sender As Object, e As GridViewRowEventArgs) Handles GvInv.RowDataBound
If e.Row.RowType = DataControlRowType.DataRow Then
'SERIE ALMACEN
If e.Row.DBCampo("CveTipoInvPS").ToEntero = 5 Then
If CveVenta > 0 Then
e.Row.FCLiteral("LtlSerie").Visible = True
Else
e.Row.FCTextBox("TxtSerie").Visible = True
e.Row.FCTextBox("TxtSerie").Attributes.Remove("onkeypress")
e.Row.FCTextBox("TxtSerie").Attributes.Add("onkeypress", String.Format("SeriePS(event,{0},this,{1});", e.Row.FCButton("BtnSerie").ClientID, e.Row.FCHiddenField("HdnSerie").ClientID))
e.Row.FCTextBox("TxtSerie").Attributes.Remove("onblur")
e.Row.FCTextBox("TxtSerie").Attributes.Add("onblur", String.Format("SeriePSBlur({0},this,{1});", e.Row.FCButton("BtnSerie").ClientID, e.Row.FCHiddenField("HdnSerie").ClientID))
End If
'e.Row.FCTextBox("TxtSerie").Attributes.Add("onkeyup", String.Format("LimpiaAF(1, '{0}'); EnterAFEdit(event,this,{1},{2});", e.Row.FCHiddenField("HdnCveConcepto").Value, e.Row.FCHiddenField("HdnCveAF").ClientID, e.Row.FCHiddenField("HdnCodAF").ClientID))
'e.Row.FCTextBox("LblCodigo").Attributes.Add("onkeyup", String.Format("LimpiaAF(1, '{0}'); EnterAFEdit(event,this,{1},{2});", e.Row.FCHiddenField("HdnCveConcepto").Value, e.Row.FCHiddenField("HdnCveAF").ClientID, e.Row.FCHiddenField("HdnCodAF").ClientID))
'e.Row.FCTextBox("LblCodigo").Attributes.Add("onblur", String.Format("LimpiaAF(1, '{0}'); AFBlurEdit(this,{1},{2});", e.Row.FCHiddenField("HdnCveConcepto").Value, e.Row.FCHiddenField("HdnCveAF").ClientID, e.Row.FCHiddenField("HdnCodAF").ClientID))
End If
If e.Row.DBCampo("CvePS") = "" Then
e.Row.FCLiteral("LtlPS").Text = String.Format("Folio: {1} Fecha: {2} -- {3} -- {4}", e.Row.DBCampo("CveMovimiento"), e.Row.DBCampo("Folio"), e.Row.DBCampo("Fecha").ToString.ToDate.ToShortDateString, e.Row.DBCampo("Almacen").ToString, e.Row.DBCampo("Concepto").ToString)
e.Row.FCCheckBox("cbInv").Visible = False
e.Row.FCCheckBox("cbInv").Enabled = False
If e.Row.DataKey("Origen").ToEntero > 0 Then
e.Row.BackColor = Drawing.Color.FromArgb(224, 130, 131)
e.Row.ForeColor = Drawing.Color.White
e.Row.Font.Bold = True
Else
e.Row.CssClass = "SubTotales"
End If
Else
e.Row.Cells(3).HorizontalAlign = HorizontalAlign.Left
e.Row.FCCheckBox("cbInv").Visible = True
e.Row.FCCheckBox("cbInv").Enabled = True
'SI ES REMISION O VENTA DEBE SALIR DE ALMACEN
'If UsuarioActual.TienePermisoProceso(157) AndAlso e.Row.DBCampo("CvePS").ToEntero > 0 AndAlso DdlTipoComprobante.SelectedValue.Contiene("Rem", "Ing") AndAlso UsuarioActual.CveEmpresa <> 72 Then
' e.Row.FCCheckBox("cbInv").Checked = True
' e.Row.FCCheckBox("cbInv").Enabled = False
'End If
'If UsuarioActual.Empresa.Funcionalidad(531).ToString = "1" Then
' e.Row.FCCheckBox("cbInv").Checked = True
'End If
End If
If CveVenta > 0 Then
e.Row.FCCheckBox("cbInv").Visible = False
End If
End If
End Sub
Protected Sub GVINV_RowEditing(sender As Object, e As GridViewEditEventArgs) Handles GvInv.RowEditing
GvInv.EditIndex = e.NewEditIndex
CargaGVInv(DtInv.FiltraParametros("CveTipoPS=2"))
End Sub
Protected Sub GVINV_RowCancelingEdit(sender As Object, e As GridViewCancelEditEventArgs) Handles GvInv.RowCancelingEdit
GvInv.EditIndex = -1
CargaGVInv(DtInv.FiltraParametros("CveTipoPS=2"))
End Sub
Protected Sub GVINV_RowUpdating(sender As Object, e As GridViewUpdateEventArgs) Handles GvInv.RowUpdating
Dim Cantidad As Double = DirectCast(GvInv.Rows(e.RowIndex).FindControl("txtECantidad"), TextBox).Text.ToDouble
DtInv.Rows.Item(e.RowIndex)("Cantidad") = Cantidad
GvInv.DataSource = DtInv.FiltraParametros("CveTipoPS=2")
End Sub
#End Region
#Region " INVENTARIO POR ENTREGA"
Private Sub CargaGVInv(DtTemporal As DataTable)
If Not DtTemporal.Columns.Contains("Lote") Then
DtTemporal.Columns.Add("Lote", Type.GetType("System.String"))
End If
If Not DtTemporal.Columns.Contains("FechaCaducidad") Then
DtTemporal.Columns.Add("FechaCaducidad", Type.GetType("System.DateTime"))
End If
GvInv.Columns(4).Visible = DtTemporal.MAX("Serie", "Serie <> ''") <> "" Or CveVenta <= 0
GvInv.Columns(5).Visible = DtTemporal.MAX("Lote", "Lote <> ''") <> ""
GvInv.Columns(6).Visible = DtTemporal.MAX("FechaCaducidad", "FechaCaducidad <> ''") <> ""
GvInv.DataSource = DtTemporal.FiltraParametros("EliminarDB = False")
GvInv.DataBind()
UpINV.Update()
End Sub
#End Region
#Region " EMITIR IMPRIMIR - GUARDAR "
Protected Sub BtnEmitirImprimir_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles BtnEmitirImprimir.Click
If Not CveCliente > 0 Then
Alert("Es necesario seleccionar el cliente al cual se le va a facturar.", TipoMensaje.MsgAdvertencia)
Exit Sub
End If
If TmpDT Is Nothing OrElse TmpDT.Rows.Count = 0 Then
Alert("Es necesario tener al menos un concepto registrado.", TipoMensaje.MsgAdvertencia)
Exit Sub
End If
'Subproyecto Obligatorio
If UsuarioActual.Empresa.Funcionalidad(120) = "1" AndAlso TmpDT.FiltraParametros("ISNULL(CveSubProyecto,0) <= 0").Rows.Count > 0 Then
Alert("El Subproyecto es obligatorio, favor de seleccionarlo", TipoMensaje.MsgAdvertencia)
Exit Sub
End If
'VALIDA PRECIO AL AGREGAR A ALMACEN
If Not UsuarioActual.TienePermisoProceso(169) Then
If Not CveContrato > 0 Then
If DdlTipoComprobante.SelectedValue.Contiene("Rem", "Ing") Then
Dim MensajeCosto As New StringBuilder
Dim CostoMenor = 0.0D
Dim CostoMayor = 0.0D
Dim Costo = 0.0D
Dim EsValido = False 'BANDERA
Dim EsValidoMayor = False
'VALIDA PROMOCIONES Y EXISTENCIAS
Dim ObjVentas As New ClsVentas
If ObjVentas.GetPromocionesPS(-1, TxtFecha.Text.ToDateTime, DdlSubProyectoDatos.SelectedValue.ToEntero, CveCliente, DdlVendedor.SelectedValue.ToEntero, UsuarioActual.CveEmpresa) Then
DtPromociones = ObjVentas.DtResultados
End If
ObjVentas.Dispose()
Dim ObjInventarios As New ClsInventarios
Dim PU = 0.0D
For Each dr As DataRow In TmpDT.Rows
'SI ES SERVICIO NO VALIDA
If GlobalDTPS(UsuarioActual.CveEmpresa, CvePS:=dr("CvePS").ToString.ToEntero).FiltroPrimeroValor("CveTipoPS").ToString.ToEntero = 1 Then
Continue For
End If
EsValido = False
PU = dr("PU").ToString.ToDecimal * If(DdlMoneda.SelectedValue.ToEntero = 1, 1, TxtTipoCambio.Text.ToDecimal)
'COSTO ALMACEN
If UsuarioActual.Empresa.Funcionalidad(129).ToEntero > 0 AndAlso UsuarioActual.CveUsuario <> 1560 Then
Costo = ObjInventarios.GetCostoPS(dr("CvePS").ToString.ToEntero, dr("Cantidad").ToString.ToDouble, -1, dr("Serie").ToString, TxtFecha.Text.ToDate, -1)
CostoMenor = Costo + ((UsuarioActual.Empresa.Funcionalidad(129).ToDecimal / 100) * Costo)
'SI EL PRECIO ES MAYOR AL COSTO, SI PASA
If PU >= CostoMenor Then
EsValido = True
End If
Else
EsValido = True
End If
If UsuarioActual.Empresa.Funcionalidad(133).ToEntero > 0 AndAlso UsuarioActual.CveUsuario <> 1560 Then
Costo = ObjInventarios.GetCostoPS(dr("CvePS").ToString.ToEntero, dr("Cantidad").ToString.ToDouble, -1, dr("Serie").ToString, TxtFecha.Text.ToDate)
CostoMayor = Costo + ((UsuarioActual.Empresa.Funcionalidad(133).ToDecimal / 100) * Costo)
'SI EL PRECIO ES MAYOR AL COSTO, SI PASA
If PU <= CostoMayor Then
EsValidoMayor = True
End If
Else
EsValidoMayor = True
End If
'VALIDA PROMOCION: SI TIENE PROMOCION Y EL PRECIO ES MENOR AL PRECIO DE PROMOCION, NO PASA | SI YA CUMPLE NO VUELVE A VALIDAR
If Not EsValido Then
If DtPromociones.FiltraParametros($"CvePS = {dr("CvePS").ToString.ToEntero}").Rows.Count > 0 Then
If PU >= DtPromociones.FiltroPrimeroValor("PUPromocion", $"CvePS = {dr("CvePS").ToString.ToEntero}").ToDecimal Then
EsValido = True
End If
End If
End If
'NO DEJA REGISTRAR CON VALIDACION DE COSTO ALMACEN O PROMOCION
If Not EsValido Then
MensajeCosto.AppendFormat("El Producto {0}. No se puede vender a un precio menor de su Costo ni a un precio mayor de su rango aceptado
", dr("PS").ToString)
End If
If Not EsValidoMayor Then
MensajeCosto.AppendFormat("El Producto {0}. No se puede vender a un precio mayor de su rango aceptado
", dr("PS").ToString)
End If
Next
ObjInventarios.Dispose()
If MensajeCosto.ToString.Length > 1 Then
Alert(MensajeCosto.ToString, TipoMensaje.MsgAdvertencia)
Exit Sub
End If
End If
End If
End If
If UsuarioActual.Empresa.Funcionalidad(135) = "1" And DdlTipoComprobante.SelectedValue = "Cot" Then
Alert("Se mando autorización al supervisor.")
MandarCorreoSupervisor = True
Dim CorreoSupervisor As String = ""
Dim Objeto As New ClsVtaVendedores
Dim DTSupervisores As New DataTable
If Objeto.GetVendedores(UsuarioActual.CveEmpresa) Then
DTSupervisores = Objeto.DtResultados.FiltraParametros(String.Format("CveVendedor = {0}", DdlVendedor.SelectedValue.ToEntero))
'Verifico si el supervisor tiene correo para proceder
If DTSupervisores.Rows.Count > 0 Then
CorreoSupervisor = DTSupervisores.Rows(0)("CorreoSupervisor").ToString
End If
End If
Objeto.Dispose()
If MandarCorreoSupervisor = True And CorreoSupervisor <> "" Then
ViewState("Mail") = CorreoSupervisor
End If
MandarCorreoSupervisor = False
End If
'If TmpDTAjustes IsNot Nothing AndAlso Not TmpDTAjustes.Rows.Count > 0 AndAlso UsuarioActual.Empresa.Funcionalidad(531).ToString = "1" Then
' RegistraScript("$('#DModalRecepcionUsados').modal('show');")
'Else
' EmitirImprimirNew()
'End If
EmitirImprimirNew()
End Sub
#End Region
#Region "E M I T I R - F A C T U R A"
Protected Sub EmitirImprimirNew()
If ValidaPagosContado() Then
Exit Sub
End If
CreaObjetosVenta()
If ObjFactura Is Nothing Or ObjFactura.Cliente Is Nothing Then
Alert("Ocurrió un error al procesar los datos de la Venta.", TipoMensaje.MsgError)
ObjFactura = Nothing
Exit Sub
End If
If ObjFactura.CveCliente > 0 Then
If TmpDT.Rows.Count > 0 Then
Dim Retorno = ObjFactura.EmitirFactura()
If Retorno.CveVenta > 0 Then
Dim SbAlert As New StringBuilder
SbAlert.AppendFormat("{0}
", Retorno.Mensajes(Retorno.Mensajes.Count - 1))
SbAlert.AppendFormat("