-- mejora
This commit is contained in:
@@ -19,6 +19,9 @@
|
||||
<li>
|
||||
<asp:LinkButton ID="LnkEliminarSeleccionados" runat="server" OnClick="LnkEliminarSeleccionados_Click"><i class='fa fa-trash' style="color:red"></i> Eliminar seleccionados</asp:LinkButton>
|
||||
</li>
|
||||
<li>
|
||||
<asp:LinkButton ID="ImgExcel" runat="server"> <i class="fa fa-file-excel-o" style="font-weight:bold;"></i> Excel</asp:LinkButton>
|
||||
</li>
|
||||
</asp:Content>
|
||||
<asp:Content ID="Content6" ContentPlaceHolderID="HA" runat="Server">
|
||||
</asp:Content>
|
||||
@@ -90,7 +93,7 @@
|
||||
<div class="row">
|
||||
<div class="col-md-12">
|
||||
<asp:GridView ID="GvDatos" runat="server" AutoGenerateColumns="false" EmptyDataText="No se encontraron solicitudes de facturación" OnRowDataBound="GvDatos_RowDataBound"
|
||||
DataKeyNames="CveFacturacionAcarreo,CvePSGeneral,Cantidad,CveCliente,CveSubProyecto,CvePSRelacionado" CssClass="table table-striped table-advance table-hover Widthall ScrollAD mysmallbtn" data-sort="true" GridLines="None" Width="99%">
|
||||
DataKeyNames="CveFacturacionAcarreo,CvePSGeneral,Cantidad,CveCliente,CveSubProyecto,CvePSRelacionado,Folio,FolioAdicional" CssClass="table table-striped table-advance table-hover Widthall ScrollAD mysmallbtn" data-sort="true" GridLines="None" Width="99%">
|
||||
<Columns>
|
||||
<asp:TemplateField ItemStyle-HorizontalAlign="center" ItemStyle-Width="20px" HeaderStyle-Width="20px" ItemStyle-CssClass="NoClick">
|
||||
<HeaderTemplate>
|
||||
@@ -99,8 +102,7 @@
|
||||
<ItemTemplate>
|
||||
<asp:CheckBox runat="server" ID="chk" CssClass="ChkAllEvt" />
|
||||
</ItemTemplate>
|
||||
</asp:TemplateField>
|
||||
<asp:BoundField HeaderText="Cliente" DataField="Nombre" />
|
||||
</asp:TemplateField>
|
||||
<asp:BoundField HeaderText="Servicio" DataField="Servicio" />
|
||||
<asp:BoundField HeaderText="Mercancia" DataField="Mercancia" />
|
||||
<asp:BoundField HeaderText="Fecha Salida" DataField="FechaSalida" DataFormatString="{0:dd/MM/yyyy HH:mm}" ItemStyle-Width="80px" />
|
||||
@@ -108,6 +110,8 @@
|
||||
<asp:BoundField HeaderText="Cant." DataField="Cantidad" DataFormatString="{0:N2}" ItemStyle-HorizontalAlign="Right" />
|
||||
<asp:BoundField HeaderText="Origen" DataField="DireccionOrigen" />
|
||||
<asp:BoundField HeaderText="Destino" DataField="DireccionDestino" />
|
||||
<asp:BoundField HeaderText="Boleta" DataField="Folio" />
|
||||
<asp:BoundField HeaderText="Hoja Servicio" DataField="FolioAdicional" />
|
||||
<asp:HyperLinkField HeaderText="Serie Folio" DataTextField="SerieFolio" DataNavigateUrlFields="CveVenta" DataNavigateUrlFormatString="/Ventas/Ventas.aspx?CveVenta={0}" />
|
||||
</Columns>
|
||||
<RowStyle CssClass="Texto" />
|
||||
|
||||
@@ -1,13 +1,15 @@
|
||||
|
||||
Option Explicit On
|
||||
Option Explicit On
|
||||
Option Strict On
|
||||
|
||||
Imports System.Data
|
||||
Imports System.Data
|
||||
Imports System.IO
|
||||
Imports System.IO.Compression
|
||||
Imports System.Net.Http
|
||||
Imports ADSTimbrado
|
||||
Imports Extensiones
|
||||
Imports GemBox.Spreadsheet
|
||||
|
||||
|
||||
Partial Class Ventas_FacturacionAcarreos
|
||||
Inherits ClsPaginas
|
||||
|
||||
@@ -15,6 +17,11 @@ Partial Class Ventas_FacturacionAcarreos
|
||||
If Not Page.IsPostBack Then
|
||||
CargaDatos()
|
||||
End If
|
||||
If IfNull(Request("OP"), "").ToString = "File" Then
|
||||
|
||||
DescargaArchivoDirecto(Request("File").ToString)
|
||||
|
||||
End If
|
||||
End Sub
|
||||
|
||||
Private Sub CargaDatos()
|
||||
@@ -41,17 +48,18 @@ Partial Class Ventas_FacturacionAcarreos
|
||||
.Add(New DataColumn("Sucursal", GetType(String)))
|
||||
.Add(New DataColumn("RFC", GetType(String)))
|
||||
.Add(New DataColumn("Cantidad", GetType(Decimal)))
|
||||
.Add(New DataColumn("Folio", GetType(String)))
|
||||
.Add(New DataColumn("ProductoGeneral", GetType(String)))
|
||||
.Add(New DataColumn("Origen", GetType(String)))
|
||||
.Add(New DataColumn("Destino", GetType(String)))
|
||||
.Add(New DataColumn("FechaSalida", GetType(DateTime)))
|
||||
.Add(New DataColumn("FechaLlegada", GetType(DateTime)))
|
||||
.Add(New DataColumn("Unidad", GetType(String)))
|
||||
.Add(New DataColumn("Chofer", GetType(String)))
|
||||
.Add(New DataColumn("Configuración", GetType(String)))
|
||||
.Add(New DataColumn("Remolque1", GetType(String)))
|
||||
.Add(New DataColumn("Remolque2", GetType(String)))
|
||||
'.Add(New DataColumn("Chofer", GetType(String)))
|
||||
'.Add(New DataColumn("Remolque1", GetType(String)))
|
||||
'.Add(New DataColumn("Remolque2", GetType(String)))
|
||||
.Add(New DataColumn("Distancia", GetType(Decimal)))
|
||||
.Add(New DataColumn("HojaServicio", GetType(String)))
|
||||
End With
|
||||
|
||||
SpreadsheetInfo.SetLicense(ModExtensiones.SerialGemBoxSpreadsheet)
|
||||
@@ -119,15 +127,30 @@ Partial Class Ventas_FacturacionAcarreos
|
||||
Dim FechaLlegada As DateTime = MinFecha
|
||||
|
||||
If row("FechaSalida").ToString().ToDateTime() > FechaSalida Then
|
||||
FechaSalida = row("FechaSalida").ToString().ToDateTime()
|
||||
FechaSalida = row("FechaSalida").ToString().ToDateTime().AddHours(9)
|
||||
End If
|
||||
If row("FechaLlegada").ToString().ToDateTime() > FechaLlegada Then
|
||||
FechaLlegada = row("FechaLlegada").ToString().ToDateTime()
|
||||
End If
|
||||
|
||||
FechaLlegada = row("FechaLlegada").ToString().ToDateTime().AddHours(14)
|
||||
End If
|
||||
|
||||
Dim Chofer, Configuracion, Remolque1, Remolque2 As String
|
||||
Dim dtu As DataRow = GlobalDTInvCamiones(UsuarioActual.CveEmpresa).FiltroPrimero($"Placa = '{row("Unidad")}'")
|
||||
If dtu IsNot Nothing Then
|
||||
'Chofer = dtu("Chofer").ToString
|
||||
'Configuracion = dtu("Configuracion").ToString
|
||||
Remolque1 = dtu("Remolque1").ToString
|
||||
Remolque2 = dtu("Remolque2").ToString
|
||||
Else
|
||||
Chofer = "" : Configuracion = "" : Remolque1 = "" : Remolque2 = ""
|
||||
End If
|
||||
|
||||
'temporal
|
||||
Chofer = row("Folio").ToString
|
||||
Configuracion = row("HojaServicio").ToString
|
||||
|
||||
Dim msg As String = ObjVentas.AddFacturacionAcarreos(row("Sucursal").ToString(), row("RFC").ToString(), row("Cantidad").ToString().ToDecimal(), row("ProductoGeneral").ToString(), row("Origen").ToString(),
|
||||
row("Destino").ToString(), FechaSalida, FechaLlegada, row("Unidad").ToString(), row("Chofer").ToString(), row("Configuración").ToString(),
|
||||
row("Remolque1").ToString(), row("Remolque2").ToString(), row("Distancia").ToString().ToDecimal(), UsuarioActual.CveEmpresa)
|
||||
row("Destino").ToString(), FechaSalida, FechaLlegada, row("Unidad").ToString(), Chofer, Configuracion,
|
||||
Remolque1, Remolque2, row("Distancia").ToString().ToDecimal(), UsuarioActual.CveEmpresa)
|
||||
If msg = "Correcto" Then
|
||||
RowsCargados += 1
|
||||
Else
|
||||
@@ -163,60 +186,8 @@ Partial Class Ventas_FacturacionAcarreos
|
||||
CargaDatos()
|
||||
|
||||
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
|
||||
|
||||
dataTable.Columns.Add("NoExcel", GetType(String))
|
||||
|
||||
While curRow < worksheet.Rows.Count
|
||||
columns = New String(cols) {}
|
||||
|
||||
For curCol = 0 To cols
|
||||
End Sub
|
||||
|
||||
If curCol = cols Then
|
||||
columns(curCol) = worksheet.Rows(curRow).Name
|
||||
Else
|
||||
If worksheet.Rows(curRow).Cells(curCol).Value Is Nothing Then
|
||||
columns(curCol) = ""
|
||||
Else
|
||||
columns(curCol) = worksheet.Rows(curRow).Cells(curCol).Value.ToString()
|
||||
End If
|
||||
End If
|
||||
Next
|
||||
|
||||
dataTable.Rows.Add(columns)
|
||||
curRow += 1
|
||||
End While
|
||||
|
||||
Return dataTable
|
||||
End Function
|
||||
#End Region
|
||||
|
||||
Protected Sub GvDatos_RowDataBound(sender As Object, e As GridViewRowEventArgs)
|
||||
@@ -227,9 +198,6 @@ Partial Class Ventas_FacturacionAcarreos
|
||||
End If
|
||||
End Sub
|
||||
|
||||
|
||||
|
||||
|
||||
Protected Sub LnkFacturarSeleccionados_Click(sender As Object, e As EventArgs)
|
||||
|
||||
If GvDatos.Rows.Cast(Of GridViewRow)().Count(Function(gvr) gvr.FCCheckBox("chk").Checked) <= 0 Then
|
||||
@@ -238,10 +206,17 @@ Partial Class Ventas_FacturacionAcarreos
|
||||
End If
|
||||
|
||||
Dim msg As New StringBuilder()
|
||||
Dim msgDescarga As New StringBuilder()
|
||||
|
||||
Dim NumFacturasGeneradas As Integer = 0
|
||||
Dim NumFacturasTimbradas As Integer = 0
|
||||
|
||||
Dim Archivo As String = ""
|
||||
Dim NombreArchivo As String = String.Format("Acarreos{0}{1}.zip", NowADS().ToString("yyyyMMddhhmmss"), UsuarioActual.CveUsuario.ToString)
|
||||
Dim ArchivoDestino As String = String.Format("{0}Temp/{1}", UsuarioActual.Empresa.Ruta, NombreArchivo)
|
||||
Dim HuboInexistentes As Boolean = False
|
||||
Dim archiveZip As ZipArchive = ZipFile.Open(ArchivoDestino, ZipArchiveMode.Create)
|
||||
|
||||
For Each GvRow As GridViewRow In GvDatos.Rows
|
||||
If GvRow.RowType = DataControlRowType.DataRow Then
|
||||
If GvRow.FCCheckBox("chk").Checked Then
|
||||
@@ -251,10 +226,10 @@ Partial Class Ventas_FacturacionAcarreos
|
||||
Dim CveMoneda As Integer = 1
|
||||
|
||||
Dim CvePS As Integer = GvRow.DataKey("CvePSGeneral").ToEntero()
|
||||
Dim Cantidad As Decimal = GvRow.DataKey("Cantidad").ToEntero()
|
||||
Dim Cantidad As Decimal = GvRow.DataKey("Cantidad").ToDecimal()
|
||||
Dim PU As Decimal = -1
|
||||
Dim Descuento As Decimal = 0
|
||||
Dim Obs As String = ""
|
||||
Dim Obs As String = $"DE ACARREO DE MINERAL DE HIERRO AQUILA SINALOA, MÉXICO, FOLIO: { GvRow.DataKey("Folio")} HOJA DE SERVICIO: {GvRow.DataKey("FolioAdicional")}"
|
||||
|
||||
Dim CvePSMercancia As Integer = GvRow.DataKey("CvePSRelacionado").ToEntero()
|
||||
|
||||
@@ -274,8 +249,19 @@ Partial Class Ventas_FacturacionAcarreos
|
||||
msg.AppendFormat("{0}<br/>", m)
|
||||
Next
|
||||
|
||||
If resp.TieneError AndAlso resp.Mensajes.Count = 0 Then
|
||||
msg.Append("Ocurrió un error al generar la factura.<br/>")
|
||||
If Not resp.TieneError Then
|
||||
If resp.SerieFolio <> String.Empty Then
|
||||
msgDescarga.AppendFormat("{0},", resp.SerieFolio)
|
||||
DescargarFactura(resp.CveVenta, UsuarioActual.CveEmpresa, UsuarioActual.CveUsuario)
|
||||
Archivo = String.Format("{0}PDF/ING/{1}.pdf", UsuarioActual.Empresa.Ruta.Replace("\", "/"), resp.SerieFolio)
|
||||
If File.Exists(Archivo) Then
|
||||
archiveZip.CreateEntryFromFile(Archivo, resp.SerieFolio & ".pdf")
|
||||
End If
|
||||
Archivo = String.Format("{0}XML/ING/{1}.xml", UsuarioActual.Empresa.Ruta.Replace("\", "/"), resp.SerieFolio)
|
||||
If File.Exists(Archivo) Then
|
||||
archiveZip.CreateEntryFromFile(Archivo, resp.SerieFolio & ".xml")
|
||||
End If
|
||||
End If
|
||||
End If
|
||||
|
||||
If resp.CveVenta > 0 AndAlso Not resp.TieneError Then
|
||||
@@ -287,9 +273,14 @@ Partial Class Ventas_FacturacionAcarreos
|
||||
End If
|
||||
End If
|
||||
Next
|
||||
|
||||
archiveZip.Dispose()
|
||||
If NumFacturasGeneradas > 0 Then
|
||||
Alert($"Se generaron {NumFacturasGeneradas} y se timbraron {NumFacturasTimbradas} facturas. <br/>" + msg.ToString(), TipoMensaje.MsgInformacion)
|
||||
Dim stt As String = $"Se generaron {NumFacturasGeneradas} y se timbraron {NumFacturasTimbradas} facturas. <br/>"
|
||||
If msgDescarga.Length > 0 Then
|
||||
stt += String.Format("<a target='_blank' class='Texto' href='/Ventas/FacturacionAcarreos.aspx?OP=File&File={0}'>Descarga zip</a>", NombreArchivo)
|
||||
End If
|
||||
Alert(stt, TipoMensaje.MsgInformacion)
|
||||
|
||||
Else
|
||||
Alert($"No se pudieron generar facturas. <br/>" + msg.ToString(), TipoMensaje.MsgError)
|
||||
End If
|
||||
@@ -367,4 +358,56 @@ Partial Class Ventas_FacturacionAcarreos
|
||||
Protected Sub BtnConsultar_Click(sender As Object, e As EventArgs)
|
||||
CargaDatos()
|
||||
End Sub
|
||||
|
||||
Private Sub ImgExcel_Click(sender As Object, e As EventArgs) Handles ImgExcel.Click
|
||||
GvDatos.Columns(0).Visible = False
|
||||
GvDatos.ExportToExcel("Acarreos_" & NowADS().ToShortDateString & ".xls")
|
||||
GvDatos.Columns(0).Visible = True
|
||||
End Sub
|
||||
Private Function DescargarFactura(CveVenta As Integer, CveEmpresa As Integer, CveUsuarioCreo As Integer, Optional GetBytes As Boolean = True, Optional Regenerar As Boolean = False, Optional strURLHOST As String = "") As Byte()
|
||||
|
||||
If String.IsNullOrEmpty(strURLHOST) Then
|
||||
strURLHOST = String.Format("{0}://{1}:{2}", HttpContext.Current.Request.Url.Scheme, HttpContext.Current.Request.Url.Host, HttpContext.Current.Request.Url.Port)
|
||||
End If
|
||||
|
||||
Dim Url As New Uri(String.Format("{0}/Compras/PopUpVerFactura.aspx?P={1}", strURLHOST, Encripta(String.Format("OP=VTA&CVEVENTA={0}&PAG=1&GUARDAR=1®ENERAR={1}", CveVenta, If(Regenerar, "1", "0")))))
|
||||
Dim File As Byte() = Nothing
|
||||
Try
|
||||
Using httpClient As New HttpClient()
|
||||
httpClient.Timeout = New TimeSpan(0, 2, 0)
|
||||
Using request As New HttpRequestMessage(HttpMethod.Get, Url)
|
||||
request.Headers.Add("ADSToken", Encripta(String.Format("CVEEMPRESA={0}&TICKS={1}&CveUsuario={2}", CveEmpresa, DateTime.UtcNow.Ticks, CveUsuarioCreo)))
|
||||
Dim response As HttpResponseMessage = httpClient.SendAsync(request).Result
|
||||
If GetBytes AndAlso response.StatusCode = Net.HttpStatusCode.OK Then
|
||||
File = response.Content.ReadAsByteArrayAsync().Result
|
||||
End If
|
||||
End Using
|
||||
End Using
|
||||
Catch ex As Exception
|
||||
File = Nothing
|
||||
OnError("Ocurrió un error al descargar la factura", ex)
|
||||
End Try
|
||||
|
||||
Return File
|
||||
End Function
|
||||
|
||||
Private Sub DescargaArchivoDirecto(NombreArchivo As String)
|
||||
If NombreArchivo <> "" Then
|
||||
|
||||
NombreArchivo = String.Format("{0}Temp\{1}", UsuarioActual.Empresa.Ruta, NombreArchivo)
|
||||
Dim Archivo As New System.IO.FileInfo(NombreArchivo)
|
||||
|
||||
If Archivo.Exists Then
|
||||
HttpContext.Current.Response.Clear()
|
||||
HttpContext.Current.Response.ClearContent()
|
||||
HttpContext.Current.Response.ContentType = "application/zip"
|
||||
HttpContext.Current.Response.AppendHeader("Content-disposition", String.Format("attachment; filename={0}", Archivo.Name))
|
||||
HttpContext.Current.Response.TransmitFile(NombreArchivo)
|
||||
HttpContext.Current.Response.Flush()
|
||||
HttpContext.Current.Response.End()
|
||||
End If
|
||||
Archivo = Nothing
|
||||
End If
|
||||
End Sub
|
||||
|
||||
End Class
|
||||
|
||||
Reference in New Issue
Block a user