diff --git a/App_Code/ClsContabilidad.vb b/App_Code/ClsContabilidad.vb index 1a7c08f99..e21cb2136 100644 --- a/App_Code/ClsContabilidad.vb +++ b/App_Code/ClsContabilidad.vb @@ -3577,7 +3577,7 @@ Public Class ClsContabilidad Public Function GetMovimientosAuxiliaresCatalogo(CveCuenta As Integer, FechaI As Date, FechaF As Date, CveMoneda As Integer, CveProyecto As Integer, CveSubProyecto As Integer, CveEmpresa As Integer, TipoReporte As String, OpcionCuentas As Integer) As Boolean Dim Retorno As Boolean = False - DataAdapter("PA_Conta_MovimientosAuxiliaresCatalogoGetOIC") + DataAdapter("PA_Conta_MovimientosAuxiliaresCatalogoGet") With SqlAdapter.SelectCommand.Parameters .Add("@FechaI", SqlDbType.Date).Value = FechaI @@ -3599,6 +3599,32 @@ Public Class ClsContabilidad Return Retorno End Function + + Public Function GetLibroMayor2(CveCuenta As Integer, FechaI As Date, FechaF As Date, CveMoneda As Integer, CveProyecto As Integer, CveSubProyecto As Integer, CveEmpresa As Integer, TipoReporte As String, OpcionCuentas As Integer) As Boolean + Dim Retorno As Boolean = False + + DataAdapter("PA_Conta_LibroMayor2Get") + + With SqlAdapter.SelectCommand.Parameters + .Add("@FechaI", SqlDbType.Date).Value = FechaI + .Add("@FechaF", SqlDbType.Date).Value = FechaF + .Add("@CveCuenta", SqlDbType.Int).Value = CveCuenta + .Add("@CveProyecto", SqlDbType.Int).Value = CveProyecto + .Add("@CveSubProyecto", SqlDbType.Int).Value = CveSubProyecto + .Add("@CveEmpresa", SqlDbType.Int).Value = CveEmpresa + .Add("@Tipo", SqlDbType.Int).Value = TipoReporte + .Add("@OpcionCuentas", SqlDbType.Int).Value = OpcionCuentas + End With + SqlAdapter.SelectCommand.CommandTimeout = 0 + Try + SqlAdapter.Fill(Data) + Retorno = True + Catch ex As Exception + Me.OnError("Ocurrió un error al obtener los Movimientos Libro mayor", ex, SqlAdapter.SelectCommand.Parameters.ParametrosInfo()) + End Try + + Return Retorno + End Function Public Function PolizaGet(CvePoliza As Integer) As Boolean Dim Retorno As Boolean = False diff --git a/App_Code/ClsInventarios.vb b/App_Code/ClsInventarios.vb index 0813ad5c8..9d36dd399 100644 --- a/App_Code/ClsInventarios.vb +++ b/App_Code/ClsInventarios.vb @@ -4495,24 +4495,24 @@ Public Class ClsInventarios Return Retorno End Function - Public Function UpdateOSEstatusInventario(CveOS As Integer, Estatus As Boolean, CveEmpresa As Integer) As Boolean - Dim Retorno As Boolean = False - - DataAdapter("PA_OS_OSEstatusInventarioUpdate") - - With SqlAdapter.SelectCommand.Parameters + Public Function UpdateOSEstatusInventario(CveOS As Integer, Estatus As Boolean, CveEmpresa As Integer) As Boolean + Dim Retorno As Boolean = False + + DataAdapter("PA_OS_OSEstatusInventarioUpdate") + + With SqlAdapter.SelectCommand.Parameters .Add("@CveOS", SqlDbType.Int).Value = CveOS - .Add("@CveEmpresa", SqlDbType.Int).Value = CveEmpresa - End With - - Try - SqlAdapter.Fill(Data) - Retorno = True - Catch ex As Exception - OnError("Ocurrió un error al actualizar el estatus de OS.", ex, SqlAdapter.SelectCommand.Parameters.ParametrosInfo) - End Try - - Return Retorno + .Add("@CveEmpresa", SqlDbType.Int).Value = CveEmpresa + End With + + Try + SqlAdapter.Fill(Data) + Retorno = True + Catch ex As Exception + OnError("Ocurrió un error al actualizar el estatus de OS.", ex, SqlAdapter.SelectCommand.Parameters.ParametrosInfo) + End Try + + Return Retorno End Function #End Region diff --git a/App_Code/ClsPaginas.vb b/App_Code/ClsPaginas.vb index 52ca8e6f7..8943c36ab 100644 --- a/App_Code/ClsPaginas.vb +++ b/App_Code/ClsPaginas.vb @@ -10172,7 +10172,7 @@ Public Class ClsPaginas PaginaDict.Add("/Contabilidad/RepEstadoResultadosHorizontal.aspx".ToUpper(), 420) PaginaDict.Add("/Contabilidad/RepAnexoCatalogoMensualHorizontal.aspx".ToUpper(), -1) PaginaDict.Add("/Contabilidad/CatBloqueoDiario.aspx".ToUpper(), 680) - PaginaDict.Add("/Contabilidad/LibroMayor2.aspx".ToUpper(), -1) + PaginaDict.Add("/Contabilidad/LibroMayor2.aspx".ToUpper(), 1353) #End Region diff --git a/Compras/Compras.aspx.vb b/Compras/Compras.aspx.vb index ef2a680a3..6f1b1b0c9 100644 --- a/Compras/Compras.aspx.vb +++ b/Compras/Compras.aspx.vb @@ -21252,8 +21252,8 @@ Partial Class Compras_Compras Return True Else - Dim TmpImporteRNC As Decimal = If(AjusteProntoPagoPorcentajeIVA > 0, (ImporteRNC * AjusteProntoPagoPorcentajeIVA), ImporteRNC) - Dim TmpImporteRNCProntoPago As Decimal = If(AjusteProntoPagoPorcentajeIVA > 0, (TmpImporteRNCProntoPago * AjusteProntoPagoPorcentajeIVA), ImporteRNCProntoPago) + Dim TmpImporteRNC As Decimal = If(AjusteProntoPagoPorcentajeIVA > 0, ImporteRNC + (ImporteRNC * AjusteProntoPagoPorcentajeIVA), ImporteRNC) + Dim TmpImporteRNCProntoPago As Decimal = If(AjusteProntoPagoPorcentajeIVA > 0, ImporteRNCProntoPago + (ImporteRNCProntoPago * AjusteProntoPagoPorcentajeIVA), ImporteRNCProntoPago) Dim StrMsg As String = $"Existe una diferencia de ${(TmpImporteRNC + TmpImporteRNCProntoPago).ToString("###,###,###.00")} entre la compra y la Orden de Compra.
Se generaran Remisiones de Nota de Crédito.
- Descuento de ${TmpImporteRNC.ToString("###,###,###.00")}.
" If TmpImporteRNCProntoPago > 0 Then diff --git a/Contabilidad/LibroMayor2.aspx b/Contabilidad/LibroMayor2.aspx index c4947c6c0..176e9ab44 100644 --- a/Contabilidad/LibroMayor2.aspx +++ b/Contabilidad/LibroMayor2.aspx @@ -25,15 +25,15 @@
  • - Generar EXCEL + Generar EXCEL
  • - Imprimir + Imprimir
  • - Movimientos Auxiliares del Catálogo + Libro Mayor @@ -97,10 +97,10 @@
    >
    -
    +
    Tipo Movto
    -
    +
    @@ -109,7 +109,7 @@
    -
    +
    Tipo
    diff --git a/Contabilidad/LibroMayor2.aspx.vb b/Contabilidad/LibroMayor2.aspx.vb index 28c1021e5..800fb365f 100644 --- a/Contabilidad/LibroMayor2.aspx.vb +++ b/Contabilidad/LibroMayor2.aspx.vb @@ -212,7 +212,7 @@ Partial Class Conta_LibroMayor2 Cuenta = DdlCuentas.SelectedItem.ToString Dim ObjConta As New ClsContabilidad - If ObjConta.GetMovimientosAuxiliaresCatalogo(DdlCuentas.SelectedValue.ToEntero, FechaInicio, FechaFin, -1, CveProyecto, CveSubProyecto, UsuarioActual.CveEmpresa, TipoReporte, DdlOpcionCuentas.SelectedValue.ToEntero) Then + If ObjConta.GetLibroMayor2(DdlCuentas.SelectedValue.ToEntero, FechaInicio, FechaFin, -1, CveProyecto, CveSubProyecto, UsuarioActual.CveEmpresa, TipoReporte, DdlOpcionCuentas.SelectedValue.ToEntero) Then DtDatos = ObjConta.DtResultados DtTotales = DtDatos.Clone diff --git a/Contabilidad/RepBalanzaComprobacion.aspx b/Contabilidad/RepBalanzaComprobacion.aspx index 5cd0c879a..703e6c717 100644 --- a/Contabilidad/RepBalanzaComprobacion.aspx +++ b/Contabilidad/RepBalanzaComprobacion.aspx @@ -10,6 +10,9 @@ Imprimir <%--  --%> +
  • + Imprimir por Sub Proyecto +
  • diff --git a/Contabilidad/RepBalanzaComprobacion.aspx.vb b/Contabilidad/RepBalanzaComprobacion.aspx.vb index 96760e3c7..d8ca1cafc 100644 --- a/Contabilidad/RepBalanzaComprobacion.aspx.vb +++ b/Contabilidad/RepBalanzaComprobacion.aspx.vb @@ -5,6 +5,12 @@ Imports System Imports System.Data Imports Extensiones Imports Microsoft.Reporting.WebForms +Imports ClosedXML.Excel +Imports Profact.TimbraCFDI40 +Imports System.IO +Imports System.Drawing + + Partial Class Contabilidad2_RepBalanzaComprobacion Inherits ClsPaginas @@ -105,6 +111,10 @@ Partial Class Contabilidad2_RepBalanzaComprobacion End If CargarCentrosDeCosto(DdlProyecto, DdlSubproyecto, LblProyecto, LblSubProyecto) + If UsuarioActual.CveRol = 1 Then + BtnImprimirPoSubProyecto.Visible = True + End If + End If End Sub @@ -254,4 +264,238 @@ Partial Class Contabilidad2_RepBalanzaComprobacion ImprimirPDF(reportpath, DtDatos, params, fileName, Formato) End Sub + + Protected Sub BtnImprimirPoSubProyecto_Click(sender As Object, e As EventArgs) + + Dim WBAnexoBalanza = New ClosedXML.Excel.XLWorkbook + Dim TipoReporte = DdlTipoReporte.SelectedValue.ToEntero + + FechaInicio = If(TxtFechaDel.Text = "" Or TxtFechaDel.Text = "__/__/____", NowADS(), TxtFechaDel.Text.ToDate) + FechaFin = If(TxtFechaAl.Text = "" Or TxtFechaAl.Text = "__/__/____", NowADS(), TxtFechaAl.Text.ToDate) + + Dim SPCounter As Integer = 1 + For Each drSP As DataRow In GlobalDTSubProyectos(UsuarioActual.CveEmpresa).Rows + + Dim ObjConta As New ClsContabilidad + If ObjConta.GetBalanzaComprobacion(FechaInicio, FechaFin, 2, TipoReporte, -1, drSP("CveSubProyecto").ToString.ToEntero, UsuarioActual.CveEmpresa, DdlVista.SelectedValue.ToEntero, DdlNivel.SelectedValue.ToEntero) Then + DtDatos = ObjConta.DtResultados + Else + DtDatos = Nothing + Alert("Ocurrio un error al cargar los datos del Anexo del Catálogo", TipoMensaje.MsgError) + Exit For + End If + ObjConta.Dispose() + + If DtDatos.Rows.Count > 0 Then + WBAnexoBalanza.AddWorksheet(WSDocumento(drSP("SubProyecto").ToString, DtDatos)) + Dim spNombre As String = drSP("SubProyecto").ToString().Replace(":", "_").Replace("/", "_").Replace("\", "_").Replace("?", "_").Replace("*", "_").Replace("[", "_").Replace("]", "_") + WBAnexoBalanza.Worksheet(SPCounter).Name = $"{SPCounter}_{spNombre}" + SPCounter = SPCounter + 1 + + End If + + + Next + + Dim msB = New MemoryStream() + WBAnexoBalanza.SaveAs(msB) + + Dim BB As Byte() = msB.ToArray + msB.Dispose() + + Response.Clear() + Response.Buffer = True + Response.AddHeader("content-disposition", "attachment; filename=Balanza_" & Now.ToString("yyyyMMddhhmmss") & ".xlsx") + Response.ContentType = "application/vnd.ms-excel" + Response.BinaryWrite(BB) + Response.End() + + End Sub + + + Function WSDocumento(SubProyecto As String, DtDatos As DataTable) As IXLWorksheet + + + Dim WBAnexoSalvar = New ClosedXML.Excel.XLWorkbook + Dim WBReporte = New ClosedXML.Excel.XLWorkbook() + WBReporte.Worksheets.Add("1") + + Dim WSReporte = WBReporte.Worksheet(1) + + Dim RutaLogo As String = String.Format("{0}Logo.png", UsuarioActual.Empresa.Ruta) + If File.Exists(RutaLogo) Then + + Dim imagePath As String = RutaLogo + Dim img As Bitmap = New Bitmap(imagePath) + Dim picture = WSReporte.AddPicture(img).MoveTo(WSReporte.Cell("A1")) + picture.Scale(0.5) + + End If + + Dim Tamaniofuente As Integer = 13 + Dim Range = WSReporte.Range("A1:D1") + + WSReporte.Style.Font.FontSize = 10 + WSReporte.Style.Font.FontName = "Arial Narrow" + + WSReporte.Style.Alignment.WrapText = True + + Range.Merge().Style.Font.SetBold().Font.FontSize = Tamaniofuente + + WSReporte.Range("A1:F1").Merge().Style.Font.SetBold().Font.FontSize = Tamaniofuente + WSReporte.Range("A2:F2").Merge().Style.Font.SetBold().Font.FontSize = Tamaniofuente + WSReporte.Range("A3:F3").Merge().Style.Font.SetBold().Font.FontSize = Tamaniofuente + WSReporte.Range("A4:F4").Merge().Style.Font.SetBold().Font.FontSize = Tamaniofuente + WSReporte.Range("A5:F5").Merge().Style.Font.SetBold().Font.FontSize = Tamaniofuente + + WSReporte.Range("A1:A5").Style.Alignment.SetHorizontal(XLAlignmentHorizontalValues.Center) + + WSReporte.Column(1).Width = 15 + WSReporte.Column(2).Width = 35 + WSReporte.Column(3).Width = 14 + WSReporte.Column(4).Width = 14 + WSReporte.Column(5).Width = 14 + WSReporte.Column(6).Width = 14 + WSReporte.Column(7).Width = 14 + + WSReporte.Cell(1, 1).Value = UsuarioActual.Empresa.Empresa + WSReporte.Cell(2, 1).Value = $"Balanza de Comprobación del {TxtFechaDel.Text} al {TxtFechaAl.Text}" + + WSReporte.Cell(5, 1).Value = $"Sub Proyecto: {SubProyecto}" + WSReporte.Cell(5, 1).Style.Alignment.Horizontal = XLAlignmentHorizontalValues.Left + WSReporte.Cell(5, 1).Style.Font.Bold = True + + WSReporte.Cell(6, 1).Value = "Cuenta" + WSReporte.Cell(6, 2).Value = "Nombre" + WSReporte.Cell(6, 1).Style.Alignment.Vertical = XLAlignmentVerticalValues.Center + WSReporte.Cell(6, 2).Style.Alignment.Vertical = XLAlignmentVerticalValues.Center + + WSReporte.Cell(6, 3).Value = $"Saldos Iniciales{vbCrLf}Deudor Acreedor" + WSReporte.Cell(6, 4).Value = $"Cargos" + WSReporte.Cell(6, 5).Value = $"Abonos" + WSReporte.Cell(6, 6).Value = $"Saldo Actuales{vbCrLf} Deudor Acreedo" + + WSReporte.Range("A6:F6").Style.Font.Bold = True + WSReporte.Range("A6:F6").Style.Font.FontSize = 10 + WSReporte.Range("A6:F6").Style.Alignment.SetHorizontal(XLAlignmentHorizontalValues.Center) + WSReporte.Range("A6:F6").Style.Border.TopBorder = ClosedXML.Excel.XLBorderStyleValues.Medium + WSReporte.Range("A6:F6").Style.Border.BottomBorder = ClosedXML.Excel.XLBorderStyleValues.Medium + WSReporte.Range("A6:F6").Style.Border.RightBorder = ClosedXML.Excel.XLBorderStyleValues.Medium + + Dim CuerrentRow As Integer = 7 + + CuerrentRow = CuerrentRow + 1 + + For Each Drow As DataRow In DtDatos.Rows + + WSReporte.Cell(CuerrentRow, 1).Value = Drow("Codigo").ToString + WSReporte.Cell(CuerrentRow, 2).Value = Drow("Nombre").ToString + WSReporte.Cell(CuerrentRow, 3).Value = Drow("SaldoInicial").ToString + WSReporte.Cell(CuerrentRow, 4).Value = Drow("Cargos").ToString + WSReporte.Cell(CuerrentRow, 5).Value = Drow("Abonos").ToString + WSReporte.Cell(CuerrentRow, 6).Value = Drow("SaldoActual").ToString + + If Drow("CtaMayor").ToString.ToEntero.Contiene(1) Then + + WSReporte.Cell(CuerrentRow, 1).Style.Font.Bold = True + WSReporte.Cell(CuerrentRow, 2).Style.Font.Bold = True + WSReporte.Cell(CuerrentRow, 3).Style.Font.Bold = True + WSReporte.Cell(CuerrentRow, 4).Style.Font.Bold = True + WSReporte.Cell(CuerrentRow, 5).Style.Font.Bold = True + WSReporte.Cell(CuerrentRow, 6).Style.Font.Bold = True + + If Drow("CtaMayor").ToString.ToEntero.Contiene(1) Then + WSReporte.Cell(CuerrentRow, 1).Style.Alignment.Indent = 1 + WSReporte.Cell(CuerrentRow, 1).Style.Font.Italic = True + End If + + Else + WSReporte.Cell(CuerrentRow, 1).Style.Alignment.WrapText = True + WSReporte.Cell(CuerrentRow, 1).Style.Alignment.Indent = 2 + End If + + WSReporte.Cell(CuerrentRow, 2).Style.NumberFormat.Format = "#,##0.00; [Black] - #,##0.00 ;""-""" + WSReporte.Cell(CuerrentRow, 3).Style.NumberFormat.Format = "#,##0.00; [Black] - #,##0.00 ;""-""" + WSReporte.Cell(CuerrentRow, 4).Style.NumberFormat.Format = "#,##0.00; [Black] - #,##0.00 ;""-""" + WSReporte.Cell(CuerrentRow, 5).Style.NumberFormat.Format = "#,##0.00; [Black] - #,##0.00 ;""-""" + WSReporte.Cell(CuerrentRow, 6).Style.NumberFormat.Format = "#,##0.00; [Black] - #,##0.00 ;""-""" + + CuerrentRow = CuerrentRow + 1 + Next + + + For xy As Integer = 6 To CuerrentRow + WSReporte.Cell(xy, 6).Style.Border.RightBorder = ClosedXML.Excel.XLBorderStyleValues.Medium + WSReporte.Cell(xy, 1).Style.Border.LeftBorder = ClosedXML.Excel.XLBorderStyleValues.Medium + Next + + CuerrentRow = CuerrentRow + 1 + + WSReporte.Cell(CuerrentRow, 1).Style.Alignment.Vertical = XLAlignmentVerticalValues.Center + WSReporte.Cell(CuerrentRow, 2).Style.Alignment.Vertical = XLAlignmentVerticalValues.Center + + WSReporte.Cell(CuerrentRow, 3).Value = $"Saldos Iniciales{vbCrLf}Deudor Acreedor" + WSReporte.Cell(CuerrentRow, 4).Value = $"Cargos" + WSReporte.Cell(CuerrentRow, 5).Value = $"Abonos" + WSReporte.Cell(CuerrentRow, 6).Value = $"Saldo Actuales{vbCrLf} Deudor Acreedo" + + WSReporte.Cell(CuerrentRow, 1).Style.Border.BottomBorder = ClosedXML.Excel.XLBorderStyleValues.Medium + WSReporte.Cell(CuerrentRow, 2).Style.Border.BottomBorder = ClosedXML.Excel.XLBorderStyleValues.Medium + WSReporte.Cell(CuerrentRow, 3).Style.Border.BottomBorder = ClosedXML.Excel.XLBorderStyleValues.Medium + WSReporte.Cell(CuerrentRow, 4).Style.Border.BottomBorder = ClosedXML.Excel.XLBorderStyleValues.Medium + WSReporte.Cell(CuerrentRow, 5).Style.Border.BottomBorder = ClosedXML.Excel.XLBorderStyleValues.Medium + WSReporte.Cell(CuerrentRow, 6).Style.Border.BottomBorder = ClosedXML.Excel.XLBorderStyleValues.Medium + WSReporte.Range($"A{CuerrentRow}:F{CuerrentRow}").Style.Font.Bold = True + WSReporte.Range($"A{CuerrentRow}:F{CuerrentRow}").Style.Font.FontSize = 10 + WSReporte.Range($"A{CuerrentRow}:F{CuerrentRow}").Style.Alignment.SetHorizontal(XLAlignmentHorizontalValues.Center) + WSReporte.Range($"A{CuerrentRow}:F{CuerrentRow}").Style.Border.TopBorder = ClosedXML.Excel.XLBorderStyleValues.Medium + WSReporte.Range($"A{CuerrentRow}:F{CuerrentRow}").Style.Border.BottomBorder = ClosedXML.Excel.XLBorderStyleValues.Medium + WSReporte.Range($"A{CuerrentRow}:F{CuerrentRow}").Style.Border.RightBorder = ClosedXML.Excel.XLBorderStyleValues.Medium + + CuerrentRow = CuerrentRow + 1 + + Dim ultimaFila As DataRow = DtDatos.Rows(DtDatos.Rows.Count - 1) + + Dim LastSaldoID As Decimal = ultimaFila("SaldoID").ToString.ToDecimal + Dim LastTotalAbonos As Decimal = ultimaFila("TotalAbonos").ToString.ToDecimal + Dim LastTotalCargos As Decimal = ultimaFila("TotalCargos").ToString.ToDecimal + Dim LastSaldoAD As Decimal = ultimaFila("SaldoAD").ToString.ToDecimal + Dim LastSaldoIA As Decimal = ultimaFila("SaldoIA").ToString.ToDecimal + Dim LastSaldoAA As Decimal = ultimaFila("SaldoAA").ToString.ToDecimal + + WSReporte.Cell(CuerrentRow, 2).Value = "Sumas Iguales" + WSReporte.Cell(CuerrentRow, 3).Value = LastSaldoID + WSReporte.Cell(CuerrentRow, 4).Value = LastTotalCargos + WSReporte.Cell(CuerrentRow, 5).Value = LastTotalAbonos + WSReporte.Cell(CuerrentRow, 6).Value = LastSaldoAD + + WSReporte.Cell(CuerrentRow, 3).Style.NumberFormat.Format = "#,##0.00; [Black] - #,##0.00 ;""-""" + WSReporte.Cell(CuerrentRow, 4).Style.NumberFormat.Format = "#,##0.00; [Black] - #,##0.00 ;""-""" + WSReporte.Cell(CuerrentRow, 5).Style.NumberFormat.Format = "#,##0.00; [Black] - #,##0.00 ;""-""" + WSReporte.Cell(CuerrentRow, 6).Style.NumberFormat.Format = "#,##0.00; [Black] - #,##0.00 ;""-""" + + + CuerrentRow = CuerrentRow + 1 + + WSReporte.Cell(CuerrentRow, 3).Value = LastSaldoIA + WSReporte.Cell(CuerrentRow, 6).Value = LastSaldoAA + + + WSReporte.Cell(CuerrentRow, 3).Style.NumberFormat.Format = "#,##0.00; [Black] - #,##0.00 ;""-""" + WSReporte.Cell(CuerrentRow, 6).Style.NumberFormat.Format = "#,##0.00; [Black] - #,##0.00 ;""-""" + + WSReporte.Range($"B{CuerrentRow}:F{CuerrentRow}").Style.Border.BottomBorder = ClosedXML.Excel.XLBorderStyleValues.Medium + + WSReporte.PageSetup.PrintAreas.Add($"A1:G{CuerrentRow + 0 + 1}") + WSReporte.PageSetup.Margins.Top = 0.3 + WSReporte.PageSetup.Margins.Left = 0.8 + WSReporte.PageSetup.Margins.Right = 0.8 + WSReporte.PageSetup.FitToPages(1, 1) + + WBReporte.Worksheet(1).CopyTo(WBAnexoSalvar, "SubProyecto") + + Return WBReporte.Worksheet(1) + + End Function + End Class diff --git a/Inventarios/EntregaAlmacen.aspx.vb b/Inventarios/EntregaAlmacen.aspx.vb index 1bdf0cc2f..54b9f9400 100644 --- a/Inventarios/EntregaAlmacen.aspx.vb +++ b/Inventarios/EntregaAlmacen.aspx.vb @@ -1,20 +1,20 @@ -Option Strict On -Option Explicit On - -Imports System.Data +Option Strict On +Option Explicit On + +Imports System.Data Imports System.Data.SqlClient -Imports System.IO -Imports System.Web.Management -Imports DocumentFormat.OpenXml.InkML +Imports System.IO +Imports System.Web.Management +Imports DocumentFormat.OpenXml.InkML Imports Extensiones -Imports Microsoft.Reporting.WebForms -Imports MoreLinq -Imports Telerik.Web.UI - -Partial Class Inventarios_EntregaAlmacen +Imports Microsoft.Reporting.WebForms +Imports MoreLinq +Imports Telerik.Web.UI + +Partial Class Inventarios_EntregaAlmacen Inherits ClsPaginas -#Region "PROPIEDADES" +#Region "PROPIEDADES" 'Private Property CveVentaAD As Integer ' Get ' Return CType(ViewState("CveVentaAD"), Integer) @@ -23,326 +23,326 @@ Partial Class Inventarios_EntregaAlmacen ' ViewState("CveVentaAD") = 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 - Private Property DtDatosDetalle As DataTable - Get - Return CType(ViewState("DtDatosDetalle"), DataTable) - End Get - Set(value As DataTable) - ViewState("DtDatosDetalle") = value - End Set - End Property - Private Property DtDatosSugerencias As DataTable - Get - Return CType(ViewState("DtDatosSugerencias"), DataTable) - End Get - Set(value As DataTable) - ViewState("DtDatosSugerencias") = value - End Set - End Property - Private Property DtDatosDetalleLote As DataTable - Get - Return CType(ViewState("DtDatosDetalleLote"), DataTable) - End Get - Set(value As DataTable) - ViewState("DtDatosDetalleLote") = value - End Set - End Property - Private Property PSSerie As String - Get - Return CType(ViewState("PSSerie"), String) - End Get - Set(value As String) - ViewState("PSSerie") = value - End Set - End Property - Private Property CveConsecSerie As Integer - Get - Return CType(ViewState("CveConsecSerie"), Integer) - End Get - Set(value As Integer) - ViewState("CveConsecSerie") = value - End Set - End Property - Private Property CvePSSerie As Integer - Get - Return CType(ViewState("CvePSSerie"), Integer) - End Get - Set(value As Integer) - ViewState("CvePSSerie") = value - End Set - End Property - Private Property CveUMSerie As Integer - Get - Return CType(ViewState("CveUMSerie"), Integer) - End Get - Set(value As Integer) - ViewState("CveUMSerie") = value - End Set - End Property - Private Property EsInterno As Boolean - Get - Return CBool(If(ViewState("EsInterno") Is Nothing, 0, ViewState("EsInterno"))) - End Get - Set(value As Boolean) - ViewState("EsInterno") = value - End Set - End Property - Private Property CveMetodoInventario As Integer - Get - Return CType(ViewState("CveMetodoInventario"), Integer) - End Get - Set(value As Integer) - ViewState("CveMetodoInventario") = value - End Set - End Property - Private Property CveVentaSurtir As Integer - Get - Return CType(ViewState("CveVentaSurtir"), Integer) - End Get - Set(value As Integer) - ViewState("CveVentaSurtir") = value - End Set + Private Property DtDatos As DataTable + Get + Return CType(ViewState("DtDatos"), DataTable) + End Get + Set(value As DataTable) + ViewState("DtDatos") = value + End Set + End Property + Private Property DtDatosDetalle As DataTable + Get + Return CType(ViewState("DtDatosDetalle"), DataTable) + End Get + Set(value As DataTable) + ViewState("DtDatosDetalle") = value + End Set + End Property + Private Property DtDatosSugerencias As DataTable + Get + Return CType(ViewState("DtDatosSugerencias"), DataTable) + End Get + Set(value As DataTable) + ViewState("DtDatosSugerencias") = value + End Set + End Property + Private Property DtDatosDetalleLote As DataTable + Get + Return CType(ViewState("DtDatosDetalleLote"), DataTable) + End Get + Set(value As DataTable) + ViewState("DtDatosDetalleLote") = value + End Set + End Property + Private Property PSSerie As String + Get + Return CType(ViewState("PSSerie"), String) + End Get + Set(value As String) + ViewState("PSSerie") = value + End Set + End Property + Private Property CveConsecSerie As Integer + Get + Return CType(ViewState("CveConsecSerie"), Integer) + End Get + Set(value As Integer) + ViewState("CveConsecSerie") = value + End Set + End Property + Private Property CvePSSerie As Integer + Get + Return CType(ViewState("CvePSSerie"), Integer) + End Get + Set(value As Integer) + ViewState("CvePSSerie") = value + End Set + End Property + Private Property CveUMSerie As Integer + Get + Return CType(ViewState("CveUMSerie"), Integer) + End Get + Set(value As Integer) + ViewState("CveUMSerie") = value + End Set + End Property + Private Property EsInterno As Boolean + Get + Return CBool(If(ViewState("EsInterno") Is Nothing, 0, ViewState("EsInterno"))) + End Get + Set(value As Boolean) + ViewState("EsInterno") = value + End Set + End Property + Private Property CveMetodoInventario As Integer + Get + Return CType(ViewState("CveMetodoInventario"), Integer) + End Get + Set(value As Integer) + ViewState("CveMetodoInventario") = value + End Set + End Property + Private Property CveVentaSurtir As Integer + Get + Return CType(ViewState("CveVentaSurtir"), Integer) + End Get + Set(value As Integer) + ViewState("CveVentaSurtir") = value + End Set End Property - Private Property CveOSSurtir As Integer - Get - Return CType(ViewState("CveOSSurtir"), Integer) - End Get - Set(value As Integer) - ViewState("CveOSSurtir") = value - End Set + Private Property CveOSSurtir As Integer + Get + Return CType(ViewState("CveOSSurtir"), Integer) + End Get + Set(value As Integer) + ViewState("CveOSSurtir") = value + End Set End Property - Private Property CveTipoVenta As Integer - Get + Private Property CveTipoVenta As Integer + Get If ViewState("CveTipoVenta") Is Nothing Then ViewState("CveTipoVenta") = -1 - End If - Return CType(ViewState("CveTipoVenta"), Integer) - End Get - Set(value As Integer) - ViewState("CveTipoVenta") = value - End Set + End If + Return CType(ViewState("CveTipoVenta"), Integer) + End Get + Set(value As Integer) + ViewState("CveTipoVenta") = value + End Set End Property - Private Property TipoEstatus As Integer - Get - Return CType(ViewState("TipoEstatus"), Integer) - End Get - Set(value As Integer) - ViewState("TipoEstatus") = value - End Set - End Property - Private Property CveContrato As Integer - Get - Return CType(ViewState("CveContrato"), Integer) - End Get - Set(value As Integer) - ViewState("CveContrato") = value - End Set - End Property - Private Property CveAlmacenTraspasoOrigen As Integer - Get - Return CType(ViewState("CveAlmacenTraspasoOrigen"), Integer) - End Get - Set(value As Integer) - ViewState("CveAlmacenTraspasoOrigen") = value - End Set - End Property - Private Property CveAlmacenTraspasoDestino As Integer - Get - Return CType(ViewState("CveAlmacenTraspasoDestino"), Integer) - End Get - Set(value As Integer) - ViewState("CveAlmacenTraspasoDestino") = value - End Set - End Property - Private Property TipoMovimiento As Integer - Get - Return CType(ViewState("TipoMovimiento"), Integer) - End Get - Set(value As Integer) - ViewState("TipoMovimiento") = value - End Set - End Property - Private Property TipoDocto As String - Get - Return CType(ViewState("TipoDocto"), String) - End Get - Set(value As String) - ViewState("TipoDocto") = value - End Set - End Property - Private Property DtExistencias As DataTable - Get - Return CType(ViewState("DtExistencias"), DataTable) - End Get - Set(value As DataTable) - ViewState("DtExistencias") = value - End Set - End Property - Private Property RowIndexCantidadEspecial As Integer - Get - Return CType(ViewState("RowIndexCantidadEspecial"), Integer) - End Get - Set(value As Integer) - ViewState("RowIndexCantidadEspecial") = value - End Set - End Property - Private Property CantidadEspecialTemp As Decimal - Get - Return CType(ViewState("CantidadEspecialTemp"), Decimal) - End Get - Set(value As Decimal) - ViewState("CantidadEspecialTemp") = value - End Set - End Property - Private Property EsDevolucionVenta As Integer - Get - Return CType(ViewState("EsDevolucionVenta"), Integer) - End Get - Set(value As Integer) - ViewState("EsDevolucionVenta") = value - End Set - End Property - Private Property CveVendedor As Integer - Get - Return CType(ViewState("CveVendedor"), Integer) - End Get - Set(value As Integer) - ViewState("CveVendedor") = value - End Set - End Property - Private Property CveSubProyecto As Integer - Get - Return CType(ViewState("CveSubProyecto"), Integer) - End Get - Set(value As Integer) - ViewState("CveSubProyecto") = value - End Set - End Property - Private Property CveOP As Integer - Get - Return CType(ViewState("CveOP"), Integer) - End Get - Set(value As Integer) - ViewState("CveOP") = value - End Set - End Property - Private Property CveCliente As Integer - Get - Return CType(ViewState("CveCliente"), Integer) - End Get - Set(value As Integer) - ViewState("CveCliente") = value - End Set - End Property - Private Property CveDireccionEnvio As Integer - Get - Return CType(ViewState("CveDireccionEnvio"), Integer) - End Get - Set(value As Integer) - ViewState("CveDireccionEnvio") = value - End Set - End Property - Private Property CveMovimiento As Integer - Get - Return CType(ViewState("CveMovimiento"), Integer) - End Get - Set(value As Integer) - ViewState("CveMovimiento") = value - End Set - End Property - Private Property CveTraspasoSurtir As Integer - Get - Return CType(ViewState("CveTraspasoSurtir"), Integer) - End Get - Set(value As Integer) - ViewState("CveTraspasoSurtir") = value - End Set - End Property - Private Property TipoEntrega As Integer - Get - Return CType(ViewState("TipoEntrega"), Integer) - End Get - Set(value As Integer) - ViewState("TipoEntrega") = value - End Set - End Property - - Private Property EsDevolucionDirecta As Boolean - Get - Return CBool(If(ViewState("EsDevolucionDirecta") Is Nothing, 0, ViewState("EsDevolucionDirecta"))) - End Get - Set(value As Boolean) - ViewState("EsDevolucionDirecta") = value - End Set - End Property - Private Property FormaPaqueteria As Integer - Get - Return CType(ViewState("FormaPaqueteria"), Integer) - End Get - Set(value As Integer) - ViewState("FormaPaqueteria") = value - End Set - End Property - 'Private Property IndexSeccionAlmacen As Integer - ' Get - ' Return CType(ViewState("IndexSeccionAlmacen"), Integer) - ' End Get - ' Set(value As Integer) - ' ViewState("IndexSeccionAlmacen") = value - ' End Set - 'End Property - Private Property ArchivoBitacora As String - Get - Return CType(ViewState("ArchivoBitacora"), String) - End Get - Set(value As String) - ViewState("ArchivoBitacora") = value - End Set - End Property - Private Property ArchivoBitacoraDetalle As String - Get - Return CType(ViewState("ArchivoBitacoraDetalle"), String) - End Get - Set(value As String) - ViewState("ArchivoBitacoraDetalle") = value - End Set - End Property - - Private Property CargaBitacora As Boolean - Get - If ViewState("CargaBitacora") Is Nothing Then - ViewState("CargaBitacora") = False - End If - Return Boolean.Parse(ViewState("CargaBitacora").ToString) - End Get - Set(value As Boolean) - ViewState("CargaBitacora") = value - End Set + Private Property TipoEstatus As Integer + Get + Return CType(ViewState("TipoEstatus"), Integer) + End Get + Set(value As Integer) + ViewState("TipoEstatus") = value + End Set + End Property + Private Property CveContrato As Integer + Get + Return CType(ViewState("CveContrato"), Integer) + End Get + Set(value As Integer) + ViewState("CveContrato") = value + End Set + End Property + Private Property CveAlmacenTraspasoOrigen As Integer + Get + Return CType(ViewState("CveAlmacenTraspasoOrigen"), Integer) + End Get + Set(value As Integer) + ViewState("CveAlmacenTraspasoOrigen") = value + End Set + End Property + Private Property CveAlmacenTraspasoDestino As Integer + Get + Return CType(ViewState("CveAlmacenTraspasoDestino"), Integer) + End Get + Set(value As Integer) + ViewState("CveAlmacenTraspasoDestino") = value + End Set + End Property + Private Property TipoMovimiento As Integer + Get + Return CType(ViewState("TipoMovimiento"), Integer) + End Get + Set(value As Integer) + ViewState("TipoMovimiento") = value + End Set + End Property + Private Property TipoDocto As String + Get + Return CType(ViewState("TipoDocto"), String) + End Get + Set(value As String) + ViewState("TipoDocto") = value + End Set + End Property + Private Property DtExistencias As DataTable + Get + Return CType(ViewState("DtExistencias"), DataTable) + End Get + Set(value As DataTable) + ViewState("DtExistencias") = value + End Set + End Property + Private Property RowIndexCantidadEspecial As Integer + Get + Return CType(ViewState("RowIndexCantidadEspecial"), Integer) + End Get + Set(value As Integer) + ViewState("RowIndexCantidadEspecial") = value + End Set + End Property + Private Property CantidadEspecialTemp As Decimal + Get + Return CType(ViewState("CantidadEspecialTemp"), Decimal) + End Get + Set(value As Decimal) + ViewState("CantidadEspecialTemp") = value + End Set + End Property + Private Property EsDevolucionVenta As Integer + Get + Return CType(ViewState("EsDevolucionVenta"), Integer) + End Get + Set(value As Integer) + ViewState("EsDevolucionVenta") = value + End Set + End Property + Private Property CveVendedor As Integer + Get + Return CType(ViewState("CveVendedor"), Integer) + End Get + Set(value As Integer) + ViewState("CveVendedor") = value + End Set + End Property + Private Property CveSubProyecto As Integer + Get + Return CType(ViewState("CveSubProyecto"), Integer) + End Get + Set(value As Integer) + ViewState("CveSubProyecto") = value + End Set + End Property + Private Property CveOP As Integer + Get + Return CType(ViewState("CveOP"), Integer) + End Get + Set(value As Integer) + ViewState("CveOP") = value + End Set + End Property + Private Property CveCliente As Integer + Get + Return CType(ViewState("CveCliente"), Integer) + End Get + Set(value As Integer) + ViewState("CveCliente") = value + End Set + End Property + Private Property CveDireccionEnvio As Integer + Get + Return CType(ViewState("CveDireccionEnvio"), Integer) + End Get + Set(value As Integer) + ViewState("CveDireccionEnvio") = value + End Set + End Property + Private Property CveMovimiento As Integer + Get + Return CType(ViewState("CveMovimiento"), Integer) + End Get + Set(value As Integer) + ViewState("CveMovimiento") = value + End Set + End Property + Private Property CveTraspasoSurtir As Integer + Get + Return CType(ViewState("CveTraspasoSurtir"), Integer) + End Get + Set(value As Integer) + ViewState("CveTraspasoSurtir") = value + End Set + End Property + Private Property TipoEntrega As Integer + Get + Return CType(ViewState("TipoEntrega"), Integer) + End Get + Set(value As Integer) + ViewState("TipoEntrega") = value + End Set End Property - Private Property BloqueCantidad As Boolean - Get + Private Property EsDevolucionDirecta As Boolean + Get + Return CBool(If(ViewState("EsDevolucionDirecta") Is Nothing, 0, ViewState("EsDevolucionDirecta"))) + End Get + Set(value As Boolean) + ViewState("EsDevolucionDirecta") = value + End Set + End Property + Private Property FormaPaqueteria As Integer + Get + Return CType(ViewState("FormaPaqueteria"), Integer) + End Get + Set(value As Integer) + ViewState("FormaPaqueteria") = value + End Set + End Property + 'Private Property IndexSeccionAlmacen As Integer + ' Get + ' Return CType(ViewState("IndexSeccionAlmacen"), Integer) + ' End Get + ' Set(value As Integer) + ' ViewState("IndexSeccionAlmacen") = value + ' End Set + 'End Property + Private Property ArchivoBitacora As String + Get + Return CType(ViewState("ArchivoBitacora"), String) + End Get + Set(value As String) + ViewState("ArchivoBitacora") = value + End Set + End Property + Private Property ArchivoBitacoraDetalle As String + Get + Return CType(ViewState("ArchivoBitacoraDetalle"), String) + End Get + Set(value As String) + ViewState("ArchivoBitacoraDetalle") = value + End Set + End Property + + Private Property CargaBitacora As Boolean + Get + If ViewState("CargaBitacora") Is Nothing Then + ViewState("CargaBitacora") = False + End If + Return Boolean.Parse(ViewState("CargaBitacora").ToString) + End Get + Set(value As Boolean) + ViewState("CargaBitacora") = value + End Set + End Property + + Private Property BloqueCantidad As Boolean + Get If ViewState("BloqueCantidad") Is Nothing Then ViewState("BloqueCantidad") = False - End If - Return Boolean.Parse(ViewState("BloqueCantidad").ToString) - End Get - Set(value As Boolean) - ViewState("BloqueCantidad") = value - End Set + End If + Return Boolean.Parse(ViewState("BloqueCantidad").ToString) + End Get + Set(value As Boolean) + ViewState("BloqueCantidad") = value + End Set End Property Private Property Adjunto As String Get @@ -357,366 +357,366 @@ Partial Class Inventarios_EntregaAlmacen End Set End Property -#End Region +#End Region + + Protected Sub Page_Load(sender As Object, e As System.EventArgs) Handles Me.Load + If Not IsPostBack Then + + InicializaValores() + CargaParametrosAD() + If UsuarioActual.CveEmpresa.Contiene(1, 72, 80, 146, 119, 186) Then DdlAlmacen.AutoPostBack = True + + If UsuarioActual.Empresa.Funcionalidad(281).ToEntero() = 1 Then + TxtFecha.Enabled = False + ImgFecha.Visible = False + End If - Protected Sub Page_Load(sender As Object, e As System.EventArgs) Handles Me.Load - If Not IsPostBack Then - - InicializaValores() - CargaParametrosAD() - If UsuarioActual.CveEmpresa.Contiene(1, 72, 80, 146, 119, 186) Then DdlAlmacen.AutoPostBack = True - - If UsuarioActual.Empresa.Funcionalidad(281).ToEntero() = 1 Then - TxtFecha.Enabled = False - ImgFecha.Visible = False - End If - If UsuarioActual.Empresa.Funcionalidad(109) = "1" Then divUsuarioRegistra.Visible = True - End If - - End If + End If + + End If End Sub -#Region " INICIALIZA VALORES " - Private Sub InicializaValores() - TipoEstatus = -1 - CveVendedor = -1 - CveCliente = -1 - CveSubProyecto = -1 - - DtDatosSugerencias = New DataTable - - Dim StrAlmacenes As String = "CveTipoAlmacen IN (1,2)" - - If (UsuarioActual.Empresa.Funcionalidad(105) = "1" Or UsuarioActual.Empresa.Funcionalidad(141) = "1") Then - DdlClientes.setEsWebService(True) - DdlClientes.Attributes.Add("data-metodo", "getcliente") - DdlClientes.SelectedText = "Todos" - DdlClientes.SelectedValue = "-1" - Else - DdlClientes.setEsWebService(False) - DdlClientes.ddl.DataSource = GlobalDTCliente(UsuarioActual.CveEmpresa) - DdlClientes.ddl.DataBind() - DdlClientes.ddl.Items.Insert(0, New ListItem("Todos", "-1")) - End If - - - DdlAlmacen.DataSource = GlobalDTAlmacenUsuarios(UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa, -1).FiltraParametros(StrAlmacenes) 'GlobalDTAlmacen(UsuarioActual.CveEmpresa) - DdlAlmacen.Items.Insert(0, New ListItem(" Seleccione ", "-1")) - DdlAlmacen.SelectedValue = "-1" - DdlAlmacen.DataBind() - If UsuarioActual.CveAlmacen > 0 Then - DdlAlmacen.SelectedValueExist(UsuarioActual.CveAlmacen) - RecargaporAlmacenes() - End If - - DdlAlmacenTransitorio.DataSource = GlobalDTAlmacenUsuarios(UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa, 3) - DdlAlmacenTransitorio.DataBind() - DdlAlmacenTransitorio.Items.Insert(0, New ListItem("Seleccione", "-1")) - - DdlFolio.Items.Insert(0, New ListItem("Seleccione", "-1")) - +#Region " INICIALIZA VALORES " + Private Sub InicializaValores() + TipoEstatus = -1 + CveVendedor = -1 + CveCliente = -1 + CveSubProyecto = -1 + + DtDatosSugerencias = New DataTable + + Dim StrAlmacenes As String = "CveTipoAlmacen IN (1,2)" + + If (UsuarioActual.Empresa.Funcionalidad(105) = "1" Or UsuarioActual.Empresa.Funcionalidad(141) = "1") Then + DdlClientes.setEsWebService(True) + DdlClientes.Attributes.Add("data-metodo", "getcliente") + DdlClientes.SelectedText = "Todos" + DdlClientes.SelectedValue = "-1" + Else + DdlClientes.setEsWebService(False) + DdlClientes.ddl.DataSource = GlobalDTCliente(UsuarioActual.CveEmpresa) + DdlClientes.ddl.DataBind() + DdlClientes.ddl.Items.Insert(0, New ListItem("Todos", "-1")) + End If + + + DdlAlmacen.DataSource = GlobalDTAlmacenUsuarios(UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa, -1).FiltraParametros(StrAlmacenes) 'GlobalDTAlmacen(UsuarioActual.CveEmpresa) + DdlAlmacen.Items.Insert(0, New ListItem(" Seleccione ", "-1")) + DdlAlmacen.SelectedValue = "-1" + DdlAlmacen.DataBind() + If UsuarioActual.CveAlmacen > 0 Then + DdlAlmacen.SelectedValueExist(UsuarioActual.CveAlmacen) + RecargaporAlmacenes() + End If + + DdlAlmacenTransitorio.DataSource = GlobalDTAlmacenUsuarios(UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa, 3) + DdlAlmacenTransitorio.DataBind() + DdlAlmacenTransitorio.Items.Insert(0, New ListItem("Seleccione", "-1")) + + DdlFolio.Items.Insert(0, New ListItem("Seleccione", "-1")) + TxtFechaPendientes.Text = NowADS().ToShortDateString - TxtFecha.Text = NowADS().ToShortDateString - RVFecha.MaximumValue = MaxFecha.ToShortDateString + TxtFecha.Text = NowADS().ToShortDateString + RVFecha.MaximumValue = MaxFecha.ToShortDateString If UsuarioActual.CveEmpresa.Contiene(119) Then RVFecha.MinimumValue = NowADS().ToShortDateString CEFecha.StartDate = NowADS() trGuia.Visible = True Else - RVFecha.MinimumValue = MinFecha.ToShortDateString + RVFecha.MinimumValue = MinFecha.ToShortDateString End If - - If Not UsuarioActual.TienePermisoProceso(190) Then - 'CARGA SOLO LAS SUCURSALES DE LOS ALMCENES QUE TIENE ASIGNADO EL USUARIO - Dim ObjInventarios As New ClsInventarios - If ObjInventarios.GetSucursalesAlmacenUsuario(UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa) Then - DdlSubProyectos.DataSource = ObjInventarios.DtResultados - End If - ObjInventarios.Dispose() - Else - DdlSubProyectos.DataSource = GlobalDTSubProyectos(UsuarioActual.CveEmpresa) - End If - DdlSubProyectos.DataBind() - DdlSubProyectos.SelectedValueExist(UsuarioActual.CveSubProyecto.ToString()) - - If UsuarioActual.TienePermisoProceso(152) Then DdlSubProyectos.Enabled = False - If UsuarioActual.Empresa.Funcionalidad(280) = "1" Then PnlEntrega.Visible = True - - CreaDtDetalle() - CreaDtDetalleLote() - CargaPendientes() - LimpiaCampos() + + If Not UsuarioActual.TienePermisoProceso(190) Then + 'CARGA SOLO LAS SUCURSALES DE LOS ALMCENES QUE TIENE ASIGNADO EL USUARIO + Dim ObjInventarios As New ClsInventarios + If ObjInventarios.GetSucursalesAlmacenUsuario(UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa) Then + DdlSubProyectos.DataSource = ObjInventarios.DtResultados + End If + ObjInventarios.Dispose() + Else + DdlSubProyectos.DataSource = GlobalDTSubProyectos(UsuarioActual.CveEmpresa) + End If + DdlSubProyectos.DataBind() + DdlSubProyectos.SelectedValueExist(UsuarioActual.CveSubProyecto.ToString()) + + If UsuarioActual.TienePermisoProceso(152) Then DdlSubProyectos.Enabled = False + If UsuarioActual.Empresa.Funcionalidad(280) = "1" Then PnlEntrega.Visible = True + + CreaDtDetalle() + CreaDtDetalleLote() + CargaPendientes() + LimpiaCampos() End Sub -#End Region +#End Region -#Region " CARGA PARAMETROS - EXCLUSIVO USO AD " - Private Sub CargaParametrosAD() - - 'CveVentaAD = -1 - - 'If UsuarioActual.CveUsuario <> 100 Then - ' Exit Sub - 'End If - - If Not IsNothing(Request("CveVenta")) AndAlso IsNumeric(Request("CveVenta")) Then - 'CveVentaAD = Request("CveVenta").ToEntero() - CargaVentaPorSurtir(Request("CveVenta").ToEntero()) - 'LbSurtida.Visible = True - 'LbSurtida.Text = "SOLO MODO VISUAL" - 'BtnGuardar.Visible = False - End If - +#Region " CARGA PARAMETROS - EXCLUSIVO USO AD " + Private Sub CargaParametrosAD() + + 'CveVentaAD = -1 + + 'If UsuarioActual.CveUsuario <> 100 Then + ' Exit Sub + 'End If + + If Not IsNothing(Request("CveVenta")) AndAlso IsNumeric(Request("CveVenta")) Then + 'CveVentaAD = Request("CveVenta").ToEntero() + CargaVentaPorSurtir(Request("CveVenta").ToEntero()) + 'LbSurtida.Visible = True + 'LbSurtida.Text = "SOLO MODO VISUAL" + 'BtnGuardar.Visible = False + End If + End Sub -#End Region +#End Region -#Region " CARGA PENDIENTES POR SURTIR " - Protected Sub DdlCliente_SelectedIndexChanged(sender As Object, e As EventArgs) - CargaFolios() - End Sub - Private Sub CargaFolios() - Dim ObjInventarios As New ClsInventarios - - DdlFolio.Items.Clear() - - If DdlClientes.SelectedValue.ToEntero() > 0 Then - If ObjInventarios.VentasPendientesAlmacenGet(DdlClientes.SelectedValue.ToEntero(), MinFecha, DdlSubProyectos.SelectedValue.ToEntero(), UsuarioActual.CveEmpresa, UsuarioActual.CveUsuario) Then - DdlFolio.DataSource = ObjInventarios.DtResultados - Else - Alert("Ocurrió un error al obtener las Compras pendientes de recibir del proveedor. Por favor vuelva a intentar", TipoMensaje.MsgError) - End If - End If - - ObjInventarios.Dispose() - - DdlFolio.DataBind() - DdlFolio.Items.Insert(0, New ListItem("Seleccione", "-1")) - UpFiltros.Update() - End Sub - Protected Sub TimmerRefresh_Tick(sender As Object, e As EventArgs) - CargaPendientes() - End Sub - Protected Sub BtnConsultarPendientes_Click(sender As Object, e As EventArgs) - CargaPendientes() - End Sub - Private Sub CargaPendientes() - DivTipoCambioAdvertencia.Visible = False - - Dim ObjInventarios As New ClsInventarios - Dim DtPendientes As New DataTable - - If ObjInventarios.VentasPendientesAlmacenGet(-1, TxtFechaPendientes.Text.ToDate, DdlSubProyectos.SelectedValue.ToEntero(), UsuarioActual.CveEmpresa, UsuarioActual.CveUsuario) Then - - - If UsuarioActual.TienePermisoProceso(266) AndAlso UsuarioActual.TienePermisoProceso(267) Then - DtPendientes = ObjInventarios.DtResultados.FiltraParametros("TipoDocto IN ('Ing','Dev','Rem','Traspaso','Ped','PDev','DPe','Ant','RNC')") - ElseIf UsuarioActual.TienePermisoProceso(266) AndAlso Not UsuarioActual.TienePermisoProceso(267) Then - DtPendientes = ObjInventarios.DtResultados.FiltraParametros("TipoDocto IN ('Ing','Dev','Rem','Traspaso','Ant','RNC')") - ElseIf UsuarioActual.TienePermisoProceso(267) AndAlso Not UsuarioActual.TienePermisoProceso(266) Then - DtPendientes = ObjInventarios.DtResultados.FiltraParametros("TipoDocto IN ('Ped','PDev','DPe','RNC')") - Else - DtPendientes = ObjInventarios.DtResultados - End If - Else - DtPendientes = Nothing - Alert("Ocurrió un error al obtener las Compras pendientes de recibir del proveedor. Por favor vuelva a intentar", TipoMensaje.MsgError) - End If - - If UsuarioActual.Empresa.Funcionalidad(540) = "1" Then - BtnGuardar.Enabled = False - Dim FI As Date = NowADS().AddDays(-1) - Dim FF As Date = NowADS().AddDays(-7) - If ObjInventarios.RepNotasSinAlmacen(1, -1, FI, FF, "-1", -1, UsuarioActual.Empresa.CveEmpresa) Then - If ObjInventarios.DtResultados IsNot Nothing AndAlso ObjInventarios.DtResultados.Rows.Count > 1 Then - BtnGuardar.Enabled = False - Alert("No se podrá realizar entrega de mercancía si no se les da salida a los documentos pendientes. Para más información ver el Reporte de notas sin entrada en la sección Ventas.", TipoMensaje.MsgAdvertencia) - Else - BtnGuardar.Enabled = True - End If - End If - End If - ObjInventarios.Dispose() - - If DtPendientes IsNot Nothing Then - GVPendientes.DataSource = DtPendientes - End If - LtActualizado.Text = String.Format("Actualizado: {0}", NowADS().ToString("H:mm")) - - GVPendientes.DataBind() - UpPendientes.Update() - If DtPendientes IsNot Nothing Then DtPendientes.Dispose() - - End Sub - Protected Sub GVPendientes_RowDataBound(sender As Object, e As GridViewRowEventArgs) Handles GVPendientes.RowDataBound - If e.Row.RowType = DataControlRowType.DataRow Then - e.Row.FCLinkButton("BtnSurtir").CommandArgument = If(e.Row.DBCampo("TipoEntrega") = "1", e.Row.DBCampo("CveVenta"), e.Row.DBCampo("CveTraspasoSolicitud")) - - Select Case e.Row.DBCampo("TipoEntrega").ToString().ToEntero() - Case 1 - If UsuarioActual.TienePermisoProceso(201) Then - Dim Css As String = "Texto" - Dim Liga As String = $"/Ventas/Ventas.aspx?&CveVenta={e.Row.DBCampo("CveVenta")}" - e.Row.FCLabel("LblFolio").Text = "" + e.Row.FCLabel("LblFolio").Text + "" - End If - - If UsuarioActual.CveEmpresa.Contiene(72, 80) Then - GVPendientes.Columns(4).Visible = True - e.Row.FCHyperLink("HplDownPDF").Visible = True - e.Row.FCHyperLink("HplDownPDF").NavigateUrl = String.Format("/Compras/PopUpVerFactura.aspx?P={0}", Encripta(String.Format("OP=VTA&CVEVENTA={0}", e.Row.DBCampo("CveVenta")))) - End If - - If e.Row.DBCampo("TipoDocto").ToString().Contiene({"Rem", "Ing", "Ped", "PeC", "Ant"}) And e.Row.DBCampo("EsDevolucionVenta").ToString().ToEntero() = 0 Then - e.Row.FCLinkButton("BtnSurtir").CssClass = "btn btn-primary btn-sm" - e.Row.FCLinkButton("BtnSurtir").Text = " Surtir " - Else - e.Row.FCLinkButton("BtnSurtir").CssClass = "btn yellow-gold btn-sm" - e.Row.FCLinkButton("BtnSurtir").Text = " Recibir" - End If - Case 2 - Dim Css As String = "Texto" - Dim Liga As String = $"/Inventarios/TrasladoSolicitud.aspx?&CveTraspasoSolicitud={e.Row.DBCampo("CveTraspasoSolicitud")}" - e.Row.FCLabel("LblFolio").Text = "" + e.Row.FCLabel("LblFolio").Text + "" - e.Row.FCLinkButton("BtnSurtir").CssClass = "btn btn-primary btn-sm" - e.Row.FCLinkButton("BtnSurtir").Text = " Traspasar " - End Select - UpPendientes.Update() - End If +#Region " CARGA PENDIENTES POR SURTIR " + Protected Sub DdlCliente_SelectedIndexChanged(sender As Object, e As EventArgs) + CargaFolios() + End Sub + Private Sub CargaFolios() + Dim ObjInventarios As New ClsInventarios + + DdlFolio.Items.Clear() + + If DdlClientes.SelectedValue.ToEntero() > 0 Then + If ObjInventarios.VentasPendientesAlmacenGet(DdlClientes.SelectedValue.ToEntero(), MinFecha, DdlSubProyectos.SelectedValue.ToEntero(), UsuarioActual.CveEmpresa, UsuarioActual.CveUsuario) Then + DdlFolio.DataSource = ObjInventarios.DtResultados + Else + Alert("Ocurrió un error al obtener las Compras pendientes de recibir del proveedor. Por favor vuelva a intentar", TipoMensaje.MsgError) + End If + End If + + ObjInventarios.Dispose() + + DdlFolio.DataBind() + DdlFolio.Items.Insert(0, New ListItem("Seleccione", "-1")) + UpFiltros.Update() + End Sub + Protected Sub TimmerRefresh_Tick(sender As Object, e As EventArgs) + CargaPendientes() + End Sub + Protected Sub BtnConsultarPendientes_Click(sender As Object, e As EventArgs) + CargaPendientes() + End Sub + Private Sub CargaPendientes() + DivTipoCambioAdvertencia.Visible = False + + Dim ObjInventarios As New ClsInventarios + Dim DtPendientes As New DataTable + + If ObjInventarios.VentasPendientesAlmacenGet(-1, TxtFechaPendientes.Text.ToDate, DdlSubProyectos.SelectedValue.ToEntero(), UsuarioActual.CveEmpresa, UsuarioActual.CveUsuario) Then + + + If UsuarioActual.TienePermisoProceso(266) AndAlso UsuarioActual.TienePermisoProceso(267) Then + DtPendientes = ObjInventarios.DtResultados.FiltraParametros("TipoDocto IN ('Ing','Dev','Rem','Traspaso','Ped','PDev','DPe','Ant','RNC')") + ElseIf UsuarioActual.TienePermisoProceso(266) AndAlso Not UsuarioActual.TienePermisoProceso(267) Then + DtPendientes = ObjInventarios.DtResultados.FiltraParametros("TipoDocto IN ('Ing','Dev','Rem','Traspaso','Ant','RNC')") + ElseIf UsuarioActual.TienePermisoProceso(267) AndAlso Not UsuarioActual.TienePermisoProceso(266) Then + DtPendientes = ObjInventarios.DtResultados.FiltraParametros("TipoDocto IN ('Ped','PDev','DPe','RNC')") + Else + DtPendientes = ObjInventarios.DtResultados + End If + Else + DtPendientes = Nothing + Alert("Ocurrió un error al obtener las Compras pendientes de recibir del proveedor. Por favor vuelva a intentar", TipoMensaje.MsgError) + End If + + If UsuarioActual.Empresa.Funcionalidad(540) = "1" Then + BtnGuardar.Enabled = False + Dim FI As Date = NowADS().AddDays(-1) + Dim FF As Date = NowADS().AddDays(-7) + If ObjInventarios.RepNotasSinAlmacen(1, -1, FI, FF, "-1", -1, UsuarioActual.Empresa.CveEmpresa) Then + If ObjInventarios.DtResultados IsNot Nothing AndAlso ObjInventarios.DtResultados.Rows.Count > 1 Then + BtnGuardar.Enabled = False + Alert("No se podrá realizar entrega de mercancía si no se les da salida a los documentos pendientes. Para más información ver el Reporte de notas sin entrada en la sección Ventas.", TipoMensaje.MsgAdvertencia) + Else + BtnGuardar.Enabled = True + End If + End If + End If + ObjInventarios.Dispose() + + If DtPendientes IsNot Nothing Then + GVPendientes.DataSource = DtPendientes + End If + LtActualizado.Text = String.Format("Actualizado: {0}", NowADS().ToString("H:mm")) + + GVPendientes.DataBind() + UpPendientes.Update() + If DtPendientes IsNot Nothing Then DtPendientes.Dispose() + + End Sub + Protected Sub GVPendientes_RowDataBound(sender As Object, e As GridViewRowEventArgs) Handles GVPendientes.RowDataBound + If e.Row.RowType = DataControlRowType.DataRow Then + e.Row.FCLinkButton("BtnSurtir").CommandArgument = If(e.Row.DBCampo("TipoEntrega") = "1", e.Row.DBCampo("CveVenta"), e.Row.DBCampo("CveTraspasoSolicitud")) + + Select Case e.Row.DBCampo("TipoEntrega").ToString().ToEntero() + Case 1 + If UsuarioActual.TienePermisoProceso(201) Then + Dim Css As String = "Texto" + Dim Liga As String = $"/Ventas/Ventas.aspx?&CveVenta={e.Row.DBCampo("CveVenta")}" + e.Row.FCLabel("LblFolio").Text = "" + e.Row.FCLabel("LblFolio").Text + "" + End If + + If UsuarioActual.CveEmpresa.Contiene(72, 80) Then + GVPendientes.Columns(4).Visible = True + e.Row.FCHyperLink("HplDownPDF").Visible = True + e.Row.FCHyperLink("HplDownPDF").NavigateUrl = String.Format("/Compras/PopUpVerFactura.aspx?P={0}", Encripta(String.Format("OP=VTA&CVEVENTA={0}", e.Row.DBCampo("CveVenta")))) + End If + + If e.Row.DBCampo("TipoDocto").ToString().Contiene({"Rem", "Ing", "Ped", "PeC", "Ant"}) And e.Row.DBCampo("EsDevolucionVenta").ToString().ToEntero() = 0 Then + e.Row.FCLinkButton("BtnSurtir").CssClass = "btn btn-primary btn-sm" + e.Row.FCLinkButton("BtnSurtir").Text = " Surtir " + Else + e.Row.FCLinkButton("BtnSurtir").CssClass = "btn yellow-gold btn-sm" + e.Row.FCLinkButton("BtnSurtir").Text = " Recibir" + End If + Case 2 + Dim Css As String = "Texto" + Dim Liga As String = $"/Inventarios/TrasladoSolicitud.aspx?&CveTraspasoSolicitud={e.Row.DBCampo("CveTraspasoSolicitud")}" + e.Row.FCLabel("LblFolio").Text = "" + e.Row.FCLabel("LblFolio").Text + "" + e.Row.FCLinkButton("BtnSurtir").CssClass = "btn btn-primary btn-sm" + e.Row.FCLinkButton("BtnSurtir").Text = " Traspasar " + End Select + UpPendientes.Update() + End If End Sub -#End Region +#End Region -#Region " CARGA VENTA POR SURTIR " - Protected Sub BtnSurtir_Click(sender As Object, e As EventArgs) - - Dim Boton As LinkButton = CType(sender, LinkButton) - - Dim GvRow As GridViewRow = DirectCast((DirectCast(sender, LinkButton)).NamingContainer, GridViewRow) +#Region " CARGA VENTA POR SURTIR " + Protected Sub BtnSurtir_Click(sender As Object, e As EventArgs) + + Dim Boton As LinkButton = CType(sender, LinkButton) + + Dim GvRow As GridViewRow = DirectCast((DirectCast(sender, LinkButton)).NamingContainer, GridViewRow) Dim CveOS As Integer = GvRow.DataKey("CveOS").ToEntero - 'CveVentaAD = -1 - - If Boton.CommandArgument.ToEntero() > 0 Then - TimmerRefresh.Enabled = False - - DivTransitorio1.Visible = False - ChkTransitorio.Checked = False - TxtResponsable.Text = "" - DivTransitorio2.Visible = False - DdlAlmacen.Enabled = True - - Select Case CType(Boton.NamingContainer, GridViewRow).DataKey("TipoEntrega").ToEntero() - Case 1 ' VENTA - CargaVentaPorSurtir(CType(sender, LinkButton).CommandArgument.ToEntero(), CveOS:=CveOS) - Case 2 ' TRASPASO - DivTransitorio1.Visible = True - CargaTraspasoPorSurtir(CType(Boton.NamingContainer, GridViewRow).DataKey("CveTraspasoSolicitud").ToEntero()) - End Select - - End If - - End Sub - Protected Sub BtnBuscar_Click(sender As Object, e As EventArgs) - 'CveVentaAD = -2 - CargaVentaPorSurtir(DdlFolio.SelectedValue.ToEntero()) - End Sub + 'CveVentaAD = -1 + + If Boton.CommandArgument.ToEntero() > 0 Then + TimmerRefresh.Enabled = False + + DivTransitorio1.Visible = False + ChkTransitorio.Checked = False + TxtResponsable.Text = "" + DivTransitorio2.Visible = False + DdlAlmacen.Enabled = True + + Select Case CType(Boton.NamingContainer, GridViewRow).DataKey("TipoEntrega").ToEntero() + Case 1 ' VENTA + CargaVentaPorSurtir(CType(sender, LinkButton).CommandArgument.ToEntero(), CveOS:=CveOS) + Case 2 ' TRASPASO + DivTransitorio1.Visible = True + CargaTraspasoPorSurtir(CType(Boton.NamingContainer, GridViewRow).DataKey("CveTraspasoSolicitud").ToEntero()) + End Select + + End If + + End Sub + Protected Sub BtnBuscar_Click(sender As Object, e As EventArgs) + 'CveVentaAD = -2 + CargaVentaPorSurtir(DdlFolio.SelectedValue.ToEntero()) + End Sub Private Sub CargaVentaPorSurtir(CveVenta As Integer, Optional CveAlmacen As Integer = -1, Optional CveOS As Integer = -1) - Adjunto = "" + Adjunto = "" BtnArchivoAdjunto.Visible = False - LbSurtida.Visible = False - CveContrato = -1 - CveSubProyecto = -1 - CveOP = -1 - DtDatos = Nothing - TipoEntrega = 1 + LbSurtida.Visible = False + CveContrato = -1 + CveSubProyecto = -1 + CveOP = -1 + DtDatos = Nothing + TipoEntrega = 1 BtnGuardar.Visible = True - Dim StrAlmacenes As String = "CveTipoAlmacen IN (1,2,26)" - If UsuarioActual.CveSubProyecto = 8804 Then - StrAlmacenes = "CveTipoAlmacen IN (1,2,12)" - End If - - Dim ObjInventario As New ClsInventarios - - If ObjInventario.EntregaAlmacenGet(CveVenta, UsuarioActual.CveEmpresa, CveAlmacen) Then - If ObjInventario.DtResultados IsNot Nothing AndAlso ObjInventario.DtResultados.Rows.Count > 0 Then - - ArchivoBitacora = String.Format("{0}Temp\EntregaDT_{1}_{2}.xml", UsuarioActual.Empresa.Ruta, UsuarioActual.CveUsuario, CveVenta) - ArchivoBitacoraDetalle = String.Format("{0}Temp\EntregaDTD_{1}_{2}.xml", UsuarioActual.Empresa.Ruta, UsuarioActual.CveUsuario, CveVenta) - If ArchivoBitacora <> "" Then - Dim Archivo As New System.IO.FileInfo(ArchivoBitacora) - If Archivo.Exists() Then - HplCargaBitacora.Visible = True - uppCargaBitacora.Update() - End If - End If - - DtDatos = ObjInventario.DtResultados - If Not DtDatos.Columns.Contains("Consec") Then DtDatos.Columns.Add("Consec", GetType(Integer)) - If Not DtDatos.Columns.Contains("CantidadGV") Then DtDatos.Columns.Add("CantidadGV", GetType(Double)) - If Not DtDatos.Columns.Contains("CantidadTraspaso") Then DtDatos.Columns.Add("CantidadTraspaso", GetType(Double)) - Dim Index As Integer = 1 - For Each Dr As DataRow In DtDatos.Rows - Dr("Consec") = Index - Index += 1 - Next - - DtDatosDetalle = Nothing - CreaDtDetalle() - - DtDatosDetalleLote = Nothing - CreaDtDetalleLote() - - If DtDatos.Rows(0) IsNot Nothing Then - Dim drE As DataRow = DtDatos.Rows(0) - - EsDevolucionVenta = drE("EsDevolucionVenta").ToString().ToEntero() - TipoDocto = DtDatos.Rows(0)("TipoDocto").ToString() - 'TipoMovimiento = If(TipoDocto.Contiene({"Rem", "Ped", "Ing", "Ped", "PeC", "Ant"}) And (EsDevolucionVenta = 0 Or CveVentaAD > 0), 1, 2) - TipoMovimiento = If(TipoDocto.Contiene({"Rem", "Ped", "Ing", "Ped", "PeC", "Ant"}) And (EsDevolucionVenta = 0), 1, 2) - + Dim StrAlmacenes As String = "CveTipoAlmacen IN (1,2,26)" + If UsuarioActual.CveSubProyecto = 8804 Then + StrAlmacenes = "CveTipoAlmacen IN (1,2,12)" + End If + + Dim ObjInventario As New ClsInventarios + + If ObjInventario.EntregaAlmacenGet(CveVenta, UsuarioActual.CveEmpresa, CveAlmacen) Then + If ObjInventario.DtResultados IsNot Nothing AndAlso ObjInventario.DtResultados.Rows.Count > 0 Then + + ArchivoBitacora = String.Format("{0}Temp\EntregaDT_{1}_{2}.xml", UsuarioActual.Empresa.Ruta, UsuarioActual.CveUsuario, CveVenta) + ArchivoBitacoraDetalle = String.Format("{0}Temp\EntregaDTD_{1}_{2}.xml", UsuarioActual.Empresa.Ruta, UsuarioActual.CveUsuario, CveVenta) + If ArchivoBitacora <> "" Then + Dim Archivo As New System.IO.FileInfo(ArchivoBitacora) + If Archivo.Exists() Then + HplCargaBitacora.Visible = True + uppCargaBitacora.Update() + End If + End If + + DtDatos = ObjInventario.DtResultados + If Not DtDatos.Columns.Contains("Consec") Then DtDatos.Columns.Add("Consec", GetType(Integer)) + If Not DtDatos.Columns.Contains("CantidadGV") Then DtDatos.Columns.Add("CantidadGV", GetType(Double)) + If Not DtDatos.Columns.Contains("CantidadTraspaso") Then DtDatos.Columns.Add("CantidadTraspaso", GetType(Double)) + Dim Index As Integer = 1 + For Each Dr As DataRow In DtDatos.Rows + Dr("Consec") = Index + Index += 1 + Next + + DtDatosDetalle = Nothing + CreaDtDetalle() + + DtDatosDetalleLote = Nothing + CreaDtDetalleLote() + + If DtDatos.Rows(0) IsNot Nothing Then + Dim drE As DataRow = DtDatos.Rows(0) + + EsDevolucionVenta = drE("EsDevolucionVenta").ToString().ToEntero() + TipoDocto = DtDatos.Rows(0)("TipoDocto").ToString() + 'TipoMovimiento = If(TipoDocto.Contiene({"Rem", "Ped", "Ing", "Ped", "PeC", "Ant"}) And (EsDevolucionVenta = 0 Or CveVentaAD > 0), 1, 2) + TipoMovimiento = If(TipoDocto.Contiene({"Rem", "Ped", "Ing", "Ped", "PeC", "Ant"}) And (EsDevolucionVenta = 0), 1, 2) + If UsuarioActual.Empresa.Funcionalidad(578).ToEntero = 1 AndAlso TipoDocto.Contiene("Ped", "Ing") Then TxtObservaciones.Text = $"Dr. {drE("Medico").ToString}{vbCrLf}Cx. {drE("Procedimiento").ToString}{vbCrLf}F. Cirugía {drE("FechaParaSurtir").ToString.ToDateTime.ToString("dd/MM/yyyy HH:mm")}{vbCrLf}H. {drE("Sucursal").ToString}{vbCrLf}" TxtObservaciones.Rows = 4 - End If - - LbCliente.Text = DtDatos.Rows(0)("Nombre").ToString() - HLFolio.Text = drE("SerieFolio").ToString() + End If + + LbCliente.Text = DtDatos.Rows(0)("Nombre").ToString() + HLFolio.Text = drE("SerieFolio").ToString() LtlRegistra.Text = drE("UsuarioRegistra").ToString - If UsuarioActual.TienePermisoProceso(201) Then - HLFolio.NavigateUrl = $"/Ventas/Ventas.aspx?CveVenta={CveVenta}" - End If - - 'filtra los Almacenes de domicilio - If DtDatos.Rows(0)("ServicioDomicilio").ToString() = "True" Then - StrAlmacenes = "CveTipoAlmacen = 29" - End If - - trObsGral.Visible = drE("Observaciones").ToString() <> "" - LbObservaciones.Text = DtDatos.Rows(0)("Observaciones").ToString() - trObsAlmacen.Visible = drE("ObservacionesAlmacen").ToString() <> "" - LbObservacionesAlmacen.Text = drE("ObservacionesAlmacen").ToString() - CveVentaSurtir = CveVenta - CveOSSurtir = CveOS - + If UsuarioActual.TienePermisoProceso(201) Then + HLFolio.NavigateUrl = $"/Ventas/Ventas.aspx?CveVenta={CveVenta}" + End If + + 'filtra los Almacenes de domicilio + If DtDatos.Rows(0)("ServicioDomicilio").ToString() = "True" Then + StrAlmacenes = "CveTipoAlmacen = 29" + End If + + trObsGral.Visible = drE("Observaciones").ToString() <> "" + LbObservaciones.Text = DtDatos.Rows(0)("Observaciones").ToString() + trObsAlmacen.Visible = drE("ObservacionesAlmacen").ToString() <> "" + LbObservacionesAlmacen.Text = drE("ObservacionesAlmacen").ToString() + CveVentaSurtir = CveVenta + CveOSSurtir = CveOS + If TipoDocto = "Ped" And CveOSSurtir <= 0 Then CveOSSurtir = drE("CveOS").ToString().ToEntero - End If - + End If + CveTipoVenta = drE("CveTipoVenta").ToString().ToEntero - CveAlmacenTraspasoDestino = drE(If(EsDevolucionVenta = 1 And TipoDocto <> "Rem" And TipoDocto <> "Ped", "CveAlmacenTraspasoOrigen", "CveAlmacenTraspasoDestino")).ToString().ToEntero() - CveAlmacenTraspasoOrigen = drE(If(EsDevolucionVenta = 1 And TipoDocto <> "Rem" And TipoDocto <> "Ped", "CveAlmacenTraspasoDestino", "CveAlmacenTraspasoOrigen")).ToString().ToEntero() - CveContrato = drE("CveContrato").ToString().ToEntero() - CveVendedor = drE("CveVendedor").ToString().ToEntero() - CveCliente = drE("CveCliente").ToString().ToEntero() - 'ClienteEntregaPersonal(CveCliente) - CveSubProyecto = drE("CveSubProyecto").ToString().ToEntero() - EsInterno = CBool(DtDatos.Rows(0)("EsInterno").ToString()) + CveAlmacenTraspasoDestino = drE(If(EsDevolucionVenta = 1 And TipoDocto <> "Rem" And TipoDocto <> "Ped", "CveAlmacenTraspasoOrigen", "CveAlmacenTraspasoDestino")).ToString().ToEntero() + CveAlmacenTraspasoOrigen = drE(If(EsDevolucionVenta = 1 And TipoDocto <> "Rem" And TipoDocto <> "Ped", "CveAlmacenTraspasoDestino", "CveAlmacenTraspasoOrigen")).ToString().ToEntero() + CveContrato = drE("CveContrato").ToString().ToEntero() + CveVendedor = drE("CveVendedor").ToString().ToEntero() + CveCliente = drE("CveCliente").ToString().ToEntero() + 'ClienteEntregaPersonal(CveCliente) + CveSubProyecto = drE("CveSubProyecto").ToString().ToEntero() + EsInterno = CBool(DtDatos.Rows(0)("EsInterno").ToString()) CveDireccionEnvio = drE("CveDireccionEnvio").ToString.ToEntero Adjunto = drE("Adjunto").ToString() @@ -731,69 +731,69 @@ Partial Class Inventarios_EntregaAlmacen End If End If - If CveDireccionEnvio > 0 Then - trDireccionEnvio.Visible = True - 'carga la dirección de envío - Dim ObjClientes As New ClsClientes - If ObjClientes.DireccionEnvioGet(CveDireccionEnvio, CveCliente, -1) Then - Dim drenvio As DataRow = ObjClientes.DtResultados.FiltroPrimero("") - LblDirEnvio.Text = drenvio("SucursalClienteVentaDireccion").ToString - End If - - ObjClientes.Dispose() - Else - trDireccionEnvio.Visible = False - End If - - If DtDatos.SUM("CantidadS") <= 0 Then - GvDatos.CssClass = "table table-striped table-hover Widthall gvInventario gvEscondeColumna" - Else - GvDatos.CssClass = "table table-striped table-hover Widthall gvInventario" - End If - - If CveAlmacenTraspasoDestino > 0 And Not (TipoMovimiento = 2 And TipoDocto.Contiene("Rem", "Ped")) Then - DivTipoCambioAdvertencia.Visible = True - LtTipoCambioAdvertencia.Text = $"Los productos seran Trasladados al Almacen: {GlobalDTAlmacen(UsuarioActual.CveEmpresa).FiltroPrimeroValor("Almacen", $"CveAlmacen = {CveAlmacenTraspasoDestino}")}" - Else - DivTipoCambioAdvertencia.Visible = False - End If - - 'DEVOLUCION REMISION - If TipoMovimiento = 2 And TipoDocto.Contiene("Rem", "Ped") And Not CveAlmacenTraspasoDestino > 0 Then - Alert("La remisión que se intenta devolver presenta inconsistencias. Comuniquese con servicio técnico SIG.", TipoMensaje.MsgError) - BtnGuardar.Visible = False - End If - - If CveAlmacen <= 0 Then - DdlAlmacen.Items.Clear() - If CveAlmacenTraspasoOrigen > 0 Then 'Not (EsDevolucionVenta = 1 And DtDatos.Rows(0)("TipoDocto").ToString() = "Rem" And UsuarioActual.Empresa.Funcionalidad(145) = "1") - ESTO ES PARA CUANDO SEA REMISION DE ENTREGA POR ADELANTADO FUNCIONA LA DEVOLUCION - DdlAlmacen.Items.Clear() - DdlAlmacen.Items.Insert(0, New ListItem(GlobalDTAlmacen(UsuarioActual.CveEmpresa).FiltroPrimeroValor("Almacen", $"CveAlmacen = {CveAlmacenTraspasoOrigen}"), CveAlmacenTraspasoOrigen.ToString())) - Else - '[IPP] PARCHE - Debe hacerse permiso proceso - 17Enero2018 - Dim RestriccionAlmacenSubProyecto As String = If(UsuarioActual.CveEmpresa.Contiene(72, 80), $" AND CveSubProyecto = {CveSubProyecto}", "") - DdlAlmacen.DataSource = GlobalDTAlmacenUsuarios(UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa, -1).FiltraParametros($"{StrAlmacenes} {RestriccionAlmacenSubProyecto}") - End If - - DdlAlmacen.Items.Insert(0, New ListItem(" Seleccione ", "-1")) - DdlAlmacen.SelectedValue = "-1" - DdlAlmacen.DataBind() - DdlAlmacen.SelectedValueExist(UsuarioActual.CveAlmacen) - If CveAlmacenTraspasoOrigen > 0 Then - DdlAlmacen.SelectedValueExist(CveAlmacenTraspasoOrigen) - End If - End If - - If Not DtDatos.Columns.Contains("Serie") Then DtDatos.Columns.Add("Serie", GetType(String)) - - If Not DtDatos.Columns.Contains("Lote") Then DtDatos.Columns.Add("Lote", GetType(String)) - - If Not DtDatos.Columns.Contains("CveSeccion") Then DtDatos.Columns.Add("CveSeccion", GetType(Integer)) - - If Not DtDatos.Columns.Contains("FechaCaducidad") Then DtDatos.Columns.Add("FechaCaducidad", GetType(Date)) - - If Not DtDatos.Columns.Contains("Seleccionado") Then DtDatos.Columns.Add("Seleccionado", GetType(Boolean)) - + If CveDireccionEnvio > 0 Then + trDireccionEnvio.Visible = True + 'carga la dirección de envío + Dim ObjClientes As New ClsClientes + If ObjClientes.DireccionEnvioGet(CveDireccionEnvio, CveCliente, -1) Then + Dim drenvio As DataRow = ObjClientes.DtResultados.FiltroPrimero("") + LblDirEnvio.Text = drenvio("SucursalClienteVentaDireccion").ToString + End If + + ObjClientes.Dispose() + Else + trDireccionEnvio.Visible = False + End If + + If DtDatos.SUM("CantidadS") <= 0 Then + GvDatos.CssClass = "table table-striped table-hover Widthall gvInventario gvEscondeColumna" + Else + GvDatos.CssClass = "table table-striped table-hover Widthall gvInventario" + End If + + If CveAlmacenTraspasoDestino > 0 And Not (TipoMovimiento = 2 And TipoDocto.Contiene("Rem", "Ped")) Then + DivTipoCambioAdvertencia.Visible = True + LtTipoCambioAdvertencia.Text = $"Los productos seran Trasladados al Almacen: {GlobalDTAlmacen(UsuarioActual.CveEmpresa).FiltroPrimeroValor("Almacen", $"CveAlmacen = {CveAlmacenTraspasoDestino}")}" + Else + DivTipoCambioAdvertencia.Visible = False + End If + + 'DEVOLUCION REMISION + If TipoMovimiento = 2 And TipoDocto.Contiene("Rem", "Ped") And Not CveAlmacenTraspasoDestino > 0 Then + Alert("La remisión que se intenta devolver presenta inconsistencias. Comuniquese con servicio técnico SIG.", TipoMensaje.MsgError) + BtnGuardar.Visible = False + End If + + If CveAlmacen <= 0 Then + DdlAlmacen.Items.Clear() + If CveAlmacenTraspasoOrigen > 0 Then 'Not (EsDevolucionVenta = 1 And DtDatos.Rows(0)("TipoDocto").ToString() = "Rem" And UsuarioActual.Empresa.Funcionalidad(145) = "1") - ESTO ES PARA CUANDO SEA REMISION DE ENTREGA POR ADELANTADO FUNCIONA LA DEVOLUCION + DdlAlmacen.Items.Clear() + DdlAlmacen.Items.Insert(0, New ListItem(GlobalDTAlmacen(UsuarioActual.CveEmpresa).FiltroPrimeroValor("Almacen", $"CveAlmacen = {CveAlmacenTraspasoOrigen}"), CveAlmacenTraspasoOrigen.ToString())) + Else + '[IPP] PARCHE - Debe hacerse permiso proceso - 17Enero2018 + Dim RestriccionAlmacenSubProyecto As String = If(UsuarioActual.CveEmpresa.Contiene(72, 80), $" AND CveSubProyecto = {CveSubProyecto}", "") + DdlAlmacen.DataSource = GlobalDTAlmacenUsuarios(UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa, -1).FiltraParametros($"{StrAlmacenes} {RestriccionAlmacenSubProyecto}") + End If + + DdlAlmacen.Items.Insert(0, New ListItem(" Seleccione ", "-1")) + DdlAlmacen.SelectedValue = "-1" + DdlAlmacen.DataBind() + DdlAlmacen.SelectedValueExist(UsuarioActual.CveAlmacen) + If CveAlmacenTraspasoOrigen > 0 Then + DdlAlmacen.SelectedValueExist(CveAlmacenTraspasoOrigen) + End If + End If + + If Not DtDatos.Columns.Contains("Serie") Then DtDatos.Columns.Add("Serie", GetType(String)) + + If Not DtDatos.Columns.Contains("Lote") Then DtDatos.Columns.Add("Lote", GetType(String)) + + If Not DtDatos.Columns.Contains("CveSeccion") Then DtDatos.Columns.Add("CveSeccion", GetType(Integer)) + + If Not DtDatos.Columns.Contains("FechaCaducidad") Then DtDatos.Columns.Add("FechaCaducidad", GetType(Date)) + + If Not DtDatos.Columns.Contains("Seleccionado") Then DtDatos.Columns.Add("Seleccionado", GetType(Boolean)) + If Not DtDatos.Columns.Contains("CantidadSeleccionada") Then DtDatos.Columns.Add("CantidadSeleccionada", GetType(Double)) If UsuarioActual.Empresa.Funcionalidad(578) = "1" AndAlso TipoMovimiento = 1 Then @@ -837,237 +837,237 @@ Partial Class Inventarios_EntregaAlmacen End If End If - If UsuarioActual.Empresa.Funcionalidad(280) = "1" Then - FormaPaqueteria = DtDatos.Rows(0)("FormaPaqueteria").ToString().ToEntero() - Dim FormaPaq As Integer = FormaPaqueteria - RbSinEntrega.Checked = False - RbEntregaInterna.Checked = False - RbEntregaExterna.Checked = False - Select Case FormaPaq - Case 1 - RbSinEntrega.Checked = True - LnkPaqueteriaDetalle.Visible = False - Case 2 - RbEntregaInterna.Checked = True - 'LnkPaqueteriaDetalle.Visible = True - DdlEstatus.SelectedValue = "5" - Case 3 - RbEntregaExterna.Checked = True - LnkPaqueteriaDetalle.Visible = True - End Select - End If - 'TxtFecha.Text = If(EsDevolucionVenta = 1, NowADS().ToShortDateString, DtDatos.Rows(0)("Fecha").ToString()) - End If - - If UsuarioActual.Empresa.Funcionalidad(132) = "1" Then - DivCodigoSeriePS.Visible = True - Else - DivCodigoSeriePS.Visible = False - End If - - If TipoMovimiento = 2 Then ' cuando es cancelación - Dim Filtro As String '= If(ObjInventario.DtResultados.Rows(0)("TipoDocto").ToString().Contiene({"Ing", "Dev", "Ped"}), "CveConcepto = 3", "CveConcepto = 9") - Dim FiltroPS As String = "" - Select Case ObjInventario.DtResultados.Rows(0)("TipoDocto").ToString() - Case "Ing" - Filtro = "CveConcepto IN (3,40)" - Case "Dev" - 'cuand es devolucionventa=1, es cancelación de la devolución - If EsDevolucionVenta = 1 Then - Filtro = "CveConcepto = 18" - Else - Filtro = "CveConcepto IN (3,40)" 'cuando es devolución - For Each drr As DataRow In ObjInventario.DtResultados.Rows - FiltroPS = FiltroPS + "," + drr("CvePS").ToString - Next - FiltroPS = "AND CvePS IN (" & FiltroPS.Substring(1) & ")" 'elimino la primer comma - End If - Case "DPe" - Filtro = "CveConcepto = 9" - Case Else - Filtro = "CveConcepto = 9" - End Select - If ObjInventario.GetInv_Mov(ObjInventario.DtResultados.Rows(0)("CveVentaPadre").ToString().ToEntero(), UsuarioActual.CveEmpresa) Then - DtExistencias = ObjInventario.DtResultados.FiltraParametros($"CvePS Is Not NULL AND {Filtro} " & FiltroPS) - - If Not DtExistencias.Rows.Count > 0 Then - Alert("La Venta original de la Devolución no tiene salida de Almacén.", TipoMensaje.MsgAdvertencia) - End If - - If TipoDocto.Contiene("Ing") AndAlso TipoMovimiento = 2 Then - Dim DtMov As DataTable = DtExistencias.FiltraParametros("CveConcepto = 40", "", {"CveAlmacen"}) - If DtMov.Rows.Count > 0 AndAlso CveAlmacen <= 0 Then - Dim CveAlmacenDev As Integer = DtMov.Rows(0)("CveAlmacen").ToString().ToEntero() - Dim AlmacenDev As String = "" - If CveAlmacenDev > 0 Then - AlmacenDev = GlobalDTAlmacen(UsuarioActual.CveEmpresa, CveAlmacen:=CveAlmacenDev).FiltroPrimeroValor("Almacen") - 'DdlAlmacen.Items.Clear() - 'DdlAlmacen.DataSource = GlobalDTAlmacenUsuarios(UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa, -1).FiltraParametros($"CveAlmacen = {CveAlmacenDev}") - 'DdlAlmacen.DataBind() - - DdlAlmacen.SelectedValueExistInsert(CveAlmacenDev, AlmacenDev) ' se va a poder regresar en algun almacen diferente - DdlAlmacen.Enabled = False - End If - - EsDevolucionDirecta = True - End If - End If - - Else - Alert("Ocurrió un error al cargar los datos de devolución. Por favor vuelva a intentar.", TipoMensaje.MsgError) - End If - End If - If UsuarioActual.Empresa.FacturaProduccion Then - CargaDocumentos(CveVenta) - End If - Else - Alert("No se encontraron productos pendientes por surtir. Por favor verifique y vuelva a intentar.", TipoMensaje.MsgAdvertencia) - End If - Else - DtDatos = Nothing - End If - - ObjInventario.Dispose() + If UsuarioActual.Empresa.Funcionalidad(280) = "1" Then + FormaPaqueteria = DtDatos.Rows(0)("FormaPaqueteria").ToString().ToEntero() + Dim FormaPaq As Integer = FormaPaqueteria + RbSinEntrega.Checked = False + RbEntregaInterna.Checked = False + RbEntregaExterna.Checked = False + Select Case FormaPaq + Case 1 + RbSinEntrega.Checked = True + LnkPaqueteriaDetalle.Visible = False + Case 2 + RbEntregaInterna.Checked = True + 'LnkPaqueteriaDetalle.Visible = True + DdlEstatus.SelectedValue = "5" + Case 3 + RbEntregaExterna.Checked = True + LnkPaqueteriaDetalle.Visible = True + End Select + End If + 'TxtFecha.Text = If(EsDevolucionVenta = 1, NowADS().ToShortDateString, DtDatos.Rows(0)("Fecha").ToString()) + End If + + If UsuarioActual.Empresa.Funcionalidad(132) = "1" Then + DivCodigoSeriePS.Visible = True + Else + DivCodigoSeriePS.Visible = False + End If + + If TipoMovimiento = 2 Then ' cuando es cancelación + Dim Filtro As String '= If(ObjInventario.DtResultados.Rows(0)("TipoDocto").ToString().Contiene({"Ing", "Dev", "Ped"}), "CveConcepto = 3", "CveConcepto = 9") + Dim FiltroPS As String = "" + Select Case ObjInventario.DtResultados.Rows(0)("TipoDocto").ToString() + Case "Ing" + Filtro = "CveConcepto IN (3,40)" + Case "Dev" + 'cuand es devolucionventa=1, es cancelación de la devolución + If EsDevolucionVenta = 1 Then + Filtro = "CveConcepto = 18" + Else + Filtro = "CveConcepto IN (3,40)" 'cuando es devolución + For Each drr As DataRow In ObjInventario.DtResultados.Rows + FiltroPS = FiltroPS + "," + drr("CvePS").ToString + Next + FiltroPS = "AND CvePS IN (" & FiltroPS.Substring(1) & ")" 'elimino la primer comma + End If + Case "DPe" + Filtro = "CveConcepto = 9" + Case Else + Filtro = "CveConcepto = 9" + End Select + If ObjInventario.GetInv_Mov(ObjInventario.DtResultados.Rows(0)("CveVentaPadre").ToString().ToEntero(), UsuarioActual.CveEmpresa) Then + DtExistencias = ObjInventario.DtResultados.FiltraParametros($"CvePS Is Not NULL AND {Filtro} " & FiltroPS) + + If Not DtExistencias.Rows.Count > 0 Then + Alert("La Venta original de la Devolución no tiene salida de Almacén.", TipoMensaje.MsgAdvertencia) + End If + + If TipoDocto.Contiene("Ing") AndAlso TipoMovimiento = 2 Then + Dim DtMov As DataTable = DtExistencias.FiltraParametros("CveConcepto = 40", "", {"CveAlmacen"}) + If DtMov.Rows.Count > 0 AndAlso CveAlmacen <= 0 Then + Dim CveAlmacenDev As Integer = DtMov.Rows(0)("CveAlmacen").ToString().ToEntero() + Dim AlmacenDev As String = "" + If CveAlmacenDev > 0 Then + AlmacenDev = GlobalDTAlmacen(UsuarioActual.CveEmpresa, CveAlmacen:=CveAlmacenDev).FiltroPrimeroValor("Almacen") + 'DdlAlmacen.Items.Clear() + 'DdlAlmacen.DataSource = GlobalDTAlmacenUsuarios(UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa, -1).FiltraParametros($"CveAlmacen = {CveAlmacenDev}") + 'DdlAlmacen.DataBind() + + DdlAlmacen.SelectedValueExistInsert(CveAlmacenDev, AlmacenDev) ' se va a poder regresar en algun almacen diferente + DdlAlmacen.Enabled = False + End If + + EsDevolucionDirecta = True + End If + End If + + Else + Alert("Ocurrió un error al cargar los datos de devolución. Por favor vuelva a intentar.", TipoMensaje.MsgError) + End If + End If + If UsuarioActual.Empresa.FacturaProduccion Then + CargaDocumentos(CveVenta) + End If + Else + Alert("No se encontraron productos pendientes por surtir. Por favor verifique y vuelva a intentar.", TipoMensaje.MsgAdvertencia) + End If + Else + DtDatos = Nothing + End If + + ObjInventario.Dispose() UpGenerales.Update() If (EsDevolucionVenta = 1 AndAlso CveOSSurtir > 0 AndAlso TipoMovimiento = 2 AndAlso TipoDocto = "Ped") Or (UsuarioActual.Empresa.Funcionalidad(578).ToEntero = 1 AndAlso CveTipoVenta <> 3) Then BloqueCantidad = True Else BloqueCantidad = False - End If - + End If + If CveAlmacen <= 0 Then CargaGvDatos() UpVenta.Update() - End Sub - Private Sub CargaTraspasoPorSurtir(CveTraspaso As Integer) - LbSurtida.Visible = False - CveContrato = -1 - CveSubProyecto = -1 - DtDatos = Nothing - TipoEntrega = 2 - - Dim ObjInventario As New ClsInventarios - - If ObjInventario.EntregaAlmacenTraspasosGet(CveTraspaso) Then - If ObjInventario.DtResultados IsNot Nothing AndAlso ObjInventario.DtResultados.Rows.Count > 0 Then - CveTraspasoSurtir = CveTraspaso - TipoMovimiento = 1 - - DtDatos = ObjInventario.DtResultados - DtDatos.Columns.Add("Consec", GetType(Integer)) - DtDatos.Columns.Add("CantidadGV", GetType(Double)) - DtDatos.Columns.Add("CantidadTraspaso", GetType(Double)) - - LbCliente.Text = DtDatos.Rows(0)("Nombre").ToString() - HLFolio.Text = DtDatos.Rows(0)("SerieFolio").ToString() - If UsuarioActual.TienePermisoProceso(201) Then - HLFolio.NavigateUrl = $"/Inventarios/TrasladoSolicitud.aspx?CveTraspasoSolicitud={CveTraspasoSurtir}" - End If - LbObservaciones.Text = DtDatos.Rows(0)("Observaciones").ToString() - - Dim Index As Integer = 1 - For Each Dr As DataRow In DtDatos.Rows - Dr("Consec") = Index - Index += 1 - Next - - DtDatosDetalle = Nothing - CreaDtDetalle() - - DtDatosDetalleLote = Nothing - CreaDtDetalleLote() - - CveAlmacenTraspasoDestino = DtDatos.Rows(0)("CveAlmacenDestino").ToString().ToEntero() - CveAlmacenTraspasoOrigen = DtDatos.Rows(0)("CveAlmacenOrigen").ToString().ToEntero() - CveSubProyecto = DtDatos.Rows(0)("CveSubProyecto").ToString().ToEntero() - EsInterno = CBool(DtDatos.Rows(0)("EsInterno").ToString()) - CveOP = DtDatos.Rows(0)("CveOP").ToString().ToEntero() - CveVentaSurtir = -1 - CveOSSurtir = -1 - If DtDatos.SUM("CantidadS") <= 0 Then - GvDatos.CssClass = "table table-striped table-hover Widthall gvInventario gvEscondeColumna" - Else - GvDatos.CssClass = "table table-striped table-hover Widthall gvInventario" - End If - - If CveAlmacenTraspasoDestino > 0 Then - DivTipoCambioAdvertencia.Visible = True - LtTipoCambioAdvertencia.Text = $"Los productos seran Trasladados al Almacen: {GlobalDTAlmacen(UsuarioActual.CveEmpresa).FiltroPrimeroValor("Almacen", $"CveAlmacen = {CveAlmacenTraspasoDestino}")}" - Else - DivTipoCambioAdvertencia.Visible = False - End If - - 'If DtDatos.Rows.Cast(Of DataRow).Any(Function(Row) Row("CveTamaño").ToString().ToEntero() > 0) Then - - 'End If - - - DdlAlmacen.Items.Clear() - If CveAlmacenTraspasoOrigen > 0 Then - DdlAlmacen.Items.Insert(0, New ListItem(GlobalDTAlmacen(UsuarioActual.CveEmpresa).FiltroPrimeroValor("Almacen", $"CveAlmacen = {CveAlmacenTraspasoOrigen}"), CveAlmacenTraspasoOrigen.ToString())) - End If - - DdlAlmacen.Items.Insert(0, New ListItem(" Seleccione ", "-1")) - DdlAlmacen.SelectedValue = "-1" - DdlAlmacen.DataBind() - DdlAlmacen.SelectedValueExist(UsuarioActual.CveAlmacen) - If CveAlmacenTraspasoOrigen > 0 Then - DdlAlmacen.SelectedValueExist(CveAlmacenTraspasoOrigen) - End If - - If Not DtDatos.Columns.Contains("CveSeccion") Then - DtDatos.Columns.Add("CveSeccion", GetType(Integer)) - End If - - If Not DtDatos.Columns.Contains("Lote") Then - DtDatos.Columns.Add("Lote", GetType(String)) - End If - - If Not DtDatos.Columns.Contains("FechaCaducidad") Then - DtDatos.Columns.Add("FechaCaducidad", GetType(Date)) - End If - If Not DtDatos.Columns.Contains("Seleccionado") Then - DtDatos.Columns.Add("Seleccionado", GetType(Boolean)) - End If - If Not DtDatos.Columns.Contains("CantidadSeleccionada") Then - DtDatos.Columns.Add("CantidadSeleccionada", GetType(Double)) - End If - - If UsuarioActual.Empresa.Funcionalidad(132) = "1" Then - DivCodigoSeriePS.Visible = True - Else - DivCodigoSeriePS.Visible = False - End If - - Else - Alert("No se encontraron productos pendientes por surtir. Por favor verifique y vuelva a intentar.", TipoMensaje.MsgAdvertencia) - End If - Else - DtDatos = Nothing - End If - - ObjInventario.Dispose() - UpGenerales.Update() - CargaGvDatos() - - End Sub - Private Sub CargaGvDatos(Optional RecargaVenta As Boolean = True) - - If DtDatos IsNot Nothing Then - - - Dim AplicaSeccion, AplicaLote, AplicaCaducidad, AplicaSerie As Boolean - If DtDatos IsNot Nothing AndAlso DtDatos.Rows.Count > 0 Then - AplicaSerie = CBool(DtDatos.MAX("AplicaSerie")) - AplicaSeccion = CBool(DtDatos.MAX("AplicaSeccion")) - AplicaLote = CBool(DtDatos.MAX("AplicaLote")) - AplicaCaducidad = CBool(DtDatos.MAX("AplicaCaducidad")) - End If - - If AplicaSeccion Then GvDatos.Columns(7).Visible = True - If AplicaLote Then GvDatos.Columns(9).Visible = True + End Sub + Private Sub CargaTraspasoPorSurtir(CveTraspaso As Integer) + LbSurtida.Visible = False + CveContrato = -1 + CveSubProyecto = -1 + DtDatos = Nothing + TipoEntrega = 2 + + Dim ObjInventario As New ClsInventarios + + If ObjInventario.EntregaAlmacenTraspasosGet(CveTraspaso) Then + If ObjInventario.DtResultados IsNot Nothing AndAlso ObjInventario.DtResultados.Rows.Count > 0 Then + CveTraspasoSurtir = CveTraspaso + TipoMovimiento = 1 + + DtDatos = ObjInventario.DtResultados + DtDatos.Columns.Add("Consec", GetType(Integer)) + DtDatos.Columns.Add("CantidadGV", GetType(Double)) + DtDatos.Columns.Add("CantidadTraspaso", GetType(Double)) + + LbCliente.Text = DtDatos.Rows(0)("Nombre").ToString() + HLFolio.Text = DtDatos.Rows(0)("SerieFolio").ToString() + If UsuarioActual.TienePermisoProceso(201) Then + HLFolio.NavigateUrl = $"/Inventarios/TrasladoSolicitud.aspx?CveTraspasoSolicitud={CveTraspasoSurtir}" + End If + LbObservaciones.Text = DtDatos.Rows(0)("Observaciones").ToString() + + Dim Index As Integer = 1 + For Each Dr As DataRow In DtDatos.Rows + Dr("Consec") = Index + Index += 1 + Next + + DtDatosDetalle = Nothing + CreaDtDetalle() + + DtDatosDetalleLote = Nothing + CreaDtDetalleLote() + + CveAlmacenTraspasoDestino = DtDatos.Rows(0)("CveAlmacenDestino").ToString().ToEntero() + CveAlmacenTraspasoOrigen = DtDatos.Rows(0)("CveAlmacenOrigen").ToString().ToEntero() + CveSubProyecto = DtDatos.Rows(0)("CveSubProyecto").ToString().ToEntero() + EsInterno = CBool(DtDatos.Rows(0)("EsInterno").ToString()) + CveOP = DtDatos.Rows(0)("CveOP").ToString().ToEntero() + CveVentaSurtir = -1 + CveOSSurtir = -1 + If DtDatos.SUM("CantidadS") <= 0 Then + GvDatos.CssClass = "table table-striped table-hover Widthall gvInventario gvEscondeColumna" + Else + GvDatos.CssClass = "table table-striped table-hover Widthall gvInventario" + End If + + If CveAlmacenTraspasoDestino > 0 Then + DivTipoCambioAdvertencia.Visible = True + LtTipoCambioAdvertencia.Text = $"Los productos seran Trasladados al Almacen: {GlobalDTAlmacen(UsuarioActual.CveEmpresa).FiltroPrimeroValor("Almacen", $"CveAlmacen = {CveAlmacenTraspasoDestino}")}" + Else + DivTipoCambioAdvertencia.Visible = False + End If + + 'If DtDatos.Rows.Cast(Of DataRow).Any(Function(Row) Row("CveTamaño").ToString().ToEntero() > 0) Then + + 'End If + + + DdlAlmacen.Items.Clear() + If CveAlmacenTraspasoOrigen > 0 Then + DdlAlmacen.Items.Insert(0, New ListItem(GlobalDTAlmacen(UsuarioActual.CveEmpresa).FiltroPrimeroValor("Almacen", $"CveAlmacen = {CveAlmacenTraspasoOrigen}"), CveAlmacenTraspasoOrigen.ToString())) + End If + + DdlAlmacen.Items.Insert(0, New ListItem(" Seleccione ", "-1")) + DdlAlmacen.SelectedValue = "-1" + DdlAlmacen.DataBind() + DdlAlmacen.SelectedValueExist(UsuarioActual.CveAlmacen) + If CveAlmacenTraspasoOrigen > 0 Then + DdlAlmacen.SelectedValueExist(CveAlmacenTraspasoOrigen) + End If + + If Not DtDatos.Columns.Contains("CveSeccion") Then + DtDatos.Columns.Add("CveSeccion", GetType(Integer)) + End If + + If Not DtDatos.Columns.Contains("Lote") Then + DtDatos.Columns.Add("Lote", GetType(String)) + End If + + If Not DtDatos.Columns.Contains("FechaCaducidad") Then + DtDatos.Columns.Add("FechaCaducidad", GetType(Date)) + End If + If Not DtDatos.Columns.Contains("Seleccionado") Then + DtDatos.Columns.Add("Seleccionado", GetType(Boolean)) + End If + If Not DtDatos.Columns.Contains("CantidadSeleccionada") Then + DtDatos.Columns.Add("CantidadSeleccionada", GetType(Double)) + End If + + If UsuarioActual.Empresa.Funcionalidad(132) = "1" Then + DivCodigoSeriePS.Visible = True + Else + DivCodigoSeriePS.Visible = False + End If + + Else + Alert("No se encontraron productos pendientes por surtir. Por favor verifique y vuelva a intentar.", TipoMensaje.MsgAdvertencia) + End If + Else + DtDatos = Nothing + End If + + ObjInventario.Dispose() + UpGenerales.Update() + CargaGvDatos() + + End Sub + Private Sub CargaGvDatos(Optional RecargaVenta As Boolean = True) + + If DtDatos IsNot Nothing Then + + + Dim AplicaSeccion, AplicaLote, AplicaCaducidad, AplicaSerie As Boolean + If DtDatos IsNot Nothing AndAlso DtDatos.Rows.Count > 0 Then + AplicaSerie = CBool(DtDatos.MAX("AplicaSerie")) + AplicaSeccion = CBool(DtDatos.MAX("AplicaSeccion")) + AplicaLote = CBool(DtDatos.MAX("AplicaLote")) + AplicaCaducidad = CBool(DtDatos.MAX("AplicaCaducidad")) + End If + + If AplicaSeccion Then GvDatos.Columns(7).Visible = True + If AplicaLote Then GvDatos.Columns(9).Visible = True If AplicaCaducidad Then GvDatos.Columns(10).Visible = True If UsuarioActual.Empresa.Funcionalidad(578).ToEntero = 1 Then @@ -1077,41 +1077,41 @@ Partial Class Inventarios_EntregaAlmacen End If If Not String.IsNullOrWhiteSpace(UsuarioActual.Empresa.Funcionalidad(147)) Then - GvDatos.Columns(10).HeaderText = UsuarioActual.Empresa.Funcionalidad(147) + GvDatos.Columns(10).HeaderText = UsuarioActual.Empresa.Funcionalidad(147) End If 'GvDatos.Columns(9).HeaderText = If(UsuarioActual.Empresa.Funcionalidad(147) <> "", UsuarioActual.Empresa.Funcionalidad(147), "") 'SugerirFecha() - If RecargaVenta AndAlso DdlAlmacen.SelectedValue.ToEntero > 0 And CveVentaSurtir > 0 Then - CargaVentaPorSurtir(CveVentaSurtir, CveAlmacen:=DdlAlmacen.SelectedValue.ToEntero, CveOS:=CveOSSurtir) - - If CargaBitacora Then - CargaBitacoraSerie() + If RecargaVenta AndAlso DdlAlmacen.SelectedValue.ToEntero > 0 And CveVentaSurtir > 0 Then + CargaVentaPorSurtir(CveVentaSurtir, CveAlmacen:=DdlAlmacen.SelectedValue.ToEntero, CveOS:=CveOSSurtir) + + If CargaBitacora Then + CargaBitacoraSerie() End If - Else - - End If - End If - GvDatos.DataSource = DtDatos - - GvDatos.DataBind() - UpDatos.Update() - UpVenta.Update() - - 'CARGA LO PRECARGADO CON SERIE - Dim Contador As Integer = 0 - For Each Gvr As GridViewRow In GvDatos.Rows - If Gvr.DataKey("CvePS").ToEntero() = CvePSSerie AndAlso DtDatosDetalle IsNot Nothing Then - Contador = DtDatosDetalle.FiltraParametros(String.Format("ConsecId = {0}", Gvr.DataKey("Consec"))).Rows.Count - Gvr.FCCheckBox("cbInv").Enabled = False - Gvr.FCCheckBox("cbInv").Checked = True - Gvr.FCTextBox("TbCantidadF").Text = Contador.ToString() - End If - Next - - End Sub - - Protected Sub GvDatos_RowDataBound(sender As Object, e As GridViewRowEventArgs) Handles GvDatos.RowDataBound + Else + + End If + End If + GvDatos.DataSource = DtDatos + + GvDatos.DataBind() + UpDatos.Update() + UpVenta.Update() + + 'CARGA LO PRECARGADO CON SERIE + Dim Contador As Integer = 0 + For Each Gvr As GridViewRow In GvDatos.Rows + If Gvr.DataKey("CvePS").ToEntero() = CvePSSerie AndAlso DtDatosDetalle IsNot Nothing Then + Contador = DtDatosDetalle.FiltraParametros(String.Format("ConsecId = {0}", Gvr.DataKey("Consec"))).Rows.Count + Gvr.FCCheckBox("cbInv").Enabled = False + Gvr.FCCheckBox("cbInv").Checked = True + Gvr.FCTextBox("TbCantidadF").Text = Contador.ToString() + End If + Next + + End Sub + + Protected Sub GvDatos_RowDataBound(sender As Object, e As GridViewRowEventArgs) Handles GvDatos.RowDataBound If e.Row.RowType = DataControlRowType.Header Then If UsuarioActual.Empresa.Funcionalidad(578) = "1" Then @@ -1124,8 +1124,8 @@ Partial Class Inventarios_EntregaAlmacen End If End If - End If - + End If + If e.Row.RowType = DataControlRowType.DataRow Then If UsuarioActual.Empresa.Funcionalidad(578) = "1" Then @@ -1139,132 +1139,132 @@ Partial Class Inventarios_EntregaAlmacen End If 'código temporal - Dim AplicaSerie As Boolean = CBool(e.Row.DBCampo("AplicaSerie")) - - If AplicaSerie Then - e.Row.FCButton("BtnSerie").Visible = True - e.Row.FCButton("BtnSerie").Text = "Serie" - e.Row.FCButton("BtnSerie").CommandArgument = String.Format("{0}°{1}°{2}°{3}°{4}°{5}", e.Row.DBCampo("CvePS"), e.Row.DBCampo("CveUM"), e.Row.DBCampo("PS"), e.Row.DBCampo("CantidadF"), e.Row.DBCampo("Consec"), e.Row.DBCampo("Inv_CveMetodoInventario")) - e.Row.FCTextBox("TbCantidadF").Enabled = False - e.Row.FCCheckBox("cbInv").Enabled = False - If e.Row.DBCampo("Consec") <> "" AndAlso DtDatosDetalle IsNot Nothing Then - Dim Contador As Integer = DtDatosDetalle.FiltraParametros(String.Format("ConsecId = {0}", e.Row.DBCampo("Consec"))).Rows.Count - e.Row.FCTextBox("TbCantidadF").Text = Contador.ToString() - Else - e.Row.FCTextBox("TbCantidadF").Text = "0" - End If - - If TipoDocto = "DPe" Then - CveConsecSerie = e.Row.DBCampo("Consec").ToString().ToEntero() - PSSerie = e.Row.DBCampo("PS").ToString() - CvePSSerie = e.Row.DBCampo("CvePS").ToEntero() - CveUMSerie = e.Row.DBCampo("CveUM").ToEntero() - LbCantidad.Text = e.Row.DBCampo("CantidadF") - LbCantidad2.Text = e.Row.DBCampo("CantidadF") - AgregaSerie(e.Row.DBCampo("ObservacionesDetalle"), 3) - End If - - If TipoDocto = "Ing" AndAlso e.Row.DBCampo("ObservacionesDetalle").Length > 8 AndAlso DdlAlmacen.SelectedValue.ToEntero > 0 AndAlso UsuarioActual.CveRol = 1 Then - Dim Str As Array = e.Row.DBCampo("ObservacionesDetalle").Replace(",", " ").Replace(".", " ").Replace(vbTab, " ").Replace(vbLf, " ").Split(" "c) - CveConsecSerie = e.Row.DBCampo("Consec").ToString().ToEntero() - PSSerie = e.Row.DBCampo("PS").ToString() - CvePSSerie = e.Row.DBCampo("CvePS").ToEntero() - CveUMSerie = e.Row.DBCampo("CveUM").ToEntero() - LbCantidad.Text = e.Row.DBCampo("CantidadF") - LbCantidad2.Text = e.Row.DBCampo("CantidadF") - For Each st As String In Str - If Not st.Contiene("", "/") Then - AgregaSerie(st, 3) - End If - Next - - End If - - Else - e.Row.FCButton("BtnSerie").Visible = False - e.Row.FCTextBox("TbCantidadF").Enabled = True - e.Row.FCTextBox("TbCantidadF").Attributes.Add("onblur", String.Format("ValidarCantidad(this, {0})", e.Row.DBCampo("CantidadF"))) - End If - - - If CBool(e.Row.DBCampo("AplicaSeccion")) Then - e.Row.FCDropDownList("DdlSeccionAlmacen").Visible = True - If DdlAlmacen.SelectedValue.ToEntero() > 0 Then - CargaSeccionesAlmacen(e.Row.FCDropDownList("DdlSeccionAlmacen"), DdlAlmacen.SelectedValue.ToEntero(), e.Row.DBCampo("CvePS").ToEntero(), UsuarioActual.CveEmpresa, True) - End If - Else - e.Row.FCDropDownList("DdlSeccionAlmacen").Visible = False + Dim AplicaSerie As Boolean = CBool(e.Row.DBCampo("AplicaSerie")) + + If AplicaSerie Then + e.Row.FCButton("BtnSerie").Visible = True + e.Row.FCButton("BtnSerie").Text = "Serie" + e.Row.FCButton("BtnSerie").CommandArgument = String.Format("{0}°{1}°{2}°{3}°{4}°{5}", e.Row.DBCampo("CvePS"), e.Row.DBCampo("CveUM"), e.Row.DBCampo("PS"), e.Row.DBCampo("CantidadF"), e.Row.DBCampo("Consec"), e.Row.DBCampo("Inv_CveMetodoInventario")) + e.Row.FCTextBox("TbCantidadF").Enabled = False + e.Row.FCCheckBox("cbInv").Enabled = False + If e.Row.DBCampo("Consec") <> "" AndAlso DtDatosDetalle IsNot Nothing Then + Dim Contador As Integer = DtDatosDetalle.FiltraParametros(String.Format("ConsecId = {0}", e.Row.DBCampo("Consec"))).Rows.Count + e.Row.FCTextBox("TbCantidadF").Text = Contador.ToString() + Else + e.Row.FCTextBox("TbCantidadF").Text = "0" + End If + + If TipoDocto = "DPe" Then + CveConsecSerie = e.Row.DBCampo("Consec").ToString().ToEntero() + PSSerie = e.Row.DBCampo("PS").ToString() + CvePSSerie = e.Row.DBCampo("CvePS").ToEntero() + CveUMSerie = e.Row.DBCampo("CveUM").ToEntero() + LbCantidad.Text = e.Row.DBCampo("CantidadF") + LbCantidad2.Text = e.Row.DBCampo("CantidadF") + AgregaSerie(e.Row.DBCampo("ObservacionesDetalle"), 3) + End If + + If TipoDocto = "Ing" AndAlso e.Row.DBCampo("ObservacionesDetalle").Length > 8 AndAlso DdlAlmacen.SelectedValue.ToEntero > 0 AndAlso UsuarioActual.CveRol = 1 Then + Dim Str As Array = e.Row.DBCampo("ObservacionesDetalle").Replace(",", " ").Replace(".", " ").Replace(vbTab, " ").Replace(vbLf, " ").Split(" "c) + CveConsecSerie = e.Row.DBCampo("Consec").ToString().ToEntero() + PSSerie = e.Row.DBCampo("PS").ToString() + CvePSSerie = e.Row.DBCampo("CvePS").ToEntero() + CveUMSerie = e.Row.DBCampo("CveUM").ToEntero() + LbCantidad.Text = e.Row.DBCampo("CantidadF") + LbCantidad2.Text = e.Row.DBCampo("CantidadF") + For Each st As String In Str + If Not st.Contiene("", "/") Then + AgregaSerie(st, 3) + End If + Next + + End If + + Else + e.Row.FCButton("BtnSerie").Visible = False + e.Row.FCTextBox("TbCantidadF").Enabled = True + e.Row.FCTextBox("TbCantidadF").Attributes.Add("onblur", String.Format("ValidarCantidad(this, {0})", e.Row.DBCampo("CantidadF"))) End If - Dim DvFechaCaducidad As HtmlGenericControl = TryCast(e.Row.FindControl("DvFechaCaducidad"), HtmlGenericControl) - + + If CBool(e.Row.DBCampo("AplicaSeccion")) Then + e.Row.FCDropDownList("DdlSeccionAlmacen").Visible = True + If DdlAlmacen.SelectedValue.ToEntero() > 0 Then + CargaSeccionesAlmacen(e.Row.FCDropDownList("DdlSeccionAlmacen"), DdlAlmacen.SelectedValue.ToEntero(), e.Row.DBCampo("CvePS").ToEntero(), UsuarioActual.CveEmpresa, True) + End If + Else + e.Row.FCDropDownList("DdlSeccionAlmacen").Visible = False + End If + + Dim DvFechaCaducidad As HtmlGenericControl = TryCast(e.Row.FindControl("DvFechaCaducidad"), HtmlGenericControl) + If CBool(e.Row.DBCampo("AplicaCaducidad")) Then DvFechaCaducidad.Visible = True ' e.Row.FCTextBox("TxtCaducidad").Visible = True 'e.Row.FCLinkButton("LnkCaducidad").Visible = True - e.Row.FCTextBox("TxtCaducidad").ReadOnly = True - 'CType(e.Row.FindControl("RFVCaducidad"), RequiredFieldValidator).Enabled = False - - 'si aplica caducidad y viene vacía (posible por venta anterior), que se active su registro - If (e.Row.FCTextBox("TxtCaducidad").Text = "" OrElse e.Row.FCTextBox("TxtCaducidad").Text.ToDate <= MinFecha) OrElse UsuarioActual.TienePermisoProceso(364) OrElse UsuarioActual.Empresa.Funcionalidad(578).ToEntero = 1 Then - e.Row.FCTextBox("TxtCaducidad").ReadOnly = False - 'CType(e.Row.FindControl("RFVCaducidad"), RequiredFieldValidator).Enabled = True - 'e.Row.FCTextBox("TxtCaducidad").Enabled = True - End If - - Else - 'e.Row.FCTextBox("TxtCaducidad").Visible = False - 'e.Row.FCLinkButton("LnkCaducidad").Visible = False - 'e.Row.FCTextBox("TxtCaducidad").Enabled = True - DvFechaCaducidad.Visible = False - End If - - If CBool(e.Row.DBCampo("AplicaLote")) Then - e.Row.FCTextBox("TxtLote").Visible = True - 'si aplica caducidad y viene vacía (posible por venta anterior), que se active su registro - If e.Row.FCTextBox("TxtLote").Text = "" OrElse UsuarioActual.TienePermisoProceso(364) OrElse UsuarioActual.Empresa.Funcionalidad(578).ToEntero = 1 Then - e.Row.FCTextBox("TxtLote").ReadOnly = False - e.Row.FCTextBox("TxtLote").Enabled = True - Else - e.Row.FCTextBox("TxtLote").ReadOnly = True - End If - Else - e.Row.FCTextBox("TxtLote").Visible = False + e.Row.FCTextBox("TxtCaducidad").ReadOnly = True + 'CType(e.Row.FindControl("RFVCaducidad"), RequiredFieldValidator).Enabled = False + + 'si aplica caducidad y viene vacía (posible por venta anterior), que se active su registro + If (e.Row.FCTextBox("TxtCaducidad").Text = "" OrElse e.Row.FCTextBox("TxtCaducidad").Text.ToDate <= MinFecha) OrElse UsuarioActual.TienePermisoProceso(364) OrElse UsuarioActual.Empresa.Funcionalidad(578).ToEntero = 1 Then + e.Row.FCTextBox("TxtCaducidad").ReadOnly = False + 'CType(e.Row.FindControl("RFVCaducidad"), RequiredFieldValidator).Enabled = True + 'e.Row.FCTextBox("TxtCaducidad").Enabled = True + End If + + Else + 'e.Row.FCTextBox("TxtCaducidad").Visible = False + 'e.Row.FCLinkButton("LnkCaducidad").Visible = False + 'e.Row.FCTextBox("TxtCaducidad").Enabled = True + DvFechaCaducidad.Visible = False End If - e.Row.FCButton("BtnDividir").Attributes.Add("onclick", String.Format("Dividir('{0}');", e.Row.FCTextBox("TxtDividir").ClientID)) - e.Row.FCButton("BtnDividir").CommandArgument = e.Row.RowIndex.ToString() - e.Row.FCTextBox("TxtDividir").Attributes.Add("onkeyup", String.Format("LimitaCantidad({0},this,'{1}');", e.Row.DBCampo("CantidadF"), e.Row.FCButton("BtnDividir").ClientID)) - - - 'FUNCIONALIDAD PISTOLA DE CODIGOS - If e.Row.DBCampo("CodigoBarras").Trim <> "" AndAlso UsuarioActual.Empresa.Funcionalidad(132) = "1" Then - - 'NO BLOQUEA PARA ROL AD - If UsuarioActual.CveRol = 1 Then - If AplicaSerie Then - e.Row.FCTextBox("TbCantidadF").Enabled = False - e.Row.FCTextBox("TbCantidadF").Text = "0" - Else - e.Row.FCTextBox("TbCantidadF").Text = e.Row.DBCampo("CantidadF").ToDecimal.ToString("#,##0.######") - End If - End If - - If UsuarioActual.Empresa.Funcionalidad(531) = "1" Then 'acumuladoras - If e.Row.DBCampo("CveCategoria") <> "249" Then - e.Row.FCTextBox("TbCantidadF").Enabled = True - End If - Else - If Not UsuarioActual.CveRol = 1 Then - e.Row.FCTextBox("TbCantidadF").Enabled = False - e.Row.FCTextBox("TbCantidadF").Text = "0" - End If - End If - End If - - 'SI ES TRASPASO OBLIGATORIO SURTIR TODO - If TipoEntrega = 2 Then - e.Row.FCCheckBox("cbInv").Enabled = False + If CBool(e.Row.DBCampo("AplicaLote")) Then + e.Row.FCTextBox("TxtLote").Visible = True + 'si aplica caducidad y viene vacía (posible por venta anterior), que se active su registro + If e.Row.FCTextBox("TxtLote").Text = "" OrElse UsuarioActual.TienePermisoProceso(364) OrElse UsuarioActual.Empresa.Funcionalidad(578).ToEntero = 1 Then + e.Row.FCTextBox("TxtLote").ReadOnly = False + e.Row.FCTextBox("TxtLote").Enabled = True + Else + e.Row.FCTextBox("TxtLote").ReadOnly = True + End If + Else + e.Row.FCTextBox("TxtLote").Visible = False + End If + + e.Row.FCButton("BtnDividir").Attributes.Add("onclick", String.Format("Dividir('{0}');", e.Row.FCTextBox("TxtDividir").ClientID)) + e.Row.FCButton("BtnDividir").CommandArgument = e.Row.RowIndex.ToString() + e.Row.FCTextBox("TxtDividir").Attributes.Add("onkeyup", String.Format("LimitaCantidad({0},this,'{1}');", e.Row.DBCampo("CantidadF"), e.Row.FCButton("BtnDividir").ClientID)) + + + 'FUNCIONALIDAD PISTOLA DE CODIGOS + If e.Row.DBCampo("CodigoBarras").Trim <> "" AndAlso UsuarioActual.Empresa.Funcionalidad(132) = "1" Then + + 'NO BLOQUEA PARA ROL AD + If UsuarioActual.CveRol = 1 Then + If AplicaSerie Then + e.Row.FCTextBox("TbCantidadF").Enabled = False + e.Row.FCTextBox("TbCantidadF").Text = "0" + Else + e.Row.FCTextBox("TbCantidadF").Text = e.Row.DBCampo("CantidadF").ToDecimal.ToString("#,##0.######") + End If + End If + + If UsuarioActual.Empresa.Funcionalidad(531) = "1" Then 'acumuladoras + If e.Row.DBCampo("CveCategoria") <> "249" Then + e.Row.FCTextBox("TbCantidadF").Enabled = True + End If + Else + If Not UsuarioActual.CveRol = 1 Then + e.Row.FCTextBox("TbCantidadF").Enabled = False + e.Row.FCTextBox("TbCantidadF").Text = "0" + End If + End If + End If + + 'SI ES TRASPASO OBLIGATORIO SURTIR TODO + If TipoEntrega = 2 Then + e.Row.FCCheckBox("cbInv").Enabled = False End If If BloqueCantidad Then @@ -1285,7 +1285,7 @@ Partial Class Inventarios_EntregaAlmacen End If - End If + End If End Sub Protected Sub DdlCaducidadProducto_SelectedIndexChanged(sender As Object, e As EventArgs) @@ -1342,698 +1342,698 @@ Partial Class Inventarios_EntregaAlmacen DdlLoteFechaCaducidad.SelectedValueExist(ValorAsignado) End If - End Sub - - Private Sub CargaDocumentos(tCveVenta As Integer) - If tCveVenta > 0 Then - Dim objInv As New ClsEdocumentacion - - If objInv.DocumentacionElectronicaGet(-1, -1, -1, UsuarioActual.CveEmpresa, -1, tCveVenta) Then - GvDocs.DataSource = objInv.DtResultados.FiltraParametros("Adjunto <> ''") - End If - objInv.Dispose() - GvDocs.DataBind() - End If - + End Sub + + Private Sub CargaDocumentos(tCveVenta As Integer) + If tCveVenta > 0 Then + Dim objInv As New ClsEdocumentacion + + If objInv.DocumentacionElectronicaGet(-1, -1, -1, UsuarioActual.CveEmpresa, -1, tCveVenta) Then + GvDocs.DataSource = objInv.DtResultados.FiltraParametros("Adjunto <> ''") + End If + objInv.Dispose() + GvDocs.DataBind() + End If + End Sub -#End Region +#End Region -#Region " AGREGAR " +#Region " AGREGAR " + + Protected Sub BtnSerie_Click(sender As Object, e As EventArgs) + + Dim Argumentos As String() = CType(sender, Button).CommandArgument.Split("°"c) + + LbProducto.Text = Argumentos(2) + LbCantidad.Text = Argumentos(3) + + LbProducto2.Text = Argumentos(2) + LbCantidad2.Text = Argumentos(3) + + CvePSSerie = Argumentos(0).ToEntero() + CveUMSerie = Argumentos(1).ToEntero() + PSSerie = Argumentos(2).ToString() + CveConsecSerie = Argumentos(4).ToEntero() + CveMetodoInventario = Argumentos(5).ToEntero() + + If CveMetodoInventario = 6 Then + RegistraScript("$('#DivLote').modal({backdrop: 'static', keyboard: false});") + CargaLote() + UpLoteBatch.Update() + Else + RegistraScript("$('#DivSerie').modal({backdrop: 'static', keyboard: false});") + CargaSerie() + UpSerie.Update() + End If - Protected Sub BtnSerie_Click(sender As Object, e As EventArgs) - - Dim Argumentos As String() = CType(sender, Button).CommandArgument.Split("°"c) - - LbProducto.Text = Argumentos(2) - LbCantidad.Text = Argumentos(3) - - LbProducto2.Text = Argumentos(2) - LbCantidad2.Text = Argumentos(3) - - CvePSSerie = Argumentos(0).ToEntero() - CveUMSerie = Argumentos(1).ToEntero() - PSSerie = Argumentos(2).ToString() - CveConsecSerie = Argumentos(4).ToEntero() - CveMetodoInventario = Argumentos(5).ToEntero() - - If CveMetodoInventario = 6 Then - RegistraScript("$('#DivLote').modal({backdrop: 'static', keyboard: false});") - CargaLote() - UpLoteBatch.Update() - Else - RegistraScript("$('#DivSerie').modal({backdrop: 'static', keyboard: false});") - CargaSerie() - UpSerie.Update() - End If - End Sub -#Region " AGREGA POR SERIE/LOTE " +#Region " AGREGA POR SERIE/LOTE " - Private Sub CreaDtDetalle() - If DtDatosDetalle Is Nothing Then - DtDatosDetalle = New DataTable - DtDatosDetalle.Columns.Add("CveVentaDetalle", GetType(Integer)) - DtDatosDetalle.Columns.Add("Consec", GetType(Integer)) - DtDatosDetalle.Columns.Add("ConsecId", GetType(Integer)) - DtDatosDetalle.Columns.Add("CvePS", GetType(Integer)) - DtDatosDetalle.Columns.Add("PS", GetType(String)) - DtDatosDetalle.Columns.Add("CveUM", GetType(Integer)) - DtDatosDetalle.Columns.Add("Serie", GetType(String)) - DtDatosDetalle.Columns.Add("Lote", GetType(String)) - DtDatosDetalle.Columns.Add("FechaCaducidad", GetType(Date)) - DtDatosDetalle.Columns.Add("FueTraspaso", GetType(Integer)) - End If - End Sub - Private Sub CargaSerie(Optional CerrarCompletado As Boolean = False, Optional CargaMasivo As Boolean = False) - - If Not CargaMasivo Then RegistraScript("$('#DivSerie').modal({backdrop: 'static', keyboard: false})", "show") - - Dim AplicaCaducidad As Boolean = False - Dim dttt As DataTable = GlobalDTPSSimplificado(UsuarioActual.CveEmpresa, CvePS:=CvePSSerie) - If dttt IsNot Nothing AndAlso dttt.Rows.Count > 0 Then - AplicaCaducidad = If(dttt.FiltraParametros("").Rows(0)("AplicaCaducidad").ToString() = "True", True, False) - End If - - GvSerie.Columns(1).HeaderText = UsuarioActual.Empresa.Funcionalidad(147) - - If AplicaCaducidad Then - GvSerie.Columns(1).Visible = True - TdCaducidad1.Visible = True - TdCaducidad2.Visible = True - Else - GvSerie.Columns(1).Visible = False - TdCaducidad1.Visible = False - TdCaducidad2.Visible = False - End If - - GvSerie.DataSource = DtDatosDetalle.FiltraParametros(String.Format("ConsecId = {0}", CveConsecSerie), "Consec DESC") - GvSerie.DataBind() - - 'SERIE LOTE RECOMENDADO - Dim DtSerie As New DataTable - If TipoMovimiento = 1 AndAlso Not CargaMasivo Then - Dim ObjInventarios As New ClsInventarios - If ObjInventarios.SerieRecomendadoGet(CvePSSerie, UsuarioActual.CveEmpresa, DdlAlmacen.SelectedValue.ToEntero(), CveSubProyecto:=CveSubProyecto, CveCliente:=CveCliente, CveVendedor:=CveVendedor) Then - DtSerie = ObjInventarios.DtResultados - End If - ObjInventarios.Dispose() - Else - DtSerie = DtExistencias.FiltraParametros("Serie <> ''") - End If - 'SERIE LOTE RECOMENDADO - QUITA YA COMPLETADOS EN EL CLIENTE - If DtSerie IsNot Nothing AndAlso DtSerie.Rows.Count > 0 Then - 'CALCULA YA COMPLETADOS - Dim DrsRemove As New List(Of DataRow) - DtSerie.Columns.Add("CantidadSeleccionada", GetType(Integer)) - For Each dr As DataRow In DtSerie.Rows - dr("CantidadSeleccionada") = DtDatosDetalle.FiltraParametros(String.Format("Consec = {0} AND Serie = '{1}'", CveConsecSerie, dr("Serie").ToString().Replace("'", "''"))).Rows.Count - If dr("CantidadSeleccionada").ToString().ToDecimal = dr("Existencia").ToString().ToDecimal Then - DrsRemove.Add(dr) - End If - Next - - 'ELIMINA YA COMPLETADOS EN PAGINA - For Each dr As DataRow In DrsRemove - DtSerie.Rows.Remove(dr) - Next - - If DtSerie.Rows.Count > 0 Then - Dim Mensaje As New StringBuilder - Mensaje.AppendFormat("Serie Recomendado: {0}", DtSerie.Rows(0)("Serie")) - - If AplicaCaducidad Then Mensaje.AppendFormat(", Caducidad: {0}", DtSerie.Rows(0)("FechaCaducidad").ToString().ToDate.ToShortDateString) - LbSerieRecomendado.Text = Mensaje.ToString() 'String.Format("Serie / Lote Recomendado: {0}, Caducicdad: {1}", ObjInventarios.DtResultados.Rows(0)("SerieLote"), ObjInventarios.DtResultados.Rows(0)("FechaCaducidad").ToString().ToDate.ToShortDateString) - Else - LbSerieRecomendado.Text = "No se encontro ningun Serie/Lote." - End If - Else - LbSerieRecomendado.Text = "No se encontro ningun Serie/Lote." - End If - - 'SI TIENE SALIDA POR SERIE LOTE, BLOQUEAMOS CHECK Y TXTCANTIDAD - Dim Contador As Integer = 0 - For Each Gvr As GridViewRow In GvDatos.Rows - If Gvr.DataKey("AplicaSerie") = "True" Then - Contador = DtDatosDetalle.FiltraParametros(String.Format("ConsecId = {0}", Gvr.DataKey("Consec"))).Rows.Count - Gvr.FCCheckBox("cbInv").Enabled = False - Gvr.FCCheckBox("cbInv").Checked = True - Gvr.FCTextBox("TbCantidadF").Text = Contador.ToString() - End If - Next - UpDatos.Update() - - 'VALIDA QUE SIGA AGREGANDO - If DtDatosDetalle.FiltraParametros(String.Format("ConsecId = {0}", CveConsecSerie)).Rows.Count = LbCantidad.Text.ToEntero() Then - BtnAgregarPS.Enabled = False - If CerrarCompletado Then - RegistraScript("$('#DivSerie').modal('hide')", "hide") - End If - UpSerie.Update() - Exit Sub - Else - BtnAgregarPS.Enabled = True - UpSerie.Update() - End If - - End Sub - - Protected Sub BtnAgregarPS_Click(sender As Object, e As EventArgs) - If TxtSerie.Text.Trim.Length >= 2 AndAlso TxtSerie.Text.Trim.StartsWith("*") AndAlso TxtSerie.Text.Trim.EndsWith("*") Then - Dim ArraySeries() As String = Nothing - Dim Series As String = Nothing - - Series = TxtSerie.Text.Trim - Series = Series.Replace("*", "") - ArraySeries = Series.Trim.Split(","c) - - For i As Integer = 0 To ArraySeries.Length - 1 - If ArraySeries(i).Trim.Length > 1 Then AgregaSerie(ArraySeries(i).Trim, 1, True) - Next - Else - AgregaSerie(TxtSerie.Text.Trim, 1) - End If - End Sub - - Private Sub AgregaSerie(Serie As String, Tipo As Integer, Optional CargaMasivo As Boolean = False) - - If Serie.Trim = "" Then - Alert("El campo 'Serie' es obligatorio. Por favor rectifique y vuelva a intentar.", TipoMensaje.MsgAdvertencia) - Exit Sub - End If - - If Serie.Trim.Length < 6 Then - Alert("El campo 'Serie' debe tener minimo 6 caracteres. Por favor rectifique y vuelva a intentar.", TipoMensaje.MsgAdvertencia) - Exit Sub - End If - - If DtDatosDetalle.FiltraParametros($"CvePS = {CvePSSerie} AND Serie = '{Serie}'").Rows.Count > 0 Then - Alert("La Serie indicada ya esta registrada. Por favor rectifique y vuelva a intentar.", TipoMensaje.MsgAdvertencia) - RegistraScript("playsonidito('142608__autistic-lucario__error.wav')", "Error1") - TxtSerie.Text = "" - Exit Sub - End If - - Dim AplicaCaducidad As Boolean = GlobalDTPSSimplificado(UsuarioActual.CveEmpresa, CvePS:=CvePSSerie).FiltroPrimeroValor("AplicaCaducidad", "") = "True" - 'If GlobalDTPSSimplificado(UsuarioActual.CveEmpresa, CvePS:=CvePSSerie).FiltraParametros("").Rows(0) IsNot Nothing Then - ' AplicaCaducidad = If(GlobalDTPS(UsuarioActual.CveEmpresa, CvePS:=CvePSSerie).FiltraParametros("").Rows(0)("AplicaCaducidad").ToString() = "True", True, False) - 'End If - - - 'Valida Existencia - If TipoMovimiento = 1 Then - Dim ObjInventarios As New ClsInventarios - Dim Existencia As Decimal = ObjInventarios.GetExistenciasPS(CvePSSerie, CveUMSerie, UsuarioActual.CveEmpresa, DdlAlmacen.SelectedValue.ToEntero(), FechaMovto:=TxtFecha.Text.ToDateTime.ToString("yyyy/MM/dd HH:mm"), Serie:=Serie, CveVendedor:=CveVendedor, CveSubProyecto:=CveSubProyecto, CveCliente:=If(UsuarioActual.Empresa.Funcionalidad(146) = "1", -1, CveCliente), ExcluyeApartados:=If(TipoEntrega = 2, 1, -1)) - If Existencia < 1 Then - Alert($"No hay existencia suficiente del producto ""{PSSerie}"" con la Serie definida ""{Serie}"". Por favor rectifique y vuelva a intentar", TipoMensaje.MsgAdvertencia, If(Tipo = 2, "window.setTimeout(Focus,200);", "")) - RegistraScript("playsonidito('142608__autistic-lucario__error.wav')", "Error2") - ObjInventarios.Dispose() - Exit Sub - End If - ObjInventarios.Dispose() - Else - If DtExistencias IsNot Nothing Then - Dim Existencia As Decimal = DtExistencias.SUMD("Cantidad", $"CvePS = {CvePSSerie} AND CveUM = {CveUMSerie} AND Serie = '{Serie}'") - If Existencia < 1 Then - Alert($"No hay existencia suficiente del producto ""{PSSerie}"" con la Serie definida ""{Serie}"". Por favor rectifique y vuelva a intentar", TipoMensaje.MsgAdvertencia, If(Tipo = 2, "window.setTimeout(Focus,200);", "")) - RegistraScript("playsonidito('142608__autistic-lucario__error.wav')", "Error3") - Exit Sub - End If - End If - End If - - Dim Row As DataRow = DtDatosDetalle.NewRow - - Row("ConsecId") = CveConsecSerie - Row("Consec") = DtDatosDetalle.Rows.Count + 1 - Row("PS") = PSSerie - Row("CvePS") = CvePSSerie - Row("CveUM") = CveUMSerie - Row("Serie") = Serie - Row("FechaCaducidad") = If(AplicaCaducidad, TxtFechaCaducidad.Text, MinFecha.ToShortDateString) - - DtDatosDetalle.Rows.Add(Row) - ActualizaBitacora() - RegistraScript("playsonidito('beep-07.wav')", "Sonidito") - - If Tipo = 1 Then - TxtSerie.Text = "" - TxtFechaCaducidad.Text = "" - End If - - If Tipo < 3 Then - CargaSerie(True, CargaMasivo) - End If - - End Sub - - Protected Sub GvSerie_RowDeleting(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewDeleteEventArgs) Handles GvSerie.RowDeleting - - Dim keySerie As String = e.Keys("Serie").ToString() - Try - For Each dr As DataRow In DtDatosDetalle.Rows - If dr("Serie").ToString() = keySerie Then - dr.Delete() - End If - Next - Catch ex As Exception - - End Try - - DtDatosDetalle.AcceptChanges() - ActualizaBitacora() - CargaSerie() - + Private Sub CreaDtDetalle() + If DtDatosDetalle Is Nothing Then + DtDatosDetalle = New DataTable + DtDatosDetalle.Columns.Add("CveVentaDetalle", GetType(Integer)) + DtDatosDetalle.Columns.Add("Consec", GetType(Integer)) + DtDatosDetalle.Columns.Add("ConsecId", GetType(Integer)) + DtDatosDetalle.Columns.Add("CvePS", GetType(Integer)) + DtDatosDetalle.Columns.Add("PS", GetType(String)) + DtDatosDetalle.Columns.Add("CveUM", GetType(Integer)) + DtDatosDetalle.Columns.Add("Serie", GetType(String)) + DtDatosDetalle.Columns.Add("Lote", GetType(String)) + DtDatosDetalle.Columns.Add("FechaCaducidad", GetType(Date)) + DtDatosDetalle.Columns.Add("FueTraspaso", GetType(Integer)) + End If End Sub -#End Region -#Region "Bitacora" - Private Sub ActualizaBitacora(Optional Eliminar As Boolean = False) - If Not Eliminar Then - DtDatos.TableName = "DtDatos" - DtDatosDetalle.TableName = "DtDatosDetalle" - DtDatos.WriteXml(ArchivoBitacora, XmlWriteMode.WriteSchema) - DtDatosDetalle.WriteXml(ArchivoBitacoraDetalle, XmlWriteMode.WriteSchema) - Else - File.Delete(ArchivoBitacora) - End If - - End Sub - - Protected Sub HplCargaBitacora_Click(sender As Object, e As EventArgs) - - CargaBitacora = False - If IO.File.Exists(ArchivoBitacora) Then - - CargaBitacoraSerie() - CargaGvDatos() - CargaBitacora = True - Else - Alert("No hay bitácora para recuperar.", TipoMensaje.ToastInformacion) - End If - - End Sub - - Private Sub CargaBitacoraSerie() - - If IO.File.Exists(ArchivoBitacora) Then - - DtDatos.ReadXml(ArchivoBitacora) - If IO.File.Exists(ArchivoBitacoraDetalle) Then - Dim dtt As New DataTable - dtt.ReadXml(ArchivoBitacoraDetalle) - DtDatosDetalle = dtt - Alert("Registro(s) Recuperados", TipoMensaje.ToastInformacion) - - End If - Else - Alert("No hay bitácora para recuperar.", TipoMensaje.ToastInformacion) - End If + Private Sub CargaSerie(Optional CerrarCompletado As Boolean = False, Optional CargaMasivo As Boolean = False) + + If Not CargaMasivo Then RegistraScript("$('#DivSerie').modal({backdrop: 'static', keyboard: false})", "show") + + Dim AplicaCaducidad As Boolean = False + Dim dttt As DataTable = GlobalDTPSSimplificado(UsuarioActual.CveEmpresa, CvePS:=CvePSSerie) + If dttt IsNot Nothing AndAlso dttt.Rows.Count > 0 Then + AplicaCaducidad = If(dttt.FiltraParametros("").Rows(0)("AplicaCaducidad").ToString() = "True", True, False) + End If + + GvSerie.Columns(1).HeaderText = UsuarioActual.Empresa.Funcionalidad(147) + + If AplicaCaducidad Then + GvSerie.Columns(1).Visible = True + TdCaducidad1.Visible = True + TdCaducidad2.Visible = True + Else + GvSerie.Columns(1).Visible = False + TdCaducidad1.Visible = False + TdCaducidad2.Visible = False + End If + + GvSerie.DataSource = DtDatosDetalle.FiltraParametros(String.Format("ConsecId = {0}", CveConsecSerie), "Consec DESC") + GvSerie.DataBind() + + 'SERIE LOTE RECOMENDADO + Dim DtSerie As New DataTable + If TipoMovimiento = 1 AndAlso Not CargaMasivo Then + Dim ObjInventarios As New ClsInventarios + If ObjInventarios.SerieRecomendadoGet(CvePSSerie, UsuarioActual.CveEmpresa, DdlAlmacen.SelectedValue.ToEntero(), CveSubProyecto:=CveSubProyecto, CveCliente:=CveCliente, CveVendedor:=CveVendedor) Then + DtSerie = ObjInventarios.DtResultados + End If + ObjInventarios.Dispose() + Else + DtSerie = DtExistencias.FiltraParametros("Serie <> ''") + End If + 'SERIE LOTE RECOMENDADO - QUITA YA COMPLETADOS EN EL CLIENTE + If DtSerie IsNot Nothing AndAlso DtSerie.Rows.Count > 0 Then + 'CALCULA YA COMPLETADOS + Dim DrsRemove As New List(Of DataRow) + DtSerie.Columns.Add("CantidadSeleccionada", GetType(Integer)) + For Each dr As DataRow In DtSerie.Rows + dr("CantidadSeleccionada") = DtDatosDetalle.FiltraParametros(String.Format("Consec = {0} AND Serie = '{1}'", CveConsecSerie, dr("Serie").ToString().Replace("'", "''"))).Rows.Count + If dr("CantidadSeleccionada").ToString().ToDecimal = dr("Existencia").ToString().ToDecimal Then + DrsRemove.Add(dr) + End If + Next + + 'ELIMINA YA COMPLETADOS EN PAGINA + For Each dr As DataRow In DrsRemove + DtSerie.Rows.Remove(dr) + Next + + If DtSerie.Rows.Count > 0 Then + Dim Mensaje As New StringBuilder + Mensaje.AppendFormat("Serie Recomendado: {0}", DtSerie.Rows(0)("Serie")) + + If AplicaCaducidad Then Mensaje.AppendFormat(", Caducidad: {0}", DtSerie.Rows(0)("FechaCaducidad").ToString().ToDate.ToShortDateString) + LbSerieRecomendado.Text = Mensaje.ToString() 'String.Format("Serie / Lote Recomendado: {0}, Caducicdad: {1}", ObjInventarios.DtResultados.Rows(0)("SerieLote"), ObjInventarios.DtResultados.Rows(0)("FechaCaducidad").ToString().ToDate.ToShortDateString) + Else + LbSerieRecomendado.Text = "No se encontro ningun Serie/Lote." + End If + Else + LbSerieRecomendado.Text = "No se encontro ningun Serie/Lote." + End If + + 'SI TIENE SALIDA POR SERIE LOTE, BLOQUEAMOS CHECK Y TXTCANTIDAD + Dim Contador As Integer = 0 + For Each Gvr As GridViewRow In GvDatos.Rows + If Gvr.DataKey("AplicaSerie") = "True" Then + Contador = DtDatosDetalle.FiltraParametros(String.Format("ConsecId = {0}", Gvr.DataKey("Consec"))).Rows.Count + Gvr.FCCheckBox("cbInv").Enabled = False + Gvr.FCCheckBox("cbInv").Checked = True + Gvr.FCTextBox("TbCantidadF").Text = Contador.ToString() + End If + Next + UpDatos.Update() + + 'VALIDA QUE SIGA AGREGANDO + If DtDatosDetalle.FiltraParametros(String.Format("ConsecId = {0}", CveConsecSerie)).Rows.Count = LbCantidad.Text.ToEntero() Then + BtnAgregarPS.Enabled = False + If CerrarCompletado Then + RegistraScript("$('#DivSerie').modal('hide')", "hide") + End If + UpSerie.Update() + Exit Sub + Else + BtnAgregarPS.Enabled = True + UpSerie.Update() + End If + End Sub -#End Region -#Region " AGREGA CON LOTE BATCH " + Protected Sub BtnAgregarPS_Click(sender As Object, e As EventArgs) + If TxtSerie.Text.Trim.Length >= 2 AndAlso TxtSerie.Text.Trim.StartsWith("*") AndAlso TxtSerie.Text.Trim.EndsWith("*") Then + Dim ArraySeries() As String = Nothing + Dim Series As String = Nothing - Private Sub CreaDtDetalleLote() - If DtDatosDetalleLote Is Nothing Then - DtDatosDetalleLote = New DataTable - DtDatosDetalleLote.Columns.Add("CveVentaDetalle", GetType(Integer)) - DtDatosDetalleLote.Columns.Add("Consec", GetType(Integer)) - DtDatosDetalleLote.Columns.Add("ConsecId", GetType(Integer)) - DtDatosDetalleLote.Columns.Add("Cantidad", GetType(Double)) - DtDatosDetalleLote.Columns.Add("CvePS", GetType(Integer)) - DtDatosDetalleLote.Columns.Add("PS", GetType(String)) - DtDatosDetalleLote.Columns.Add("CveUM", GetType(Integer)) - DtDatosDetalleLote.Columns.Add("Lote", GetType(String)) - DtDatosDetalleLote.Columns.Add("FechaCaducidad", GetType(String)) - DtDatosDetalleLote.Columns.Add("FueTraspaso", GetType(Integer)) - End If - End Sub - Private Sub CargaLote(Optional CerrarCompletado As Boolean = False) - - RegistraScript("$('#DivLote').modal({backdrop: 'static', keyboard: false})") - GvLote.Columns(2).HeaderText = UsuarioActual.Empresa.Funcionalidad(147) - GvLote.DataSource = DtDatosDetalleLote.FiltraParametros(String.Format("ConsecId = {0}", CveConsecSerie), "Consec DESC") - GvLote.DataBind() - - 'VALIDA QUE SIGA AGREGANDO - If DtDatosDetalleLote.SUM("Cantidad", String.Format("ConsecId = {0}", CveConsecSerie)) = LbCantidad2.Text.ToDecimal Then - BtnLote.Enabled = False - If CerrarCompletado Then - RegistraScript("$('#DivLote').modal('hide')", "hide") - End If - Else - BtnLote.Enabled = True - End If - - 'LOTE RECOMENDADO - Dim DtLotes As New DataTable - If TipoMovimiento = 1 Then - Dim ObjInventarios As New ClsInventarios - If ObjInventarios.LoteRecomendadoGet(CvePSSerie, UsuarioActual.CveEmpresa, DdlAlmacen.SelectedValue.ToEntero()) Then - DtLotes = ObjInventarios.DtResultados - End If - ObjInventarios.Dispose() - Else - DtLotes = DtExistencias.FiltraParametros("Lote <> ''") - End If - - Dim DrsRemove As New List(Of DataRow) - - If DtLotes.Rows.Count > 0 Then - 'CALCULA YA COMPLETADOS - DtLotes.Columns.Add("CantidadSeleccionada", GetType(Integer)) - For Each dr As DataRow In DtLotes.Rows - dr("CantidadSeleccionada") = DtDatosDetalleLote.SUM("Cantidad", String.Format("Consec = {0} AND Lote = '{1}'", CveConsecSerie, dr("Lote"))) - If dr("CantidadSeleccionada").ToString().ToDecimal = dr("Existencia").ToString().ToDecimal Then - DrsRemove.Add(dr) - End If - Next - - 'ELIMINA YA COMPLETADOS EN PAGINA - For Each dr As DataRow In DrsRemove - DtLotes.Rows.Remove(dr) - Next - - If DtLotes.Rows.Count > 0 Then - Dim Mensaje As New StringBuilder - Mensaje.AppendFormat("Recomendado: Existencia: {0} Lote: {1} Fecha Caducidad: {2} ", DtLotes.Rows(0)("Existencia").ToString().FormatoNumero, DtLotes.Rows(0)("Lote"), DtLotes.Rows(0)("FechaCaducidad").ToString().ToDate.ToShortDateString) - LbLoteRecomendado.Text = Mensaje.ToString() - Else - LbLoteRecomendado.Text = "No se encontro ningún Lote recomendado." - End If - Else - LbLoteRecomendado.Text = "No se encontro ningún Lote recomendado." - End If - - - 'SI TIENE SALIDA POR LOTE, BLOQUEAMOS CHECK Y TXTCANTIDAD - Dim Contador As Decimal = 0 - For Each Gvr As GridViewRow In GvDatos.Rows - If Gvr.DataKey("CvePS").ToEntero() = CvePSSerie Then - Contador = DtDatosDetalleLote.SUM("Cantidad", String.Format("ConsecId = {0}", Gvr.DataKey("Consec"))) - Gvr.FCCheckBox("cbInv").Enabled = False - Gvr.FCCheckBox("cbInv").Checked = True - Gvr.FCTextBox("TbCantidadF").Text = Contador.ToString().FormatoNumero - End If - Next - - RVCantidadLote.MaximumValue = (If((LbCantidad2.Text.ToDecimal - Contador) = 0, 0.02, LbCantidad2.Text.ToDecimal - Contador)).ToString().FormatoNumero - - TxtCantidadLote.Text = "1" - TxtLote.Text = "" - TxtBatch.Text = "" - TxtLote.Focus() - - UpLoteBatch.Update() - UpDatos.Update() - - End Sub - - Protected Sub BtnAgregarPS2_Click(sender As Object, e As EventArgs) - AgregaLote(TxtLote.Text.Trim, TxtBatch.Text.Trim, 1) - End Sub - Private Sub AgregaLote(Lote As String, Batch As String, Tipo As Integer) - - If Lote = "" Then - Alert("El campo Lote es obligatorio. Por favor rectifique y vuelva a intentar.", TipoMensaje.MsgAdvertencia) - Exit Sub - End If - - 'VALIDACION DE SERIES DUPLICADAS - Dim MensajeAlert As New StringBuilder - Dim DtDuplicado As New DataTable - Dim DtSeriesNuevas As New DataTable - DtSeriesNuevas.Columns.Add("Serie", GetType(String)) - - DtDuplicado = DtDatosDetalleLote.FiltraParametros($"ConsecId = {CveConsecSerie} AND Lote = '{Lote}' AND Batch = '{Batch}'") - If DtDuplicado IsNot Nothing AndAlso DtDuplicado.Rows.Count > 0 Then - Alert($"
    El numero de Lote ""{Lote}"" y Batch = '{Batch}' proporcionado ya se encuentra ingresado.", TipoMensaje.MsgAdvertencia) - RegistraScript("playsonidito('142608__autistic-lucario__error.wav')") - Exit Sub - End If - - Dim Row As DataRow = DtDatosDetalleLote.NewRow - Dim CantidadLote As Decimal = TxtCantidadLote.Text.ToDecimal - - Dim MensajeSinExistencias As New StringBuilder - Dim ObjInventarios As New ClsInventarios - - 'VERIFICA EXISTENCIAS - If TipoMovimiento = 1 Then - Dim Existencia As Decimal = ObjInventarios.GetExistenciasPS(CvePSSerie, CveUMSerie, UsuarioActual.CveEmpresa, DdlAlmacen.SelectedValue.ToEntero(), FechaMovto:=TxtFecha.Text.ToDateTime.ToString("yyyy/MM/dd HH:mm"), CveVendedor:=CveVendedor, CveSubProyecto:=CveSubProyecto, CveCliente:=If(UsuarioActual.Empresa.Funcionalidad(146) = "1", -1, CveCliente), Lote:=Lote, ExcluyeApartados:=If(TipoEntrega = 2, 1, -1)) - If Existencia < CantidadLote Then - Alert($"No hay existencia suficiente del producto ""{PSSerie}"" con el lote definido ""{Lote}"" y el batch ""{Batch}"". Por favor rectifique y vuelva a intentar", TipoMensaje.MsgAdvertencia) - RegistraScript("playsonidito('142608__autistic-lucario__error.wav')") - ObjInventarios.Dispose() - Exit Sub - End If - Else - If DtExistencias IsNot Nothing Then - Dim Existencia As Decimal = DtExistencias.SUMD("Cantidad", $"CvePS = {CvePSSerie} AND CveUM = {CveUMSerie} AND Lote = '{Lote}' AND Batch = '{Batch}'") - If Existencia < CantidadLote Then - Alert($"No hay existencia suficiente del producto ""{PSSerie}"" con el lote definido ""{Lote}"" y el batch ""{Batch}"". Por favor rectifique y vuelva a intentar", TipoMensaje.MsgAdvertencia) - RegistraScript("playsonidito('142608__autistic-lucario__error.wav')") - ObjInventarios.Dispose() - Exit Sub - End If - End If - End If - - Dim FechaCaducidad As String = "" - If ObjInventarios.LoteRecomendadoGet(CvePSSerie, UsuarioActual.CveEmpresa, DdlAlmacen.SelectedValue.ToEntero()) AndAlso ObjInventarios.DtResultados.Rows.Count > 0 Then - FechaCaducidad = ObjInventarios.DtResultados.Rows(0)("FechaCaducidad").ToString().ToDate.ToShortDateString - End If - - Row("ConsecId") = CveConsecSerie - Row("Consec") = DtDatosDetalle.Rows.Count + 1 - Row("Cantidad") = CantidadLote - Row("CvePS") = CvePSSerie - Row("PS") = PSSerie - Row("CveUM") = CveUMSerie - Row("Lote") = Lote - Row("Batch") = Batch - Row("FechaCaducidad") = FechaCaducidad - - DtDatosDetalleLote.Rows.Add(Row) - ObjInventarios.Dispose() - - If Tipo = 1 Then - TxtCantidadLote.Text = "1" - TxtLote.Text = "" - TxtBatch.Text = "" - End If - - CargaLote(True) - - End Sub - - Protected Sub GvLote_RowDeleting(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewDeleteEventArgs) Handles GvLote.RowDeleting - - Dim keyLote As String = e.Keys("Lote").ToString() - Try - For Each dr As DataRow In DtDatosDetalleLote.Rows - If dr("Lote").ToString() = keyLote Then - dr.Delete() - End If - Next - Catch ex As Exception - - End Try - DtDatosDetalleLote.AcceptChanges() - CargaLote() + Series = TxtSerie.Text.Trim + Series = Series.Replace("*", "") + ArraySeries = Series.Trim.Split(","c) + + For i As Integer = 0 To ArraySeries.Length - 1 + If ArraySeries(i).Trim.Length > 1 Then AgregaSerie(ArraySeries(i).Trim, 1, True) + Next + Else + AgregaSerie(TxtSerie.Text.Trim, 1) + End If End Sub -#End Region -#Region " AGREGA CON TXT | CODIGO - SERIE " - Protected Sub BtnCodigoPS_Click(sender As Object, e As EventArgs) - - If TxtCodigoPS.Text = "" Then - Exit Sub - End If - - TdSeriePS.Visible = False - Dim Existe As Boolean = False - Dim PSTemp As String = "" - - For Each Gvr As GridViewRow In GvDatos.Rows - If Gvr.DataKey("CodigoBarras") = TxtCodigoPS.Text.Trim Then - Dim TxtCantidad As TextBox = GvDatos.Rows(Gvr.RowIndex).FCTextBox("TbCantidadF") - If Gvr.DataKey("CantidadF").ToDecimal - TxtCantidad.Text.ToDecimal - 1 >= 0 Then - - ''VALIDA EXISTENCIA - If Not TipoDocto.Contiene("Dev", "RNC") Then - If TipoMovimiento = 1 Then - Dim ObjInventario As New ClsInventarios - Dim Existencia As Decimal = ObjInventario.GetExistenciasPS(Gvr.DataKey("CvePS").ToString().ToEntero(), Gvr.DataKey("CveUM").ToString().ToEntero(), UsuarioActual.CveEmpresa, DdlAlmacen.SelectedValue.ToEntero(), FechaMovto:=TxtFecha.Text.ToDateTime.ToString("yyyy/MM/dd HH:mm"), CveVendedor:=CveVendedor, CveSubProyecto:=CveSubProyecto, CveCliente:=If(UsuarioActual.Empresa.Funcionalidad(146) = "1", -1, CveCliente), ExcluyeApartados:=If(TipoEntrega = 2, 1, -1)) - ObjInventario.Dispose() - If Not Existencia >= TxtCantidad.Text.ToDecimal + 1 Then - TxtCodigoPS.Text = "" - Alert($"No hay existencias suficientes del producto:
    ""{Gvr.DataKey("Codigo")}-{Gvr.DataKey("PS")}"".
    Solo hay disponibles {Existencia.FormatoNumero} en Almacen. Por favor Verifique y vuelva a intentar.", TipoMensaje.MsgAdvertencia, "window.setTimeout(Focus,200);") - RegistraScript("playsonidito('142608__autistic-lucario__error.wav')") - Exit Sub - End If - Else - If DtExistencias IsNot Nothing Then - Dim Existencia As Decimal = DtExistencias.SUMD("Cantidad", $"CvePS = {Gvr.DataKey("CvePS")} AND CveUM = {Gvr.DataKey("CveUM").ToString().ToEntero()}") - If Not Existencia >= TxtCantidad.Text.ToDecimal + 1 Then - TxtCodigoPS.Text = "" - Alert($"No hay existencias suficientes del producto:
    ""{Gvr.DataKey("Codigo")}-{Gvr.DataKey("PS")}"".
    Solo hay disponibles {Existencia.FormatoNumero} en Almacen. Por favor Verifique y vuelva a intentar.", TipoMensaje.MsgAdvertencia, "window.setTimeout(Focus,200);") - RegistraScript("playsonidito('142608__autistic-lucario__error.wav')") - Exit Sub - End If - End If - End If - End If - - If Gvr.DataKey("AplicaSerie") = "True" Then - TdSeriePS.Visible = True - TxtSeriePS.Focus() - - CveConsecSerie = Gvr.DataKey("Consec").ToString().ToEntero() - PSSerie = Gvr.DataKey("PS").ToString() - CvePSSerie = Gvr.DataKey("CvePS").ToEntero() - CveUMSerie = Gvr.DataKey("CveUM").ToEntero() - Exit Sub - End If - - Dim CantidadEspecial As Boolean = Gvr.DataKey("CveClasificacion").ToString().ToEntero().Contiene(17601, 17881) OrElse Gvr.DataKey("CvePS").ToString().ToEntero().Contiene(343032, 343033) - - If CantidadEspecial Then - RegistraScript("CantidadEspecial();window.setTimeout(FocusCantidadEspecial,200);") - LtlProductoCantidad.Text = $"{Gvr.DataKey("Codigo")}" - RowIndexCantidadEspecial = Gvr.RowIndex - CantidadEspecialTemp = Gvr.DataKey("CantidadF").ToDecimal - TxtCodigoPS.Text = "" - Exit Sub - Else - TxtCantidad.Text = (TxtCantidad.Text.ToDecimal + 1).ToString().FormatoNumero - TxtCodigoPS.Text = "" - UpDatos.Update() - Exit Sub - End If - - VerificaVentaSurtida() - Exit Sub - End If - - Existe = True - PSTemp = Gvr.DataKey("PS").ToString() - 'Alert($"Ya se ha cargado la totalidad del Producto ""{Gvr.DataKey("PS").ToString()}"" con el Codigo ""{TxtCodigoPS.Text}"".", TipoMensaje.MsgAdvertencia, "window.setTimeout(Focus,200);") - 'VerificaVentaSurtida() - 'Exit Sub - End If - Next - - VerificaVentaSurtida() - If Existe Then - Alert($"Ya se ha cargado la totalidad del Producto ""{PSTemp}"" con el Codigo ""{TxtCodigoPS.Text}"".", TipoMensaje.MsgAdvertencia, "window.setTimeout(Focus,200);") - Else - Alert($"No se ha encontrado un producto para surtir con el Codigo ""{TxtCodigoPS.Text}"". ", TipoMensaje.MsgAdvertencia, "window.setTimeout(Focus,200);") - End If - RegistraScript("playsonidito('142608__autistic-lucario__error.wav')") - TxtCodigoPS.Text = "" - - End Sub - Private Sub VerificaVentaSurtida() - Dim Surtida As Boolean = True - - For Each Gvr As GridViewRow In GvDatos.Rows - If Gvr.DataKey("CantidadF").ToDecimal <> Gvr.FCTextBox("TbCantidadF").Text.ToDecimal Then - Surtida = False - Exit Sub - End If - Next - - If Surtida Then - LbSurtida.Visible = True - End If - End Sub - Protected Sub BtnSeriePS_Click(sender As Object, e As EventArgs) - AgregaSerie(TxtSeriePS.Text.Trim, 2, True) - - TdSeriePS.Visible = False - TxtSeriePS.Text = "" - TxtCodigoPS.Text = "" - TxtCodigoPS.Focus() - VerificaVentaSurtida() - - End Sub - Protected Sub BtnGuardarCantidadEspecial_Click(sender As Object, e As EventArgs) - AgregaCantidadEspecial() - End Sub - Private Sub AgregaCantidadEspecial() - Dim TxtCantidad As TextBox = GvDatos.Rows(RowIndexCantidadEspecial).FCTextBox("TbCantidadF") - If CantidadEspecialTemp - TxtCantidadEspecialDiv.Text.ToDecimal - TxtCantidad.Text.ToDecimal >= 0 Then - TxtCantidad.Text = (TxtCantidad.Text.ToDecimal + TxtCantidadEspecialDiv.Text.ToDecimal).ToString().FormatoNumero - 'RegistraScript("$('#ModalCantidad').modal('hide');") - RegistraScript("$('#DivCantidadEspecial').hide(200);") - UpDatos.Update() - TxtCodigoPS.Focus() - Else - Alert("La cantidad excede la pendiente por surtir. Por favor rectifique y vuelva a intentar.", TipoMensaje.MsgAdvertencia, "window.setTimeout(Focus,200);") - RegistraScript("playsonidito('142608__autistic-lucario__error.wav')") - End If - - TxtCantidadEspecialDiv.Text = "1" + Private Sub AgregaSerie(Serie As String, Tipo As Integer, Optional CargaMasivo As Boolean = False) + + If Serie.Trim = "" Then + Alert("El campo 'Serie' es obligatorio. Por favor rectifique y vuelva a intentar.", TipoMensaje.MsgAdvertencia) + Exit Sub + End If + + If Serie.Trim.Length < 6 Then + Alert("El campo 'Serie' debe tener minimo 6 caracteres. Por favor rectifique y vuelva a intentar.", TipoMensaje.MsgAdvertencia) + Exit Sub + End If + + If DtDatosDetalle.FiltraParametros($"CvePS = {CvePSSerie} AND Serie = '{Serie}'").Rows.Count > 0 Then + Alert("La Serie indicada ya esta registrada. Por favor rectifique y vuelva a intentar.", TipoMensaje.MsgAdvertencia) + RegistraScript("playsonidito('142608__autistic-lucario__error.wav')", "Error1") + TxtSerie.Text = "" + Exit Sub + End If + + Dim AplicaCaducidad As Boolean = GlobalDTPSSimplificado(UsuarioActual.CveEmpresa, CvePS:=CvePSSerie).FiltroPrimeroValor("AplicaCaducidad", "") = "True" + 'If GlobalDTPSSimplificado(UsuarioActual.CveEmpresa, CvePS:=CvePSSerie).FiltraParametros("").Rows(0) IsNot Nothing Then + ' AplicaCaducidad = If(GlobalDTPS(UsuarioActual.CveEmpresa, CvePS:=CvePSSerie).FiltraParametros("").Rows(0)("AplicaCaducidad").ToString() = "True", True, False) + 'End If + + + 'Valida Existencia + If TipoMovimiento = 1 Then + Dim ObjInventarios As New ClsInventarios + Dim Existencia As Decimal = ObjInventarios.GetExistenciasPS(CvePSSerie, CveUMSerie, UsuarioActual.CveEmpresa, DdlAlmacen.SelectedValue.ToEntero(), FechaMovto:=TxtFecha.Text.ToDateTime.ToString("yyyy/MM/dd HH:mm"), Serie:=Serie, CveVendedor:=CveVendedor, CveSubProyecto:=CveSubProyecto, CveCliente:=If(UsuarioActual.Empresa.Funcionalidad(146) = "1", -1, CveCliente), ExcluyeApartados:=If(TipoEntrega = 2, 1, -1)) + If Existencia < 1 Then + Alert($"No hay existencia suficiente del producto ""{PSSerie}"" con la Serie definida ""{Serie}"". Por favor rectifique y vuelva a intentar", TipoMensaje.MsgAdvertencia, If(Tipo = 2, "window.setTimeout(Focus,200);", "")) + RegistraScript("playsonidito('142608__autistic-lucario__error.wav')", "Error2") + ObjInventarios.Dispose() + Exit Sub + End If + ObjInventarios.Dispose() + Else + If DtExistencias IsNot Nothing Then + Dim Existencia As Decimal = DtExistencias.SUMD("Cantidad", $"CvePS = {CvePSSerie} AND CveUM = {CveUMSerie} AND Serie = '{Serie}'") + If Existencia < 1 Then + Alert($"No hay existencia suficiente del producto ""{PSSerie}"" con la Serie definida ""{Serie}"". Por favor rectifique y vuelva a intentar", TipoMensaje.MsgAdvertencia, If(Tipo = 2, "window.setTimeout(Focus,200);", "")) + RegistraScript("playsonidito('142608__autistic-lucario__error.wav')", "Error3") + Exit Sub + End If + End If + End If + + Dim Row As DataRow = DtDatosDetalle.NewRow + + Row("ConsecId") = CveConsecSerie + Row("Consec") = DtDatosDetalle.Rows.Count + 1 + Row("PS") = PSSerie + Row("CvePS") = CvePSSerie + Row("CveUM") = CveUMSerie + Row("Serie") = Serie + Row("FechaCaducidad") = If(AplicaCaducidad, TxtFechaCaducidad.Text, MinFecha.ToShortDateString) + + DtDatosDetalle.Rows.Add(Row) + ActualizaBitacora() + RegistraScript("playsonidito('beep-07.wav')", "Sonidito") + + If Tipo = 1 Then + TxtSerie.Text = "" + TxtFechaCaducidad.Text = "" + End If + + If Tipo < 3 Then + CargaSerie(True, CargaMasivo) + End If + End Sub -#End Region -#End Region + Protected Sub GvSerie_RowDeleting(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewDeleteEventArgs) Handles GvSerie.RowDeleting + + Dim keySerie As String = e.Keys("Serie").ToString() + Try + For Each dr As DataRow In DtDatosDetalle.Rows + If dr("Serie").ToString() = keySerie Then + dr.Delete() + End If + Next + Catch ex As Exception + + End Try + + DtDatosDetalle.AcceptChanges() + ActualizaBitacora() + CargaSerie() + + End Sub +#End Region +#Region "Bitacora" + Private Sub ActualizaBitacora(Optional Eliminar As Boolean = False) + If Not Eliminar Then + DtDatos.TableName = "DtDatos" + DtDatosDetalle.TableName = "DtDatosDetalle" + DtDatos.WriteXml(ArchivoBitacora, XmlWriteMode.WriteSchema) + DtDatosDetalle.WriteXml(ArchivoBitacoraDetalle, XmlWriteMode.WriteSchema) + Else + File.Delete(ArchivoBitacora) + End If + + End Sub + + Protected Sub HplCargaBitacora_Click(sender As Object, e As EventArgs) + + CargaBitacora = False + If IO.File.Exists(ArchivoBitacora) Then + + CargaBitacoraSerie() + CargaGvDatos() + CargaBitacora = True + Else + Alert("No hay bitácora para recuperar.", TipoMensaje.ToastInformacion) + End If + + End Sub + + Private Sub CargaBitacoraSerie() + + If IO.File.Exists(ArchivoBitacora) Then + + DtDatos.ReadXml(ArchivoBitacora) + If IO.File.Exists(ArchivoBitacoraDetalle) Then + Dim dtt As New DataTable + dtt.ReadXml(ArchivoBitacoraDetalle) + DtDatosDetalle = dtt + Alert("Registro(s) Recuperados", TipoMensaje.ToastInformacion) + + End If + Else + Alert("No hay bitácora para recuperar.", TipoMensaje.ToastInformacion) + End If + End Sub + +#End Region +#Region " AGREGA CON LOTE BATCH " + + Private Sub CreaDtDetalleLote() + If DtDatosDetalleLote Is Nothing Then + DtDatosDetalleLote = New DataTable + DtDatosDetalleLote.Columns.Add("CveVentaDetalle", GetType(Integer)) + DtDatosDetalleLote.Columns.Add("Consec", GetType(Integer)) + DtDatosDetalleLote.Columns.Add("ConsecId", GetType(Integer)) + DtDatosDetalleLote.Columns.Add("Cantidad", GetType(Double)) + DtDatosDetalleLote.Columns.Add("CvePS", GetType(Integer)) + DtDatosDetalleLote.Columns.Add("PS", GetType(String)) + DtDatosDetalleLote.Columns.Add("CveUM", GetType(Integer)) + DtDatosDetalleLote.Columns.Add("Lote", GetType(String)) + DtDatosDetalleLote.Columns.Add("FechaCaducidad", GetType(String)) + DtDatosDetalleLote.Columns.Add("FueTraspaso", GetType(Integer)) + End If + End Sub + Private Sub CargaLote(Optional CerrarCompletado As Boolean = False) + + RegistraScript("$('#DivLote').modal({backdrop: 'static', keyboard: false})") + GvLote.Columns(2).HeaderText = UsuarioActual.Empresa.Funcionalidad(147) + GvLote.DataSource = DtDatosDetalleLote.FiltraParametros(String.Format("ConsecId = {0}", CveConsecSerie), "Consec DESC") + GvLote.DataBind() + + 'VALIDA QUE SIGA AGREGANDO + If DtDatosDetalleLote.SUM("Cantidad", String.Format("ConsecId = {0}", CveConsecSerie)) = LbCantidad2.Text.ToDecimal Then + BtnLote.Enabled = False + If CerrarCompletado Then + RegistraScript("$('#DivLote').modal('hide')", "hide") + End If + Else + BtnLote.Enabled = True + End If + + 'LOTE RECOMENDADO + Dim DtLotes As New DataTable + If TipoMovimiento = 1 Then + Dim ObjInventarios As New ClsInventarios + If ObjInventarios.LoteRecomendadoGet(CvePSSerie, UsuarioActual.CveEmpresa, DdlAlmacen.SelectedValue.ToEntero()) Then + DtLotes = ObjInventarios.DtResultados + End If + ObjInventarios.Dispose() + Else + DtLotes = DtExistencias.FiltraParametros("Lote <> ''") + End If + + Dim DrsRemove As New List(Of DataRow) + + If DtLotes.Rows.Count > 0 Then + 'CALCULA YA COMPLETADOS + DtLotes.Columns.Add("CantidadSeleccionada", GetType(Integer)) + For Each dr As DataRow In DtLotes.Rows + dr("CantidadSeleccionada") = DtDatosDetalleLote.SUM("Cantidad", String.Format("Consec = {0} AND Lote = '{1}'", CveConsecSerie, dr("Lote"))) + If dr("CantidadSeleccionada").ToString().ToDecimal = dr("Existencia").ToString().ToDecimal Then + DrsRemove.Add(dr) + End If + Next + + 'ELIMINA YA COMPLETADOS EN PAGINA + For Each dr As DataRow In DrsRemove + DtLotes.Rows.Remove(dr) + Next + + If DtLotes.Rows.Count > 0 Then + Dim Mensaje As New StringBuilder + Mensaje.AppendFormat("Recomendado: Existencia: {0} Lote: {1} Fecha Caducidad: {2} ", DtLotes.Rows(0)("Existencia").ToString().FormatoNumero, DtLotes.Rows(0)("Lote"), DtLotes.Rows(0)("FechaCaducidad").ToString().ToDate.ToShortDateString) + LbLoteRecomendado.Text = Mensaje.ToString() + Else + LbLoteRecomendado.Text = "No se encontro ningún Lote recomendado." + End If + Else + LbLoteRecomendado.Text = "No se encontro ningún Lote recomendado." + End If -#Region " GUARDAR " - Protected Sub BtnGuardar_Click(sender As Object, e As EventArgs) - - Select Case TipoEntrega - Case 1 - GuardaVenta() - Case 2 - GuardaTraspaso() - End Select - - End Sub - + 'SI TIENE SALIDA POR LOTE, BLOQUEAMOS CHECK Y TXTCANTIDAD + Dim Contador As Decimal = 0 + For Each Gvr As GridViewRow In GvDatos.Rows + If Gvr.DataKey("CvePS").ToEntero() = CvePSSerie Then + Contador = DtDatosDetalleLote.SUM("Cantidad", String.Format("ConsecId = {0}", Gvr.DataKey("Consec"))) + Gvr.FCCheckBox("cbInv").Enabled = False + Gvr.FCCheckBox("cbInv").Checked = True + Gvr.FCTextBox("TbCantidadF").Text = Contador.ToString().FormatoNumero + End If + Next + + RVCantidadLote.MaximumValue = (If((LbCantidad2.Text.ToDecimal - Contador) = 0, 0.02, LbCantidad2.Text.ToDecimal - Contador)).ToString().FormatoNumero + + TxtCantidadLote.Text = "1" + TxtLote.Text = "" + TxtBatch.Text = "" + TxtLote.Focus() + + UpLoteBatch.Update() + UpDatos.Update() + + End Sub + + Protected Sub BtnAgregarPS2_Click(sender As Object, e As EventArgs) + AgregaLote(TxtLote.Text.Trim, TxtBatch.Text.Trim, 1) + End Sub + Private Sub AgregaLote(Lote As String, Batch As String, Tipo As Integer) + + If Lote = "" Then + Alert("El campo Lote es obligatorio. Por favor rectifique y vuelva a intentar.", TipoMensaje.MsgAdvertencia) + Exit Sub + End If + + 'VALIDACION DE SERIES DUPLICADAS + Dim MensajeAlert As New StringBuilder + Dim DtDuplicado As New DataTable + Dim DtSeriesNuevas As New DataTable + DtSeriesNuevas.Columns.Add("Serie", GetType(String)) + + DtDuplicado = DtDatosDetalleLote.FiltraParametros($"ConsecId = {CveConsecSerie} AND Lote = '{Lote}' AND Batch = '{Batch}'") + If DtDuplicado IsNot Nothing AndAlso DtDuplicado.Rows.Count > 0 Then + Alert($"
    El numero de Lote ""{Lote}"" y Batch = '{Batch}' proporcionado ya se encuentra ingresado.", TipoMensaje.MsgAdvertencia) + RegistraScript("playsonidito('142608__autistic-lucario__error.wav')") + Exit Sub + End If + + Dim Row As DataRow = DtDatosDetalleLote.NewRow + Dim CantidadLote As Decimal = TxtCantidadLote.Text.ToDecimal + + Dim MensajeSinExistencias As New StringBuilder + Dim ObjInventarios As New ClsInventarios + + 'VERIFICA EXISTENCIAS + If TipoMovimiento = 1 Then + Dim Existencia As Decimal = ObjInventarios.GetExistenciasPS(CvePSSerie, CveUMSerie, UsuarioActual.CveEmpresa, DdlAlmacen.SelectedValue.ToEntero(), FechaMovto:=TxtFecha.Text.ToDateTime.ToString("yyyy/MM/dd HH:mm"), CveVendedor:=CveVendedor, CveSubProyecto:=CveSubProyecto, CveCliente:=If(UsuarioActual.Empresa.Funcionalidad(146) = "1", -1, CveCliente), Lote:=Lote, ExcluyeApartados:=If(TipoEntrega = 2, 1, -1)) + If Existencia < CantidadLote Then + Alert($"No hay existencia suficiente del producto ""{PSSerie}"" con el lote definido ""{Lote}"" y el batch ""{Batch}"". Por favor rectifique y vuelva a intentar", TipoMensaje.MsgAdvertencia) + RegistraScript("playsonidito('142608__autistic-lucario__error.wav')") + ObjInventarios.Dispose() + Exit Sub + End If + Else + If DtExistencias IsNot Nothing Then + Dim Existencia As Decimal = DtExistencias.SUMD("Cantidad", $"CvePS = {CvePSSerie} AND CveUM = {CveUMSerie} AND Lote = '{Lote}' AND Batch = '{Batch}'") + If Existencia < CantidadLote Then + Alert($"No hay existencia suficiente del producto ""{PSSerie}"" con el lote definido ""{Lote}"" y el batch ""{Batch}"". Por favor rectifique y vuelva a intentar", TipoMensaje.MsgAdvertencia) + RegistraScript("playsonidito('142608__autistic-lucario__error.wav')") + ObjInventarios.Dispose() + Exit Sub + End If + End If + End If + + Dim FechaCaducidad As String = "" + If ObjInventarios.LoteRecomendadoGet(CvePSSerie, UsuarioActual.CveEmpresa, DdlAlmacen.SelectedValue.ToEntero()) AndAlso ObjInventarios.DtResultados.Rows.Count > 0 Then + FechaCaducidad = ObjInventarios.DtResultados.Rows(0)("FechaCaducidad").ToString().ToDate.ToShortDateString + End If + + Row("ConsecId") = CveConsecSerie + Row("Consec") = DtDatosDetalle.Rows.Count + 1 + Row("Cantidad") = CantidadLote + Row("CvePS") = CvePSSerie + Row("PS") = PSSerie + Row("CveUM") = CveUMSerie + Row("Lote") = Lote + Row("Batch") = Batch + Row("FechaCaducidad") = FechaCaducidad + + DtDatosDetalleLote.Rows.Add(Row) + ObjInventarios.Dispose() + + If Tipo = 1 Then + TxtCantidadLote.Text = "1" + TxtLote.Text = "" + TxtBatch.Text = "" + End If + + CargaLote(True) + + End Sub + + Protected Sub GvLote_RowDeleting(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewDeleteEventArgs) Handles GvLote.RowDeleting + + Dim keyLote As String = e.Keys("Lote").ToString() + Try + For Each dr As DataRow In DtDatosDetalleLote.Rows + If dr("Lote").ToString() = keyLote Then + dr.Delete() + End If + Next + Catch ex As Exception + + End Try + DtDatosDetalleLote.AcceptChanges() + CargaLote() + End Sub +#End Region + +#Region " AGREGA CON TXT | CODIGO - SERIE " + Protected Sub BtnCodigoPS_Click(sender As Object, e As EventArgs) + + If TxtCodigoPS.Text = "" Then + Exit Sub + End If + + TdSeriePS.Visible = False + Dim Existe As Boolean = False + Dim PSTemp As String = "" + + For Each Gvr As GridViewRow In GvDatos.Rows + If Gvr.DataKey("CodigoBarras") = TxtCodigoPS.Text.Trim Then + Dim TxtCantidad As TextBox = GvDatos.Rows(Gvr.RowIndex).FCTextBox("TbCantidadF") + If Gvr.DataKey("CantidadF").ToDecimal - TxtCantidad.Text.ToDecimal - 1 >= 0 Then + + ''VALIDA EXISTENCIA + If Not TipoDocto.Contiene("Dev", "RNC") Then + If TipoMovimiento = 1 Then + Dim ObjInventario As New ClsInventarios + Dim Existencia As Decimal = ObjInventario.GetExistenciasPS(Gvr.DataKey("CvePS").ToString().ToEntero(), Gvr.DataKey("CveUM").ToString().ToEntero(), UsuarioActual.CveEmpresa, DdlAlmacen.SelectedValue.ToEntero(), FechaMovto:=TxtFecha.Text.ToDateTime.ToString("yyyy/MM/dd HH:mm"), CveVendedor:=CveVendedor, CveSubProyecto:=CveSubProyecto, CveCliente:=If(UsuarioActual.Empresa.Funcionalidad(146) = "1", -1, CveCliente), ExcluyeApartados:=If(TipoEntrega = 2, 1, -1)) + ObjInventario.Dispose() + If Not Existencia >= TxtCantidad.Text.ToDecimal + 1 Then + TxtCodigoPS.Text = "" + Alert($"No hay existencias suficientes del producto:
    ""{Gvr.DataKey("Codigo")}-{Gvr.DataKey("PS")}"".
    Solo hay disponibles {Existencia.FormatoNumero} en Almacen. Por favor Verifique y vuelva a intentar.", TipoMensaje.MsgAdvertencia, "window.setTimeout(Focus,200);") + RegistraScript("playsonidito('142608__autistic-lucario__error.wav')") + Exit Sub + End If + Else + If DtExistencias IsNot Nothing Then + Dim Existencia As Decimal = DtExistencias.SUMD("Cantidad", $"CvePS = {Gvr.DataKey("CvePS")} AND CveUM = {Gvr.DataKey("CveUM").ToString().ToEntero()}") + If Not Existencia >= TxtCantidad.Text.ToDecimal + 1 Then + TxtCodigoPS.Text = "" + Alert($"No hay existencias suficientes del producto:
    ""{Gvr.DataKey("Codigo")}-{Gvr.DataKey("PS")}"".
    Solo hay disponibles {Existencia.FormatoNumero} en Almacen. Por favor Verifique y vuelva a intentar.", TipoMensaje.MsgAdvertencia, "window.setTimeout(Focus,200);") + RegistraScript("playsonidito('142608__autistic-lucario__error.wav')") + Exit Sub + End If + End If + End If + End If + + If Gvr.DataKey("AplicaSerie") = "True" Then + TdSeriePS.Visible = True + TxtSeriePS.Focus() + + CveConsecSerie = Gvr.DataKey("Consec").ToString().ToEntero() + PSSerie = Gvr.DataKey("PS").ToString() + CvePSSerie = Gvr.DataKey("CvePS").ToEntero() + CveUMSerie = Gvr.DataKey("CveUM").ToEntero() + Exit Sub + End If + + Dim CantidadEspecial As Boolean = Gvr.DataKey("CveClasificacion").ToString().ToEntero().Contiene(17601, 17881) OrElse Gvr.DataKey("CvePS").ToString().ToEntero().Contiene(343032, 343033) + + If CantidadEspecial Then + RegistraScript("CantidadEspecial();window.setTimeout(FocusCantidadEspecial,200);") + LtlProductoCantidad.Text = $"{Gvr.DataKey("Codigo")}" + RowIndexCantidadEspecial = Gvr.RowIndex + CantidadEspecialTemp = Gvr.DataKey("CantidadF").ToDecimal + TxtCodigoPS.Text = "" + Exit Sub + Else + TxtCantidad.Text = (TxtCantidad.Text.ToDecimal + 1).ToString().FormatoNumero + TxtCodigoPS.Text = "" + UpDatos.Update() + Exit Sub + End If + + VerificaVentaSurtida() + Exit Sub + End If + + Existe = True + PSTemp = Gvr.DataKey("PS").ToString() + 'Alert($"Ya se ha cargado la totalidad del Producto ""{Gvr.DataKey("PS").ToString()}"" con el Codigo ""{TxtCodigoPS.Text}"".", TipoMensaje.MsgAdvertencia, "window.setTimeout(Focus,200);") + 'VerificaVentaSurtida() + 'Exit Sub + End If + Next + + VerificaVentaSurtida() + If Existe Then + Alert($"Ya se ha cargado la totalidad del Producto ""{PSTemp}"" con el Codigo ""{TxtCodigoPS.Text}"".", TipoMensaje.MsgAdvertencia, "window.setTimeout(Focus,200);") + Else + Alert($"No se ha encontrado un producto para surtir con el Codigo ""{TxtCodigoPS.Text}"". ", TipoMensaje.MsgAdvertencia, "window.setTimeout(Focus,200);") + End If + RegistraScript("playsonidito('142608__autistic-lucario__error.wav')") + TxtCodigoPS.Text = "" + + End Sub + Private Sub VerificaVentaSurtida() + Dim Surtida As Boolean = True + + For Each Gvr As GridViewRow In GvDatos.Rows + If Gvr.DataKey("CantidadF").ToDecimal <> Gvr.FCTextBox("TbCantidadF").Text.ToDecimal Then + Surtida = False + Exit Sub + End If + Next + + If Surtida Then + LbSurtida.Visible = True + End If + End Sub + Protected Sub BtnSeriePS_Click(sender As Object, e As EventArgs) + AgregaSerie(TxtSeriePS.Text.Trim, 2, True) + + TdSeriePS.Visible = False + TxtSeriePS.Text = "" + TxtCodigoPS.Text = "" + TxtCodigoPS.Focus() + VerificaVentaSurtida() + + End Sub + Protected Sub BtnGuardarCantidadEspecial_Click(sender As Object, e As EventArgs) + AgregaCantidadEspecial() + End Sub + Private Sub AgregaCantidadEspecial() + Dim TxtCantidad As TextBox = GvDatos.Rows(RowIndexCantidadEspecial).FCTextBox("TbCantidadF") + If CantidadEspecialTemp - TxtCantidadEspecialDiv.Text.ToDecimal - TxtCantidad.Text.ToDecimal >= 0 Then + TxtCantidad.Text = (TxtCantidad.Text.ToDecimal + TxtCantidadEspecialDiv.Text.ToDecimal).ToString().FormatoNumero + 'RegistraScript("$('#ModalCantidad').modal('hide');") + RegistraScript("$('#DivCantidadEspecial').hide(200);") + UpDatos.Update() + TxtCodigoPS.Focus() + Else + Alert("La cantidad excede la pendiente por surtir. Por favor rectifique y vuelva a intentar.", TipoMensaje.MsgAdvertencia, "window.setTimeout(Focus,200);") + RegistraScript("playsonidito('142608__autistic-lucario__error.wav')") + End If + + TxtCantidadEspecialDiv.Text = "1" + End Sub +#End Region + +#End Region + + +#Region " GUARDAR " + Protected Sub BtnGuardar_Click(sender As Object, e As EventArgs) + + Select Case TipoEntrega + Case 1 + GuardaVenta() + Case 2 + GuardaTraspaso() + End Select + + End Sub + Private Sub GuardaVenta() Dim CantidadVenta As Decimal = 0 '' INICIA: VALIDACIONES 'Valida el estatus de la Venta, si es = 5 O DevolucionVenta = 2, NO SE SURTE! - Dim ObjVentaInv As New ClsInventarios - If ObjVentaInv.GetEstatusVentaPorSurtir(CveVentaSurtir) Then - TipoEstatus = ObjVentaInv.TipoEstatus - EsDevolucionVenta = ObjVentaInv.EsDevolucionVenta - CantidadVenta = ObjVentaInv.CantidadVenta - End If - ObjVentaInv.Dispose() - - Dim VerificaCancelada As Boolean = True - + Dim ObjVentaInv As New ClsInventarios + If ObjVentaInv.GetEstatusVentaPorSurtir(CveVentaSurtir) Then + TipoEstatus = ObjVentaInv.TipoEstatus + EsDevolucionVenta = ObjVentaInv.EsDevolucionVenta + CantidadVenta = ObjVentaInv.CantidadVenta + End If + ObjVentaInv.Dispose() + + Dim VerificaCancelada As Boolean = True + If UsuarioActual.Empresa.Funcionalidad(578) = "1" AndAlso TipoDocto = "Ped" Then VerificaCancelada = False - End If - + End If + If VerificaCancelada Then If TipoEstatus = 5 Then Alert("No se puede surtir esta venta, verifique que no esté cancelada", TipoMensaje.MsgAdvertencia) Exit Sub End If - End If - - If EsDevolucionVenta.Contiene(2, 3) Then - Alert("No se puede surtir esta venta, verifique que no esté registrado su movimiento en almacen", TipoMensaje.MsgAdvertencia) - Exit Sub - End If - - Dim ValidaSeccion As Boolean = False : Dim ValidaCaducidad As Boolean = False : Dim ValidaLote As Boolean = False - 'VALIDA CANTIDAD DE SALIDA + End If + + If EsDevolucionVenta.Contiene(2, 3) Then + Alert("No se puede surtir esta venta, verifique que no esté registrado su movimiento en almacen", TipoMensaje.MsgAdvertencia) + Exit Sub + End If + + Dim ValidaSeccion As Boolean = False : Dim ValidaCaducidad As Boolean = False : Dim ValidaLote As Boolean = False + 'VALIDA CANTIDAD DE SALIDA Dim Cantidad As Decimal = 0.0D - Dim NumRegistros As Integer = 0 - - For Each Gvr As GridViewRow In GvDatos.Rows + Dim NumRegistros As Integer = 0 + + For Each Gvr As GridViewRow In GvDatos.Rows If Gvr.RowType = DataControlRowType.DataRow Then If Gvr.FCCheckBox("cbInv").Checked Then NumRegistros += 1 @@ -2070,36 +2070,36 @@ Partial Class Inventarios_EntregaAlmacen Cantidad += Gvr.FCTextBox("TbCantidadF").Text.ToDecimal End If End If - End If + End If Next - If ValidaSeccion Then - Alert("La sección de almacen no ha sido especificada en todos los productos.", TipoMensaje.MsgAdvertencia) - Exit Sub - End If - If ValidaCaducidad Then - Alert("La caducidad no ha sido especificada en todos los productos.", TipoMensaje.MsgAdvertencia) - Exit Sub - End If - If ValidaLote Then - Alert("El lote de almacen no ha sido especificada en todos los productos.", TipoMensaje.MsgAdvertencia) - Exit Sub - End If - - If Not Cantidad > 0 Then - Alert("No se detecto ningun movimiento por hacer. Por favor verifique e intente nuevamente.", TipoMensaje.MsgAdvertencia) - Exit Sub + If ValidaSeccion Then + Alert("La sección de almacen no ha sido especificada en todos los productos.", TipoMensaje.MsgAdvertencia) + Exit Sub + End If + If ValidaCaducidad Then + Alert("La caducidad no ha sido especificada en todos los productos.", TipoMensaje.MsgAdvertencia) + Exit Sub + End If + If ValidaLote Then + Alert("El lote de almacen no ha sido especificada en todos los productos.", TipoMensaje.MsgAdvertencia) + Exit Sub + End If + + If Not Cantidad > 0 Then + Alert("No se detecto ningun movimiento por hacer. Por favor verifique e intente nuevamente.", TipoMensaje.MsgAdvertencia) + Exit Sub End If If UsuarioActual.Empresa.Funcionalidad(578) = "1" AndAlso TipoDocto = "Ped" Then VerificaCancelada = False - End If - + End If + Dim ValidaEntregaCompleto As Boolean = Not UsuarioActual.TienePermisoProceso(176) If CveTipoVenta = 3 Then ValidaEntregaCompleto = False 'PROCESO , si tiene proceso "176" no lo valida - If ValidaEntregaCompleto Then 'Tipoventa diferente a A-vista + If ValidaEntregaCompleto Then 'Tipoventa diferente a A-vista If Not TipoDocto.Contiene("Dev") Then 'para devoluciones debe de aceptar parcialidades For Each Gvr As GridViewRow In GvDatos.Rows If Gvr.DataKey("CantidadF").ToDecimal <> Gvr.FCTextBox("TbCantidadF").Text.ToDecimal Then @@ -2108,9 +2108,9 @@ Partial Class Inventarios_EntregaAlmacen End If Next End If - End If + End If Dim Guia As String = TxtGuia.Text.Trim - Dim Recibio As String = "" + Dim Recibio As String = "" If EsDevolucionVenta = 1 Or TipoDocto.Contiene({"Ped"}) Then Dim ValidaSalidaCompleta As Boolean = Not (EsDevolucionVenta = 1 And TipoDocto.Contiene("Rem", "Ped")) 'LIMITAR EL NUMERO DE PARTIDAS QUE SE PUEDEN ENTREGAR @@ -2136,50 +2136,50 @@ Partial Class Inventarios_EntregaAlmacen End If End If ValidaSalidaCompleta = False - End If - - If ValidaSalidaCompleta Then ' condicion si hay una devolucion de remision, no verifique la totalidad surtido - For Each Gvr As GridViewRow In GvDatos.Rows - If Not Gvr.FCCheckBox("cbInv").Checked Or (Gvr.FCCheckBox("cbInv").Checked AndAlso Gvr.FCTextBox("TbCantidadF").Text.ToDecimal <> Gvr.DataKey("CantidadC").ToString().ToDecimal) Then - Alert("Es necesario surtir todos los productos. Por favor rectifique y vuelva a intentar.", TipoMensaje.MsgAdvertencia) - RegistraScript("playsonidito('142608__autistic-lucario__error.wav')") - Exit Sub - End If - Next - End If - End If - - Dim EsInterno As Integer = -1 - 'If TipoDocto = "Ped" Then - ' EsInterno = If(Me.EsInterno, 1, 0) - 'End If - - Dim ObjInventario As New ClsInventarios - Dim ObjConta As New ClsContabilidad(ObjInventario.IniciaTransacSQL()) - Dim ObjVentas As New ClsVentas(ObjInventario.IniciaTransacSQL()) - Dim ObjEventos As New ClsOIEventos(ObjInventario.IniciaTransacSQL()) - Dim ObjAcumuladores As New ClsAcumuladores(ObjInventario.IniciaTransacSQL()) - Dim ObjGeneral As New ClsGenerales(ObjInventario.IniciaTransacSQL()) - Dim CveMovimiento As Integer - Dim Folio As Integer - Dim ErrorMovInv As Boolean - Dim DtDetalle As New DataTable - Dim DtDetalleLote As New DataTable - Dim TextoError As New StringBuilder - - Dim CveMovimientoGarantia As Integer = -1 - Dim FolioGarantia As Integer = -1 - - Dim CveMovimientoVirtual As Integer = -1 - Dim FolioVirtual As Integer = -1 - - 'PASA DATOS DEL GV A DATATABLE PARA MANEJOR CON FOR EACH - Dim Index As Integer = 0 - For Each gvr As GridViewRow In GvDatos.Rows - If gvr.FCCheckBox("cbInv").Checked AndAlso gvr.FCTextBox("TbCantidadF").Text.ToDecimal > 0 Then - DtDatos.Rows(Index)("CantidadGV") = gvr.FCTextBox("TbCantidadF").Text.ToDecimal - DtDatos.Rows(Index)("CveSeccion") = gvr.FCDropDownList("DdlSeccionAlmacen").SelectedValue.ToEntero() - + End If + + If ValidaSalidaCompleta Then ' condicion si hay una devolucion de remision, no verifique la totalidad surtido + For Each Gvr As GridViewRow In GvDatos.Rows + If Not Gvr.FCCheckBox("cbInv").Checked Or (Gvr.FCCheckBox("cbInv").Checked AndAlso Gvr.FCTextBox("TbCantidadF").Text.ToDecimal <> Gvr.DataKey("CantidadC").ToString().ToDecimal) Then + Alert("Es necesario surtir todos los productos. Por favor rectifique y vuelva a intentar.", TipoMensaje.MsgAdvertencia) + RegistraScript("playsonidito('142608__autistic-lucario__error.wav')") + Exit Sub + End If + Next + End If + End If + + Dim EsInterno As Integer = -1 + 'If TipoDocto = "Ped" Then + ' EsInterno = If(Me.EsInterno, 1, 0) + 'End If + + Dim ObjInventario As New ClsInventarios + Dim ObjConta As New ClsContabilidad(ObjInventario.IniciaTransacSQL()) + Dim ObjVentas As New ClsVentas(ObjInventario.IniciaTransacSQL()) + Dim ObjEventos As New ClsOIEventos(ObjInventario.IniciaTransacSQL()) + Dim ObjAcumuladores As New ClsAcumuladores(ObjInventario.IniciaTransacSQL()) + Dim ObjGeneral As New ClsGenerales(ObjInventario.IniciaTransacSQL()) + Dim CveMovimiento As Integer + Dim Folio As Integer + Dim ErrorMovInv As Boolean + Dim DtDetalle As New DataTable + Dim DtDetalleLote As New DataTable + Dim TextoError As New StringBuilder + + Dim CveMovimientoGarantia As Integer = -1 + Dim FolioGarantia As Integer = -1 + + Dim CveMovimientoVirtual As Integer = -1 + Dim FolioVirtual As Integer = -1 + + 'PASA DATOS DEL GV A DATATABLE PARA MANEJOR CON FOR EACH + Dim Index As Integer = 0 + For Each gvr As GridViewRow In GvDatos.Rows + If gvr.FCCheckBox("cbInv").Checked AndAlso gvr.FCTextBox("TbCantidadF").Text.ToDecimal > 0 Then + DtDatos.Rows(Index)("CantidadGV") = gvr.FCTextBox("TbCantidadF").Text.ToDecimal + DtDatos.Rows(Index)("CveSeccion") = gvr.FCDropDownList("DdlSeccionAlmacen").SelectedValue.ToEntero() + If UsuarioActual.Empresa.Funcionalidad(578).ToEntero = 1 Then 'Esto es por que Dim DdlCaducidadProducto As DropDownList = gvr.FCDropDownList("DdlCaducidadProducto") @@ -2195,95 +2195,95 @@ Partial Class Inventarios_EntregaAlmacen DtDatos.Rows(Index)("Lote") = gvr.FCTextBox("TxtLote").Text End If - End If - Index += 1 - Next - - 'VALIDA SI HUBO CAMBIOS EN LA EXISTENCIA - Dim DtDatosVenta As New DataTable - If ObjInventario.EntregaAlmacenGet(CveVentaSurtir, UsuarioActual.CveEmpresa) Then - DtDatosVenta = ObjInventario.DtResultados - End If - Dim CantidadGV As Decimal = GvDatos.Rows.Cast(Of GridViewRow)().Sum(Function(gvr) gvr.DataKey("CantidadF").ToDecimal) - - 'VERIFICA SI LA CANTIDADES NOT SON MAYORES A LO ESTABLECIDO EN LA VENTA O LO QUE FALTA POR RECIBIR - If CantidadGV > DtDatosVenta.SUMD("CantidadF") OrElse Cantidad > CantidadVenta Then - ObjInventario.RollBack() - ObjInventario.Dispose() - ObjConta.Dispose() - ObjVentas.Dispose() - ObjEventos.Dispose() - '' identificar que productos no están completos. - CargaVentaPorSurtir(CveVentaSurtir) - CargaPendientes() - + End If + Index += 1 + Next + + 'VALIDA SI HUBO CAMBIOS EN LA EXISTENCIA + Dim DtDatosVenta As New DataTable + If ObjInventario.EntregaAlmacenGet(CveVentaSurtir, UsuarioActual.CveEmpresa) Then + DtDatosVenta = ObjInventario.DtResultados + End If + Dim CantidadGV As Decimal = GvDatos.Rows.Cast(Of GridViewRow)().Sum(Function(gvr) gvr.DataKey("CantidadF").ToDecimal) + + 'VERIFICA SI LA CANTIDADES NOT SON MAYORES A LO ESTABLECIDO EN LA VENTA O LO QUE FALTA POR RECIBIR + If CantidadGV > DtDatosVenta.SUMD("CantidadF") OrElse Cantidad > CantidadVenta Then + ObjInventario.RollBack() + ObjInventario.Dispose() + ObjConta.Dispose() + ObjVentas.Dispose() + ObjEventos.Dispose() + '' identificar que productos no están completos. + CargaVentaPorSurtir(CveVentaSurtir) + CargaPendientes() + If Cantidad > CantidadVenta Then Alert("No se puede procesar una cantidad mayor a la que esta definida en la venta.", TipoMensaje.MsgAdvertencia) Else Alert("Ha sido cambiada la informacion de existencias de la venta actual, se han recargado la información.", TipoMensaje.MsgAdvertencia) End If - Exit Sub - End If - - If Not ObjVentas.UpdateVentasDevolucionAlmacen(3, CveVentaSurtir) Then - ObjInventario.RollBack() - ObjInventario.Dispose() - ObjConta.Dispose() - ObjVentas.Dispose() - ObjEventos.Dispose() - Exit Sub - End If - - Dim DtTraspasos As New DataTable - DtTraspasos.Columns.Add("CveAlmacen", GetType(Integer)) - DtTraspasos.Columns.Add("Almacen", GetType(String)) - DtTraspasos.Columns.Add("CveMovimientoSalida", GetType(Integer)) - DtTraspasos.Columns.Add("FolioSalida", GetType(Integer)) - DtTraspasos.Columns.Add("CveMovimientoEntrada", GetType(Integer)) - DtTraspasos.Columns.Add("FolioEntrada", GetType(Integer)) - DtTraspasos.Columns.Add("CveTipoAlmacen", GetType(Integer)) - DtTraspasos.Columns.Add("CveConceptoMovimientoSalida", GetType(Integer)) - - Dim CveMovimientoSalida As Integer = -1, FolioSalida As Integer = -1, CveMovimientoEntrada As Integer = -1, CveMovimientoEntradaApartado As Integer = -1, FolioEntrada As Integer = -1, CveMovimientoSalidaDevRem As Integer = -1, FolioMovimientoSalidaDevRem As Integer = -1, CveMovimientoEntradaDevRem As Integer = -1, FolioMovimientoEntradaDevRem As Integer = -1 - - Dim DtDevSinCosto As New DataTable - DtDevSinCosto.Columns.Add("CveAlmacen", GetType(Integer)) - DtDevSinCosto.Columns.Add("Almacen", GetType(String)) - DtDevSinCosto.Columns.Add("CveMovimientoEntrada", GetType(Integer)) - DtDevSinCosto.Columns.Add("FolioEntrada", GetType(Integer)) - DtDevSinCosto.Columns.Add("CveTipoAlmacen", GetType(Integer)) - DtDevSinCosto.Columns.Add("CveConceptoMovimientoSalida", GetType(Integer)) - - Try - 'VALIDA EXISTENCIA 2 - If TipoMovimiento = 1 Then - Dim StrXML As New StringBuilder - StrXML.Append("") - Dim FechaCaducidad As Date - Dim Lote As String = "" - - For Each Dr As DataRow In DtDatos.Rows - FechaCaducidad = If(CBool(Dr("AplicaCaducidad")) AndAlso Dr("FechaCaducidad").ToString() <> "", Dr("FechaCaducidad").ToString().ToDate, MinFecha) - Lote = If(CBool(Dr("AplicaLote")), Dr("Lote").ToString().Trim, "-1") - - If Dr("CantidadGV").ToString().ToDecimal > 0 Then - If CBool(Dr("AplicaSerie")) Then - DtDetalle = DtDatosDetalle.FiltraParametros(String.Format("ConsecId = {0}", Dr("Consec"))) - For Each Dr1 As DataRow In DtDetalle.Rows - StrXML.AppendFormat("", Dr1("CvePS"), Dr1("CveUM"), 1, IfNull(Dr("CveSeccion"), -1), Dr1("Serie"), Lote, FechaCaducidad.ToString("yyyy/MM/dd")) - Next - Else - StrXML.AppendFormat("", Dr("CvePS"), Dr("CveUM"), Dr("CantidadGV"), IfNull(Dr("CveSeccion"), -1), "-1", Lote, FechaCaducidad.ToString("yyyy/MM/dd")) - End If - End If - Next - StrXML.Append("") - - Dim TieneErrorExistencia As Boolean = False - If ObjInventario.GetExistenciasPSXML(StrXML.ToString(), DdlAlmacen.SelectedValue.ToEntero(), TxtFecha.Text.ToDateTime.ToString("yyyy/MM/dd HH:mm"), CveSubProyecto, CveVendedor, If(UsuarioActual.Empresa.Funcionalidad(146) = "1", -1, CveCliente), If(TipoEntrega = 2, 1, -1), UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa) Then - If ObjInventario.DtResultados.Rows.Count > 0 Then - TieneErrorExistencia = True + Exit Sub + End If + + If Not ObjVentas.UpdateVentasDevolucionAlmacen(3, CveVentaSurtir) Then + ObjInventario.RollBack() + ObjInventario.Dispose() + ObjConta.Dispose() + ObjVentas.Dispose() + ObjEventos.Dispose() + Exit Sub + End If + + Dim DtTraspasos As New DataTable + DtTraspasos.Columns.Add("CveAlmacen", GetType(Integer)) + DtTraspasos.Columns.Add("Almacen", GetType(String)) + DtTraspasos.Columns.Add("CveMovimientoSalida", GetType(Integer)) + DtTraspasos.Columns.Add("FolioSalida", GetType(Integer)) + DtTraspasos.Columns.Add("CveMovimientoEntrada", GetType(Integer)) + DtTraspasos.Columns.Add("FolioEntrada", GetType(Integer)) + DtTraspasos.Columns.Add("CveTipoAlmacen", GetType(Integer)) + DtTraspasos.Columns.Add("CveConceptoMovimientoSalida", GetType(Integer)) + + Dim CveMovimientoSalida As Integer = -1, FolioSalida As Integer = -1, CveMovimientoEntrada As Integer = -1, CveMovimientoEntradaApartado As Integer = -1, FolioEntrada As Integer = -1, CveMovimientoSalidaDevRem As Integer = -1, FolioMovimientoSalidaDevRem As Integer = -1, CveMovimientoEntradaDevRem As Integer = -1, FolioMovimientoEntradaDevRem As Integer = -1 + + Dim DtDevSinCosto As New DataTable + DtDevSinCosto.Columns.Add("CveAlmacen", GetType(Integer)) + DtDevSinCosto.Columns.Add("Almacen", GetType(String)) + DtDevSinCosto.Columns.Add("CveMovimientoEntrada", GetType(Integer)) + DtDevSinCosto.Columns.Add("FolioEntrada", GetType(Integer)) + DtDevSinCosto.Columns.Add("CveTipoAlmacen", GetType(Integer)) + DtDevSinCosto.Columns.Add("CveConceptoMovimientoSalida", GetType(Integer)) + + Try + 'VALIDA EXISTENCIA 2 + If TipoMovimiento = 1 Then + Dim StrXML As New StringBuilder + StrXML.Append("") + Dim FechaCaducidad As Date + Dim Lote As String = "" + + For Each Dr As DataRow In DtDatos.Rows + FechaCaducidad = If(CBool(Dr("AplicaCaducidad")) AndAlso Dr("FechaCaducidad").ToString() <> "", Dr("FechaCaducidad").ToString().ToDate, MinFecha) + Lote = If(CBool(Dr("AplicaLote")), Dr("Lote").ToString().Trim, "-1") + + If Dr("CantidadGV").ToString().ToDecimal > 0 Then + If CBool(Dr("AplicaSerie")) Then + DtDetalle = DtDatosDetalle.FiltraParametros(String.Format("ConsecId = {0}", Dr("Consec"))) + For Each Dr1 As DataRow In DtDetalle.Rows + StrXML.AppendFormat("", Dr1("CvePS"), Dr1("CveUM"), 1, IfNull(Dr("CveSeccion"), -1), Dr1("Serie"), Lote, FechaCaducidad.ToString("yyyy/MM/dd")) + Next + Else + StrXML.AppendFormat("", Dr("CvePS"), Dr("CveUM"), Dr("CantidadGV"), IfNull(Dr("CveSeccion"), -1), "-1", Lote, FechaCaducidad.ToString("yyyy/MM/dd")) + End If + End If + Next + StrXML.Append("") + + Dim TieneErrorExistencia As Boolean = False + If ObjInventario.GetExistenciasPSXML(StrXML.ToString(), DdlAlmacen.SelectedValue.ToEntero(), TxtFecha.Text.ToDateTime.ToString("yyyy/MM/dd HH:mm"), CveSubProyecto, CveVendedor, If(UsuarioActual.Empresa.Funcionalidad(146) = "1", -1, CveCliente), If(TipoEntrega = 2, 1, -1), UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa) Then + If ObjInventario.DtResultados.Rows.Count > 0 Then + TieneErrorExistencia = True For Each Dr As DataRow In ObjInventario.DtResultados.Rows Dim SerieLoteCaducidad As String = "," @@ -2297,1721 +2297,1721 @@ Partial Class Inventarios_EntregaAlmacen SerieLoteCaducidad = $"{SerieLoteCaducidad} Caducidad: { Dr("FechaCaducidad").ToString.Trim.ToDate.ToString("dd/MM/yyyy")}" End If TextoError.AppendFormat(" - {0} Existencia: {1:#,##0.##} {2}
    ", Dr("CodigoPS"), Dr("Existencia"), If(SerieLoteCaducidad <> ",", SerieLoteCaducidad, "")) - Next - End If - Else - TieneErrorExistencia = True - End If - - If TieneErrorExistencia Then - ObjInventario.RollBack() - ObjInventario.Dispose() - ObjConta.Dispose() - ObjVentas.Dispose() - ObjEventos.Dispose() - If TextoError.Length > 0 Then - Alert($" Lo(s) siguiente(s) Productos no tienen existencia suficiente:

    {TextoError}", TipoMensaje.MsgAdvertencia) - End If - RegistraScript("playsonidito('142608__autistic-lucario__error.wav')") - Exit Sub - End If - End If - - '' TERMINA: VALIDACIONES - - Dim CantidadPendienteSinCosto As Decimal = 0 - Dim CantidadSaldoSinCosto As Decimal = 0 - - Dim CantidadSalidaSinCosto As Decimal = 0 - - '' COMIENZA: SIN COSTO - If TipoDocto.Contiene("Ing", "Rem", "Ped") AndAlso UsuarioActual.Empresa.Funcionalidad(587) = "1" AndAlso TipoMovimiento = 1 Then - - Dim CveConceptoSalidaSinCosto As Integer = If(TipoDocto.Contiene("Rem", "Ped"), 8, 40) - - For Each Dr As DataRow In DtDatos.Rows - If Dr("CantidadGV").ToString().ToDecimal > 0 Then - If CBool(Dr("AplicaSerie")) Then - DtDetalle = DtDatosDetalle.FiltraParametros(String.Format("ConsecId = {0}", Dr("Consec"))) - For Each Dr1 As DataRow In DtDetalle.Rows - If ObjInventario.GetExistenciasProducto(Dr1("CvePS").ToString().ToEntero(), Dr1("CveUM").ToString().ToEntero(), UsuarioActual.CveEmpresa, -1, FechaMovto:=TxtFecha.Text.ToDateTime.ToString("yyyy/MM/dd HH:mm"), Serie:=Dr1("Serie").ToString(), CveTipoAlmacen:=26, CveSubProyecto:=CveSubProyecto, Caducidad:=If(CBool(Dr("AplicaCaducidad")), Dr("FechaCaducidad").ToString().ToDate, MinFecha), Lote:=If(CBool(Dr("AplicaLote")), Dr("Lote").ToString(), "-1"), CveSeccionAlmacen:=If(CBool(Dr("AplicaSeccion")), Dr("CveSeccion").ToString().ToEntero(), -1)) Then - For Each Dr2 As DataRow In ObjInventario.DtResultados.FiltraParametros("CveAlmacen > 0 AND ExistenciaFinal > 0").Rows - - 'BUSCA SI EXISTE YA UN TRASPASO DEL ALMACEN DE APARTADO - CveMovimientoSalida = DtTraspasos.FiltroPrimeroValor("CveMovimientoSalida", $"CveAlmacen = {Dr2("CveAlmacen")}").ToEntero() - - If Not CveMovimientoSalida > 0 Then - - CveMovimientoSalida = ObjInventario.AddMovimiento(Dr2("CveAlmacen").ToString().ToEntero(), CveConceptoSalidaSinCosto, 1, TxtFecha.Text.ToDate, -1, UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa, -1, CveVentaSurtir, -1, -1, CveOS:=CveOSSurtir, - Observaciones:=TxtObservaciones.Text.Trim, Guia:=Guia, CveContrato:=CveContrato, Modulo:="RE/GSC1") - FolioSalida = ObjInventario.Folio - - If Not CveMovimientoSalida > 0 Then - ErrorMovInv = True - TextoError.AppendFormat("Ocurrió un error al procesar los movimientos de traspaso de apartado. Por favor vuelva a intentar.") - Exit For - End If - - Dim DrMovto As DataRow = DtTraspasos.NewRow - DrMovto("Almacen") = Dr2("Almacen").ToString().ToEntero() - DrMovto("CveAlmacen") = Dr2("CveAlmacen").ToString().ToEntero() - DrMovto("CveMovimientoSalida") = CveMovimientoSalida - DrMovto("FolioSalida") = FolioSalida - DrMovto("CveTipoAlmacen") = 26 - DrMovto("CveConceptoMovimientoSalida") = CveConceptoSalidaSinCosto - DtTraspasos.Rows.Add(DrMovto) - End If - - - CantidadPendienteSinCosto = 1 - - If Not ObjInventario.AddMovimientoDetalle(CveMovimientoSalida, CantidadPendienteSinCosto, Dr("CveUM").ToString().ToEntero(), Dr("CvePS").ToString().ToEntero(), 0, Serie:=Dr1("Serie").ToString(), CveVentaDetalle:=Dr("CveVentaDetalle").ToString().ToEntero(), FechaCaducidad:=If(CBool(Dr("AplicaCaducidad")), Dr("FechaCaducidad").ToString().ToDate, MinFecha), Lote:=If(CBool(Dr("AplicaLote")), Dr("Lote").ToString(), "-1"), CveSeccionAlmacen:=If(CBool(Dr("AplicaSeccion")), Dr("CveSeccion").ToString().ToEntero(), -1)) Then - ErrorMovInv = True - TextoError.AppendFormat("Ocurrió un Error al procesar los conceptos de traspaso de apartado. Por favor vuelva a intentar.") - Exit For - End If - - DtDatosDetalle.Select($"Consec = {Dr1("Consec")}")(0)("FueTraspaso") = 1 - DtDatosDetalle.Select($"Consec = {Dr1("Consec")}")(0)("CveVentaDetalle") = Dr("CveVentaDetalle") - Dr("CantidadTraspaso") = Dr("CantidadTraspaso").ToString().ToDecimal + CantidadPendienteSinCosto - Exit For - Next - End If - If ErrorMovInv Then Exit For - Next - - Else - - If ObjInventario.GetExistenciasProducto(Dr("CvePS").ToString().ToEntero(), Dr("CveUM").ToString().ToEntero(), UsuarioActual.CveEmpresa, -1, FechaMovto:=TxtFecha.Text.ToDateTime.ToString("yyyy/MM/dd HH:mm"), CveTipoAlmacen:=26, CveSubProyecto:=CveSubProyecto, Caducidad:=If(CBool(Dr("AplicaCaducidad")), Dr("FechaCaducidad").ToString().ToDate, MinFecha), Lote:=If(CBool(Dr("AplicaLote")), Dr("Lote").ToString(), "-1"), CveSeccionAlmacen:=If(CBool(Dr("AplicaSeccion")), Dr("CveSeccion").ToString().ToEntero(), -1)) Then - - CantidadSaldoSinCosto = Dr("CantidadGV").ToString().ToDecimal - - For Each Dr1 As DataRow In ObjInventario.DtResultados.FiltraParametros("CveAlmacen > 0 AND ExistenciaFinal > 0").Rows - - 'BUSCA SI EXISTE YA UN TRASPASO DEL ALMACEN DE APARTADO - CveMovimientoSalida = DtTraspasos.FiltroPrimeroValor("CveMovimientoSalida", $"CveAlmacen = {Dr1("CveAlmacen")}").ToEntero() - - If Not CveMovimientoSalida > 0 Then - CveMovimientoSalida = ObjInventario.AddMovimiento(Dr1("CveAlmacen").ToString().ToEntero(), CveConceptoSalidaSinCosto, 1, TxtFecha.Text.ToDate, -1, UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa, -1, CveVentaSurtir, -1, -1, CveOS:=CveOSSurtir, - Observaciones:=TxtObservaciones.Text.Trim, Guia:=Guia, CveContrato:=CveContrato, Modulo:="RE/GSC3") - FolioSalida = ObjInventario.Folio - - If Not CveMovimientoSalida > 0 Then - ErrorMovInv = True - TextoError.AppendFormat("Ocurrió un error al procesar los movimientos de traspaso de apartado. Por favor vuelva a intentar.") - Exit For - End If - - Dim DrMovto As DataRow = DtTraspasos.NewRow - DrMovto("Almacen") = Dr1("Almacen").ToString().ToEntero() - DrMovto("CveAlmacen") = Dr1("CveAlmacen").ToString().ToEntero() - DrMovto("CveMovimientoSalida") = CveMovimientoSalida - DrMovto("FolioSalida") = FolioSalida - DrMovto("CveTipoAlmacen") = 26 - DrMovto("CveConceptoMovimientoSalida") = CveConceptoSalidaSinCosto - DtTraspasos.Rows.Add(DrMovto) - End If - - CantidadPendienteSinCosto = If(Dr1("ExistenciaFinal").ToString().ToDecimal > CantidadSaldoSinCosto, CantidadSaldoSinCosto, Dr1("ExistenciaFinal").ToString().ToDecimal) - - If Not ObjInventario.AddMovimientoDetalle(CveMovimientoSalida, CantidadPendienteSinCosto.ToString().ToDecimal, Dr("CveUM").ToString().ToEntero(), Dr("CvePS").ToString().ToEntero(), 0, - Serie:=Dr("Serie").ToString(), - CveVentaDetalle:=Dr("CveVentaDetalle").ToString().ToEntero(), - FechaCaducidad:=If(CBool(Dr("AplicaCaducidad")), Dr("FechaCaducidad").ToString().ToDate, MinFecha), - Lote:=If(CBool(Dr("AplicaLote")), Dr("Lote").ToString(), "-1"), - CveSeccionAlmacen:=If(CBool(Dr("AplicaSeccion")), Dr("CveSeccion").ToString().ToEntero(), -1)) Then - ErrorMovInv = True - TextoError.AppendFormat("Ocurrió un error al procesar los conceptos de traspaso de apartado. Por favor vuelva a intentar.") - Exit For - End If - CantidadSaldoSinCosto -= CantidadPendienteSinCosto - Dr("CantidadTraspaso") = Dr("CantidadTraspaso").ToString().ToDecimal + CantidadPendienteSinCosto - If CantidadSaldoSinCosto <= 0 Then Exit For - Next - - If ErrorMovInv Then Exit For - Else - ErrorMovInv = True - End If - End If - CantidadSalidaSinCosto += Dr("CantidadTraspaso").ToString().ToDecimal() - If ErrorMovInv Then Exit For - End If - Next - - 'ENTRADA POR TRASPASO A ENTREGA POR ADELANTADO - If TipoDocto.Contiene("Rem", "Ped") AndAlso Not ErrorMovInv Then - For Each Dr1 As DataRow In DtTraspasos.Select("CveTipoAlmacen = 26") - CveMovimientoSalida = Dr1("CveMovimientoSalida").ToString().ToEntero() - - Dim CveAlmacenExA As Integer = GlobalDTAlmacen(UsuarioActual.CveEmpresa, CveTipoAlmacen:=10).FiltroPrimeroValor("CveAlmacen", $"CveSubProyecto={CveSubProyecto}").ToEntero() - - CveMovimientoEntradaApartado = ObjInventario.AddMovimiento(CveAlmacenExA, 9, 1, TxtFecha.Text.ToDate, -1, UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa, -1, CveVentaSurtir, -1, -1, CveOS:=CveOSSurtir, - Observaciones:=TxtObservaciones.Text.Trim, CveAlmacenDestino:=DdlAlmacen.SelectedValue.ToEntero(), CveMovimientoRelacionado:=CveMovimientoSalida, - Guia:=Guia, CveContrato:=CveContrato, CveVendedor:=CveVendedor, CveCliente:=CveCliente, Modulo:="RE/G4") - FolioEntrada = ObjInventario.Folio - - If Not CveMovimientoEntradaApartado > 0 Then - ErrorMovInv = True - TextoError.AppendFormat("Ocurrió un error al procesar los movimientos de traspaso de apartado. Por favor vuelva a intentar.") - Exit For - End If - - Dr1("CveMovimientoEntrada") = CveMovimientoEntradaApartado - Dr1("FolioEntrada") = FolioEntrada - - If ObjInventario.GetMovimientosDetalle(CveMovimientoSalida, UsuarioActual.CveEmpresa) Then - Dim CveSeccionAlmacen As Integer = -1 - For Each Dr As DataRow In ObjInventario.DtResultados.Rows - - If Not ObjInventario.AddMovimientoDetalle(CveMovimientoEntradaApartado, Dr("Cantidad").ToString().ToDecimal, Dr("CveUM").ToString().ToEntero(), Dr("CvePS").ToString().ToEntero(), Dr("PU").ToString().ToDecimal, CveAF:=Dr("CveAF").ToString().ToEntero(), Serie:=Dr("Serie").ToString(), CveMovimientoDetalleEntrada:=Dr("CveMovimientoDetalle").ToString().ToEntero(), CveVentaDetalle:=Dr("CveVentaDetalle").ToString().ToEntero(), FechaCaducidad:=If(CBool(Dr("AplicaCaducidad")), Dr("FechaCaducidad").ToString().ToDate, MinFecha), Lote:=If(CBool(Dr("AplicaLote")), Dr("Lote").ToString(), "-1"), CveSeccionAlmacen:=-3) Then - ErrorMovInv = True - TextoError.AppendFormat("Ocurrió un error al procesar los conceptos de traspaso de apartado. Por favor vuelva a intentar.") - Exit For - End If - Next - End If - - If ErrorMovInv Then Exit For - Next - End If - - If Not ErrorMovInv AndAlso CveMovimientoSalida > 0 AndAlso TipoDocto.Contiene("Rem", "Ped") Then - Dim CvePrePolizaSinCosto As Integer = ObjConta.AddPrePolizas("EA/SinCost", 53, 0, 0, 1, TxtFecha.Text.ToDate, "Entrega", UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa) - If CvePrePolizaSinCosto > 0 Then - - If Not ErrorMovInv AndAlso Not ObjConta.AddPrePolizasDetalle(CvePrePolizaSinCosto, True, 0, 0, 68, TxtObservaciones.Text, TxtObservaciones.Text, -1, -1, CveMovimientoAlmacen:=CveMovimientoSalida, Contabilizable:=False) Then - ErrorMovInv = True - End If - If Not ErrorMovInv AndAlso Not ObjConta.AddPrePolizasDetalle(CvePrePolizaSinCosto, False, 0, 0, 68, TxtObservaciones.Text, TxtObservaciones.Text, -1, -1, CveMovimientoAlmacen:=CveMovimientoEntradaApartado, Contabilizable:=False) Then - ErrorMovInv = True - End If - - Else - ErrorMovInv = True - End If - End If - - End If - - If Not ErrorMovInv Then - For Each DrMovto As DataRow In DtTraspasos.FiltraParametros("CveConceptoMovimientoSalida = 40").Rows - ErrorMovInv = Not GenerarPrePoliza(ObjInventario, ObjVentas, ObjConta, DrMovto("CveMovimientoSalida").ToString().ToEntero(), TextoError) - If ErrorMovInv Then - Exit For - End If - Next - End If - - ''TERMINA: SIN COSTO - - '' COMIENZA: APARTADOS - Dim CantidadPendiente As Decimal = 0 - Dim CantidadSaldo As Decimal = 0 - - - If Not ErrorMovInv AndAlso CveVendedor > 0 AndAlso (UsuarioActual.Empresa.Funcionalidad(146) = "1" Or CveCliente > 0) Then 'no debe considerar cuando es pedido de contrato - If TipoMovimiento = 1 Then ' SI ES DEVOLUCION NO APLICA APARTADO - ' SALIDA POR TRASPASO DE LOS ALMACENES DE APARTADO - For Each Dr As DataRow In DtDatos.Rows - If Dr("CantidadGV").ToString().ToDecimal > 0 Then - - If CBool(Dr("AplicaSerie")) Then - - DtDetalle = DtDatosDetalle.FiltraParametros(String.Format("ConsecId = {0}", Dr("Consec"))) - For Each Dr1 As DataRow In DtDetalle.Rows - If ObjInventario.GetExistenciasProducto(Dr1("CvePS").ToString().ToEntero(), Dr1("CveUM").ToString().ToEntero(), UsuarioActual.CveEmpresa, -1, FechaMovto:=TxtFecha.Text.ToDateTime.ToString("yyyy/MM/dd HH:mm"), Serie:=Dr1("Serie").ToString(), CveTipoAlmacen:=9, CveVendedor:=CveVendedor, CveSubProyecto:=CveSubProyecto, CveCliente:=If(UsuarioActual.Empresa.Funcionalidad(146) = "1", -1, CveCliente), ExcluyeApartados:=-1, Caducidad:=If(CBool(Dr("AplicaCaducidad")), Dr("FechaCaducidad").ToString().ToDate, MinFecha), Lote:=If(CBool(Dr("AplicaLote")), Dr("Lote").ToString(), "-1"), CveSeccionAlmacen:=-1) Then - Dim CveSeccionAlmacen As Integer = 0 - For Each Dr2 As DataRow In ObjInventario.DtResultados.FiltraParametros("CveAlmacen > 0 AND ExistenciaFinal > 0").Rows - - 'BUSCA SI EXISTE YA UN TRASPASO DEL ALMACEN DE APARTADO - CveMovimientoSalida = DtTraspasos.FiltroPrimeroValor("CveMovimientoSalida", $"CveAlmacen = {Dr2("CveAlmacen")}").ToEntero() - - If Not CveMovimientoSalida > 0 Then - CveMovimientoSalida = ObjInventario.AddMovimiento(Dr2("CveAlmacen").ToString().ToEntero(), 8, 1, TxtFecha.Text.ToDate, -1, UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa, -1, CveVentaSurtir, -1, -1, CveOS:=CveOSSurtir, - Observaciones:=TxtObservaciones.Text.Trim, Guia:=Guia, CveContrato:=CveContrato, CveVendedor:=CveVendedor, CveCliente:=If(UsuarioActual.Empresa.Funcionalidad(146) = "1", -1, CveCliente), - CveAlmacenDestino:=DdlAlmacen.SelectedValue.ToEntero(), Modulo:="RE/G1") - FolioSalida = ObjInventario.Folio - - If Not CveMovimientoSalida > 0 Then - ErrorMovInv = True - TextoError.AppendFormat("Ocurrió un error al procesar los movimientos de traspaso de apartado. Por favor vuelva a intentar.") - Exit For - End If - - Dim DrMovto As DataRow = DtTraspasos.NewRow - DrMovto("Almacen") = Dr2("Almacen").ToString().ToEntero() - DrMovto("CveAlmacen") = Dr2("CveAlmacen").ToString().ToEntero() - DrMovto("CveMovimientoSalida") = CveMovimientoSalida - DrMovto("FolioSalida") = FolioSalida - DrMovto("CveTipoAlmacen") = 9 - DrMovto("CveConceptoMovimientoSalida") = 8 - DtTraspasos.Rows.Add(DrMovto) - End If - - - CantidadPendiente = 1 - CveSeccionAlmacen = -3 - - If Not ObjInventario.AddMovimientoDetalle(CveMovimientoSalida, CantidadPendiente.ToString().ToDecimal, Dr("CveUM").ToString().ToEntero(), Dr("CvePS").ToString().ToEntero(), 0, Serie:=Dr1("Serie").ToString(), CveVentaDetalle:=Dr("CveVentaDetalle").ToString().ToEntero(), FechaCaducidad:=If(CBool(Dr("AplicaCaducidad")), Dr("FechaCaducidad").ToString().ToDate, MinFecha), Lote:=If(CBool(Dr("AplicaLote")), Dr("Lote").ToString(), "-1"), CveSeccionAlmacen:=CveSeccionAlmacen) Then - ErrorMovInv = True - TextoError.AppendFormat("Ocurrió un Error al procesar los conceptos de traspaso de apartado. Por favor vuelva a intentar.") - Exit For - End If - - DtDatosDetalle.Select($"Consec = {Dr1("Consec")}")(0)("FueTraspaso") = 1 - DtDatosDetalle.Select($"Consec = {Dr1("Consec")}")(0)("CveVentaDetalle") = Dr("CveVentaDetalle") - Dr("CantidadTraspaso") = Dr("CantidadTraspaso").ToString().ToDecimal + CantidadPendiente - Exit For - Next - End If - If ErrorMovInv Then Exit For - Next - - ElseIf CBool(Dr("AplicaLote")) Then - - DtDetalle = DtDatosDetalleLote.FiltraParametros(String.Format("ConsecId = {0}", Dr("Consec"))) - For Each Dr1 As DataRow In DtDetalle.Rows - If ObjInventario.GetExistenciasProducto(Dr1("CvePS").ToString().ToEntero(), Dr1("CveUM").ToString().ToEntero(), UsuarioActual.CveEmpresa, -1, FechaMovto:=TxtFecha.Text.ToDateTime.ToString("yyyy/MM/dd HH:mm"), Lote:=Dr1("Lote").ToString(), CveTipoAlmacen:=9, CveVendedor:=CveVendedor, CveSubProyecto:=CveSubProyecto, CveCliente:=If(UsuarioActual.Empresa.Funcionalidad(146) = "1", -1, CveCliente), ExcluyeApartados:=-1, Caducidad:=If(CBool(Dr("AplicaCaducidad")), Dr("FechaCaducidad").ToString().ToDate, MinFecha), CveSeccionAlmacen:=-1) Then - - CantidadSaldo = Dr("CantidadGV").ToString().ToDecimal - - For Each Dr2 As DataRow In ObjInventario.DtResultados.FiltraParametros("CveAlmacen > 0 AND ExistenciaFinal > 0").Rows - - 'BUSCA SI EXISTE YA UN TRASPASO DEL ALMACEN DE APARTADO - CveMovimientoSalida = DtTraspasos.FiltroPrimeroValor("CveMovimientoSalida", $"CveAlmacen = {Dr2("CveAlmacen")}").ToEntero() - - If Not CveMovimientoSalida > 0 Then - CveMovimientoSalida = ObjInventario.AddMovimiento(Dr2("CveAlmacen").ToString().ToEntero(), 8, 1, TxtFecha.Text.ToDate, -1, UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa, -1, CveVentaSurtir, -1, -1, CveOS:=CveOSSurtir, Observaciones:=TxtObservaciones.Text.Trim, - Guia:=Guia, CveContrato:=CveContrato, CveVendedor:=CveVendedor, CveCliente:=If(UsuarioActual.Empresa.Funcionalidad(146) = "1", -1, CveCliente), - CveAlmacenDestino:=DdlAlmacen.SelectedValue.ToEntero(), Modulo:="RE/G2") - FolioSalida = ObjInventario.Folio - - If Not CveMovimientoSalida > 0 Then - ErrorMovInv = True - TextoError.AppendFormat("Ocurrió un error al procesar los movimientos de traspaso de apartado. Por favor vuelva a intentar.") - Exit For - End If - - Dim DrMovto As DataRow = DtTraspasos.NewRow - DrMovto("Almacen") = Dr2("Almacen").ToString().ToEntero() - DrMovto("CveAlmacen") = Dr2("CveAlmacen").ToString().ToEntero() - DrMovto("CveMovimientoSalida") = CveMovimientoSalida - DrMovto("FolioSalida") = FolioSalida - DrMovto("CveTipoAlmacen") = 9 - DrMovto("CveConceptoMovimientoSalida") = 8 - DtTraspasos.Rows.Add(DrMovto) - End If - - CantidadPendiente = If(Dr1("Cantidad").ToString().ToDecimal > CantidadSaldo, CantidadSaldo, Dr1("Cantidad").ToString().ToDecimal) - - If Not ObjInventario.AddMovimientoDetalle(CveMovimientoSalida, CantidadPendiente.ToString().ToDecimal, Dr("CveUM").ToString().ToEntero(), Dr("CvePS").ToString().ToEntero(), 0, Lote:=Dr1("Lote").ToString(), CveVentaDetalle:=Dr("CveVentaDetalle").ToString().ToEntero(), FechaCaducidad:=If(CBool(Dr("AplicaCaducidad")), Dr("FechaCaducidad").ToString().ToDate, MinFecha), CveSeccionAlmacen:=If(CBool(Dr("AplicaSeccion")), Dr("CveSeccion").ToString().ToEntero(), -1)) Then - ErrorMovInv = True - TextoError.AppendFormat("Ocurrió un error al procesar los conceptos de traspaso de apartado. Por favor vuelva a intentar.") - Exit For - End If - - DtDatosDetalle.Select($"Consec = {Dr1("Consec")}")(0)("FueTraspaso") = 1 - DtDatosDetalle.Select($"Consec = {Dr1("Consec")}")(0)("CveVentaDetalle") = Dr("CveVentaDetalle") - - CantidadSaldo -= CantidadPendiente - Dr("CantidadTraspaso") = Dr("CantidadTraspaso").ToString().ToDecimal + CantidadPendiente - If CantidadSaldo <= 0 Then Exit For - Next - End If - Next - - Else - - If ObjInventario.GetExistenciasProducto(Dr("CvePS").ToString().ToEntero(), Dr("CveUM").ToString().ToEntero(), UsuarioActual.CveEmpresa, -1, FechaMovto:=TxtFecha.Text.ToDateTime.ToString("yyyy/MM/dd HH:mm"), CveTipoAlmacen:=9, CveVendedor:=CveVendedor, CveSubProyecto:=CveSubProyecto, CveCliente:=If(UsuarioActual.Empresa.Funcionalidad(146) = "1", -1, CveCliente), ExcluyeApartados:=-1, Caducidad:=If(CBool(Dr("AplicaCaducidad")), Dr("FechaCaducidad").ToString().ToDate, MinFecha), Lote:=If(CBool(Dr("AplicaLote")), Dr("Lote").ToString(), "-1"), CveSeccionAlmacen:=-1) Then - - CantidadSaldo = Dr("CantidadGV").ToString().ToDecimal - - For Each Dr1 As DataRow In ObjInventario.DtResultados.FiltraParametros("CveAlmacen > 0 AND ExistenciaFinal > 0").Rows - - 'BUSCA SI EXISTE YA UN TRASPASO DEL ALMACEN DE APARTADO - CveMovimientoSalida = DtTraspasos.FiltroPrimeroValor("CveMovimientoSalida", $"CveAlmacen = {Dr1("CveAlmacen")}").ToEntero() - - If Not CveMovimientoSalida > 0 Then - - - CveMovimientoSalida = ObjInventario.AddMovimiento(Dr1("CveAlmacen").ToString().ToEntero(), 8, 1, TxtFecha.Text.ToDate, -1, UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa, -1, CveVentaSurtir, -1, -1, CveOS:=CveOSSurtir, - Observaciones:=TxtObservaciones.Text.Trim, Guia:=Guia, CveContrato:=CveContrato, CveVendedor:=CveVendedor, - CveCliente:=If(UsuarioActual.Empresa.Funcionalidad(146) = "1", -1, CveCliente), CveAlmacenDestino:=DdlAlmacen.SelectedValue.ToEntero(), Modulo:="RE/G3") - FolioSalida = ObjInventario.Folio - - If Not CveMovimientoSalida > 0 Then - ErrorMovInv = True - TextoError.AppendFormat("Ocurrió un error al procesar los movimientos de traspaso de apartado. Por favor vuelva a intentar.") - Exit For - End If - - Dim DrMovto As DataRow = DtTraspasos.NewRow - DrMovto("Almacen") = Dr1("Almacen").ToString().ToEntero() - DrMovto("CveAlmacen") = Dr1("CveAlmacen").ToString().ToEntero() - DrMovto("CveMovimientoSalida") = CveMovimientoSalida - DrMovto("FolioSalida") = FolioSalida - DrMovto("CveTipoAlmacen") = 9 - DrMovto("CveConceptoMovimientoSalida") = 8 - DtTraspasos.Rows.Add(DrMovto) - End If - - CantidadPendiente = If(Dr1("ExistenciaFinal").ToString().ToDecimal > CantidadSaldo, CantidadSaldo, Dr1("ExistenciaFinal").ToString().ToDecimal) - - If Not ObjInventario.AddMovimientoDetalle(CveMovimientoSalida, CantidadPendiente.ToString().ToDecimal, Dr("CveUM").ToString().ToEntero(), Dr("CvePS").ToString().ToEntero(), 0, - Serie:=Dr("Serie").ToString(), - CveVentaDetalle:=Dr("CveVentaDetalle").ToString().ToEntero(), - FechaCaducidad:=If(CBool(Dr("AplicaCaducidad")), Dr("FechaCaducidad").ToString().ToDate, MinFecha), - Lote:=If(CBool(Dr("AplicaLote")), Dr("Lote").ToString(), "-1"), - CveSeccionAlmacen:=-3) Then - ErrorMovInv = True - TextoError.AppendFormat("Ocurrió un error al procesar los conceptos de traspaso de apartado. Por favor vuelva a intentar.") - Exit For - End If - - CantidadSaldo -= CantidadPendiente - Dr("CantidadTraspaso") = Dr("CantidadTraspaso").ToString().ToDecimal + CantidadPendiente - If CantidadSaldo <= 0 Then Exit For - Next - - If ErrorMovInv Then Exit For - - - Else - ErrorMovInv = True - End If - - End If - If ErrorMovInv Then Exit For - - End If - - Next - - 'ENTRADA POR TRASPASO AL ALMACEN GENERAL - If Not ErrorMovInv Then - For Each Dr1 As DataRow In DtTraspasos.Select("CveTipoAlmacen = 9") - CveMovimientoSalida = Dr1("CveMovimientoSalida").ToString().ToEntero() - - CveMovimientoEntradaApartado = ObjInventario.AddMovimiento(DdlAlmacen.SelectedValue.ToEntero(), 9, 1, TxtFecha.Text.ToDate, -1, UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa, -1, CveVentaSurtir, -1, -1, CveOS:=CveOSSurtir, - Observaciones:=TxtObservaciones.Text.Trim, CveAlmacenDestino:=DdlAlmacen.SelectedValue.ToEntero(), CveMovimientoRelacionado:=CveMovimientoSalida, - Guia:=Guia, CveContrato:=CveContrato, CveVendedor:=CveVendedor, CveCliente:=CveCliente, Modulo:="RE/G4") - FolioEntrada = ObjInventario.Folio - - If Not CveMovimientoEntradaApartado > 0 Then - ErrorMovInv = True - TextoError.AppendFormat("Ocurrió un error al procesar los movimientos de traspaso de apartado. Por favor vuelva a intentar.") - Exit For - End If - - Dr1("CveMovimientoEntrada") = CveMovimientoEntradaApartado - Dr1("FolioEntrada") = FolioEntrada - - If ObjInventario.GetMovimientosDetalle(CveMovimientoSalida, UsuarioActual.CveEmpresa) Then - For Each Dr As DataRow In ObjInventario.DtResultados.Rows - If Not ObjInventario.AddMovimientoDetalle(CveMovimientoEntradaApartado, Dr("Cantidad").ToString().ToDecimal, Dr("CveUM").ToString().ToEntero(), Dr("CvePS").ToString().ToEntero(), Dr("PU").ToString().ToDecimal, CveAF:=Dr("CveAF").ToString().ToEntero(), Serie:=Dr("Serie").ToString(), CveMovimientoDetalleEntrada:=Dr("CveMovimientoDetalle").ToString().ToEntero(), CveVentaDetalle:=Dr("CveVentaDetalle").ToString().ToEntero(), FechaCaducidad:=If(CBool(Dr("AplicaCaducidad")), Dr("FechaCaducidad").ToString().ToDate, MinFecha), Lote:=If(CBool(Dr("AplicaLote")), Dr("Lote").ToString(), "-1"), CveSeccionAlmacen:=-3) Then - ErrorMovInv = True - TextoError.AppendFormat("Ocurrió un error al procesar los conceptos de traspaso de apartado. Por favor vuelva a intentar.") - Exit For - End If - Next - End If - - If ErrorMovInv Then Exit For - - Next - End If - End If - End If - '' TERMINA: APARTADOS - Dim TotalGarantia As Decimal = 0 - - ' COMIENZA: GARANTIAS - If Not ErrorMovInv AndAlso TipoDocto.Contiene("Ing", "Rem", "Ped") AndAlso UsuarioActual.Empresa.Funcionalidad(531) = "1" AndAlso TipoMovimiento = 1 Then - - Dim CveAlmacenGarantia As Integer = GlobalDTAlmacen(UsuarioActual.CveEmpresa, CveTipoAlmacen:=6).FiltroPrimeroValor("CveAlmacen", $"CveSubProyecto={CveSubProyecto}").ToEntero() - Dim DtGarantias As DataTable = Nothing - - If ObjAcumuladores.GetGarantiasDetalle(CveVentaSurtir) Then - DtGarantias = ObjAcumuladores.DtResultados.Copy() - End If - - If DtGarantias IsNot Nothing AndAlso DtGarantias.Rows.Count > 0 AndAlso CveAlmacenGarantia > 0 Then - CveMovimientoGarantia = ObjInventario.AddMovimiento(CveAlmacenGarantia, 14, 1, TxtFecha.Text.ToDate, -1, UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa, -1, CveVentaSurtir, -1, -1, CveOS:=CveOSSurtir, Observaciones:=TxtObservaciones.Text.Trim, Guia:=Guia, Modulo:="EA/G5") - FolioGarantia = ObjInventario.Folio - - For Each RowGarantia As DataRow In DtGarantias.Rows - Dim CvePS As Integer = RowGarantia("CvePS").ToString().ToEntero() - Dim CveTamaño As Integer = RowGarantia("CveTamaño").ToString().ToEntero() - Dim CveUM As Integer = RowGarantia("CveUnidadMedida").ToString().ToEntero() - Dim PU As Decimal = 0 'valor cero, por tema contable 'RowGarantia("Importe").ToString().ToDecimal() ' / RowGarantia("Cantidad").ToString().ToDouble() - Dim Serie As String = RowGarantia("Comprobante").ToString - - If Not ObjInventario.AddMovimientoDetalle(CveMovimientoGarantia, RowGarantia("Cantidad").ToString().ToDecimal, CveUM, CvePS, PU, Serie:=Serie, CveVentaDetalle:=IIf(RowGarantia("MismoCvePS").ToString = "1", RowGarantia("CveVentaDetalle"), -1).ToString.ToEntero) Then - ErrorMovInv = True - TextoError.AppendFormat("Ocurrió un error al procesar los conceptos de traspaso de apartado. Por favor vuelva a intentar.") - Exit For - End If - TotalGarantia += (RowGarantia("Cantidad").ToString().ToDecimal() * PU) - Next - - ''se registra - 'If ContabilizaMovimientoAlmacen(ObjConta, TxtFecha.Text.ToDate, HLFolio.Text, "EntregaAlmacen", -1, CveMovimientoGarantia, TotalGarantia, UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa, True) <= 0 Then - ' ErrorMovInv = True - 'End If - - Dim CvePrePolizaTraspaso As Integer = ObjConta.AddPrePolizas("EA/Gar", 53, 0, 0, 1, TxtFecha.Text.ToDate, "Entrada Garantía", UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa) - If CvePrePolizaTraspaso > 0 Then - - Dim TotalGarantiaValor As Decimal = 0 ' el valor en almacen es cero, por tema contable - If Not ObjConta.AddPrePolizasDetalle(CvePrePolizaTraspaso, False, TotalGarantiaValor, TotalGarantia, 68, TxtObservaciones.Text, TxtObservaciones.Text, CveMovimientoAlmacen:=CveMovimientoGarantia, Contabilizable:=False) Then - ErrorMovInv = True - End If - - If Not ErrorMovInv AndAlso Not ObjConta.AddPrePolizasDetalle(CvePrePolizaTraspaso, True, TotalGarantiaValor, TotalGarantia, 331, TxtObservaciones.Text, TxtObservaciones.Text, CveMovimientoAlmacen:=CveMovimientoGarantia, Contabilizable:=False) Then - ErrorMovInv = True - End If - Else - ErrorMovInv = True - End If - End If - End If - ' TERMINA: GARANTIAS - - 'DEVOLUCION DE SIN COSTO - Dim CantidadEntradaSinCosto As Decimal = 0 - - If Not ErrorMovInv AndAlso TipoMovimiento = 2 AndAlso UsuarioActual.Empresa.Funcionalidad(587) = "1" Then - For Each Dr1 As DataRow In DtExistencias.FiltraParametros("CveTipoAlmacenDevolucion = 26").Rows - Dim CveMovimientoSalidaSinCosto As Integer = Dr1("CveMovimiento").ToString().ToEntero() - - 'Dim CveAlmacenSinCosto As Integer = Dr1("CveAlmacenDevolucion").ToString().ToEntero() - - 'Dim AlmacenSinCosto As String = GlobalDTAlmacen(UsuarioActual.CveEmpresa, CveTipoAlmacen:=26).FiltroPrimeroValor("Almacen", $"CveAlmacen={CveAlmacenSinCosto}").ToString() - - Dim CveMovimientoDevolucionSinCosto As Integer = ObjInventario.AddMovimiento(DdlAlmacen.SelectedValue.ToEntero(), 41, 1, TxtFecha.Text.ToDate, -1, UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa, -1, CveVentaSurtir, -1, -1, CveOS:=CveOSSurtir, - Observaciones:=TxtObservaciones.Text.Trim, CveAlmacenDestino:=DdlAlmacen.SelectedValue.ToEntero(), CveMovimientoRelacionado:=CveMovimientoSalida, - Guia:=Guia, CveContrato:=CveContrato, CveVendedor:=CveVendedor, CveCliente:=CveCliente, Modulo:="RE/G4") - Dim FolioDevSinCosto As Integer = ObjInventario.Folio - - If Not CveMovimientoDevolucionSinCosto > 0 Then - ErrorMovInv = True - TextoError.AppendFormat("Ocurrió un error al procesar los movimientos de traspaso de apartado. Por favor vuelva a intentar.") - Exit For - End If - - If ObjInventario.GetMovimientosDetalle(CveMovimientoSalidaSinCosto, UsuarioActual.CveEmpresa) Then - For Each Dr As DataRow In ObjInventario.DtResultados.Rows - - CantidadEntradaSinCosto += Dr("Cantidad").ToString().ToDecimal() - - If Not ObjInventario.AddMovimientoDetalle(CveMovimientoDevolucionSinCosto, Dr("Cantidad").ToString().ToDecimal, Dr("CveUM").ToString().ToEntero(), Dr("CvePS").ToString().ToEntero(), Dr("PU").ToString().ToDecimal, CveAF:=Dr("CveAF").ToString().ToEntero(), Serie:=Dr("Serie").ToString(), CveMovimientoDetalleEntrada:=Dr("CveMovimientoDetalle").ToString().ToEntero(), CveVentaDetalle:=Dr("CveVentaDetalle").ToString().ToEntero(), FechaCaducidad:=If(CBool(Dr("AplicaCaducidad")), Dr("FechaCaducidad").ToString().ToDate, MinFecha), Lote:=If(CBool(Dr("AplicaLote")), Dr("Lote").ToString(), "-1"), CveSeccionAlmacen:=If(CBool(Dr("AplicaSeccion")), Dr("CveSeccion").ToString().ToEntero(), -1)) Then - ErrorMovInv = True - TextoError.AppendFormat("Ocurrió un error al procesar los conceptos de traspaso de apartado. Por favor vuelva a intentar.") - Exit For - End If - Next - End If - - If ErrorMovInv Then Exit For - - Dim DrMovto As DataRow = DtDevSinCosto.NewRow - DrMovto("Almacen") = DdlAlmacen.SelectedItem.Text - DrMovto("CveAlmacen") = DdlAlmacen.SelectedValue.ToEntero() - DrMovto("CveMovimientoEntrada") = CveMovimientoDevolucionSinCosto - DrMovto("FolioEntrada") = FolioDevSinCosto - DrMovto("CveTipoAlmacen") = 10 - DrMovto("CveConceptoMovimientoSalida") = 41 - DtDevSinCosto.Rows.Add(DrMovto) - - If Not ErrorMovInv Then - ErrorMovInv = Not GenerarPrePoliza(ObjInventario, ObjVentas, ObjConta, CveMovimientoDevolucionSinCosto, TextoError) - End If - - Next - End If - - Dim CantidadPendientePorSalir As Decimal = DtDatos.SUM("CantidadGV") - - If TipoMovimiento = 1 Then - CantidadPendientePorSalir = CantidadPendientePorSalir - CantidadSalidaSinCosto - ElseIf TipoMovimiento = 2 Then - CantidadPendientePorSalir = CantidadPendientePorSalir - CantidadEntradaSinCosto - End If - 'si el alamcen del que salio, es el mismo que entra, no hay traspasos. - If CveAlmacenTraspasoDestino = DdlAlmacen.SelectedValue.ToEntero() And TipoDocto <> "Rem" And TipoDocto <> "Ped" Then CveAlmacenTraspasoDestino = 0 - - If Not ErrorMovInv AndAlso CantidadPendientePorSalir > 0 Then - Dim ConceptoMovimiento As Integer = 3 - ConceptoMovimiento = If(TipoMovimiento = 1, ConceptoMovimiento, 18) - ConceptoMovimiento = If(CveAlmacenTraspasoDestino > 0, 8, ConceptoMovimiento) - - Dim Almacen1 As Integer = DdlAlmacen.SelectedValue.ToEntero() - Dim tCveAlmacenTraspasoDestino As Integer = CveAlmacenTraspasoDestino - - If TipoDocto.Contiene("Rem", "Ped") AndAlso tCveAlmacenTraspasoDestino = 0 Then - ErrorMovInv = True - TextoError.AppendFormat("Ocurrió un error. no se tiene definido el almacen destino") - End If - - 'DEVOLUCION REMISION - If TipoMovimiento = 2 And TipoDocto.Contiene("Rem", "Ped") Then - ConceptoMovimiento = 8 - Almacen1 = CveAlmacenTraspasoDestino - tCveAlmacenTraspasoDestino = DdlAlmacen.SelectedValue.ToEntero() - End If - - 'CANCELACION DE DEVOLUCION - If TipoMovimiento = 2 And TipoDocto = "Dev" And EsDevolucionVenta = 1 Then - ConceptoMovimiento = 3 - Almacen1 = DdlAlmacen.SelectedValue.ToEntero() - tCveAlmacenTraspasoDestino = DdlAlmacen.SelectedValue.ToEntero() - End If - - 'DEVOLUCION DIRECTA A ENTREGA POR ADELANTADO - If TipoMovimiento = 2 And ConceptoMovimiento = 18 AndAlso EsDevolucionDirecta Then - ConceptoMovimiento = 41 - End If - 'sms + Next + End If + Else + TieneErrorExistencia = True + End If + + If TieneErrorExistencia Then + ObjInventario.RollBack() + ObjInventario.Dispose() + ObjConta.Dispose() + ObjVentas.Dispose() + ObjEventos.Dispose() + If TextoError.Length > 0 Then + Alert($" Lo(s) siguiente(s) Productos no tienen existencia suficiente:

    {TextoError}", TipoMensaje.MsgAdvertencia) + End If + RegistraScript("playsonidito('142608__autistic-lucario__error.wav')") + Exit Sub + End If + End If + + '' TERMINA: VALIDACIONES + + Dim CantidadPendienteSinCosto As Decimal = 0 + Dim CantidadSaldoSinCosto As Decimal = 0 + + Dim CantidadSalidaSinCosto As Decimal = 0 + + '' COMIENZA: SIN COSTO + If TipoDocto.Contiene("Ing", "Rem", "Ped") AndAlso UsuarioActual.Empresa.Funcionalidad(587) = "1" AndAlso TipoMovimiento = 1 Then + + Dim CveConceptoSalidaSinCosto As Integer = If(TipoDocto.Contiene("Rem", "Ped"), 8, 40) + + For Each Dr As DataRow In DtDatos.Rows + If Dr("CantidadGV").ToString().ToDecimal > 0 Then + If CBool(Dr("AplicaSerie")) Then + DtDetalle = DtDatosDetalle.FiltraParametros(String.Format("ConsecId = {0}", Dr("Consec"))) + For Each Dr1 As DataRow In DtDetalle.Rows + If ObjInventario.GetExistenciasProducto(Dr1("CvePS").ToString().ToEntero(), Dr1("CveUM").ToString().ToEntero(), UsuarioActual.CveEmpresa, -1, FechaMovto:=TxtFecha.Text.ToDateTime.ToString("yyyy/MM/dd HH:mm"), Serie:=Dr1("Serie").ToString(), CveTipoAlmacen:=26, CveSubProyecto:=CveSubProyecto, Caducidad:=If(CBool(Dr("AplicaCaducidad")), Dr("FechaCaducidad").ToString().ToDate, MinFecha), Lote:=If(CBool(Dr("AplicaLote")), Dr("Lote").ToString(), "-1"), CveSeccionAlmacen:=If(CBool(Dr("AplicaSeccion")), Dr("CveSeccion").ToString().ToEntero(), -1)) Then + For Each Dr2 As DataRow In ObjInventario.DtResultados.FiltraParametros("CveAlmacen > 0 AND ExistenciaFinal > 0").Rows + + 'BUSCA SI EXISTE YA UN TRASPASO DEL ALMACEN DE APARTADO + CveMovimientoSalida = DtTraspasos.FiltroPrimeroValor("CveMovimientoSalida", $"CveAlmacen = {Dr2("CveAlmacen")}").ToEntero() + + If Not CveMovimientoSalida > 0 Then + + CveMovimientoSalida = ObjInventario.AddMovimiento(Dr2("CveAlmacen").ToString().ToEntero(), CveConceptoSalidaSinCosto, 1, TxtFecha.Text.ToDate, -1, UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa, -1, CveVentaSurtir, -1, -1, CveOS:=CveOSSurtir, + Observaciones:=TxtObservaciones.Text.Trim, Guia:=Guia, CveContrato:=CveContrato, Modulo:="RE/GSC1") + FolioSalida = ObjInventario.Folio + + If Not CveMovimientoSalida > 0 Then + ErrorMovInv = True + TextoError.AppendFormat("Ocurrió un error al procesar los movimientos de traspaso de apartado. Por favor vuelva a intentar.") + Exit For + End If + + Dim DrMovto As DataRow = DtTraspasos.NewRow + DrMovto("Almacen") = Dr2("Almacen").ToString().ToEntero() + DrMovto("CveAlmacen") = Dr2("CveAlmacen").ToString().ToEntero() + DrMovto("CveMovimientoSalida") = CveMovimientoSalida + DrMovto("FolioSalida") = FolioSalida + DrMovto("CveTipoAlmacen") = 26 + DrMovto("CveConceptoMovimientoSalida") = CveConceptoSalidaSinCosto + DtTraspasos.Rows.Add(DrMovto) + End If + + + CantidadPendienteSinCosto = 1 + + If Not ObjInventario.AddMovimientoDetalle(CveMovimientoSalida, CantidadPendienteSinCosto, Dr("CveUM").ToString().ToEntero(), Dr("CvePS").ToString().ToEntero(), 0, Serie:=Dr1("Serie").ToString(), CveVentaDetalle:=Dr("CveVentaDetalle").ToString().ToEntero(), FechaCaducidad:=If(CBool(Dr("AplicaCaducidad")), Dr("FechaCaducidad").ToString().ToDate, MinFecha), Lote:=If(CBool(Dr("AplicaLote")), Dr("Lote").ToString(), "-1"), CveSeccionAlmacen:=If(CBool(Dr("AplicaSeccion")), Dr("CveSeccion").ToString().ToEntero(), -1)) Then + ErrorMovInv = True + TextoError.AppendFormat("Ocurrió un Error al procesar los conceptos de traspaso de apartado. Por favor vuelva a intentar.") + Exit For + End If + + DtDatosDetalle.Select($"Consec = {Dr1("Consec")}")(0)("FueTraspaso") = 1 + DtDatosDetalle.Select($"Consec = {Dr1("Consec")}")(0)("CveVentaDetalle") = Dr("CveVentaDetalle") + Dr("CantidadTraspaso") = Dr("CantidadTraspaso").ToString().ToDecimal + CantidadPendienteSinCosto + Exit For + Next + End If + If ErrorMovInv Then Exit For + Next + + Else + + If ObjInventario.GetExistenciasProducto(Dr("CvePS").ToString().ToEntero(), Dr("CveUM").ToString().ToEntero(), UsuarioActual.CveEmpresa, -1, FechaMovto:=TxtFecha.Text.ToDateTime.ToString("yyyy/MM/dd HH:mm"), CveTipoAlmacen:=26, CveSubProyecto:=CveSubProyecto, Caducidad:=If(CBool(Dr("AplicaCaducidad")), Dr("FechaCaducidad").ToString().ToDate, MinFecha), Lote:=If(CBool(Dr("AplicaLote")), Dr("Lote").ToString(), "-1"), CveSeccionAlmacen:=If(CBool(Dr("AplicaSeccion")), Dr("CveSeccion").ToString().ToEntero(), -1)) Then + + CantidadSaldoSinCosto = Dr("CantidadGV").ToString().ToDecimal + + For Each Dr1 As DataRow In ObjInventario.DtResultados.FiltraParametros("CveAlmacen > 0 AND ExistenciaFinal > 0").Rows + + 'BUSCA SI EXISTE YA UN TRASPASO DEL ALMACEN DE APARTADO + CveMovimientoSalida = DtTraspasos.FiltroPrimeroValor("CveMovimientoSalida", $"CveAlmacen = {Dr1("CveAlmacen")}").ToEntero() + + If Not CveMovimientoSalida > 0 Then + CveMovimientoSalida = ObjInventario.AddMovimiento(Dr1("CveAlmacen").ToString().ToEntero(), CveConceptoSalidaSinCosto, 1, TxtFecha.Text.ToDate, -1, UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa, -1, CveVentaSurtir, -1, -1, CveOS:=CveOSSurtir, + Observaciones:=TxtObservaciones.Text.Trim, Guia:=Guia, CveContrato:=CveContrato, Modulo:="RE/GSC3") + FolioSalida = ObjInventario.Folio + + If Not CveMovimientoSalida > 0 Then + ErrorMovInv = True + TextoError.AppendFormat("Ocurrió un error al procesar los movimientos de traspaso de apartado. Por favor vuelva a intentar.") + Exit For + End If + + Dim DrMovto As DataRow = DtTraspasos.NewRow + DrMovto("Almacen") = Dr1("Almacen").ToString().ToEntero() + DrMovto("CveAlmacen") = Dr1("CveAlmacen").ToString().ToEntero() + DrMovto("CveMovimientoSalida") = CveMovimientoSalida + DrMovto("FolioSalida") = FolioSalida + DrMovto("CveTipoAlmacen") = 26 + DrMovto("CveConceptoMovimientoSalida") = CveConceptoSalidaSinCosto + DtTraspasos.Rows.Add(DrMovto) + End If + + CantidadPendienteSinCosto = If(Dr1("ExistenciaFinal").ToString().ToDecimal > CantidadSaldoSinCosto, CantidadSaldoSinCosto, Dr1("ExistenciaFinal").ToString().ToDecimal) + + If Not ObjInventario.AddMovimientoDetalle(CveMovimientoSalida, CantidadPendienteSinCosto.ToString().ToDecimal, Dr("CveUM").ToString().ToEntero(), Dr("CvePS").ToString().ToEntero(), 0, + Serie:=Dr("Serie").ToString(), + CveVentaDetalle:=Dr("CveVentaDetalle").ToString().ToEntero(), + FechaCaducidad:=If(CBool(Dr("AplicaCaducidad")), Dr("FechaCaducidad").ToString().ToDate, MinFecha), + Lote:=If(CBool(Dr("AplicaLote")), Dr("Lote").ToString(), "-1"), + CveSeccionAlmacen:=If(CBool(Dr("AplicaSeccion")), Dr("CveSeccion").ToString().ToEntero(), -1)) Then + ErrorMovInv = True + TextoError.AppendFormat("Ocurrió un error al procesar los conceptos de traspaso de apartado. Por favor vuelva a intentar.") + Exit For + End If + CantidadSaldoSinCosto -= CantidadPendienteSinCosto + Dr("CantidadTraspaso") = Dr("CantidadTraspaso").ToString().ToDecimal + CantidadPendienteSinCosto + If CantidadSaldoSinCosto <= 0 Then Exit For + Next + + If ErrorMovInv Then Exit For + Else + ErrorMovInv = True + End If + End If + CantidadSalidaSinCosto += Dr("CantidadTraspaso").ToString().ToDecimal() + If ErrorMovInv Then Exit For + End If + Next + + 'ENTRADA POR TRASPASO A ENTREGA POR ADELANTADO + If TipoDocto.Contiene("Rem", "Ped") AndAlso Not ErrorMovInv Then + For Each Dr1 As DataRow In DtTraspasos.Select("CveTipoAlmacen = 26") + CveMovimientoSalida = Dr1("CveMovimientoSalida").ToString().ToEntero() + + Dim CveAlmacenExA As Integer = GlobalDTAlmacen(UsuarioActual.CveEmpresa, CveTipoAlmacen:=10).FiltroPrimeroValor("CveAlmacen", $"CveSubProyecto={CveSubProyecto}").ToEntero() + + CveMovimientoEntradaApartado = ObjInventario.AddMovimiento(CveAlmacenExA, 9, 1, TxtFecha.Text.ToDate, -1, UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa, -1, CveVentaSurtir, -1, -1, CveOS:=CveOSSurtir, + Observaciones:=TxtObservaciones.Text.Trim, CveAlmacenDestino:=DdlAlmacen.SelectedValue.ToEntero(), CveMovimientoRelacionado:=CveMovimientoSalida, + Guia:=Guia, CveContrato:=CveContrato, CveVendedor:=CveVendedor, CveCliente:=CveCliente, Modulo:="RE/G4") + FolioEntrada = ObjInventario.Folio + + If Not CveMovimientoEntradaApartado > 0 Then + ErrorMovInv = True + TextoError.AppendFormat("Ocurrió un error al procesar los movimientos de traspaso de apartado. Por favor vuelva a intentar.") + Exit For + End If + + Dr1("CveMovimientoEntrada") = CveMovimientoEntradaApartado + Dr1("FolioEntrada") = FolioEntrada + + If ObjInventario.GetMovimientosDetalle(CveMovimientoSalida, UsuarioActual.CveEmpresa) Then + Dim CveSeccionAlmacen As Integer = -1 + For Each Dr As DataRow In ObjInventario.DtResultados.Rows + + If Not ObjInventario.AddMovimientoDetalle(CveMovimientoEntradaApartado, Dr("Cantidad").ToString().ToDecimal, Dr("CveUM").ToString().ToEntero(), Dr("CvePS").ToString().ToEntero(), Dr("PU").ToString().ToDecimal, CveAF:=Dr("CveAF").ToString().ToEntero(), Serie:=Dr("Serie").ToString(), CveMovimientoDetalleEntrada:=Dr("CveMovimientoDetalle").ToString().ToEntero(), CveVentaDetalle:=Dr("CveVentaDetalle").ToString().ToEntero(), FechaCaducidad:=If(CBool(Dr("AplicaCaducidad")), Dr("FechaCaducidad").ToString().ToDate, MinFecha), Lote:=If(CBool(Dr("AplicaLote")), Dr("Lote").ToString(), "-1"), CveSeccionAlmacen:=-3) Then + ErrorMovInv = True + TextoError.AppendFormat("Ocurrió un error al procesar los conceptos de traspaso de apartado. Por favor vuelva a intentar.") + Exit For + End If + Next + End If + + If ErrorMovInv Then Exit For + Next + End If + + If Not ErrorMovInv AndAlso CveMovimientoSalida > 0 AndAlso TipoDocto.Contiene("Rem", "Ped") Then + Dim CvePrePolizaSinCosto As Integer = ObjConta.AddPrePolizas("EA/SinCost", 53, 0, 0, 1, TxtFecha.Text.ToDate, "Entrega", UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa) + If CvePrePolizaSinCosto > 0 Then + + If Not ErrorMovInv AndAlso Not ObjConta.AddPrePolizasDetalle(CvePrePolizaSinCosto, True, 0, 0, 68, TxtObservaciones.Text, TxtObservaciones.Text, -1, -1, CveMovimientoAlmacen:=CveMovimientoSalida, Contabilizable:=False) Then + ErrorMovInv = True + End If + If Not ErrorMovInv AndAlso Not ObjConta.AddPrePolizasDetalle(CvePrePolizaSinCosto, False, 0, 0, 68, TxtObservaciones.Text, TxtObservaciones.Text, -1, -1, CveMovimientoAlmacen:=CveMovimientoEntradaApartado, Contabilizable:=False) Then + ErrorMovInv = True + End If + + Else + ErrorMovInv = True + End If + End If + + End If + + If Not ErrorMovInv Then + For Each DrMovto As DataRow In DtTraspasos.FiltraParametros("CveConceptoMovimientoSalida = 40").Rows + ErrorMovInv = Not GenerarPrePoliza(ObjInventario, ObjVentas, ObjConta, DrMovto("CveMovimientoSalida").ToString().ToEntero(), TextoError) + If ErrorMovInv Then + Exit For + End If + Next + End If + + ''TERMINA: SIN COSTO + + '' COMIENZA: APARTADOS + Dim CantidadPendiente As Decimal = 0 + Dim CantidadSaldo As Decimal = 0 + + + If Not ErrorMovInv AndAlso CveVendedor > 0 AndAlso (UsuarioActual.Empresa.Funcionalidad(146) = "1" Or CveCliente > 0) Then 'no debe considerar cuando es pedido de contrato + If TipoMovimiento = 1 Then ' SI ES DEVOLUCION NO APLICA APARTADO + ' SALIDA POR TRASPASO DE LOS ALMACENES DE APARTADO + For Each Dr As DataRow In DtDatos.Rows + If Dr("CantidadGV").ToString().ToDecimal > 0 Then + + If CBool(Dr("AplicaSerie")) Then + + DtDetalle = DtDatosDetalle.FiltraParametros(String.Format("ConsecId = {0}", Dr("Consec"))) + For Each Dr1 As DataRow In DtDetalle.Rows + If ObjInventario.GetExistenciasProducto(Dr1("CvePS").ToString().ToEntero(), Dr1("CveUM").ToString().ToEntero(), UsuarioActual.CveEmpresa, -1, FechaMovto:=TxtFecha.Text.ToDateTime.ToString("yyyy/MM/dd HH:mm"), Serie:=Dr1("Serie").ToString(), CveTipoAlmacen:=9, CveVendedor:=CveVendedor, CveSubProyecto:=CveSubProyecto, CveCliente:=If(UsuarioActual.Empresa.Funcionalidad(146) = "1", -1, CveCliente), ExcluyeApartados:=-1, Caducidad:=If(CBool(Dr("AplicaCaducidad")), Dr("FechaCaducidad").ToString().ToDate, MinFecha), Lote:=If(CBool(Dr("AplicaLote")), Dr("Lote").ToString(), "-1"), CveSeccionAlmacen:=-1) Then + Dim CveSeccionAlmacen As Integer = 0 + For Each Dr2 As DataRow In ObjInventario.DtResultados.FiltraParametros("CveAlmacen > 0 AND ExistenciaFinal > 0").Rows + + 'BUSCA SI EXISTE YA UN TRASPASO DEL ALMACEN DE APARTADO + CveMovimientoSalida = DtTraspasos.FiltroPrimeroValor("CveMovimientoSalida", $"CveAlmacen = {Dr2("CveAlmacen")}").ToEntero() + + If Not CveMovimientoSalida > 0 Then + CveMovimientoSalida = ObjInventario.AddMovimiento(Dr2("CveAlmacen").ToString().ToEntero(), 8, 1, TxtFecha.Text.ToDate, -1, UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa, -1, CveVentaSurtir, -1, -1, CveOS:=CveOSSurtir, + Observaciones:=TxtObservaciones.Text.Trim, Guia:=Guia, CveContrato:=CveContrato, CveVendedor:=CveVendedor, CveCliente:=If(UsuarioActual.Empresa.Funcionalidad(146) = "1", -1, CveCliente), + CveAlmacenDestino:=DdlAlmacen.SelectedValue.ToEntero(), Modulo:="RE/G1") + FolioSalida = ObjInventario.Folio + + If Not CveMovimientoSalida > 0 Then + ErrorMovInv = True + TextoError.AppendFormat("Ocurrió un error al procesar los movimientos de traspaso de apartado. Por favor vuelva a intentar.") + Exit For + End If + + Dim DrMovto As DataRow = DtTraspasos.NewRow + DrMovto("Almacen") = Dr2("Almacen").ToString().ToEntero() + DrMovto("CveAlmacen") = Dr2("CveAlmacen").ToString().ToEntero() + DrMovto("CveMovimientoSalida") = CveMovimientoSalida + DrMovto("FolioSalida") = FolioSalida + DrMovto("CveTipoAlmacen") = 9 + DrMovto("CveConceptoMovimientoSalida") = 8 + DtTraspasos.Rows.Add(DrMovto) + End If + + + CantidadPendiente = 1 + CveSeccionAlmacen = -3 + + If Not ObjInventario.AddMovimientoDetalle(CveMovimientoSalida, CantidadPendiente.ToString().ToDecimal, Dr("CveUM").ToString().ToEntero(), Dr("CvePS").ToString().ToEntero(), 0, Serie:=Dr1("Serie").ToString(), CveVentaDetalle:=Dr("CveVentaDetalle").ToString().ToEntero(), FechaCaducidad:=If(CBool(Dr("AplicaCaducidad")), Dr("FechaCaducidad").ToString().ToDate, MinFecha), Lote:=If(CBool(Dr("AplicaLote")), Dr("Lote").ToString(), "-1"), CveSeccionAlmacen:=CveSeccionAlmacen) Then + ErrorMovInv = True + TextoError.AppendFormat("Ocurrió un Error al procesar los conceptos de traspaso de apartado. Por favor vuelva a intentar.") + Exit For + End If + + DtDatosDetalle.Select($"Consec = {Dr1("Consec")}")(0)("FueTraspaso") = 1 + DtDatosDetalle.Select($"Consec = {Dr1("Consec")}")(0)("CveVentaDetalle") = Dr("CveVentaDetalle") + Dr("CantidadTraspaso") = Dr("CantidadTraspaso").ToString().ToDecimal + CantidadPendiente + Exit For + Next + End If + If ErrorMovInv Then Exit For + Next + + ElseIf CBool(Dr("AplicaLote")) Then + + DtDetalle = DtDatosDetalleLote.FiltraParametros(String.Format("ConsecId = {0}", Dr("Consec"))) + For Each Dr1 As DataRow In DtDetalle.Rows + If ObjInventario.GetExistenciasProducto(Dr1("CvePS").ToString().ToEntero(), Dr1("CveUM").ToString().ToEntero(), UsuarioActual.CveEmpresa, -1, FechaMovto:=TxtFecha.Text.ToDateTime.ToString("yyyy/MM/dd HH:mm"), Lote:=Dr1("Lote").ToString(), CveTipoAlmacen:=9, CveVendedor:=CveVendedor, CveSubProyecto:=CveSubProyecto, CveCliente:=If(UsuarioActual.Empresa.Funcionalidad(146) = "1", -1, CveCliente), ExcluyeApartados:=-1, Caducidad:=If(CBool(Dr("AplicaCaducidad")), Dr("FechaCaducidad").ToString().ToDate, MinFecha), CveSeccionAlmacen:=-1) Then + + CantidadSaldo = Dr("CantidadGV").ToString().ToDecimal + + For Each Dr2 As DataRow In ObjInventario.DtResultados.FiltraParametros("CveAlmacen > 0 AND ExistenciaFinal > 0").Rows + + 'BUSCA SI EXISTE YA UN TRASPASO DEL ALMACEN DE APARTADO + CveMovimientoSalida = DtTraspasos.FiltroPrimeroValor("CveMovimientoSalida", $"CveAlmacen = {Dr2("CveAlmacen")}").ToEntero() + + If Not CveMovimientoSalida > 0 Then + CveMovimientoSalida = ObjInventario.AddMovimiento(Dr2("CveAlmacen").ToString().ToEntero(), 8, 1, TxtFecha.Text.ToDate, -1, UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa, -1, CveVentaSurtir, -1, -1, CveOS:=CveOSSurtir, Observaciones:=TxtObservaciones.Text.Trim, + Guia:=Guia, CveContrato:=CveContrato, CveVendedor:=CveVendedor, CveCliente:=If(UsuarioActual.Empresa.Funcionalidad(146) = "1", -1, CveCliente), + CveAlmacenDestino:=DdlAlmacen.SelectedValue.ToEntero(), Modulo:="RE/G2") + FolioSalida = ObjInventario.Folio + + If Not CveMovimientoSalida > 0 Then + ErrorMovInv = True + TextoError.AppendFormat("Ocurrió un error al procesar los movimientos de traspaso de apartado. Por favor vuelva a intentar.") + Exit For + End If + + Dim DrMovto As DataRow = DtTraspasos.NewRow + DrMovto("Almacen") = Dr2("Almacen").ToString().ToEntero() + DrMovto("CveAlmacen") = Dr2("CveAlmacen").ToString().ToEntero() + DrMovto("CveMovimientoSalida") = CveMovimientoSalida + DrMovto("FolioSalida") = FolioSalida + DrMovto("CveTipoAlmacen") = 9 + DrMovto("CveConceptoMovimientoSalida") = 8 + DtTraspasos.Rows.Add(DrMovto) + End If + + CantidadPendiente = If(Dr1("Cantidad").ToString().ToDecimal > CantidadSaldo, CantidadSaldo, Dr1("Cantidad").ToString().ToDecimal) + + If Not ObjInventario.AddMovimientoDetalle(CveMovimientoSalida, CantidadPendiente.ToString().ToDecimal, Dr("CveUM").ToString().ToEntero(), Dr("CvePS").ToString().ToEntero(), 0, Lote:=Dr1("Lote").ToString(), CveVentaDetalle:=Dr("CveVentaDetalle").ToString().ToEntero(), FechaCaducidad:=If(CBool(Dr("AplicaCaducidad")), Dr("FechaCaducidad").ToString().ToDate, MinFecha), CveSeccionAlmacen:=If(CBool(Dr("AplicaSeccion")), Dr("CveSeccion").ToString().ToEntero(), -1)) Then + ErrorMovInv = True + TextoError.AppendFormat("Ocurrió un error al procesar los conceptos de traspaso de apartado. Por favor vuelva a intentar.") + Exit For + End If + + DtDatosDetalle.Select($"Consec = {Dr1("Consec")}")(0)("FueTraspaso") = 1 + DtDatosDetalle.Select($"Consec = {Dr1("Consec")}")(0)("CveVentaDetalle") = Dr("CveVentaDetalle") + + CantidadSaldo -= CantidadPendiente + Dr("CantidadTraspaso") = Dr("CantidadTraspaso").ToString().ToDecimal + CantidadPendiente + If CantidadSaldo <= 0 Then Exit For + Next + End If + Next + + Else + + If ObjInventario.GetExistenciasProducto(Dr("CvePS").ToString().ToEntero(), Dr("CveUM").ToString().ToEntero(), UsuarioActual.CveEmpresa, -1, FechaMovto:=TxtFecha.Text.ToDateTime.ToString("yyyy/MM/dd HH:mm"), CveTipoAlmacen:=9, CveVendedor:=CveVendedor, CveSubProyecto:=CveSubProyecto, CveCliente:=If(UsuarioActual.Empresa.Funcionalidad(146) = "1", -1, CveCliente), ExcluyeApartados:=-1, Caducidad:=If(CBool(Dr("AplicaCaducidad")), Dr("FechaCaducidad").ToString().ToDate, MinFecha), Lote:=If(CBool(Dr("AplicaLote")), Dr("Lote").ToString(), "-1"), CveSeccionAlmacen:=-1) Then + + CantidadSaldo = Dr("CantidadGV").ToString().ToDecimal + + For Each Dr1 As DataRow In ObjInventario.DtResultados.FiltraParametros("CveAlmacen > 0 AND ExistenciaFinal > 0").Rows + + 'BUSCA SI EXISTE YA UN TRASPASO DEL ALMACEN DE APARTADO + CveMovimientoSalida = DtTraspasos.FiltroPrimeroValor("CveMovimientoSalida", $"CveAlmacen = {Dr1("CveAlmacen")}").ToEntero() + + If Not CveMovimientoSalida > 0 Then + + + CveMovimientoSalida = ObjInventario.AddMovimiento(Dr1("CveAlmacen").ToString().ToEntero(), 8, 1, TxtFecha.Text.ToDate, -1, UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa, -1, CveVentaSurtir, -1, -1, CveOS:=CveOSSurtir, + Observaciones:=TxtObservaciones.Text.Trim, Guia:=Guia, CveContrato:=CveContrato, CveVendedor:=CveVendedor, + CveCliente:=If(UsuarioActual.Empresa.Funcionalidad(146) = "1", -1, CveCliente), CveAlmacenDestino:=DdlAlmacen.SelectedValue.ToEntero(), Modulo:="RE/G3") + FolioSalida = ObjInventario.Folio + + If Not CveMovimientoSalida > 0 Then + ErrorMovInv = True + TextoError.AppendFormat("Ocurrió un error al procesar los movimientos de traspaso de apartado. Por favor vuelva a intentar.") + Exit For + End If + + Dim DrMovto As DataRow = DtTraspasos.NewRow + DrMovto("Almacen") = Dr1("Almacen").ToString().ToEntero() + DrMovto("CveAlmacen") = Dr1("CveAlmacen").ToString().ToEntero() + DrMovto("CveMovimientoSalida") = CveMovimientoSalida + DrMovto("FolioSalida") = FolioSalida + DrMovto("CveTipoAlmacen") = 9 + DrMovto("CveConceptoMovimientoSalida") = 8 + DtTraspasos.Rows.Add(DrMovto) + End If + + CantidadPendiente = If(Dr1("ExistenciaFinal").ToString().ToDecimal > CantidadSaldo, CantidadSaldo, Dr1("ExistenciaFinal").ToString().ToDecimal) + + If Not ObjInventario.AddMovimientoDetalle(CveMovimientoSalida, CantidadPendiente.ToString().ToDecimal, Dr("CveUM").ToString().ToEntero(), Dr("CvePS").ToString().ToEntero(), 0, + Serie:=Dr("Serie").ToString(), + CveVentaDetalle:=Dr("CveVentaDetalle").ToString().ToEntero(), + FechaCaducidad:=If(CBool(Dr("AplicaCaducidad")), Dr("FechaCaducidad").ToString().ToDate, MinFecha), + Lote:=If(CBool(Dr("AplicaLote")), Dr("Lote").ToString(), "-1"), + CveSeccionAlmacen:=-3) Then + ErrorMovInv = True + TextoError.AppendFormat("Ocurrió un error al procesar los conceptos de traspaso de apartado. Por favor vuelva a intentar.") + Exit For + End If + + CantidadSaldo -= CantidadPendiente + Dr("CantidadTraspaso") = Dr("CantidadTraspaso").ToString().ToDecimal + CantidadPendiente + If CantidadSaldo <= 0 Then Exit For + Next + + If ErrorMovInv Then Exit For + + + Else + ErrorMovInv = True + End If + + End If + If ErrorMovInv Then Exit For + + End If + + Next + + 'ENTRADA POR TRASPASO AL ALMACEN GENERAL + If Not ErrorMovInv Then + For Each Dr1 As DataRow In DtTraspasos.Select("CveTipoAlmacen = 9") + CveMovimientoSalida = Dr1("CveMovimientoSalida").ToString().ToEntero() + + CveMovimientoEntradaApartado = ObjInventario.AddMovimiento(DdlAlmacen.SelectedValue.ToEntero(), 9, 1, TxtFecha.Text.ToDate, -1, UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa, -1, CveVentaSurtir, -1, -1, CveOS:=CveOSSurtir, + Observaciones:=TxtObservaciones.Text.Trim, CveAlmacenDestino:=DdlAlmacen.SelectedValue.ToEntero(), CveMovimientoRelacionado:=CveMovimientoSalida, + Guia:=Guia, CveContrato:=CveContrato, CveVendedor:=CveVendedor, CveCliente:=CveCliente, Modulo:="RE/G4") + FolioEntrada = ObjInventario.Folio + + If Not CveMovimientoEntradaApartado > 0 Then + ErrorMovInv = True + TextoError.AppendFormat("Ocurrió un error al procesar los movimientos de traspaso de apartado. Por favor vuelva a intentar.") + Exit For + End If + + Dr1("CveMovimientoEntrada") = CveMovimientoEntradaApartado + Dr1("FolioEntrada") = FolioEntrada + + If ObjInventario.GetMovimientosDetalle(CveMovimientoSalida, UsuarioActual.CveEmpresa) Then + For Each Dr As DataRow In ObjInventario.DtResultados.Rows + If Not ObjInventario.AddMovimientoDetalle(CveMovimientoEntradaApartado, Dr("Cantidad").ToString().ToDecimal, Dr("CveUM").ToString().ToEntero(), Dr("CvePS").ToString().ToEntero(), Dr("PU").ToString().ToDecimal, CveAF:=Dr("CveAF").ToString().ToEntero(), Serie:=Dr("Serie").ToString(), CveMovimientoDetalleEntrada:=Dr("CveMovimientoDetalle").ToString().ToEntero(), CveVentaDetalle:=Dr("CveVentaDetalle").ToString().ToEntero(), FechaCaducidad:=If(CBool(Dr("AplicaCaducidad")), Dr("FechaCaducidad").ToString().ToDate, MinFecha), Lote:=If(CBool(Dr("AplicaLote")), Dr("Lote").ToString(), "-1"), CveSeccionAlmacen:=-3) Then + ErrorMovInv = True + TextoError.AppendFormat("Ocurrió un error al procesar los conceptos de traspaso de apartado. Por favor vuelva a intentar.") + Exit For + End If + Next + End If + + If ErrorMovInv Then Exit For + + Next + End If + End If + End If + '' TERMINA: APARTADOS + Dim TotalGarantia As Decimal = 0 + + ' COMIENZA: GARANTIAS + If Not ErrorMovInv AndAlso TipoDocto.Contiene("Ing", "Rem", "Ped") AndAlso UsuarioActual.Empresa.Funcionalidad(531) = "1" AndAlso TipoMovimiento = 1 Then + + Dim CveAlmacenGarantia As Integer = GlobalDTAlmacen(UsuarioActual.CveEmpresa, CveTipoAlmacen:=6).FiltroPrimeroValor("CveAlmacen", $"CveSubProyecto={CveSubProyecto}").ToEntero() + Dim DtGarantias As DataTable = Nothing + + If ObjAcumuladores.GetGarantiasDetalle(CveVentaSurtir) Then + DtGarantias = ObjAcumuladores.DtResultados.Copy() + End If + + If DtGarantias IsNot Nothing AndAlso DtGarantias.Rows.Count > 0 AndAlso CveAlmacenGarantia > 0 Then + CveMovimientoGarantia = ObjInventario.AddMovimiento(CveAlmacenGarantia, 14, 1, TxtFecha.Text.ToDate, -1, UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa, -1, CveVentaSurtir, -1, -1, CveOS:=CveOSSurtir, Observaciones:=TxtObservaciones.Text.Trim, Guia:=Guia, Modulo:="EA/G5") + FolioGarantia = ObjInventario.Folio + + For Each RowGarantia As DataRow In DtGarantias.Rows + Dim CvePS As Integer = RowGarantia("CvePS").ToString().ToEntero() + Dim CveTamaño As Integer = RowGarantia("CveTamaño").ToString().ToEntero() + Dim CveUM As Integer = RowGarantia("CveUnidadMedida").ToString().ToEntero() + Dim PU As Decimal = 0 'valor cero, por tema contable 'RowGarantia("Importe").ToString().ToDecimal() ' / RowGarantia("Cantidad").ToString().ToDouble() + Dim Serie As String = RowGarantia("Comprobante").ToString + + If Not ObjInventario.AddMovimientoDetalle(CveMovimientoGarantia, RowGarantia("Cantidad").ToString().ToDecimal, CveUM, CvePS, PU, Serie:=Serie, CveVentaDetalle:=IIf(RowGarantia("MismoCvePS").ToString = "1", RowGarantia("CveVentaDetalle"), -1).ToString.ToEntero) Then + ErrorMovInv = True + TextoError.AppendFormat("Ocurrió un error al procesar los conceptos de traspaso de apartado. Por favor vuelva a intentar.") + Exit For + End If + TotalGarantia += (RowGarantia("Cantidad").ToString().ToDecimal() * PU) + Next + + ''se registra + 'If ContabilizaMovimientoAlmacen(ObjConta, TxtFecha.Text.ToDate, HLFolio.Text, "EntregaAlmacen", -1, CveMovimientoGarantia, TotalGarantia, UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa, True) <= 0 Then + ' ErrorMovInv = True + 'End If + + Dim CvePrePolizaTraspaso As Integer = ObjConta.AddPrePolizas("EA/Gar", 53, 0, 0, 1, TxtFecha.Text.ToDate, "Entrada Garantía", UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa) + If CvePrePolizaTraspaso > 0 Then + + Dim TotalGarantiaValor As Decimal = 0 ' el valor en almacen es cero, por tema contable + If Not ObjConta.AddPrePolizasDetalle(CvePrePolizaTraspaso, False, TotalGarantiaValor, TotalGarantia, 68, TxtObservaciones.Text, TxtObservaciones.Text, CveMovimientoAlmacen:=CveMovimientoGarantia, Contabilizable:=False) Then + ErrorMovInv = True + End If + + If Not ErrorMovInv AndAlso Not ObjConta.AddPrePolizasDetalle(CvePrePolizaTraspaso, True, TotalGarantiaValor, TotalGarantia, 331, TxtObservaciones.Text, TxtObservaciones.Text, CveMovimientoAlmacen:=CveMovimientoGarantia, Contabilizable:=False) Then + ErrorMovInv = True + End If + Else + ErrorMovInv = True + End If + End If + End If + ' TERMINA: GARANTIAS + + 'DEVOLUCION DE SIN COSTO + Dim CantidadEntradaSinCosto As Decimal = 0 + + If Not ErrorMovInv AndAlso TipoMovimiento = 2 AndAlso UsuarioActual.Empresa.Funcionalidad(587) = "1" Then + For Each Dr1 As DataRow In DtExistencias.FiltraParametros("CveTipoAlmacenDevolucion = 26").Rows + Dim CveMovimientoSalidaSinCosto As Integer = Dr1("CveMovimiento").ToString().ToEntero() + + 'Dim CveAlmacenSinCosto As Integer = Dr1("CveAlmacenDevolucion").ToString().ToEntero() + + 'Dim AlmacenSinCosto As String = GlobalDTAlmacen(UsuarioActual.CveEmpresa, CveTipoAlmacen:=26).FiltroPrimeroValor("Almacen", $"CveAlmacen={CveAlmacenSinCosto}").ToString() + + Dim CveMovimientoDevolucionSinCosto As Integer = ObjInventario.AddMovimiento(DdlAlmacen.SelectedValue.ToEntero(), 41, 1, TxtFecha.Text.ToDate, -1, UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa, -1, CveVentaSurtir, -1, -1, CveOS:=CveOSSurtir, + Observaciones:=TxtObservaciones.Text.Trim, CveAlmacenDestino:=DdlAlmacen.SelectedValue.ToEntero(), CveMovimientoRelacionado:=CveMovimientoSalida, + Guia:=Guia, CveContrato:=CveContrato, CveVendedor:=CveVendedor, CveCliente:=CveCliente, Modulo:="RE/G4") + Dim FolioDevSinCosto As Integer = ObjInventario.Folio + + If Not CveMovimientoDevolucionSinCosto > 0 Then + ErrorMovInv = True + TextoError.AppendFormat("Ocurrió un error al procesar los movimientos de traspaso de apartado. Por favor vuelva a intentar.") + Exit For + End If + + If ObjInventario.GetMovimientosDetalle(CveMovimientoSalidaSinCosto, UsuarioActual.CveEmpresa) Then + For Each Dr As DataRow In ObjInventario.DtResultados.Rows + + CantidadEntradaSinCosto += Dr("Cantidad").ToString().ToDecimal() + + If Not ObjInventario.AddMovimientoDetalle(CveMovimientoDevolucionSinCosto, Dr("Cantidad").ToString().ToDecimal, Dr("CveUM").ToString().ToEntero(), Dr("CvePS").ToString().ToEntero(), Dr("PU").ToString().ToDecimal, CveAF:=Dr("CveAF").ToString().ToEntero(), Serie:=Dr("Serie").ToString(), CveMovimientoDetalleEntrada:=Dr("CveMovimientoDetalle").ToString().ToEntero(), CveVentaDetalle:=Dr("CveVentaDetalle").ToString().ToEntero(), FechaCaducidad:=If(CBool(Dr("AplicaCaducidad")), Dr("FechaCaducidad").ToString().ToDate, MinFecha), Lote:=If(CBool(Dr("AplicaLote")), Dr("Lote").ToString(), "-1"), CveSeccionAlmacen:=If(CBool(Dr("AplicaSeccion")), Dr("CveSeccion").ToString().ToEntero(), -1)) Then + ErrorMovInv = True + TextoError.AppendFormat("Ocurrió un error al procesar los conceptos de traspaso de apartado. Por favor vuelva a intentar.") + Exit For + End If + Next + End If + + If ErrorMovInv Then Exit For + + Dim DrMovto As DataRow = DtDevSinCosto.NewRow + DrMovto("Almacen") = DdlAlmacen.SelectedItem.Text + DrMovto("CveAlmacen") = DdlAlmacen.SelectedValue.ToEntero() + DrMovto("CveMovimientoEntrada") = CveMovimientoDevolucionSinCosto + DrMovto("FolioEntrada") = FolioDevSinCosto + DrMovto("CveTipoAlmacen") = 10 + DrMovto("CveConceptoMovimientoSalida") = 41 + DtDevSinCosto.Rows.Add(DrMovto) + + If Not ErrorMovInv Then + ErrorMovInv = Not GenerarPrePoliza(ObjInventario, ObjVentas, ObjConta, CveMovimientoDevolucionSinCosto, TextoError) + End If + + Next + End If + + Dim CantidadPendientePorSalir As Decimal = DtDatos.SUM("CantidadGV") + + If TipoMovimiento = 1 Then + CantidadPendientePorSalir = CantidadPendientePorSalir - CantidadSalidaSinCosto + ElseIf TipoMovimiento = 2 Then + CantidadPendientePorSalir = CantidadPendientePorSalir - CantidadEntradaSinCosto + End If + 'si el alamcen del que salio, es el mismo que entra, no hay traspasos. + If CveAlmacenTraspasoDestino = DdlAlmacen.SelectedValue.ToEntero() And TipoDocto <> "Rem" And TipoDocto <> "Ped" Then CveAlmacenTraspasoDestino = 0 + + If Not ErrorMovInv AndAlso CantidadPendientePorSalir > 0 Then + Dim ConceptoMovimiento As Integer = 3 + ConceptoMovimiento = If(TipoMovimiento = 1, ConceptoMovimiento, 18) + ConceptoMovimiento = If(CveAlmacenTraspasoDestino > 0, 8, ConceptoMovimiento) + + Dim Almacen1 As Integer = DdlAlmacen.SelectedValue.ToEntero() + Dim tCveAlmacenTraspasoDestino As Integer = CveAlmacenTraspasoDestino + + If TipoDocto.Contiene("Rem", "Ped") AndAlso tCveAlmacenTraspasoDestino = 0 Then + ErrorMovInv = True + TextoError.AppendFormat("Ocurrió un error. no se tiene definido el almacen destino") + End If + + 'DEVOLUCION REMISION + If TipoMovimiento = 2 And TipoDocto.Contiene("Rem", "Ped") Then + ConceptoMovimiento = 8 + Almacen1 = CveAlmacenTraspasoDestino + tCveAlmacenTraspasoDestino = DdlAlmacen.SelectedValue.ToEntero() + End If + + 'CANCELACION DE DEVOLUCION + If TipoMovimiento = 2 And TipoDocto = "Dev" And EsDevolucionVenta = 1 Then + ConceptoMovimiento = 3 + Almacen1 = DdlAlmacen.SelectedValue.ToEntero() + tCveAlmacenTraspasoDestino = DdlAlmacen.SelectedValue.ToEntero() + End If + + 'DEVOLUCION DIRECTA A ENTREGA POR ADELANTADO + If TipoMovimiento = 2 And ConceptoMovimiento = 18 AndAlso EsDevolucionDirecta Then + ConceptoMovimiento = 41 + End If + 'sms If UsuarioActual.Empresa.Funcionalidad(578) = "1" AndAlso ConceptoMovimiento = 8 AndAlso TipoMovimiento = 1 Then ConceptoMovimiento = 35 - End If - - CveMovimiento = ObjInventario.AddMovimiento(Almacen1, ConceptoMovimiento, 1, TxtFecha.Text.ToDate, -1, UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa, -1, CveVentaSurtir, -1, -1, CveOS:=CveOSSurtir, Observaciones:=TxtObservaciones.Text.Trim, Guia:=Guia, Recibio:=Recibio, - CveContrato:=CveContrato, CveAlmacenDestino:=tCveAlmacenTraspasoDestino, Modulo:="RE/G7") - Folio = ObjInventario.Folio - - 'SALIDA DE ALMACEN - SALIDA POR TRASPASO CUANDO ES REMISION - DEVOLUCION (SI ES TRASPASO Y TIENE CONTRATO NO HACE DEVOLUCIóN) - 'If Not (CveContrato > 0 And CveAlmacenTraspasoDestino > 0) Then - If CveMovimiento > 0 Then - - 'SACA LO DE TRASPASOS - APARTADO - For Each Dr1 As DataRow In DtTraspasos.Select("CveTipoAlmacen = 9") - CveMovimientoSalida = Dr1("CveMovimientoEntrada").ToString().ToEntero() - If ObjInventario.GetMovimientosDetalle(CveMovimientoSalida, UsuarioActual.CveEmpresa) Then - If ObjInventario.DtResultados.Rows.Count = 0 Then - ErrorMovInv = True - TextoError.AppendFormat("Ocurrió un error, no se tienen registros que ingresar") - Exit Sub - End If - For Each Dr As DataRow In ObjInventario.DtResultados.Rows - - If Not ObjInventario.AddMovimientoDetalle(CveMovimiento, Dr("Cantidad").ToString().ToDecimal, Dr("CveUM").ToString().ToEntero(), Dr("CvePS").ToString().ToEntero(), Dr("PU").ToString().ToDecimal, CveAF:=Dr("CveAF").ToString().ToEntero(), Serie:=Dr("Serie").ToString(), CveMovimientoDetalleEntrada:=Dr("CveMovimientoDetalle").ToString().ToEntero(), CveVentaDetalle:=Dr("CveVentaDetalle").ToString().ToEntero(), FechaCaducidad:=If(CBool(Dr("AplicaCaducidad")), Dr("FechaCaducidad").ToString().ToDate, MinFecha), Lote:=If(CBool(Dr("AplicaLote")), Dr("Lote").ToString(), "-1"), CveSeccionAlmacen:=-3, EsInterno:=EsInterno) Then - ErrorMovInv = True - TextoError.AppendFormat("Ocurrió un error al procesar los conceptos de traspaso de apartado. Por favor vuelva a intentar.") - Exit For - End If - Next - Else - ErrorMovInv = True - TextoError.AppendFormat("Ocurrió un error al obtener los registros") - End If - If ErrorMovInv Then Exit For - Next - - 'ES EL MOVIMIENTO PRINCIPAL - CantidadPendiente = 0 - Dim Cont As Integer = 0 - For Each Dr As DataRow In DtDatos.Rows - CantidadPendiente = Dr("CantidadGV").ToString().ToDecimal - Dr("CantidadTraspaso").ToString().ToDecimal - CantidadEntradaSinCosto - If CantidadPendiente > 0 Then - Dim PU As Decimal = 0 - Dim CveSeccionAlmacen As Integer = If(CBool(Dr("AplicaSeccion")), Dr("CveSeccion").ToString().ToEntero(), -1) - - 'SI FUE POR SERIE - DtDetalle = DtDatosDetalle.FiltraParametros(String.Format("ConsecId = {0} AND FueTraspaso IS NULL", Dr("Consec"))) - DtDetalleLote = DtDatosDetalleLote.FiltraParametros(String.Format("ConsecId = {0} AND FueTraspaso IS NULL", Dr("Consec"))) - If DtDetalle.Rows.Count > 0 Then - For Each Dr1 As DataRow In DtDetalle.Rows - If TipoMovimiento = 2 AndAlso DtExistencias IsNot Nothing Then - 'CveSeccionAlmacen = DtExistencias.FiltroPrimeroValor("CveSeccionAlmacen", $"ISNULL(CveTipoAlmacenDevolucion,0) <> 26 AND CvePS = {Dr("CvePS")} AND CveUM = {Dr("CveUM").ToString().ToEntero()} AND Serie = '{Dr1("Serie").ToString()}'").ToString().ToEntero - - PU = DtExistencias.FiltroPrimeroValor("PU", $"ISNULL(CveTipoAlmacenDevolucion,-1) <> 26 AND CvePS = {Dr("CvePS")} AND CveUM = {Dr("CveUM").ToString().ToEntero()} AND Serie = '{Dr1("Serie").ToString()}'").ToString().ToDecimal - End If - - If Not ObjInventario.AddMovimientoDetalle(CveMovimiento, 1, Dr("CveUM").ToString().ToEntero(), Dr("CvePS").ToString().ToEntero(), PU, Serie:=Dr1("Serie").ToString(), CveVentaDetalle:=Dr("CveVentaDetalle").ToString().ToEntero(), CveVentaDetalleRemision:=Dr("CveVentaDetalleRemision").ToString().ToEntero(), FechaCaducidad:=If(CBool(Dr("AplicaCaducidad")), Dr("FechaCaducidad").ToString().ToDate, MinFecha), Lote:=If(CBool(Dr("AplicaLote")), Dr("Lote").ToString(), "-1"), CveSeccionAlmacen:=-3) Then - ErrorMovInv = True - TextoError.AppendFormat("Ocurrió un error al procesar los conceptos con serie. Por favor vuelva a intentar.") - Exit For - End If - Next - ElseIf DtDetalleLote.Rows.Count > 0 Then - For Each Dr1 As DataRow In DtDetalleLote.Rows - If TipoMovimiento = 2 AndAlso DtExistencias IsNot Nothing Then - 'CveSeccionAlmacen = DtExistencias.FiltroPrimeroValor("CveSeccionAlmacen", $"CvePS = {Dr("CvePS")} AND CveUM = {Dr("CveUM").ToString().ToEntero()} AND Serie = '{Dr1("Serie").ToString()}'").ToString().ToEntero - PU = DtExistencias.FiltroPrimeroValor("PU", $"CvePS = {Dr("CvePS")} AND CveUM = {Dr("CveUM").ToString().ToEntero()} AND Serie = '{Dr1("Serie").ToString()}'").ToString().ToDecimal - End If - - If Not ObjInventario.AddMovimientoDetalle(CveMovimiento, Dr1("Cantidad").ToString().ToDecimal, Dr("CveUM").ToString().ToEntero(), Dr("CvePS").ToString().ToEntero(), PU, CveVentaDetalle:=Dr("CveVentaDetalle").ToString().ToEntero(), CveVentaDetalleRemision:=Dr("CveVentaDetalleRemision").ToString().ToEntero(), FechaCaducidad:=If(CBool(Dr("AplicaCaducidad")), Dr("FechaCaducidad").ToString().ToDate, MinFecha), Lote:=If(CBool(Dr("AplicaLote")), Dr("Lote").ToString(), "-1"), CveSeccionAlmacen:=-3) Then - ErrorMovInv = True - TextoError.AppendFormat("Ocurrió un error al procesar los conceptos con serie. Por favor vuelva a intentar.") - Exit For - End If - Next - Else - If TipoMovimiento = 2 AndAlso DtExistencias IsNot Nothing Then - PU = DtExistencias.FiltroPrimeroValor("PU", $"CvePS = {Dr("CvePS")} AND CveUM = {Dr("CveUM").ToString().ToEntero()}").ToString().ToDecimal - End If - - If Not ObjInventario.AddMovimientoDetalle(CveMovimiento, CantidadPendiente, Dr("CveUM").ToString().ToEntero(), Dr("CvePS").ToString().ToEntero(), PU, CveVentaDetalle:=Dr("CveVentaDetalle").ToString().ToEntero(), CveVentaDetalleRemision:=Dr("CveVentaDetalleRemision").ToString().ToEntero(), FechaCaducidad:=If(CBool(Dr("AplicaCaducidad")), Dr("FechaCaducidad").ToString().ToDate, MinFecha), Lote:=If(CBool(Dr("AplicaLote")), Dr("Lote").ToString(), "-1"), CveSeccionAlmacen:=-3) Then - ErrorMovInv = True - TextoError.AppendFormat("Ocurrió un error al procesar los conceptos de salida. Por favor vuelva a intentar.") - Exit For - End If - End If - 'If ObjInventario.CveMovimientoDetalle > 0 AndAlso DtSeccionAlmacen.Rows.Count > 0 Then - ' For Each Dr2 As DataRow In DtSeccionAlmacen.FiltraParametros($"IndexSeccionAlmacen = {Cont}").Rows - ' If Not ObjInventario.AddMovimientosDetalleSeccionesAlmacen(ObjInventario.CveMovimientoDetalle, Dr2("CveSeccionAlmacen").ToString().ToEntero(), -Dr2("CantidadSeccionAlmacen").ToString().ToDecimal) Then - ' ErrorMovInv = True - ' TextoError = "Ocurrió un error al procesar las secciones de almacen. Por favor vuelva a intentar." - ' Exit For - ' End If - ' Next - 'End If - Cont += 1 - End If - Next - Else - ErrorMovInv = True - End If - - 'ENTRADA POR TRASPASO CUANDO ES REMISION - If Not ErrorMovInv Then - If tCveAlmacenTraspasoDestino > 0 AndAlso Not (TipoMovimiento = 2 And TipoDocto = "Dev" And EsDevolucionVenta = 1) Then ' TRASPASO CUANDO ES REMISION - CveMovimientoEntrada = ObjInventario.AddMovimiento(tCveAlmacenTraspasoDestino, 9, 1, TxtFecha.Text.ToDate, -1, UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa, -1, CveVentaSurtir, -1, -1, CveOS:=CveOSSurtir, Observaciones:=TxtObservaciones.Text.Trim, Guia:=Guia, CveContrato:=CveContrato, - CveMovimientoRelacionado:=CveMovimiento, CveAlmacenDestino:=DdlAlmacen.SelectedValue.ToEntero(), Modulo:="RE/G8") - FolioEntrada = ObjInventario.Folio - Dim ImporteAlmacen As Decimal = 0 - - If CveMovimientoEntrada <= 0 Then - TextoError.AppendFormat("No se pudo generar el movimiento de entrada correctamente") - ErrorMovInv = True - Else - If ObjInventario.GetMovimientosDetalle(CveMovimiento, UsuarioActual.CveEmpresa) AndAlso ObjInventario.DtResultados.Rows.Count > 0 Then - ImporteAlmacen = ObjInventario.DtResultados.SUMD("Total").RoundSQL - - For Each Dr As DataRow In ObjInventario.DtResultados.Rows - If Not ObjInventario.AddMovimientoDetalle(CveMovimientoEntrada, Dr("Cantidad").ToString().ToDecimal, Dr("CveUM").ToString().ToEntero(), Dr("CvePS").ToString().ToEntero(), Dr("PU").ToString().ToDecimal, CveAF:=Dr("CveAF").ToString().ToEntero(), CveSeccionAlmacen:=-3, Serie:=Dr("Serie").ToString(), Lote:=Dr("Lote").ToString(), FechaCaducidad:=Dr("FechaCaducidad").ToString().ToDate, CveVentaDetalle:=Dr("CveVentaDetalle").ToString().ToEntero(), EsInterno:=EsInterno, CveMovimientoDetalleEntrada:=Dr("CveMovimientoDetalle").ToString().ToEntero()) Then - ErrorMovInv = True - TextoError.AppendFormat("Ocurrió un error al guardar los movimientos de entrada") - Exit For - End If - Next - - Else - ErrorMovInv = True - TextoError.AppendFormat("Ocurrió un error al guardar los movimientos de entrada") - End If - End If - - 'se registra + End If + + CveMovimiento = ObjInventario.AddMovimiento(Almacen1, ConceptoMovimiento, 1, TxtFecha.Text.ToDate, -1, UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa, -1, CveVentaSurtir, -1, -1, CveOS:=CveOSSurtir, Observaciones:=TxtObservaciones.Text.Trim, Guia:=Guia, Recibio:=Recibio, + CveContrato:=CveContrato, CveAlmacenDestino:=tCveAlmacenTraspasoDestino, Modulo:="RE/G7") + Folio = ObjInventario.Folio + + 'SALIDA DE ALMACEN - SALIDA POR TRASPASO CUANDO ES REMISION - DEVOLUCION (SI ES TRASPASO Y TIENE CONTRATO NO HACE DEVOLUCIóN) + 'If Not (CveContrato > 0 And CveAlmacenTraspasoDestino > 0) Then + If CveMovimiento > 0 Then + + 'SACA LO DE TRASPASOS - APARTADO + For Each Dr1 As DataRow In DtTraspasos.Select("CveTipoAlmacen = 9") + CveMovimientoSalida = Dr1("CveMovimientoEntrada").ToString().ToEntero() + If ObjInventario.GetMovimientosDetalle(CveMovimientoSalida, UsuarioActual.CveEmpresa) Then + If ObjInventario.DtResultados.Rows.Count = 0 Then + ErrorMovInv = True + TextoError.AppendFormat("Ocurrió un error, no se tienen registros que ingresar") + Exit Sub + End If + For Each Dr As DataRow In ObjInventario.DtResultados.Rows + + If Not ObjInventario.AddMovimientoDetalle(CveMovimiento, Dr("Cantidad").ToString().ToDecimal, Dr("CveUM").ToString().ToEntero(), Dr("CvePS").ToString().ToEntero(), Dr("PU").ToString().ToDecimal, CveAF:=Dr("CveAF").ToString().ToEntero(), Serie:=Dr("Serie").ToString(), CveMovimientoDetalleEntrada:=Dr("CveMovimientoDetalle").ToString().ToEntero(), CveVentaDetalle:=Dr("CveVentaDetalle").ToString().ToEntero(), FechaCaducidad:=If(CBool(Dr("AplicaCaducidad")), Dr("FechaCaducidad").ToString().ToDate, MinFecha), Lote:=If(CBool(Dr("AplicaLote")), Dr("Lote").ToString(), "-1"), CveSeccionAlmacen:=-3, EsInterno:=EsInterno) Then + ErrorMovInv = True + TextoError.AppendFormat("Ocurrió un error al procesar los conceptos de traspaso de apartado. Por favor vuelva a intentar.") + Exit For + End If + Next + Else + ErrorMovInv = True + TextoError.AppendFormat("Ocurrió un error al obtener los registros") + End If + If ErrorMovInv Then Exit For + Next + + 'ES EL MOVIMIENTO PRINCIPAL + CantidadPendiente = 0 + Dim Cont As Integer = 0 + For Each Dr As DataRow In DtDatos.Rows + CantidadPendiente = Dr("CantidadGV").ToString().ToDecimal - Dr("CantidadTraspaso").ToString().ToDecimal - CantidadEntradaSinCosto + If CantidadPendiente > 0 Then + Dim PU As Decimal = 0 + Dim CveSeccionAlmacen As Integer = If(CBool(Dr("AplicaSeccion")), Dr("CveSeccion").ToString().ToEntero(), -1) + + 'SI FUE POR SERIE + DtDetalle = DtDatosDetalle.FiltraParametros(String.Format("ConsecId = {0} AND FueTraspaso IS NULL", Dr("Consec"))) + DtDetalleLote = DtDatosDetalleLote.FiltraParametros(String.Format("ConsecId = {0} AND FueTraspaso IS NULL", Dr("Consec"))) + If DtDetalle.Rows.Count > 0 Then + For Each Dr1 As DataRow In DtDetalle.Rows + If TipoMovimiento = 2 AndAlso DtExistencias IsNot Nothing Then + 'CveSeccionAlmacen = DtExistencias.FiltroPrimeroValor("CveSeccionAlmacen", $"ISNULL(CveTipoAlmacenDevolucion,0) <> 26 AND CvePS = {Dr("CvePS")} AND CveUM = {Dr("CveUM").ToString().ToEntero()} AND Serie = '{Dr1("Serie").ToString()}'").ToString().ToEntero + + PU = DtExistencias.FiltroPrimeroValor("PU", $"ISNULL(CveTipoAlmacenDevolucion,-1) <> 26 AND CvePS = {Dr("CvePS")} AND CveUM = {Dr("CveUM").ToString().ToEntero()} AND Serie = '{Dr1("Serie").ToString()}'").ToString().ToDecimal + End If + + If Not ObjInventario.AddMovimientoDetalle(CveMovimiento, 1, Dr("CveUM").ToString().ToEntero(), Dr("CvePS").ToString().ToEntero(), PU, Serie:=Dr1("Serie").ToString(), CveVentaDetalle:=Dr("CveVentaDetalle").ToString().ToEntero(), CveVentaDetalleRemision:=Dr("CveVentaDetalleRemision").ToString().ToEntero(), FechaCaducidad:=If(CBool(Dr("AplicaCaducidad")), Dr("FechaCaducidad").ToString().ToDate, MinFecha), Lote:=If(CBool(Dr("AplicaLote")), Dr("Lote").ToString(), "-1"), CveSeccionAlmacen:=-3) Then + ErrorMovInv = True + TextoError.AppendFormat("Ocurrió un error al procesar los conceptos con serie. Por favor vuelva a intentar.") + Exit For + End If + Next + ElseIf DtDetalleLote.Rows.Count > 0 Then + For Each Dr1 As DataRow In DtDetalleLote.Rows + If TipoMovimiento = 2 AndAlso DtExistencias IsNot Nothing Then + 'CveSeccionAlmacen = DtExistencias.FiltroPrimeroValor("CveSeccionAlmacen", $"CvePS = {Dr("CvePS")} AND CveUM = {Dr("CveUM").ToString().ToEntero()} AND Serie = '{Dr1("Serie").ToString()}'").ToString().ToEntero + PU = DtExistencias.FiltroPrimeroValor("PU", $"CvePS = {Dr("CvePS")} AND CveUM = {Dr("CveUM").ToString().ToEntero()} AND Serie = '{Dr1("Serie").ToString()}'").ToString().ToDecimal + End If + + If Not ObjInventario.AddMovimientoDetalle(CveMovimiento, Dr1("Cantidad").ToString().ToDecimal, Dr("CveUM").ToString().ToEntero(), Dr("CvePS").ToString().ToEntero(), PU, CveVentaDetalle:=Dr("CveVentaDetalle").ToString().ToEntero(), CveVentaDetalleRemision:=Dr("CveVentaDetalleRemision").ToString().ToEntero(), FechaCaducidad:=If(CBool(Dr("AplicaCaducidad")), Dr("FechaCaducidad").ToString().ToDate, MinFecha), Lote:=If(CBool(Dr("AplicaLote")), Dr("Lote").ToString(), "-1"), CveSeccionAlmacen:=-3) Then + ErrorMovInv = True + TextoError.AppendFormat("Ocurrió un error al procesar los conceptos con serie. Por favor vuelva a intentar.") + Exit For + End If + Next + Else + If TipoMovimiento = 2 AndAlso DtExistencias IsNot Nothing Then + PU = DtExistencias.FiltroPrimeroValor("PU", $"CvePS = {Dr("CvePS")} AND CveUM = {Dr("CveUM").ToString().ToEntero()}").ToString().ToDecimal + End If + + If Not ObjInventario.AddMovimientoDetalle(CveMovimiento, CantidadPendiente, Dr("CveUM").ToString().ToEntero(), Dr("CvePS").ToString().ToEntero(), PU, CveVentaDetalle:=Dr("CveVentaDetalle").ToString().ToEntero(), CveVentaDetalleRemision:=Dr("CveVentaDetalleRemision").ToString().ToEntero(), FechaCaducidad:=If(CBool(Dr("AplicaCaducidad")), Dr("FechaCaducidad").ToString().ToDate, MinFecha), Lote:=If(CBool(Dr("AplicaLote")), Dr("Lote").ToString(), "-1"), CveSeccionAlmacen:=-3) Then + ErrorMovInv = True + TextoError.AppendFormat("Ocurrió un error al procesar los conceptos de salida. Por favor vuelva a intentar.") + Exit For + End If + End If + 'If ObjInventario.CveMovimientoDetalle > 0 AndAlso DtSeccionAlmacen.Rows.Count > 0 Then + ' For Each Dr2 As DataRow In DtSeccionAlmacen.FiltraParametros($"IndexSeccionAlmacen = {Cont}").Rows + ' If Not ObjInventario.AddMovimientosDetalleSeccionesAlmacen(ObjInventario.CveMovimientoDetalle, Dr2("CveSeccionAlmacen").ToString().ToEntero(), -Dr2("CantidadSeccionAlmacen").ToString().ToDecimal) Then + ' ErrorMovInv = True + ' TextoError = "Ocurrió un error al procesar las secciones de almacen. Por favor vuelva a intentar." + ' Exit For + ' End If + ' Next + 'End If + Cont += 1 + End If + Next + Else + ErrorMovInv = True + End If + + 'ENTRADA POR TRASPASO CUANDO ES REMISION + If Not ErrorMovInv Then + If tCveAlmacenTraspasoDestino > 0 AndAlso Not (TipoMovimiento = 2 And TipoDocto = "Dev" And EsDevolucionVenta = 1) Then ' TRASPASO CUANDO ES REMISION + CveMovimientoEntrada = ObjInventario.AddMovimiento(tCveAlmacenTraspasoDestino, 9, 1, TxtFecha.Text.ToDate, -1, UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa, -1, CveVentaSurtir, -1, -1, CveOS:=CveOSSurtir, Observaciones:=TxtObservaciones.Text.Trim, Guia:=Guia, CveContrato:=CveContrato, + CveMovimientoRelacionado:=CveMovimiento, CveAlmacenDestino:=DdlAlmacen.SelectedValue.ToEntero(), Modulo:="RE/G8") + FolioEntrada = ObjInventario.Folio + Dim ImporteAlmacen As Decimal = 0 + + If CveMovimientoEntrada <= 0 Then + TextoError.AppendFormat("No se pudo generar el movimiento de entrada correctamente") + ErrorMovInv = True + Else + If ObjInventario.GetMovimientosDetalle(CveMovimiento, UsuarioActual.CveEmpresa) AndAlso ObjInventario.DtResultados.Rows.Count > 0 Then + ImporteAlmacen = ObjInventario.DtResultados.SUMD("Total").RoundSQL + + For Each Dr As DataRow In ObjInventario.DtResultados.Rows + If Not ObjInventario.AddMovimientoDetalle(CveMovimientoEntrada, Dr("Cantidad").ToString().ToDecimal, Dr("CveUM").ToString().ToEntero(), Dr("CvePS").ToString().ToEntero(), Dr("PU").ToString().ToDecimal, CveAF:=Dr("CveAF").ToString().ToEntero(), CveSeccionAlmacen:=-3, Serie:=Dr("Serie").ToString(), Lote:=Dr("Lote").ToString(), FechaCaducidad:=Dr("FechaCaducidad").ToString().ToDate, CveVentaDetalle:=Dr("CveVentaDetalle").ToString().ToEntero(), EsInterno:=EsInterno, CveMovimientoDetalleEntrada:=Dr("CveMovimientoDetalle").ToString().ToEntero()) Then + ErrorMovInv = True + TextoError.AppendFormat("Ocurrió un error al guardar los movimientos de entrada") + Exit For + End If + Next + + Else + ErrorMovInv = True + TextoError.AppendFormat("Ocurrió un error al guardar los movimientos de entrada") + End If + End If + + 'se registra If Not ErrorMovInv Then If ContabilizaMovimientoAlmacen(ObjConta, TxtFecha.Text.ToDate, HLFolio.Text, "EntregaAlmacen", CveMovimiento, CveMovimientoEntrada, ImporteAlmacen, UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa, False) <= 0 Then ErrorMovInv = True End If End If - Else 'REGISTRO LA PREPOLIZA DE COSTO VS ALMACEN - SALIDA ALMACEN - ErrorMovInv = Not GenerarPrePoliza(ObjInventario, ObjVentas, ObjConta, CveMovimiento, TextoError) - End If - - End If - - End If - - - 'DEVOLUCION APARTADOS - If Not ErrorMovInv Then - If TipoMovimiento = 2 Then - If ObjInventario.VentasAlmacenApartadosGet(CveVentaSurtir) Then - - Dim DtTempApartados As DataTable = ObjInventario.DtResultados.FiltraParametros("CveTipoAlmacen = 9", "CveAlmacen") - Dim CveMovimientoSalidaApartado As Integer = -1 - Dim CveAlmacenApartado As Integer = -1 - Dim CveAlmacenOrigen As Integer = If(CveAlmacenTraspasoDestino > 0, CveAlmacenTraspasoDestino, DdlAlmacen.SelectedValue.ToEntero()) - Dim CveSeccionAlmacen As Integer = 0 - Dim ValorTraspaso As Decimal = 0 - If DtTempApartados IsNot Nothing AndAlso DtTempApartados.Rows.Count > 0 Then - For Each Dr As DataRow In DtTempApartados.Rows - - If CveMovimientoSalidaApartado = -1 Or CveAlmacenApartado <> Dr("CveAlmacen").ToString().ToEntero() Then - CveMovimientoSalidaApartado = ObjInventario.AddMovimiento(CveAlmacenOrigen, 8, 1, TxtFecha.Text.ToDate, -1, UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa, -1, CveVentaSurtir, -1, -1, CveOS:=CveOSSurtir, - Observaciones:=TxtObservaciones.Text.Trim, Guia:=Guia, CveContrato:=CveContrato, CveVendedor:=CveVendedor, CveCliente:=CveCliente, - CveAlmacenDestino:=Dr("CveAlmacen").ToString().ToEntero(), Modulo:="RE/G9") - FolioSalida = ObjInventario.Folio - CveAlmacenApartado = Dr("CveAlmacen").ToString().ToEntero() - - Dim DrMovto As DataRow = DtTraspasos.NewRow - DrMovto("Almacen") = Dr("Almacen").ToString().ToEntero() - DrMovto("CveAlmacen") = Dr("CveAlmacen").ToString().ToEntero() - DrMovto("CveMovimientoSalida") = CveMovimientoSalidaApartado - DrMovto("FolioSalida") = FolioSalida - DtTraspasos.Rows.Add(DrMovto) - End If - - If Not CveMovimientoSalidaApartado > 0 Then - ErrorMovInv = True - TextoError.AppendFormat("Ocurrió un error al guardar los movimientos de control de apartados") - Exit For - End If - 'If CBool(Dr("AplicaSeccion")) Then - ' CveSeccionAlmacen = GlobalDTInvPSSeccionesAlmacen(UsuarioActual.CveEmpresa, CveAlmacenOrigen, Dr("CvePS").ToString().ToEntero()).FiltroPrimeroValor("CveSeccionAlmacen").ToEntero() - ' Dim a As String = String.Format("CveAlmacen={0}-CvePS:{1}-CveseccionAlmacen={2}", CveAlmacenOrigen, Dr("CvePS"), CveSeccionAlmacen) - 'Else - ' CveSeccionAlmacen = -1 - 'End If - CveSeccionAlmacen = -3 - - If Not ObjInventario.AddMovimientoDetalle(CveMovimientoSalidaApartado, Dr("Cantidad").ToString().ToDecimal, Dr("CveUM").ToString().ToEntero(), Dr("CvePS").ToString().ToEntero(), Dr("PU").ToString().ToDecimal, CveAF:=Dr("CveAF").ToString().ToEntero(), Serie:=Dr("Serie").ToString(), CveVentaDetalle:=Dr("CveVentaDetalle").ToString().ToEntero(), Lote:=Dr("Lote").ToString(), CveSeccionAlmacen:=CveSeccionAlmacen) Then - ErrorMovInv = True - TextoError.AppendFormat("Ocurrió un error al guardar los movimientos de control de apartados") - Exit For - End If - Next - - If Not ErrorMovInv Then - - Dim CvePrePolizaTraspaso As Integer = ObjConta.AddPrePolizas("EA/Apart", 53, 0, 0, 1, TxtFecha.Text.ToDate, "Traspaso Apartado", UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa) - If CvePrePolizaTraspaso > 0 Then - - If Not ObjConta.AddPrePolizasDetalle(CvePrePolizaTraspaso, True, ValorTraspaso, ValorTraspaso, 68, TxtObservaciones.Text, TxtObservaciones.Text, CveMovimientoAlmacen:=CveMovimientoSalidaApartado, Contabilizable:=False) Then - ErrorMovInv = True - End If - - For Each Dr1 As DataRow In DtTraspasos.Rows - CveMovimientoSalida = Dr1("CveMovimientoSalida").ToString().ToEntero() - - CveMovimientoEntradaApartado = ObjInventario.AddMovimiento(Dr1("CveAlmacen").ToString().ToEntero(), 9, 1, TxtFecha.Text.ToDate, -1, UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa, - -1, CveVentaSurtir, -1, -1, CveOS:=CveOSSurtir, Observaciones:=TxtObservaciones.Text.Trim, CveAlmacenDestino:=DdlAlmacen.SelectedValue.ToEntero(), - CveMovimientoRelacionado:=CveMovimientoSalida, Guia:=Guia, CveContrato:=CveContrato, CveVendedor:=CveVendedor, - CveCliente:=CveCliente, Modulo:="RE/G10") - FolioEntrada = ObjInventario.Folio - - If Not CveMovimientoEntradaApartado > 0 Then - ErrorMovInv = True - TextoError.AppendFormat("Ocurrió un error al procesar los movimientos de traspaso de apartado. Por favor vuelva a intentar.") - Exit For - End If - - Dr1("CveMovimientoEntrada") = CveMovimientoEntradaApartado - Dr1("FolioEntrada") = FolioEntrada - - If ObjInventario.GetMovimientosDetalle(CveMovimientoSalida, UsuarioActual.CveEmpresa) Then - ValorTraspaso = ObjInventario.DtResultados.SUMD("Total").RoundSQL - For Each Dr As DataRow In ObjInventario.DtResultados.Rows - - CveSeccionAlmacen = -3 - - If Not ObjInventario.AddMovimientoDetalle(CveMovimientoEntradaApartado, Dr("Cantidad").ToString().ToDecimal, Dr("CveUM").ToString().ToEntero(), Dr("CvePS").ToString().ToEntero(), Dr("PU").ToString().ToDecimal, CveAF:=Dr("CveAF").ToString().ToEntero(), Serie:=Dr("Serie").ToString(), CveMovimientoDetalleEntrada:=Dr("CveMovimientoDetalle").ToString().ToEntero(), Lote:=Dr("Lote").ToString(), CveSeccionAlmacen:=CveSeccionAlmacen) Then - ErrorMovInv = True - TextoError.AppendFormat("Ocurrió un error al procesar los conceptos de traspaso de apartado. Por favor vuelva a intentar.") - Exit For - End If - Next - End If - - If ErrorMovInv Then Exit For - - If Not ErrorMovInv AndAlso Not ObjConta.AddPrePolizasDetalle(CvePrePolizaTraspaso, False, ValorTraspaso, ValorTraspaso, 68, TxtObservaciones.Text, TxtObservaciones.Text, CveMovimientoAlmacen:=CveMovimientoEntradaApartado, Contabilizable:=False) Then - ErrorMovInv = True - End If - Next - - - Else - ErrorMovInv = True - End If - End If - End If - End If - End If - End If - - 'QUEMAR REMISIONES - If Not ErrorMovInv And EsDevolucionVenta = 1 And TipoDocto = "Ing" Then - Dim DtDevRem As New DataTable - - 'CARGA REMISIONES DE LA VENTA DEVUELTA - If ObjInventario.GetDevolucionRemisionesFacturadas(CveVentaSurtir) Then - DtDevRem = ObjInventario.DtResultados.FiltraParametros("CantidadAlmacen = 0") - Else - ErrorMovInv = True - End If - - If Not ErrorMovInv Then - If DtDevRem.Rows.Count > 0 Then - For Each DrMovtos As DataRow In DtDevRem.FiltraParametros("", "CveRem", {"CveRem"}).Rows - If Not ObjInventario.ActualizarEsDevolucionVenta(DrMovtos("CveRem").ToString().ToEntero(), 2) Then - TextoError.AppendFormat("Ocurrió un error al hacer la devolución hacia la remision. Por favor vuelva a intentar.") - ErrorMovInv = True - Exit For - End If - Next - End If - Else - TextoError.AppendFormat("Ocurrió un error al hacer la devolucion a remisión. Por favor vuelva a intentar.") - ErrorMovInv = True - End If - - End If - - 'QUEMA DEVOLUCION | QUEMA = LA QUITA DE PENDIENTE POR RECIBIR (DEVOLVER) - If Not ErrorMovInv And EsDevolucionVenta = 1 Then - If Not ObjVentas.UpdateVentasDevolucionAlmacen(2, CveVentaSurtir) Then - TextoError.AppendFormat("Ocurrió un error al hacer la devolución. Por favor vuelva a intentar.") - ErrorMovInv = True - End If - End If - - If Not ErrorMovInv And EsDevolucionVenta = 0 Then - If Not ObjVentas.UpdateVentasDevolucionAlmacen(0, CveVentaSurtir) Then - TextoError.AppendFormat("Ocurrió un error al hacer la devolucion. Por favor vuelva a intentar.") - ErrorMovInv = True - End If - End If - - If Not ErrorMovInv And EsDevolucionVenta = 0 AndAlso TipoDocto = "RNC" Then - If Not ObjVentas.UpdateVentasDevolucionAlmacen(2, CveVentaSurtir) Then - TextoError.AppendFormat("Ocurrió un error al hacer la devolucion. Por favor vuelva a intentar.") - ErrorMovInv = True - End If - End If - - Dim TotalVirtual As Decimal = 0 - - ' COMIENZA: VIRTUAL - If Not ErrorMovInv AndAlso TipoDocto.Contiene("Ing", "Dev") AndAlso UsuarioActual.Empresa.Funcionalidad(573) = "1" AndAlso CveMovimiento > 0 Then - Dim DtPSVirtual As New DataTable("DtTamanios") - Dim tCveAlmacen As Integer = -1 - - If ObjInventario.GetMovimientos(CveMovimiento, -1, -1, UsuarioActual.CveEmpresa) AndAlso ObjInventario.DtResultados.Rows.Count > 0 Then - tCveAlmacen = ObjInventario.DtResultados.FiltroPrimeroValor("CveAlmacen").ToEntero() - End If - - If ObjInventario.GetMovimientosDetalleVirtual(CveMovimiento, UsuarioActual.CveEmpresa) Then - DtPSVirtual = ObjInventario.DtResultados - End If - - ' - 'DtPSVirtual.Columns.Add(New DataColumn("CvePS", GetType(Integer))) - 'DtPSVirtual.Columns.Add(New DataColumn("Cantidad", GetType(Decimal))) - 'DtPSVirtual.Columns.Add(New DataColumn("PU", GetType(Decimal))) - 'DtPSVirtual.Columns.Add(New DataColumn("CveUM", GetType(Integer))) - - 'Dim DtTamanios As DataTable = Nothing - - 'If ObjAcumuladores.TamañoGet(-1, UsuarioActual.CveEmpresa) Then - ' DtTamanios = ObjAcumuladores.DtResultados.Copy() - 'End If - - Dim CveConceptoMovimientoVirtual As Integer = -1 - Dim CveAlmacenVirtual As Integer = -1 - Dim CveMovimientoRelacionadoVirtual As Integer = CveMovimiento - Dim ValidaVirtual As Boolean = False - CveAlmacenVirtual = GlobalDTAlmacen(UsuarioActual.CveEmpresa, CveAlmacen:=tCveAlmacen).FiltroPrimeroValor("CveAlmacenVirtual").ToEntero() - - If TipoMovimiento = 1 Then - CveConceptoMovimientoVirtual = 37 - ElseIf TipoMovimiento = 2 Then - ValidaVirtual = True - CveConceptoMovimientoVirtual = 36 - End If - - 'SI NO TIENE ALMACEN VIRTUAL ASIGNADO NO GENERA EL MOVIMIENTO VIRTUAL - If CveAlmacenVirtual <= 0 Then - ValidaVirtual = False - End If - - 'SI NO APLICA VIRTUAL EN LOS PRODUCTOS NO VALIDA - If CveAlmacenVirtual > 0 AndAlso DtPSVirtual IsNot Nothing AndAlso DtPSVirtual.Rows.Count = 0 Then - ValidaVirtual = False - End If - - If DtPSVirtual IsNot Nothing AndAlso DtPSVirtual.Rows.Count > 0 AndAlso CveAlmacenVirtual > 0 AndAlso CveConceptoMovimientoVirtual > 0 Then - CveMovimientoVirtual = ObjInventario.AddMovimiento(CveAlmacenVirtual, CveConceptoMovimientoVirtual, 1, TxtFecha.Text.ToDate, -1, UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa, -1, CveVentaSurtir, -1, -1, CveOS:=CveOSSurtir, - Observaciones:=TxtObservaciones.Text.Trim, Guia:=Guia, CveMovimientoRelacionado:=CveMovimientoRelacionadoVirtual, Modulo:="RE/G6") - FolioVirtual = ObjInventario.Folio - - If CveMovimientoVirtual > 0 Then - Dim TmpDTDetalleFactura As DataTable = Nothing - If ObjVentas.GetVentaDetalle(CveVentaSurtir) Then - TmpDTDetalleFactura = ObjVentas.DtResultados.Copy() - End If - - For Each RowUsado As DataRow In DtPSVirtual.Rows - Dim CvePS As Integer = RowUsado("CvePS").ToString().ToEntero() - Dim CantidadUsado As Decimal = RowUsado("Cantidad").ToString().ToDecimal() - Dim PU As Decimal = RowUsado("Cargo").ToString().ToDecimal() - Dim CveUM As Integer = RowUsado("CveUM").ToString().ToEntero() - - Dim CveVentaDetalle As Integer = -1 - If TmpDTDetalleFactura IsNot Nothing Then - CveVentaDetalle = TmpDTDetalleFactura.FiltroPrimeroValor("CveVentaDetalle", $"Cantidad = {RowUsado("Cantidad")} AND CvePS = {RowUsado("CvePS")}").ToEntero() - If CveVentaDetalle <= 0 Then - CveVentaDetalle = -1 - End If - End If - - If Not ObjInventario.AddMovimientoDetalle(CveMovimientoVirtual, CantidadUsado, CveUM, CvePS, PU, CveVentaDetalle:=CveVentaDetalle) Then - ErrorMovInv = True - TextoError.AppendFormat("Ocurrió un error al procesar los conceptos de traspaso de apartado. Por favor vuelva a intentar.") - Exit For - End If - TotalVirtual += (CantidadUsado * PU) - Next - 'insertar en prepóliza de la salida virtual - If Not ErrorMovInv Then - ErrorMovInv = Not GenerarPrePoliza(ObjInventario, ObjVentas, ObjConta, CveMovimientoVirtual, TextoError) - - End If - - Else - ErrorMovInv = True - End If - - Else - If ValidaVirtual Then - ErrorMovInv = True - TextoError.AppendFormat("Ocurrió un error al procesar el movimiento en almacen virtual. Por favor vuelva a intentar.") - - End If - End If - - If DtPSVirtual.Rows.Count = 0 AndAlso ValidaVirtual = True Then - ErrorMovInv = True - TextoError.AppendFormat("No se tienen productos para el almacen virtual.") - End If - End If - - ' TERMINA: VIRTUAL - - - 'AGREGA BITACORA A VENTA - If Not ErrorMovInv Then - Dim MensajeBitacora As String = If(TipoMovimiento = 1, "Surtida", "Devuelta") - Dim LigaVenta As String = String.Format("Venta {2} en Folio: {1}", CveMovimiento, Folio, MensajeBitacora) - - If Not ObjEventos.AddEventoBitacora(LigaVenta, "-1", UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa, CveVenta:=CveVentaSurtir, CveOS:=CveOSSurtir) Then - ErrorMovInv = True - End If - - End If - - 'Paqueterias guias - If RbEntregaInterna.Checked AndAlso Not ErrorMovInv Then - Dim CveEstatus As Integer = 1 ' DdlEstatus.SelectedValue.ToEntero() - Dim Fecha As String = NowADS().ToString() 'TxtFechaPaqInterna.Text - Dim FechaEstimada As String = "-1" 'If(TxtFechaEstimada.Text = "", "-1", TxtFechaEstimada.Text) - Dim NoCajas As Integer = 0 'TxtNoCajas.Text.ToEntero() - Dim Observaciones As String = "" 'TxtObservacionesPaqInterna.Text - Dim CvePaqueteria As Integer = GlobalDTPaqueterias(UsuarioActual.CveEmpresa, 0).FiltroPrimeroValor("CvePaqueteria", "").ToEntero() - - If CveSubProyecto > 0 Then - Dim CvePaqueteriaGuia As Integer = ObjGeneral.AddPaqueteriasGuias(CvePaqueteria, 9, CveEstatus, CveSubProyecto, Fecha, "", "", NoCajas, 0.00, "-1", FechaEstimada, Observaciones, UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa, EsEntregaInterna:=True) - - If CvePaqueteriaGuia > 0 Then - - If CveVentaSurtir > 0 OrElse CveSubProyecto > 0 Then - If Not ObjGeneral.AddPaqueteriasGuiasDetalles(CvePaqueteriaGuia, CveVentaSurtir, -1, CveMovimientoSalida, -1) Then - ''manda correo - ErrorMovInv = True - End If - End If - If ErrorMovInv Then - Alert("Error en el paqueteria guia detalle", TipoMensaje.MsgError) - End If - Else - ErrorMovInv = True - Alert("Error en el paqueteria guia", TipoMensaje.MsgError) - End If - Else - Alert("Hace falta indicar un Sub Proyecto", TipoMensaje.MsgAdvertencia) - ErrorMovInv = True - End If - ElseIf RbSinEntrega.Checked AndAlso Not ErrorMovInv Then - MandaCorreoEntrega(CveVentaSurtir) - End If - Catch ex As Exception - ErrorMovInv = True - OnError("Ocurrió un error al guardar", ex) - End Try - + Else 'REGISTRO LA PREPOLIZA DE COSTO VS ALMACEN - SALIDA ALMACEN + ErrorMovInv = Not GenerarPrePoliza(ObjInventario, ObjVentas, ObjConta, CveMovimiento, TextoError) + End If + + End If + + End If + + + 'DEVOLUCION APARTADOS + If Not ErrorMovInv Then + If TipoMovimiento = 2 Then + If ObjInventario.VentasAlmacenApartadosGet(CveVentaSurtir) Then + + Dim DtTempApartados As DataTable = ObjInventario.DtResultados.FiltraParametros("CveTipoAlmacen = 9", "CveAlmacen") + Dim CveMovimientoSalidaApartado As Integer = -1 + Dim CveAlmacenApartado As Integer = -1 + Dim CveAlmacenOrigen As Integer = If(CveAlmacenTraspasoDestino > 0, CveAlmacenTraspasoDestino, DdlAlmacen.SelectedValue.ToEntero()) + Dim CveSeccionAlmacen As Integer = 0 + Dim ValorTraspaso As Decimal = 0 + If DtTempApartados IsNot Nothing AndAlso DtTempApartados.Rows.Count > 0 Then + For Each Dr As DataRow In DtTempApartados.Rows + + If CveMovimientoSalidaApartado = -1 Or CveAlmacenApartado <> Dr("CveAlmacen").ToString().ToEntero() Then + CveMovimientoSalidaApartado = ObjInventario.AddMovimiento(CveAlmacenOrigen, 8, 1, TxtFecha.Text.ToDate, -1, UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa, -1, CveVentaSurtir, -1, -1, CveOS:=CveOSSurtir, + Observaciones:=TxtObservaciones.Text.Trim, Guia:=Guia, CveContrato:=CveContrato, CveVendedor:=CveVendedor, CveCliente:=CveCliente, + CveAlmacenDestino:=Dr("CveAlmacen").ToString().ToEntero(), Modulo:="RE/G9") + FolioSalida = ObjInventario.Folio + CveAlmacenApartado = Dr("CveAlmacen").ToString().ToEntero() + + Dim DrMovto As DataRow = DtTraspasos.NewRow + DrMovto("Almacen") = Dr("Almacen").ToString().ToEntero() + DrMovto("CveAlmacen") = Dr("CveAlmacen").ToString().ToEntero() + DrMovto("CveMovimientoSalida") = CveMovimientoSalidaApartado + DrMovto("FolioSalida") = FolioSalida + DtTraspasos.Rows.Add(DrMovto) + End If + + If Not CveMovimientoSalidaApartado > 0 Then + ErrorMovInv = True + TextoError.AppendFormat("Ocurrió un error al guardar los movimientos de control de apartados") + Exit For + End If + 'If CBool(Dr("AplicaSeccion")) Then + ' CveSeccionAlmacen = GlobalDTInvPSSeccionesAlmacen(UsuarioActual.CveEmpresa, CveAlmacenOrigen, Dr("CvePS").ToString().ToEntero()).FiltroPrimeroValor("CveSeccionAlmacen").ToEntero() + ' Dim a As String = String.Format("CveAlmacen={0}-CvePS:{1}-CveseccionAlmacen={2}", CveAlmacenOrigen, Dr("CvePS"), CveSeccionAlmacen) + 'Else + ' CveSeccionAlmacen = -1 + 'End If + CveSeccionAlmacen = -3 + + If Not ObjInventario.AddMovimientoDetalle(CveMovimientoSalidaApartado, Dr("Cantidad").ToString().ToDecimal, Dr("CveUM").ToString().ToEntero(), Dr("CvePS").ToString().ToEntero(), Dr("PU").ToString().ToDecimal, CveAF:=Dr("CveAF").ToString().ToEntero(), Serie:=Dr("Serie").ToString(), CveVentaDetalle:=Dr("CveVentaDetalle").ToString().ToEntero(), Lote:=Dr("Lote").ToString(), CveSeccionAlmacen:=CveSeccionAlmacen) Then + ErrorMovInv = True + TextoError.AppendFormat("Ocurrió un error al guardar los movimientos de control de apartados") + Exit For + End If + Next + + If Not ErrorMovInv Then + + Dim CvePrePolizaTraspaso As Integer = ObjConta.AddPrePolizas("EA/Apart", 53, 0, 0, 1, TxtFecha.Text.ToDate, "Traspaso Apartado", UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa) + If CvePrePolizaTraspaso > 0 Then + + If Not ObjConta.AddPrePolizasDetalle(CvePrePolizaTraspaso, True, ValorTraspaso, ValorTraspaso, 68, TxtObservaciones.Text, TxtObservaciones.Text, CveMovimientoAlmacen:=CveMovimientoSalidaApartado, Contabilizable:=False) Then + ErrorMovInv = True + End If + + For Each Dr1 As DataRow In DtTraspasos.Rows + CveMovimientoSalida = Dr1("CveMovimientoSalida").ToString().ToEntero() + + CveMovimientoEntradaApartado = ObjInventario.AddMovimiento(Dr1("CveAlmacen").ToString().ToEntero(), 9, 1, TxtFecha.Text.ToDate, -1, UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa, + -1, CveVentaSurtir, -1, -1, CveOS:=CveOSSurtir, Observaciones:=TxtObservaciones.Text.Trim, CveAlmacenDestino:=DdlAlmacen.SelectedValue.ToEntero(), + CveMovimientoRelacionado:=CveMovimientoSalida, Guia:=Guia, CveContrato:=CveContrato, CveVendedor:=CveVendedor, + CveCliente:=CveCliente, Modulo:="RE/G10") + FolioEntrada = ObjInventario.Folio + + If Not CveMovimientoEntradaApartado > 0 Then + ErrorMovInv = True + TextoError.AppendFormat("Ocurrió un error al procesar los movimientos de traspaso de apartado. Por favor vuelva a intentar.") + Exit For + End If + + Dr1("CveMovimientoEntrada") = CveMovimientoEntradaApartado + Dr1("FolioEntrada") = FolioEntrada + + If ObjInventario.GetMovimientosDetalle(CveMovimientoSalida, UsuarioActual.CveEmpresa) Then + ValorTraspaso = ObjInventario.DtResultados.SUMD("Total").RoundSQL + For Each Dr As DataRow In ObjInventario.DtResultados.Rows + + CveSeccionAlmacen = -3 + + If Not ObjInventario.AddMovimientoDetalle(CveMovimientoEntradaApartado, Dr("Cantidad").ToString().ToDecimal, Dr("CveUM").ToString().ToEntero(), Dr("CvePS").ToString().ToEntero(), Dr("PU").ToString().ToDecimal, CveAF:=Dr("CveAF").ToString().ToEntero(), Serie:=Dr("Serie").ToString(), CveMovimientoDetalleEntrada:=Dr("CveMovimientoDetalle").ToString().ToEntero(), Lote:=Dr("Lote").ToString(), CveSeccionAlmacen:=CveSeccionAlmacen) Then + ErrorMovInv = True + TextoError.AppendFormat("Ocurrió un error al procesar los conceptos de traspaso de apartado. Por favor vuelva a intentar.") + Exit For + End If + Next + End If + + If ErrorMovInv Then Exit For + + If Not ErrorMovInv AndAlso Not ObjConta.AddPrePolizasDetalle(CvePrePolizaTraspaso, False, ValorTraspaso, ValorTraspaso, 68, TxtObservaciones.Text, TxtObservaciones.Text, CveMovimientoAlmacen:=CveMovimientoEntradaApartado, Contabilizable:=False) Then + ErrorMovInv = True + End If + Next + + + Else + ErrorMovInv = True + End If + End If + End If + End If + End If + End If + + 'QUEMAR REMISIONES + If Not ErrorMovInv And EsDevolucionVenta = 1 And TipoDocto = "Ing" Then + Dim DtDevRem As New DataTable + + 'CARGA REMISIONES DE LA VENTA DEVUELTA + If ObjInventario.GetDevolucionRemisionesFacturadas(CveVentaSurtir) Then + DtDevRem = ObjInventario.DtResultados.FiltraParametros("CantidadAlmacen = 0") + Else + ErrorMovInv = True + End If + + If Not ErrorMovInv Then + If DtDevRem.Rows.Count > 0 Then + For Each DrMovtos As DataRow In DtDevRem.FiltraParametros("", "CveRem", {"CveRem"}).Rows + If Not ObjInventario.ActualizarEsDevolucionVenta(DrMovtos("CveRem").ToString().ToEntero(), 2) Then + TextoError.AppendFormat("Ocurrió un error al hacer la devolución hacia la remision. Por favor vuelva a intentar.") + ErrorMovInv = True + Exit For + End If + Next + End If + Else + TextoError.AppendFormat("Ocurrió un error al hacer la devolucion a remisión. Por favor vuelva a intentar.") + ErrorMovInv = True + End If + + End If + + 'QUEMA DEVOLUCION | QUEMA = LA QUITA DE PENDIENTE POR RECIBIR (DEVOLVER) + If Not ErrorMovInv And EsDevolucionVenta = 1 Then + If Not ObjVentas.UpdateVentasDevolucionAlmacen(2, CveVentaSurtir) Then + TextoError.AppendFormat("Ocurrió un error al hacer la devolución. Por favor vuelva a intentar.") + ErrorMovInv = True + End If + End If + + If Not ErrorMovInv And EsDevolucionVenta = 0 Then + If Not ObjVentas.UpdateVentasDevolucionAlmacen(0, CveVentaSurtir) Then + TextoError.AppendFormat("Ocurrió un error al hacer la devolucion. Por favor vuelva a intentar.") + ErrorMovInv = True + End If + End If + + If Not ErrorMovInv And EsDevolucionVenta = 0 AndAlso TipoDocto = "RNC" Then + If Not ObjVentas.UpdateVentasDevolucionAlmacen(2, CveVentaSurtir) Then + TextoError.AppendFormat("Ocurrió un error al hacer la devolucion. Por favor vuelva a intentar.") + ErrorMovInv = True + End If + End If + + Dim TotalVirtual As Decimal = 0 + + ' COMIENZA: VIRTUAL + If Not ErrorMovInv AndAlso TipoDocto.Contiene("Ing", "Dev") AndAlso UsuarioActual.Empresa.Funcionalidad(573) = "1" AndAlso CveMovimiento > 0 Then + Dim DtPSVirtual As New DataTable("DtTamanios") + Dim tCveAlmacen As Integer = -1 + + If ObjInventario.GetMovimientos(CveMovimiento, -1, -1, UsuarioActual.CveEmpresa) AndAlso ObjInventario.DtResultados.Rows.Count > 0 Then + tCveAlmacen = ObjInventario.DtResultados.FiltroPrimeroValor("CveAlmacen").ToEntero() + End If + + If ObjInventario.GetMovimientosDetalleVirtual(CveMovimiento, UsuarioActual.CveEmpresa) Then + DtPSVirtual = ObjInventario.DtResultados + End If + + ' + 'DtPSVirtual.Columns.Add(New DataColumn("CvePS", GetType(Integer))) + 'DtPSVirtual.Columns.Add(New DataColumn("Cantidad", GetType(Decimal))) + 'DtPSVirtual.Columns.Add(New DataColumn("PU", GetType(Decimal))) + 'DtPSVirtual.Columns.Add(New DataColumn("CveUM", GetType(Integer))) + + 'Dim DtTamanios As DataTable = Nothing + + 'If ObjAcumuladores.TamañoGet(-1, UsuarioActual.CveEmpresa) Then + ' DtTamanios = ObjAcumuladores.DtResultados.Copy() + 'End If + + Dim CveConceptoMovimientoVirtual As Integer = -1 + Dim CveAlmacenVirtual As Integer = -1 + Dim CveMovimientoRelacionadoVirtual As Integer = CveMovimiento + Dim ValidaVirtual As Boolean = False + CveAlmacenVirtual = GlobalDTAlmacen(UsuarioActual.CveEmpresa, CveAlmacen:=tCveAlmacen).FiltroPrimeroValor("CveAlmacenVirtual").ToEntero() + + If TipoMovimiento = 1 Then + CveConceptoMovimientoVirtual = 37 + ElseIf TipoMovimiento = 2 Then + ValidaVirtual = True + CveConceptoMovimientoVirtual = 36 + End If + + 'SI NO TIENE ALMACEN VIRTUAL ASIGNADO NO GENERA EL MOVIMIENTO VIRTUAL + If CveAlmacenVirtual <= 0 Then + ValidaVirtual = False + End If + + 'SI NO APLICA VIRTUAL EN LOS PRODUCTOS NO VALIDA + If CveAlmacenVirtual > 0 AndAlso DtPSVirtual IsNot Nothing AndAlso DtPSVirtual.Rows.Count = 0 Then + ValidaVirtual = False + End If + + If DtPSVirtual IsNot Nothing AndAlso DtPSVirtual.Rows.Count > 0 AndAlso CveAlmacenVirtual > 0 AndAlso CveConceptoMovimientoVirtual > 0 Then + CveMovimientoVirtual = ObjInventario.AddMovimiento(CveAlmacenVirtual, CveConceptoMovimientoVirtual, 1, TxtFecha.Text.ToDate, -1, UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa, -1, CveVentaSurtir, -1, -1, CveOS:=CveOSSurtir, + Observaciones:=TxtObservaciones.Text.Trim, Guia:=Guia, CveMovimientoRelacionado:=CveMovimientoRelacionadoVirtual, Modulo:="RE/G6") + FolioVirtual = ObjInventario.Folio + + If CveMovimientoVirtual > 0 Then + Dim TmpDTDetalleFactura As DataTable = Nothing + If ObjVentas.GetVentaDetalle(CveVentaSurtir) Then + TmpDTDetalleFactura = ObjVentas.DtResultados.Copy() + End If + + For Each RowUsado As DataRow In DtPSVirtual.Rows + Dim CvePS As Integer = RowUsado("CvePS").ToString().ToEntero() + Dim CantidadUsado As Decimal = RowUsado("Cantidad").ToString().ToDecimal() + Dim PU As Decimal = RowUsado("Cargo").ToString().ToDecimal() + Dim CveUM As Integer = RowUsado("CveUM").ToString().ToEntero() + + Dim CveVentaDetalle As Integer = -1 + If TmpDTDetalleFactura IsNot Nothing Then + CveVentaDetalle = TmpDTDetalleFactura.FiltroPrimeroValor("CveVentaDetalle", $"Cantidad = {RowUsado("Cantidad")} AND CvePS = {RowUsado("CvePS")}").ToEntero() + If CveVentaDetalle <= 0 Then + CveVentaDetalle = -1 + End If + End If + + If Not ObjInventario.AddMovimientoDetalle(CveMovimientoVirtual, CantidadUsado, CveUM, CvePS, PU, CveVentaDetalle:=CveVentaDetalle) Then + ErrorMovInv = True + TextoError.AppendFormat("Ocurrió un error al procesar los conceptos de traspaso de apartado. Por favor vuelva a intentar.") + Exit For + End If + TotalVirtual += (CantidadUsado * PU) + Next + 'insertar en prepóliza de la salida virtual + If Not ErrorMovInv Then + ErrorMovInv = Not GenerarPrePoliza(ObjInventario, ObjVentas, ObjConta, CveMovimientoVirtual, TextoError) + + End If + + Else + ErrorMovInv = True + End If + + Else + If ValidaVirtual Then + ErrorMovInv = True + TextoError.AppendFormat("Ocurrió un error al procesar el movimiento en almacen virtual. Por favor vuelva a intentar.") + + End If + End If + + If DtPSVirtual.Rows.Count = 0 AndAlso ValidaVirtual = True Then + ErrorMovInv = True + TextoError.AppendFormat("No se tienen productos para el almacen virtual.") + End If + End If + + ' TERMINA: VIRTUAL + + + 'AGREGA BITACORA A VENTA + If Not ErrorMovInv Then + Dim MensajeBitacora As String = If(TipoMovimiento = 1, "Surtida", "Devuelta") + Dim LigaVenta As String = String.Format("Venta {2} en Folio: {1}", CveMovimiento, Folio, MensajeBitacora) + + If Not ObjEventos.AddEventoBitacora(LigaVenta, "-1", UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa, CveVenta:=CveVentaSurtir, CveOS:=CveOSSurtir) Then + ErrorMovInv = True + End If + + End If + + 'Paqueterias guias + If RbEntregaInterna.Checked AndAlso Not ErrorMovInv Then + Dim CveEstatus As Integer = 1 ' DdlEstatus.SelectedValue.ToEntero() + Dim Fecha As String = NowADS().ToString() 'TxtFechaPaqInterna.Text + Dim FechaEstimada As String = "-1" 'If(TxtFechaEstimada.Text = "", "-1", TxtFechaEstimada.Text) + Dim NoCajas As Integer = 0 'TxtNoCajas.Text.ToEntero() + Dim Observaciones As String = "" 'TxtObservacionesPaqInterna.Text + Dim CvePaqueteria As Integer = GlobalDTPaqueterias(UsuarioActual.CveEmpresa, 0).FiltroPrimeroValor("CvePaqueteria", "").ToEntero() + + If CveSubProyecto > 0 Then + Dim CvePaqueteriaGuia As Integer = ObjGeneral.AddPaqueteriasGuias(CvePaqueteria, 9, CveEstatus, CveSubProyecto, Fecha, "", "", NoCajas, 0.00, "-1", FechaEstimada, Observaciones, UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa, EsEntregaInterna:=True) + + If CvePaqueteriaGuia > 0 Then + + If CveVentaSurtir > 0 OrElse CveSubProyecto > 0 Then + If Not ObjGeneral.AddPaqueteriasGuiasDetalles(CvePaqueteriaGuia, CveVentaSurtir, -1, CveMovimientoSalida, -1) Then + ''manda correo + ErrorMovInv = True + End If + End If + If ErrorMovInv Then + Alert("Error en el paqueteria guia detalle", TipoMensaje.MsgError) + End If + Else + ErrorMovInv = True + Alert("Error en el paqueteria guia", TipoMensaje.MsgError) + End If + Else + Alert("Hace falta indicar un Sub Proyecto", TipoMensaje.MsgAdvertencia) + ErrorMovInv = True + End If + ElseIf RbSinEntrega.Checked AndAlso Not ErrorMovInv Then + MandaCorreoEntrega(CveVentaSurtir) + End If + Catch ex As Exception + ErrorMovInv = True + OnError("Ocurrió un error al guardar", ex) + End Try + If Not ErrorMovInv AndAlso EsDevolucionVenta = 1 AndAlso CveOSSurtir > 0 AndAlso TipoMovimiento = 2 AndAlso TipoDocto = "Ped" Then If Not CierreOS(CveOSSurtir, CveMovimiento, ObjInventario.IniciaTransacSQL) Then ErrorMovInv = True Alert("Error al finalizar orden de servicio", TipoMensaje.MsgError) End If - End If - - 'SI YA FUE DEVUELTO LA CANTIDAD COMPLETA DE LA DEVOLUCION,MARCAR PARA QUE NO APAREZCA + End If + + 'SI YA FUE DEVUELTO LA CANTIDAD COMPLETA DE LA DEVOLUCION,MARCAR PARA QUE NO APAREZCA If Not ErrorMovInv AndAlso Cantidad.RoundSQL(6) = CantidadVenta.RoundSQL(6) AndAlso TipoDocto = "Dev" Then If Not ObjVentas.UpdateVentasDevolucionAlmacen(2, CveVentaSurtir) Then TextoError.AppendFormat("Ocurrió un error al actualizar la devolucion.") ErrorMovInv = True End If - End If - - If Not ErrorMovInv Then - - ObjInventario.Commit() - ObjGeneral.Dispose() - RegistraScript("playsonidito('beep-07.wav')") - Dim Msg As New StringBuilder - - Msg.AppendFormat("Movimiento {2}: {1}", CveMovimiento, Folio, If(TipoMovimiento = 1, "Salida", "Entrada")) - Msg.AppendFormat("
    Imprimir Movimiento ", Encripta(String.Format("OP=Alm&CveMovimiento={0}", CveMovimiento))) + End If + + If Not ErrorMovInv Then + + ObjInventario.Commit() + ObjGeneral.Dispose() + RegistraScript("playsonidito('beep-07.wav')") + Dim Msg As New StringBuilder + + Msg.AppendFormat("Movimiento {2}: {1}", CveMovimiento, Folio, If(TipoMovimiento = 1, "Salida", "Entrada")) + Msg.AppendFormat("
    Imprimir Movimiento ", Encripta(String.Format("OP=Alm&CveMovimiento={0}", CveMovimiento))) If Consola.Trim.Length > 0 Then Msg.AppendFormat("
    Consola ", Encripta(String.Format("OP=Alm&CveMovimiento={0}&Consola={1}", CveMovimiento, Consola))) - End If - - If CveMovimientoEntrada > 0 AndAlso Not UsuarioActual.Empresa.Funcionalidad(578).ToEntero = 1 Then - Msg.AppendFormat("

    Movimiento Entrada (Traspaso): {1}", CveMovimientoEntrada, FolioEntrada) - Msg.AppendFormat("
    Imprimir Movimiento ", Encripta(String.Format("OP=Alm&CveMovimiento={0}", CveMovimientoEntrada))) - End If - - If DtTraspasos.FiltraParametros("CveTipoAlmacen=9").Rows.Count > 0 Then - Msg.AppendFormat("

    Movimientos de Control (Apartados):") - For Each Dr As DataRow In DtTraspasos.Rows - Msg.AppendFormat("
    Almacén {0} | Salida por Traspaso: {2} | Entrada por Traspaso: {4} ", Dr("Almacen"), Dr("CveMovimientoSalida"), Dr("FolioSalida"), Dr("CveMovimientoEntrada"), Dr("FolioEntrada")) - Next - End If - - If DtTraspasos.FiltraParametros("CveTipoAlmacen=26").Rows.Count > 0 Then - Msg.AppendFormat("

    Movimientos de Control (Sin Costo):") - For Each Dr As DataRow In DtTraspasos.FiltraParametros("CveConceptoMovimientoSalida=40").Rows - Msg.AppendFormat("
    Almacén {0} | Salida directa de almacen: {2} ", Dr("Almacen"), Dr("CveMovimientoSalida"), Dr("FolioSalida"), Dr("CveMovimientoEntrada"), Dr("FolioEntrada")) - Next - For Each Dr As DataRow In DtTraspasos.FiltraParametros("CveConceptoMovimientoSalida=8").Rows - Msg.AppendFormat("
    Almacén {0} | Salida por Traspaso: {2} ", Dr("Almacen"), Dr("CveMovimientoSalida"), Dr("FolioSalida"), Dr("CveMovimientoEntrada"), Dr("FolioEntrada")) - Next - End If - - If DtDevSinCosto.Rows.Count > 0 Then - Msg.AppendFormat("

    Movimientos de Control (Sin Costo):") - For Each Dr As DataRow In DtDevSinCosto.Rows - Msg.AppendFormat("
    Almacén {0} | Devolución directa de almacen: {2} ", Dr("Almacen"), Dr("CveMovimientoEntrada"), Dr("FolioEntrada")) - Next - End If - - If CveMovimientoGarantia > 0 Then - Msg.AppendFormat("
    Movimiento de Entrada (garantías): {1}", CveMovimientoGarantia, FolioGarantia) - Msg.AppendFormat("
    Imprimir Movimiento ", Encripta(String.Format("OP=Alm&CveMovimiento={0}", CveMovimientoGarantia))) - End If - - If CveMovimientoVirtual > 0 Then - Msg.AppendFormat("

    {0} Almacen Virtual: ", If(TipoMovimiento = 1, "Salida", "Entrada")) - Msg.AppendFormat("{1}", CveMovimientoVirtual, FolioVirtual) - Msg.AppendFormat("
    Imprimir Movimiento ", Encripta(String.Format("OP=Alm&CveMovimiento={0}", CveMovimientoVirtual))) - End If - - If RbEntregaInterna.Checked Then - Msg.AppendFormat("

    Se agregó una guía de paquetería interna") - End If - - 'SI NO ES GARANTIA MANDA A RECIBIR AL USADO - If UsuarioActual.Empresa.Funcionalidad(531) = "1" AndAlso TipoDocto.Contiene("Rem", "Ped") AndAlso CveMovimientoGarantia <= 0 Then - Msg.AppendFormat("

    Recibir Usado: Ir a Recepción de Usados", CveVentaSurtir) End If - Alert(Msg.ToString(), TipoMensaje.MsgInformacion) - - Limpia() - CargaPendientes() - LimpiaCampos() - CargaBitacora = False - Else - ObjInventario.RollBack() - Alert(TextoError.ToString(), TipoMensaje.MsgError) - RegistraScript("playsonidito('142608__autistic-lucario__error.wav')") - End If - - ObjAcumuladores.Dispose() - ObjInventario.Dispose() - ObjConta.Dispose() - ObjVentas.Dispose() - ObjEventos.Dispose() - - End Sub - - Private Function GenerarPrePoliza(ByRef ObjInventario As ClsInventarios, ByRef ObjVentas As ClsVentas, ByRef ObjConta As ClsContabilidad, CveMovimiento As Integer, ByRef TextoError As StringBuilder) As Boolean - Dim ErrorMovInv As Boolean = False - Dim DtCostos As DataTable = Nothing - Dim ValorInventario As Decimal = 0 - If ObjInventario.GetMovimientosDetalle(CveMovimiento, UsuarioActual.CveEmpresa) Then - DtCostos = ObjInventario.DtResultados - - Dim tmpCostos As DataTable = DtCostos.FiltraParametros("", "", {"CveClasificacion"}) - If tmpCostos.Rows.Count > 0 Then - - If ObjVentas.GetVenta(CveVentaSurtir, UsuarioActual.CveEmpresa, False) Then - Dim Fecha As Date = TxtFecha.Text.ToDate ' If(TipoMovimiento <> 1, TxtFecha.Text.ToDate, ObjVentas.DtResultados(0)("Fecha").ToString().ToDate) - Dim CveCliente As Integer = ObjVentas.DtResultados(0)("CveCliente").ToString().ToEntero() - Dim ClienteNombre As String = ObjVentas.DtResultados(0)("ClienteNombre").ToString() - Dim Serie As String = ObjVentas.DtResultados(0)("SerieFolio").ToString() - Dim TotalCosto As Decimal = DtCostos.SUMD("Total").RoundSQL() - Dim TotalCostoAcumulado As Decimal = 0 - Dim cont As Integer = 1 - - Dim ValorMultiplicador As Decimal = 1 - - If TipoMovimiento = 1 Then - ValorMultiplicador = 1 - ElseIf TipoMovimiento = 2 AndAlso TipoDocto.Contiene({"Dev"}) AndAlso (EsDevolucionVenta = 1) Then - ValorMultiplicador = 1 - ElseIf TipoMovimiento = 2 Then - ValorMultiplicador = -1 - End If - - Dim CvePrePoliza As Integer = ObjConta.AddPrePolizas("Inventario/EntregaAlmacen", 4, TotalCosto, TotalCosto, 1, Fecha, ClienteNombre, UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa) - 'Se agrega movimiento separado por la cuenta de ventas (ER) - - If CvePrePoliza > 0 Then - - For Each RowInv As DataRow In tmpCostos.Rows - ValorInventario = DtCostos.SUMD("Total", $"CveClasificacion = {RowInv("CveClasificacion")}").RoundSQL() - TotalCostoAcumulado += ValorInventario - - 'cuando es el último movimiento y hay diferencias en los importes - If cont = DtCostos.FiltraParametros("", "", {"CveClasificacion"}).Rows.Count AndAlso TotalCosto <> TotalCostoAcumulado Then - ValorInventario = ValorInventario + (TotalCosto - TotalCostoAcumulado) + If CveMovimientoEntrada > 0 AndAlso Not UsuarioActual.Empresa.Funcionalidad(578).ToEntero = 1 Then + Msg.AppendFormat("

    Movimiento Entrada (Traspaso): {1}", CveMovimientoEntrada, FolioEntrada) + Msg.AppendFormat("
    Imprimir Movimiento ", Encripta(String.Format("OP=Alm&CveMovimiento={0}", CveMovimientoEntrada))) + End If + + If DtTraspasos.FiltraParametros("CveTipoAlmacen=9").Rows.Count > 0 Then + Msg.AppendFormat("

    Movimientos de Control (Apartados):") + For Each Dr As DataRow In DtTraspasos.Rows + Msg.AppendFormat("
    Almacén {0} | Salida por Traspaso: {2} | Entrada por Traspaso: {4} ", Dr("Almacen"), Dr("CveMovimientoSalida"), Dr("FolioSalida"), Dr("CveMovimientoEntrada"), Dr("FolioEntrada")) + Next + End If + + If DtTraspasos.FiltraParametros("CveTipoAlmacen=26").Rows.Count > 0 Then + Msg.AppendFormat("

    Movimientos de Control (Sin Costo):") + For Each Dr As DataRow In DtTraspasos.FiltraParametros("CveConceptoMovimientoSalida=40").Rows + Msg.AppendFormat("
    Almacén {0} | Salida directa de almacen: {2} ", Dr("Almacen"), Dr("CveMovimientoSalida"), Dr("FolioSalida"), Dr("CveMovimientoEntrada"), Dr("FolioEntrada")) + Next + For Each Dr As DataRow In DtTraspasos.FiltraParametros("CveConceptoMovimientoSalida=8").Rows + Msg.AppendFormat("
    Almacén {0} | Salida por Traspaso: {2} ", Dr("Almacen"), Dr("CveMovimientoSalida"), Dr("FolioSalida"), Dr("CveMovimientoEntrada"), Dr("FolioEntrada")) + Next + End If + + If DtDevSinCosto.Rows.Count > 0 Then + Msg.AppendFormat("

    Movimientos de Control (Sin Costo):") + For Each Dr As DataRow In DtDevSinCosto.Rows + Msg.AppendFormat("
    Almacén {0} | Devolución directa de almacen: {2} ", Dr("Almacen"), Dr("CveMovimientoEntrada"), Dr("FolioEntrada")) + Next + End If + + If CveMovimientoGarantia > 0 Then + Msg.AppendFormat("
    Movimiento de Entrada (garantías): {1}", CveMovimientoGarantia, FolioGarantia) + Msg.AppendFormat("
    Imprimir Movimiento ", Encripta(String.Format("OP=Alm&CveMovimiento={0}", CveMovimientoGarantia))) + End If + + If CveMovimientoVirtual > 0 Then + Msg.AppendFormat("

    {0} Almacen Virtual: ", If(TipoMovimiento = 1, "Salida", "Entrada")) + Msg.AppendFormat("{1}", CveMovimientoVirtual, FolioVirtual) + Msg.AppendFormat("
    Imprimir Movimiento ", Encripta(String.Format("OP=Alm&CveMovimiento={0}", CveMovimientoVirtual))) + End If + + If RbEntregaInterna.Checked Then + Msg.AppendFormat("

    Se agregó una guía de paquetería interna") + End If + + 'SI NO ES GARANTIA MANDA A RECIBIR AL USADO + If UsuarioActual.Empresa.Funcionalidad(531) = "1" AndAlso TipoDocto.Contiene("Rem", "Ped") AndAlso CveMovimientoGarantia <= 0 Then + Msg.AppendFormat("

    Recibir Usado: Ir a Recepción de Usados", CveVentaSurtir) + End If + + Alert(Msg.ToString(), TipoMensaje.MsgInformacion) + + Limpia() + CargaPendientes() + LimpiaCampos() + CargaBitacora = False + Else + ObjInventario.RollBack() + Alert(TextoError.ToString(), TipoMensaje.MsgError) + RegistraScript("playsonidito('142608__autistic-lucario__error.wav')") + End If + + ObjAcumuladores.Dispose() + ObjInventario.Dispose() + ObjConta.Dispose() + ObjVentas.Dispose() + ObjEventos.Dispose() + + End Sub + + Private Function GenerarPrePoliza(ByRef ObjInventario As ClsInventarios, ByRef ObjVentas As ClsVentas, ByRef ObjConta As ClsContabilidad, CveMovimiento As Integer, ByRef TextoError As StringBuilder) As Boolean + Dim ErrorMovInv As Boolean = False + Dim DtCostos As DataTable = Nothing + Dim ValorInventario As Decimal = 0 + If ObjInventario.GetMovimientosDetalle(CveMovimiento, UsuarioActual.CveEmpresa) Then + DtCostos = ObjInventario.DtResultados + + Dim tmpCostos As DataTable = DtCostos.FiltraParametros("", "", {"CveClasificacion"}) + If tmpCostos.Rows.Count > 0 Then + + If ObjVentas.GetVenta(CveVentaSurtir, UsuarioActual.CveEmpresa, False) Then + Dim Fecha As Date = TxtFecha.Text.ToDate ' If(TipoMovimiento <> 1, TxtFecha.Text.ToDate, ObjVentas.DtResultados(0)("Fecha").ToString().ToDate) + Dim CveCliente As Integer = ObjVentas.DtResultados(0)("CveCliente").ToString().ToEntero() + Dim ClienteNombre As String = ObjVentas.DtResultados(0)("ClienteNombre").ToString() + Dim Serie As String = ObjVentas.DtResultados(0)("SerieFolio").ToString() + Dim TotalCosto As Decimal = DtCostos.SUMD("Total").RoundSQL() + Dim TotalCostoAcumulado As Decimal = 0 + Dim cont As Integer = 1 + + Dim ValorMultiplicador As Decimal = 1 + + If TipoMovimiento = 1 Then + ValorMultiplicador = 1 + ElseIf TipoMovimiento = 2 AndAlso TipoDocto.Contiene({"Dev"}) AndAlso (EsDevolucionVenta = 1) Then + ValorMultiplicador = 1 + ElseIf TipoMovimiento = 2 Then + ValorMultiplicador = -1 + End If + + Dim CvePrePoliza As Integer = ObjConta.AddPrePolizas("Inventario/EntregaAlmacen", 4, TotalCosto, TotalCosto, 1, Fecha, ClienteNombre, UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa) + 'Se agrega movimiento separado por la cuenta de ventas (ER) + + If CvePrePoliza > 0 Then + + For Each RowInv As DataRow In tmpCostos.Rows + ValorInventario = DtCostos.SUMD("Total", $"CveClasificacion = {RowInv("CveClasificacion")}").RoundSQL() + TotalCostoAcumulado += ValorInventario + + 'cuando es el último movimiento y hay diferencias en los importes + If cont = DtCostos.FiltraParametros("", "", {"CveClasificacion"}).Rows.Count AndAlso TotalCosto <> TotalCostoAcumulado Then + ValorInventario = ValorInventario + (TotalCosto - TotalCostoAcumulado) End If - If Not ErrorMovInv Then - If Not ObjConta.AddPrePolizasDetalle(CvePrePoliza, False, ValorMultiplicador * ValorInventario, ValorMultiplicador * ValorInventario, 69, Serie, Serie, CveVenta:=CveVentaSurtir, CveCliente:=CveCliente, CveMovimientoAlmacen:=CveMovimiento, CveSubProyecto:=CveSubProyecto, CveClasificacion:=RowInv("CveClasificacion").ToString().ToEntero()) Then - ErrorMovInv = True - End If - End If - - cont += 1 - Next - Dim tCveSubProyectoAlmacen As Integer = GlobalDTAlmacen(UsuarioActual.CveEmpresa, CveAlmacen:=DdlAlmacen.SelectedValue.ToEntero).FiltroPrimeroValor("CveSubProyecto").ToEntero() - If Not ObjConta.AddPrePolizasDetalle(CvePrePoliza, True, ValorMultiplicador * TotalCosto, ValorMultiplicador * TotalCosto, 68, Serie, Serie, CveVenta:=CveVentaSurtir, CveCliente:=CveCliente, CveMovimientoAlmacen:=CveMovimiento, CveSubProyecto:=tCveSubProyectoAlmacen) Then - ErrorMovInv = True - End If - - If Not ErrorMovInv AndAlso ObjConta.ValidacionesPrePoliza(CvePrePoliza, UsuarioActual) Then - If ObjConta.ValorPolizaDescuadre > 0 Then - GuardaLogAD($"Inventario/EntregaAlmacen | Error{ObjConta.MensajePolizaDescuadre} Diferencia{ObjConta.ValorDiferencia} | CvePrePoliza:{CvePrePoliza}", "LogPrePolizas") - ErrorMovInv = True - End If + If Not ErrorMovInv Then + If Not ObjConta.AddPrePolizasDetalle(CvePrePoliza, False, ValorMultiplicador * ValorInventario, ValorMultiplicador * ValorInventario, 69, Serie, Serie, CveVenta:=CveVentaSurtir, CveCliente:=CveCliente, CveMovimientoAlmacen:=CveMovimiento, CveSubProyecto:=CveSubProyecto, CveClasificacion:=RowInv("CveClasificacion").ToString().ToEntero()) Then + ErrorMovInv = True + End If + End If + + cont += 1 + Next + Dim tCveSubProyectoAlmacen As Integer = GlobalDTAlmacen(UsuarioActual.CveEmpresa, CveAlmacen:=DdlAlmacen.SelectedValue.ToEntero).FiltroPrimeroValor("CveSubProyecto").ToEntero() + If Not ObjConta.AddPrePolizasDetalle(CvePrePoliza, True, ValorMultiplicador * TotalCosto, ValorMultiplicador * TotalCosto, 68, Serie, Serie, CveVenta:=CveVentaSurtir, CveCliente:=CveCliente, CveMovimientoAlmacen:=CveMovimiento, CveSubProyecto:=tCveSubProyectoAlmacen) Then + ErrorMovInv = True End If - Else - ErrorMovInv = True - TextoError.AppendFormat("Ocurrió un Error al ingresar la prepoliza.1") - End If - Else - ErrorMovInv = True - TextoError.AppendFormat("Ocurrió un Error al ingresar las prepolizas.2") - End If - Else - ErrorMovInv = True - TextoError.AppendFormat("Ocurrió un Error al ingresar las prepolizas.3") - End If - Else - ErrorMovInv = True - TextoError.AppendFormat("Ocurrió un Error al ingresar las prepolizas.4") - End If - - Return Not ErrorMovInv - End Function - - Private Sub GuardaTraspaso() - - 'OBLIGA A SURTIR TODO - For Each Gvr As GridViewRow In GvDatos.Rows - If Not Gvr.FCCheckBox("cbInv").Checked Or (Gvr.FCCheckBox("cbInv").Checked AndAlso Gvr.FCTextBox("TbCantidadF").Text.ToDecimal <> Gvr.DataKey("CantidadC").ToString().ToDecimal) Then - Alert("Es necesario surtir todos los productos. Por favor rectifique y vuelva a intentar.", TipoMensaje.MsgAdvertencia) - RegistraScript("playsonidito('142608__autistic-lucario__error.wav')") - Exit Sub - End If - Next - - Dim ValidaSeccion As Boolean = False : Dim ValidaCaducidad As Boolean = False : Dim ValidaLote As Boolean = False - 'VALIDA CANTIDAD DE SALIDA - Dim Cantidad As Decimal = 0.0D - For Each Gvr As GridViewRow In GvDatos.Rows - If CBool(Gvr.DataKey("AplicaSeccion")) AndAlso Gvr.FCDropDownList("DdlSeccionAlmacen").SelectedValue.ToEntero() <= 0 Then - ValidaSeccion = True - End If - If CBool(Gvr.DataKey("AplicaCaducidad")) AndAlso Gvr.FCTextBox("TxtCaducidad").Text.Trim = "" Then - ValidaCaducidad = True - End If - If CBool(Gvr.DataKey("AplicaLote")) AndAlso Gvr.FCTextBox("TxtLote").Text.Trim = "" Then - ValidaLote = True - End If - - If Gvr.FCCheckBox("cbInv").Checked AndAlso Gvr.FCTextBox("TbCantidadF").Text.ToDecimal > 0 Then - Cantidad = Gvr.FCTextBox("TbCantidadF").Text.ToDecimal - Exit For - End If - Next - - If ValidaSeccion Then - Alert("La sección de almacen no ha sido especificada en todos los productos.", TipoMensaje.MsgAdvertencia) - Exit Sub - End If - If ValidaCaducidad Then - Alert("La caducidad no ha sido especificada en todos los productos.", TipoMensaje.MsgAdvertencia) - Exit Sub - End If - If ValidaLote Then - Alert("El lote de almacen no ha sido especificada en todos los productos.", TipoMensaje.MsgAdvertencia) - Exit Sub - End If - - 'VALIDA TRANSITORIO - If ChkTransitorio.Checked Then - If TxtResponsable.Text.Trim = "" Then - Alert("Debe seleccionar un responsable para el traspaso transitorio.", TipoMensaje.MsgAdvertencia) - RegistraScript("playsonidito(''142608__autistic-lucario__error.wav'')") - If ChkTransitorio.Checked Then RegistraScript("$('#DivTransitorio').show(200);") - Exit Sub - End If - - If DdlAlmacenTransitorio.SelectedValue.ToEntero() <= 0 Then - Alert("Debe seleccionar un almacen transitorio.", TipoMensaje.MsgAdvertencia) - RegistraScript("playsonidito(''142608__autistic-lucario__error.wav'')") - If ChkTransitorio.Checked Then RegistraScript("$('#DivTransitorio').show(200);") - Exit Sub - End If - End If - - Dim ObjInventario As New ClsInventarios : ObjInventario.IniciaTransacSQL() - Dim ObjGeneral As New ClsGenerales(ObjInventario.IniciaTransacSQL()) - Dim ObjConta As New ClsContabilidad(ObjInventario.IniciaTransacSQL()) - Dim CveMovimientoSalida As Integer - Dim ConceptoMovimiento As Integer = 0 - Dim FolioSalida As Integer - Dim CveMovimientoEntrada As Integer - Dim FolioEntrada As Integer - Dim ErrorMovInv As Boolean - Dim DtDetalle As New DataTable - Dim TextoError As String = "" - - 'PASA DATOS DEL GV A DATATABLE PARA MANEJOR CON FOR EACH - Dim Index As Integer = 0 - For Each gvr As GridViewRow In GvDatos.Rows - If gvr.FCCheckBox("cbInv").Checked AndAlso gvr.FCTextBox("TbCantidadF").Text.ToDecimal > 0 Then - DtDatos.Rows(Index)("CantidadGV") = gvr.FCTextBox("TbCantidadF").Text.ToDecimal - DtDatos.Rows(Index)("CveSeccion") = gvr.FCDropDownList("DdlSeccionAlmacen").SelectedValue.ToEntero() - DtDatos.Rows(Index)("FechaCaducidad") = gvr.FCTextBox("TxtCaducidad").Text.ToDate - DtDatos.Rows(Index)("Lote") = gvr.FCTextBox("TxtLote").Text - End If - Index += 1 - Next - - 'VALIDA SI HUBO CAMBIOS EN LA EXISTENCIA - Dim DtDatosTraspaso As New DataTable - If ObjInventario.EntregaAlmacenTraspasosGet(CveTraspasoSurtir) Then - DtDatosTraspaso = ObjInventario.DtResultados - End If - Dim CantidadGV As Decimal = GvDatos.Rows.Cast(Of GridViewRow)().Sum(Function(gvr) gvr.DataKey("CantidadF").ToDecimal) - If DtDatos.SUM("CantidadF") <> DtDatosTraspaso.SUM("CantidadF") Then - ObjInventario.RollBack() - ObjInventario.Dispose() - CargaTraspasoPorSurtir(CveTraspasoSurtir) - CargaPendientes() - Alert("Ha sido cambiada la informacion de existencias del traspaso actual. Por favor verifique.", TipoMensaje.MsgAdvertencia) - Exit Sub - End If - - 'VALIDA QUE EL TRASPASO SIGA VIGENTE - If ObjInventario.AddTrasladoSolicitudGet(CveTraspasoSurtir, UsuarioActual.CveEmpresa) AndAlso ObjInventario.DtResultados.Rows.Count > 0 AndAlso ObjInventario.DtResultados.Rows(0)("CveTrasladoEstatus").ToString() = "2" Then - ObjInventario.RollBack() - ObjInventario.Dispose() - CargaTraspasoPorSurtir(CveTraspasoSurtir) - CargaPendientes() - Alert("Ha sido cambiada la informacion del traspaso actual. Por favor verifique.", TipoMensaje.MsgAdvertencia) - Exit Sub - End If - - 'VALIDA ALMACENES - Dim Almacen1 As Integer = DdlAlmacen.SelectedValue.ToEntero() - Dim Almacen2 As Integer = CveAlmacenTraspasoDestino - If Almacen1 <= 0 Or Almacen2 <= 0 Then - Alert("Ocurrió un error al obtener los almacenes del movimiento. Por favor recargue y vuelva a intentar.", TipoMensaje.MsgAdvertencia) - ObjInventario.RollBack() - ObjInventario.Dispose() - Exit Sub - End If - - 'VERIFICAR EXISTENCIA - Dim StrXML As New StringBuilder - Dim Lote As String = "" - Dim FechaCaducidad As Date - StrXML.Append("") - For Each Dr As DataRow In DtDatos.Rows - FechaCaducidad = If(CBool(Dr("AplicaCaducidad")) AndAlso Dr("FechaCaducidad").ToString() <> "", Dr("FechaCaducidad").ToString().ToDate, MinFecha) - Lote = If(CBool(Dr("AplicaLote")), Dr("Lote").ToString(), "-1") - - If Dr("CantidadGV").ToString().ToDecimal > 0 Then - If CBool(Dr("AplicaSerie")) Then - DtDetalle = DtDatosDetalle.FiltraParametros(String.Format("ConsecId = {0}", Dr("Consec"))) - For Each Dr1 As DataRow In DtDetalle.Rows - StrXML.AppendFormat("", Dr1("CvePS"), Dr1("CveUM"), 1, IfNull(Dr("CveSeccion"), -1), Dr1("Serie"), Lote, FechaCaducidad.ToString("yyyy/MM/dd")) - Next - Else - StrXML.AppendFormat("", Dr("CvePS"), Dr("CveUM"), Dr("CantidadGV"), IfNull(Dr("CveSeccion"), -1), "-1", Lote, FechaCaducidad.ToString("yyyy/MM/dd")) - End If - End If - Next - StrXML.Append("") - - Dim TieneErrorExistencia As Boolean = False - If ObjInventario.GetExistenciasPSXML(StrXML.ToString(), DdlAlmacen.SelectedValue.ToEntero(), TxtFecha.Text.ToDateTime.ToString("yyyy/MM/dd HH:mm"), CveSubProyecto, CveVendedor, If(UsuarioActual.Empresa.Funcionalidad(146) = "1", -1, CveCliente), If(TipoEntrega = 2, 1, -1), UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa) Then - If ObjInventario.DtResultados.Rows.Count > 0 Then - TieneErrorExistencia = True - For Each Dr As DataRow In ObjInventario.DtResultados.Rows - TextoError += $" - {Dr("CodigoPS")} Existencia: {Dr("Existencia").ToString().ToDecimal.ToString("#,##0.##")}
    " - Next - End If - Else - TieneErrorExistencia = True - End If - - If TieneErrorExistencia Then - ObjInventario.RollBack() - ObjInventario.Dispose() - If TextoError.Length > 0 Then - Alert($" Lo(s) siguiente(s) Productos no tienen existencia suficiente:

    {TextoError}", TipoMensaje.MsgAdvertencia) - End If - RegistraScript("playsonidito('142608__autistic-lucario__error.wav')") - Exit Sub - End If - - 'SALIDA POR TRASPASO - If Not ErrorMovInv Then - ConceptoMovimiento = 26 - CveMovimientoSalida = ObjInventario.AddMovimiento(Almacen1, ConceptoMovimiento, 1, TxtFecha.Text.ToDate, -1, UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa, -1, -1, -1, -1, Observaciones:=TxtObservaciones.Text.Trim, Guia:="", - CveContrato:=-1, CveAlmacenDestino:=CveAlmacenTraspasoDestino, Recibio:=If(ChkTransitorio.Checked, TxtResponsable.Text.Trim, ""), Modulo:="RE/GT", CveOP:=CveOP) - FolioSalida = ObjInventario.Folio - If CveMovimientoSalida > 0 Then - Dim CantidadPendiente As Decimal = 0 - Dim CveSeccionAlmacen As Integer = -1 - - For Each Dr As DataRow In DtDatos.Rows - + + If Not ErrorMovInv AndAlso ObjConta.ValidacionesPrePoliza(CvePrePoliza, UsuarioActual) Then + If ObjConta.ValorPolizaDescuadre > 0 Then + GuardaLogAD($"Inventario/EntregaAlmacen | Error{ObjConta.MensajePolizaDescuadre} Diferencia{ObjConta.ValorDiferencia} | CvePrePoliza:{CvePrePoliza}", "LogPrePolizas") + ErrorMovInv = True + End If + End If + Else + ErrorMovInv = True + TextoError.AppendFormat("Ocurrió un Error al ingresar la prepoliza.1") + End If + Else + ErrorMovInv = True + TextoError.AppendFormat("Ocurrió un Error al ingresar las prepolizas.2") + End If + Else + ErrorMovInv = True + TextoError.AppendFormat("Ocurrió un Error al ingresar las prepolizas.3") + End If + Else + ErrorMovInv = True + TextoError.AppendFormat("Ocurrió un Error al ingresar las prepolizas.4") + End If + + Return Not ErrorMovInv + End Function + + Private Sub GuardaTraspaso() + + 'OBLIGA A SURTIR TODO + For Each Gvr As GridViewRow In GvDatos.Rows + If Not Gvr.FCCheckBox("cbInv").Checked Or (Gvr.FCCheckBox("cbInv").Checked AndAlso Gvr.FCTextBox("TbCantidadF").Text.ToDecimal <> Gvr.DataKey("CantidadC").ToString().ToDecimal) Then + Alert("Es necesario surtir todos los productos. Por favor rectifique y vuelva a intentar.", TipoMensaje.MsgAdvertencia) + RegistraScript("playsonidito('142608__autistic-lucario__error.wav')") + Exit Sub + End If + Next + + Dim ValidaSeccion As Boolean = False : Dim ValidaCaducidad As Boolean = False : Dim ValidaLote As Boolean = False + 'VALIDA CANTIDAD DE SALIDA + Dim Cantidad As Decimal = 0.0D + For Each Gvr As GridViewRow In GvDatos.Rows + If CBool(Gvr.DataKey("AplicaSeccion")) AndAlso Gvr.FCDropDownList("DdlSeccionAlmacen").SelectedValue.ToEntero() <= 0 Then + ValidaSeccion = True + End If + If CBool(Gvr.DataKey("AplicaCaducidad")) AndAlso Gvr.FCTextBox("TxtCaducidad").Text.Trim = "" Then + ValidaCaducidad = True + End If + If CBool(Gvr.DataKey("AplicaLote")) AndAlso Gvr.FCTextBox("TxtLote").Text.Trim = "" Then + ValidaLote = True + End If + + If Gvr.FCCheckBox("cbInv").Checked AndAlso Gvr.FCTextBox("TbCantidadF").Text.ToDecimal > 0 Then + Cantidad = Gvr.FCTextBox("TbCantidadF").Text.ToDecimal + Exit For + End If + Next + + If ValidaSeccion Then + Alert("La sección de almacen no ha sido especificada en todos los productos.", TipoMensaje.MsgAdvertencia) + Exit Sub + End If + If ValidaCaducidad Then + Alert("La caducidad no ha sido especificada en todos los productos.", TipoMensaje.MsgAdvertencia) + Exit Sub + End If + If ValidaLote Then + Alert("El lote de almacen no ha sido especificada en todos los productos.", TipoMensaje.MsgAdvertencia) + Exit Sub + End If + + 'VALIDA TRANSITORIO + If ChkTransitorio.Checked Then + If TxtResponsable.Text.Trim = "" Then + Alert("Debe seleccionar un responsable para el traspaso transitorio.", TipoMensaje.MsgAdvertencia) + RegistraScript("playsonidito(''142608__autistic-lucario__error.wav'')") + If ChkTransitorio.Checked Then RegistraScript("$('#DivTransitorio').show(200);") + Exit Sub + End If + + If DdlAlmacenTransitorio.SelectedValue.ToEntero() <= 0 Then + Alert("Debe seleccionar un almacen transitorio.", TipoMensaje.MsgAdvertencia) + RegistraScript("playsonidito(''142608__autistic-lucario__error.wav'')") + If ChkTransitorio.Checked Then RegistraScript("$('#DivTransitorio').show(200);") + Exit Sub + End If + End If + + Dim ObjInventario As New ClsInventarios : ObjInventario.IniciaTransacSQL() + Dim ObjGeneral As New ClsGenerales(ObjInventario.IniciaTransacSQL()) + Dim ObjConta As New ClsContabilidad(ObjInventario.IniciaTransacSQL()) + Dim CveMovimientoSalida As Integer + Dim ConceptoMovimiento As Integer = 0 + Dim FolioSalida As Integer + Dim CveMovimientoEntrada As Integer + Dim FolioEntrada As Integer + Dim ErrorMovInv As Boolean + Dim DtDetalle As New DataTable + Dim TextoError As String = "" + + 'PASA DATOS DEL GV A DATATABLE PARA MANEJOR CON FOR EACH + Dim Index As Integer = 0 + For Each gvr As GridViewRow In GvDatos.Rows + If gvr.FCCheckBox("cbInv").Checked AndAlso gvr.FCTextBox("TbCantidadF").Text.ToDecimal > 0 Then + DtDatos.Rows(Index)("CantidadGV") = gvr.FCTextBox("TbCantidadF").Text.ToDecimal + DtDatos.Rows(Index)("CveSeccion") = gvr.FCDropDownList("DdlSeccionAlmacen").SelectedValue.ToEntero() + DtDatos.Rows(Index)("FechaCaducidad") = gvr.FCTextBox("TxtCaducidad").Text.ToDate + DtDatos.Rows(Index)("Lote") = gvr.FCTextBox("TxtLote").Text + End If + Index += 1 + Next + + 'VALIDA SI HUBO CAMBIOS EN LA EXISTENCIA + Dim DtDatosTraspaso As New DataTable + If ObjInventario.EntregaAlmacenTraspasosGet(CveTraspasoSurtir) Then + DtDatosTraspaso = ObjInventario.DtResultados + End If + Dim CantidadGV As Decimal = GvDatos.Rows.Cast(Of GridViewRow)().Sum(Function(gvr) gvr.DataKey("CantidadF").ToDecimal) + If DtDatos.SUM("CantidadF") <> DtDatosTraspaso.SUM("CantidadF") Then + ObjInventario.RollBack() + ObjInventario.Dispose() + CargaTraspasoPorSurtir(CveTraspasoSurtir) + CargaPendientes() + Alert("Ha sido cambiada la informacion de existencias del traspaso actual. Por favor verifique.", TipoMensaje.MsgAdvertencia) + Exit Sub + End If + + 'VALIDA QUE EL TRASPASO SIGA VIGENTE + If ObjInventario.AddTrasladoSolicitudGet(CveTraspasoSurtir, UsuarioActual.CveEmpresa) AndAlso ObjInventario.DtResultados.Rows.Count > 0 AndAlso ObjInventario.DtResultados.Rows(0)("CveTrasladoEstatus").ToString() = "2" Then + ObjInventario.RollBack() + ObjInventario.Dispose() + CargaTraspasoPorSurtir(CveTraspasoSurtir) + CargaPendientes() + Alert("Ha sido cambiada la informacion del traspaso actual. Por favor verifique.", TipoMensaje.MsgAdvertencia) + Exit Sub + End If + + 'VALIDA ALMACENES + Dim Almacen1 As Integer = DdlAlmacen.SelectedValue.ToEntero() + Dim Almacen2 As Integer = CveAlmacenTraspasoDestino + If Almacen1 <= 0 Or Almacen2 <= 0 Then + Alert("Ocurrió un error al obtener los almacenes del movimiento. Por favor recargue y vuelva a intentar.", TipoMensaje.MsgAdvertencia) + ObjInventario.RollBack() + ObjInventario.Dispose() + Exit Sub + End If + + 'VERIFICAR EXISTENCIA + Dim StrXML As New StringBuilder + Dim Lote As String = "" + Dim FechaCaducidad As Date + StrXML.Append("") + For Each Dr As DataRow In DtDatos.Rows + FechaCaducidad = If(CBool(Dr("AplicaCaducidad")) AndAlso Dr("FechaCaducidad").ToString() <> "", Dr("FechaCaducidad").ToString().ToDate, MinFecha) + Lote = If(CBool(Dr("AplicaLote")), Dr("Lote").ToString(), "-1") + + If Dr("CantidadGV").ToString().ToDecimal > 0 Then + If CBool(Dr("AplicaSerie")) Then + DtDetalle = DtDatosDetalle.FiltraParametros(String.Format("ConsecId = {0}", Dr("Consec"))) + For Each Dr1 As DataRow In DtDetalle.Rows + StrXML.AppendFormat("", Dr1("CvePS"), Dr1("CveUM"), 1, IfNull(Dr("CveSeccion"), -1), Dr1("Serie"), Lote, FechaCaducidad.ToString("yyyy/MM/dd")) + Next + Else + StrXML.AppendFormat("", Dr("CvePS"), Dr("CveUM"), Dr("CantidadGV"), IfNull(Dr("CveSeccion"), -1), "-1", Lote, FechaCaducidad.ToString("yyyy/MM/dd")) + End If + End If + Next + StrXML.Append("") + + Dim TieneErrorExistencia As Boolean = False + If ObjInventario.GetExistenciasPSXML(StrXML.ToString(), DdlAlmacen.SelectedValue.ToEntero(), TxtFecha.Text.ToDateTime.ToString("yyyy/MM/dd HH:mm"), CveSubProyecto, CveVendedor, If(UsuarioActual.Empresa.Funcionalidad(146) = "1", -1, CveCliente), If(TipoEntrega = 2, 1, -1), UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa) Then + If ObjInventario.DtResultados.Rows.Count > 0 Then + TieneErrorExistencia = True + For Each Dr As DataRow In ObjInventario.DtResultados.Rows + TextoError += $" - {Dr("CodigoPS")} Existencia: {Dr("Existencia").ToString().ToDecimal.ToString("#,##0.##")}
    " + Next + End If + Else + TieneErrorExistencia = True + End If + + If TieneErrorExistencia Then + ObjInventario.RollBack() + ObjInventario.Dispose() + If TextoError.Length > 0 Then + Alert($" Lo(s) siguiente(s) Productos no tienen existencia suficiente:

    {TextoError}", TipoMensaje.MsgAdvertencia) + End If + RegistraScript("playsonidito('142608__autistic-lucario__error.wav')") + Exit Sub + End If + + 'SALIDA POR TRASPASO + If Not ErrorMovInv Then + ConceptoMovimiento = 26 + CveMovimientoSalida = ObjInventario.AddMovimiento(Almacen1, ConceptoMovimiento, 1, TxtFecha.Text.ToDate, -1, UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa, -1, -1, -1, -1, Observaciones:=TxtObservaciones.Text.Trim, Guia:="", + CveContrato:=-1, CveAlmacenDestino:=CveAlmacenTraspasoDestino, Recibio:=If(ChkTransitorio.Checked, TxtResponsable.Text.Trim, ""), Modulo:="RE/GT", CveOP:=CveOP) + FolioSalida = ObjInventario.Folio + If CveMovimientoSalida > 0 Then + Dim CantidadPendiente As Decimal = 0 + Dim CveSeccionAlmacen As Integer = -1 + + For Each Dr As DataRow In DtDatos.Rows + If ErrorMovInv Then Exit For - End If - - FechaCaducidad = If(CBool(Dr("AplicaCaducidad")) AndAlso Dr("FechaCaducidad").ToString() <> "", Dr("FechaCaducidad").ToString().ToDate, MinFecha) - Lote = If(CBool(Dr("AplicaLote")), Dr("Lote").ToString(), "-1") - CveSeccionAlmacen = If(CBool(Dr("AplicaSeccion")), Dr("CveSeccion").ToString().ToEntero(), -1) - - DtDetalle = DtDatosDetalle.FiltraParametros(String.Format("ConsecId = {0} AND FueTraspaso IS NULL", Dr("Consec"))) - 'DtDetalleLote = DtDatosDetalleLote.FiltraParametros(String.Format("ConsecId = {0} AND FueTraspaso IS NULL", Dr("Consec"))) - If DtDetalle.Rows.Count > 0 Then 'SI FUE POR SERIE - For Each Dr1 As DataRow In DtDetalle.Rows - If Not ObjInventario.AddMovimientoDetalle(CveMovimientoSalida, 1, Dr("CveUM").ToString().ToEntero(), Dr("CvePS").ToString().ToEntero(), 0, Serie:=Dr1("Serie").ToString(), Lote:=Lote, FechaCaducidad:=FechaCaducidad, CveSeccionAlmacen:=CveSeccionAlmacen, CveVentaDetalle:=-1, CveContratoDetalle:=Dr("CveContratoDetalle").ToString().ToEntero()) Then - ErrorMovInv = True - TextoError = $"Ocurrió un error al procesar los conceptos con serie '{Dr1("Serie").ToString()}'. Por favor vuelva a intentar." - Exit For - End If - Next - 'ElseIf DtDetalleLote.Rows.Count > 0 Then 'SI FUE POR LOTE BATCH - ' For Each Dr1 As DataRow In DtDetalleLote.Rows - ' If Not ObjInventario.AddMovimientoDetalle(CveMovimientoSalida, Dr1("Cantidad").ToString().ToDecimal, Dr("CveUM").ToString().ToEntero(), Dr("CvePS").ToString().ToEntero(), 0, Serie:="", Lote:=Dr1("Lote").ToString(), FechaCaducidad:=FechaCaducidad, CveSeccionAlmacen:=CveSeccionAlmacen, CveVentaDetalle:=-1, CveContratoDetalle:=Dr("CveContratoDetalle").ToString().ToEntero()) Then - ' ErrorMovInv = True - ' TextoError = "Ocurrió un error al procesar los conceptos con serie. Por favor vuelva a intentar." - ' Exit For - ' End If - ' Next - Else 'NORMAL - If Not ObjInventario.AddMovimientoDetalle(CveMovimientoSalida, Dr("CantidadGV").ToString().ToDecimal, Dr("CveUM").ToString().ToEntero(), Dr("CvePS").ToString().ToEntero(), 0, -1, Lote:=Lote, FechaCaducidad:=FechaCaducidad, CveSeccionAlmacen:=CveSeccionAlmacen, CveContratoDetalle:=Dr("CveContratoDetalle").ToString().ToEntero()) Then - ErrorMovInv = True - TextoError = "Ocurrió un error al procesar los conceptos de salida. Por favor vuelva a intentar." - Exit For - End If - End If - Next - Else - TextoError = "Ocurrió un error al generar el movimiento de salida." - ErrorMovInv = True - End If - End If - - Dim ValorTraspaso As Decimal = 0 - 'ENTRADA POR TRASPASO - If Not ErrorMovInv Then - 'sino es transitorio, los transitorios, ya no se hace otro movimiento - - ConceptoMovimiento = If(ChkTransitorio.Checked, 2, 27) - Almacen2 = If(ChkTransitorio.Checked, DdlAlmacenTransitorio.SelectedValue.ToEntero(), CveAlmacenTraspasoDestino) - CveMovimientoEntrada = ObjInventario.AddMovimiento(Almacen2, ConceptoMovimiento, 1, TxtFecha.Text.ToDate, -1, UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa, -1, -1, -1, -1, Observaciones:=TxtObservaciones.Text.Trim, - Guia:="", CveContrato:=CveContrato, CveMovimientoRelacionado:=CveMovimientoSalida, CveAlmacenDestino:=CveAlmacenTraspasoDestino, - Recibio:=If(ChkTransitorio.Checked, TxtResponsable.Text.Trim, ""), Modulo:="RE/GT1", CveOP:=CveOP) - FolioEntrada = ObjInventario.Folio - If CveMovimientoEntrada > 0 Then - If ObjInventario.GetMovimientosDetalle(CveMovimientoSalida, UsuarioActual.CveEmpresa) Then - Dim CveSeccionAlmacen As Integer = -1 - ValorTraspaso = ObjInventario.DtResultados.SUMD("Total").RoundSQL - For Each Dr As DataRow In ObjInventario.DtResultados.Rows - - CveSeccionAlmacen = -3 - - If Not ObjInventario.AddMovimientoDetalle(CveMovimientoEntrada, Dr("Cantidad").ToString().ToDecimal, Dr("CveUM").ToString().ToEntero(), Dr("CvePS").ToString().ToEntero(), Dr("PU").ToString().ToDecimal, CveAF:=Dr("CveAF").ToString().ToEntero(), CveSeccionAlmacen:=CveSeccionAlmacen, Serie:=Dr("Serie").ToString(), Lote:=Dr("Lote").ToString(), FechaCaducidad:=Dr("FechaCaducidad").ToString().ToDate, CveMovimientoDetalleEntrada:=Dr("CveMovimientoDetalle").ToString().ToEntero(), CveVentaDetalle:=Dr("CveVentaDetalle").ToString().ToEntero()) Then - ErrorMovInv = True - TextoError = "Ocurrió un error al guardar los movimientos de entrada" - Exit For - End If - Next - End If - Else - TextoError = "Ocurrió un error al generar el movimiento de entrada" - ErrorMovInv = True - End If - - End If - - 'MARCA SOLICITUD CON EL MOVIMIENTO GENERADO - If Not ErrorMovInv Then - If Not ObjInventario.UpdateTraspasoSolicitudMovimiento(CveTraspasoSurtir, CveMovimientoSalida) Then - TextoError = "Ocurrió un error al vincular los movimientos con la solicitud de traspaso. Por favor verifique y vuelva a intentar" - ErrorMovInv = True - End If - End If - - Dim Fecha As Date = TxtFecha.Text.ToDate - 'Paqueterias Guias - If RbEntregaInterna.Checked AndAlso Not ErrorMovInv Then - Dim CveEstatus As Integer = 0 ' DdlEstatus.SelectedValue.ToEntero() - Dim FechaEstimada As String = "-1" 'If(TxtFechaEstimada.Text = "", "-1", TxtFechaEstimada.Text) - Dim NoCajas As Integer = 0 'TxtNoCajas.Text.ToEntero() - Dim Observaciones As String = "" 'TxtObservacionesPaqInterna.Text - Dim CvePaqueteria As Integer = GlobalDTPaqueterias(UsuarioActual.CveEmpresa, 0).FiltroPrimeroValor("CvePaqueteria", "").ToEntero() - - Dim CvePaqueteriaGuia As Integer = ObjGeneral.AddPaqueteriasGuias(CvePaqueteria, 9, CveEstatus, CveSubProyecto, Fecha.ToShortDateString, "-1", "-1", NoCajas, 0.00, "-1", FechaEstimada, Observaciones, UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa, EsEntregaInterna:=True) - - If CvePaqueteriaGuia > 0 Then - If CveVentaSurtir > 0 OrElse CveSubProyecto > 0 Then - ErrorMovInv = Not ObjGeneral.AddPaqueteriasGuiasDetalles(CvePaqueteriaGuia, CveVentaSurtir, -1, CveMovimientoEntrada, -1) - End If - - If ErrorMovInv Then - Alert("Error en el paqueteria guia detalle", TipoMensaje.MsgError) - End If - Else - ErrorMovInv = True - Alert("Error en el paqueteria guia", TipoMensaje.MsgError) - End If - End If - - 'AGREGAMOS PREPOLIZAS TRASPASO DIRECTO: - - Dim CvePrePolizaTraspaso As Integer = ObjConta.AddPrePolizas("EA/GT", 53, 0, 0, 1, Fecha, "Traspaso", UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa) - If CvePrePolizaTraspaso > 0 Then - - - If Not ObjConta.AddPrePolizasDetalle(CvePrePolizaTraspaso, True, ValorTraspaso, ValorTraspaso, 68, TxtObservaciones.Text, TxtObservaciones.Text, CveMovimientoAlmacen:=CveMovimientoSalida, Contabilizable:=False) Then - ErrorMovInv = True - End If - - If Not ErrorMovInv AndAlso Not ObjConta.AddPrePolizasDetalle(CvePrePolizaTraspaso, False, ValorTraspaso, ValorTraspaso, 68, TxtObservaciones.Text, TxtObservaciones.Text, CveMovimientoAlmacen:=CveMovimientoEntrada, Contabilizable:=False) Then - ErrorMovInv = True - End If - Else - ErrorMovInv = True - End If - - - If Not ErrorMovInv Then - ObjInventario.Commit() - ObjGeneral.Dispose() - RegistraScript("playsonidito('beep-07.wav')") - - Dim Msg As New StringBuilder - Msg.AppendFormat("Movimiento Salida: {1}", CveMovimientoSalida, FolioSalida) - Msg.AppendFormat("
    Imprimir Movimiento ", Encripta(String.Format("OP=Alm&CveMovimiento={0}", CveMovimientoSalida))) - - Msg.AppendFormat("

    Movimiento Entrada (Traspaso): {1}", CveMovimientoEntrada, FolioEntrada) - Msg.AppendFormat("
    Imprimir Movimiento ", Encripta(String.Format("OP=Alm&CveMovimiento={0}", CveMovimientoEntrada))) - - If RbEntregaInterna.Checked Then - Msg.AppendFormat("

    Se agregó una guía de paquetería interna") - End If - - Alert(Msg.ToString(), TipoMensaje.MsgInformacion) - - Limpia() - LimpiaCampos() - CargaPendientes() - - CargaBitacora = False - - Else - Alert(TextoError, TipoMensaje.MsgError) - RegistraScript("playsonidito('142608__autistic-lucario__error.wav')") - ObjInventario.RollBack() - End If - - ObjInventario.Dispose() - - End Sub - - - Private Sub MandaCorreoEntrega(tCveVenta As Integer) - EnviarCorreoEntrega(tCveVenta, UsuarioActual) - End Sub - - Private Sub EnviarCorreoEntrega(tCveVenta As Integer, UsuarioActual As Usuario) - 'Dim Correo As New ClsSisMail - Dim SerieFolio As String = "" - Dim Asunto As String = String.Format("{0} Envio de pedido: {1}", UsuarioActual.Empresa.NombreCorto, SerieFolio) - Dim Cuerpo As New StringBuilder() - Dim Destinatario As String = "" - Dim MensajeEnviado As Boolean = False - Dim tCvecliente As Integer - Dim tCveVendedor As Integer - Dim bytes() As Byte = Nothing - Dim ObjVentas As New ClsVentas() - - Dim strBody As New StringBuilder - If ObjVentas.GetVenta(tCveVenta, UsuarioActual.CveEmpresa) Then - Dim dr As DataRow = ObjVentas.DtResultados.FiltroPrimero("") - tCveVendedor = dr("CveVendedor").ToString().ToEntero() - Dim CorreoVendedor As String = GlobalDTVendedores(UsuarioActual.CveEmpresa).FiltroPrimeroValor("Correo", String.Format("CveVendedor = {0}", tCveVendedor)) - Dim CorreoAsistente As String = GlobalDTVendedores(UsuarioActual.CveEmpresa, VendedorTipo:=3).FiltroPrimeroValor("Correo", String.Format("CveSuperior = {0}", CveVendedor)) - Destinatario = String.Format("{0};{1};{2}", dr("CorreoNotificacion"), CorreoVendedor, CorreoAsistente) - tCvecliente = dr("CveCliente").ToString().ToEntero() - - Dim drC As DataRow = GlobalDTCliente(UsuarioActual.CveEmpresa, CveCliente:=tCvecliente).FiltroPrimero("") - If drC IsNot Nothing Then - - Destinatario += String.Format(";{0};{1}", drC("CorreoEntregaCompras"), drC("CorreoEntregaAlmacen")) - - Dim ClienteNombre As String = dr("ClienteNombre").ToString() - Dim FolioVenta As String = dr("SerieFolio").ToString() - Dim Pedido As String = dr("PedidoContrato").ToString() - Dim OrdenCompra As String = dr("OrdenCompra").ToString() - Dim CveVenta As Integer = dr("CveVenta").ToString().ToEntero() - Dim TipoDocto As String = dr("TipoDocto").ToString() - - Dim dtDetalle As New DataTable - If ObjVentas.GetVentaDetalle(CveVenta) Then - dtDetalle = ObjVentas.DtResultados - End If - Dim DetalleTable As String = "" - For Each dRow As DataRow In dtDetalle.Rows - Dim detalle As String = String.Format("{0}{1}{2}", dRow("Codigo"), dRow("Cantidad"), dRow("PS")) - DetalleTable += detalle - Next - - strBody.Append("") - strBody.Append("") - strBody.Append("") - strBody.Append("") - strBody.Append(" ") - strBody.Append("
    ") - strBody.Append($"") - strBody.Append("
    ") - strBody.Append("

    ") - strBody.Append($" Apreciable {ClienteNombre}, le confirmamos los") - strBody.Append(" productos surtidos y entregados en mostrador conforme a la") - strBody.Append($" {TipoDocto}:") - strBody.Append("

    ") - strBody.Append($"

    {FolioVenta} - Pedido {Pedido} - Orden de Compra {OrdenCompra}

    ") - strBody.Append("
    ") - strBody.Append(" ") - strBody.Append(DetalleTable) - strBody.Append(" ") - strBody.Append("
    ") - strBody.Append("
    ") - strBody.Append("

    ") - strBody.Append(" Se entregaron los productos conforme a las especificaciones de su pedido y verificamos que no se presentara alguno de los siguientes inconvenientes:") - strBody.Append("

    ") - strBody.Append("

    ") - strBody.Append(" • Empaque violado.
    ") - strBody.Append("• Daño físico en la caja.
    ") - strBody.Append("• Producto incompleto o distinto al solicitado.
    ") - strBody.Append("• Alguna otra situación que se considere que compromete la integridad de la mercancía.
    ") - strBody.Append("") - strBody.Append("

    ") - strBody.Append("
    ") - strBody.Append("

    ") - strBody.Append($" Aceptando a entera satisfacción a las {Today.Hour}:{Today.Minute} hrs del {Today.ToString()}") - strBody.Append("

    ") - strBody.Append("
    ") - strBody.Append("

    ") - strBody.Append(" Gracias por su compra
    ") - 'strBody.Append(" Compuproveedores") - strBody.Append("

    ") - strBody.Append("

    ") - strBody.Append(" Sigue disfrutando de nuestros productos y servicios
    ") - 'strBody.Append(" www.compuproveedores.com") - strBody.Append("") - strBody.Append("

    ") - strBody.Append(" ") - strBody.Append("") - End If - - End If - ObjVentas.Dispose() - - Dim MailCls As New ClsSisMail - - Dim LSRutasMail As New List(Of ClsSisMail.ArchivoMail) - Dim itemMail As New ClsSisMail.ArchivoMail() - LSRutasMail.Add(New ClsSisMail.ArchivoMail With {.ArchivoBinario = bytes, .NombreArchivo = "Entrega en mostrador"}) - - MailCls.SendMail(ClsPaginas.EmpresaNotificaciones, Destinatario, "Enviado desde Entrega Almacen", strBody.ToString(), Destinatario) - MailCls = Nothing - End Sub - - Private Sub Limpia() - - 'DATOS DE LA VENTA - LbCantidad.Text = "" - LbCliente.Text = "" - LbObservaciones.Text = "" - 'LbFolio.Text = "" - HLFolio.Text = "" - - 'DATOS DEL MOVIMINETO - TxtObservaciones.Text = "" - TxtFecha.Text = NowADS().ToShortDateString - DdlAlmacen.SelectedValueExist(-1) - CargaFolios() - - 'VARIABLES GENERALES + End If + + FechaCaducidad = If(CBool(Dr("AplicaCaducidad")) AndAlso Dr("FechaCaducidad").ToString() <> "", Dr("FechaCaducidad").ToString().ToDate, MinFecha) + Lote = If(CBool(Dr("AplicaLote")), Dr("Lote").ToString(), "-1") + CveSeccionAlmacen = If(CBool(Dr("AplicaSeccion")), Dr("CveSeccion").ToString().ToEntero(), -1) + + DtDetalle = DtDatosDetalle.FiltraParametros(String.Format("ConsecId = {0} AND FueTraspaso IS NULL", Dr("Consec"))) + 'DtDetalleLote = DtDatosDetalleLote.FiltraParametros(String.Format("ConsecId = {0} AND FueTraspaso IS NULL", Dr("Consec"))) + If DtDetalle.Rows.Count > 0 Then 'SI FUE POR SERIE + For Each Dr1 As DataRow In DtDetalle.Rows + If Not ObjInventario.AddMovimientoDetalle(CveMovimientoSalida, 1, Dr("CveUM").ToString().ToEntero(), Dr("CvePS").ToString().ToEntero(), 0, Serie:=Dr1("Serie").ToString(), Lote:=Lote, FechaCaducidad:=FechaCaducidad, CveSeccionAlmacen:=CveSeccionAlmacen, CveVentaDetalle:=-1, CveContratoDetalle:=Dr("CveContratoDetalle").ToString().ToEntero()) Then + ErrorMovInv = True + TextoError = $"Ocurrió un error al procesar los conceptos con serie '{Dr1("Serie").ToString()}'. Por favor vuelva a intentar." + Exit For + End If + Next + 'ElseIf DtDetalleLote.Rows.Count > 0 Then 'SI FUE POR LOTE BATCH + ' For Each Dr1 As DataRow In DtDetalleLote.Rows + ' If Not ObjInventario.AddMovimientoDetalle(CveMovimientoSalida, Dr1("Cantidad").ToString().ToDecimal, Dr("CveUM").ToString().ToEntero(), Dr("CvePS").ToString().ToEntero(), 0, Serie:="", Lote:=Dr1("Lote").ToString(), FechaCaducidad:=FechaCaducidad, CveSeccionAlmacen:=CveSeccionAlmacen, CveVentaDetalle:=-1, CveContratoDetalle:=Dr("CveContratoDetalle").ToString().ToEntero()) Then + ' ErrorMovInv = True + ' TextoError = "Ocurrió un error al procesar los conceptos con serie. Por favor vuelva a intentar." + ' Exit For + ' End If + ' Next + Else 'NORMAL + If Not ObjInventario.AddMovimientoDetalle(CveMovimientoSalida, Dr("CantidadGV").ToString().ToDecimal, Dr("CveUM").ToString().ToEntero(), Dr("CvePS").ToString().ToEntero(), 0, -1, Lote:=Lote, FechaCaducidad:=FechaCaducidad, CveSeccionAlmacen:=CveSeccionAlmacen, CveContratoDetalle:=Dr("CveContratoDetalle").ToString().ToEntero()) Then + ErrorMovInv = True + TextoError = "Ocurrió un error al procesar los conceptos de salida. Por favor vuelva a intentar." + Exit For + End If + End If + Next + Else + TextoError = "Ocurrió un error al generar el movimiento de salida." + ErrorMovInv = True + End If + End If + + Dim ValorTraspaso As Decimal = 0 + 'ENTRADA POR TRASPASO + If Not ErrorMovInv Then + 'sino es transitorio, los transitorios, ya no se hace otro movimiento + + ConceptoMovimiento = If(ChkTransitorio.Checked, 2, 27) + Almacen2 = If(ChkTransitorio.Checked, DdlAlmacenTransitorio.SelectedValue.ToEntero(), CveAlmacenTraspasoDestino) + CveMovimientoEntrada = ObjInventario.AddMovimiento(Almacen2, ConceptoMovimiento, 1, TxtFecha.Text.ToDate, -1, UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa, -1, -1, -1, -1, Observaciones:=TxtObservaciones.Text.Trim, + Guia:="", CveContrato:=CveContrato, CveMovimientoRelacionado:=CveMovimientoSalida, CveAlmacenDestino:=CveAlmacenTraspasoDestino, + Recibio:=If(ChkTransitorio.Checked, TxtResponsable.Text.Trim, ""), Modulo:="RE/GT1", CveOP:=CveOP) + FolioEntrada = ObjInventario.Folio + If CveMovimientoEntrada > 0 Then + If ObjInventario.GetMovimientosDetalle(CveMovimientoSalida, UsuarioActual.CveEmpresa) Then + Dim CveSeccionAlmacen As Integer = -1 + ValorTraspaso = ObjInventario.DtResultados.SUMD("Total").RoundSQL + For Each Dr As DataRow In ObjInventario.DtResultados.Rows + + CveSeccionAlmacen = -3 + + If Not ObjInventario.AddMovimientoDetalle(CveMovimientoEntrada, Dr("Cantidad").ToString().ToDecimal, Dr("CveUM").ToString().ToEntero(), Dr("CvePS").ToString().ToEntero(), Dr("PU").ToString().ToDecimal, CveAF:=Dr("CveAF").ToString().ToEntero(), CveSeccionAlmacen:=CveSeccionAlmacen, Serie:=Dr("Serie").ToString(), Lote:=Dr("Lote").ToString(), FechaCaducidad:=Dr("FechaCaducidad").ToString().ToDate, CveMovimientoDetalleEntrada:=Dr("CveMovimientoDetalle").ToString().ToEntero(), CveVentaDetalle:=Dr("CveVentaDetalle").ToString().ToEntero()) Then + ErrorMovInv = True + TextoError = "Ocurrió un error al guardar los movimientos de entrada" + Exit For + End If + Next + End If + Else + TextoError = "Ocurrió un error al generar el movimiento de entrada" + ErrorMovInv = True + End If + + End If + + 'MARCA SOLICITUD CON EL MOVIMIENTO GENERADO + If Not ErrorMovInv Then + If Not ObjInventario.UpdateTraspasoSolicitudMovimiento(CveTraspasoSurtir, CveMovimientoSalida) Then + TextoError = "Ocurrió un error al vincular los movimientos con la solicitud de traspaso. Por favor verifique y vuelva a intentar" + ErrorMovInv = True + End If + End If + + Dim Fecha As Date = TxtFecha.Text.ToDate + 'Paqueterias Guias + If RbEntregaInterna.Checked AndAlso Not ErrorMovInv Then + Dim CveEstatus As Integer = 0 ' DdlEstatus.SelectedValue.ToEntero() + Dim FechaEstimada As String = "-1" 'If(TxtFechaEstimada.Text = "", "-1", TxtFechaEstimada.Text) + Dim NoCajas As Integer = 0 'TxtNoCajas.Text.ToEntero() + Dim Observaciones As String = "" 'TxtObservacionesPaqInterna.Text + Dim CvePaqueteria As Integer = GlobalDTPaqueterias(UsuarioActual.CveEmpresa, 0).FiltroPrimeroValor("CvePaqueteria", "").ToEntero() + + Dim CvePaqueteriaGuia As Integer = ObjGeneral.AddPaqueteriasGuias(CvePaqueteria, 9, CveEstatus, CveSubProyecto, Fecha.ToShortDateString, "-1", "-1", NoCajas, 0.00, "-1", FechaEstimada, Observaciones, UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa, EsEntregaInterna:=True) + + If CvePaqueteriaGuia > 0 Then + If CveVentaSurtir > 0 OrElse CveSubProyecto > 0 Then + ErrorMovInv = Not ObjGeneral.AddPaqueteriasGuiasDetalles(CvePaqueteriaGuia, CveVentaSurtir, -1, CveMovimientoEntrada, -1) + End If + + If ErrorMovInv Then + Alert("Error en el paqueteria guia detalle", TipoMensaje.MsgError) + End If + Else + ErrorMovInv = True + Alert("Error en el paqueteria guia", TipoMensaje.MsgError) + End If + End If + + 'AGREGAMOS PREPOLIZAS TRASPASO DIRECTO: + + Dim CvePrePolizaTraspaso As Integer = ObjConta.AddPrePolizas("EA/GT", 53, 0, 0, 1, Fecha, "Traspaso", UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa) + If CvePrePolizaTraspaso > 0 Then + + + If Not ObjConta.AddPrePolizasDetalle(CvePrePolizaTraspaso, True, ValorTraspaso, ValorTraspaso, 68, TxtObservaciones.Text, TxtObservaciones.Text, CveMovimientoAlmacen:=CveMovimientoSalida, Contabilizable:=False) Then + ErrorMovInv = True + End If + + If Not ErrorMovInv AndAlso Not ObjConta.AddPrePolizasDetalle(CvePrePolizaTraspaso, False, ValorTraspaso, ValorTraspaso, 68, TxtObservaciones.Text, TxtObservaciones.Text, CveMovimientoAlmacen:=CveMovimientoEntrada, Contabilizable:=False) Then + ErrorMovInv = True + End If + Else + ErrorMovInv = True + End If + + + If Not ErrorMovInv Then + ObjInventario.Commit() + ObjGeneral.Dispose() + RegistraScript("playsonidito('beep-07.wav')") + + Dim Msg As New StringBuilder + Msg.AppendFormat("Movimiento Salida: {1}", CveMovimientoSalida, FolioSalida) + Msg.AppendFormat("
    Imprimir Movimiento ", Encripta(String.Format("OP=Alm&CveMovimiento={0}", CveMovimientoSalida))) + + Msg.AppendFormat("

    Movimiento Entrada (Traspaso): {1}", CveMovimientoEntrada, FolioEntrada) + Msg.AppendFormat("
    Imprimir Movimiento ", Encripta(String.Format("OP=Alm&CveMovimiento={0}", CveMovimientoEntrada))) + + If RbEntregaInterna.Checked Then + Msg.AppendFormat("

    Se agregó una guía de paquetería interna") + End If + + Alert(Msg.ToString(), TipoMensaje.MsgInformacion) + + Limpia() + LimpiaCampos() + CargaPendientes() + + CargaBitacora = False + + Else + Alert(TextoError, TipoMensaje.MsgError) + RegistraScript("playsonidito('142608__autistic-lucario__error.wav')") + ObjInventario.RollBack() + End If + + ObjInventario.Dispose() + + End Sub + + + Private Sub MandaCorreoEntrega(tCveVenta As Integer) + EnviarCorreoEntrega(tCveVenta, UsuarioActual) + End Sub + + Private Sub EnviarCorreoEntrega(tCveVenta As Integer, UsuarioActual As Usuario) + 'Dim Correo As New ClsSisMail + Dim SerieFolio As String = "" + Dim Asunto As String = String.Format("{0} Envio de pedido: {1}", UsuarioActual.Empresa.NombreCorto, SerieFolio) + Dim Cuerpo As New StringBuilder() + Dim Destinatario As String = "" + Dim MensajeEnviado As Boolean = False + Dim tCvecliente As Integer + Dim tCveVendedor As Integer + Dim bytes() As Byte = Nothing + Dim ObjVentas As New ClsVentas() + + Dim strBody As New StringBuilder + If ObjVentas.GetVenta(tCveVenta, UsuarioActual.CveEmpresa) Then + Dim dr As DataRow = ObjVentas.DtResultados.FiltroPrimero("") + tCveVendedor = dr("CveVendedor").ToString().ToEntero() + Dim CorreoVendedor As String = GlobalDTVendedores(UsuarioActual.CveEmpresa).FiltroPrimeroValor("Correo", String.Format("CveVendedor = {0}", tCveVendedor)) + Dim CorreoAsistente As String = GlobalDTVendedores(UsuarioActual.CveEmpresa, VendedorTipo:=3).FiltroPrimeroValor("Correo", String.Format("CveSuperior = {0}", CveVendedor)) + Destinatario = String.Format("{0};{1};{2}", dr("CorreoNotificacion"), CorreoVendedor, CorreoAsistente) + tCvecliente = dr("CveCliente").ToString().ToEntero() + + Dim drC As DataRow = GlobalDTCliente(UsuarioActual.CveEmpresa, CveCliente:=tCvecliente).FiltroPrimero("") + If drC IsNot Nothing Then + + Destinatario += String.Format(";{0};{1}", drC("CorreoEntregaCompras"), drC("CorreoEntregaAlmacen")) + + Dim ClienteNombre As String = dr("ClienteNombre").ToString() + Dim FolioVenta As String = dr("SerieFolio").ToString() + Dim Pedido As String = dr("PedidoContrato").ToString() + Dim OrdenCompra As String = dr("OrdenCompra").ToString() + Dim CveVenta As Integer = dr("CveVenta").ToString().ToEntero() + Dim TipoDocto As String = dr("TipoDocto").ToString() + + Dim dtDetalle As New DataTable + If ObjVentas.GetVentaDetalle(CveVenta) Then + dtDetalle = ObjVentas.DtResultados + End If + Dim DetalleTable As String = "" + For Each dRow As DataRow In dtDetalle.Rows + Dim detalle As String = String.Format("{0}{1}{2}", dRow("Codigo"), dRow("Cantidad"), dRow("PS")) + DetalleTable += detalle + Next + + strBody.Append("") + strBody.Append("") + strBody.Append("") + strBody.Append("") + strBody.Append(" ") + strBody.Append("
    ") + strBody.Append($"") + strBody.Append("
    ") + strBody.Append("

    ") + strBody.Append($" Apreciable {ClienteNombre}, le confirmamos los") + strBody.Append(" productos surtidos y entregados en mostrador conforme a la") + strBody.Append($" {TipoDocto}:") + strBody.Append("

    ") + strBody.Append($"

    {FolioVenta} - Pedido {Pedido} - Orden de Compra {OrdenCompra}

    ") + strBody.Append("
    ") + strBody.Append(" ") + strBody.Append(DetalleTable) + strBody.Append(" ") + strBody.Append("
    ") + strBody.Append("
    ") + strBody.Append("

    ") + strBody.Append(" Se entregaron los productos conforme a las especificaciones de su pedido y verificamos que no se presentara alguno de los siguientes inconvenientes:") + strBody.Append("

    ") + strBody.Append("

    ") + strBody.Append(" • Empaque violado.
    ") + strBody.Append("• Daño físico en la caja.
    ") + strBody.Append("• Producto incompleto o distinto al solicitado.
    ") + strBody.Append("• Alguna otra situación que se considere que compromete la integridad de la mercancía.
    ") + strBody.Append("") + strBody.Append("

    ") + strBody.Append("
    ") + strBody.Append("

    ") + strBody.Append($" Aceptando a entera satisfacción a las {Today.Hour}:{Today.Minute} hrs del {Today.ToString()}") + strBody.Append("

    ") + strBody.Append("
    ") + strBody.Append("

    ") + strBody.Append(" Gracias por su compra
    ") + 'strBody.Append(" Compuproveedores") + strBody.Append("

    ") + strBody.Append("

    ") + strBody.Append(" Sigue disfrutando de nuestros productos y servicios
    ") + 'strBody.Append(" www.compuproveedores.com") + strBody.Append("") + strBody.Append("

    ") + strBody.Append(" ") + strBody.Append("") + End If + + End If + ObjVentas.Dispose() + + Dim MailCls As New ClsSisMail + + Dim LSRutasMail As New List(Of ClsSisMail.ArchivoMail) + Dim itemMail As New ClsSisMail.ArchivoMail() + LSRutasMail.Add(New ClsSisMail.ArchivoMail With {.ArchivoBinario = bytes, .NombreArchivo = "Entrega en mostrador"}) + + MailCls.SendMail(ClsPaginas.EmpresaNotificaciones, Destinatario, "Enviado desde Entrega Almacen", strBody.ToString(), Destinatario) + MailCls = Nothing + End Sub + + Private Sub Limpia() + + 'DATOS DE LA VENTA + LbCantidad.Text = "" + LbCliente.Text = "" + LbObservaciones.Text = "" + 'LbFolio.Text = "" + HLFolio.Text = "" + + 'DATOS DEL MOVIMINETO + TxtObservaciones.Text = "" + TxtFecha.Text = NowADS().ToShortDateString + DdlAlmacen.SelectedValueExist(-1) + CargaFolios() + + 'VARIABLES GENERALES CveVentaSurtir = -1 CveOSSurtir = -1 - DtDatosDetalle = Nothing - DtDatosDetalleLote = Nothing - DtDatos = Nothing - - DivTipoCambioAdvertencia.Visible = False - - 'TRASPASO - DivTransitorio1.Visible = False - ChkTransitorio.Checked = False - TxtResponsable.Text = "" - DivTransitorio2.Visible = False - - LbSurtida.Visible = False - TimmerRefresh.Enabled = True - - DdlAlmacen.Enabled = True - - UpGenerales.Update() - CargaGvDatos() - - UpDatos.Update() + DtDatosDetalle = Nothing + DtDatosDetalleLote = Nothing + DtDatos = Nothing + + DivTipoCambioAdvertencia.Visible = False + + 'TRASPASO + DivTransitorio1.Visible = False + ChkTransitorio.Checked = False + TxtResponsable.Text = "" + DivTransitorio2.Visible = False + + LbSurtida.Visible = False + TimmerRefresh.Enabled = True + + DdlAlmacen.Enabled = True + + UpGenerales.Update() + CargaGvDatos() + + UpDatos.Update() End Sub -#End Region +#End Region + +#Region " TRASPASO - TRANSITORIO " + Protected Sub ChkTransitorio_CheckedChanged(sender As Object, e As EventArgs) + + TxtResponsable.Text = "" + DivTransitorio2.Visible = ChkTransitorio.Checked -#Region " TRASPASO - TRANSITORIO " - Protected Sub ChkTransitorio_CheckedChanged(sender As Object, e As EventArgs) - - TxtResponsable.Text = "" - DivTransitorio2.Visible = ChkTransitorio.Checked - End Sub -#End Region +#End Region -#Region "SECCION ALMACEN" +#Region "SECCION ALMACEN" 'Private Sub CreaDtSeccionAlmacen() ' DtSeccionAlmacen = New DataTable ' DtSeccionAlmacen.Columns.Add("CantidadSeccionAlmacen", GetType(Decimal)) @@ -4148,70 +4148,70 @@ Partial Class Inventarios_EntregaAlmacen ' RegistraScript("$('#ModalVerSeccionesAlmacen').modal()") 'End Sub -#End Region +#End Region -#Region "DIVIDIR" +#Region "DIVIDIR" + + Protected Sub Dividir(sender As Object, e As EventArgs) + Dim index2 As Integer = 0 + + For Each Row As DataRow In DtDatos.Rows + Row("Seleccionado") = GvDatos.Rows(index2).FCCheckBox("cbInv").Checked + If GvDatos.Rows(index2).FCTextBox("TbCantidadF").Text <> "" Then + Row("CantidadSeleccionada") = GvDatos.Rows(index2).FCTextBox("TbCantidadF").Text + End If + If GvDatos.Rows(index2).FCTextBox("TxtLote").Text <> "" Then + Row("Lote") = GvDatos.Rows(index2).FCTextBox("TxtLote").Text + End If + If GvDatos.Rows(index2).FCDropDownList("DdlSeccionAlmacen").SelectedValue <> "-1" Then + Row("CveSeccion") = GvDatos.Rows(index2).FCDropDownList("DdlSeccionAlmacen").SelectedValue.ToEntero() + End If + If GvDatos.Rows(index2).FCTextBox("TxtCaducidad").Text <> "" Then + Row("FechaCaducidad") = GvDatos.Rows(index2).FCTextBox("TxtCaducidad").Text.ToDate + End If + index2 += 1 + Next + DtDatos.AcceptChanges() + + Dim gvRow As GridViewRow = DirectCast((DirectCast(sender, Button)).NamingContainer, GridViewRow) + Dim Index As Integer = gvRow.RowIndex + Dim Cantidad As String = HdnCantidadMovimiento.Value + Dim dr1 As DataRow = DtDatos.Rows(Index) + Dim dr As DataRow = DtDatos.NewRow + dr.ItemArray = dr1.ItemArray + dr1("CantidadC") = (dr1("CantidadC").ToString().ToDouble - Cantidad.ToDouble) + Dim CantidadFOriginal As Double = dr1("CantidadF").ToString().ToDouble + dr1("CantidadF") = (dr1("CantidadF").ToString().ToDouble - Cantidad.ToDouble) + Dim CantidadSOriginal As Double = dr1("CantidadS").ToString().ToDouble + dr1("CantidadS") = (CantidadSOriginal * dr1("CantidadF").ToString().ToDouble) / CantidadFOriginal + Dim CantidadSeleccionadaOriginal As Double = dr1("CantidadSeleccionada").ToString().ToDouble + dr1("CantidadSeleccionada") = If(CantidadSeleccionadaOriginal > dr1("CantidadF").ToString().ToDouble, dr1("CantidadF").ToString().ToDouble, CantidadSeleccionadaOriginal) + CantidadSeleccionadaOriginal = CantidadSeleccionadaOriginal - dr1("CantidadF").ToString().ToDouble + + 'Dim CostoIndirectoOriginal As Double = dr1("CostoIndirecto").ToString().ToDouble + 'dr1("CostoIndirecto") = (CostoIndirectoOriginal * dr1("CantidadF").ToString().ToDouble) / CantidadFOriginal + 'Dim CostoIndirectoExtranjeroOriginal As Double = dr1("CostoIndirectoExtranjero").ToString().ToDouble + 'dr1("CostoIndirectoExtranjero") = (CostoIndirectoExtranjeroOriginal * dr1("CantidadF").ToString().ToDouble) / CantidadFOriginal + + DtDatos.AcceptChanges() + + dr("CantidadC") = Cantidad.ToDouble + dr("CantidadF") = Cantidad.ToDouble + dr("CantidadS") = (CantidadSOriginal * dr("CantidadF").ToString().ToDouble) / CantidadFOriginal + dr("CantidadSeleccionada") = If(CantidadSeleccionadaOriginal > 0, CantidadSeleccionadaOriginal, 0) + dr("Seleccionado") = If(CantidadSeleccionadaOriginal > 0, True, False) + 'dr("CostoIndirecto") = (CostoIndirectoOriginal * dr("CantidadF").ToString().ToDouble) / CantidadFOriginal + 'dr("CostoIndirectoExtranjero") = (CostoIndirectoExtranjeroOriginal * dr("CantidadF").ToString().ToDouble) / CantidadFOriginal + DtDatos.Rows.InsertAt(dr, Index) + DtDatos.AcceptChanges() + + index2 = 1 + For Each Row As DataRow In DtDatos.Rows + Row("Consec") = index2 + index2 += 1 + Next + DtDatos.AcceptChanges() - Protected Sub Dividir(sender As Object, e As EventArgs) - Dim index2 As Integer = 0 - - For Each Row As DataRow In DtDatos.Rows - Row("Seleccionado") = GvDatos.Rows(index2).FCCheckBox("cbInv").Checked - If GvDatos.Rows(index2).FCTextBox("TbCantidadF").Text <> "" Then - Row("CantidadSeleccionada") = GvDatos.Rows(index2).FCTextBox("TbCantidadF").Text - End If - If GvDatos.Rows(index2).FCTextBox("TxtLote").Text <> "" Then - Row("Lote") = GvDatos.Rows(index2).FCTextBox("TxtLote").Text - End If - If GvDatos.Rows(index2).FCDropDownList("DdlSeccionAlmacen").SelectedValue <> "-1" Then - Row("CveSeccion") = GvDatos.Rows(index2).FCDropDownList("DdlSeccionAlmacen").SelectedValue.ToEntero() - End If - If GvDatos.Rows(index2).FCTextBox("TxtCaducidad").Text <> "" Then - Row("FechaCaducidad") = GvDatos.Rows(index2).FCTextBox("TxtCaducidad").Text.ToDate - End If - index2 += 1 - Next - DtDatos.AcceptChanges() - - Dim gvRow As GridViewRow = DirectCast((DirectCast(sender, Button)).NamingContainer, GridViewRow) - Dim Index As Integer = gvRow.RowIndex - Dim Cantidad As String = HdnCantidadMovimiento.Value - Dim dr1 As DataRow = DtDatos.Rows(Index) - Dim dr As DataRow = DtDatos.NewRow - dr.ItemArray = dr1.ItemArray - dr1("CantidadC") = (dr1("CantidadC").ToString().ToDouble - Cantidad.ToDouble) - Dim CantidadFOriginal As Double = dr1("CantidadF").ToString().ToDouble - dr1("CantidadF") = (dr1("CantidadF").ToString().ToDouble - Cantidad.ToDouble) - Dim CantidadSOriginal As Double = dr1("CantidadS").ToString().ToDouble - dr1("CantidadS") = (CantidadSOriginal * dr1("CantidadF").ToString().ToDouble) / CantidadFOriginal - Dim CantidadSeleccionadaOriginal As Double = dr1("CantidadSeleccionada").ToString().ToDouble - dr1("CantidadSeleccionada") = If(CantidadSeleccionadaOriginal > dr1("CantidadF").ToString().ToDouble, dr1("CantidadF").ToString().ToDouble, CantidadSeleccionadaOriginal) - CantidadSeleccionadaOriginal = CantidadSeleccionadaOriginal - dr1("CantidadF").ToString().ToDouble - - 'Dim CostoIndirectoOriginal As Double = dr1("CostoIndirecto").ToString().ToDouble - 'dr1("CostoIndirecto") = (CostoIndirectoOriginal * dr1("CantidadF").ToString().ToDouble) / CantidadFOriginal - 'Dim CostoIndirectoExtranjeroOriginal As Double = dr1("CostoIndirectoExtranjero").ToString().ToDouble - 'dr1("CostoIndirectoExtranjero") = (CostoIndirectoExtranjeroOriginal * dr1("CantidadF").ToString().ToDouble) / CantidadFOriginal - - DtDatos.AcceptChanges() - - dr("CantidadC") = Cantidad.ToDouble - dr("CantidadF") = Cantidad.ToDouble - dr("CantidadS") = (CantidadSOriginal * dr("CantidadF").ToString().ToDouble) / CantidadFOriginal - dr("CantidadSeleccionada") = If(CantidadSeleccionadaOriginal > 0, CantidadSeleccionadaOriginal, 0) - dr("Seleccionado") = If(CantidadSeleccionadaOriginal > 0, True, False) - 'dr("CostoIndirecto") = (CostoIndirectoOriginal * dr("CantidadF").ToString().ToDouble) / CantidadFOriginal - 'dr("CostoIndirectoExtranjero") = (CostoIndirectoExtranjeroOriginal * dr("CantidadF").ToString().ToDouble) / CantidadFOriginal - DtDatos.Rows.InsertAt(dr, Index) - DtDatos.AcceptChanges() - - index2 = 1 - For Each Row As DataRow In DtDatos.Rows - Row("Consec") = index2 - index2 += 1 - Next - DtDatos.AcceptChanges() - If UsuarioActual.Empresa.Funcionalidad(578) = "1" Then CargaGvDatos(False) Else @@ -4219,151 +4219,151 @@ Partial Class Inventarios_EntregaAlmacen End If - index2 = 0 - For Each Row As DataRow In DtDatos.Rows - GvDatos.Rows(index2).FCCheckBox("cbInv").Checked = CBool(Row("Seleccionado")) - If Row("CantidadSeleccionada").ToString() <> "" Then - GvDatos.Rows(index2).FCTextBox("TbCantidadF").Text = Row("CantidadSeleccionada").ToString() - End If - If Row("Lote").ToString() <> "" Then - GvDatos.Rows(index2).FCTextBox("TxtLote").Text = Row("Lote").ToString() - End If - If Row("CveSeccion").ToString() <> "" Then - GvDatos.Rows(index2).FCDropDownList("DdlSeccionAlmacen").SelectedValue = Row("CveSeccion").ToString() - End If - If Row("FechaCaducidad").ToString() <> "" Then - GvDatos.Rows(index2).FCTextBox("TxtCaducidad").Text = Row("FechaCaducidad").ToString().ToDate.ToShortDateString - End If - index2 += 1 - Next - + index2 = 0 + For Each Row As DataRow In DtDatos.Rows + GvDatos.Rows(index2).FCCheckBox("cbInv").Checked = CBool(Row("Seleccionado")) + If Row("CantidadSeleccionada").ToString() <> "" Then + GvDatos.Rows(index2).FCTextBox("TbCantidadF").Text = Row("CantidadSeleccionada").ToString() + End If + If Row("Lote").ToString() <> "" Then + GvDatos.Rows(index2).FCTextBox("TxtLote").Text = Row("Lote").ToString() + End If + If Row("CveSeccion").ToString() <> "" Then + GvDatos.Rows(index2).FCDropDownList("DdlSeccionAlmacen").SelectedValue = Row("CveSeccion").ToString() + End If + If Row("FechaCaducidad").ToString() <> "" Then + GvDatos.Rows(index2).FCTextBox("TxtCaducidad").Text = Row("FechaCaducidad").ToString().ToDate.ToShortDateString + End If + index2 += 1 + Next + End Sub -#End Region +#End Region -#Region " GUIAS - SABE QUE ES PORQUE NO VEO QUE SE UTILIZE EN ALGUNA PARTE - EN MIRAS DE ELIMINAR - IPP 24 AGOSTO 2017 " - Private Sub BtnNumeroGuia_Click(sender As Object, e As EventArgs) Handles BtnNumeroGuia.Click - Dim Objeto As New ClsInventarios - If Objeto.UpdateMovimientoGuia(TxtGuia.Text, CveMovimiento, UsuarioActual.CveEmpresa) Then - Alert("Se ha guardado correctamente la póliza", TipoMensaje.MsgConfirmacion) - End If - Objeto.Dispose() - End Sub - - Private Sub GvDocs_RowDataBound(sender As Object, e As GridViewRowEventArgs) Handles GvDocs.RowDataBound - - If e.Row.RowType = DataControlRowType.DataRow Then - - Dim ImgDownLoad As Literal = e.Row.FCLiteral("HplDown") - Dim Adjunto As String = e.Row.DBCampo("Adjunto").ToString() - Dim ArchivoRuta As String = "" - - If Adjunto.Trim.Length > 0 Then - ArchivoRuta = UsuarioActual.Empresa.Ruta & "Documentacion\Ventas\" & Adjunto - Dim fi As New FileInfo(ArchivoRuta) - Dim linkDescarga As String = "" - If fi.Exists() Then - linkDescarga = $"/Empresas/{UsuarioActual.CveEmpresa}/Documentacion/ventas/{fi.Name}" - ImgDownLoad.Visible = True - ImgDownLoad.Text = String.Format(" ", linkDescarga) - - - End If - - End If - - End If - +#Region " GUIAS - SABE QUE ES PORQUE NO VEO QUE SE UTILIZE EN ALGUNA PARTE - EN MIRAS DE ELIMINAR - IPP 24 AGOSTO 2017 " + Private Sub BtnNumeroGuia_Click(sender As Object, e As EventArgs) Handles BtnNumeroGuia.Click + Dim Objeto As New ClsInventarios + If Objeto.UpdateMovimientoGuia(TxtGuia.Text, CveMovimiento, UsuarioActual.CveEmpresa) Then + Alert("Se ha guardado correctamente la póliza", TipoMensaje.MsgConfirmacion) + End If + Objeto.Dispose() End Sub -#End Region -#Region "SUGERENCIAS" + Private Sub GvDocs_RowDataBound(sender As Object, e As GridViewRowEventArgs) Handles GvDocs.RowDataBound - Protected Sub BtnVerSugerencias_Click(sender As Object, e As EventArgs) - If Not CveVentaSurtir > 0 Then - Alert("Tiene que seleccionar la venta a surtir", TipoMensaje.MsgAdvertencia) - Exit Sub - End If - - If Not DdlAlmacen.SelectedValue.ToEntero() > 0 Then - Alert("Tiene que seleccionar el almacen", TipoMensaje.MsgAdvertencia) - Exit Sub - End If - - Dim ObjInv As New ClsInventarios - If ObjInv.GetSugerenciasSalidaAlmacen(CveVentaSurtir, DdlAlmacen.SelectedValue.ToEntero(), UsuarioActual.CveEmpresa) Then - GvSugerencias.DataSource = ObjInv.DtResultados - - - DtDatosSugerencias = ObjInv.DtResultados - - DtDatosSugerencias.Columns.Add("Consec", GetType(Integer)) - DtDatosSugerencias.Columns.Add("CantidadGV", GetType(Double)) - DtDatosSugerencias.Columns.Add("CantidadTraspaso", GetType(Double)) - - If Not DtDatosSugerencias.Columns.Contains("Lote") Then - DtDatosSugerencias.Columns.Add("Lote", GetType(String)) - End If - If Not DtDatosSugerencias.Columns.Contains("CveSeccion") Then - DtDatosSugerencias.Columns.Add("CveSeccion", GetType(Integer)) - End If - - If Not DtDatosSugerencias.Columns.Contains("Seleccionado") Then - DtDatosSugerencias.Columns.Add("Seleccionado", GetType(Boolean)) - End If - If Not DtDatosSugerencias.Columns.Contains("CantidadSeleccionada") Then - DtDatosSugerencias.Columns.Add("CantidadSeleccionada", GetType(Double)) - End If - - Dim Index As Integer = 1 - For Each Dr As DataRow In DtDatosSugerencias.Rows - Dr("Consec") = Index - - Index += 1 - Next - - DtDatosSugerencias.AcceptChanges() - - If DtDatosSugerencias IsNot Nothing AndAlso DtDatosSugerencias.Rows.Count > 0 Then - GvSugerencias.Columns(2).Visible = DtDatosSugerencias.MAX("Seccion") <> "" - GvSugerencias.Columns(3).Visible = DtDatosSugerencias.MAX("Serie") <> "" - GvSugerencias.Columns(4).Visible = DtDatosSugerencias.MAX("Lote") <> "" - GvSugerencias.Columns(5).Visible = DtDatosSugerencias.MAX("FechaCaducidad") <> "" - End If - - - End If - ObjInv.Dispose() - GvSugerencias.DataBind() - - UpVerSugerencias.Update() - - RegistraScript("$('#ModalVerSugerencias').modal({backdrop: 'static', keyboard: false});") - End Sub - Protected Sub BtnAplicarSugerencias_Click(sender As Object, e As EventArgs) - - DtDatos = Nothing - DtDatos = New DataTable - DtDatos = DtDatosSugerencias - - DtDatosDetalle = Nothing - CreaDtDetalle() - - DtDatosDetalleLote = Nothing - CreaDtDetalleLote() - - CargaGvDatos() - - RegistraScript("$('#ModalVerSugerencias').modal('hide')") - End Sub - - Protected Sub DdlAlmacen_SelectedIndexChanged(sender As Object, e As EventArgs) Handles DdlAlmacen.SelectedIndexChanged - RecargaporAlmacenes() - End Sub - - Private Sub RecargaporAlmacenes() - If DdlAlmacen.SelectedValue <> "-1" Then + If e.Row.RowType = DataControlRowType.DataRow Then + + Dim ImgDownLoad As Literal = e.Row.FCLiteral("HplDown") + Dim Adjunto As String = e.Row.DBCampo("Adjunto").ToString() + Dim ArchivoRuta As String = "" + + If Adjunto.Trim.Length > 0 Then + ArchivoRuta = UsuarioActual.Empresa.Ruta & "Documentacion\Ventas\" & Adjunto + Dim fi As New FileInfo(ArchivoRuta) + Dim linkDescarga As String = "" + If fi.Exists() Then + linkDescarga = $"/Empresas/{UsuarioActual.CveEmpresa}/Documentacion/ventas/{fi.Name}" + ImgDownLoad.Visible = True + ImgDownLoad.Text = String.Format(" ", linkDescarga) + + + End If + + End If + + End If + + End Sub +#End Region + +#Region "SUGERENCIAS" + + Protected Sub BtnVerSugerencias_Click(sender As Object, e As EventArgs) + If Not CveVentaSurtir > 0 Then + Alert("Tiene que seleccionar la venta a surtir", TipoMensaje.MsgAdvertencia) + Exit Sub + End If + + If Not DdlAlmacen.SelectedValue.ToEntero() > 0 Then + Alert("Tiene que seleccionar el almacen", TipoMensaje.MsgAdvertencia) + Exit Sub + End If + + Dim ObjInv As New ClsInventarios + If ObjInv.GetSugerenciasSalidaAlmacen(CveVentaSurtir, DdlAlmacen.SelectedValue.ToEntero(), UsuarioActual.CveEmpresa) Then + GvSugerencias.DataSource = ObjInv.DtResultados + + + DtDatosSugerencias = ObjInv.DtResultados + + DtDatosSugerencias.Columns.Add("Consec", GetType(Integer)) + DtDatosSugerencias.Columns.Add("CantidadGV", GetType(Double)) + DtDatosSugerencias.Columns.Add("CantidadTraspaso", GetType(Double)) + + If Not DtDatosSugerencias.Columns.Contains("Lote") Then + DtDatosSugerencias.Columns.Add("Lote", GetType(String)) + End If + If Not DtDatosSugerencias.Columns.Contains("CveSeccion") Then + DtDatosSugerencias.Columns.Add("CveSeccion", GetType(Integer)) + End If + + If Not DtDatosSugerencias.Columns.Contains("Seleccionado") Then + DtDatosSugerencias.Columns.Add("Seleccionado", GetType(Boolean)) + End If + If Not DtDatosSugerencias.Columns.Contains("CantidadSeleccionada") Then + DtDatosSugerencias.Columns.Add("CantidadSeleccionada", GetType(Double)) + End If + + Dim Index As Integer = 1 + For Each Dr As DataRow In DtDatosSugerencias.Rows + Dr("Consec") = Index + + Index += 1 + Next + + DtDatosSugerencias.AcceptChanges() + + If DtDatosSugerencias IsNot Nothing AndAlso DtDatosSugerencias.Rows.Count > 0 Then + GvSugerencias.Columns(2).Visible = DtDatosSugerencias.MAX("Seccion") <> "" + GvSugerencias.Columns(3).Visible = DtDatosSugerencias.MAX("Serie") <> "" + GvSugerencias.Columns(4).Visible = DtDatosSugerencias.MAX("Lote") <> "" + GvSugerencias.Columns(5).Visible = DtDatosSugerencias.MAX("FechaCaducidad") <> "" + End If + + + End If + ObjInv.Dispose() + GvSugerencias.DataBind() + + UpVerSugerencias.Update() + + RegistraScript("$('#ModalVerSugerencias').modal({backdrop: 'static', keyboard: false});") + End Sub + Protected Sub BtnAplicarSugerencias_Click(sender As Object, e As EventArgs) + + DtDatos = Nothing + DtDatos = New DataTable + DtDatos = DtDatosSugerencias + + DtDatosDetalle = Nothing + CreaDtDetalle() + + DtDatosDetalleLote = Nothing + CreaDtDetalleLote() + + CargaGvDatos() + + RegistraScript("$('#ModalVerSugerencias').modal('hide')") + End Sub + + Protected Sub DdlAlmacen_SelectedIndexChanged(sender As Object, e As EventArgs) Handles DdlAlmacen.SelectedIndexChanged + RecargaporAlmacenes() + End Sub + + Private Sub RecargaporAlmacenes() + If DdlAlmacen.SelectedValue <> "-1" Then If UsuarioActual.Empresa.Funcionalidad(578) = "1" Then CargaGvDatos(False) Else @@ -4371,138 +4371,138 @@ Partial Class Inventarios_EntregaAlmacen End If - End If - End Sub - - Protected Sub BtnImprimirSugerencias_Click(sender As Object, e As EventArgs) - Dim LogoRutaFisica As String = String.Format("Empresas\{0}\Logo.png", UsuarioActual.CveEmpresa) - Dim logouri As String = String.Format("{0}://{1}:{2}/ashx/sigfiles.ashx?P={3}", Request.Url.Scheme, Request.Url.Host, Request.Url.Port, Encripta(LogoRutaFisica)) - Dim Imagen As New System.IO.FileInfo(String.Format("{0}Logo.png", UsuarioActual.Empresa.Ruta)) - - Dim params As New List(Of ReportParameter) - params.Add(New ReportParameter("LogoPath", If(Imagen.Exists, $"file://{Imagen.FullName}", ""))) - params.Add(New ReportParameter("NombreEmpresa", UsuarioActual.Empresa.Empresa)) - params.Add(New ReportParameter("UsuarioImprimio", UsuarioActual.Usuario)) - - ImprimirPDF("Empresas/Grales/Formatos/RepEntregaAlmacenSugerencia.rdlc", DtDatosSugerencias, params, "Equipo GPS") + End If End Sub -#End Region + Protected Sub BtnImprimirSugerencias_Click(sender As Object, e As EventArgs) + Dim LogoRutaFisica As String = String.Format("Empresas\{0}\Logo.png", UsuarioActual.CveEmpresa) + Dim logouri As String = String.Format("{0}://{1}:{2}/ashx/sigfiles.ashx?P={3}", Request.Url.Scheme, Request.Url.Host, Request.Url.Port, Encripta(LogoRutaFisica)) + Dim Imagen As New System.IO.FileInfo(String.Format("{0}Logo.png", UsuarioActual.Empresa.Ruta)) -#Region "TipoEntrega" + Dim params As New List(Of ReportParameter) + params.Add(New ReportParameter("LogoPath", If(Imagen.Exists, $"file://{Imagen.FullName}", ""))) + params.Add(New ReportParameter("NombreEmpresa", UsuarioActual.Empresa.Empresa)) + params.Add(New ReportParameter("UsuarioImprimio", UsuarioActual.Usuario)) - Protected Sub EntregaRadioGroup_Click(sender As Object, e As EventArgs) - If RbEntregaExterna.Checked Then - RegistraScript($"AbrirVentana('/General/PopUpPaqueteriasGuias.aspx?CveVenta={CveVentaSurtir}',800,547,'N')") - ElseIf RbEntregaInterna.Checked Then - 'RegistraScript("$('#ModalPaqueteriaInterna').modal('show')") - 'RegistraScript($"AbrirVentana('/General/PopUpPaqueteriasGuiasInternas.aspx?CveVenta={CveVentaSurtir}&CveSubProyecto={CveSubProyecto}',800,547,'N')") - 'CveVentaSurtir - ElseIf RbSinEntrega.Checked Then - LimpiaCampos() - End If - End Sub - - Protected Sub LimpiaCampos() - DdlEstatus.SelectedValue = "1" - TxtFechaPaqInterna.Text = "" - TxtFechaEstimada.Text = "" - TxtNoCajas.Text = "" - TxtObservacionesPaqInterna.Text = "" - UpPaqInterna.Update() - End Sub - Protected Sub PaqueteriaDetalle_Click(sender As Object, e As EventArgs) - If RbEntregaExterna.Checked Then - RegistraScript($"AbrirVentana('/General/PopUpPaqueteriasGuias.aspx?CveVenta={CveVentaSurtir}',800,547,'N')") - ElseIf RbEntregaInterna.Checked Then - 'RegistraScript("$('#ModalPaqueteriaInterna').modal('show')") - End If - End Sub -#End Region - -#Region "Cliente entrega personal" - Private Sub ClienteEntregaPersonal(CveCliente As Integer) - Dim ObjVentas As New ClsVentas() - If ObjVentas.GetClientesPersonalEntrega(-1, CveCliente, UsuarioActual.CveEmpresa, 1) Then - If ObjVentas.DtResultados.Rows.Count > 0 Then - GvClentesPersonalEntrega.DataSource = ObjVentas.DtResultados - GvClentesPersonalEntrega.DataBind() - DivPersonalEntrega.Visible = True - Else - DivPersonalEntrega.Visible = False - End If - End If - ObjVentas.Dispose() - UpClentesPersonalEntrega.Update() - End Sub -#End Region - -#Region "sugerir caducidad" - - Private Sub SugiereLoteCaducidad(CveAlmacen As Integer) - Dim TempDT As New DataTable - Dim DtLotesCaducidad As New DataTable - TempDT = DtDatos.Clone - Dim CvePSAnterior As Integer = 0 - Dim ObjInventarios As New ClsInventarios() - - For Each dr As DataRow In DtDatos.Rows - If CBool(dr("AplicaLote")) Then - If CvePSAnterior <> dr("CvePS").ToString.ToEntero Then - CvePSAnterior = dr("CvePS").ToString.ToEntero - - If ObjInventarios.GetExistenciasCaducidad(dr("CvePS").ToString.ToEntero, CveAlmacen, UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa) Then - DtLotesCaducidad.Merge(ObjInventarios.DtResultados) - - End If - End If - End If - Next - - ObjInventarios.Dispose() - - For Each dr As DataRow In DtDatos.Rows - If CBool(dr("AplicaLote")) Then - - Dim dtta As DataTable = DtLotesCaducidad.FiltraParametros(String.Format("CvePS = {0}", dr("CvePS"))) - - If dtta IsNot Nothing AndAlso dtta.Rows.Count > 0 Then - - 'recorre que cumplan con la cantidad total a llenar - Dim CantidadSurtir As Decimal = dr("CantidadF").ToString.ToDecimal - For Each drl As DataRow In dtta.Rows - If CantidadSurtir < drl("Cantidad").ToString.ToDecimal Then - dr("CantidadF") = CantidadSurtir - dr("CantidadC") = CantidadSurtir - dr("Lote") = drl("Lote") - dr("FechaCaducidad") = drl("FechaCaducidad") - TempDT.ImportRow(dr) - CantidadSurtir = 0 - Else - CantidadSurtir -= drl("Cantidad").ToString.ToDecimal - dr("CantidadF") = drl("Cantidad").ToString.ToDecimal - dr("CantidadC") = drl("Cantidad").ToString.ToDecimal - dr("Lote") = drl("Lote") - dr("FechaCaducidad") = drl("FechaCaducidad") - TempDT.ImportRow(dr) - End If - If CantidadSurtir <= 0 Then Exit For - Next - - Else - 'error, no hay lote sugerido - End If - Else - TempDT.ImportRow(dr) - End If - - Next - - - DtDatos = TempDT + ImprimirPDF("Empresas/Grales/Formatos/RepEntregaAlmacenSugerencia.rdlc", DtDatosSugerencias, params, "Equipo GPS") End Sub -#End Region +#End Region + +#Region "TipoEntrega" + + Protected Sub EntregaRadioGroup_Click(sender As Object, e As EventArgs) + If RbEntregaExterna.Checked Then + RegistraScript($"AbrirVentana('/General/PopUpPaqueteriasGuias.aspx?CveVenta={CveVentaSurtir}',800,547,'N')") + ElseIf RbEntregaInterna.Checked Then + 'RegistraScript("$('#ModalPaqueteriaInterna').modal('show')") + 'RegistraScript($"AbrirVentana('/General/PopUpPaqueteriasGuiasInternas.aspx?CveVenta={CveVentaSurtir}&CveSubProyecto={CveSubProyecto}',800,547,'N')") + 'CveVentaSurtir + ElseIf RbSinEntrega.Checked Then + LimpiaCampos() + End If + End Sub + + Protected Sub LimpiaCampos() + DdlEstatus.SelectedValue = "1" + TxtFechaPaqInterna.Text = "" + TxtFechaEstimada.Text = "" + TxtNoCajas.Text = "" + TxtObservacionesPaqInterna.Text = "" + UpPaqInterna.Update() + End Sub + Protected Sub PaqueteriaDetalle_Click(sender As Object, e As EventArgs) + If RbEntregaExterna.Checked Then + RegistraScript($"AbrirVentana('/General/PopUpPaqueteriasGuias.aspx?CveVenta={CveVentaSurtir}',800,547,'N')") + ElseIf RbEntregaInterna.Checked Then + 'RegistraScript("$('#ModalPaqueteriaInterna').modal('show')") + End If + End Sub +#End Region + +#Region "Cliente entrega personal" + Private Sub ClienteEntregaPersonal(CveCliente As Integer) + Dim ObjVentas As New ClsVentas() + If ObjVentas.GetClientesPersonalEntrega(-1, CveCliente, UsuarioActual.CveEmpresa, 1) Then + If ObjVentas.DtResultados.Rows.Count > 0 Then + GvClentesPersonalEntrega.DataSource = ObjVentas.DtResultados + GvClentesPersonalEntrega.DataBind() + DivPersonalEntrega.Visible = True + Else + DivPersonalEntrega.Visible = False + End If + End If + ObjVentas.Dispose() + UpClentesPersonalEntrega.Update() + End Sub +#End Region + +#Region "sugerir caducidad" + + Private Sub SugiereLoteCaducidad(CveAlmacen As Integer) + Dim TempDT As New DataTable + Dim DtLotesCaducidad As New DataTable + TempDT = DtDatos.Clone + Dim CvePSAnterior As Integer = 0 + Dim ObjInventarios As New ClsInventarios() + + For Each dr As DataRow In DtDatos.Rows + If CBool(dr("AplicaLote")) Then + If CvePSAnterior <> dr("CvePS").ToString.ToEntero Then + CvePSAnterior = dr("CvePS").ToString.ToEntero + + If ObjInventarios.GetExistenciasCaducidad(dr("CvePS").ToString.ToEntero, CveAlmacen, UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa) Then + DtLotesCaducidad.Merge(ObjInventarios.DtResultados) + + End If + End If + End If + Next + + ObjInventarios.Dispose() + + For Each dr As DataRow In DtDatos.Rows + If CBool(dr("AplicaLote")) Then + + Dim dtta As DataTable = DtLotesCaducidad.FiltraParametros(String.Format("CvePS = {0}", dr("CvePS"))) + + If dtta IsNot Nothing AndAlso dtta.Rows.Count > 0 Then + + 'recorre que cumplan con la cantidad total a llenar + Dim CantidadSurtir As Decimal = dr("CantidadF").ToString.ToDecimal + For Each drl As DataRow In dtta.Rows + If CantidadSurtir < drl("Cantidad").ToString.ToDecimal Then + dr("CantidadF") = CantidadSurtir + dr("CantidadC") = CantidadSurtir + dr("Lote") = drl("Lote") + dr("FechaCaducidad") = drl("FechaCaducidad") + TempDT.ImportRow(dr) + CantidadSurtir = 0 + Else + CantidadSurtir -= drl("Cantidad").ToString.ToDecimal + dr("CantidadF") = drl("Cantidad").ToString.ToDecimal + dr("CantidadC") = drl("Cantidad").ToString.ToDecimal + dr("Lote") = drl("Lote") + dr("FechaCaducidad") = drl("FechaCaducidad") + TempDT.ImportRow(dr) + End If + If CantidadSurtir <= 0 Then Exit For + Next + + Else + 'error, no hay lote sugerido + End If + Else + TempDT.ImportRow(dr) + End If + + Next + + + DtDatos = TempDT + End Sub + +#End Region 'Protected void LnkEditarDir_Click(Object sender, EventArgs e) @@ -4522,52 +4522,52 @@ Partial Class Inventarios_EntregaAlmacen - Protected Sub LnkEditarDir_Click(sender As Object, e As EventArgs) - - HdnCveVenta.Value = CveVentaSurtir.ToString - CargaModalCombosDirecciones(CveCliente, CveDireccionEnvio) - - RegistraScript("$('#DivEditarEntrega').modal({backdrop: 'static', keyboard: false});") - - End Sub - - - Private Sub CargaModalCombosDirecciones(CveCliente As Integer, CveDireccionEnvio As Integer) - - DdlModalDireccionEnvio.Items.Clear() - - Dim dtt As New DataTable() - Dim ObjClientes As New ClsClientes() - If (ObjClientes.DireccionEnvioGet(-1, CveCliente, -1)) Then - dtt = ObjClientes.DtResultados - End If - ObjClientes.Dispose() - - DdlModalDireccionEnvio.DataSource = dtt - DdlModalDireccionEnvio.DataBind() - DdlModalDireccionEnvio.SelectedValueExist(CveDireccionEnvio) - UpModalEditarentrega.Update() - dtt.Dispose() - - End Sub - - - Protected Sub BtnModalEditarentrega_Click(sender As Object, e As EventArgs) - Dim ProcesoOK As Boolean = True - - Dim ObjVentas As New ClsVentas() - If Not ObjVentas.UpdateDireccionEnvioVenta(HdnCveVenta.Value.ToEntero(), DdlModalDireccionEnvio.SelectedValue.ToEntero(), UsuarioActual.CveEmpresa) Then - ProcesoOK = False - End If - ObjVentas.Dispose() - - If ProcesoOK Then - RegistraScript("$('#DivEditarEntrega').modal('hide');") - Alert("Dirección Actualizada correctamente.", ModExtensiones.TipoMensaje.ToastInformacion) - 'CargaDatos() - End If - - + Protected Sub LnkEditarDir_Click(sender As Object, e As EventArgs) + + HdnCveVenta.Value = CveVentaSurtir.ToString + CargaModalCombosDirecciones(CveCliente, CveDireccionEnvio) + + RegistraScript("$('#DivEditarEntrega').modal({backdrop: 'static', keyboard: false});") + + End Sub + + + Private Sub CargaModalCombosDirecciones(CveCliente As Integer, CveDireccionEnvio As Integer) + + DdlModalDireccionEnvio.Items.Clear() + + Dim dtt As New DataTable() + Dim ObjClientes As New ClsClientes() + If (ObjClientes.DireccionEnvioGet(-1, CveCliente, -1)) Then + dtt = ObjClientes.DtResultados + End If + ObjClientes.Dispose() + + DdlModalDireccionEnvio.DataSource = dtt + DdlModalDireccionEnvio.DataBind() + DdlModalDireccionEnvio.SelectedValueExist(CveDireccionEnvio) + UpModalEditarentrega.Update() + dtt.Dispose() + + End Sub + + + Protected Sub BtnModalEditarentrega_Click(sender As Object, e As EventArgs) + Dim ProcesoOK As Boolean = True + + Dim ObjVentas As New ClsVentas() + If Not ObjVentas.UpdateDireccionEnvioVenta(HdnCveVenta.Value.ToEntero(), DdlModalDireccionEnvio.SelectedValue.ToEntero(), UsuarioActual.CveEmpresa) Then + ProcesoOK = False + End If + ObjVentas.Dispose() + + If ProcesoOK Then + RegistraScript("$('#DivEditarEntrega').modal('hide');") + Alert("Dirección Actualizada correctamente.", ModExtensiones.TipoMensaje.ToastInformacion) + 'CargaDatos() + End If + + End Sub Private Function CierreOS(CveOSCerrar As Integer, CveMovimientoGenerado As Integer, ByRef TransaccionSql As SqlTransaction) As Boolean @@ -4657,8 +4657,8 @@ Partial Class Inventarios_EntregaAlmacen Return Respuesta - End Function - + End Function + Private Function CancelarPedido(ByRef TransaccionSql As SqlTransaction, CveMovimientoGenerado As Integer, ByRef RespuestaPadre As Boolean) As Boolean Dim Cancelar As Boolean = True @@ -4777,4 +4777,4 @@ Partial Class Inventarios_EntregaAlmacen End Sub -End Class +End Class diff --git a/Inventarios/RepNotasSinAlmacen.aspx b/Inventarios/RepNotasSinAlmacen.aspx index f047680e6..0eb7ee138 100644 --- a/Inventarios/RepNotasSinAlmacen.aspx +++ b/Inventarios/RepNotasSinAlmacen.aspx @@ -79,7 +79,7 @@
    - +
    @@ -136,11 +136,11 @@
    - <%--
    Sucursal:
    -
    - - - + <%--
    Sucursal:
    +
    + + +
    --%>
    @@ -243,51 +243,51 @@ - <%-- - + --%> diff --git a/OC/PopUpBuscarReq.aspx.vb b/OC/PopUpBuscarReq.aspx.vb index 0ba324f3a..64e17073b 100644 --- a/OC/PopUpBuscarReq.aspx.vb +++ b/OC/PopUpBuscarReq.aspx.vb @@ -196,8 +196,15 @@ Partial Class OC_PopUpBuscarReq Folio = Array(2).ToEntero End If Else + Serie = "-1" - Folio = TxtFolio.Text.Trim.ToEntero + Folio = -1 + + If TxtFolio.Text.Trim.ToEntero > 0 Then + Folio = TxtFolio.Text.Trim.ToEntero + Else + Serie = TxtFolio.Text.Trim + End If End If End If diff --git a/OS/OrdenesServicios.aspx.vb b/OS/OrdenesServicios.aspx.vb index 6c78b4994..bebbd24ad 100644 --- a/OS/OrdenesServicios.aspx.vb +++ b/OS/OrdenesServicios.aspx.vb @@ -479,8 +479,16 @@ Partial Class OS_OrdenesServicios End If End If - If TipoEstatus.Contiene(1, 2, 3, 4) And CveVenta <= 0 And (UsuarioActual.TienePermisoProceso(370) Or UsuarioActual.TienePermisoProceso(382)) Then + If TipoEstatus.Contiene(1, 2, 3) And CveVenta <= 0 And (UsuarioActual.TienePermisoProceso(370) Or UsuarioActual.TienePermisoProceso(382)) Then BtnCancelar.Visible = True + ElseIf TipoEstatus.Contiene(4) And (UsuarioActual.TienePermisoProceso(370) Or UsuarioActual.TienePermisoProceso(382)) Then + BtnCancelar.Visible = False + BtnGuardar.Visible = True + DdlEstatusOS.Enabled = False + ElseIf TipoEstatus.Contiene(5) And (UsuarioActual.TienePermisoProceso(370) Or UsuarioActual.TienePermisoProceso(382)) Then + BtnCancelar.Visible = False + BtnGuardar.Visible = False + DdlEstatusOS.Enabled = False Else BtnGuardar.Visible = False End If