void GetCurrentInventoryAmount()
        {
            InventoryBatch batch = inventorySource.FindInventoryBatchByBatchNumber(BatchNumber);

            AmountInInventory = batch.Quantity.ToString();
            NotifyPropertyChanged("AmountInInventory");
        }
示例#2
0
        bool QuantityIsAvialableToDeleteFromInInventory()
        {
            string         batchNumber    = ReceivedBatches[ReceivedBatchesSelectedIndex].BatchNumber;
            InventoryBatch inventoryBatch = inventorySource.FindInventoryBatchByBatchNumber(batchNumber);

            return(inventoryBatch.Quantity >= originalQuantity);
        }
示例#3
0
        void MergeCommonBatches(ITransaction finder)
        {
            List <InventoryBatch> merged = new List <InventoryBatch>();

            foreach (IEntity result in finder.Results)
            {
                Entity <InventoryBatch> currentEntity = result as Entity <InventoryBatch>;
                InventoryBatch          currentBatch  = currentEntity.NativeModel;
                bool batchNotFound = true;

                for (int i = 0; i < merged.Count; i++)
                {
                    if (merged[i].BatchNumber == currentBatch.BatchNumber)
                    {
                        merged[i].AddQuantity(currentBatch.Quantity);
                        batchNotFound = false;
                        continue;
                    }
                }

                if (batchNotFound)
                {
                    merged.Add(currentBatch);
                }
            }

            foreach (InventoryBatch batch in merged)
            {
                ITransaction deleter = new DeleteFromActiveInventoryAtBatchNumberTransaction(batch.BatchNumber, sqliteStore);
                deleter.Execute();
                ITransaction adder = new AddReceivedBatchToInventoryTransaction(new Entity <InventoryBatch>(batch), sqliteStore);
                adder.Execute();
            }
        }
        public void SavingReceivedBatchAlsoUpdatesActiveInventoryWithNewRecord()
        {
            ReceivedBatch batch       = helper.GetUniqueBatch1();
            string        batchNumber = batch.BatchNumber;

            receivedBatchSource.SaveReceivedBatch(batch);
            InventoryBatch stored = inventorySource.FindInventoryBatchByBatchNumber(batchNumber);

            Assert.AreEqual(batchNumber, stored.BatchNumber);
        }
示例#5
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 FindSpecificBatchFromMultipleBatchesInActiveInventory()
        {
            ReceivedBatch paddingBatch = SetupReceivedBatch();
            ReceivedBatch targetBatch  = SetupReceivedBatch();

            targetBatch.BatchNumber = "872894501202";

            inventorySource.AddReceivedBatchToInventory(paddingBatch);
            inventorySource.AddReceivedBatchToInventory(targetBatch);
            InventoryBatch found = inventorySource.FindInventoryBatchByBatchNumber(targetBatch.BatchNumber);

            Assert.AreEqual(targetBatch.BatchNumber, found.BatchNumber);
        }
        public void DeductImplementedBatchFromActiveInventory()
        {
            int           expectedQty = 1;
            ReceivedBatch batch       = SetupReceivedBatch();

            batch.Quantity = 2;

            inventorySource.AddReceivedBatchToInventory(batch);
            inventorySource.DeductBatchFromInventory(batch.BatchNumber);

            InventoryBatch found = inventorySource.FindInventoryBatchByBatchNumber(batch.BatchNumber);

            Assert.AreEqual(expectedQty, found.Quantity);
        }
        public void AddReceivedBatchToInventory(ReceivedBatch batch)
        {
            InventoryBatch inventoryBatch = new InventoryBatch(
                batch.ColorName,
                batch.BatchNumber,
                batch.ActivityDate,
                batch.Quantity
                );

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

            adder.Execute();
            UpdateActiveInventory();
        }
        public void MergedInventoryRecordsHaveCorrectQuantity()
        {
            int           expectedQty = 5;
            ReceivedBatch batch       = SetupReceivedBatch();

            batch.Quantity = 3;
            inventorySource.AddReceivedBatchToInventory(batch);

            batch.Quantity = 2;
            inventorySource.AddReceivedBatchToInventory(batch);

            InventoryBatch found = inventorySource.FindInventoryBatchByBatchNumber(batch.BatchNumber);

            Assert.AreEqual(expectedQty, found.Quantity);
        }
        public void CorrectBatchIsDeductedWhenSendingToImplementationLedger()
        {
            int    expectedQuantity = 2;
            string targetBatch      = string.Empty;

            receivedBatch.Quantity = expectedQuantity + 1;

            inventorySource.AddReceivedBatchToInventory(receivedBatch);
            receivedBatch.BatchNumber = receivedBatchHelper.GetUniqueBatch2().BatchNumber;

            targetBatch = receivedBatch.BatchNumber;
            inventorySource.AddReceivedBatchToInventory(receivedBatch);
            implementedBatchSource.AddBatchToImplementationLedger(targetBatch, date, batchOperator);
            InventoryBatch found = inventorySource.FindInventoryBatchByBatchNumber(targetBatch);

            Assert.AreEqual(expectedQuantity, found.Quantity);
        }
示例#11
0
        public void ExecutedCommandWillAddBatchToImplementationLedgerAndRemoveFromInventory()
        {
            ReceivedBatch receivedBatch          = SetupReceivedBatchWithQuantityOfTwo();
            BatchOperator implementingOperator   = operatorHelper.GetJaneDoeOperator();
            int           expectedQuantity       = 1;
            int           expectedLedgerCount    = 1;
            int           expectedInventoryCount = 1;

            SetupInventoryStateToImplementBatch();
            SetupViewModelStateToImplementBatch();

            command.Execute(null);

            InventoryBatch inventoryBatch = viewModel.CurrentInventory[0];

            Assert.AreEqual(expectedQuantity, inventoryBatch.Quantity);
            Assert.AreEqual(expectedLedgerCount, viewModel.ImplementedBatchLedger.Count);
            Assert.AreEqual(expectedInventoryCount, viewModel.TotalInventoryCount);
        }
        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);
        }
示例#13
0
        public void AddBatchToImplementationLedger(string batchNumber, DateTime date, BatchOperator batchOperator)
        {
            InventoryBatch inventoryBatch = inventorySource.FindInventoryBatchByBatchNumber(batchNumber);

            date = CreateDateTimeWithPrecisionToMinutes(date);

            if (inventoryBatch.BatchNumber == batchNumber)
            {
                LoggedBatch implemented = new LoggedBatch(
                    inventoryBatch.ColorName,
                    inventoryBatch.BatchNumber,
                    date,
                    batchOperator
                    );

                Entity <LoggedBatch> entity = new Entity <LoggedBatch>(implemented);
                ITransaction         adder  = new TransferInventoryBatchToImplementedBatchLedgerTransaction(entity, sqliteStore);
                adder.Execute();
                inventorySource.DeductBatchFromInventory(batchNumber);
                UpdateImplementationLedger();
            }
        }
示例#14
0
        List <IEntity> ProcessInventoryBatches(SQLiteDataReader reader)
        {
            List <IEntity> entities = new List <IEntity>();

            if (reader.HasRows)
            {
                while (reader.Read())
                {
                    InventoryBatch inventoryBatch = new InventoryBatch(
                        reader.GetString(1),
                        reader.GetString(2),
                        DateTime.ParseExact(reader.GetString(3), "yyyy-MM-dd HH:mm:ss", null),
                        reader.GetInt32(4)
                        );

                    Entity <InventoryBatch> entity = new Entity <InventoryBatch>(reader.GetInt32(0), inventoryBatch);
                    entities.Add(entity);
                }
            }

            return(entities);
        }
示例#15
0
 public void Setup()
 {
     batch = new InventoryBatch(colorName, batchNumber, inventoryDate, quantity);
 }