Cambios Finalizacion de OP
This commit is contained in:
@@ -481,15 +481,16 @@ Public Class ClsOP
|
|||||||
Return Retorno
|
Return Retorno
|
||||||
End Function
|
End Function
|
||||||
|
|
||||||
Public Function GetEstatusOP(CveEmpresa As Integer, Optional CveEstatusOP As Integer = -1, Optional TipoEstatus As Integer = -1, Optional Estatus As Integer = -1) As Boolean
|
Public Function GetEstatusOP(CveEmpresa As Integer, Optional CveEstatusOP As Integer = -1, Optional TipoEstatus As Integer = -1, Optional Estatus As Integer = -1, Optional CveUsuario As Integer = -1) As Boolean
|
||||||
Dim Retorno As Boolean = False
|
Dim Retorno As Boolean = False
|
||||||
|
|
||||||
DataAdapter("PA_OP_EstatusOPGet")
|
DataAdapter("PA_OP_EstatusOPGet")
|
||||||
With SqlAdapter.SelectCommand.Parameters
|
With SqlAdapter.SelectCommand.Parameters
|
||||||
.Add("@CveEmpresa", SqlDbType.Int).Value = CveEmpresa
|
.Add("@cveEmpresa", SqlDbType.Int).Value = CveEmpresa
|
||||||
.Add("@CveEstatusOP", SqlDbType.Int).Value = CveEstatusOP
|
.Add("@cveEstatusOP", SqlDbType.Int).Value = CveEstatusOP
|
||||||
.Add("@TipoEstatus", SqlDbType.Int).Value = TipoEstatus
|
.Add("@tipoEstatus", SqlDbType.Int).Value = TipoEstatus
|
||||||
.Add("@Estatus", SqlDbType.Int).Value = Estatus
|
.Add("@estatus", SqlDbType.Int).Value = Estatus
|
||||||
|
.Add("@cveUsuario", SqlDbType.Int).Value = CveUsuario
|
||||||
End With
|
End With
|
||||||
Try
|
Try
|
||||||
SqlAdapter.Fill(Data)
|
SqlAdapter.Fill(Data)
|
||||||
|
|||||||
117
OP/OP.aspx
117
OP/OP.aspx
@@ -279,6 +279,36 @@
|
|||||||
padding: 5px;
|
padding: 5px;
|
||||||
margin-top: 10px;
|
margin-top: 10px;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.quantity-control {
|
||||||
|
position: relative;
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
width: 120px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.quantity-input {
|
||||||
|
width: 70px !important;
|
||||||
|
padding-right: 30px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.quantity-buttons {
|
||||||
|
position: absolute;
|
||||||
|
right: 0;
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
gap: 2px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.btn-quantity {
|
||||||
|
padding: 0;
|
||||||
|
width: 22px;
|
||||||
|
height: 18px;
|
||||||
|
line-height: 1;
|
||||||
|
border: 1px solid #ddd;
|
||||||
|
background: #f8f9fa;
|
||||||
|
cursor: pointer;
|
||||||
|
}
|
||||||
</style>
|
</style>
|
||||||
|
|
||||||
</asp:Content>
|
</asp:Content>
|
||||||
@@ -466,7 +496,8 @@
|
|||||||
<div class="col-md-12">
|
<div class="col-md-12">
|
||||||
<div class="section-title">Productos</div>
|
<div class="section-title">Productos</div>
|
||||||
<asp:GridView ID="GvProductos" runat="server" AutoGenerateColumns="False"
|
<asp:GridView ID="GvProductos" runat="server" AutoGenerateColumns="False"
|
||||||
CssClass="table table-striped table-hover" GridLines="None" Width="100%">
|
CssClass="table table-striped table-hover" GridLines="None" Width="100%"
|
||||||
|
OnRowDataBound="GvProductos_RowDataBound">
|
||||||
<Columns>
|
<Columns>
|
||||||
<asp:BoundField DataField="PSCodigo" HeaderText="Producto" />
|
<asp:BoundField DataField="PSCodigo" HeaderText="Producto" />
|
||||||
<asp:BoundField DataField="UnidadMedida" HeaderText="UM" />
|
<asp:BoundField DataField="UnidadMedida" HeaderText="UM" />
|
||||||
@@ -754,67 +785,115 @@
|
|||||||
<h4 class="modal-title">Finalizar Orden de Producción #<%= LblFolio.Text %></h4>
|
<h4 class="modal-title">Finalizar Orden de Producción #<%= LblFolio.Text %></h4>
|
||||||
</div>
|
</div>
|
||||||
<div class="modal-body">
|
<div class="modal-body">
|
||||||
<!-- Almacén de Materia Prima (Fijo) -->
|
<!-- Sección de Almacenes -->
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="col-md-6 form-group">
|
<!-- Almacén Salida MP -->
|
||||||
<label>Almacén de Salida (Materia Prima):</label>
|
<div class="col-md-4 form-group">
|
||||||
|
<label>Almacén Salida (MP):</label>
|
||||||
<asp:DropDownList ID="DdlAlmacenOrigenSalidaMP" runat="server"
|
<asp:DropDownList ID="DdlAlmacenOrigenSalidaMP" runat="server"
|
||||||
DataTextField="Almacen" DataValueField="CveAlmacen"
|
DataTextField="Almacen" DataValueField="CveAlmacen"
|
||||||
CssClass="form-control select2me" />
|
CssClass="form-control select2me" />
|
||||||
</div>
|
</div>
|
||||||
<!-- Almacén de Producto Terminado (Dropdown) -->
|
|
||||||
<div class="col-md-6 form-group">
|
<!-- Almacén Entrada PT -->
|
||||||
<label>Almacén de Entrada (Producto Terminado):</label>
|
<div class="col-md-4 form-group">
|
||||||
|
<label>Almacén Entrada (PT):</label>
|
||||||
<asp:DropDownList ID="DdlAlmacenTerminado" runat="server"
|
<asp:DropDownList ID="DdlAlmacenTerminado" runat="server"
|
||||||
DataTextField="Almacen" DataValueField="CveAlmacen"
|
DataTextField="Almacen" DataValueField="CveAlmacen"
|
||||||
CssClass="form-control select2me" />
|
CssClass="form-control select2me" />
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<!-- Almacén Devoluciones -->
|
||||||
|
<div class="col-md-4 form-group">
|
||||||
|
<label>Almacén Devoluciones:</label>
|
||||||
|
<asp:DropDownList ID="DdlAlmacenDevolucion" runat="server"
|
||||||
|
DataTextField="Almacen" DataValueField="CveAlmacen"
|
||||||
|
CssClass="form-control select2me" />
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<!-- GridViews -->
|
|
||||||
<div class="row">
|
<div class="row">
|
||||||
|
|
||||||
<div class="col-md-12">
|
<div class="col-md-12">
|
||||||
<div class="section-title">Producto Terminado</div>
|
<div class="section-title">Producto Terminado</div>
|
||||||
<asp:GridView ID="GvProductoTerminado" runat="server" AutoGenerateColumns="False"
|
<asp:GridView ID="GvProductoTerminado" runat="server" AutoGenerateColumns="False"
|
||||||
CssClass="table table-striped table-hover" GridLines="None" Width="100%">
|
CssClass="table table-striped table-hover" GridLines="None" Width="100%"
|
||||||
|
OnRowDataBound="GvProductoTerminado_RowDataBound">
|
||||||
<Columns>
|
<Columns>
|
||||||
<asp:BoundField DataField="PSCodigo" HeaderText="Producto" />
|
<asp:BoundField DataField="PSCodigo" HeaderText="Producto" />
|
||||||
<asp:BoundField DataField="UnidadMedida" HeaderText="UM" />
|
<asp:BoundField DataField="UnidadMedida" HeaderText="UM" />
|
||||||
<asp:BoundField DataField="Cantidad" HeaderText="Cantidad" DataFormatString="{0:N2}" />
|
<asp:TemplateField HeaderText="Cantidad">
|
||||||
|
<ItemTemplate>
|
||||||
|
<asp:TextBox ID="TxtCantidadPT" runat="server"
|
||||||
|
Text='<%# Bind("Cantidad") %>'
|
||||||
|
CssClass="form-control"
|
||||||
|
TextMode="Number"
|
||||||
|
min="0"
|
||||||
|
step="1"
|
||||||
|
data-original='<%# Eval("Cantidad") %>'
|
||||||
|
onchange="validarCantidad(this)" />
|
||||||
|
</ItemTemplate>
|
||||||
|
</asp:TemplateField>
|
||||||
</Columns>
|
</Columns>
|
||||||
</asp:GridView>
|
</asp:GridView>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="row">
|
|
||||||
<div class="col-md-12">
|
<div class="col-md-12">
|
||||||
<div class="section-title">Materia Prima</div>
|
<div class="section-title">Materia Prima</div>
|
||||||
<asp:GridView ID="GvMPUtilizada" runat="server" AutoGenerateColumns="False"
|
<asp:GridView ID="GvMPUtilizada" runat="server" AutoGenerateColumns="False" DataKeyNames="CvePSMateriaPrima, CveUMMateriaPrima"
|
||||||
CssClass="table table-striped table-hover" GridLines="None" Width="100%">
|
CssClass="table table-striped table-hover" GridLines="None" Width="100%">
|
||||||
<Columns>
|
<Columns>
|
||||||
<asp:BoundField DataField="PSCodigo" HeaderText="Producto" />
|
<asp:BoundField DataField="PSCodigo" HeaderText="Producto" />
|
||||||
<asp:BoundField DataField="Cantidad" HeaderText="Cantidad" DataFormatString="{0:N2}" />
|
<asp:BoundField DataField="Cantidad" HeaderText="Cantidad" DataFormatString="{0:N2}" />
|
||||||
|
<asp:TemplateField HeaderText="Devolución">
|
||||||
|
<ItemTemplate>
|
||||||
|
<asp:TextBox ID="TxtDevolucionMP" runat="server"
|
||||||
|
Text="0"
|
||||||
|
CssClass="form-control"
|
||||||
|
TextMode="Number"
|
||||||
|
min="0"
|
||||||
|
step="1"
|
||||||
|
data-original='<%# Eval("Cantidad") %>'
|
||||||
|
onchange="validarCantidad(this)" />
|
||||||
|
</ItemTemplate>
|
||||||
|
|
||||||
|
</asp:TemplateField>
|
||||||
</Columns>
|
</Columns>
|
||||||
</asp:GridView>
|
</asp:GridView>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="modal-footer">
|
<div class="modal-footer">
|
||||||
<%-- Botón Guardar --%>
|
<asp:Button ID="BtnGuardarFinalizarOP" runat="server" Text="Guardar"
|
||||||
<asp:Button ID="BtnGuardarFinalizarOP" runat="server" Text="Guardar"
|
CssClass="btn btn-primary" OnClick="BtnGuardarFinalizarOP_Click" />
|
||||||
CssClass="btn btn-primary" OnClick="BtnGuardarFinalizarOP_Click" />
|
<button type="button" class="btn btn-default" data-dismiss="modal">Cerrar</button>
|
||||||
<%-- Botón Cerrar --%>
|
</div>
|
||||||
<button type="button" class="btn btn-default" data-dismiss="modal">Cerrar</button>
|
|
||||||
</div>
|
|
||||||
</ContentTemplate>
|
</ContentTemplate>
|
||||||
</asp:UpdatePanel>
|
</asp:UpdatePanel>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
</asp:Content>
|
</asp:Content>
|
||||||
|
|
||||||
|
|
||||||
<asp:Content ID="Content8" ContentPlaceHolderID="JS" runat="Server">
|
<asp:Content ID="Content8" ContentPlaceHolderID="JS" runat="Server">
|
||||||
|
<script>
|
||||||
|
function validarCantidad(input) {
|
||||||
|
var valor = parseFloat(input.value) || 0;
|
||||||
|
var maximo = parseFloat(input.getAttribute('data-original')) || 0;
|
||||||
|
|
||||||
|
if (valor > maximo) {
|
||||||
|
input.value = maximo.toFixed(4);
|
||||||
|
alert("¡La cantidad no puede superar el valor original!");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
</script>
|
||||||
</asp:Content>
|
</asp:Content>
|
||||||
|
|
||||||
|
|||||||
384
OP/OP.aspx.vb
384
OP/OP.aspx.vb
@@ -41,7 +41,15 @@ Partial Class OP_OP
|
|||||||
|
|
||||||
Private Property DtMO As DataTable
|
Private Property DtMO As DataTable
|
||||||
Get
|
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
|
End Get
|
||||||
Set(value As DataTable)
|
Set(value As DataTable)
|
||||||
ViewState("DtMO") = value
|
ViewState("DtMO") = value
|
||||||
@@ -50,13 +58,31 @@ Partial Class OP_OP
|
|||||||
|
|
||||||
Private Property DtCI As DataTable
|
Private Property DtCI As DataTable
|
||||||
Get
|
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
|
End Get
|
||||||
Set(value As DataTable)
|
Set(value As DataTable)
|
||||||
ViewState("DtCI") = value
|
ViewState("DtCI") = value
|
||||||
End Set
|
End Set
|
||||||
End Property
|
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
|
Private Property DtMPAgregados As DataTable
|
||||||
Get
|
Get
|
||||||
If ViewState("DtMPAgregados") Is Nothing Then
|
If ViewState("DtMPAgregados") Is Nothing Then
|
||||||
@@ -74,12 +100,27 @@ Partial Class OP_OP
|
|||||||
End Set
|
End Set
|
||||||
End Property
|
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
|
#End Region
|
||||||
|
|
||||||
Protected Sub Page_Load(sender As Object, e As System.EventArgs) Handles Me.Load
|
Protected Sub Page_Load(sender As Object, e As System.EventArgs) Handles Me.Load
|
||||||
If Not IsPostBack Then
|
If Not IsPostBack Then
|
||||||
CveOP = If(Request("CveOP") <> "", Request("CveOP").ToString.ToEntero, "-1".ToEntero)
|
CveOP = If(Request("CveOP") <> "", Request("CveOP").ToString.ToEntero, "-1".ToEntero)
|
||||||
|
TipoEstatus = -1
|
||||||
CreaPS()
|
CreaPS()
|
||||||
SetValues()
|
SetValues()
|
||||||
End If
|
End If
|
||||||
@@ -106,6 +147,7 @@ Partial Class OP_OP
|
|||||||
DtMP.Columns.Add("UnidadMedida", GetType(String))
|
DtMP.Columns.Add("UnidadMedida", GetType(String))
|
||||||
DtMP.Columns.Add("Cantidad", GetType(Decimal))
|
DtMP.Columns.Add("Cantidad", GetType(Decimal))
|
||||||
DtMP.Columns.Add("Surtido", GetType(Decimal))
|
DtMP.Columns.Add("Surtido", GetType(Decimal))
|
||||||
|
'DtMP.Columns.Add("CvePSProducto", GetType(Integer))
|
||||||
'DtMP.Columns.Add("CveAlmacenDestino", GetType(Integer))
|
'DtMP.Columns.Add("CveAlmacenDestino", GetType(Integer))
|
||||||
|
|
||||||
DtMO = New DataTable()
|
DtMO = New DataTable()
|
||||||
@@ -115,15 +157,17 @@ Partial Class OP_OP
|
|||||||
DtMO.Columns.Add("CvePuesto", GetType(Integer))
|
DtMO.Columns.Add("CvePuesto", GetType(Integer))
|
||||||
DtMO.Columns.Add("Puesto", GetType(String))
|
DtMO.Columns.Add("Puesto", GetType(String))
|
||||||
DtMO.Columns.Add("Cantidad", GetType(Decimal))
|
DtMO.Columns.Add("Cantidad", GetType(Decimal))
|
||||||
|
DtMO.Columns.Add("CostoHora", GetType(Decimal))
|
||||||
|
DtMO.Columns.Add("Total", GetType(Decimal))
|
||||||
|
|
||||||
|
|
||||||
DtCI = New DataTable()
|
DtCI = New DataTable()
|
||||||
DtCI.Columns.Add("Tipo", GetType(String)) ' Producto, MP, MO, CI
|
DtCI.Columns.Add("Tipo", GetType(String)) ' Producto, MP, MO, CI
|
||||||
DtCI.Columns.Add("Clave", GetType(Integer))
|
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("productoMateriaPrima", GetType(String))
|
||||||
DtCI.Columns.Add("Cantidad", GetType(Decimal))
|
DtCI.Columns.Add("Cantidad", GetType(Decimal))
|
||||||
|
DtCI.Columns.Add("PU", GetType(Decimal))
|
||||||
|
DtCI.Columns.Add("Total", GetType(Decimal))
|
||||||
|
|
||||||
|
|
||||||
End Sub
|
End Sub
|
||||||
@@ -133,24 +177,65 @@ Partial Class OP_OP
|
|||||||
CargarClientes()
|
CargarClientes()
|
||||||
CargarCentrosDeCosto(DdlProyecto, DdlSubProyecto, LblProyecto, LblSubProyecto, divProyecto:=DivProyecto, VisualizacionReporte:=1)
|
CargarCentrosDeCosto(DdlProyecto, DdlSubProyecto, LblProyecto, LblSubProyecto, divProyecto:=DivProyecto, VisualizacionReporte:=1)
|
||||||
CargarProductos()
|
CargarProductos()
|
||||||
|
CargaDatos()
|
||||||
|
|
||||||
If CveOP = -1 Then
|
If TipoEstatus = 3 Then
|
||||||
|
DeshabilitarControles() ' Deshabilita todos los controles relevantes
|
||||||
DdlClientes.Enabled = True
|
|
||||||
DdlProyecto.Enabled = True
|
|
||||||
DdlSubProyecto.Enabled = True
|
|
||||||
DdlPS.Enabled = True
|
|
||||||
LnkSolicitarMP.Visible = False
|
|
||||||
BtnSimularMP.Visible = True
|
|
||||||
BtnFinalizarOP.Visible = False
|
|
||||||
Else
|
Else
|
||||||
DdlClientes.Enabled = False
|
If CveOP = -1 Then ' Nueva OP
|
||||||
DdlPS.Enabled = False
|
DdlClientes.Enabled = True
|
||||||
LnkSolicitarMP.Visible = False
|
DdlProyecto.Enabled = True
|
||||||
BtnSimularMP.Visible = False
|
DdlSubProyecto.Enabled = True
|
||||||
BtnFinalizarOP.Visible = True
|
DdlPS.Enabled = True
|
||||||
CargaDatos()
|
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
|
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
|
End Sub
|
||||||
|
|
||||||
Private Sub CargaDatos()
|
Private Sub CargaDatos()
|
||||||
@@ -169,6 +254,7 @@ Partial Class OP_OP
|
|||||||
DdlPS.txtValue.Value = dr("CvePS").ToString
|
DdlPS.txtValue.Value = dr("CvePS").ToString
|
||||||
Txtfecha.Text = dr("Fecha").ToString
|
Txtfecha.Text = dr("Fecha").ToString
|
||||||
TxtDescripcion.Text = dr("Descripcion").ToString
|
TxtDescripcion.Text = dr("Descripcion").ToString
|
||||||
|
TipoEstatus = dr("TipoEstatus").ToString.ToEntero
|
||||||
|
|
||||||
|
|
||||||
If ObjOP.GetProductosOP(CveOP, UsuarioActual.CveEmpresa) Then
|
If ObjOP.GetProductosOP(CveOP, UsuarioActual.CveEmpresa) Then
|
||||||
@@ -221,7 +307,7 @@ Partial Class OP_OP
|
|||||||
Dim newRow As DataRow = DtCI.NewRow()
|
Dim newRow As DataRow = DtCI.NewRow()
|
||||||
newRow("Tipo") = "CI"
|
newRow("Tipo") = "CI"
|
||||||
newRow("productoMateriaPrima") = rowCI("producto").ToString
|
newRow("productoMateriaPrima") = rowCI("producto").ToString
|
||||||
newRow("Cantidad") = rowCI("Cantidad").ToString.ToDecimal
|
newRow("Costo") = rowCI("Costo").ToString.ToDecimal
|
||||||
DtCI.Rows.Add(newRow)
|
DtCI.Rows.Add(newRow)
|
||||||
|
|
||||||
Next
|
Next
|
||||||
@@ -292,6 +378,7 @@ Partial Class OP_OP
|
|||||||
rowMP("PSCodigo") = drMP("productoMateriaPrima").ToString()
|
rowMP("PSCodigo") = drMP("productoMateriaPrima").ToString()
|
||||||
rowMP("UnidadMedida") = drMP("UnidadMedidaMateriaPrima").ToString()
|
rowMP("UnidadMedida") = drMP("UnidadMedidaMateriaPrima").ToString()
|
||||||
rowMP("Cantidad") = drMP("Cantidad").ToString().ToDecimal()
|
rowMP("Cantidad") = drMP("Cantidad").ToString().ToDecimal()
|
||||||
|
'rowMP("CvePSProducto") = CvePS
|
||||||
rowMP("Surtido") = 0
|
rowMP("Surtido") = 0
|
||||||
DtMP.Rows.Add(rowMP)
|
DtMP.Rows.Add(rowMP)
|
||||||
Next
|
Next
|
||||||
@@ -306,6 +393,8 @@ Partial Class OP_OP
|
|||||||
rowMO("Clave") = CvePS
|
rowMO("Clave") = CvePS
|
||||||
rowMO("Puesto") = drMO("Puesto").ToString()
|
rowMO("Puesto") = drMO("Puesto").ToString()
|
||||||
rowMO("Cantidad") = drMO("Cantidad").ToString().ToDecimal()
|
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)
|
DtMO.Rows.Add(rowMO)
|
||||||
Next
|
Next
|
||||||
End If
|
End If
|
||||||
@@ -321,6 +410,8 @@ Partial Class OP_OP
|
|||||||
'rowCI("CvePSMateriaPrima") = drCI("CvePSMateriaPrima").ToString().ToEntero()
|
'rowCI("CvePSMateriaPrima") = drCI("CvePSMateriaPrima").ToString().ToEntero()
|
||||||
rowCI("productoMateriaPrima") = drCI("productoMateriaPrima").ToString()
|
rowCI("productoMateriaPrima") = drCI("productoMateriaPrima").ToString()
|
||||||
rowCI("Cantidad") = drCI("Cantidad").ToString().ToDecimal()
|
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)
|
DtCI.Rows.Add(rowCI)
|
||||||
Next
|
Next
|
||||||
End If
|
End If
|
||||||
@@ -329,6 +420,12 @@ Partial Class OP_OP
|
|||||||
End Sub
|
End Sub
|
||||||
|
|
||||||
Protected Sub BtnEliminarProducto_Click(sender As Object, e As EventArgs)
|
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 btnEliminar As LinkButton = DirectCast(sender, LinkButton)
|
||||||
Dim CveProducto As Integer = btnEliminar.CommandArgument.ToEntero()
|
Dim CveProducto As Integer = btnEliminar.CommandArgument.ToEntero()
|
||||||
|
|
||||||
@@ -361,6 +458,13 @@ Partial Class OP_OP
|
|||||||
Next
|
Next
|
||||||
End Sub
|
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)
|
Protected Sub LnkSolicitarMP_Click(sender As Object, e As EventArgs)
|
||||||
' Cargar almacenes
|
' Cargar almacenes
|
||||||
DdlAlmacenOrigenMP.DataSource = GlobalDTAlmacen(UsuarioActual.CveEmpresa).FiltraParametros("CveTipoAlmacen = 1")
|
DdlAlmacenOrigenMP.DataSource = GlobalDTAlmacen(UsuarioActual.CveEmpresa).FiltraParametros("CveTipoAlmacen = 1")
|
||||||
@@ -560,16 +664,16 @@ Partial Class OP_OP
|
|||||||
Dim MensajeExistencia As New StringBuilder
|
Dim MensajeExistencia As New StringBuilder
|
||||||
MensajeExistencia.Append("No hay la existencia suficiente de los siguientes productos:<br/>")
|
MensajeExistencia.Append("No hay la existencia suficiente de los siguientes productos:<br/>")
|
||||||
|
|
||||||
'✅ 1. Validar existencias de MP
|
|
||||||
For Each row As GridViewRow In GvMPAgregados.Rows
|
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 CveMP As Integer = GvMPAgregados.DataKeys(row.RowIndex)("CvePSMateriaPrima").ToString().ToEntero()
|
||||||
Dim CveUMMP As Integer = GvMPAgregados.DataKeys(row.RowIndex)("CveUMMateriaPrima").ToString().ToEntero()
|
Dim CveUMMP As Integer = GvMPAgregados.DataKeys(row.RowIndex)("CveUMMateriaPrima").ToString().ToEntero()
|
||||||
Dim CantidadSolicitada As Decimal = DtMP.Rows(row.RowIndex)("Cantidad").ToString().ToDecimal()
|
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(
|
Dim Existencia As Decimal = ObjInventario.GetExistenciasPS(
|
||||||
CvePS:=CveMP,
|
CvePS:=CveMP,
|
||||||
CveUnidadMedida:=CveUMMP,
|
CveUnidadMedida:=CveUMMP,
|
||||||
@@ -596,7 +700,7 @@ Partial Class OP_OP
|
|||||||
Exit Sub
|
Exit Sub
|
||||||
End If
|
End If
|
||||||
|
|
||||||
'✅ 2. Crear traspaso si todo está correcto
|
|
||||||
ObjInventario.IniciaTransacSQL()
|
ObjInventario.IniciaTransacSQL()
|
||||||
Dim TieneError As Boolean = False
|
Dim TieneError As Boolean = False
|
||||||
|
|
||||||
@@ -618,10 +722,10 @@ Partial Class OP_OP
|
|||||||
TieneError = True
|
TieneError = True
|
||||||
End If
|
End If
|
||||||
|
|
||||||
'✅ 3. Agregar detalles del traspaso
|
|
||||||
If Not TieneError Then
|
If Not TieneError Then
|
||||||
For Each row As GridViewRow In GvMPAgregados.Rows
|
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 CveMP As Integer = GvMPAgregados.DataKeys(row.RowIndex)("CvePSMateriaPrima").ToString().ToEntero()
|
||||||
Dim CveUMMP As Integer = GvMPAgregados.DataKeys(row.RowIndex)("CveUMMateriaPrima").ToString().ToEntero()
|
Dim CveUMMP As Integer = GvMPAgregados.DataKeys(row.RowIndex)("CveUMMateriaPrima").ToString().ToEntero()
|
||||||
Dim Cantidad As Decimal = DtMP.Rows(row.RowIndex)("Cantidad").ToString().ToDecimal()
|
Dim Cantidad As Decimal = DtMP.Rows(row.RowIndex)("Cantidad").ToString().ToDecimal()
|
||||||
@@ -629,8 +733,8 @@ Partial Class OP_OP
|
|||||||
If Not ObjInventario.AddTrasladoSolicitudDetalle(
|
If Not ObjInventario.AddTrasladoSolicitudDetalle(
|
||||||
CveTraspasoSolicitud,
|
CveTraspasoSolicitud,
|
||||||
Cantidad,
|
Cantidad,
|
||||||
CveUMMP, '✅ Unidad de medida de la MP
|
CveUMMP,
|
||||||
CveMP, '✅ Clave de la MP
|
CveMP,
|
||||||
0, "", -1, "-1", "-1", MinFecha
|
0, "", -1, "-1", "-1", MinFecha
|
||||||
) Then
|
) Then
|
||||||
TieneError = True
|
TieneError = True
|
||||||
@@ -639,7 +743,7 @@ Partial Class OP_OP
|
|||||||
Next
|
Next
|
||||||
End If
|
End If
|
||||||
|
|
||||||
'✅ 4. Confirmar o cancelar transacción
|
|
||||||
If Not TieneError Then
|
If Not TieneError Then
|
||||||
ObjInventario.Commit()
|
ObjInventario.Commit()
|
||||||
Alert($"Solicitud de Traspaso guardada. Folio: <b>{FolioSolicitud}</b>", TipoMensaje.MsgInformacion)
|
Alert($"Solicitud de Traspaso guardada. Folio: <b>{FolioSolicitud}</b>", TipoMensaje.MsgInformacion)
|
||||||
@@ -786,18 +890,35 @@ Partial Class OP_OP
|
|||||||
End Sub
|
End Sub
|
||||||
|
|
||||||
Protected Sub DdlAlmacenOrigenMP_SelectedIndexChanged(sender As Object, e As EventArgs)
|
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.DataSource = GlobalDTAlmacen(UsuarioActual.CveEmpresa).FiltraParametros("CveTipoAlmacen = 28")
|
||||||
DdlAlmacenDestinoMP.DataBind()
|
DdlAlmacenDestinoMP.DataBind()
|
||||||
|
|
||||||
' ✅ Opcional: Seleccionar el primer almacén de producción por defecto
|
|
||||||
If DdlAlmacenDestinoMP.Items.Count > 0 Then
|
If DdlAlmacenDestinoMP.Items.Count > 0 Then
|
||||||
DdlAlmacenDestinoMP.SelectedIndex = 0
|
DdlAlmacenDestinoMP.SelectedIndex = 0
|
||||||
End If
|
End If
|
||||||
End Sub
|
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)
|
Protected Sub BtnFinalizarOP_Click(sender As Object, e As EventArgs)
|
||||||
If CveOP = -1 Then Exit Sub
|
If CveOP = -1 Then Exit Sub
|
||||||
|
|
||||||
@@ -811,6 +932,11 @@ Partial Class OP_OP
|
|||||||
DdlAlmacenTerminado.DataBind()
|
DdlAlmacenTerminado.DataBind()
|
||||||
DdlAlmacenTerminado.Items.Insert(0, New ListItem("Seleccionar almacén", "-1"))
|
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
|
' 3. Cargar GridViews
|
||||||
GvProductoTerminado.DataSource = DtPS.FiltraParametros("Tipo = 'Producto'")
|
GvProductoTerminado.DataSource = DtPS.FiltraParametros("Tipo = 'Producto'")
|
||||||
GvProductoTerminado.DataBind()
|
GvProductoTerminado.DataBind()
|
||||||
@@ -823,15 +949,42 @@ Partial Class OP_OP
|
|||||||
End Sub
|
End Sub
|
||||||
|
|
||||||
Protected Sub BtnGuardarFinalizarOP_Click(sender As Object, e As EventArgs)
|
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
|
If DdlAlmacenOrigenSalidaMP.SelectedValue = "-1" OrElse DdlAlmacenTerminado.SelectedValue = "-1" Then
|
||||||
Alert("Selecciona ambos almacenes.", TipoMensaje.MsgAdvertencia)
|
Alert("Selecciona ambos almacenes.", TipoMensaje.MsgAdvertencia)
|
||||||
Exit Sub
|
Exit Sub
|
||||||
End If
|
End If
|
||||||
|
|
||||||
' Dim TotalCantidad As Decimal = DtMovimientos.SUMD("Cantidad")
|
For Each row As GridViewRow In GvProductoTerminado.Rows
|
||||||
'Inicia la transacción
|
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 CveMovimientoEntrada As Integer = 0
|
||||||
Dim IDPoliza As Integer = 0
|
Dim IDPoliza As Integer = 0
|
||||||
Dim FolioSalida As Integer = 0
|
Dim FolioSalida As Integer = 0
|
||||||
@@ -844,8 +997,13 @@ Partial Class OP_OP
|
|||||||
Dim ErrorMovInv As Boolean = False
|
Dim ErrorMovInv As Boolean = False
|
||||||
Dim TextoError As String = ""
|
Dim TextoError As String = ""
|
||||||
Dim TipoMovimientoSalida As Integer = 8
|
Dim TipoMovimientoSalida As Integer = 8
|
||||||
|
Dim TipoMovimientoDev As Integer = 33
|
||||||
Dim CveConceptoEntrada As Integer = 9
|
Dim CveConceptoEntrada As Integer = 9
|
||||||
Dim TotalCostoMP As Decimal = 0
|
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()
|
Dim ObjInventario As New ClsInventarios()
|
||||||
|
|
||||||
@@ -855,16 +1013,102 @@ Partial Class OP_OP
|
|||||||
Try
|
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")
|
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
|
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
|
For Each rowMP As DataRow In DtMP.Select("Tipo = 'MP'")
|
||||||
ErrorMovInv = True : TextoError = "x" : Exit For
|
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
|
End If
|
||||||
Next
|
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
|
End If
|
||||||
|
|
||||||
If Not ErrorMovInv Then
|
If Not ErrorMovInv Then
|
||||||
@@ -872,8 +1116,9 @@ Partial Class OP_OP
|
|||||||
End If
|
End If
|
||||||
|
|
||||||
If CveMovimientoEntrada > 0 AndAlso Not ErrorMovInv Then
|
If CveMovimientoEntrada > 0 AndAlso Not ErrorMovInv Then
|
||||||
Dim CantidadPT As Decimal = DtPS.AsEnumerable().Sum(Function(row) Convert.ToDecimal(row("Cantidad")))
|
Dim CostoPTAjustado As Decimal = TotalCostoMP - CostoDevoluciones
|
||||||
Dim PU_PT As Decimal = If(CantidadPT > 0, TotalCostoMP / CantidadPT, 1)
|
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'")
|
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
|
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
|
ErrorMovInv = True
|
||||||
End If
|
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
|
ErrorMovInv = True
|
||||||
End If
|
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
|
ObjConta.AddPrePolizasDetalle(CvePrePoliza, False, CostoDevoluciones, CostoDevoluciones, 95, "", $"OP #{LblFolio.Text}", CveMovimientoAlmacen:=CveMovimientoDev)
|
||||||
End If
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
'If Not ErrorMovInv Then
|
'If Not ErrorMovInv Then
|
||||||
' If Not ObjConta.ValidacionesPrePoliza(CvePrePoliza, UsuarioActual) Then
|
'If Not ObjConta.ValidacionesPrePoliza(CvePrePoliza, UsuarioActual) Then
|
||||||
' ErrorMovInv = True : TextoError = "Error en validación de póliza"
|
'ErrorMovInv = True : TextoError = "Error en validación de póliza"
|
||||||
' ElseIf ObjConta.ValorPolizaDescuadre > 0 Then
|
'ElseIf ObjConta.ValorPolizaDescuadre > 0 Then
|
||||||
' ErrorMovInv = True : TextoError = "Descuadre en póliza contable"
|
' ErrorMovInv = True : TextoError = "Descuadre en póliza contable"
|
||||||
' End If
|
'End If
|
||||||
'End If
|
'End If
|
||||||
End If
|
End If
|
||||||
End If
|
End If
|
||||||
@@ -914,16 +1159,32 @@ Partial Class OP_OP
|
|||||||
|
|
||||||
|
|
||||||
If Not ErrorMovInv Then
|
If Not ErrorMovInv Then
|
||||||
ObjInventario.Commit()
|
If ObjOP.UpdateEstatusOP(CveOP, CveEstatusFinalizar, UsuarioActual.CveEmpresa) Then
|
||||||
Alert($"Orden de producción finalizada.
|
ObjInventario.Commit()
|
||||||
<br/><a class='Texto' href='/Inventarios/EntradasSalidas.aspx?CveMovimiento= {CveMovimientoEntrada}'>{ObjInventario.Folio}</a> ", TipoMensaje.MsgInformacion)
|
TxtEstatus.Text = EstatusFinalizar
|
||||||
|
DeshabilitarControles()
|
||||||
|
UpOP.Update()
|
||||||
|
UpGvDatosOP.Update()
|
||||||
|
Alert("Orden de producción finalizada.<br/>" & "<a class='Texto' href='/Inventarios/EntradasSalidas.aspx?CveMovimiento=" & CveMovimientoEntrada & "'>" & FolioEntrada & "</a>",
|
||||||
|
TipoMensaje.MsgInformacion)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
RegistraScript("$('#DVModalFinalizarOP').modal('hide');")
|
||||||
|
|
||||||
|
|
||||||
|
Else
|
||||||
|
ObjInventario.RollBack()
|
||||||
|
Alert("Error al actualizar el estatus.", TipoMensaje.MsgError)
|
||||||
|
End If
|
||||||
|
|
||||||
Else
|
Else
|
||||||
ObjInventario.RollBack()
|
ObjInventario.RollBack()
|
||||||
Alert($"Error contable: {TextoError}", TipoMensaje.MsgError)
|
Alert($"Error contable: {TextoError}", TipoMensaje.MsgError)
|
||||||
End If
|
End If
|
||||||
|
|
||||||
RegistraScript("$('#DVModalFinalizarOP').modal('hide');")
|
|
||||||
CargaDatos()
|
|
||||||
|
|
||||||
Catch ex As Exception
|
Catch ex As Exception
|
||||||
ObjInventario.RollBack()
|
ObjInventario.RollBack()
|
||||||
@@ -933,7 +1194,6 @@ Partial Class OP_OP
|
|||||||
ObjConta.Dispose()
|
ObjConta.Dispose()
|
||||||
End Try
|
End Try
|
||||||
|
|
||||||
|
|
||||||
End Sub
|
End Sub
|
||||||
#End Region
|
#End Region
|
||||||
End Class
|
End Class
|
||||||
|
|||||||
Reference in New Issue
Block a user