From 43a6af3fb65b97a68feb106fa2d93fce25cde1fe Mon Sep 17 00:00:00 2001 From: Rakcsle Supertramp Date: Wed, 21 Oct 2020 20:41:48 -0700 Subject: [PATCH] eFacturas Agregar complmento, se agrega CveFactura a filtro de complementos ya vinculados, Compras Unificacion se retorna valor SeUnifico --- App_Code/ClsCompras.vb | 3 +- App_Code/ClsContratos.vb | 160 +- App_Code/ClsPaginas.vb | 4 +- Compras/eFacturas.aspx.vb | 4 +- Contratos/ContratoObra.aspx | 2679 +++++++++++++++++++ Contratos/ContratoObra.aspx.vb | 4415 ++++++++++++++++++++++++++++++++ 6 files changed, 7259 insertions(+), 6 deletions(-) create mode 100644 Contratos/ContratoObra.aspx create mode 100644 Contratos/ContratoObra.aspx.vb diff --git a/App_Code/ClsCompras.vb b/App_Code/ClsCompras.vb index bf0da4b34..cc76dc5f6 100644 --- a/App_Code/ClsCompras.vb +++ b/App_Code/ClsCompras.vb @@ -2410,7 +2410,7 @@ Public Class ClsCompras End Function - Public Function GetCompararComplementoPago(CveProveedor As Integer, Monto As Decimal, XMLPagos As String, CveEmpresa As Integer, Optional CveIE As Integer = -1, Optional OP As Integer = 1) As Boolean + Public Function GetCompararComplementoPago(CveProveedor As Integer, Monto As Decimal, XMLPagos As String, CveEmpresa As Integer, Optional CveIE As Integer = -1, Optional OP As Integer = 1, Optional CveFactura As Integer = -1) As Boolean Dim Retorno As Boolean = False DataAdapter("PA_Comp_CompararComplementoPagoGet") With SqlAdapter.SelectCommand.Parameters @@ -2420,6 +2420,7 @@ Public Class ClsCompras .Add("@CveEmpresa", SqlDbType.Int).Value = CveEmpresa .Add("@CveIE", SqlDbType.Int).Value = CveIE .Add("@OP", SqlDbType.Int).Value = OP + .Add("@CveFactura", SqlDbType.Int).Value = CveFactura End With Try SqlAdapter.Fill(Data) diff --git a/App_Code/ClsContratos.vb b/App_Code/ClsContratos.vb index 3da032b9a..b5237427d 100644 --- a/App_Code/ClsContratos.vb +++ b/App_Code/ClsContratos.vb @@ -446,6 +446,7 @@ Public Class ClsContratos Return Retorno End Function + Public Function TerminarContrato(CveContrato As Integer, CveTipoEstatus As Integer, CveEmpresa As Integer) As Integer Dim Retorno = -1 @@ -511,10 +512,167 @@ Public Class ClsContratos End Try Return Retorno + End Function + +#End Region + + + + +#Region "CONTRATO OBRA" + + Public Function AddContratosObra(NumeroContrato As String, DescripcionContrato As String, NumeroLicitacion As String, CveProveedor As Integer, CveCliente As Integer, CveProspecto As Integer, FechaInicial As DateTime, FechaFinal As DateTime, + Ubicacion As String, Responsable As String, CveProyecto As Integer, PorIVA As Double, PorAnticipo As Double, PorAmortizacionAnticipo As Double, PorGarantia As Double, Archivo As String, + Geom As String, CveContratoPadre As Integer, CveUsuario As Integer, CveEmpresa As Integer, EsPresupuestal As Boolean, Minimo As Double, Maximo As Double, Importe As Double, CveMoneda As Integer, ModalidadDetalle As Integer, + Optional CveContratosEstatus As Integer = -1, Optional CveContratoTipo As Integer = -1, Optional TipoCambio As Double = 1, Optional CveSucursalCliente As Integer = -1, Optional CveAlmacenOrigen As Integer = -1, Optional CveAlmacenDestino As Integer = -1, Optional PorcentajeComision As Integer = -1, + Optional TipoGarantia As Integer = -1, Optional Folio As Integer = -1, Optional FechaVenc As Date = Nothing, Optional EstatusFianza As Integer = -1, Optional CvePeriodo As Integer = -1, Optional CveContratoPlantilla As Integer = -1, Optional CveCuentaEquipo As Integer = -1, + Optional CveVendedor As Integer = -1, Optional Observaciones As String = "", Optional CveDireccionEnvio As Integer = -1, Optional AplicaImpuestosLocales As Boolean = False, Optional CorreoNotificacionPedDev As String = "") As Integer + + Dim Retorno As Integer = -1 + DataAdapter("PA_Con_ContratosObraAdd") + With SqlAdapter.SelectCommand.Parameters + .Add("@NumeroContrato", SqlDbType.VarChar).Value = NumeroContrato + .Add("@DescripcionContrato", SqlDbType.VarChar).Value = DescripcionContrato + .Add("@NumeroLicitacion", SqlDbType.VarChar).Value = NumeroLicitacion + .Add("@CveProveedor", SqlDbType.Int).Value = CveProveedor + .Add("@CveCliente", SqlDbType.Int).Value = CveCliente + .Add("@CveProspecto", SqlDbType.Int).Value = CveProspecto + .Add("@FechaInicial", SqlDbType.DateTime).Value = FechaInicial + .Add("@FechaFinal", SqlDbType.DateTime).Value = FechaFinal + .Add("@Ubicacion", SqlDbType.VarChar).Value = Ubicacion + .Add("@Responsable", SqlDbType.VarChar).Value = Responsable + .Add("@CveProyecto", SqlDbType.Int).Value = CveProyecto + .Add("@CveContratosEstatus", SqlDbType.Int).Value = CveContratosEstatus + .Add("@PorIVA", SqlDbType.Float).Value = PorIVA + .Add("@PorAnticipo", SqlDbType.Float).Value = PorAnticipo + .Add("@PorAmortizacionAnticipo", SqlDbType.Float).Value = PorAmortizacionAnticipo + .Add("@PorGarantia", SqlDbType.Float).Value = PorGarantia + '.Add("@EstatusContrato", SqlDbType.Bit).Value = EstatusContrato + .Add("@Archivo", SqlDbType.VarChar).Value = Archivo + .Add("@Geom", SqlDbType.VarChar).Value = Geom + .Add("@CveContratoPadre", SqlDbType.Int).Value = CveContratoPadre + .Add("@CveUsuario", SqlDbType.Int).Value = CveUsuario + .Add("@CveEmpresa", SqlDbType.Int).Value = CveEmpresa + .Add("@EsPresupuestal", SqlDbType.Int).Value = EsPresupuestal + .Add("@CveContratoTipo", SqlDbType.SmallInt).Value = CveContratoTipo + .Add("@ImporteMin", SqlDbType.Money).Value = Minimo + .Add("@ImporteMax", SqlDbType.Money).Value = Maximo + .Add("@Importe", SqlDbType.Money).Value = Importe + .Add("@CveMoneda", SqlDbType.Int).Value = CveMoneda + .Add("@TipoCambio", SqlDbType.Money).Value = TipoCambio + .Add("@ModalidadDetalle", SqlDbType.TinyInt).Value = ModalidadDetalle + .Add("@CveSucursalCliente", SqlDbType.Int).Value = CveSucursalCliente + .Add("@CveAlmacenOrigen", SqlDbType.Int).Value = CveAlmacenOrigen + .Add("@CveAlmacenDestino", SqlDbType.Int).Value = CveAlmacenDestino + .Add("@PorcentajeComision", SqlDbType.Int).Value = PorcentajeComision + .Add("@TipoGarantia", SqlDbType.Int).Value = TipoGarantia + .Add("@Folio", SqlDbType.Int).Value = Folio + .Add("@FechaVenc", SqlDbType.Date).Value = FechaVenc + .Add("@EstatusFianza", SqlDbType.Int).Value = EstatusFianza + .Add("@CvePeriodo", SqlDbType.Int).Value = CvePeriodo + .Add("@CveCuentaEquipo", SqlDbType.Int).Value = CveCuentaEquipo + .Add("@CveContratoPlantilla", SqlDbType.Int).Value = CveContratoPlantilla + .Add("@CveVendedor", SqlDbType.Int).Value = CveVendedor + .Add("@Observaciones", SqlDbType.VarChar).Value = Observaciones + .Add("@CveDireccionEnvio", SqlDbType.Int).Value = CveDireccionEnvio + .Add("@AplicaImpuestosLocales", SqlDbType.Bit).Value = If(AplicaImpuestosLocales, 1, 0) + .Add("@CorreoNotificacionPedDev", SqlDbType.VarChar).Value = CorreoNotificacionPedDev + + .Add("@CveContrato", SqlDbType.Int).Direction = ParameterDirection.Output + + End With + + Try + SqlAdapter.Fill(Data) + Retorno = CInt(SqlAdapter.SelectCommand.Parameters("@CveContrato").Value) + Catch ex As Exception + If ex.Message.Contains("Número: 2601;") Then + Alert("Ya existe un contrato con el mismo número de contrato registrado: " & NumeroContrato & ".", TipoMensaje.MsgAdvertencia) + Else + OnError("Ocurrió un error al agregar el Contrato.", ex, SqlAdapter.SelectCommand.Parameters.ParametrosInfo()) + End If + + End Try + + Return Retorno + End Function -#End Region + Public Function UpdateContratosObra(CveContrato As Integer, NumeroContrato As String, DescripcionContrato As String, NumeroLicitacion As String, CveProveedor As Integer, CveCliente As Integer, CveProspecto As Integer, FechaInicial As DateTime, FechaFinal As DateTime, + Ubicacion As String, Responsable As String, PorIVA As Double, PorAnticipo As Double, PorAmortizacionAnticipo As Double, PorGarantia As Double, Archivo As String, Geom As String, + CveContratoPadre As Integer, CveUsuario As Integer, CveEmpresa As Integer, EsPresupuestal As Boolean, Minimo As Double, Maximo As Double, Importe As Double, CveMoneda As Integer, ModalidadDetalle As Integer, + Optional CveContratosEstatus As Integer = -1, Optional CveContratoTipo As Integer = -1, Optional TipoCambio As Double = 1.0, Optional CveSucursalCliente As Integer = -1, Optional CveAlmacenOrigen As Integer = -1, Optional CveAlmacenDestino As Integer = -1, Optional PorcentajeComision As Integer = -1, + Optional TipoGarantia As Integer = -1, Optional Folio As Integer = -1, Optional FechaVenc As Date = Nothing, Optional EstatusFianza As Integer = -1, Optional CveContratoPlantilla As Integer = -1, Optional CveCuentaEquipo As Integer = -1, + Optional CveVendedor As Integer = -1, Optional Observaciones As String = "", Optional CveDireccionEnvio As Integer = -1, Optional AplicaImpuestosLocales As Boolean = False, Optional CorreoNotificacionPedDev As String = "") As Boolean + Dim Retorno = False + DataAdapter("PA_Con_ContratosObraUpdate") + With SqlAdapter.SelectCommand.Parameters + .Add("@CveContrato", SqlDbType.Int).Value = CveContrato + .Add("@NumeroContrato", SqlDbType.VarChar).Value = NumeroContrato + .Add("@DescripcionContrato", SqlDbType.VarChar).Value = DescripcionContrato + .Add("@NumeroLicitacion", SqlDbType.VarChar).Value = NumeroLicitacion + .Add("@CveProveedor", SqlDbType.Int).Value = CveProveedor + .Add("@CveCliente", SqlDbType.Int).Value = CveCliente + .Add("@CveProspecto", SqlDbType.Int).Value = CveProspecto + .Add("@FechaInicial", SqlDbType.DateTime).Value = FechaInicial + .Add("@FechaFinal", SqlDbType.DateTime).Value = FechaFinal + .Add("@Ubicacion", SqlDbType.VarChar).Value = Ubicacion + .Add("@Responsable", SqlDbType.VarChar).Value = Responsable + .Add("@CveContratosEstatus", SqlDbType.Int).Value = CveContratosEstatus + .Add("@PorIVA", SqlDbType.Float).Value = PorIVA + .Add("@PorAnticipo", SqlDbType.Float).Value = PorAnticipo + .Add("@PorAmortizacionAnticipo", SqlDbType.Float).Value = PorAmortizacionAnticipo + .Add("@PorGarantia", SqlDbType.Float).Value = PorGarantia + '.Add("@EstatusContrato", SqlDbType.Bit).Value = EstatusContrato + .Add("@Archivo", SqlDbType.VarChar).Value = Archivo + .Add("@Geom", SqlDbType.VarChar).Value = Geom + .Add("@CveContratoPadre", SqlDbType.Int).Value = CveContratoPadre + .Add("@CveUsuario", SqlDbType.Int).Value = CveUsuario + .Add("@CveEmpresa", SqlDbType.Int).Value = CveEmpresa + .Add("@EsPresupuestal", SqlDbType.Int).Value = EsPresupuestal + .Add("@ImporteMin", SqlDbType.Money).Value = Minimo + .Add("@ImporteMax", SqlDbType.Money).Value = Maximo + .Add("@Importe", SqlDbType.Money).Value = Importe + .Add("@CveContratoTipo", SqlDbType.SmallInt).Value = CveContratoTipo + .Add("@CveMoneda", SqlDbType.Int).Value = CveMoneda + .Add("@TipoCambio", SqlDbType.Money).Value = TipoCambio + .Add("@ModalidadDetalle", SqlDbType.TinyInt).Value = ModalidadDetalle + .Add("@CveSucursalCliente", SqlDbType.Int).Value = CveSucursalCliente + .Add("@CveAlmacenOrigen", SqlDbType.Int).Value = CveAlmacenOrigen + .Add("@CveAlmacenDestino", SqlDbType.Int).Value = CveAlmacenDestino + .Add("@PorcentajeComision", SqlDbType.Int).Value = PorcentajeComision + .Add("@TipoGarantia", SqlDbType.Int).Value = TipoGarantia + .Add("@Folio", SqlDbType.Int).Value = Folio + .Add("@FechaVenc", SqlDbType.Date).Value = FechaVenc + .Add("@EstatusFianza", SqlDbType.Int).Value = EstatusFianza + .Add("@CveContratoPlantilla", SqlDbType.Int).Value = CveContratoPlantilla + .Add("@CveCuentaEquipo", SqlDbType.Int).Value = CveCuentaEquipo + .Add("@CveVendedor", SqlDbType.Int).Value = CveVendedor + .Add("@Observaciones", SqlDbType.VarChar).Value = Observaciones + .Add("@CveDireccionEnvio", SqlDbType.Int).Value = CveDireccionEnvio + .Add("@AplicaImpuestosLocales", SqlDbType.Bit).Value = If(AplicaImpuestosLocales, 1, 0) + .Add("@CorreoNotificacionPedDev", SqlDbType.VarChar).Value = CorreoNotificacionPedDev + + End With + + Try + SqlAdapter.Fill(Data) + Retorno = True + Catch ex As Exception + If ex.Message.Contains("Número: 2601;") Then + Alert("Ya existe un contrato con el mismo número de contrato registrado: " & NumeroContrato & ".", TipoMensaje.MsgAdvertencia) + Else + OnError("Ocurrió un error al actualizar el Contrato.", ex, SqlAdapter.SelectCommand.Parameters.ParametrosInfo()) + End If + + End Try + + Return Retorno + End Function + +#End Region + #Region "C I C L O C O M E R C I A L" Public Function CicloComercialAdd(CveContrato As Integer, CveCotizacion As Integer, CveCliente As Integer, FueFacturado As Boolean, CveFactura As Integer, Estatus As Integer, CveEmpresa As Integer, FechaVenc As Date) As Boolean Dim Retorno As Boolean = False diff --git a/App_Code/ClsPaginas.vb b/App_Code/ClsPaginas.vb index a1583a93a..2f896980b 100644 --- a/App_Code/ClsPaginas.vb +++ b/App_Code/ClsPaginas.vb @@ -4978,9 +4978,7 @@ Public Class ClsPaginas PaginaDict.Add("/PV/PVRepCompras.aspx".ToUpper(), 272) PaginaDict.Add("/PV/PVRepVentasCompras.aspx".ToUpper(), 273) - - - + PaginaDict.Add("/Contratos/ContratoObra.aspx".ToUpper(), -1) diff --git a/Compras/eFacturas.aspx.vb b/Compras/eFacturas.aspx.vb index a565bc154..7a44163ab 100644 --- a/Compras/eFacturas.aspx.vb +++ b/Compras/eFacturas.aspx.vb @@ -2653,6 +2653,8 @@ Partial Class Compras_eFacturas Dim gvRow As GridViewRow = DirectCast((DirectCast(sender, LinkButton)).NamingContainer, GridViewRow) + + Dim CveFacturaComplemento As Integer = gvRow.DataKey("CveFactura").ToString.ToEntero Dim CveComplementoPagoCompra As Integer = gvRow.DataKey("CveComplementoPagoCompra").ToString.ToEntero If CveComplementoPagoCompra > 0 Then @@ -2773,7 +2775,7 @@ Partial Class Compras_eFacturas Dim ObjCompraFolios As New ClsCompras - If ObjCompraFolios.GetCompararComplementoPago(gvRow.DataKey("CveProveedor").ToEntero, Monto, nodePagos2.InnerXml.Replace("pago10:", ""), UsuarioActual.CveEmpresa, OP:=2) Then + If ObjCompraFolios.GetCompararComplementoPago(gvRow.DataKey("CveProveedor").ToEntero, Monto, nodePagos2.InnerXml.Replace("pago10:", ""), UsuarioActual.CveEmpresa, OP:=If(CveComplementoPagoCompra > 0, 2, 1), CveFactura:=CveFacturaComplemento) Then ' '.GetCompararComplementoPago(gvRow.DataKey("CveProveedor").ToEntero, Monto, nodePagos2.InnerXml.Replace("pago10:", ""), UsuarioActual.CveEmpresa) Then If ObjCompraFolios.DtResultados.Rows.Count > 0 Then diff --git a/Contratos/ContratoObra.aspx b/Contratos/ContratoObra.aspx new file mode 100644 index 000000000..18722fc8a --- /dev/null +++ b/Contratos/ContratoObra.aspx @@ -0,0 +1,2679 @@ +<%@ Page Title="" Language="VB" MasterPageFile="~/Site.master" AutoEventWireup="false" CodeFile="ContratoObra.aspx.vb" Inherits="Contratos_ContratoObra" %> + + + + + + + + + + + +
  • + Concluir Contrato +
  • +
  • + Cancelar Contrato +
  • +
  • + Reactivar Contrato +
  • +
  • + Descargar Formato +
  • +
  • + Crear A Partir De +
  • + +
  • + Importar Listado +
  • + + +
  • + Agregar Gastos +
  • + + +
  • + Avance por Documento PDF +
  • + + +
  • + Descargar Contrato +
  • + +
  • + Informacion PDF +
  • + + +
  • + Gastos PDF +
  • + + +
  • + Suministros PDF +
  • +
  • + Avance PDF +
  • + +
  • + Presupuesto PDF +
  • + +
  • + Activos Fijos PDF +
  • + +
  • + Activos Fijos Excel +
  • +
  • + Pedidos / Devoluciones PDF +
  • + +
  • + Pedidos / Devoluciones Excel +
  • + + + + + + +
  • + Habilitar Ajuste A.F. +
  • +
    +
    + + + + + +
    + + + + + + + + + + + + + +
    +
    + +   + + + + + + +<%-- + +
    +
    + +
    +
    +
    + +

    Tipo de Contrato

    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    + +
    +
    + +
    +
    +
    +
    +
    Tipo Contrato:
    +
    + + +
    +
    +
    +
    +
    + +
    +
    +
    +
    + +
    +
    +
    +
    + +
    + +
    + +
    + +
    + +
    +
    +
    +
    --%> + + + + +
    + + + + + + + + + + + +
    Importe Contratado: $ + + Facturado: $ + + Por Facturar: $ + + Descargar ContratoDescargar ContratoUtilidad: + +
    +
    +
    + + + + + +
    +
    +
    +
    +
    + +
    +
    Datos del Contrato
    +
    +
    +
    + +
    + + + +
    +
    +
    + +
    + + + +
    +
    +
    + +
    + +
    +
    +
    +
    + + + +
    +
    + +
    + +
    + +
    +
    + + <%--
    + +
    + +
    +
    + +
    + +
    + + + +
    +
    +
    + +
    + + + +
    +
    +
    + +
    + + +
    +
    --%> + + + +
    +
    +
    + +
    + + +
    +
    +
    + +
    +
    +
    +
    +
    + Proyecto: +
    + + + + + + + +
    +
    +
    + + : +
    + + + <%--
    +
    + + + + + +
    +
    --%> + + <%--
    + +
    + +
    +
    --%> + +
    +
    +
    +
    +
    + +
    + +
    +
    +
    +
    +
    + +
    +
    Información
    +
    +
    +
    +
    + + + +
    +
    + + +
    +
    + + + +
    +
    +
    +
    + + +<%-- + +
    +
    + + + +
    +
    +
    +
    --%> + + + <%-- + +
    +
    + + + +
    +
    +
    +
    + + + + +
    +
    + + + +
    +
    +
    +
    + + + +
    +
    +
    +
    + + + +
    +
    --%> + + +
    + + +
    + + Seleccione uno + Obra + Comercial + + + + +
    + +
    + +
    + +
    +
    + +
    + + + + +
    +
    +
    + +
    +
    + +
    + + + + +
    +
    +
    + +
    + +
    +
    +
    + +
    + + +
    +
    +
    + +
    + +
    +
    +
    + +
    + +
    +
    +
    + +
    + +
    +
    +
    + +
    + +
    +
    + <%--
    + +
    + +
    +
    +
    + +
    + +
    +
    --%> +
    + +
    + +
    +
    + + +
    + +
    + +
    +
    +
    + +
    +
    + +
    + +
    +
    +
    +
    +
    + +
    +
    Estatus
    +
    +
    +
    + +
    + +
    +
    + + <%--
    + +
    + + + + + + +
    +
    --%> + + + <%-- + + --%> + + +
    +
    +
    +
    + + <%-- AGREGAR FIANZA --%> + <%--
    +
    +
    +
    +
    + +
    +
    Fianzas
    + +
    +
    + +
    +
    +
    +
    + +
    + +
    + + + + + + + + + + + + + + + + + + + + + +
    +
    +
    +
    +
    +
    --%> + <%-- --%> + +
    +
    +
    +
    +
    + +
    +
    Contrato Digitalizado
    +
    +
    +
    +
    + + + + Descargar + + + + + <%-- + Archivo + --%> + + + <%-- + Archivo + --%> + + + + + +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    + + +
    +
    +
    +
    + <%--
    +
    +
    +
    +
    + + +
    +
    + + Impuestos Locales: + +
    +
    + + +
    +
    +
    +
    +
    +
    +
    + + + + + + + + + + + + + + + + + + + + + + + +
    +
    +
    +
    +
    +
    --%> +
    +
    + +
    + + + + + + + +
    + + + + + +
    + + + + + + + + + + + +
    + " style="display: inline-block; margin-right: -20px; width: 150px;" /> + " style="margin-top: -3px;" class="btn btn-circle btn-sm label-info"> +
    + + + + + + + + + + + + + + <%-- --%> + + + + + + + + + + + + + + + + + + + + + + + +
    + + Cantidad + + Producto/ServicioU. M.ObservaciónPrecio UnitarioTotalPermite AvancePermite Estimación Comandos
    + + + + + + + + + + +
    + +
    + +
    +
    + + + + + + + +
    +
    + +
    +
    + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + <%-- + + + + + --%> + + +
    + +
    +
    + + + +
    + + + + + +
    +
    + + + + + + + + +
    Total General: +
    + + + +
    + + + + +
    + + + + +
    + Cerrar
    +
    +
    +
    +
    + +
    +
    + +
    +
    + + + + + + + + + +
    + " style="display: inline-block; margin-right: -20px; width: 150px;" /> + " style="margin-top: -3px;" class="btn btn-circle btn-sm label-info"> +
    + + + + + + + + + + + + <%-- --%> + + + + + + + + + + + + + +
    CantidadLimitarClave InternaProducto/ServicioU. M.Precio UnitarioTotalPermite AvancePermite Estimación Comandos
    + + + + + + + + + +
    + +
    + +
    +
    + + + + + + +
    +
    + +
    +
    + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + <%-- + + + + + --%> + + +
    + +
    +
    + + + +
    + + + + + +
    +
    + + + + + + + + +
    Total General: +
    + + + +
    + + + + +
    + + + + +
    + Cerrar
    +
    +
    +
    +
    + +
    +
    + +
    +
    + + + Interno + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    CantidadProducto/ServicioU.M.Precio UnitarioTotalautorizadoComandos
    + + + +
    +
    + + + +
    +
    + + + + CantidadPrecio UnitarioTotal +
    +
    +
    +
    + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    + +
    +
    + + + +
    + + + + + +
    +
    + + + + + + +
    Total General: +
    + + +
    + + + + +
    + + + + +
    + Cerrar
    +
    +
    +
    +
    +
    +
    + +
    +
    + +
    + +
    + +
    + +
    + +
    + +
    Se deben guardar la informacion General para poder editar el presupuesto
    + +
    + + +
    + + + + +
    +
    + " style="display: inline-block; margin-right: -20px; width: 150px;" /> + " style="margin-top: -3px;" class="btn btn-circle btn-sm label-info"> +
    +
    + + + + +
    + + + + + + + + + +
    Clasificación Contratado Avance Faltante Avance Por Facturar Anticipo
    +
    + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    +
    + +
    +
    + + + + +
    +
    +
    +
    +
    +
    +
    + + + + + + +
    +
    +
    + +
    +
    + +
    +
    + " style="display: inline-block; margin-right: -20px; width: 150px;" /> + " style="margin-top: -3px;" class="btn btn-circle btn-sm label-info"> +
    +
    + + + + + + + + <%----%> + + + + + + + + + + + + +
    +
    + + + + +
    +
    +
    +
    + Nota: Incluye gastos manuales, salidas de almacén de suministros y de facturas. + +
    +
    +
    +
    + " style="display: inline-block; margin-right: -20px; width: 150px;" /> + " style="margin-top: -3px;" class="btn btn-circle btn-sm label-info"> +
    +
    + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    + + + + +
    + + + + + + +
    +
    + + + +   + + + + + + + + + + + + + + + +
    +
    +
    +
    + +
    +
    + + + + + + +
    +
    +
    +
    +
    +
    +
    + + + + + +
    +
    + + + +
    +
    +
    + +
    +
    + +
    + + + + + + + + + + + + + + + + + + + + + + +
    Total: + Internos: + Externos + Varlor Activo: $ + Es Interno: + + + Todos + Es Interno + Es Externo + + + +
    + +
    +
    + + +
    + + + +
    + Tipo: + + + Es Interno + Es Externo + + +
    +
    +
    + + +
    + Aun no se han registrado Activos Fijos. + +
    +
    + + + +
    + " style="display: inline-block; margin-right: -20px; width: 150px;" /> + " style="margin-top: -3px;" class="btn btn-circle btn-sm label-info"> +
    + + + +
    +
    + + + + + + + + + + + + + + + + + + + + + + + + + +
    +
    + +
    +
    + +
    +
    +
    + +
    +
    + + + + + +
    +
    +
    + Pedidos +
    +
    +
    +
    +
    +
    + +
    +
    +
    +
    +
    +
    +
    + " style="display: inline-block; margin-right: -20px; width: 150px;" /> + " style="margin-top: -3px;" class="btn btn-circle btn-sm label-info"> +
    +
    + + + + + + + + + + +
    +
    +
    +
    +
    +
    +
    + Devoluciones +
    +
    +
    +
    +
    +
    + +
    +
    +
    +
    +
    +
    +
    + " style="display: inline-block; margin-right: -20px; width: 150px;" /> + " style="margin-top: -3px;" class="btn btn-circle btn-sm label-info"> +
    +
    + + + + + + + + + + +
    +
    +
    +
    +
    + + + + + +
    +
    +
    +
    +
    +
    +
    +
    + + + + + + + + + + + + + + + + + + + + + +
    +
    +
    + Sistema + + + + + + + + + + + + + +
    Fecha de Captura: +
    Usuario Capturó: +
    Estatus: +
    +
    +
    +
    + +
    +
    + + + + +
    + + + + + + + + +   + + + +
    + +
    + + + <%-- BITACORA--%> +
    +
    +
    + +
    +
    + Bitácora +
    +
    +
    +
    + +
    +
    +
    + +
    + + + + + + + Fecha + + + + + + Fecha Agenda + + + + + + Usuario + + + + + + Descripción + + + + + + Archivo + + + + + + + + + + + + + + + + + + + + +
    +
    +
    +
    + +
    +
    + + <%--MODAL BITACORA--%> + + + + +
    + + <%-- MODAL FIANZA --%> + + + + <%--MODAL UPLOAD--%> + + + + <%--VENTAS AVANCE--%> + + + + + + + + <%--CARGA EXCEL--%> + + + + + + + + + + + + +
    + + + + + + diff --git a/Contratos/ContratoObra.aspx.vb b/Contratos/ContratoObra.aspx.vb new file mode 100644 index 000000000..2bdcf71b0 --- /dev/null +++ b/Contratos/ContratoObra.aspx.vb @@ -0,0 +1,4415 @@ +Option Explicit On +Option Strict On + +Imports Extensiones +Imports System.IO +Imports System.Data +Imports Microsoft.Reporting.WebForms +Imports System.Globalization +Imports GemBox.Spreadsheet + +Partial Class Contratos_ContratoObra + Inherits ClsPaginas + +#Region " PROPIEDADES " + Private Property CveContrato As Integer + Get + If ViewState("CveContrato") Is Nothing Then + Return 0 + Else + Return ViewState("CveContrato").ToString.ToEntero + End If + + End Get + Set(value As Integer) + ViewState("CveContrato") = value + End Set + End Property + Private Property CveTipoContrato As Integer + Get + If ViewState("CveTipoContrato") Is Nothing Then + Return 0 + Else + Return ViewState("CveTipoContrato").ToString.ToEntero + End If + + End Get + Set(value As Integer) + ViewState("CveTipoContrato") = value + End Set + End Property + Private Property CveMovimiento As Integer + Get + Return ViewState("CveMovimiento").ToString.ToEntero + End Get + Set(value As Integer) + ViewState("CveMovimiento") = value + End Set + End Property + Private Property CveMovimientoDevolucion As Integer + Get + Return ViewState("CveMovimientoDevolucion").ToString.ToEntero + End Get + Set(value As Integer) + ViewState("CveMovimientoDevolucion") = value + End Set + End Property + + Private Property FolioSugerido As String + Get + Return ViewState("FolioSugerido").ToString + End Get + Set(value As String) + ViewState("FolioSugerido") = value + End Set + End Property + + Private Property CveVenta As Integer + Get + Return ViewState("CveVenta").ToString.ToEntero + End Get + Set(value As Integer) + ViewState("CveVenta") = value + End Set + End Property + Public Property Autorizado As Boolean + Get + Return DirectCast(ViewState("Autorizado"), Boolean) + End Get + Set(value As Boolean) + ViewState("Autorizado") = value + End Set + End Property + Private Property ArchivoUpdate As String + Get + Return ViewState("ArchivoUpdate").ToString + End Get + Set(value As String) + ViewState("ArchivoUpdate") = value + End Set + End Property + Private Property TipoContrato As Integer + Get + Return ViewState("TipoContrato").ToString.ToEntero + End Get + Set(value As Integer) + ViewState("TipoContrato") = value + End Set + End Property + Private Property DtDatos As DataTable + Get + Return CType(ViewState("DtDatos"), DataTable) + End Get + Set(value As DataTable) + ViewState("DtDatos") = value + End Set + End Property + Private Property DtPlantillasContratos As DataTable + Get + Return CType(ViewState("DtPlantillasContratos"), DataTable) + End Get + Set(value As DataTable) + ViewState("DtPlantillasContratos") = value + End Set + End Property + Private Property DtPeriodo As DataTable + Get + Return CType(ViewState("DtPeriodo"), DataTable) + End Get + Set(value As DataTable) + ViewState("DtPeriodo") = value + End Set + End Property + Private Property TmpDT As DataTable + Get + Return CType(ViewState("TmpDT"), DataTable) + End Get + Set(value As DataTable) + ViewState("TmpDT") = value + End Set + End Property + + Private Property ModalidadDetalle As Integer + Get + Return DirectCast(ViewState(" ModalidadDetalle"), Integer) + End Get + Set(value As Integer) + ViewState(" ModalidadDetalle") = value + End Set + End Property + Public Property DtMovimientos() As DataTable + Get + Return CType(ViewState("DtMovimientos"), DataTable) + End Get + Set(value As DataTable) + ViewState("DtMovimientos") = value + End Set + End Property + + Public Property DtGastos() As DataTable + Get + Return CType(ViewState("DtGastos"), DataTable) + End Get + Set(value As DataTable) + ViewState("DtGastos") = value + End Set + End Property + + Public Property DtSuministros() As DataTable + Get + Return CType(ViewState("DtSuministros"), DataTable) + End Get + Set(value As DataTable) + ViewState("DtSuministros") = value + End Set + End Property + Public Property DtAvance() As DataTable + Get + Return CType(ViewState("DtAvance"), DataTable) + End Get + Set(value As DataTable) + ViewState("DtAvance") = value + End Set + End Property + + + Public Property DtPresupuestos() As DataTable + Get + Return CType(ViewState("DtPresupuestos"), DataTable) + End Get + Set(value As DataTable) + ViewState("DtPresupuestos") = value + End Set + End Property + Private Property FechaI As DateTime + Get + Return CType(ViewState("FechaI"), DateTime) + End Get + Set(value As DateTime) + ViewState("FechaI") = value + End Set + End Property + + Private Property FechaF As DateTime + Get + Return CType(ViewState("FechaF"), DateTime) + End Get + Set(value As DateTime) + ViewState("FechaF") = value + End Set + End Property + + Public Property DtActivosFijos() As DataTable + Get + Return CType(ViewState("DtActivosFijos"), DataTable) + End Get + Set(value As DataTable) + ViewState("DtActivosFijos") = value + End Set + End Property + + Private Property CvePSSerieLote As Integer + Get + Return CType(ViewState("CvePSSerieLote"), Integer) + End Get + Set(value As Integer) + ViewState("CvePSSerieLote") = value + End Set + End Property + Private Property CveUMSerieLote As Integer + Get + Return CType(ViewState("CveUMSerieLote"), Integer) + End Get + Set(value As Integer) + ViewState("CveUMSerieLote") = value + End Set + End Property + Private Property DtAvanceDocumento As DataTable + Get + Return CType(ViewState("DtAvanceDocumento"), DataTable) + End Get + Set(value As DataTable) + ViewState("DtAvanceDocumento") = value + End Set + End Property + Private Property Titulo As String + Get + Return ViewState("Titulo").ToString + End Get + Set(value As String) + ViewState("Titulo") = value + End Set + End Property + Private Property TituloCorto As String + Get + Return ViewState("TituloCorto").ToString + End Get + Set(value As String) + ViewState("TituloCorto") = value + End Set + End Property + + Private Property TipoDocumento As String + Get + Return ViewState("TipoDocumento").ToString + End Get + Set(value As String) + ViewState("TipoDocumento") = value + End Set + End Property + + Private Property Contratante As String + Get + Return ViewState("Contratante").ToString + End Get + Set(value As String) + ViewState("Contratante") = value + End Set + End Property + Private Property SumaAvance As Double + Get + Return If(ViewState("SumaAvance") IsNot Nothing, ViewState("SumaAvance").ToString.ToDouble, 0) + End Get + Set(value As Double) + ViewState("SumaAvance") = value + End Set + End Property + Private Property SumaUtilidad As Double + Get + Return If(ViewState("SumaUtilidad") IsNot Nothing, ViewState("SumaUtilidad").ToString.ToDouble, 0) + End Get + Set(value As Double) + ViewState("SumaUtilidad") = value + End Set + End Property + Private Property SumaGasto As Double + Get + Return If(ViewState("SumaGasto") IsNot Nothing, ViewState("SumaGasto").ToString.ToDouble, 0) + End Get + Set(value As Double) + ViewState("SumaGasto") = value + End Set + End Property + Private Property NumRow As Integer + + Private Property EsEditarFianza As Boolean + Get + Return CType(ViewState("EsEditarFianza"), Boolean) + End Get + Set(value As Boolean) + ViewState("EsEditarFianza") = value + End Set + End Property + Private Property IndexFianzaEditar As Integer + Get + Return CType(ViewState("IndexFianzaEditar"), Integer) + End Get + Set(value As Integer) + ViewState("IndexFianzaEditar") = value + End Set + End Property + Public Property DtTmpFianzas() As DataTable + Get + Return CType(ViewState("DtTmpFianzas"), DataTable) + End Get + Set(value As DataTable) + ViewState("DtTmpFianzas") = value + End Set + End Property + Public Property DtTmpFianzasInicial() As DataTable + Get + Return CType(ViewState("DtTmpFianzasInicial"), DataTable) + End Get + Set(value As DataTable) + ViewState("DtTmpFianzasInicial") = value + End Set + End Property + Private Property MensajeAlert As StringBuilder + Get + Return CType(ViewState("MensajeAlert"), StringBuilder) + End Get + Set(value As StringBuilder) + ViewState("MensajeAlert") = value + End Set + End Property + Private Property DsDatosPedDev As DataSet + Get + DsDatosPedDev = DirectCast(ViewState("DsDatosPedDev"), DataSet) + End Get + + Set(ByVal value As DataSet) + ViewState("DsDatosPedDev") = value + End Set + End Property + + Private Property CveSubProyecto As Integer + Get + + If ViewState("CveSubProyecto") Is Nothing Then + Return -1 + Else + Return CType(ViewState("CveSubProyecto"), Integer) + End If + End Get + Set(value As Integer) + ViewState("CveSubProyecto") = value + End Set + End Property + + +#End Region + + Protected Sub Page_Load(sender As Object, e As System.EventArgs) Handles Me.Load + If Not IsPostBack Then + CargaValoresIniciales() + CreaDtTmpFianzas() + + If Request("CveCliente") IsNot Nothing Then + cargaClientes() + End If + + If Request("CveContrato") IsNot Nothing AndAlso IsNumeric(Request("CveContrato")) AndAlso Request("CveContrato").ToEntero > 0 Then + ViewState("CveContrato") = Request("CveContrato") + + DvBitacora.Visible = True + DdlEstatus.Enabled = False + If UsuarioActual.TienePermisoProceso(126) Then + BtnAutorizar.Visible = True + End If + DivContent.Visible = True + ' DivTipoContrato.Visible = False + 'TxtArchivo.Visible = True + + CargaDatos() + + CargaDatosAvance() + CargaDatosAvancePorDocumento() + CargaInventarios() + + '12/04/2018 - Si el tipo de contrato es convenio de precio fijo configura campos + If CveTipoContrato = 28 Then + CargaConvenioPrecioFijo() + End If + + 'Configuración de Modalidad Update + BtnGuardar.Text = "Guardar Cambios" + + If Request("Opt") IsNot Nothing AndAlso IsNumeric(Request("Opt")) Then TAB.ActiveTabIndex = Request("Opt").ToEntero + Else + 'Configuración de Modalidad Insert + LblFechaCaptura.Text = Now.ToShortDateString() + LblUsuarioCapturo.Text = UsuarioActual.Usuario + ViewState("CveContrato") = -1 + + DvBitacora.Visible = False + TabContratosGastos.Visible = False + TabAF.Visible = False + TabReporteAvance.Visible = False + TabAvanveDocumento.Visible = False + + TAB.ActiveTabIndex = 0 + + 'If UsuarioActual.Empresa.CvePlataforma = 3 Then + ' rdventa.Checked = True + ' rdventa_CheckedChanged(Nothing, Nothing) + ' If (DdlTipoContrato.Items.FindByValue("14") Is Nothing) Then + ' DdlTipoContrato.Items.Insert(1, New ListItem("Contrato de Cuenta y Equipo", "14")) + ' End If + ' DdlTipoContrato.SelectedValue = "14" + ' TipoContrato = 14 + ' BtnTipoContrato_Click(Nothing, Nothing) + 'End If + + End If + + 'carga combos + CargaClasificaciones() + CargaPS() + CargaPSInsumos() + ConfiguraTipos() + CargaDatosEncabezado() + ' CargaImpuestosLocales() + + End If + + + '[IPP] PORQUE ESTA TODO ESTO EN TODOS LOS POSTBACK ??? - REVISEN BIEN DONDE PONEN EL CODIGO + + If UsuarioActual.TienePermisoProceso(165) Then + BtnGuardar.Visible = True + Else + BtnGuardar.Visible = False + End If + + If CveContrato > 0 Then + If UsuarioActual.TienePermisoProceso(164) Then + BtnEliminar.Visible = True + Gv.Columns(11).Visible = True + GvInsumos.Columns(9).Visible = True + Else + BtnEliminar.Visible = False + Gv.Columns(11).Visible = False + GvInsumos.Columns(9).Visible = False + End If + + 'If CveTipoContrato.Contiene(11, 25) Then 'ciclo comercial + ' Gv.Columns(9).Visible = False + ' GvInsumos.Columns(8).Visible = False + 'End If + + Else + TabPres.Visible = False + Gv.Columns(11).Visible = True + GvInsumos.Columns(9).Visible = True + + End If + + End Sub + +#Region " CARGA VALORES INICIALES " + Private Sub CargaValoresIniciales() + CveContrato = -1 + ViewState("TipoContrato") = 0 + CveVenta = -1 + Autorizado = False + BtnAutorizar.Visible = False + Session("FileUpload") = "" + Session("FileExtension") = "" + Session("FileFolder") = "" + ArchivoUpdate = "" + ModalidadDetalle = 1 + FolioSugerido = "" + + CargaProyecto() + CargaContratista() + ' CargaVendedores() + + DdlUM.DataSource = GlobalDTUnidadesMedida(UsuarioActual.CveEmpresa) + DdlUM.DataBind() + DdlMoneda.DataSource = GlobalDTMonedas + DdlMoneda.DataBind() + + + ' CargaContratoPadre() + CargaContratosEstatus() + CreaDT() + + 'DdlAlmacenOrigen.Items.Insert(0, New ListItem("Seleccione", "-1")) + 'DdlAlmacenDestino.Items.Insert(0, New ListItem("Seleccione", "-1")) + + 'If UsuarioActual.TienePermisoProceso(172) Then + ' RowPorcentajeComision.Visible = True + 'End If + If UsuarioActual.CveEmpresa.Contiene(72, 80) Then divResponsable.Visible = False + + End Sub + + 'Public Sub CargaDireccionesEnvios(CveCliente As Integer) + ' Dim ObjVentas As New ClsClientes + ' If ObjVentas.DireccionEnvioGet(-1, CveCliente, -1) Then + + ' If ObjVentas.DtResultados.Rows.Count > 0 Then + ' DdlClienteDireccionEnvio.DataSource = ObjVentas.DtResultados + ' DdlClienteDireccionEnvio.DataBind() + ' DivClienteDireccion.Visible = True + ' Else + ' DivClienteDireccion.Visible = False + ' End If + + ' End If + ' ObjVentas.Dispose() + ' UpGral.Update() + 'End Sub + + Protected Sub DdlMoneda_SelectedIndexChanged(sender As Object, e As EventArgs) Handles DdlMoneda.SelectedIndexChanged + + If DdlMoneda.SelectedIndex = 0 Then + tipoCambio.Visible = False + TxtTipoCambio.Text = "" + UpGral.Update() + Else + tipoCambio.Visible = True + TxtTipoCambio.Text = "" + UpGral.Update() + End If + End Sub + Public Function isWithFamily() As Boolean + Return UsuarioActual.CveEmpresa = 66 + End Function + Private Sub cargaClientes() + TrCliente.Visible = True + TrProveedor.Visible = False + DdlCliente.DataSource = GlobalDTCliente(UsuarioActual.CveEmpresa, -1) + DdlCliente.DataBind() + End Sub + Private Sub CreaDT() + TmpDT = New DataTable + TmpDT.Columns.Add("CveContratoDetalle", GetType(Integer)) + TmpDT.Columns.Add("Cantidad", GetType(Double)) + TmpDT.Columns.Add("CantidadContratada", GetType(Double)) + TmpDT.Columns.Add("CveUM", GetType(Integer)) + TmpDT.Columns.Add("UM", GetType(String)) + TmpDT.Columns.Add("CveClasificacion", GetType(Integer)) + TmpDT.Columns.Add("Clasificacion", GetType(String)) + TmpDT.Columns.Add("CvePS", GetType(Integer)) + TmpDT.Columns.Add("PS", GetType(String)) + TmpDT.Columns.Add("CodigoPS", GetType(String)) + TmpDT.Columns.Add("PU", GetType(Double)) + TmpDT.Columns.Add("Total", GetType(Double)) + TmpDT.Columns.Add("CveTipoPresupuesto", GetType(Integer)) + TmpDT.Columns.Add("PermitirAvance", GetType(Integer)) + TmpDT.Columns.Add("PermitirEstimacion", GetType(Integer)) + TmpDT.Columns.Add("UsuarioAvance", GetType(Integer)) + TmpDT.Columns.Add("Cantidad_Original", GetType(Double)) + TmpDT.Columns.Add("PU_Original", GetType(Double)) + TmpDT.Columns.Add("Total_Original", GetType(Double)) + TmpDT.Columns.Add("NoIdentificacion", GetType(String)) + TmpDT.Columns.Add("LimitarCantidad", GetType(Integer)) + TmpDT.Columns.Add("OCInterna", GetType(String)) + TmpDT.Columns.Add("Observacion", GetType(String)) + End Sub + Protected Sub Limpiar() + TxtNumeroContrato.Text = "" + TxtDescripcionContrato.Text = "" + DdlContratista.SelectedValue = "-1" + DdlCliente.SelectedValue = "-1" + TxtFechaInicial.Text = "" + TxtFechaFinal.Text = "" + TxtPorIVA.Text = "" + 'txtMinimo.Text = "" + 'txtMaximo.Text = "" + 'TxtArchivo.Text = "" + + DdlProyecto.SelectedValue = "-1" + 'DdlSubProyectoContrato.SelectedValue = "-1" + 'DdlContratoPadre.SelectedValue = "-1" + + 'Tab Presupuesto + TxtCantidad.Text = "" + TxtPU.Text = "" + TmpDT.Clear() + CargaGVPresupuestos(TmpDT) + CargaGVPresupuestosInsumos(TmpDT) + LbTotalGeneral.Text = "0.00" + End Sub +#End Region + +#Region " CONFIGURA TIPOS CONTRATO " + + Private Sub ConfiguraTipos() + If Not TipoContrato.Contiene({7, 9, 13, 16, 18, 21}) Then + TabAF.Visible = False + End If + 'TabContratosGastos.Visible = False + + 'DONDE OCUPA ALMACEN + Dim CveTipoAlmacenOrigen = "12,15" + Dim CveTipoAlmacenDestino = "11,12" + + 'If TipoContrato.Contiene({7, 9, 13, 16, 18, 21, 27}) Then + ' RowAlmacen.Visible = True + ' If TipoContrato.Contiene(7, 9, 13, 21, 27) Then + ' If TipoContrato.Contiene(27) Then + ' CveTipoAlmacenOrigen = "1" + ' CveTipoAlmacenDestino = "17" + ' End If + ' RowAlmacenOrigen.Visible = True + ' End If + 'End If + + 'Dim CveOrigen = DdlAlmacenOrigen.SelectedValue + 'DdlAlmacenOrigen.Items.Clear() + 'DdlAlmacenOrigen.SelectedValue = "-1" + 'DdlAlmacenOrigen.Items.Insert(0, New ListItem("Seleccione", "-1")) + 'DdlAlmacenOrigen.DataSource = GlobalDTAlmacen(UsuarioActual.CveEmpresa).FiltraParametros($"CveTipoAlmacen IN ({CveTipoAlmacenOrigen})") ' GlobalDTAlmacenUsuarios(UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa, -1) 'GlobalDTAlmacen(UsuarioActual.CveEmpresa) + 'DdlAlmacenOrigen.DataBind() + 'DdlAlmacenOrigen.SelectedValueExist(CveOrigen) + ''SI EL ALMACEN ANTERIOR DEL CONTRATO NO ESTA EN LOS ALMACENES ACTUALES LO INSERTA A FUERZAS + 'If DdlAlmacenOrigen.SelectedValue <> CveOrigen Then + ' DdlAlmacenOrigen.Items.Insert(1, New ListItem(GlobalDTAlmacen(UsuarioActual.CveEmpresa).FiltroPrimeroValor("Almacen", $"CveAlmacen = {CveOrigen}"), CveOrigen)) + ' DdlAlmacenOrigen.SelectedValueExist(CveOrigen) + 'End If + + 'Dim CveDestino = DdlAlmacenDestino.SelectedValue + 'DdlAlmacenDestino.Items.Clear() + 'DdlAlmacenDestino.SelectedValue = "-1" + 'DdlAlmacenDestino.Items.Insert(0, New ListItem("Seleccione", "-1")) + 'DdlAlmacenDestino.DataSource = GlobalDTAlmacen(UsuarioActual.CveEmpresa).FiltraParametros($"CveTipoAlmacen In ({CveTipoAlmacenDestino})") 'GlobalDTAlmacenUsuarios(UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa, -1) + 'DdlAlmacenDestino.DataBind() + 'DdlAlmacenDestino.SelectedValueExist(CveDestino) + ''SI EL ALMACEN ANTERIOR DEL CONTRATO NO ESTA EN LOS ALMACENES ACTUALES LO INSERTA A FUERZAS + 'If DdlAlmacenDestino.SelectedValue <> CveDestino Then + ' DdlAlmacenDestino.Items.Insert(1, New ListItem(GlobalDTAlmacen(UsuarioActual.CveEmpresa).FiltroPrimeroValor("Almacen", $"CveAlmacen = {CveDestino}"), CveDestino)) + ' DdlAlmacenDestino.SelectedValueExist(CveDestino) + 'End If + + End Sub + + Private Sub MuestraPermiteAvance() + + 'If Not TipoContrato.Contiene({4, 5, 25, 11}) Then + ' Gv.Columns(9).Visible = False + ' GvInsumos.Columns(7).Visible = False + ' THAvance.Style.Add("display", "none") + ' TDAvance.Style.Add("display", "none") + ' THAvance.Visible = False + ' THAvanceInsumos.Visible = False + ' ' tdCol7.Visible = False + ' TDAvance.Visible = False + ' TDAvanceInsumos.Visible = False + 'Else + ' Gv.Columns(9).Visible = True + ' GvInsumos.Columns(6).Visible = True + ' THAvance.Visible = True + ' THAvanceInsumos.Visible = True + ' 'tdCol7.Visible = True + ' TDAvance.Visible = True + ' TDAvanceInsumos.Visible = True + 'End If + 'UpTitulos.Update() + 'UpGral.Update() + End Sub + +#End Region + +#Region " PANTALLA INICIAL" + 'Protected Sub rpCompra_CheckedChanged(sender As Object, e As EventArgs) Handles rpCompra.CheckedChanged + ' loadComboTipoContrato(False) + 'End Sub + 'Protected Sub rdventa_CheckedChanged(sender As Object, e As EventArgs) Handles rdventa.CheckedChanged + ' loadComboTipoContrato(True) + 'End Sub + + 'Private Sub loadComboTipoContrato(venta As Boolean) + ' Try + ' If venta Then + ' DdlTipoContrato.DataSource = GlobalDTContratosTipos(UsuarioActual.CveEmpresa).FiltraParametros(" TipoMovimiento = 1") + + ' Else + ' DdlTipoContrato.DataSource = GlobalDTContratosTipos(UsuarioActual.CveEmpresa).FiltraParametros(" TipoMovimiento = 0") + ' End If + ' dvDetContrato.Visible = True + ' ' DdlTipoContrato.Visible = True + ' DdlTipoContrato.DataBind() + ' DdlTipoContrato.Items.Insert(0, New ListItem("Seleccione una opción", "-1")) + ' If UsuarioActual.CveEmpresa.Contiene(1, 11, 4, 12) And venta Then + ' DdlTipoContrato.Items.Insert(1, New ListItem("Contrato con facturación ciclica", "25")) + ' End If + ' UPTipo.Update() + ' Catch ex As Exception + ' Alert(ex.Message, TipoMensaje.MsgError) + + ' End Try + 'End Sub + +#End Region + +#Region " INICIO DE PAGINA " + + 'Protected Sub DdlTipoContrato_SelectedIndexChanged(sender As Object, e As EventArgs) + ' CargaTipoContrato() + + ' '12/04/2018 - Se configuran campos de convenio de precio fijo + ' If DdlTipoContrato.SelectedValue = "28" Then + ' CargaConvenioPrecioFijo() + ' End If + + ' If UsuarioActual.CveEmpresa = 72 And DdlTipoContrato.SelectedValue.Contiene("7", "8", "10", "13", "28") Then + ' GetNoContratoNuevo() + ' End If + + 'End Sub + + + 'Private Sub CargaTipoContrato() + ' If DdlTipoContrato.SelectedIndex = 0 Then + ' TxtDescripcionTipoContrato.Text = "" + ' Exit Sub + ' End If + + ' TipoContrato = DdlTipoContrato.SelectedValue.ToEntero + ' If GlobalDTContratosTipos(UsuarioActual.CveEmpresa).FiltraParametros("CveContratoTipo = " & DdlTipoContrato.SelectedValue).Rows.Count > 0 Then + ' TxtDescripcionTipoContrato.Text = GlobalDTContratosTipos(UsuarioActual.CveEmpresa).FiltraParametros("CveContratoTipo = " & DdlTipoContrato.SelectedValue)(0)("Descripcion").ToString() + ' TxtDescripcionTipoContrato.Visible = True + ' End If + + + ' CargaContratoPadre() + ' UpProyecto.Update() + 'End Sub + + Private Sub modalidades(modalidadDetalleInt As Integer) + + If modalidadDetalleInt = 1 Then + ModalidadDetalle = 1 + + ' DvMax.Visible = True + ' DvMin.Visible = True + DvTotal.Visible = True + + + If CveContrato > 0 AndAlso CveTipoContrato <> 25 Then + TableDatosCabecera.Visible = True + End If + + If CveTipoContrato = 25 Then + 'DvMax.Visible = False + ' DvMin.Visible = False + DvTotal.Visible = False + + ' DivFianzas.Visible = False + 'DivImpuestosLocales.Visible = False + End If + + ElseIf modalidadDetalleInt = 2 Then + ModalidadDetalle = 2 + + ' DvMax.Visible = True + ' DvMin.Visible = True + DvTotal.Visible = True + 'TxtCantidad.Visible = False + + If CveContrato > 0 AndAlso CveTipoContrato <> 25 Then + TableDatosCabecera.Visible = True + End If + + If CveTipoContrato = 25 Then + ' DvMax.Visible = False + ' DvMin.Visible = False + DvTotal.Visible = False + + ' DivFianzas.Visible = False + ' DivImpuestosLocales.Visible = False + End If + + End If + + UpGral.Update() + + End Sub + + + 'Protected Sub chkDetalleContrato_CheckedChanged(sender As Object, e As EventArgs) + ' If chkDetalleContrato.Checked = False Then + ' modalidades(1) + ' Else + ' modalidades(2) + ' End If + 'End Sub + + 'Protected Sub BtnTipoContrato_Click(sender As Object, e As EventArgs) Handles BtnTipoContrato.Click + ' If DdlTipoContrato.SelectedIndex = 0 Then + ' Alert("Tiene que seleccionar un tipo de Contrato.", TipoMensaje.MsgAdvertencia) + ' Exit Sub + ' End If + + ' Me.CveTipoContrato = DdlTipoContrato.SelectedValue.ToEntero + + + + ' If rpCompra.Checked Then + + ' Response.Redirect($"/Contratos/Presupuestos.aspx?CveContrato=-1&CveContratoTipo={Me.CveTipoContrato}") + ' 'RegistraScript("window.location='/Contratos/Presupuestos.aspx") + ' Else + + ' modalidades(1) + + ' DivTipoContrato.Visible = False + + ' If rdventa.Checked Then + ' DdlCliente.Visible = True + ' TrCliente.Visible = True + + ' DdlContratista.Visible = False + ' TrProveedor.Visible = False + + + ' Else + ' DdlCliente.Visible = False + ' TrCliente.Visible = False + + ' TrProveedor.Visible = True + ' DdlContratista.Visible = True + ' End If + + ' If rdventa.Checked Then + ' cargaClientes() + ' Else + ' CargaContratista() + ' End If + + ' If DdlTipoContrato.SelectedValue = "14" Then + ' TrCtaEquipo.Visible = True + ' TrPeriodo.Visible = True + ' RFVEstatus.ValidationGroup = "" + ' RequiredFieldValidator1.ValidationGroup = "" + ' DvMin.Visible = True + ' DvMax.Visible = True + ' DvTotal.Visible = True + ' RowFlexible.Visible = False + ' RowEstatus.Visible = False + ' RowPorcentajeComision.Visible = False + ' dvAddendum.Visible = False + ' CargaPeriodos() + ' CargaPlantillas() + ' TrContratoPlantilla.Visible = True + ' TabPres.HeaderText = "Partidas" + ' Else + ' DtPeriodo = Nothing + ' End If + + + ' If DdlTipoContrato.SelectedValue = "25" Then + ' trLicitacion.Visible = False + ' divResponsable.Visible = False + ' TrPeriodo.Visible = True + ' CargaPeriodos() + ' trIva.Visible = False + ' trAnticipo.Visible = False + ' trAmortizacion.Visible = False + ' trPorGarantia.Visible = False + ' DvMin.Visible = False + ' RowFlexible.Visible = False + ' RowPorcentajeComision.Visible = False + ' DvMax.Visible = False + ' DvTotal.Visible = False + ' RowEstatus.Visible = False + ' TabPres.HeaderText = "Partidas" + ' DdlSubProyectoContrato.AutoPostBack = True + ' DvObservaciones.Visible = True + ' End If + + ' 'Dim CveTipoContrato = DdlTipoContrato.SelectedValue + + ' 'Dim TipoMov = GlobalDTContratosTipos.AsEnumerable().Where(Function(a) a("CveContratoTipo").ToString = CveTipoContrato).FirstOrDefault()("TipoMovimiento") + + + ' DivContent.Visible = True + ' ConfiguraTipos() + + + ' UpGral.Update() + ' 'UPTipo.Update() + ' End If + + 'End Sub + + + 'Protected Sub DdlSubProyectoContrato_SelectedIndexChanged(sender As Object, e As EventArgs) Handles DdlSubProyectoContrato.SelectedIndexChanged + ' Dim ObjFolios As New ClsGralFolios + ' If ObjFolios.GetFolios("Con", UsuarioActual.CveEmpresa) Then + ' If ObjFolios.DtResultados.FiltraParametros($"CveSubProyecto = {DdlSubProyectoContrato.SelectedValue}").Rows.Count > 0 Then + ' FolioSugerido = $"{GlobalDTSubProyectos(-1, DdlSubProyectoContrato.SelectedValue.ToEntero).FiltroPrimeroValor("Serie")}-{ObjFolios.DtResultados.FiltroPrimeroValor("FActual", $"CveSubProyecto = {DdlSubProyectoContrato.SelectedValue}")}" + ' TxtNumeroContrato.Text = FolioSugerido + ' Else + ' Alert("La sucursal no cuenta con folios de contratos", TipoMensaje.MsgAdvertencia) + ' End If + ' End If + ' ObjFolios.Dispose() + ' UpGral.Update() + 'End Sub +#End Region + +#Region " CARGA DATOS " + Private Sub CargaDatos() + Dim ObjContratos As New ClsContratos() + Dim Ruta = Request.ApplicationPath + "Empresas\" & UsuarioActual.CveEmpresa & "\Contratos\" + 'DivTipoContrato.Visible = False + + If ObjContratos.GetContratos(CveContrato, UsuarioActual.CveEmpresa) Then + If ObjContratos.DtResultados.Rows.Count > 0 Then + + GRidsPresupuestos.Visible = True + msjpresupuestos.Visible = False + + If ArchivoUpdate = ObjContratos.Archivo.ToString Then + LinkArchivo.Visible = True + LinkArchivo.HRef = String.Format("{0}{1}", Ruta, ObjContratos.Archivo.ToString) + End If + Titulo = $"{ObjContratos.NumeroContrato} - {ObjContratos.DescripcionContrato} ({ObjContratos.DtResultados.Rows(0)("ContratoTipo")})" + TituloCorto = $"{ObjContratos.NumeroContrato} - {ObjContratos.DescripcionContrato} " + TipoDocumento = ObjContratos.DtResultados.Rows(0)("ContratoTipo").ToString + LtlTitulo.Text = $"Contrato: {Titulo})" + 'Pestaña Datos Generales + TxtObservaciones.Text = ObjContratos.Observaciones + TxtDescripcionContrato.Text = ObjContratos.DescripcionContrato + TxtNumeroContrato.Text = ObjContratos.NumeroContrato + TxtNumeroLicitacion.Text = ObjContratos.NumeroLicitacion + TipoContrato = ObjContratos.CveContratoTipo + ' TxtPorcentajeComision.Text = ObjContratos.PorcentajeComision.ToString + CveTipoContrato = ObjContratos.DtResultados.Rows(0)("CveContratoTipo").ToString.ToEntero + TxtCorreoNotificacion.Text = ObjContratos.DtResultados.Rows(0)("CorreoNotificacionPedDev").ToString + + + If ObjContratos.CveProveedor > 0 Then + TrProveedor.Visible = True + TrCliente.Visible = False + CargaContratista() + DdlContratista.SelectedValue = ObjContratos.CveProveedor.ToString + Else + cargaClientes() + DdlCliente.SelectedValueExist(ObjContratos.CveCliente.ToString) + UpGral.Update() + CargaSucursalCliente() + DdlSucursalCliente.SelectedValue = ObjContratos.CveSucursalCliente.ToString + End If + + + 'If DdlCliente.SelectedValue.ToEntero > 0 Then + ' CargaDireccionesEnvios(DdlCliente.SelectedValue.ToEntero) + ' DdlClienteDireccionEnvio.SelectedValueExist(ObjContratos.DtResultados.Rows(0)("CveDireccionEnvio").ToString.ToEntero) + 'End If + + 'CargaContratoPadre() + CargaContratoAddendum() + + If ObjContratos.DtResultados.Rows(0)("CveContratoTipo").ToString.ToEntero = 14 Then + ' CargaPeriodos() + 'TrCtaEquipo.Visible = True + ' TrPeriodo.Visible = True + RFVEstatus.ValidationGroup = "" + ' RequiredFieldValidator1.ValidationGroup = "" + ' DvMin.Visible = True + ' DvMax.Visible = True + DvTotal.Visible = True + 'RowFlexible.Visible = False + 'RowPorcentajeComision.Visible = False + RowEstatus.Visible = False + 'dvAddendum.Visible = False + liImprimir.Visible = True + CargaPlantillas() + 'TrContratoPlantilla.Visible = True + 'DdlPeriodo.SelectedValueExist(ObjContratos.DtResultados.Rows(0)("CvePeriodo")) + 'DdlCuentaEquipo.SelectedValueExist(ObjContratos.DtResultados.Rows(0)("CveCuentaEquipo")) + 'DdlPlantillaContrato.SelectedValueExist(ObjContratos.DtResultados.Rows(0)("CveContratoPlantilla")) + TabPres.HeaderText = "Partidas" + End If + + If ObjContratos.DtResultados.Rows(0)("CveContratoTipo").ToString.ToEntero = 25 Then + trLicitacion.Visible = False + divResponsable.Visible = False + 'TrPeriodo.Visible = True + 'CargaPeriodos() + trIva.Visible = False + trAnticipo.Visible = False + trAmortizacion.Visible = False + trPorGarantia.Visible = False + 'DvMin.Visible = False + ' DvMax.Visible = False + DvTotal.Visible = False + TabPVInsumos.Visible = False + RowEstatus.Visible = False + TabPres.HeaderText = "Partidas" + thOcCliente.Style.Add("display", "none") + tdOcCliente.Style.Add("display", "none") + thNoIdentificacionv.Style.Add("display", "none") + thLimitar.Style.Add("display", "none") + tdLimitar2.Style.Add("display", "none") + tdNoIdentificacionv.Style.Add("display", "none") + 'RowFlexible.Visible = False + TableDatosCabecera.Visible = False + TabAvanveDocumento.Visible = False + TabSistema.Visible = False + 'RowPorcentajeComision.Visible = False + TabContratosGastos.Visible = False + tdCveInterna.Text = "" + tdLimitar.Text = "" + tdOC.Text = "" + THAvance.Visible = False + THAvance.Style.Add("display", "none") + TDAvance.Style.Add("display", "none") + TxtOCInterna.Visible = False + TxtNoIdentificacionv.Visible = False + ChkLimitarVenta.Visible = False + DvObservaciones.Visible = True + TDObservacion.Visible = True + tdObservaciones.Visible = True + TxtObservaciones.Text = ObjContratos.DtResultados.Rows(0)("Observaciones").ToString + Gv.Columns(6).Visible = True + 'DdlPeriodo.SelectedValueExist(ObjContratos.DtResultados.Rows(0)("CvePeriodo").ToString) + End If + + 'If ObjContratos.DtResultados.Rows(0)("CveVendedor").ToString.ToEntero > 0 Then + ' DdlVendedor.SelectedValueExist(ObjContratos.DtResultados.Rows(0)("CveVendedor")) + 'End If + + + 'If (DdlAlmacenDestino.Items.FindByValue(ObjContratos.CveAlmacen.ToString()) Is Nothing) Then + ' Dim dr As DataRow = GlobalDTAlmacen(UsuarioActual.CveEmpresa).FiltroPrimero(String.Format("CveAlmacen = {0}", ObjContratos.CveAlmacen)) + ' If dr IsNot Nothing Then + ' DdlAlmacenDestino.Items.Insert(1, New ListItem(dr("Almacen").ToString, dr("CveAlmacen").ToString)) ' lo genera Obj.SelectedValue = Valor.ToString + ' End If + 'End If + 'DdlAlmacenDestino.SelectedValue = ObjContratos.CveAlmacen.ToString + + 'If (DdlAlmacenOrigen.Items.FindByValue(ObjContratos.CveAlmacenOrigen.ToString()) Is Nothing) Then + ' Dim dr As DataRow = GlobalDTAlmacen(UsuarioActual.CveEmpresa).FiltroPrimero(String.Format("CveAlmacen = {0}", ObjContratos.CveAlmacenOrigen)) + ' If dr IsNot Nothing Then + ' DdlAlmacenOrigen.Items.Insert(1, New ListItem(dr("Almacen").ToString, dr("CveAlmacen").ToString)) ' lo genera Obj.SelectedValue = Valor.ToString + ' End If + 'End If + 'DdlAlmacenOrigen.SelectedValue = ObjContratos.CveAlmacenOrigen.ToString + + FechaF = ObjContratos.FechaFinal + FechaI = ObjContratos.FechaInicial + TxtFechaFinal.Text = ObjContratos.FechaFinal.ToShortDateString + TxtFechaInicial.Text = ObjContratos.FechaInicial.ToShortDateString + TxtUbicacion.Text = ObjContratos.Ubicacion + TxtResponsable.Text = ObjContratos.Responsable + TxtPorAnticipo.Text = ObjContratos.PorAmortizacionAnticipo.FormatoNumero + TxtPorAmortizacionAnticipo.Text = ObjContratos.PorAmortizacionAnticipo.FormatoNumero + TxtPorGarantia.Text = ObjContratos.PorGarantia.FormatoNumero + DdlProyecto.SelectedValue = ObjContratos.CveProyecto.ToString + LblSubProyecto.Text = ObjContratos.SubProyectoContrato + DdlTipoContratoObra.SelectedValueExist(ObjContratos.CveContratoTipo) + 'CargaSubProyectoContrato(DdlProyecto.SelectedValue.ToEntero) + + 'DdlSubProyectoContrato.SelectedValue = ObjContratos.CveSubProyecto.ToString + + + + TxtPorIVA.Text = ObjContratos.PorIVA.ToString + 'txtMinimo.Text = ObjContratos.Minimo.FormatoNumero + 'txtMaximo.Text = ObjContratos.Maximo.FormatoNumero + TxtTotal.Text = ObjContratos.Importe.FormatoNumero + 'TxtArchivo.Text = ObjContratos.Archivo + 'DdlTipoGarantia.SelectedValueExist(ObjContratos.TipoGarantia) + 'DdlEstatusFianza.SelectedValueExist(ObjContratos.EstatusFianza) + 'TxtFolio.Text = ObjContratos.Folio.ToString + 'txtFechaVenc.Text = ObjContratos.FechaVenc.ToString + DdlEstatus.SelectedValueExist(ObjContratos.CveContratosEstatus.ToString) + CargarFianzas() + + If ObjContratos.TipoEstatus = 2 Then + DdlEstatus.Enabled = False + If UsuarioActual.TienePermisoProceso(173) Then + liVigenteContrato.Visible = True + LBVigenteContrato.Visible = True + End If + Else + DdlEstatus.Items.Clear() + 'Se esta ocultando concluido' + DdlEstatus.DataSource = CType(DdlEstatus.DataSource, DataTable).FiltraParametros("TipoEstatus NOT IN (2)") + DdlEstatus.DataBind() + Select Case ObjContratos.TipoEstatus + Case 1 + If UsuarioActual.TienePermisoProceso(173) Then + liTerminarContrato.Visible = True + LBTerminarContrato.Visible = True + + liCancelarContrato.Visible = True + LBCancelarContrato.Visible = True + End If + Case 2, 3 ' reactivar el contrato + If UsuarioActual.TienePermisoProceso(173) Then + liVigenteContrato.Visible = True + LBVigenteContrato.Visible = True + End If + End Select + + End If + TxtTipoCambio.Text = ObjContratos.TipoCambio.ToString + + ModalidadDetalle = ObjContratos.ModalidadDetalle + 'chkDetalleContrato.Checked = If(ModalidadDetalle = 2, True, False) + 'ChkImpuestosLocales.Checked = ObjContratos.AplicaImpuestosLocales + 'GvImpuestosLocales.Visible = ObjContratos.AplicaImpuestosLocales + modalidades(ModalidadDetalle) + + CargaGVGastos() + + DdlMoneda.SelectedValue = ObjContratos.CveMoneda.ToString + If DdlMoneda.SelectedIndex > 0 Then + tipoCambio.Visible = True + End If + + + If ObjContratos.CveProveedor > 0 Then + Contratante = ObjContratos.RazonSocial.ToString + Else + Contratante = ObjContratos.NombreComercial.ToString + End If + + 'AFU.Visible = False + + 'TxtArchivo.Text = ObjContratos.Archivo.ToString + + 'ChkEstatusContrato.Checked = CBool(ObjContratos.EstatusContrato) + 'DdlContratoPadre.SelectedValue = ObjContratos.CveContratoPadre.ToString + LblFechaCaptura.Text = ObjContratos.FechaIng.ToShortDateString + 'HplSecciones.NavigateUrl = "/Contratos/ContratosSecciones.aspx?CveContrato=" & CveContrato + 'CargaDatosPresup() + + CargaPresupuesto() + ' MuestraPermiteAvance() + cargarBitacora() + If LblImporte.Text.ToDecimal <= 0 Then + LblImporte.Text = ObjContratos.ImporteTotal.ToString.FormatoNumero + End If + + If Not IsDBNull(ObjContratos.Archivo) AndAlso ObjContratos.Archivo <> "" AndAlso ObjContratos.Archivo <> "-1" AndAlso ObjContratos.Archivo <> $"{ObjContratos.CveContrato}." Then + ViewState("FUrl") = Path.Combine(UsuarioActual.Empresa.Ruta, "CONTRATOS", ObjContratos.Archivo) + 'A2.NavigateUrl = String.Format("/Compras/PopUpVerFactura.aspx?P={0}", Encripta(String.Format("OP=CONTRATO&CveEmpresa={0}&Archivo={1}", ObjContratos.CveEmpresa, ViewState("FUrl").ToString))) + BtnDescargar.Visible = True + Else + BtnDescargar.Visible = False + A1.Visible = True + End If + + + DVSubProyecto.Visible = True + DVddlproyecto.Visible = False + + Else + CveContrato = -1 + Alert("El Contrato Solicitado no existe, por favor revise su búsqueda.", TipoMensaje.MsgAdvertencia) + BtnGuardar.Enabled = False + End If + Else + CveContrato = -1 + Alert("Ocurrió un error al cargar el Contrato. Por favor vuelva a intentar.", TipoMensaje.MsgError) + BtnGuardar.Enabled = False + End If + UpGral.Update() + UPAFUL.Update() + UpProyecto.Update() + ' UpImpuestos.Update() + UpTitulos.Update() + ObjContratos.Dispose() + End Sub + Private Sub CargaContratoAddendum() + Dim ObjContratos As New ClsContratos + If ObjContratos.GetContratosAddendum(CveContrato) Then + If ObjContratos.DtResultados.Rows.Count > 0 Then + TabAddendum.Visible = True + GvAddendum.DataSource = ObjContratos.DtResultados + GvAddendum.DataBind() + End If + End If + End Sub + Private Sub CargaPresupuesto() + Dim ObjContratos As New ClsContratos + TabPres.Visible = True + + If TipoContrato = 4 Then + TabPI.Visible = True + End If + If ObjContratos.GetContratosDetalle(CveContrato) Then + TmpDT = ObjContratos.DtResultados + If TmpDT.MAX("Cantidad_Original").ToString.ToEntero > 0 OrElse TmpDT.MAX("PU_Original").ToString.ToEntero > 0 Then + BtnAutorizar.Visible = False + Autorizado = True + BtnAgregarDetalle.Visible = False + AgregarInt.Visible = UsuarioActual.TienePermisoProceso(129) + End If + + CargaGVPresupuestos(TmpDT.FiltraParametros("CveTipoPresupuesto=2")) + CargaGVPresupuestosInsumos(TmpDT.FiltraParametros("CveTipoPresupuesto=1")) + + GvInt.DataSource = TmpDT.FiltraParametros("CveTipoPresupuesto=1") + GvInt.DataBind() + + UpGV.Update() + UpGVInsumos.Update() + UPGVInt.Update() + LbTotalGeneral.Text = TmpDT.FiltraParametros("CveTipoPresupuesto=2").SUM("Total").FormatoNumero() + LbTotalGeneralInsumos.Text = TmpDT.FiltraParametros("CveTipoPresupuesto=1").SUM("Total").FormatoNumero() + LbTotalGeneralInt.Text = TmpDT.FiltraParametros("CveTipoPresupuesto=1").SUM("Total").FormatoNumero() + LblImporte.Text = "$" & TmpDT.FiltraParametros("CveTipoPresupuesto=2").SUM("Total").FormatoNumero() + End If + End Sub + + Private Sub CargarFianzas() + + 'DivFianzas.Visible = True + + Dim ObjContrato As ClsContratos = New ClsContratos() + + If ObjContrato.GetContratoFianza(CveContrato, -1, "-1", "-1", UsuarioActual.CveEmpresa, -1) Then + DtTmpFianzas = ObjContrato.DtResultados + ' GvFianzas.DataSource = ObjContrato.DtResultados + + DtTmpFianzasInicial = DtTmpFianzas.Copy() + + End If + + ObjContrato.Dispose() + ' GvFianzas.DataBind() + ' UpGvFianzas.Update() + + End Sub +#End Region + +#Region " GUARDAR " + Protected Sub BtnGuardar_Click(sender As Object, e As EventArgs) Handles BtnGuardar.Click + + If DdlContratista.SelectedValue.ToEntero = -1 And DdlCliente.SelectedValue.ToEntero = -1 Then + Alert("Debe seleccionar con quién está haciendo el contrato. Proveedor o Cliente", TipoMensaje.MsgAdvertencia) + Exit Sub + End If + + Dim TieneError = False + Dim Modificado = False + ' Dim Extension = Session("FileExtension").ToString + Dim Archivo = Session("FileUpload").ToString + Dim Ruta = Session("FileFolder").ToString + + Dim Minimo, Maximo, Total As Double + 'If txtMinimo.Text.ToDouble > 0 Then Minimo = txtMinimo.Text.ToDouble Else Minimo = -1 + 'If txtMaximo.Text.ToDouble > 0 Then Maximo = txtMaximo.Text.ToDouble Else Maximo = -1 + 'If TxtTotal.Text.ToDouble > 0 Then Total = TxtTotal.Text.ToDouble Else Total = -1 + Minimo = 0 'txtMinimo.Text.ToDouble + Maximo = 0 'txtMaximo.Text.ToDouble + Total = TxtTotal.Text.ToDouble + + 'If DdlTipoContrato.SelectedValue = "25" AndAlso DdlPeriodo.SelectedValue.ToEntero() <= 0 Then + ' Alert("Debe seleccionar el periodo de facturación.", TipoMensaje.MsgAdvertencia) + ' Exit Sub + 'End If + + If DdlMoneda.SelectedIndex > 0 Then + If TxtTipoCambio.Text.Trim.Length = 0 Or TxtTipoCambio.Text.Trim.ToDouble = 0.0 Then + Alert("Cuando seleccione una moneda diferente a peso debe especificar el tipo de cambio.", TipoMensaje.MsgAdvertencia) + Exit Sub + End If + End If + + If CveContrato > 0 Then + If DdlContratista.SelectedValue.ToEntero = -1 And DdlCliente.SelectedValue.ToEntero = -1 Then + Alert("Debe seleccionar con quién está haciendo el contrato. Proveedor o Cliente", TipoMensaje.MsgAdvertencia) + Exit Sub + End If + End If + + Dim ObjContratos As New ClsContratos + Dim ObjInventarios As New ClsInventarios(ObjContratos.IniciaTransacSQL) + + TipoContrato = DdlTipoContratoObra.SelectedValue.ToEntero + + 'Crear Contrato + If Not CveContrato > 0 Then + + Dim EstatusContrato As Integer = 1 + + CveContrato = ObjContratos.AddContratosObra(TxtNumeroContrato.Text, TxtDescripcionContrato.Text, TxtNumeroLicitacion.Text.Trim, DdlContratista.SelectedValue.ToEntero, DdlCliente.SelectedValue.ToEntero, -1, TxtFechaInicial.Text.ToDate, TxtFechaFinal.Text.ToDate, + TxtUbicacion.Text, TxtResponsable.Text, DdlProyecto.SelectedValue.ToEntero, TxtPorIVA.Text.ToDouble, TxtPorAnticipo.Text.ToDouble, TxtPorAmortizacionAnticipo.Text.ToDouble, + TxtPorGarantia.Text.ToDouble, "." & Session("FileExtension").ToString, "", -1, UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa, False, Minimo, Maximo, Total, + DdlMoneda.SelectedValue.ToEntero, ModalidadDetalle, EstatusContrato, TipoContrato, + TxtTipoCambio.Text.ToDouble, CveSucursalCliente:=DdlSucursalCliente.SelectedValue.ToEntero, CveAlmacenOrigen:=-1, CveAlmacenDestino:=-1, + PorcentajeComision:=0, TipoGarantia:=-1, Folio:=0, FechaVenc:=Nothing, EstatusFianza:=1, + CvePeriodo:=-1, CveCuentaEquipo:=-1, CveContratoPlantilla:=-1, CveVendedor:=-1, + Observaciones:=TxtObservaciones.Text, CveDireccionEnvio:=-1, AplicaImpuestosLocales:=False, CorreoNotificacionPedDev:=TxtCorreoNotificacion.Text.Trim()) + + + TieneError = Not GuardaFianzas(ObjContratos) + + + If CveContrato > 0 AndAlso Not TieneError Then + 'Renombrar archivo + If ViewState("extencion") IsNot Nothing Then + If ViewState("FUrl").ToString.Length > 0 AndAlso ViewState("extencion").ToString.Length > 0 Then + If Not Directory.Exists(ModExtensiones.DirectorioBaseEmpresas + "Empresas\" & UsuarioActual.CveEmpresa & "\Contratos") Then + Directory.CreateDirectory(ModExtensiones.DirectorioBaseEmpresas + "Empresas\" & UsuarioActual.CveEmpresa & "\Contratos") + End If + Ruta = ModExtensiones.DirectorioBaseEmpresas + "Empresas\" & UsuarioActual.CveEmpresa & "\Contratos\" + + 'ViewState("extencion") = FileExtension + 'ViewState("FUrl") = Path.Combine(UsuarioActual.Empresa.Ruta, "Contratos", "Temp", ViewState("FName").ToString) + Try + If File.Exists(String.Format("{0}{1}.{2}", Ruta, CveContrato.ToString, ViewState("extencion").ToString)) Then + File.Delete(String.Format("{0}{1}.{2}", Ruta, CveContrato.ToString, ViewState("extencion").ToString)) + End If + System.IO.File.Move(ViewState("FUrl").ToString, String.Format("{0}{1}.{2}", Ruta, CveContrato.ToString, ViewState("extencion").ToString)) + Catch ex As Exception + + End Try + End If + End If + + 'If UsuarioActual.Empresa.CvePlataforma = 3 AndAlso DdlTipoContrato.SelectedValue = "14" Then + ' Dim FechaI As DateTime = TxtFechaInicial.Text.ToDateTime + ' Dim FechaF As DateTime = TxtFechaFinal.Text.ToDateTime + ' Dim Periodo As Integer = DtPeriodo.FiltraParametros($"CvePeriodo = {DdlPeriodo.SelectedValue.ToEntero}").Rows(0)("Dias").ToString.ToEntero + ' Dim VigenciaEnDias As Double = DateDiff(DateInterval.Day, FechaI, FechaF) + ' Dim CiclosComerciales As Integer = Math.Round(VigenciaEnDias / Periodo).ToEntero + ' For Ciclo As Integer = 1 To CiclosComerciales + ' If Not ObjContratos.CicloComercialAdd(CveContrato, -1, DdlCliente.SelectedValue.ToEntero, False, -1, 1, UsuarioActual.CveEmpresa, FechaI.AddDays(Periodo * Ciclo)) Then TieneError = True : Exit For + ' Next + 'ElseIf DdlTipoContrato.SelectedValue = "25" Then + ' Dim FechaI As DateTime = TxtFechaInicial.Text.ToDateTime + ' Dim FechaF As DateTime = TxtFechaFinal.Text.ToDateTime + ' If FechaI >= DateTime.Today Then + ' If Not ObjContratos.CicloComercialAdd(CveContrato, -1, DdlCliente.SelectedValue.ToEntero, False, -1, 1, UsuarioActual.CveEmpresa, FechaI) Then TieneError = True + ' End If + ' Dim Periodo As Integer = DtPeriodo.FiltroPrimeroValor("Meses", $"CvePeriodo = {DdlPeriodo.SelectedValue.ToEntero}").ToEntero + ' Dim VigenciaMeses As Double = DateDiff(DateInterval.Month, FechaI, FechaF) + ' Dim CiclosComerciales As Integer = Math.Ceiling(VigenciaMeses / Periodo).ToEntero + ' For Ciclo As Integer = 1 To CiclosComerciales + ' If Not ObjContratos.CicloComercialAdd(CveContrato, -1, DdlCliente.SelectedValue.ToEntero, False, -1, 1, UsuarioActual.CveEmpresa, If(FechaI.AddMonths(Periodo * Ciclo) > FechaF, FechaF, FechaI.AddMonths(Periodo * Ciclo))) Then TieneError = True : Exit For + ' Next + 'End If + + If TxtNumeroContrato.Text = FolioSugerido Then + Dim ObjFolios As New ClsGralFolios + + If Not ObjFolios.UpdateFolioActual(CveSubProyecto, "Con", True, UsuarioActual.CveEmpresa) Then + TieneError = True + End If + + ObjFolios.Dispose() + End If + + 'If ChkImpuestosLocales.Checked Then + ' Dim count As Integer = 0 + + ' For Each GVR As GridViewRow In GvImpuestosLocales.Rows + ' If GVR.FCCheckBox("ChkDeduccion").Checked Then + ' count = count + 1 + ' ObjContratos.AddContratoImpuestosLocales(CveContrato, GVR.DataKey("CveImpuestoLocal").ToEntero) + ' End If + ' Next + + ' If count = 0 Then + ' Alert("Debe seleccionar un Impuesto Local", TipoMensaje.MsgAdvertencia) + ' TieneError = True + ' End If + 'End If + + Else + TieneError = True + End If + + Else + Modificado = True + + Dim ArchivoUpdate As String = "-1" + + If Session("FileExtension").ToString <> "" Then + ArchivoUpdate = "." & Session("FileExtension").ToString + Else + + End If + + If ObjContratos.UpdateContratosObra(CveContrato, TxtNumeroContrato.Text, TxtDescripcionContrato.Text, TxtNumeroLicitacion.Text.Trim, DdlContratista.SelectedValue.ToEntero, DdlCliente.SelectedValue.ToEntero, -1, TxtFechaInicial.Text.ToDate, TxtFechaFinal.Text.ToDate, + TxtUbicacion.Text, TxtResponsable.Text, TxtPorIVA.Text.ToDouble, TxtPorAnticipo.Text.ToDouble, TxtPorAmortizacionAnticipo.Text.ToDouble, + TxtPorGarantia.Text.ToDouble, ArchivoUpdate, "", -1, UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa, False, Minimo, Maximo, Total, DdlMoneda.SelectedValue.ToEntero, + ModalidadDetalle, If(UsuarioActual.Empresa.CvePlataforma = 3 OrElse CveTipoContrato = 25, 1, DdlEstatus.SelectedValue.ToEntero), TipoContrato, TxtTipoCambio.Text.ToDouble, CveSucursalCliente:=DdlSucursalCliente.SelectedValue.ToEntero, + CveAlmacenOrigen:=-1, CveAlmacenDestino:=-1, PorcentajeComision:=0, + TipoGarantia:=-1, Folio:=-1, FechaVenc:=Nothing, EstatusFianza:=-1, CveContratoPlantilla:=-1, + CveCuentaEquipo:=-1, CveVendedor:=-1, Observaciones:=TxtObservaciones.Text, CveDireccionEnvio:=-1, AplicaImpuestosLocales:=False, + CorreoNotificacionPedDev:=TxtCorreoNotificacion.Text.Trim()) Then + + + TieneError = Not GuardaFianzas(ObjContratos) + + 'Renombrar archivo + If Not TieneError Then + + 'If UsuarioActual.Empresa.CvePlataforma = 3 AndAlso DdlTipoContrato.SelectedValue = "14" Then + ' Dim FechaIN As DateTime = TxtFechaInicial.Text.ToDateTime + ' Dim FechaFN As DateTime = TxtFechaFinal.Text.ToDateTime + ' Dim Periodo As Integer = DtPeriodo.FiltraParametros($"CvePeriodo = {DdlPeriodo.SelectedValue.ToEntero}").Rows(0)("Dias").ToString.ToEntero + ' Dim VigenciaEnDias As Double = DateDiff(DateInterval.Day, FechaI, FechaF) + ' Dim CiclosComerciales As Integer = Math.Round(VigenciaEnDias / Periodo).ToEntero + ' For Ciclo As Integer = 1 To CiclosComerciales + ' If Not ObjContratos.CicloComercialAdd(CveContrato, -1, DdlCliente.SelectedValue.ToEntero, False, -1, 1, UsuarioActual.CveEmpresa, FechaI.AddDays(Periodo * Ciclo)) Then TieneError = True : Exit For + ' Next + 'ElseIf CveTipoContrato = 25 Then + ' Dim FechaIN As DateTime = TxtFechaInicial.Text.ToDateTime + ' Dim FechaFN As DateTime = TxtFechaFinal.Text.ToDateTime + ' If FechaFN <> FechaF OrElse FechaI <> FechaIN Then + ' If Not ObjContratos.CicloComercialDelete(CveContrato, False, UsuarioActual.CveEmpresa) Then + ' TieneError = True + ' End If + ' If Not TieneError Then + ' If FechaIN >= DateTime.Today Then + ' If Not ObjContratos.CicloComercialAdd(CveContrato, -1, DdlCliente.SelectedValue.ToEntero, False, -1, 1, UsuarioActual.CveEmpresa, FechaIN) Then TieneError = True + ' End If + ' Dim Periodo As Integer = DtPeriodo.FiltroPrimeroValor("Meses", $"CvePeriodo = {DdlPeriodo.SelectedValue.ToEntero}").ToEntero + ' Dim VigenciaMeses As Double = DateDiff(DateInterval.Month, FechaI, FechaF) + ' Dim CiclosComerciales As Integer = Math.Ceiling(VigenciaMeses / Periodo).ToEntero + ' For Ciclo As Integer = 1 To CiclosComerciales + ' If Not ObjContratos.CicloComercialAdd(CveContrato, -1, DdlCliente.SelectedValue.ToEntero, False, -1, 1, UsuarioActual.CveEmpresa, If(FechaIN.AddMonths(Periodo * Ciclo) > FechaFN, FechaFN, FechaIN.AddMonths(Periodo * Ciclo))) Then TieneError = True : Exit For + ' Next + ' End If + ' End If + 'End If + + If ViewState("extencion") IsNot Nothing Then + + If ViewState("FUrl").ToString.Length > 0 AndAlso ViewState("extencion").ToString.Length > 0 Then + If Not Directory.Exists(ModExtensiones.DirectorioBaseEmpresas + "Empresas\" & UsuarioActual.CveEmpresa & "\Contratos") Then + Directory.CreateDirectory(ModExtensiones.DirectorioBaseEmpresas + "Empresas\" & UsuarioActual.CveEmpresa & "\Contratos") + End If + Ruta = ModExtensiones.DirectorioBaseEmpresas + "Empresas\" & UsuarioActual.CveEmpresa & "\Contratos\" + + Try + If File.Exists(String.Format("{0}{1}.{2}", Ruta, CveContrato.ToString, ViewState("extencion").ToString)) Then + File.Delete(String.Format("{0}{1}.{2}", Ruta, CveContrato.ToString, ViewState("extencion").ToString)) + End If + System.IO.File.Move(ViewState("FUrl").ToString, String.Format("{0}{1}.{2}", Ruta, CveContrato.ToString, ViewState("extencion").ToString)) + Catch ex As Exception + + End Try + ' System.IO.File.Move(Archivo, String.Format("{0}{1}{2}", Ruta, CveContrato.ToString, Extension)) + End If + End If + + 'If ChkImpuestosLocales.Checked Then + ' Dim count As Integer = 0 + ' ObjContratos.LimpiaImpuestosLocales(CveContrato) + + ' For Each GVR As GridViewRow In GvImpuestosLocales.Rows + ' If GVR.FCCheckBox("ChkDeduccion").Checked Then + ' count = count + 1 + ' ObjContratos.AddContratoImpuestosLocales(CveContrato, GVR.DataKey("CveImpuestoLocal").ToEntero) + ' End If + ' Next + + ' If count = 0 Then + ' Alert("Debe seleccionar un Impuesto Local", TipoMensaje.MsgAdvertencia) + ' TieneError = True + ' End If + 'Else + ' ObjContratos.LimpiaImpuestosLocales(CveContrato) + 'End If + + End If + Else + TieneError = True + End If + + + End If + + If TieneError Then + ObjContratos.RollBack() + Else + ObjContratos.Commit() + + If ObjContratos.GetContratos(-1, -1) Then + Application("GlobalDTContratos") = ObjContratos.DtResultados + End If + + Limpiar() + If Modificado Then + Alert("El Contrato se modificó Correctamente.", TipoMensaje.MsgInformacion, String.Format("document.location.href=""/Contratos/ContratoObra.aspx?CveContrato={0}""", CveContrato)) + Else + Alert("El Contrato se registró Correctamente.", TipoMensaje.MsgInformacion, String.Format("document.location.href=""/Contratos/ContratoObra.aspx?CveContrato={0}""", CveContrato)) + End If + + End If + + UpGral.Update() + ObjContratos.Dispose() + End Sub +#End Region + +#Region " ELIMINAR " + Protected Sub BtnEliminar_Click(sender As Object, e As EventArgs) Handles BtnEliminar.Click + Dim objContratos As New ClsContratos + + If objContratos.RemoveContrato(CveContrato, UsuarioActual.Empresa.CveEmpresa) Then + Response.Redirect("./Contratos.aspx") + Else + ' Alert("Ocurrio un error al eliminar el contrato", TipoMensaje.MsgError) + End If + End Sub +#End Region + +#Region " TERMINAR/CANCELAR CONTRATO " + Protected Sub LBTerminarContrato_Click(sender As Object, e As EventArgs) + Dim ObjContratos As New ClsContratos + If ObjContratos.TerminarContrato(CveContrato, 2, UsuarioActual.CveEmpresa) > 0 Then + Alert("El Contrato fue terminado Correctamente.", TipoMensaje.MsgInformacion, String.Format("document.location.href=""/Contratos/Contrato.aspx?CveContrato={0}""", CveContrato)) + End If + ObjContratos.Dispose() + End Sub + + Protected Sub LBCancelarContrato_Click(sender As Object, e As EventArgs) + Dim ObjContratos As New ClsContratos + If ObjContratos.TerminarContrato(CveContrato, 3, UsuarioActual.CveEmpresa) > 0 Then + Alert("El Contrato fue cancelado Correctamente.", TipoMensaje.MsgInformacion, String.Format("document.location.href=""/Contratos/Contrato.aspx?CveContrato={0}""", CveContrato)) + End If + ObjContratos.Dispose() + End Sub + + Protected Sub LBVigenteContrato_Click(sender As Object, e As EventArgs) + Dim ObjContratos As New ClsContratos + If ObjContratos.TerminarContrato(CveContrato, 1, UsuarioActual.CveEmpresa) > 0 Then + Alert("El Contrato fue cancelado Correctamente.", TipoMensaje.MsgInformacion, String.Format("document.location.href=""/Contratos/Contrato.aspx?CveContrato={0}""", CveContrato)) + End If + ObjContratos.Dispose() + End Sub +#End Region + +#Region " TABS " + +#Region " TAB: INFORMACION GENERAL" + +#Region "COMBOS - INFO GENERAL" + Private Sub CargaProyecto() + + 'trddlproyecto.Visible = LblProyecto.Visible + CargarCentrosDeCosto(DdlProyecto, Nothing, LblProyecto, LblSubProyectoTitulo) + + DdlProyecto.Visible = True + LblProyecto.Visible = True + + + LblCentroCosto.Text = LblSubProyectoTitulo.Text + LblSubProyectoTitulo.Text = LblSubProyectoTitulo.Text & ":" + + 'If UsuarioActual.Empresa.GralSoloProyecto Then + ' CargaSubProyectoContrato(-1) + ' lblsubproyecto.Text = "Proyecto" + 'Else + ' DdlProyecto.DataSource = GlobalDTProyectos(UsuarioActual.Empresa.CveEmpresa).FiltraParametros("", "", {"CveProyecto", "Proyecto"}) + ' DdlProyecto.DataBind() + 'End If + End Sub + 'Protected Sub DdlProyecto_SelectedIndexChanged(sender As Object, e As System.EventArgs) Handles DdlProyecto.SelectedIndexChanged + ' CargaSubProyectoContrato(DdlProyecto.SelectedValue.ToEntero) + 'End Sub + 'Protected Sub CargaSubProyectoContrato(CveProyecto As Integer) + ' DdlSubProyectoContrato.Items.Clear() + ' DdlSubProyectoContrato.DataSource = GlobalDTSubProyectos(CveProyecto, CveEmpresa:=UsuarioActual.CveEmpresa).FiltraParametros("", "", {"CveSubproyecto", "SubProyecto"}) + ' DdlSubProyectoContrato.DataBind() + ' DdlSubProyectoContrato.Items.Insert(0, New ListItem("Seleccione un Proyecto", "-1")) + 'End Sub + Private Sub CargaContratista() + DdlContratista.DataSource = GlobalDTCompProveedores(UsuarioActual.CveEmpresa) + DdlContratista.DataBind() + End Sub + + 'Private Sub CargaVendedores() + ' DdlVendedor.DataSource = GlobalDTVendedores(UsuarioActual.CveEmpresa) + ' DdlVendedor.DataBind() + 'End Sub + 'Private Sub CargaContratoPadre() + ' DdlContratoPadre.Items.Clear() + ' DdlContratoPadre.DataSource = GlobalDTContratos.FiltraParametros($"CveEmpresa = {UsuarioActual.CveEmpresa} AND CveContratoTipo = {TipoContrato} {If(DdlCliente.SelectedValue.ToEntero > 0, $"AND CveCliente = {DdlCliente.SelectedValue}", "")} {If(CveContrato > 0, $"AND CveContrato <> {CveContrato}", "")} ") + ' DdlContratoPadre.DataBind() + ' DdlContratoPadre.Items.Insert(0, New ListItem("Seleccione", "-1")) + 'End Sub + Private Sub CargaContratosEstatus() + Dim ObjContratos As New ClsContratos + ObjContratos.GetContratosEstatus(UsuarioActual.CveEmpresa) + DdlEstatus.DataSource = ObjContratos.DtResultados + DdlEstatus.DataBind() + ObjContratos.Dispose() + End Sub + Protected Sub DdlCliente_SelectedIndexChanged(sender As Object, e As EventArgs) + CargaSucursalCliente() + ' CargaDireccionesEnvios(DdlCliente.SelectedValue.ToEntero) + UPPDatos.Update() + End Sub + Private Sub CargaSucursalCliente() + TrClienteSucursal.Visible = False + + Dim ObjCliente As New ClsClientes() + + If DdlCliente.SelectedValue.ToEntero > 0 Then + + If ObjCliente.GetSucursales(DdlCliente.SelectedValue.ToEntero) Then + DdlSucursalCliente.DataSource = ObjCliente.DtResultados + If ObjCliente.DtResultados.Rows.Count > 0 Then + TrClienteSucursal.Visible = True + End If + DdlSucursalCliente.DataBind() + ' DdlTipoContrato.Items.Insert(0, New ListItem("Matriz", "-1")) + End If + 'If UsuarioActual.Empresa.CvePlataforma = 3 Then ' QUITAR + ' CargaCuentasEquipos() + 'End If + End If + + ObjCliente.Dispose() + + 'CargaContratoPadre() + UpProyecto.Update() + End Sub + + + + + + + + + +#End Region + +#Region " ARCHIVO " + + Private Sub BtnDescargar_Click(sender As Object, e As EventArgs) Handles BtnDescargar.Click + DescargarArchivo() + End Sub + + Private Sub DescargarArchivo() + Dim File As New FileInfo(ViewState("FUrl").ToString) + + If File.Exists Then 'set appropriate headers + Response.Clear() + Response.ClearHeaders() + Response.ClearContent() + Response.AddHeader("Content-Disposition", "attachment; filename=" & TxtNumeroContrato.Text & ".pdf") + Response.AddHeader("Content-Length", File.Length.ToString()) + 'Response.ContentType = "text/plain" + Response.ContentType = "application/octet-stream" + Response.Flush() + ' Response.TransmitFile(File.FullName) + Response.WriteFile(File.FullName) + Response.End() + 'if file does not exist + + Alert("Descargado Correctamente.", TipoMensaje.MsgInformacion) + Else + Alert("Ocurrio un error al descargar el archivo", TipoMensaje.MsgAdvertencia, "window.close()") + + End If 'nothing in the URL as HTTP GET + End Sub + + Protected Sub BtnGuardarArchivo_Click1(sender As Object, e As EventArgs) Handles BtnGuardarArchivo.Click + Dim FileExtension As String = "-1" + Dim Filesgral As List(Of Archivo) = Anexo.getfiles().Archivos + Dim Filename As String = "" + Dim folderContratosPath As String = Path.Combine(UsuarioActual.Empresa.Ruta, "Contratos") + + If Not Directory.Exists(folderContratosPath) Then + Directory.CreateDirectory(folderContratosPath) + End If + + If Not Directory.Exists(Path.Combine(folderContratosPath, "Temp")) Then + Directory.CreateDirectory(Path.Combine(folderContratosPath, "Temp")) + End If + + For Each fileItem As Archivo In Filesgral + + FileExtension = IO.Path.GetExtension(String.Format("{0}Temp\{1}", AppDomain.CurrentDomain.BaseDirectory, fileItem.filename)).Replace(".", "") + Session("FileExtension") = FileExtension + Dim tempArray() As String + tempArray = fileItem.filename.ToString().Split("-".ToCharArray()) + + + ViewState("extencion") = FileExtension + ViewState("FUrl") = Path.Combine(UsuarioActual.Empresa.Ruta, "Contratos", "Temp", fileItem.filename) + + File.Move(fileItem.FileUrl, ViewState("FUrl").ToString) + TxtArchivo.Text = tempArray(1) + ' imgFileOk.Visible = True + 'ImgArchivo.Src = "/imagenes/accept.png" + Next + + UPAFUL.Update() + + RegistraScript("$('#ModalUpload').modal('hide')", "hidemodal1") + A1.Visible = True + If Not FileExtension = "-1" Then + BtnDescargar.Visible = True + End If + End Sub +#End Region + +#End Region + +#Region " TAB: PRESUPUESTOS " + +#Region "C O M B O S - PRESUPUESTOS" + Private Function isWhitFamily() As Boolean + Return (UsuarioActual.CveEmpresa = 66) + End Function + + Private Sub CargaClasificaciones() + DdlClasificacionAdd.DataSource = GlobalDTClasificaciones(UsuarioActual.CveEmpresa) ' GlobalDTClasificacionesPresupuestos(UsuarioActual.CveEmpresa) + DdlClasificacionAdd.DataBind() + DdlClasificacionAdd.Items.Insert(0, New ListItem("Seleccione", "-1")) + + DdlClasificacionAddInsumos.DataSource = GlobalDTClasificaciones(UsuarioActual.CveEmpresa) ' GlobalDTClasificacionesPresupuestos(UsuarioActual.CveEmpresa) + DdlClasificacionAddInsumos.DataBind() + DdlClasificacionAddInsumos.Items.Insert(0, New ListItem("Seleccione", "-1")) + + DdlClasificacionInt.DataSource = GlobalDTClasificaciones(UsuarioActual.CveEmpresa) 'GlobalDTSubFamilias(UsuarioActual.CveEmpresa) + DdlClasificacionInt.DataBind() + DdlClasificacionInt.Items.Insert(0, New ListItem("Seleccione", "-1")) + End Sub + +#Region " FUNCIONALIDAD 105 " + Private Sub CargaPS() + DdlProductows.setEsWebService(UsuarioActual.Empresa.Funcionalidad(105) = "1") + If Not DdlProductows.UsaWebService AndAlso CType(DdlProductows.DataSource, DataTable) Is Nothing Then + DdlProductows.DataSource = GlobalDTPSSimplificado(UsuarioActual.CveEmpresa) + DdlProductows.DataBind() + Else + DdlProductows.ddlWS.Attributes.Add("data-cveclasificacion", DdlClasificacionAdd.SelectedValue) + End If + ElProductoChange() + End Sub + Protected Sub DdlProducto_ValueChanged(sender As Object, e As EventArgs) Handles DdlProductows.selectedindexchange + ElProductoChange() + End Sub + Private Sub ElProductoChange() + DdlUM.Items.Clear() + DdlUM.DataSource = GlobalDTProductosServiciosEquivalencias(DdlProductows.SelectedValue.ToEntero, -1, UsuarioActual.CveEmpresa) + DdlUM.DataBind() + UpTitulos.Update() + End Sub + Protected Sub DdlClasificacion_SelectedIndexChanged(sender As Object, e As System.EventArgs) Handles DdlClasificacionAdd.SelectedIndexChanged + ChangeDdlProducto() + End Sub + Private Sub ChangeDdlProducto() + If UsuarioActual.Empresa.Funcionalidad(105) = "" Then + DdlProductows.DataSource = GlobalDTPSSimplificado(UsuarioActual.CveEmpresa, CveClasificacion:=DdlClasificacionAdd.SelectedValue.ToEntero).FiltraParametros("", "PSCodigo") + DdlProductows.DataBind() + DdlProductows.ddl.Items.Insert(0, New ListItem("Seleccione", "-1")) + Else + DdlProductows.ddlWS.Attributes.Add("data-cveclasificacion", DdlClasificacionAdd.SelectedValue) + DdlProductows.SelectedText = "Seleccione" + DdlProductows.SelectedValue = "-1" + End If + End Sub + + Private Sub CargaPSInsumos() + DdlProductowsInsumos.setEsWebService(UsuarioActual.Empresa.Funcionalidad(105) = "1") + If Not DdlProductowsInsumos.UsaWebService AndAlso CType(DdlProductowsInsumos.DataSource, DataTable) Is Nothing Then + DdlProductowsInsumos.DataSource = GlobalDTPSSimplificado(UsuarioActual.CveEmpresa) + DdlProductowsInsumos.DataBind() + End If + ElProductoChangeInsumos() + End Sub + Protected Sub DdlProductoInsumos_ValueChanged(sender As Object, e As EventArgs) Handles DdlProductowsInsumos.selectedindexchange + ElProductoChangeInsumos() + End Sub + Private Sub ElProductoChangeInsumos() + DdlUMInsumos.Items.Clear() + DdlUMInsumos.DataSource = GlobalDTProductosServiciosEquivalencias(DdlProductowsInsumos.SelectedValue.ToEntero, -1, UsuarioActual.CveEmpresa) + DdlUMInsumos.DataBind() + UpTitulos.Update() + End Sub + Protected Sub DdlClasificacionInsumos_SelectedIndexChanged(sender As Object, e As System.EventArgs) Handles DdlClasificacionAddInsumos.SelectedIndexChanged + ChangeDdlProductoInsumos() + End Sub + Private Sub ChangeDdlProductoInsumos() + If UsuarioActual.Empresa.Funcionalidad(105) = "" Then + 'Dim filtro As String = "" + 'If Not (DdlClasificacionAddInsumos.SelectedValue = "-1") Then + + ' If isWhitFamily() Then + ' filtro = String.Format("CveSubFamilia={0}", DdlClasificacionAddInsumos.SelectedValue) + ' Else + ' filtro = String.Format("CveClasificacion={0}", DdlClasificacionAddInsumos.SelectedValue) + ' End If + 'End If + DdlProductowsInsumos.DataSource = GlobalDTPSSimplificado(UsuarioActual.CveEmpresa, CveClasificacion:=DdlClasificacionAddInsumos.SelectedValue.ToEntero).FiltraParametros("", "PSCodigo") + DdlProductowsInsumos.DataBind() + DdlProductowsInsumos.ddl.Items.Insert(0, New ListItem("Seleccione", "-1")) + Else + 'If isWhitFamily() Then + ' DdlProductowsInsumos.ddlWS.Attributes.Add("data-idSubFamilia", DdlClasificacionAddInsumos.SelectedValue) + 'Else + DdlProductowsInsumos.ddlWS.Attributes.Add("data-idClasificacion", DdlClasificacionAddInsumos.SelectedValue) + 'End If + End If + End Sub +#End Region + +#End Region + +#Region " TAB PRESUPUESTOS VENTAS " + Private Sub CargaGVPresupuestos(DtTemp As DataTable) + Gv.DataSource = DtTemp + DtPresupuestos = DtTemp + Gv.DataBind() + If CveTipoContrato = 25 Then + Gv.Columns(0).Visible = False + Gv.Columns(2).Visible = False + Gv.Columns(3).Visible = False + Gv.Columns(9).Visible = False + End If + 'If (Gv.Rows.Count > 0) Then + ' Gv.UseAccessibleHeader = True + ' Gv.HeaderRow.TableSection = TableRowSection.TableHeader + ' RegistraScript("OrdenarGVPresupuestos();") + 'End If + UpGV.Update() + End Sub + Protected Sub BtnAutorizar_Click(sender As Object, e As EventArgs) Handles BtnAutorizar.Click + Dim pinterno = TmpDT.SUM("Total", "CveTipoPresupuesto=1").ToString.ToDouble + Dim pventas = TmpDT.SUM("Total", "CveTipoPresupuesto=2").ToString.ToDouble + If (pinterno < pventas) Then + Dim objContrato As New ClsContratos + + If objContrato.AutorizarContratos(CveContrato, UsuarioActual.CveUsuario) Then + BtnAutorizar.Visible = False + Autorizado = True + Alert("Contrato Autorizado", TipoMensaje.MsgInformacion, String.Format("document.location.href=""/Contratos/Contrato.aspx?CveContrato={0}""", CveContrato)) + End If + objContrato.Dispose() + Else + Alert("el presupuesto de ventas debe ser mayor al presupuesto interno!", TipoMensaje.MsgAdvertencia) + End If + End Sub + + Protected Sub BtnAgregarDetalle_Click(sender As Object, e As EventArgs) + Dim Row As DataRow = TmpDT.NewRow() + Row("Cantidad") = TxtCantidad.Text.ToDouble.FormatoNumero + Row("CantidadContratada") = TxtCantidad.Text.ToDouble.FormatoNumero + Row("CveUM") = DdlUM.SelectedValue.ToEntero + Row("UM") = DdlUM.SelectedItem + Row("CveClasificacion") = DdlClasificacionAdd.SelectedValue + Row("Clasificacion") = DdlClasificacionAdd.SelectedItem + Row("CvePS") = DdlProductows.SelectedValue.ToEntero + Row("PS") = DdlProductows.SelectedText + Row("CodigoPS") = DdlProductows.SelectedText + Row("PU") = TxtPU.Text.ToDouble.FormatoNumero + Row("Total") = (TxtCantidad.Text.ToDouble * TxtPU.Text.ToDouble).FormatoNumero + Row("CveTipoPresupuesto") = 2 + Row("NoIdentificacion") = TxtNoIdentificacionv.Text.Trim + Row("OCInterna") = TxtOCInterna.Text.Trim + Row("LimitarCantidad") = If(ChkLimitarVenta.Checked, 1, 0) + Row("Observacion") = TxtObservacionesDetalles.Text + + Dim ObjContratos As New ClsContratos + If ObjContratos.AddContratosDetalle(CveContrato, Row("CvePS").ToString.ToEntero, Row("Cantidad").ToString.ToDouble, Row("PU").ToString.ToDouble, UsuarioActual.CveUsuario, Row("CveTipoPresupuesto").ToString.ToEntero, Row("NoIdentificacion").ToString, Convert.ToBoolean(Row("LimitarCantidad")), Row("OCInterna").ToString, Observacion:=Row("Observacion").ToString) Then + If Autorizado Then + Dim msj As String = String.Format("Se agregaron {0} {1} del producto {2} con un precio ${3}.", Row("Cantidad"), Row("UM"), Row("PS"), Row("PU")) + guardarBitacora(msj) + End If + Row("CveContratoDetalle") = ObjContratos.DtResultados.Rows(0)("CveContratoDetalle") + TmpDT.Rows.Add(Row) + TmpDT.AcceptChanges() + Dim TotalRow = Row("Total").ToString.ToDouble + + CargaGVPresupuestos(TmpDT.FiltraParametros("CveTipoPresupuesto=2")) + + UpGV.Update() + TxtCantidad.Text = "" + TxtOCInterna.Text = "" + TxtNoIdentificacionv.Text = "" + TxtObservacionesDetalles.Text = "" + TxtPU.Text = "" + DdlClasificacionAdd.SelectedValue = "-1" + LbTotalGeneral.Text = (LbTotalGeneral.Text.ToDouble + TotalRow).ToString.FormatoNumero + LblImporte.Text = LbTotalGeneral.Text + TxtCantidad.Focus() + UpGral.Update() + Else + Alert("Ocurrio un error al agregar el detalle", TipoMensaje.MsgError) + End If + + ObjContratos.Dispose() + End Sub + + Private Sub CargaDatosPresup() + Dim ContratosSecciones As New ClsContratos() + + If ContratosSecciones.GetContratosSecciones(-1, CveContrato, -1, -1, -1, UsuarioActual.CveEmpresa) Then + 'If ContratosSecciones.GetContratosSecciones(-1, DdlEstatus.SelectedValue.ToEntero, DdlPS.SelectedValue.ToEntero, DdlContrato.SelectedValue.ToEntero, -1, -1, FechaI, FechaF) Then + DtDatos = ContratosSecciones.DtResultados + ' DtDatos.Rows.RemoveAt(0) + CargaGVPresupuestos(DtDatos) + LblImporte.Text = "$" & DtDatos.MAX("Total").FormatoNumero() + Else + Gv.DataSource = Nothing + End If + + ContratosSecciones.Dispose() + + UpGral.Update() + End Sub + +#Region "GV PRESUPUESTOS" + Protected Sub EstClick(sender As Object, e As System.EventArgs) + 'Get the button that raised the event + Dim btn As CheckBox = DirectCast(sender, CheckBox) + Dim gvr As GridViewRow = DirectCast(btn.NamingContainer, GridViewRow) + Dim CveContratoDetalle As Integer = gvr.DataKey("CveContratoDetalle").ToString.ToEntero + Dim objContrato As New ClsContratos + If objContrato.UpdateContratosDetalleEstimacion(CveContratoDetalle, IIf(btn.Checked, 1, 0).ToString.ToEntero) Then + Dim row = TmpDT.Select(String.Format("CveContratoDetalle={0}", CveContratoDetalle))(0) + row("PermitirEstimacion") = IIf(btn.Checked, 1, 0).ToString.ToEntero + Alert("Se ha permitido estimar", TipoMensaje.MsgInformacion) + Else + Alert("no se pudo permitir avance") + End If + objContrato.Dispose() + + End Sub + + Protected Sub AvaClick(sender As Object, e As System.EventArgs) + 'Get the button that raised the event + Dim btn As CheckBox = DirectCast(sender, CheckBox) + Dim gvr As GridViewRow = DirectCast(btn.NamingContainer, GridViewRow) + Dim CveContratoDetalle As Integer = gvr.DataKey("CveContratoDetalle").ToString.ToEntero + Dim objContrato As New ClsContratos + If objContrato.UpdateContratosDetalleAvance(CveContratoDetalle, IIf(btn.Checked, 1, 0).ToString.ToEntero) Then + Dim row = TmpDT.Select(String.Format("CveContratoDetalle={0}", CveContratoDetalle))(0) + row("PermitirAvance") = IIf(btn.Checked, 1, 0).ToString.ToEntero + + + CargaGVPresupuestos(TmpDT.FiltraParametros("CveTipoPresupuesto=2")) + + + Alert("Se ha permitido levantar avance", TipoMensaje.MsgInformacion) + Else + Alert("no se pudo permitir avance", TipoMensaje.MsgAdvertencia) + End If + objContrato.Dispose() + End Sub + Protected Sub GV_RowDataBound(ByVal sender As Object, ByVal e As GridViewRowEventArgs) Handles Gv.RowDataBound + + If e.Row.RowIndex > -1 Then + + e.Row.FCCheckBox("CHKPAvance").Visible = Autorizado + 'e.Row.FCCheckBox("CHKPEstimacion").Visible = Autorizado + If UsuarioActual.TienePermisoProceso(124) Then + e.Row.FCCheckBox("CHKPAvance").Enabled = True + End If + + If e.Row.DBCampo("PermitirAvance").ToString = "1" Then + e.Row.FCCheckBox("CHKPAvance").Checked = True + ' If UsuarioActual.TienePermisoProceso(125) Then : e.Row.FCCheckBox("CHKPEstimacion").Enabled = True : End If + End If + + If e.Row.DBCampo("PermitirEstimacion").ToString = "1" Then + ' e.Row.FCCheckBox("CHKPEstimacion").Checked = True + End If + If Autorizado Then + e.Row.FCLinkButton("imgE").Visible = False + e.Row.FCLinkButton("imgD").Visible = False + End If + If CveTipoContrato = 25 Then + e.Row.Cells(1).Width = Unit.Pixel(10) + e.Row.Cells(6).Width = Unit.Pixel(250) + End If + End If + If e.Row.RowState = DataControlRowState.Edit OrElse e.Row.RowState = 5 Then + e.Row.FCDropDownList("DdlUMEdit").DataSource = GlobalDTProductosServiciosEquivalencias(e.Row.DataKey("CvePS").ToString.ToEntero, -1, UsuarioActual.CveEmpresa) + e.Row.FCDropDownList("DdlUMEdit").DataBind() + e.Row.FCDropDownList("DdlUMEdit").SelectedValue = e.Row.DataKey("CveUM") + End If + + End Sub + Protected Sub GV_RowEditing(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewEditEventArgs) Handles Gv.RowEditing + Gv.EditIndex = e.NewEditIndex + CargaGVPresupuestos(TmpDT.FiltraParametros("CveTipoPresupuesto=2")) + End Sub + Protected Sub Gv_RowUpdating(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewUpdateEventArgs) Handles Gv.RowUpdating + Dim Cantidad, PU As Double : Dim CvePS, CveContratoDetalle, CveUM As Integer + Dim NoIdentificacion As String = "" + Dim OCInterna As String = "" + Dim LimitarCantidad As Boolean + Dim Observaciones As String = "" + CveContratoDetalle = Gv.Rows(e.RowIndex).DataKey("CveContratoDetalle").ToString.ToEntero + Cantidad = Gv.Rows(e.RowIndex).FCTextBox("TxtCantidad").Text.Trim.ToDouble + PU = Gv.Rows(e.RowIndex).FCTextBox("TxtPU").Text.Trim.ToDouble + CvePS = Gv.Rows(e.RowIndex).DataKey("CvePS").ToString.ToEntero + CveUM = Gv.Rows(e.RowIndex).FCDropDownList("DdlUMEdit").SelectedValue.ToEntero + NoIdentificacion = Gv.Rows(e.RowIndex).FCTextBox("TxtNoIdentificacion").Text.ToString + OCInterna = Gv.Rows(e.RowIndex).FCTextBox("TxtOCInternaEdit").Text.ToString + LimitarCantidad = Gv.Rows(e.RowIndex).FCCheckBox("ChkLimitarCantidad").Checked + Observaciones = Gv.Rows(e.RowIndex).FCTextBox("TxtObservacion").Text.ToString + Dim row = TmpDT.Select(String.Format(" CveContratoDetalle={0}", CveContratoDetalle))(0) + Dim LimitarCantidadValidator As Boolean = row("LimitarCantidad").ToString = "True" + If row("CantidadContratada").ToString.ToEntero <> Cantidad OrElse row("PU").ToString.ToEntero <> PU OrElse CveUM <> row("CveUM").ToString.ToEntero OrElse row("NoIdentificacion").ToString <> NoIdentificacion OrElse row("OCInterna").ToString <> OCInterna OrElse LimitarCantidadValidator <> LimitarCantidad Then + + Dim ObjContratos As New ClsContratos + If ObjContratos.UpdateContratosDetalle(CveContratoDetalle, CveContrato, CvePS, Cantidad, PU, UsuarioActual.CveUsuario, NoIdentificacion, LimitarCantidad, OCInterna, Observaciones) Then + + If Autorizado Then + Dim msj As String = String.Format("Se realizaron los siguientes cambios, el Presupuesto Interno se modificó: {1} {0} {2:C2} a {3} {0} {4:C2}", + row("PS").ToString, row("Cantidad").ToString, row("PU").ToString, Cantidad, PU) + guardarBitacora(msj) + End If + + row("Cantidad") = Cantidad + row("CantidadContratada") = Cantidad + row("PU") = PU + row("Total") = Cantidad * PU + row("CveUM") = CveUM + row("UM") = Gv.Rows(e.RowIndex).FCDropDownList("DdlUMEdit").SelectedItem.Text + row("NoIdentificacion") = NoIdentificacion + row("OCInterna") = OCInterna + row("LimitarCantidad") = LimitarCantidad + row("Observacion") = Observaciones + + TmpDT.AcceptChanges() + Alert("Cambios realizados correctamente.", TipoMensaje.MsgInformacion) + Else + Alert("Error al Actualizar Detalle", TipoMensaje.MsgError) + End If + ObjContratos.Dispose() + + Else + Alert("Cambios realizados correctamente") + End If + + Gv.EditIndex = -1 + LbTotalGeneral.Text = TmpDT.FiltraParametros("CveTipoPresupuesto=2").SUM("Total").FormatoNumero + LblImporte.Text = LbTotalGeneral.Text + CargaGVPresupuestos(TmpDT.FiltraParametros("CveTipoPresupuesto=2")) + + End Sub + Protected Sub GV_RowCancelingEdit(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewCancelEditEventArgs) Handles Gv.RowCancelingEdit + Gv.EditIndex = -1 + CargaGVPresupuestos(TmpDT.FiltraParametros("CveTipoPresupuesto=2")) + End Sub + Protected Sub GV_RowDeleting(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewDeleteEventArgs) Handles Gv.RowDeleting + + Dim ObjContratos As New ClsContratos + Dim DbRow As DataRow = Nothing + Dim CveContratoDetalle As Integer = Gv.Rows(e.RowIndex).DataKey("CveContratoDetalle").ToString.ToEntero + DbRow = TmpDT.Select(String.Format(" CveContratoDetalle={0}", CveContratoDetalle))(0) + If Autorizado Then + Dim msj As String = String.Format("Se eliminaron {0} {1} producto {2} con el precio {3}", DbRow("Cantidad"), DbRow("UM"), DbRow("PS"), DbRow("PU")) + guardarBitacora(msj) + End If + + If ObjContratos.RemoveContratosDetalle(CveContratoDetalle, CveContrato) Then + TmpDT.Rows.Remove(DbRow) + CargaGVPresupuestos(TmpDT.FiltraParametros("CveTipoPresupuesto=2")) + LbTotalGeneral.Text = Gv.Rows.Cast(Of GridViewRow)().Sum(Function(gvr) gvr.FCLabel("LtTotal").Text.ToDouble).ToString.FormatoNumero + Else + Alert("Ocurrió un error al eliminar el detalle (Producto/Servicio). Por favor vuelva a intentar", TipoMensaje.MsgError) + End If + + ObjContratos.Dispose() + End Sub + Protected Sub GV_RowCommand(sender As Object, e As GridViewCommandEventArgs) Handles Gv.RowCommand + If e.CommandName = "Sel" Then + ' Seleccionado = e.CommandArgument.ToString + Gv.SelectRow(e.CommandArgument.ToString.ToEntero - 1) + End If + End Sub +#End Region + + +#End Region + +#Region " TAB PRESUPUESTOS INSUMOS " + Private Sub CargaGVPresupuestosInsumos(DtTemp As DataTable) + GvInsumos.DataSource = DtTemp + DtSuministros = DtTemp + GvInsumos.DataBind() + 'If (GvInsumos.Rows.Count > 0) Then + ' GvInsumos.UseAccessibleHeader = True + ' GvInsumos.HeaderRow.TableSection = TableRowSection.TableHeader + ' RegistraScript("OrdenarGVPresupuestosInsumos();") + 'End If + UpGVInsumos.Update() + End Sub + + Protected Sub BtnAgregarDetalleInsumos_Click(sender As Object, e As EventArgs) + Dim Row As DataRow = TmpDT.NewRow() + Row("Cantidad") = TxtCantidadInsumos.Text.ToDouble.FormatoNumero + Row("CantidadContratada") = TxtCantidadInsumos.Text.ToDouble.FormatoNumero + Row("CveUM") = DdlUMInsumos.SelectedValue.ToEntero + Row("UM") = DdlUMInsumos.SelectedItem + Row("CveClasificacion") = DdlClasificacionAddInsumos.SelectedValue + Row("Clasificacion") = DdlClasificacionAddInsumos.SelectedItem + Row("CvePS") = DdlProductowsInsumos.SelectedValue.ToEntero + Row("PS") = DdlProductowsInsumos.SelectedText + Row("CodigoPS") = DdlProductowsInsumos.SelectedText + Row("PU") = TxtPUInsumos.Text.ToDouble.FormatoNumero + Row("Total") = (TxtCantidadInsumos.Text.ToDouble * TxtPUInsumos.Text.ToDouble).FormatoNumero + Row("CveTipoPresupuesto") = 1 + Row("NoIdentificacion") = TxtNoIdentificacionvInsumos.Text.Trim + Row("LimitarCantidad") = If(ChkLimitar.Checked, 1, 0) + + Dim ObjContratos As New ClsContratos + If ObjContratos.AddContratosDetalle(CveContrato, Row("CvePS").ToString.ToEntero, Row("Cantidad").ToString.ToDouble, Row("PU").ToString.ToDouble, UsuarioActual.CveUsuario, Row("CveTipoPresupuesto").ToString.ToEntero, Row("NoIdentificacion").ToString, Convert.ToBoolean(Row("LimitarCantidad")), "") Then + If Autorizado Then + Dim msj As String = String.Format("Se agregaron {0} {1} del producto {2} con un precio ${3}.", Row("Cantidad"), Row("UM"), Row("PS"), Row("PU")) + guardarBitacora(msj) + End If + Row("CveContratoDetalle") = ObjContratos.DtResultados.Rows(0)("CveContratoDetalle") + TmpDT.Rows.Add(Row) + Dim TotalRow = Row("Total").ToString.ToDouble + + CargaGVPresupuestosInsumos(TmpDT.FiltraParametros("CveTipoPresupuesto=1")) + + UpGVInsumos.Update() + TxtCantidadInsumos.Text = "" + TxtPUInsumos.Text = "" + DdlClasificacionAddInsumos.SelectedValue = "-1" + LbTotalGeneralInsumos.Text = (LbTotalGeneralInsumos.Text.ToDouble + TotalRow).ToString.FormatoNumero + 'LblImporte.Text = LbTotalGeneral.Text + TxtCantidadInsumos.Focus() + UpGral.Update() + Else + Alert("Ocurrio un error al agregar el detalle", TipoMensaje.MsgError) + End If + + ObjContratos.Dispose() + End Sub + +#Region "GV PRESUPUESTOS" + + Protected Sub GVInsumos_RowDataBound(ByVal sender As Object, ByVal e As GridViewRowEventArgs) Handles GvInsumos.RowDataBound + + If e.Row.RowIndex > -1 Then + + e.Row.FCCheckBox("CHKPAvance").Visible = Autorizado + 'e.Row.FCCheckBox("CHKPEstimacion").Visible = Autorizado + If UsuarioActual.TienePermisoProceso(124) Then + e.Row.FCCheckBox("CHKPAvance").Enabled = True + End If + + If e.Row.DBCampo("PermitirAvance").ToString = "1" Then + e.Row.FCCheckBox("CHKPAvance").Checked = True + ' If UsuarioActual.TienePermisoProceso(125) Then : e.Row.FCCheckBox("CHKPEstimacion").Enabled = True : End If + End If + + If e.Row.DBCampo("PermitirEstimacion").ToString = "1" Then + ' e.Row.FCCheckBox("CHKPEstimacion").Checked = True + End If + If Autorizado Then + e.Row.FCLinkButton("imgE").Visible = False + e.Row.FCLinkButton("imgD").Visible = False + End If + + End If + If e.Row.RowState = DataControlRowState.Edit OrElse e.Row.RowState = 5 Then + e.Row.FCDropDownList("DdlUMEdit").DataSource = GlobalDTProductosServiciosEquivalencias(e.Row.DataKey("CvePS").ToString.ToEntero, -1, UsuarioActual.CveEmpresa) + e.Row.FCDropDownList("DdlUMEdit").DataBind() + e.Row.FCDropDownList("DdlUMEdit").SelectedValue = e.Row.DataKey("CveUM") + End If + + End Sub + Protected Sub GVInsumos_RowEditing(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewEditEventArgs) Handles GvInsumos.RowEditing + GvInsumos.EditIndex = e.NewEditIndex + CargaGVPresupuestosInsumos(TmpDT.FiltraParametros("CveTipoPresupuesto=1")) + End Sub + Protected Sub GvInsumos_RowUpdating(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewUpdateEventArgs) Handles GvInsumos.RowUpdating + Dim Cantidad, PU As Double + Dim CvePS, CveContratoDetalle, CveUM As Integer + Dim NoIdentificacion As String = "" + Dim LimitarCantidad As Boolean + + CveContratoDetalle = GvInsumos.Rows(e.RowIndex).DataKey("CveContratoDetalle").ToString.ToEntero + Cantidad = GvInsumos.Rows(e.RowIndex).FCTextBox("TxtCantidad").Text.Trim.ToDouble + PU = GvInsumos.Rows(e.RowIndex).FCTextBox("TxtPU").Text.Trim.ToDouble + CvePS = GvInsumos.Rows(e.RowIndex).DataKey("CvePS").ToString.ToEntero + CveUM = GvInsumos.Rows(e.RowIndex).FCDropDownList("DdlUMEdit").SelectedValue.ToEntero + NoIdentificacion = GvInsumos.Rows(e.RowIndex).FCTextBox("TxtNoIdentificacion").Text.ToString + LimitarCantidad = GvInsumos.Rows(e.RowIndex).FCCheckBox("ChkLimitarCantidad").Checked + + Dim row = TmpDT.Select(String.Format(" CveContratoDetalle={0}", CveContratoDetalle))(0) + + If row("Cantidad").ToString.ToEntero <> Cantidad OrElse row("PU").ToString.ToEntero <> PU OrElse CveUM <> row("CveUM").ToString.ToEntero OrElse row("NoIdentificacion").ToString <> NoIdentificacion OrElse (row("LimitarCantidad").ToString = "True") <> LimitarCantidad Then + + Dim ObjContratos As New ClsContratos + If ObjContratos.UpdateContratosDetalle(CveContratoDetalle, CveContrato, CvePS, Cantidad, PU, UsuarioActual.CveUsuario, NoIdentificacion, LimitarCantidad, "") Then + + If Autorizado Then + Dim msj As String = String.Format("Se realizaron los siguientes cambios, el Presupuesto Interno se modificó: {1} {0} {2:C2} a {3} {0} {4:C2}", + row("PS").ToString, row("Cantidad").ToString, row("PU").ToString, Cantidad, PU) + guardarBitacora(msj) + End If + + row("Cantidad") = Cantidad + row("CantidadContratada") = Cantidad + row("PU") = PU + row("Total") = Cantidad * PU + row("CveUM") = CveUM + row("UM") = GvInsumos.Rows(e.RowIndex).FCDropDownList("DdlUMEdit").SelectedItem.Text + row("NoIdentificacion") = NoIdentificacion + row("LimitarCantidad") = LimitarCantidad + TmpDT.AcceptChanges() + Alert("Cambios realizados correctamente.", TipoMensaje.MsgInformacion) + Else + Alert("Error al Actualizar Detalle", TipoMensaje.MsgError) + End If + ObjContratos.Dispose() + + Else + Alert("Cambios realizados correctamente") + End If + + GvInsumos.EditIndex = -1 + LbTotalGeneralInsumos.Text = TmpDT.FiltraParametros("CveTipoPresupuesto=1").SUM("Total").FormatoNumero + 'LblImporte.Text = LbTotalGeneral.Text + CargaGVPresupuestosInsumos(TmpDT.FiltraParametros("CveTipoPresupuesto=1")) + + End Sub + Protected Sub GVInsumos_RowCancelingEdit(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewCancelEditEventArgs) Handles GvInsumos.RowCancelingEdit + GvInsumos.EditIndex = -1 + CargaGVPresupuestosInsumos(TmpDT.FiltraParametros("CveTipoPresupuesto=1")) + End Sub + Protected Sub GVInsumos_RowDeleting(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewDeleteEventArgs) Handles GvInsumos.RowDeleting + + Dim ObjContratos As New ClsContratos + Dim DbRow As DataRow = Nothing + Dim CveContratoDetalle As Integer = GvInsumos.Rows(e.RowIndex).DataKey("CveContratoDetalle").ToString.ToEntero + DbRow = TmpDT.Select(String.Format(" CveContratoDetalle={0}", CveContratoDetalle))(0) + If Autorizado Then + Dim msj As String = String.Format("Se eliminaron {0} {1} producto {2} con el precio {3}", DbRow("Cantidad"), DbRow("UM"), DbRow("PS"), DbRow("PU")) + guardarBitacora(msj) + End If + + If ObjContratos.RemoveContratosDetalle(CveContratoDetalle, CveContrato) Then + TmpDT.Rows.Remove(DbRow) + CargaGVPresupuestosInsumos(TmpDT.FiltraParametros("CveTipoPresupuesto=1")) + LbTotalGeneralInsumos.Text = GvInsumos.Rows.Cast(Of GridViewRow)().Sum(Function(gvr) gvr.FCLiteral("LtTotal").Text.ToDouble).ToString.FormatoNumero + Else + Alert("Ocurrió un error al eliminar el detalle (Producto/Servicio). Por favor vuelva a intentar", TipoMensaje.MsgError) + End If + + ObjContratos.Dispose() + End Sub + Protected Sub GVInsumos_RowCommand(sender As Object, e As GridViewCommandEventArgs) Handles GvInsumos.RowCommand + If e.CommandName = "Sel" Then + ' Seleccionado = e.CommandArgument.ToString + GvInsumos.SelectRow(e.CommandArgument.ToString.ToEntero - 1) + End If + End Sub +#End Region + + +#End Region + +#Region " TAB PRESUPUESTOS INTERNOS" + + Protected Sub AgregarInt_Click(sender As Object, e As EventArgs) Handles AgregarInt.Click + Dim Row As DataRow = TmpDT.NewRow() + Row("Cantidad") = TxtCantidadInt.Text.ToDouble.FormatoNumero + Row("CveUM") = DdlUMInt.SelectedValue.ToEntero + Row("UM") = DdlUMInt.SelectedItem + Row("CveClasificacion") = DdlClasificacionInt.SelectedValue + Row("Clasificacion") = DdlClasificacionInt.SelectedItem + Row("CvePS") = HFProductoInt.Value + Row("PS") = HFTProductoInt.Value + Row("PU") = TxtPUInt.Text.ToDouble.FormatoNumero + Row("Total") = (TxtCantidadInt.Text.ToDouble * TxtPUInt.Text.ToDouble).FormatoNumero + Row("CveTipoPresupuesto") = 1 + Row("NoIdentificacion") = TxtNoIdentificacionv.Text.Trim + Row("LimitarCantidad") = ChkLimitar.Checked + + Dim ObjContratos As New ClsContratos + If ObjContratos.AddContratosDetalle(CveContrato, Row("CvePS").ToString.ToEntero, Row("Cantidad").ToString.ToDouble, Row("PU").ToString.ToDouble, UsuarioActual.CveUsuario, Row("CveTipoPresupuesto").ToString.ToEntero, Row("NoIdentificacion").ToString, Row("LimitarCantidad").ToString.ToEntero = 1, "") Then + If Autorizado Then + Dim msj As String = String.Format("Se agregaron {0} {1} del producto {2} con un precio ${3}.", Row("Cantidad"), Row("UM"), Row("PS"), Row("PU")) + guardarBitacora(msj) + End If + Row("CveContratoDetalle") = ObjContratos.DtResultados.Rows(0)("CveContratoDetalle") + TmpDT.Rows.Add(Row) + Dim TotalRow = Row("Total").ToString.ToDouble + GvInt.DataSource = TmpDT.FiltraParametros("CveTipoPresupuesto=1") + GvInt.DataBind() + + HFProductoInt.Value = "" + HFTProductoInt.Value = "" + TxtCantidadInt.Text = "" + TxtPUInt.Text = "" + DdlClasificacionInt.SelectedValue = "-1" + LbTotalGeneralInt.Text = (LbTotalGeneralInt.Text.ToDouble + TotalRow).ToString.FormatoNumero + TxtCantidad.Focus() + UPGVInt.Update() + Else + 'Alert("No se pudo agregar el detalle") + End If + ObjContratos.Dispose() + End Sub + + +#Region "GVInternos" + + + Protected Sub GVInt_RowEditing(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewEditEventArgs) Handles GvInt.RowEditing + GvInt.EditIndex = e.NewEditIndex + GvInt.DataSource = TmpDT.FiltraParametros("CveTipoPresupuesto=1") + GvInt.DataBind() + UPGVInt.Update() + End Sub + Protected Sub GvInt_RowUpdating(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewUpdateEventArgs) Handles GvInt.RowUpdating + Dim Cantidad, PU As Double : Dim CvePS, CveContratoDetalle, CveUM As Integer + CveContratoDetalle = GvInt.Rows(e.RowIndex).DataKey("CveContratoDetalle").ToString.ToEntero + Dim NoIdentificacion As String = "" + Dim LimitarCantidad As Boolean + 'Row("NoIdentificacion") = txtNoIdentificacion.Text.Trim + Cantidad = GvInt.Rows(e.RowIndex).FCTextBox("TxtCantidad").Text.Trim.ToDouble + PU = GvInt.Rows(e.RowIndex).FCTextBox("TxtPU").Text.Trim.ToDouble + LimitarCantidad = False + CvePS = GvInt.Rows(e.RowIndex).DataKey("CvePS").ToString.ToEntero + CveUM = GvInt.Rows(e.RowIndex).FCDropDownList("DdlUMEdit").SelectedValue.ToEntero + + 'NoIdentificacion = GvInt.Rows(e.RowIndex).FCDropDownList("NoIdentificacion").ToString + Dim row = TmpDT.Select(String.Format(" CveContratoDetalle={0}", CveContratoDetalle))(0) + Dim c1 = row("Cantidad").ToString.ToEntero + Dim p1 = row("PU").ToString.ToEntero + Dim cvum1 = row("CveUM").ToString.ToEntero + If c1 <> Cantidad OrElse p1 <> PU OrElse CveUM <> cvum1 Then + + Dim ObjContratos As New ClsContratos + If ObjContratos.UpdateContratosDetalle(CveContratoDetalle, CveContrato, CvePS, Cantidad, PU, UsuarioActual.CveUsuario, Nothing, LimitarCantidad, "") Then + If Autorizado Then + Dim msj As String = String.Format("Se realizaron los siguientes cambios, el Presupuesto Interno se modificó: {1} {0} {2:C2} a {3} {0} {4:C2}", + row("PS").ToString, row("Cantidad"), row("PU").ToString, Cantidad, PU) + guardarBitacora(msj) + End If + row("Cantidad") = Cantidad + row("PU") = PU + row("Total") = Cantidad * PU + row("CveUM") = CveUM + row("UM") = GvInt.Rows(e.RowIndex).FCDropDownList("DdlUMEdit").SelectedItem.Text + Else + End If + ObjContratos.Dispose() + Else + Alert("No realizaste ningun Cambio") + End If + GvInt.EditIndex = -1 + GvInt.DataSource = TmpDT.FiltraParametros("CveTipoPresupuesto=1") + GvInt.DataBind() + LbTotalGeneralInt.Text = TmpDT.FiltraParametros("CveTipoPresupuesto=1").SUM("Total").FormatoNumero + End Sub + Protected Sub GVInt_RowCancelingEdit(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewCancelEditEventArgs) Handles GvInt.RowCancelingEdit + GvInt.EditIndex = -1 + GvInt.DataSource = TmpDT.FiltraParametros("CveTipoPresupuesto=1") + GvInt.DataBind() + UPGVInt.Update() + End Sub + Protected Sub GVInt_RowDeleting(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewDeleteEventArgs) Handles GvInt.RowDeleting + Dim ObjContratos As New ClsContratos + Dim DbRow As DataRow = Nothing + Dim CveContratoDetalle As Integer = GvInt.Rows(e.RowIndex).DataKey("CveContratoDetalle").ToString.ToEntero + + If ObjContratos.RemoveContratosDetalle(CveContratoDetalle, CveContrato) Then + DbRow = TmpDT.Select(String.Format(" CveContratoDetalle={0}", CveContratoDetalle))(0) + If Autorizado Then + Dim msj As String = String.Format("Se eliminaron {0} {1} {2} con el precio {3:C2}", DbRow("Cantidad"), DbRow("UM"), DbRow("PS"), DbRow("PU")) + guardarBitacora(msj) + End If + TmpDT.Rows.Remove(DbRow) + GvInt.DataSource = TmpDT.FiltraParametros("CveTipoPresupuesto=1") + GvInt.DataBind() + UPGVInt.Update() + LbTotalGeneralInt.Text = GvInt.Rows.Cast(Of GridViewRow)().Sum(Function(gvr) gvr.FCLabel("LtTotal").Text.ToDouble).ToString.FormatoNumero + Else + Alert("Ocurrió un error al eliminar el detalle (Producto/Servicio). Por favor vuelva a intentar", TipoMensaje.MsgAdvertencia) + End If + + ObjContratos.Dispose() + End Sub + Protected Sub GVInt_RowCommand(sender As Object, e As GridViewCommandEventArgs) Handles GvInt.RowCommand + If e.CommandName = "Sel" Then + ' Seleccionado = e.CommandArgument.ToString + GvInt.SelectRow(e.CommandArgument.ToString.ToEntero - 1) + End If + End Sub +#End Region + +#End Region + +#End Region + +#Region " TAB: REPORTE AVANCES " + Private Sub CargaDatosAvance() + If CveContrato <= 0 Then + Exit Sub + End If + + TabReporteAvance.Visible = True + lbImprimirAvance.Visible = True + + Dim Modalidad = IfNull(Request("Tipo"), 1, 2) + + If Modalidad.ToString.ToEntero = 2 Then + TAB.ActiveTabIndex = 2 + End If + + Dim ObjContratos As New ClsContratos + + If ObjContratos.GetReporteContratosAvancesDetalleCP(CveContrato, UsuarioActual.CveEmpresa) Then + GvDatosAvance.DataSource = ObjContratos.DtResultados + SumaAvance = ObjContratos.DtResultados.SUM("AvanceImporte", "CveClasificacion IS NULL") + SumaUtilidad = ObjContratos.DtResultados.SUM("AvanceUtilidad", "CveClasificacion IS NULL") + DtAvance = ObjContratos.DtResultados + Else + Alert("Ocurrió un Error al obtener el Reporte de Avances. Por favor vuelva a intentar", TipoMensaje.MsgError) + End If + + ObjContratos.Dispose() + GvDatosAvance.DataBind() + + If (GvDatosAvance.Rows.Count > 0) Then + GvDatosAvance.UseAccessibleHeader = True + GvDatosAvance.HeaderRow.TableSection = TableRowSection.TableHeader + RegistraScript("OrdenarGV();") + End If + + UpGral.Update() + End Sub + + Protected Sub GvDatosAvance_RowDataBound(sender As Object, e As GridViewRowEventArgs) Handles GvDatosAvance.RowDataBound + If e.Row.RowType = DataControlRowType.DataRow Then + + If e.Row.DBCampo("CveClasificacion").ToString.ToEntero = 0 Then + e.Row.CssClass = "Totales white" + ElseIf e.Row.DBCampo("CvePS").ToString.ToEntero = 0 Then + e.Row.CssClass = "SubTotales" + End If + + Dim Liga1 = $"{e.Row.DBCampo("CveClasificacion").ToEntero}|{e.Row.DBCampo("Clasificacion")}|{e.Row.DBCampo("CvePS").ToEntero}|{e.Row.DBCampo("CodigoPS")}|1" + e.Row.FCLinkButton("LBAvanceCantidad").CommandArgument = Liga1 + e.Row.FCLinkButton("LBAvanceImporte").CommandArgument = Liga1 + + Dim Liga2 = $"{e.Row.DBCampo("CveClasificacion").ToEntero}|{e.Row.DBCampo("Clasificacion")}|{e.Row.DBCampo("CvePS").ToEntero}|{e.Row.DBCampo("CodigoPS")}|2" + e.Row.FCLinkButton("LBAvanceXFacturarCantidad").CommandArgument = Liga2 + e.Row.FCLinkButton("LBAvanceXFacturarImporte").CommandArgument = Liga2 + + End If + End Sub + Protected Sub MuestaModalVentasAvance(sender As Object, e As EventArgs) + Dim Btn = CType(sender, LinkButton) + Dim Parametros = Btn.CommandArgument.Split("|"c) + + Dim ObjContratos As New ClsContratos + + If ObjContratos.GetVentasAvance(CveContrato, If(Parametros(0).ToEntero > 0, Parametros(0).ToEntero, -1), If(Parametros(2).ToEntero > 0, Parametros(2).ToEntero, -1), If(Parametros(4).ToEntero > 0, Parametros(4).ToEntero, -1)) Then + GvDatosVentasAvance.DataSource = ObjContratos.DtResultados + RegistraScript("$('#ModalVentasAvance').modal('show');RecargaAvances = true;") + Else + Alert("Ocurrió un error al obtener el Listado de Ventas/Remisiones de Avance. Por favor vuelva a intentar", TipoMensaje.MsgError) + End If + + ObjContratos.Dispose() + GvDatosVentasAvance.DataBind() + + + LbTituloModalVentasAvance.Text = If(Parametros(4).ToEntero = 1, "Ventas de Avance", "Remisiones de Avance") + LbClasificacionVentasAvance.Text = Parametros(1) + LbPSVentasAvance.Text = If(Parametros(2).ToEntero > 0, Parametros(3), "") + + UpVentasAvance.Update() + + End Sub +#End Region + +#Region " TAB: REPORTE AVANCES POR DOCUMENTO " + Protected Sub RBLTipoDocto_SelectedIndexChanged(sender As Object, e As EventArgs) + CargaDatosAvancePorDocumento() + End Sub + Private Sub CargaDatosAvancePorDocumento() + If CveContrato <= 0 Then + Exit Sub + End If + + Dim ObjContratos As New ClsContratos + + If ObjContratos.GetContratosAvancePorDocumento(CveContrato, RBLTipoDocto.SelectedValue, UsuarioActual.CveEmpresa) Then + GVAvanceXDocumento.DataSource = ObjContratos.DtResultados + DtAvanceDocumento = ObjContratos.DtResultados + If DtAvanceDocumento.Rows.Count > 0 Then + LBImprimir.Visible = True + End If + LBImprimirInformacionG.Visible = True + Else + Alert("Ocurrió un error al obtener el Reporte de Avances por Documento. Por favor vuelva a intentar", TipoMensaje.MsgError) + End If + + ObjContratos.Dispose() + GVAvanceXDocumento.DataBind() + + If (GVAvanceXDocumento.Rows.Count > 0) Then + GVAvanceXDocumento.UseAccessibleHeader = True + GVAvanceXDocumento.HeaderRow.TableSection = TableRowSection.TableHeader + RegistraScript("OrdenarGVPorDocumento();") + End If + + UpGral.Update() + End Sub + + Private Sub GVAvanceXDocumento_RowDataBound(sender As Object, e As GridViewRowEventArgs) Handles GVAvanceXDocumento.RowDataBound + If e.Row.RowType = DataControlRowType.DataRow Then + If Not e.Row.DBCampo("CveVenta").ToEntero > 0 Then + e.Row.Cells(2).Text = "TOTAL: " + e.Row.Cells(0).HorizontalAlign = HorizontalAlign.Right + e.Row.Cells(0).Text = e.Row.DBCampo("Cantidad").FormatoNumero(0) + e.Row.CssClass = "Totales" + End If + End If + End Sub + +#End Region + +#Region " TAB: CONTRATO GASTOS " + Private Sub MandaCorreo(Para As String, Asunto As String, Body As String) + Dim a As String = String.Format("{0} -- {1} ---- -->", Asunto, Para) + Dim Mail As New ClsSisMail() + Mail.SendMail(ClsPaginas.EmpresaNotificaciones, Para, Asunto, Body) + End Sub + Protected Sub EnvioCorreo(Dr As DataRow) + Dim Body As String = GeneraCorreoContratoGasto(Dr) + Dim Asunto As String = $"Se agrego un gasto en el {LtlTitulo.Text}" + Dim Correo As String = "" + If UsuarioActual.CveEmpresa = 72 Then + Correo = "anamartinez@compuproveedores.com;benjamincarrillo@compuproveedores.com" + Else + Correo = "signotificaciones@adssistemas.mx" + End If + Try + Dim Hilo As New System.Threading.Thread(Sub() MandaCorreo(Correo, Asunto, Body)) + Hilo.Start() + Catch ex As Exception + OnError("Ocurrió error al mandar MAIL", ex) + End Try + End Sub + Public Function GeneraCorreoContratoGasto(Dr As DataRow) As String + Dim strBody As New StringBuilder + strBody.Append(" ") + strBody.Append(" ") + strBody.Append(" ") + strBody.Append(" ") + strBody.Append(" ") + strBody.Append("
    ") + strBody.AppendFormat("
    Datos {0} ", "del contrato") + strBody.Append(" ") + strBody.Append(" ") + strBody.AppendFormat(" ") + strBody.Append(" ") + strBody.Append(" ") + strBody.AppendFormat(" ", Dr("DescripcionContrato").ToString) + strBody.Append(" ") + strBody.Append(" ") + strBody.AppendFormat(" ", Dr("NombreComercial").ToString) + strBody.Append(" ") + strBody.Append(" ") + strBody.AppendFormat(" ", Dr("Monto").ToString.FormatoNumero) + strBody.Append(" ") + strBody.Append(" ") + strBody.AppendFormat(" ", Dr("SubProyectoContrato")) + strBody.Append(" ") + strBody.Append(" ") + strBody.AppendFormat(" ", Dr("FechaInicial")) + strBody.Append(" ") + strBody.Append(" ") + strBody.AppendFormat(" ", Dr("FechaFinal")) + strBody.Append(" ") + strBody.Append(" ") + strBody.AppendFormat(" ", Dr("ContratoAvance").ToString.FormatoNumero) + strBody.Append(" ") + strBody.Append("
    No. Contrato: " + Dr("NumeroContrato").ToString + "
    Descripcion:{0}  
    Cliente:{0}  
    Monto Adjudicado:{0}  
    SubProyecto:{0}  
    Fecha Inicio:{0}  
    Fecha Final:{0}  
    Avance:{0}%  
    ") + strBody.Append("
    ") + strBody.Append("
    ") + strBody.AppendFormat("
    Datos {0} ", "del gasto") + strBody.Append(" ") + strBody.Append(" ") + strBody.AppendFormat(" ", TxtDescripcion.Text) + strBody.Append(" ") + strBody.Append(" ") + strBody.AppendFormat(" ", TxtImporteC.Text.FormatoNumero) + strBody.Append(" ") + strBody.Append(" ") + strBody.AppendFormat(" ", TxtFecha.Text.ToDate.ToShortDateString) + strBody.Append(" ") + strBody.Append("
    Descripción:{0}  
    Importe:{0}  
    Fecha:{0}  
    ") + strBody.Append("
    ") + strBody.Append("
    ") + strBody.Append("
    ") + strBody.AppendFormat(" Ir al contrato ", "http://sig.adssistemas.mx/", CveContrato) + strBody.Append("
    ") + strBody.Append("") + Return strBody.ToString + End Function + + Protected Sub LBAgregar_Click(sender As Object, e As EventArgs) Handles LBAgregar.Click + Dim ObjContrato As New ClsContratos + If ObjContrato.AddContratoGasto(CveContrato, TxtDescripcion.Text, TxtImporteC.Text.ToDecimal, TxtFecha.Text.ToDate, UsuarioActual.CveUsuario) Then + MensajeAlert = New StringBuilder + MensajeAlert.AppendFormat("El Gasto del contrato se guardó correctamente.") + MensajeAlert.AppendFormat("

    ", Encripta(String.Format("OP=CONG&CVECONTRATO={0}&CVECONTRATOGASTO={1}", CveContrato, ObjContrato.CveContratoGasto))) + If ObjContrato.GetContratos(CveContrato, UsuarioActual.CveEmpresa) Then + If ObjContrato.DtResultados.Rows.Count > 0 Then + EnvioCorreo(ObjContrato.DtResultados.Rows(0)) + End If + End If + TxtDescripcion.Text = "" + TxtImporteC.Text = "" + TxtFecha.Text = "" + Alert(MensajeAlert.ToString, TipoMensaje.MsgInformacion) + CargaGVGastos() + RegistraScript("$('#ModalAgregarGastos').modal('hide');") + MensajeAlert = Nothing + End If + ObjContrato.Dispose() + End Sub + + Private Sub CargaGVGastos() + Dim objContrato As New ClsContratos + If objContrato.GetContratoGastos(CveContrato) Then + DtGastos = objContrato.DtResultados + GvContratosGastos.DataSource = DtGastos + SumaGasto = objContrato.DtResultados.SUM("Importe", "CveContratoGasto IS NULL") + Else + GvContratosGastos.DataSource = Nothing + End If + objContrato.Dispose() + GvContratosGastos.DataBind() + + If GvContratosGastos.Rows.Count > 0 Then + GvContratosGastos.HeaderRow.CssClass = "SinColor" + LBImprimirGastos.Visible = True + End If + + UpContratoGasto.Update() + End Sub + + Protected Sub GvContratoGastos_RowDataBound(ByVal sender As Object, ByVal e As GridViewRowEventArgs) Handles GvContratosGastos.RowDataBound + If e.Row.RowType = DataControlRowType.DataRow Then + + If e.Row.DBCampo("CveContrato").ToString.ToEntero = 0 Or e.Row.DBCampo("CveVenta").ToString.ToEntero > 0 Then + If e.Row.DBCampo("CveContrato").ToString.ToEntero = 0 Then e.Row.CssClass = "SubTotales" : e.Row.Cells(0).Text = e.Row.DBCampo("Cantidad").FormatoNumero(0) + e.Row.FCLinkButton("imgE").Visible = False + e.Row.FCLinkButton("imgD").Visible = False + e.Row.FCLinkButton("LnkDescargar").Visible = False + Else + Dim lb As LinkButton = CType(e.Row.FindControl("LnkDescargar"), LinkButton) + ScriptManager.GetCurrent(Me).RegisterAsyncPostBackControl(lb) + End If + End If + End Sub + + Protected Sub GvContratoGastos_RowDeleting(ByVal sender As Object, ByVal e As GridViewDeleteEventArgs) Handles GvContratosGastos.RowDeleting + Dim objContrato As New ClsContratos + If objContrato.RemoveContratoGasto(GvContratosGastos.DataKeys(e.RowIndex).Value.ToString.ToEntero) Then + GvContratosGastos.EditIndex = -1 + Alert("Se eliminó correctamente el gasto del contrato") + CargaGVGastos() + End If + objContrato.Dispose() + End Sub + + Protected Sub GvContratosGastos_RowEditing(ByVal sender As Object, ByVal e As GridViewEditEventArgs) Handles GvContratosGastos.RowEditing + GvContratosGastos.EditIndex = e.NewEditIndex + CargaGVGastos() + End Sub + + Protected Sub GvContratosGastos_RowUpdating(ByVal sender As Object, ByVal e As GridViewUpdateEventArgs) Handles GvContratosGastos.RowUpdating + Dim objContrato As New ClsContratos + + Dim CveContratoGasto As Integer = GvContratosGastos.DataKeys(e.RowIndex).Value.ToString.ToEntero + Dim Observaciones As String = GvContratosGastos.Rows(e.RowIndex).FCTextBox("TxtDescripcion").Text.Trim + Dim Importe As Decimal = GvContratosGastos.Rows(e.RowIndex).FCTextBox("TxtImporteC").Text.Trim.ToDecimal + Dim Fecha As Date = GvContratosGastos.Rows(e.RowIndex).FCTextBox("TxtFecha").Text.Trim.ToDate + + If objContrato.UpdateContratoGasto(CveContratoGasto, Observaciones, Importe, Fecha, UsuarioActual.CveUsuario) Then + GvContratosGastos.EditIndex = -1 + CargaGVGastos() + End If + objContrato.Dispose() + End Sub + Protected Sub GvContratosGastos_RowCancelingEdit(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewCancelEditEventArgs) Handles GvContratosGastos.RowCancelingEdit + GvContratosGastos.EditIndex = -1 + CargaGVGastos() + End Sub + + Protected Sub LnkDescargar_Click1(sender As Object, e As EventArgs) + Dim gvRow As GridViewRow = DirectCast((DirectCast(sender, LinkButton)).NamingContainer, GridViewRow) + RegistraScript($"window.location.href = '/Compras/PopUpVerFactura.aspx?P={Encripta(String.Format("OP=CONG&CVECONTRATO={0}&CVECONTRATOGASTO={1}", CveContrato, gvRow.DataKey("CveContratoGasto").ToString))}'") + End Sub +#End Region + +#Region "TAB: PEDIDOS / DEVOLUCIONES" + Private Sub CargaDatosPedDev() + Dim ObjContratos As New ClsContratos + If ObjContratos.GetRepDevolucionesPedidos(Me.CveContrato, MinFecha, MaxFecha, -1, -1, UsuarioActual.CveEmpresa) Then + DsDatosPedDev = ObjContratos.DsResultados + + GvPedidos.DataSource = DsDatosPedDev.Tables(0) + GvDevs.DataSource = DsDatosPedDev.Tables(1) + End If + ObjContratos.Dispose() + + GvPedidos.DataBind() + GvDevs.DataBind() + + UpPedidosDevoluciones.Update() + End Sub + Protected Sub ImgExcelPedDev_Click(sender As Object, e As EventArgs) Handles LbImprimirPedDevExcel.Click + GenerarPDFPedDev("Excel") + End Sub + Protected Sub ImgImprimirPedDev_Click(sender As Object, e As EventArgs) Handles LbImprimirPedDev.Click + GenerarPDFPedDev() + End Sub + Private Sub GenerarPDFPedDev(Optional Formato As String = "PDF") + If DsDatosPedDev Is Nothing Then + Alert("No se pudieron consultar los pedidos y devoluciones", TipoMensaje.MsgAdvertencia) + Exit Sub + End If + + Dim Imagen As New System.IO.FileInfo(String.Format("{0}/Logo.png", UsuarioActual.Empresa.Ruta)) + Dim logouri = String.Format("{0}://{1}:{2}/Empresas/{3}/Logo.png", Request.Url.Scheme, Request.Url.Host, Request.Url.Port, UsuarioActual.CveEmpresa) + + Dim params As New List(Of ReportParameter) + + params.Add(New ReportParameter("NombreEmpresa", UsuarioActual.Empresa.Empresa)) + params.Add(New ReportParameter("FechaInicio", "-1")) + params.Add(New ReportParameter("FechaFin", "-1")) + params.Add(New ReportParameter("UsuarioImprimio", UsuarioActual.Nombre)) + params.Add(New ReportParameter("FechaImpresion", Now.ToDateTime.ToShortDateString)) + params.Add(New ReportParameter("Contrato", Me.Titulo)) + params.Add(New ReportParameter("Estatus", "")) + params.Add(New ReportParameter("Tipo", "-1")) + + If Imagen.Exists Then + params.Add(New ReportParameter("LogoPath", logouri)) + Else + params.Add(New ReportParameter("LogoPath", "")) + End If + + Dim lrds As New List(Of ReportDataSource) + lrds.Add(New ReportDataSource("DataSet1", DsDatosPedDev.Tables(0))) + lrds.Add(New ReportDataSource("DataSet2", DsDatosPedDev.Tables(1))) + + ImprimirPDF("Empresas/Grales/Formatos/RepPedDevolucionesXContrato.rdlc", lrds, params, "ReportePedidosDevoluciones", Formato) + + End Sub + + Protected Sub GvPedidos_RowDataBound(sender As Object, e As GridViewRowEventArgs) + If e.Row.RowType = DataControlRowType.DataRow Then + + 'CABECERA + If e.Row.DBCampo("CodigoPS") = "" Then + e.Row.CssClass = "SubTotales2" + e.Row.Attributes.Add("style", "background-color:#B9B5B4 !important;") + e.Row.Cells(0).Text = "" + e.Row.Cells(4).Text = "" + e.Row.Cells(5).Text = "" + + Dim Texto = $"Pedido: {e.Row.DBCampo("SerieFolio")} | " + Texto += If(e.Row.DBCampo("CveMovimiento").ToString = "", " SIN MOVIMIENTO DE ALMACÉN", $"Folio Almacén: {e.Row.DBCampo("Folio")}") + + e.Row.Cells(0).ColumnSpan = 2 + e.Row.Cells(1).Visible = False + e.Row.Cells(0).Text = Texto + e.Row.Cells(0).HorizontalAlign = HorizontalAlign.Left + Else + + If e.Row.DBCampo("CveMovimiento").ToString = "" Then + e.Row.Cells(1).Text = "SIN MOVIMIENTO DE ALMACÉN" + End If + + End If + End If + End Sub + Protected Sub GvDevs_RowDataBound(sender As Object, e As GridViewRowEventArgs) + If e.Row.RowType = DataControlRowType.DataRow Then + + 'CABECERA + If e.Row.DBCampo("CodigoPS") = "" Then + e.Row.CssClass = "SubTotales2" + e.Row.Attributes.Add("style", "background-color:#B9B5B4 !important;") + e.Row.Cells(0).Text = "" + e.Row.Cells(4).Text = "" + e.Row.Cells(5).Text = "" + + Dim Texto = $"Devolución: {e.Row.DBCampo("SerieFolio")} | " + Texto += If(e.Row.DBCampo("CveMovimiento").ToString = "", " SIN MOVIMIENTO DE ALMACÉN", $"Folio Almacén: {e.Row.DBCampo("Folio")}") + + e.Row.Cells(0).ColumnSpan = 2 + e.Row.Cells(1).Visible = False + e.Row.Cells(0).Text = Texto + e.Row.Cells(0).HorizontalAlign = HorizontalAlign.Left + Else + + If e.Row.DBCampo("CveMovimiento").ToString = "" Then + e.Row.Cells(1).Text = "SIN MOVIMIENTO DE ALMACÉN" + End If + + End If + End If + End Sub + +#End Region + +#Region " TAB: ALMACEN - ACTIVOS FIJBtnAlmacenEsInterno_ClickOS " + Private Sub CargaInventarios() + + Dim ObjInventarios As New ClsInventarios + 'cargar también los movimentos detalle + If ObjInventarios.GetMovimientosDetalleContrato(CveContrato, UsuarioActual.CveEmpresa, DdlEsinternoExternoFiltro.SelectedValue.ToEntero) Then + DtMovimientos = ObjInventarios.DtResultados + Else + Alert("Ocurrió un error al cargar la información de los Activos Fijos. Por favor vuelva a intentar.", TipoMensaje.MsgError) + End If + ObjInventarios.Dispose() + + If DtMovimientos.Rows.Count > 0 Then + CargaGVDatosInventarios() + CargaDatosPedDev() + 'BtnDevolucionAlmacen.Visible = True + CveMovimientoDevolucion = -1 + If CveMovimientoDevolucion > 0 Then + HLSurtirAF.Visible = False + BtnDevolucionAlmacen.Visible = False + End If + Else + DivSinRegistrosAlmacen.Visible = True + GvDatosAlmacen.DataSource = Nothing + GvDatosAlmacen.DataBind() + + End If + + 'CARGA MODALIDAD ALMACEN + If TipoContrato.Contiene(8, 17) Then ' cuando es consignacion + HLSurtirAF.Visible = False + HLSurtirMercancia.NavigateUrl = $"/Ventas/Ventas.aspx?CveContrato={CveContrato}&Tipo=1" + Else + HLSurtirMercancia.Visible = False + HLSurtirAF.NavigateUrl = $"/Ventas/Ventas.aspx?CveContrato={CveContrato}&Tipo=0" + End If + + UpAlmacen.Update() + + End Sub + + Protected Sub RBLAlmacen_SelectedIndexChanged(sender As Object, e As EventArgs) + CargaGVDatosInventarios() + End Sub + Private Sub CargaGVDatosInventarios() + Select Case RBLAlmacen.SelectedValue + Case "-1" + GvDatosAlmacen.DataSource = DtMovimientos + Actualiza(DtMovimientos) + Case "Vig" + GvDatosAlmacen.DataSource = DtMovimientos.FiltraParametros($"(CodigoPS IS NULL AND Cantidad - CantidadDevolucion > 0) OR (CodigoPS IS NOT NULL AND SerieFolioDevolucion IS NULL)") + Actualiza(DtMovimientos.FiltraParametros($"(CodigoPS IS NULL AND Cantidad - CantidadDevolucion > 0) OR (CodigoPS IS NOT NULL AND SerieFolioDevolucion IS NULL)")) + Case "Dev" + GvDatosAlmacen.DataSource = DtMovimientos.FiltraParametros($"SerieFolioDevolucion IS NOT NULL") + Actualiza(DtMovimientos.FiltraParametros($"SerieFolioDevolucion IS NOT NULL")) + Case Else + End Select + GvDatosAlmacen.DataBind() + End Sub + + Public Sub Actualiza(DT As DataTable) + + LblAFInternos.Text = DT.SUM("Cantidad", "CveMovimientoDetalle > 0 AND EsInterno = 1 ").ToString + LblAFExternos.Text = DT.SUM("Cantidad", "CveMovimientoDetalle > 0 AND (EsInterno = 0 OR EsInterno IS NULL)").ToString + + 'Dim ValorAF = DT.SUM("ValorImporte", "CveMovimientoDetalle > 0 AND TipoDocto = 'Ped'") - DT.SUM("ValorImporte", "TipoDocto = 'DPe'") + + LBLAFValorActivo.Text = DT.SUM("ValorImporte", "CveMovimientoDetalle > 0").ToString("###,###,###.00") + + Dim Total = DT.SUM("Cantidad", "CveMovimientoDetalle > 0 AND TipoDocto = 'Ped'") - DT.SUM("Cantidad", "TipoDocto = 'DPe'") + + LBLAFTotal.Text = DT.SUM("Cantidad", "CveMovimientoDetalle > 0").ToString() + UPAFResumen.Update() + + End Sub + Protected Sub GvDatosAlmacen_RowDataBound(sender As Object, e As GridViewRowEventArgs) Handles GvDatosAlmacen.RowDataBound + If e.Row.RowType = DataControlRowType.DataRow Then + + 'CABECERA + If e.Row.DBCampo("CodigoPS") = "" Then + e.Row.CssClass = "SubTotales2" + e.Row.Attributes.Add("style", "background-color:#B9B5B4 !important;") + e.Row.Cells(0).Text = "" + e.Row.Cells(4).Text = "" + e.Row.Cells(5).Text = "" + + Dim Texto = $"{If(e.Row.DBCampo("TipoDocto") = "Ped", "Pedido", "Devolución") }: {e.Row.DBCampo("SerieFolio")} | " + Texto += If(e.Row.DBCampo("CveMovimiento").ToString = "", " SIN MOVIMIENTO DE ALMACÉN", $"Folio Almacén: {e.Row.DBCampo("Folio")}") + + + e.Row.Cells(0).ColumnSpan = 2 + e.Row.Cells(1).Visible = False + 'e.Row.Cells(2).Visible = False + e.Row.Cells(0).Text = Texto + e.Row.Cells(0).HorizontalAlign = HorizontalAlign.Left + + If e.Row.DBCampo("TipoDocto") = "Ped" Then + If e.Row.DBCampo("Cantidad").ToDecimal - e.Row.DBCampo("CantidadDevolucion").ToDecimal > 0 Then + e.Row.Cells(9).Text = If(e.Row.DBCampo("CveMovimiento").ToString = "", "", $" Solicitud de devolución de pedido") + Else + e.Row.Cells(9).Text = "" + End If + End If + + Else + If e.Row.DBCampo("CveMovimiento").ToString = "" Then + e.Row.Cells(1).Text = "SIN MOVIMIENTO DE ALMACÉN" + End If + If e.Row.DBCampo("TipoDocto") = "Ped" Then + If e.Row.DBCampo("Cantidad").ToDecimal - e.Row.DBCampo("CantidadDevolucion").ToDecimal > 0 Then + e.Row.Cells(9).Text = If(e.Row.DBCampo("CveMovimiento").ToString = "", "", $" Solicitud de devolución de pedido") + End If + End If + + + e.Row.FCCheckBox("ChkEsInterno").Visible = True + + End If + + 'If e.Row.DBCampo("SerieLote").ToString = "-1" Then + ' e.Row.Cells(7).Text = "" + 'End If + End If + End Sub + + Private Sub BtnFiltraInternosExternos_Click(sender As Object, e As EventArgs) Handles BtnFiltraInternosExternos.Click + CargaInventarios() + End Sub + + + Protected Sub BtnAlmacenEsInterno_Click(sender As Object, e As EventArgs) + + Dim ObjInv As New ClsInventarios() + + For Each GRow As GridViewRow In GvDatosAlmacen.Rows + Dim CveMovimientoDetalle As Integer = GRow.DataKey("CveMovimientoDetalle").ToEntero + Dim ChkEsInterno = GRow.FCCheckBox("ChkEsInterno") + + If CveMovimientoDetalle > 0 And ChkEsInterno.Checked And DdlEsInterno.SelectedValue.ToEntero > 0 Then + Dim EsInterno As Boolean + + Select Case DdlEsInterno.SelectedValue.ToEntero + Case 1 + EsInterno = True + Case 2 + EsInterno = False + End Select + + If Not (ObjInv.UpdateMovimientoDetalleEsInterno(UsuarioActual.CveEmpresa, CveMovimientoDetalle, EsInterno)) Then + Exit For + End If + + End If + Next + + ObjInv.Dispose() + + LnkAjusteAF.Visible = True + DivHajusteAF.Visible = False + GvDatosAlmacen.Columns(6).Visible = False + + CargaInventarios() + UPHajusteAF.Update() + UpHajusteAcciones.Update() + + End Sub + + + Protected Sub LnkAjusteAF_Click(sender As Object, e As EventArgs) + + LnkAjusteAF.Visible = False + DivHajusteAF.Visible = True + GvDatosAlmacen.Columns(6).Visible = True + + CargaInventarios() + + UPHajusteAF.Update() + UpHajusteAcciones.Update() + UpAlmacen.Update() + + End Sub + + + +#Region " DEVOLUCION ALMACEN " + Protected Sub BtnDevolucionAlmacen_Click(sender As Object, e As EventArgs) + Dim ObjVentas As New ClsVentas + ObjVentas.IniciaTransacSQL() + Dim TieneError = False + + For Each Dr As DataRow In DtMovimientos.FiltraParametros("CveVenta IS NOT NULL AND CveMovimiento IS NOT NULL AND EsDevolucionVenta = 0", "", {"CveVenta"}).Rows + If Not ObjVentas.UpdateVentasDevolucionAlmacen(1, Dr("CveVenta").ToString.ToEntero) Then + TieneError = True + End If + Next + + + If Not TieneError Then + ObjVentas.Commit() + Alert("La solicitud de devolución se guardo correctamente.", TipoMensaje.MsgInformacion) + Else + ObjVentas.RollBack() + Alert("Ocurrió un error al guardar la solicitud de devolución. Por favor vuelva a intentar.", TipoMensaje.MsgError) + End If + + ObjVentas.Dispose() + End Sub + + + + + Public Sub CargaDatosEncabezado() + + TablaUtilidad.Visible = True + LblUtilidad.Text = $"$ {(SumaAvance - SumaGasto).ToString.FormatoNumero()}" + + If (SumaAvance - SumaGasto) < 0 Then LblUtilidad.ForeColor = Drawing.Color.Red + LblFacturado.Text = SumaAvance.FormatoNumero + LblPorFacturar.Text = (LblImporte.Text.ToDouble - SumaAvance).FormatoNumero + + End Sub + +#End Region + +#End Region + +#Region "TAB SISTEMA" + Protected Sub ChkPermitirAvance_CheckedChanged(sender As Object, e As EventArgs) + Dim ObjContrato As New ClsContratos + Dim Row As GridViewRow = DirectCast(DirectCast(sender, CheckBox).NamingContainer, GridViewRow) + ObjContrato.PermitirAvance(Gv.DataKeys(Row.RowIndex).Value.ToString.ToEntero, DirectCast(sender, CheckBox).Checked) + ObjContrato.Dispose() + Alert("Se ha permitido avance a la sección", TipoMensaje.MsgInformacion) + CargaDatos() + End Sub + + Protected Sub ChkPermitirEstimacion_CheckedChanged(sender As Object, e As EventArgs) + Dim ObjContrato As New ClsContratos + Dim Row As GridViewRow = DirectCast(DirectCast(sender, CheckBox).NamingContainer, GridViewRow) + ObjContrato.PermitirEstimacion(Gv.DataKeys(Row.RowIndex).Value.ToString.ToEntero, DirectCast(sender, CheckBox).Checked) + ObjContrato.Dispose() + Alert("Se ha permitido estimar en la sección", TipoMensaje.MsgInformacion) + CargaDatos() + End Sub +#End Region + +#End Region + +#Region " BITACORA " + Private Sub guardarBitacora(Descripcion As String) + Dim ObjEventoBitacora As New ClsOIEventos + If ObjEventoBitacora.AddEventoBitacora(Descripcion, "", UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa, CveContrato:=CveContrato) Then + cargarBitacora() + End If + ObjEventoBitacora.Dispose() + End Sub + + Private Sub cargarBitacora() + Dim ObjEventoBitacora As New ClsOIEventos + If ObjEventoBitacora.GetEventos(-1, -1, -1, "-1", "-1", -1, -1, -1, -1, -1, -1, "-1", -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa, CveContrato:=CveContrato) Then + GvEB.DataSource = ObjEventoBitacora.DtResultados.FiltraParametros("CveTipoEvento = 6 OR CveTipoEvento = 2") + GvEB.DataBind() + HlEvento.NavigateUrl = "/OI/PopUpAgenda.aspx?CveTipoEvento=2&CveContrato=" & ViewState("CveContrato").ToString & "&TB_iframe=true&height=370&width=600;" + ' UpBitacora.Update() + End If + ObjEventoBitacora.Dispose() + End Sub + Protected Sub GVEventoBitacora_RowDataBound(sender As Object, e As GridViewRowEventArgs) Handles GvEB.RowDataBound + If e.Row.RowType = DataControlRowType.DataRow Then + If e.Row.RowIndex = 0 Then + e.Row.Cells(0).Width = Unit.Pixel(200) + e.Row.Cells(1).Width = Unit.Pixel(200) + e.Row.Cells(2).Width = Unit.Pixel(100) + 'e.Row.Cells(3).Width = Unit.Pixel(500) 'VARIABLE PARA QUE SEA LO MAS GRANDE POSIBLE + e.Row.Cells(4).Width = Unit.Pixel(100) + e.Row.Cells(5).Width = Unit.Pixel(5) + End If + Dim asd As String = e.Row.DBCampo("Archivo").ToString + + If e.Row.DBCampo("Archivo").ToString <> "" And e.Row.DBCampo("Archivo").ToString <> "-1" Then + e.Row.FCLinkButton("LinkArchivo").Visible = True + e.Row.FCLinkButton("LinkArchivo").CommandArgument = String.Format("OI\{0}", e.Row.DBCampo("Archivo").ToString) + ScriptManager.GetCurrent(Me).RegisterPostBackControl(e.Row.FCLinkButton("LinkArchivo")) 'Registro un evento Postbacktrigger, que recargue toda la pagina para que funcione + End If + + e.Row.Cells(3).HorizontalAlign = HorizontalAlign.Left + + If e.Row.DataKey("CveUsuarioIng").ToEntero = UsuarioActual.CveUsuario Then + e.Row.FCLinkButton("LinkEliminarBitacora").Visible = True + End If + + End If + End Sub + + Protected Sub BtnGuardarEventoBitacora_Click(sender As Object, e As EventArgs) Handles BtnGuardarEventoBitacora.Click + Dim ObjEventoBitacora As New ClsOIEventos + + Dim FileExtension As String = "-1" + Dim Filesgral As List(Of Archivo) = txtFileBit.getfiles().Archivos + Dim Filename As String = "" + + For Each fileItem As Archivo In Filesgral + FileExtension = IO.Path.GetExtension(String.Format("{0}Temp\{1}", AppDomain.CurrentDomain.BaseDirectory, fileItem.filename)).Replace(".", "") + Filename = fileItem.filename + Next + + If ObjEventoBitacora.AddEventoBitacora(TxtEventoDescripcion.Text.Trim, String.Format(".{0}", FileExtension), UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa, CveContrato:=CveContrato) Then + If Filename <> "" Then + Filename.FilesMove(String.Format("OI{0}", ObjEventoBitacora.CveEvento.ToString), String.Format("Empresas\{0}\OI", UsuarioActual.CveEmpresa)) + End If + + cargarBitacora() + TxtEventoDescripcion.Text = "" + txtFileBit.getfiles().Archivos.Clear() + + txtFileBit.Text = "" + Alert("La bitácora/observación se guardó correctamente", TipoMensaje.MsgInformacion) + RegistraScript("$('#ModalBitacora').modal('hide')", "hidemodal") + + End If + ObjEventoBitacora.Dispose() + GvEB.DataBind() + + UPEventoBitacora.Update() + 'CargaEventoBitacora() + UPAddEventoBitacora.Update() + End Sub + + + Protected Sub DownloadFile(ByVal sender As Object, ByVal e As EventArgs) + Dim filePath As String = String.Format("{0}{1}", UsuarioActual.Empresa.Ruta, CType(sender, LinkButton).CommandArgument) + Dim Archivo As New System.IO.FileInfo(filePath) + + HttpContext.Current.Response.Clear() + HttpContext.Current.Response.ClearContent() + HttpContext.Current.Response.ContentType = "application/octet-stream" + HttpContext.Current.Response.AppendHeader("Content-disposition", "attachment; filename=" + Path.GetFileName(filePath)) + HttpContext.Current.Response.AddHeader("Content-Length", Archivo.Length.ToString()) + HttpContext.Current.Response.TransmitFile(filePath) + HttpContext.Current.Response.Flush() + HttpContext.Current.Response.End() + + Archivo = Nothing + End Sub + + Protected Sub GvEB_RowDeleting(sender As Object, e As GridViewDeleteEventArgs) + Dim ObjEventoBitacora As New ClsOIEventos + If ObjEventoBitacora.RemoveEvento(GvEB.Rows(e.RowIndex).DataKey("CveEvento").ToEntero(), UsuarioActual.CveEmpresa) Then + cargarBitacora() + LimpiaModalBitacora() + Alert("El evento se elimino correctamente de la bitácora.", TipoMensaje.MsgInformacion) + End If + ObjEventoBitacora.Dispose() + End Sub + + Protected Sub LimpiaModalBitacora() + TxtEventoDescripcion.Text = "" + txtFileBit.getfiles().Archivos.Clear() + + txtFileBit.Text = "" + End Sub + +#End Region + +#Region "SUBIR EXCEL" + Public Sub DescargarFormato() + Dim Directorio As String = ModExtensiones.DirectorioBaseEmpresas & "Empresas\Grales\Formatos\FormatoContrato.xlsx" + Dim Archivo As New IO.FileInfo(Directorio) + If Archivo.Exists Then + Response.Clear() + Response.ClearHeaders() + Response.ClearContent() + Response.AddHeader("Content-Disposition", "attachment; filename=" + Archivo.Name) + Response.AddHeader("Content-Length", Archivo.Length.ToString()) + Response.ContentType = "text/plain" + Response.Flush() + Response.TransmitFile(Archivo.FullName) + Response.End() + End If + End Sub + Public Sub LbDescargarExcel_Click(sender As Object, e As EventArgs) Handles LbDescargarExcel.Click + DescargarFormato() + End Sub + Private Function ReadExcelFile(ByVal flatFilePath As String, ByVal firstRowHasHeaders As Boolean) As DataTable + SpreadsheetInfo.SetLicense(ModExtensiones.SerialGemBoxSpreadsheet) + Dim excelFile As ExcelFile = ExcelFile.Load(flatFilePath) + + Dim unnamed As Integer = 0 + Dim cols As Integer + Dim columns As String() + Dim curRow As Integer = 0 + Dim curCol As Integer = 0 + Dim dataTable As DataTable = New DataTable() + Dim worksheet As ExcelWorksheet = excelFile.Worksheets(0) + + For cols = 0 To worksheet.Rows(0).AllocatedCells.Count - 1 + + If firstRowHasHeaders Then + + If worksheet.Rows(0).Cells(cols).Value IsNot Nothing Then + dataTable.Columns.Add(worksheet.Rows(0).Cells(cols).Value.ToString()) + Else + dataTable.Columns.Add("Unnamed Column " & (System.Threading.Interlocked.Increment(unnamed))) + End If + + curRow = 1 + Else + dataTable.Columns.Add("Column " & (cols + 1)) + End If + Next + + While curRow < worksheet.Rows.Count + columns = New String(cols - 1) {} + + For curCol = 0 To cols - 1 + + If worksheet.Rows(curRow).Cells(curCol).Value Is Nothing Then + columns(curCol) = "" + Else + columns(curCol) = worksheet.Rows(curRow).Cells(curCol).Value.ToString() + End If + Next + + dataTable.Rows.Add(columns) + curRow += 1 + End While + + Return dataTable + End Function + + Private Sub CargarArchivo(Ruta As String, FileName As String, Tipo As String) + Dim dt As New DataTable + dt = ReadExcelFile(Ruta + FileName, True) + Dim ErrorArchivo = False + + 'Dim Conexion As Odbc.OdbcConnection = Nothing + 'Try + ' Select Case Tipo + ' Case "EXCEL" + ' Conexion = New Odbc.OdbcConnection("Driver={Microsoft Excel Driver (*.xls, *.xlsx, *.xlsm, *.xlsb)};DBQ=" + Ruta + FileName + ";") + ' Conexion.Open() + ' Dim cmd = Conexion.CreateCommand() + ' cmd.CommandType = CommandType.Text + ' cmd.CommandText = "SELECT * FROM [Hoja1$]" + ' Dim DataAdapter = New Odbc.OdbcDataAdapter(cmd) + ' DataAdapter.Fill(dt) + ' Case Else + ' Alert("El archivo no tiene el formato correcto", TipoMensaje.MsgError) + ' Exit Sub + ' End Select + 'Catch ex As Exception + ' ErrorArchivo = True + ' OnError("Ocurrio un error al leer el archivo
    " & ex.Message, ex) + 'End Try + 'Conexion.Close() + If Not ErrorArchivo AndAlso dt IsNot Nothing Then + If Not dt.Columns(0).ColumnName = "OC Interna" Then + Alert("El nombre de la primera columna debe ser 'OC Interna'. Favor de corregirlo", TipoMensaje.MsgError) + Exit Sub + End If + If Not dt.Columns(1).ColumnName = "Cantidad" Then + Alert("El nombre de la primera columna debe ser 'Cantidad'. Favor de corregirlo", TipoMensaje.MsgError) + Exit Sub + End If + If Not dt.Columns(2).ColumnName = "Clave Interna Cliente" Then + Alert("El nombre de la segunda columna debe ser 'Clave Interna'. Favor de corregirlo", TipoMensaje.MsgError) + Exit Sub + End If + If Not dt.Columns(3).ColumnName = "Código" Then + Alert("El nombre de la tercera columna debe ser 'Código'. Favor de corregirlo", TipoMensaje.MsgError) + Exit Sub + End If + If Not dt.Columns(4).ColumnName = "Código Barras" Then + Alert("El nombre de la cuarta columna debe ser 'Código Barras'. Favor de corregirlo", TipoMensaje.MsgError) + Exit Sub + End If + If Not dt.Columns(5).ColumnName = "Producto/Servicio" Then + Alert("El nombre de la quinta columna debe ser 'Producto/Servicio'. Favor de corregirlo", TipoMensaje.MsgError) + Exit Sub + End If + If Not dt.Columns(6).ColumnName = "UM" Then + Alert("El nombre de la sexta columna debe ser 'U.M'. Favor de corregirlo", TipoMensaje.MsgError) + Exit Sub + End If + If Not dt.Columns(7).ColumnName = "Precio Unitario" Then + Alert("El nombre de la septima columna debe ser 'Precio Unitario'. Favor de corregirlo", TipoMensaje.MsgError) + Exit Sub + End If + + dt.TableName = "Datos" + + If Not ErrorArchivo Then + NumRow = 1 + Dim RowNoEncontrados As String = String.Empty + Dim NumAgregados As Integer = 0 + For Each Row As DataRow In dt.Rows + Dim Cantidad As Integer = Row("Cantidad").ToString.ToEntero + Dim Codigo As String = Row("Código").ToString.Trim.ToUpper + Dim CodigoBarras As String = Row("Código Barras").ToString.Trim.ToUpper + Dim UM As String = Row("UM").ToString + Dim ClaveInterna As String = Row("Clave Interna Cliente").ToString.Trim.ToUpper + Dim OCInterna As String = Row("OC Interna").ToString.Trim.ToUpper + Dim ProductoServicio As String = Row("Producto/Servicio").ToString.Trim.ToUpper + Dim PrecioUnitario As Double = Row("Precio Unitario").ToString.ToDouble + Dim CvePS As Integer = 0 + Dim CveUM As Integer = 0 ' GlobalDTPS(UsuarioActual.CveEmpresa).FiltroPrimeroValor("CveUnidadMedida", $"CvePS = '{CvePS}'").ToString.ToEntero + Dim CodigoPS As Integer = 0 + Dim Total As Double = (Cantidad * PrecioUnitario) + + + NumRow = NumRow + 1 + + If Codigo.Length > 0 Then + Dim StrArray() As String = GetPS("Codigo", Codigo).Split("|"c) + If StrArray.Length > 0 Then + If CBool(StrArray(0)) = True Then + CvePS = StrArray(1).ToEntero + Else + RowNoEncontrados &= StrArray(1) & "<\BR>" + End If + End If + ElseIf CodigoBarras.Length > 0 Then + Dim StrArray() As String = GetPS("CodigoBarras", CodigoBarras).Split("|"c) + If StrArray.Length > 0 Then + If CBool(StrArray(0)) = True Then + CvePS = StrArray(1).ToEntero + Else + RowNoEncontrados &= StrArray(1) & "<\BR>" + End If + End If + ElseIf ProductoServicio.Length > 0 Then + Dim StrArray() As String = GetPS("PS", ProductoServicio).Split("|"c) + If StrArray.Length > 0 Then + If CBool(StrArray(0)) = True Then + CvePS = StrArray(1).ToEntero + Else + RowNoEncontrados &= StrArray(1) & "<\BR>" + End If + End If + Else + RowNoEncontrados &= "<\BR>    - En la fila " & NumRow & " no se especificó código, código de barras ó descripción." + End If + CveUM = GlobalDTPS(UsuarioActual.CveEmpresa, CvePS:=CvePS).FiltroPrimeroValor("CveUnidadMedida", "").ToString.ToEntero + + If TmpDT IsNot Nothing AndAlso CvePS > 0 Then + Dim dr As DataRow = TmpDT.NewRow + dr("Cantidad") = Cantidad + dr("CantidadContratada") = Cantidad + dr("CveUM") = CveUM + dr("UM") = UM + dr("CveClasificacion") = GlobalDTPS(UsuarioActual.CveEmpresa, CvePS:=CvePS).FiltroPrimeroValor("CveClasificacion", "").ToString.ToEntero + dr("Clasificacion") = GlobalDTClasificaciones(UsuarioActual.CveEmpresa).FiltroPrimeroValor("Clasificacion", $"CveClasificacion = '{dr("CveClasificacion")}'").ToString + dr("CvePS") = CvePS + dr("PS") = GlobalDTPS(UsuarioActual.CveEmpresa, CvePS:=dr("CvePS").ToString.ToEntero).FiltroPrimeroValor("PS", "").ToString + dr("CodigoPS") = dr("PS") + dr("PU") = PrecioUnitario + dr("Total") = Cantidad * PrecioUnitario + dr("CveTipoPresupuesto") = 2 + dr("NoIdentificacion") = ClaveInterna + dr("OCInterna") = OCInterna + dr("LimitarCantidad") = 0 + + If CvePS > 0 Then + Dim ObjContratos As New ClsContratos + If ObjContratos.AddContratosDetalle(CveContrato, dr("CvePS").ToString.ToEntero, dr("Cantidad").ToString.ToDouble, dr("PU").ToString.ToDouble, UsuarioActual.CveUsuario, dr("CveTipoPresupuesto").ToString.ToEntero, dr("NoIdentificacion").ToString, dr("LimitarCantidad").ToString.ToEntero = 1, dr("OCInterna").ToString) Then + Dim msj As String = String.Format("Se agregaron {0} {1} del producto {2} con un precio ${3}.", dr("Cantidad"), dr("UM"), dr("PS"), dr("PU")) + guardarBitacora(msj) + dr("CveContratoDetalle") = ObjContratos.DtResultados.Rows(0)("CveContratoDetalle") + TmpDT.Rows.Add(dr) + Dim TotalRow = dr("Total").ToString.ToDouble + + CargaGVPresupuestos(TmpDT.FiltraParametros("CveTipoPresupuesto=2")) + LbTotalGeneral.Text = (LbTotalGeneral.Text.ToDouble + TotalRow).ToString.FormatoNumero + LblImporte.Text = LbTotalGeneral.Text + Else + Alert("Ocurrio un error al agregar el detalle", TipoMensaje.MsgError) + End If + ObjContratos.Dispose() + End If + + + End If + Next + 'Cargo el GridView + Gv.DataSource = TmpDT + Gv.DataBind() + UpGV.Update() + + + If RowNoEncontrados.Length > 0 Then + Alert("Los siguientes Productos o Servicios no se encontraron en la Base de Datos.<\BR>" & RowNoEncontrados, TipoMensaje.MsgAdvertencia) + Else + Alert("Se Cargaron " & NumRow & " Productos o Servicios correctamente.") + End If + End If + End If + End Sub + + Private Function GetPS(Opt As String, Valor As String) As String + Dim StrReturn As String = String.Empty + Dim CvePS As Integer = 0 + CvePS = GlobalDTPS(UsuarioActual.CveEmpresa).FiltroPrimeroValor("CvePS", Opt & " = '" & Valor & "'").ToString.ToEntero + If CvePS > 0 Then + StrReturn = "True|" & CvePS.ToString + Else + + StrReturn = "False|    - No se encontró " & Valor & " en la fila " & NumRow & ", columna " & Opt + End If + Return StrReturn + End Function + + Private Sub BtnCargaExcel_Click(sender As Object, e As EventArgs) Handles BtnCargaExcel.Click + If TxtExcel.getfiles().Archivos.Count > 0 Then + Dim file As Archivo = TxtExcel.getfiles().Archivos(0) + Dim Directorio As String = AppDomain.CurrentDomain.BaseDirectory & file.patch + Dim Tipo As String = If(file.Extencion.Contiene("xlsx", "xlsx", "xlsm", "xlsb"), "EXCEL", "CSV") + CargarArchivo(Directorio, file.filename, Tipo) + Else + Alert("No existe el archivo. Favor de subir un archivo excel a la plataforma.", TipoMensaje.MsgError) + End If + End Sub + + +#End Region + +#Region " GPS " + 'Private Sub CargaCuentasEquipos() + + ' Dim GPS As New ClsGPS + ' If GPS.DispositivosGet(-1, -1, DdlCliente.SelectedValue.ToEntero) Then + ' DdlCuentaEquipo.DataSource = GPS.DtResultados + ' Else + ' DdlCuentaEquipo.DataSource = Nothing + ' End If + ' GPS.Dispose() + ' DdlCuentaEquipo.DataBind() + ' UpGral.Update() + + 'End Sub + + 'Private Sub CargaPeriodos() + ' Dim ObjContratos As New ClsContratos + ' If ObjContratos.GetPeriodos(-1, UsuarioActual.CveEmpresa) Then + ' DtPeriodo = ObjContratos.DtResultados + ' Else + ' DtPeriodo = Nothing + ' End If + ' DdlPeriodo.DataSource = DtPeriodo + ' ObjContratos.Dispose() + ' DdlPeriodo.DataBind() + ' UpGral.Update() + 'End Sub +#End Region + +#Region " IMPRESION " + +#Region " IMPRIMIR AVANCE POR DOCUMENTO " + Protected Sub ImgImprimir_Click(sender As Object, e As EventArgs) Handles LBImprimir.Click + GenerarPDF() + End Sub + Private Sub GenerarPDF(Optional Formato As String = "PDF") + + Dim Imagen As New System.IO.FileInfo(String.Format("{0}/Logo.png", UsuarioActual.Empresa.Ruta)) + Dim logouri = String.Format("{0}://{1}:{2}/Empresas/{3}/Logo.png", Request.Url.Scheme, Request.Url.Host, Request.Url.Port, UsuarioActual.CveEmpresa) + + Dim dt As DataTable = DtAvanceDocumento.FiltraParametros("CveVenta > 0") + Dim params As New List(Of ReportParameter) + params.Add(New ReportParameter("NombreEmpresa", UsuarioActual.Empresa.Empresa)) + params.Add(New ReportParameter("UsuarioImprimio", UsuarioActual.Nombre)) + params.Add(New ReportParameter("FechaImpresion", Now.ToDateTime.ToShortDateString)) + params.Add(New ReportParameter("Contrato", Titulo)) + + 'Datos NUEVOS + params.Add(New ReportParameter("Proveedor", Contratante)) + params.Add(New ReportParameter("FechaInicio", TxtFechaInicial.Text.Trim)) + params.Add(New ReportParameter("FechaFin", TxtFechaFinal.Text.Trim)) + params.Add(New ReportParameter("TipoContrato", TipoDocumento)) + params.Add(New ReportParameter("TotalContrato", LblImporte.Text)) + If Imagen.Exists Then + params.Add(New ReportParameter("LogoPath", logouri)) + Else + params.Add(New ReportParameter("LogoPath", "")) + End If + Dim Nombre As String = If(LtlTitulo.Text.Length > 20, LtlTitulo.Text.Substring(0, 20), LtlTitulo.Text) + ImprimirPDF("Empresas/Grales/Formatos/RepContratoAvanceDocumento.rdlc", dt, params, $"{Nombre}-AvanceDocumento", Formato:=Formato) + End Sub + Private Sub LBImprimirInformacionG_Click(sender As Object, e As EventArgs) Handles LBImprimirInformacionG.Click + Dim Imagen As New System.IO.FileInfo(String.Format("{0}/Logo.png", UsuarioActual.Empresa.Ruta)) + Dim logouri = String.Format("{0}://{1}:{2}/Empresas/{3}/Logo.png", Request.Url.Scheme, Request.Url.Host, Request.Url.Port, UsuarioActual.CveEmpresa) + + Dim dt As DataTable = DtAvanceDocumento + Dim params As New List(Of ReportParameter) + params.Add(New ReportParameter("NombreEmpresa", UsuarioActual.Empresa.Empresa)) + params.Add(New ReportParameter("UsuarioImprimio", UsuarioActual.Nombre)) + params.Add(New ReportParameter("FechaImpresion", Now.ToDateTime.ToShortDateString)) + params.Add(New ReportParameter("Contrato", Titulo)) + 'DATOS DEL CONTRATO + params.Add(New ReportParameter("NoContrato", TxtNumeroContrato.Text.Trim)) + params.Add(New ReportParameter("Descripcion", TxtDescripcionContrato.Text.Trim)) + params.Add(New ReportParameter("Proveedor", If(TrProveedor.Visible = True, DdlContratista.SelectedItem.Text.Trim, "-"))) + params.Add(New ReportParameter("Ubicacion", TxtUbicacion.Text.Trim)) + params.Add(New ReportParameter("Responsable", TxtResponsable.Text.Trim)) + params.Add(New ReportParameter("Almacen", "-")) + params.Add(New ReportParameter("Porcentaje", "-")) + 'CENTRO DE COSTOS + params.Add(New ReportParameter("Proyecto", If(DVddlproyecto.Visible = True, DdlProyecto.SelectedItem.Text.Trim, "-"))) + params.Add(New ReportParameter("SubProyecto", CveSubProyecto.ToString)) + params.Add(New ReportParameter("Addendum", "")) + 'INFORMACION + params.Add(New ReportParameter("Cliente", If(TrCliente.Visible = True, DdlCliente.SelectedItem.Text.Trim, "-"))) + params.Add(New ReportParameter("Sucursal", If(TrClienteSucursal.Visible = True, DdlSucursalCliente.SelectedItem.Text.Trim, "-"))) + params.Add(New ReportParameter("FechaInicial", TxtFechaInicial.Text.Trim)) + params.Add(New ReportParameter("FechaFinal", TxtFechaFinal.Text.Trim)) + params.Add(New ReportParameter("Moneda", DdlMoneda.SelectedItem.Text.Trim)) + params.Add(New ReportParameter("TipoCambio", If(tipoCambio.Visible = True, TxtTipoCambio.Text.Trim, "-"))) + params.Add(New ReportParameter("IVA", TxtPorIVA.Text.Trim)) + params.Add(New ReportParameter("Anticipo", TxtPorAnticipo.Text.Trim)) + params.Add(New ReportParameter("Amortizacion", TxtPorAmortizacionAnticipo.Text.Trim)) + params.Add(New ReportParameter("Garantia", TxtPorGarantia.Text.Trim)) + params.Add(New ReportParameter("Minimo", "-")) + params.Add(New ReportParameter("Maximo", "-")) + params.Add(New ReportParameter("Total", If(DvTotal.Visible = True, TxtTotal.Text.Trim, "-"))) + 'Estatus + params.Add(New ReportParameter("Estatus", DdlEstatus.SelectedItem.Text.Trim)) + params.Add(New ReportParameter("TipoGarantia", "")) + params.Add(New ReportParameter("EstatusFianza", "")) + params.Add(New ReportParameter("Folio", "0")) + params.Add(New ReportParameter("FechaVencimiento", "")) + + If Imagen.Exists Then + params.Add(New ReportParameter("LogoPath", logouri)) + Else + params.Add(New ReportParameter("LogoPath", "")) + End If + ImprimirPDF("Empresas/Grales/Formatos/Contrato.rdlc", dt, params, $"Contrato-{Titulo}", Formato:="PDF") + + End Sub + + +#End Region + +#Region "I M P R E S I O N D E G A S T O S" + Protected Sub ImgImprimirGastos_Click(sender As Object, e As EventArgs) Handles LBImprimirGastos.Click + GenerarPDFGastos() + End Sub + Private Sub GenerarPDFGastos(Optional Formato As String = "PDF") + + Dim Imagen As New System.IO.FileInfo(String.Format("{0}/Logo.png", UsuarioActual.Empresa.Ruta)) + Dim logouri = String.Format("{0}://{1}:{2}/Empresas/{3}/Logo.png", Request.Url.Scheme, Request.Url.Host, Request.Url.Port, UsuarioActual.CveEmpresa) + Dim UtilidadGastos As String = IIf(LblUtilidad.Text <> "", LblUtilidad.Text, "-").ToString + + + Dim dt As DataTable = DtGastos + Dim params As New List(Of ReportParameter) + params.Add(New ReportParameter("NombreEmpresa", UsuarioActual.Empresa.Empresa)) + params.Add(New ReportParameter("UsuarioImprimio", UsuarioActual.Nombre)) + params.Add(New ReportParameter("FechaImpresion", Now.ToDateTime.ToShortDateString)) + params.Add(New ReportParameter("Contrato", TituloCorto)) + + 'Datos NUEVOS + params.Add(New ReportParameter("Proveedor", Contratante)) + params.Add(New ReportParameter("FechaInicio", TxtFechaInicial.Text.Trim)) + params.Add(New ReportParameter("FechaFin", TxtFechaFinal.Text.Trim)) + params.Add(New ReportParameter("TipoContrato", TipoDocumento)) + params.Add(New ReportParameter("TotalContrato", LblImporte.Text)) + params.Add(New ReportParameter("Utilidad", UtilidadGastos)) + + If Imagen.Exists Then + params.Add(New ReportParameter("LogoPath", logouri)) + Else + params.Add(New ReportParameter("LogoPath", "")) + End If + Dim Nombre As String = If(LtlTitulo.Text.Length > 20, LtlTitulo.Text.Substring(0, 20), LtlTitulo.Text) + ImprimirPDF("Empresas/Grales/Formatos/RepContratoGastos.rdlc", dt, params, $"{Nombre}-Gastos", Formato:=Formato) + End Sub + + Private Sub LBAgregarGasto_Click(sender As Object, e As EventArgs) Handles LBAgregarGasto.Click + TxtDescripcion.Text = "" + TxtImporteC.Text = "" + TxtFecha.Text = "" + UpAgregarGastos.Update() + RegistraScript("$('#ModalAgregarGastos').modal();") + End Sub + +#End Region + +#Region "I M P R E S I O N D E S U M I N I S T R O S" + Protected Sub ImgImprimirSuministros_Click(sender As Object, e As EventArgs) Handles LbImprimirSuministros.Click + GenerarPDFSuministros() + End Sub + Private Sub GenerarPDFSuministros(Optional Formato As String = "PDF") + Dim Imagen As New System.IO.FileInfo(String.Format("{0}/Logo.png", UsuarioActual.Empresa.Ruta)) + Dim logouri = String.Format("{0}://{1}:{2}/Empresas/{3}/Logo.png", Request.Url.Scheme, Request.Url.Host, Request.Url.Port, UsuarioActual.CveEmpresa) + + Dim dt As DataTable = DtSuministros + Dim params As New List(Of ReportParameter) + params.Add(New ReportParameter("NombreEmpresa", UsuarioActual.Empresa.Empresa)) + params.Add(New ReportParameter("UsuarioImprimio", UsuarioActual.Nombre)) + params.Add(New ReportParameter("FechaImpresion", Now.ToDateTime.ToShortDateString)) + params.Add(New ReportParameter("Contrato", TituloCorto)) + + 'Datos NUEVOS + params.Add(New ReportParameter("Proveedor", Contratante)) + params.Add(New ReportParameter("FechaInicio", TxtFechaInicial.Text.Trim)) + params.Add(New ReportParameter("FechaFin", TxtFechaFinal.Text.Trim)) + params.Add(New ReportParameter("TipoContrato", TipoDocumento)) + params.Add(New ReportParameter("TotalContrato", LblImporte.Text)) + If Imagen.Exists Then + params.Add(New ReportParameter("LogoPath", logouri)) + Else + params.Add(New ReportParameter("LogoPath", "")) + End If + Dim Nombre As String = If(LtlTitulo.Text.Length > 20, LtlTitulo.Text.Substring(0, 20), LtlTitulo.Text) + ImprimirPDF("Empresas/Grales/Formatos/RepContratoSuministros.rdlc", dt, params, $"{Nombre}-Suministros", Formato:=Formato) + End Sub +#End Region + +#Region "I M P R E S I O N D E A V A N C E " + Private Sub lbImprimirAvance_Click(sender As Object, e As EventArgs) Handles lbImprimirAvance.Click + GenerarPDFAvance() + End Sub + Private Sub GenerarPDFAvance(Optional Formato As String = "PDF") + Dim Imagen As New System.IO.FileInfo(String.Format("{0}/Logo.png", UsuarioActual.Empresa.Ruta)) + Dim logouri = String.Format("{0}://{1}:{2}/Empresas/{3}/Logo.png", Request.Url.Scheme, Request.Url.Host, Request.Url.Port, UsuarioActual.CveEmpresa) + + Dim dt As DataTable = DtAvance + Dim params As New List(Of ReportParameter) + params.Add(New ReportParameter("NombreEmpresa", UsuarioActual.Empresa.Empresa)) + params.Add(New ReportParameter("UsuarioImprimio", UsuarioActual.Nombre)) + params.Add(New ReportParameter("FechaImpresion", Now.ToDateTime.ToShortDateString)) + params.Add(New ReportParameter("Contrato", TituloCorto)) + + 'Datos NUEVOS + params.Add(New ReportParameter("Proveedor", Contratante)) + params.Add(New ReportParameter("FechaInicio", TxtFechaInicial.Text.Trim)) + params.Add(New ReportParameter("FechaFin", TxtFechaFinal.Text.Trim)) + params.Add(New ReportParameter("TipoContrato", TipoDocumento)) + params.Add(New ReportParameter("TotalContrato", LblImporte.Text)) + + If Imagen.Exists Then + params.Add(New ReportParameter("LogoPath", logouri)) + Else + params.Add(New ReportParameter("LogoPath", "")) + End If + Dim Nombre As String = If(LtlTitulo.Text.Length > 20, LtlTitulo.Text.Substring(0, 20), LtlTitulo.Text) + ImprimirPDF("Empresas/Grales/Formatos/ContratoAvance.rdlc", dt, params, $"{Nombre}-Avance", Formato:=Formato) + End Sub +#End Region + +#Region "I M P R E S I O N D E P R E S U P U E S T O " + Private Sub lLbImprimirPresupuesto_Click(sender As Object, e As EventArgs) Handles LbImprimirPresupuesto.Click + GenerarPDFPPresupuesto() + End Sub + Private Sub GenerarPDFPPresupuesto(Optional Formato As String = "PDF") + Dim Imagen As New System.IO.FileInfo(String.Format("{0}/Logo.png", UsuarioActual.Empresa.Ruta)) + Dim logouri = String.Format("{0}://{1}:{2}/Empresas/{3}/Logo.png", Request.Url.Scheme, Request.Url.Host, Request.Url.Port, UsuarioActual.CveEmpresa) + + Dim dt As DataTable = DtPresupuestos + Dim params As New List(Of ReportParameter) + params.Add(New ReportParameter("NombreEmpresa", UsuarioActual.Empresa.Empresa)) + params.Add(New ReportParameter("UsuarioImprimio", UsuarioActual.Nombre)) + params.Add(New ReportParameter("FechaImpresion", Now.ToDateTime.ToShortDateString)) + params.Add(New ReportParameter("Contrato", TituloCorto)) + + 'Datos NUEVOS + params.Add(New ReportParameter("Proveedor", Contratante)) + params.Add(New ReportParameter("FechaInicio", TxtFechaInicial.Text.Trim)) + params.Add(New ReportParameter("FechaFin", TxtFechaFinal.Text.Trim)) + params.Add(New ReportParameter("TipoContrato", TipoDocumento)) + params.Add(New ReportParameter("TotalContrato", LblImporte.Text)) + + If Imagen.Exists Then + params.Add(New ReportParameter("LogoPath", logouri)) + Else + params.Add(New ReportParameter("LogoPath", "")) + End If + Dim Nombre As String = If(LtlTitulo.Text.Length > 20, LtlTitulo.Text.Substring(0, 20), LtlTitulo.Text) + ImprimirPDF("Empresas/Grales/Formatos/RepContratoPresupuestos.rdlc", dt, params, $"{Nombre}-Presupuestos", Formato:=Formato) + End Sub +#End Region + +#Region "I M P R E S I O N D E A C T I V O S F I J O S " + Private Sub LbImprmirAF_Click(sender As Object, e As EventArgs) Handles LbImprmirAF.Click + GenerarPDFActivosFijos() + End Sub + Private Sub LbImprmirAFExcel_Click(sender As Object, e As EventArgs) Handles LbImprmirAFExcel.Click + GenerarPDFActivosFijos("Excel") + End Sub + Private Sub GenerarPDFActivosFijos(Optional Formato As String = "PDF") + Dim Imagen As New System.IO.FileInfo(String.Format("{0}/Logo.png", UsuarioActual.Empresa.Ruta)) + Dim logouri = String.Format("{0}://{1}:{2}/Empresas/{3}/Logo.png", Request.Url.Scheme, Request.Url.Host, Request.Url.Port, UsuarioActual.CveEmpresa) + + Dim dt As DataTable = Nothing + + Select Case RBLAlmacen.SelectedValue + Case "-1" + dt = DtMovimientos + Case "Vig" + dt = DtMovimientos.FiltraParametros($"(CodigoPS IS NULL AND Cantidad - CantidadDevolucion > 0) OR (CodigoPS IS NOT NULL AND SerieFolioDevolucion IS NULL)") + Case "Dev" + dt = DtMovimientos.FiltraParametros($"SerieFolioDevolucion IS NOT NULL") + Case Else + End Select + + Dim params As New List(Of ReportParameter) + params.Add(New ReportParameter("NombreEmpresa", UsuarioActual.Empresa.Empresa)) + params.Add(New ReportParameter("UsuarioImprimio", UsuarioActual.Nombre)) + params.Add(New ReportParameter("FechaImpresion", Now.ToDateTime.ToShortDateString)) + params.Add(New ReportParameter("Contrato", TituloCorto)) + + 'Datos NUEVOS + params.Add(New ReportParameter("Proveedor", Contratante)) + params.Add(New ReportParameter("FechaInicio", TxtFechaInicial.Text.Trim)) + params.Add(New ReportParameter("FechaFin", TxtFechaFinal.Text.Trim)) + params.Add(New ReportParameter("TipoContrato", TipoDocumento)) + params.Add(New ReportParameter("TotalContrato", LblImporte.Text)) + + Dim Filtro As String = If(RBLAlmacen.SelectedValue = "-1", "Todos", If(RBLAlmacen.SelectedValue = "Vig", "Vigentes", "Devueltos")) + + params.Add(New ReportParameter("CantInternos", LblAFInternos.Text)) + params.Add(New ReportParameter("CantExternos", LblAFExternos.Text)) + params.Add(New ReportParameter("TotalCant", LBLAFTotal.Text)) + params.Add(New ReportParameter("ValorActivo", LBLAFValorActivo.Text)) + params.Add(New ReportParameter("FiltroContratos", Filtro)) + + If Imagen.Exists Then + params.Add(New ReportParameter("LogoPath", logouri)) + Else + params.Add(New ReportParameter("LogoPath", "")) + End If + Dim Nombre As String = If(LtlTitulo.Text.Length > 20, LtlTitulo.Text.Substring(0, 20), LtlTitulo.Text) + ImprimirPDF("Empresas/Grales/Formatos/RepContratoActivosFijos.rdlc", dt, params, $"{Nombre}-ActivosFijos", Formato:=Formato) + End Sub + + +#End Region + +#Region " IMPRIMIR DOCUMENTO - SABE " + Public Sub DescarFormato(documento As String) + + Dim PathRoot As String = Server.MapPath("/") + Dim PathSource As String + Dim pathDesti As String + + PathSource = $"{UsuarioActual.Empresa.Ruta}\Formatos\Plantillas\{documento}" + pathDesti = PathRoot & "Temp\" & CveContrato & documento + + If File.Exists(pathDesti) Then + File.Delete(pathDesti) + End If + + File.Copy(PathSource, pathDesti) + + Dim objDoc As New clsGemBoxDocument(pathDesti) + Dim FechaActual As String = Now.Day.ToString("0#") & " de " & CultureInfo.CurrentCulture.DateTimeFormat.GetMonthName(1).ToString & " del " & Now.Year.ToString() + + objDoc.SustituirTags(GetDatosTagsDocumentos) + objDoc.Guardar(pathDesti) + + Dim fileinfo As New FileInfo(pathDesti) + + Dim baseUrl As String = Request.Url.GetLeftPart(UriPartial.Authority) + baseUrl = baseUrl & "/temp/" & fileinfo.Name + + RegistraScript("Download('" & baseUrl & "')") + End Sub + + Private Function GetDatosTagsDocumentos() As List(Of TagsDocumentos) + Dim ListaTagsDocumentost = New List(Of TagsDocumentos) + Dim ObjContratos As New ClsContratos + If CveContrato <> -1 Then + If ObjContratos.GetContratos(CveContrato, UsuarioActual.CveEmpresa) Then + ListaTagsDocumentost.Add(New TagsDocumentos("{{NumeroContrato}}", ObjContratos.NumeroContrato)) + ListaTagsDocumentost.Add(New TagsDocumentos("{{DescripcionContrato}}", ObjContratos.DescripcionContrato)) + ListaTagsDocumentost.Add(New TagsDocumentos("{{Ubicacion}}", ObjContratos.Ubicacion)) + ListaTagsDocumentost.Add(New TagsDocumentos("{{Responsable}}", ObjContratos.Responsable)) + ListaTagsDocumentost.Add(New TagsDocumentos("{{FechaInicial}}", ObjContratos.FechaInicial.ToString("d"))) + ListaTagsDocumentost.Add(New TagsDocumentos("{{FechaFinal}}", ObjContratos.FechaFinal.ToString("d"))) + ListaTagsDocumentost.Add(New TagsDocumentos("{{Moneda}}", GlobalDTMonedas().FiltroPrimeroValor("Moneda", $"CveMoneda = {ObjContratos.CveMoneda}"))) + ListaTagsDocumentost.Add(New TagsDocumentos("{{IVA}}", ObjContratos.PorIVA.ToString)) + ListaTagsDocumentost.Add(New TagsDocumentos("{{Anticipo}}", ObjContratos.PorAnticipo.ToString)) + ListaTagsDocumentost.Add(New TagsDocumentos("{{AmortizacionAnticipo}}", ObjContratos.PorAmortizacionAnticipo.ToString)) + ListaTagsDocumentost.Add(New TagsDocumentos("{{Garantia}}", ObjContratos.PorGarantia.ToString)) + If Not IsDBNull(ObjContratos.DtResultados(0)("Periodo")) Then + ListaTagsDocumentost.Add(New TagsDocumentos("{{Periodo}}", ObjContratos.DtResultados(0)("Periodo").ToString)) + End If + If Not IsDBNull(ObjContratos.DtResultados(0)("CveCuentaEquipo")) Then + ListaTagsDocumentost.Add(New TagsDocumentos("{{CuentaEquipo}}", "-1")) + End If + If Not IsDBNull(ObjContratos.DtResultados(0)("NombreComercial")) Then + ListaTagsDocumentost.Add(New TagsDocumentos("{{NombreComercial}}", ObjContratos.DtResultados(0)("NombreComercial").ToString)) + End If + End If + End If + ObjContratos.Dispose() + Return ListaTagsDocumentost + End Function + Private Sub CargaPlantillas() + Dim ObjGral As New ClsGenerales + If ObjGral.ContratosPlantillaGet(-1, UsuarioActual.CveEmpresa) Then + DtPlantillasContratos = ObjGral.DtResultados.FiltraParametros("Tipo = 'Con'") + ' DdlPlantillaContrato.DataSource = DtPlantillasContratos + Else + DtPlantillasContratos = Nothing + End If + ObjGral.Dispose() + 'DdlPlantillaContrato.DataSource = DtPlantillasContratos + 'DdlPlantillaContrato.DataBind() + End Sub + + Protected Sub BtnImprimirC_Click(sender As Object, e As EventArgs) Handles liImprimir.Click + ' Dim docx As String = DtPlantillasContratos.FiltroPrimeroValor("URL", $"CveContratoPlantilla = {DdlPlantillaContrato.SelectedValue}") + ' DescarFormato(docx) + End Sub + +#End Region + + +#End Region + +#Region "CREAR A PARTIR DE" + Private Sub BtnAgregarContratoHijo_Click(sender As Object, e As EventArgs) Handles BtnAgregarContratoHijo.Click + Dim TieneError = False + + Dim ObjContratos As New ClsContratos + ObjContratos.IniciaTransacSQL() + + Try + Dim CveContratoHijo As Integer = -1 + Dim Minimo, Maximo, Total As Double + + Minimo = -1 + Maximo = -1 + Total = -1 + + 'If txtMinimo.Text.ToDouble > 0 And chkDetalleContrato.Checked Then Minimo = txtMinimo.Text.ToDouble Else Minimo = -1 + 'If txtMaximo.Text.ToDouble > 0 And chkDetalleContrato.Checked Then Maximo = txtMaximo.Text.ToDouble Else Maximo = -1 + 'If TxtTotal.Text.ToDouble > 0 And chkDetalleContrato.Checked Then Total = TxtTotal.Text.ToDouble Else Total = -1 + + Dim CveEstatusInicial As Integer = 10 'falta sacar por + If ObjContratos.GetContratosEstatus(UsuarioActual.CveEmpresa) Then + CveEstatusInicial = ObjContratos.DtResultados.FiltroPrimeroValor("CveContratoEstatus", "TipoEstatus=1").ToEntero + End If + + CveContratoHijo = ObjContratos.AddContratos(TxtCodigoApartirDe.Text, TxtDescripcionApartirDe.Text, TxtNumeroLicitacion.Text.Trim, DdlContratista.SelectedValue.ToEntero, DdlCliente.SelectedValue.ToEntero, -1, txtFechaI4.Text.ToDate, txtFechaF4.Text.ToDate, + TxtUbicacion.Text, TxtResponsable.Text, CveSubProyecto, TxtPorIVA.Text.ToDouble, TxtPorAnticipo.Text.ToDouble, TxtPorAmortizacionAnticipo.Text.ToDouble, + TxtPorGarantia.Text.ToDouble, "." & Session("FileExtension").ToString, "", CveContrato, UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa, False, Minimo, Maximo, Total, + DdlMoneda.SelectedValue.ToEntero, ModalidadDetalle, If(UsuarioActual.Empresa.CvePlataforma = 3, 1, CveEstatusInicial), TipoContrato, TxtTipoCambio.Text.ToDouble, CveSucursalCliente:=DdlSucursalCliente.SelectedValue.ToEntero, CveAlmacenOrigen:=-1, CveAlmacenDestino:=-1, PorcentajeComision:=0, + TipoGarantia:=-1, Folio:=0, FechaVenc:=Nothing, EstatusFianza:=-1, CvePeriodo:=-1, CveCuentaEquipo:=-1, CveContratoPlantilla:=-1, CveVendedor:=-1) + + + If CveContratoHijo > 0 Then + + If ChkCantidades.Checked Then + TieneError = AgregarDetalleHijo(CveContratoHijo, ObjContratos) + End If + + If ChkTrasAF.Checked Then + TieneError = AgregarMovimientosAFHijo(CveContratoHijo, ObjContratos) + End If + + Else + TieneError = True + Alert("Ocurrió un error al generar el contrato.", TipoMensaje.MsgError) + End If + + If Not TieneError Then + ObjContratos.Commit() + Dim Msj As New StringBuilder + Msj.Append($"Se ha generado correctamente el contrato {TxtCodigoApartirDe.Text}, a partir del contrato: {TxtNumeroContrato.Text}") + Msj.AppendFormat("
    Ver Contrato", CveContratoHijo) + RegistraScript("$('#ModalCrearApartirDe').modal('hide');") + Alert(Msj.ToString, TipoMensaje.MsgInformacion) + Else + ObjContratos.RollBack() + End If + Catch ex As Exception + ObjContratos.RollBack() + OnError("Ocurrió un error al crear un nuevo contrato.", ex) + Finally + ObjContratos.Dispose() + End Try + + End Sub + + + Private Function AgregarDetalleHijo(CveContratoHijo As Integer, ByRef ObjContratos As ClsContratos) As Boolean + Dim TieneError = False + + Dim Cantidades As Double + For Each Row As DataRow In TmpDT.Rows + Cantidades = Row("CantidadContratada").ToString.ToDouble + 'If ChkCantidades.Checked Then + ' Cantidades = Row("CantidadContratada").ToString.ToDouble + 'Else + ' Cantidades = 0 + 'End If + + If Row("CveTipoPresupuesto").ToString.ToEntero = 1 Then + If ObjContratos.AddContratosDetalle(CveContratoHijo, Row("CvePS").ToString.ToEntero, Cantidades, Row("PU").ToString.ToDouble, UsuarioActual.CveUsuario, Row("CveTipoPresupuesto").ToString.ToEntero, Row("NoIdentificacion").ToString, Row("LimitarCantidad").ToString.ToEntero = 1, "") Then + If Autorizado Then + Dim msj As String = String.Format("Se agregaron {0} {1} del producto {2} con un precio ${3}.", Row("Cantidad"), Row("UM"), Row("PS"), Row("PU")) + guardarBitacora(msj) + End If + Row("CveContratoDetalle") = ObjContratos.DtResultados.Rows(0)("CveContratoDetalle") + Else + TieneError = True + Alert("Ocurrió un error al agregar el detalle del contrato", TipoMensaje.MsgError) + Exit For + End If + ElseIf Row("CveTipoPresupuesto").ToString.ToEntero = 2 Then + If ObjContratos.AddContratosDetalle(CveContratoHijo, Row("CvePS").ToString.ToEntero, Cantidades, Row("PU").ToString.ToDouble, UsuarioActual.CveUsuario, Row("CveTipoPresupuesto").ToString.ToEntero, Row("NoIdentificacion").ToString, Row("LimitarCantidad").ToString.ToEntero = 1, Row("OCInterna").ToString) Then + If Autorizado Then + Dim msj As String = String.Format("Se agregaron {0} {1} del producto {2} con un precio ${3}.", Row("Cantidad"), Row("UM"), Row("PS"), Row("PU")) + guardarBitacora(msj) + End If + Row("CveContratoDetalle") = ObjContratos.DtResultados.Rows(0)("CveContratoDetalle") + Else + TieneError = True + Alert("Ocurrió un error al agregar el detalle del contrato", TipoMensaje.MsgError) + Exit For + End If + End If + Next + + Return TieneError + End Function + + Private Function AgregarMovimientosAFHijo(CveContratoHijo As Integer, ByRef ObjContratos As ClsContratos) As Boolean + Dim TieneError As Boolean = False + + 'BUSCA LOS ACTIVOS FIJOS VIGENTES + Dim Dt As DataTable = DtMovimientos.FiltraParametros($"(CodigoPS IS NULL AND Cantidad - CantidadDevolucion > 0) OR (CodigoPS IS NOT NULL AND SerieFolioDevolucion IS NULL)") + + Dim DtVentas As DataTable = Dt.FiltraParametros($"No = 0") + + For Each Dr As DataRow In DtVentas.Rows + Dim CveVenta As Integer = Dr("CveVenta").ToString.ToEntero + Dim CveMovimiento As Integer = Dr("CveMovimiento").ToString.ToEntero + + TieneError = Not ObjContratos.UpdateMovimientoContrato(CveContratoHijo, CveMovimiento) + + If Not TieneError Then + TieneError = Not ObjContratos.UpdateVentasContrato(CveContratoHijo, CveVenta) + End If + + If TieneError Then + Exit For + End If + Next + + If TieneError Then + Alert("Ocurrió un error al traspasar los activos fijos del contrato", TipoMensaje.MsgError) + End If + + Return TieneError + End Function + + 'Private Sub AgregarMovimientosAFHijo(CveContratoHijo As Integer) + ' 'BUSCA LOS ACTIVOS FIJOS VIGENTES + ' Dim Dt As DataTable = DtMovimientos.FiltraParametros($"(CodigoPS IS NULL AND Cantidad - CantidadDevolucion > 0) OR (CodigoPS IS NOT NULL AND SerieFolioDevolucion IS NULL)") + + + ' Dim DtVentas As DataTable = Dt.FiltraParametros($"No = 0") + + ' Dim CveAlmacenOrigen As Integer = DdlAlmacenOrigen.SelectedValue.ToEntero + ' Dim CveAlmacenDestino As Integer = DdlAlmacenDestino.SelectedValue.ToEntero + ' Dim CveMoneda As Integer = DdlMoneda.SelectedValue.ToEntero + + ' Dim CveConceptoSalida As Integer = 8 + ' Dim CveConceptoEntrada As Integer = 9 + ' Dim CveCliente As Integer = If(UsuarioActual.Empresa.Funcionalidad(146) = "1", -1, DdlCliente.SelectedValue.ToEntero) + + ' Dim ObjInv As New ClsInventarios() + ' Try + ' ObjInv.IniciaTransacSQL() + ' Dim TieneError As Boolean = False + + ' For Each Dr As DataRow In DtVentas.Rows + + ' Dim CveVentaAlmacen As Integer = Dr("CveVenta").ToString.ToEntero + + ' 'Movimiento de salida por traspaso al almacen destino + ' Dim CveMovimientoSalida As Integer = ObjInv.AddMovimiento(CveAlmacenDestino, CveConceptoSalida, CveMoneda, Now, -1, UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa, -1, -1, DdlSubProyectoContrato.SelectedValue.ToEntero, -1, CveContrato:=CveContrato, CveCliente:=CveCliente, CveAlmacenDestino:=CveAlmacenOrigen) + + ' If CveMovimientoSalida > 0 Then + ' For Each Row As DataRow In Dt.FiltraParametros($"CvePS IS NOT NULL AND CveVenta = {CveVentaAlmacen}").Rows + + ' Dim Cantidad As Double = Row("Cantidad").ToString.ToDouble + ' Dim CvePS As Integer = Row("CvePS").ToString.ToEntero + ' Dim CveVentaDetalle As Integer = Row("CveVentaDetalle").ToString.ToEntero + ' Dim CveUnidadMedida As Integer = Row("CveUnidadMedida").ToString.ToEntero + ' Dim PU As Double = Row("PU").ToString.ToDouble + + ' If Not ObjInv.AddMovimientoDetalle(CveMovimientoSalida, Cantidad, CveUnidadMedida, CvePS, PU, -1) Then + ' TieneError = True + ' Exit For + ' End If + ' Next + ' Else + ' TieneError = True + ' Exit For + ' End If + + ' 'Movimeinto de entrada por traspaso al almacen origen + ' Dim CveMovimientoEntrada As Integer = ObjInv.AddMovimiento(CveAlmacenOrigen, CveConceptoEntrada, CveMoneda, Now, -1, UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa, -1, -1, DdlSubProyectoContrato.SelectedValue.ToEntero, -1, CveContrato:=CveContratoHijo, CveCliente:=CveCliente, CveAlmacenDestino:=CveAlmacenDestino) + + ' If CveMovimientoEntrada > 0 Then + ' For Each Row As DataRow In Dt.FiltraParametros($"CvePS IS NOT NULL AND CveVenta = {CveVentaAlmacen}").Rows + + ' Dim Cantidad As Double = Row("Cantidad").ToString.ToDouble + ' Dim CvePS As Integer = Row("CvePS").ToString.ToEntero + ' Dim CveVentaDetalle As Integer = Row("CveVentaDetalle").ToString.ToEntero + ' Dim CveUnidadMedida As Integer = Row("CveUnidadMedida").ToString.ToEntero + ' Dim PU As Double = Row("PU").ToString.ToDouble + + ' If Not ObjInv.AddMovimientoDetalle(CveMovimientoEntrada, Cantidad, CveUnidadMedida, CvePS, PU, -1) Then + ' TieneError = True + ' Exit For + ' End If + ' Next + ' Else + ' TieneError = True + ' Exit For + ' End If + + ' Next + ' If TieneError Then + ' Alert("Ocurrió un error al traspasar los activos fijos", TipoMensaje.MsgAdvertencia) + ' ObjInv.RollBack() + ' Else + ' ObjInv.Commit() + ' End If + + ' Catch ex As Exception + ' ObjInv.RollBack() + ' OnError("Ocurrió un error al traspasar los activos fijos", ex) + ' End Try + ' ObjInv.Dispose() + + + 'End Sub + + + +#End Region + +#Region "FIANZAS" + Protected Sub LimpiarCamposModalFianzas() + txtFolioFianza.Text = "" + TxtModalAdjuntoArchivo.Text = "" + DdlFianza.SelectedValue = "-1" + txtFechaVenFianza.Text = DateTime.Today.ToShortDateString + End Sub + Protected Sub btnAgregarFianza_Click(sender As Object, e As EventArgs) + + LimpiarCamposModalFianzas() + EsEditarFianza = False + txth4Fianza.InnerText = "Agregar Fianza" + LnkDescargar.Visible = False + 'BtnGuardarFianza.Text = "Guardar" + UPModalFianza.Update() + Me.RegistraScript("$('#DvModalFianza').modal();") + 'GvFianzas.DataSource = DtTmpFianzas + 'GvFianzas.DataBind() + 'UpGvFianzas.Update() + End Sub + 'Protected Sub BtnGuardarFianza_Click(sender As Object, e As EventArgs) + + ' Dim dr As DataRow = DtTmpFianzas.NewRow() + + ' Dim Folio As String = txtFolioFianza.Text + ' Dim CveEstatus As Integer = DdlFianza.SelectedValue.ToEntero() + ' Dim Estatus As String = DdlFianza.SelectedItem.Text + + ' Dim TieneError As Boolean = False + + ' Dim Adjunto As String = "" + ' If TxtModalAdjuntoArchivo.getfiles.Archivos.Count > 0 Then + ' Dim ArchivoAdjunto As Archivo = TxtModalAdjuntoArchivo.getfiles.Archivos(0) + ' Adjunto = ArchivoAdjunto.filenameO + ' End If + + + ' If EsEditarFianza Then + ' DtTmpFianzas.Rows.RemoveAt(IndexFianzaEditar) + ' dr("CveContratoFianza") = GvFianzas.Rows(IndexFianzaEditar).DataKey("CveContratoFianza").ToString + ' dr("Folio") = Folio + ' dr("EstatusFianza") = Estatus + ' dr("CveEstatusFianza") = CveEstatus + ' dr("FechaVencimiento") = txtFechaVenFianza.Text + ' dr("Adjunto") = If(Adjunto = "", GvFianzas.Rows(IndexFianzaEditar).DataKey("Adjunto").ToString, Adjunto) + ' Else + ' dr("CveContratoFianza") = "-1" + ' dr("Folio") = Folio + ' dr("EstatusFianza") = Estatus + ' dr("CveEstatusFianza") = CveEstatus + ' dr("FechaVencimiento") = txtFechaVenFianza.Text + ' dr("Adjunto") = Adjunto + ' End If + + ' DtTmpFianzas.Rows.Add(dr) + ' GuardaAdjunto($"{Folio} - {txtFechaVenFianza.Text}") + + ' GvFianzas.DataSource = DtTmpFianzas + ' GvFianzas.DataBind() + ' UpGvFianzas.Update() + + ' LimpiarCamposModalFianzas() + ' Me.RegistraScript("$('#DvModalFianza').modal('hide');") + + 'End Sub + + + + Private Sub GuardaAdjunto(FolioFechaVencimiento As String) + If Not TxtModalAdjuntoArchivo.getfiles.Archivos.Count > 0 Then + Exit Sub + End If + Dim ArchivoAdjunto As Archivo = TxtModalAdjuntoArchivo.getfiles.Archivos(0) + If ArchivoAdjunto.filenameO.Length > 114 Then + Alert("El nombre del archivo excede los 115 caracteres permitidos. Por favor rectifique y vuelva a intentar.", TipoMensaje.MsgAdvertencia) + Exit Sub + End If + + Try + Dim Path As String = String.Format("{0}\\{1}\\{2}\\{3}", UsuarioActual.Empresa.Ruta, "Contratos", "Fianzas", FolioFechaVencimiento) + DirectoryExistsCreate(Path) + Dim ArchivoDestino As String = String.Format("{0}\\{1}", Path, ArchivoAdjunto.filenameO) + If File.Exists(ArchivoDestino) Then + System.IO.File.Delete(ArchivoDestino) + End If + System.IO.File.Move(ArchivoAdjunto.FileUrl, ArchivoDestino) + Catch ex As Exception + Alert("Ocurrió un error al guardar el archivo Adjunto. Por favor vuelva a intentar.", TipoMensaje.MsgError) + End Try + End Sub + 'Private Sub DescargarAdjunto() + ' Dim filename As String = GvFianzas.Rows(IndexFianzaEditar).DataKey("Adjunto").ToString + ' If Not String.IsNullOrEmpty(filename) Then + ' Dim rutaAplicacion As String = HttpContext.Current.Server.MapPath(HttpContext.Current.Request.ApplicationPath) + ' Dim Path As String = String.Format("{0}\\{1}\\{2}\\{3}", UsuarioActual.Empresa.Ruta, "Contratos", "Fianzas", $"{GvFianzas.Rows(IndexFianzaEditar).DataKey("Folio").ToString} - {GvFianzas.Rows(IndexFianzaEditar).DataKey("FechaVencimiento").ToDate.ToShortDateString}") + ' Dim ArchivoDestino As String = String.Format("{0}\\{1}", Path, GvFianzas.Rows(IndexFianzaEditar).DataKey("Adjunto").ToString) + ' Dim toDownload As System.IO.FileInfo = New System.IO.FileInfo(ArchivoDestino) + ' If toDownload.Exists Then + ' Response.ClearContent() + ' Response.ClearHeaders() + ' Response.AddHeader("Content-Disposition", "attachment; filename=" + filename) + ' Response.ContentType = "application/octet-stream" + ' Response.WriteFile(ArchivoDestino) + ' Response.Flush() + ' Response.Close() + ' Response.End() + ' HttpContext.Current.ApplicationInstance.CompleteRequest() + ' End If + ' End If + 'End Sub + + Protected Sub LnkDescargar_Click(sender As Object, e As EventArgs) + 'DescargarAdjunto() + End Sub + 'Protected Sub GvFianzas_RowDeleting(sender As Object, e As GridViewDeleteEventArgs) + + ' DtTmpFianzas.Rows.RemoveAt(e.RowIndex) + ' GvFianzas.DataSource = DtTmpFianzas + ' GvFianzas.DataBind() + ' UpGvFianzas.Update() + + 'End Sub + Protected Sub imgEFianzaGv_Click(sender As Object, e As EventArgs) + LimpiarCamposModalFianzas() + EsEditarFianza = True + + Dim GvRow As GridViewRow = CType(((CType(sender, LinkButton)).NamingContainer), GridViewRow) + + IndexFianzaEditar = GvRow.DataItemIndex + + txtFolioFianza.Text = GvRow.DataKey("Folio").ToString() + DdlFianza.SelectedValue = GvRow.DataKey("CveEstatusFianza").ToString() + txtFechaVenFianza.Text = GvRow.DataKey("FechaVencimiento").ToString() + LnkDescargar.Visible = GvRow.DataKey("Adjunto").ToString <> "" + + txth4Fianza.InnerText = "Editar Fianza" + 'BtnGuardarFianza.Text = "Actualizar" + UPModalFianza.Update() + Me.RegistraScript("$('#DvModalFianza').modal();") + 'GvFianzas.DataSource = DtTmpFianzas + 'GvFianzas.DataBind() + 'UpGvFianzas.Update() + End Sub + Protected Sub CreaDtTmpFianzas() + DtTmpFianzas = New DataTable() + + + DtTmpFianzas.Columns.Add("CveContratoFianza", GetType(String)) + DtTmpFianzas.Columns.Add("Folio", GetType(String)) + DtTmpFianzas.Columns.Add("CveEstatusFianza", GetType(String)) + DtTmpFianzas.Columns.Add("EstatusFianza", GetType(String)) + DtTmpFianzas.Columns.Add("FechaVencimiento", GetType(String)) + DtTmpFianzas.Columns.Add("Adjunto", GetType(String)) + + DtTmpFianzasInicial = DtTmpFianzas.Copy + + 'GvFianzas.DataSource = DtTmpFianzas + 'GvFianzas.DataBind() + 'UpGvFianzas.Update() + End Sub + + Protected Function GuardaFianzas(ObjContrato As ClsContratos) As Boolean + + Dim TieneError As Boolean = False + + For Each row As DataRow In DtTmpFianzas.Rows + Dim Folio As String = row("Folio").ToString() + Dim CveEstatus As Integer = row("CveEstatusFianza").ToString().ToEntero + Dim FechaVen As Date = Date.Parse(row("FechaVencimiento").ToString()) + Dim Adjunto As String = row("Adjunto").ToString() + + ' Si la cve es -1 es nuevo y lo agrega + If row("CveContratoFianza").ToString() = "-1" Then + + If Not ObjContrato.AddContratoFianza(CveContrato, Folio, CveEstatus, FechaVen, Adjunto) Then + TieneError = True + Exit For + End If + Else + Dim CveFianza As Integer = row("CveContratoFianza").ToString().ToEntero + + If Not ObjContrato.UpdateContratoFianza(CveFianza, Folio, CveEstatus, FechaVen, Adjunto) Then + TieneError = True + Exit For + End If + + End If + Next + ' Compara si aun existe la fianza, si ya no existe la elimina + For Each row As DataRow In DtTmpFianzasInicial.Rows + + Dim CveFianza As Integer = row("CveContratoFianza").ToString().ToEntero + Dim filtro As String = String.Format("CveContratoFianza ={0}", CveFianza) + + If DtTmpFianzas.FiltraParametros(filtro).Rows.Count = 0 Then + TieneError = Not ObjContrato.RemoveContratoFianza(CveFianza) + Exit For + End If + Next + + Return Not TieneError + End Function + + Protected Sub LnkDescargaAdjunto_Click(sender As Object, e As EventArgs) + Dim GvRow As GridViewRow = CType(((CType(sender, LinkButton)).NamingContainer), GridViewRow) + IndexFianzaEditar = GvRow.DataItemIndex + ' DescargarAdjunto() + End Sub + Protected Sub GvFianzas_RowDataBound(sender As Object, e As GridViewRowEventArgs) + If e.Row.RowType = DataControlRowType.DataRow Then + If e.Row.DBCampo("Adjunto").ToString <> "" Then + e.Row.FCLinkButton("LnkDescargaAdjunto").Visible = True + Dim lb As LinkButton = CType(e.Row.FindControl("LnkDescargaAdjunto"), LinkButton) + ScriptManager.GetCurrent(Me).RegisterPostBackControl(lb) + End If + End If + End Sub + +#End Region + +#Region "CONVENIO DE PRECIO FIJO" + Protected Sub CargaConvenioPrecioFijo() + '12/04/2018 - oculta campo de licitacion, portlet finanzas y campo tipo de garantia + trLicitacion.Visible = False + 'DivFianzas.Visible = False + 'DivTipoGarantia.Visible = False + + UpGral.Update() + End Sub +#End Region + +#Region "NOMENCLATURA CONTRATOS" + Protected Sub GetNoContratoNuevo() + Dim ObjContratos As New ClsContratos() + + 'Dim TipoContrato As Integer = DdlTipoContrato.SelectedValue.ToEntero() + + + Dim SufijoContrato As String = "" + + Select Case TipoContrato + Case 7 'Contrato Comodato + SufijoContrato = "COM" + Case 8 'Contrato Consignacion + SufijoContrato = "CONSIG" + Case 10 'Contrato de Financiamiento + SufijoContrato = "FIN" + Case 13 'Contrato Servicio Administrado de Impresion (?) + SufijoContrato = "MPS" + Case 28 'Convenio Precio Fijo + SufijoContrato = "CON" + End Select + + Dim Serie As String = String.Format("-{0}-{1}", DateTime.Today.Year, SufijoContrato) + + If ObjContratos.GetContratoNomenclatura(Serie, UsuarioActual.CveEmpresa) Then + TxtNumeroContrato.Text = ObjContratos.DtResultados.Rows(0)("NoContrato").ToString + End If + + ObjContratos.Dispose() + End Sub +#End Region + +#Region "IMPUESOS LOCALES" + 'Protected Sub ChkImpuestosLocales_CheckedChanged(sender As Object, e As EventArgs) + ' If ChkImpuestosLocales.Checked Then + ' GvImpuestosLocales.Visible = True + ' Else + ' GvImpuestosLocales.Visible = False + ' End If + 'End Sub + 'Public Sub CargaImpuestosLocales() + ' Dim ObjContratos As New ClsContratos + ' If ObjContratos.GetContratoImpuestosLocales(CveContrato, UsuarioActual.CveEmpresa) Then + ' GvImpuestosLocales.DataSource = ObjContratos.DtResultados + ' End If + ' ObjContratos.Dispose() + ' GvImpuestosLocales.DataBind() + ' UpImpuestos.Update() + 'End Sub + + +#End Region + + + + + +End Class + +