public static bool DeleteInventory(Session session, int id) { //Dim inventory As SPG.InventoryDataTable = Adapter.GetInventoryByID(id) //Dim rowsAffected As Integer = 0 //Dim inventorySession As Session = session session.DropIdentityMap(); int item = 0; int quantity = 0; int locationID = 0; Inventory production = session.GetObjectByKey <Inventory>(id); //If inventory.Count = 1 Then if (production == null) { return(false); } else if (production.Shipment != null) { MessageBox.Show("The selected record can't be deleted, it was already shipped."); return(true); } //Dim inventoryRecord As SPG.InventoryRow = CType(Inventory.Rows(0), SPG.InventoryRow) InventoryBOMsBLL inventoryBOM = new InventoryBOMsBLL(); item = production.InventoryItemID.ItemID; quantity = production.InventoryQuantity; locationID = production.ProductionLocation.Oid; InventoryBOMsBLL.DeleteInventoryBOMByInventoryID(session, id); DeleteInventoryConsumption(production, session); DeleteProductionProjectDetails(session, production); //rowsAffected = Adapter.Delete(id, inventoryRecord.ts) try { production.Delete(); //If rowsAffected = 1 Then //If production.IsDeleted Then ItemsBLL items = new ItemsBLL(); items.UpdateStock(session, item, quantity * -1, true, locationID); //End If //Return true if precisely one row was deleted, otherwise return false. //Return rowsAffected = 1 //Return production.IsDeleted return(true); } catch (Exception ex) { return(false); } }
public Inventory UpdateInventory(Session session, int inventoryID, DateTime inventoryDate, int item, int quantity, float?pallets, string po, string lot, int?shift, int?pallet, DateTime?expirationDate, int locationID, string note) { //Dim inventory As SPG.InventoryDataTable = Adapter.GetInventoryByID(inventoryID) //If inventory.Count = 0 Then Change change = new Change(); Inventory production = session.GetObjectByKey <Inventory>(inventoryID); if (production == null) { //It is a new Production Record change = new Change() { PropertyName = Inventory.Fields.InventoryID.PropertyName, PrevValue = "<NULL>", NewValue = inventoryID.ToString() }; changes.Add(change); return(InsertInventory(session, inventoryID, inventoryDate, item, quantity, pallets, po, lot, shift, pallet, expirationDate, locationID, note)); } //Dim inventoryRecord As SPG.InventoryRow = inventory(0) int originalQuantity = 0; int newQuantity = 0; bool itemChanged = false; //Dim originalRecord As Object() = inventoryRecord.ItemArray //inventoryRecord.InventoryDate = CDate(Format(inventoryDate, "D")) int originalItem = production.InventoryItemID.ItemID; if (originalItem != item) { itemChanged = true; } else { itemChanged = false; } //inventoryRecord.InventoryItemID = item originalQuantity = production.InventoryQuantity; newQuantity = production.InventoryQuantity - quantity; //inventoryRecord.InventoryQuantity = quantity //inventoryRecord.InventoryPallets = pallets.Value //inventoryRecord.PO = po //inventoryRecord.Lot = lot //If shift.HasValue AndAlso shift.Value > 0 Then // inventoryRecord.Shift = shift.Value //Else // inventoryRecord.SetShiftNull() //End If //If pallet.HasValue AndAlso pallet.Value > 0 Then // inventoryRecord.Pallet = pallet.Value //Else // inventoryRecord.SetPalletNull() //End If //If expirationDate.HasValue Then // inventoryRecord.ExpirationDate = expirationDate.Value //Else // inventoryRecord.SetExpirationDateNull() //End If change = new Change() { PropertyName = Inventory.Fields.InventoryID.PropertyName, PrevValue = production.InventoryID.ToString(), NewValue = production.InventoryID.ToString() }; changes.Add(change); SetInventoryFields(session, inventoryDate, item, quantity, pallets, po, lot, shift, pallet, expirationDate, locationID, note, production); //If Not IsNothing(originalRecord) Then // Me.UpdateAuditTrail(inventoryRecord, originalRecord) //End If try { production.Save(); } catch (Exception ex) { return(null); } UpdateAuditTrail(); //Dim rowsAffected As Integer = Adapter.Update(inventoryRecord) //If rowsAffected = 1 Then ItemsBLL items = new ItemsBLL(); //Dim inventoryBOM As InventoryBOMsBLL = New InventoryBOMsBLL if (itemChanged == true) { items.UpdateStock(session, originalItem, inventoryID, originalQuantity * -1, true, locationID); InventoryBOMsBLL.DeleteInventoryBOMByInventoryID(session, inventoryID); InventoryBOMsBLL.AddInventoryBOMByItemID(session, item, production); items.UpdateStock(session, item, quantity, true, locationID); } else { if (newQuantity != 0) //there was a change in the quantity { items.UpdateStock(session, item, inventoryID, newQuantity * -1, true, locationID); } } //End If //Return rowsAffected = 1 return(production); }
public Inventory InsertInventory(Session session, int inventoryID, DateTime?inventoryDate, int?item, int?quantity, float?pallets, string po, string lot, int?shift, int?pallet, DateTime?expirationDate, int locationID, string note) { //Dim inventory As SPG.InventoryDataTable = New SPG.InventoryDataTable //Dim inventoryRecord As SPG.InventoryRow = inventory.NewInventoryRow() //inventoryRecord.InventoryID = inventoryID Inventory production = new Inventory(session) { InventoryID = inventoryID, InventoryItemID = session.GetObjectByKey <Items>(item.Value) }; //inventoryRecord.InventoryDate = CDate(Format(inventoryDate, "D")) //inventoryRecord.InventoryItemID = item.Value //inventoryRecord.InventoryQuantity = quantity.Value //inventoryRecord.InventoryPallets = pallets.Value //inventoryRecord.PO = po //inventoryRecord.Lot = lot //If shift.HasValue AndAlso shift.Value > 0 Then // inventoryRecord.Shift = shift.Value //Else // inventoryRecord.SetShiftNull() //End If if (pallet.HasValue == false || pallet.Value <= 0) { // inventoryRecord.Pallet = pallet.Value //Else pallet = GetNewPalletNumber(session, Convert.ToDateTime(inventoryDate), item.Value, shift.Value); } //If expirationDate.HasValue() Then // inventoryRecord.ExpirationDate = expirationDate.Value //Else // inventoryRecord.SetExpirationDateNull() //End If SetInventoryFields(session, inventoryDate.Value, item.Value, quantity.Value, pallets, po, lot, shift, pallet, expirationDate, locationID, note, production); production.strEnteredBy = Properties.Settings.Default.UserName; production.dtmEnteredOn = DateTime.Now; try { production.Save(); } catch (Exception ex) { return(null); } //inventory.AddInventoryRow(inventoryRecord) //Dim rowsAffected As Integer = Adapter.Update(inventory) //If rowsAffected = 1 Then ItemsBLL items = new ItemsBLL(); items.UpdateStock(session, item.Value, quantity.Value, true, locationID); InventoryBOMsBLL inventoryBOM = new InventoryBOMsBLL(); InventoryBOMsBLL.AddInventoryBOMByItemID(session, item.Value, production); //End If //Return rowsAffected = 1 return(production); }
public void UpdateStock(Session session, int itemID, int?inventoryID, float quantity, bool updateBOM, int locationID, string lot = "", int?LPNNumber = null, DateTime?ExpirationDate = null, bool IsNewInventory = true) { double scrapfactor = 0; //To do update the stock for the item and bom's associated with it if (updateBOM == true) { if (inventoryID.HasValue) { //Dim inventoryBOMs As InventoryBOMsBLL = New InventoryBOMsBLL //Dim inventoryItemBOM As SPG.InventoryBOMsDataTable = inventoryBOMs.GetInventoryBOMsBYInventoryID(inventoryID.Value) XPCollection <InventoryBOMs> inventoryItemBOM = InventoryBOMsBLL.GetInventoryBOMsByInventoryID(session, inventoryID.Value); //If inventoryItemBOM.Rows.Count <> 0 Then if (inventoryItemBOM.Count != 0) { //Dim itemsBOM As SPG.InventoryBOMsRow InventoryBOMs itemsBOM = null; for (int i = 0; i < inventoryItemBOM.Count; i++) { //itemsBOM = CType(inventoryItemBOM.Rows(i), SPG.InventoryBOMsRow) itemsBOM = inventoryItemBOM[i]; if (itemsBOM.IsDeleted == false) { //updates the raw material if (itemsBOM.ScrapFactor > 0) { scrapfactor = itemsBOM.InventoryBOMQuantity * itemsBOM.ScrapFactor; } else { scrapfactor = 0; } UpdateStock(session, itemsBOM.InventoryBOMRawMatID.ItemID, (Convert.ToSingle(quantity * (itemsBOM.InventoryBOMQuantity + scrapfactor)) * -1), false, locationID); } } updateBOM = false; } } } if (updateBOM == true) { //The item has a bom attached to it BOMBLL boms = new BOMBLL(); //Dim itemsBOMs As SPG.BOMDataTable = boms.GetBOMBYFGItemID(itemID) XPCollection <BOMs> itemsBOMs = BOMBLL.GetBOMByFGItemID(session, itemID); //If itemsBOMs.Rows.Count <> 0 Then if (itemsBOMs.Count != 0) { //Dim itemsBOM As SPG.BOMRow BOMs itemsBOM = null; //For i As Integer = 0 To itemsBOMs.Rows.Count - 1 for (int i = 0; i < itemsBOMs.Count; i++) { //itemsBOM = CType(itemsBOMs.Rows(i), SPG.BOMRow) itemsBOM = itemsBOMs[i]; //updates the raw material if (itemsBOM.BOMRawMatID.ItemID != itemID) { if (itemsBOM.ScrapFactor > 0) { scrapfactor = itemsBOM.BOMQuantity * (itemsBOM.ScrapFactor / 100); } else { scrapfactor = 0; } UpdateStock(session, itemsBOM.BOMRawMatID.ItemID, (Convert.ToSingle(quantity * (itemsBOM.BOMQuantity + scrapfactor)) * -1), false, locationID); } } } } LocationInventoryBLL.UpdateStock(session, itemID, locationID, quantity, lot, LPNNumber, ExpirationDate, IsNewInventory); //Dim item As SPG.ItemsRow = CType(GetItemBYId(itemID).Rows(0), SPG.ItemsRow) //item.s ngQuantityOnHand += quantity //Adapter.Update(item) }