Cargar cotizaciones desde excel
This commit is contained in:
190
OC/OC.aspx.vb
190
OC/OC.aspx.vb
@@ -1,5 +1,4 @@
|
||||
Option Explicit On
|
||||
Option Strict On
|
||||
|
||||
Imports System.Data
|
||||
Imports Extensiones
|
||||
@@ -176,7 +175,7 @@ Partial Class OC
|
||||
End Property
|
||||
Private Property NumCotizacionesEvaluar As Integer
|
||||
Get
|
||||
NumCotizacionesEvaluar = IfNull(ViewState("NumCotizacionesEvaluar"), "-1", ViewState("NumCotizacionesEvaluar")).ToString().ToEntero()
|
||||
NumCotizacionesEvaluar = IfNull(ViewState("NumCotizacionesEvaluar"), "0", ViewState("NumCotizacionesEvaluar")).ToString().ToEntero()
|
||||
End Get
|
||||
Set(value As Integer)
|
||||
ViewState("NumCotizacionesEvaluar") = value
|
||||
@@ -1509,7 +1508,7 @@ Partial Class OC
|
||||
|
||||
|
||||
'Si requiere cotizacion y el estatus siguiente es el final, desabilitar el combo del estatus
|
||||
If ChkCotizacion.Checked AndAlso objOC.CveEstatusSiguiente = CveEstatusFinalOK AndAlso (gvCotizaciones.Rows.Count = 0 Or NumCotizacionesGanadoras < gvCotizaciones.Rows.Count - 1) Then
|
||||
If UsuarioActual.Empresa.Funcionalidad(556) = "1" AndAlso ChkCotizacion.Checked AndAlso objOC.CveEstatusSiguiente = CveEstatusFinalOK AndAlso (gvCotizaciones.Rows.Count = 0 Or NumCotizacionesGanadoras < gvCotizaciones.Rows.Count - 1) Then
|
||||
CboE.Enabled = False
|
||||
LblMsgEstatus.Visible = True
|
||||
LblMsgEstatus.Text = "Cotización requerida para avanzar"
|
||||
@@ -1669,7 +1668,7 @@ Partial Class OC
|
||||
|
||||
|
||||
'If ChkCotizacion.Checked AndAlso objOC.CveEstatusSiguiente = CveEstatusFinalOK AndAlso NumCotizacionesGanadoras < gvCotizaciones.Rows.Count - 1 Then
|
||||
If ChkCotizacion.Checked AndAlso CveEstatusSiguiente = CveEstatusFinalOK AndAlso NumCotizacionesGanadoras < gvCotizaciones.Rows.Count - 1 Then
|
||||
If UsuarioActual.Empresa.Funcionalidad(556) = "1" AndAlso ChkCotizacion.Checked AndAlso CveEstatusSiguiente = CveEstatusFinalOK AndAlso NumCotizacionesGanadoras < gvCotizaciones.Rows.Count - 1 Then
|
||||
CboE.Enabled = False
|
||||
LblMsgEstatus.Visible = True
|
||||
LblMsgEstatus.Text = "Cotización requerida para avanzar"
|
||||
@@ -1745,6 +1744,11 @@ Partial Class OC
|
||||
DdlProveedores.DataSource = GlobalDTCompProveedores(CveEmpresaActual)
|
||||
DdlProveedores.DataBind()
|
||||
DdlProveedores.Items.Insert(0, New ListItem("Seleccione", "-1"))
|
||||
|
||||
DdlProveedorCot.DataSource = GlobalDTCompProveedores(CveEmpresaActual)
|
||||
DdlProveedorCot.DataBind()
|
||||
DdlProveedorCot.Items.Insert(0, New ListItem("Seleccione", "-1"))
|
||||
|
||||
UPProv.Update() : UPPEmp.Update()
|
||||
End Sub
|
||||
|
||||
@@ -2766,9 +2770,9 @@ Partial Class OC
|
||||
If UsuarioActual.Empresa.Funcionalidad(565) = "1" Then
|
||||
If CveConfianzaProveedor > 0 Then
|
||||
|
||||
If CveConfianzaProveedor = 1 AndAlso Me.NumCotizaciones >= 1 Then
|
||||
If CveConfianzaProveedor = 1 AndAlso Me.NumCotizacionesEvaluar >= 1 Then
|
||||
TieneError = GeneraOrdenes(OC, Conta, ObjInventarios)
|
||||
ElseIf CveConfianzaProveedor = 2 AndAlso Me.NumCotizaciones >= 2 Then
|
||||
ElseIf CveConfianzaProveedor = 2 AndAlso Me.NumCotizacionesEvaluar >= 2 Then
|
||||
TieneError = GeneraOrdenes(OC, Conta, ObjInventarios)
|
||||
Else
|
||||
TieneError = True
|
||||
@@ -2878,7 +2882,7 @@ Partial Class OC
|
||||
Promocion = TxtPromocion.Text.Trim
|
||||
|
||||
Try
|
||||
If ChkCotizacion.Checked Then
|
||||
If ChkCotizacion.Checked AndAlso gvCotizaciones.Rows.Count > 0 Then
|
||||
Dim CveProveedor = -1
|
||||
Dim TotalCot = 0.0, IVACot = 0D, RetIVA = 0.0, RetISR = 0.0, PorIVA = 0.0, Porcentaje = 0.0
|
||||
Dim IdPoliza = -1
|
||||
@@ -2932,6 +2936,7 @@ Partial Class OC
|
||||
HuboError = True
|
||||
Exit For
|
||||
End If
|
||||
|
||||
End If
|
||||
|
||||
'AGREGA DETALLES
|
||||
@@ -4174,7 +4179,7 @@ Partial Class OC
|
||||
' uppOpciones.Update()
|
||||
'End If
|
||||
|
||||
If ChkCotizacion.Checked AndAlso CveEstatusSiguiente = CveEstatusFinalOK AndAlso (gvCotizaciones.Rows.Count = 0 Or NumCotizacionesGanadoras < gvCotizaciones.Rows.Count - 1) Then
|
||||
If UsuarioActual.Empresa.Funcionalidad(556) = "1" AndAlso ChkCotizacion.Checked AndAlso CveEstatusSiguiente = CveEstatusFinalOK AndAlso (gvCotizaciones.Rows.Count = 0 Or NumCotizacionesGanadoras < gvCotizaciones.Rows.Count - 1) Then
|
||||
CboE.Enabled = False
|
||||
LblMsgEstatus.Visible = True
|
||||
LblMsgEstatus.Text = "Cotización requerida para avanzar"
|
||||
@@ -7307,4 +7312,173 @@ Partial Class OC
|
||||
|
||||
#End Region
|
||||
|
||||
#Region "C A R G A R E X C E L "
|
||||
Protected Sub BtnCargaExcelCot_Click(sender As Object, e As EventArgs)
|
||||
If TxtExcelCot.getfiles().Archivos.Count > 0 Then
|
||||
Dim file As Archivo = TxtExcelCot.getfiles().Archivos(0)
|
||||
Dim Directorio As String = AppDomain.CurrentDomain.BaseDirectory & file.patch
|
||||
CargarArchivoCot(Directorio, file.filename)
|
||||
|
||||
CargaCotizaciones(CveOrdenCompra)
|
||||
RegistraScript("$('#DivCargaExcelCotizaciones').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 BtnDescargarFormatoCot_Click(sender As Object, e As EventArgs)
|
||||
'cantidad, Producto, Precio Unitario, Fecha Entrega, Observación
|
||||
Dim DtPS As DataTable = GlobalDTPSSimplificado(UsuarioActual.CveEmpresa)
|
||||
|
||||
Dim DtExcel As DataTable = (From row As GridViewRow In GvD.Rows
|
||||
Join rowPS In DtPS On rowPS("CvePS").ToString().ToEntero() Equals row.DataKey("CvePS").ToEntero()
|
||||
Where row.RowType = DataControlRowType.DataRow
|
||||
Select New With
|
||||
{
|
||||
.Cantidad = row.DataKey("Cantidad"),
|
||||
.Codigo = rowPS("Codigo"),
|
||||
.Producto = rowPS("PSCodigo"),
|
||||
.PrecioUnitario = row.DataKey("Importe").ToDecimal(),
|
||||
.FechaEntrega = "",
|
||||
.Observacion = row.DataKey("Observacion")
|
||||
}).QueryToDataTable(True)
|
||||
If DtExcel.Rows.Count < 2 Then
|
||||
Alert("No hay resutados en la busqueda.", TipoMensaje.MsgAdvertencia)
|
||||
Exit Sub
|
||||
End If
|
||||
|
||||
DtExcel.TableName = "Cotización"
|
||||
'DtExcel.Columns("Codigo").ColumnName = "Código"
|
||||
'DtExcel.Columns("PS").ColumnName = "Producto / Servicio"
|
||||
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, "Cotizacion.xlsx", SaveOptions.XlsxDefault)
|
||||
|
||||
End Sub
|
||||
Protected Sub CargarArchivoCot(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
|
||||
'cantidad, Producto, Precio Unitario, Fecha Entrega, Observación
|
||||
If DdlProveedorCot.SelectedValue.ToEntero() <= 0 Then
|
||||
Alert("Debe Seleccionar la lista de precios a cargar. Favor de corregirlo", TipoMensaje.MsgError)
|
||||
Exit Sub
|
||||
End If
|
||||
If Not dt.Columns(0).ColumnName = "Cantidad" Then
|
||||
Alert("El nombre de la tercera 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 cuarta 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 cuarta columna debe ser 'Producto'. Favor de corregirlo", TipoMensaje.MsgError)
|
||||
Exit Sub
|
||||
End If
|
||||
If Not dt.Columns(3).ColumnName = "PrecioUnitario" Then
|
||||
Alert("El nombre de la sexta columna debe ser 'PrecioUnitario'. Favor de corregirlo", TipoMensaje.MsgError)
|
||||
Exit Sub
|
||||
End If
|
||||
If Not dt.Columns(4).ColumnName = "FechaEntrega" Then
|
||||
Alert("El nombre de la sexta columna debe ser 'FechaEntrega'. Favor de corregirlo", TipoMensaje.MsgError)
|
||||
Exit Sub
|
||||
End If
|
||||
If Not dt.Columns(5).ColumnName = "Observacion" Then
|
||||
Alert("El nombre de la sexta columna debe ser 'Observacion'. 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 TieneError As Boolean = False
|
||||
|
||||
Dim objCotizacion As New ClsOC
|
||||
objCotizacion.IniciaTransacSQL()
|
||||
|
||||
Try
|
||||
Dim DtPS As DataTable = GlobalDTPSSimplificado(UsuarioActual.CveEmpresa)
|
||||
|
||||
Dim DtOCDetalle As DataTable = (From row As GridViewRow In GvD.Rows
|
||||
Join rowPS In DtPS On rowPS("CvePS").ToString().ToEntero() Equals row.DataKey("CvePS").ToEntero()
|
||||
Where row.RowType = DataControlRowType.DataRow
|
||||
Select New With
|
||||
{
|
||||
.CvePS = row.DataKey("CvePS").ToEntero(),
|
||||
.CveUnidadMedida = rowPS("CveUnidadMedida").ToString().ToEntero(),
|
||||
.CveOrdenCompraDetalle = row.DataKey("CveOrdenCompraDetalle").ToString().ToEntero(),
|
||||
.Codigo = rowPS("Codigo")
|
||||
}).QueryToDataTable(True)
|
||||
|
||||
|
||||
|
||||
Dim Folio As String = ""
|
||||
Dim CveProveedor As Integer = DdlProveedorCot.SelectedValue.ToEntero()
|
||||
|
||||
If CveProveedor > 0 Then
|
||||
If objCotizacion.AddCotizacion(CveOrdenCompra, CveProveedor, -1, Folio, TxtFecha.Text, "", DdlMoneda.SelectedValue.ToEntero, 0, UsuarioActual.CveUsuario) Then
|
||||
For Each dr As DataRow In dt.Rows
|
||||
Dim RowPS = DtOCDetalle.FiltroPrimero(String.Format("Codigo='{0}'", dr("Codigo").ToString()))
|
||||
|
||||
Dim CveOrdenCompraDetalle As Integer = RowPS("CveOrdenCompraDetalle").ToString().ToEntero()
|
||||
Dim CvePS As Integer = RowPS("CvePS").ToString().ToEntero()
|
||||
Dim CveUnidadMedida As Integer = RowPS("CveUnidadMedida").ToString().ToEntero()
|
||||
Dim Fecha As String = If(String.IsNullOrEmpty(dr("FechaEntrega").ToString()), "", If(IsDate(dr("FechaEntrega").ToString()), dr("FechaEntrega").ToString(), ""))
|
||||
|
||||
TieneError = Not objCotizacion.AddCotizacionDetalle(objCotizacion.CveCotizacion, CvePS, dr("PrecioUnitario").ToString().ToDecimal(), dr("Cantidad").ToString().ToDouble, CveUnidadMedida,
|
||||
dr("Cantidad").ToString().ToDouble, Fecha, dr("Observacion").ToString(), CveOrdenCompraDetalle)
|
||||
If TieneError = True Then Exit For
|
||||
Next
|
||||
End If
|
||||
Else
|
||||
TieneError = False
|
||||
End If
|
||||
|
||||
Catch ex As Exception
|
||||
TieneError = True
|
||||
OnError("Ocurrió un error al cargar las cotizaciones.", ex)
|
||||
Finally
|
||||
If TieneError Then
|
||||
objCotizacion.RollBack()
|
||||
Alert("Ocurrió un error al cargar las cotizaciones.")
|
||||
Else
|
||||
objCotizacion.Commit()
|
||||
Alert("Las cotizaciones se cargaron correctamente.")
|
||||
End If
|
||||
objCotizacion.Dispose()
|
||||
End Try
|
||||
|
||||
End If
|
||||
End Sub
|
||||
#End Region
|
||||
|
||||
End Class
|
||||
|
||||
Reference in New Issue
Block a user