-- actualización masiva mediante layout de ps adicionales
This commit is contained in:
@@ -115,7 +115,9 @@
|
||||
<li>
|
||||
<asp:LinkButton ID="LBExcelPersonalizado" runat="server"><i style="font-weight:bold" class="fa fa-file-excel-o"></i> Excel Personalizado</asp:LinkButton>
|
||||
</li>
|
||||
|
||||
<li>
|
||||
<asp:LinkButton ID="LnkExcelPSAdicional" runat="server" Visible="false" data-target="#DivCargaExcel"><i class="fa fa-file-excel-o" style="font-weight:bold;"></i> Cargar Productos Adicionales</asp:LinkButton>
|
||||
</li>
|
||||
|
||||
<%--onclick="AbrirVentana('/Ventas/ProductosServicios.aspx', 700, 400, 'N', 'PS')"--%>
|
||||
</asp:Content>
|
||||
@@ -373,7 +375,48 @@
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
<div id="DivCargaExcelPSAdicionales" class="modal ADS fade" role="dialog">
|
||||
<div class="modal-dialog">
|
||||
<!-- Modal content-->
|
||||
<div class="modal-content">
|
||||
<div class="modal-header ">
|
||||
<button type="button" class="close" data-dismiss="modal">×</button>
|
||||
<h4 class="modal-title">Agregar Excel</h4>
|
||||
</div>
|
||||
<div class="modal-body">
|
||||
<div class="row">
|
||||
<div class="col-md-12">
|
||||
<h3>Arraste o haga click para subir el archivo Excel</h3>
|
||||
</div>
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="col-md-11" style="margin-left: 30px; margin-right: 30px; margin-bottom: 10px;">
|
||||
<asp:TextBox ID="TxtExcel" CssClass="ADSdropzone hidden" Text="" data-maxFile="1" runat="server"></asp:TextBox>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="modal-footer">
|
||||
<div class="row">
|
||||
<div class="col-md-3" style="text-align: left">
|
||||
<asp:UpdatePanel ID="UpDescargar" runat="server" UpdateMode="Conditional">
|
||||
<ContentTemplate>
|
||||
<asp:Button ID="BtnDescargarPSAdicional" runat="server" CssClass="btn btn-warning" Text="Descargar Formato" />
|
||||
</ContentTemplate>
|
||||
<Triggers>
|
||||
<asp:PostBackTrigger ControlID="BtnDescargarPSAdicional" />
|
||||
</Triggers>
|
||||
</asp:UpdatePanel>
|
||||
|
||||
</div>
|
||||
<div class="col-md-9" style="text-align: right">
|
||||
<asp:Button ID="BtnCargaExcelPSAdicional" runat="server" CssClass="btn btn-success" Text="Aceptar"></asp:Button>
|
||||
<button type="button" class="btn btn-danger" data-dismiss="modal">Cancelar</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user