430 lines
18 KiB
VB.net
430 lines
18 KiB
VB.net
Option Explicit On
|
|
Option Strict On
|
|
Imports System.Data
|
|
Imports System.IO
|
|
Imports Extensiones
|
|
Imports Extensiones.ModExtensiones
|
|
Imports Microsoft.Reporting.WebForms
|
|
|
|
Partial Class ListadoContratos
|
|
Inherits ClsPaginas
|
|
|
|
#Region "Propiedad"
|
|
Private Property DtAvanceDocumento As DataTable
|
|
Get
|
|
Return CType(ViewState("DtAvanceDocumento"), DataTable)
|
|
End Get
|
|
Set(value As DataTable)
|
|
ViewState("DtAvanceDocumento") = value
|
|
End Set
|
|
End Property
|
|
|
|
|
|
|
|
|
|
Private Property DtDatos As DataTable
|
|
Get
|
|
Return CType(ViewState("DtDatos"), DataTable)
|
|
End Get
|
|
Set(value As DataTable)
|
|
ViewState("DtDatos") = value
|
|
End Set
|
|
End Property
|
|
#End Region
|
|
#Region "Carga Página"
|
|
Protected Sub Page_Load(sender As Object, e As System.EventArgs) Handles Me.Load
|
|
|
|
If Not IsPostBack Then
|
|
DtDatos = New DataTable
|
|
txtFechaI.Text = DateTime.Now.AddMonths(-1).ToShortDateString
|
|
txtFechaF.Text = DateTime.Now.AddDays(1).ToShortDateString
|
|
InicializaCombos()
|
|
CargaDatos()
|
|
End If
|
|
End Sub
|
|
Private Sub InicializaCombos()
|
|
'Lista Tipo AF
|
|
DdlTipoAF.DataSource = GlobalDTTipoActivoFijo(UsuarioActual.CveEmpresa).FiltraParametros("MedidaVehicularClave IN (2,3)")
|
|
DdlTipoAF.DataBind()
|
|
DdlTipoAF.Items.Insert(0, New ListItem("Seleccione", "-1"))
|
|
DdlTipoAF.SelectedValue = "-1"
|
|
|
|
DdlTipoUnidad.DataSource = GlobalDTTipoActivoFijo(UsuarioActual.CveEmpresa).FiltraParametros("MedidaVehicularClave IN (2,3)")
|
|
DdlTipoUnidad.DataBind()
|
|
DdlTipoUnidad.Items.Insert(0, New ListItem("-", ""))
|
|
'Lista Chofer'
|
|
DdlChofer.DataSource = GlobalDTRHPersonal(UsuarioActual.CveEmpresa)
|
|
DdlChofer.DataBind()
|
|
DdlChofer.Items.Insert(0, New ListItem("-", ""))
|
|
'Lista de Monedas
|
|
DdlMoneda.DataSource = GlobalDTMonedas
|
|
DdlMoneda.DataBind()
|
|
|
|
DdlEstatus.DataSource = GlobalDTContratosEstatus(UsuarioActual.CveEmpresa)
|
|
DdlEstatus.DataBind()
|
|
DdlEstatus.Items.Insert(0, New ListItem("Todos", "-1"))
|
|
|
|
CargarCentrosDeCosto(Nothing, DdlCentroCostos, Nothing, LblSubProyectoModal)
|
|
|
|
DdlSubProyectoModal.DataSource = GlobalDTSubProyectos(UsuarioActual.CveEmpresa)
|
|
DdlSubProyectoModal.DataBind()
|
|
DdlSubProyectoModal.Items.Insert(0, New ListItem("Seleccione uno", "-1"))
|
|
End Sub
|
|
Private Sub CargaDatos()
|
|
Dim ObjContratos As New ClsContratos
|
|
|
|
If ObjContratos.GetContratosReporte(UsuarioActual.CveEmpresa, txtFechaI.Text.ToDate, txtFechaF.Text.ToDate, DdlCliente.SelectedValue.ToEntero, DdlEstatus.SelectedValue.ToEntero, CveSubProyecto:=DdlCentroCostos.SelectedValue.ToEntero, CveTipoAF:=DdlTipoUnidad.SelectedValue.ToEntero, CveChofer:=DdlChofer.SelectedValue.ToEntero) Then
|
|
|
|
GvContratos.DataSource = ObjContratos.DtResultados.FiltraParametros($"FechaInicial >= '{txtFechaI.Text.ToDate.ToString("yyyy/MM/dd")}'", "FechaInicial")
|
|
DtDatos = ObjContratos.DtResultados.Copy
|
|
|
|
End If
|
|
ObjContratos.Dispose()
|
|
GvContratos.DataBind()
|
|
|
|
UpTitulos.Update()
|
|
End Sub
|
|
|
|
Private Sub CargaFolio()
|
|
|
|
Dim ObjFolio As New ClsGralFolios
|
|
If ObjFolio.GetFolios("Con", UsuarioActual.CveEmpresa, CveSubProyecto:=-1) Then
|
|
If ObjFolio.DtResultados.Rows.Count > 0 Then
|
|
Dim drr As DataRow = ObjFolio.DtResultados.FiltroPrimero("")
|
|
LbFolio.Text = $"{drr("Serie").ToString}-{drr("FActual").ToString}"
|
|
End If
|
|
End If
|
|
ObjFolio.Dispose()
|
|
|
|
UpModal.Update()
|
|
End Sub
|
|
#End Region
|
|
#Region "Contrato"
|
|
Protected Sub OnChangePasajeros(sender As Object, e As EventArgs)
|
|
If TxtCantidadPasajeros.Text.ToDecimal > 19 Then
|
|
Dim sprintersItem As ListItem = DdlTipoAF.Items.FindByText("Sprinter")
|
|
If sprintersItem IsNot Nothing Then
|
|
DdlTipoAF.Items.Remove(sprintersItem)
|
|
End If
|
|
Else
|
|
Dim sprintersItem As ListItem = DdlTipoAF.Items.FindByText("Sprinter")
|
|
If sprintersItem Is Nothing Then
|
|
DdlTipoAF.Items.Add(New ListItem("Sprinter", "183"))
|
|
End If
|
|
|
|
End If
|
|
End Sub
|
|
Protected Sub AddContrato(sender As Object, e As EventArgs)
|
|
|
|
If Not VallidaCantidadPasajeros(DdlTipoAF.SelectedValue.ToEntero, TxtCantidadPasajeros.Text.ToEntero) Then
|
|
Exit Sub
|
|
End If
|
|
|
|
Dim ErrorProceso As Boolean = False
|
|
Dim CveContrato As Integer = -1
|
|
|
|
Dim FileExtension As String = "-1"
|
|
Dim Filesgral As List(Of Extensiones.Archivo) = Anexo.getfiles().Archivos
|
|
Dim Filename As String = ""
|
|
Dim folderContratosPath As String = Path.Combine(UsuarioActual.Empresa.Ruta, "Contratos")
|
|
|
|
Dim CveVentaRemision As Integer = -1
|
|
Dim SerieFolioRemision As String = ""
|
|
|
|
If Not Directory.Exists(folderContratosPath) Then
|
|
Directory.CreateDirectory(folderContratosPath)
|
|
End If
|
|
|
|
If DdlClientes.SelectedValue = "" Then
|
|
Alert("Debe seleccionar al cliente", TipoMensaje.MsgAdvertencia)
|
|
Exit Sub
|
|
End If
|
|
|
|
If TxtFechaSalida.Text.ToDateTime > TxtFechaRegreso.Text.ToDateTime Then
|
|
Alert("La fecha inicial no puede ser mayor al final.", TipoMensaje.MsgAdvertencia)
|
|
Exit Sub
|
|
End If
|
|
|
|
'Agregamos Contrato
|
|
|
|
Dim ObjContratos As New ClsContratos
|
|
Dim ObjFolios As New ClsGralFolios(ObjContratos.IniciaTransacSQL())
|
|
|
|
CveContrato = ObjContratos.AddContratos(LbFolio.Text, TxtDescripcion.Text, "", UsuarioActual.CveProveedor, DdlClientes.SelectedValue.ToEntero, -1, TxtFechaSalida.Text.ToDateTime, TxtFechaRegreso.Text.ToDateTime, TxtUbicacion.Text, "",
|
|
DdlSubProyectoModal.SelectedValue.ToEntero, -1, -1, -1, -1, LbArchivo.Text, "", -1, UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa, ChkEsPresupuestal.Checked, TxtAnticipo.Text.ToDecimal, -1, TxtImporte.Text.ToDecimal,
|
|
DdlMoneda.SelectedValue.ToEntero, 0, CveContratoTipo:=34, CveContratosEstatus:=50, CveTipoAF:=DdlTipoAF.SelectedValue.ToEntero, CantidadPasajeros:=TxtCantidadPasajeros.Text.ToEntero, Observaciones:=TxtObservaciones.Text,
|
|
CveVendedor:=UsuarioActual.CveVendedor)
|
|
|
|
If CveContrato > 0 Then
|
|
|
|
If Filesgral.Count > 0 Then
|
|
|
|
For Each fileItem As Archivo In Filesgral
|
|
|
|
FileExtension = IO.Path.GetExtension(String.Format("{0}Temp\{1}", AppDomain.CurrentDomain.BaseDirectory, fileItem.filename)).Replace(".", "")
|
|
Dim tempArray() As String
|
|
tempArray = fileItem.filename.ToString().Split("-".ToCharArray())
|
|
Dim fDestino = Path.Combine(UsuarioActual.Empresa.Ruta, "Contratos", $"{CveContrato.ToString}.{ FileExtension}")
|
|
Try
|
|
If File.Exists(fDestino) Then
|
|
File.Delete(fDestino)
|
|
End If
|
|
File.Move(fileItem.FileUrl, fDestino)
|
|
If Not File.Exists(fDestino) Then
|
|
ErrorProceso = True
|
|
End If
|
|
If ObjContratos.UpdateContratoArchivo(CveContrato, $"{CveContrato.ToString}.{ FileExtension}", UsuarioActual.CveEmpresa) Then
|
|
ErrorProceso = False
|
|
End If
|
|
Catch ex As Exception
|
|
ErrorProceso = True
|
|
End Try
|
|
|
|
|
|
Exit For
|
|
Next
|
|
|
|
Else
|
|
ErrorProceso = False
|
|
End If
|
|
Anexo.Text = ""
|
|
|
|
If ErrorProceso = False Then
|
|
|
|
Dim ObsRemisionPartida As String = $"{DdlTipoAF.SelectedItem.Text}-{ TxtDescripcion.Text}-{LbFolio.Text}"
|
|
|
|
Dim Respuesta As New RespuestaFacturacion()
|
|
Dim CvePS As Integer = 907784
|
|
Respuesta = GeneraRemision(CveContrato, ObsRemisionPartida, TxtImporte.Text.ToDecimal, CvePS, ObjContratos.IniciaTransacSQL)
|
|
|
|
If Respuesta.CveVenta > 0 Then
|
|
CveVentaRemision = Respuesta.CveVenta
|
|
SerieFolioRemision = Respuesta.SerieFolio
|
|
ErrorProceso = False
|
|
Else
|
|
ErrorProceso = True
|
|
Alert("se presento un error al generar la remisión", TipoMensaje.MsgAdvertencia)
|
|
End If
|
|
End If
|
|
Else
|
|
ErrorProceso = True
|
|
End If
|
|
|
|
If Not ErrorProceso Then
|
|
'Aumentamos Folio
|
|
If Not ObjFolios.UpdateFolioActual(-1, "Con", True, UsuarioActual.CveEmpresa) Then
|
|
ErrorProceso = True
|
|
End If
|
|
End If
|
|
|
|
If Not ErrorProceso Then
|
|
ObjContratos.Commit()
|
|
|
|
If CveVentaRemision > 0 Then
|
|
Alert($"Agregado Correctamente.<br> Remisión Generada <a target='_blank' class='Texto' href='/Ventas/Ventas.aspx?CveVenta={CveVentaRemision}' ><b>{SerieFolioRemision}</b></a>")
|
|
Else
|
|
Alert($"Agregado Correctamente")
|
|
End If
|
|
|
|
Else
|
|
ObjContratos.RollBack()
|
|
Alert("Se presento un error al guardar el contrato.", TipoMensaje.MsgAdvertencia)
|
|
End If
|
|
|
|
ObjContratos.Dispose()
|
|
ObjFolios.Dispose()
|
|
|
|
ResetModal()
|
|
CargaDatos()
|
|
RegistraScript("$('#ModalAgregar').modal('hide')", "hidemodal1")
|
|
End Sub
|
|
|
|
Private Function VallidaCantidadPasajeros(CveTipoAF As Integer, Cantidad As Integer) As Boolean
|
|
|
|
Dim Respuesta As Boolean = True
|
|
If CveTipoAF = 181 And Cantidad < 21 Then 'autobus
|
|
Respuesta = False
|
|
Alert("El tipo unidad autobus debe de tener un minimo de 22 pasajeros.", TipoMensaje.MsgAdvertencia)
|
|
ElseIf CveTipoAF = 184 And Cantidad > 21 Then 'sprinter
|
|
Respuesta = False
|
|
Alert("El tipo de unidad sprinter no puede tener más de 21 pasajeros.", TipoMensaje.MsgAdvertencia)
|
|
End If
|
|
Return Respuesta
|
|
|
|
End Function
|
|
|
|
Protected Sub ResetModal()
|
|
'Reiniciamos modal
|
|
TxtDescripcion.Text = ""
|
|
TxtFechaSalida.Text = ""
|
|
TxtFechaRegreso.Text = ""
|
|
TxtObservaciones.Text = ""
|
|
TxtUbicacion.Text = ""
|
|
DdlClientes.SelectedText = ""
|
|
DdlSubProyectoModal.SelectedValueExist(-1)
|
|
DdlTipoAF.SelectedValueExist(-1)
|
|
TxtImporte.Text = ""
|
|
TxtAnticipo.Text = ""
|
|
TxtCantidadPasajeros.Text = ""
|
|
LbArchivo.Text = ""
|
|
|
|
UpModal.Update()
|
|
End Sub
|
|
Protected Sub LnkExcel_Click(sender As Object, e As EventArgs) Handles LnkExcel.Click
|
|
'GvContratos.ExportToExcel("ReporteCompras" & NowADS().ToShortDateString)
|
|
ImprimeReporte("Excel")
|
|
End Sub
|
|
Protected Sub LnkPDF_Click(sender As Object, e As EventArgs) Handles LnkPdf.Click
|
|
ImprimeReporte("PDF")
|
|
End Sub
|
|
Private Sub ImprimeReporte(Formato As String)
|
|
'Dim ObjContratos As New ClsContratos
|
|
If DtDatos.Rows.Count > 0 Then
|
|
Dim Imagen As New IO.FileInfo($"{UsuarioActual.Empresa.Ruta}/Logo.png")
|
|
Dim logouri As String = String.Format("{0}://{1}:{2}/Empresas/{3}/Logo.png", Request.Url.Scheme, Request.Url.Host, Request.Url.Port, UsuarioActual.CveEmpresa)
|
|
Dim Cliente As String = If(DdlClientes.SelectedValue = "-1", "", $" <b>Cliente:</b> {DdlClientes.SelectedText}")
|
|
|
|
Dim params As New List(Of ReportParameter) From {
|
|
New ReportParameter("NombreEmpresa", UsuarioActual.Empresa.Empresa),
|
|
New ReportParameter("FechaInicio", "-1"),
|
|
New ReportParameter("FechaFin", "-1"),
|
|
New ReportParameter("NombreEmpresa", UsuarioActual.Empresa.Empresa),
|
|
New ReportParameter("UsuarioImprimio", UsuarioActual.Nombre),
|
|
New ReportParameter("FechaImpresion", NowADS().ToDateTime.ToShortDateString),
|
|
New ReportParameter("LogoPath", If(Imagen.Exists, $"file://{Imagen.FullName}", ""))
|
|
}
|
|
ImprimirPDF("Empresas/Grales/Formatos/RepContratos.rdlc", DtDatos, params, NombreArchivo:="Reporte Contratos", Formato:=Formato)
|
|
Else
|
|
Alert("No hay datos consultados", TipoMensaje.MsgAdvertencia)
|
|
End If
|
|
|
|
End Sub
|
|
Protected Sub Consultar(sender As Object, e As EventArgs)
|
|
CargaDatos()
|
|
End Sub
|
|
Protected Sub Personalizar(sender As Object, e As EventArgs)
|
|
GvContratos.Columns(6).Visible = ChkChofer.Checked
|
|
GvContratos.Columns(7).Visible = ChkChofer2.Checked
|
|
GvContratos.Columns(8).Visible = ChkUnidad.Checked
|
|
UpTitulos.Update()
|
|
End Sub
|
|
Protected Sub GuardarArchivo(sender As Object, e As EventArgs)
|
|
Dim FileExtension As String = "-1"
|
|
Dim Filesgral As List(Of Archivo) = Anexo.getfiles().Archivos
|
|
Dim Filename As String = ""
|
|
Dim folderContratosPath As String = Path.Combine(UsuarioActual.Empresa.Ruta, "Contratos")
|
|
|
|
If Not Directory.Exists(folderContratosPath) Then
|
|
Directory.CreateDirectory(folderContratosPath)
|
|
End If
|
|
If Not Directory.Exists(Path.Combine(folderContratosPath, "Temp")) Then
|
|
Directory.CreateDirectory(Path.Combine(folderContratosPath, "Temp"))
|
|
End If
|
|
|
|
For Each fileItem As Archivo In Filesgral
|
|
|
|
FileExtension = IO.Path.GetExtension(String.Format("{0}Temp\{1}", AppDomain.CurrentDomain.BaseDirectory, fileItem.filename)).Replace(".", "")
|
|
Session("FileExtension") = FileExtension
|
|
Dim tempArray() As String
|
|
tempArray = fileItem.filename.ToString().Split("-".ToCharArray())
|
|
ViewState("extencion") = FileExtension
|
|
ViewState("FUrl") = Path.Combine(UsuarioActual.Empresa.Ruta, "Contratos", "Temp", fileItem.filename)
|
|
File.Move(fileItem.FileUrl, ViewState("FUrl").ToString)
|
|
LbArchivo.Text = tempArray(1)
|
|
Next
|
|
|
|
UpModal.Update()
|
|
RegistraScript("$('#ModalUpload').modal('hide')", "hidemodal1")
|
|
End Sub
|
|
#End Region
|
|
|
|
|
|
#Region "G E N E R A R E M I S O N"
|
|
|
|
Private Function GeneraRemision(CveContrato As Integer, ObsPartida As String, Importe As Decimal, CvePS As Integer, ByRef TransaccionSQL As SqlClient.SqlTransaction) As RespuestaFacturacion
|
|
|
|
Dim Respuesta As New RespuestaFacturacion()
|
|
Dim CveRemisionGenerada As Integer = -1
|
|
Dim ObjVentas As New ClsVentas(TransaccionSQL)
|
|
Dim ProcesoOK As Boolean = True
|
|
Dim CveSubProyecto As Integer = DdlSubProyectoModal.SelectedValue.ToEntero
|
|
Dim CveMoneda As Integer = DdlMoneda.SelectedValue.ToEntero
|
|
|
|
Dim ObjFactura As Modelos.Factura = Modelos.Factura.CrearVentaNueva(UsuarioActual, CveSubProyecto, DdlClientes.SelectedValue.ToEntero, CveMoneda, "Rem")
|
|
|
|
If ObjFactura IsNot Nothing AndAlso ProcesoOK Then
|
|
ObjFactura.CveMoneda = CveMoneda
|
|
ObjFactura.CveContrato = CveContrato
|
|
ObjFactura.Observaciones = ObsPartida
|
|
ObjFactura.CveFormaPago = 20 ' por definir
|
|
If CveMoneda > 1 Then
|
|
ObjFactura.TipoCambio = GlobalTipoCambio(DateTime.Now).ToDecimal
|
|
End If
|
|
|
|
Dim TmpDTMat As New DataTable
|
|
TmpDTMat.Columns.Add("Consec", GetType(Integer))
|
|
TmpDTMat.Columns.Add("CvePS", GetType(Integer))
|
|
TmpDTMat.Columns.Add("CveUM", GetType(Integer))
|
|
TmpDTMat.Columns.Add("Cantidad", GetType(Integer))
|
|
TmpDTMat.Columns.Add("PU", GetType(Decimal))
|
|
TmpDTMat.Columns.Add("Lote", GetType(String))
|
|
TmpDTMat.Columns.Add("FechaCaducidad", GetType(Date))
|
|
TmpDTMat.Columns.Add("CveVentaDetalle", GetType(Integer))
|
|
|
|
Dim CantidadRegistro As Decimal = 1
|
|
Dim PorcentajeIVA As Decimal = GlobalDTSubProyectos(UsuarioActual.CveEmpresa, CveSubProyecto:=CveSubProyecto).FiltroPrimeroValor("IVA").ToDecimal
|
|
Dim SubTotal As Decimal = (Importe / (1D + PorcentajeIVA))
|
|
Dim PU As Decimal = SubTotal
|
|
Dim Descuento As Decimal = 0
|
|
Dim Obs As String = ObsPartida
|
|
|
|
If CantidadRegistro > 0 Then
|
|
If ObjFactura.AgregarPS(CvePS, CantidadRegistro, PU, Descuento, Obs, CveSubProyecto:=CveSubProyecto, PorcentajeIVA:=PorcentajeIVA) Then
|
|
Dim drp As DataRow = TmpDTMat.NewRow
|
|
drp("CvePS") = CvePS
|
|
drp("Cantidad") = CantidadRegistro
|
|
drp("PU") = PU
|
|
TmpDTMat.Rows.Add(drp)
|
|
Else
|
|
Alert("Error al agregar producto", TipoMensaje.MsgAdvertencia)
|
|
ProcesoOK = False
|
|
End If
|
|
End If
|
|
|
|
If ProcesoOK Then
|
|
ObjFactura.CalculaTotales()
|
|
Dim Resp As New Modelos.Factura.MMensajeFactura
|
|
Resp = ObjFactura.EmitirFactura(False, Transac:=TransaccionSQL)
|
|
|
|
If Resp.CveVenta > 0 Then
|
|
Respuesta.CveVenta = Resp.CveVenta
|
|
Respuesta.SerieFolio = Resp.SerieFolio
|
|
Respuesta.dtdetalle = TmpDTMat
|
|
Else
|
|
ProcesoOK = False
|
|
End If
|
|
End If
|
|
Else
|
|
ProcesoOK = False
|
|
End If
|
|
Return Respuesta
|
|
|
|
End Function
|
|
|
|
Friend Class RespuestaFacturacion
|
|
Public Property CveVenta As Integer = -1
|
|
Public Property SerieFolio As String = "-1"
|
|
Public Property dtdetalle As DataTable = Nothing
|
|
Public Sub New()
|
|
|
|
End Sub
|
|
End Class
|
|
#End Region
|
|
|
|
Protected Sub LnkAgregarContrato_Click(sender As Object, e As EventArgs)
|
|
CargaFolio()
|
|
RegistraScript("$('#ModalAgregar').modal({ backdrop: 'static', keyboard: false });")
|
|
UpTitulos.Update()
|
|
End Sub
|
|
End Class
|