Пример #1
0
        private void ProductStockIn(Guid ownerID, Guid positionID, Guid skuID, string serialNumber, decimal quantity, decimal auxiliaryQuantity)
        {
            ProductStock productStock = null;

            productStock = _context.ProductStocks.Find(ownerID, positionID, skuID, serialNumber);
            if (productStock == null)
            {
                ProductStock newProductStock = ProductStock.Create(ownerID, positionID, skuID, serialNumber, quantity, auxiliaryQuantity);
                _context.ProductStocks.Add(newProductStock);
            }
            else
            {
                if (serialNumber != string.Empty)
                {
                    throw new DomainException("已存在此编码");
                }
                else
                {
                    productStock.AuxiliaryQuantity += auxiliaryQuantity;
                    productStock.Quantity          += quantity;
                }
            }
            var sku = _context.ProductSkus.Find(skuID);

            sku.StockAuxiliaryQuantity += auxiliaryQuantity;
            sku.StockQuantity          += quantity;
        }
Пример #2
0
            void ProductMgrSeed(AlpsContext context)
            {
                var ysjsID = context.Departments.FirstOrDefault(p => p.Name == "轧钢车间").ID;
                var cgID   = context.ProductSkus.FirstOrDefault().ID;

                #region 初始化库存
                context.ProductStocks.Add(ProductStock.Create(ysjsID, positionID, cgID, "900001", 2.5m, 1));
                context.ProductStocks.Add(ProductStock.Create(ysjsID, positionID, cgID, "900002", 2.52m, 1));
                context.SaveChanges();
                #endregion

                #region 初始化入库单--StockInVoucher
                var            skuID   = context.ProductSkus.Find(gcSkuID).ID;
                var            sID     = context.Suppliers.FirstOrDefault().ID;
                var            dID     = context.Departments.OrderByDescending(p => p.ID).FirstOrDefault().ID;
                StockInVoucher voucher = StockInVoucher.Create(sID, dID, "系统初始化");
                context.StockInVouchers.Add(voucher);
                voucher.AddItem(positionID, skuID, "12345", 2.3m, 1, 2100);
                voucher.AddItem(positionID, skuID, "151515", 2.5m, 1, 2100);
                context.SaveChanges();
                voucher = StockInVoucher.Create(sID, dID, "系统初始化2");
                context.StockInVouchers.Add(voucher);
                voucher.AddItem(positionID, skuID, "600001", 2.4m, 1, 2000);
                voucher.AddItem(positionID, skuID, "600002", 2.6m, 1, 2000);

                skuID   = context.ProductSkus.Find(gpSkuID).ID;
                voucher = StockInVoucher.Create(sID, dID, "系统初始化3");
                context.StockInVouchers.Add(voucher);
                voucher.AddItem(positionID, skuID, "", 1000m, 1500, 1800);
                voucher.AddItem(positionID, skuID, "", 2000m, 3000, 1700);

                voucher = StockInVoucher.Create(sID, dID, "系统初始化3");
                context.StockInVouchers.Add(voucher);
                voucher.AddItem(positionID, skuID, "", 500m, 750, 1700);

                context.SaveChanges();
                #endregion

                #region 初始化出库单--StockOutVoucher
                var             cID = context.Customers.FirstOrDefault().ID;
                StockOutVoucher dv  = StockOutVoucher.Create(dID, cID, "系统初始化");
                skuID = context.ProductSkus.Find(gcSkuID).ID;
                dv.AddItem(positionID, skuID, "900001", 2.5m, 1, 2000);
                context.StockOutVouchers.Add(dv);
                skuID = context.ProductSkus.Find(gpSkuID).ID;
                dv    = StockOutVoucher.Create(dID, cID, "系统初始化");
                dv.AddItem(positionID, skuID, "900003", 2.5m, 2, 2000);
                context.StockOutVouchers.Add(dv);
                context.SaveChanges();
                #endregion
            }