예제 #1
0
        // создает новый товарный остаток
        public IEnumerable <IResult> AddFromCatalog()
        {
            while (true)
            {
                var search = new AddStockFromCatalog(Address);
                yield return(new DialogResult(search));

                var edit = new EditStock(search.Item)
                {
                    EditMode = EditStock.Mode.EditAll
                };
                yield return(new DialogResult(edit));

                var stock    = edit.Stock;
                var quantity = stock.Quantity;
                stock.Quantity = 0;
                stock.Status   = StockStatus.InTransit;
                Session.Save(stock);
                var line = new InventoryLine(Doc, stock, quantity, Session, true);
                Lines.Add(line);
                Doc.Lines.Add(line);
                Doc.UpdateStat();
                Save();
            }
        }
        private Stock MapToWebshopType(InventoryLine inventoryLine)
        {
            var stockItem = new Stock()
            {
                ArticleNumber = inventoryLine.Article.ArticleNumber,
                SellableStock = inventoryLine.NumberOfItems - inventoryLine.NumberOfBookedItems
            };

            return(stockItem);
        }
        public void Doc_Flow_with_new_stock()
        {
            stock.Quantity = stock.ReservedQuantity = stock.SupplyQuantity = 0;
            stock.Status   = StockStatus.InTransit;
            session.Update(stock);
            session.Flush();
            // новый пустой сток
            Assert.AreEqual(stock.Quantity, 0);
            Assert.AreEqual(stock.ReservedQuantity, 0);

            var line = new InventoryLine(doc, stock, 3, session, true);

            doc.Lines.Add(line);
            session.Save(doc);
            session.Flush();
            Assert.AreEqual(stock.Quantity, 0);
            Assert.AreEqual(stock.ReservedQuantity, 3);
            Assert.AreEqual(stock.SupplyQuantity, 0);
            Assert.AreEqual(line.Quantity, 3);

            doc.Post();
            session.Save(doc);
            session.Flush();
            Assert.AreEqual(stock.Quantity, 3);
            Assert.AreEqual(stock.ReservedQuantity, 0);
            Assert.AreEqual(stock.SupplyQuantity, 3);
            Assert.AreEqual(line.Quantity, 3);
            Assert.AreEqual(stock.Status, StockStatus.Available);

            //Если мы снова откроем документ, то получим что было до закрытия
            doc.UnPost();
            session.Save(doc);
            session.Flush();
            Assert.AreEqual(stock.Quantity, 0);
            Assert.AreEqual(stock.ReservedQuantity, 3);
            Assert.AreEqual(stock.SupplyQuantity, 3);
            Assert.AreEqual(line.Quantity, 3);
            Assert.AreEqual(stock.Status, StockStatus.InTransit);

            //Если документ будет удален то на складе получим - Папаверин 5 шт, 0 шт в поставке
            doc.BeforeDelete(session);
            session.Delete(doc);
            session.Flush();
            Assert.AreEqual(stock.Quantity, 0);
            Assert.AreEqual(stock.ReservedQuantity, 0);
            Assert.AreEqual(stock.SupplyQuantity, 3);
        }
예제 #4
0
        // добавляет количество к существующему товарному остатку
        public IEnumerable <IResult> Add()
        {
            while (true)
            {
                var search = new StockSearch();
                yield return(new DialogResult(search, resizable: true));

                var edit = new EditStock(search.CurrentItem)
                {
                    EditMode = EditStock.Mode.EditQuantity
                };
                yield return(new DialogResult(edit));

                var line = new InventoryLine(Doc, Session.Load <Stock>(edit.Stock.Id), edit.Stock.Quantity, Session);
                Lines.Add(line);
                Doc.Lines.Add(line);
                Doc.UpdateStat();
                Save();
            }
        }
        public void Doc_Flow()
        {
            //На складе есть Папаверин в количестве 5 шт.
            Assert.AreEqual(stock.Quantity, 5);
            Assert.AreEqual(stock.SupplyQuantity, 5);

            var line = new InventoryLine(doc, stock, 3, session);

            doc.Lines.Add(line);
            session.Save(doc);
            session.Flush();
            Assert.AreEqual(stock.Quantity, 5);
            Assert.AreEqual(stock.ReservedQuantity, 3);
            Assert.AreEqual(stock.SupplyQuantity, 5);
            Assert.AreEqual(line.Quantity, 3);

            doc.Post();
            session.Save(doc);
            session.Flush();
            Assert.AreEqual(stock.Quantity, 8);
            Assert.AreEqual(stock.ReservedQuantity, 0);
            Assert.AreEqual(stock.SupplyQuantity, 5);
            Assert.AreEqual(line.Quantity, 3);

            //Если мы снова откроем документ, то получим что было до закрытия - Папаверин 5 шт, 3 шт в поставке
            doc.UnPost();
            session.Save(doc);
            session.Flush();
            Assert.AreEqual(stock.Quantity, 5);
            Assert.AreEqual(stock.ReservedQuantity, 3);
            Assert.AreEqual(stock.SupplyQuantity, 5);
            Assert.AreEqual(line.Quantity, 3);

            //Если документ будет удален то на складе получим - Папаверин 5 шт, 0 шт в поставке
            doc.BeforeDelete(session);
            session.Delete(doc);
            session.Flush();
            Assert.AreEqual(stock.Quantity, 5);
            Assert.AreEqual(stock.ReservedQuantity, 0);
            Assert.AreEqual(stock.SupplyQuantity, 5);
        }
예제 #6
0
        public void Edit(Library.Model.Location model)
        {
            IQueryable <Location> locations = _locationContext.Locations
                                              .Include(l => l.InventoryLines)
                                              .ThenInclude(il => il.Product);
            Location entity = locations.First(l => l.LocationId == model.LocationId);

            if (entity == null)
            {
                s_logger.Warn($"Location to be edited does not exist: ignoring.");
                return;
            }
            foreach (Library.Model.InventoryLine line in model.Inventory)
            {
                InventoryLine entity2 = entity.InventoryLines.First(il => il.InventoryLineId == line.InventoryLineId);
                if (entity2 == null)
                {
                    s_logger.Warn($"InventoryLine to be edited on location ${entity.LocationId} does not exist: ignoring.");
                    return;
                }
            }

            s_logger.Info($"Editing Location");

            var products = _locationContext.Products
                           .AsNoTracking();

            foreach (Library.Model.InventoryLine line in model.Inventory)
            {
                InventoryLine entity2 = entity.InventoryLines.First(il => il.InventoryLineId == line.InventoryLineId);
                entity2.Quantity  = line.Quantity;
                entity2.LineTotal = entity2.Quantity * entity2.Product.UnitPrice;
                _locationContext.Update(entity2);
            }
            _locationContext.Update(entity);
        }
예제 #7
0
        public void Exchange()
        {
            localSession.Connection.Execute(@"delete from Stocks; delete from StockActions;");
            session.Connection.Execute(@"delete from inventory.Stocks;");
            session.Connection.Execute(@"delete from inventory.StockActions;");
            session.Connection.Execute(@"delete from  Documents.DocumentHeaders;");
            var stockCount = session.Connection.Query <object>("select * from inventory.Stocks").ToArray();
            var actions    = session.Connection.Query <object>("select * from inventory.StockActions").ToArray();

            stockCount = localSession.Connection.Query <object>("select * from Stocks").ToArray();
            actions    = localSession.Connection.Query <object>("select * from StockActions").ToArray();

            Run(new SyncCommand());

            var fixture = new CreateWaybill();

            Fixture(fixture);

            Run(new UpdateCommand("Waybills"));
            var waybill  = localSession.Load <Waybill>(fixture.Waybill.Log.Id);
            var stockids = waybill.Lines.Where(x => x.StockId != null).Select(x => x.StockId).ToArray();
            var map      = localSession.Query <Stock>().Where(x => stockids.Contains(x.ServerId)).ToDictionary(x => x.ServerId);

            waybill.Lines.Each(y =>
            {
                y.Stock = map.GetValueOrDefault(y.StockId);
            });
            waybill.Stock(localSession);
            // чек +0 сток = 33  +1 стокакшин = 34
            var check = new Check(localSession.Query <User>().First(), address, new[] { new CheckLine(waybill.Lines[0].Stock, 1), }, CheckType.SaleBuyer);

            check.Lines.Each(x => x.Doc = check);
            localSession.Save(check);
            localSession.SaveEach(check.Lines);
            localSession.SaveEach(check.Lines.Select(x => x.UpdateStock(x.Stock, CheckType.SaleBuyer)));

            // распаковка +1 сток = 34  +2 стокакшин = 36
            var unpackingDoc  = new UnpackingDoc(address, localSession.Query <User>().First());
            var unpackingLine = new UnpackingLine(waybill.Lines[1].Stock, 10);

            unpackingDoc.Lines.Add(unpackingLine);
            unpackingDoc.Post();
            unpackingDoc.PostStockActions();
            localSession.Save(unpackingDoc);
            foreach (var line in unpackingDoc.Lines)
            {
                localSession.Save(line);
            }
            unpackingDoc.PostStockActions();
            foreach (var line in unpackingDoc.Lines)
            {
                localSession.Save(line.SrcStockAction);
                localSession.Save(line.DstStockAction);
            }

            // Списание +0 сток = 34  +1 стокакшин = 37
            var writeoffDoc  = new WriteoffDoc(address, localSession.Query <User>().First());
            var writeoffLine = new WriteoffLine(waybill.Lines[2].Stock, 1);

            writeoffDoc.Lines.Add(writeoffLine);
            writeoffDoc.Post(localSession);
            localSession.Save(writeoffDoc);

            //Возврат +0 сток = 34  +1 стокакшин = 38
            var ReturnDoc = new ReturnDoc(address, localSession.Query <User>().First());

            ReturnDoc.Supplier = waybill.Supplier;
            var ReturnLine = new ReturnLine(waybill.Lines[3].Stock, 1);

            ReturnDoc.Lines.Add(ReturnLine);
            ReturnDoc.Post(localSession);
            localSession.Save(ReturnDoc);

            //переоценка +1 сток = 35  +2 стокакшин = 40
            var ReassessmentDoc = new ReassessmentDoc(address, localSession.Query <User>().First());
            var stock           = waybill.Lines[4].Stock.Copy();

            stock.RetailCost += 10;
            var ReassessmentLine = new ReassessmentLine(waybill.Lines[4].Stock, stock);

            ReassessmentDoc.Lines.Add(ReassessmentLine);
            ReassessmentDoc.Post(localSession);
            localSession.Save(ReassessmentDoc);

            //переоценка +0 сток = 35  +1 стокакшин = 41
            var InventoryDoc  = new InventoryDoc(address, localSession.Query <User>().First());
            var InventoryLine = new InventoryLine(InventoryDoc, waybill.Lines[5].Stock, 5, localSession);

            InventoryDoc.Lines.Add(InventoryLine);
            InventoryDoc.Post();
            localSession.Save(InventoryDoc);

            //Перемещение +1 сток = 36  +2 стокакшин = 43
            var DisplacementDoc  = new DisplacementDoc(address, localSession.Query <User>().First());
            var DisplacementLine = new DisplacementLine(waybill.Lines[6].Stock, waybill.Lines[6].Stock.Copy(), 1);

            DisplacementDoc.Lines.Add(DisplacementLine);
            DisplacementDoc.Post(localSession);
            localSession.Save(DisplacementDoc);

            Run(new SyncCommand());
            stockCount = session.Connection.Query <object>("select * from inventory.Stocks").ToArray();
            actions    = session.Connection.Query <object>("select * from inventory.StockActions").ToArray();
            Assert.AreEqual(36, stockCount.Length);
            Assert.AreEqual(43, actions.Length);

            Run(new SyncCommand());
            stockCount = session.Connection.Query <object>("select * from inventory.Stocks").ToArray();
            actions    = session.Connection.Query <object>("select * from inventory.StockActions").ToArray();
            Assert.AreEqual(36, stockCount.Length);
            Assert.AreEqual(43, actions.Length);
        }