// 采购中 protected void IbnPurchasing_Click(object sender, EventArgs eventArgs) { bool isHave = false; var codeManager = new CodeManager(); foreach (GridDataItem dataItem in RG_DebitNote.Items) { var purchasingId = new Guid(dataItem.GetDataKeyValue("PurchasingId").ToString()); var personResponsible = new Guid(dataItem.GetDataKeyValue("PersonResponsible").ToString()); var cbCheck = (CheckBox)dataItem.FindControl("CB_Check"); if (cbCheck.Checked) { using (var ts = new TransactionScope(TransactionScopeOption.Required)) { isHave = true; _debitNoteDao.UpdateDebitNoteStateByPurchasingId(purchasingId, (int)DebitNoteState.Purchasing); //生成采购单 DebitNoteInfo debitNoteInfo = _debitNoteDao.GetDebitNoteInfo(purchasingId) ?? new DebitNoteInfo(); IList <DebitNoteDetailInfo> debitNoteDetailList = _debitNoteDao.GetDebitNoteDetailList(purchasingId); CompanyCussentInfo companyCussentInfo = CompanyCussentList.FirstOrDefault(w => w.CompanyId == debitNoteInfo.CompanyId); //var warehouseInfo = WarehouseManager.Get(debitNoteInfo.WarehouseId); PersonnelInfo personnelInfo = PersonnelList.FirstOrDefault(w => w.PersonnelId == debitNoteInfo.PersonResponsible) ?? new PersonnelInfo(null); PurchasingInfo oldPurchasingInfo = _purchasing.GetPurchasingById(purchasingId); var realName = CurrentSession.Personnel.Get().RealName; var filialeId = string.IsNullOrWhiteSpace(debitNoteInfo.PurchasingNo) || debitNoteInfo.PurchasingNo == "-"?FilialeManager.GetHeadList().First(ent => ent.Name.Contains("可得")).ID : _purchasing.GetPurchasingList(debitNoteInfo.PurchasingNo).FilialeID; var pInfo = new PurchasingInfo { PurchasingID = Guid.NewGuid(), PurchasingNo = codeManager.GetCode(CodeType.PH), CompanyID = debitNoteInfo.CompanyId, CompanyName = companyCussentInfo == null ? "" : companyCussentInfo.CompanyName, FilialeID = filialeId, WarehouseID = debitNoteInfo.WarehouseId, PurchasingState = (int)PurchasingState.Purchasing, PurchasingType = (int)PurchasingType.Custom, StartTime = DateTime.Now, EndTime = DateTime.MaxValue, //Description = "[采购类别:{0}赠品借记单][对应采购单号" + debitNoteInfo.PurchasingNo + "]" + CurrentSession.Personnel.Get().RealName, Description = string.Format("[采购类别:{0},赠品借记单对应采购单号{1};采购人:{2}]", EnumAttribute.GetKeyName(PurchasingType.Custom), debitNoteInfo.PurchasingNo, realName), PmId = personnelInfo.PersonnelId, PmName = personnelInfo.RealName, ArrivalTime = oldPurchasingInfo.ArrivalTime, PersonResponsible = personResponsible, PurchasingFilialeId = filialeId }; IList <PurchasingDetailInfo> purchasingDetailList = new List <PurchasingDetailInfo>(); if (debitNoteDetailList.Count > 0) { List <Guid> goodsIdOrRealGoodsIdList = debitNoteDetailList.Select(w => w.GoodsId).Distinct().ToList(); Dictionary <Guid, GoodsInfo> dicGoods = _goodsCenterSao.GetGoodsBaseListByGoodsIdOrRealGoodsIdList(goodsIdOrRealGoodsIdList); if (dicGoods != null && dicGoods.Count > 0) { foreach (var debitNoteDetailInfo in debitNoteDetailList) { bool hasKey = dicGoods.ContainsKey(debitNoteDetailInfo.GoodsId); if (hasKey) { GoodsInfo goodsBaseInfo = dicGoods.FirstOrDefault(w => w.Key == debitNoteDetailInfo.GoodsId).Value; // 获取商品的60、30、11天销量 var purchasingDetailInfo = _purchasingDetail.GetChildGoodsSale(debitNoteDetailInfo.GoodsId, debitNoteInfo.WarehouseId, DateTime.Now, pInfo.PurchasingFilialeId) ?? new PurchasingDetailInfo(); var durchasingDetailInfo = new PurchasingDetailInfo { PurchasingID = pInfo.PurchasingID, PurchasingGoodsID = Guid.NewGuid(), GoodsID = debitNoteDetailInfo.GoodsId, GoodsName = debitNoteDetailInfo.GoodsName, GoodsCode = goodsBaseInfo.GoodsCode, Specification = debitNoteDetailInfo.Specification, CompanyID = pInfo.CompanyID, Price = debitNoteDetailInfo.Price, PlanQuantity = debitNoteDetailInfo.GivingCount, RealityQuantity = 0, State = 0, Description = "", Units = goodsBaseInfo.Units, PurchasingGoodsType = (int)PurchasingGoodsType.Gift, SixtyDaySales = purchasingDetailInfo.SixtyDaySales, ThirtyDaySales = purchasingDetailInfo.ThirtyDaySales, ElevenDaySales = purchasingDetailInfo.ElevenDaySales == 0 ? 0 : purchasingDetailInfo.ElevenDaySales, // 11 //日均销量(11天) CPrice = debitNoteDetailInfo.Price }; purchasingDetailList.Add(durchasingDetailInfo); } } } } if (purchasingDetailList.Count > 0) { _debitNoteDao.UpdateDebitNoteNewPurchasingIdByPurchasingId(purchasingId, pInfo.PurchasingID); _purchasing.PurchasingInsert(pInfo); _purchasing.PurchasingUpdateIsOut(pInfo.PurchasingID); //报备管理生成采购单操作记录添加 WebControl.AddOperationLog(personnelInfo.PersonnelId, personnelInfo.RealName, pInfo.PurchasingID, pInfo.PurchasingNo, OperationPoint.ReportManage.DebitToAddPurchasingList.GetBusinessInfo(), string.Empty); var purchasingDetailManager = new PurchasingDetailManager(_purchasingDetail, _purchasing); purchasingDetailManager.Save(purchasingDetailList); } ts.Complete(); } } } if (isHave == false) { RAM.Alert("未勾选借记单!"); } else { RAM.ResponseScripts.Add("setTimeout(function(){ refreshGrid(); }, " + GlobalConfig.PageAutoRefreshDelayTime + ");"); } }
public void BuilderPurchasing(List <PurchaseDeclarationDTO> stockDeclareDtos, IList <PurchaseSetInfo> purchaseSetList, Guid warehouseId, DateTime?arrivalTime, string operationer, ref StringBuilder failMessage) { var goodsIdList = stockDeclareDtos.Select(w => w.GoodsId).Distinct().ToList(); var goodsBaseInfos = _goodsCenterSao.GetGoodsListByGoodsIds(goodsIdList); if (goodsBaseInfos == null || goodsBaseInfos.Count == 0 || goodsIdList.Count != goodsBaseInfos.Count) { failMessage = new StringBuilder("获取商品信息失败!"); return; } var goodsBaseDics = goodsBaseInfos.ToDictionary(k => k.GoodsId, v => v); if (purchaseSetList == null) { purchaseSetList = _purchaseSet.GetPurchaseSetList(goodsIdList, warehouseId); } var purDics = new Dictionary <PurchasingInfo, IList <PurchasingDetailInfo> >(); var purchasingLists = new List <PurchasingInfo>(); var goodsDics = new Dictionary <string, Guid>(); foreach (var gdiInfoGroup in stockDeclareDtos.GroupBy(ent => new { ent.FilialeId, ent.CompanyId, ent.PersonResponsible })) { var dataList = _purchasing.GetPurchasingList(DateTime.MinValue, DateTime.MinValue, gdiInfoGroup.Key.CompanyId, warehouseId, gdiInfoGroup.Key.FilialeId, PurchasingState.NoSubmit, PurchasingType.StockDeclare, string.Empty, Guid.Empty, gdiInfoGroup.Key.PersonResponsible); if (dataList != null && dataList.Count > 0) { purchasingLists.AddRange(dataList); } foreach (var item in gdiInfoGroup.Where(ent => goodsBaseDics.ContainsKey(ent.GoodsId))) { if (!goodsDics.ContainsKey(item.GoodsName)) { goodsDics.Add(item.GoodsName, item.GoodsId); } var goodsBaseInfo = goodsBaseDics[item.GoodsId]; Guid pGuid = Guid.NewGuid(); var existPurchsingInfo = purchasingLists.FirstOrDefault(ent => ent.CompanyID == gdiInfoGroup.Key.CompanyId && ent.PurchasingFilialeId == gdiInfoGroup.Key.FilialeId && ent.PersonResponsible == gdiInfoGroup.Key.PersonResponsible); var tempPurchasingInfo = purDics.Keys.FirstOrDefault(ent => ent.CompanyID == gdiInfoGroup.Key.CompanyId && ent.PurchasingFilialeId == gdiInfoGroup.Key.FilialeId && ent.PersonResponsible == gdiInfoGroup.Key.PersonResponsible); var flag = tempPurchasingInfo == null || tempPurchasingInfo.PurchasingID == Guid.Empty; if (existPurchsingInfo == null) { IList <PurchasingDetailInfo> pdList; if (flag) { tempPurchasingInfo = new PurchasingInfo(pGuid, new CodeManager().GetCode(CodeType.PH), item.CompanyId, item.CompanyName, item.FilialeId, warehouseId, (int)PurchasingState.NoSubmit , (int)PurchasingType.StockDeclare, DateTime.Now, DateTime.MaxValue , string.Format("[采购类别:{0};采购人:{1}]", Enum.Attribute.EnumAttribute.GetKeyName(PurchasingType.StockDeclare), operationer), Guid.Empty, string.Empty, operationer) { Director = item.PersonResponsibleName, PersonResponsible = item.PersonResponsible, PurchasingFilialeId = item.FilialeId }; pdList = new List <PurchasingDetailInfo>(); } else { pGuid = tempPurchasingInfo.PurchasingID; pdList = purDics[tempPurchasingInfo]; } if (arrivalTime != null) { tempPurchasingInfo.ArrivalTime = (DateTime)arrivalTime; } var detailInfo = new PurchasingDetailInfo(pGuid, item.RealGoodsId, item.GoodsName, goodsBaseInfo.Units, goodsBaseInfo.GoodsCode, item.Sku, item.CompanyId , item.PurchasePrice <= 0?-1: item.PurchasePrice, item.Quantity, 0, 0, string.Empty, Guid.NewGuid(), (int)PurchasingGoodsType.NoGift) { CPrice = item.PurchasePrice == 0 ? -1 : item.PurchasePrice }; //获取商品的60、30、11天销量 var pdInfo = _purchasingDetailManager.GetChildGoodsSale(detailInfo.GoodsID, warehouseId, DateTime.Now, item.FilialeId); if (pdInfo != null) { detailInfo.SixtyDaySales = pdInfo.SixtyDaySales; detailInfo.ThirtyDaySales = pdInfo.ThirtyDaySales; detailInfo.ElevenDaySales = pdInfo.ElevenDaySales / 11;//日均销量(11天) } else { detailInfo.SixtyDaySales = 0; detailInfo.ThirtyDaySales = 0; detailInfo.ElevenDaySales = 0; } if (flag) { pdList.Add(detailInfo); purDics.Add(tempPurchasingInfo, pdList); } else { var tempDetailInfo = pdList.FirstOrDefault(act => act.GoodsID == item.RealGoodsId && act.PurchasingGoodsType == (int)PurchasingGoodsType.NoGift); if (tempDetailInfo == null) { pdList.Add(detailInfo); } else { tempDetailInfo.PlanQuantity += item.PurchaseQuantity; } purDics[tempPurchasingInfo] = pdList; } purchasingLists.Add(tempPurchasingInfo); } else { IList <PurchasingDetailInfo> pdList = new List <PurchasingDetailInfo>(); var detailInfo = new PurchasingDetailInfo(existPurchsingInfo.PurchasingID, item.RealGoodsId, item.GoodsName, goodsBaseInfo.Units, goodsBaseInfo.GoodsCode, item.Sku, item.CompanyId , item.PurchasePrice <= 0 ? -1 : item.PurchasePrice, item.Quantity, 0, 0, "", Guid.NewGuid(), (int)PurchasingGoodsType.NoGift) { CPrice = item.PurchasePrice == 0 ? -1 : item.PurchasePrice }; // 获取商品的60、30、11天销量 var purchasingDetailInfo = _purchasingDetailManager.GetChildGoodsSale(detailInfo.GoodsID, warehouseId, DateTime.Now, item.FilialeId); if (purchasingDetailInfo != null) { detailInfo.SixtyDaySales = purchasingDetailInfo.SixtyDaySales; detailInfo.ThirtyDaySales = purchasingDetailInfo.ThirtyDaySales; detailInfo.ElevenDaySales = purchasingDetailInfo.ElevenDaySales / 11;//日均销量(11天) } else { detailInfo.SixtyDaySales = 0; detailInfo.ThirtyDaySales = 0; detailInfo.ElevenDaySales = 0; } if (!flag) //已经添加采购单 { pdList = purDics[tempPurchasingInfo]; } else { tempPurchasingInfo = existPurchsingInfo; purDics.Add(tempPurchasingInfo, pdList); } var tempDetailInfo = pdList.FirstOrDefault(act => act.GoodsID == detailInfo.GoodsID && act.PurchasingGoodsType == (int)PurchasingGoodsType.NoGift); if (tempDetailInfo == null) { pdList.Add(detailInfo); } else { tempDetailInfo.PlanQuantity += detailInfo.PlanQuantity; } purDics[tempPurchasingInfo] = pdList; } } } #region 采购单重新分配 string msg; var result = CreatePurchasing(purDics, goodsDics, purchaseSetList, out msg); if (!result) { failMessage = new StringBuilder(msg); } #endregion }