diff --git a/DbBackup/stp_ItemShrinkHist.sql b/DbBackup/stp_ItemShrinkHist.sql new file mode 100644 index 0000000..e3f286d --- /dev/null +++ b/DbBackup/stp_ItemShrinkHist.sql @@ -0,0 +1,71 @@ +USE [StockMan] +GO + +/****** Object: StoredProcedure [dbo].[stp_ItemShrinkHist] Script Date: 29/09/2016 23:44:55 ******/ +SET ANSI_NULLS ON +GO + +SET QUOTED_IDENTIFIER ON +GO + + +-- ============================================= +-- Author: S.E.L. +-- Create date: 2016.09.21 +-- Description: Riduce i movimenti per una data locazione-item (nulli, oppure a somma nulla a pari giorno) +-- ============================================= +CREATE PROCEDURE [dbo].[stp_ItemShrinkHist] +( + @ItemID INT = 0 +) +AS +BEGIN + -- SET NOCOUNT ON added to prevent extra result sets from + -- interfering with SELECT statements. + SET NOCOUNT ON; + + BEGIN tran + -- elimino in primis i movimenti nulli... + DELETE + FROM ItemFlux + WHERE Qta = 0 + AND ItemID = @ItemID + + -- cerco movimenti di un item solo positivi o solo negativi + ;WITH cteAdd AS + ( + SELECT * + FROM ItemFlux + WHERE Qta > 0 + AND ItemID = @ItemID + ), cteRem AS + ( + SELECT * + FROM ItemFlux + WHERE Qta < 0 + AND ItemID = @ItemID + ) + -- li incrocio e se si annullano.. + , cteNull AS + ( + SELECT a.* + FROM cteAdd a INNER JOIN cteRem r + ON a.LocationID=r.LocationID + AND a.dtMov = r.dtMov + AND ABS(a.Qta) = ABS(r.Qta) + ) + --select * from cteNull + -- ora che li ho selezionati li elimino... + DELETE iflx + FROM ItemFlux iflx INNER JOIN cteNull cte + ON iflx.LocationID = cte.LocationID + AND iflx.ItemID = cte.ItemID + AND iflx.dtMov = cte.dtMov + WHERE ABS(iflx.Qta) = ABS(cte.Qta) + + COMMIT tran +END + +GO + + diff --git a/StockManMVC/Controllers/ItemsController.cs b/StockManMVC/Controllers/ItemsController.cs index b71fd05..6e85fdf 100644 --- a/StockManMVC/Controllers/ItemsController.cs +++ b/StockManMVC/Controllers/ItemsController.cs @@ -170,6 +170,33 @@ namespace StockManMVC.Controllers } } + // GET: Items/ShrinkHistory/5?caller=callingController + public ActionResult ShrinkHistory(int? id, string caller) + { + if (id == null) + { + return new HttpStatusCodeResult(HttpStatusCode.BadRequest); + } + // chiamo stored x consolidamento flussi (da movimenti a giacenza confermata) + using (var ctx = new StockManEntities()) + { + // esegue stored procedure come function, SE id == 0 processa TUTTI... + int rowMod = ctx.stp_ItemShrinkHist(id); + } + + // se non specificati rimando a /Items/Details + if (caller == "") caller = "Items"; + + // rimanda alla view principale da cui รจ stata fatta la chiamata... + if (caller == "Items") + { + return RedirectToAction("Details", "Items", new { ID = id, StockItemID = id, FluxItemID = id }); + } + else + { + return RedirectToAction("Index", "vItemFlux2Save"); + } + } /// /// calcolo num risultati diff --git a/StockManMVC/Models/SMModel.Context.cs b/StockManMVC/Models/SMModel.Context.cs index 171c762..dac5099 100644 --- a/StockManMVC/Models/SMModel.Context.cs +++ b/StockManMVC/Models/SMModel.Context.cs @@ -110,5 +110,14 @@ namespace StockManMVC.Models return ((IObjectContextAdapter)this).ObjectContext.ExecuteFunction("stp_ItemStockMove_New", stockIDParameter, locationID_FROMParameter, locationID_TOParameter, operatorIDParameter, qtyMovParameter); } + + public virtual int stp_ItemShrinkHist(Nullable itemID) + { + var itemIDParameter = itemID.HasValue ? + new ObjectParameter("ItemID", itemID) : + new ObjectParameter("ItemID", typeof(int)); + + return ((IObjectContextAdapter)this).ObjectContext.ExecuteFunction("stp_ItemShrinkHist", itemIDParameter); + } } } diff --git a/StockManMVC/Models/SMModel.edmx b/StockManMVC/Models/SMModel.edmx index 89d550a..b728b40 100644 --- a/StockManMVC/Models/SMModel.edmx +++ b/StockManMVC/Models/SMModel.edmx @@ -229,6 +229,9 @@ warning 6002: The table/view 'StockMan.dbo.vLocationVal' does not have a primary + + + @@ -500,6 +503,9 @@ warning 6002: The table/view 'StockMan.dbo.vLocationVal' does not have a primary + + + @@ -794,6 +800,7 @@ warning 6002: The table/view 'StockMan.dbo.vLocationVal' does not have a primary + diff --git a/StockManMVC/Views/Items/Details.cshtml b/StockManMVC/Views/Items/Details.cshtml index 2a6da52..04baf41 100644 --- a/StockManMVC/Views/Items/Details.cshtml +++ b/StockManMVC/Views/Items/Details.cshtml @@ -95,10 +95,21 @@
@Html.MVCGrid("StockItemsGrid") - - - Registra movimenti - + +
@@ -130,40 +141,35 @@
@*
- - - - -
*@ + + + + +
*@ @* - - ALL/none - *@ + + ALL/none + *@ - @Html.Partial("_MVCGridToolbar", new StockManMVC.Models.MVCGridToolbarModel() - { - MVCGridName = "FluxItemsGrid", - PageSize = true, - ColumnVisibility = true, - Export = false, - GlobalSearch = true - }) - @Html.MVCGrid("FluxItemsGrid") -
+ @Html.Partial("_MVCGridToolbar", new StockManMVC.Models.MVCGridToolbarModel() + { + MVCGridName = "FluxItemsGrid", + PageSize = true, + ColumnVisibility = true, + Export = false, + GlobalSearch = true + }) + @Html.MVCGrid("FluxItemsGrid") +
- - - - - diff --git a/StockManMVC/bin/StockManMVC.dll b/StockManMVC/bin/StockManMVC.dll index 0ec501d..1903eb8 100644 Binary files a/StockManMVC/bin/StockManMVC.dll and b/StockManMVC/bin/StockManMVC.dll differ