Commit inicial Ventas Productivo
This commit is contained in:
408
Inventarios/Fletes.aspx.vb
Normal file
408
Inventarios/Fletes.aspx.vb
Normal file
@@ -0,0 +1,408 @@
|
||||
Option Explicit On
|
||||
Option Strict On
|
||||
|
||||
Imports System.Data
|
||||
Imports Extensiones
|
||||
Partial Class Compras_Fletes
|
||||
Inherits ClsPaginas
|
||||
|
||||
#Region "PROPIEDADES"
|
||||
Private Property CveFlete As Integer
|
||||
Get
|
||||
Return ViewState("CveFlete").ToString.ToEntero
|
||||
End Get
|
||||
Set(value As Integer)
|
||||
ViewState("CveFlete") = value
|
||||
End Set
|
||||
End Property
|
||||
Private Property DtCompras As DataTable
|
||||
Get
|
||||
Return CType(ViewState("DtCompras"), DataTable)
|
||||
End Get
|
||||
Set(value As DataTable)
|
||||
ViewState("DtCompras") = value
|
||||
End Set
|
||||
End Property
|
||||
#End Region
|
||||
|
||||
Protected Sub Page_Load(sender As Object, e As System.EventArgs) Handles Me.Load
|
||||
If Not Page.IsPostBack Then
|
||||
|
||||
InicializaValores()
|
||||
CargaURLParametros()
|
||||
|
||||
End If
|
||||
End Sub
|
||||
|
||||
|
||||
#Region " INICIALIZA VALORES "
|
||||
Private Sub InicializaValores()
|
||||
DtCompras = New DataTable
|
||||
TxtFecha.Text = Now.ToShortDateString
|
||||
End Sub
|
||||
Private Sub CargaFolio()
|
||||
Dim ObjFolios As New ClsGralFolios
|
||||
If ObjFolios.GetFolios("FLE", UsuarioActual.CveEmpresa) Then
|
||||
If ObjFolios.DtResultados.Rows.Count > 0 Then
|
||||
LblFolio.Text = ObjFolios.DtResultados(0)("FActual").ToString
|
||||
Else
|
||||
Alert("Necesita registrar un folio de fletes", TipoMensaje.MsgAdvertencia)
|
||||
BtnGuardar.Enabled = False
|
||||
End If
|
||||
End If
|
||||
ObjFolios.Dispose()
|
||||
UpRegistro.Update()
|
||||
End Sub
|
||||
#End Region
|
||||
|
||||
#Region " CARGA DATOS "
|
||||
|
||||
Private Sub CargaURLParametros()
|
||||
If Request("CveFlete") IsNot Nothing AndAlso IsNumeric(Request("CveFlete")) AndAlso Request("CveFlete").ToEntero > 0 Then
|
||||
CveFlete = Request("CveFlete").ToEntero
|
||||
BtnGuardar.Text = "Guardar"
|
||||
CargaFlete()
|
||||
BtnEliminar.Visible = True
|
||||
Else
|
||||
CveFlete = -1
|
||||
CargaFolio()
|
||||
End If
|
||||
End Sub
|
||||
|
||||
Private Sub CargaFlete()
|
||||
Dim ObjInv As New ClsInventarios
|
||||
|
||||
If ObjInv.GetFletes(UsuarioActual.CveEmpresa, CveFlete:=CveFlete) Then
|
||||
If ObjInv.DtResultados.Rows.Count > 0 Then
|
||||
LblFolio.Text = ObjInv.DtResultados.Rows(0)("Folio").ToString
|
||||
TxtDescripcion.Text = ObjInv.DtResultados.Rows(0)("Descripcion").ToString
|
||||
TxtFecha.Text = ObjInv.DtResultados.Rows(0)("Fecha").ToString
|
||||
|
||||
If ObjInv.DtResultados.Rows(0)("CveOC").ToString.ToEntero > 0 Then
|
||||
DdlModalidad.SelectedValue = "1"
|
||||
Else
|
||||
DdlModalidad.SelectedValue = "2"
|
||||
End If
|
||||
CambiaModalidad()
|
||||
HdnCveOC.Value = ObjInv.DtResultados.Rows(0)("CveOC").ToString
|
||||
HdnCveCompra.Value = ObjInv.DtResultados.Rows(0)("CveCompra").ToString
|
||||
|
||||
LbOCProveedor.Text = ObjInv.DtResultados.Rows(0)("RazonSocial").ToString
|
||||
HLOCFolio.Text = ObjInv.DtResultados.Rows(0)("FolioDocumento").ToString
|
||||
HLOCFolio.NavigateUrl = If(HdnCveOC.Value.ToEntero > 0, $"/OC/OC.aspx?OC={HdnCveOC.Value}", $"/Compras/Compras.aspx?CveCompra={HdnCveCompra.Value}")
|
||||
LbOCImporte.Text = $"{ObjInv.DtResultados.Rows(0)("TotalDocumento").ToString.FormatoNumero} {ObjInv.DtResultados.Rows(0)("Moneda").ToString}"
|
||||
|
||||
If ObjInv.GetFleteDetalle(CveFlete) Then
|
||||
DtCompras = ObjInv.DtResultados
|
||||
Else
|
||||
Alert("Ocurrió un error al cargar el detalle del flete", TipoMensaje.MsgError)
|
||||
End If
|
||||
|
||||
Else
|
||||
Alert("No se encontró el flete", TipoMensaje.MsgInformacion)
|
||||
End If
|
||||
Else
|
||||
Alert("Ocurrió un error al cargar el flete", TipoMensaje.MsgError)
|
||||
End If
|
||||
|
||||
ObjInv.Dispose()
|
||||
CargaGrid()
|
||||
UpRegistro.Update()
|
||||
|
||||
End Sub
|
||||
Private Sub CargaGrid()
|
||||
GvDatos.DataSource = DtCompras
|
||||
GvDatos.DataBind()
|
||||
UpComprasGasto.Update()
|
||||
End Sub
|
||||
|
||||
#End Region
|
||||
|
||||
#Region " VINCULA DOCUMENTO PRINCIPAL - OC | COMPRA "
|
||||
|
||||
Protected Sub DdlModalidad_SelectedIndexChanged(sender As Object, e As EventArgs)
|
||||
CambiaModalidad()
|
||||
UpRegistro.Update()
|
||||
End Sub
|
||||
Private Sub CambiaModalidad()
|
||||
HdnCveOC.Value = "-1"
|
||||
HdnCveCompra.Value = "-1"
|
||||
|
||||
LbOCProveedor.Text = ""
|
||||
HLOCFolio.Text = ""
|
||||
HLOCFolio.NavigateUrl = "#"
|
||||
LbOCImporte.Text = ""
|
||||
|
||||
DivVincularOC.Visible = DdlModalidad.SelectedValue = "1"
|
||||
DivVincularCompra.Visible = DdlModalidad.SelectedValue = "2"
|
||||
End Sub
|
||||
|
||||
Protected Sub BtnVincularOC_Click(sender As Object, e As EventArgs)
|
||||
VinculaOC()
|
||||
End Sub
|
||||
Private Sub VinculaOC()
|
||||
If HdnCveOC.Value <> "-1" AndAlso IsNumeric(HdnCveOC.Value) AndAlso HdnCveOC.Value.ToEntero > 0 Then
|
||||
Dim ObjInv As New ClsInventarios
|
||||
Dim ObjOC As New ClsOC
|
||||
If ObjInv.GetFletes(UsuarioActual.CveEmpresa, CveOC:=HdnCveOC.Value.ToEntero) AndAlso ObjInv.DtResultados.Rows.Count = 0 Then
|
||||
If ObjOC.GetOC(HdnCveOC.Value.ToEntero, UsuarioActual.CveEmpresa) Then
|
||||
If ObjOC.DtResultados.Rows.Count > 0 Then
|
||||
LbOCProveedor.Text = ObjOC.DtResultados.Rows(0)("RazonSocial").ToString
|
||||
HLOCFolio.Text = $"{ObjOC.DtResultados.Rows(0)("Folio").ToString}"
|
||||
HLOCFolio.NavigateUrl = $"/OC/OC.aspx?OC={HdnCveOC.Value}"
|
||||
LbOCImporte.Text = $"$ {ObjOC.DtResultados.Rows(0)("Total").ToString.FormatoNumero} {ObjOC.DtResultados.Rows(0)("Moneda").ToString}"
|
||||
End If
|
||||
Else
|
||||
HdnCveOC.Value = "-1"
|
||||
End If
|
||||
Else
|
||||
Alert($"La orden de compra ya forma parte del flete: <b>{ObjInv.DtResultados.Rows(0)("Folio")}</b>. Por favor verifique y vuelva a intentar.", TipoMensaje.MsgAdvertencia)
|
||||
End If
|
||||
ObjInv.Dispose()
|
||||
ObjOC.Dispose()
|
||||
End If
|
||||
UpRegistro.Update()
|
||||
End Sub
|
||||
Protected Sub BtnVincularCompra_Click(sender As Object, e As EventArgs)
|
||||
VincularCompra()
|
||||
End Sub
|
||||
Private Sub VincularCompra()
|
||||
|
||||
If Not (HdnCveCompra.Value <> "-1" AndAlso IsNumeric(HdnCveCompra.Value) AndAlso HdnCveCompra.Value.ToEntero > 0) Then
|
||||
Alert("No hay compra seleccionaada", TipoMensaje.MsgAdvertencia)
|
||||
Exit Sub
|
||||
End If
|
||||
|
||||
Dim ObjCompras As New ClsCompras
|
||||
Dim ObjInv As New ClsInventarios
|
||||
Dim ErrorAgregar = False
|
||||
Dim RowCompras As DataRow = Nothing
|
||||
|
||||
If ObjCompras.GetCompras(HdnCveCompra.Value.ToEntero, "-1", "-1", -1, -1, UsuarioActual.CveEmpresa) Then
|
||||
RowCompras = ObjCompras.DtResultados.Rows(0)
|
||||
If Not (ObjInv.GetFleteDetalle(-1, HdnCveCompra.Value.ToEntero) AndAlso ObjInv.DtResultados.Rows.Count = 0) Then
|
||||
ErrorAgregar = True
|
||||
Alert($"La compra ya forma parte del flete: <b>{ObjCompras.DtResultados.Rows(0)("Folio")}</b>. Por favor verifique y vuelva a intentar.", TipoMensaje.MsgAdvertencia)
|
||||
End If
|
||||
Else
|
||||
ErrorAgregar = True
|
||||
Alert("Ocurrió un error al cargar la información de la compra. Por favor comuniquese con atención SIG.", TipoMensaje.MsgError)
|
||||
End If
|
||||
|
||||
If Not ErrorAgregar Then
|
||||
If DtCompras.FiltraParametros($"CveCompra = {RowCompras("CveCompra").ToString.ToEntero}").Rows.Count > 0 Then
|
||||
ErrorAgregar = True
|
||||
Alert("La compra seleccionada ya es parte del flete. Por favor verifique y vuelva a intentar.", TipoMensaje.MsgAdvertencia)
|
||||
End If
|
||||
End If
|
||||
|
||||
If Not ErrorAgregar Then
|
||||
LbOCProveedor.Text = ObjCompras.DtResultados.Rows(0)("RazonSocial").ToString
|
||||
HLOCFolio.Text = $"{ObjCompras.DtResultados.Rows(0)("Folio").ToString}"
|
||||
HLOCFolio.NavigateUrl = $"/Compras/Compras.aspx?CveCompra={HdnCveCompra.Value}"
|
||||
LbOCImporte.Text = $"$ {ObjCompras.DtResultados.Rows(0)("Total").ToString.FormatoNumero} {ObjCompras.DtResultados.Rows(0)("Moneda").ToString}"
|
||||
Else
|
||||
HdnCveCompra.Value = "-1"
|
||||
End If
|
||||
|
||||
ObjCompras.Dispose()
|
||||
ObjInv.Dispose()
|
||||
|
||||
End Sub
|
||||
|
||||
#End Region
|
||||
|
||||
#Region " AGREGA COMPRA GASTO "
|
||||
Protected Sub BtnVincularCompraGasto_Click(sender As Object, e As EventArgs)
|
||||
AgregaCompraGasto()
|
||||
End Sub
|
||||
Protected Sub ImgAgregarCompraGasto_Click(sender As Object, e As ImageClickEventArgs)
|
||||
AgregaCompraGasto()
|
||||
End Sub
|
||||
Private Sub AgregaCompraGasto()
|
||||
|
||||
If Not (HdnCveCompraGasto.Value <> "-1" AndAlso IsNumeric(HdnCveCompraGasto.Value) AndAlso HdnCveCompraGasto.Value.ToEntero > 0) Then
|
||||
Alert("No hay compra de gasto seleccionaada", TipoMensaje.MsgAdvertencia)
|
||||
Exit Sub
|
||||
End If
|
||||
|
||||
Dim ObjCompras As New ClsCompras
|
||||
Dim ObjInv As New ClsInventarios(ObjCompras.IniciaTransacSQL)
|
||||
Dim ErrorAgregar = False
|
||||
Dim RowCompras As DataRow = Nothing
|
||||
|
||||
If ObjCompras.GetCompras(HdnCveCompraGasto.Value.ToEntero, "-1", "-1", -1, -1, UsuarioActual.CveEmpresa) Then
|
||||
RowCompras = ObjCompras.DtResultados.Rows(0)
|
||||
If Not (ObjInv.GetFleteDetalle(-1, HdnCveCompraGasto.Value.ToEntero) AndAlso ObjInv.DtResultados.Rows.Count = 0) Then
|
||||
ErrorAgregar = True
|
||||
Alert($"La compra ya forma parte del flete: <b>{ObjCompras.DtResultados.Rows(0)("Folio")}</b>. Por favor verifique y vuelva a intentar.", TipoMensaje.MsgAdvertencia)
|
||||
End If
|
||||
Else
|
||||
ErrorAgregar = True
|
||||
Alert("Ocurrió un error al cargar la información de la compra. Por favor comuniquese con atención SIG.", TipoMensaje.MsgError)
|
||||
End If
|
||||
|
||||
If HdnCveCompraGasto.Value.ToEntero = HdnCveOC.Value.ToEntero Then
|
||||
ErrorAgregar = True
|
||||
Alert("La Compra seleccionada como gasto es la orden de compra del pedimento. Por favor verifique y vuelva a intentar.", TipoMensaje.MsgAdvertencia)
|
||||
End If
|
||||
|
||||
If Not ErrorAgregar Then
|
||||
If DtCompras.FiltraParametros($"CveCompra = {RowCompras("CveCompra").ToString.ToEntero}").Rows.Count > 0 Then
|
||||
ErrorAgregar = True
|
||||
Alert("La compra seleccionada ya es parte del flete. Por favor verifique y vuelva a intentar.", TipoMensaje.MsgAdvertencia)
|
||||
End If
|
||||
End If
|
||||
|
||||
If Not ErrorAgregar Then
|
||||
If Not GvDatos.Rows.Count > 0 Then
|
||||
DtCompras = RowCompras.Table.Clone
|
||||
DtCompras.Columns.Add("CveFleteDetalle", Type.GetType("System.Int32"))
|
||||
End If
|
||||
If CveFlete > 0 Then
|
||||
If Not ObjInv.AddFleteDetalle(CveFlete, RowCompras("CveCompra").ToString.ToEntero) Then
|
||||
ErrorAgregar = True
|
||||
Alert("Ocurrió un error al agregar la compra. Por favor intente de nuevo.", TipoMensaje.MsgError)
|
||||
End If
|
||||
End If
|
||||
End If
|
||||
|
||||
If Not ErrorAgregar Then
|
||||
ObjCompras.Commit()
|
||||
DtCompras.ImportRow(RowCompras)
|
||||
CargaGrid()
|
||||
If CveFlete > 0 Then
|
||||
Alert("La orden de compra se agregó correctamente.", TipoMensaje.MsgInformacion)
|
||||
End If
|
||||
Else
|
||||
ObjCompras.RollBack()
|
||||
End If
|
||||
|
||||
HdnCveCompraGasto.Value = "-1"
|
||||
ObjCompras.Dispose()
|
||||
ObjInv.Dispose()
|
||||
|
||||
End Sub
|
||||
Private Sub GvDireccionesEnvio_RowDeleting(sender As Object, e As GridViewDeleteEventArgs) Handles GvDatos.RowDeleting
|
||||
Dim TieneError = False
|
||||
If CveFlete > 0 AndAlso GvDatos.Rows(e.RowIndex).DataKey("CveFleteDetalle").ToEntero > 0 Then
|
||||
Dim ObjInv As New ClsInventarios
|
||||
|
||||
If Not ObjInv.RemoveFleteDetalle(GvDatos.Rows(e.RowIndex).DataKey("CveFleteDetalle").ToEntero) Then
|
||||
TieneError = True
|
||||
Alert("Ocurrió un error al eliminar el detalle. Por favor intente de nuevo", TipoMensaje.MsgError)
|
||||
Else
|
||||
Alert("Elflete detalle se eliminó correctamente", TipoMensaje.MsgInformacion)
|
||||
End If
|
||||
ObjInv.Dispose()
|
||||
End If
|
||||
|
||||
If Not TieneError Then
|
||||
DtCompras.Rows.RemoveAt(e.RowIndex)
|
||||
DtCompras.AcceptChanges()
|
||||
End If
|
||||
|
||||
CargaGrid()
|
||||
End Sub
|
||||
|
||||
#End Region
|
||||
|
||||
#Region " GUARDAR "
|
||||
Protected Sub BtnGuardar_Click(sender As Object, e As EventArgs)
|
||||
|
||||
Select Case DdlModalidad.SelectedValue.ToEntero
|
||||
Case 1
|
||||
If Not HdnCveOC.Value.ToEntero > 0 Then
|
||||
Alert("Tiene que tener vinculada una OC", TipoMensaje.MsgAdvertencia)
|
||||
Exit Sub
|
||||
End If
|
||||
Case 2
|
||||
If Not HdnCveCompra.Value.ToEntero > 0 Then
|
||||
Alert("Tiene que tener vinculada una Compra", TipoMensaje.MsgAdvertencia)
|
||||
Exit Sub
|
||||
End If
|
||||
End Select
|
||||
|
||||
If Not DtCompras.Rows.Count > 0 Then
|
||||
Alert("Tiene que tener compras de gastos agregadas", TipoMensaje.MsgAdvertencia)
|
||||
Exit Sub
|
||||
End If
|
||||
|
||||
Dim ObjInv As New ClsInventarios
|
||||
ObjInv.IniciaTransacSQL()
|
||||
Dim ErrorFlete = False
|
||||
Dim CveFleteTemporal As Integer = 0
|
||||
|
||||
If CveFlete < 0 Then
|
||||
If ObjInv.AddFlete(LblFolio.Text, TxtDescripcion.Text.Trim, TxtFecha.Text.ToDate, HdnCveOC.Value.ToEntero, HdnCveCompra.Value.ToEntero, UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa) Then
|
||||
CveFleteTemporal = ObjInv.CveFlete
|
||||
Else
|
||||
ErrorFlete = True
|
||||
End If
|
||||
|
||||
If CveFleteTemporal > 0 Then
|
||||
For Each dr As DataRow In DtCompras.Rows
|
||||
If Not ObjInv.AddFleteDetalle(CveFleteTemporal, dr("CveCompra").ToString.ToEntero) Then
|
||||
ErrorFlete = True
|
||||
End If
|
||||
Next
|
||||
Else
|
||||
ErrorFlete = True
|
||||
End If
|
||||
Else
|
||||
If Not ObjInv.UpdateFlete(CveFlete, TxtDescripcion.Text, TxtFecha.Text.ToDate, HdnCveOC.Value.ToEntero, HdnCveCompra.Value.ToEntero, UsuarioActual.CveUsuario) Then
|
||||
ErrorFlete = True
|
||||
End If
|
||||
End If
|
||||
|
||||
If Not ErrorFlete Then
|
||||
BtnGuardar.Enabled = False
|
||||
ObjInv.Commit()
|
||||
If CveFlete > 0 Then
|
||||
Alert("Flete actualizado con éxito.", TipoMensaje.MsgInformacion, "document.location.href=""/Inventarios/RepFletes.aspx"";")
|
||||
Else
|
||||
Alert("Flete agregado con éxito.", TipoMensaje.MsgInformacion, "document.location.href=""/Inventarios/RepFletes.aspx"";")
|
||||
End If
|
||||
Else
|
||||
ObjInv.RollBack()
|
||||
Alert("Ocurrió un error al registrar el flete. Por favor vuelva a intentar.", TipoMensaje.MsgError)
|
||||
End If
|
||||
|
||||
ObjInv.Dispose()
|
||||
End Sub
|
||||
#End Region
|
||||
|
||||
#Region " ELIMINAR "
|
||||
Protected Sub BtnEliminar_Click(sender As Object, e As EventArgs)
|
||||
Dim ObjInv As New ClsInventarios
|
||||
ObjInv.IniciaTransacSQL()
|
||||
Dim ErrorEliminar = False
|
||||
|
||||
For Each dr As DataRow In DtCompras.Rows
|
||||
If Not ObjInv.RemoveFleteDetalle(dr("CveFleteDetalle").ToString.ToEntero) Then
|
||||
ErrorEliminar = True
|
||||
End If
|
||||
Next
|
||||
|
||||
If Not ErrorEliminar Then
|
||||
If Not ObjInv.RemoveFlete(CveFlete) Then
|
||||
ErrorEliminar = True
|
||||
End If
|
||||
End If
|
||||
|
||||
If Not ErrorEliminar Then
|
||||
Alert("Flete elimnado con éxito.", TipoMensaje.MsgInformacion, "document.location.href=""/Inventarios/RepFletes.aspx"";")
|
||||
ObjInv.Commit()
|
||||
Else
|
||||
ObjInv.RollBack()
|
||||
End If
|
||||
|
||||
ObjInv.Dispose()
|
||||
End Sub
|
||||
|
||||
#End Region
|
||||
|
||||
|
||||
|
||||
|
||||
End Class
|
||||
Reference in New Issue
Block a user