-- mejoras en tipos de venta

This commit is contained in:
2024-09-20 12:32:10 -07:00
parent 0d4add5d3c
commit 4ed9e71aeb

View File

@@ -454,7 +454,7 @@ Partial Class OS_OrdenesServicios
End If End If
End If End If
If UsuarioActual.Empresa.Funcionalidad(578).ToEntero = 1 Then If UsuarioActual.Empresa.Funcionalidad(578) = "1" Then
BtnCancelar.Text = "Cancelar Cirugía" BtnCancelar.Text = "Cancelar Cirugía"
HplRegresar.NavigateUrl = "/OS/RepOSMedicas.aspx" HplRegresar.NavigateUrl = "/OS/RepOSMedicas.aspx"
@@ -2980,57 +2980,55 @@ Partial Class OS_OrdenesServicios
End Sub End Sub
Protected Sub LnkAccionesMaterialUtilizado_Click(sender As Object, e As EventArgs) Protected Sub LnkAccionesMaterialUtilizado_Click(sender As Object, e As EventArgs)
If UsuarioActual.Empresa.Funcionalidad(578) = "1" Then
LnkModalMaterialUtilizado.Visible = True LnkModalMaterialUtilizado.Visible = True
DTSolicitudDev = New DataTable DTSolicitudDev = New DataTable
Dim Opcion As Integer = If(DdlTipoVenta.SelectedValue.Contiene("2", "3"), 2, 1) Dim Opcion As Integer = If(DdlTipoVenta.SelectedValue.Contiene("2", "3"), 2, 1)
Select Case DdlTipoVenta.SelectedValue.ToEntero
Case 1, 2 ' *Fuera de liena *pago directo
Opcion = 1
Case 3 ' por el momento ya no se usa
Opcion = 2
Case 5 ' consignacion uso
Opcion = 3
Case 6 ' a vista uso de material
Opcion = 4
Case Else
Opcion = 1
End Select
Select Case DdlTipoVenta.SelectedValue.ToEntero Dim ObjOS As New ClsOS
Case 1, 2 ' *Fuera de liena *pago directo If ObjOS.GetOrdenesServicioDevolucionMaterial(CveOS, If(UsuarioActual.Empresa.Funcionalidad(578) = "1", CvePedido, CveVenta), Opcion, UsuarioActual.CveEmpresa) Then
Opcion = 1 DTSolicitudDev = ObjOS.DtResultados
Case 3 ' por el momento ya no se usa GvMU.DataSource = DTSolicitudDev
Opcion = 2 GvMU.Columns(3).Visible = DTSolicitudDev.MIN("Serie") <> ""
Case 5 ' consignacion uso GvMU.Columns(4).Visible = DTSolicitudDev.MIN("Lote") <> ""
Opcion = 3 GvMU.Columns(5).Visible = DTSolicitudDev.MIN("FechaCaducidad") <> ""
Case 6 ' a vista uso de material End If
Opcion = 4 ObjOS.Dispose()
Case Else GvMU.DataBind()
Opcion = 1
End Select
Dim ObjOS As New ClsOS Dim EsDevolucionVenta As Boolean = (DTSolicitudDev.FiltroPrimeroValor("EsDevolucionVenta", "").ToEntero > 0)
If ObjOS.GetOrdenesServicioDevolucionMaterial(CveOS, If(UsuarioActual.Empresa.Funcionalidad(578).ToEntero = 1, CvePedido, CveVenta), Opcion, UsuarioActual.CveEmpresa) Then
DTSolicitudDev = ObjOS.DtResultados
GvMU.DataSource = DTSolicitudDev
GvMU.Columns(3).Visible = DTSolicitudDev.MIN("Serie") <> ""
GvMU.Columns(4).Visible = DTSolicitudDev.MIN("Lote") <> ""
GvMU.Columns(5).Visible = DTSolicitudDev.MIN("FechaCaducidad") <> ""
End If
ObjOS.Dispose()
GvMU.DataBind()
Dim EsDevolucionVenta As Boolean = (DTSolicitudDev.FiltroPrimeroValor("EsDevolucionVenta", "").ToEntero > 0) RegistraScript("$('#DivModalMaterialUtilizado').modal();")
RegistraScript("$('#DivModalMaterialUtilizado').modal();") If EsDevolucionVenta Then
Alert("En la orden de servicio ya se determinó el material utilizado.", TipoMensaje.MsgAdvertencia)
LnkModalMaterialUtilizado.Visible = False
End If
If EsDevolucionVenta Then
Alert("En la orden de servicio ya se determinó el material utilizado.", TipoMensaje.MsgAdvertencia)
LnkModalMaterialUtilizado.Visible = False
End If
If UsuarioActual.Empresa.Funcionalidad(578).ToEntero = 1 Then
TxtPacienteModal.Text = TxtPaciente.Text TxtPacienteModal.Text = TxtPaciente.Text
TxtEpisodioModal.Text = TxtIdentificadorCliente.Text TxtEpisodioModal.Text = TxtIdentificadorCliente.Text
TxtFolioRemisionModal.Text = TxtFolioAdicional.Text TxtFolioRemisionModal.Text = TxtFolioAdicional.Text
End If
If DdlTipoVenta.SelectedValue.ToEntero = 5 Then If DdlTipoVenta.SelectedValue.ToEntero = 5 Then
DvTxtFolioRemisionModal.Visible = False DvTxtFolioRemisionModal.Visible = False
Else Else
DvTxtFolioRemisionModal.Visible = True DvTxtFolioRemisionModal.Visible = True
End If
End If End If
UpModalMaterialUtilizado.Update() UpModalMaterialUtilizado.Update()
End Sub End Sub
@@ -3048,7 +3046,10 @@ Partial Class OS_OrdenesServicios
Dim ProcesoOK As Boolean = True Dim ProcesoOK As Boolean = True
If UsuarioActual.Empresa.Funcionalidad(578).ToEntero = 1 Then If UsuarioActual.Empresa.Funcionalidad(578) = "1" Then
Dim CveAlmacenDestino As Integer = -1
Dim CveSubProyectoPedido As Integer
'---------------- INICIO VALIDACIONES -----------------
If TxtPacienteModal.Text.Trim.Length = 0 Then If TxtPacienteModal.Text.Trim.Length = 0 Then
Alert("Debe de proporcionar el paciente.", TipoMensaje.MsgAdvertencia) Alert("Debe de proporcionar el paciente.", TipoMensaje.MsgAdvertencia)
Exit Sub Exit Sub
@@ -3058,350 +3059,349 @@ Partial Class OS_OrdenesServicios
Alert("Debe de proporcionar el episodio.", TipoMensaje.MsgAdvertencia) Alert("Debe de proporcionar el episodio.", TipoMensaje.MsgAdvertencia)
Exit Sub Exit Sub
End If End If
End If
Dim TieneArchivos As Boolean = False Dim TieneArchivos As Boolean = False
Dim Filesgral As List(Of Archivo) = AnexoManerialUtilizado.getfiles().Archivos Dim Filesgral As List(Of Archivo) = AnexoManerialUtilizado.getfiles().Archivos
For Each fileItem As Archivo In Filesgral For Each fileItem As Archivo In Filesgral
TieneArchivos = True TieneArchivos = True
Exit For Exit For
Next Next
If Not TieneArchivos Then If Not TieneArchivos Then
Alert("Debe de agregar un documento de confirmación (5 máximo).") Alert("Debe de agregar un documento de confirmación (5 máximo).")
Exit Sub Exit Sub
End If End If
Dim CveAlmacenActual As Integer = DTSolicitudDev.FiltroPrimeroValor("CveAlmacenActual").ToEntero
Dim CveMoneda As Integer = DTSolicitudDev.FiltroPrimeroValor("CveMoneda").ToEntero
Dim CveSubProyectoPedido As Integer = DTSolicitudDev.FiltroPrimeroValor("CveSubProyecto").ToEntero
Dim CveVentaPedido As Integer = DTSolicitudDev.FiltroPrimeroValor("CveVenta").ToEntero
Dim CveAlmacenDestino As Integer = GlobalDTAlmacen(UsuarioActual.CveEmpresa, 10).FiltroPrimeroValor("CveAlmacen", $"CveSubProyecto = {CveSubProyectoPedido}").ToEntero
Dim CveVentaRemisionGenerada As Integer = -1
If DdlTipoVenta.SelectedValue.ToEntero = 5 Then
Dim TotalSeleccionado As Decimal = 0 Dim TotalSeleccionado As Decimal = 0
For Each GVRow As GridViewRow In GvMU.Rows For Each GVRow As GridViewRow In GvMU.Rows
TotalSeleccionado = TotalSeleccionado + GVRow.FCTextBox("TxtUtilizado").Text.ToDecimal TotalSeleccionado = TotalSeleccionado + GVRow.FCTextBox("TxtUtilizado").Text.ToDecimal
Next Next
If TotalSeleccionado = 0 Then
Alert("No se seleccionó ningun material", TipoMensaje.MsgAdvertencia)
Exit Sub
End If
Else
If Not CveAlmacenDestino > 0 Then If DdlTipoVenta.SelectedValue = "5" Then
Alert("No se encontró almacen de entrega por adelantado", TipoMensaje.MsgAdvertencia) If TotalSeleccionado = 0 Then
Exit Sub Alert("No se seleccionó ningun material", TipoMensaje.MsgAdvertencia)
End If Exit Sub
End If
Dim ObjV As New ClsVentas
Dim ObjOS As New ClsOS(ObjV.IniciaTransacSQL())
Dim ObjInventario As New ClsInventarios(ObjV.IniciaTransacSQL())
Dim ObjConta As New ClsContabilidad(ObjV.IniciaTransacSQL())
Dim GenerarRemisionMovimientos As Boolean = False
If DdlTipoVenta.SelectedValue = "5" Then 'Consignación - Uso Material
'genera una salida de almacen.
Dim Fecha As DateTime = ClsPaginas.NowADS()
Dim CveMovimientoSalida As Integer = ObjInventario.AddMovimiento(CveAlmacenActual, 8, CveMoneda, Fecha, -1, UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa, -1, CveVenta, CveSubProyectoPedido, -1, CveOS:=CveOS, CveAlmacenDestino:=CveAlmacenDestino, Modulo:="OS/MatUtilConsig")
Dim Folio As Integer = ObjInventario.Folio
If CveMovimientoSalida > 0 Then
For Each GVRow As GridViewRow In GvMU.Rows
Dim CantidadRegistro As Decimal = GVRow.FCTextBox("TxtUtilizado").Text.ToDecimal
Dim CvePS As Integer = GVRow.DataKey("CvePS").ToEntero
If CantidadRegistro > 0 Then
Dim Serie As String = GVRow.DataKey("Serie")
Dim Lote As String = GVRow.DataKey("Lote")
Dim CveUM As Integer = GVRow.DataKey("CveUM").ToEntero
Dim FechaCaducidad As DateTime = GVRow.DataKey("FechaCaducidad").ToDate
If Not ObjInventario.AddMovimientoDetalle(CveMovimientoSalida, CantidadRegistro, CveUM, CvePS, 0, Lote:=Lote, Serie:=Serie, FechaCaducidad:=FechaCaducidad) Then
Alert("Error al agregar detalle de movimiento.", TipoMensaje.MsgAdvertencia)
ProcesoOK = False
Exit For
End If
End If
Next
If ProcesoOK Then
Dim CveOSEstatusFinalizada As Integer = GlobalDTEstatusOrdenServicios(UsuarioActual.CveEmpresa).FiltroPrimeroValor("CveEstatusOrdenServicio", "TipoEstatus = 4").ToEntero
If CveOSEstatusFinalizada > 0 Then
If Not ObjOS.UpdateOrdenesServiciosEstatus(CveOSEstatusFinalizada, UsuarioActual.CveUsuario, CveOS) Then
ProcesoOK = False
End If
Else
Alert("No se pudo obtener el estado para finalizar la orden de servicio.")
ProcesoOK = False
End If
End If
If ProcesoOK Then
Dim Contabilizable As Boolean = False
Dim Concepto As String = "Material utilizado Consigna"
Dim CvePrePoliza As Integer = ObjConta.AddPrePolizas("OS-MatUtil5", 53, 0, 0, 1, Fecha, Concepto, UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa)
Dim ImporteAlmacen As Decimal = 0
If CveMovimientoSalida > 0 Then
If ObjInventario.GetMovimientosDetalle(CveMovimientoSalida, UsuarioActual.CveEmpresa) AndAlso ObjInventario.DtResultados.Rows.Count > 0 Then
ImporteAlmacen = ObjInventario.DtResultados.SUM("Total")
End If
If Not ObjConta.AddPrePolizasDetalle(CvePrePoliza, True, ImporteAlmacen, ImporteAlmacen, 68, "", Concepto, CveMovimientoAlmacen:=CveMovimientoSalida, Contabilizable:=Contabilizable) Then
ProcesoOK = False
End If
If Not ObjConta.AddPrePolizasDetalle(CvePrePoliza, False, ImporteAlmacen, ImporteAlmacen, 95, "", Concepto, CveMovimientoAlmacen:=CveMovimientoSalida, Contabilizable:=Contabilizable) Then
ProcesoOK = False
End If
End If
End If End If
Else Else
ProcesoOK = False CveSubProyectoPedido = DTSolicitudDev.FiltroPrimeroValor("CveSubProyecto").ToEntero
CveAlmacenDestino = GlobalDTAlmacen(UsuarioActual.CveEmpresa, 10).FiltroPrimeroValor("CveAlmacen", $"CveSubProyecto = {CveSubProyectoPedido}").ToEntero
If Not CveAlmacenDestino > 0 Then
Alert("No se encontró almacen de entrega por adelantado", TipoMensaje.MsgAdvertencia)
Exit Sub
End If
End If End If
If TotalSeleccionado > 0 AndAlso Not TxtFolioRemisionModal.Text.Trim.Length > 0 Then
Alert("El campo Folio es requerido por favor ingréselo.", TipoMensaje.MsgAdvertencia)
Exit Sub
End If
Dim DT_Ventas_Detalles As DataTable = DTSolicitudDev.FiltraParametros("", "", {"CantidadPedido", "CvePS", "CveVentaDetalle"}) '---------------- FIN VALIDACIONES -----------------
DT_Ventas_Detalles.Columns.Add("CantidadUsada", GetType(Decimal))
DT_Ventas_Detalles.AcceptChanges()
For Each dRow As DataRow In DT_Ventas_Detalles.Rows Dim CveAlmacenActual As Integer = DTSolicitudDev.FiltroPrimeroValor("CveAlmacenActual").ToEntero
Dim CveMoneda As Integer = DTSolicitudDev.FiltroPrimeroValor("CveMoneda").ToEntero
For Each gvRow As GridViewRow In GvMU.Rows Dim CveVentaPedido As Integer = DTSolicitudDev.FiltroPrimeroValor("CveVenta").ToEntero
Dim CveVentaRemisionGenerada As Integer = -1
Dim CantidadUsada As Decimal = gvRow.FCTextBox("TxtUtilizado").Text.ToDecimal Dim ObjV As New ClsVentas
Dim ObjOS As New ClsOS(ObjV.IniciaTransacSQL())
Dim ObjInventario As New ClsInventarios(ObjV.IniciaTransacSQL())
Dim ObjConta As New ClsContabilidad(ObjV.IniciaTransacSQL())
Dim GenerarRemisionMovimientos As Boolean = False
If dRow("CvePS").ToString.ToDecimal = gvRow.DataKey("CvePS").ToDecimal AndAlso CantidadUsada > 0 Then If DdlTipoVenta.SelectedValue = "5" Then 'Consignación - Uso Material
'genera una salida de almacen.
Dim Fecha As DateTime = ClsPaginas.NowADS()
Dim CveMovimientoSalida As Integer = ObjInventario.AddMovimiento(CveAlmacenActual, 8, CveMoneda, Fecha, -1, UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa, -1, CveVenta, CveSubProyectoPedido, -1, CveOS:=CveOS, CveAlmacenDestino:=CveAlmacenDestino, Modulo:="OS/MatUtilConsig")
Dim Folio As Integer = ObjInventario.Folio
dRow("CantidadUsada") = dRow("CantidadUsada").ToString.ToDecimal + CantidadUsada If CveMovimientoSalida > 0 Then
For Each GVRow As GridViewRow In GvMU.Rows
Dim CantidadRegistro As Decimal = GVRow.FCTextBox("TxtUtilizado").Text.ToDecimal
Dim CvePS As Integer = GVRow.DataKey("CvePS").ToEntero
End If If CantidadRegistro > 0 Then
Next Dim Serie As String = GVRow.DataKey("Serie")
Dim Lote As String = GVRow.DataKey("Lote")
Next Dim CveUM As Integer = GVRow.DataKey("CveUM").ToEntero
Dim FechaCaducidad As DateTime = GVRow.DataKey("FechaCaducidad").ToDate
For Each dRow As DataRow In DT_Ventas_Detalles.Rows If Not ObjInventario.AddMovimientoDetalle(CveMovimientoSalida, CantidadRegistro, CveUM, CvePS, 0, Lote:=Lote, Serie:=Serie, FechaCaducidad:=FechaCaducidad) Then
Dim CantidadUsada As Decimal = dRow("CantidadUsada").ToString.ToDecimal Alert("Error al agregar detalle de movimiento.", TipoMensaje.MsgAdvertencia)
If dRow("CantidadUsada").ToString.ToDecimal < dRow("CantidadPedido").ToString.ToDecimal Then ProcesoOK = False
If Not ObjInventario.UpdatePedidoDetalleCantidad(dRow("CveVentaDetalle").ToString.ToEntero, CantidadUsada, 2) Then Exit For
ProcesoOK = False End If
Exit For End If
End If Next
End If If ProcesoOK Then
Next Dim CveOSEstatusFinalizada As Integer = GlobalDTEstatusOrdenServicios(UsuarioActual.CveEmpresa).FiltroPrimeroValor("CveEstatusOrdenServicio", "TipoEstatus = 4").ToEntero
If CveOSEstatusFinalizada > 0 Then
If Not ObjOS.UpdateOrdenesServiciosEstatus(CveOSEstatusFinalizada, UsuarioActual.CveUsuario, CveOS) Then
Else ProcesoOK = False
If ProcesoOK Then End If
Dim AplicaDevolucion As Boolean = False Else
For Each GvRow As GridViewRow In GvMU.Rows Alert("No se pudo obtener el estado para finalizar la orden de servicio.")
Dim CveVentaDetalle As Integer = GvRow.DataKey("CveVentaDetalle").ToEntero
Dim CantidadDev As Decimal = GvRow.DataKey("Cantidad").ToDecimal - GvRow.FCTextBox("TxtUtilizado").Text.ToDecimal
If CantidadDev > 0 AndAlso CveVentaDetalle > 0 Then
AplicaDevolucion = True
If Not ObjV.UpdateVentasDetalleCantidadDevolucion(CveVentaDetalle, CantidadDev) Then
ProcesoOK = False ProcesoOK = False
GenerarRemisionMovimientos = False
AplicaDevolucion = False
Exit For
End If End If
End If End If
If ProcesoOK Then
If GvRow.FCTextBox("TxtUtilizado").Text.ToDecimal > 0 Then Dim Contabilizable As Boolean = False
GenerarRemisionMovimientos = True Dim Concepto As String = "Material utilizado Consigna"
End If Dim CvePrePoliza As Integer = ObjConta.AddPrePolizas("OS-MatUtil5", 53, 0, 0, 1, Fecha, Concepto, UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa)
Next Dim ImporteAlmacen As Decimal = 0
If AplicaDevolucion Then If CveMovimientoSalida > 0 Then
If Not ObjV.UpdateVentasDevolucionAlmacen(1, CveVentaPedido) Then If ObjInventario.GetMovimientosDetalle(CveMovimientoSalida, UsuarioActual.CveEmpresa) AndAlso ObjInventario.DtResultados.Rows.Count > 0 Then
ProcesoOK = False ImporteAlmacen = ObjInventario.DtResultados.SUM("Total")
End If
End If
End If
'ProcesoOK = False
Dim Respuesta As New RespuestaFacturacion()
Dim DtVentaDetalle As New DataTable
Dim CveMovimientoSalida, CveMovimientoEntrada As Integer
Dim ImporteAlmacen As Decimal
Dim Fecha As DateTime = ClsPaginas.NowADS()
If GenerarRemisionMovimientos AndAlso ProcesoOK Then
If Not TxtFolioRemisionModal.Text.Trim.Length > 0 Then
Alert("El campo Folio es requerido por favor ingréselo.", TipoMensaje.MsgAdvertencia)
ProcesoOK = False
GenerarRemisionMovimientos = False
End If
End If
If GenerarRemisionMovimientos AndAlso ProcesoOK Then
Respuesta = GeneraRemision(CveVentaPedido, ObjV.IniciaTransacSQL())
If Respuesta.CveVenta > 0 Then
CveVentaRemisionGenerada = Respuesta.CveVenta
If ObjV.GetVentaDetalle(Respuesta.CveVenta) Then
Dim dtClon As DataTable = ObjV.DtResultados.Copy
dtClon.DefaultView.Sort = "CveVentaDetalle ASC"
Dim dtmat As DataTable = dtClon.DefaultView.ToTable()
'una vez registrada, asocia los lotes/cad con el cveventadetalle para que se surta así
DtVentaDetalle = Respuesta.dtdetalle
For i = 0 To dtmat.Rows.Count - 1
If DtVentaDetalle.Rows(i)("CvePS").ToString = dtmat.Rows(i)("CvePS").ToString Then
DtVentaDetalle.Rows(i)("CveVentaDetalle") = dtmat.Rows(i)("CveVentaDetalle")
DtVentaDetalle.Rows(i)("CveUM") = dtmat.Rows(i)("CveUM")
End If End If
Next If Not ObjConta.AddPrePolizasDetalle(CvePrePoliza, True, ImporteAlmacen, ImporteAlmacen, 68, "", Concepto, CveMovimientoAlmacen:=CveMovimientoSalida, Contabilizable:=Contabilizable) Then
ProcesoOK = False
End If
If Not ObjConta.AddPrePolizasDetalle(CvePrePoliza, False, ImporteAlmacen, ImporteAlmacen, 95, "", Concepto, CveMovimientoAlmacen:=CveMovimientoSalida, Contabilizable:=Contabilizable) Then
ProcesoOK = False
End If
End If
End If
'asigno la cveventa, como concluido
If ProcesoOK Then
If Not ObjOS.UpdateVentaOS(CveVenta, CveOS, UsuarioActual.CveEmpresa, TxtPacienteModal.Text.Trim, TxtEpisodioModal.Text.Trim, FolioAdicional:=TxtFolioRemisionModal.Text.Trim) Then
ProcesoOK = False
End If
End If End If
Else Else
ProcesoOK = False ProcesoOK = False
End If End If
End If
If GenerarRemisionMovimientos AndAlso ProcesoOK Then Dim DT_Ventas_Detalles As DataTable = DTSolicitudDev.FiltraParametros("", "", {"CantidadPedido", "CvePS", "CveVentaDetalle"})
DT_Ventas_Detalles.Columns.Add("CantidadUsada", GetType(Decimal))
DT_Ventas_Detalles.AcceptChanges()
CveMovimientoSalida = ObjInventario.AddMovimiento(CveAlmacenActual, 8, CveMoneda, Fecha, -1, UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa, -1, Respuesta.CveVenta, CveSubProyectoPedido, -1, CveOS:=CveOS, CveAlmacenDestino:=CveAlmacenDestino, Modulo:="OS/MatUtil3") For Each dRow As DataRow In DT_Ventas_Detalles.Rows
Dim Folio As Integer = ObjInventario.Folio For Each gvRow As GridViewRow In GvMU.Rows
Dim CantidadUsada As Decimal = gvRow.FCTextBox("TxtUtilizado").Text.ToDecimal
If dRow("CvePS").ToString.ToDecimal = gvRow.DataKey("CvePS").ToDecimal AndAlso CantidadUsada > 0 Then
dRow("CantidadUsada") = dRow("CantidadUsada").ToString.ToDecimal + CantidadUsada
End If
Next
Next
If CveMovimientoSalida > 0 Then For Each dRow As DataRow In DT_Ventas_Detalles.Rows
Dim CantidadUsada As Decimal = dRow("CantidadUsada").ToString.ToDecimal
If dRow("CantidadUsada").ToString.ToDecimal < dRow("CantidadPedido").ToString.ToDecimal Then
If Not ObjInventario.UpdatePedidoDetalleCantidad(dRow("CveVentaDetalle").ToString.ToEntero, CantidadUsada, 2) Then
ProcesoOK = False
Exit For
End If
End If
Next
Else
'' otros opciones <> 5
If ProcesoOK Then
Dim IndexMov1 As Integer = 0 Dim AplicaDevolucion As Boolean = False
For Each drr As DataRow In DtVentaDetalle.Rows Dim StrCveVentasDetalle As New StringBuilder
For Each GvRow As GridViewRow In GvMU.Rows
Dim CveVentaDetalle As Integer = GvRow.DataKey("CveVentaDetalle").ToEntero
Dim CantidadDev As Decimal = GvRow.DataKey("Cantidad").ToDecimal - GvRow.FCTextBox("TxtUtilizado").Text.ToDecimal
StrCveVentasDetalle.AppendFormat("{0},", CveVentaDetalle)
Dim Cantidad As Decimal = drr("Cantidad").ToString.ToDecimal If CantidadDev > 0 AndAlso CveVentaDetalle > 0 Then
'Dim CantidadRegistro As Decimal = GvRow.FCTextBox("TxtUtilizado").Text.ToDecimal AplicaDevolucion = True
Dim CvePS As Integer = drr("CvePS").ToString.ToEntero If Not ObjV.UpdateVentasDetalleCantidadDevolucion(CveVentaDetalle, CantidadDev) Then
Dim CveUM As Integer = drr("CveUM").ToString.ToEntero
Dim PU As Decimal = drr("PU").ToString.ToDecimal
If Cantidad > 0 Then
Dim CveVentaDetalle As Integer = drr("CveVentaDetalle").ToString.ToEntero 'DtVentaDetalle.FiltroPrimeroValor("CveVentaDetalle", $"CveVentaDetallePadre = {GvRow.DataKey("CveVentaDetalle")}").ToEntero
Dim CveMovimientoDetalle As Integer = -1 'GvRow.DataKey("CveMovimientoDetalle").ToEntero
If CveVentaDetalle <= 0 Then
Alert("Error al agregar detalle de movimiento.", TipoMensaje.MsgAdvertencia)
ProcesoOK = False
Exit For
End If
Dim Serie As String = drr("Serie").ToString
Dim Lote As String = drr("Lote").ToString
Dim FechaCaducidad As DateTime = drr("FechaCaducidad").ToString.ToDate
If Not ObjInventario.AddMovimientoDetalle(CveMovimientoSalida, Cantidad, CveUM, CvePS, PU, CveVentaDetalle:=CveVentaDetalle, CveMovimientoDetalleEntrada:=CveMovimientoDetalle, Lote:=Lote, Serie:=Serie, FechaCaducidad:=FechaCaducidad) Then
Alert("Error al agregar detalle de movimiento.", TipoMensaje.MsgAdvertencia)
ProcesoOK = False ProcesoOK = False
GenerarRemisionMovimientos = False
AplicaDevolucion = False
Exit For Exit For
End If End If
End If End If
IndexMov1 = IndexMov1 + 1 If GvRow.FCTextBox("TxtUtilizado").Text.ToDecimal > 0 Then
GenerarRemisionMovimientos = True
End If
Next Next
If AplicaDevolucion Then
If Not ObjV.UpdateVentasDevolucionAlmacen(1, CveVentaPedido) Then
ProcesoOK = False
End If
End If
' obtiene las ventasdetalle del pedido/rem, para recorrerlas y si hay alguna solo solicitada pero no surtida, que no siga pendiente de surtir.
If ProcesoOK AndAlso ObjV.GetVentaDetalle(CveVentaPedido) Then
Dim DtVentasDetalle As DataTable = ObjV.DtResultados
Dim dtt As DataTable = DtVentasDetalle.FiltraParametros($"CveVentaDetalle NOT IN ({StrCveVentasDetalle.ToString} -1)")
For Each dr As DataRow In dtt.Rows
ObjInventario.UpdateEstatusAlmacen(dr("CveVentaDetalle").ToString.ToEntero, 1) 'para no surtirse
Next
End If
End If
If ProcesoOK Then Dim Respuesta As New RespuestaFacturacion()
Dim DtVentaDetalle As New DataTable
Dim CveMovimientoSalida, CveMovimientoEntrada As Integer
Dim ImporteAlmacen As Decimal
Dim Fecha As DateTime = ClsPaginas.NowADS()
CveMovimientoEntrada = ObjInventario.AddMovimiento(CveAlmacenDestino, 9, CveMoneda, Fecha, -1, UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa, -1, Respuesta.CveVenta, CveSubProyectoPedido, -1, CveOS:=CveOS, CveMovimientoRelacionado:=CveMovimientoSalida, Modulo:="OS/MatUtil2") If GenerarRemisionMovimientos AndAlso ProcesoOK Then
Respuesta = GeneraRemision(CveVentaPedido, ObjV.IniciaTransacSQL())
If ObjInventario.GetMovimientosDetalle(CveMovimientoSalida, UsuarioActual.CveEmpresa) AndAlso ObjInventario.DtResultados.Rows.Count > 0 Then If Respuesta.CveVenta > 0 Then
ImporteAlmacen = ObjInventario.DtResultados.SUM("Total")
Dim IndexMov2 As Integer = 0
For Each dRow As DataRow In ObjInventario.DtResultados.Rows
Dim Cantidad As Decimal = dRow("Cantidad").ToString.ToDecimal CveVentaRemisionGenerada = Respuesta.CveVenta
Dim CvePS As Integer = dRow("CvePS").ToString.ToEntero If ObjV.GetVentaDetalle(Respuesta.CveVenta) Then
Dim CveUM As Integer = dRow("CveUM").ToString.ToEntero Dim dtClon As DataTable = ObjV.DtResultados.Copy
Dim PU As Decimal = dRow("PU").ToString.ToDecimal dtClon.DefaultView.Sort = "CveVentaDetalle ASC"
Dim CveVentaDetalle As Integer = dRow("CveVentaDetalle").ToString.ToEntero Dim dtmat As DataTable = dtClon.DefaultView.ToTable()
Dim CveMovimientoDetalle As Integer = dRow("CveMovimientoDetalle").ToString.ToEntero 'una vez registrada, asocia los lotes/cad con el cveventadetalle para que se surta así
DtVentaDetalle = Respuesta.dtdetalle
For i = 0 To dtmat.Rows.Count - 1
If DtVentaDetalle.Rows(i)("CvePS").ToString = dtmat.Rows(i)("CvePS").ToString Then
DtVentaDetalle.Rows(i)("CveVentaDetalle") = dtmat.Rows(i)("CveVentaDetalle")
DtVentaDetalle.Rows(i)("CveUM") = dtmat.Rows(i)("CveUM")
End If
Next
End If
Else
ProcesoOK = False
End If
End If
Dim Lote As String = dRow("Lote").ToString If GenerarRemisionMovimientos AndAlso ProcesoOK Then
Dim Serie As String = dRow("Serie").ToString
Dim FechaCaducidad As DateTime = dRow("FechaCaducidad").ToString.ToDateTime
If Not ObjInventario.AddMovimientoDetalle(CveMovimientoEntrada, Cantidad, CveUM, CvePS, PU, CveVentaDetalle:=CveVentaDetalle, CveMovimientoDetalleEntrada:=CveMovimientoDetalle, Lote:=Lote, Serie:=Serie, FechaCaducidad:=FechaCaducidad) Then CveMovimientoSalida = ObjInventario.AddMovimiento(CveAlmacenActual, 8, CveMoneda, Fecha, -1, UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa, -1, Respuesta.CveVenta, CveSubProyectoPedido, -1, CveOS:=CveOS, CveAlmacenDestino:=CveAlmacenDestino, Modulo:="OS/MatUtil3")
Dim Folio As Integer = ObjInventario.Folio
If CveMovimientoSalida > 0 Then
Dim IndexMov1 As Integer = 0
For Each drr As DataRow In DtVentaDetalle.Rows
Dim Cantidad As Decimal = drr("Cantidad").ToString.ToDecimal
'Dim CantidadRegistro As Decimal = GvRow.FCTextBox("TxtUtilizado").Text.ToDecimal
Dim CvePS As Integer = drr("CvePS").ToString.ToEntero
Dim CveUM As Integer = drr("CveUM").ToString.ToEntero
Dim PU As Decimal = drr("PU").ToString.ToDecimal
If Cantidad > 0 Then
Dim CveVentaDetalle As Integer = drr("CveVentaDetalle").ToString.ToEntero 'DtVentaDetalle.FiltroPrimeroValor("CveVentaDetalle", $"CveVentaDetallePadre = {GvRow.DataKey("CveVentaDetalle")}").ToEntero
Dim CveMovimientoDetalle As Integer = -1 'GvRow.DataKey("CveMovimientoDetalle").ToEntero
If CveVentaDetalle <= 0 Then
Alert("Error al agregar detalle de movimiento.", TipoMensaje.MsgAdvertencia) Alert("Error al agregar detalle de movimiento.", TipoMensaje.MsgAdvertencia)
ProcesoOK = False ProcesoOK = False
Exit For Exit For
End If End If
IndexMov2 = IndexMov2 + 1 Dim Serie As String = drr("Serie").ToString
Next Dim Lote As String = drr("Lote").ToString
If ProcesoOK Then Dim FechaCaducidad As DateTime = drr("FechaCaducidad").ToString.ToDate
Dim ObjEventos As New ClsOIEventos(ObjInventario.IniciaTransacSQL) If Not ObjInventario.AddMovimientoDetalle(CveMovimientoSalida, Cantidad, CveUM, CvePS, PU, CveVentaDetalle:=CveVentaDetalle, CveMovimientoDetalleEntrada:=CveMovimientoDetalle, Lote:=Lote, Serie:=Serie, FechaCaducidad:=FechaCaducidad) Then
Dim LigaVenta As String = String.Format("Venta {2} en Folio: <a href=""/Inventarios/EntradasSalidas.aspx?CveMovimiento={0}"" target=""_blank"">{1}</a>", CveMovimientoEntrada, Folio, "Material utilizado") Alert("Error al agregar detalle de movimiento.", TipoMensaje.MsgAdvertencia)
ProcesoOK = False
Exit For
End If
End If
IndexMov1 = IndexMov1 + 1
Next
If Not ObjEventos.AddEventoBitacora(LigaVenta, "-1", UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa, CveVenta:=Respuesta.CveVenta, CveOS:=CveOS) Then If ProcesoOK Then
CveMovimientoEntrada = ObjInventario.AddMovimiento(CveAlmacenDestino, 9, CveMoneda, Fecha, -1, UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa, -1, Respuesta.CveVenta, CveSubProyectoPedido, -1, CveOS:=CveOS, CveMovimientoRelacionado:=CveMovimientoSalida, Modulo:="OS/MatUtil2")
If ObjInventario.GetMovimientosDetalle(CveMovimientoSalida, UsuarioActual.CveEmpresa) AndAlso ObjInventario.DtResultados.Rows.Count > 0 Then
ImporteAlmacen = ObjInventario.DtResultados.SUM("Total")
Dim IndexMov2 As Integer = 0
For Each dRow As DataRow In ObjInventario.DtResultados.Rows
Dim Cantidad As Decimal = dRow("Cantidad").ToString.ToDecimal
Dim CvePS As Integer = dRow("CvePS").ToString.ToEntero
Dim CveUM As Integer = dRow("CveUM").ToString.ToEntero
Dim PU As Decimal = dRow("PU").ToString.ToDecimal
Dim CveVentaDetalle As Integer = dRow("CveVentaDetalle").ToString.ToEntero
Dim CveMovimientoDetalle As Integer = dRow("CveMovimientoDetalle").ToString.ToEntero
Dim Lote As String = dRow("Lote").ToString
Dim Serie As String = dRow("Serie").ToString
Dim FechaCaducidad As DateTime = dRow("FechaCaducidad").ToString.ToDateTime
If Not ObjInventario.AddMovimientoDetalle(CveMovimientoEntrada, Cantidad, CveUM, CvePS, PU, CveVentaDetalle:=CveVentaDetalle, CveMovimientoDetalleEntrada:=CveMovimientoDetalle, Lote:=Lote, Serie:=Serie, FechaCaducidad:=FechaCaducidad) Then
Alert("Error al agregar detalle de movimiento.", TipoMensaje.MsgAdvertencia)
ProcesoOK = False
Exit For
End If
IndexMov2 = IndexMov2 + 1
Next
If ProcesoOK Then
Dim ObjEventos As New ClsOIEventos(ObjInventario.IniciaTransacSQL)
Dim LigaVenta As String = String.Format("Venta {2} en Folio: <a href=""/Inventarios/EntradasSalidas.aspx?CveMovimiento={0}"" target=""_blank"">{1}</a>", CveMovimientoEntrada, Folio, "Material utilizado")
If Not ObjEventos.AddEventoBitacora(LigaVenta, "-1", UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa, CveVenta:=Respuesta.CveVenta, CveOS:=CveOS) Then
ProcesoOK = False
End If
End If
Else
ProcesoOK = False
End If
End If
If ProcesoOK Then
Dim Contabilizable As Boolean = False
Dim Concepto As String = "Material utilizado"
Dim CvePrePoliza As Integer = ObjConta.AddPrePolizas("OS-MatUtil", 53, 0, 0, 1, Fecha, Concepto, UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa)
If CveMovimientoSalida > 0 Then
If Not ObjConta.AddPrePolizasDetalle(CvePrePoliza, True, ImporteAlmacen, ImporteAlmacen, 68, "", Concepto, CveMovimientoAlmacen:=CveMovimientoSalida, Contabilizable:=Contabilizable) Then
ProcesoOK = False ProcesoOK = False
End If End If
End If End If
Else If CveMovimientoEntrada > 0 Then
If Not ObjConta.AddPrePolizasDetalle(CvePrePoliza, False, ImporteAlmacen, ImporteAlmacen, 68, "", Concepto, CveMovimientoAlmacen:=CveMovimientoEntrada, Contabilizable:=Contabilizable) Then
ProcesoOK = False
End If
End If
End If
Else
ProcesoOK = False
End If
If ProcesoOK Then
If Not ObjOS.UpdateVentaOS(Respuesta.CveVenta, CveOS, UsuarioActual.CveEmpresa, TxtPacienteModal.Text.Trim, TxtEpisodioModal.Text.Trim, FolioAdicional:=TxtFolioRemisionModal.Text.Trim) Then
ProcesoOK = False ProcesoOK = False
End If End If
End If End If
If ProcesoOK Then
Dim Contabilizable As Boolean = False
Dim Concepto As String = "Material utilizado"
Dim CvePrePoliza As Integer = ObjConta.AddPrePolizas("OS-MatUtil", 53, 0, 0, 1, Fecha, Concepto, UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa)
If CveMovimientoSalida > 0 Then
If Not ObjConta.AddPrePolizasDetalle(CvePrePoliza, True, ImporteAlmacen, ImporteAlmacen, 68, "", Concepto, CveMovimientoAlmacen:=CveMovimientoSalida, Contabilizable:=Contabilizable) Then
ProcesoOK = False
End If
End If
If CveMovimientoEntrada > 0 Then
If Not ObjConta.AddPrePolizasDetalle(CvePrePoliza, False, ImporteAlmacen, ImporteAlmacen, 68, "", Concepto, CveMovimientoAlmacen:=CveMovimientoEntrada, Contabilizable:=Contabilizable) Then
ProcesoOK = False
End If
End If
End If
Else
ProcesoOK = False
End If End If
If ProcesoOK Then If ProcesoOK Then
If Not ObjOS.UpdateVentaOS(Respuesta.CveVenta, CveOS, UsuarioActual.CveEmpresa, TxtPacienteModal.Text.Trim, TxtEpisodioModal.Text.Trim, FolioAdicional:=TxtFolioRemisionModal.Text.Trim) Then If Not ObjOS.UpdateOrdenesServiciosFinaliza(CveOS, -1, -1, UsuarioActual.CveEmpresa, Observaciones:=TxtObservacionModal.Text.Trim) Then
ProcesoOK = False ProcesoOK = False
End If End If
End If End If
End If End If
If ProcesoOK Then If ProcesoOK Then
If Not ObjOS.UpdateOrdenesServiciosFinaliza(CveOS, -1, -1, UsuarioActual.CveEmpresa, Observaciones:=TxtObservacionModal.Text.Trim) Then If Not ObjOS.UpdateVentaOS(-1, CveOS, UsuarioActual.CveEmpresa, TxtPacienteModal.Text.Trim, TxtEpisodioModal.Text.Trim) Then
ProcesoOK = False ProcesoOK = False
End If End If
End If End If
End If
If ProcesoOK Then
If ProcesoOK Then ProcesoOK = GuardarArchivoConfirmacion(ObjV.IniciaTransacSQL, CveOS, CveVentaRemisionGenerada)
If Not ObjOS.UpdateVentaOS(-1, CveOS, UsuarioActual.CveEmpresa, TxtPacienteModal.Text.Trim, TxtEpisodioModal.Text.Trim) Then
ProcesoOK = False
End If End If
End If
If ProcesoOK Then If ProcesoOK Then
ProcesoOK = GuardarArchivoConfirmacion(ObjV.IniciaTransacSQL, CveOS, CveVentaRemisionGenerada)
End If
If ProcesoOK Then ObjV.Commit()
If DdlTipoVenta.SelectedValue.ToEntero = 5 Then
ObjV.Commit() Dim Liga As String = $" document.location.href=""/OS/OrdenesServicios.aspx?CveOS={CveOS}""; "
If DdlTipoVenta.SelectedValue.ToEntero = 5 Then Alert("El material utilizado se guardó correctamente", TipoMensaje.MsgInformacion, Liga)
Dim Liga As String = $" document.location.href=""/OS/OrdenesServicios.aspx?CveOS={CveOS}""; "
Alert("El material utilizado se guardó correctamente", TipoMensaje.MsgInformacion, Liga)
Else
If GenerarRemisionMovimientos = False Then
Alert("El material sera recibido en almacén.")
Else Else
Alert("El material utilizado se guardó correctamente") If GenerarRemisionMovimientos = False Then
Alert("El material sera recibido en almacén.")
Else
Alert("El material utilizado se guardó correctamente")
End If
End If End If
RegistraScript("$('#DivModalMaterialUtilizado').modal('hide');")
CargaEventoBitacora()
Else
ObjV.RollBack()
Alert("Se presento un error al guardar el material", TipoMensaje.MsgAdvertencia)
End If End If
RegistraScript("$('#DivModalMaterialUtilizado').modal('hide');") ObjV.Dispose()
CargaEventoBitacora()
Else
ObjV.RollBack()
Alert("Se presento un error al guardar el material", TipoMensaje.MsgAdvertencia)
End If End If
ObjV.Dispose()
End Sub End Sub
@@ -3609,13 +3609,10 @@ Partial Class OS_OrdenesServicios
End Class End Class
Protected Sub LnkActualizarUsaurioAtendio_Click(sender As Object, e As EventArgs) Protected Sub LnkActualizarUsaurioAtendio_Click(sender As Object, e As EventArgs)
If DdlUsuarioAtendio.SelectedValue.ToEntero > 0 Then If DdlUsuarioAtendio.SelectedValue.ToEntero > 0 Then
Dim ObjOS As New ClsOS Dim ObjOS As New ClsOS
ObjOS.IniciaTransacSQL() ObjOS.IniciaTransacSQL()
Dim ProcesoOk As Boolean = True Dim ProcesoOk As Boolean = True
For Each GvRow As GridViewRow In GvPS.Rows For Each GvRow As GridViewRow In GvPS.Rows
@@ -3637,13 +3634,10 @@ Partial Class OS_OrdenesServicios
Alert($"Se presento un error al actualizar el técnico.") Alert($"Se presento un error al actualizar el técnico.")
CargaHistorial() CargaHistorial()
End If End If
Else Else
Alert("Debe de seleccionar un ténico para actualziar", TipoMensaje.MsgAdvertencia) Alert("Debe de seleccionar un ténico para actualziar", TipoMensaje.MsgAdvertencia)
End If End If
End Sub End Sub
Protected Sub GVEventoBitacora_RowDataBound(sender As Object, e As GridViewRowEventArgs) Handles GvEB.RowDataBound Protected Sub GVEventoBitacora_RowDataBound(sender As Object, e As GridViewRowEventArgs) Handles GvEB.RowDataBound
@@ -3692,7 +3686,6 @@ Partial Class OS_OrdenesServicios
Protected Sub BtnCancelar_Click(sender As Object, e As EventArgs) Protected Sub BtnCancelar_Click(sender As Object, e As EventArgs)
Dim CveEstatusOrdenServicioCancelacion As Integer = GlobalDTEstatusOrdenServicios(UsuarioActual.CveEmpresa).FiltroPrimeroValor("CveEstatusOrdenServicio", " TipoEstatus = 5 ").ToEntero Dim CveEstatusOrdenServicioCancelacion As Integer = GlobalDTEstatusOrdenServicios(UsuarioActual.CveEmpresa).FiltroPrimeroValor("CveEstatusOrdenServicio", " TipoEstatus = 5 ").ToEntero
Dim CveAlmacenDevolucion As Integer Dim CveAlmacenDevolucion As Integer
Dim CveMotivoCancelacion As Integer = GlobalDTMotivosCancelacionEmpresa(UsuarioActual.CveEmpresa).FiltroPrimeroValor("CveMotivoCancelacion", "CveSATMotivoCancelacion IN (3)").ToEntero Dim CveMotivoCancelacion As Integer = GlobalDTMotivosCancelacionEmpresa(UsuarioActual.CveEmpresa).FiltroPrimeroValor("CveMotivoCancelacion", "CveSATMotivoCancelacion IN (3)").ToEntero
@@ -3710,9 +3703,7 @@ Partial Class OS_OrdenesServicios
Dim ObjFacturaCancelacion As New Modelos.Factura(UsuarioActual, CvePedido, UsuarioActual.CveEmpresa, EsCancelacion:=True, VerificaAlmacen:=True) Dim ObjFacturaCancelacion As New Modelos.Factura(UsuarioActual, CvePedido, UsuarioActual.CveEmpresa, EsCancelacion:=True, VerificaAlmacen:=True)
Try Try
Dim resp As Modelos.Factura.MCancelacionVentaMensaje = Nothing Dim resp As Modelos.Factura.MCancelacionVentaMensaje = Nothing
If ObjFacturaCancelacion IsNot Nothing AndAlso ObjFacturaCancelacion.CveVenta > 0 Then If ObjFacturaCancelacion IsNot Nothing AndAlso ObjFacturaCancelacion.CveVenta > 0 Then
Dim SWatch As New Stopwatch Dim SWatch As New Stopwatch
@@ -3728,16 +3719,11 @@ Partial Class OS_OrdenesServicios
Alert($"Se presento un error al cancelar la orden de servicio, {resp.Mensaje}".ToString(), TipoMensaje.MsgError) Alert($"Se presento un error al cancelar la orden de servicio, {resp.Mensaje}".ToString(), TipoMensaje.MsgError)
Else Else
Alert($"la orden de servicio se cancelada correctamente, {resp.Mensaje}", resp.TipoMensaje, " location.reload(true); ") Alert($"la orden de servicio se cancelada correctamente, {resp.Mensaje}", resp.TipoMensaje, " location.reload(true); ")
Dim objGeneral As New ClsGenerales Dim objGeneral As New ClsGenerales
objGeneral.AddHistorialBitacora(256, -1, -1, -1, CveOS, -1, -1, -1, "Cancelada", DdlEstatusOS.SelectedItem.Text, UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa, 0, "", "", "") objGeneral.AddHistorialBitacora(256, -1, -1, -1, CveOS, -1, -1, -1, "Cancelada", DdlEstatusOS.SelectedItem.Text, UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa, 0, "", "", "")
objGeneral.Dispose() objGeneral.Dispose()
End If End If
End If End If
Catch ex As Exception Catch ex As Exception
Alert("Se presento un error al cancelar la orden de servicio") Alert("Se presento un error al cancelar la orden de servicio")
End Try End Try