Пример #1
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);
        }
Пример #2
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 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();
        }