+
+
diff --git a/OP/OP.aspx.vb b/OP/OP.aspx.vb
index 3053d6962..6db555ecf 100644
--- a/OP/OP.aspx.vb
+++ b/OP/OP.aspx.vb
@@ -41,7 +41,15 @@ Partial Class OP_OP
Private Property DtMO As DataTable
Get
- Return DirectCast(ViewState("DtMO"), DataTable)
+ If ViewState("DtMO") Is Nothing Then
+ DtMO = New DataTable()
+ DtMO.Columns.Add("CvePS", GetType(Integer)) ' Producto asociado
+ DtMO.Columns.Add("CvePuesto", GetType(Integer))
+ DtMO.Columns.Add("Puesto", GetType(String))
+ DtMO.Columns.Add("CostoHora", GetType(Decimal))
+ DtMO.Columns.Add("Total", GetType(Decimal))
+ End If
+ Return CType(ViewState("DtMO"), DataTable)
End Get
Set(value As DataTable)
ViewState("DtMO") = value
@@ -50,13 +58,31 @@ Partial Class OP_OP
Private Property DtCI As DataTable
Get
- Return DirectCast(ViewState("DtCI"), DataTable)
+ If ViewState("DtCI") Is Nothing Then
+ DtCI = New DataTable()
+ DtCI.Columns.Add("CvePS", GetType(Integer)) ' Producto asociado
+ DtCI.Columns.Add("CvePSMateriaPrima", GetType(Integer))
+ DtCI.Columns.Add("productoMateriaPrima", GetType(String))
+ DtCI.Columns.Add("Cantidad", GetType(Decimal))
+ DtCI.Columns.Add("PU", GetType(Decimal))
+ DtCI.Columns.Add("Total", GetType(Decimal))
+ End If
+ Return CType(ViewState("DtCI"), DataTable)
End Get
Set(value As DataTable)
ViewState("DtCI") = value
End Set
End Property
+ Private Property TipoEstatus As Integer
+ Get
+ Return ViewState("TipoEstatus").ToString.ToEntero
+ End Get
+ Set(value As Integer)
+ ViewState("TipoEstatus") = value
+ End Set
+ End Property
+
Private Property DtMPAgregados As DataTable
Get
If ViewState("DtMPAgregados") Is Nothing Then
@@ -74,12 +100,27 @@ Partial Class OP_OP
End Set
End Property
+ Private Property DtDevoluciones As DataTable
+ Get
+ If ViewState("DtDevoluciones") Is Nothing Then
+ DtDevoluciones = New DataTable()
+ DtDevoluciones.Columns.Add("CvePS", GetType(Integer))
+ DtDevoluciones.Columns.Add("Devolucion", GetType(Decimal))
+ DtDevoluciones.Columns.Add("CveAlmacenDevolucion", GetType(Integer))
+ End If
+ Return CType(ViewState("DtDevoluciones"), DataTable)
+ End Get
+ Set(value As DataTable)
+ ViewState("DtDevoluciones") = value
+ End Set
+ End Property
#End Region
Protected Sub Page_Load(sender As Object, e As System.EventArgs) Handles Me.Load
If Not IsPostBack Then
CveOP = If(Request("CveOP") <> "", Request("CveOP").ToString.ToEntero, "-1".ToEntero)
+ TipoEstatus = -1
CreaPS()
SetValues()
End If
@@ -106,6 +147,7 @@ Partial Class OP_OP
DtMP.Columns.Add("UnidadMedida", GetType(String))
DtMP.Columns.Add("Cantidad", GetType(Decimal))
DtMP.Columns.Add("Surtido", GetType(Decimal))
+ 'DtMP.Columns.Add("CvePSProducto", GetType(Integer))
'DtMP.Columns.Add("CveAlmacenDestino", GetType(Integer))
DtMO = New DataTable()
@@ -115,15 +157,17 @@ Partial Class OP_OP
DtMO.Columns.Add("CvePuesto", GetType(Integer))
DtMO.Columns.Add("Puesto", GetType(String))
DtMO.Columns.Add("Cantidad", GetType(Decimal))
+ DtMO.Columns.Add("CostoHora", GetType(Decimal))
+ DtMO.Columns.Add("Total", GetType(Decimal))
+
DtCI = New DataTable()
DtCI.Columns.Add("Tipo", GetType(String)) ' Producto, MP, MO, CI
DtCI.Columns.Add("Clave", GetType(Integer))
- 'DtCI.Columns.Add("CveUM", GetType(Integer))
- 'DtCI.Columns.Add("CvePSMateriaPrima", GetType(Integer))
- 'DtCI.Columns.Add("CveUMMateriaPrima", GetType(Integer))
DtCI.Columns.Add("productoMateriaPrima", GetType(String))
DtCI.Columns.Add("Cantidad", GetType(Decimal))
+ DtCI.Columns.Add("PU", GetType(Decimal))
+ DtCI.Columns.Add("Total", GetType(Decimal))
End Sub
@@ -133,24 +177,65 @@ Partial Class OP_OP
CargarClientes()
CargarCentrosDeCosto(DdlProyecto, DdlSubProyecto, LblProyecto, LblSubProyecto, divProyecto:=DivProyecto, VisualizacionReporte:=1)
CargarProductos()
+ CargaDatos()
- If CveOP = -1 Then
-
- DdlClientes.Enabled = True
- DdlProyecto.Enabled = True
- DdlSubProyecto.Enabled = True
- DdlPS.Enabled = True
- LnkSolicitarMP.Visible = False
- BtnSimularMP.Visible = True
- BtnFinalizarOP.Visible = False
+ If TipoEstatus = 3 Then
+ DeshabilitarControles() ' Deshabilita todos los controles relevantes
Else
- DdlClientes.Enabled = False
- DdlPS.Enabled = False
- LnkSolicitarMP.Visible = False
- BtnSimularMP.Visible = False
- BtnFinalizarOP.Visible = True
- CargaDatos()
+ If CveOP = -1 Then ' Nueva OP
+ DdlClientes.Enabled = True
+ DdlProyecto.Enabled = True
+ DdlSubProyecto.Enabled = True
+ DdlPS.Enabled = True
+ TxtEstatus.Enabled = True ' Estatus no editable
+ LnkSolicitarMP.Visible = False
+ BtnSimularMP.Visible = True
+ BtnFinalizarOP.Visible = False
+ Else ' OP existente no finalizada
+ If TipoEstatus <> 3 Then
+ DdlClientes.Enabled = True
+ DdlProyecto.Enabled = True
+ DdlSubProyecto.Enabled = True
+ DdlPS.Enabled = True
+ TxtDescripcion.Enabled = True
+ Txtfecha.Enabled = True
+ TxtEstatus.Enabled = True ' Estatus no editable
+ BtnAgregarProducto.Enabled = True
+ BtnSimularMP.Visible = False
+ BtnGuardarOP.Enabled = True
+ BtnFinalizarOP.Visible = True
+ imgCalendarioF.Enabled = True
+ LnkSolicitarMP.Visible = True
+ End If
+ End If
End If
+
+ UpOP.Update()
+ UpGvDatosOP.Update()
+ End Sub
+
+ Private Sub DeshabilitarControles()
+ ' Deshabilitar DropDownLists
+ DdlClientes.Enabled = False
+ DdlProyecto.Enabled = False
+ DdlSubProyecto.Enabled = False
+ DdlPS.Enabled = False
+
+ ' Deshabilitar TextBox y Date
+ TxtDescripcion.Enabled = False
+ Txtfecha.Enabled = False
+ imgCalendarioF.Enabled = False
+ TxtEstatus.Enabled = False
+
+ ' Ocultar Botones
+ BtnAgregarProducto.Visible = False
+ BtnSimularMP.Visible = False
+ BtnGuardarOP.Visible = False
+ BtnFinalizarOP.Visible = False
+ LnkSolicitarMP.Visible = False
+
+ UpOP.Update()
+ UpGvDatosOP.Update()
End Sub
Private Sub CargaDatos()
@@ -169,6 +254,7 @@ Partial Class OP_OP
DdlPS.txtValue.Value = dr("CvePS").ToString
Txtfecha.Text = dr("Fecha").ToString
TxtDescripcion.Text = dr("Descripcion").ToString
+ TipoEstatus = dr("TipoEstatus").ToString.ToEntero
If ObjOP.GetProductosOP(CveOP, UsuarioActual.CveEmpresa) Then
@@ -221,7 +307,7 @@ Partial Class OP_OP
Dim newRow As DataRow = DtCI.NewRow()
newRow("Tipo") = "CI"
newRow("productoMateriaPrima") = rowCI("producto").ToString
- newRow("Cantidad") = rowCI("Cantidad").ToString.ToDecimal
+ newRow("Costo") = rowCI("Costo").ToString.ToDecimal
DtCI.Rows.Add(newRow)
Next
@@ -292,6 +378,7 @@ Partial Class OP_OP
rowMP("PSCodigo") = drMP("productoMateriaPrima").ToString()
rowMP("UnidadMedida") = drMP("UnidadMedidaMateriaPrima").ToString()
rowMP("Cantidad") = drMP("Cantidad").ToString().ToDecimal()
+ 'rowMP("CvePSProducto") = CvePS
rowMP("Surtido") = 0
DtMP.Rows.Add(rowMP)
Next
@@ -306,6 +393,8 @@ Partial Class OP_OP
rowMO("Clave") = CvePS
rowMO("Puesto") = drMO("Puesto").ToString()
rowMO("Cantidad") = drMO("Cantidad").ToString().ToDecimal()
+ rowMO("CostoHora") = drMO("precioHora").ToString.ToDecimal()
+ rowMO("Total") = drMO("Cantidad").ToString().ToDecimal() * drMO("precioHora").ToString().ToDecimal()
DtMO.Rows.Add(rowMO)
Next
End If
@@ -321,6 +410,8 @@ Partial Class OP_OP
'rowCI("CvePSMateriaPrima") = drCI("CvePSMateriaPrima").ToString().ToEntero()
rowCI("productoMateriaPrima") = drCI("productoMateriaPrima").ToString()
rowCI("Cantidad") = drCI("Cantidad").ToString().ToDecimal()
+ rowCI("PU") = drCI("ImporteCostoIndirecto").ToString().ToDecimal()
+ rowCI("Total") = rowCI("Cantidad").ToString().ToDecimal() * rowCI("PU").ToString().ToDecimal()
DtCI.Rows.Add(rowCI)
Next
End If
@@ -329,6 +420,12 @@ Partial Class OP_OP
End Sub
Protected Sub BtnEliminarProducto_Click(sender As Object, e As EventArgs)
+
+ ' Verificar si la OP está finalizada
+ If TxtEstatus.Text = "Finalizada" Then
+ Alert("No se pueden eliminar productos de una OP finalizada.", TipoMensaje.MsgAdvertencia)
+ Exit Sub
+ End If
Dim btnEliminar As LinkButton = DirectCast(sender, LinkButton)
Dim CveProducto As Integer = btnEliminar.CommandArgument.ToEntero()
@@ -361,6 +458,13 @@ Partial Class OP_OP
Next
End Sub
+ Protected Sub GvProductos_RowDataBound(sender As Object, e As GridViewRowEventArgs) Handles GvProductos.RowDataBound
+ If e.Row.RowType = DataControlRowType.DataRow Then
+ Dim btnEliminar As LinkButton = DirectCast(e.Row.FindControl("BtnEliminar"), LinkButton)
+ btnEliminar.Visible = (TipoEstatus <> 3)
+ End If
+ End Sub
+
Protected Sub LnkSolicitarMP_Click(sender As Object, e As EventArgs)
' Cargar almacenes
DdlAlmacenOrigenMP.DataSource = GlobalDTAlmacen(UsuarioActual.CveEmpresa).FiltraParametros("CveTipoAlmacen = 1")
@@ -560,16 +664,16 @@ Partial Class OP_OP
Dim MensajeExistencia As New StringBuilder
MensajeExistencia.Append("No hay la existencia suficiente de los siguientes productos: ")
- '✅ 1. Validar existencias de MP
+
For Each row As GridViewRow In GvMPAgregados.Rows
- '✅ Obtener claves CORRECTAS de la materia prima
+
Dim CveMP As Integer = GvMPAgregados.DataKeys(row.RowIndex)("CvePSMateriaPrima").ToString().ToEntero()
Dim CveUMMP As Integer = GvMPAgregados.DataKeys(row.RowIndex)("CveUMMateriaPrima").ToString().ToEntero()
Dim CantidadSolicitada As Decimal = DtMP.Rows(row.RowIndex)("Cantidad").ToString().ToDecimal()
- 'DtMP.Rows(row.RowIndex)("CveAlmacenDestino") = DdlAlmacenDestinoMP.SelectedValue.ToEntero()
- '✅ Verificar existencias
+
+
Dim Existencia As Decimal = ObjInventario.GetExistenciasPS(
CvePS:=CveMP,
CveUnidadMedida:=CveUMMP,
@@ -596,7 +700,7 @@ Partial Class OP_OP
Exit Sub
End If
- '✅ 2. Crear traspaso si todo está correcto
+
ObjInventario.IniciaTransacSQL()
Dim TieneError As Boolean = False
@@ -618,10 +722,10 @@ Partial Class OP_OP
TieneError = True
End If
- '✅ 3. Agregar detalles del traspaso
+
If Not TieneError Then
For Each row As GridViewRow In GvMPAgregados.Rows
- '✅ Usar claves de MATERIA PRIMA (CvePSMateriaPrima y CveUMMateriaPrima)
+
Dim CveMP As Integer = GvMPAgregados.DataKeys(row.RowIndex)("CvePSMateriaPrima").ToString().ToEntero()
Dim CveUMMP As Integer = GvMPAgregados.DataKeys(row.RowIndex)("CveUMMateriaPrima").ToString().ToEntero()
Dim Cantidad As Decimal = DtMP.Rows(row.RowIndex)("Cantidad").ToString().ToDecimal()
@@ -629,8 +733,8 @@ Partial Class OP_OP
If Not ObjInventario.AddTrasladoSolicitudDetalle(
CveTraspasoSolicitud,
Cantidad,
- CveUMMP, '✅ Unidad de medida de la MP
- CveMP, '✅ Clave de la MP
+ CveUMMP,
+ CveMP,
0, "", -1, "-1", "-1", MinFecha
) Then
TieneError = True
@@ -639,7 +743,7 @@ Partial Class OP_OP
Next
End If
- '✅ 4. Confirmar o cancelar transacción
+
If Not TieneError Then
ObjInventario.Commit()
Alert($"Solicitud de Traspaso guardada. Folio: {FolioSolicitud}", TipoMensaje.MsgInformacion)
@@ -786,18 +890,35 @@ Partial Class OP_OP
End Sub
Protected Sub DdlAlmacenOrigenMP_SelectedIndexChanged(sender As Object, e As EventArgs)
- ' ✅ Mantener siempre el almacén de producción (tipo 28) en destino
+
DdlAlmacenDestinoMP.DataSource = GlobalDTAlmacen(UsuarioActual.CveEmpresa).FiltraParametros("CveTipoAlmacen = 28")
DdlAlmacenDestinoMP.DataBind()
- ' ✅ Opcional: Seleccionar el primer almacén de producción por defecto
+
If DdlAlmacenDestinoMP.Items.Count > 0 Then
DdlAlmacenDestinoMP.SelectedIndex = 0
End If
End Sub
-#Region "Eventos de Botones"
+ Protected Sub GvProductoTerminado_RowDataBound(sender As Object, e As GridViewRowEventArgs)
+ If e.Row.RowType = DataControlRowType.DataRow Then
+ Dim originalQty As Decimal = Convert.ToDecimal(DataBinder.Eval(e.Row.DataItem, "Cantidad"))
+ Dim txtCantidad As TextBox = DirectCast(e.Row.FindControl("TxtCantidadPT"), TextBox)
+ txtCantidad.Attributes("data-original") = originalQty.ToString("0")
+ End If
+ End Sub
+ Protected Sub GvMPUtilizada_RowDataBound(sender As Object, e As GridViewRowEventArgs)
+ If e.Row.RowType = DataControlRowType.DataRow Then
+ Dim originalQty As Decimal = Convert.ToDecimal(DataBinder.Eval(e.Row.DataItem, "Cantidad"))
+ Dim txtDevolucion As TextBox = DirectCast(e.Row.FindControl("TxtDevolucionMP"), TextBox)
+ txtDevolucion.Attributes("data-original") = originalQty.ToString("0")
+ End If
+ End Sub
+
+
+
+#Region "Finalizar"
Protected Sub BtnFinalizarOP_Click(sender As Object, e As EventArgs)
If CveOP = -1 Then Exit Sub
@@ -811,6 +932,11 @@ Partial Class OP_OP
DdlAlmacenTerminado.DataBind()
DdlAlmacenTerminado.Items.Insert(0, New ListItem("Seleccionar almacén", "-1"))
+ ' Almacén de Devoluciones (Tipo 1)
+ DdlAlmacenDevolucion.DataSource = GlobalDTAlmacen(UsuarioActual.CveEmpresa).FiltraParametros("CveTipoAlmacen = 1")
+ DdlAlmacenDevolucion.DataBind()
+ DdlAlmacenDevolucion.Items.Insert(0, New ListItem("Seleccionar almacén", "-1"))
+
' 3. Cargar GridViews
GvProductoTerminado.DataSource = DtPS.FiltraParametros("Tipo = 'Producto'")
GvProductoTerminado.DataBind()
@@ -823,15 +949,42 @@ Partial Class OP_OP
End Sub
Protected Sub BtnGuardarFinalizarOP_Click(sender As Object, e As EventArgs)
+ Dim EstatusFinalizar As String = GlobalDTOPEstatus(UsuarioActual.CveEmpresa).FiltroPrimeroValor("EstatusOP", "TipoEstatus=3")
+ Dim CveEstatusFinalizar As Integer = GlobalDTOPEstatus(UsuarioActual.CveEmpresa).FiltroPrimeroValor("CveEstatusOP", "TipoEstatus=3").ToEntero()
+ If Not CveEstatusFinalizar > 0 Then
+ Alert("No se encontró el estatus de finalización de la OP.", TipoMensaje.MsgError)
+ Exit Sub
+ End If
+
If DdlAlmacenOrigenSalidaMP.SelectedValue = "-1" OrElse DdlAlmacenTerminado.SelectedValue = "-1" Then
Alert("Selecciona ambos almacenes.", TipoMensaje.MsgAdvertencia)
Exit Sub
End If
- ' Dim TotalCantidad As Decimal = DtMovimientos.SUMD("Cantidad")
- 'Inicia la transacción
+ For Each row As GridViewRow In GvProductoTerminado.Rows
+ Dim txtCantidad As TextBox = DirectCast(row.FindControl("TxtCantidadPT"), TextBox)
+ Dim cantidadIngresada As Decimal = txtCantidad.Text.ToDecimal()
+ Dim cantidadOriginal As Decimal = txtCantidad.Attributes("data-original").ToDecimal()
- Dim CveMovimientoSalida As Integer = 0
+ If cantidadIngresada > cantidadOriginal Then
+ Alert("La cantidad del producto terminado no puede superar lo solicitado.", TipoMensaje.MsgAdvertencia)
+ Exit Sub
+ End If
+ Next
+
+
+ For Each row As GridViewRow In GvMPUtilizada.Rows
+ Dim txtDevolucion As TextBox = DirectCast(row.FindControl("TxtDevolucionMP"), TextBox)
+ Dim devolucionIngresada As Decimal = txtDevolucion.Text.ToDecimal()
+ Dim cantidadOriginal As Decimal = txtDevolucion.Attributes("data-original").ToDecimal()
+
+ If devolucionIngresada > cantidadOriginal Then
+ Alert("La devolución no puede superar la cantidad de materia prima solicitada.", TipoMensaje.MsgAdvertencia)
+ Exit Sub
+ End If
+ Next
+
+ Dim CveMovimientoSalida As Integer = 1
Dim CveMovimientoEntrada As Integer = 0
Dim IDPoliza As Integer = 0
Dim FolioSalida As Integer = 0
@@ -844,8 +997,13 @@ Partial Class OP_OP
Dim ErrorMovInv As Boolean = False
Dim TextoError As String = ""
Dim TipoMovimientoSalida As Integer = 8
+ Dim TipoMovimientoDev As Integer = 33
Dim CveConceptoEntrada As Integer = 9
Dim TotalCostoMP As Decimal = 0
+ 'Dim TotalDevoluciones As Decimal = 0
+ Dim CveMovimientoDev As Integer = 0
+ Dim CostoDevoluciones As Decimal = 0
+
Dim ObjInventario As New ClsInventarios()
@@ -855,16 +1013,102 @@ Partial Class OP_OP
Try
CveMovimientoSalida = ObjInventario.AddMovimiento(DdlAlmacenOrigenSalidaMP.SelectedValue.ToEntero(), TipoMovimientoSalida, 1, Fecha, -1, UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa, -1, -1, -1, -1, Observaciones:="Finalización OP #" & LblFolio.Text, Modulo:="OP/FinalizarOPSalida")
-
+ FolioEntrada = ObjInventario.Folio
+ Dim DtMPAlmacen As DataTable = Nothing
If CveMovimientoSalida > 0 Then
- For Each rowMP As DataRow In DtMP.Select("Tipo = 'MP'")
- If Not ObjInventario.AddMovimientoDetalle(CveMovimientoSalida, rowMP("Cantidad").ToString.ToDecimal(), rowMP("CveUMMateriaPrima").ToString.ToEntero(), rowMP("CvePSMateriaPrima").ToString.ToEntero(), 1) Then
- ErrorMovInv = True : TextoError = "x" : Exit For
+ For Each rowMP As DataRow In DtMP.Select("Tipo = 'MP'")
+ Dim CvePS As Integer = rowMP("CvePSMateriaPrima").ToString.ToEntero
+ Dim CveUM As Integer = rowMP("CveUMMateriaPrima").ToString.ToEntero
+ Dim Cantidad As Decimal = rowMP("Cantidad").ToString.ToDecimal
+
+ ' Registrar detalle
+ If Not ObjInventario.AddMovimientoDetalle(CveMovimientoSalida, Cantidad, CveUM, CvePS, 0) Then
+ ErrorMovInv = True
+ Exit For
End If
Next
- If ObjInventario.GetMovimientosDetalle(CveMovimientoSalida, UsuarioActual.CveEmpresa) Then
- TotalCostoMP = ObjInventario.DtResultados.SUMD("Total")
+
+ If Not ObjInventario.GetMovimientosDetalle(CveMovimientoSalida, UsuarioActual.CveEmpresa) Then
+ Throw New Exception("Error al cargar detalles del inventario")
+ End If
+ DtMPAlmacen = ObjInventario.DtResultados.Copy()
+
+ ' 5. Calcular TotalCostoMP (ya está actualizado)
+ TotalCostoMP = ObjInventario.DtResultados.SUMD("Total")
+
+ Dim CostosPorProducto As New Dictionary(Of Integer, Decimal)
+
+ ' 1. Recorrer cada Producto Terminado en la OP
+ For Each rowProducto As DataRow In DtPS.Select("Tipo = 'Producto'")
+ Dim CvePSProducto As Integer = rowProducto("Clave").ToString.ToEntero()
+ Dim CantidadProducto As Decimal = rowProducto("Cantidad").ToString.ToDecimal()
+ Dim TotalMPProducto As Decimal = 0
+ Dim TotalMOProducto As Decimal = 0
+ Dim TotalCIProducto As Decimal = 0
+
+ ' 2. Calcular Costo de Materias Primas por Producto
+ For Each rowMP As DataRow In DtMP.Select($"Clave = {CvePSProducto}")
+ Dim CvePSMP As Integer = rowMP("CvePSMateriaPrima").ToString.ToEntero()
+ Dim CveUMMP As Integer = rowMP("CveUMMateriaPrima").ToString.ToEntero()
+ Dim PU As Decimal = DtMPAlmacen.FiltroPrimeroValor("PU", $"CvePS = {CvePSMP} AND CveUM = {CveUMMP}").ToDecimal()
+ TotalMPProducto += rowMP("Cantidad").ToString().ToDecimal() * PU
+ Next
+
+ ' 3. Calcular Mano de Obra por Producto
+ For Each rowMO As DataRow In DtMO.Select($"Clave = {CvePSProducto}")
+ TotalMOProducto += rowMO("Total").ToString.ToDecimal()
+ Next
+
+ ' 4. Calcular Costos Indirectos por Producto
+ For Each rowCI As DataRow In DtCI.Select($"Clave = {CvePSProducto}")
+ TotalCIProducto += rowCI("Total").ToString.ToDecimal()
+ Next
+
+ ' 5. Sumar Total por Producto (MP + MO + CI)
+ Dim TotalProducto As Decimal = TotalMPProducto + TotalMOProducto + TotalCIProducto
+ CostosPorProducto.Add(CvePSProducto, TotalProducto)
+ Next
+
+ ' 2. PROCESAR DEVOLUCIONES SI EXISTEN
+ If Not ErrorMovInv Then
+ Dim TotalDevoluciones As Decimal = GvMPUtilizada.Rows.Cast(Of GridViewRow)().Sum(Function(row) DirectCast(row.FindControl("TxtDevolucionMP"), TextBox).Text.ToDecimal())
+
+ If TotalDevoluciones > 0 Then
+ If DdlAlmacenDevolucion.SelectedValue = "-1" Then
+ Alert("Seleccione almacén para devoluciones", TipoMensaje.MsgAdvertencia)
+ Exit Sub
+ End If
+
+ CveMovimientoDev = ObjInventario.AddMovimiento(DdlAlmacenDevolucion.SelectedValue.ToEntero(), TipoMovimientoDev, 1, Fecha, -1, UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa, -1, -1, -1, -1, Observaciones:=$"Devolución OP #{LblFolio.Text}", Modulo:="OP/Devoluciones", CveMovimientoRelacionado:=CveMovimientoSalida)
+
+
+ If CveMovimientoDev > 0 Then
+ For Each row As GridViewRow In GvMPUtilizada.Rows
+ Dim Devolucion As Decimal = row.FCTextBox("TxtDevolucionMP").Text.ToDecimal()
+ If Devolucion > 0 Then
+ Dim CvePS As Integer = row.DataKey("CvePSMateriaPrima").ToEntero 'GvMPUtilizada.DataKeys(row.RowIndex)("CvePSMateriaPrima").ToString.ToEntero()
+ Dim CveUM As Integer = row.DataKey("CveUMMateriaPrima").ToEntero 'GvMPUtilizada.DataKeys(row.RowIndex)("CveUMMateriaPrima").ToString.ToEntero()
+
+
+ Dim PU As Decimal = DtMPAlmacen.FiltroPrimeroValor("PU", $"CvePS = {CvePS} AND CveUM = {CveUM}").ToDecimal()
+
+ If Not ObjInventario.AddMovimientoDetalle(
+ CveMovimientoDev,
+ Devolucion,
+ CveUM,
+ CvePS,
+ PU
+ ) Then
+ ErrorMovInv = True
+ End If
+
+ CostoDevoluciones += Devolucion * PU
+ End If
+ Next
+ End If
+ End If
+
End If
If Not ErrorMovInv Then
@@ -872,8 +1116,9 @@ Partial Class OP_OP
End If
If CveMovimientoEntrada > 0 AndAlso Not ErrorMovInv Then
- Dim CantidadPT As Decimal = DtPS.AsEnumerable().Sum(Function(row) Convert.ToDecimal(row("Cantidad")))
- Dim PU_PT As Decimal = If(CantidadPT > 0, TotalCostoMP / CantidadPT, 1)
+ Dim CostoPTAjustado As Decimal = TotalCostoMP - CostoDevoluciones
+ Dim CantidadPT As Decimal = DtPS.AsEnumerable().Sum(Function(r) r.Field(Of Decimal)("Cantidad"))
+ Dim PU_PT As Decimal = If(CantidadPT > 0, CostoPTAjustado / CantidadPT, 0)
For Each rowPT As DataRow In DtPS.Select("Tipo = 'Producto'")
If Not ObjInventario.AddMovimientoDetalle(CveMovimientoEntrada, rowPT("Cantidad").ToString.ToDecimal(), rowPT("CveUM").ToString.ToEntero(), rowPT("Clave").ToString.ToEntero(), PU_PT) Then
@@ -889,24 +1134,24 @@ Partial Class OP_OP
ErrorMovInv = True
End If
- If Not ErrorMovInv AndAlso Not ObjConta.AddPrePolizasDetalle(CvePrePoliza, False, TotalCostoMP, TotalCostoMP, 68, "Producción PT OP #" & LblFolio.Text, "Producción PT OP #" & LblFolio.Text, CveMovimientoAlmacen:=CveMovimientoEntrada) Then
+ If Not ErrorMovInv AndAlso Not ObjConta.AddPrePolizasDetalle(CvePrePoliza, False, CostoPTAjustado, CostoPTAjustado, 68, "Producción PT OP #" & LblFolio.Text, "Producción PT OP #" & LblFolio.Text, CveMovimientoAlmacen:=CveMovimientoEntrada) Then
ErrorMovInv = True
End If
- If Not ErrorMovInv Then
- If Not ObjOP.UpdateEstatusOP(CveOP, 3, UsuarioActual.CveEmpresa) Then
- ErrorMovInv = True : TextoError = "Error al actualizar estatus de la OP"
- End If
- End If
+
+
+ ObjConta.AddPrePolizasDetalle(CvePrePoliza, False, CostoDevoluciones, CostoDevoluciones, 95, "", $"OP #{LblFolio.Text}", CveMovimientoAlmacen:=CveMovimientoDev)
+
+
'If Not ErrorMovInv Then
- ' If Not ObjConta.ValidacionesPrePoliza(CvePrePoliza, UsuarioActual) Then
- ' ErrorMovInv = True : TextoError = "Error en validación de póliza"
- ' ElseIf ObjConta.ValorPolizaDescuadre > 0 Then
- ' ErrorMovInv = True : TextoError = "Descuadre en póliza contable"
- ' End If
+ 'If Not ObjConta.ValidacionesPrePoliza(CvePrePoliza, UsuarioActual) Then
+ 'ErrorMovInv = True : TextoError = "Error en validación de póliza"
+ 'ElseIf ObjConta.ValorPolizaDescuadre > 0 Then
+ ' ErrorMovInv = True : TextoError = "Descuadre en póliza contable"
+ 'End If
'End If
End If
End If
@@ -914,16 +1159,32 @@ Partial Class OP_OP
If Not ErrorMovInv Then
- ObjInventario.Commit()
- Alert($"Orden de producción finalizada.
- {ObjInventario.Folio} ", TipoMensaje.MsgInformacion)
+ If ObjOP.UpdateEstatusOP(CveOP, CveEstatusFinalizar, UsuarioActual.CveEmpresa) Then
+ ObjInventario.Commit()
+ TxtEstatus.Text = EstatusFinalizar
+ DeshabilitarControles()
+ UpOP.Update()
+ UpGvDatosOP.Update()
+ Alert("Orden de producción finalizada. " & "" & FolioEntrada & "",
+ TipoMensaje.MsgInformacion)
+
+
+
+ RegistraScript("$('#DVModalFinalizarOP').modal('hide');")
+
+
+ Else
+ ObjInventario.RollBack()
+ Alert("Error al actualizar el estatus.", TipoMensaje.MsgError)
+ End If
+
Else
ObjInventario.RollBack()
Alert($"Error contable: {TextoError}", TipoMensaje.MsgError)
End If
- RegistraScript("$('#DVModalFinalizarOP').modal('hide');")
- CargaDatos()
+
+
Catch ex As Exception
ObjInventario.RollBack()
@@ -933,7 +1194,6 @@ Partial Class OP_OP
ObjConta.Dispose()
End Try
-
End Sub
#End Region
End Class
diff --git a/Ventas/Clientes.aspx.vb b/Ventas/Clientes.aspx.vb
index 1256f66bd..66f54796e 100644
--- a/Ventas/Clientes.aspx.vb
+++ b/Ventas/Clientes.aspx.vb
@@ -2601,16 +2601,27 @@ Partial Class Clientes
If tPagare = 0 Then InformacionCompleta = False
End If
- If TxtContacto.Text.Trim() = "" Then InformacionCompleta = False
+
If TxtTelefono.Text.Trim() = "" Then InformacionCompleta = False
If TxtEmail.Text.Trim() = "" Then InformacionCompleta = False
- If TxtRepresentanteLegal.Text.Trim() = "" Then InformacionCompleta = False
- tPagare = 0 'valida que cuando menos tenga una cuenta
- For Each dRow As GridViewRow In GvBancosCuentas.Rows
- tPagare = 1
- Next
- If tPagare = 0 Then InformacionCompleta = False
+ 'SOLO VALIDA EN CLIENTES FRENCUENTE
+ If DdlTipoCliente.SelectedValue = "1" Then
+ If TxtContacto.Text.Trim() = "" Then InformacionCompleta = False
+ If TxtRepresentanteLegal.Text.Trim() = "" Then InformacionCompleta = False
+ 'si es el concepto de pagaré
+ Dim tPagare As Integer = 0
+ For Each dRow As GridViewRow In GvDocumentosCliente.Rows
+ Dim CveDocumentacion As Integer = dRow.DataKey("CveDocumentacion").ToEntero()
+ If CveDocumentacion = 265 Then tPagare = 1
+ Next
+ If tPagare = 0 Then InformacionCompleta = False
+ tPagare = 0 'valida que cuando menos tenga una cuenta
+ For Each dRow As GridViewRow In GvBancosCuentas.Rows
+ tPagare = 1
+ Next
+ If tPagare = 0 Then InformacionCompleta = False
+ End If
'If DivInfoCompleta.Visible Then
' InformacionCompleta = ChkInformacionCompleta.Checked
diff --git a/Ventas/PVCobranza.aspx b/Ventas/PVCobranza.aspx
index 1178e920e..74235e10c 100644
--- a/Ventas/PVCobranza.aspx
+++ b/Ventas/PVCobranza.aspx
@@ -706,7 +706,7 @@
$
-
+
@@ -1591,7 +1591,7 @@
} else {
$get("TxtFaltante").value = FormatoNumero(cambio);
$get("ChkSobFaltante").checked = true;
- $get("TxtCambio").value = FormatoNumero(cambio);
+ $get("TxtCambio").value = "";
}
} else {
@@ -1617,15 +1617,26 @@
$('#C_LblDiferenciaCajaBloqueo').val(FormatoNumero(total));
}
+ function ValidaSobranteFaltante() {
+ if (ToDouble($get("TxtFaltante").value) > 1) {
+ alert("El sobrante/faltante no debe ser mayor a 1");
+ $get("TxtFaltante").value = "";
+ $get("ChkSobFaltante").checked = false;
+ } else {
+ $get("ChkSobFaltante").checked = true;
+ }
+ }
+
function CargaSobranteFaltante() {
$('#ChkSobFaltante').change(function () {
if (this.checked == true) {
if (ToDouble($get("TxtCambio").value) > 1) {
alert("El sobrante/faltante no debe ser mayor a 1")
+ $get("ChkSobFaltante").checked = false;
} else {
$get("TxtFaltante").value = $get("TxtCambio").value;
}
-
+
}
else {
$get("TxtFaltante").value = "";
diff --git a/Ventas/PVCobranza.aspx.vb b/Ventas/PVCobranza.aspx.vb
index efa42fdd2..68f1cf8a0 100644
--- a/Ventas/PVCobranza.aspx.vb
+++ b/Ventas/PVCobranza.aspx.vb
@@ -607,6 +607,11 @@ Partial Class Ventas_PVCobranza
Alert("No hay importe para sobrante/faltante", TipoMensaje.MsgAdvertencia)
Exit Sub
End If
+ Else
+ If TxtFaltante.Text.ToDecimal() <> 0 Then
+ Alert("No debe especificar sobrante/faltante", TipoMensaje.MsgAdvertencia)
+ Exit Sub
+ End If
End If
'validaciones
@@ -1024,12 +1029,12 @@ Partial Class Ventas_PVCobranza
If respFactura IsNot Nothing AndAlso respFactura.Factura IsNot Nothing AndAlso respFactura.Factura.DtAnticiposAplicados IsNot Nothing Then
For Each dr As DataRow In respFactura.Factura.DtAnticiposAplicados.Rows
- msBuild.AppendLine($" Imprimir Saldo Aplicado {dr("Folio").ToString} ")
+ respFactura.Factura.Total, dr("Tipo")))}"">Imprimir Saldo Aplicado {dr("Folio").ToString} ")
Next
End If
@@ -1064,12 +1069,12 @@ Partial Class Ventas_PVCobranza
If respNC IsNot Nothing AndAlso respNC.Factura IsNot Nothing AndAlso respNC.Factura.DtAnticiposAplicados IsNot Nothing Then
For Each dr As DataRow In respNC.Factura.DtAnticiposAplicados.Rows
- msBuild.AppendLine($" Imprimir Saldo Aplicado {dr("Folio").ToString} ")
+ respNC.Factura.Total, dr("Tipo")))}"">Imprimir Saldo Aplicado {dr("Folio").ToString} ")
Next
End If
@@ -1444,22 +1449,6 @@ Partial Class Ventas_PVCobranza
For Each msg In Retorno.Mensajes
SbAlert.AppendFormat("{0} ", msg)
Next
-
- SbAlert.AppendFormat("
", Encripta(String.Format("OP=VTA&CVEVENTA={0}&PAG=1&GUARDAR=1", Retorno.CveVenta)))
-
- For Each dr As DataRow In DtAnticipos.Rows
- SBAmortizaciones.AppendLine($" Imprimir historial {dr("Folio").ToString} ")
- Next
-
-
- SbAlert.Append(SBAmortizaciones.ToString)
-
Else
SbAlert.Append("Ocurrió un error al generar la factura")
End If
@@ -1601,7 +1590,6 @@ Partial Class Ventas_PVCobranza
Dim Importe = GvRowAnticipo.FCTextBox(String.Format("TxtAnticipo{0}", GvRowAnticipo.RowIndex)).Text.ToDecimal()
Dim CveConceptoContable = GvRowAnticipo.DataKey("CveConceptoContable").ToEntero()
-
Dim FolioFiscal = GvRowAnticipo.DataKey("FolioFiscal")
Dim Descuentos As Decimal = GvRowAnticipo.DataKey("Descuentos").ToDecimal()
Dim TotalAnticipo As Decimal = GvRowAnticipo.DataKey("TotalAnticipo").ToDecimal()
@@ -1612,8 +1600,10 @@ Partial Class Ventas_PVCobranza
Dim Folio = GvRowAnticipo.DataKey("Folio")
Dim Tipo = GvRowAnticipo.DataKey("Tipo")
-
DtAnticipos.Rows.Add(CveVenta, Importe, CveConceptoContable, CveIE, FolioFiscal, Descuentos, TotalAnticipo, SubTotalAnticipo, CveMoneda, Fecha, TipoCambioPago, Folio, Tipo)
+
+ ObjNC.Observaciones = $"Folio: {GvRowAnticipo.DataKey("Folio")}"
+
End If
ObjNC.EsNCAmortizacion = True
@@ -1708,12 +1698,14 @@ Partial Class Ventas_PVCobranza
'METER LO QUE FALTA COMO GASTO
If (ImporteBancos.RoundSQL(2) + Math.Abs(SobranteFaltante)) = ImporteAbonoVenta.RoundSQL(2) Then
Pago.OtroGastoIngreso = SobranteFaltante.ToString().ToDecimal()
- 'LIMPIAR SOBRANTE/FALTANTE
- SobranteFaltante = 0
+
'SUMAR AL PAGO
If ImporteBancos < ImporteAbonoVenta Then
ImporteBancos += Math.Abs(SobranteFaltante)
End If
+
+ 'LIMPIAR SOBRANTE/FALTANTE
+ SobranteFaltante = 0
End If
End If
@@ -2469,9 +2461,9 @@ Partial Class Ventas_PVCobranza
Dim AnticipoAutorizado = CBool(e.Row.DBCampo("AnticipoAutorizado"))
- 'If Not EsProduccion AndAlso UsuarioActual.CveRol = 1 Then
- ' AnticipoAutorizado = True
- 'End If
+ If Not EsProduccion AndAlso UsuarioActual.CveRol = 1 Then
+ AnticipoAutorizado = True
+ End If
If UsuarioActual.Empresa.Funcionalidad(185) = "1" Then
If e.Row.DBCampo("Tipo").ToString().Contiene("NC", "Ant", "IxC") AndAlso Not AnticipoAutorizado Then
diff --git a/Ventas/Ventas.aspx.vb b/Ventas/Ventas.aspx.vb
index d13f1cad4..012dbd014 100644
--- a/Ventas/Ventas.aspx.vb
+++ b/Ventas/Ventas.aspx.vb
@@ -5255,7 +5255,7 @@ Partial Class Ventas
If TienePermiso <> "" Then ' si tiene acceso en el subproyecto
'LkNotaCredito.Visible = UsuarioActual.TienePermisoProceso(175)
If UsuarioActual.TienePermisoProceso(264) Then
- InicializaAplicaDevolucion(TmpDT)
+ InicializaAplicaDevolucion(TmpDT, DbRowVenta("Fecha").ToString().ToDateTime())
End If
End If
@@ -32863,7 +32863,7 @@ Partial Class Ventas
#End Region
#Region " APLICA DEVOLUCION "
- Private Sub InicializaAplicaDevolucion(DtDetalle As DataTable)
+ Private Sub InicializaAplicaDevolucion(DtDetalle As DataTable, FechaVenta As DateTime)
'If Not UsuarioActual.CveUsuario = 100 Then
' If Not UsuarioActual.CveEmpresa.Contiene(72, 80, 119, 140, 141, 146) Then
' Exit Sub
@@ -32875,7 +32875,17 @@ Partial Class Ventas
Exit Sub
End If
- LBAplicaDevolucion.Visible = True
+ If UsuarioActual.Empresa.Funcionalidad(382) = "1" Then
+ If FechaVenta.ToShortDateString.ToDate < Now.ToShortDateString.ToDate Then
+ LBAplicaDevolucion.Visible = True
+ Else
+ LBAplicaDevolucion.Visible = False
+ End If
+ Else
+ LBAplicaDevolucion.Visible = True
+ End If
+
+
'SOLO APLICA DEVOLUCION SI TIENE MOVIMIENTOS DE ALMACEN
'If VentaSaldoAlmacen < 0 Then