public bool InsertInventoryAdjustment(int adjustmentID, DateTime adjustmentDate, int customer, int item, float originalQuantity, float?newQuantity, string reason, int locationID, string OriginalLot, string NewLot, int?LPN, DateTime?Expr, bool IsNewInventory = true) { //Dim adjustments As SPG.InventoryAdjustmentDataTable = New SPG.InventoryAdjustmentDataTable //Dim adjustment As SPG.InventoryAdjustmentRow = adjustments.NewInventoryAdjustmentRow() //adjustment.AdjustmentID = adjustmentID InventoryAdjustment adjustment = new InventoryAdjustment(Session.DefaultSession) { AdjustmentID = adjustmentID }; //adjustment.AdjustmentDate = CDate(Format(adjustmentDate, "D")) //adjustment.Customer = customer //adjustment.ItemID = item //adjustment.OriginalQuantity = originalQuantity //adjustment.NewCount = newQuantity //adjustment.Reason = reason SetInventoryAdjustmentFields(adjustmentDate, customer, item, originalQuantity, newQuantity, reason, locationID, OriginalLot, NewLot, LPN, adjustment); adjustment.strEnteredBy = Properties.Settings.Default.UserName; adjustment.dtmEnteredOn = DateTime.Now; try { adjustment.Save(); } catch (Exception ex) { return(false); } //adjustments.AddInventoryAdjustmentRow(adjustment) //Dim rowsAffected As Integer = Adapter.Update(adjustments) //If rowsAffected = 1 Then ItemsBLL items = new ItemsBLL(); if (!string.IsNullOrEmpty(NewLot)) { items.UpdateStock(Session.DefaultSession, item, originalQuantity * -1, false, locationID, OriginalLot, LPN, Expr, IsNewInventory); items.UpdateStock(Session.DefaultSession, item, originalQuantity, false, locationID, NewLot, LPN, Expr, IsNewInventory); } else { items.UpdateStock(Session.DefaultSession, item, (newQuantity ?? 0) - originalQuantity, false, locationID, OriginalLot, LPN, Expr); } //End If //Return rowsAffected = 1 return(true); }
public static bool DeleteInventoryAdjustment(int id) { //Dim adjustments As SPG.InventoryAdjustmentDataTable = Adapter.GetInventoryAdjustmentByID(id) //Dim rowsAffected As Integer = 0 int item = 0; int locationID = 0; int? LPN = null; float quantity = 0; string oldlot = null; string newlot = null; //If adjustments.Count = 1 Then // Dim adjustment As SPG.InventoryAdjustmentRow = CType(adjustments.Rows(0), SPG.InventoryAdjustmentRow) InventoryAdjustment adjustment = Session.DefaultSession.GetObjectByKey <InventoryAdjustment>(id); if (adjustment == null) { return(false); } item = adjustment.AdjustmentItem.ItemID; quantity = adjustment.OriginalQuantity - (adjustment.NewCount ?? 0); locationID = adjustment.InventoryLocation.Oid; LPN = adjustment.LPN; newlot = adjustment.NewLot; oldlot = adjustment.OriginalLot; //rowsAffected = Adapter.Delete(id, adjustment.rv) //End If try { adjustment.Delete(); ItemsBLL items = new ItemsBLL(); if (!string.IsNullOrEmpty(newlot)) { items.UpdateStock(Session.DefaultSession, item, quantity * -1, false, locationID, newlot, LPN); items.UpdateStock(Session.DefaultSession, item, quantity, false, locationID, oldlot, LPN); } else { items.UpdateStock(Session.DefaultSession, item, quantity, false, locationID, oldlot, LPN); } return(true); } catch (Exception ex) { return(false); } }
public bool DeleteReturnDetail(Session session, int detailID) { SPG.ReturnDetDataTable details = Adapter.GetReturnDetByID(detailID); int rowsAffected = 0; int itemID = 0; int quantity = 0; int locationID = 0; if (details.Count() == 1) { SPG.ReturnDetRow returnDetail = (SPG.ReturnDetRow)details.Rows[0]; itemID = returnDetail.ReturnDetItemID; quantity = returnDetail.ReturnDetQty; locationID = session.GetObjectByKey <Receiving>(returnDetail.ReceiveMainID).ReceivingLocation.Oid; rowsAffected = Adapter.Delete(detailID, returnDetail.ts); } if (rowsAffected == 1) { ItemsBLL items = new ItemsBLL(); items.UpdateStock(session, itemID, quantity * -1, false, locationID); } //Return true if precisely one row was deleted, otherwise return false. return(rowsAffected == 1); }
public bool DeleteReceivingDetail(Session session, int detailID) { ReceivingDetail detail = session.GetObjectByKey <ReceivingDetail>(detailID); int rowsAffected = 0; int itemID = 0; int quantity = 0; int locationID = 0; int units = 0; int? lpn = null; string lot = null; if (detail != null) { itemID = detail.ReceivDetItemID.ItemID; units = detail.intUnits; quantity = detail.ReceivDetQty; locationID = session.GetObjectByKey <Receiving>(detail.ReceivMainID.ReceivID).ReceivingLocation.Oid; lpn = detail.ReceivDetLPN; lot = detail.ReceivDetLot; session.Delete(detail); } ItemsBLL items = new ItemsBLL(); items.UpdateStock(session, itemID, quantity * -1, false, locationID, lot, lpn); return(true); }
public bool InsertDetails(Session session, int receivingID, int?itemID, string lot, int?quantity, int?units, float?pallets, string reason, DateTime?expirationDate) { SPG.ReturnDetDataTable details = new SPG.ReturnDetDataTable(); SPG.ReturnDetRow returnDetail = details.NewReturnDetRow(); returnDetail.ReceiveMainID = receivingID; returnDetail.ReturnDetItemID = itemID.Value; if (string.IsNullOrEmpty(lot)) { returnDetail.SetReturnDetLotNull(); } else { returnDetail.ReturnDetLot = lot; } returnDetail.ReturnDetQty = quantity.Value; if (!units.HasValue) { returnDetail.SetintUnitsNull(); } else { returnDetail.intUnits = units.Value; } if (!pallets.HasValue) { returnDetail.SetsngPalletsNull(); } else { returnDetail.sngPallets = pallets.Value; } if (string.IsNullOrEmpty(reason)) { returnDetail.SetReasonNull(); } else { returnDetail.Reason = reason; } if (expirationDate.HasValue) { returnDetail.ExpirationDate = expirationDate.Value; } else { returnDetail.SetExpirationDateNull(); } details.AddReturnDetRow(returnDetail); int rowsAffected = Adapter.Update(details); if (rowsAffected == 1) { ItemsBLL items = new ItemsBLL(); items.UpdateStock(session, itemID.Value, quantity.Value, false, session.GetObjectByKey <Receiving>(receivingID).ReceivingLocation.Oid); } return(rowsAffected == 1); }
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); } }
private void AddLpnSimpleButton_Click(object sender, EventArgs e) { if (((int?)itemLookUpEdit.EditValue).HasValue && ((int?)locationLookUpEdit.EditValue).HasValue && !m_newLpn) { int lpn = LPNLabel.GetNextLPNNumber(7); ItemsBLL items = new ItemsBLL(); items.UpdateStock(Session.DefaultSession, Convert.ToInt32(itemLookUpEdit.EditValue), 0, false, Convert.ToInt32(locationLookUpEdit.EditValue), "", lpn); lpnXpView.Reload(); lpnLookUpEdit.EditValue = lpn; FilterLots(); m_newLpn = true; } }
public bool DeleteShippingDetail(Session session, int detailID) { SPG.ShippingDetailsDataTable details = Adapter.GetDetailsByDetailID(detailID); int rowsAffected = 0; int itemID = 0; int quantity = 0; int locationID = 0; string lot = null; string fullLPNNumber = null; if (details.Count() == 1) { SPG.ShippingDetailsRow shippingDetail = (SPG.ShippingDetailsRow)details.Rows[0]; itemID = shippingDetail.ShipDetItemID; quantity = shippingDetail.ShipDetDetQty; lot = shippingDetail.ShipDetLot; fullLPNNumber = shippingDetail.FullLPNNumber; locationID = session.GetObjectByKey <Shipping>(shippingDetail.ShipDetMainID).ShippingLocation.Oid; rowsAffected = Adapter.Delete(detailID, shippingDetail.ts); } if (rowsAffected == 1) { ItemsBLL items = new ItemsBLL(); if (fullLPNNumber.StartsWith(CustomersBLL.GetLPNPrefix(7))) { items.UpdateStock(session, itemID, quantity, false, locationID, lot, int.Parse(fullLPNNumber.Replace(CustomersBLL.GetLPNPrefix(7), ""))); } else { items.UpdateStock(session, itemID, quantity, false, locationID); } } //Return true if precisely one row was deleted, otherwise return false. return(rowsAffected == 1); }
public int InsertDetails(Session session, int receivingID, Items item, string lot, int?quantity, int?units, int?LPN, DateTime?expirationDate) { ReceivingDetail detail = new ReceivingDetail(session); detail.ReceivMainID = session.GetObjectByKey <Receiving>(receivingID); detail.ReceivDetItemID = item; detail.intUnits = units.Value; detail.ReceivDetQty = quantity.Value; detail.ExpirationDate = expirationDate; detail.ReceivDetLPN = LPN; detail.ReceivDetLot = lot; detail.Save(); ItemsBLL items = new ItemsBLL(); int locationID = session.GetObjectByKey <Receiving>(receivingID).ReceivingLocation.Oid; items.UpdateStock(session, item.ItemID, quantity.Value, false, locationID, lot, LPN, expirationDate); return(detail.ReceivDetID); }
private void AddPalletsSimpleButton_Click(object sender, EventArgs e) { if (!ValidateAddLPN()) { return; } originalQtyTextEdit.EditValue = QtyTextEdit.EditValue; newQtyTextEdit.EditValue = QtyTextEdit.EditValue; newLotTextEdit.EditValue = LotTextEdit.EditValue; //m_newLpn = false; if (((int?)itemLookUpEdit.EditValue).HasValue && ((int?)locationLookUpEdit.EditValue).HasValue && !m_newLpn) { ItemsBLL items = new ItemsBLL(); items.UpdateStock(Session.DefaultSession, Convert.ToInt32(itemLookUpEdit.EditValue), 0, false, Convert.ToInt32(locationLookUpEdit.EditValue), LotTextEdit.Text, null, null, false); lpnXpView.Reload(); FilterLots(); m_newLpn = true; } saveSimpleButton.Tag = null; AddLpns(); }
public bool UpdateShippingDetails(Session session, int?detailID, int shippingID, int?itemID, string lot, int?quantity, float?pallets, string note, DateTime?expirationDate, string fullLPNNumber) { if (!itemID.HasValue) { throw new ApplicationException("You must provide shipping item."); } if (!quantity.HasValue) { throw new ApplicationException("You must provide the Quantity shipped."); } SPG.ShippingDetailsDataTable details = Adapter.GetDetailsByDetailID(detailID.Value); if (details.Count() == 0) { //It is a new Detail return(InsertDetails(session, shippingID, itemID, lot, quantity, pallets, note, expirationDate, fullLPNNumber)); } SPG.ShippingDetailsRow shippingDetail = details[0]; int originalItem = 0; int originalQuantity = 0; int newQuantity = 0; bool itemChanged = false; object[] originalRecord = shippingDetail.ItemArray; SPG.ShippingDetailsRow originalDetail = details.NewShippingDetailsRow(); originalDetail.ItemArray = (object[])originalRecord.Clone(); originalItem = shippingDetail.ShipDetItemID; if (itemID.HasValue && originalItem != itemID.Value) { itemChanged = true; } shippingDetail.ShipDetItemID = itemID.Value; if (string.IsNullOrEmpty(lot)) { shippingDetail.SetShipDetLotNull(); } else { shippingDetail.ShipDetLot = lot; } originalQuantity = shippingDetail.ShipDetDetQty; newQuantity = quantity.Value - shippingDetail.ShipDetDetQty; shippingDetail.ShipDetDetQty = quantity.Value; shippingDetail.SetsngPackagesNull(); if (!pallets.HasValue) { shippingDetail.SetsngPalletsNull(); } else { shippingDetail.sngPallets = pallets.Value; } if (string.IsNullOrEmpty(note)) { shippingDetail.SetNoteNull(); } else { shippingDetail.Note = note; } if (expirationDate.HasValue) { shippingDetail.ExpirationDate = expirationDate.Value; } else { shippingDetail.SetExpirationDateNull(); } if (string.IsNullOrEmpty(fullLPNNumber)) { shippingDetail.SetFullLPNNumberNull(); } else { shippingDetail.FullLPNNumber = fullLPNNumber; } if (!(originalRecord == null)) { UpdateAuditTrail(shippingDetail, originalRecord); } int rowsAffected = Adapter.Update(shippingDetail); if (rowsAffected == 1) { ItemsBLL items = new ItemsBLL(); int locationID = session.GetObjectByKey <Shipping>(shippingID).ShippingLocation.Oid; //If itemChanged = True Then if (originalDetail.FullLPNNumber.StartsWith(CustomersBLL.GetLPNPrefix(7))) { items.UpdateStock(session, originalItem, originalQuantity, false, locationID, originalDetail.ShipDetLot, int.Parse(originalDetail.FullLPNNumber.Replace(CustomersBLL.GetLPNPrefix(7), ""))); } else { items.UpdateStock(session, originalItem, originalQuantity, false, locationID); } if (fullLPNNumber.StartsWith(CustomersBLL.GetLPNPrefix(7))) { items.UpdateStock(session, itemID.Value, quantity.Value * -1, false, locationID, lot, int.Parse(fullLPNNumber.Replace(CustomersBLL.GetLPNPrefix(7), ""))); } else { items.UpdateStock(session, itemID.Value, quantity.Value * -1, false, locationID); } //Else // If newQuantity <> 0 Then // items.UpdateStock(session, itemID.Value, newQuantity * -1, False, locationID) // End If //End If } return(rowsAffected == 1); }
public bool InsertDetails(Session session, int shippingID, int?itemID, string lot, int?quantity, float?pallets, string note, DateTime?expirationDate, string fullLPNNumber) { SPG.ShippingDetailsDataTable details = new SPG.ShippingDetailsDataTable(); SPG.ShippingDetailsRow shippingDetail = details.NewShippingDetailsRow(); shippingDetail.ShipDetMainID = shippingID; shippingDetail.ShipDetItemID = itemID.Value; if (string.IsNullOrEmpty(lot)) { shippingDetail.SetShipDetLotNull(); } else { shippingDetail.ShipDetLot = lot; } shippingDetail.ShipDetDetQty = quantity.Value; shippingDetail.SetsngPackagesNull(); if (!pallets.HasValue) { shippingDetail.SetsngPalletsNull(); } else { shippingDetail.sngPallets = pallets.Value; } if (string.IsNullOrEmpty(note)) { shippingDetail.SetNoteNull(); } else { shippingDetail.Note = note; } if (expirationDate.HasValue) { shippingDetail.ExpirationDate = expirationDate.Value; } else { shippingDetail.SetExpirationDateNull(); } if (string.IsNullOrEmpty(fullLPNNumber)) { shippingDetail.SetFullLPNNumberNull(); } else { shippingDetail.FullLPNNumber = fullLPNNumber; } details.AddShippingDetailsRow(shippingDetail); int rowsAffected = Adapter.Update(details); if (rowsAffected == 1) { ItemsBLL items = new ItemsBLL(); if (fullLPNNumber.StartsWith(CustomersBLL.GetLPNPrefix(7))) { items.UpdateStock(session, itemID.Value, quantity.Value * -1, false, session.GetObjectByKey <Shipping>(shippingID).ShippingLocation.Oid, lot, int.Parse(fullLPNNumber.Replace(CustomersBLL.GetLPNPrefix(7), ""))); } else { items.UpdateStock(session, itemID.Value, quantity.Value * -1, false, session.GetObjectByKey <Shipping>(shippingID).ShippingLocation.Oid); } } return(rowsAffected == 1); }
public int UpdateReceivingDetails(Session session, int?detailID, int receivingID, int?itemID, string lot, int?quantity, int?units, int?LPN, DateTime?expirationDate) { if (!itemID.HasValue) { throw new ApplicationException("You must provide receiving item."); } if (!quantity.HasValue || !units.HasValue) { throw new ApplicationException("You must provide the amount of quamtity\\units received."); } if (LPN == null) { throw new ApplicationException("LPN is blank."); } Items item = session.GetObjectByKey <Items>(itemID.Value, true); if (!LotCodeValidator.ValidateByItem(item, lot, true)) { throw new ApplicationException("Item " + item.ItemCode + " & lot # " + lot + " is invalid" + Environment.NewLine + "You must provide a valid lot."); } ReceivingDetail detail = session.GetObjectByKey <ReceivingDetail>(detailID); if (detail == null) { //It is a new Detail return(InsertDetails(session, receivingID, item, lot, quantity, units, LPN, expirationDate)); } bool itemChanged = false; ReceivingDetail originalDetail = null; Cloner cloner = new Cloner(); originalDetail = (ReceivingDetail)cloner.CloneTo(detail, typeof(ReceivingDetail)); if (itemID.HasValue && originalDetail.ReceivDetItemID.ItemID != itemID) { itemChanged = true; } detail.ReceivDetItemID = item; detail.intUnits = units.Value; detail.ReceivDetQty = quantity.Value; detail.ExpirationDate = expirationDate; detail.ReceivDetLPN = LPN; detail.ReceivDetLot = lot; if (!(originalDetail == null)) { UpdateAuditTrail(detail, originalDetail); } session.Save(detail); if (!detail.Equals(originalDetail)) { ItemsBLL items = new ItemsBLL(); int locationID = session.GetObjectByKey <Receiving>(receivingID).ReceivingLocation.Oid; items.UpdateStock(session, originalDetail.ReceivDetItemID.ItemID, null, originalDetail.ReceivDetQty * -1, false, locationID, originalDetail.ReceivDetLot, LPN); items.UpdateStock(session, itemID.Value, quantity.Value, false, locationID, lot, LPN, expirationDate); } return(detail.ReceivDetID); }
public bool UpdateInventoryAdjustment(int adjustmentID, DateTime adjustmentDate, int customer, int item, float originalQuantity, float?newQuantity, string reason, int locationID, string OriginalLot, string NewLot, int?LPN, DateTime?Expr, bool IsNewInventory = true) { //Dim adjustments As SPG.InventoryAdjustmentDataTable = Adapter.GetInventoryAdjustmentByID(adjustmentID) //If adjustments.Count = 0 Then Change change = new Change(); InventoryAdjustment adjustment = Session.DefaultSession.GetObjectByKey <InventoryAdjustment>(adjustmentID); if (adjustment == null) { //It is a new Production Record change = new Change() { PropertyName = InventoryAdjustment.Fields.AdjustmentID.PropertyName, PrevValue = "<NULL>", NewValue = adjustmentID.ToString() }; changes.Add(change); return(InsertInventoryAdjustment(adjustmentID, adjustmentDate, customer, item, originalQuantity, newQuantity, reason, locationID, OriginalLot, NewLot, LPN, Expr, IsNewInventory)); } //Dim adjustment As SPG.InventoryAdjustmentRow = adjustments(0) int originalItem = adjustment.AdjustmentItem.ItemID; float? originalNewQuantity = null; float? newNewQuantity = null; string originalNewLot = null; string newNewLot = null; string originalOldLot = null; string newOldLot = null; bool itemChanged = false; int? originalLPN = null; int originalLocation = 0; //Dim originalRecord As Object() = adjustment.ItemArray //adjustment.AdjustmentDate = CDate(Format(adjustmentDate, "D")) //adjustment.Customer = customer if (originalItem != item) { itemChanged = true; } else { itemChanged = false; } //adjustment.ItemID = item float originalOriginalQuantity = adjustment.OriginalQuantity; originalNewQuantity = adjustment.NewCount; originalNewLot = adjustment.NewLot; originalOldLot = adjustment.OriginalLot; originalLPN = adjustment.LPN; originalLocation = adjustment.InventoryLocation.Oid; newNewQuantity = (newQuantity ?? 0) - originalNewQuantity; //adjustment.OriginalQuantity = originalQuantity //adjustment.NewCount = newQuantity //adjustment.Reason = reason change = new Change() { PropertyName = InventoryAdjustment.Fields.AdjustmentID.PropertyName, PrevValue = adjustment.AdjustmentID.ToString(), NewValue = adjustment.AdjustmentID.ToString() }; changes.Add(change); SetInventoryAdjustmentFields(adjustmentDate, customer, item, originalQuantity, newQuantity, reason, locationID, OriginalLot, NewLot, LPN, adjustment); try { adjustment.Save(); } catch (Exception ex) { return(false); } UpdateAuditTrail(); //If Not IsNothing(originalRecord) Then // UpdateAuditTrail(adjustment, originalRecord) //End If //Dim rowsAffected As Integer = Adapter.Update(adjustment) //If rowsAffected = 1 Then ItemsBLL items = new ItemsBLL(); if (!string.IsNullOrEmpty(originalNewLot)) { items.UpdateStock(Session.DefaultSession, originalItem, originalOriginalQuantity, false, originalLocation, originalOldLot, originalLocation, null, IsNewInventory); items.UpdateStock(Session.DefaultSession, originalItem, originalOriginalQuantity * -1, false, originalLocation, originalNewLot, originalLPN, null, IsNewInventory); } else { items.UpdateStock(Session.DefaultSession, originalItem, ((originalNewQuantity ?? 0) - originalOriginalQuantity) * -1, false, originalLocation, OriginalLot, originalLPN); } if (!string.IsNullOrEmpty(NewLot)) { items.UpdateStock(Session.DefaultSession, item, originalQuantity * -1, false, locationID, OriginalLot, LPN, Expr, IsNewInventory); items.UpdateStock(Session.DefaultSession, item, originalQuantity, false, locationID, NewLot, LPN, Expr, IsNewInventory); } else { items.UpdateStock(Session.DefaultSession, item, (newQuantity ?? 0) - originalQuantity, false, locationID, OriginalLot, LPN, Expr); } //If itemChanged = True Then // items.UpdateStock(Session.DefaultSession, originalItem, (If(originalNewQuantity, 0) - originalOriginalQuantity) * -1, False, locationID) // items.UpdateStock(Session.DefaultSession, item, If(newQuantity, 0) - originalQuantity, False, locationID) //Else // If newNewQuantity <> 0 Then 'there was a change in the quantity // items.UpdateStock(Session.DefaultSession, item, If(newNewQuantity, 0), False, locationID) // End If //End If //End If //Return rowsAffected = 1 return(true); }
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 bool UpdateReturnDetails(Session session, int?detailID, int receivingID, int?itemID, string lot, int?quantity, int?units, float?pallets, string reason, DateTime?expirationDate) { if (!itemID.HasValue) { throw new ApplicationException("You must provide return item."); } if (!quantity.HasValue) { throw new ApplicationException("You must provide the Quantity returned."); } SPG.ReturnDetDataTable details = Adapter.GetReturnDetByID(detailID.Value); if (details.Count() == 0) { //It is a new Detail return(InsertDetails(session, receivingID, itemID, lot, quantity, units, pallets, reason, expirationDate)); } SPG.ReturnDetRow returnDetail = details[0]; int originalItem = 0; int originalQuantity = 0; int newQuantity = 0; bool itemChanged = false; object[] originalRecord = returnDetail.ItemArray; originalItem = returnDetail.ReturnDetItemID; if (itemID.HasValue && originalItem != itemID.Value) { itemChanged = true; } returnDetail.ReturnDetItemID = itemID.Value; if (string.IsNullOrEmpty(lot)) { returnDetail.SetReturnDetLotNull(); } else { returnDetail.ReturnDetLot = lot; } originalQuantity = returnDetail.ReturnDetQty; newQuantity = returnDetail.ReturnDetQty - quantity.Value; returnDetail.ReturnDetQty = quantity.Value; if (!units.HasValue) { returnDetail.SetintUnitsNull(); } else { returnDetail.intUnits = units.Value; } if (!pallets.HasValue) { returnDetail.SetsngPalletsNull(); } else { returnDetail.sngPallets = pallets.Value; } if (string.IsNullOrEmpty(reason)) { returnDetail.SetReasonNull(); } else { returnDetail.Reason = reason; } if (expirationDate.HasValue) { returnDetail.ExpirationDate = expirationDate.Value; } else { returnDetail.SetExpirationDateNull(); } if (!(originalRecord == null)) { UpdateAuditTrail(returnDetail, originalRecord); } int rowsAffected = Adapter.Update(returnDetail); if (rowsAffected == 1) { ItemsBLL items = new ItemsBLL(); int locationID = session.GetObjectByKey <Receiving>(receivingID).ReceivingLocation.Oid; if (itemChanged == true) { items.UpdateStock(session, originalItem, originalQuantity * -1, false, locationID); items.UpdateStock(session, itemID.Value, quantity.Value, false, locationID); } else { if (newQuantity != 0) { items.UpdateStock(session, itemID.Value, newQuantity * -1, false, locationID); } } } return(rowsAffected == 1); }
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); }