public void Create(StocktakingModel model) { var entity = model.MapTo <Stocktaking>(); entity.Status = StocktakingStatus.Audited; entity.StocktakingType = StocktakingType.Stocktaking; entity.Items = JsonConvert.DeserializeObject <List <StocktakingItem> >(model.ItemsJson); if (entity.Items.Sum(n => n.CountQuantity) == 0) { throw new Exception("盘点数不能都为0"); } entity.Code = _billService.GenerateNewCode(BillIdentity.StoreStocktaking); _db.Insert(entity); _db.SaveChange(); }
/// <summary> /// 创建调价单就立即生效 /// </summary> /// <param name="model"></param> public void Create(AdjustSalePriceModel model) { // 创建调价单 var entity = new AdjustSalePrice(); entity = model.MapTo <AdjustSalePrice>(); var items = model.ConvertJsonToItem(); entity.AddItems(items); entity.CreatedBy = model.UpdatedBy; entity.Code = _sequenceService.GenerateNewCode(BillIdentity.AdjustSalePrice); _service.Create(entity); // 修改商品价格 Dictionary <int, decimal> productSalePriceDic = new Dictionary <int, decimal>(); items.ToList().ForEach(n => productSalePriceDic.Add(n.ProductId, n.AdjustPrice)); _productService.UpdateSalePrice(productSalePriceDic); // 修改单据状态 entity.Submit(); _db.SaveChange(); var reason = "创建商品调价单"; entity = _db.Table.Find <AdjustSalePrice>(n => n.Code == entity.Code); _processHistoryService.Track(model.UpdatedBy, model.UpdatedByName, (int)entity.Status, entity.Id, BillIdentity.AdjustSalePrice.ToString(), reason); _db.SaveChange(); }
public void Create(TransferOrderModel model) { TransferOrder entity = model.MapTo <TransferOrder>(); entity.CreatedBy = model.EditBy; entity.CreatedByName = model.EditByName; entity.UpdatedBy = model.EditBy; entity.Code = _sequenceService.GenerateNewCode(BillIdentity.TransferOrder); // 明细 var items = JsonConvert.DeserializeObject <List <TransferOrderItem> >(model.ItemsJson); entity.Items = items; _db.Insert(entity); //跟踪记录 var reason = "创建调拨单"; var history = new ProcessHistory(model.EditBy, model.EditByName, (int)entity.Status, entity.Id, BillIdentity.TransferOrder.ToString(), reason); _db.Command.AddExecute(history.CreateSql(entity.GetType().Name, entity.Code), history); _db.SaveChange(); var modelEntity = _db.Table.Find <TransferOrder>(n => n.Code == entity.Code); model.Id = modelEntity.Id; model.Code = entity.Code; model.StatusName = entity.Status.Description(); entity.Id = modelEntity.Id; }
public void Create(CreateStorePurchaseOrder model) { var entity = new StorePurchaseOrder(); entity = model.MapTo <StorePurchaseOrder>(); entity.AddItems(model.ConvertJsonToItem()); var reason = "创建采购单"; var billIdentity = BillIdentity.StorePurchaseOrder; if (entity.OrderType == OrderType.Refund) { reason = "创建采购退单"; billIdentity = BillIdentity.StorePurchaseRefundOrder; } var entitys = _service.SplitOrderItem(entity); foreach (var order in entitys) { entity.Code = _sequenceService.GenerateNewCode(billIdentity); entity.SetItems(order.Items.ToList()); _db.Insert(entity); var history = new ProcessHistory(model.CreatedBy, model.CreatedByName, (int)entity.Status, entity.Id, billIdentity.ToString(), reason); _db.Command.AddExecute(history.CreateSql(entity.GetType().Name, entity.Code), history); _db.SaveChange(); } }
public void Create(ProductModel model) { Product entity = model.MapTo <Product>(); entity.BarCode = entity.BarCode.Trim(); _productService.ValidateBarCode(entity.BarCode); entity.CreatedBy = model.UpdatedBy; entity.Code = _productService.GenerateNewCode(entity.CategoryId); _db.Insert(entity); // 有变价,记录变价 if (entity.SalePrice > 0) { var newCode = _sequenceService.GenerateNewCode(BillIdentity.AdjustSalePrice); var adjustEntity = _adjustSalePriceService.Create(entity, model.SalePrice, newCode, model.UpdatedBy); _db.Insert(adjustEntity); } _db.SaveChange(); }
public void Create(StocktakingPlanModel model) { var entity = model.MapTo <StocktakingPlan>(); entity.CreatedBy = model.EditedBy; entity.CreatedByName = model.Editor; entity.UpdatedBy = model.EditedBy; entity.UpdatedByName = model.Editor; entity.Code = _billService.GenerateNewCode(BillIdentity.StoreStocktakingPlan); _service.ValidatePlan(entity); _service.ValidatePlanDate(entity); _db.Insert(entity); _db.SaveChange(); }
public void Create(AdjustStorePriceModel model) { var entity = new AdjustStorePrice(); entity = model.MapTo <AdjustStorePrice>(); entity.AddItems(model.ConvertJsonToItem()); entity.CreatedBy = model.UpdatedBy; entity.Code = _sequenceService.GenerateNewCode(BillIdentity.AdjustStorePrice); _db.Insert(entity); var reason = "创建门店调价单"; var history = new ProcessHistory(model.UpdatedBy, model.UpdatedByName, (int)entity.Status, entity.Id, BillIdentity.AdjustStorePrice.ToString(), reason); _db.Command.AddExecute(history.CreateSql(entity.GetType().Name, entity.Code), history); _db.SaveChange(); }
public void Create(OutInOrderModel model) { OutInOrder entity = model.MapTo <OutInOrder>(); entity.CreatedBy = model.EditBy; entity.CreatedByName = model.EditByName; entity.UpdatedBy = model.EditBy; entity.UpdatedByName = model.EditByName; // entity.Code = _sequenceService.GenerateNewCode(BillIdentity.OtherInOrder); // 明细 var items = JsonConvert.DeserializeObject <List <OutInOrderItem> >(model.ItemsJson); entity.SetItems(items); var orderType = _db.Table.Find <OutInOrderType>(entity.OutInOrderTypeId); if (orderType == null) { throw new FriendlyException("业务类别为空"); } var reason = "创建其他入库单"; var billIdentity = BillIdentity.OtherInOrder; if (orderType.OutInInventory == OutInInventoryType.Out) { reason = "创建其他出库单"; billIdentity = BillIdentity.OtherOutOrder; } var entitys = _service.SplitOrderItem(entity, orderType); foreach (var order in entitys) { entity.Code = _sequenceService.GenerateNewCode(billIdentity); entity.SetItems(order.Items.ToList()); _db.Insert(entity); var history = new ProcessHistory(entity.CreatedBy, entity.CreatedByName, (int)entity.Status, entity.Id, billIdentity.ToString(), reason); _db.Command.AddExecute(history.CreateSql(entity.GetType().Name, entity.Code), history); _db.SaveChange(); if (model.SaveAndSubmit) { var modelEntity = _db.Table.Find <OutInOrder>(n => n.Code == entity.Code); model.Id = modelEntity.Id; Submit(model.Id, model.EditBy, model.EditByName); } } }
public void Create(AdjustSalePriceModel model) { var entity = new AdjustSalePrice(); entity = model.MapTo <AdjustSalePrice>(); entity.AddItems(model.ConvertJsonToItem()); entity.CreatedBy = model.UpdatedBy; entity.Code = _sequenceService.GenerateNewCode(BillIdentity.AdjustSalePrice); _service.Create(entity); _db.SaveChange(); var reason = "创建商品调价单"; entity = _db.Table.Find <AdjustSalePrice>(n => n.Code == entity.Code); _processHistoryService.Track(model.UpdatedBy, model.UpdatedByName, (int)entity.Status, entity.Id, BillIdentity.AdjustSalePrice.ToString(), reason); _db.SaveChange(); }