727 lines
31 KiB
C#
727 lines
31 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Data;
|
|
using System.Data.Entity;
|
|
using System.Linq;
|
|
using System.Net;
|
|
using System.Web;
|
|
using System.Web.Mvc;
|
|
using StockManMVC.Models;
|
|
using X.PagedList;
|
|
|
|
namespace StockManMVC.Controllers
|
|
{
|
|
public class ItemFluxesController : Controller
|
|
{
|
|
private StockManEntities db = new StockManEntities();
|
|
|
|
/// <summary>
|
|
/// Selezione
|
|
/// </summary>
|
|
/// <param name="ItemID"></param>
|
|
/// <param name="SearchVal"></param>
|
|
/// <returns></returns>
|
|
public static IEnumerable<ItemFlux> Select(int? ItemID, string SearchVal)
|
|
{
|
|
StockManEntities db = new StockManEntities();
|
|
if (ItemID == null)
|
|
{
|
|
ItemID = 0;
|
|
}
|
|
var answ = db.ItemFlux.Where(s => s.ItemID == ItemID
|
|
&& (
|
|
s.Note.Contains(SearchVal)
|
|
|| s.Location.Descr.Contains(SearchVal)
|
|
|| s.Location1.Descr.Contains(SearchVal)
|
|
|| s.Operator.LastName.Contains(SearchVal)
|
|
|| s.Operator.FirstName.Contains(SearchVal)
|
|
|| s.MovType.Descr.Contains(SearchVal)
|
|
));
|
|
return answ;
|
|
}
|
|
/// <summary>
|
|
/// Ricerca con selezione parametri
|
|
/// </summary>
|
|
/// <param name="ItemID"></param>
|
|
/// <param name="SearchVal"></param>
|
|
/// <param name="OrderBy"></param>
|
|
/// <param name="Sort"></param>
|
|
/// <returns></returns>
|
|
public static IEnumerable<ItemFlux> Order(int? ItemID, string SearchVal, string OrderBy, string Sort)
|
|
{
|
|
IEnumerable<ItemFlux> answ = Select(ItemID, SearchVal);
|
|
switch (OrderBy)
|
|
{
|
|
case "note":
|
|
if (Sort == "dsc")
|
|
{
|
|
answ = answ.OrderByDescending(x => x.Note);
|
|
}
|
|
else
|
|
{
|
|
answ = answ.OrderBy(x => x.Note);
|
|
}
|
|
break;
|
|
case "Posizione":
|
|
if (Sort == "dsc")
|
|
{
|
|
answ = answ.OrderByDescending(x => x.Location.Descr);
|
|
}
|
|
else
|
|
{
|
|
answ = answ.OrderBy(x => x.Location.Descr);
|
|
}
|
|
break;
|
|
case "Tipo":
|
|
if (Sort == "dsc")
|
|
{
|
|
answ = answ.OrderByDescending(x => x.MovType.Descr);
|
|
}
|
|
else
|
|
{
|
|
answ = answ.OrderBy(x => x.MovType.Descr);
|
|
}
|
|
break;
|
|
case "Riferimento":
|
|
if (Sort == "dsc")
|
|
{
|
|
answ = answ.OrderByDescending(x => x.Location1.Descr);
|
|
}
|
|
else
|
|
{
|
|
answ = answ.OrderBy(x => x.Location1.Descr);
|
|
}
|
|
break;
|
|
case "Operatore":
|
|
if (Sort == "dsc")
|
|
{
|
|
answ = answ.OrderByDescending(x => x.Operator.LastName);
|
|
}
|
|
else
|
|
{
|
|
answ = answ.OrderBy(x => x.Operator.LastName);
|
|
}
|
|
break;
|
|
case "dtMov":
|
|
default:
|
|
if (Sort == "dsc")
|
|
{
|
|
answ = answ.OrderByDescending(x => x.ID);
|
|
}
|
|
else
|
|
{
|
|
answ = answ.OrderBy(x => x.ID);
|
|
}
|
|
break;
|
|
}
|
|
return answ;
|
|
}
|
|
/// <summary>
|
|
/// Ricerca con paginazione
|
|
/// </summary>
|
|
/// <param name="ItemID"></param>
|
|
/// <param name="SearchVal"></param>
|
|
/// <param name="OrderBy"></param>
|
|
/// <param name="Sort"></param>
|
|
/// <param name="startRowIndex"></param>
|
|
/// <param name="maximumRows"></param>
|
|
/// <returns></returns>
|
|
public static IEnumerable<ItemFlux> SelectPage(int? ItemID, string SearchVal, string OrderBy, string Sort, int startRowIndex, int maximumRows)
|
|
{
|
|
return Order(ItemID, SearchVal, OrderBy, Sort).Skip(startRowIndex * maximumRows).Take(maximumRows);
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// Ricerca con selezione parametri
|
|
/// </summary>
|
|
/// <param name="ItemID"></param>
|
|
/// <param name="SearchVal"></param>
|
|
/// <param name="OrderBy"></param>
|
|
/// <param name="Sort"></param>
|
|
/// <returns></returns>
|
|
public static IEnumerable<ItemFlux> Order(int? ItemID, string SearchVal, string SortOrd)
|
|
{
|
|
IEnumerable<ItemFlux> answ = Select(ItemID, SearchVal);
|
|
// ora verifico ordinamento...
|
|
switch (SortOrd)
|
|
{
|
|
case "Loc":
|
|
answ = answ.OrderBy(s => s.Location.Descr);
|
|
break;
|
|
case "Loc_desc":
|
|
answ = answ.OrderByDescending(s => s.Location.Descr);
|
|
break;
|
|
case "Qta":
|
|
answ = answ.OrderBy(s => s.Qta);
|
|
break;
|
|
case "Qta_desc":
|
|
answ = answ.OrderByDescending(s => s.Qta);
|
|
break;
|
|
case "Rif":
|
|
answ = answ.OrderBy(s => s.Location1.Descr);
|
|
break;
|
|
case "Rif_desc":
|
|
answ = answ.OrderByDescending(s => s.Location1.Descr);
|
|
break;
|
|
case "Val":
|
|
answ = answ.OrderBy(s => s.TotValue);
|
|
break;
|
|
case "Val_desc":
|
|
answ = answ.OrderByDescending(s => s.TotValue);
|
|
break;
|
|
case "DtMov":
|
|
answ = answ.OrderBy(s => s.dtMov).ThenBy(s => s.ID);
|
|
break;
|
|
case "DtMov_desc":
|
|
default:
|
|
answ = answ.OrderByDescending(s => s.dtMov).ThenByDescending(s => s.ID);
|
|
break;
|
|
}
|
|
return answ;
|
|
}
|
|
|
|
// GET: Location/ListByType/LocTypeID
|
|
public ActionResult ListByItem(int? ID, string SearchVal, string SortOrd, int? page, int? pageSize)
|
|
{
|
|
// gestione selettore dim pagina
|
|
if (page == null) page = 1;
|
|
if (pageSize == null) pageSize = 10;
|
|
ViewBag.pageSize = pageSize;
|
|
var pageOptions = new[] { "5", "10", "25", "50", "100" };
|
|
ViewBag.PageSizeDD = new SelectList(pageOptions, pageSize.ToString());
|
|
|
|
if (ID == null) ID = 0;
|
|
if (SearchVal == null) SearchVal = "";
|
|
if (SortOrd == null) SortOrd = "";
|
|
ViewBag.ID = ID;
|
|
ViewBag.SearchVal = SearchVal;
|
|
ViewBag.SortOrd = SortOrd;
|
|
// fix valori sorting
|
|
ViewBag.DtMovSortParm = String.IsNullOrEmpty(SortOrd) ? "DtMov" : "";
|
|
ViewBag.LocSortParm = SortOrd == "Loc" ? "Loc_desc" : "Loc";
|
|
ViewBag.QtaSortParm = SortOrd == "Qta" ? "Qta_desc" : "Qta";
|
|
ViewBag.ValSortParm = SortOrd == "Val" ? "Val_desc" : "Val";
|
|
ViewBag.RifSortParm = SortOrd == "Rif" ? "Rif_desc" : "Rif";
|
|
|
|
var pagedData = Order(ID, SearchVal, SortOrd).ToPagedList((int)page, (int)pageSize);
|
|
return PartialView("_ListByItem", pagedData);
|
|
}
|
|
/// <summary>
|
|
/// calcolo num risultati
|
|
/// </summary>
|
|
/// <param name="ItemID"></param>
|
|
/// <param name="SearchVal"></param>
|
|
/// <returns></returns>
|
|
public static int SelectCount(int? ItemID, string SearchVal)
|
|
{
|
|
return Select(ItemID, SearchVal).Count();
|
|
}
|
|
|
|
// GET: ItemFluxes
|
|
public ActionResult Index()
|
|
{
|
|
var itemFlux = db.ItemFlux.Include(i => i.Location).Include(i => i.MovType).Include(i => i.Item).Include(i => i.Operator).Include(i => i.Location1);
|
|
return View(itemFlux.ToList());
|
|
}
|
|
|
|
// GET: ItemFluxes/Details/5
|
|
public ActionResult Details(int? id)
|
|
{
|
|
if (id == null)
|
|
{
|
|
return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
|
|
}
|
|
ItemFlux itemFlux = db.ItemFlux.Find(id);
|
|
if (itemFlux == null)
|
|
{
|
|
return HttpNotFound();
|
|
}
|
|
return View(itemFlux);
|
|
}
|
|
|
|
// GET: ItemFluxes/Create
|
|
public ActionResult Create()
|
|
{
|
|
ViewBag.LocationID = new SelectList(db.Location, "ID", "Descr");
|
|
ViewBag.MovTypeID = new SelectList(db.MovType, "ID", "Descr");
|
|
ViewBag.ItemID = new SelectList(db.Item, "ID", "Descr");
|
|
ViewBag.OperatorID = new SelectList(db.Operator, "ID", "CodExt");
|
|
ViewBag.ExtLocationID = new SelectList(db.Location, "ID", "Descr");
|
|
return View();
|
|
}
|
|
|
|
// POST: ItemFluxes/Create
|
|
// To protect from overposting attacks, please enable the specific properties you want to bind to, for
|
|
// more details see http://go.microsoft.com/fwlink/?LinkId=317598.
|
|
[HttpPost]
|
|
[ValidateAntiForgeryToken]
|
|
public ActionResult Create([Bind(Include = "ID,ItemID,LocationID,MovTypeID,ExtLocationID,dtMov,Qta,TotValue,UnitVal,Note,dtExport,OperatorID")] ItemFlux itemFlux)
|
|
{
|
|
if (ModelState.IsValid)
|
|
{
|
|
db.ItemFlux.Add(itemFlux);
|
|
db.SaveChanges();
|
|
return RedirectToAction("Index");
|
|
}
|
|
|
|
ViewBag.LocationID = new SelectList(db.Location, "ID", "Descr", itemFlux.LocationID);
|
|
ViewBag.MovTypeID = new SelectList(db.MovType, "ID", "Descr", itemFlux.MovTypeID);
|
|
ViewBag.ItemID = new SelectList(db.Item, "ID", "Descr", itemFlux.ItemID);
|
|
ViewBag.OperatorID = new SelectList(db.Operator, "ID", "CodExt", itemFlux.OperatorID);
|
|
ViewBag.ExtLocationID = new SelectList(db.Location, "ID", "Descr", itemFlux.ExtLocationID);
|
|
return View(itemFlux);
|
|
}
|
|
|
|
// GET: ItemFluxes/Create with params preselected
|
|
public ActionResult CreatePrecompiled(int ItemID, string MovTypeID)
|
|
{
|
|
ViewBag.LocationID = new SelectList(db.Location.Where(o => o.LocType.IsStock), "ID", "Descr");
|
|
ViewBag.MovTypeID = new SelectList(db.MovType, "ID", "Descr", MovTypeID);
|
|
ViewBag.ItemID = new SelectList(db.Item, "ID", "Descr", ItemID);
|
|
ViewBag.enabEditVal = true;
|
|
// preparo query degli scaffali ammissibili
|
|
// recupero SOLO gli scaffali ammissibili
|
|
var query = db.Location.Where(o => o.LocType.IsStock).Join(db.ItemStock.Where(s => s.ItemID == ItemID),
|
|
l => l.ID,
|
|
s => s.LocationID,
|
|
(l, s) => new { l.ID, l.Descr });
|
|
// in base al tipo di mov richiesto determino cosa mostrare...
|
|
string CurrStyle = "";
|
|
switch (MovTypeID)
|
|
{
|
|
case "CAR":
|
|
// per partire scelgo la posizione di default ric ordini
|
|
string stdLocationId = "#RIC-ORD";
|
|
// cerco se ci sia una posizione occupata dall'item in stock..
|
|
if (db.ItemStock.Where(s => s.ItemID == ItemID).Count() > 0)
|
|
{
|
|
stdLocationId = db.ItemStock.Where(s => s.ItemID == ItemID).ToList()[0].LocationID;
|
|
}
|
|
ViewBag.LocationID = new SelectList(db.Location.Where(o => o.LocType.IsStock), "ID", "Descr", stdLocationId);
|
|
ViewBag.ExtLocationID = new SelectList(db.Location.Where(o => o.LocType.IsFor), "ID", "Descr");
|
|
CurrStyle = "bg-success";
|
|
break;
|
|
case "SCAR":
|
|
if (query.Count() > 0)
|
|
{
|
|
ViewBag.LocationID = new SelectList(query, "ID", "Descr");
|
|
}
|
|
ViewBag.ExtLocationID = new SelectList(db.Location.Where(o => o.LocType.IsCli), "ID", "Descr");
|
|
ViewBag.enabEditVal = false;
|
|
CurrStyle = "bg-danger";
|
|
break;
|
|
case "MOV":
|
|
ViewBag.ExtLocationID = new SelectList(db.Location.Where(o => o.LocType.IsStock), "ID", "Descr");
|
|
ViewBag.enabEditVal = false;
|
|
CurrStyle = "bg-primary";
|
|
break;
|
|
case "OFOR":
|
|
ViewBag.LocationID = new SelectList(db.Location.Where(o => o.LocType.IsStock), "ID", "Descr", "#RIC-ORD");
|
|
ViewBag.ExtLocationID = new SelectList(db.Location.Where(o => o.LocType.IsFor), "ID", "Descr");
|
|
CurrStyle = "bg-info";
|
|
break;
|
|
case "RETT":
|
|
if (query.Count() > 0)
|
|
{
|
|
ViewBag.LocationID = new SelectList(query, "ID", "Descr");
|
|
}
|
|
ViewBag.ExtLocationID = new SelectList(db.Location, "ID", "Descr");
|
|
ViewBag.enabEditVal = false;
|
|
CurrStyle = "bg-warning";
|
|
break;
|
|
case "ND":
|
|
default:
|
|
ViewBag.ExtLocationID = new SelectList(db.Location, "ID", "Descr");
|
|
CurrStyle = "bg-default";
|
|
break;
|
|
}
|
|
ViewBag.CurrStyle = CurrStyle;
|
|
// aggiungo valori default...
|
|
ItemFlux itemFlux = new ItemFlux();
|
|
itemFlux.dtMov = DateTime.Now.Date;
|
|
// alore propongo corrente
|
|
return PartialView("_CreatePrecompiled", itemFlux);
|
|
}
|
|
|
|
// POST: ItemFluxes/Create
|
|
// To protect from overposting attacks, please enable the specific properties you want to bind to, for
|
|
// more details see http://go.microsoft.com/fwlink/?LinkId=317598.
|
|
[HttpPost]
|
|
[ValidateAntiForgeryToken]
|
|
public ActionResult CreatePrecompiled([Bind(Include = "ID,ItemID,LocationID,MovTypeID,ExtLocationID,dtMov,Qta,TotValue,UnitVal,CodDoc,Note")] ItemFlux itemFlux)
|
|
{
|
|
// aggiungo campi mancanti...
|
|
if (itemFlux.dtMov == null) itemFlux.dtMov = DateTime.Now;
|
|
if (itemFlux.Note == null) itemFlux.Note = "";
|
|
if (itemFlux.CodDoc == null) itemFlux.CodDoc = "";
|
|
itemFlux.dtExport = null;
|
|
string currOpID = "ND"; // default
|
|
try
|
|
{
|
|
var trovato = db.Operator.SingleOrDefault(s => s.CodExt == User.Identity.Name || s.CodExt.Contains(User.Identity.Name) || s.ID == User.Identity.Name);
|
|
Operator currOp = (Operator)trovato;
|
|
currOpID = currOp.ID;
|
|
}
|
|
catch
|
|
{ }
|
|
itemFlux.OperatorID = currOpID;
|
|
itemFlux.ModOperatorID = currOpID;
|
|
|
|
// verifico Qta: SE CAR > 0, se SCAR < 0, se MOV / rett libero...
|
|
switch (itemFlux.MovTypeID)
|
|
{
|
|
case "CAR":
|
|
itemFlux.Qta = Math.Abs(itemFlux.Qta);
|
|
break;
|
|
case "SCAR":
|
|
itemFlux.Qta = -Math.Abs(itemFlux.Qta);
|
|
break;
|
|
default:
|
|
break;
|
|
}
|
|
|
|
if (ModelState.IsValid)
|
|
{
|
|
db.ItemFlux.Add(itemFlux);
|
|
db.SaveChanges();
|
|
// rimando a pag esterna...
|
|
return RedirectToAction("Details", "Items", new { ID = itemFlux.ItemID, StockItemID = itemFlux.ItemID });
|
|
//return RedirectToAction("Index");
|
|
}
|
|
|
|
ViewBag.LocationID = new SelectList(db.Location, "ID", "Descr", itemFlux.LocationID);
|
|
ViewBag.MovTypeID = new SelectList(db.MovType, "ID", "Descr", itemFlux.MovTypeID);
|
|
ViewBag.ItemID = new SelectList(db.Item, "ID", "Descr", itemFlux.ItemID);
|
|
ViewBag.OperatorID = new SelectList(db.Operator, "ID", "CodExt", itemFlux.OperatorID);
|
|
ViewBag.ExtLocationID = new SelectList(db.Location, "ID", "Descr", itemFlux.ExtLocationID);
|
|
|
|
return View("CreatePrecompiled", itemFlux);
|
|
}
|
|
|
|
// GET: ItemFluxes/ConvOrder/5 converte da ORDINE a CARICO e manda in edit...
|
|
public ActionResult ConvOrder(int? id)
|
|
{
|
|
if (id == null)
|
|
{
|
|
return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
|
|
}
|
|
ItemFlux itemFlux = db.ItemFlux.Find(id);
|
|
if (itemFlux == null)
|
|
{
|
|
return HttpNotFound();
|
|
}
|
|
// converto ordine in carico!
|
|
if (itemFlux.MovTypeID == "OFOR")
|
|
{
|
|
itemFlux.MovTypeID = "CAR";
|
|
db.SaveChanges();
|
|
}
|
|
// ritorno a dettaglio!
|
|
return RedirectToAction("Details", "Items", new { ID = itemFlux.ItemID, StockItemID = itemFlux.ItemID });
|
|
}
|
|
|
|
|
|
// GET: ItemFluxes/Duplicate/5
|
|
public ActionResult Duplicate(int? id)
|
|
{
|
|
if (id == null)
|
|
{
|
|
return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
|
|
}
|
|
int newId = 0;
|
|
int ItemID = 0;
|
|
// ora chiamo stored e recupero nuovo ID del record duplicato
|
|
using (var ctx = new StockManEntities())
|
|
{
|
|
// esegue stored procedure come function, recuperando nuovo ID creato...
|
|
var newItemFlux = ctx.stp_ItemFluxDuplicate(id).ToList();
|
|
newId = newItemFlux[0].ID;
|
|
ItemID = newItemFlux[0].ItemID;
|
|
}
|
|
|
|
// rimando in editing!
|
|
return RedirectToAction("Edit", "ItemFluxes", new { ID = newId, mode = "std" });
|
|
//return Edit(newId, "std");
|
|
//return RedirectToAction("Details", "Items", new { ID = ItemID, StockItemID = ItemID });
|
|
}
|
|
|
|
// GET: ItemFluxes/Read/5
|
|
public ActionResult Read(int? id,string mode)
|
|
{
|
|
if (id == null)
|
|
{
|
|
return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
|
|
}
|
|
if (mode == null)
|
|
{
|
|
mode = "std";
|
|
}
|
|
// recupero item
|
|
ItemFlux itemFlux = db.ItemFlux.Find(id);
|
|
if (itemFlux == null)
|
|
{
|
|
return HttpNotFound();
|
|
}
|
|
// recupero SOLO gli scaffali ammissibili
|
|
var query = db.Location.Where(o => o.LocType.IsStock).Join(db.ItemStock.Where(s => s.ItemID == itemFlux.ItemID),
|
|
l => l.ID,
|
|
s => s.LocationID,
|
|
(l, s) => new { l.ID, l.Descr });
|
|
// calcolo sfondo e location ammesse da vari casi tipo movimento
|
|
string CurrStyle = "";
|
|
ViewBag.LocationID = new SelectList(db.Location, "ID", "Descr", itemFlux.LocationID);
|
|
ViewBag.ExtLocationID = new SelectList(db.Location, "ID", "Descr", itemFlux.ExtLocationID);
|
|
switch (itemFlux.MovTypeID)
|
|
{
|
|
case "CAR":
|
|
// per partire scelgo la posizione di default ric ordini
|
|
ViewBag.LocationID = new SelectList(db.Location.Where(o => o.LocType.IsStock), "ID", "Descr", itemFlux.LocationID);
|
|
ViewBag.ExtLocationID = new SelectList(db.Location.Where(o => o.LocType.IsFor), "ID", "Descr", itemFlux.ExtLocationID);
|
|
CurrStyle = "bg-success";
|
|
break;
|
|
case "SCAR":
|
|
if (query.Count() > 0)
|
|
{
|
|
ViewBag.LocationID = new SelectList(query, "ID", "Descr");
|
|
}
|
|
ViewBag.ExtLocationID = new SelectList(db.Location.Where(o => o.LocType.IsCli), "ID", "Descr", itemFlux.ExtLocationID);
|
|
ViewBag.enabEditVal = false;
|
|
CurrStyle = "bg-danger";
|
|
break;
|
|
case "MOV":
|
|
ViewBag.ExtLocationID = new SelectList(db.Location.Where(o => o.LocType.IsStock), "ID", "Descr", itemFlux.ExtLocationID);
|
|
ViewBag.enabEditVal = false;
|
|
CurrStyle = "bg-primary";
|
|
break;
|
|
case "OFOR":
|
|
ViewBag.LocationID = new SelectList(db.Location.Where(o => o.LocType.IsStock), "ID", "Descr", itemFlux.LocationID);
|
|
ViewBag.ExtLocationID = new SelectList(db.Location.Where(o => o.LocType.IsFor), "ID", "Descr", itemFlux.ExtLocationID);
|
|
CurrStyle = "bg-info";
|
|
break;
|
|
case "RETT":
|
|
if (query.Count() > 0)
|
|
{
|
|
ViewBag.LocationID = new SelectList(query, "ID", "Descr");
|
|
}
|
|
ViewBag.ExtLocationID = new SelectList(db.Location, "ID", "Descr", itemFlux.ExtLocationID);
|
|
ViewBag.enabEditVal = false;
|
|
CurrStyle = "bg-warning";
|
|
break;
|
|
case "ND":
|
|
default:
|
|
ViewBag.ExtLocationID = new SelectList(db.Location, "ID", "Descr", itemFlux.ExtLocationID);
|
|
CurrStyle = "bg-default";
|
|
break;
|
|
}
|
|
// altri valori in viewbag
|
|
ViewBag.CurrStyle = CurrStyle;
|
|
ViewBag.MovTypeID = new SelectList(db.MovType, "ID", "Descr", itemFlux.MovTypeID);
|
|
ViewBag.ItemID = new SelectList(db.Item, "ID", "Descr", itemFlux.ItemID);
|
|
ViewBag.OperatorID = new SelectList(db.Operator, "ID", "CodExt", itemFlux.OperatorID);
|
|
if (mode == "std")
|
|
{
|
|
return PartialView(itemFlux);
|
|
}
|
|
else
|
|
{
|
|
return View(itemFlux);
|
|
}
|
|
|
|
}
|
|
|
|
// GET: ItemFluxes/Edit/5
|
|
public ActionResult Edit(int? id, string mode)
|
|
{
|
|
if (mode == null)
|
|
{
|
|
mode = "std";
|
|
}
|
|
if (id == null)
|
|
{
|
|
return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
|
|
}
|
|
// recupero item
|
|
ItemFlux itemFlux = db.ItemFlux.Find(id);
|
|
if (itemFlux == null)
|
|
{
|
|
return HttpNotFound();
|
|
}
|
|
// recupero SOLO gli scaffali ammissibili
|
|
var query = db.Location.Where(o => o.LocType.IsStock).Join(db.ItemStock.Where(s => s.ItemID == itemFlux.ItemID),
|
|
l => l.ID,
|
|
s => s.LocationID,
|
|
(l, s) => new { l.ID, l.Descr });
|
|
// calcolo sfondo e location ammesse da vari casi tipo movimento
|
|
string CurrStyle = "";
|
|
ViewBag.LocationID = new SelectList(db.Location, "ID", "Descr", itemFlux.LocationID);
|
|
ViewBag.ExtLocationID = new SelectList(db.Location, "ID", "Descr", itemFlux.ExtLocationID);
|
|
switch (itemFlux.MovTypeID)
|
|
{
|
|
case "CAR":
|
|
// per partire scelgo la posizione di default ric ordini
|
|
ViewBag.LocationID = new SelectList(db.Location.Where(o => o.LocType.IsStock), "ID", "Descr", itemFlux.LocationID);
|
|
ViewBag.ExtLocationID = new SelectList(db.Location.Where(o => o.LocType.IsFor), "ID", "Descr", itemFlux.ExtLocationID);
|
|
CurrStyle = "bg-success";
|
|
break;
|
|
case "SCAR":
|
|
if (query.Count() > 0)
|
|
{
|
|
ViewBag.LocationID = new SelectList(query, "ID", "Descr");
|
|
}
|
|
ViewBag.ExtLocationID = new SelectList(db.Location.Where(o => o.LocType.IsCli), "ID", "Descr", itemFlux.ExtLocationID);
|
|
ViewBag.enabEditVal = false;
|
|
CurrStyle = "bg-danger";
|
|
break;
|
|
case "MOV":
|
|
ViewBag.ExtLocationID = new SelectList(db.Location.Where(o => o.LocType.IsStock), "ID", "Descr", itemFlux.ExtLocationID);
|
|
ViewBag.enabEditVal = false;
|
|
CurrStyle = "bg-primary";
|
|
break;
|
|
case "OFOR":
|
|
ViewBag.LocationID = new SelectList(db.Location.Where(o => o.LocType.IsStock), "ID", "Descr", itemFlux.LocationID);
|
|
ViewBag.ExtLocationID = new SelectList(db.Location.Where(o => o.LocType.IsFor), "ID", "Descr", itemFlux.ExtLocationID);
|
|
CurrStyle = "bg-info";
|
|
break;
|
|
case "RETT":
|
|
if (query.Count() > 0)
|
|
{
|
|
ViewBag.LocationID = new SelectList(query, "ID", "Descr");
|
|
}
|
|
ViewBag.ExtLocationID = new SelectList(db.Location, "ID", "Descr", itemFlux.ExtLocationID);
|
|
ViewBag.enabEditVal = false;
|
|
CurrStyle = "bg-warning";
|
|
break;
|
|
case "ND":
|
|
default:
|
|
ViewBag.ExtLocationID = new SelectList(db.Location, "ID", "Descr", itemFlux.ExtLocationID);
|
|
CurrStyle = "bg-default";
|
|
break;
|
|
}
|
|
// altri valori in viewbag
|
|
ViewBag.CurrStyle = CurrStyle;
|
|
ViewBag.MovTypeID = new SelectList(db.MovType, "ID", "Descr", itemFlux.MovTypeID);
|
|
ViewBag.ItemID = new SelectList(db.Item, "ID", "Descr", itemFlux.ItemID);
|
|
ViewBag.OperatorID = new SelectList(db.Operator, "ID", "CodExt", itemFlux.OperatorID);
|
|
if (mode == "std")
|
|
{
|
|
return PartialView(itemFlux);
|
|
}
|
|
else
|
|
{
|
|
return View(itemFlux);
|
|
}
|
|
}
|
|
|
|
// POST: ItemFluxes/Edit/5
|
|
// To protect from overposting attacks, please enable the specific properties you want to bind to, for
|
|
// more details see http://go.microsoft.com/fwlink/?LinkId=317598.
|
|
[HttpPost]
|
|
[ValidateAntiForgeryToken]
|
|
public ActionResult Edit([Bind(Include = "ID,LocationID,ExtLocationID,dtMov,Qta,TotValue,UnitVal,CodDoc,Note,dtExport")] ItemFlux itemFlux)
|
|
{
|
|
// recupero vecchi valori...
|
|
ItemFlux itemFluxOld = db.ItemFlux.Find(itemFlux.ID);
|
|
// fix operatore modifica
|
|
string currOpIDMod = "ND"; // default
|
|
try
|
|
{
|
|
var trovato = db.Operator.SingleOrDefault(s => s.CodExt == User.Identity.Name || s.CodExt.Contains(User.Identity.Name) || s.ID == User.Identity.Name);
|
|
Operator currOp = (Operator)trovato;
|
|
currOpIDMod = currOp.ID;
|
|
}
|
|
catch
|
|
{ }
|
|
itemFlux.ModOperatorID = currOpIDMod;
|
|
// imposto valori vecchi x campi "bloccati" (articolo, tipo movimento, operatore iniziale...)
|
|
itemFlux.ItemID = itemFluxOld.ItemID;
|
|
itemFlux.MovTypeID = itemFluxOld.MovTypeID;
|
|
if (itemFlux.OperatorID == null) itemFlux.OperatorID = itemFluxOld.OperatorID;
|
|
// fix valori opzionali da non annullare...
|
|
if (itemFlux.dtMov == null) itemFlux.dtMov = DateTime.Now;
|
|
if (itemFlux.Note == null) itemFlux.Note = "";
|
|
if (itemFlux.CodDoc == null) itemFlux.CodDoc = "";
|
|
// continuo
|
|
if (ModelState.IsValid)
|
|
{
|
|
// verifico: se è un carico --> positivo, scarico --> negativo!
|
|
switch (itemFlux.MovTypeID)
|
|
{
|
|
case "CAR":
|
|
itemFlux.Qta = Math.Abs(itemFlux.Qta);
|
|
break;
|
|
case "SCAR":
|
|
itemFlux.Qta = -Math.Abs(itemFlux.Qta);
|
|
break;
|
|
default:
|
|
break;
|
|
}
|
|
// sblocco vecchio item x non fare conflitto
|
|
db.Entry(itemFluxOld).State = EntityState.Detached;
|
|
// indico che devo salvare nuovo!
|
|
db.Entry(itemFlux).State = EntityState.Modified;
|
|
db.SaveChanges();
|
|
|
|
// rimando pag dettaglio...
|
|
return RedirectToAction("Details", "Items", new { ID = itemFlux.ItemID, StockItemID = itemFlux.ItemID });
|
|
//return RedirectToAction("Index");
|
|
}
|
|
ViewBag.LocationID = new SelectList(db.Location, "ID", "Descr", itemFlux.LocationID);
|
|
ViewBag.MovTypeID = new SelectList(db.MovType, "ID", "Descr", itemFlux.MovTypeID);
|
|
ViewBag.ItemID = new SelectList(db.Item, "ID", "Descr", itemFlux.ItemID);
|
|
ViewBag.OperatorID = new SelectList(db.Operator, "ID", "CodExt", itemFlux.OperatorID);
|
|
ViewBag.ExtLocationID = new SelectList(db.Location, "ID", "Descr", itemFlux.ExtLocationID);
|
|
|
|
// rimando pag dettaglio...
|
|
return View(itemFlux);
|
|
}
|
|
|
|
// GET: ItemFluxes/Delete/5
|
|
public ActionResult Delete(int? id, string mode)
|
|
{
|
|
if (mode == null)
|
|
{
|
|
mode = "std";
|
|
}
|
|
if (id == null)
|
|
{
|
|
return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
|
|
}
|
|
ItemFlux itemFlux = db.ItemFlux.Find(id);
|
|
if (itemFlux == null)
|
|
{
|
|
return HttpNotFound();
|
|
}
|
|
if (mode == "std")
|
|
{
|
|
return PartialView(itemFlux);
|
|
}
|
|
else
|
|
{
|
|
return View(itemFlux);
|
|
}
|
|
}
|
|
|
|
// POST: ItemFluxes/Delete/5
|
|
[HttpPost, ActionName("Delete")]
|
|
[ValidateAntiForgeryToken]
|
|
public ActionResult DeleteConfirmed(int id)
|
|
{
|
|
ItemFlux itemFlux = db.ItemFlux.Find(id);
|
|
db.ItemFlux.Remove(itemFlux);
|
|
db.SaveChanges();
|
|
//return RedirectToAction("Index");
|
|
return RedirectToAction("Details", "Items", new { ID = itemFlux.ItemID, StockItemID = itemFlux.ItemID });
|
|
}
|
|
|
|
protected override void Dispose(bool disposing)
|
|
{
|
|
if (disposing)
|
|
{
|
|
db.Dispose();
|
|
}
|
|
base.Dispose(disposing);
|
|
}
|
|
}
|
|
}
|