From 5d21b6ebca92bd51501d4c4d5f834e9707ddcd28 Mon Sep 17 00:00:00 2001 From: rrene Date: Mon, 15 May 2023 18:29:56 -0700 Subject: [PATCH] =?UTF-8?q?--=20actualizaci=C3=B3n=20masiva=20mediante=20l?= =?UTF-8?q?ayout=20de=20ps=20adicionales?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Ventas/CatPS.aspx | 47 ++++++++++++- Ventas/CatPS.aspx.vb | 158 ++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 202 insertions(+), 3 deletions(-) diff --git a/Ventas/CatPS.aspx b/Ventas/CatPS.aspx index ff53aa055..8477021f0 100644 --- a/Ventas/CatPS.aspx +++ b/Ventas/CatPS.aspx @@ -115,7 +115,9 @@
  • Excel Personalizado
  • - +
  • + Cargar Productos Adicionales +
  • <%--onclick="AbrirVentana('/Ventas/ProductosServicios.aspx', 700, 400, 'N', 'PS')"--%> @@ -373,7 +375,48 @@ - + diff --git a/Ventas/CatPS.aspx.vb b/Ventas/CatPS.aspx.vb index 65e31729e..eb24c6069 100644 --- a/Ventas/CatPS.aspx.vb +++ b/Ventas/CatPS.aspx.vb @@ -46,6 +46,9 @@ Partial Class CatPS If UsuarioActual.CveEmpresa = 119 Then DdlEstado.SelectedValue = "-1" End If + If UsuarioActual.Empresa.Funcionalidad(563) <> "" AndAlso Not UsuarioActual.TienePermisoProceso(122) Then + LnkExcelPSAdicional.Visible = True + End If End If End Sub @@ -65,7 +68,6 @@ Partial Class CatPS If TxtCodigoBarras.Text.Trim = "" Then CodigoBarras = "-1" Else CodigoBarras = TxtCodigoBarras.Text.Trim If TxtNombre.Text.Trim = "" Then Nombre = "-1" Else Nombre = TxtNombre.Text.ToUpper.Trim - Dim ObjPS As New ClsProductosServicios If ObjPS.GetPSLite(Ddlclasificacion.SelectedValue.ToEntero, UsuarioActual.Empresa.CveEmpresa, Codigo, CodigoBarras, Nombre, DdlAplicaVenta.SelectedValue.ToEntero, DdlEstado.SelectedValue.ToEntero, DdlCveTipoPS.SelectedValue.ToEntero, DdlTipoClasificacion.SelectedValue.ToEntero) Then DtDatos = ObjPS.DtResultados @@ -285,4 +287,158 @@ Partial Class CatPS End Sub #End Region + +#Region "P R O D U C T O S A D I C I O N A L E S" + + Private Function GuardarProductosEquivalenteEnFranquicia(ObjPS As ClsProductosServicios, CodigoPS As String, PSAdicional As String, Cantidad As Decimal, Opcion As Integer) As Boolean + If UsuarioActual.Empresa.Funcionalidad(563) <> "" Then + + Dim StrEmpresas As String = UsuarioActual.Empresa.Funcionalidad(563) & "," & UsuarioActual.CveEmpresa ' agregamos la empresa actual + Dim EmpresasFranquicia As List(Of Integer) = StrEmpresas.Split(","c).ToList().ConvertAll(Function(x) Convert.ToInt32(x)) + For Each Franquicia As Integer In EmpresasFranquicia + Dim CvePSPagina As Integer = GlobalDTPS(Franquicia).FiltroPrimeroValor("CvePS", String.Format("Codigo = '{0}'", CodigoPS)).ToEntero + Dim CvePSAdicional As Integer + + If Opcion = 1 Then CvePSAdicional = GlobalDTPS(Franquicia).FiltroPrimeroValor("CvePS", String.Format("Codigo = '{0}'", PSAdicional)).ToEntero + + If CvePSPagina <= 0 Then + Alert(String.Format("El producto de la página no existe en la franquicia: '{0}'", GlobalDTEmpresas(Franquicia).FiltroPrimeroValor("Empresa")), TipoMensaje.MsgAdvertencia) + Return False + End If + + If CvePSAdicional <= 0 AndAlso Opcion = 1 Then + Alert(String.Format("El producto adicional no existe en la franquicia: '{0}'", GlobalDTEmpresas(Franquicia).FiltroPrimeroValor("Empresa")), TipoMensaje.MsgAdvertencia) + Return False + End If + + If Opcion = 1 Then + If Not ObjPS.AddPSAdicionales(CvePSPagina, CvePSAdicional, Cantidad) Then + Return False + End If + End If + If Opcion = 2 Then + If Not ObjPS.RemovePSAdicionales(CvePSPagina, -1) Then + Return False + End If + End If + Next + End If + Return True + End Function + + Private Sub LnkExcelPSAdicional_Click(sender As Object, e As EventArgs) Handles LnkExcelPSAdicional.Click + RegistraScript(String.Format("$('#{0}').modal();", "DivCargaExcelPSAdicionales")) + + End Sub + + Protected Sub BtnDescargar_Click(sender As Object, e As EventArgs) Handles BtnDescargarPSAdicional.Click + + GemBox.Spreadsheet.SpreadsheetInfo.SetLicense(ModExtensiones.SerialGemBoxSpreadsheet) + Dim workbook As New GemBox.Spreadsheet.ExcelFile() + Dim worksheet = workbook.Worksheets.Add("Productos") + Dim DtExcel As New DataTable + DtExcel.Columns.Add("CodigoProducto", GetType(String)) + DtExcel.Columns.Add("CodigoProductoAdicional", GetType(String)) + DtExcel.Columns.Add("CantidadFija", GetType(String)) + + worksheet.InsertDataTable(DtExcel, New GemBox.Spreadsheet.InsertDataTableOptions() With + { + .ColumnHeaders = True, + .StartRow = 0, + .StartColumn = 0 + }) + + Dim columnCount = worksheet.CalculateMaxUsedColumns() + For i = 0 To columnCount + worksheet.Columns(i).AutoFit(1, worksheet.Rows(0), worksheet.Rows(worksheet.Rows.Count - 1)) + Next + workbook.Save(Response, $"CargaProductos.xlsx", GemBox.Spreadsheet.SaveOptions.XlsxDefault) + + End Sub + + Protected Sub BtnCargaExcel_Click(sender As Object, e As EventArgs) Handles BtnCargaExcelPSAdicional.Click + If TxtExcel.getfiles().Archivos.Count > 0 Then + Dim file As Archivo = TxtExcel.getfiles().Archivos(0) + + Dim Directorio As String = Server.MapPath("~") & file.path + + Dim Tipo As String = If(file.Extension.Contiene("xlsx", "xlsx", "xlsm", "xlsb"), "EXCEL", "CSV") + CargaArchivoPSAdicional(Directorio, file.filename, Tipo) + Else + Alert("No existe el archivo.Favor de subir un archivo csv o excel a la plataforma", TipoMensaje.MsgError) + End If + End Sub + + Private Sub CargaArchivoPSAdicional(Ruta As String, FileName As String, Tipo As String) + Dim dt As New DataTable + Dim ErrorArchivo = False + Dim ErrorExcel As Boolean = False + + dt = ReadExcelFile(Ruta + FileName, True, 0).FiltraParametros("CodigoProducto <> ''") + + If Not ErrorArchivo Then + If Not dt.Columns(0).ColumnName.ToUpper = "CODIGOPRODUCTO" Then + Alert("El nombre de la primera columna debe ser 'ConceptoAdministrativo'. Favor de corregirlo", TipoMensaje.MsgError) + Exit Sub + End If + If Not dt.Columns(1).ColumnName.ToUpper = "CODIGOPRODUCTOADICIONAL" Then + Alert("El nombre de la segunda columna debe ser 'Cuenta'.Favor de corregirlo", TipoMensaje.MsgError) + Exit Sub + End If + End If + + If Not ErrorArchivo Then + + Try + Dim ContadorRegistros As Integer = 0 + Dim ObjPS As New ClsProductosServicios + ObjPS.IniciaTransacSQL() + + 'antes de iniciar la carga se limpiarán los asignados, se filtran por codigops + For Each Row As DataRow In dt.FiltraParametros("", DistinctColumns:={"CodigoProducto"}).Rows + If Not GuardarProductosEquivalenteEnFranquicia(ObjPS, Row("CodigoProducto").ToString.Trim, "", 0, 2) Then + ErrorExcel = True + Exit For + End If + Next + If Not ErrorExcel Then + For Each Row As DataRow In dt.Rows + Dim CodigoPS As String = Row("CodigoProducto").ToString + Dim CodigoPSAdicional As String = Row("CodigoProductoAdicional").ToString + Dim Cantidad As Integer = Row("CantidadFija").ToString.ToEntero + If Not GuardarProductosEquivalenteEnFranquicia(ObjPS, CodigoPS, CodigoPSAdicional, Cantidad, 1) Then + ErrorExcel = True + Exit For + End If + ContadorRegistros = ContadorRegistros + 1 + Next + End If + If Not ErrorExcel Then + ObjPS.Commit() + Dim StrEmpresas As String = UsuarioActual.Empresa.Funcionalidad(563) & "," & UsuarioActual.CveEmpresa ' agregamos la empresa actual + Dim EmpresasFranquicia As List(Of Integer) = StrEmpresas.Split(","c).ToList().ConvertAll(Function(x) Convert.ToInt32(x)) + 'regenerar el global de cada empresa + For Each Franquicia As Integer In EmpresasFranquicia + GlobalDTPSAdicionales(-1, Franquicia) = Nothing + Next + + Alert($"{ContadorRegistros} Registros aplicados.") + Else + ObjPS.RollBack() + Alert($"Ocurrió un error al cargar los productos.", TipoMensaje.MsgAdvertencia) + End If + + + Catch ex As Exception + Alert("No se pudo cargar el excel", TipoMensaje.MsgAdvertencia) + GuardaLog(ex.Message) + End Try + + End If + End Sub + + + +#End Region + End Class