diff --git a/Ventas/Ventas.aspx.vb b/Ventas/Ventas.aspx.vb index b5cbe9e05..b8286dbce 100644 --- a/Ventas/Ventas.aspx.vb +++ b/Ventas/Ventas.aspx.vb @@ -4400,1172 +4400,1188 @@ Partial Class Ventas CveVenta = If(CvePedido > 0, CvePedido, CveVenta) Dim DtAntRelacionados As DataTable = Nothing - - Dim ObjVentas As New ClsVentas() - - If ObjVentas.GetVentasRelacionadas(CveVenta, UsuarioActual.CveEmpresa) Then - DtAntRelacionados = ObjVentas.DtResultados.FiltraParametros("TipoDocto IN ('Ing','Ant','Egs','Dev')") - End If - Dim SerieFolioPadre As String + Dim DbRowVenta As DataRow = Nothing - 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() - HdnCveVenta.Value = CveVenta.ToString() - - Me.EsGarantia = CBool(DbRowVenta("EsGarantia")) - - RFCReceptorVenta = DbRowVenta("RFCReceptor").ToString() - 'Adjuntar archivo - Adjunto = DbRowVenta("Adjunto").ToString() - If Adjunto <> "" Then - BtnArchivoAdjunto.Text = Adjunto - BtnArchivoAdjunto.Visible = True - BtnEliminarAdjunto.Visible = False - BtnAdjuntar.Visible = False - - tdAdjuntar.Style.Item("display") = "none" - tdAdjunto.Style.Item("display") = "block" - - Else - DivAdjuntar.Visible = False - + 'CARGA DTs DE VENTAS + If CveVenta > 0 Then + Using ObjVentas As New ClsVentas() + If ObjVentas.GetVenta(CveVenta, UsuarioActual.CveEmpresa) Then + If ObjVentas.DtResultados IsNot Nothing AndAlso ObjVentas.DtResultados.Rows.Count > 0 Then + DbRowVenta = ObjVentas.DtResultados.Copy().Rows(0) + Else + ViewState("CveVenta") = -1 + Alert("El documento solicitado no existe, favor de revisar su búsqueda.", TipoMensaje.MsgAdvertencia) + End If End If - ViewState("CveSubProyectoVenta") = DbRowVenta("CveSubProyecto").ToString().ToEntero() - - - - Me.CveEstatusFacturaPadre = DbRowVenta("CveEstatusFacturaPadre").ToString().ToEntero() - 'CargaEncabezado - If Not (CveRemision > 0 Or CveCotizacion > 0) Then - DdlTipoComprobante.SelectedValue = DbRowVenta("TipoDocto").ToString() - - If UsuarioActual.TienePermisoProceso(274) Then - TrAntEspecial.Visible = DdlTipoComprobante.SelectedValue = "Ant" - End If - - If TrAntEspecial.Visible Then - ChkAntEspecial.Enabled = False - ChkAntEspecial.Checked = If(DbRowVenta("AnticipoEspecial").ToString() = "True", True, False) - End If - CargaEstatusFactura(DdlTipoComprobante.SelectedValue) - CveEstatus = DbRowVenta("CveEstatusFactura").ToString().ToEntero() - LbEstatus.Text = DbRowVenta("EstatusFactura").ToString() - ViewState("SaldoVenta") = DbRowVenta("Saldo").ToString() - AplicaCancelarRemision = CBool(DbRowVenta("AplicaCancelarRemision").ToString()) - If AplicaCancelarRemision AndAlso CveEstatus.Contiene(2, 3) AndAlso DdlTipoComprobante.SelectedValue = "Ing" Then DivCanRem.Visible = True - VentaSaldoAlmacen = DbRowVenta("SaldoAlmacen").ToString().ToDecimal - - If CveEstatus = 5 Then LbCancelarDocumento.Enabled = False - 'If CveEstatus = 20 Then - ' LbCancelarDocumentoManual.Visible = True - 'End If - - - If (Not CveEstatus.Contiene(4, 5, 12, 13, 20, 23) OrElse (CveEstatus = 5 AndAlso DbRowVenta("CveEstatusRefacturacion").ToString().ToEntero() = 4)) AndAlso DdlTipoComprobante.SelectedValue.Contiene("Ing", "Egs", "Ant") AndAlso UsuarioActual.TienePermisoProceso(159) Then - Dim TienePermiso As String = GlobalDTSubProyectosUsuarios(UsuarioActual.CveUsuario, -1, UsuarioActual.CveEmpresa, -1, -1).FiltroPrimeroValor("CveSubProyecto", String.Format("CveSubProyecto = {0}", DbRowVenta("CveSubProyecto"))) - If TienePermiso <> "" Then - LkRefacturacion.Visible = True - If (CveEstatus = 5 AndAlso DbRowVenta("CveEstatusRefacturacion").ToString().ToEntero() = 4) Then - RefacturarCancelada = True - End If - End If - End If - - If DbRowVenta("CveVentaRelacionada").ToString().ToEntero() > 0 Then - TrRefacturadaa.Visible = True - HplRefacturadaEn.NavigateUrl = String.Format("/Ventas/Ventas.aspx?CveVenta={0}", DbRowVenta("CveVentaRelacionada")) - HplRefacturadaEn.Text = DbRowVenta("SerieFolioRelacionada").ToString() - LblAlertRefacInv.Visible = True - End If - - If DdlTipoComprobante.SelectedValue.Contiene("Egs", "Ing", "Ant", "Dev", "Rem", "DPe", "RNC", "Pd2", "Cot") AndAlso Not CveEstatus.Contiene(4, 5, 10, 12, 13, 20, 23) Then - If UsuarioActual.TienePermisoProceso(159) Then - Dim TienePermiso As String = GlobalDTSubProyectosUsuarios(UsuarioActual.CveUsuario, -1, UsuarioActual.CveEmpresa, -1, -1).FiltroPrimeroValor("CveSubProyecto", String.Format("CveSubProyecto = {0}", DbRowVenta("CveSubProyecto"))) - If TienePermiso <> "" Then - LbCancelarDocumento.Visible = True - 'If UsuarioActual.CveEmpresa = 119 And Not UsuarioActual.CveUsuario.Contiene(100, 1703) Then '[IPP] AD y Jesus de JAM - ' 'si es del mes anterior no permita cancelar - ' If Not DdlTipoComprobante.SelectedValue.Contiene("Rem") Then - ' If DbRowVenta("Fecha").ToString().ToDate <= Now.AddMonths(-1).LastDayOfMonth Then - ' LbCancelarDocumento.Visible = False - ' End If - ' End If - 'End If - End If - - End If - End If - - Dim TipoEstatus As Integer = GlobalDTEstatusFactura().FiltroPrimeroValor("TipoEstatus", $"CveEstatusFactura = {CveEstatus}").ToEntero() - - If UsuarioActual.Empresa.Funcionalidad(135).Contiene("1", "2") AndAlso DdlTipoComprobante.SelectedValue.Contiene("Cot") Then - If UsuarioActual.TienePermisoProceso(116) Then - LbCancelarDocumento.Visible = True - If TipoEstatus = 2 Then - LbCancelarDocumento.Visible = False - ElseIf TipoEstatus = 5 Then - LbCancelarDocumento.Visible = False - End If - End If - End If - - If UsuarioActual.Empresa.Funcionalidad(531) = "1" AndAlso CBool(DbRowVenta("ServicioDomicilio")) Then - TrServicioDomicilio.Visible = True + If DbRowVenta IsNot Nothing Then + If ObjVentas.GetVentasRelacionadas(CveVenta, UsuarioActual.CveEmpresa) Then + DtAntRelacionados = ObjVentas.DtResultados.FiltraParametros("TipoDocto IN ('Ing','Ant','Egs','Dev')") End If 'CargaDetalle If ObjVentas.GetVentaDetalle(CveVenta) Then - TmpDT = ObjVentas.DtResultados + TmpDT = ObjVentas.DtResultados.Copy() + TmpDT.Columns.Add("EntregaDirecta", GetType(Integer)) TmpDT.Columns.Add("CveMovimientoDetallePedido", GetType(Integer)) TmpDT.Columns.Add("CveVentaDetalleRNC", GetType(Integer)) TmpDT.Columns.Add("TieneProntoPago", GetType(String)) TmpDT.Columns.Add("ImporteProntoPago", GetType(Decimal)) - GvPS.DataSource = ObjVentas.DtResultados - GvPS.DataBind() - - 'IEPS A NIVEL DETALLE - 'TxtIEPS.Text = If(TmpDT.SUM("IEPS") > 0, TmpDT.SUM("IEPS").FormatoNumero, TxtIEPS.Text) End If - If UsuarioActual.TienePermisoProceso(318) Then - If DdlTipoComprobante.SelectedValue.Contiene("Egs", "Ing", "Ant", "Dev") AndAlso String.IsNullOrEmpty(DbRowVenta("FolioFiscal").ToString.Trim) Then HplFolioFiscalModal.Visible = True + 'CargaFirmas + If ObjVentas.GetVentasFirmas(CveVenta) Then + If ObjVentas.DtResultados.Rows.Count > 0 Then + DTmpF = ObjVentas.DtResultados.Copy() + End If End If - Select Case DbRowVenta("TipoDocto").ToString() - Case "Ing" - Trsaldo.Visible = True - HplSaldoAuxiliar.NavigateUrl = String.Format("/Contabilidad/PopUpAuxiliar.aspx?Tipo=CxCClientes&CveCliente={0}&CveVenta={1}&TB_iframe=true&height=550&width=920", DbRowVenta("CveCliente"), DbRowVenta("CveVenta")) - HplPagado.NavigateUrl = String.Format("/Contabilidad/PopUpAuxiliar.aspx?Tipo=CxCClientes&CveCliente={0}&CveVenta={1}&TB_iframe=true&height=550&width=920", DbRowVenta("CveCliente"), DbRowVenta("CveVenta")) - If SaldoVenta > 0 And UsuarioActual.TienePermisoProceso(100) Then - HLPagar.Visible = True - HLPagar.NavigateUrl = $"/Bancos/PopIEVentas.aspx?CveVenta={CveVenta}&TB_iframe=true&height=500&width=675" - HlCuentaTerminal.Visible = True + 'CARGA IMPUESTOS LOCALES + If ObjVentas.GetVentaImpuestosLocales(CveVenta) Then + If ObjVentas.DtResultados.Rows.Count > 0 Then + TmpDTImpuestos = ObjVentas.DtResultados.Copy() + End If + End If + + 'CARGA ANTICIPOS + If Not (CveRemision > 0 Or CveCotizacion > 0) Then + If DbRowVenta("TipoDocto").ToString().Contiene("Ing", "Ant") Then + 'carga as notas de credito vinculadas + If ObjVentas.GetVentasAntNC(CveVenta, -1) Then + TmpDTDocumentosRelacionados = ObjVentas.DtResultados.Copy() + GvAntNC.DataSource = TmpDTDocumentosRelacionados + GvAntNC.Caption = "
(Anticipos/NC/IxC) Vinculados
" + GvAntNC.DataBind() End If - CargarSaldoAuxiliar(CveCliente) - TabAuxiliarConta.Visible = UsuarioActual.TienePermisoProceso(306) - Dim TienePermiso As String = GlobalDTSubProyectosUsuarios(UsuarioActual.CveUsuario, -1, UsuarioActual.CveEmpresa, -1, -1).FiltroPrimeroValor("CveSubProyecto", String.Format("CveSubProyecto = {0}", DbRowVenta("CveSubProyecto"))) - If TienePermiso <> "" Then ' si tiene acceso en el subproyecto - 'LkNotaCredito.Visible = UsuarioActual.TienePermisoProceso(175) - If UsuarioActual.TienePermisoProceso(264) Then - InicializaAplicaDevolucion(TmpDT) + End If + + If DbRowVenta("TipoDocto").ToString().Contiene("Egs", "Dev", "Ant") Then + Dim AplicaAmortizacion As Boolean = False + If DbRowVenta("TipoDocto").ToString().Contiene("Ant") Then AplicaAmortizacion = True + + If ObjVentas.GetVentasAntNC(-1, CveVenta, AplicaAmortizacion) Then + + TmpDTNCVinculadas = ObjVentas.DtResultados.Copy() + GvNC.DataSource = TmpDTNCVinculadas + GvNC.Caption = "
Ventas Aplicadas
" + GvNC.DataBind() + InicializaDTVentasNC() + + For Each Dr As DataRow In TmpDTNCVinculadas.Rows + If Dr("CveConceptoContable").ToString().ToEntero() = 91 Then + CargaNCDT(Dr("CveVenta").ToString().ToEntero(), Dr("Importe").ToString().ToDecimal, Dr("FolioFiscal").ToString(), TC:=Dr("TipoCambio").ToString().ToDecimal) + End If + Next + + If GvNC.Rows.Count > 0 Then + ImgAntiPend.Visible = False End If + + End If + End If + End If + + 'CARGA REMISIONES + If ObjVentas.GetRemisionesRelacionadas(CveVenta, DbRowVenta("TipoDocto").ToString()) Then + GvRemisiones.Caption = "
Remisiones/Facturas
" + GvRemisiones.DataSource = ObjVentas.DtResultados.Copy() + GvCancelarRemisiones.DataSource = ObjVentas.DtResultados.Copy() + + GvRemisiones.DataBind() + GvCancelarRemisiones.DataBind() + + '[IPP] SI ES REMISION PARA CANCELARLA NO DEBE TENER NINGUNA FACTURADA RELACIONADA - 24Abril2018 + If DbRowVenta("TipoDocto").ToString().Contiene("Rem") And GvRemisiones.Rows.Count > 0 Then + LbCancelarDocumento.Visible = False + End If + + 'SI TIENE REMISIONES Y VA A CANCELAR ES NECESARIO EL MOVIMIENTO DE DEVOLUCION + If DbRowVenta("TipoDocto").ToString().Contiene("Ing", "Ant") AndAlso GvRemisiones.Rows.Count > 0 Then + ChkDevAlm.Checked = True + ChkDevAlm.Enabled = False + 'LiDevolucionAlmacen.Visible = False + End If + + End If + + 'SI ES COTIZACION PUEDE GENERAR UNA OC PARA MODIFICAR LOS IMPORTES + If DbRowVenta("TipoDocto").ToString() = "Cot" AndAlso UsuarioActual.Empresa.Funcionalidad(583) = "1" Then + Dim DtOCGeneradas As DataTable = Nothing + If ObjVentas.GetVentasCotizacionesOC(Me.CveVenta, -1, UsuarioActual.CveEmpresa) Then + DtOCGeneradas = ObjVentas.DtResultados.Copy() + End If + If DtOCGeneradas IsNot Nothing AndAlso DtOCGeneradas.Rows.Count > 0 Then + LtGenerarOC.Visible = False + Else + LtGenerarOC.Visible = True + End If + End If + + 'CARGA GV DE OC RELACIONADAS + If ObjVentas.GetOCRelacionadas(CveVenta) Then + If ObjVentas.DtResultados.Rows.Count > 0 Then + DivOCRelacionadas.Visible = True + GvOCRelacionadas.DataSource = ObjVentas.DtResultados + GvOCRelacionadas.DataBind() + End If + End If + + End If + End Using + End If + + If DbRowVenta IsNot Nothing Then + 'CARGAR PS + GvPS.DataSource = TmpDT + GvPS.DataBind() + + Dim CveCliente As Integer = DbRowVenta("CveCliente").ToString().ToEntero() + HdnCveVenta.Value = CveVenta.ToString() + + Me.EsGarantia = CBool(DbRowVenta("EsGarantia")) + + RFCReceptorVenta = DbRowVenta("RFCReceptor").ToString() + 'Adjuntar archivo + Adjunto = DbRowVenta("Adjunto").ToString() + If Adjunto <> "" Then + BtnArchivoAdjunto.Text = Adjunto + BtnArchivoAdjunto.Visible = True + BtnEliminarAdjunto.Visible = False + BtnAdjuntar.Visible = False + + tdAdjuntar.Style.Item("display") = "none" + tdAdjunto.Style.Item("display") = "block" + + Else + DivAdjuntar.Visible = False + End If + + ViewState("CveSubProyectoVenta") = DbRowVenta("CveSubProyecto").ToString().ToEntero() + + Me.CveEstatusFacturaPadre = DbRowVenta("CveEstatusFacturaPadre").ToString().ToEntero() + 'CargaEncabezado + If Not (CveRemision > 0 Or CveCotizacion > 0) Then + DdlTipoComprobante.SelectedValue = DbRowVenta("TipoDocto").ToString() + + If UsuarioActual.TienePermisoProceso(274) Then + TrAntEspecial.Visible = DdlTipoComprobante.SelectedValue = "Ant" + End If + + If TrAntEspecial.Visible Then + ChkAntEspecial.Enabled = False + ChkAntEspecial.Checked = If(DbRowVenta("AnticipoEspecial").ToString() = "True", True, False) + End If + CargaEstatusFactura(DdlTipoComprobante.SelectedValue) + CveEstatus = DbRowVenta("CveEstatusFactura").ToString().ToEntero() + LbEstatus.Text = DbRowVenta("EstatusFactura").ToString() + ViewState("SaldoVenta") = DbRowVenta("Saldo").ToString() + AplicaCancelarRemision = CBool(DbRowVenta("AplicaCancelarRemision").ToString()) + If AplicaCancelarRemision AndAlso CveEstatus.Contiene(2, 3) AndAlso DdlTipoComprobante.SelectedValue = "Ing" Then DivCanRem.Visible = True + VentaSaldoAlmacen = DbRowVenta("SaldoAlmacen").ToString().ToDecimal + + If CveEstatus = 5 Then LbCancelarDocumento.Enabled = False + 'If CveEstatus = 20 Then + ' LbCancelarDocumentoManual.Visible = True + 'End If + + + If (Not CveEstatus.Contiene(4, 5, 12, 13, 20, 23) OrElse (CveEstatus = 5 AndAlso DbRowVenta("CveEstatusRefacturacion").ToString().ToEntero() = 4)) AndAlso DdlTipoComprobante.SelectedValue.Contiene("Ing", "Egs", "Ant") AndAlso UsuarioActual.TienePermisoProceso(159) Then + Dim TienePermiso As String = GlobalDTSubProyectosUsuarios(UsuarioActual.CveUsuario, -1, UsuarioActual.CveEmpresa, -1, -1).FiltroPrimeroValor("CveSubProyecto", String.Format("CveSubProyecto = {0}", DbRowVenta("CveSubProyecto"))) + If TienePermiso <> "" Then + LkRefacturacion.Visible = True + If (CveEstatus = 5 AndAlso DbRowVenta("CveEstatusRefacturacion").ToString().ToEntero() = 4) Then + RefacturarCancelada = True + End If + End If + End If + + If DbRowVenta("CveVentaRelacionada").ToString().ToEntero() > 0 Then + TrRefacturadaa.Visible = True + HplRefacturadaEn.NavigateUrl = String.Format("/Ventas/Ventas.aspx?CveVenta={0}", DbRowVenta("CveVentaRelacionada")) + HplRefacturadaEn.Text = DbRowVenta("SerieFolioRelacionada").ToString() + LblAlertRefacInv.Visible = True + End If + + If DdlTipoComprobante.SelectedValue.Contiene("Egs", "Ing", "Ant", "Dev", "Rem", "DPe", "RNC", "Pd2", "Cot") AndAlso Not CveEstatus.Contiene(4, 5, 10, 12, 13, 20, 23) Then + If UsuarioActual.TienePermisoProceso(159) Then + Dim TienePermiso As String = GlobalDTSubProyectosUsuarios(UsuarioActual.CveUsuario, -1, UsuarioActual.CveEmpresa, -1, -1).FiltroPrimeroValor("CveSubProyecto", String.Format("CveSubProyecto = {0}", DbRowVenta("CveSubProyecto"))) + If TienePermiso <> "" Then + LbCancelarDocumento.Visible = True + 'If UsuarioActual.CveEmpresa = 119 And Not UsuarioActual.CveUsuario.Contiene(100, 1703) Then '[IPP] AD y Jesus de JAM + ' 'si es del mes anterior no permita cancelar + ' If Not DdlTipoComprobante.SelectedValue.Contiene("Rem") Then + ' If DbRowVenta("Fecha").ToString().ToDate <= Now.AddMonths(-1).LastDayOfMonth Then + ' LbCancelarDocumento.Visible = False + ' End If + ' End If + 'End If + End If + + End If + End If + + Dim TipoEstatus As Integer = GlobalDTEstatusFactura().FiltroPrimeroValor("TipoEstatus", $"CveEstatusFactura = {CveEstatus}").ToEntero() + + If UsuarioActual.Empresa.Funcionalidad(135).Contiene("1", "2") AndAlso DdlTipoComprobante.SelectedValue.Contiene("Cot") Then + If UsuarioActual.TienePermisoProceso(116) Then + LbCancelarDocumento.Visible = True + If TipoEstatus = 2 Then + LbCancelarDocumento.Visible = False + ElseIf TipoEstatus = 5 Then + LbCancelarDocumento.Visible = False + End If + End If + End If + + If UsuarioActual.Empresa.Funcionalidad(531) = "1" AndAlso CBool(DbRowVenta("ServicioDomicilio")) Then + TrServicioDomicilio.Visible = True + End If + + If UsuarioActual.TienePermisoProceso(318) Then + If DdlTipoComprobante.SelectedValue.Contiene("Egs", "Ing", "Ant", "Dev") AndAlso String.IsNullOrEmpty(DbRowVenta("FolioFiscal").ToString.Trim) Then HplFolioFiscalModal.Visible = True + End If + + Select Case DbRowVenta("TipoDocto").ToString() + Case "Ing" + Trsaldo.Visible = True + HplSaldoAuxiliar.NavigateUrl = String.Format("/Contabilidad/PopUpAuxiliar.aspx?Tipo=CxCClientes&CveCliente={0}&CveVenta={1}&TB_iframe=true&height=550&width=920", DbRowVenta("CveCliente"), DbRowVenta("CveVenta")) + HplPagado.NavigateUrl = String.Format("/Contabilidad/PopUpAuxiliar.aspx?Tipo=CxCClientes&CveCliente={0}&CveVenta={1}&TB_iframe=true&height=550&width=920", DbRowVenta("CveCliente"), DbRowVenta("CveVenta")) + If SaldoVenta > 0 And UsuarioActual.TienePermisoProceso(100) Then + HLPagar.Visible = True + HLPagar.NavigateUrl = $"/Bancos/PopIEVentas.aspx?CveVenta={CveVenta}&TB_iframe=true&height=500&width=675" + HlCuentaTerminal.Visible = True + End If + CargarSaldoAuxiliar(CveCliente) + TabAuxiliarConta.Visible = UsuarioActual.TienePermisoProceso(306) + Dim TienePermiso As String = GlobalDTSubProyectosUsuarios(UsuarioActual.CveUsuario, -1, UsuarioActual.CveEmpresa, -1, -1).FiltroPrimeroValor("CveSubProyecto", String.Format("CveSubProyecto = {0}", DbRowVenta("CveSubProyecto"))) + If TienePermiso <> "" Then ' si tiene acceso en el subproyecto + 'LkNotaCredito.Visible = UsuarioActual.TienePermisoProceso(175) + If UsuarioActual.TienePermisoProceso(264) Then + InicializaAplicaDevolucion(TmpDT) + End If + End If + + + HplDownXML.NavigateUrl = String.Format("/Compras/PopUpVerFactura.aspx?P={0}", Encripta(String.Format("OP=FactVta&CVEVENTA={0}&EXT={1}&SERIEFOLIO={2}&TIPODOCTO={3}", CveVenta, "XML", DbRowVenta("SerieFolio"), DbRowVenta("TipoDocto")))) + Case "Egs" + HplDownXML.NavigateUrl = String.Format("/Compras/PopUpVerFactura.aspx?P={0}", Encripta(String.Format("OP=FactVta&CVEVENTA={0}&EXT={1}&SERIEFOLIO={2}&TIPODOCTO={3}", CveVenta, "XML", DbRowVenta("SerieFolio"), DbRowVenta("TipoDocto")))) + HdnFolioFiscalNC.Value = DbRowVenta("FolioFiscalPadre").ToString() + Trsaldo.Visible = True + HplSaldoAuxiliar.NavigateUrl = String.Format("/Contabilidad/PopUpAuxiliar.aspx?Tipo=CxCClientes&CveCliente={0}&CveVenta={1}&TB_iframe=true&height=550&width=920", DbRowVenta("CveCliente"), DbRowVenta("CveVenta")) + HplPagado.NavigateUrl = String.Format("/Contabilidad/PopUpAuxiliar.aspx?Tipo=CxCClientes&CveCliente={0}&CveVenta={1}&TB_iframe=true&height=550&width=920", DbRowVenta("CveCliente"), DbRowVenta("CveVenta")) + Case "Rem" + 'IPP 15 Julio 2017 + Trsaldo.Visible = True + HplSaldoAuxiliar.NavigateUrl = String.Format("/Contabilidad/PopUpAuxiliar.aspx?Tipo=CxCClientes&CveCliente={0}&CveVenta={1}&TB_iframe=true&height=550&width=920", DbRowVenta("CveCliente"), DbRowVenta("CveVenta")) + HplPagado.NavigateUrl = String.Format("/Contabilidad/PopUpAuxiliar.aspx?Tipo=CxCClientes&CveCliente={0}&CveVenta={1}&TB_iframe=true&height=550&width=920", DbRowVenta("CveCliente"), DbRowVenta("CveVenta")) + If SaldoVenta > 0 And UsuarioActual.TienePermisoProceso(100) Then + HLPagar.Visible = True + HLPagar.NavigateUrl = $"/Bancos/PopIEVentas.aspx?CveVenta={CveVenta}&TB_iframe=true&height=500&width=675" + HlCuentaTerminal.Visible = True + End If + + If UsuarioActual.CveEmpresa = 80 Then + LtlImprimir.Text = String.Format("
  • Imprimir
  • ", Encripta(String.Format("OP=VTA&CVEVENTA={0}&PAG=0", CveVenta))) + End If + DiasCredito = DbRowVenta("DiasCredito").ToString().ToEntero() + EsDiasCreditoFijo = CBool(DbRowVenta("EsDiasCreditoFijo").ToString()) + Case "RNC" + Trsaldo.Visible = True + HplSaldoAuxiliar.NavigateUrl = String.Format("/Contabilidad/PopUpAuxiliar.aspx?Tipo=CxCClientes&CveCliente={0}&CveVenta={1}&TB_iframe=true&height=550&width=920", DbRowVenta("CveCliente"), DbRowVenta("CveVenta")) + HplPagado.NavigateUrl = String.Format("/Contabilidad/PopUpAuxiliar.aspx?Tipo=CxCClientes&CveCliente={0}&CveVenta={1}&TB_iframe=true&height=550&width=920", DbRowVenta("CveCliente"), DbRowVenta("CveVenta")) + + Case "OP" + TdOrdenPago.Visible = True + DdlOrdenPago.SelectedValue = DbRowVenta("Num3").ToString() + DdlOrdenPago.Enabled = False + Case "Cot" + TxtAtencionA.Text = DbRowVenta("AtencionA").ToString() + TxtFechaVencimientoCotizacion.Text = DbRowVenta("Vigencia").ToString() + PnlImprimir.Visible = True + HLOrdendeCompra.Visible = True + HLOrdendeCompra.NavigateUrl = String.Format("/OC/OC.aspx?Tipo=Req&CveCotizacion={0}", CveVenta) + + Dim ObjOS As New ClsOS() + If ObjOS.GetCotizacionOS(CveVenta) Then + If ObjOS.DtResultados.Rows.Count > 0 Then + Dim DbRowOS As DataRow = ObjOS.DtResultados.Rows(0) + ViewState("CveOS") = DbRowOS("CveOS").ToString().ToEntero() + CargaOS(CveOS) End If + Else + HLOrdenServicio.Visible = True + HLOrdenServicio.NavigateUrl = String.Format("/OS/OrdenesServicios.aspx?CveCotizacion={0}", CveVenta) + End If + ObjOS.Dispose() - HplDownXML.NavigateUrl = String.Format("/Compras/PopUpVerFactura.aspx?P={0}", Encripta(String.Format("OP=FactVta&CVEVENTA={0}&EXT={1}&SERIEFOLIO={2}&TIPODOCTO={3}", CveVenta, "XML", DbRowVenta("SerieFolio"), DbRowVenta("TipoDocto")))) - Case "Egs" - HplDownXML.NavigateUrl = String.Format("/Compras/PopUpVerFactura.aspx?P={0}", Encripta(String.Format("OP=FactVta&CVEVENTA={0}&EXT={1}&SERIEFOLIO={2}&TIPODOCTO={3}", CveVenta, "XML", DbRowVenta("SerieFolio"), DbRowVenta("TipoDocto")))) - HdnFolioFiscalNC.Value = DbRowVenta("FolioFiscalPadre").ToString() - Trsaldo.Visible = True - HplSaldoAuxiliar.NavigateUrl = String.Format("/Contabilidad/PopUpAuxiliar.aspx?Tipo=CxCClientes&CveCliente={0}&CveVenta={1}&TB_iframe=true&height=550&width=920", DbRowVenta("CveCliente"), DbRowVenta("CveVenta")) - HplPagado.NavigateUrl = String.Format("/Contabilidad/PopUpAuxiliar.aspx?Tipo=CxCClientes&CveCliente={0}&CveVenta={1}&TB_iframe=true&height=550&width=920", DbRowVenta("CveCliente"), DbRowVenta("CveVenta")) - Case "Rem" - 'IPP 15 Julio 2017 - Trsaldo.Visible = True - HplSaldoAuxiliar.NavigateUrl = String.Format("/Contabilidad/PopUpAuxiliar.aspx?Tipo=CxCClientes&CveCliente={0}&CveVenta={1}&TB_iframe=true&height=550&width=920", DbRowVenta("CveCliente"), DbRowVenta("CveVenta")) - HplPagado.NavigateUrl = String.Format("/Contabilidad/PopUpAuxiliar.aspx?Tipo=CxCClientes&CveCliente={0}&CveVenta={1}&TB_iframe=true&height=550&width=920", DbRowVenta("CveCliente"), DbRowVenta("CveVenta")) - If SaldoVenta > 0 And UsuarioActual.TienePermisoProceso(100) Then - HLPagar.Visible = True - HLPagar.NavigateUrl = $"/Bancos/PopIEVentas.aspx?CveVenta={CveVenta}&TB_iframe=true&height=500&width=675" - HlCuentaTerminal.Visible = True - End If - - If UsuarioActual.CveEmpresa = 80 Then - LtlImprimir.Text = String.Format("
  • Imprimir
  • ", Encripta(String.Format("OP=VTA&CVEVENTA={0}&PAG=0", CveVenta))) - End If - DiasCredito = DbRowVenta("DiasCredito").ToString().ToEntero() - EsDiasCreditoFijo = CBool(DbRowVenta("EsDiasCreditoFijo").ToString()) - Case "RNC" - Trsaldo.Visible = True - HplSaldoAuxiliar.NavigateUrl = String.Format("/Contabilidad/PopUpAuxiliar.aspx?Tipo=CxCClientes&CveCliente={0}&CveVenta={1}&TB_iframe=true&height=550&width=920", DbRowVenta("CveCliente"), DbRowVenta("CveVenta")) - HplPagado.NavigateUrl = String.Format("/Contabilidad/PopUpAuxiliar.aspx?Tipo=CxCClientes&CveCliente={0}&CveVenta={1}&TB_iframe=true&height=550&width=920", DbRowVenta("CveCliente"), DbRowVenta("CveVenta")) - - Case "OP" - TdOrdenPago.Visible = True - DdlOrdenPago.SelectedValue = DbRowVenta("Num3").ToString() - DdlOrdenPago.Enabled = False - Case "Cot" - TxtAtencionA.Text = DbRowVenta("AtencionA").ToString() - TxtFechaVencimientoCotizacion.Text = DbRowVenta("Vigencia").ToString() + If UsuarioActual.CveEmpresa.Contiene(4, 7, 11, 12, 145) Then PnlImprimir.Visible = True : LnkImprimir.OnClientClick = "javascript:ImprimirCotizacion();return false;" + 'Deshabilitar impresión cuando no esté supervisada + If DbRowVenta("TipoEstatus").ToString().ToEntero() = 2 Or UsuarioActual.Empresa.Funcionalidad(113) = "1" Then PnlImprimir.Visible = True - HLOrdendeCompra.Visible = True - HLOrdendeCompra.NavigateUrl = String.Format("/OC/OC.aspx?Tipo=Req&CveCotizacion={0}", CveVenta) + Else + HplDownPDF.Visible = False + PnlImprimir.Visible = False + End If - Dim ObjOS As New ClsOS() - If ObjOS.GetCotizacionOS(CveVenta) Then - If ObjOS.DtResultados.Rows.Count > 0 Then - Dim DbRowOS As DataRow = ObjOS.DtResultados.Rows(0) - ViewState("CveOS") = DbRowOS("CveOS").ToString().ToEntero() - CargaOS(CveOS) + + 'SI LA AUTORIZACION ES POR SUPERVISOR, BUSCA EL SUPERVISOR QUE TIENE EL VENDEDOR + If UsuarioActual.Empresa.Funcionalidad(135) = "1" Then + 'Reviso cuales son los supervisores + Dim Objeto As New ClsVtaVendedores + + If Objeto.GetVendedores(UsuarioActual.CveEmpresa) Then + Dim DTVendedores As New DataTable + If DbRowVenta("CveVendedor").ToString().ToEntero() > 0 AndAlso UsuarioActual.CveVendedor > 0 Then + DTVendedores = Objeto.DtResultados.FiltraParametros(String.Format("CveVendedor = {0}", DbRowVenta("CveVendedor").ToString())).FiltraParametros(String.Format("CveSupervisor = {0}", UsuarioActual.CveVendedor)) End If - Else - HLOrdenServicio.Visible = True - HLOrdenServicio.NavigateUrl = String.Format("/OS/OrdenesServicios.aspx?CveCotizacion={0}", CveVenta) - End If - ObjOS.Dispose() - - If UsuarioActual.CveEmpresa.Contiene(4, 7, 11, 12, 145) Then PnlImprimir.Visible = True : LnkImprimir.OnClientClick = "javascript:ImprimirCotizacion();return false;" - 'Deshabilitar impresión cuando no esté supervisada - If DbRowVenta("TipoEstatus").ToString().ToEntero() = 2 Or UsuarioActual.Empresa.Funcionalidad(113) = "1" Then - PnlImprimir.Visible = True - Else - HplDownPDF.Visible = False - PnlImprimir.Visible = False - End If - - - 'SI LA AUTORIZACION ES POR SUPERVISOR, BUSCA EL SUPERVISOR QUE TIENE EL VENDEDOR - If UsuarioActual.Empresa.Funcionalidad(135) = "1" Then - 'Reviso cuales son los supervisores - Dim Objeto As New ClsVtaVendedores - - If Objeto.GetVendedores(UsuarioActual.CveEmpresa) Then - Dim DTVendedores As New DataTable - If DbRowVenta("CveVendedor").ToString().ToEntero() > 0 AndAlso UsuarioActual.CveVendedor > 0 Then - DTVendedores = Objeto.DtResultados.FiltraParametros(String.Format("CveVendedor = {0}", DbRowVenta("CveVendedor").ToString())).FiltraParametros(String.Format("CveSupervisor = {0}", UsuarioActual.CveVendedor)) - End If - - 'Verifico si es su supervisor asignado - If DTVendedores.Rows.Count > 0 Then - LkCotizacionAutorizar.Visible = True - - If TipoEstatus = 2 Then - LkCotizacionAutorizar.Visible = False - ElseIf TipoEstatus = 5 Then - LkCotizacionAutorizar.Visible = False - End If - End If - DTVendedores.Dispose() - End If - Objeto.Dispose() - End If - - 'SI LA AUTORIZACION ES POR PERMISO, BUSCA QUE EL USUARIO TENGA EL PERMISO PARA AUTORIZAR - If UsuarioActual.Empresa.Funcionalidad(135) = "2" Then - 'Reviso cuales son los supervisores - If UsuarioActual.TienePermisoProceso(116) Then + 'Verifico si es su supervisor asignado + If DTVendedores.Rows.Count > 0 Then LkCotizacionAutorizar.Visible = True + If TipoEstatus = 2 Then LkCotizacionAutorizar.Visible = False ElseIf TipoEstatus = 5 Then LkCotizacionAutorizar.Visible = False End If End If + DTVendedores.Dispose() End If - - Case "Ant" - Trsaldo.Visible = True - HplSaldoAuxiliar.NavigateUrl = String.Format("/Contabilidad/PopUpAuxiliar.aspx?Tipo=CxCClientes&CveCliente={0}&CveVenta={1}&TB_iframe=true&height=550&width=920", DbRowVenta("CveCliente"), DbRowVenta("CveVenta")) - HplPagado.NavigateUrl = String.Format("/Contabilidad/PopUpAuxiliar.aspx?Tipo=CxCClientes&CveCliente={0}&CveVenta={1}&TB_iframe=true&height=550&width=920", DbRowVenta("CveCliente"), DbRowVenta("CveVenta")) - 'LkNotaCredito.Visible = True - HplDownXML.NavigateUrl = String.Format("/Compras/PopUpVerFactura.aspx?P={0}", Encripta(String.Format("OP=FactVta&CVEVENTA={0}&EXT={1}&SERIEFOLIO={2}&TIPODOCTO={3}", CveVenta, "XML", DbRowVenta("SerieFolio"), DbRowVenta("TipoDocto")))) - 'visualizo el saldo de anticipos, para cuando se aplique una Nota de crédito, decida si afecta anticipos o a DSV - LblNCSaldoAnticipo.Visible = True - ChkAplicaNCAnticipo.Visible = True - ChkAplicaNCAnticipo.Checked = True - If SaldoVenta > 0 And UsuarioActual.TienePermisoProceso(100) Then - HLPagar.Visible = True - HLPagar.NavigateUrl = $"/Bancos/PopIEVentas.aspx?CveVenta={CveVenta}&TB_iframe=true&height=500&width=675" - HlCuentaTerminal.Visible = True - End If - Me.SaldoAnticipo = DbRowVenta("SaldoAnticipo").ToString().ToDecimal - If SaldoAnticipo > 0 Then - InicializaDTAnticiposAmortizacion() - ChkAplicaNCAnticipo.Enabled = False - Else - ChkAplicaNCAnticipo.Enabled = False - ChkAplicaNCAnticipo.Checked = False - End If - 'If DbRowVenta("SaldoAnticipo").ToString().ToDouble <= 0 Then ChkAplicaNCAnticipo.Checked = False : ChkAplicaNCAnticipo.Enabled = False - LblNCSaldoAnticipo.Text = String.Format("Saldo Anticipo: $ {0}", DbRowVenta("SaldoAnticipo").ToString().ToDouble.FormatoNumero) - Case "Dev" - DdlTipoComprobante.Items.Insert(0, New ListItem("Devolucion", "Dev")) - HplDownXML.NavigateUrl = String.Format("/Compras/PopUpVerFactura.aspx?P={0}", Encripta(String.Format("OP=FactVta&CVEVENTA={0}&EXT={1}&SERIEFOLIO={2}&TIPODOCTO={3}", CveVenta, "XML", DbRowVenta("SerieFolio"), DbRowVenta("TipoDocto")))) - HdnFolioFiscalNC.Value = DbRowVenta("FolioFiscalPadre").ToString() - 'ViewState("CveDevolucion") = DbRowVenta("CveVentaPadre").ToString().ToEntero() - Trsaldo.Visible = True - HplSaldoAuxiliar.NavigateUrl = String.Format("/Contabilidad/PopUpAuxiliar.aspx?Tipo=CxCClientes&CveCliente={0}&CveVenta={1}&TB_iframe=true&height=550&width=920", DbRowVenta("CveCliente"), DbRowVenta("CveVenta")) - HplPagado.NavigateUrl = String.Format("/Contabilidad/PopUpAuxiliar.aspx?Tipo=CxCClientes&CveCliente={0}&CveVenta={1}&TB_iframe=true&height=550&width=920", DbRowVenta("CveCliente"), DbRowVenta("CveVenta")) - Case "Ped" - DdlTipoComprobante.Items.Insert(0, New ListItem("Pedido", "Ped")) - Case "DPe" - DdlTipoComprobante.Items.Insert(5, New ListItem("Devolución de perdido", "DPe")) - Case "PeC" - DdlTipoComprobante.Items.Insert(5, New ListItem("Pedido de Consignación", "PeC")) - Case "PA" - If UsuarioActual.TienePermisoProceso(199) Then - BtnGenerarRemision.Visible = If(CveEstatus = 16, True, False) - Else - BtnGenerarRemision.Visible = False - End If - CvePedidoA = CveVenta - DiasCredito = DbRowVenta("DiasCredito").ToString().ToEntero() - EsDiasCreditoFijo = CBool(DbRowVenta("EsDiasCreditoFijo").ToString()) - Case "Pd2" - CvePedido2 = CveVenta - BtnGeneraAutorizacion.Visible = If(CveEstatus <> 21, True, False) - If UsuarioActual.TienePermisoProceso(199) Then - BtnGenerarRemision.Visible = If(CveEstatus <> 21, True, False) - Else - BtnGenerarRemision.Visible = False - End If - End Select - - DdlTipoComprobante.SelectedValue = DbRowVenta("TipoDocto").ToString() - - End If - - DdlTipoRelacionARelacionar.SelectedValueExist(DbRowVenta("CveTipoRelacion").ToString()) - - 'contado 0, credito 1, terminal 2 - If DbRowVenta("CondicionesPago").ToString().ToEntero() = 1 Then - RBLPago.SelectedValue = "1" - RBLPago_SelectedIndexChanged(Nothing, Nothing) - UPCondicionesPago.Update() - ElseIf DbRowVenta("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 - - - 'ESCONDE ACCIONES - LnkRemisiones.Visible = False - LnkPedido2SinFacturar.Visible = False - LnkCotizaciones.Visible = False - LnkOCs.Visible = False - UpnTools.Update() - - DivEstatusFac.Visible = True - 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 - HplPagado.Visible = True - Dim EsCancelado = GlobalDTEstatusFactura().FiltroPrimeroValor("TipoEstatus", $"CveEstatusFactura = {CveEstatus}").ToEntero() = 5 - If EsCancelado Then - HplPagado.Text = "CANCELADO" - End If - If ViewState("CveCotizacion") IsNot Nothing AndAlso ViewState("CveCotizacion").ToString().ToEntero() > 0 AndAlso DdlTipoComprobante.SelectedValue = "Ing" Then - ImgAntiPend.Visible = True - Else - ImgAntiPend.Visible = False - End If - - 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() - - CveVentaRelacion = DbRowVenta("CveVentaRelacion").ToString().ToEntero() - ImporteRelacion = DbRowVenta("ImporteRelacion").ToString().ToDouble - - DdlMoneda.SelectedValue = DbRowVenta("CveMoneda").ToString() - CambiaMoneda() - - If DbRowVenta("TipoDocto").ToString() = "Pd2" Then - 'CANTIDAD FACTURADA - If TmpDT.SUM("CantidadFacturadaPed2") > 0 Then - GvPS.Columns(7).Visible = True - ThCantidadFacturada.Visible = True - ThCantidadFacturada2.Visible = True - Else - GvPS.Columns(7).Visible = False - ThCantidadFacturada.Visible = False - ThCantidadFacturada2.Visible = False - End If - - ''ACTIVA EDITAR - ''SOLO LA PUEDE EDITAR USUATIOACTUAL-VENDEDOR | NO DEBE ESTAR FACTURADA - 'If (UsuarioActual.CveUsuario = DbRowVenta("CveUsuario").ToString().ToEntero() Or UsuarioActual.CveVendedor = DdlVendedor.SelectedValue.ToEntero()) And TmpDT.SUM("CantidadFacturadaCot") = 0 Then 'And TmpDT.SUM("CantidadFacturadaCot") < TmpDT.SUM("Cantidad") - ' BtnPermisoEditarCotizacion.Visible = True - 'End If - - 'ACTIVA BOTONERA | DEBE TENER CONCEPTOS PENDIENTES DE FACTURAR - 'If TmpDT.SUM("CantidadFacturadaPed2") < TmpDT.SUM("Cantidad") Then - ' BtnGenerarRemision.Visible = If(CveEstatus = 10, False, True) - ' BtnsFacturar.Visible = True - 'End If - ElseIf DbRowVenta("TipoDocto").ToString() = "Cot" AndAlso CveCotizacion > 0 Then - CveEstatusCotizacion = DbRowVenta("CveEstatusFactura").ToString().ToEntero() - End If - - - If CveEmpresaCRM > 0 And Not CveCliente > 0 Then - CargaEmpresaCRM(CveEmpresaCRM) - Else - CveEmpresaCRM = IIf(CveEmpresaCRM > 0, CveEmpresaCRM, 0).ToString().ToEntero() - 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()) - - Me.CveMetodoPago33Venta = DbRowVenta("CveMetodoPago33").ToString().ToEntero() - Me.CveFormaPago33Venta = DbRowVenta("CveFormaPago33").ToString().ToEntero() - Me.CveVendedorVenta = DbRowVenta("CveVendedor").ToString().ToEntero() - - 'SI YA TIENE UN VALOR ASIGNADO SELECCIONA EL GUARDADO - 'If UsuarioActual.Empresa.Funcionalidad(531) = "1" AndAlso Me.CveVenta > 0 AndAlso Me.CveVendedorVenta > 0 Then - ' Dim Vendedor = GlobalDTVendedores(UsuarioActual.CveEmpresa, VendedorTipo:=1).FiltroPrimeroValor("Vendedor", String.Format("CveVendedor = {0}", Me.CveVendedorVenta)) - ' 'SI NO ENCUENTRA BUSCA EN LOS VENDEDORES DEL PV - ' If String.IsNullOrEmpty(Vendedor) Then - ' Vendedor = GlobalDTVendedores(UsuarioActual.CveEmpresa, VendedorTipo:=4).FiltroPrimeroValor("Vendedor", String.Format("CveVendedor = {0}", Me.CveVendedorVenta)) - ' End If - ' DdlVendedor.SelectedValueExistInsert(Me.CveVendedorVenta, Vendedor) - 'End If - - 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 UsuarioActual.CveEmpresa = 126 Then CargaOrdenProduccion(2, CveVenta) - - If DbRowVenta("CveTipoRelacion").ToString().ToEntero() > 0 Then - TrTipoRelacion.Visible = True - DdlTiposRelacion.SelectedValueExist(DbRowVenta("CveTipoRelacion").ToString().ToEntero()) - - 'RELACIONAR ANTICIPOS APLICADOS - If DbRowVenta("CveTipoRelacion").ToString().ToEntero() = 7 AndAlso DtAntRelacionados IsNot Nothing AndAlso DtAntRelacionados.Rows.Count > 0 Then - DdlTipoRelacionAnticipo.SelectedValueExist(7) - ListaAnticiposAplicados = New List(Of MAnticipoRelacionado)() - For Each RowAnt As DataRow In DtAntRelacionados.Rows - ListaAnticiposAplicados.Add(New MAnticipoRelacionado() With {.CveVenta = RowAnt("CveVentaRelacionada").ToString().ToEntero(), .FolioFiscal = RowAnt("FolioFiscal").ToString()}) - Next - Else - HdnFolioFiscalNC.Value = DbRowVenta("FolioFiscalPadre").ToString() - End If - End If - - If DbRowVenta("Saldo").ToString().ToDouble < 0.01 Then - If ViewState("CveCotizacion") IsNot Nothing AndAlso ViewState("CveCotizacion").ToString().ToEntero() > 0 AndAlso DdlTipoComprobante.SelectedValue = "Ing" Then - ImgAntiPend.Visible = True - Else - ImgAntiPend.Visible = False - End If - ElseIf Opcion <> "Op" Then - ImgAntiPend.Visible = True - End If - If UsuarioActual.CveRol.Contiene(1, 1155) Then LiLnkGuias.Visible = True - - LiComplementoPago.Visible = True - - - ViewState("FolioFiscal") = DbRowVenta("FolioFiscal").ToString() - - SerieVenta = DbRowVenta("Serie").ToString() - LblSerie.Text = SerieVenta - ViewState("Serie") = DbRowVenta("Serie").ToString() - ViewState("Folio") = DbRowVenta("Folio").ToString().ToEntero() - TxtFolio.Text = DbRowVenta("Folio").ToString() - 'TxtDocto.Text = DbRowVenta("Ref").ToString() - 'TxtNumCtaPago.Text = DbRowVenta("NumeroCuenta").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) - TxtCorreoNotificaciones.Text = DbRowVenta("CorreoNotificacion").ToString() - - If TxtRetIVA.Text.ToDecimal() > 0 Then - TrRetIVA.Style.Add("display", "") - UsuarioActual.Empresa.MostrarRetIVA = True - If DdlTipoRetencion.SelectedValue.ToEntero() > 0 Then - DdlTipoRetencion.Visible = True - End If - 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() - LblFechaRegistro.Text = DbRowVenta("FechaIng").ToString().ToDate.ToShortDateString - LblSeTimbro.Text = DbRowVenta("SeTimbro").ToString() - LblMail.Text = DbRowVenta("EnvioMail").ToString() - TxtFechaPago.Text = DbRowVenta("FechaVencimiento").ToString() - TxtFechaVencimientoCotizacion.Text = Vigencia - TxtDet_OrdenCompra.Text = DbRowVenta("Det_OrdenCompra").ToString() - TxtDet_FechaOrdenCompra.Text = DbRowVenta("Det_FechaOrdenCompra").ToString() - HdnIVAOriginal.Value = TxtIVA.Text - TxtPedidoContrato.Text = DbRowVenta("PedidoContrato").ToString() - TxtPedidoContrato.Enabled = False - TxtKilometraje.Text = DbRowVenta("Kilometraje").ToString().PadLeft(6, "0"c) - - HdnAmortizacion.Value = LblAmort.Text.ToDouble.ToString() - HdnSubTotalDescuestos.Value = (TxtSubTotal.Text.Replace(",", "").ToDouble - LblDescuentos.Text.Replace(",", "").ToDouble - LblAmortizacion.Text.Trim.Replace(",", "").ToDouble - TxtRetISR.Text.Replace(",", "").ToDouble).FormatoNumero(2) - 'DdlAmortizacionConceptos.SelectedValue = DbRowVenta("AnticipoPosicion").ToString() - 'ChkAnticipoEnSubTotal.Checked = DbRowVenta("AnticipoEnSubTotal").ToString() = "True" - DdlTipoAmortizacionAnticipo.SelectedValueExist(DbRowVenta("CveTipoAmortizacionAnticipo")) - DdlTiposRelacion.SelectedValueExist(DbRowVenta("CveTipoRelacion")) - - 'Si es AMORTIZACIÓN ANTICIPO SOBRE FACTURA EN CERO no debe timbrar - If DbRowVenta("CveTipoAmortizacionAnticipo").ToString().ToEntero() = 3 Then - BtnEmitir.Visible = False - End If - - 'HdnAmortizacion.Value = LblAmort.Text.ToDouble.ToString() - 'HdnSubTotalDescuestos.Value = (TxtSubTotal.Text.Replace(",", "").ToDouble - LblDescuentos.Text.Replace(",", "").ToDouble - LblAmortizacion.Text.Trim.Replace(",", "").ToDouble - TxtRetISR.Text.Replace(",", "").ToDouble).FormatoNumero(2) - 'DdlAmortizacionConceptos.SelectedValue = DbRowVenta("AnticipoPosicion").ToString() - 'ChkAnticipoEnSubTotal.Checked = DbRowVenta("AnticipoEnSubTotal").ToString() = "True" - - - If DbRowVenta("CveTipoRelacion").ToString().ToEntero() > 0 Then - TrTipoRelacion2.Visible = True - LblTipoRelacion.Text = DbRowVenta("TipoRelacion").ToString() - HdnFolioFiscalNC.Value = DbRowVenta("FolioFiscalPadre").ToString() - - - - End If - - - TxtOrdenCompra.Text = DbRowVenta("OrdenCompra").ToString() - TxtOrdenCompra.Enabled = False - - TxtObsAlmacen.Text = DbRowVenta("ObservacionesAlmacen").ToString() - CvePAC = DbRowVenta("CvePAC").ToString().ToEntero() - - If DbRowVenta("Saldo").ToString().ToDecimal > 0 AndAlso UsuarioActual.TienePermisoProceso(204) AndAlso Not UsuarioActual.CveEmpresa.Contiene(119) Then - TxtFechaSaldarVenta.Text = TxtFecha.Text - CEFechaSaldarVenta.StartDate = TxtFecha.Text.ToDate - HLSaldarVenta.Visible = True - End If - - - If (UsuarioActual.TienePermisoProceso(166) Or UsuarioActual.CveRol = 1) AndAlso (LblFolioFiscal.Text = "" Or LblFolioFiscal.Text = "test") Then - LkEliminarFactura.Visible = True - End If - If (UsuarioActual.CveRol = 1) AndAlso (LblFolioFiscal.Text <> "") Then - LnkUUIDRelacionados.Visible = True - 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_SelectedIndexChanged(DdlDireccionEnvio, EventArgs.Empty) - DdlDireccionEnvio.Enabled = False - ChkDireccionEnvio.Enabled = False - DdlDireccionEnvio.Visible = True - trDireccionEnvio.Visible = True - If UsuarioActual.TienePermisoProceso(333) Then LnkEditarDir.Visible = True - End If - - 'ESTATUS FACTURA - If Not (CveRemision > 0 Or CveCotizacion > 0) Then - CveEstatus = DbRowVenta("CveEstatusFactura").ToString().ToEntero() - - End If - - TxtTipoCambio.Text = DbRowVenta("TipoCambio").ToString() - If DbRowVenta("UltimasFluctuaciones").ToString() <> "" Then - LblTCValuacion.Text = String.Format("Ult. Val:{0}", DbRowVenta("UltimasFluctuaciones").ToString()) - LblTCValuacion.Visible = True - End If - - 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 - - TxtFechaEjecucion.Text = DbRowVenta("FechaEjecucion").ToString().ToDateTime.ToString("dd/MM/yyyy") - 'DdlSucursalEjecucion.SelectedValueExist(DbRowVenta("CveSucursalEjecucion").ToString()) - 'DdlSucursalCobranza.SelectedValueExist(DbRowVenta("CveSucursalCobranza").ToString()) - DdlSucursalCliente.SelectedValueExist(DbRowVenta("CveClienteSucursal").ToString()) - 'DdlSucursal.SelectedValueExist(DbRowVenta("CveSucursal").ToString()) - 'DdlSubProyectoDatos.SelectedValueExist(DbRowVenta("CveSubProyecto").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()) - DdlSubProyecto.SelectedValueExist(DbRowVenta("CveSubProyecto").ToString()) - - CargarAlmacenes() - - If DdlSubProyectoCobranza.Items.Count = 0 Then - DdlSubProyectoCobranza.Items.Insert(0, New ListItem("Seleccione", "-1")) - End If - DdlSubProyectoCobranza.SelectedValueExistInsert(DbRowVenta("CveSubProyectoCobranza").ToString(), GlobalDTSubProyectos(-1, DbRowVenta("CveSubProyectoCobranza").ToString().ToEntero()).FiltroPrimeroValor("SubProyecto").ToString()) - - If DdlSubProyectoEjecucion.Items.Count = 0 Then - DdlSubProyectoEjecucion.Items.Insert(0, New ListItem("Seleccione", "-1")) - End If - DdlSubProyectoEjecucion.SelectedValueExistInsert(DbRowVenta("CveSubProyectoEjecucion").ToString(), GlobalDTSubProyectos(-1, DbRowVenta("CveSubProyectoEjecucion").ToString().ToEntero()).FiltroPrimeroValor("SubProyecto").ToString()) - - CargaClienteSucursal(DbRowVenta("CveClienteSucursal").ToString().ToEntero()) - - If DbRowVenta("CveContrato").ToString().ToEntero() > 0 Then - CveContrato = DbRowVenta("CveContrato").ToString().ToEntero() - NumeroContrato = DbRowVenta("NumeroContrato").ToString() - DescripcionContrato = DbRowVenta("DescripcionContrato").ToString() - DdlContrato.Visible = False - HLContrato.Text = $"{DbRowVenta("NumeroContrato")} - {DbRowVenta("DescripcionContrato")}" - HLContrato.NavigateUrl = $"/Contratos/Contrato.aspx?CveContrato={CveContrato}" - 'trPresupuesto.Visible = True - 'HplPresupuesto.NavigateUrl = String.Format(" / Presupuestos / Presupuesto.aspx?CvePresupuesto={0}", DbRowVenta("CveContrato").ToString()) - Else - NumeroContrato = "" - DescripcionContrato = "" - End If - - 'DdlEstatus.Items.Remove(DdlEstatus.Items.FindByText("Cotización")) - - If DbRowVenta("SeTimbro").ToString() <> "No" Then - HplDownXML.Visible = True - 'If HLImprimir.Visible = False Then - HplDownPDF.Visible = True - 'End If - ElseIf UsuarioActual.Empresa.TipoFacturacion = "CBB" OrElse DdlTipoComprobante.SelectedValue = "Cot" Then - 'If drv("TipoEstatus").ToString().ToEntero() = 2 AndAlso drv("TipoDocto").ToString() = "Cot" Then - ' ImgDownPDF.Visible = True - 'Else - HplDownPDF.Visible = False - 'End If - ElseIf UsuarioActual.Empresa.TipoFacturacion = "CFDi" AndAlso DbRowVenta("SeTimbro").ToString() = "No" AndAlso DbRowVenta("CveEstatusFactura").ToString() = "2" AndAlso DbRowVenta("TipoDocto").ToString().Contiene("Ing", "Egs", "Dev", "Ant") Then - TrEmitir.Visible = True - If TxtFecha.Text.ToDate < Now.AddDays(-3) Then - TxtFecha.Enabled = True - End If - End If - - 'NO DEBE IMPRIMIR PDF DE COTIZACION - If UsuarioActual.Empresa.Funcionalidad(531) = "1" AndAlso DbRowVenta("TipoDocto").ToString() = "Cot" Then - HplDownPDF.Visible = False - End If - - If DbRowVenta("SeTimbro").ToString() = "Si" Then - TrEmitir.Visible = False - End If - - 'CargaAcuseCancelacion - If DbRowVenta("CveEstatusFactura").ToString().Contiene("5", "20") Then - ImgDownCancelacion.Visible = True - ImgDownCancelacion.NavigateUrl = String.Format("/Compras/PopUpVerFactura.aspx?P={0}", Encripta(String.Format("OP=CAN&CVEVTA={0}", CveVenta))) - 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 - If UsuarioActual.TienePermisoProceso(107) Then BtnDescontabilizar.Visible = True - - Else - 'cuando no este contabilizada y usa AC, habilita el boton para generar la poliza - If UsuarioActual.Empresa.TipoContabilidad = 2 AndAlso UsuarioActual.Empresa.UsaAC AndAlso UsuarioActual.CveRol = 1 Then - BtnGenerarPoliza.Visible = True - End If - If UsuarioActual.Empresa.Funcionalidad(200) = "1" Then - BtnContabilizar.Visible = True - End If - 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 - - - If UsuarioActual.Empresa.UsaOS AndAlso DbRowVenta("CveOS").ToString().ToEntero() = 0 Then - BtnGenerarOS.Visible = True - BtnGenerarOS.OnClientClick = String.Format("javascriptwindow.location.href = '/OS/OrdenesServicios.aspx?CveVenta={0}'; return false;", CveVenta) - ' BtnGenerarOS.OnClientClick = String.Format("/OS/OrdenesServicios.aspx?CveVenta={0}", CveVenta) - End If - - - '[IPP] COMENTADO 12/MARZO/2018 -SABRA QUE SE QUERIA ESCONDER - 'If DbRowVenta("TipoDocto").ToString() = "Rem" Then - ' GvPS.Columns(11).Visible = False - ' GvPS.Columns(12).Visible = False - 'End If - - - 'Ocultamos los botones Clonar y Ordenar - GvPS.Columns(19).Visible = False - GvPS.Columns(20).Visible = False - - 'CargaFirmas - If ObjVentas.GetVentasFirmas(CveVenta) Then - If ObjVentas.DtResultados.Rows.Count > 0 Then - DTmpF = ObjVentas.DtResultados - GvFirmas.DataSource = ObjVentas.DtResultados - GvFirmas.DataBind() - Else - GvFirmas.DataSource = Nothing - End If - 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 = If(DbRowVenta("CveVendedor").ToString = "", "0", DbRowVenta("CveVendedor").ToString) 'si viene dbnull, que ponga cero. - DdlTipoComprobante.Enabled = False - 'TxtDocto.Enabled = False - - '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 - DdlProyecto.Enabled = False - DdlSubProyecto.Enabled = False - TxtPrecio.Enabled = False - ImgDescPU.Attributes.Clear() - ImgDescTotal.Attributes.Clear() - ImgDescConcepto.Attributes.Clear() - LbAgregar.Enabled = False - LnkAgregarPyME.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 - TxtObsAlmacen.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 - DdlTipoRetencion.Enabled = False - TxtFechaEjecucion.ReadOnly = True - ImgCalendarFechaEje.Enabled = False - 'DdlSucursalEjecucion.Enabled = False - 'DdlSucursalCobranza.Enabled = False - DdlVendedor.Enabled = False - DdlSucursalCliente.Enabled = False - TxtTiempoEntrega.Enabled = False - TxtAlfa1.ReadOnly = True - TxtAlfa2.ReadOnly = True - TxtAlfa3.ReadOnly = True - TxtNum1.ReadOnly = True - TxtNum2.ReadOnly = True - TxtNum3.ReadOnly = True - TxtFech1.ReadOnly = True : ImgFech1.Enabled = False - TxtFech2.ReadOnly = True : ImgFech2.Enabled = False - TxtFech3.ReadOnly = True : ImgFech3.Enabled = False - ChkConvertirDoctoPesos.Enabled = False - ChkConvertirDolares.Enabled = False - - TxtTipoCambio.Enabled = UsuarioActual.CveEmpresa.Contiene(13, 83) - TxtTipoCambioDlls.Enabled = UsuarioActual.CveEmpresa.Contiene(13, 83) - TxtTipoCambio.ReadOnly = Not UsuarioActual.CveEmpresa.Contiene(13, 83) - TxtTipoCambioDlls.ReadOnly = Not UsuarioActual.CveEmpresa.Contiene(13, 83) - - '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", "Cot") Then - TxtFechaPago.ReadOnly = Not UsuarioActual.TienePermisoProceso(260) - LnkUpdateFechaVencimiento.Visible = UsuarioActual.TienePermisoProceso(260) - Else - TxtFechaPago.ReadOnly = False - End If - - imgCalendario.Enabled = False - DdlFuenteRecaudacion.Enabled = False - - TrVistaPrevia.Visible = False - BtnEmitirImprimir.Visible = False - 'CargaLeyendasFiscales - ViewState("VentaFolio") = If(LblSerie.Text.Trim.Length = 0, TxtFolio.Text.Trim, LblSerie.Text.Trim & "-" & TxtFolio.Text.Trim) - - CalculaTotalesVenta(False) - - 'JJMQ 20160506: Se agrego para la validacion de pago de contado. - 'CVImporteContado.ValueToCompare = TxtTotal.Text.Replace(",", "") - - 'CARGA ANTICIPOS - If Not (CveRemision > 0 Or CveCotizacion > 0) Then - If DdlTipoComprobante.SelectedValue.Contiene("Ing", "Ant", "Rem") Then - 'carga as notas de credito vinculadas - If ObjVentas.GetVentasAntNC(CveVenta, -1) Then - GvAntNC.DataSource = ObjVentas.DtResultados - TmpDTDocumentosRelacionados = ObjVentas.DtResultados - GvAntNC.Caption = "
    (Anticipos/NC/IxC) Vinculados
    " - GvAntNC.DataBind() + Objeto.Dispose() End If - End If - If DdlTipoComprobante.SelectedValue.Contiene("Egs", "Dev", "Ant") Then - Dim AplicaAmortizacion As Boolean = False - If DdlTipoComprobante.SelectedValue.Contiene("Ant") Then AplicaAmortizacion = True - - If ObjVentas.GetVentasAntNC(-1, CveVenta, AplicaAmortizacion) Then - GvNC.DataSource = ObjVentas.DtResultados - TmpDTNCVinculadas = ObjVentas.DtResultados - GvNC.Caption = "
    Ventas Aplicadas
    " - GvNC.DataBind() - InicializaDTVentasNC() - For Each Dr As DataRow In ObjVentas.DtResultados.Rows - If Dr("CveConceptoContable").ToString().ToEntero() = 91 Then - CargaNCDT(Dr("CveVenta").ToString().ToEntero(), Dr("Importe").ToString().ToDecimal, Dr("FolioFiscal").ToString(), TC:=Dr("TipoCambio").ToString().ToDecimal) + 'SI LA AUTORIZACION ES POR PERMISO, BUSCA QUE EL USUARIO TENGA EL PERMISO PARA AUTORIZAR + If UsuarioActual.Empresa.Funcionalidad(135) = "2" Then + 'Reviso cuales son los supervisores + If UsuarioActual.TienePermisoProceso(116) Then + LkCotizacionAutorizar.Visible = True + If TipoEstatus = 2 Then + LkCotizacionAutorizar.Visible = False + ElseIf TipoEstatus = 5 Then + LkCotizacionAutorizar.Visible = False End If - Next + End If End If - End If - End If - If GvNC.Rows.Count > 0 Then + Case "Ant" + Trsaldo.Visible = True + HplSaldoAuxiliar.NavigateUrl = String.Format("/Contabilidad/PopUpAuxiliar.aspx?Tipo=CxCClientes&CveCliente={0}&CveVenta={1}&TB_iframe=true&height=550&width=920", DbRowVenta("CveCliente"), DbRowVenta("CveVenta")) + HplPagado.NavigateUrl = String.Format("/Contabilidad/PopUpAuxiliar.aspx?Tipo=CxCClientes&CveCliente={0}&CveVenta={1}&TB_iframe=true&height=550&width=920", DbRowVenta("CveCliente"), DbRowVenta("CveVenta")) + 'LkNotaCredito.Visible = True + HplDownXML.NavigateUrl = String.Format("/Compras/PopUpVerFactura.aspx?P={0}", Encripta(String.Format("OP=FactVta&CVEVENTA={0}&EXT={1}&SERIEFOLIO={2}&TIPODOCTO={3}", CveVenta, "XML", DbRowVenta("SerieFolio"), DbRowVenta("TipoDocto")))) + 'visualizo el saldo de anticipos, para cuando se aplique una Nota de crédito, decida si afecta anticipos o a DSV + LblNCSaldoAnticipo.Visible = True + ChkAplicaNCAnticipo.Visible = True + ChkAplicaNCAnticipo.Checked = True + If SaldoVenta > 0 And UsuarioActual.TienePermisoProceso(100) Then + HLPagar.Visible = True + HLPagar.NavigateUrl = $"/Bancos/PopIEVentas.aspx?CveVenta={CveVenta}&TB_iframe=true&height=500&width=675" + HlCuentaTerminal.Visible = True + End If + Me.SaldoAnticipo = DbRowVenta("SaldoAnticipo").ToString().ToDecimal + If SaldoAnticipo > 0 Then + InicializaDTAnticiposAmortizacion() + ChkAplicaNCAnticipo.Enabled = False + Else + ChkAplicaNCAnticipo.Enabled = False + ChkAplicaNCAnticipo.Checked = False + End If + 'If DbRowVenta("SaldoAnticipo").ToString().ToDouble <= 0 Then ChkAplicaNCAnticipo.Checked = False : ChkAplicaNCAnticipo.Enabled = False + LblNCSaldoAnticipo.Text = String.Format("Saldo Anticipo: $ {0}", DbRowVenta("SaldoAnticipo").ToString().ToDouble.FormatoNumero) + Case "Dev" + DdlTipoComprobante.Items.Insert(0, New ListItem("Devolucion", "Dev")) + HplDownXML.NavigateUrl = String.Format("/Compras/PopUpVerFactura.aspx?P={0}", Encripta(String.Format("OP=FactVta&CVEVENTA={0}&EXT={1}&SERIEFOLIO={2}&TIPODOCTO={3}", CveVenta, "XML", DbRowVenta("SerieFolio"), DbRowVenta("TipoDocto")))) + HdnFolioFiscalNC.Value = DbRowVenta("FolioFiscalPadre").ToString() + 'ViewState("CveDevolucion") = DbRowVenta("CveVentaPadre").ToString().ToEntero() + Trsaldo.Visible = True + HplSaldoAuxiliar.NavigateUrl = String.Format("/Contabilidad/PopUpAuxiliar.aspx?Tipo=CxCClientes&CveCliente={0}&CveVenta={1}&TB_iframe=true&height=550&width=920", DbRowVenta("CveCliente"), DbRowVenta("CveVenta")) + HplPagado.NavigateUrl = String.Format("/Contabilidad/PopUpAuxiliar.aspx?Tipo=CxCClientes&CveCliente={0}&CveVenta={1}&TB_iframe=true&height=550&width=920", DbRowVenta("CveCliente"), DbRowVenta("CveVenta")) + Case "Ped" + DdlTipoComprobante.Items.Insert(0, New ListItem("Pedido", "Ped")) + Case "DPe" + DdlTipoComprobante.Items.Insert(5, New ListItem("Devolución de perdido", "DPe")) + Case "PeC" + DdlTipoComprobante.Items.Insert(5, New ListItem("Pedido de Consignación", "PeC")) + Case "PA" + If UsuarioActual.TienePermisoProceso(199) Then + BtnGenerarRemision.Visible = If(CveEstatus = 16, True, False) + Else + BtnGenerarRemision.Visible = False + End If + CvePedidoA = CveVenta + DiasCredito = DbRowVenta("DiasCredito").ToString().ToEntero() + EsDiasCreditoFijo = CBool(DbRowVenta("EsDiasCreditoFijo").ToString()) + Case "Pd2" + CvePedido2 = CveVenta + BtnGeneraAutorizacion.Visible = If(CveEstatus <> 21, True, False) + If UsuarioActual.TienePermisoProceso(199) Then + BtnGenerarRemision.Visible = If(CveEstatus <> 21, True, False) + Else + BtnGenerarRemision.Visible = False + End If + End Select + + DdlTipoComprobante.SelectedValue = DbRowVenta("TipoDocto").ToString() + + End If + + DdlTipoRelacionARelacionar.SelectedValueExist(DbRowVenta("CveTipoRelacion").ToString()) + + 'contado 0, credito 1, terminal 2 + If DbRowVenta("CondicionesPago").ToString().ToEntero() = 1 Then + RBLPago.SelectedValue = "1" + RBLPago_SelectedIndexChanged(Nothing, Nothing) + UPCondicionesPago.Update() + ElseIf DbRowVenta("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 + + + 'ESCONDE ACCIONES + LnkRemisiones.Visible = False + LnkPedido2SinFacturar.Visible = False + LnkCotizaciones.Visible = False + LnkOCs.Visible = False + UpnTools.Update() + + DivEstatusFac.Visible = True + 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 + HplPagado.Visible = True + Dim EsCancelado = GlobalDTEstatusFactura().FiltroPrimeroValor("TipoEstatus", $"CveEstatusFactura = {CveEstatus}").ToEntero() = 5 + If EsCancelado Then + HplPagado.Text = "CANCELADO" + End If + If ViewState("CveCotizacion") IsNot Nothing AndAlso ViewState("CveCotizacion").ToString().ToEntero() > 0 AndAlso DdlTipoComprobante.SelectedValue = "Ing" Then + ImgAntiPend.Visible = True + Else ImgAntiPend.Visible = False End If - 'CARGA REMISIONES - If ObjVentas.GetRemisionesRelacionadas(CveVenta, DdlTipoComprobante.SelectedValue) Then - GvRemisiones.Caption = "
    Remisiones/Facturas
    " - GvRemisiones.DataSource = ObjVentas.DtResultados - GvCancelarRemisiones.DataSource = ObjVentas.DtResultados + 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() - GvRemisiones.DataBind() - GvCancelarRemisiones.DataBind() + CveVentaRelacion = DbRowVenta("CveVentaRelacion").ToString().ToEntero() + ImporteRelacion = DbRowVenta("ImporteRelacion").ToString().ToDouble - '[IPP] SI ES REMISION PARA CANCELARLA NO DEBE TENER NINGUNA FACTURADA RELACIONADA - 24Abril2018 - If DdlTipoComprobante.SelectedValue.Contiene("Rem") And GvRemisiones.Rows.Count > 0 Then - LbCancelarDocumento.Visible = False - End If - - 'SI TIENE REMISIONES Y VA A CANCELAR ES NECESARIO EL MOVIMIENTO DE DEVOLUCION - If DdlTipoComprobante.SelectedValue.Contiene("Ing", "Ant") AndAlso GvRemisiones.Rows.Count > 0 Then - ChkDevAlm.Checked = True - ChkDevAlm.Enabled = False - 'LiDevolucionAlmacen.Visible = False - End If + DdlMoneda.SelectedValue = DbRowVenta("CveMoneda").ToString() + CambiaMoneda() + If DbRowVenta("TipoDocto").ToString() = "Pd2" Then + 'CANTIDAD FACTURADA + If TmpDT.SUM("CantidadFacturadaPed2") > 0 Then + GvPS.Columns(7).Visible = True + ThCantidadFacturada.Visible = True + ThCantidadFacturada2.Visible = True + Else + GvPS.Columns(7).Visible = False + ThCantidadFacturada.Visible = False + ThCantidadFacturada2.Visible = False End If - tdVigencia.Visible = DdlTipoComprobante.SelectedValue.Contiene("Cot") - tdFechaVigencia.Visible = DdlTipoComprobante.SelectedValue.Contiene("Cot") + ''ACTIVA EDITAR + ''SOLO LA PUEDE EDITAR USUATIOACTUAL-VENDEDOR | NO DEBE ESTAR FACTURADA + 'If (UsuarioActual.CveUsuario = DbRowVenta("CveUsuario").ToString().ToEntero() Or UsuarioActual.CveVendedor = DdlVendedor.SelectedValue.ToEntero()) And TmpDT.SUM("CantidadFacturadaCot") = 0 Then 'And TmpDT.SUM("CantidadFacturadaCot") < TmpDT.SUM("Cantidad") + ' BtnPermisoEditarCotizacion.Visible = True + 'End If - If DbRowVenta("TipoDocto").ToString() = "Rem" Then - 'CANTIDAD FACTURADA - If TmpDT.SUM("CantidadFacturadaRem") > 0 Then - GvPS.Columns(6).Visible = True - ThCantidadFacturadaRem.Visible = True - ThCantidadFacturadaRem2.Visible = True - Else - GvPS.Columns(6).Visible = False - ThCantidadFacturadaRem.Visible = False - ThCantidadFacturadaRem2.Visible = False - End If - - 'ACTIVA EDITAR - 'SOLO LA PUEDE EDITAR CON PROCESO | DEBE TENER CONCEPTOS PENDIENTES DE FACTURAR - If UsuarioActual.TienePermisoProceso(202) And TmpDT.SUM("CantidadFacturadaRem") < TmpDT.SUM("Cantidad") Then - BtnPermisoEditarRemision.Visible = True - End If - - 'ACTIVA BOTONERA | DEBE TENER CONCEPTOS PENDIENTES DE FACTURAR - If TmpDT.SUM("CantidadFacturadaRem") < TmpDT.SUM("Cantidad") Then - BtnsFacturar.Visible = True - - LBFacturarAnticipo.Visible = UsuarioActual.TienePermisoProceso(274) - - 'ACTIVA CONVERSION DE MONEDA - If DdlMoneda.SelectedValue.ToEntero() = 1 Then - TrConversionDolares.Visible = True - ChkConvertirDolares.Enabled = Not UsuarioActual.TienePermisoProceso(324) - TxtTipoCambioDlls.Enabled = True - Else - TrConversionTipoCambio.Visible = True - ChkConvertirDoctoPesos.Enabled = Not UsuarioActual.TienePermisoProceso(324) - TxtTipoCambio.Enabled = True - End If - End If - - 'Si es Empresa de Acumuladores - If CveVenta > 0 AndAlso UsuarioActual.Empresa.Funcionalidad(531) = "1" AndAlso DbRowVenta("TipoDocto").ToString() = "Rem" AndAlso (GlobalDTEstatusFactura().FiltroPrimeroValor("TipoEstatus", $"CveEstatusFactura = {Me.CveEstatus}").ToEntero() <> 5) Then - - BtnsFacturar.Visible = False - - Dim DtUsadosPendientes As DataTable = Nothing - Dim DtGarantiasPendientes As DataTable = Nothing - - Dim ObjUsados As New ClsVentas - - If ObjUsados.GetVentasUsados(CveVenta, -1, DbRowVenta("Fecha").ToString().ToDateTime, UsuarioActual.CveEmpresa) Then - DtUsadosPendientes = ObjUsados.DtResultados.Copy() - End If - - If ObjUsados.GetVentasGarantiaPendiente(CveVenta, Now, UsuarioActual.CveEmpresa) Then - DtGarantiasPendientes = ObjUsados.DtResultados.Copy() - End If - - 'If ObjUsados.GetVentasGarantiaPendiente(CveVenta, -1, Now, UsuarioActual.CveEmpresa) Then - ' DtGarantiasPendientes = ObjUsados.DtResultados.Copy() - 'End If - ObjUsados.Dispose() - - 'Si ya se surtió y recibió - If DbRowVenta("SaldoAlmacen").ToString().ToDecimal > 0 OrElse TmpDT.MAX("CveTipoPS") = "1" Then - BtnsFacturar.Visible = True - End If - - 'VERIFICA SI YA SE FACTURO COMPLETAMENTE - If TmpDT.SUM("CantidadFacturadaRem") = TmpDT.SUM("Cantidad") Then - BtnsFacturar.Visible = False - End If - - 'VERIFICA SI TIENE USADOS O GARANTIAS PENDIENTES - If BtnsFacturar.Visible Then - If (Not EsGarantia AndAlso (DtUsadosPendientes IsNot Nothing AndAlso DtUsadosPendientes.Rows.Count > 0)) Then - BtnsFacturar.Visible = False - Alert("Tiene usados pendiente de recibir", TipoMensaje.MsgAdvertencia) - End If - - If (EsGarantia AndAlso (DtGarantiasPendientes IsNot Nothing AndAlso DtGarantiasPendientes.Rows.Count > 0)) Then - Alert("Tiene garantías pendientes de recibir", TipoMensaje.MsgAdvertencia) - BtnsFacturar.Visible = False - End If - End If + 'ACTIVA BOTONERA | DEBE TENER CONCEPTOS PENDIENTES DE FACTURAR + 'If TmpDT.SUM("CantidadFacturadaPed2") < TmpDT.SUM("Cantidad") Then + ' BtnGenerarRemision.Visible = If(CveEstatus = 10, False, True) + ' BtnsFacturar.Visible = True + 'End If + ElseIf DbRowVenta("TipoDocto").ToString() = "Cot" AndAlso CveCotizacion > 0 Then + CveEstatusCotizacion = DbRowVenta("CveEstatusFactura").ToString().ToEntero() + End If - LBFacturarAnticipo.Visible = UsuarioActual.TienePermisoProceso(274) - End If + If CveEmpresaCRM > 0 And Not CveCliente > 0 Then + CargaEmpresaCRM(CveEmpresaCRM) + Else + CveEmpresaCRM = IIf(CveEmpresaCRM > 0, CveEmpresaCRM, 0).ToString().ToEntero() + 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()) + + Me.CveMetodoPago33Venta = DbRowVenta("CveMetodoPago33").ToString().ToEntero() + Me.CveFormaPago33Venta = DbRowVenta("CveFormaPago33").ToString().ToEntero() + Me.CveVendedorVenta = DbRowVenta("CveVendedor").ToString().ToEntero() + + 'SI YA TIENE UN VALOR ASIGNADO SELECCIONA EL GUARDADO + 'If UsuarioActual.Empresa.Funcionalidad(531) = "1" AndAlso Me.CveVenta > 0 AndAlso Me.CveVendedorVenta > 0 Then + ' Dim Vendedor = GlobalDTVendedores(UsuarioActual.CveEmpresa, VendedorTipo:=1).FiltroPrimeroValor("Vendedor", String.Format("CveVendedor = {0}", Me.CveVendedorVenta)) + ' 'SI NO ENCUENTRA BUSCA EN LOS VENDEDORES DEL PV + ' If String.IsNullOrEmpty(Vendedor) Then + ' Vendedor = GlobalDTVendedores(UsuarioActual.CveEmpresa, VendedorTipo:=4).FiltroPrimeroValor("Vendedor", String.Format("CveVendedor = {0}", Me.CveVendedorVenta)) + ' End If + ' DdlVendedor.SelectedValueExistInsert(Me.CveVendedorVenta, Vendedor) + 'End If + + 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 UsuarioActual.CveEmpresa = 126 Then CargaOrdenProduccion(2, CveVenta) + + If DbRowVenta("CveTipoRelacion").ToString().ToEntero() > 0 Then + TrTipoRelacion.Visible = True + DdlTiposRelacion.SelectedValueExist(DbRowVenta("CveTipoRelacion").ToString().ToEntero()) + + 'RELACIONAR ANTICIPOS APLICADOS + If DbRowVenta("CveTipoRelacion").ToString().ToEntero() = 7 AndAlso DtAntRelacionados IsNot Nothing AndAlso DtAntRelacionados.Rows.Count > 0 Then + DdlTipoRelacionAnticipo.SelectedValueExist(7) + ListaAnticiposAplicados = New List(Of MAnticipoRelacionado)() + For Each RowAnt As DataRow In DtAntRelacionados.Rows + ListaAnticiposAplicados.Add(New MAnticipoRelacionado() With {.CveVenta = RowAnt("CveVentaRelacionada").ToString().ToEntero(), .FolioFiscal = RowAnt("FolioFiscal").ToString()}) + Next + Else + HdnFolioFiscalNC.Value = DbRowVenta("FolioFiscalPadre").ToString() + End If + End If + + If DbRowVenta("Saldo").ToString().ToDouble < 0.01 Then + If ViewState("CveCotizacion") IsNot Nothing AndAlso ViewState("CveCotizacion").ToString().ToEntero() > 0 AndAlso DdlTipoComprobante.SelectedValue = "Ing" Then + ImgAntiPend.Visible = True + Else + ImgAntiPend.Visible = False + End If + ElseIf Opcion <> "Op" Then + ImgAntiPend.Visible = True + End If + If UsuarioActual.CveRol.Contiene(1, 1155) Then LiLnkGuias.Visible = True + + LiComplementoPago.Visible = True + + + ViewState("FolioFiscal") = DbRowVenta("FolioFiscal").ToString() + + SerieVenta = DbRowVenta("Serie").ToString() + LblSerie.Text = SerieVenta + ViewState("Serie") = DbRowVenta("Serie").ToString() + ViewState("Folio") = DbRowVenta("Folio").ToString().ToEntero() + TxtFolio.Text = DbRowVenta("Folio").ToString() + 'TxtDocto.Text = DbRowVenta("Ref").ToString() + 'TxtNumCtaPago.Text = DbRowVenta("NumeroCuenta").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) + TxtCorreoNotificaciones.Text = DbRowVenta("CorreoNotificacion").ToString() + + If TxtRetIVA.Text.ToDecimal() > 0 Then + TrRetIVA.Style.Add("display", "") + UsuarioActual.Empresa.MostrarRetIVA = True + If DdlTipoRetencion.SelectedValue.ToEntero() > 0 Then + DdlTipoRetencion.Visible = True + End If + If TmpDT IsNot Nothing Then + Dim PorcentajeRetIVA = (TmpDT.MAX("PorcentajeRetIVA").ToDecimal() * 100) + LblRetIVA.Text = PorcentajeRetIVA.FormatoNumero(2) End If - If DbRowVenta("TipoDocto").ToString().Contiene("Cot", "Pd2") Then - 'CANTIDAD FACTURADA - If TmpDT.SUM("CantidadFacturadaCot") > 0 Then - GvPS.Columns(7).Visible = True - ThCantidadFacturada.Visible = True - ThCantidadFacturada2.Visible = True - Else - GvPS.Columns(7).Visible = False - ThCantidadFacturada.Visible = False - ThCantidadFacturada2.Visible = False - 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() + LblFechaRegistro.Text = DbRowVenta("FechaIng").ToString().ToDate.ToShortDateString + LblSeTimbro.Text = DbRowVenta("SeTimbro").ToString() + LblMail.Text = DbRowVenta("EnvioMail").ToString() + TxtFechaPago.Text = DbRowVenta("FechaVencimiento").ToString() + TxtFechaVencimientoCotizacion.Text = Vigencia + TxtDet_OrdenCompra.Text = DbRowVenta("Det_OrdenCompra").ToString() + TxtDet_FechaOrdenCompra.Text = DbRowVenta("Det_FechaOrdenCompra").ToString() + HdnIVAOriginal.Value = TxtIVA.Text + TxtPedidoContrato.Text = DbRowVenta("PedidoContrato").ToString() + TxtPedidoContrato.Enabled = False + TxtKilometraje.Text = DbRowVenta("Kilometraje").ToString().PadLeft(6, "0"c) - 'ACTIVA EDITAR - 'SOLO LA PUEDE EDITAR USUATIOACTUAL-VENDEDOR | NO DEBE ESTAR FACTURADA - If (UsuarioActual.CveUsuario = DbRowVenta("CveUsuario").ToString().ToEntero() Or UsuarioActual.CveVendedor = DdlVendedor.SelectedValue.ToEntero()) And TmpDT.SUM("CantidadFacturadaCot") = 0 Then 'And TmpDT.SUM("CantidadFacturadaCot") < TmpDT.SUM("Cantidad") - BtnPermisoEditarCotizacion.Visible = True - End If + HdnAmortizacion.Value = LblAmort.Text.ToDouble.ToString() + HdnSubTotalDescuestos.Value = (TxtSubTotal.Text.Replace(",", "").ToDouble - LblDescuentos.Text.Replace(",", "").ToDouble - LblAmortizacion.Text.Trim.Replace(",", "").ToDouble - TxtRetISR.Text.Replace(",", "").ToDouble).FormatoNumero(2) + 'DdlAmortizacionConceptos.SelectedValue = DbRowVenta("AnticipoPosicion").ToString() + 'ChkAnticipoEnSubTotal.Checked = DbRowVenta("AnticipoEnSubTotal").ToString() = "True" + DdlTipoAmortizacionAnticipo.SelectedValueExist(DbRowVenta("CveTipoAmortizacionAnticipo")) + DdlTiposRelacion.SelectedValueExist(DbRowVenta("CveTipoRelacion")) - 'SOLO LA PUEDE EDITAR USUATIOACTUAL-VENDEDOR | NO DEBE ESTAR FACTURADA - If UsuarioActual.TienePermisoProceso(281) And TmpDT.SUM("CantidadFacturadaCot") = 0 Then 'And TmpDT.SUM("CantidadFacturadaCot") < TmpDT.SUM("Cantidad") - BtnPermisoEditarCotizacion.Visible = True - End If + 'Si es AMORTIZACIÓN ANTICIPO SOBRE FACTURA EN CERO no debe timbrar + If DbRowVenta("CveTipoAmortizacionAnticipo").ToString().ToEntero() = 3 Then + BtnEmitir.Visible = False + End If - 'ACTIVA BOTONERA | DEBE TENER CONCEPTOS PENDIENTES DE FACTURAR - VerificarBtnFacturarCotizacion(DbRowVenta("CveVendedor").ToString().ToEntero()) + 'HdnAmortizacion.Value = LblAmort.Text.ToDouble.ToString() + 'HdnSubTotalDescuestos.Value = (TxtSubTotal.Text.Replace(",", "").ToDouble - LblDescuentos.Text.Replace(",", "").ToDouble - LblAmortizacion.Text.Trim.Replace(",", "").ToDouble - TxtRetISR.Text.Replace(",", "").ToDouble).FormatoNumero(2) + 'DdlAmortizacionConceptos.SelectedValue = DbRowVenta("AnticipoPosicion").ToString() + 'ChkAnticipoEnSubTotal.Checked = DbRowVenta("AnticipoEnSubTotal").ToString() = "True" + + + If DbRowVenta("CveTipoRelacion").ToString().ToEntero() > 0 Then + TrTipoRelacion2.Visible = True + LblTipoRelacion.Text = DbRowVenta("TipoRelacion").ToString() + HdnFolioFiscalNC.Value = DbRowVenta("FolioFiscalPadre").ToString() + End If + + + TxtOrdenCompra.Text = DbRowVenta("OrdenCompra").ToString() + TxtOrdenCompra.Enabled = False + + TxtObsAlmacen.Text = DbRowVenta("ObservacionesAlmacen").ToString() + CvePAC = DbRowVenta("CvePAC").ToString().ToEntero() + + If DbRowVenta("Saldo").ToString().ToDecimal > 0 AndAlso UsuarioActual.TienePermisoProceso(204) AndAlso Not UsuarioActual.CveEmpresa.Contiene(119) Then + TxtFechaSaldarVenta.Text = TxtFecha.Text + CEFechaSaldarVenta.StartDate = TxtFecha.Text.ToDate + HLSaldarVenta.Visible = True + End If + + + If (UsuarioActual.TienePermisoProceso(166) Or UsuarioActual.CveRol = 1) AndAlso (LblFolioFiscal.Text = "" Or LblFolioFiscal.Text = "test") Then + LkEliminarFactura.Visible = True + End If + If (UsuarioActual.CveRol = 1) AndAlso (LblFolioFiscal.Text <> "") Then + LnkUUIDRelacionados.Visible = True + 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_SelectedIndexChanged(DdlDireccionEnvio, EventArgs.Empty) + DdlDireccionEnvio.Enabled = False + ChkDireccionEnvio.Enabled = False + DdlDireccionEnvio.Visible = True + trDireccionEnvio.Visible = True + If UsuarioActual.TienePermisoProceso(333) Then LnkEditarDir.Visible = True + End If + + 'ESTATUS FACTURA + If Not (CveRemision > 0 Or CveCotizacion > 0) Then + CveEstatus = DbRowVenta("CveEstatusFactura").ToString().ToEntero() + + End If + + TxtTipoCambio.Text = DbRowVenta("TipoCambio").ToString() + If DbRowVenta("UltimasFluctuaciones").ToString() <> "" Then + LblTCValuacion.Text = String.Format("Ult. Val:{0}", DbRowVenta("UltimasFluctuaciones").ToString()) + LblTCValuacion.Visible = True + End If + + 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) - If UsuarioActual.Empresa.Funcionalidad(280) = "1" Then - RblPaqueteria.SelectedValue = If(DbRowVenta("FormaPaqueteria").ToString = "", "1", DbRowVenta("FormaPaqueteria").ToString) - RblPaqueteria.Enabled = False + End If + + TxtFechaEjecucion.Text = DbRowVenta("FechaEjecucion").ToString().ToDateTime.ToString("dd/MM/yyyy") + 'DdlSucursalEjecucion.SelectedValueExist(DbRowVenta("CveSucursalEjecucion").ToString()) + 'DdlSucursalCobranza.SelectedValueExist(DbRowVenta("CveSucursalCobranza").ToString()) + DdlSucursalCliente.SelectedValueExist(DbRowVenta("CveClienteSucursal").ToString()) + 'DdlSucursal.SelectedValueExist(DbRowVenta("CveSucursal").ToString()) + 'DdlSubProyectoDatos.SelectedValueExist(DbRowVenta("CveSubProyecto").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()) + DdlSubProyecto.SelectedValueExist(DbRowVenta("CveSubProyecto").ToString()) + + CargarAlmacenes() + + If DdlSubProyectoCobranza.Items.Count = 0 Then + DdlSubProyectoCobranza.Items.Insert(0, New ListItem("Seleccione", "-1")) + End If + DdlSubProyectoCobranza.SelectedValueExistInsert(DbRowVenta("CveSubProyectoCobranza").ToString(), GlobalDTSubProyectos(-1, DbRowVenta("CveSubProyectoCobranza").ToString().ToEntero()).FiltroPrimeroValor("SubProyecto").ToString()) + + If DdlSubProyectoEjecucion.Items.Count = 0 Then + DdlSubProyectoEjecucion.Items.Insert(0, New ListItem("Seleccione", "-1")) + End If + DdlSubProyectoEjecucion.SelectedValueExistInsert(DbRowVenta("CveSubProyectoEjecucion").ToString(), GlobalDTSubProyectos(-1, DbRowVenta("CveSubProyectoEjecucion").ToString().ToEntero()).FiltroPrimeroValor("SubProyecto").ToString()) + + CargaClienteSucursal(DbRowVenta("CveClienteSucursal").ToString().ToEntero()) + + If DbRowVenta("CveContrato").ToString().ToEntero() > 0 Then + CveContrato = DbRowVenta("CveContrato").ToString().ToEntero() + NumeroContrato = DbRowVenta("NumeroContrato").ToString() + DescripcionContrato = DbRowVenta("DescripcionContrato").ToString() + DdlContrato.Visible = False + HLContrato.Text = $"{DbRowVenta("NumeroContrato")} - {DbRowVenta("DescripcionContrato")}" + HLContrato.NavigateUrl = $"/Contratos/Contrato.aspx?CveContrato={CveContrato}" + 'trPresupuesto.Visible = True + 'HplPresupuesto.NavigateUrl = String.Format(" / Presupuestos / Presupuesto.aspx?CvePresupuesto={0}", DbRowVenta("CveContrato").ToString()) + Else + NumeroContrato = "" + DescripcionContrato = "" + End If + + 'DdlEstatus.Items.Remove(DdlEstatus.Items.FindByText("Cotización")) + + If DbRowVenta("SeTimbro").ToString() <> "No" Then + HplDownXML.Visible = True + 'If HLImprimir.Visible = False Then + HplDownPDF.Visible = True + 'End If + ElseIf UsuarioActual.Empresa.TipoFacturacion = "CBB" OrElse DdlTipoComprobante.SelectedValue = "Cot" Then + 'If drv("TipoEstatus").ToString().ToEntero() = 2 AndAlso drv("TipoDocto").ToString() = "Cot" Then + ' ImgDownPDF.Visible = True + 'Else + HplDownPDF.Visible = False + 'End If + ElseIf UsuarioActual.Empresa.TipoFacturacion = "CFDi" AndAlso DbRowVenta("SeTimbro").ToString() = "No" AndAlso DbRowVenta("CveEstatusFactura").ToString() = "2" AndAlso DbRowVenta("TipoDocto").ToString().Contiene("Ing", "Egs", "Dev", "Ant") Then + TrEmitir.Visible = True + If TxtFecha.Text.ToDate < Now.AddDays(-3) Then + TxtFecha.Enabled = True End If + End If - If UsuarioActual.CveEmpresa = 48 Then - TxtFecha.AutoPostBack = True - End If + 'NO DEBE IMPRIMIR PDF DE COTIZACION + If UsuarioActual.Empresa.Funcionalidad(531) = "1" AndAlso DbRowVenta("TipoDocto").ToString() = "Cot" Then + HplDownPDF.Visible = False + End If - CargaCodigoUnico() + If DbRowVenta("SeTimbro").ToString() = "Si" Then + TrEmitir.Visible = False + End If - 'SI ES COTIZACION PUEDE GENERAR UNA OC PARA MODIFICAR LOS IMPORTES - If DdlTipoComprobante.SelectedValue = "Cot" AndAlso UsuarioActual.Empresa.Funcionalidad(583) = "1" Then - Dim DtOCGeneradas As DataTable = Nothing - If ObjVentas.GetVentasCotizacionesOC(Me.CveVenta, -1, UsuarioActual.CveEmpresa) Then - DtOCGeneradas = ObjVentas.DtResultados.Copy() - End If - If DtOCGeneradas IsNot Nothing AndAlso DtOCGeneradas.Rows.Count > 0 Then - LtGenerarOC.Visible = False - Else - LtGenerarOC.Visible = True - End If - End If + 'CargaAcuseCancelacion + If DbRowVenta("CveEstatusFactura").ToString().Contiene("5", "20") Then + ImgDownCancelacion.Visible = True + ImgDownCancelacion.NavigateUrl = String.Format("/Compras/PopUpVerFactura.aspx?P={0}", Encripta(String.Format("OP=CAN&CVEVTA={0}", CveVenta))) + End If + IdPoliza = DbRowVenta("IdPoliza").ToString().ToEntero() - DdlTipoRetencion.SelectedValueExist(DbRowVenta("CveTipoRetencion").ToString()) - - Me.FacturarSucursal = CBool(DbRowVenta("FacturarSucursal").ToString()) - - If Me.FacturarSucursal Then - HabilitarFacturacionSucursal() - End If - - CargaPS(-1, DdlPS) - - 'CARGA GV DE OC RELACIONADAS - If CveVenta > 0 AndAlso ObjVentas.GetOCRelacionadas(CveVenta) Then - If ObjVentas.DtResultados.Rows.Count > 0 Then - DivOCRelacionadas.Visible = True - GvOCRelacionadas.DataSource = ObjVentas.DtResultados - - End If - End If - GvOCRelacionadas.DataBind() - - - 'Verifico si tiene la funcionalidad (135) - If DdlTipoComprobante.SelectedValue = "Cot" AndAlso UsuarioActual.Empresa.Funcionalidad(135).Contiene("1", "2") Then - - Select Case UsuarioActual.Empresa.Funcionalidad(135) - Case "1" ' POR SUPERVISOR - Dim ObjVendedores As New ClsVtaVendedores - - If ObjVendedores.GetVendedores(UsuarioActual.CveEmpresa) Then - Dim DTVendedores As New DataTable - If DbRowVenta("CveVendedor").ToString().ToEntero() > 0 AndAlso UsuarioActual.CveVendedor > 0 Then - DTVendedores = ObjVendedores.DtResultados.FiltraParametros(String.Format("CveVendedor = {0}", DbRowVenta("CveVendedor").ToString())).FiltraParametros(String.Format("CveSupervisor = {0}", UsuarioActual.CveVendedor)) - End If - - 'Verifico si es su supervisor asignado - If DTVendedores.Rows.Count > 0 Then - If GlobalDTEstatusFactura().FiltroPrimeroValor("TipoEstatus", $"CveEstatusFactura = {Me.CveEstatus}").ToEntero() = 2 Then - BtnsFacturar.Visible = True - BtnGenerarRemision.Visible = True - Else - BtnsFacturar.Visible = False - BtnGenerarRemision.Visible = False - End If - End If - - DTVendedores.Dispose() - End If - ObjVendedores.Dispose() - - Case "2" ' POR PERMISO - If GlobalDTEstatusFactura().FiltroPrimeroValor("TipoEstatus", $"CveEstatusFactura = {Me.CveEstatus}").ToEntero() = 2 Then - BtnsFacturar.Visible = UsuarioActual.TienePermisoProceso(60) - If UsuarioActual.TienePermisoProceso(199) Then - BtnGenerarRemision.Visible = If(CveEstatus = 10, False, True) - Else - BtnGenerarRemision.Visible = False - End If - Else - BtnsFacturar.Visible = False - BtnGenerarRemision.Visible = False - End If - - End Select - - - End If - - If DdlTipoComprobante.SelectedValue = "Cot" Then - If GlobalDTEstatusFactura().FiltroPrimeroValor("TipoEstatus", $"CveEstatusFactura = {Me.CveEstatus}").ToEntero() = 5 Then - BtnsFacturar.Visible = False - BtnGenerarRemision.Visible = False - End If - End If - - If DdlTipoComprobante.SelectedValue = "Rem" Then - If GlobalDTEstatusFactura().FiltroPrimeroValor("TipoEstatus", $"CveEstatusFactura = {Me.CveEstatus}").ToEntero() = 5 Then - BtnsFacturar.Visible = False - BtnEmitirImprimir.Visible = False - BtnPermisoEditarRemision.Visible = False - End If - End If - - UpPS.Update() - UpContado.Update() - UpEstatus.Update() - Retorno = True + 'Carga si es Contabilizada + If IdPoliza > 0 Then + HLContabilizada.Text = "Si" + HLContabilizada.NavigateUrl = $"/Contabilidad/RegPoliza.aspx?IdPoliza={DbRowVenta("IdPoliza")}" + trContabilizada.Visible = True + If UsuarioActual.TienePermisoProceso(107) Then BtnDescontabilizar.Visible = True Else - ViewState("CveVenta") = -1 - Alert("El documento solicitado no existe, favor de revisar su búsqueda.", TipoMensaje.MsgAdvertencia) + 'cuando no este contabilizada y usa AC, habilita el boton para generar la poliza + If UsuarioActual.Empresa.TipoContabilidad = 2 AndAlso UsuarioActual.Empresa.UsaAC AndAlso UsuarioActual.CveRol = 1 Then + BtnGenerarPoliza.Visible = True + End If + If UsuarioActual.Empresa.Funcionalidad(200) = "1" Then + BtnContabilizar.Visible = True + End If 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 + + + If UsuarioActual.Empresa.UsaOS AndAlso DbRowVenta("CveOS").ToString().ToEntero() = 0 Then + BtnGenerarOS.Visible = True + BtnGenerarOS.OnClientClick = String.Format("javascriptwindow.location.href = '/OS/OrdenesServicios.aspx?CveVenta={0}'; return false;", CveVenta) + ' BtnGenerarOS.OnClientClick = String.Format("/OS/OrdenesServicios.aspx?CveVenta={0}", CveVenta) + End If + + + '[IPP] COMENTADO 12/MARZO/2018 -SABRA QUE SE QUERIA ESCONDER + 'If DbRowVenta("TipoDocto").ToString() = "Rem" Then + ' GvPS.Columns(11).Visible = False + ' GvPS.Columns(12).Visible = False + 'End If + + + 'Ocultamos los botones Clonar y Ordenar + GvPS.Columns(19).Visible = False + GvPS.Columns(20).Visible = False + + GvFirmas.DataSource = DTmpF + GvFirmas.DataBind() + + If TmpDTImpuestos IsNot Nothing AndAlso TmpDTImpuestos.Rows.Count > 0 Then + TrOtros.Visible = True + GvImpuestosLocales2.DataSource = TmpDTImpuestos + GvImpuestosLocales2.DataBind() + + GvImpuestosLocales2.Enabled = False + GvImpuestosLocales2.Visible = True + End If + + DdlVendedor.SelectedValue = If(DbRowVenta("CveVendedor").ToString = "", "0", DbRowVenta("CveVendedor").ToString) 'si viene dbnull, que ponga cero. + DdlTipoComprobante.Enabled = False + 'TxtDocto.Enabled = False + + '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 + DdlProyecto.Enabled = False + DdlSubProyecto.Enabled = False + TxtPrecio.Enabled = False + ImgDescPU.Attributes.Clear() + ImgDescTotal.Attributes.Clear() + ImgDescConcepto.Attributes.Clear() + LbAgregar.Enabled = False + LnkAgregarPyME.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 + TxtObsAlmacen.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 + DdlTipoRetencion.Enabled = False + TxtFechaEjecucion.ReadOnly = True + ImgCalendarFechaEje.Enabled = False + 'DdlSucursalEjecucion.Enabled = False + 'DdlSucursalCobranza.Enabled = False + DdlVendedor.Enabled = False + DdlSucursalCliente.Enabled = False + TxtTiempoEntrega.Enabled = False + TxtAlfa1.ReadOnly = True + TxtAlfa2.ReadOnly = True + TxtAlfa3.ReadOnly = True + TxtNum1.ReadOnly = True + TxtNum2.ReadOnly = True + TxtNum3.ReadOnly = True + TxtFech1.ReadOnly = True : ImgFech1.Enabled = False + TxtFech2.ReadOnly = True : ImgFech2.Enabled = False + TxtFech3.ReadOnly = True : ImgFech3.Enabled = False + ChkConvertirDoctoPesos.Enabled = False + ChkConvertirDolares.Enabled = False + + TxtTipoCambio.Enabled = UsuarioActual.CveEmpresa.Contiene(13, 83) + TxtTipoCambioDlls.Enabled = UsuarioActual.CveEmpresa.Contiene(13, 83) + TxtTipoCambio.ReadOnly = Not UsuarioActual.CveEmpresa.Contiene(13, 83) + TxtTipoCambioDlls.ReadOnly = Not UsuarioActual.CveEmpresa.Contiene(13, 83) + + '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", "Cot") Then + TxtFechaPago.ReadOnly = Not UsuarioActual.TienePermisoProceso(260) + LnkUpdateFechaVencimiento.Visible = UsuarioActual.TienePermisoProceso(260) + Else + TxtFechaPago.ReadOnly = False + End If + + imgCalendario.Enabled = False + DdlFuenteRecaudacion.Enabled = False + + TrVistaPrevia.Visible = False + BtnEmitirImprimir.Visible = False + 'CargaLeyendasFiscales + ViewState("VentaFolio") = If(LblSerie.Text.Trim.Length = 0, TxtFolio.Text.Trim, LblSerie.Text.Trim & "-" & TxtFolio.Text.Trim) + + CalculaTotalesVenta(False) + + 'JJMQ 20160506: Se agrego para la validacion de pago de contado. + 'CVImporteContado.ValueToCompare = TxtTotal.Text.Replace(",", "") + + tdVigencia.Visible = DdlTipoComprobante.SelectedValue.Contiene("Cot") + tdFechaVigencia.Visible = DdlTipoComprobante.SelectedValue.Contiene("Cot") + + If DbRowVenta("TipoDocto").ToString() = "Rem" Then + 'CANTIDAD FACTURADA + If TmpDT.SUM("CantidadFacturadaRem") > 0 Then + GvPS.Columns(6).Visible = True + ThCantidadFacturadaRem.Visible = True + ThCantidadFacturadaRem2.Visible = True + Else + GvPS.Columns(6).Visible = False + ThCantidadFacturadaRem.Visible = False + ThCantidadFacturadaRem2.Visible = False + End If + + 'ACTIVA EDITAR + 'SOLO LA PUEDE EDITAR CON PROCESO | DEBE TENER CONCEPTOS PENDIENTES DE FACTURAR + If UsuarioActual.TienePermisoProceso(202) And TmpDT.SUM("CantidadFacturadaRem") < TmpDT.SUM("Cantidad") Then + BtnPermisoEditarRemision.Visible = True + End If + + 'ACTIVA BOTONERA | DEBE TENER CONCEPTOS PENDIENTES DE FACTURAR + If TmpDT.SUM("CantidadFacturadaRem") < TmpDT.SUM("Cantidad") Then + BtnsFacturar.Visible = True + + LBFacturarAnticipo.Visible = UsuarioActual.TienePermisoProceso(274) + + 'ACTIVA CONVERSION DE MONEDA + If DdlMoneda.SelectedValue.ToEntero() = 1 Then + TrConversionDolares.Visible = True + ChkConvertirDolares.Enabled = Not UsuarioActual.TienePermisoProceso(324) + TxtTipoCambioDlls.Enabled = True + Else + TrConversionTipoCambio.Visible = True + ChkConvertirDoctoPesos.Enabled = Not UsuarioActual.TienePermisoProceso(324) + TxtTipoCambio.Enabled = True + End If + End If + + 'Si es Empresa de Acumuladores + If CveVenta > 0 AndAlso UsuarioActual.Empresa.Funcionalidad(531) = "1" AndAlso DbRowVenta("TipoDocto").ToString() = "Rem" AndAlso (GlobalDTEstatusFactura().FiltroPrimeroValor("TipoEstatus", $"CveEstatusFactura = {Me.CveEstatus}").ToEntero() <> 5) Then + + BtnsFacturar.Visible = False + + Dim DtUsadosPendientes As DataTable = Nothing + Dim DtGarantiasPendientes As DataTable = Nothing + + Dim ObjUsados As New ClsVentas + + If ObjUsados.GetVentasUsados(CveVenta, -1, DbRowVenta("Fecha").ToString().ToDateTime, UsuarioActual.CveEmpresa) Then + DtUsadosPendientes = ObjUsados.DtResultados.Copy() + End If + + If ObjUsados.GetVentasGarantiaPendiente(CveVenta, Now, UsuarioActual.CveEmpresa) Then + DtGarantiasPendientes = ObjUsados.DtResultados.Copy() + End If + + 'If ObjUsados.GetVentasGarantiaPendiente(CveVenta, -1, Now, UsuarioActual.CveEmpresa) Then + ' DtGarantiasPendientes = ObjUsados.DtResultados.Copy() + 'End If + + ObjUsados.Dispose() + + Dim SaldoAlmacenExA As Decimal = 0 + 'Dim SaldoAlmacenUsados As Decimal = 0 + + Using ObjInventarios As New ClsInventarios + 'VERIFICA SI HACE FALTA DEVOLVER PRODUCTOS Y USADOS EN ESPECIFICO + If ObjInventarios.GetSaldoVentaDetalleAlmacen(CveVenta, UsuarioActual.CveEmpresa) Then + SaldoAlmacenExA = ObjInventarios.DtResultados.SUMD("SaldoAlmacen", $"CveTipoAlmacen = 10") + 'SaldoAlmacenUsados = ObjInventarios.DtResultados.SUMD("SaldoAlmacen", $"CveTipoAlmacen = 22") + End If + End Using + + 'Si ya se surtió y recibió + If SaldoAlmacenExA > 0 OrElse TmpDT.MAX("CveTipoPS") = "1" Then + BtnsFacturar.Visible = True + End If + + 'VERIFICA SI YA SE FACTURO COMPLETAMENTE + If TmpDT.SUM("CantidadFacturadaRem") = TmpDT.SUM("Cantidad") Then + BtnsFacturar.Visible = False + End If + + 'VERIFICA SI TIENE USADOS O GARANTIAS PENDIENTES + If BtnsFacturar.Visible Then + If (Not EsGarantia AndAlso (DtUsadosPendientes IsNot Nothing AndAlso DtUsadosPendientes.Rows.Count > 0)) Then + BtnsFacturar.Visible = False + Alert("Tiene usados pendiente de recibir", TipoMensaje.MsgAdvertencia) + End If + + If (EsGarantia AndAlso (DtGarantiasPendientes IsNot Nothing AndAlso DtGarantiasPendientes.Rows.Count > 0)) Then + Alert("Tiene garantías pendientes de recibir", TipoMensaje.MsgAdvertencia) + BtnsFacturar.Visible = False + End If + End If + + + LBFacturarAnticipo.Visible = UsuarioActual.TienePermisoProceso(274) + End If + + End If + + If DbRowVenta("TipoDocto").ToString().Contiene("Cot", "Pd2") Then + 'CANTIDAD FACTURADA + If TmpDT.SUM("CantidadFacturadaCot") > 0 Then + GvPS.Columns(7).Visible = True + ThCantidadFacturada.Visible = True + ThCantidadFacturada2.Visible = True + Else + GvPS.Columns(7).Visible = False + ThCantidadFacturada.Visible = False + ThCantidadFacturada2.Visible = False + End If + + 'ACTIVA EDITAR + 'SOLO LA PUEDE EDITAR USUATIOACTUAL-VENDEDOR | NO DEBE ESTAR FACTURADA + If (UsuarioActual.CveUsuario = DbRowVenta("CveUsuario").ToString().ToEntero() Or UsuarioActual.CveVendedor = DdlVendedor.SelectedValue.ToEntero()) And TmpDT.SUM("CantidadFacturadaCot") = 0 Then 'And TmpDT.SUM("CantidadFacturadaCot") < TmpDT.SUM("Cantidad") + BtnPermisoEditarCotizacion.Visible = True + End If + + 'SOLO LA PUEDE EDITAR USUATIOACTUAL-VENDEDOR | NO DEBE ESTAR FACTURADA + If UsuarioActual.TienePermisoProceso(281) And TmpDT.SUM("CantidadFacturadaCot") = 0 Then 'And TmpDT.SUM("CantidadFacturadaCot") < TmpDT.SUM("Cantidad") + BtnPermisoEditarCotizacion.Visible = True + End If + + 'ACTIVA BOTONERA | DEBE TENER CONCEPTOS PENDIENTES DE FACTURAR + VerificarBtnFacturarCotizacion(DbRowVenta("CveVendedor").ToString().ToEntero()) + End If + + If UsuarioActual.Empresa.Funcionalidad(280) = "1" Then + RblPaqueteria.SelectedValue = If(DbRowVenta("FormaPaqueteria").ToString = "", "1", DbRowVenta("FormaPaqueteria").ToString) + RblPaqueteria.Enabled = False + End If + + If UsuarioActual.CveEmpresa = 48 Then + TxtFecha.AutoPostBack = True + End If + + CargaCodigoUnico() + + DdlTipoRetencion.SelectedValueExist(DbRowVenta("CveTipoRetencion").ToString()) + + Me.FacturarSucursal = CBool(DbRowVenta("FacturarSucursal").ToString()) + + If Me.FacturarSucursal Then + HabilitarFacturacionSucursal() + End If + + CargaPS(-1, DdlPS) + + 'Verifico si tiene la funcionalidad (135) + If DdlTipoComprobante.SelectedValue = "Cot" AndAlso UsuarioActual.Empresa.Funcionalidad(135).Contiene("1", "2") Then + + Select Case UsuarioActual.Empresa.Funcionalidad(135) + Case "1" ' POR SUPERVISOR + Dim ObjVendedores As New ClsVtaVendedores + + If ObjVendedores.GetVendedores(UsuarioActual.CveEmpresa) Then + Dim DTVendedores As New DataTable + If DbRowVenta("CveVendedor").ToString().ToEntero() > 0 AndAlso UsuarioActual.CveVendedor > 0 Then + DTVendedores = ObjVendedores.DtResultados.FiltraParametros(String.Format("CveVendedor = {0}", DbRowVenta("CveVendedor").ToString())).FiltraParametros(String.Format("CveSupervisor = {0}", UsuarioActual.CveVendedor)) + End If + + 'Verifico si es su supervisor asignado + If DTVendedores.Rows.Count > 0 Then + If GlobalDTEstatusFactura().FiltroPrimeroValor("TipoEstatus", $"CveEstatusFactura = {Me.CveEstatus}").ToEntero() = 2 Then + BtnsFacturar.Visible = True + BtnGenerarRemision.Visible = True + Else + BtnsFacturar.Visible = False + BtnGenerarRemision.Visible = False + End If + End If + + DTVendedores.Dispose() + End If + ObjVendedores.Dispose() + + Case "2" ' POR PERMISO + If GlobalDTEstatusFactura().FiltroPrimeroValor("TipoEstatus", $"CveEstatusFactura = {Me.CveEstatus}").ToEntero() = 2 Then + BtnsFacturar.Visible = UsuarioActual.TienePermisoProceso(60) + If UsuarioActual.TienePermisoProceso(199) Then + BtnGenerarRemision.Visible = If(CveEstatus = 10, False, True) + Else + BtnGenerarRemision.Visible = False + End If + Else + BtnsFacturar.Visible = False + BtnGenerarRemision.Visible = False + End If + + End Select + + + End If + + If DdlTipoComprobante.SelectedValue = "Cot" Then + If GlobalDTEstatusFactura().FiltroPrimeroValor("TipoEstatus", $"CveEstatusFactura = {Me.CveEstatus}").ToEntero() = 5 Then + BtnsFacturar.Visible = False + BtnGenerarRemision.Visible = False + End If + End If + + If DdlTipoComprobante.SelectedValue = "Rem" Then + If GlobalDTEstatusFactura().FiltroPrimeroValor("TipoEstatus", $"CveEstatusFactura = {Me.CveEstatus}").ToEntero() = 5 Then + BtnsFacturar.Visible = False + BtnEmitirImprimir.Visible = False + BtnPermisoEditarRemision.Visible = False + End If + End If + + UpPS.Update() + UpContado.Update() + UpEstatus.Update() + Retorno = True + End If - ObjVentas.Dispose() Return Retorno End Function @@ -26690,6 +26706,33 @@ Partial Class Ventas 'GvRemisionesNCBon.DataSource = Me.TmpDTRNCBonificacionesSeleccionadas 'GvRemisionesNCBon.DataBind() + Dim SaldoMaximoUtilizable As Decimal = 0 + + If CargarSoloGarantias Then + Dim SaldoMaximo As Decimal = DtNC.SUMD("Saldo", "TipoRNC = 1 AND EsGarantia = True") + If SaldoMaximo > 0 Then + SaldoMaximoUtilizable = SaldoMaximo + Else + SaldoMaximoUtilizable = 0 + End If + Else + Dim ObjAcum As New ClsAcumuladores + If ObjAcum.GetMovimientosDistribuidorResumen(CveCliente, UsuarioActual.CveEmpresa) Then + Dim RowUsadosNC As DataRow = ObjAcum.DtResultados.Rows(2) + DivSMU.Visible = True + + Dim SaldoMaximo As Decimal = RowUsadosNC("ValorConImpuestos").ToString().ToDecimal() + If SaldoMaximo > 0 Then + SaldoMaximoUtilizable = RowUsadosNC("ValorConImpuestos").ToString().ToDecimal() + Else + SaldoMaximoUtilizable = 0 + End If + + Else + SaldoMaximoUtilizable = 0 + End If + ObjAcum.Dispose() + End If If CveVentaUsado > 0 Then DivSMU.Visible = True @@ -26702,44 +26745,21 @@ Partial Class Ventas End Using If DtDetalleUsado IsNot Nothing Then - Dim SaldoMaximoUsados As Decimal = DtDetalleUsado.SUM("Total", "EsCargo = True").ToDecimal() + DtDetalleUsado.SUM("ImporteIVA", "EsCargo = True").ToDecimal() - HdnSaldoMaximoUsados.Value = SaldoMaximoUsados.ToString() - LtlSMU.Text = String.Format("{0:N2}", SaldoMaximoUsados) - End If - - Else - If CargarSoloGarantias Then - Dim SaldoMaximo As Decimal = DtNC.SUMD("Saldo", "TipoRNC = 1 AND EsGarantia = True") - If SaldoMaximo > 0 Then - HdnSaldoMaximoUsados.Value = SaldoMaximo.ToString() - LtlSMU.Text = SaldoMaximo.FormatoNumero(2) + Dim SaldoMaximoUsadosFactura As Decimal = DtDetalleUsado.SUM("Total", "EsCargo = True").ToDecimal() + DtDetalleUsado.SUM("ImporteIVA", "EsCargo = True").ToDecimal() + If SaldoMaximoUtilizable < SaldoMaximoUsadosFactura Then + HdnSaldoMaximoUsados.Value = SaldoMaximoUtilizable.ToString() + LtlSMU.Text = String.Format("{0:N2}", SaldoMaximoUtilizable) Else - HdnSaldoMaximoUsados.Value = "0" - LtlSMU.Text = "0" + HdnSaldoMaximoUsados.Value = SaldoMaximoUsadosFactura.ToString() + LtlSMU.Text = String.Format("{0:N2}", SaldoMaximoUsadosFactura) End If Else - Dim ObjAcum As New ClsAcumuladores - If ObjAcum.GetMovimientosDistribuidorResumen(CveCliente, UsuarioActual.CveEmpresa) Then - Dim RowUsadosNC As DataRow = ObjAcum.DtResultados.Rows(2) - DivSMU.Visible = True - - Dim SaldoMaximo As Decimal = RowUsadosNC("ValorConImpuestos").ToString().ToDecimal() - If SaldoMaximo > 0 Then - HdnSaldoMaximoUsados.Value = RowUsadosNC("ValorConImpuestos").ToString() - LtlSMU.Text = RowUsadosNC("ValorConImpuestos").ToString().ToDecimal().FormatoNumero(2) - Else - HdnSaldoMaximoUsados.Value = "0" - LtlSMU.Text = "0" - End If - - Else - 'DivSMU.Visible = False - HdnSaldoMaximoUsados.Value = "0" - LtlSMU.Text = "0" - End If - ObjAcum.Dispose() + HdnSaldoMaximoUsados.Value = SaldoMaximoUtilizable.ToString() + LtlSMU.Text = String.Format("{0:N2}", SaldoMaximoUtilizable) End If - + Else + HdnSaldoMaximoUsados.Value = SaldoMaximoUtilizable.ToString() + LtlSMU.Text = SaldoMaximoUtilizable.FormatoNumero(2) End If Else HdnSaldoMaximoUsados.Value = "0" @@ -26778,9 +26798,44 @@ Partial Class Ventas End If GvDescNCCargos.DataBind() - Dim SaldoMaximoUsados As Decimal = Me.TmpDT.SUM("Total", "EsCargo = True").ToDecimal() + Me.TmpDT.SUM("ImporteIVA", "EsCargo = True").ToDecimal() - HdnSaldoMaximoUsados.Value = SaldoMaximoUsados.ToString() - LblSaldoMaximoUsados.Text = String.Format("{0:N2}", SaldoMaximoUsados) + Dim SaldoMaximoUtilizable As Decimal = 0 + + If CargarSoloGarantias Then + Dim SaldoMaximo As Decimal = DtNC.SUMD("Saldo", "TipoRNC = 1 AND EsGarantia = True") + If SaldoMaximo > 0 Then + SaldoMaximoUtilizable = SaldoMaximo + Else + SaldoMaximoUtilizable = 0 + End If + Else + Dim ObjAcum As New ClsAcumuladores + If ObjAcum.GetMovimientosDistribuidorResumen(CveCliente, UsuarioActual.CveEmpresa) Then + Dim RowUsadosNC As DataRow = ObjAcum.DtResultados.Rows(2) + DivSMU.Visible = True + + Dim SaldoMaximo As Decimal = RowUsadosNC("ValorConImpuestos").ToString().ToDecimal() + If SaldoMaximo > 0 Then + SaldoMaximoUtilizable = RowUsadosNC("ValorConImpuestos").ToString().ToDecimal() + Else + SaldoMaximoUtilizable = 0 + End If + + Else + SaldoMaximoUtilizable = 0 + End If + ObjAcum.Dispose() + End If + + Dim SaldoMaximoUsadosFactura As Decimal = Me.TmpDT.SUM("Total", "EsCargo = True").ToDecimal() + Me.TmpDT.SUM("ImporteIVA", "EsCargo = True").ToDecimal() + + If SaldoMaximoUtilizable < SaldoMaximoUsadosFactura Then + HdnSaldoMaximoUsados.Value = SaldoMaximoUtilizable.ToString() + LblSaldoMaximoUsados.Text = String.Format("{0:N2}", SaldoMaximoUtilizable) + Else + HdnSaldoMaximoUsados.Value = SaldoMaximoUsadosFactura.ToString() + LblSaldoMaximoUsados.Text = String.Format("{0:N2}", SaldoMaximoUsadosFactura) + End If + Else HdnSaldoMaximoUsados.Value = "0" LblSaldoMaximoUsados.Text = "0" @@ -26820,6 +26875,27 @@ Partial Class Ventas GvRemisionesNCDetalle.DataBind() 'GvRemisionesNCBon.DataBind() + Dim SaldoMaximoUtilizable As Decimal = 0 + + If CargaSoloGarantias Then + Dim SaldoMaximo As Decimal = TmpDTRNCDetalle.SUMD("Total", "TipoRNC = 1") + If SaldoMaximo > 0 Then + SaldoMaximoUtilizable = SaldoMaximo + Else + SaldoMaximoUtilizable = 0 + End If + Else + Dim ObjAcum As New ClsAcumuladores + If ObjAcum.GetMovimientosDistribuidorResumen(CveCliente, UsuarioActual.CveEmpresa) Then + Dim RowUsadosNC As DataRow = ObjAcum.DtResultados.Rows(2) + DivSMU.Visible = True + SaldoMaximoUtilizable = RowUsadosNC("ValorConImpuestos").ToString().ToDecimal() + Else + 'DivSMU.Visible = False + SaldoMaximoUtilizable = 0 + End If + ObjAcum.Dispose() + End If If CveVentaUsado > 0 Then DivSMU.Visible = True @@ -26833,49 +26909,26 @@ Partial Class Ventas If DtDetalleUsado IsNot Nothing Then Dim SaldoMaximoUsados As Decimal = DtDetalleUsado.SUM("Total", "EsCargo = True").ToDecimal() + DtDetalleUsado.SUM("ImporteIVA", "EsCargo = True").ToDecimal() + HdnSaldoMaximoUsados.Value = SaldoMaximoUtilizable.ToString() - If SaldoMaximoUsados > 0 Then + If SaldoMaximoUtilizable < SaldoMaximoUsados Then + HdnSaldoMaximoUsados.Value = SaldoMaximoUtilizable.ToString() + LtlSMU.Text = String.Format("{0:N2}", SaldoMaximoUtilizable) + Else HdnSaldoMaximoUsados.Value = SaldoMaximoUsados.ToString() LtlSMU.Text = String.Format("{0:N2}", SaldoMaximoUsados) - Else - HdnSaldoMaximoUsados.Value = "0" - LtlSMU.Text = "0" End If End If - Else - If CargaSoloGarantias Then - Dim SaldoMaximo As Decimal = TmpDTRNCDetalle.SUMD("Total", "TipoRNC = 1") - If SaldoMaximo > 0 Then - HdnSaldoMaximoUsados.Value = SaldoMaximo.ToString() - LtlSMU.Text = SaldoMaximo.FormatoNumero(2) - Else - HdnSaldoMaximoUsados.Value = "0" - LtlSMU.Text = "0" - End If - Else - Dim ObjAcum As New ClsAcumuladores - If ObjAcum.GetMovimientosDistribuidorResumen(CveCliente, UsuarioActual.CveEmpresa) Then - Dim RowUsadosNC As DataRow = ObjAcum.DtResultados.Rows(2) - DivSMU.Visible = True - HdnSaldoMaximoUsados.Value = RowUsadosNC("ValorConImpuestos").ToString() - LtlSMU.Text = RowUsadosNC("ValorConImpuestos").ToString().ToDecimal().FormatoNumero(2) - Else - 'DivSMU.Visible = False - HdnSaldoMaximoUsados.Value = "0" - LtlSMU.Text = "0" - End If - ObjAcum.Dispose() - End If - + HdnSaldoMaximoUsados.Value = SaldoMaximoUtilizable.ToString() + LtlSMU.Text = SaldoMaximoUtilizable.FormatoNumero(2) End If UpModalRemisionesNC.Update() UpDescNC.Update() End Sub Private Sub CargaRNCDetalleDesc(Optional CargarSoloGarantias As Boolean = False) - Dim DtNC As DataTable = Nothing Dim ObjMovtos As New ClsMovimientos() If ObjMovtos.GetRemisionesNCCliente(CveCliente, True, CveMoneda:=-1) Then @@ -26896,14 +26949,42 @@ Partial Class Ventas End If GvDescNCCargosDetalle.DataBind() + Dim SaldoMaximoUtilizable As Decimal = 0 + + If CargarSoloGarantias Then + Dim SaldoMaximo As Decimal = TmpDTRNCDetalle.SUMD("Saldo", "TipoRNC = 1 AND EsGarantia = True") + If SaldoMaximo > 0 Then + SaldoMaximoUtilizable = SaldoMaximo + Else + SaldoMaximoUtilizable = 0 + End If + Else + Dim ObjAcum As New ClsAcumuladores + If ObjAcum.GetMovimientosDistribuidorResumen(CveCliente, UsuarioActual.CveEmpresa) Then + Dim RowUsadosNC As DataRow = ObjAcum.DtResultados.Rows(2) + DivSMU.Visible = True + + Dim SaldoMaximo As Decimal = RowUsadosNC("ValorConImpuestos").ToString().ToDecimal() + If SaldoMaximo > 0 Then + SaldoMaximoUtilizable = RowUsadosNC("ValorConImpuestos").ToString().ToDecimal() + Else + SaldoMaximoUtilizable = 0 + End If + + Else + SaldoMaximoUtilizable = 0 + End If + ObjAcum.Dispose() + End If + Dim SaldoMaximoUsados As Decimal = Me.TmpDT.SUM("Total", "EsCargo = True").ToDecimal() + Me.TmpDT.SUM("ImporteIVA", "EsCargo = True").ToDecimal() - If SaldoMaximoUsados > 0 Then + If SaldoMaximoUtilizable < SaldoMaximoUsados Then + HdnSaldoMaximoUsados.Value = SaldoMaximoUtilizable.ToString() + LblSaldoMaximoUsados.Text = String.Format("{0:N2}", SaldoMaximoUtilizable) + Else HdnSaldoMaximoUsados.Value = SaldoMaximoUsados.ToString() LblSaldoMaximoUsados.Text = String.Format("{0:N2}", SaldoMaximoUsados) - Else - HdnSaldoMaximoUsados.Value = "0" - LblSaldoMaximoUsados.Text = "0" End If UpDescNC.Update() @@ -26940,6 +27021,16 @@ Partial Class Ventas GvRemisionesNCBonDetalle.DataSource = TmpDTRNCDetalle.FiltraParametros("TipoRNC = 2") GvRemisionesNCBonDetalle.DataBind() + Dim SaldoMaximoUtilizable As Decimal = 0 + If TmpDTRNCBonificacionesSeleccionadas IsNot Nothing Then + Dim SaldoMaximo As Decimal = TmpDTRNCBonificacionesSeleccionadas.SUMD("Saldo") + If SaldoMaximo > 0 Then + SaldoMaximoUtilizable = SaldoMaximo + Else + SaldoMaximoUtilizable = 0 + End If + End If + If DdlVentaUsado.SelectedValue.ToEntero() > 0 Then Dim DtDetalleFactura As DataTable = Nothing Using ObjVentas As New ClsVentas @@ -26949,21 +27040,18 @@ Partial Class Ventas End Using Dim ImporteBon As Decimal = DtDetalleFactura.SUMD("PUBonificacion") * (1 + DtDetalleFactura.MAX("PorcentajeIVA").ToDecimal()) - LtlSMUBon.Text = String.Format("{0:N2}", ImporteBon) - HdnSMUBon.Value = ImporteBon.ToString() + If SaldoMaximoUtilizable < ImporteBon Then + LtlSMUBon.Text = String.Format("{0:N2}", SaldoMaximoUtilizable) + HdnSMUBon.Value = SaldoMaximoUtilizable.ToString() + Else + LtlSMUBon.Text = String.Format("{0:N2}", ImporteBon) + HdnSMUBon.Value = ImporteBon.ToString() + End If DtDetalleFactura.Dispose() Else - If TmpDTRNCBonificacionesSeleccionadas IsNot Nothing Then - Dim SaldoMaximo As Decimal = TmpDTRNCBonificacionesSeleccionadas.SUMD("Saldo") - If SaldoMaximo > 0 Then - HdnSMUBon.Value = SaldoMaximo.ToString() - LtlSMUBon.Text = SaldoMaximo.FormatoNumero(2) - Else - HdnSMUBon.Value = "0" - LtlSMUBon.Text = "0" - End If - End If + HdnSMUBon.Value = SaldoMaximoUtilizable.ToString() + LtlSMUBon.Text = SaldoMaximoUtilizable.FormatoNumero(2) End If UpModalRemisionesNC.Update() @@ -27077,6 +27165,9 @@ Partial Class Ventas 'LtlSMUBon.Text = String.Format("{0:N2}", SMUBon) 'HdnSMUBon.Value = SMUBon.ToString() + + Dim SaldoMaximoUtilizable As Decimal = TmpDTRNCBonificacionesSeleccionadas.SUMD("Saldo") + If DdlVentaUsado.SelectedValue.ToEntero() > 0 Then Dim DtDetalleFactura As DataTable = Nothing Using ObjVentas As New ClsVentas @@ -27086,15 +27177,20 @@ Partial Class Ventas End Using Dim ImporteBon As Decimal = DtDetalleFactura.SUMD("PUBonificacion") * (1 + DtDetalleFactura.MAX("PorcentajeIVA").ToDecimal()) - LtlSMUBon.Text = String.Format("{0:N2}", ImporteBon) - HdnSMUBon.Value = ImporteBon.ToString() + If SaldoMaximoUtilizable < ImporteBon Then + LtlSMUBon.Text = String.Format("{0:N2}", SaldoMaximoUtilizable) + HdnSMUBon.Value = SaldoMaximoUtilizable.ToString() + Else + LtlSMUBon.Text = String.Format("{0:N2}", ImporteBon) + HdnSMUBon.Value = ImporteBon.ToString() + End If + DtDetalleFactura.Dispose() Else - Dim SaldoMaximo As Decimal = TmpDTRNCBonificacionesSeleccionadas.SUMD("Saldo") - If SaldoMaximo > 0 Then - HdnSMUBon.Value = SaldoMaximo.ToString() - LtlSMUBon.Text = SaldoMaximo.FormatoNumero(2) + If SaldoMaximoUtilizable > 0 Then + HdnSMUBon.Value = SaldoMaximoUtilizable.ToString() + LtlSMUBon.Text = SaldoMaximoUtilizable.FormatoNumero(2) Else HdnSMUBon.Value = "0" LtlSMUBon.Text = "0"