void DeductBatchQuantityFromInventory()
        {
            string        query      = "SELECT * FROM ReceivedBatches WHERE SystemId = ?";
            List <object> parameters = new List <object> {
                targetId
            };

            store.ExecuteReader(typeof(ReceivedBatch), query, parameters);

            if (store.Results.Count > 0)
            {
                Entity <ReceivedBatch> targetInventoryEntity = store.Results[0] as Entity <ReceivedBatch>;
                ITransaction           finder = new ListCurrentInventoryTransaction(store);
                finder.Execute();

                foreach (IEntity entity in finder.Results)
                {
                    Entity <InventoryBatch> inventoryEntity = entity as Entity <InventoryBatch>;

                    if (inventoryEntity.NativeModel.BatchNumber == targetInventoryEntity.NativeModel.BatchNumber)
                    {
                        inventoryEntity.NativeModel.DeductQuantity(targetInventoryEntity.NativeModel.Quantity);
                        ITransaction updater = new EditBatchInCurrentInventoryTransaction(inventoryEntity, store);
                        updater.Execute();
                        break;
                    }
                }
            }
        }
Ejemplo n.º 2
0
        void UpdateInventoryBatches(Entity <ReceivedBatch> original, Entity <ReceivedBatch> updated)
        {
            ITransaction deleter = null;

            ProcessColorAndBatchNumberUpdates(original, updated);

            if (BatchDoesNotExistInInventory(updated.NativeModel.BatchNumber))
            {
                InventoryBatch inventoryBatch = new InventoryBatch(
                    updated.NativeModel.ColorName,
                    updated.NativeModel.BatchNumber,
                    updated.NativeModel.ActivityDate,
                    updated.NativeModel.Quantity
                    );

                ITransaction adder = new AddReceivedBatchToInventoryTransaction(new Entity <InventoryBatch>(inventoryBatch), sqliteStore);
                adder.Execute();
            }

            ITransaction finder = new ListCurrentInventoryTransaction(sqliteStore);

            finder.Execute();

            foreach (IEntity entity in finder.Results)
            {
                Entity <InventoryBatch> inventoryEntity = entity as Entity <InventoryBatch>;

                if (inventoryEntity.NativeModel.BatchNumber == original.NativeModel.BatchNumber)
                {
                    inventoryEntity.NativeModel.Quantity = GetAdjustedInventoryQuantity(
                        inventoryEntity.NativeModel.BatchNumber,
                        original.NativeModel.Quantity,
                        updated.NativeModel.Quantity
                        );

                    ITransaction updater = new EditBatchInCurrentInventoryTransaction(inventoryEntity, sqliteStore);
                    updater.Execute();

                    if (inventoryEntity.NativeModel.Quantity == 0)
                    {
                        deleter = new DeleteDepletedInventoryBatchAtId(inventoryEntity, sqliteStore);
                    }
                }
            }

            if (deleter != null)
            {
                deleter.Execute();
            }

            finder.Execute();
            MergeCommonBatches(finder);
        }
        public void UpdateActiveInventory()
        {
            ITransaction finder = new ListCurrentInventoryTransaction(sqliteStore);

            finder.Execute();
            CurrentInventory.Clear();
            CurrentInventoryBatchNumberToIdMappings.Clear();
            BubbleSortEntitiesByBatchDisplayName(finder);

            for (int i = 0; i < finder.Results.Count; i++)
            {
                Entity <InventoryBatch> entity = finder.Results[i] as Entity <InventoryBatch>;
                CurrentInventory.Add(entity.NativeModel);
                CurrentInventoryBatchNumberToIdMappings.Add(entity.NativeModel.BatchNumber, entity.SystemId);
            }
        }
Ejemplo n.º 4
0
        bool BatchDoesNotExistInInventory(string batchNumber)
        {
            ITransaction finder = new ListCurrentInventoryTransaction(sqliteStore);

            finder.Execute();

            foreach (IEntity result in finder.Results)
            {
                Entity <InventoryBatch> entity = result as Entity <InventoryBatch>;

                if (entity.NativeModel.BatchNumber == batchNumber)
                {
                    return(false);
                }
            }

            return(true);
        }
Ejemplo n.º 5
0
        void ProcessColorAndBatchNumberUpdates(Entity <ReceivedBatch> original, Entity <ReceivedBatch> updated)
        {
            ITransaction finder = new ListCurrentInventoryTransaction(sqliteStore);

            finder.Execute();

            foreach (IEntity entity in finder.Results)
            {
                Entity <InventoryBatch> inventoryEntity = entity as Entity <InventoryBatch>;

                if (inventoryEntity.NativeModel.BatchNumber == original.NativeModel.BatchNumber)
                {
                    inventoryEntity.NativeModel.BatchNumber = updated.NativeModel.BatchNumber;
                    inventoryEntity.NativeModel.ColorName   = updated.NativeModel.ColorName;
                    ITransaction updater = new EditBatchInCurrentInventoryTransaction(inventoryEntity, sqliteStore);
                    updater.Execute();
                }
            }
        }
        public InventoryBatch FindInventoryBatchByBatchNumber(string batchNumber)
        {
            InventoryBatch batch  = new InventoryBatch();
            ITransaction   finder = new ListCurrentInventoryTransaction(sqliteStore);

            finder.Execute();

            foreach (IEntity result in finder.Results)
            {
                Entity <InventoryBatch> entity = result as Entity <InventoryBatch>;

                if (entity.NativeModel.BatchNumber == batchNumber)
                {
                    batch = entity.NativeModel;
                    break;
                }
            }

            return(batch);
        }
        public void DeductBatchFromInventory(string batchNumber)
        {
            ITransaction finder = new ListCurrentInventoryTransaction(sqliteStore);

            finder.Execute();

            foreach (IEntity result in finder.Results)
            {
                Entity <InventoryBatch> entity = result as Entity <InventoryBatch>;

                if (entity.NativeModel.BatchNumber == batchNumber)
                {
                    entity.NativeModel.DeductQuantity(1);
                    ITransaction updater = new EditBatchInCurrentInventoryTransaction(entity, sqliteStore);
                    updater.Execute();
                    break;
                }
            }

            UpdateActiveInventory();
        }