This commit is contained in:
janeth arvizu
2019-10-29 14:17:42 -07:00
2 changed files with 396 additions and 137 deletions

View File

@@ -60,9 +60,9 @@
Traspaso de Almacén Traspaso de Almacén
</asp:Content> </asp:Content>
<asp:Content ID="Content5" ContentPlaceHolderID="H" runat="Server"> <asp:Content ID="Content5" ContentPlaceHolderID="H" runat="Server">
<%-- <li> <li>
<asp:HyperLink ID="LnkEnviarMail" runat="server" Style="color: #686868;" Visible="false"><i class="fa fa-envelope" style="color: #686868;"></i> Enviar Mail</asp:HyperLink> <asp:HyperLink ID="LnkCargarExcel" runat="server" NavigateUrl="#" data-toggle="modal" data-target="#DivCargaExcelConceptos" Style="color: #686868;" ><i class="fa fa-file-excel-o" style="color: #686868;"></i> Cargar Conceptos</asp:HyperLink>
</li>--%> </li>
</asp:Content> </asp:Content>
<asp:Content ID="Content6" ContentPlaceHolderID="C" runat="Server"> <asp:Content ID="Content6" ContentPlaceHolderID="C" runat="Server">
@@ -780,7 +780,52 @@
</ContentTemplate> </ContentTemplate>
</asp:UpdatePanel> </asp:UpdatePanel>
</div> </div>
<%--CARGA EXCEL--%>
<div id="DivCargaExcelConceptos" 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">&times;</button>
<h4 class="modal-title">Cargar Conceptos</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;">
<asp:TextBox ID="TxtExcelConceptos" 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-2" style="text-align: left">
<asp:UpdatePanel ID="UpDescargar" runat="server" UpdateMode="Conditional">
<ContentTemplate>
<asp:Button ID="BtnDescargarFormatoExcelConceptos" OnClick="BtnDescargarFormatoExcelConceptos_Click" runat="server" CssClass="btn btn-warning" Text="Descargar Formato" />
</ContentTemplate>
<Triggers>
<asp:PostBackTrigger ControlID="BtnDescargarFormatoExcelConceptos" />
</Triggers>
</asp:UpdatePanel>
</div>
<div class="col-md-10" style="text-align: right">
<asp:UpdatePanel runat="server">
<ContentTemplate>
<asp:Button ID="BtnCargaExcelConceptos" runat="server" OnClick="BtnCargaExcelConceptos_Click" CssClass="btn btn-success" Text="Aceptar" ValidationGroup="GrpCargarExcel"></asp:Button>
<button type="button" class="btn btn-danger" data-dismiss="modal">Cancelar</button>
</ContentTemplate>
</asp:UpdatePanel>
</div>
</div>
</div>
</div>
</div>
</div>
</asp:Content> </asp:Content>
<asp:Content ID="Content7" ContentPlaceHolderID="JS" runat="Server"> <asp:Content ID="Content7" ContentPlaceHolderID="JS" runat="Server">

View File

@@ -4,6 +4,7 @@ Option Strict On
Imports System.Data Imports System.Data
Imports System.IO Imports System.IO
Imports Extensiones Imports Extensiones
Imports GemBox.Spreadsheet
Imports Microsoft.Reporting.WebForms Imports Microsoft.Reporting.WebForms
Partial Class Inventarios_TraspasoAlmacen Partial Class Inventarios_TraspasoAlmacen
@@ -1042,18 +1043,18 @@ Partial Class Inventarios_TraspasoAlmacen
ThSerieLote.Visible = True ThSerieLote.Visible = True
TdSerieLote.Visible = True TdSerieLote.Visible = True
TxtnSerieLote.Visible = True TxtnSerieLote.Visible = True
GvDatos.Columns(4).Visible = True GvDatos.Columns(5).Visible = True
End If End If
If GlobalDTPS(UsuarioActual.CveEmpresa, CvePS:=DdlProducto2.SelectedValue.ToEntero).FiltraParametros("Inv_CveMetodoInventario = 6", "PS").Rows.Count > 0 Then If GlobalDTPS(UsuarioActual.CveEmpresa, CvePS:=DdlProducto2.SelectedValue.ToEntero).FiltraParametros("Inv_CveMetodoInventario = 6", "PS").Rows.Count > 0 Then
TxtnLote.Visible = True TxtnLote.Visible = True
ThLote.Visible = True ThLote.Visible = True
TdLote.Visible = True TdLote.Visible = True
GvDatos.Columns(5).Visible = True GvDatos.Columns(6).Visible = True
TxtnBatch.Visible = True TxtnBatch.Visible = True
ThBatch.Visible = True ThBatch.Visible = True
TdBatch.Visible = True TdBatch.Visible = True
GvDatos.Columns(6).Visible = True GvDatos.Columns(7).Visible = True
End If End If
End If End If
@@ -2423,4 +2424,217 @@ Partial Class Inventarios_TraspasoAlmacen
End If End If
ObjAcar.Dispose() ObjAcar.Dispose()
End Sub End Sub
Protected Sub BtnCargaExcelConceptos_Click(sender As Object, e As EventArgs)
If TxtExcelConceptos.getfiles().Archivos.Count > 0 Then
Dim file As Archivo = TxtExcelConceptos.getfiles().Archivos(0)
Dim Directorio As String = AppDomain.CurrentDomain.BaseDirectory & file.patch
CargarArchivoConceptos(Directorio, file.filename)
RegistraScript("$('#DivCargaExcelConceptos').modal('hide');")
Else
Alert("No existe el archivo. Favor de subir un archivo excel a la plataforma.", TipoMensaje.MsgError)
End If
End Sub
Protected Sub BtnDescargarFormatoExcelConceptos_Click(sender As Object, e As EventArgs)
Dim DtExcel As New DataTable
DtExcel.Columns.Add(New DataColumn("Cantidad", GetType(Decimal)))
DtExcel.Columns.Add(New DataColumn("Codigo", GetType(String)))
DtExcel.Columns.Add(New DataColumn("Producto", GetType(String)))
DtExcel.Columns.Add(New DataColumn("SerieLote", GetType(String)))
DtExcel.Columns.Add(New DataColumn("Observaciones", GetType(String)))
DtExcel.TableName = "Traspaso"
SpreadsheetInfo.SetLicense(ModExtensiones.SerialGemBoxSpreadsheet)
Dim FileExcel As New ExcelFile()
Dim worksheet = FileExcel.Worksheets.Add(DtExcel.TableName)
worksheet.InsertDataTable(DtExcel, New InsertDataTableOptions() With
{
.ColumnHeaders = True,
.StartRow = 0,
.StartColumn = 0
})
worksheet.Rows(0).Style.FillPattern.SetPattern(FillPatternStyle.Solid, SpreadsheetColor.FromArgb(75, 119, 190), SpreadsheetColor.FromArgb(255, 255, 255))
worksheet.Rows(0).Style.Font.Color = SpreadsheetColor.FromArgb(255, 255, 255)
Dim columnCount = worksheet.CalculateMaxUsedColumns()
For i = 0 To columnCount
worksheet.Columns(i).AutoFit(1, worksheet.Rows(0), worksheet.Rows(worksheet.Rows.Count - 1))
Next
FileExcel.Save(Response, "Traspaso.xlsx", SaveOptions.XlsxDefault)
End Sub
Protected Sub CargarArchivoConceptos(Ruta As String, FileName As String)
SpreadsheetInfo.SetLicense(ModExtensiones.SerialGemBoxSpreadsheet)
Dim dt As DataTable = Nothing
Dim ErrorArchivo = False
Try
dt = ReadExcelFile(Ruta + FileName, True)
Catch ex As Exception
ErrorArchivo = True
OnError("Ocurrio un error al leer el archivo <br/>" & ex.Message, ex)
End Try
If Not ErrorArchivo AndAlso dt IsNot Nothing Then
If Not dt.Columns(0).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(1).ColumnName = "Codigo" Then
Alert("El nombre de la segunda columna debe ser 'Codigo'. Favor de corregirlo", TipoMensaje.MsgError)
Exit Sub
End If
If Not dt.Columns(2).ColumnName = "Producto" Then
Alert("El nombre de la tercera columna debe ser 'Producto'. Favor de corregirlo", TipoMensaje.MsgError)
Exit Sub
End If
If Not dt.Columns(3).ColumnName = "SerieLote" Then
Alert("El nombre de la cuarta columna debe ser 'SerieLote'. Favor de corregirlo", TipoMensaje.MsgError)
Exit Sub
End If
If Not dt.Columns(4).ColumnName = "Observaciones" Then
Alert("El nombre de la quinta columna debe ser 'Observaciones'. Favor de corregirlo", TipoMensaje.MsgError)
Exit Sub
End If
dt.TableName = "Datos"
Dim ProductosNoCargados As New StringBuilder()
Dim RowsCargados As Integer = 0
Dim RowsNoCargados As Integer = 0
Dim NoPSConSerieLote As Integer = 0
Try
Dim DtPS As DataTable = GlobalDTPS(UsuarioActual.CveEmpresa)
For Each RowExcel As DataRow In dt.Rows
Dim RowPS = DtPS.FiltroPrimero(String.Format("Codigo='{0}'", RowExcel("Codigo").ToString()))
Dim CveProducto As Integer = RowPS("CvePS").ToString().ToEntero()
Dim CveUnidadMedida As Integer = RowPS("CveUnidadMedida").ToString().ToEntero()
Dim Cantidad As Double = RowExcel("Cantidad").ToString().ToDecimal()
Dim SerieLote As String = RowExcel("SerieLote").ToString()
Dim Observaciones As String = RowExcel("Observaciones").ToString()
If CveProducto > 0 Then
Dim Valido As Boolean = True
Dim CveMetodoInventario As Integer = RowPS("Inv_CveMetodoInventario").ToString().ToEntero()
If CveMetodoInventario = 5 And (String.IsNullOrEmpty(SerieLote.Trim()) OrElse SerieLote = "-1") Then
Valido = False
Alert($"El producto '{RowPS("PS")}' requiere 'SerieLote'", TipoMensaje.MsgAdvertencia)
ProductosNoCargados.AppendFormat("{0},", RowPS("PS").ToString())
End If
If CveMetodoInventario = 5 AndAlso Not String.IsNullOrEmpty(SerieLote.Trim()) Then
NoPSConSerieLote = NoPSConSerieLote + 1
End If
If Valido AndAlso (Cantidad > 0 AndAlso RowPS("VentaMinima").ToString.ToDecimal > 0) Then
If Cantidad Mod RowPS("VentaMinima").ToString.ToDecimal <> 0 Then
Valido = False
ProductosNoCargados.AppendFormat("{0},", RowPS("PS").ToString())
End If
End If
If Valido Then
Valido = ValidaExistencia(Cantidad, CveProducto, CveUnidadMedida, If(Not String.IsNullOrEmpty(SerieLote), SerieLote, "-1"), "-1", "-1")
End If
If Valido Then
AgregarPS(Cantidad, CveProducto, CveUnidadMedida, Observaciones, If(Not String.IsNullOrEmpty(SerieLote), SerieLote, ""), "", "", False)
RowsCargados = RowsCargados + 1
Else
RowsNoCargados = RowsNoCargados + 1
ProductosNoCargados.AppendFormat("{0},", RowPS("PS").ToString())
End If
Else
RowsNoCargados = RowsNoCargados + 1
ProductosNoCargados.AppendFormat("{0},", RowExcel("Producto").ToString())
End If
Next
Catch ex As Exception
OnError("Ocurrió un error al cargar los productos.", ex)
Finally
If NoPSConSerieLote > 0 Then
ThSerieLote.Visible = True
TdSerieLote.Visible = True
TxtnSerieLote.Visible = True
GvDatos.Columns(5).Visible = True
End If
Dim MensajeFinal As New StringBuilder()
If RowsNoCargados = 0 AndAlso RowsCargados > 0 Then
MensajeFinal.Append("Los productos se cargaron correctamente. <br/><br/>")
End If
If RowsCargados > 0 Then
MensajeFinal.Append("Se cargaron <b>" & RowsCargados & "</b> productos correctamente.")
End If
If RowsNoCargados > 0 Then
MensajeFinal.Append("No se pudieron cargar <b>" & RowsNoCargados & "</b> productos. <br/>Los siguientes productos no se pudieron cargar: " & ProductosNoCargados.ToString())
End If
Alert(MensajeFinal.ToString())
End Try
UpDatos.Update()
End If
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
End Class End Class