Example #1
0
        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);
        }
Example #2
0
        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);
        }